The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251894 lines
6.4MB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifdef __JUCE_JUCEHEADER__
  19. #error
  20. #endif
  21. /*** Start of inlined file: juce_TargetPlatform.h ***/
  22. #ifndef __JUCE_TARGETPLATFORM_JUCEHEADER__
  23. #define __JUCE_TARGETPLATFORM_JUCEHEADER__
  24. #if (defined (_WIN32) || defined (_WIN64))
  25. #define JUCE_WIN32 1
  26. #define JUCE_WINDOWS 1
  27. #elif defined (LINUX) || defined (__linux__)
  28. #define JUCE_LINUX 1
  29. #elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  30. #include <CoreFoundation/CoreFoundation.h> // (needed to find out what platform we're using)
  31. #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
  32. #define JUCE_IPHONE 1
  33. #else
  34. #define JUCE_MAC 1
  35. #endif
  36. #else
  37. #error "Unknown platform!"
  38. #endif
  39. #if JUCE_WINDOWS
  40. #ifdef _MSC_VER
  41. #ifdef _WIN64
  42. #define JUCE_64BIT 1
  43. #else
  44. #define JUCE_32BIT 1
  45. #endif
  46. #endif
  47. #ifdef _DEBUG
  48. #define JUCE_DEBUG 1
  49. #endif
  50. #ifdef __MINGW32__
  51. #define JUCE_MINGW 1
  52. #endif
  53. #define JUCE_LITTLE_ENDIAN 1
  54. #define JUCE_INTEL 1
  55. #endif
  56. #if JUCE_MAC
  57. #ifndef NDEBUG
  58. #define JUCE_DEBUG 1
  59. #endif
  60. #ifdef __LITTLE_ENDIAN__
  61. #define JUCE_LITTLE_ENDIAN 1
  62. #else
  63. #define JUCE_BIG_ENDIAN 1
  64. #endif
  65. #if defined (__ppc__) || defined (__ppc64__)
  66. #define JUCE_PPC 1
  67. #undef MAC_OS_X_VERSION_MAX_ALLOWED
  68. #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_4
  69. #else
  70. #define JUCE_INTEL 1
  71. #endif
  72. #ifdef __LP64__
  73. #define JUCE_64BIT 1
  74. #else
  75. #define JUCE_32BIT 1
  76. #endif
  77. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  78. #error "Building for OSX 10.3 is no longer supported!"
  79. #endif
  80. #ifndef MAC_OS_X_VERSION_10_5
  81. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  82. #endif
  83. #endif
  84. #if JUCE_IPHONE
  85. #ifndef NDEBUG
  86. #define JUCE_DEBUG 1
  87. #endif
  88. #ifdef __LITTLE_ENDIAN__
  89. #define JUCE_LITTLE_ENDIAN 1
  90. #else
  91. #define JUCE_BIG_ENDIAN 1
  92. #endif
  93. #endif
  94. #if JUCE_LINUX
  95. #ifdef _DEBUG
  96. #define JUCE_DEBUG 1
  97. #endif
  98. // Allow override for big-endian Linux platforms
  99. #ifndef JUCE_BIG_ENDIAN
  100. #define JUCE_LITTLE_ENDIAN 1
  101. #endif
  102. #if defined (__LP64__) || defined (_LP64)
  103. #define JUCE_64BIT 1
  104. #else
  105. #define JUCE_32BIT 1
  106. #endif
  107. #define JUCE_INTEL 1
  108. #endif
  109. // Compiler type macros.
  110. #ifdef __GNUC__
  111. #define JUCE_GCC 1
  112. #elif defined (_MSC_VER)
  113. #define JUCE_MSVC 1
  114. #if _MSC_VER >= 1400
  115. #define JUCE_USE_INTRINSICS 1
  116. #endif
  117. #else
  118. #error unknown compiler
  119. #endif
  120. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  121. /*** End of inlined file: juce_TargetPlatform.h ***/
  122. // FORCE_AMALGAMATOR_INCLUDE
  123. /*** Start of inlined file: juce_Config.h ***/
  124. #ifndef __JUCE_CONFIG_JUCEHEADER__
  125. #define __JUCE_CONFIG_JUCEHEADER__
  126. #ifndef JUCE_NAMESPACE
  127. #define JUCE_NAMESPACE juce
  128. #endif
  129. #ifndef JUCE_FORCE_DEBUG
  130. //#define JUCE_FORCE_DEBUG 0
  131. #endif
  132. #ifndef JUCE_LOG_ASSERTIONS
  133. #define JUCE_LOG_ASSERTIONS 0
  134. #endif
  135. #ifndef JUCE_ASIO
  136. #define JUCE_ASIO 0
  137. #endif
  138. #ifndef JUCE_WASAPI
  139. #define JUCE_WASAPI 0
  140. #endif
  141. #ifndef JUCE_DIRECTSOUND
  142. #define JUCE_DIRECTSOUND 1
  143. #endif
  144. #ifndef JUCE_ALSA
  145. #define JUCE_ALSA 1
  146. #endif
  147. #ifndef JUCE_JACK
  148. #define JUCE_JACK 0
  149. #endif
  150. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  151. #define JUCE_QUICKTIME 0
  152. #endif
  153. #if (JUCE_IPHONE || JUCE_LINUX) && JUCE_QUICKTIME
  154. #undef JUCE_QUICKTIME
  155. #endif
  156. #ifndef JUCE_OPENGL
  157. #define JUCE_OPENGL 1
  158. #endif
  159. #ifndef JUCE_USE_FLAC
  160. #define JUCE_USE_FLAC 1
  161. #endif
  162. #ifndef JUCE_USE_OGGVORBIS
  163. #define JUCE_USE_OGGVORBIS 1
  164. #endif
  165. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  166. #define JUCE_USE_CDBURNER 0
  167. #endif
  168. #ifndef JUCE_USE_CDREADER
  169. #define JUCE_USE_CDREADER 0
  170. #endif
  171. #if (JUCE_QUICKTIME || JUCE_WINDOWS) && ! defined (JUCE_USE_CAMERA)
  172. #define JUCE_USE_CAMERA 0
  173. #endif
  174. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  175. #define JUCE_ENABLE_REPAINT_DEBUGGING 0
  176. #endif
  177. #ifndef JUCE_USE_XINERAMA
  178. #define JUCE_USE_XINERAMA 1
  179. #endif
  180. #ifndef JUCE_USE_XSHM
  181. #define JUCE_USE_XSHM 1
  182. #endif
  183. #ifndef JUCE_USE_XRENDER
  184. #define JUCE_USE_XRENDER 0
  185. #endif
  186. #ifndef JUCE_USE_XCURSOR
  187. #define JUCE_USE_XCURSOR 1
  188. #endif
  189. #ifndef JUCE_PLUGINHOST_VST
  190. #define JUCE_PLUGINHOST_VST 0
  191. #endif
  192. #ifndef JUCE_PLUGINHOST_AU
  193. #define JUCE_PLUGINHOST_AU 0
  194. #endif
  195. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  196. #define JUCE_ONLY_BUILD_CORE_LIBRARY 0
  197. #endif
  198. #ifndef JUCE_WEB_BROWSER
  199. #define JUCE_WEB_BROWSER 0
  200. #endif
  201. #ifndef JUCE_SUPPORT_CARBON
  202. #define JUCE_SUPPORT_CARBON 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_ZLIB_CODE
  205. #define JUCE_INCLUDE_ZLIB_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_FLAC_CODE
  208. #define JUCE_INCLUDE_FLAC_CODE 1
  209. #endif
  210. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  211. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  212. #endif
  213. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  214. #define JUCE_INCLUDE_PNGLIB_CODE 1
  215. #endif
  216. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  217. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  218. #endif
  219. #ifndef JUCE_CHECK_MEMORY_LEAKS
  220. #define JUCE_CHECK_MEMORY_LEAKS 1
  221. #endif
  222. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  223. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  224. #endif
  225. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  226. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  227. #undef JUCE_QUICKTIME
  228. #define JUCE_QUICKTIME 0
  229. #undef JUCE_OPENGL
  230. #define JUCE_OPENGL 0
  231. #undef JUCE_USE_CDBURNER
  232. #define JUCE_USE_CDBURNER 0
  233. #undef JUCE_USE_CDREADER
  234. #define JUCE_USE_CDREADER 0
  235. #undef JUCE_WEB_BROWSER
  236. #define JUCE_WEB_BROWSER 0
  237. #undef JUCE_PLUGINHOST_AU
  238. #define JUCE_PLUGINHOST_AU 0
  239. #undef JUCE_PLUGINHOST_VST
  240. #define JUCE_PLUGINHOST_VST 0
  241. #endif
  242. #endif
  243. /*** End of inlined file: juce_Config.h ***/
  244. // FORCE_AMALGAMATOR_INCLUDE
  245. #ifndef JUCE_BUILD_CORE
  246. #define JUCE_BUILD_CORE 1
  247. #endif
  248. #ifndef JUCE_BUILD_MISC
  249. #define JUCE_BUILD_MISC 1
  250. #endif
  251. #ifndef JUCE_BUILD_GUI
  252. #define JUCE_BUILD_GUI 1
  253. #endif
  254. #ifndef JUCE_BUILD_NATIVE
  255. #define JUCE_BUILD_NATIVE 1
  256. #endif
  257. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  258. #undef JUCE_BUILD_MISC
  259. #undef JUCE_BUILD_GUI
  260. #endif
  261. //==============================================================================
  262. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  263. #if JUCE_WINDOWS
  264. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  265. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  266. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  267. #ifndef STRICT
  268. #define STRICT 1
  269. #endif
  270. #undef WIN32_LEAN_AND_MEAN
  271. #define WIN32_LEAN_AND_MEAN 1
  272. #ifdef _MSC_VER
  273. #pragma warning (push)
  274. #pragma warning (disable : 4100 4201 4514 4312 4995)
  275. #endif
  276. #define _WIN32_WINNT 0x0500
  277. #define _UNICODE 1
  278. #define UNICODE 1
  279. #ifndef _WIN32_IE
  280. #define _WIN32_IE 0x0400
  281. #endif
  282. #include <windows.h>
  283. #include <windowsx.h>
  284. #include <commdlg.h>
  285. #include <shellapi.h>
  286. #include <mmsystem.h>
  287. #include <vfw.h>
  288. #include <tchar.h>
  289. #include <stddef.h>
  290. #include <ctime>
  291. #include <wininet.h>
  292. #include <nb30.h>
  293. #include <iphlpapi.h>
  294. #include <mapi.h>
  295. #include <float.h>
  296. #include <process.h>
  297. #include <Exdisp.h>
  298. #include <exdispid.h>
  299. #include <shlobj.h>
  300. #if ! JUCE_MINGW
  301. #include <crtdbg.h>
  302. #include <comutil.h>
  303. #endif
  304. #if JUCE_OPENGL
  305. #include <gl/gl.h>
  306. #endif
  307. #undef PACKED
  308. #if JUCE_ASIO
  309. #include "iasiodrv.h"
  310. #endif
  311. #if JUCE_USE_CDBURNER
  312. #include <imapi.h>
  313. #include <imapierror.h>
  314. #endif
  315. #if JUCE_USE_CAMERA
  316. #include <dshow.h>
  317. #include <qedit.h>
  318. #include <dshowasf.h>
  319. #endif
  320. #if JUCE_WASAPI
  321. #include <MMReg.h>
  322. #include <mmdeviceapi.h>
  323. #include <Audioclient.h>
  324. #include <Avrt.h>
  325. #include <functiondiscoverykeys.h>
  326. #endif
  327. #if JUCE_QUICKTIME
  328. #include <Movies.h>
  329. #include <QTML.h>
  330. #include <QuickTimeComponents.h>
  331. #include <MediaHandlers.h>
  332. #include <ImageCodec.h>
  333. #import <QTOLibrary.dll>
  334. #import <QTOControl.dll>
  335. #endif
  336. #ifdef _MSC_VER
  337. #pragma warning (pop)
  338. #endif
  339. template <class ComClass>
  340. class ComSmartPtr
  341. {
  342. public:
  343. ComSmartPtr() throw() : p (0) {}
  344. ComSmartPtr (ComClass* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  345. ComSmartPtr (const ComSmartPtr<ComClass>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  346. ~ComSmartPtr() { if (p != 0) p->Release(); }
  347. operator ComClass*() const throw() { return p; }
  348. ComClass& operator*() const throw() { return *p; }
  349. ComClass** operator&() throw() { return &p; }
  350. ComClass* operator->() const throw() { return p; }
  351. ComClass* operator= (ComClass* const newP)
  352. {
  353. if (newP != 0) newP->AddRef();
  354. if (p != 0) p->Release();
  355. p = newP;
  356. return newP;
  357. }
  358. ComClass* operator= (const ComSmartPtr<ComClass>& newP) { return operator= (newP.p); }
  359. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext = CLSCTX_INPROC_SERVER)
  360. {
  361. #ifndef __MINGW32__
  362. operator= (0);
  363. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof (ComClass), (void**) &p);
  364. #else
  365. return S_FALSE;
  366. #endif
  367. }
  368. private:
  369. ComClass* p;
  370. };
  371. template <class ComClass>
  372. class ComBaseClassHelper : public ComClass
  373. {
  374. public:
  375. ComBaseClassHelper() : refCount (1) {}
  376. virtual ~ComBaseClassHelper() {}
  377. HRESULT __stdcall QueryInterface (REFIID refId, void __RPC_FAR* __RPC_FAR* result)
  378. {
  379. if (refId == __uuidof (ComClass)) { AddRef(); *result = dynamic_cast <ComClass*> (this); return S_OK; }
  380. if (refId == IID_IUnknown) { AddRef(); *result = dynamic_cast <IUnknown*> (this); return S_OK; }
  381. *result = 0;
  382. return E_NOINTERFACE;
  383. }
  384. ULONG __stdcall AddRef() { return ++refCount; }
  385. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  386. protected:
  387. int refCount;
  388. };
  389. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  390. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  391. #elif JUCE_LINUX
  392. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  393. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  394. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  395. #include <sched.h>
  396. #include <pthread.h>
  397. #include <sys/time.h>
  398. #include <errno.h>
  399. #include <sys/stat.h>
  400. #include <sys/dir.h>
  401. #include <sys/ptrace.h>
  402. #include <sys/vfs.h>
  403. #include <sys/wait.h>
  404. #include <fnmatch.h>
  405. #include <utime.h>
  406. #include <pwd.h>
  407. #include <fcntl.h>
  408. #include <dlfcn.h>
  409. #include <netdb.h>
  410. #include <arpa/inet.h>
  411. #include <netinet/in.h>
  412. #include <sys/types.h>
  413. #include <sys/ioctl.h>
  414. #include <sys/socket.h>
  415. #include <linux/if.h>
  416. #include <sys/sysinfo.h>
  417. #include <sys/file.h>
  418. #include <signal.h>
  419. #include <ft2build.h>
  420. #include FT_FREETYPE_H
  421. #include <X11/Xlib.h>
  422. #include <X11/Xatom.h>
  423. #include <X11/Xresource.h>
  424. #include <X11/Xutil.h>
  425. #include <X11/Xmd.h>
  426. #include <X11/keysym.h>
  427. #include <X11/cursorfont.h>
  428. #if JUCE_USE_XINERAMA
  429. #include <X11/extensions/Xinerama.h>
  430. #endif
  431. #if JUCE_USE_XSHM
  432. #include <X11/extensions/XShm.h>
  433. #include <sys/shm.h>
  434. #include <sys/ipc.h>
  435. #endif
  436. #if JUCE_USE_XRENDER
  437. // If you're missing these headers, try installing the libxrender-dev and libxcomposite-dev
  438. #include <X11/extensions/Xrender.h>
  439. #include <X11/extensions/Xcomposite.h>
  440. #endif
  441. #if JUCE_USE_XCURSOR
  442. // If you're missing this header, try installing the libxcursor-dev package
  443. #include <X11/Xcursor/Xcursor.h>
  444. #endif
  445. #if JUCE_OPENGL
  446. #include <GL/glx.h>
  447. #endif
  448. #undef KeyPress
  449. #if JUCE_ALSA
  450. #include <alsa/asoundlib.h>
  451. #endif
  452. #if JUCE_JACK
  453. #include <jack/jack.h>
  454. //#include <jack/transport.h>
  455. #endif
  456. #undef SIZEOF
  457. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  458. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  459. #elif JUCE_MAC || JUCE_IPHONE
  460. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  461. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  462. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  463. #define USE_COREGRAPHICS_RENDERING 1
  464. #if JUCE_IPHONE
  465. #import <Foundation/Foundation.h>
  466. #import <UIKit/UIKit.h>
  467. #import <AudioToolbox/AudioToolbox.h>
  468. #import <AVFoundation/AVFoundation.h>
  469. #import <CoreData/CoreData.h>
  470. #import <MobileCoreServices/MobileCoreServices.h>
  471. #import <QuartzCore/QuartzCore.h>
  472. #include <sys/fcntl.h>
  473. #if JUCE_OPENGL
  474. #include <OpenGLES/ES1/gl.h>
  475. #include <OpenGLES/ES1/glext.h>
  476. #endif
  477. #else
  478. #import <Cocoa/Cocoa.h>
  479. #import <CoreAudio/HostTime.h>
  480. #import <CoreAudio/AudioHardware.h>
  481. #import <CoreMIDI/MIDIServices.h>
  482. #import <QTKit/QTKit.h>
  483. #import <WebKit/WebKit.h>
  484. #import <DiscRecording/DiscRecording.h>
  485. #import <IOKit/IOKitLib.h>
  486. #import <IOKit/IOCFPlugIn.h>
  487. #import <IOKit/hid/IOHIDLib.h>
  488. #import <IOKit/hid/IOHIDKeys.h>
  489. #import <IOKit/pwr_mgt/IOPMLib.h>
  490. #include <Carbon/Carbon.h>
  491. #include <sys/dir.h>
  492. #endif
  493. #include <sys/socket.h>
  494. #include <sys/sysctl.h>
  495. #include <sys/stat.h>
  496. #include <sys/param.h>
  497. #include <sys/mount.h>
  498. #include <fnmatch.h>
  499. #include <utime.h>
  500. #include <dlfcn.h>
  501. #include <ifaddrs.h>
  502. #include <net/if_dl.h>
  503. #include <mach/mach_time.h>
  504. #if MACOS_10_4_OR_EARLIER
  505. #include <GLUT/glut.h>
  506. #endif
  507. #if ! CGFLOAT_DEFINED
  508. #define CGFloat float
  509. #endif
  510. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  511. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  512. #else
  513. #error "Unknown platform!"
  514. #endif
  515. #endif
  516. //==============================================================================
  517. #define DONT_SET_USING_JUCE_NAMESPACE 1
  518. #undef max
  519. #undef min
  520. #define NO_DUMMY_DECL
  521. #if JUCE_BUILD_NATIVE
  522. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  523. #endif
  524. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  525. #pragma warning (disable: 4309 4305)
  526. #endif
  527. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  528. BEGIN_JUCE_NAMESPACE
  529. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  530. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  531. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  532. class CarbonViewWrapperComponent : public Component,
  533. public ComponentMovementWatcher,
  534. public Timer
  535. {
  536. public:
  537. CarbonViewWrapperComponent()
  538. : ComponentMovementWatcher (this),
  539. wrapperWindow (0),
  540. embeddedView (0),
  541. recursiveResize (false)
  542. {
  543. }
  544. virtual ~CarbonViewWrapperComponent()
  545. {
  546. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  547. }
  548. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  549. virtual void removeView (HIViewRef embeddedView) = 0;
  550. virtual void mouseDown (int x, int y) {}
  551. virtual void paint() {}
  552. virtual bool getEmbeddedViewSize (int& w, int& h)
  553. {
  554. if (embeddedView == 0)
  555. return false;
  556. HIRect bounds;
  557. HIViewGetBounds (embeddedView, &bounds);
  558. w = jmax (1, roundToInt (bounds.size.width));
  559. h = jmax (1, roundToInt (bounds.size.height));
  560. return true;
  561. }
  562. void createWindow()
  563. {
  564. if (wrapperWindow == 0)
  565. {
  566. Rect r;
  567. r.left = getScreenX();
  568. r.top = getScreenY();
  569. r.right = r.left + getWidth();
  570. r.bottom = r.top + getHeight();
  571. CreateNewWindow (kDocumentWindowClass,
  572. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  573. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  574. &r, &wrapperWindow);
  575. jassert (wrapperWindow != 0);
  576. if (wrapperWindow == 0)
  577. return;
  578. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  579. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  580. [ownerWindow addChildWindow: carbonWindow
  581. ordered: NSWindowAbove];
  582. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  583. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  584. { kEventClassWindow, kEventWindowHandleDeactivate } };
  585. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  586. InstallWindowEventHandler (wrapperWindow, upp,
  587. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  588. windowEventTypes, this, &eventHandlerRef);
  589. setOurSizeToEmbeddedViewSize();
  590. setEmbeddedWindowToOurSize();
  591. creationTime = Time::getCurrentTime();
  592. }
  593. }
  594. void deleteWindow()
  595. {
  596. removeView (embeddedView);
  597. embeddedView = 0;
  598. if (wrapperWindow != 0)
  599. {
  600. RemoveEventHandler (eventHandlerRef);
  601. DisposeWindow (wrapperWindow);
  602. wrapperWindow = 0;
  603. }
  604. }
  605. void setOurSizeToEmbeddedViewSize()
  606. {
  607. int w, h;
  608. if (getEmbeddedViewSize (w, h))
  609. {
  610. if (w != getWidth() || h != getHeight())
  611. {
  612. startTimer (50);
  613. setSize (w, h);
  614. if (getParentComponent() != 0)
  615. getParentComponent()->setSize (w, h);
  616. }
  617. else
  618. {
  619. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  620. }
  621. }
  622. else
  623. {
  624. stopTimer();
  625. }
  626. }
  627. void setEmbeddedWindowToOurSize()
  628. {
  629. if (! recursiveResize)
  630. {
  631. recursiveResize = true;
  632. if (embeddedView != 0)
  633. {
  634. HIRect r;
  635. r.origin.x = 0;
  636. r.origin.y = 0;
  637. r.size.width = (float) getWidth();
  638. r.size.height = (float) getHeight();
  639. HIViewSetFrame (embeddedView, &r);
  640. }
  641. if (wrapperWindow != 0)
  642. {
  643. Rect wr;
  644. wr.left = getScreenX();
  645. wr.top = getScreenY();
  646. wr.right = wr.left + getWidth();
  647. wr.bottom = wr.top + getHeight();
  648. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  649. ShowWindow (wrapperWindow);
  650. }
  651. recursiveResize = false;
  652. }
  653. }
  654. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  655. {
  656. setEmbeddedWindowToOurSize();
  657. }
  658. void componentPeerChanged()
  659. {
  660. deleteWindow();
  661. createWindow();
  662. }
  663. void componentVisibilityChanged (Component&)
  664. {
  665. if (isShowing())
  666. createWindow();
  667. else
  668. deleteWindow();
  669. setEmbeddedWindowToOurSize();
  670. }
  671. static void recursiveHIViewRepaint (HIViewRef view)
  672. {
  673. HIViewSetNeedsDisplay (view, true);
  674. HIViewRef child = HIViewGetFirstSubview (view);
  675. while (child != 0)
  676. {
  677. recursiveHIViewRepaint (child);
  678. child = HIViewGetNextView (child);
  679. }
  680. }
  681. void timerCallback()
  682. {
  683. setOurSizeToEmbeddedViewSize();
  684. // To avoid strange overpainting problems when the UI is first opened, we'll
  685. // repaint it a few times during the first second that it's on-screen..
  686. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  687. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  688. }
  689. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  690. EventRef event)
  691. {
  692. switch (GetEventKind (event))
  693. {
  694. case kEventWindowHandleDeactivate:
  695. ActivateWindow (wrapperWindow, TRUE);
  696. break;
  697. case kEventWindowGetClickActivation:
  698. {
  699. getTopLevelComponent()->toFront (false);
  700. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  701. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  702. sizeof (ClickActivationResult), &howToHandleClick);
  703. HIViewSetNeedsDisplay (embeddedView, true);
  704. }
  705. break;
  706. }
  707. return noErr;
  708. }
  709. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  710. EventRef event, void* userData)
  711. {
  712. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  713. }
  714. protected:
  715. WindowRef wrapperWindow;
  716. HIViewRef embeddedView;
  717. bool recursiveResize;
  718. Time creationTime;
  719. EventHandlerRef eventHandlerRef;
  720. };
  721. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  722. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  723. END_JUCE_NAMESPACE
  724. #endif
  725. #define JUCE_AMALGAMATED_TEMPLATE 1
  726. //==============================================================================
  727. #if JUCE_BUILD_CORE
  728. /*** Start of inlined file: juce_FileLogger.cpp ***/
  729. BEGIN_JUCE_NAMESPACE
  730. FileLogger::FileLogger (const File& logFile_,
  731. const String& welcomeMessage,
  732. const int maxInitialFileSizeBytes)
  733. : logFile (logFile_)
  734. {
  735. if (maxInitialFileSizeBytes >= 0)
  736. trimFileSize (maxInitialFileSizeBytes);
  737. if (! logFile_.exists())
  738. {
  739. // do this so that the parent directories get created..
  740. logFile_.create();
  741. }
  742. logStream = logFile_.createOutputStream (256);
  743. jassert (logStream != 0);
  744. String welcome;
  745. welcome << "\r\n**********************************************************\r\n"
  746. << welcomeMessage
  747. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  748. << "\r\n";
  749. logMessage (welcome);
  750. }
  751. FileLogger::~FileLogger()
  752. {
  753. }
  754. void FileLogger::logMessage (const String& message)
  755. {
  756. if (logStream != 0)
  757. {
  758. DBG (message);
  759. const ScopedLock sl (logLock);
  760. (*logStream) << message << "\r\n";
  761. logStream->flush();
  762. }
  763. }
  764. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  765. {
  766. if (maxFileSizeBytes <= 0)
  767. {
  768. logFile.deleteFile();
  769. }
  770. else
  771. {
  772. const int64 fileSize = logFile.getSize();
  773. if (fileSize > maxFileSizeBytes)
  774. {
  775. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  776. jassert (in != 0);
  777. if (in != 0)
  778. {
  779. in->setPosition (fileSize - maxFileSizeBytes);
  780. String content;
  781. {
  782. MemoryBlock contentToSave;
  783. contentToSave.setSize (maxFileSizeBytes + 4);
  784. contentToSave.fillWith (0);
  785. in->read (contentToSave.getData(), maxFileSizeBytes);
  786. in = 0;
  787. content = contentToSave.toString();
  788. }
  789. int newStart = 0;
  790. while (newStart < fileSize
  791. && content[newStart] != '\n'
  792. && content[newStart] != '\r')
  793. ++newStart;
  794. logFile.deleteFile();
  795. logFile.appendText (content.substring (newStart), false, false);
  796. }
  797. }
  798. }
  799. }
  800. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  801. const String& logFileName,
  802. const String& welcomeMessage,
  803. const int maxInitialFileSizeBytes)
  804. {
  805. #if JUCE_MAC
  806. File logFile ("~/Library/Logs");
  807. logFile = logFile.getChildFile (logFileSubDirectoryName)
  808. .getChildFile (logFileName);
  809. #else
  810. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  811. if (logFile.isDirectory())
  812. {
  813. logFile = logFile.getChildFile (logFileSubDirectoryName)
  814. .getChildFile (logFileName);
  815. }
  816. #endif
  817. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  818. }
  819. END_JUCE_NAMESPACE
  820. /*** End of inlined file: juce_FileLogger.cpp ***/
  821. /*** Start of inlined file: juce_Logger.cpp ***/
  822. BEGIN_JUCE_NAMESPACE
  823. Logger::Logger()
  824. {
  825. }
  826. Logger::~Logger()
  827. {
  828. }
  829. static Logger* currentLogger = 0;
  830. void Logger::setCurrentLogger (Logger* const newLogger,
  831. const bool deleteOldLogger)
  832. {
  833. Logger* const oldLogger = currentLogger;
  834. currentLogger = newLogger;
  835. if (deleteOldLogger)
  836. delete oldLogger;
  837. }
  838. void Logger::writeToLog (const String& message)
  839. {
  840. if (currentLogger != 0)
  841. currentLogger->logMessage (message);
  842. else
  843. outputDebugString (message);
  844. }
  845. #if JUCE_LOG_ASSERTIONS
  846. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  847. {
  848. String m ("JUCE Assertion failure in ");
  849. m << filename << ", line " << lineNum;
  850. Logger::writeToLog (m);
  851. }
  852. #endif
  853. END_JUCE_NAMESPACE
  854. /*** End of inlined file: juce_Logger.cpp ***/
  855. /*** Start of inlined file: juce_Random.cpp ***/
  856. BEGIN_JUCE_NAMESPACE
  857. Random::Random (const int64 seedValue) throw()
  858. : seed (seedValue)
  859. {
  860. }
  861. Random::~Random() throw()
  862. {
  863. }
  864. void Random::setSeed (const int64 newSeed) throw()
  865. {
  866. seed = newSeed;
  867. }
  868. void Random::combineSeed (const int64 seedValue) throw()
  869. {
  870. seed ^= nextInt64() ^ seedValue;
  871. }
  872. void Random::setSeedRandomly()
  873. {
  874. combineSeed ((int64) (pointer_sized_int) this);
  875. combineSeed (Time::getMillisecondCounter());
  876. combineSeed (Time::getHighResolutionTicks());
  877. combineSeed (Time::getHighResolutionTicksPerSecond());
  878. combineSeed (Time::currentTimeMillis());
  879. }
  880. int Random::nextInt() throw()
  881. {
  882. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  883. return (int) (seed >> 16);
  884. }
  885. int Random::nextInt (const int maxValue) throw()
  886. {
  887. jassert (maxValue > 0);
  888. return (nextInt() & 0x7fffffff) % maxValue;
  889. }
  890. int64 Random::nextInt64() throw()
  891. {
  892. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  893. }
  894. bool Random::nextBool() throw()
  895. {
  896. return (nextInt() & 0x80000000) != 0;
  897. }
  898. float Random::nextFloat() throw()
  899. {
  900. return static_cast <uint32> (nextInt()) / (float) 0xffffffff;
  901. }
  902. double Random::nextDouble() throw()
  903. {
  904. return static_cast <uint32> (nextInt()) / (double) 0xffffffff;
  905. }
  906. const BigInteger Random::nextLargeNumber (const BigInteger& maximumValue)
  907. {
  908. BigInteger n;
  909. do
  910. {
  911. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  912. }
  913. while (n >= maximumValue);
  914. return n;
  915. }
  916. void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits)
  917. {
  918. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  919. while ((startBit & 31) != 0 && numBits > 0)
  920. {
  921. arrayToChange.setBit (startBit++, nextBool());
  922. --numBits;
  923. }
  924. while (numBits >= 32)
  925. {
  926. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  927. startBit += 32;
  928. numBits -= 32;
  929. }
  930. while (--numBits >= 0)
  931. arrayToChange.setBit (startBit + numBits, nextBool());
  932. }
  933. Random& Random::getSystemRandom() throw()
  934. {
  935. static Random sysRand (1);
  936. return sysRand;
  937. }
  938. END_JUCE_NAMESPACE
  939. /*** End of inlined file: juce_Random.cpp ***/
  940. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  941. BEGIN_JUCE_NAMESPACE
  942. RelativeTime::RelativeTime (const double seconds_) throw()
  943. : seconds (seconds_)
  944. {
  945. }
  946. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  947. : seconds (other.seconds)
  948. {
  949. }
  950. RelativeTime::~RelativeTime() throw()
  951. {
  952. }
  953. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  954. {
  955. return RelativeTime (milliseconds * 0.001);
  956. }
  957. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  958. {
  959. return RelativeTime (milliseconds * 0.001);
  960. }
  961. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  962. {
  963. return RelativeTime (numberOfMinutes * 60.0);
  964. }
  965. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  966. {
  967. return RelativeTime (numberOfHours * (60.0 * 60.0));
  968. }
  969. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  970. {
  971. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  972. }
  973. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  974. {
  975. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  976. }
  977. int64 RelativeTime::inMilliseconds() const throw()
  978. {
  979. return (int64)(seconds * 1000.0);
  980. }
  981. double RelativeTime::inMinutes() const throw()
  982. {
  983. return seconds / 60.0;
  984. }
  985. double RelativeTime::inHours() const throw()
  986. {
  987. return seconds / (60.0 * 60.0);
  988. }
  989. double RelativeTime::inDays() const throw()
  990. {
  991. return seconds / (60.0 * 60.0 * 24.0);
  992. }
  993. double RelativeTime::inWeeks() const throw()
  994. {
  995. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  996. }
  997. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  998. {
  999. if (seconds < 0.001 && seconds > -0.001)
  1000. return returnValueForZeroTime;
  1001. String result;
  1002. if (seconds < 0)
  1003. result = "-";
  1004. int fieldsShown = 0;
  1005. int n = abs ((int) inWeeks());
  1006. if (n > 0)
  1007. {
  1008. result << n << ((n == 1) ? TRANS(" week ")
  1009. : TRANS(" weeks "));
  1010. ++fieldsShown;
  1011. }
  1012. n = abs ((int) inDays()) % 7;
  1013. if (n > 0)
  1014. {
  1015. result << n << ((n == 1) ? TRANS(" day ")
  1016. : TRANS(" days "));
  1017. ++fieldsShown;
  1018. }
  1019. if (fieldsShown < 2)
  1020. {
  1021. n = abs ((int) inHours()) % 24;
  1022. if (n > 0)
  1023. {
  1024. result << n << ((n == 1) ? TRANS(" hr ")
  1025. : TRANS(" hrs "));
  1026. ++fieldsShown;
  1027. }
  1028. if (fieldsShown < 2)
  1029. {
  1030. n = abs ((int) inMinutes()) % 60;
  1031. if (n > 0)
  1032. {
  1033. result << n << ((n == 1) ? TRANS(" min ")
  1034. : TRANS(" mins "));
  1035. ++fieldsShown;
  1036. }
  1037. if (fieldsShown < 2)
  1038. {
  1039. n = abs ((int) inSeconds()) % 60;
  1040. if (n > 0)
  1041. {
  1042. result << n << ((n == 1) ? TRANS(" sec ")
  1043. : TRANS(" secs "));
  1044. ++fieldsShown;
  1045. }
  1046. if (fieldsShown < 1)
  1047. {
  1048. n = abs ((int) inMilliseconds()) % 1000;
  1049. if (n > 0)
  1050. {
  1051. result << n << TRANS(" ms");
  1052. ++fieldsShown;
  1053. }
  1054. }
  1055. }
  1056. }
  1057. }
  1058. return result.trimEnd();
  1059. }
  1060. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1061. {
  1062. seconds = other.seconds;
  1063. return *this;
  1064. }
  1065. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1066. {
  1067. return seconds == other.seconds;
  1068. }
  1069. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1070. {
  1071. return seconds != other.seconds;
  1072. }
  1073. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1074. {
  1075. return seconds > other.seconds;
  1076. }
  1077. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1078. {
  1079. return seconds < other.seconds;
  1080. }
  1081. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1082. {
  1083. return seconds >= other.seconds;
  1084. }
  1085. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1086. {
  1087. return seconds <= other.seconds;
  1088. }
  1089. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1090. {
  1091. return RelativeTime (seconds + timeToAdd.seconds);
  1092. }
  1093. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1094. {
  1095. return RelativeTime (seconds - timeToSubtract.seconds);
  1096. }
  1097. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1098. {
  1099. return RelativeTime (seconds + secondsToAdd);
  1100. }
  1101. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1102. {
  1103. return RelativeTime (seconds - secondsToSubtract);
  1104. }
  1105. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1106. {
  1107. seconds += timeToAdd.seconds;
  1108. return *this;
  1109. }
  1110. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1111. {
  1112. seconds -= timeToSubtract.seconds;
  1113. return *this;
  1114. }
  1115. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1116. {
  1117. seconds += secondsToAdd;
  1118. return *this;
  1119. }
  1120. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1121. {
  1122. seconds -= secondsToSubtract;
  1123. return *this;
  1124. }
  1125. END_JUCE_NAMESPACE
  1126. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1127. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1128. BEGIN_JUCE_NAMESPACE
  1129. const String SystemStats::getJUCEVersion() throw()
  1130. {
  1131. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1132. + "." + String (JUCE_MINOR_VERSION)
  1133. + "." + String (JUCE_BUILDNUMBER);
  1134. }
  1135. const StringArray SystemStats::getMACAddressStrings()
  1136. {
  1137. int64 macAddresses [16];
  1138. const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);
  1139. StringArray s;
  1140. for (int i = 0; i < numAddresses; ++i)
  1141. {
  1142. s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
  1143. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
  1144. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
  1145. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
  1146. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
  1147. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
  1148. }
  1149. return s;
  1150. }
  1151. static bool juceInitialisedNonGUI = false;
  1152. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1153. {
  1154. if (! juceInitialisedNonGUI)
  1155. {
  1156. #if JUCE_MAC || JUCE_IPHONE
  1157. const ScopedAutoReleasePool pool;
  1158. #endif
  1159. #ifdef JUCE_DEBUG
  1160. {
  1161. // Some simple test code to keep an eye on things and make sure these functions
  1162. // work ok on all platforms. Let me know if any of these assertions fail!
  1163. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1164. static_jassert (sizeof (int8) == 1);
  1165. static_jassert (sizeof (uint8) == 1);
  1166. static_jassert (sizeof (int16) == 2);
  1167. static_jassert (sizeof (uint16) == 2);
  1168. static_jassert (sizeof (int32) == 4);
  1169. static_jassert (sizeof (uint32) == 4);
  1170. static_jassert (sizeof (int64) == 8);
  1171. static_jassert (sizeof (uint64) == 8);
  1172. char a1[7];
  1173. jassert (numElementsInArray(a1) == 7);
  1174. int a2[3];
  1175. jassert (numElementsInArray(a2) == 3);
  1176. int n = 1;
  1177. Atomic::increment (n);
  1178. jassert (Atomic::incrementAndReturn (n) == 3);
  1179. Atomic::decrement (n);
  1180. jassert (Atomic::decrementAndReturn (n) == 1);
  1181. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1182. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1183. // Some quick stream tests..
  1184. int randomInt = Random::getSystemRandom().nextInt();
  1185. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1186. double randomDouble = Random::getSystemRandom().nextDouble();
  1187. String randomString;
  1188. for (int i = 50; --i >= 0;)
  1189. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1190. MemoryOutputStream mo;
  1191. mo.writeInt (randomInt);
  1192. mo.writeIntBigEndian (randomInt);
  1193. mo.writeCompressedInt (randomInt);
  1194. mo.writeString (randomString);
  1195. mo.writeInt64 (randomInt64);
  1196. mo.writeInt64BigEndian (randomInt64);
  1197. mo.writeDouble (randomDouble);
  1198. mo.writeDoubleBigEndian (randomDouble);
  1199. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1200. jassert (mi.readInt() == randomInt);
  1201. jassert (mi.readIntBigEndian() == randomInt);
  1202. jassert (mi.readCompressedInt() == randomInt);
  1203. jassert (mi.readString() == randomString);
  1204. jassert (mi.readInt64() == randomInt64);
  1205. jassert (mi.readInt64BigEndian() == randomInt64);
  1206. jassert (mi.readDouble() == randomDouble);
  1207. jassert (mi.readDoubleBigEndian() == randomDouble);
  1208. }
  1209. #endif
  1210. // Now the real initialisation..
  1211. juceInitialisedNonGUI = true;
  1212. DBG (SystemStats::getJUCEVersion());
  1213. SystemStats::initialiseStats();
  1214. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1215. }
  1216. }
  1217. #if JUCE_WINDOWS
  1218. // This is imported from the sockets code..
  1219. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1220. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1221. #endif
  1222. #if JUCE_DEBUG
  1223. extern void juce_CheckForDanglingStreams();
  1224. #endif
  1225. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1226. {
  1227. if (juceInitialisedNonGUI)
  1228. {
  1229. #if JUCE_MAC || JUCE_IPHONE
  1230. const ScopedAutoReleasePool pool;
  1231. #endif
  1232. #if JUCE_WINDOWS
  1233. // need to shut down sockets if they were used..
  1234. if (juce_CloseWin32SocketLib != 0)
  1235. (*juce_CloseWin32SocketLib)();
  1236. #endif
  1237. LocalisedStrings::setCurrentMappings (0);
  1238. Thread::stopAllThreads (3000);
  1239. #if JUCE_DEBUG
  1240. juce_CheckForDanglingStreams();
  1241. #endif
  1242. juceInitialisedNonGUI = false;
  1243. }
  1244. }
  1245. #ifdef JUCE_DLL
  1246. void* juce_Malloc (const int size)
  1247. {
  1248. return malloc (size);
  1249. }
  1250. void* juce_Calloc (const int size)
  1251. {
  1252. return calloc (1, size);
  1253. }
  1254. void* juce_Realloc (void* const block, const int size)
  1255. {
  1256. return realloc (block, size);
  1257. }
  1258. void juce_Free (void* const block)
  1259. {
  1260. free (block);
  1261. }
  1262. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1263. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1264. {
  1265. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1266. }
  1267. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1268. {
  1269. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1270. }
  1271. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1272. {
  1273. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1274. }
  1275. void juce_DebugFree (void* const block)
  1276. {
  1277. _free_dbg (block, _NORMAL_BLOCK);
  1278. }
  1279. #endif
  1280. #endif
  1281. END_JUCE_NAMESPACE
  1282. /*** End of inlined file: juce_SystemStats.cpp ***/
  1283. /*** Start of inlined file: juce_Time.cpp ***/
  1284. #ifdef _MSC_VER
  1285. #pragma warning (disable: 4514)
  1286. #pragma warning (push)
  1287. #endif
  1288. #ifndef JUCE_WINDOWS
  1289. #include <sys/time.h>
  1290. #else
  1291. #include <ctime>
  1292. #endif
  1293. #include <sys/timeb.h>
  1294. BEGIN_JUCE_NAMESPACE
  1295. #ifdef _MSC_VER
  1296. #pragma warning (pop)
  1297. #ifdef _INC_TIME_INL
  1298. #define USE_NEW_SECURE_TIME_FNS
  1299. #endif
  1300. #endif
  1301. namespace TimeHelpers
  1302. {
  1303. static struct tm millisToLocal (const int64 millis) throw()
  1304. {
  1305. struct tm result;
  1306. const int64 seconds = millis / 1000;
  1307. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1308. {
  1309. // use extended maths for dates beyond 1970 to 2037..
  1310. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1311. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1312. const int days = (int) (jdm / literal64bit (86400));
  1313. const int a = 32044 + days;
  1314. const int b = (4 * a + 3) / 146097;
  1315. const int c = a - (b * 146097) / 4;
  1316. const int d = (4 * c + 3) / 1461;
  1317. const int e = c - (d * 1461) / 4;
  1318. const int m = (5 * e + 2) / 153;
  1319. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1320. result.tm_mon = m + 2 - 12 * (m / 10);
  1321. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1322. result.tm_wday = (days + 1) % 7;
  1323. result.tm_yday = -1;
  1324. int t = (int) (jdm % literal64bit (86400));
  1325. result.tm_hour = t / 3600;
  1326. t %= 3600;
  1327. result.tm_min = t / 60;
  1328. result.tm_sec = t % 60;
  1329. result.tm_isdst = -1;
  1330. }
  1331. else
  1332. {
  1333. time_t now = static_cast <time_t> (seconds);
  1334. #if JUCE_WINDOWS
  1335. #ifdef USE_NEW_SECURE_TIME_FNS
  1336. if (now >= 0 && now <= 0x793406fff)
  1337. localtime_s (&result, &now);
  1338. else
  1339. zeromem (&result, sizeof (result));
  1340. #else
  1341. result = *localtime (&now);
  1342. #endif
  1343. #else
  1344. // more thread-safe
  1345. localtime_r (&now, &result);
  1346. #endif
  1347. }
  1348. return result;
  1349. }
  1350. static int extendedModulo (const int64 value, const int modulo) throw()
  1351. {
  1352. return (int) (value >= 0 ? (value % modulo)
  1353. : (value - ((value / modulo) + 1) * modulo));
  1354. }
  1355. static uint32 lastMSCounterValue = 0;
  1356. }
  1357. Time::Time() throw()
  1358. : millisSinceEpoch (0)
  1359. {
  1360. }
  1361. Time::Time (const Time& other) throw()
  1362. : millisSinceEpoch (other.millisSinceEpoch)
  1363. {
  1364. }
  1365. Time::Time (const int64 ms) throw()
  1366. : millisSinceEpoch (ms)
  1367. {
  1368. }
  1369. Time::Time (const int year,
  1370. const int month,
  1371. const int day,
  1372. const int hours,
  1373. const int minutes,
  1374. const int seconds,
  1375. const int milliseconds,
  1376. const bool useLocalTime) throw()
  1377. {
  1378. jassert (year > 100); // year must be a 4-digit version
  1379. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1380. {
  1381. // use extended maths for dates beyond 1970 to 2037..
  1382. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1383. : 0;
  1384. const int a = (13 - month) / 12;
  1385. const int y = year + 4800 - a;
  1386. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1387. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1388. - 32045;
  1389. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1390. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1391. + milliseconds;
  1392. }
  1393. else
  1394. {
  1395. struct tm t;
  1396. t.tm_year = year - 1900;
  1397. t.tm_mon = month;
  1398. t.tm_mday = day;
  1399. t.tm_hour = hours;
  1400. t.tm_min = minutes;
  1401. t.tm_sec = seconds;
  1402. t.tm_isdst = -1;
  1403. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1404. if (millisSinceEpoch < 0)
  1405. millisSinceEpoch = 0;
  1406. else
  1407. millisSinceEpoch += milliseconds;
  1408. }
  1409. }
  1410. Time::~Time() throw()
  1411. {
  1412. }
  1413. Time& Time::operator= (const Time& other) throw()
  1414. {
  1415. millisSinceEpoch = other.millisSinceEpoch;
  1416. return *this;
  1417. }
  1418. int64 Time::currentTimeMillis() throw()
  1419. {
  1420. static uint32 lastCounterResult = 0xffffffff;
  1421. static int64 correction = 0;
  1422. const uint32 now = getMillisecondCounter();
  1423. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1424. if (now < lastCounterResult)
  1425. {
  1426. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1427. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1428. {
  1429. // get the time once using normal library calls, and store the difference needed to
  1430. // turn the millisecond counter into a real time.
  1431. #if JUCE_WINDOWS
  1432. struct _timeb t;
  1433. #ifdef USE_NEW_SECURE_TIME_FNS
  1434. _ftime_s (&t);
  1435. #else
  1436. _ftime (&t);
  1437. #endif
  1438. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1439. #else
  1440. struct timeval tv;
  1441. struct timezone tz;
  1442. gettimeofday (&tv, &tz);
  1443. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1444. #endif
  1445. }
  1446. }
  1447. lastCounterResult = now;
  1448. return correction + now;
  1449. }
  1450. uint32 juce_millisecondsSinceStartup() throw();
  1451. uint32 Time::getMillisecondCounter() throw()
  1452. {
  1453. const uint32 now = juce_millisecondsSinceStartup();
  1454. if (now < TimeHelpers::lastMSCounterValue)
  1455. {
  1456. // in multi-threaded apps this might be called concurrently, so
  1457. // make sure that our last counter value only increases and doesn't
  1458. // go backwards..
  1459. if (now < TimeHelpers::lastMSCounterValue - 1000)
  1460. TimeHelpers::lastMSCounterValue = now;
  1461. }
  1462. else
  1463. {
  1464. TimeHelpers::lastMSCounterValue = now;
  1465. }
  1466. return now;
  1467. }
  1468. uint32 Time::getApproximateMillisecondCounter() throw()
  1469. {
  1470. jassert (TimeHelpers::lastMSCounterValue != 0);
  1471. return TimeHelpers::lastMSCounterValue;
  1472. }
  1473. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1474. {
  1475. for (;;)
  1476. {
  1477. const uint32 now = getMillisecondCounter();
  1478. if (now >= targetTime)
  1479. break;
  1480. const int toWait = targetTime - now;
  1481. if (toWait > 2)
  1482. {
  1483. Thread::sleep (jmin (20, toWait >> 1));
  1484. }
  1485. else
  1486. {
  1487. // xxx should consider using mutex_pause on the mac as it apparently
  1488. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1489. for (int i = 10; --i >= 0;)
  1490. Thread::yield();
  1491. }
  1492. }
  1493. }
  1494. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1495. {
  1496. return ticks / (double) getHighResolutionTicksPerSecond();
  1497. }
  1498. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1499. {
  1500. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1501. }
  1502. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1503. {
  1504. return Time (currentTimeMillis());
  1505. }
  1506. const String Time::toString (const bool includeDate,
  1507. const bool includeTime,
  1508. const bool includeSeconds,
  1509. const bool use24HourClock) const throw()
  1510. {
  1511. String result;
  1512. if (includeDate)
  1513. {
  1514. result << getDayOfMonth() << ' '
  1515. << getMonthName (true) << ' '
  1516. << getYear();
  1517. if (includeTime)
  1518. result << ' ';
  1519. }
  1520. if (includeTime)
  1521. {
  1522. const int mins = getMinutes();
  1523. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1524. << (mins < 10 ? ":0" : ":") << mins;
  1525. if (includeSeconds)
  1526. {
  1527. const int secs = getSeconds();
  1528. result << (secs < 10 ? ":0" : ":") << secs;
  1529. }
  1530. if (! use24HourClock)
  1531. result << (isAfternoon() ? "pm" : "am");
  1532. }
  1533. return result.trimEnd();
  1534. }
  1535. const String Time::formatted (const String& format) const throw()
  1536. {
  1537. String buffer;
  1538. int bufferSize = 128;
  1539. buffer.preallocateStorage (bufferSize);
  1540. struct tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  1541. while (CharacterFunctions::ftime (static_cast <juce_wchar*> (buffer), bufferSize, format, &t) <= 0)
  1542. {
  1543. bufferSize += 128;
  1544. buffer.preallocateStorage (bufferSize);
  1545. }
  1546. return buffer;
  1547. }
  1548. int Time::getYear() const throw()
  1549. {
  1550. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900;
  1551. }
  1552. int Time::getMonth() const throw()
  1553. {
  1554. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon;
  1555. }
  1556. int Time::getDayOfMonth() const throw()
  1557. {
  1558. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday;
  1559. }
  1560. int Time::getDayOfWeek() const throw()
  1561. {
  1562. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday;
  1563. }
  1564. int Time::getHours() const throw()
  1565. {
  1566. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour;
  1567. }
  1568. int Time::getHoursInAmPmFormat() const throw()
  1569. {
  1570. const int hours = getHours();
  1571. if (hours == 0)
  1572. return 12;
  1573. else if (hours <= 12)
  1574. return hours;
  1575. else
  1576. return hours - 12;
  1577. }
  1578. bool Time::isAfternoon() const throw()
  1579. {
  1580. return getHours() >= 12;
  1581. }
  1582. int Time::getMinutes() const throw()
  1583. {
  1584. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min;
  1585. }
  1586. int Time::getSeconds() const throw()
  1587. {
  1588. return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60);
  1589. }
  1590. int Time::getMilliseconds() const throw()
  1591. {
  1592. return TimeHelpers::extendedModulo (millisSinceEpoch, 1000);
  1593. }
  1594. bool Time::isDaylightSavingTime() const throw()
  1595. {
  1596. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  1597. }
  1598. const String Time::getTimeZone() const throw()
  1599. {
  1600. String zone[2];
  1601. #if JUCE_WINDOWS
  1602. _tzset();
  1603. #ifdef USE_NEW_SECURE_TIME_FNS
  1604. {
  1605. char name [128];
  1606. size_t length;
  1607. for (int i = 0; i < 2; ++i)
  1608. {
  1609. zeromem (name, sizeof (name));
  1610. _get_tzname (&length, name, 127, i);
  1611. zone[i] = name;
  1612. }
  1613. }
  1614. #else
  1615. const char** const zonePtr = (const char**) _tzname;
  1616. zone[0] = zonePtr[0];
  1617. zone[1] = zonePtr[1];
  1618. #endif
  1619. #else
  1620. tzset();
  1621. const char** const zonePtr = (const char**) tzname;
  1622. zone[0] = zonePtr[0];
  1623. zone[1] = zonePtr[1];
  1624. #endif
  1625. if (isDaylightSavingTime())
  1626. {
  1627. zone[0] = zone[1];
  1628. if (zone[0].length() > 3
  1629. && zone[0].containsIgnoreCase ("daylight")
  1630. && zone[0].contains ("GMT"))
  1631. zone[0] = "BST";
  1632. }
  1633. return zone[0].substring (0, 3);
  1634. }
  1635. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1636. {
  1637. return getMonthName (getMonth(), threeLetterVersion);
  1638. }
  1639. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1640. {
  1641. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1642. }
  1643. const String Time::getMonthName (int monthNumber, const bool threeLetterVersion) throw()
  1644. {
  1645. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1646. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1647. monthNumber %= 12;
  1648. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1649. : longMonthNames [monthNumber]);
  1650. }
  1651. const String Time::getWeekdayName (int day, const bool threeLetterVersion) throw()
  1652. {
  1653. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1654. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1655. day %= 7;
  1656. return TRANS (threeLetterVersion ? shortDayNames [day]
  1657. : longDayNames [day]);
  1658. }
  1659. END_JUCE_NAMESPACE
  1660. /*** End of inlined file: juce_Time.cpp ***/
  1661. /*** Start of inlined file: juce_BitArray.cpp ***/
  1662. BEGIN_JUCE_NAMESPACE
  1663. BigInteger::BigInteger()
  1664. : numValues (4),
  1665. highestBit (-1),
  1666. negative (false)
  1667. {
  1668. values.calloc (numValues + 1);
  1669. }
  1670. BigInteger::BigInteger (const int value)
  1671. : numValues (4),
  1672. highestBit (31),
  1673. negative (value < 0)
  1674. {
  1675. values.calloc (numValues + 1);
  1676. values[0] = abs (value);
  1677. highestBit = getHighestBit();
  1678. }
  1679. BigInteger::BigInteger (int64 value)
  1680. : numValues (4),
  1681. highestBit (63),
  1682. negative (value < 0)
  1683. {
  1684. values.calloc (numValues + 1);
  1685. if (value < 0)
  1686. value = -value;
  1687. values[0] = (unsigned int) value;
  1688. values[1] = (unsigned int) (value >> 32);
  1689. highestBit = getHighestBit();
  1690. }
  1691. BigInteger::BigInteger (const unsigned int value)
  1692. : numValues (4),
  1693. highestBit (31),
  1694. negative (false)
  1695. {
  1696. values.calloc (numValues + 1);
  1697. values[0] = value;
  1698. highestBit = getHighestBit();
  1699. }
  1700. BigInteger::BigInteger (const BigInteger& other)
  1701. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1702. highestBit (other.getHighestBit()),
  1703. negative (other.negative)
  1704. {
  1705. values.malloc (numValues + 1);
  1706. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1707. }
  1708. BigInteger::~BigInteger()
  1709. {
  1710. }
  1711. void BigInteger::swapWith (BigInteger& other) throw()
  1712. {
  1713. values.swapWith (other.values);
  1714. swapVariables (numValues, other.numValues);
  1715. swapVariables (highestBit, other.highestBit);
  1716. swapVariables (negative, other.negative);
  1717. }
  1718. BigInteger& BigInteger::operator= (const BigInteger& other)
  1719. {
  1720. if (this != &other)
  1721. {
  1722. highestBit = other.getHighestBit();
  1723. numValues = jmax (4, (highestBit >> 5) + 1);
  1724. negative = other.negative;
  1725. values.malloc (numValues + 1);
  1726. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1727. }
  1728. return *this;
  1729. }
  1730. void BigInteger::ensureSize (const int numVals)
  1731. {
  1732. if (numVals + 2 >= numValues)
  1733. {
  1734. int oldSize = numValues;
  1735. numValues = ((numVals + 2) * 3) / 2;
  1736. values.realloc (numValues + 1);
  1737. while (oldSize < numValues)
  1738. values [oldSize++] = 0;
  1739. }
  1740. }
  1741. bool BigInteger::operator[] (const int bit) const throw()
  1742. {
  1743. return bit <= highestBit && bit >= 0
  1744. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1745. }
  1746. int BigInteger::toInteger() const throw()
  1747. {
  1748. const int n = (int) (values[0] & 0x7fffffff);
  1749. return negative ? -n : n;
  1750. }
  1751. const BigInteger BigInteger::getBitRange (int startBit, int numBits) const
  1752. {
  1753. BigInteger r;
  1754. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  1755. r.ensureSize (numBits >> 5);
  1756. r.highestBit = numBits;
  1757. int i = 0;
  1758. while (numBits > 0)
  1759. {
  1760. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  1761. numBits -= 32;
  1762. startBit += 32;
  1763. }
  1764. r.highestBit = r.getHighestBit();
  1765. return r;
  1766. }
  1767. int BigInteger::getBitRangeAsInt (const int startBit, int numBits) const throw()
  1768. {
  1769. if (numBits > 32)
  1770. {
  1771. jassertfalse // use getBitRange() if you need more than 32 bits..
  1772. numBits = 32;
  1773. }
  1774. numBits = jmin (numBits, highestBit + 1 - startBit);
  1775. if (numBits <= 0)
  1776. return 0;
  1777. const int pos = startBit >> 5;
  1778. const int offset = startBit & 31;
  1779. const int endSpace = 32 - numBits;
  1780. uint32 n = ((uint32) values [pos]) >> offset;
  1781. if (offset > endSpace)
  1782. n |= ((uint32) values [pos + 1]) << (32 - offset);
  1783. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  1784. }
  1785. void BigInteger::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet)
  1786. {
  1787. if (numBits > 32)
  1788. {
  1789. jassertfalse
  1790. numBits = 32;
  1791. }
  1792. for (int i = 0; i < numBits; ++i)
  1793. {
  1794. setBit (startBit + i, (valueToSet & 1) != 0);
  1795. valueToSet >>= 1;
  1796. }
  1797. }
  1798. void BigInteger::clear()
  1799. {
  1800. if (numValues > 16)
  1801. {
  1802. numValues = 4;
  1803. values.calloc (numValues + 1);
  1804. }
  1805. else
  1806. {
  1807. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1808. }
  1809. highestBit = -1;
  1810. negative = false;
  1811. }
  1812. void BigInteger::setBit (const int bit)
  1813. {
  1814. if (bit >= 0)
  1815. {
  1816. if (bit > highestBit)
  1817. {
  1818. ensureSize (bit >> 5);
  1819. highestBit = bit;
  1820. }
  1821. values [bit >> 5] |= (1 << (bit & 31));
  1822. }
  1823. }
  1824. void BigInteger::setBit (const int bit, const bool shouldBeSet)
  1825. {
  1826. if (shouldBeSet)
  1827. setBit (bit);
  1828. else
  1829. clearBit (bit);
  1830. }
  1831. void BigInteger::clearBit (const int bit) throw()
  1832. {
  1833. if (bit >= 0 && bit <= highestBit)
  1834. values [bit >> 5] &= ~(1 << (bit & 31));
  1835. }
  1836. void BigInteger::setRange (int startBit, int numBits, const bool shouldBeSet)
  1837. {
  1838. while (--numBits >= 0)
  1839. setBit (startBit++, shouldBeSet);
  1840. }
  1841. void BigInteger::insertBit (const int bit, const bool shouldBeSet)
  1842. {
  1843. if (bit >= 0)
  1844. shiftBits (1, bit);
  1845. setBit (bit, shouldBeSet);
  1846. }
  1847. bool BigInteger::isZero() const throw()
  1848. {
  1849. return getHighestBit() < 0;
  1850. }
  1851. bool BigInteger::isOne() const throw()
  1852. {
  1853. return getHighestBit() == 0 && ! negative;
  1854. }
  1855. bool BigInteger::isNegative() const throw()
  1856. {
  1857. return negative && ! isZero();
  1858. }
  1859. void BigInteger::setNegative (const bool neg) throw()
  1860. {
  1861. negative = neg;
  1862. }
  1863. void BigInteger::negate() throw()
  1864. {
  1865. negative = (! negative) && ! isZero();
  1866. }
  1867. int BigInteger::countNumberOfSetBits() const throw()
  1868. {
  1869. int total = 0;
  1870. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  1871. {
  1872. unsigned int n = values[i];
  1873. if (n == 0xffffffff)
  1874. {
  1875. total += 32;
  1876. }
  1877. else
  1878. {
  1879. while (n != 0)
  1880. {
  1881. total += (n & 1);
  1882. n >>= 1;
  1883. }
  1884. }
  1885. }
  1886. return total;
  1887. }
  1888. int BigInteger::getHighestBit() const throw()
  1889. {
  1890. for (int i = highestBit + 1; --i >= 0;)
  1891. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1892. return i;
  1893. return -1;
  1894. }
  1895. int BigInteger::findNextSetBit (int i) const throw()
  1896. {
  1897. for (; i <= highestBit; ++i)
  1898. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1899. return i;
  1900. return -1;
  1901. }
  1902. int BigInteger::findNextClearBit (int i) const throw()
  1903. {
  1904. for (; i <= highestBit; ++i)
  1905. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  1906. break;
  1907. return i;
  1908. }
  1909. BigInteger& BigInteger::operator+= (const BigInteger& other)
  1910. {
  1911. if (other.isNegative())
  1912. return operator-= (-other);
  1913. if (isNegative())
  1914. {
  1915. if (compareAbsolute (other) < 0)
  1916. {
  1917. BigInteger temp (*this);
  1918. temp.negate();
  1919. *this = other;
  1920. operator-= (temp);
  1921. }
  1922. else
  1923. {
  1924. negate();
  1925. operator-= (other);
  1926. negate();
  1927. }
  1928. }
  1929. else
  1930. {
  1931. if (other.highestBit > highestBit)
  1932. highestBit = other.highestBit;
  1933. ++highestBit;
  1934. const int numInts = (highestBit >> 5) + 1;
  1935. ensureSize (numInts);
  1936. int64 remainder = 0;
  1937. for (int i = 0; i <= numInts; ++i)
  1938. {
  1939. if (i < numValues)
  1940. remainder += values[i];
  1941. if (i < other.numValues)
  1942. remainder += other.values[i];
  1943. values[i] = (unsigned int) remainder;
  1944. remainder >>= 32;
  1945. }
  1946. jassert (remainder == 0);
  1947. highestBit = getHighestBit();
  1948. }
  1949. return *this;
  1950. }
  1951. BigInteger& BigInteger::operator-= (const BigInteger& other)
  1952. {
  1953. if (other.isNegative())
  1954. return operator+= (-other);
  1955. if (! isNegative())
  1956. {
  1957. if (compareAbsolute (other) < 0)
  1958. {
  1959. BigInteger temp (other);
  1960. swapWith (temp);
  1961. operator-= (temp);
  1962. negate();
  1963. return *this;
  1964. }
  1965. }
  1966. else
  1967. {
  1968. negate();
  1969. operator+= (other);
  1970. negate();
  1971. return *this;
  1972. }
  1973. const int numInts = (highestBit >> 5) + 1;
  1974. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1975. int64 amountToSubtract = 0;
  1976. for (int i = 0; i <= numInts; ++i)
  1977. {
  1978. if (i <= maxOtherInts)
  1979. amountToSubtract += (int64) other.values[i];
  1980. if (values[i] >= amountToSubtract)
  1981. {
  1982. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1983. amountToSubtract = 0;
  1984. }
  1985. else
  1986. {
  1987. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1988. values[i] = (unsigned int) n;
  1989. amountToSubtract = 1;
  1990. }
  1991. }
  1992. return *this;
  1993. }
  1994. BigInteger& BigInteger::operator*= (const BigInteger& other)
  1995. {
  1996. BigInteger total;
  1997. highestBit = getHighestBit();
  1998. const bool wasNegative = isNegative();
  1999. setNegative (false);
  2000. for (int i = 0; i <= highestBit; ++i)
  2001. {
  2002. if (operator[](i))
  2003. {
  2004. BigInteger n (other);
  2005. n.setNegative (false);
  2006. n <<= i;
  2007. total += n;
  2008. }
  2009. }
  2010. total.setNegative (wasNegative ^ other.isNegative());
  2011. swapWith (total);
  2012. return *this;
  2013. }
  2014. void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
  2015. {
  2016. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  2017. const int divHB = divisor.getHighestBit();
  2018. const int ourHB = getHighestBit();
  2019. if (divHB < 0 || ourHB < 0)
  2020. {
  2021. // division by zero
  2022. remainder.clear();
  2023. clear();
  2024. }
  2025. else
  2026. {
  2027. const bool wasNegative = isNegative();
  2028. swapWith (remainder);
  2029. remainder.setNegative (false);
  2030. clear();
  2031. BigInteger temp (divisor);
  2032. temp.setNegative (false);
  2033. int leftShift = ourHB - divHB;
  2034. temp <<= leftShift;
  2035. while (leftShift >= 0)
  2036. {
  2037. if (remainder.compareAbsolute (temp) >= 0)
  2038. {
  2039. remainder -= temp;
  2040. setBit (leftShift);
  2041. }
  2042. if (--leftShift >= 0)
  2043. temp >>= 1;
  2044. }
  2045. negative = wasNegative ^ divisor.isNegative();
  2046. remainder.setNegative (wasNegative);
  2047. }
  2048. }
  2049. BigInteger& BigInteger::operator/= (const BigInteger& other)
  2050. {
  2051. BigInteger remainder;
  2052. divideBy (other, remainder);
  2053. return *this;
  2054. }
  2055. BigInteger& BigInteger::operator|= (const BigInteger& other)
  2056. {
  2057. // this operation doesn't take into account negative values..
  2058. jassert (isNegative() == other.isNegative());
  2059. if (other.highestBit >= 0)
  2060. {
  2061. ensureSize (other.highestBit >> 5);
  2062. int n = (other.highestBit >> 5) + 1;
  2063. while (--n >= 0)
  2064. values[n] |= other.values[n];
  2065. if (other.highestBit > highestBit)
  2066. highestBit = other.highestBit;
  2067. highestBit = getHighestBit();
  2068. }
  2069. return *this;
  2070. }
  2071. BigInteger& BigInteger::operator&= (const BigInteger& other)
  2072. {
  2073. // this operation doesn't take into account negative values..
  2074. jassert (isNegative() == other.isNegative());
  2075. int n = numValues;
  2076. while (n > other.numValues)
  2077. values[--n] = 0;
  2078. while (--n >= 0)
  2079. values[n] &= other.values[n];
  2080. if (other.highestBit < highestBit)
  2081. highestBit = other.highestBit;
  2082. highestBit = getHighestBit();
  2083. return *this;
  2084. }
  2085. BigInteger& BigInteger::operator^= (const BigInteger& other)
  2086. {
  2087. // this operation will only work with the absolute values
  2088. jassert (isNegative() == other.isNegative());
  2089. if (other.highestBit >= 0)
  2090. {
  2091. ensureSize (other.highestBit >> 5);
  2092. int n = (other.highestBit >> 5) + 1;
  2093. while (--n >= 0)
  2094. values[n] ^= other.values[n];
  2095. if (other.highestBit > highestBit)
  2096. highestBit = other.highestBit;
  2097. highestBit = getHighestBit();
  2098. }
  2099. return *this;
  2100. }
  2101. BigInteger& BigInteger::operator%= (const BigInteger& divisor)
  2102. {
  2103. BigInteger remainder;
  2104. divideBy (divisor, remainder);
  2105. swapWith (remainder);
  2106. return *this;
  2107. }
  2108. BigInteger& BigInteger::operator<<= (int numBitsToShift)
  2109. {
  2110. shiftBits (numBitsToShift, 0);
  2111. return *this;
  2112. }
  2113. BigInteger& BigInteger::operator>>= (int numBitsToShift)
  2114. {
  2115. return operator<<= (-numBitsToShift);
  2116. }
  2117. BigInteger& BigInteger::operator++() { return operator+= (1); }
  2118. BigInteger& BigInteger::operator--() { return operator-= (1); }
  2119. const BigInteger BigInteger::operator++ (int) { const BigInteger old (*this); operator+= (1); return old; }
  2120. const BigInteger BigInteger::operator-- (int) { const BigInteger old (*this); operator-= (1); return old; }
  2121. const BigInteger BigInteger::operator+ (const BigInteger& other) const { BigInteger b (*this); return b += other; }
  2122. const BigInteger BigInteger::operator- (const BigInteger& other) const { BigInteger b (*this); return b -= other; }
  2123. const BigInteger BigInteger::operator* (const BigInteger& other) const { BigInteger b (*this); return b *= other; }
  2124. const BigInteger BigInteger::operator/ (const BigInteger& other) const { BigInteger b (*this); return b /= other; }
  2125. const BigInteger BigInteger::operator| (const BigInteger& other) const { BigInteger b (*this); return b |= other; }
  2126. const BigInteger BigInteger::operator& (const BigInteger& other) const { BigInteger b (*this); return b &= other; }
  2127. const BigInteger BigInteger::operator^ (const BigInteger& other) const { BigInteger b (*this); return b ^= other; }
  2128. const BigInteger BigInteger::operator% (const BigInteger& other) const { BigInteger b (*this); return b %= other; }
  2129. const BigInteger BigInteger::operator<< (const int numBits) const { BigInteger b (*this); return b <<= numBits; }
  2130. const BigInteger BigInteger::operator>> (const int numBits) const { BigInteger b (*this); return b >>= numBits; }
  2131. const BigInteger BigInteger::operator-() const { BigInteger b (*this); b.negate(); return b; }
  2132. int BigInteger::compare (const BigInteger& other) const throw()
  2133. {
  2134. if (isNegative() == other.isNegative())
  2135. {
  2136. const int absComp = compareAbsolute (other);
  2137. return isNegative() ? -absComp : absComp;
  2138. }
  2139. else
  2140. {
  2141. return isNegative() ? -1 : 1;
  2142. }
  2143. }
  2144. int BigInteger::compareAbsolute (const BigInteger& other) const throw()
  2145. {
  2146. const int h1 = getHighestBit();
  2147. const int h2 = other.getHighestBit();
  2148. if (h1 > h2)
  2149. return 1;
  2150. else if (h1 < h2)
  2151. return -1;
  2152. for (int i = (h1 >> 5) + 1; --i >= 0;)
  2153. if (values[i] != other.values[i])
  2154. return (values[i] > other.values[i]) ? 1 : -1;
  2155. return 0;
  2156. }
  2157. bool BigInteger::operator== (const BigInteger& other) const throw() { return compare (other) == 0; }
  2158. bool BigInteger::operator!= (const BigInteger& other) const throw() { return compare (other) != 0; }
  2159. bool BigInteger::operator< (const BigInteger& other) const throw() { return compare (other) < 0; }
  2160. bool BigInteger::operator<= (const BigInteger& other) const throw() { return compare (other) <= 0; }
  2161. bool BigInteger::operator> (const BigInteger& other) const throw() { return compare (other) > 0; }
  2162. bool BigInteger::operator>= (const BigInteger& other) const throw() { return compare (other) >= 0; }
  2163. void BigInteger::shiftBits (int bits, const int startBit)
  2164. {
  2165. if (highestBit < 0)
  2166. return;
  2167. if (startBit > 0)
  2168. {
  2169. if (bits < 0)
  2170. {
  2171. // right shift
  2172. for (int i = startBit; i <= highestBit; ++i)
  2173. setBit (i, operator[] (i - bits));
  2174. highestBit = getHighestBit();
  2175. }
  2176. else if (bits > 0)
  2177. {
  2178. // left shift
  2179. for (int i = highestBit + 1; --i >= startBit;)
  2180. setBit (i + bits, operator[] (i));
  2181. while (--bits >= 0)
  2182. clearBit (bits + startBit);
  2183. }
  2184. }
  2185. else
  2186. {
  2187. if (bits < 0)
  2188. {
  2189. // right shift
  2190. bits = -bits;
  2191. if (bits > highestBit)
  2192. {
  2193. clear();
  2194. }
  2195. else
  2196. {
  2197. const int wordsToMove = bits >> 5;
  2198. int top = 1 + (highestBit >> 5) - wordsToMove;
  2199. highestBit -= bits;
  2200. if (wordsToMove > 0)
  2201. {
  2202. int i;
  2203. for (i = 0; i < top; ++i)
  2204. values [i] = values [i + wordsToMove];
  2205. for (i = 0; i < wordsToMove; ++i)
  2206. values [top + i] = 0;
  2207. bits &= 31;
  2208. }
  2209. if (bits != 0)
  2210. {
  2211. const int invBits = 32 - bits;
  2212. --top;
  2213. for (int i = 0; i < top; ++i)
  2214. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2215. values[top] = (values[top] >> bits);
  2216. }
  2217. highestBit = getHighestBit();
  2218. }
  2219. }
  2220. else if (bits > 0)
  2221. {
  2222. // left shift
  2223. ensureSize (((highestBit + bits) >> 5) + 1);
  2224. const int wordsToMove = bits >> 5;
  2225. int top = 1 + (highestBit >> 5);
  2226. highestBit += bits;
  2227. if (wordsToMove > 0)
  2228. {
  2229. int i;
  2230. for (i = top; --i >= 0;)
  2231. values [i + wordsToMove] = values [i];
  2232. for (i = 0; i < wordsToMove; ++i)
  2233. values [i] = 0;
  2234. bits &= 31;
  2235. }
  2236. if (bits != 0)
  2237. {
  2238. const int invBits = 32 - bits;
  2239. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2240. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2241. values [wordsToMove] = values [wordsToMove] << bits;
  2242. }
  2243. highestBit = getHighestBit();
  2244. }
  2245. }
  2246. }
  2247. const BigInteger BigInteger::simpleGCD (BigInteger* m, BigInteger* n)
  2248. {
  2249. while (! m->isZero())
  2250. {
  2251. if (n->compareAbsolute (*m) > 0)
  2252. swapVariables (m, n);
  2253. *m -= *n;
  2254. }
  2255. return *n;
  2256. }
  2257. const BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
  2258. {
  2259. BigInteger m (*this);
  2260. while (! n.isZero())
  2261. {
  2262. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  2263. return simpleGCD (&m, &n);
  2264. BigInteger temp1 (m), temp2;
  2265. temp1.divideBy (n, temp2);
  2266. m = n;
  2267. n = temp2;
  2268. }
  2269. return m;
  2270. }
  2271. void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
  2272. {
  2273. BigInteger exp (exponent);
  2274. exp %= modulus;
  2275. BigInteger value (1);
  2276. swapWith (value);
  2277. value %= modulus;
  2278. while (! exp.isZero())
  2279. {
  2280. if (exp [0])
  2281. {
  2282. operator*= (value);
  2283. operator%= (modulus);
  2284. }
  2285. value *= value;
  2286. value %= modulus;
  2287. exp >>= 1;
  2288. }
  2289. }
  2290. void BigInteger::inverseModulo (const BigInteger& modulus)
  2291. {
  2292. if (modulus.isOne() || modulus.isNegative())
  2293. {
  2294. clear();
  2295. return;
  2296. }
  2297. if (isNegative() || compareAbsolute (modulus) >= 0)
  2298. operator%= (modulus);
  2299. if (isOne())
  2300. return;
  2301. if (! (*this)[0])
  2302. {
  2303. // not invertible
  2304. clear();
  2305. return;
  2306. }
  2307. BigInteger a1 (modulus);
  2308. BigInteger a2 (*this);
  2309. BigInteger b1 (modulus);
  2310. BigInteger b2 (1);
  2311. while (! a2.isOne())
  2312. {
  2313. BigInteger temp1, temp2, multiplier (a1);
  2314. multiplier.divideBy (a2, temp1);
  2315. temp1 = a2;
  2316. temp1 *= multiplier;
  2317. temp2 = a1;
  2318. temp2 -= temp1;
  2319. a1 = a2;
  2320. a2 = temp2;
  2321. temp1 = b2;
  2322. temp1 *= multiplier;
  2323. temp2 = b1;
  2324. temp2 -= temp1;
  2325. b1 = b2;
  2326. b2 = temp2;
  2327. }
  2328. while (b2.isNegative())
  2329. b2 += modulus;
  2330. b2 %= modulus;
  2331. swapWith (b2);
  2332. }
  2333. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger& value)
  2334. {
  2335. return stream << value.toString (10);
  2336. }
  2337. const String BigInteger::toString (const int base, const int minimumNumCharacters) const
  2338. {
  2339. String s;
  2340. BigInteger v (*this);
  2341. if (base == 2 || base == 8 || base == 16)
  2342. {
  2343. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2344. static const char* const hexDigits = "0123456789abcdef";
  2345. for (;;)
  2346. {
  2347. const int remainder = v.getBitRangeAsInt (0, bits);
  2348. v >>= bits;
  2349. if (remainder == 0 && v.isZero())
  2350. break;
  2351. s = String::charToString (hexDigits [remainder]) + s;
  2352. }
  2353. }
  2354. else if (base == 10)
  2355. {
  2356. const BigInteger ten (10);
  2357. BigInteger remainder;
  2358. for (;;)
  2359. {
  2360. v.divideBy (ten, remainder);
  2361. if (remainder.isZero() && v.isZero())
  2362. break;
  2363. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2364. }
  2365. }
  2366. else
  2367. {
  2368. jassertfalse // can't do the specified base!
  2369. return String::empty;
  2370. }
  2371. s = s.paddedLeft ('0', minimumNumCharacters);
  2372. return isNegative() ? "-" + s : s;
  2373. }
  2374. void BigInteger::parseString (const String& text, const int base)
  2375. {
  2376. clear();
  2377. const juce_wchar* t = text;
  2378. if (base == 2 || base == 8 || base == 16)
  2379. {
  2380. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2381. for (;;)
  2382. {
  2383. const juce_wchar c = *t++;
  2384. const int digit = CharacterFunctions::getHexDigitValue (c);
  2385. if (((unsigned int) digit) < (unsigned int) base)
  2386. {
  2387. operator<<= (bits);
  2388. operator+= (digit);
  2389. }
  2390. else if (c == 0)
  2391. {
  2392. break;
  2393. }
  2394. }
  2395. }
  2396. else if (base == 10)
  2397. {
  2398. const BigInteger ten ((unsigned int) 10);
  2399. for (;;)
  2400. {
  2401. const juce_wchar c = *t++;
  2402. if (c >= '0' && c <= '9')
  2403. {
  2404. operator*= (ten);
  2405. operator+= ((int) (c - '0'));
  2406. }
  2407. else if (c == 0)
  2408. {
  2409. break;
  2410. }
  2411. }
  2412. }
  2413. setNegative (text.trimStart().startsWithChar ('-'));
  2414. }
  2415. const MemoryBlock BigInteger::toMemoryBlock() const
  2416. {
  2417. const int numBytes = (getHighestBit() + 8) >> 3;
  2418. MemoryBlock mb ((size_t) numBytes);
  2419. for (int i = 0; i < numBytes; ++i)
  2420. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2421. return mb;
  2422. }
  2423. void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
  2424. {
  2425. clear();
  2426. for (int i = (int) data.getSize(); --i >= 0;)
  2427. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2428. }
  2429. END_JUCE_NAMESPACE
  2430. /*** End of inlined file: juce_BitArray.cpp ***/
  2431. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2432. BEGIN_JUCE_NAMESPACE
  2433. MemoryBlock::MemoryBlock() throw()
  2434. : size (0)
  2435. {
  2436. }
  2437. MemoryBlock::MemoryBlock (const size_t initialSize,
  2438. const bool initialiseToZero) throw()
  2439. {
  2440. if (initialSize > 0)
  2441. {
  2442. size = initialSize;
  2443. data.allocate (initialSize, initialiseToZero);
  2444. }
  2445. else
  2446. {
  2447. size = 0;
  2448. }
  2449. }
  2450. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2451. : size (other.size)
  2452. {
  2453. if (size > 0)
  2454. {
  2455. jassert (other.data != 0);
  2456. data.malloc (size);
  2457. memcpy (data, other.data, size);
  2458. }
  2459. }
  2460. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2461. const size_t sizeInBytes) throw()
  2462. : size (jmax ((size_t) 0, sizeInBytes))
  2463. {
  2464. jassert (sizeInBytes >= 0);
  2465. if (size > 0)
  2466. {
  2467. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2468. data.malloc (size);
  2469. if (dataToInitialiseFrom != 0)
  2470. memcpy (data, dataToInitialiseFrom, size);
  2471. }
  2472. }
  2473. MemoryBlock::~MemoryBlock() throw()
  2474. {
  2475. jassert (size >= 0); // should never happen
  2476. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2477. }
  2478. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2479. {
  2480. if (this != &other)
  2481. {
  2482. setSize (other.size, false);
  2483. memcpy (data, other.data, size);
  2484. }
  2485. return *this;
  2486. }
  2487. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2488. {
  2489. return matches (other.data, other.size);
  2490. }
  2491. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2492. {
  2493. return ! operator== (other);
  2494. }
  2495. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2496. {
  2497. return size == dataSize
  2498. && memcmp (data, dataToCompare, size) == 0;
  2499. }
  2500. // this will resize the block to this size
  2501. void MemoryBlock::setSize (const size_t newSize,
  2502. const bool initialiseToZero) throw()
  2503. {
  2504. if (size != newSize)
  2505. {
  2506. if (newSize <= 0)
  2507. {
  2508. data.free();
  2509. size = 0;
  2510. }
  2511. else
  2512. {
  2513. if (data != 0)
  2514. {
  2515. data.realloc (newSize);
  2516. if (initialiseToZero && (newSize > size))
  2517. zeromem (data + size, newSize - size);
  2518. }
  2519. else
  2520. {
  2521. data.allocate (newSize, initialiseToZero);
  2522. }
  2523. size = newSize;
  2524. }
  2525. }
  2526. }
  2527. void MemoryBlock::ensureSize (const size_t minimumSize,
  2528. const bool initialiseToZero) throw()
  2529. {
  2530. if (size < minimumSize)
  2531. setSize (minimumSize, initialiseToZero);
  2532. }
  2533. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2534. {
  2535. swapVariables (size, other.size);
  2536. data.swapWith (other.data);
  2537. }
  2538. void MemoryBlock::fillWith (const uint8 value) throw()
  2539. {
  2540. memset (data, (int) value, size);
  2541. }
  2542. void MemoryBlock::append (const void* const srcData,
  2543. const size_t numBytes) throw()
  2544. {
  2545. if (numBytes > 0)
  2546. {
  2547. const size_t oldSize = size;
  2548. setSize (size + numBytes);
  2549. memcpy (data + oldSize, srcData, numBytes);
  2550. }
  2551. }
  2552. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2553. {
  2554. const char* d = static_cast<const char*> (src);
  2555. if (offset < 0)
  2556. {
  2557. d -= offset;
  2558. num -= offset;
  2559. offset = 0;
  2560. }
  2561. if (offset + num > size)
  2562. num = size - offset;
  2563. if (num > 0)
  2564. memcpy (data + offset, d, num);
  2565. }
  2566. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2567. {
  2568. char* d = static_cast<char*> (dst);
  2569. if (offset < 0)
  2570. {
  2571. zeromem (d, -offset);
  2572. d -= offset;
  2573. num += offset;
  2574. offset = 0;
  2575. }
  2576. if (offset + num > size)
  2577. {
  2578. const size_t newNum = size - offset;
  2579. zeromem (d + newNum, num - newNum);
  2580. num = newNum;
  2581. }
  2582. if (num > 0)
  2583. memcpy (d, data + offset, num);
  2584. }
  2585. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2586. {
  2587. if (startByte < 0)
  2588. {
  2589. numBytesToRemove += startByte;
  2590. startByte = 0;
  2591. }
  2592. if (startByte + numBytesToRemove >= size)
  2593. {
  2594. setSize (startByte);
  2595. }
  2596. else if (numBytesToRemove > 0)
  2597. {
  2598. memmove (data + startByte,
  2599. data + startByte + numBytesToRemove,
  2600. size - (startByte + numBytesToRemove));
  2601. setSize (size - numBytesToRemove);
  2602. }
  2603. }
  2604. const String MemoryBlock::toString() const throw()
  2605. {
  2606. return String (static_cast <const char*> (getData()), size);
  2607. }
  2608. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2609. {
  2610. int res = 0;
  2611. size_t byte = bitRangeStart >> 3;
  2612. int offsetInByte = (int) bitRangeStart & 7;
  2613. size_t bitsSoFar = 0;
  2614. while (numBits > 0 && (size_t) byte < size)
  2615. {
  2616. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2617. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2618. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2619. bitsSoFar += bitsThisTime;
  2620. numBits -= bitsThisTime;
  2621. ++byte;
  2622. offsetInByte = 0;
  2623. }
  2624. return res;
  2625. }
  2626. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2627. {
  2628. size_t byte = bitRangeStart >> 3;
  2629. int offsetInByte = (int) bitRangeStart & 7;
  2630. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2631. while (numBits > 0 && (size_t) byte < size)
  2632. {
  2633. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2634. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2635. const unsigned int tempBits = bitsToSet << offsetInByte;
  2636. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2637. ++byte;
  2638. numBits -= bitsThisTime;
  2639. bitsToSet >>= bitsThisTime;
  2640. mask >>= bitsThisTime;
  2641. offsetInByte = 0;
  2642. }
  2643. }
  2644. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2645. {
  2646. ensureSize (hex.length() >> 1);
  2647. char* dest = data;
  2648. int i = 0;
  2649. for (;;)
  2650. {
  2651. int byte = 0;
  2652. for (int loop = 2; --loop >= 0;)
  2653. {
  2654. byte <<= 4;
  2655. for (;;)
  2656. {
  2657. const juce_wchar c = hex [i++];
  2658. if (c >= '0' && c <= '9')
  2659. {
  2660. byte |= c - '0';
  2661. break;
  2662. }
  2663. else if (c >= 'a' && c <= 'z')
  2664. {
  2665. byte |= c - ('a' - 10);
  2666. break;
  2667. }
  2668. else if (c >= 'A' && c <= 'Z')
  2669. {
  2670. byte |= c - ('A' - 10);
  2671. break;
  2672. }
  2673. else if (c == 0)
  2674. {
  2675. setSize (static_cast <size_t> (dest - data));
  2676. return;
  2677. }
  2678. }
  2679. }
  2680. *dest++ = (char) byte;
  2681. }
  2682. }
  2683. static const char* const encodingTable
  2684. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2685. const String MemoryBlock::toBase64Encoding() const throw()
  2686. {
  2687. const size_t numChars = ((size << 3) + 5) / 6;
  2688. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2689. const int initialLen = destString.length();
  2690. destString.preallocateStorage (initialLen + 2 + numChars);
  2691. juce_wchar* d = destString;
  2692. d += initialLen;
  2693. *d++ = '.';
  2694. for (size_t i = 0; i < numChars; ++i)
  2695. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2696. *d++ = 0;
  2697. return destString;
  2698. }
  2699. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2700. {
  2701. const int startPos = s.indexOfChar ('.') + 1;
  2702. if (startPos <= 0)
  2703. return false;
  2704. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2705. setSize (numBytesNeeded, true);
  2706. const int numChars = s.length() - startPos;
  2707. const juce_wchar* srcChars = s;
  2708. srcChars += startPos;
  2709. int pos = 0;
  2710. for (int i = 0; i < numChars; ++i)
  2711. {
  2712. const char c = (char) srcChars[i];
  2713. for (int j = 0; j < 64; ++j)
  2714. {
  2715. if (encodingTable[j] == c)
  2716. {
  2717. setBitRange (pos, 6, j);
  2718. pos += 6;
  2719. break;
  2720. }
  2721. }
  2722. }
  2723. return true;
  2724. }
  2725. END_JUCE_NAMESPACE
  2726. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2727. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2728. BEGIN_JUCE_NAMESPACE
  2729. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2730. : properties (ignoreCaseOfKeyNames),
  2731. fallbackProperties (0),
  2732. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2733. {
  2734. }
  2735. PropertySet::PropertySet (const PropertySet& other) throw()
  2736. : properties (other.properties),
  2737. fallbackProperties (other.fallbackProperties),
  2738. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2739. {
  2740. }
  2741. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2742. {
  2743. properties = other.properties;
  2744. fallbackProperties = other.fallbackProperties;
  2745. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2746. propertyChanged();
  2747. return *this;
  2748. }
  2749. PropertySet::~PropertySet()
  2750. {
  2751. }
  2752. void PropertySet::clear()
  2753. {
  2754. const ScopedLock sl (lock);
  2755. if (properties.size() > 0)
  2756. {
  2757. properties.clear();
  2758. propertyChanged();
  2759. }
  2760. }
  2761. const String PropertySet::getValue (const String& keyName,
  2762. const String& defaultValue) const throw()
  2763. {
  2764. const ScopedLock sl (lock);
  2765. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2766. if (index >= 0)
  2767. return properties.getAllValues() [index];
  2768. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2769. : defaultValue;
  2770. }
  2771. int PropertySet::getIntValue (const String& keyName,
  2772. const int defaultValue) const throw()
  2773. {
  2774. const ScopedLock sl (lock);
  2775. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2776. if (index >= 0)
  2777. return properties.getAllValues() [index].getIntValue();
  2778. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2779. : defaultValue;
  2780. }
  2781. double PropertySet::getDoubleValue (const String& keyName,
  2782. const double defaultValue) const throw()
  2783. {
  2784. const ScopedLock sl (lock);
  2785. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2786. if (index >= 0)
  2787. return properties.getAllValues()[index].getDoubleValue();
  2788. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2789. : defaultValue;
  2790. }
  2791. bool PropertySet::getBoolValue (const String& keyName,
  2792. const bool defaultValue) const throw()
  2793. {
  2794. const ScopedLock sl (lock);
  2795. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2796. if (index >= 0)
  2797. return properties.getAllValues() [index].getIntValue() != 0;
  2798. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2799. : defaultValue;
  2800. }
  2801. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2802. {
  2803. XmlDocument doc (getValue (keyName));
  2804. return doc.getDocumentElement();
  2805. }
  2806. void PropertySet::setValue (const String& keyName,
  2807. const String& value) throw()
  2808. {
  2809. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2810. if (keyName.isNotEmpty())
  2811. {
  2812. const ScopedLock sl (lock);
  2813. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2814. if (index < 0 || properties.getAllValues() [index] != value)
  2815. {
  2816. properties.set (keyName, value);
  2817. propertyChanged();
  2818. }
  2819. }
  2820. }
  2821. void PropertySet::removeValue (const String& keyName) throw()
  2822. {
  2823. if (keyName.isNotEmpty())
  2824. {
  2825. const ScopedLock sl (lock);
  2826. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2827. if (index >= 0)
  2828. {
  2829. properties.remove (keyName);
  2830. propertyChanged();
  2831. }
  2832. }
  2833. }
  2834. void PropertySet::setValue (const String& keyName, const int value) throw()
  2835. {
  2836. setValue (keyName, String (value));
  2837. }
  2838. void PropertySet::setValue (const String& keyName, const double value) throw()
  2839. {
  2840. setValue (keyName, String (value));
  2841. }
  2842. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2843. {
  2844. setValue (keyName, String (value ? "1" : "0"));
  2845. }
  2846. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2847. {
  2848. setValue (keyName, (xml == 0) ? String::empty
  2849. : xml->createDocument (String::empty, true));
  2850. }
  2851. bool PropertySet::containsKey (const String& keyName) const throw()
  2852. {
  2853. const ScopedLock sl (lock);
  2854. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2855. }
  2856. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2857. {
  2858. const ScopedLock sl (lock);
  2859. fallbackProperties = fallbackProperties_;
  2860. }
  2861. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2862. {
  2863. const ScopedLock sl (lock);
  2864. XmlElement* const xml = new XmlElement (nodeName);
  2865. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2866. {
  2867. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2868. e->setAttribute ("name", properties.getAllKeys()[i]);
  2869. e->setAttribute ("val", properties.getAllValues()[i]);
  2870. }
  2871. return xml;
  2872. }
  2873. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2874. {
  2875. const ScopedLock sl (lock);
  2876. clear();
  2877. forEachXmlChildElementWithTagName (xml, e, "VALUE")
  2878. {
  2879. if (e->hasAttribute ("name")
  2880. && e->hasAttribute ("val"))
  2881. {
  2882. properties.set (e->getStringAttribute ("name"),
  2883. e->getStringAttribute ("val"));
  2884. }
  2885. }
  2886. if (properties.size() > 0)
  2887. propertyChanged();
  2888. }
  2889. void PropertySet::propertyChanged()
  2890. {
  2891. }
  2892. END_JUCE_NAMESPACE
  2893. /*** End of inlined file: juce_PropertySet.cpp ***/
  2894. /*** Start of inlined file: juce_Variant.cpp ***/
  2895. BEGIN_JUCE_NAMESPACE
  2896. var::var() throw()
  2897. : type (voidType)
  2898. {
  2899. value.doubleValue = 0;
  2900. }
  2901. var::~var() throw()
  2902. {
  2903. if (type == stringType)
  2904. delete value.stringValue;
  2905. else if (type == objectType && value.objectValue != 0)
  2906. value.objectValue->decReferenceCount();
  2907. }
  2908. const var var::null;
  2909. var::var (const var& valueToCopy)
  2910. : type (valueToCopy.type),
  2911. value (valueToCopy.value)
  2912. {
  2913. if (type == stringType)
  2914. value.stringValue = new String (*(value.stringValue));
  2915. else if (type == objectType && value.objectValue != 0)
  2916. value.objectValue->incReferenceCount();
  2917. }
  2918. var::var (const int value_) throw()
  2919. : type (intType)
  2920. {
  2921. value.intValue = value_;
  2922. }
  2923. var::var (const bool value_) throw()
  2924. : type (boolType)
  2925. {
  2926. value.boolValue = value_;
  2927. }
  2928. var::var (const double value_) throw()
  2929. : type (doubleType)
  2930. {
  2931. value.doubleValue = value_;
  2932. }
  2933. var::var (const String& value_)
  2934. : type (stringType)
  2935. {
  2936. value.stringValue = new String (value_);
  2937. }
  2938. var::var (const char* const value_)
  2939. : type (stringType)
  2940. {
  2941. value.stringValue = new String (value_);
  2942. }
  2943. var::var (const juce_wchar* const value_)
  2944. : type (stringType)
  2945. {
  2946. value.stringValue = new String (value_);
  2947. }
  2948. var::var (DynamicObject* const object)
  2949. : type (objectType)
  2950. {
  2951. value.objectValue = object;
  2952. if (object != 0)
  2953. object->incReferenceCount();
  2954. }
  2955. var::var (MethodFunction method_) throw()
  2956. : type (methodType)
  2957. {
  2958. value.methodValue = method_;
  2959. }
  2960. void var::swapWith (var& other) throw()
  2961. {
  2962. swapVariables (type, other.type);
  2963. swapVariables (value, other.value);
  2964. }
  2965. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2966. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2967. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2968. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2969. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2970. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2971. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2972. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2973. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2974. var::operator int() const
  2975. {
  2976. switch (type)
  2977. {
  2978. case voidType: break;
  2979. case intType: return value.intValue;
  2980. case boolType: return value.boolValue ? 1 : 0;
  2981. case doubleType: return static_cast <int> (value.doubleValue);
  2982. case stringType: return value.stringValue->getIntValue();
  2983. case objectType: break;
  2984. default: jassertfalse; break;
  2985. }
  2986. return 0;
  2987. }
  2988. var::operator bool() const
  2989. {
  2990. switch (type)
  2991. {
  2992. case voidType: break;
  2993. case intType: return value.intValue != 0;
  2994. case boolType: return value.boolValue;
  2995. case doubleType: return value.doubleValue != 0;
  2996. case stringType: return value.stringValue->getIntValue() != 0
  2997. || value.stringValue->trim().equalsIgnoreCase ("true")
  2998. || value.stringValue->trim().equalsIgnoreCase ("yes");
  2999. case objectType: return value.objectValue != 0;
  3000. default: jassertfalse; break;
  3001. }
  3002. return false;
  3003. }
  3004. var::operator float() const
  3005. {
  3006. return (float) operator double();
  3007. }
  3008. var::operator double() const
  3009. {
  3010. switch (type)
  3011. {
  3012. case voidType: break;
  3013. case intType: return value.intValue;
  3014. case boolType: return value.boolValue ? 1.0 : 0.0;
  3015. case doubleType: return value.doubleValue;
  3016. case stringType: return value.stringValue->getDoubleValue();
  3017. case objectType: break;
  3018. default: jassertfalse; break;
  3019. }
  3020. return 0.0;
  3021. }
  3022. const String var::toString() const
  3023. {
  3024. switch (type)
  3025. {
  3026. case voidType: return String::empty;
  3027. case intType: return String (value.intValue);
  3028. case boolType: return String::charToString (value.boolValue ? '1' : '0');
  3029. case doubleType: return String (value.doubleValue);
  3030. case stringType: return *(value.stringValue);
  3031. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  3032. case methodType: return "Method";
  3033. default: jassertfalse; break;
  3034. }
  3035. return String::empty;
  3036. }
  3037. var::operator const String() const
  3038. {
  3039. return toString();
  3040. }
  3041. DynamicObject* var::getObject() const
  3042. {
  3043. return type == objectType ? value.objectValue : 0;
  3044. }
  3045. bool var::equals (const var& other) const throw()
  3046. {
  3047. switch (type)
  3048. {
  3049. case voidType: return other.isVoid();
  3050. case intType: return value.intValue == static_cast <int> (other);
  3051. case boolType: return value.boolValue == static_cast <bool> (other);
  3052. case doubleType: return value.doubleValue == static_cast <double> (other);
  3053. case stringType: return (*(value.stringValue)) == other.toString();
  3054. case objectType: return value.objectValue == other.getObject();
  3055. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  3056. default: jassertfalse; break;
  3057. }
  3058. return false;
  3059. }
  3060. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  3061. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  3062. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  3063. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  3064. void var::writeToStream (OutputStream& output) const
  3065. {
  3066. switch (type)
  3067. {
  3068. case voidType: output.writeCompressedInt (0); break;
  3069. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  3070. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  3071. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  3072. case stringType:
  3073. {
  3074. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  3075. output.writeCompressedInt (len + 1);
  3076. output.writeByte (5);
  3077. HeapBlock<char> temp (len);
  3078. value.stringValue->copyToUTF8 (temp, len);
  3079. output.write (temp, len);
  3080. break;
  3081. }
  3082. case objectType:
  3083. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3084. default: jassertfalse; break; // Is this a corrupted object?
  3085. }
  3086. }
  3087. const var var::readFromStream (InputStream& input)
  3088. {
  3089. const int numBytes = input.readCompressedInt();
  3090. if (numBytes > 0)
  3091. {
  3092. switch (input.readByte())
  3093. {
  3094. case 1: return var (input.readInt());
  3095. case 2: return var (true);
  3096. case 3: return var (false);
  3097. case 4: return var (input.readDouble());
  3098. case 5:
  3099. {
  3100. MemoryBlock mb;
  3101. input.readIntoMemoryBlock (mb, numBytes - 1);
  3102. return var (String::fromUTF8 (static_cast <const char*> (mb.getData()), (int) mb.getSize()));
  3103. }
  3104. default: input.skipNextBytes (numBytes - 1); break;
  3105. }
  3106. }
  3107. return var::null;
  3108. }
  3109. const var var::operator[] (const var::identifier& propertyName) const
  3110. {
  3111. if (type == objectType && value.objectValue != 0)
  3112. return value.objectValue->getProperty (propertyName);
  3113. return var::null;
  3114. }
  3115. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3116. {
  3117. if (type == objectType && value.objectValue != 0)
  3118. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3119. return var::null;
  3120. }
  3121. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3122. {
  3123. if (isMethod())
  3124. {
  3125. DynamicObject* const target = targetObject.getObject();
  3126. if (target != 0)
  3127. return (target->*(value.methodValue)) (arguments, numArguments);
  3128. }
  3129. return var::null;
  3130. }
  3131. const var var::call (const var::identifier& method) const
  3132. {
  3133. return invoke (method, 0, 0);
  3134. }
  3135. const var var::call (const var::identifier& method, const var& arg1) const
  3136. {
  3137. return invoke (method, &arg1, 1);
  3138. }
  3139. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3140. {
  3141. var args[] = { arg1, arg2 };
  3142. return invoke (method, args, 2);
  3143. }
  3144. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3145. {
  3146. var args[] = { arg1, arg2, arg3 };
  3147. return invoke (method, args, 3);
  3148. }
  3149. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3150. {
  3151. var args[] = { arg1, arg2, arg3, arg4 };
  3152. return invoke (method, args, 4);
  3153. }
  3154. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3155. {
  3156. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3157. return invoke (method, args, 5);
  3158. }
  3159. var::identifier::identifier() throw()
  3160. : hashCode (0)
  3161. {
  3162. }
  3163. var::identifier::identifier (const String& name_)
  3164. : name (name_),
  3165. hashCode (name_.hashCode())
  3166. {
  3167. /* An identifier string must be suitable for use as a script variable or XML
  3168. attribute, so it can only contain this limited set of characters.. */
  3169. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3170. }
  3171. var::identifier::identifier (const char* const name_)
  3172. : name (name_),
  3173. hashCode (name.hashCode())
  3174. {
  3175. /* An identifier string must be suitable for use as a script variable or XML
  3176. attribute, so it can only contain this limited set of characters.. */
  3177. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3178. }
  3179. var::identifier::~identifier()
  3180. {
  3181. }
  3182. END_JUCE_NAMESPACE
  3183. /*** End of inlined file: juce_Variant.cpp ***/
  3184. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3185. BEGIN_JUCE_NAMESPACE
  3186. NamedValueSet::NamedValue::NamedValue() throw()
  3187. {
  3188. }
  3189. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3190. : name (name_), value (value_)
  3191. {
  3192. }
  3193. NamedValueSet::NamedValueSet() throw()
  3194. {
  3195. }
  3196. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3197. : values (other.values)
  3198. {
  3199. }
  3200. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3201. {
  3202. values = other.values;
  3203. return *this;
  3204. }
  3205. NamedValueSet::~NamedValueSet()
  3206. {
  3207. }
  3208. int NamedValueSet::size() const throw()
  3209. {
  3210. return values.size();
  3211. }
  3212. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3213. {
  3214. for (int i = values.size(); --i >= 0;)
  3215. {
  3216. const NamedValue& v = values.getReference(i);
  3217. if (v.name == name)
  3218. return v.value;
  3219. }
  3220. return var::null;
  3221. }
  3222. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3223. {
  3224. const var* v = getItem (name);
  3225. return v != 0 ? *v : defaultReturnValue;
  3226. }
  3227. var* NamedValueSet::getItem (const var::identifier& name) const
  3228. {
  3229. for (int i = values.size(); --i >= 0;)
  3230. {
  3231. NamedValue& v = values.getReference(i);
  3232. if (v.name == name)
  3233. return &(v.value);
  3234. }
  3235. return 0;
  3236. }
  3237. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3238. {
  3239. for (int i = values.size(); --i >= 0;)
  3240. {
  3241. NamedValue& v = values.getReference(i);
  3242. if (v.name == name)
  3243. {
  3244. if (v.value == newValue)
  3245. return false;
  3246. v.value = newValue;
  3247. return true;
  3248. }
  3249. }
  3250. values.add (NamedValue (name, newValue));
  3251. return true;
  3252. }
  3253. bool NamedValueSet::contains (const var::identifier& name) const
  3254. {
  3255. return getItem (name) != 0;
  3256. }
  3257. bool NamedValueSet::remove (const var::identifier& name)
  3258. {
  3259. for (int i = values.size(); --i >= 0;)
  3260. {
  3261. if (values.getReference(i).name == name)
  3262. {
  3263. values.remove (i);
  3264. return true;
  3265. }
  3266. }
  3267. return false;
  3268. }
  3269. const var::identifier NamedValueSet::getName (int index) const
  3270. {
  3271. jassert (((unsigned int) index) < (unsigned int) values.size());
  3272. return values [index].name;
  3273. }
  3274. void NamedValueSet::clear()
  3275. {
  3276. values.clear();
  3277. }
  3278. END_JUCE_NAMESPACE
  3279. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3280. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3281. BEGIN_JUCE_NAMESPACE
  3282. DynamicObject::DynamicObject()
  3283. {
  3284. }
  3285. DynamicObject::~DynamicObject()
  3286. {
  3287. }
  3288. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3289. {
  3290. var* const v = properties.getItem (propertyName);
  3291. return v != 0 && ! v->isMethod();
  3292. }
  3293. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3294. {
  3295. return properties [propertyName];
  3296. }
  3297. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3298. {
  3299. properties.set (propertyName, newValue);
  3300. }
  3301. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3302. {
  3303. properties.remove (propertyName);
  3304. }
  3305. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3306. {
  3307. return getProperty (methodName).isMethod();
  3308. }
  3309. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3310. const var* parameters,
  3311. int numParameters)
  3312. {
  3313. return properties [methodName].invoke (var (this), parameters, numParameters);
  3314. }
  3315. void DynamicObject::setMethod (const var::identifier& name,
  3316. var::MethodFunction methodFunction)
  3317. {
  3318. properties.set (name, var (methodFunction));
  3319. }
  3320. void DynamicObject::clear()
  3321. {
  3322. properties.clear();
  3323. }
  3324. END_JUCE_NAMESPACE
  3325. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3326. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3327. BEGIN_JUCE_NAMESPACE
  3328. BlowFish::BlowFish (const void* const keyData, const int keyBytes)
  3329. {
  3330. jassert (keyData != 0);
  3331. jassert (keyBytes > 0);
  3332. static const uint32 initialPValues [18] =
  3333. {
  3334. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3335. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3336. 0x9216d5d9, 0x8979fb1b
  3337. };
  3338. static const uint32 initialSValues [4 * 256] =
  3339. {
  3340. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3341. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3342. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3343. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3344. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3345. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3346. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3347. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3348. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3349. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3350. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3351. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3352. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3353. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3354. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3355. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3356. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3357. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3358. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3359. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3360. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3361. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3362. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3363. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3364. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3365. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3366. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3367. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3368. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3369. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3370. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3371. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3372. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3373. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3374. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3375. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3376. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3377. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3378. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3379. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3380. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3381. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3382. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3383. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3384. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3385. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3386. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3387. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3388. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3389. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3390. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3391. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3392. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3393. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3394. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3395. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3396. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3397. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3398. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3399. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3400. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3401. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3402. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3403. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3404. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3405. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3406. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3407. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3408. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3409. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3410. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3411. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3412. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3413. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3414. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3415. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3416. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3417. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3418. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3419. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3420. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3421. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3422. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3423. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3424. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3425. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3426. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3427. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3428. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3429. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3430. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3431. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3432. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3433. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3434. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3435. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3436. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3437. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3438. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3439. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3440. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3441. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3442. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3443. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3444. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3445. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3446. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3447. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3448. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3449. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3450. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3451. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3452. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3453. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3454. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3455. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3456. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3457. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3458. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3459. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3460. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3461. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3462. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3463. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3464. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3465. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3466. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3467. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3468. };
  3469. memcpy (p, initialPValues, sizeof (p));
  3470. int i, j = 0;
  3471. for (i = 4; --i >= 0;)
  3472. {
  3473. s[i].malloc (256);
  3474. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3475. }
  3476. for (i = 0; i < 18; ++i)
  3477. {
  3478. uint32 d = 0;
  3479. for (int k = 0; k < 4; ++k)
  3480. {
  3481. d = (d << 8) | static_cast <const uint8*> (keyData)[j];
  3482. if (++j >= keyBytes)
  3483. j = 0;
  3484. }
  3485. p[i] = initialPValues[i] ^ d;
  3486. }
  3487. uint32 l = 0, r = 0;
  3488. for (i = 0; i < 18; i += 2)
  3489. {
  3490. encrypt (l, r);
  3491. p[i] = l;
  3492. p[i + 1] = r;
  3493. }
  3494. for (i = 0; i < 4; ++i)
  3495. {
  3496. for (j = 0; j < 256; j += 2)
  3497. {
  3498. encrypt (l, r);
  3499. s[i][j] = l;
  3500. s[i][j + 1] = r;
  3501. }
  3502. }
  3503. }
  3504. BlowFish::BlowFish (const BlowFish& other)
  3505. {
  3506. for (int i = 4; --i >= 0;)
  3507. s[i].malloc (256);
  3508. operator= (other);
  3509. }
  3510. BlowFish& BlowFish::operator= (const BlowFish& other)
  3511. {
  3512. memcpy (p, other.p, sizeof (p));
  3513. for (int i = 4; --i >= 0;)
  3514. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3515. return *this;
  3516. }
  3517. BlowFish::~BlowFish()
  3518. {
  3519. }
  3520. uint32 BlowFish::F (const uint32 x) const throw()
  3521. {
  3522. return ((s[0][(x >> 24) & 0xff] + s[1][(x >> 16) & 0xff])
  3523. ^ s[2][(x >> 8) & 0xff]) + s[3][x & 0xff];
  3524. }
  3525. void BlowFish::encrypt (uint32& data1, uint32& data2) const throw()
  3526. {
  3527. uint32 l = data1;
  3528. uint32 r = data2;
  3529. for (int i = 0; i < 16; ++i)
  3530. {
  3531. l ^= p[i];
  3532. r ^= F(l);
  3533. swapVariables (l, r);
  3534. }
  3535. data1 = r ^ p[17];
  3536. data2 = l ^ p[16];
  3537. }
  3538. void BlowFish::decrypt (uint32& data1, uint32& data2) const throw()
  3539. {
  3540. uint32 l = data1;
  3541. uint32 r = data2;
  3542. for (int i = 17; i > 1; --i)
  3543. {
  3544. l ^= p[i];
  3545. r ^= F(l);
  3546. swapVariables (l, r);
  3547. }
  3548. data1 = r ^ p[0];
  3549. data2 = l ^ p[1];
  3550. }
  3551. END_JUCE_NAMESPACE
  3552. /*** End of inlined file: juce_BlowFish.cpp ***/
  3553. /*** Start of inlined file: juce_MD5.cpp ***/
  3554. BEGIN_JUCE_NAMESPACE
  3555. MD5::MD5()
  3556. {
  3557. zerostruct (result);
  3558. }
  3559. MD5::MD5 (const MD5& other)
  3560. {
  3561. memcpy (result, other.result, sizeof (result));
  3562. }
  3563. MD5& MD5::operator= (const MD5& other)
  3564. {
  3565. memcpy (result, other.result, sizeof (result));
  3566. return *this;
  3567. }
  3568. MD5::MD5 (const MemoryBlock& data)
  3569. {
  3570. ProcessContext context;
  3571. context.processBlock (data.getData(), data.getSize());
  3572. context.finish (result);
  3573. }
  3574. MD5::MD5 (const void* data, const size_t numBytes)
  3575. {
  3576. ProcessContext context;
  3577. context.processBlock (data, numBytes);
  3578. context.finish (result);
  3579. }
  3580. MD5::MD5 (const String& text)
  3581. {
  3582. ProcessContext context;
  3583. const int len = text.length();
  3584. const juce_wchar* const t = text;
  3585. for (int i = 0; i < len; ++i)
  3586. {
  3587. // force the string into integer-sized unicode characters, to try to make it
  3588. // get the same results on all platforms + compilers.
  3589. uint32 unicodeChar = ByteOrder::swapIfBigEndian ((uint32) t[i]);
  3590. context.processBlock (&unicodeChar, sizeof (unicodeChar));
  3591. }
  3592. context.finish (result);
  3593. }
  3594. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3595. {
  3596. ProcessContext context;
  3597. if (numBytesToRead < 0)
  3598. numBytesToRead = std::numeric_limits<int64>::max();
  3599. while (numBytesToRead > 0)
  3600. {
  3601. uint8 tempBuffer [512];
  3602. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3603. if (bytesRead <= 0)
  3604. break;
  3605. numBytesToRead -= bytesRead;
  3606. context.processBlock (tempBuffer, bytesRead);
  3607. }
  3608. context.finish (result);
  3609. }
  3610. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3611. {
  3612. processStream (input, numBytesToRead);
  3613. }
  3614. MD5::MD5 (const File& file)
  3615. {
  3616. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3617. if (fin != 0)
  3618. processStream (*fin, -1);
  3619. else
  3620. zerostruct (result);
  3621. }
  3622. MD5::~MD5()
  3623. {
  3624. }
  3625. namespace MD5Functions
  3626. {
  3627. static void encode (void* const output, const void* const input, const int numBytes) throw()
  3628. {
  3629. for (int i = 0; i < (numBytes >> 2); ++i)
  3630. static_cast<uint32*> (output)[i] = ByteOrder::swapIfBigEndian (static_cast<const uint32*> (input) [i]);
  3631. }
  3632. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3633. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3634. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3635. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3636. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3637. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3638. {
  3639. a += F (b, c, d) + x + ac;
  3640. a = rotateLeft (a, s) + b;
  3641. }
  3642. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3643. {
  3644. a += G (b, c, d) + x + ac;
  3645. a = rotateLeft (a, s) + b;
  3646. }
  3647. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3648. {
  3649. a += H (b, c, d) + x + ac;
  3650. a = rotateLeft (a, s) + b;
  3651. }
  3652. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3653. {
  3654. a += I (b, c, d) + x + ac;
  3655. a = rotateLeft (a, s) + b;
  3656. }
  3657. }
  3658. MD5::ProcessContext::ProcessContext()
  3659. {
  3660. state[0] = 0x67452301;
  3661. state[1] = 0xefcdab89;
  3662. state[2] = 0x98badcfe;
  3663. state[3] = 0x10325476;
  3664. count[0] = 0;
  3665. count[1] = 0;
  3666. }
  3667. void MD5::ProcessContext::processBlock (const void* const data, const size_t dataSize)
  3668. {
  3669. int bufferPos = ((count[0] >> 3) & 0x3F);
  3670. count[0] += (uint32) (dataSize << 3);
  3671. if (count[0] < ((uint32) dataSize << 3))
  3672. count[1]++;
  3673. count[1] += (uint32) (dataSize >> 29);
  3674. const size_t spaceLeft = 64 - bufferPos;
  3675. size_t i = 0;
  3676. if (dataSize >= spaceLeft)
  3677. {
  3678. memcpy (buffer + bufferPos, data, spaceLeft);
  3679. transform (buffer);
  3680. for (i = spaceLeft; i + 64 <= dataSize; i += 64)
  3681. transform (static_cast <const char*> (data) + i);
  3682. bufferPos = 0;
  3683. }
  3684. memcpy (buffer + bufferPos, static_cast <const char*> (data) + i, dataSize - i);
  3685. }
  3686. void MD5::ProcessContext::finish (void* const result)
  3687. {
  3688. unsigned char encodedLength[8];
  3689. MD5Functions::encode (encodedLength, count, 8);
  3690. // Pad out to 56 mod 64.
  3691. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3692. const int paddingLength = (index < 56) ? (56 - index)
  3693. : (120 - index);
  3694. uint8 paddingBuffer [64];
  3695. zeromem (paddingBuffer, paddingLength);
  3696. paddingBuffer [0] = 0x80;
  3697. processBlock (paddingBuffer, paddingLength);
  3698. processBlock (encodedLength, 8);
  3699. MD5Functions::encode (result, state, 16);
  3700. zerostruct (buffer);
  3701. }
  3702. void MD5::ProcessContext::transform (const void* const bufferToTransform)
  3703. {
  3704. using namespace MD5Functions;
  3705. uint32 a = state[0];
  3706. uint32 b = state[1];
  3707. uint32 c = state[2];
  3708. uint32 d = state[3];
  3709. uint32 x[16];
  3710. encode (x, bufferToTransform, 64);
  3711. enum Constants
  3712. {
  3713. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3714. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3715. };
  3716. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); FF (d, a, b, c, x[ 1], S12, 0xe8c7b756);
  3717. FF (c, d, a, b, x[ 2], S13, 0x242070db); FF (b, c, d, a, x[ 3], S14, 0xc1bdceee);
  3718. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); FF (d, a, b, c, x[ 5], S12, 0x4787c62a);
  3719. FF (c, d, a, b, x[ 6], S13, 0xa8304613); FF (b, c, d, a, x[ 7], S14, 0xfd469501);
  3720. FF (a, b, c, d, x[ 8], S11, 0x698098d8); FF (d, a, b, c, x[ 9], S12, 0x8b44f7af);
  3721. FF (c, d, a, b, x[10], S13, 0xffff5bb1); FF (b, c, d, a, x[11], S14, 0x895cd7be);
  3722. FF (a, b, c, d, x[12], S11, 0x6b901122); FF (d, a, b, c, x[13], S12, 0xfd987193);
  3723. FF (c, d, a, b, x[14], S13, 0xa679438e); FF (b, c, d, a, x[15], S14, 0x49b40821);
  3724. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); GG (d, a, b, c, x[ 6], S22, 0xc040b340);
  3725. GG (c, d, a, b, x[11], S23, 0x265e5a51); GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa);
  3726. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); GG (d, a, b, c, x[10], S22, 0x02441453);
  3727. GG (c, d, a, b, x[15], S23, 0xd8a1e681); GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8);
  3728. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); GG (d, a, b, c, x[14], S22, 0xc33707d6);
  3729. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); GG (b, c, d, a, x[ 8], S24, 0x455a14ed);
  3730. GG (a, b, c, d, x[13], S21, 0xa9e3e905); GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8);
  3731. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); GG (b, c, d, a, x[12], S24, 0x8d2a4c8a);
  3732. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); HH (d, a, b, c, x[ 8], S32, 0x8771f681);
  3733. HH (c, d, a, b, x[11], S33, 0x6d9d6122); HH (b, c, d, a, x[14], S34, 0xfde5380c);
  3734. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9);
  3735. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); HH (b, c, d, a, x[10], S34, 0xbebfbc70);
  3736. HH (a, b, c, d, x[13], S31, 0x289b7ec6); HH (d, a, b, c, x[ 0], S32, 0xeaa127fa);
  3737. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); HH (b, c, d, a, x[ 6], S34, 0x04881d05);
  3738. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); HH (d, a, b, c, x[12], S32, 0xe6db99e5);
  3739. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); HH (b, c, d, a, x[ 2], S34, 0xc4ac5665);
  3740. II (a, b, c, d, x[ 0], S41, 0xf4292244); II (d, a, b, c, x[ 7], S42, 0x432aff97);
  3741. II (c, d, a, b, x[14], S43, 0xab9423a7); II (b, c, d, a, x[ 5], S44, 0xfc93a039);
  3742. II (a, b, c, d, x[12], S41, 0x655b59c3); II (d, a, b, c, x[ 3], S42, 0x8f0ccc92);
  3743. II (c, d, a, b, x[10], S43, 0xffeff47d); II (b, c, d, a, x[ 1], S44, 0x85845dd1);
  3744. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); II (d, a, b, c, x[15], S42, 0xfe2ce6e0);
  3745. II (c, d, a, b, x[ 6], S43, 0xa3014314); II (b, c, d, a, x[13], S44, 0x4e0811a1);
  3746. II (a, b, c, d, x[ 4], S41, 0xf7537e82); II (d, a, b, c, x[11], S42, 0xbd3af235);
  3747. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); II (b, c, d, a, x[ 9], S44, 0xeb86d391);
  3748. state[0] += a;
  3749. state[1] += b;
  3750. state[2] += c;
  3751. state[3] += d;
  3752. zerostruct (x);
  3753. }
  3754. const MemoryBlock MD5::getRawChecksumData() const
  3755. {
  3756. return MemoryBlock (result, sizeof (result));
  3757. }
  3758. const String MD5::toHexString() const
  3759. {
  3760. return String::toHexString (result, sizeof (result), 0);
  3761. }
  3762. bool MD5::operator== (const MD5& other) const
  3763. {
  3764. return memcmp (result, other.result, sizeof (result)) == 0;
  3765. }
  3766. bool MD5::operator!= (const MD5& other) const
  3767. {
  3768. return ! operator== (other);
  3769. }
  3770. END_JUCE_NAMESPACE
  3771. /*** End of inlined file: juce_MD5.cpp ***/
  3772. /*** Start of inlined file: juce_Primes.cpp ***/
  3773. BEGIN_JUCE_NAMESPACE
  3774. namespace PrimesHelpers
  3775. {
  3776. static void createSmallSieve (const int numBits, BigInteger& result)
  3777. {
  3778. result.setBit (numBits);
  3779. result.clearBit (numBits); // to enlarge the array
  3780. result.setBit (0);
  3781. int n = 2;
  3782. do
  3783. {
  3784. for (int i = n + n; i < numBits; i += n)
  3785. result.setBit (i);
  3786. n = result.findNextClearBit (n + 1);
  3787. }
  3788. while (n <= (numBits >> 1));
  3789. }
  3790. static void bigSieve (const BigInteger& base, const int numBits, BigInteger& result,
  3791. const BigInteger& smallSieve, const int smallSieveSize)
  3792. {
  3793. jassert (! base[0]); // must be even!
  3794. result.setBit (numBits);
  3795. result.clearBit (numBits); // to enlarge the array
  3796. int index = smallSieve.findNextClearBit (0);
  3797. do
  3798. {
  3799. const int prime = (index << 1) + 1;
  3800. BigInteger r (base), remainder;
  3801. r.divideBy (prime, remainder);
  3802. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3803. if (r.isZero())
  3804. i += prime;
  3805. if ((i & 1) == 0)
  3806. i += prime;
  3807. i = (i - 1) >> 1;
  3808. while (i < numBits)
  3809. {
  3810. result.setBit (i);
  3811. i += prime;
  3812. }
  3813. index = smallSieve.findNextClearBit (index + 1);
  3814. }
  3815. while (index < smallSieveSize);
  3816. }
  3817. static bool findCandidate (const BigInteger& base, const BigInteger& sieve,
  3818. const int numBits, BigInteger& result, const int certainty)
  3819. {
  3820. for (int i = 0; i < numBits; ++i)
  3821. {
  3822. if (! sieve[i])
  3823. {
  3824. result = base + (unsigned int) ((i << 1) + 1);
  3825. if (Primes::isProbablyPrime (result, certainty))
  3826. return true;
  3827. }
  3828. }
  3829. return false;
  3830. }
  3831. static bool passesMillerRabin (const BigInteger& n, int iterations)
  3832. {
  3833. const BigInteger one (1), two (2);
  3834. const BigInteger nMinusOne (n - one);
  3835. BigInteger d (nMinusOne);
  3836. const int s = d.findNextSetBit (0);
  3837. d >>= s;
  3838. BigInteger smallPrimes;
  3839. int numBitsInSmallPrimes = 0;
  3840. for (;;)
  3841. {
  3842. numBitsInSmallPrimes += 256;
  3843. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3844. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3845. if (numPrimesFound > iterations + 1)
  3846. break;
  3847. }
  3848. int smallPrime = 2;
  3849. while (--iterations >= 0)
  3850. {
  3851. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3852. BigInteger r (smallPrime);
  3853. r.exponentModulo (d, n);
  3854. if (r != one && r != nMinusOne)
  3855. {
  3856. for (int j = 0; j < s; ++j)
  3857. {
  3858. r.exponentModulo (two, n);
  3859. if (r == nMinusOne)
  3860. break;
  3861. }
  3862. if (r != nMinusOne)
  3863. return false;
  3864. }
  3865. }
  3866. return true;
  3867. }
  3868. }
  3869. const BigInteger Primes::createProbablePrime (const int bitLength,
  3870. const int certainty,
  3871. const int* randomSeeds,
  3872. int numRandomSeeds)
  3873. {
  3874. using namespace PrimesHelpers;
  3875. int defaultSeeds [16];
  3876. if (numRandomSeeds <= 0)
  3877. {
  3878. randomSeeds = defaultSeeds;
  3879. numRandomSeeds = numElementsInArray (defaultSeeds);
  3880. Random r (0);
  3881. for (int j = 10; --j >= 0;)
  3882. {
  3883. r.setSeedRandomly();
  3884. for (int i = numRandomSeeds; --i >= 0;)
  3885. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3886. }
  3887. }
  3888. BigInteger smallSieve;
  3889. const int smallSieveSize = 15000;
  3890. createSmallSieve (smallSieveSize, smallSieve);
  3891. BigInteger p;
  3892. for (int i = numRandomSeeds; --i >= 0;)
  3893. {
  3894. BigInteger p2;
  3895. Random r (randomSeeds[i]);
  3896. r.fillBitsRandomly (p2, 0, bitLength);
  3897. p ^= p2;
  3898. }
  3899. p.setBit (bitLength - 1);
  3900. p.clearBit (0);
  3901. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3902. while (p.getHighestBit() < bitLength)
  3903. {
  3904. p += 2 * searchLen;
  3905. BigInteger sieve;
  3906. bigSieve (p, searchLen, sieve,
  3907. smallSieve, smallSieveSize);
  3908. BigInteger candidate;
  3909. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3910. return candidate;
  3911. }
  3912. jassertfalse
  3913. return BigInteger();
  3914. }
  3915. bool Primes::isProbablyPrime (const BigInteger& number, const int certainty)
  3916. {
  3917. using namespace PrimesHelpers;
  3918. if (! number[0])
  3919. return false;
  3920. if (number.getHighestBit() <= 10)
  3921. {
  3922. const int num = number.getBitRangeAsInt (0, 10);
  3923. for (int i = num / 2; --i > 1;)
  3924. if (num % i == 0)
  3925. return false;
  3926. return true;
  3927. }
  3928. else
  3929. {
  3930. if (number.findGreatestCommonDivisor (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23) != 1)
  3931. return false;
  3932. return passesMillerRabin (number, certainty);
  3933. }
  3934. }
  3935. END_JUCE_NAMESPACE
  3936. /*** End of inlined file: juce_Primes.cpp ***/
  3937. /*** Start of inlined file: juce_RSAKey.cpp ***/
  3938. BEGIN_JUCE_NAMESPACE
  3939. RSAKey::RSAKey()
  3940. {
  3941. }
  3942. RSAKey::RSAKey (const String& s)
  3943. {
  3944. if (s.containsChar (','))
  3945. {
  3946. part1.parseString (s.upToFirstOccurrenceOf (",", false, false), 16);
  3947. part2.parseString (s.fromFirstOccurrenceOf (",", false, false), 16);
  3948. }
  3949. else
  3950. {
  3951. // the string needs to be two hex numbers, comma-separated..
  3952. jassertfalse;
  3953. }
  3954. }
  3955. RSAKey::~RSAKey()
  3956. {
  3957. }
  3958. const String RSAKey::toString() const
  3959. {
  3960. return part1.toString (16) + "," + part2.toString (16);
  3961. }
  3962. bool RSAKey::applyToValue (BigInteger& value) const
  3963. {
  3964. if (part1.isZero() || part2.isZero() || value <= 0)
  3965. {
  3966. jassertfalse // using an uninitialised key
  3967. value.clear();
  3968. return false;
  3969. }
  3970. BigInteger result;
  3971. while (! value.isZero())
  3972. {
  3973. result *= part2;
  3974. BigInteger remainder;
  3975. value.divideBy (part2, remainder);
  3976. remainder.exponentModulo (part1, part2);
  3977. result += remainder;
  3978. }
  3979. value.swapWith (result);
  3980. return true;
  3981. }
  3982. static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q)
  3983. {
  3984. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  3985. // are fast to divide + multiply
  3986. for (int i = 2; i <= 65536; i *= 2)
  3987. {
  3988. const BigInteger e (1 + i);
  3989. if (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne())
  3990. return e;
  3991. }
  3992. BigInteger e (4);
  3993. while (! (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne()))
  3994. ++e;
  3995. return e;
  3996. }
  3997. void RSAKey::createKeyPair (RSAKey& publicKey, RSAKey& privateKey,
  3998. const int numBits, const int* randomSeeds, const int numRandomSeeds)
  3999. {
  4000. jassert (numBits > 16); // not much point using less than this..
  4001. BigInteger p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4002. BigInteger q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4003. const BigInteger n (p * q);
  4004. const BigInteger m (--p * --q);
  4005. const BigInteger e (findBestCommonDivisor (p, q));
  4006. BigInteger d (e);
  4007. d.inverseModulo (m);
  4008. publicKey.part1 = e;
  4009. publicKey.part2 = n;
  4010. privateKey.part1 = d;
  4011. privateKey.part2 = n;
  4012. }
  4013. END_JUCE_NAMESPACE
  4014. /*** End of inlined file: juce_RSAKey.cpp ***/
  4015. /*** Start of inlined file: juce_InputStream.cpp ***/
  4016. BEGIN_JUCE_NAMESPACE
  4017. char InputStream::readByte()
  4018. {
  4019. char temp = 0;
  4020. read (&temp, 1);
  4021. return temp;
  4022. }
  4023. bool InputStream::readBool()
  4024. {
  4025. return readByte() != 0;
  4026. }
  4027. short InputStream::readShort()
  4028. {
  4029. char temp[2];
  4030. if (read (temp, 2) == 2)
  4031. return (short) ByteOrder::littleEndianShort (temp);
  4032. return 0;
  4033. }
  4034. short InputStream::readShortBigEndian()
  4035. {
  4036. char temp[2];
  4037. if (read (temp, 2) == 2)
  4038. return (short) ByteOrder::bigEndianShort (temp);
  4039. return 0;
  4040. }
  4041. int InputStream::readInt()
  4042. {
  4043. char temp[4];
  4044. if (read (temp, 4) == 4)
  4045. return (int) ByteOrder::littleEndianInt (temp);
  4046. return 0;
  4047. }
  4048. int InputStream::readIntBigEndian()
  4049. {
  4050. char temp[4];
  4051. if (read (temp, 4) == 4)
  4052. return (int) ByteOrder::bigEndianInt (temp);
  4053. return 0;
  4054. }
  4055. int InputStream::readCompressedInt()
  4056. {
  4057. const unsigned char sizeByte = readByte();
  4058. if (sizeByte == 0)
  4059. return 0;
  4060. const int numBytes = (sizeByte & 0x7f);
  4061. if (numBytes > 4)
  4062. {
  4063. jassertfalse // trying to read corrupt data - this method must only be used
  4064. // to read data that was written by OutputStream::writeCompressedInt()
  4065. return 0;
  4066. }
  4067. char bytes[4] = { 0, 0, 0, 0 };
  4068. if (read (bytes, numBytes) != numBytes)
  4069. return 0;
  4070. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4071. return (sizeByte >> 7) ? -num : num;
  4072. }
  4073. int64 InputStream::readInt64()
  4074. {
  4075. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4076. if (read (n.asBytes, 8) == 8)
  4077. return (int64) ByteOrder::swapIfBigEndian (n.asInt64);
  4078. return 0;
  4079. }
  4080. int64 InputStream::readInt64BigEndian()
  4081. {
  4082. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4083. if (read (n.asBytes, 8) == 8)
  4084. return (int64) ByteOrder::swapIfLittleEndian (n.asInt64);
  4085. return 0;
  4086. }
  4087. float InputStream::readFloat()
  4088. {
  4089. // the union below relies on these types being the same size...
  4090. static_jassert (sizeof (int32) == sizeof (float));
  4091. union { int32 asInt; float asFloat; } n;
  4092. n.asInt = (int32) readInt();
  4093. return n.asFloat;
  4094. }
  4095. float InputStream::readFloatBigEndian()
  4096. {
  4097. union { int32 asInt; float asFloat; } n;
  4098. n.asInt = (int32) readIntBigEndian();
  4099. return n.asFloat;
  4100. }
  4101. double InputStream::readDouble()
  4102. {
  4103. union { int64 asInt; double asDouble; } n;
  4104. n.asInt = readInt64();
  4105. return n.asDouble;
  4106. }
  4107. double InputStream::readDoubleBigEndian()
  4108. {
  4109. union { int64 asInt; double asDouble; } n;
  4110. n.asInt = readInt64BigEndian();
  4111. return n.asDouble;
  4112. }
  4113. const String InputStream::readString()
  4114. {
  4115. MemoryBlock buffer (256);
  4116. char* data = static_cast<char*> (buffer.getData());
  4117. size_t i = 0;
  4118. while ((data[i] = readByte()) != 0)
  4119. {
  4120. if (++i >= buffer.getSize())
  4121. {
  4122. buffer.setSize (buffer.getSize() + 512);
  4123. data = static_cast<char*> (buffer.getData());
  4124. }
  4125. }
  4126. return String::fromUTF8 (data, (int) i);
  4127. }
  4128. const String InputStream::readNextLine()
  4129. {
  4130. MemoryBlock buffer (256);
  4131. char* data = static_cast<char*> (buffer.getData());
  4132. size_t i = 0;
  4133. while ((data[i] = readByte()) != 0)
  4134. {
  4135. if (data[i] == '\n')
  4136. break;
  4137. if (data[i] == '\r')
  4138. {
  4139. const int64 lastPos = getPosition();
  4140. if (readByte() != '\n')
  4141. setPosition (lastPos);
  4142. break;
  4143. }
  4144. if (++i >= buffer.getSize())
  4145. {
  4146. buffer.setSize (buffer.getSize() + 512);
  4147. data = static_cast<char*> (buffer.getData());
  4148. }
  4149. }
  4150. return String::fromUTF8 (data, (int) i);
  4151. }
  4152. int InputStream::readIntoMemoryBlock (MemoryBlock& block, int numBytes)
  4153. {
  4154. const int64 totalLength = getTotalLength();
  4155. if (totalLength >= 0)
  4156. {
  4157. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4158. totalLength - getPosition());
  4159. if (numBytes < 0)
  4160. numBytes = totalBytesRemaining;
  4161. else if (numBytes > 0)
  4162. numBytes = jmin (numBytes, totalBytesRemaining);
  4163. else
  4164. return 0;
  4165. }
  4166. const size_t originalBlockSize = block.getSize();
  4167. int totalBytesRead = 0;
  4168. if (numBytes > 0)
  4169. {
  4170. // know how many bytes we want, so we can resize the block first..
  4171. block.setSize (originalBlockSize + numBytes, false);
  4172. totalBytesRead = read (static_cast<char*> (block.getData()) + originalBlockSize, numBytes);
  4173. }
  4174. else
  4175. {
  4176. // read until end of stram..
  4177. const int chunkSize = 32768;
  4178. for (;;)
  4179. {
  4180. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4181. const int bytesJustIn = read (static_cast<char*> (block.getData())
  4182. + originalBlockSize
  4183. + totalBytesRead,
  4184. chunkSize);
  4185. if (bytesJustIn == 0)
  4186. break;
  4187. totalBytesRead += bytesJustIn;
  4188. }
  4189. }
  4190. // trim off any excess left at the end
  4191. block.setSize (originalBlockSize + totalBytesRead, false);
  4192. return totalBytesRead;
  4193. }
  4194. const String InputStream::readEntireStreamAsString()
  4195. {
  4196. MemoryBlock mb;
  4197. const int size = readIntoMemoryBlock (mb);
  4198. return String::createStringFromData (static_cast<const char*> (mb.getData()), size);
  4199. }
  4200. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4201. {
  4202. if (numBytesToSkip > 0)
  4203. {
  4204. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4205. HeapBlock<char> temp (skipBufferSize);
  4206. while (numBytesToSkip > 0 && ! isExhausted())
  4207. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4208. }
  4209. }
  4210. END_JUCE_NAMESPACE
  4211. /*** End of inlined file: juce_InputStream.cpp ***/
  4212. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4213. BEGIN_JUCE_NAMESPACE
  4214. #if JUCE_DEBUG
  4215. static CriticalSection activeStreamLock;
  4216. static VoidArray activeStreams;
  4217. void juce_CheckForDanglingStreams()
  4218. {
  4219. /*
  4220. It's always a bad idea to leak any object, but if you're leaking output
  4221. streams, then there's a good chance that you're failing to flush a file
  4222. to disk properly, which could result in corrupted data and other similar
  4223. nastiness..
  4224. */
  4225. jassert (activeStreams.size() == 0);
  4226. };
  4227. #endif
  4228. OutputStream::OutputStream()
  4229. {
  4230. #if JUCE_DEBUG
  4231. const ScopedLock sl (activeStreamLock);
  4232. activeStreams.add (this);
  4233. #endif
  4234. }
  4235. OutputStream::~OutputStream()
  4236. {
  4237. #if JUCE_DEBUG
  4238. const ScopedLock sl (activeStreamLock);
  4239. activeStreams.removeValue (this);
  4240. #endif
  4241. }
  4242. void OutputStream::writeBool (const bool b)
  4243. {
  4244. writeByte (b ? (char) 1
  4245. : (char) 0);
  4246. }
  4247. void OutputStream::writeByte (char byte)
  4248. {
  4249. write (&byte, 1);
  4250. }
  4251. void OutputStream::writeShort (short value)
  4252. {
  4253. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4254. write (&v, 2);
  4255. }
  4256. void OutputStream::writeShortBigEndian (short value)
  4257. {
  4258. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4259. write (&v, 2);
  4260. }
  4261. void OutputStream::writeInt (int value)
  4262. {
  4263. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4264. write (&v, 4);
  4265. }
  4266. void OutputStream::writeIntBigEndian (int value)
  4267. {
  4268. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4269. write (&v, 4);
  4270. }
  4271. void OutputStream::writeCompressedInt (int value)
  4272. {
  4273. unsigned int un = (value < 0) ? (unsigned int) -value
  4274. : (unsigned int) value;
  4275. uint8 data[5];
  4276. int num = 0;
  4277. while (un > 0)
  4278. {
  4279. data[++num] = (uint8) un;
  4280. un >>= 8;
  4281. }
  4282. data[0] = (uint8) num;
  4283. if (value < 0)
  4284. data[0] |= 0x80;
  4285. write (data, num + 1);
  4286. }
  4287. void OutputStream::writeInt64 (int64 value)
  4288. {
  4289. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4290. write (&v, 8);
  4291. }
  4292. void OutputStream::writeInt64BigEndian (int64 value)
  4293. {
  4294. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4295. write (&v, 8);
  4296. }
  4297. void OutputStream::writeFloat (float value)
  4298. {
  4299. union { int asInt; float asFloat; } n;
  4300. n.asFloat = value;
  4301. writeInt (n.asInt);
  4302. }
  4303. void OutputStream::writeFloatBigEndian (float value)
  4304. {
  4305. union { int asInt; float asFloat; } n;
  4306. n.asFloat = value;
  4307. writeIntBigEndian (n.asInt);
  4308. }
  4309. void OutputStream::writeDouble (double value)
  4310. {
  4311. union { int64 asInt; double asDouble; } n;
  4312. n.asDouble = value;
  4313. writeInt64 (n.asInt);
  4314. }
  4315. void OutputStream::writeDoubleBigEndian (double value)
  4316. {
  4317. union { int64 asInt; double asDouble; } n;
  4318. n.asDouble = value;
  4319. writeInt64BigEndian (n.asInt);
  4320. }
  4321. void OutputStream::writeString (const String& text)
  4322. {
  4323. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4324. // if lots of large, persistent strings were to be written to streams).
  4325. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4326. HeapBlock<char> temp (numBytes);
  4327. text.copyToUTF8 (temp, numBytes);
  4328. write (temp, numBytes);
  4329. }
  4330. void OutputStream::writeText (const String& text, const bool asUnicode,
  4331. const bool writeUnicodeHeaderBytes)
  4332. {
  4333. if (asUnicode)
  4334. {
  4335. if (writeUnicodeHeaderBytes)
  4336. write ("\x0ff\x0fe", 2);
  4337. const juce_wchar* src = text;
  4338. bool lastCharWasReturn = false;
  4339. while (*src != 0)
  4340. {
  4341. if (*src == L'\n' && ! lastCharWasReturn)
  4342. writeShort ((short) L'\r');
  4343. lastCharWasReturn = (*src == L'\r');
  4344. writeShort ((short) *src++);
  4345. }
  4346. }
  4347. else
  4348. {
  4349. const char* src = text.toUTF8();
  4350. const char* t = src;
  4351. for (;;)
  4352. {
  4353. if (*t == '\n')
  4354. {
  4355. if (t > src)
  4356. write (src, (int) (t - src));
  4357. write ("\r\n", 2);
  4358. src = t + 1;
  4359. }
  4360. else if (*t == '\r')
  4361. {
  4362. if (t[1] == '\n')
  4363. ++t;
  4364. }
  4365. else if (*t == 0)
  4366. {
  4367. if (t > src)
  4368. write (src, (int) (t - src));
  4369. break;
  4370. }
  4371. ++t;
  4372. }
  4373. }
  4374. }
  4375. int OutputStream::writeFromInputStream (InputStream& source, int64 numBytesToWrite)
  4376. {
  4377. if (numBytesToWrite < 0)
  4378. numBytesToWrite = std::numeric_limits<int64>::max();
  4379. int numWritten = 0;
  4380. while (numBytesToWrite > 0 && ! source.isExhausted())
  4381. {
  4382. char buffer [8192];
  4383. const int num = source.read (buffer, (int) jmin (numBytesToWrite, (int64) sizeof (buffer)));
  4384. if (num <= 0)
  4385. break;
  4386. write (buffer, num);
  4387. numBytesToWrite -= num;
  4388. numWritten += num;
  4389. }
  4390. return numWritten;
  4391. }
  4392. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4393. {
  4394. return stream << String (number);
  4395. }
  4396. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4397. {
  4398. return stream << String (number);
  4399. }
  4400. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4401. {
  4402. stream.writeByte (character);
  4403. return stream;
  4404. }
  4405. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4406. {
  4407. stream.write (text, (int) strlen (text));
  4408. return stream;
  4409. }
  4410. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryBlock& data)
  4411. {
  4412. stream.write (data.getData(), (int) data.getSize());
  4413. return stream;
  4414. }
  4415. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const File& fileToRead)
  4416. {
  4417. const ScopedPointer<FileInputStream> in (fileToRead.createInputStream());
  4418. if (in != 0)
  4419. stream.writeFromInputStream (*in, -1);
  4420. return stream;
  4421. }
  4422. END_JUCE_NAMESPACE
  4423. /*** End of inlined file: juce_OutputStream.cpp ***/
  4424. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4425. BEGIN_JUCE_NAMESPACE
  4426. DirectoryIterator::DirectoryIterator (const File& directory,
  4427. bool isRecursive_,
  4428. const String& wildCard_,
  4429. const int whatToLookFor_)
  4430. : fileFinder (directory, isRecursive ? "*" : wildCard_),
  4431. wildCard (wildCard_),
  4432. path (File::addTrailingSeparator (directory.getFullPathName())),
  4433. index (-1),
  4434. totalNumFiles (-1),
  4435. whatToLookFor (whatToLookFor_),
  4436. isRecursive (isRecursive_)
  4437. {
  4438. // you have to specify the type of files you're looking for!
  4439. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4440. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4441. }
  4442. DirectoryIterator::~DirectoryIterator()
  4443. {
  4444. }
  4445. bool DirectoryIterator::next()
  4446. {
  4447. return next (0, 0, 0, 0, 0, 0);
  4448. }
  4449. bool DirectoryIterator::next (bool* const isDirResult, bool* const isHiddenResult, int64* const fileSize,
  4450. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  4451. {
  4452. if (subIterator != 0)
  4453. {
  4454. if (subIterator->next (isDirResult, isHiddenResult, fileSize, modTime, creationTime, isReadOnly))
  4455. return true;
  4456. subIterator = 0;
  4457. }
  4458. String filename;
  4459. bool isDirectory, isHidden;
  4460. while (fileFinder.next (filename, &isDirectory, &isHidden, fileSize, modTime, creationTime, isReadOnly))
  4461. {
  4462. ++index;
  4463. if (! filename.containsOnly ("."))
  4464. {
  4465. const File fileFound (path + filename, 0);
  4466. bool matches = false;
  4467. if (isDirectory)
  4468. {
  4469. if (isRecursive && ((whatToLookFor & File::ignoreHiddenFiles) == 0 || ! isHidden))
  4470. subIterator = new DirectoryIterator (fileFound, true, wildCard, whatToLookFor);
  4471. matches = (whatToLookFor & File::findDirectories) != 0;
  4472. }
  4473. else
  4474. {
  4475. matches = (whatToLookFor & File::findFiles) != 0;
  4476. }
  4477. // if recursive, we're not relying on the OS iterator to do the wildcard match, so do it now..
  4478. if (matches && isRecursive)
  4479. matches = filename.matchesWildcard (wildCard, ! File::areFileNamesCaseSensitive());
  4480. if (matches && (whatToLookFor & File::ignoreHiddenFiles) != 0)
  4481. matches = ! isHidden;
  4482. if (matches)
  4483. {
  4484. currentFile = fileFound;
  4485. if (isHiddenResult != 0) *isHiddenResult = isHidden;
  4486. if (isDirResult != 0) *isDirResult = isDirectory;
  4487. return true;
  4488. }
  4489. else if (subIterator != 0)
  4490. {
  4491. return next();
  4492. }
  4493. }
  4494. }
  4495. return false;
  4496. }
  4497. const File DirectoryIterator::getFile() const
  4498. {
  4499. if (subIterator != 0)
  4500. return subIterator->getFile();
  4501. return currentFile;
  4502. }
  4503. float DirectoryIterator::getEstimatedProgress() const
  4504. {
  4505. if (totalNumFiles < 0)
  4506. totalNumFiles = File (path).getNumberOfChildFiles (File::findFilesAndDirectories);
  4507. if (totalNumFiles <= 0)
  4508. return 0.0f;
  4509. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4510. : (float) index;
  4511. return detailedIndex / totalNumFiles;
  4512. }
  4513. END_JUCE_NAMESPACE
  4514. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4515. /*** Start of inlined file: juce_File.cpp ***/
  4516. #if ! JUCE_WINDOWS
  4517. #include <pwd.h>
  4518. #endif
  4519. BEGIN_JUCE_NAMESPACE
  4520. File::File (const String& fullPathName)
  4521. : fullPath (parseAbsolutePath (fullPathName))
  4522. {
  4523. }
  4524. File::File (const String& path, int)
  4525. : fullPath (path)
  4526. {
  4527. }
  4528. const File File::createFileWithoutCheckingPath (const String& path)
  4529. {
  4530. return File (path, 0);
  4531. }
  4532. File::File (const File& other)
  4533. : fullPath (other.fullPath)
  4534. {
  4535. }
  4536. File& File::operator= (const String& newPath)
  4537. {
  4538. fullPath = parseAbsolutePath (newPath);
  4539. return *this;
  4540. }
  4541. File& File::operator= (const File& other)
  4542. {
  4543. fullPath = other.fullPath;
  4544. return *this;
  4545. }
  4546. const File File::nonexistent;
  4547. const String File::parseAbsolutePath (const String& p)
  4548. {
  4549. if (p.isEmpty())
  4550. return String::empty;
  4551. #if JUCE_WINDOWS
  4552. // Windows..
  4553. String path (p.replaceCharacter ('/', '\\'));
  4554. if (path.startsWithChar (File::separator))
  4555. {
  4556. if (path[1] != File::separator)
  4557. {
  4558. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4559. If you're trying to parse a string that may be either a relative path or an absolute path,
  4560. you MUST provide a context against which the partial path can be evaluated - you can do
  4561. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4562. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4563. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4564. */
  4565. jassertfalse
  4566. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4567. }
  4568. }
  4569. else if (! path.containsChar (':'))
  4570. {
  4571. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4572. If you're trying to parse a string that may be either a relative path or an absolute path,
  4573. you MUST provide a context against which the partial path can be evaluated - you can do
  4574. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4575. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4576. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4577. */
  4578. jassertfalse
  4579. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4580. }
  4581. #else
  4582. // Mac or Linux..
  4583. String path (p.replaceCharacter ('\\', '/'));
  4584. if (path.startsWithChar ('~'))
  4585. {
  4586. if (path[1] == File::separator || path[1] == 0)
  4587. {
  4588. // expand a name of the form "~/abc"
  4589. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4590. + path.substring (1);
  4591. }
  4592. else
  4593. {
  4594. // expand a name of type "~dave/abc"
  4595. const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false));
  4596. struct passwd* const pw = getpwnam (userName.toUTF8());
  4597. if (pw != 0)
  4598. path = addTrailingSeparator (pw->pw_dir) + path.fromFirstOccurrenceOf ("/", false, false);
  4599. }
  4600. }
  4601. else if (! path.startsWithChar (File::separator))
  4602. {
  4603. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4604. If you're trying to parse a string that may be either a relative path or an absolute path,
  4605. you MUST provide a context against which the partial path can be evaluated - you can do
  4606. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4607. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4608. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4609. */
  4610. jassert (path.startsWith ("./") || path.startsWith ("../")); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4611. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4612. }
  4613. #endif
  4614. return path.trimCharactersAtEnd (separatorString);
  4615. }
  4616. const String File::addTrailingSeparator (const String& path)
  4617. {
  4618. return path.endsWithChar (File::separator) ? path
  4619. : path + File::separator;
  4620. }
  4621. #if JUCE_LINUX
  4622. #define NAMES_ARE_CASE_SENSITIVE 1
  4623. #endif
  4624. bool File::areFileNamesCaseSensitive()
  4625. {
  4626. #if NAMES_ARE_CASE_SENSITIVE
  4627. return true;
  4628. #else
  4629. return false;
  4630. #endif
  4631. }
  4632. bool File::operator== (const File& other) const
  4633. {
  4634. #if NAMES_ARE_CASE_SENSITIVE
  4635. return fullPath == other.fullPath;
  4636. #else
  4637. return fullPath.equalsIgnoreCase (other.fullPath);
  4638. #endif
  4639. }
  4640. bool File::operator!= (const File& other) const
  4641. {
  4642. return ! operator== (other);
  4643. }
  4644. bool File::operator< (const File& other) const
  4645. {
  4646. #if NAMES_ARE_CASE_SENSITIVE
  4647. return fullPath < other.fullPath;
  4648. #else
  4649. return fullPath.compareIgnoreCase (other.fullPath) < 0;
  4650. #endif
  4651. }
  4652. bool File::operator> (const File& other) const
  4653. {
  4654. #if NAMES_ARE_CASE_SENSITIVE
  4655. return fullPath > other.fullPath;
  4656. #else
  4657. return fullPath.compareIgnoreCase (other.fullPath) > 0;
  4658. #endif
  4659. }
  4660. bool File::setReadOnly (const bool shouldBeReadOnly,
  4661. const bool applyRecursively) const
  4662. {
  4663. bool worked = true;
  4664. if (applyRecursively && isDirectory())
  4665. {
  4666. Array <File> subFiles;
  4667. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4668. for (int i = subFiles.size(); --i >= 0;)
  4669. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4670. }
  4671. return setFileReadOnlyInternal (shouldBeReadOnly) && worked;
  4672. }
  4673. bool File::deleteRecursively() const
  4674. {
  4675. bool worked = true;
  4676. if (isDirectory())
  4677. {
  4678. Array<File> subFiles;
  4679. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4680. for (int i = subFiles.size(); --i >= 0;)
  4681. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4682. }
  4683. return deleteFile() && worked;
  4684. }
  4685. bool File::moveFileTo (const File& newFile) const
  4686. {
  4687. if (newFile.fullPath == fullPath)
  4688. return true;
  4689. #if ! NAMES_ARE_CASE_SENSITIVE
  4690. if (*this != newFile)
  4691. #endif
  4692. if (! newFile.deleteFile())
  4693. return false;
  4694. return moveInternal (newFile);
  4695. }
  4696. bool File::copyFileTo (const File& newFile) const
  4697. {
  4698. return (*this == newFile)
  4699. || (exists() && newFile.deleteFile() && copyInternal (newFile));
  4700. }
  4701. bool File::copyDirectoryTo (const File& newDirectory) const
  4702. {
  4703. if (isDirectory() && newDirectory.createDirectory())
  4704. {
  4705. Array<File> subFiles;
  4706. findChildFiles (subFiles, File::findFiles, false);
  4707. int i;
  4708. for (i = 0; i < subFiles.size(); ++i)
  4709. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4710. return false;
  4711. subFiles.clear();
  4712. findChildFiles (subFiles, File::findDirectories, false);
  4713. for (i = 0; i < subFiles.size(); ++i)
  4714. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4715. return false;
  4716. return true;
  4717. }
  4718. return false;
  4719. }
  4720. const String File::getPathUpToLastSlash() const
  4721. {
  4722. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4723. if (lastSlash > 0)
  4724. return fullPath.substring (0, lastSlash);
  4725. else if (lastSlash == 0)
  4726. return separatorString;
  4727. else
  4728. return fullPath;
  4729. }
  4730. const File File::getParentDirectory() const
  4731. {
  4732. return File (getPathUpToLastSlash());
  4733. }
  4734. const String File::getFileName() const
  4735. {
  4736. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4737. }
  4738. int File::hashCode() const
  4739. {
  4740. return fullPath.hashCode();
  4741. }
  4742. int64 File::hashCode64() const
  4743. {
  4744. return fullPath.hashCode64();
  4745. }
  4746. const String File::getFileNameWithoutExtension() const
  4747. {
  4748. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4749. const int lastDot = fullPath.lastIndexOfChar ('.');
  4750. if (lastDot > lastSlash)
  4751. return fullPath.substring (lastSlash, lastDot);
  4752. else
  4753. return fullPath.substring (lastSlash);
  4754. }
  4755. bool File::isAChildOf (const File& potentialParent) const
  4756. {
  4757. if (potentialParent == File::nonexistent)
  4758. return false;
  4759. const String ourPath (getPathUpToLastSlash());
  4760. #if NAMES_ARE_CASE_SENSITIVE
  4761. if (potentialParent.fullPath == ourPath)
  4762. #else
  4763. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4764. #endif
  4765. {
  4766. return true;
  4767. }
  4768. else if (potentialParent.fullPath.length() >= ourPath.length())
  4769. {
  4770. return false;
  4771. }
  4772. else
  4773. {
  4774. return getParentDirectory().isAChildOf (potentialParent);
  4775. }
  4776. }
  4777. bool File::isAbsolutePath (const String& path)
  4778. {
  4779. return path.startsWithChar ('/') || path.startsWithChar ('\\')
  4780. #if JUCE_WINDOWS
  4781. || (path.isNotEmpty() && path[1] == ':');
  4782. #else
  4783. || path.startsWithChar ('~');
  4784. #endif
  4785. }
  4786. const File File::getChildFile (String relativePath) const
  4787. {
  4788. if (isAbsolutePath (relativePath))
  4789. {
  4790. // the path is really absolute..
  4791. return File (relativePath);
  4792. }
  4793. else
  4794. {
  4795. // it's relative, so remove any ../ or ./ bits at the start.
  4796. String path (fullPath);
  4797. if (relativePath[0] == '.')
  4798. {
  4799. #if JUCE_WINDOWS
  4800. relativePath = relativePath.replaceCharacter ('/', '\\').trimStart();
  4801. #else
  4802. relativePath = relativePath.replaceCharacter ('\\', '/').trimStart();
  4803. #endif
  4804. while (relativePath[0] == '.')
  4805. {
  4806. if (relativePath[1] == '.')
  4807. {
  4808. if (relativePath [2] == 0 || relativePath[2] == separator)
  4809. {
  4810. const int lastSlash = path.lastIndexOfChar (separator);
  4811. if (lastSlash >= 0)
  4812. path = path.substring (0, lastSlash);
  4813. relativePath = relativePath.substring (3);
  4814. }
  4815. else
  4816. {
  4817. break;
  4818. }
  4819. }
  4820. else if (relativePath[1] == separator)
  4821. {
  4822. relativePath = relativePath.substring (2);
  4823. }
  4824. else
  4825. {
  4826. break;
  4827. }
  4828. }
  4829. }
  4830. return File (addTrailingSeparator (path) + relativePath);
  4831. }
  4832. }
  4833. const File File::getSiblingFile (const String& fileName) const
  4834. {
  4835. return getParentDirectory().getChildFile (fileName);
  4836. }
  4837. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4838. {
  4839. if (bytes == 1)
  4840. {
  4841. return "1 byte";
  4842. }
  4843. else if (bytes < 1024)
  4844. {
  4845. return String ((int) bytes) + " bytes";
  4846. }
  4847. else if (bytes < 1024 * 1024)
  4848. {
  4849. return String (bytes / 1024.0, 1) + " KB";
  4850. }
  4851. else if (bytes < 1024 * 1024 * 1024)
  4852. {
  4853. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4854. }
  4855. else
  4856. {
  4857. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4858. }
  4859. }
  4860. bool File::create() const
  4861. {
  4862. if (exists())
  4863. return true;
  4864. {
  4865. const File parentDir (getParentDirectory());
  4866. if (parentDir == *this || ! parentDir.createDirectory())
  4867. return false;
  4868. FileOutputStream fo (*this, 8);
  4869. }
  4870. return exists();
  4871. }
  4872. bool File::createDirectory() const
  4873. {
  4874. if (! isDirectory())
  4875. {
  4876. const File parentDir (getParentDirectory());
  4877. if (parentDir == *this || ! parentDir.createDirectory())
  4878. return false;
  4879. createDirectoryInternal (fullPath.trimCharactersAtEnd (separatorString));
  4880. return isDirectory();
  4881. }
  4882. return true;
  4883. }
  4884. const Time File::getCreationTime() const
  4885. {
  4886. int64 m, a, c;
  4887. getFileTimesInternal (m, a, c);
  4888. return Time (c);
  4889. }
  4890. const Time File::getLastModificationTime() const
  4891. {
  4892. int64 m, a, c;
  4893. getFileTimesInternal (m, a, c);
  4894. return Time (m);
  4895. }
  4896. const Time File::getLastAccessTime() const
  4897. {
  4898. int64 m, a, c;
  4899. getFileTimesInternal (m, a, c);
  4900. return Time (a);
  4901. }
  4902. bool File::setLastModificationTime (const Time& t) const { return setFileTimesInternal (t.toMilliseconds(), 0, 0); }
  4903. bool File::setLastAccessTime (const Time& t) const { return setFileTimesInternal (0, t.toMilliseconds(), 0); }
  4904. bool File::setCreationTime (const Time& t) const { return setFileTimesInternal (0, 0, t.toMilliseconds()); }
  4905. bool File::loadFileAsData (MemoryBlock& destBlock) const
  4906. {
  4907. if (! existsAsFile())
  4908. return false;
  4909. FileInputStream in (*this);
  4910. return getSize() == in.readIntoMemoryBlock (destBlock);
  4911. }
  4912. const String File::loadFileAsString() const
  4913. {
  4914. if (! existsAsFile())
  4915. return String::empty;
  4916. FileInputStream in (*this);
  4917. return in.readEntireStreamAsString();
  4918. }
  4919. bool File::fileTypeMatches (const int whatToLookFor, const bool isDir, const bool isHidden)
  4920. {
  4921. return (whatToLookFor & (isDir ? findDirectories
  4922. : findFiles)) != 0
  4923. && ((! isHidden) || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  4924. }
  4925. int File::findChildFiles (Array<File>& results,
  4926. const int whatToLookFor,
  4927. const bool searchRecursively,
  4928. const String& wildCardPattern) const
  4929. {
  4930. // you have to specify the type of files you're looking for!
  4931. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  4932. int total = 0;
  4933. if (isDirectory())
  4934. {
  4935. // find child files or directories in this directory first..
  4936. String path (addTrailingSeparator (fullPath)), filename;
  4937. bool itemIsDirectory, itemIsHidden;
  4938. DirectoryIterator::NativeIterator i (path, wildCardPattern);
  4939. while (i.next (filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0))
  4940. {
  4941. if (! filename.containsOnly ("."))
  4942. {
  4943. const File fileFound (path + filename, 0);
  4944. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden))
  4945. {
  4946. results.add (fileFound);
  4947. ++total;
  4948. }
  4949. if (searchRecursively && itemIsDirectory
  4950. && fileTypeMatches (whatToLookFor | findDirectories, true, itemIsHidden))
  4951. {
  4952. total += fileFound.findChildFiles (results, whatToLookFor, true, wildCardPattern);
  4953. }
  4954. }
  4955. }
  4956. }
  4957. return total;
  4958. }
  4959. int File::getNumberOfChildFiles (const int whatToLookFor,
  4960. const String& wildCardPattern) const
  4961. {
  4962. // you have to specify the type of files you're looking for!
  4963. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  4964. int count = 0;
  4965. if (isDirectory())
  4966. {
  4967. String filename;
  4968. bool itemIsDirectory, itemIsHidden;
  4969. DirectoryIterator::NativeIterator i (*this, wildCardPattern);
  4970. while (i.next (filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0))
  4971. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  4972. && ! filename.containsOnly ("."))
  4973. ++count;
  4974. }
  4975. else
  4976. {
  4977. // trying to search for files inside a non-directory?
  4978. jassertfalse
  4979. }
  4980. return count;
  4981. }
  4982. bool File::containsSubDirectories() const
  4983. {
  4984. if (isDirectory())
  4985. {
  4986. String filename;
  4987. bool itemIsDirectory;
  4988. DirectoryIterator::NativeIterator i (*this, "*");
  4989. while (i.next (filename, &itemIsDirectory, 0, 0, 0, 0, 0))
  4990. if (itemIsDirectory)
  4991. return true;
  4992. }
  4993. return false;
  4994. }
  4995. const File File::getNonexistentChildFile (const String& prefix_,
  4996. const String& suffix,
  4997. bool putNumbersInBrackets) const
  4998. {
  4999. File f (getChildFile (prefix_ + suffix));
  5000. if (f.exists())
  5001. {
  5002. int num = 2;
  5003. String prefix (prefix_);
  5004. // remove any bracketed numbers that may already be on the end..
  5005. if (prefix.trim().endsWithChar (')'))
  5006. {
  5007. putNumbersInBrackets = true;
  5008. const int openBracks = prefix.lastIndexOfChar ('(');
  5009. const int closeBracks = prefix.lastIndexOfChar (')');
  5010. if (openBracks > 0
  5011. && closeBracks > openBracks
  5012. && prefix.substring (openBracks + 1, closeBracks).containsOnly ("0123456789"))
  5013. {
  5014. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5015. prefix = prefix.substring (0, openBracks);
  5016. }
  5017. }
  5018. // also use brackets if it ends in a digit.
  5019. putNumbersInBrackets = putNumbersInBrackets
  5020. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5021. do
  5022. {
  5023. if (putNumbersInBrackets)
  5024. f = getChildFile (prefix + '(' + String (num++) + ')' + suffix);
  5025. else
  5026. f = getChildFile (prefix + String (num++) + suffix);
  5027. } while (f.exists());
  5028. }
  5029. return f;
  5030. }
  5031. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5032. {
  5033. if (exists())
  5034. {
  5035. return getParentDirectory()
  5036. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5037. getFileExtension(),
  5038. putNumbersInBrackets);
  5039. }
  5040. else
  5041. {
  5042. return *this;
  5043. }
  5044. }
  5045. const String File::getFileExtension() const
  5046. {
  5047. String ext;
  5048. if (! isDirectory())
  5049. {
  5050. const int indexOfDot = fullPath.lastIndexOfChar ('.');
  5051. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5052. ext = fullPath.substring (indexOfDot);
  5053. }
  5054. return ext;
  5055. }
  5056. bool File::hasFileExtension (const String& possibleSuffix) const
  5057. {
  5058. if (possibleSuffix.isEmpty())
  5059. return fullPath.lastIndexOfChar ('.') <= fullPath.lastIndexOfChar (separator);
  5060. const int semicolon = possibleSuffix.indexOfChar (0, ';');
  5061. if (semicolon >= 0)
  5062. {
  5063. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5064. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5065. }
  5066. else
  5067. {
  5068. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5069. {
  5070. if (possibleSuffix.startsWithChar ('.'))
  5071. return true;
  5072. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5073. if (dotPos >= 0)
  5074. return fullPath [dotPos] == '.';
  5075. }
  5076. }
  5077. return false;
  5078. }
  5079. const File File::withFileExtension (const String& newExtension) const
  5080. {
  5081. if (fullPath.isEmpty())
  5082. return File::nonexistent;
  5083. String filePart (getFileName());
  5084. int i = filePart.lastIndexOfChar ('.');
  5085. if (i >= 0)
  5086. filePart = filePart.substring (0, i);
  5087. if (newExtension.isNotEmpty() && ! newExtension.startsWithChar ('.'))
  5088. filePart << '.';
  5089. return getSiblingFile (filePart + newExtension);
  5090. }
  5091. bool File::startAsProcess (const String& parameters) const
  5092. {
  5093. return exists() && PlatformUtilities::openDocument (fullPath, parameters);
  5094. }
  5095. FileInputStream* File::createInputStream() const
  5096. {
  5097. if (existsAsFile())
  5098. return new FileInputStream (*this);
  5099. return 0;
  5100. }
  5101. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5102. {
  5103. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5104. if (out->failedToOpen())
  5105. return 0;
  5106. return out.release();
  5107. }
  5108. bool File::appendData (const void* const dataToAppend,
  5109. const int numberOfBytes) const
  5110. {
  5111. if (numberOfBytes > 0)
  5112. {
  5113. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5114. if (out == 0)
  5115. return false;
  5116. out->write (dataToAppend, numberOfBytes);
  5117. }
  5118. return true;
  5119. }
  5120. bool File::replaceWithData (const void* const dataToWrite,
  5121. const int numberOfBytes) const
  5122. {
  5123. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5124. if (numberOfBytes <= 0)
  5125. return deleteFile();
  5126. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5127. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5128. return tempFile.overwriteTargetFileWithTemporary();
  5129. }
  5130. bool File::appendText (const String& text,
  5131. const bool asUnicode,
  5132. const bool writeUnicodeHeaderBytes) const
  5133. {
  5134. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5135. if (out != 0)
  5136. {
  5137. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5138. return true;
  5139. }
  5140. return false;
  5141. }
  5142. bool File::replaceWithText (const String& textToWrite,
  5143. const bool asUnicode,
  5144. const bool writeUnicodeHeaderBytes) const
  5145. {
  5146. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5147. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5148. return tempFile.overwriteTargetFileWithTemporary();
  5149. }
  5150. const String File::createLegalPathName (const String& original)
  5151. {
  5152. String s (original);
  5153. String start;
  5154. if (s[1] == ':')
  5155. {
  5156. start = s.substring (0, 2);
  5157. s = s.substring (2);
  5158. }
  5159. return start + s.removeCharacters ("\"#@,;:<>*^|?")
  5160. .substring (0, 1024);
  5161. }
  5162. const String File::createLegalFileName (const String& original)
  5163. {
  5164. String s (original.removeCharacters ("\"#@,;:<>*^|?\\/"));
  5165. const int maxLength = 128; // only the length of the filename, not the whole path
  5166. const int len = s.length();
  5167. if (len > maxLength)
  5168. {
  5169. const int lastDot = s.lastIndexOfChar ('.');
  5170. if (lastDot > jmax (0, len - 12))
  5171. {
  5172. s = s.substring (0, maxLength - (len - lastDot))
  5173. + s.substring (lastDot);
  5174. }
  5175. else
  5176. {
  5177. s = s.substring (0, maxLength);
  5178. }
  5179. }
  5180. return s;
  5181. }
  5182. const String File::getRelativePathFrom (const File& dir) const
  5183. {
  5184. String thisPath (fullPath);
  5185. {
  5186. int len = thisPath.length();
  5187. while (--len >= 0 && thisPath [len] == File::separator)
  5188. thisPath [len] = 0;
  5189. }
  5190. String dirPath (addTrailingSeparator (dir.existsAsFile() ? dir.getParentDirectory().getFullPathName()
  5191. : dir.fullPath));
  5192. const int len = jmin (thisPath.length(), dirPath.length());
  5193. int commonBitLength = 0;
  5194. for (int i = 0; i < len; ++i)
  5195. {
  5196. #if NAMES_ARE_CASE_SENSITIVE
  5197. if (thisPath[i] != dirPath[i])
  5198. #else
  5199. if (CharacterFunctions::toLowerCase (thisPath[i])
  5200. != CharacterFunctions::toLowerCase (dirPath[i]))
  5201. #endif
  5202. {
  5203. break;
  5204. }
  5205. ++commonBitLength;
  5206. }
  5207. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5208. --commonBitLength;
  5209. // if the only common bit is the root, then just return the full path..
  5210. if (commonBitLength <= 0
  5211. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5212. return fullPath;
  5213. thisPath = thisPath.substring (commonBitLength);
  5214. dirPath = dirPath.substring (commonBitLength);
  5215. while (dirPath.isNotEmpty())
  5216. {
  5217. #if JUCE_WINDOWS
  5218. thisPath = "..\\" + thisPath;
  5219. #else
  5220. thisPath = "../" + thisPath;
  5221. #endif
  5222. const int sep = dirPath.indexOfChar (separator);
  5223. if (sep >= 0)
  5224. dirPath = dirPath.substring (sep + 1);
  5225. else
  5226. dirPath = String::empty;
  5227. }
  5228. return thisPath;
  5229. }
  5230. const File File::createTempFile (const String& fileNameEnding)
  5231. {
  5232. const File tempFile (getSpecialLocation (tempDirectory)
  5233. .getChildFile ("temp_" + String (Random::getSystemRandom().nextInt()))
  5234. .withFileExtension (fileNameEnding));
  5235. if (tempFile.exists())
  5236. return createTempFile (fileNameEnding);
  5237. else
  5238. return tempFile;
  5239. }
  5240. END_JUCE_NAMESPACE
  5241. /*** End of inlined file: juce_File.cpp ***/
  5242. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5243. BEGIN_JUCE_NAMESPACE
  5244. void* juce_fileOpen (const File& file, bool forWriting);
  5245. void juce_fileClose (void* handle);
  5246. int juce_fileRead (void* handle, void* buffer, int size);
  5247. int64 juce_fileSetPosition (void* handle, int64 pos);
  5248. FileInputStream::FileInputStream (const File& f)
  5249. : file (f),
  5250. currentPosition (0),
  5251. needToSeek (true)
  5252. {
  5253. totalSize = f.getSize();
  5254. fileHandle = juce_fileOpen (f, false);
  5255. }
  5256. FileInputStream::~FileInputStream()
  5257. {
  5258. juce_fileClose (fileHandle);
  5259. }
  5260. int64 FileInputStream::getTotalLength()
  5261. {
  5262. return totalSize;
  5263. }
  5264. int FileInputStream::read (void* buffer, int bytesToRead)
  5265. {
  5266. int num = 0;
  5267. if (needToSeek)
  5268. {
  5269. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5270. return 0;
  5271. needToSeek = false;
  5272. }
  5273. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5274. currentPosition += num;
  5275. return num;
  5276. }
  5277. bool FileInputStream::isExhausted()
  5278. {
  5279. return currentPosition >= totalSize;
  5280. }
  5281. int64 FileInputStream::getPosition()
  5282. {
  5283. return currentPosition;
  5284. }
  5285. bool FileInputStream::setPosition (int64 pos)
  5286. {
  5287. pos = jlimit ((int64) 0, totalSize, pos);
  5288. needToSeek |= (currentPosition != pos);
  5289. currentPosition = pos;
  5290. return true;
  5291. }
  5292. END_JUCE_NAMESPACE
  5293. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5294. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5295. BEGIN_JUCE_NAMESPACE
  5296. void* juce_fileOpen (const File& file, bool forWriting);
  5297. void juce_fileClose (void* handle);
  5298. int juce_fileWrite (void* handle, const void* buffer, int size);
  5299. int64 juce_fileSetPosition (void* handle, int64 pos);
  5300. FileOutputStream::FileOutputStream (const File& f,
  5301. const int bufferSize_)
  5302. : file (f),
  5303. bufferSize (bufferSize_),
  5304. bytesInBuffer (0)
  5305. {
  5306. fileHandle = juce_fileOpen (f, true);
  5307. if (fileHandle != 0)
  5308. {
  5309. currentPosition = getPositionInternal();
  5310. if (currentPosition < 0)
  5311. {
  5312. jassertfalse
  5313. juce_fileClose (fileHandle);
  5314. fileHandle = 0;
  5315. }
  5316. }
  5317. buffer.malloc (jmax (bufferSize_, 16));
  5318. }
  5319. FileOutputStream::~FileOutputStream()
  5320. {
  5321. flush();
  5322. juce_fileClose (fileHandle);
  5323. }
  5324. int64 FileOutputStream::getPosition()
  5325. {
  5326. return currentPosition;
  5327. }
  5328. bool FileOutputStream::setPosition (int64 newPosition)
  5329. {
  5330. if (newPosition != currentPosition)
  5331. {
  5332. flush();
  5333. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5334. }
  5335. return newPosition == currentPosition;
  5336. }
  5337. void FileOutputStream::flush()
  5338. {
  5339. if (bytesInBuffer > 0)
  5340. {
  5341. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5342. bytesInBuffer = 0;
  5343. }
  5344. flushInternal();
  5345. }
  5346. bool FileOutputStream::write (const void* const src, const int numBytes)
  5347. {
  5348. if (bytesInBuffer + numBytes < bufferSize)
  5349. {
  5350. memcpy (buffer + bytesInBuffer, src, numBytes);
  5351. bytesInBuffer += numBytes;
  5352. currentPosition += numBytes;
  5353. }
  5354. else
  5355. {
  5356. if (bytesInBuffer > 0)
  5357. {
  5358. // flush the reservoir
  5359. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5360. bytesInBuffer = 0;
  5361. if (! wroteOk)
  5362. return false;
  5363. }
  5364. if (numBytes < bufferSize)
  5365. {
  5366. memcpy (buffer + bytesInBuffer, src, numBytes);
  5367. bytesInBuffer += numBytes;
  5368. currentPosition += numBytes;
  5369. }
  5370. else
  5371. {
  5372. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5373. currentPosition += bytesWritten;
  5374. return bytesWritten == numBytes;
  5375. }
  5376. }
  5377. return true;
  5378. }
  5379. END_JUCE_NAMESPACE
  5380. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5381. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5382. BEGIN_JUCE_NAMESPACE
  5383. FileSearchPath::FileSearchPath()
  5384. {
  5385. }
  5386. FileSearchPath::FileSearchPath (const String& path)
  5387. {
  5388. init (path);
  5389. }
  5390. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5391. : directories (other.directories)
  5392. {
  5393. }
  5394. FileSearchPath::~FileSearchPath()
  5395. {
  5396. }
  5397. FileSearchPath& FileSearchPath::operator= (const String& path)
  5398. {
  5399. init (path);
  5400. return *this;
  5401. }
  5402. void FileSearchPath::init (const String& path)
  5403. {
  5404. directories.clear();
  5405. directories.addTokens (path, ";", "\"");
  5406. directories.trim();
  5407. directories.removeEmptyStrings();
  5408. for (int i = directories.size(); --i >= 0;)
  5409. directories.set (i, directories[i].unquoted());
  5410. }
  5411. int FileSearchPath::getNumPaths() const
  5412. {
  5413. return directories.size();
  5414. }
  5415. const File FileSearchPath::operator[] (const int index) const
  5416. {
  5417. return File (directories [index]);
  5418. }
  5419. const String FileSearchPath::toString() const
  5420. {
  5421. StringArray directories2 (directories);
  5422. for (int i = directories2.size(); --i >= 0;)
  5423. if (directories2[i].containsChar (';'))
  5424. directories2.set (i, directories2[i].quoted());
  5425. return directories2.joinIntoString (";");
  5426. }
  5427. void FileSearchPath::add (const File& dir, const int insertIndex)
  5428. {
  5429. directories.insert (insertIndex, dir.getFullPathName());
  5430. }
  5431. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5432. {
  5433. for (int i = 0; i < directories.size(); ++i)
  5434. if (File (directories[i]) == dir)
  5435. return;
  5436. add (dir);
  5437. }
  5438. void FileSearchPath::remove (const int index)
  5439. {
  5440. directories.remove (index);
  5441. }
  5442. void FileSearchPath::addPath (const FileSearchPath& other)
  5443. {
  5444. for (int i = 0; i < other.getNumPaths(); ++i)
  5445. addIfNotAlreadyThere (other[i]);
  5446. }
  5447. void FileSearchPath::removeRedundantPaths()
  5448. {
  5449. for (int i = directories.size(); --i >= 0;)
  5450. {
  5451. const File d1 (directories[i]);
  5452. for (int j = directories.size(); --j >= 0;)
  5453. {
  5454. const File d2 (directories[j]);
  5455. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5456. {
  5457. directories.remove (i);
  5458. break;
  5459. }
  5460. }
  5461. }
  5462. }
  5463. void FileSearchPath::removeNonExistentPaths()
  5464. {
  5465. for (int i = directories.size(); --i >= 0;)
  5466. if (! File (directories[i]).isDirectory())
  5467. directories.remove (i);
  5468. }
  5469. int FileSearchPath::findChildFiles (Array<File>& results,
  5470. const int whatToLookFor,
  5471. const bool searchRecursively,
  5472. const String& wildCardPattern) const
  5473. {
  5474. int total = 0;
  5475. for (int i = 0; i < directories.size(); ++i)
  5476. total += operator[] (i).findChildFiles (results,
  5477. whatToLookFor,
  5478. searchRecursively,
  5479. wildCardPattern);
  5480. return total;
  5481. }
  5482. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5483. const bool checkRecursively) const
  5484. {
  5485. for (int i = directories.size(); --i >= 0;)
  5486. {
  5487. const File d (directories[i]);
  5488. if (checkRecursively)
  5489. {
  5490. if (fileToCheck.isAChildOf (d))
  5491. return true;
  5492. }
  5493. else
  5494. {
  5495. if (fileToCheck.getParentDirectory() == d)
  5496. return true;
  5497. }
  5498. }
  5499. return false;
  5500. }
  5501. END_JUCE_NAMESPACE
  5502. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5503. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5504. BEGIN_JUCE_NAMESPACE
  5505. NamedPipe::NamedPipe()
  5506. : internal (0)
  5507. {
  5508. }
  5509. NamedPipe::~NamedPipe()
  5510. {
  5511. close();
  5512. }
  5513. bool NamedPipe::openExisting (const String& pipeName)
  5514. {
  5515. currentPipeName = pipeName;
  5516. return openInternal (pipeName, false);
  5517. }
  5518. bool NamedPipe::createNewPipe (const String& pipeName)
  5519. {
  5520. currentPipeName = pipeName;
  5521. return openInternal (pipeName, true);
  5522. }
  5523. bool NamedPipe::isOpen() const
  5524. {
  5525. return internal != 0;
  5526. }
  5527. const String NamedPipe::getName() const
  5528. {
  5529. return currentPipeName;
  5530. }
  5531. // other methods for this class are implemented in the platform-specific files
  5532. END_JUCE_NAMESPACE
  5533. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5534. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5535. BEGIN_JUCE_NAMESPACE
  5536. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5537. {
  5538. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5539. "temp_" + String (Random::getSystemRandom().nextInt()),
  5540. suffix,
  5541. optionFlags);
  5542. }
  5543. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5544. : targetFile (targetFile_)
  5545. {
  5546. // If you use this constructor, you need to give it a valid target file!
  5547. jassert (targetFile != File::nonexistent);
  5548. createTempFile (targetFile.getParentDirectory(),
  5549. targetFile.getFileNameWithoutExtension() + "_temp" + String (Random::getSystemRandom().nextInt()),
  5550. targetFile.getFileExtension(),
  5551. optionFlags);
  5552. }
  5553. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5554. const String& suffix, const int optionFlags)
  5555. {
  5556. if ((optionFlags & useHiddenFile) != 0)
  5557. name = "." + name;
  5558. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5559. }
  5560. TemporaryFile::~TemporaryFile()
  5561. {
  5562. // Have a few attempts at deleting the file before giving up..
  5563. for (int i = 5; --i >= 0;)
  5564. {
  5565. if (temporaryFile.deleteFile())
  5566. return;
  5567. Thread::sleep (50);
  5568. }
  5569. // Failed to delete our temporary file! Check that you've deleted all the
  5570. // file output streams that were using it!
  5571. jassertfalse;
  5572. }
  5573. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5574. {
  5575. // This method only works if you created this object with the constructor
  5576. // that takes a target file!
  5577. jassert (targetFile != File::nonexistent);
  5578. if (temporaryFile.exists())
  5579. {
  5580. // Have a few attempts at overwriting the file before giving up..
  5581. for (int i = 5; --i >= 0;)
  5582. {
  5583. if (temporaryFile.moveFileTo (targetFile))
  5584. return true;
  5585. Thread::sleep (100);
  5586. }
  5587. }
  5588. else
  5589. {
  5590. // There's no temporary file to use. If your write failed, you should
  5591. // probably check, and not bother calling this method.
  5592. jassertfalse
  5593. }
  5594. return false;
  5595. }
  5596. END_JUCE_NAMESPACE
  5597. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5598. /*** Start of inlined file: juce_Socket.cpp ***/
  5599. #if JUCE_WINDOWS
  5600. #include <winsock2.h>
  5601. #ifdef _MSC_VER
  5602. #pragma warning (disable : 4127 4389 4018)
  5603. #endif
  5604. #else
  5605. #if JUCE_LINUX
  5606. #include <sys/types.h>
  5607. #include <sys/socket.h>
  5608. #include <sys/errno.h>
  5609. #include <unistd.h>
  5610. #include <netinet/in.h>
  5611. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5612. #include <CoreServices/CoreServices.h>
  5613. #endif
  5614. #include <fcntl.h>
  5615. #include <netdb.h>
  5616. #include <arpa/inet.h>
  5617. #include <netinet/tcp.h>
  5618. #endif
  5619. BEGIN_JUCE_NAMESPACE
  5620. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5621. typedef socklen_t juce_socklen_t;
  5622. #else
  5623. typedef int juce_socklen_t;
  5624. #endif
  5625. #if JUCE_WINDOWS
  5626. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5627. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5628. static void initWin32Sockets()
  5629. {
  5630. static CriticalSection lock;
  5631. const ScopedLock sl (lock);
  5632. if (juce_CloseWin32SocketLib == 0)
  5633. {
  5634. WSADATA wsaData;
  5635. const WORD wVersionRequested = MAKEWORD (1, 1);
  5636. WSAStartup (wVersionRequested, &wsaData);
  5637. juce_CloseWin32SocketLib = &WSACleanup;
  5638. }
  5639. }
  5640. #endif
  5641. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5642. {
  5643. const int sndBufSize = 65536;
  5644. const int rcvBufSize = 65536;
  5645. const int one = 1;
  5646. return handle > 0
  5647. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5648. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5649. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5650. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5651. }
  5652. static bool bindSocketToPort (const int handle, const int port) throw()
  5653. {
  5654. if (handle <= 0 || port <= 0)
  5655. return false;
  5656. struct sockaddr_in servTmpAddr;
  5657. zerostruct (servTmpAddr);
  5658. servTmpAddr.sin_family = PF_INET;
  5659. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5660. servTmpAddr.sin_port = htons ((uint16) port);
  5661. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5662. }
  5663. static int readSocket (const int handle,
  5664. void* const destBuffer, const int maxBytesToRead,
  5665. bool volatile& connected,
  5666. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5667. {
  5668. int bytesRead = 0;
  5669. while (bytesRead < maxBytesToRead)
  5670. {
  5671. int bytesThisTime;
  5672. #if JUCE_WINDOWS
  5673. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5674. #else
  5675. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5676. && errno == EINTR
  5677. && connected)
  5678. {
  5679. }
  5680. #endif
  5681. if (bytesThisTime <= 0 || ! connected)
  5682. {
  5683. if (bytesRead == 0)
  5684. bytesRead = -1;
  5685. break;
  5686. }
  5687. bytesRead += bytesThisTime;
  5688. if (! blockUntilSpecifiedAmountHasArrived)
  5689. break;
  5690. }
  5691. return bytesRead;
  5692. }
  5693. static int waitForReadiness (const int handle, const bool forReading,
  5694. const int timeoutMsecs) throw()
  5695. {
  5696. struct timeval timeout;
  5697. struct timeval* timeoutp;
  5698. if (timeoutMsecs >= 0)
  5699. {
  5700. timeout.tv_sec = timeoutMsecs / 1000;
  5701. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5702. timeoutp = &timeout;
  5703. }
  5704. else
  5705. {
  5706. timeoutp = 0;
  5707. }
  5708. fd_set rset, wset;
  5709. FD_ZERO (&rset);
  5710. FD_SET (handle, &rset);
  5711. FD_ZERO (&wset);
  5712. FD_SET (handle, &wset);
  5713. fd_set* const prset = forReading ? &rset : 0;
  5714. fd_set* const pwset = forReading ? 0 : &wset;
  5715. #if JUCE_WINDOWS
  5716. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5717. return -1;
  5718. #else
  5719. {
  5720. int result;
  5721. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5722. && errno == EINTR)
  5723. {
  5724. }
  5725. if (result < 0)
  5726. return -1;
  5727. }
  5728. #endif
  5729. {
  5730. int opt;
  5731. juce_socklen_t len = sizeof (opt);
  5732. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5733. || opt != 0)
  5734. return -1;
  5735. }
  5736. if ((forReading && FD_ISSET (handle, &rset))
  5737. || ((! forReading) && FD_ISSET (handle, &wset)))
  5738. return 1;
  5739. return 0;
  5740. }
  5741. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5742. {
  5743. #if JUCE_WINDOWS
  5744. u_long nonBlocking = shouldBlock ? 0 : 1;
  5745. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5746. return false;
  5747. #else
  5748. int socketFlags = fcntl (handle, F_GETFL, 0);
  5749. if (socketFlags == -1)
  5750. return false;
  5751. if (shouldBlock)
  5752. socketFlags &= ~O_NONBLOCK;
  5753. else
  5754. socketFlags |= O_NONBLOCK;
  5755. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5756. return false;
  5757. #endif
  5758. return true;
  5759. }
  5760. static bool connectSocket (int volatile& handle,
  5761. const bool isDatagram,
  5762. void** serverAddress,
  5763. const String& hostName,
  5764. const int portNumber,
  5765. const int timeOutMillisecs) throw()
  5766. {
  5767. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  5768. if (hostEnt == 0)
  5769. return false;
  5770. struct in_addr targetAddress;
  5771. memcpy (&targetAddress.s_addr,
  5772. *(hostEnt->h_addr_list),
  5773. sizeof (targetAddress.s_addr));
  5774. struct sockaddr_in servTmpAddr;
  5775. zerostruct (servTmpAddr);
  5776. servTmpAddr.sin_family = PF_INET;
  5777. servTmpAddr.sin_addr = targetAddress;
  5778. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5779. if (handle < 0)
  5780. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5781. if (handle < 0)
  5782. return false;
  5783. if (isDatagram)
  5784. {
  5785. *serverAddress = new struct sockaddr_in();
  5786. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  5787. return true;
  5788. }
  5789. setSocketBlockingState (handle, false);
  5790. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  5791. if (result < 0)
  5792. {
  5793. #if JUCE_WINDOWS
  5794. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  5795. #else
  5796. if (errno == EINPROGRESS)
  5797. #endif
  5798. {
  5799. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  5800. {
  5801. setSocketBlockingState (handle, true);
  5802. return false;
  5803. }
  5804. }
  5805. }
  5806. setSocketBlockingState (handle, true);
  5807. resetSocketOptions (handle, false, false);
  5808. return true;
  5809. }
  5810. StreamingSocket::StreamingSocket()
  5811. : portNumber (0),
  5812. handle (-1),
  5813. connected (false),
  5814. isListener (false)
  5815. {
  5816. #if JUCE_WINDOWS
  5817. initWin32Sockets();
  5818. #endif
  5819. }
  5820. StreamingSocket::StreamingSocket (const String& hostName_,
  5821. const int portNumber_,
  5822. const int handle_)
  5823. : hostName (hostName_),
  5824. portNumber (portNumber_),
  5825. handle (handle_),
  5826. connected (true),
  5827. isListener (false)
  5828. {
  5829. #if JUCE_WINDOWS
  5830. initWin32Sockets();
  5831. #endif
  5832. resetSocketOptions (handle_, false, false);
  5833. }
  5834. StreamingSocket::~StreamingSocket()
  5835. {
  5836. close();
  5837. }
  5838. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  5839. {
  5840. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  5841. : -1;
  5842. }
  5843. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  5844. {
  5845. if (isListener || ! connected)
  5846. return -1;
  5847. #if JUCE_WINDOWS
  5848. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  5849. #else
  5850. int result;
  5851. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  5852. && errno == EINTR)
  5853. {
  5854. }
  5855. return result;
  5856. #endif
  5857. }
  5858. int StreamingSocket::waitUntilReady (const bool readyForReading,
  5859. const int timeoutMsecs) const
  5860. {
  5861. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  5862. : -1;
  5863. }
  5864. bool StreamingSocket::bindToPort (const int port)
  5865. {
  5866. return bindSocketToPort (handle, port);
  5867. }
  5868. bool StreamingSocket::connect (const String& remoteHostName,
  5869. const int remotePortNumber,
  5870. const int timeOutMillisecs)
  5871. {
  5872. if (isListener)
  5873. {
  5874. jassertfalse // a listener socket can't connect to another one!
  5875. return false;
  5876. }
  5877. if (connected)
  5878. close();
  5879. hostName = remoteHostName;
  5880. portNumber = remotePortNumber;
  5881. isListener = false;
  5882. connected = connectSocket (handle, false, 0, remoteHostName,
  5883. remotePortNumber, timeOutMillisecs);
  5884. if (! (connected && resetSocketOptions (handle, false, false)))
  5885. {
  5886. close();
  5887. return false;
  5888. }
  5889. return true;
  5890. }
  5891. void StreamingSocket::close()
  5892. {
  5893. #if JUCE_WINDOWS
  5894. if (handle != SOCKET_ERROR || connected)
  5895. closesocket (handle);
  5896. connected = false;
  5897. #else
  5898. if (connected)
  5899. {
  5900. connected = false;
  5901. if (isListener)
  5902. {
  5903. // need to do this to interrupt the accept() function..
  5904. StreamingSocket temp;
  5905. temp.connect ("localhost", portNumber, 1000);
  5906. }
  5907. }
  5908. if (handle != -1)
  5909. ::close (handle);
  5910. #endif
  5911. hostName = String::empty;
  5912. portNumber = 0;
  5913. handle = -1;
  5914. isListener = false;
  5915. }
  5916. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  5917. {
  5918. if (connected)
  5919. close();
  5920. hostName = "listener";
  5921. portNumber = newPortNumber;
  5922. isListener = true;
  5923. struct sockaddr_in servTmpAddr;
  5924. zerostruct (servTmpAddr);
  5925. servTmpAddr.sin_family = PF_INET;
  5926. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5927. if (localHostName.isNotEmpty())
  5928. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  5929. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5930. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  5931. if (handle < 0)
  5932. return false;
  5933. const int reuse = 1;
  5934. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  5935. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  5936. || listen (handle, SOMAXCONN) < 0)
  5937. {
  5938. close();
  5939. return false;
  5940. }
  5941. connected = true;
  5942. return true;
  5943. }
  5944. StreamingSocket* StreamingSocket::waitForNextConnection() const
  5945. {
  5946. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  5947. // prepare this socket as a listener.
  5948. if (connected && isListener)
  5949. {
  5950. struct sockaddr address;
  5951. juce_socklen_t len = sizeof (sockaddr);
  5952. const int newSocket = (int) accept (handle, &address, &len);
  5953. if (newSocket >= 0 && connected)
  5954. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  5955. portNumber, newSocket);
  5956. }
  5957. return 0;
  5958. }
  5959. bool StreamingSocket::isLocal() const throw()
  5960. {
  5961. return hostName == "127.0.0.1";
  5962. }
  5963. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  5964. : portNumber (0),
  5965. handle (-1),
  5966. connected (true),
  5967. allowBroadcast (allowBroadcast_),
  5968. serverAddress (0)
  5969. {
  5970. #if JUCE_WINDOWS
  5971. initWin32Sockets();
  5972. #endif
  5973. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  5974. bindToPort (localPortNumber);
  5975. }
  5976. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  5977. const int handle_, const int localPortNumber)
  5978. : hostName (hostName_),
  5979. portNumber (portNumber_),
  5980. handle (handle_),
  5981. connected (true),
  5982. allowBroadcast (false),
  5983. serverAddress (0)
  5984. {
  5985. #if JUCE_WINDOWS
  5986. initWin32Sockets();
  5987. #endif
  5988. resetSocketOptions (handle_, true, allowBroadcast);
  5989. bindToPort (localPortNumber);
  5990. }
  5991. DatagramSocket::~DatagramSocket()
  5992. {
  5993. close();
  5994. delete ((struct sockaddr_in*) serverAddress);
  5995. serverAddress = 0;
  5996. }
  5997. void DatagramSocket::close()
  5998. {
  5999. #if JUCE_WINDOWS
  6000. closesocket (handle);
  6001. connected = false;
  6002. #else
  6003. connected = false;
  6004. ::close (handle);
  6005. #endif
  6006. hostName = String::empty;
  6007. portNumber = 0;
  6008. handle = -1;
  6009. }
  6010. bool DatagramSocket::bindToPort (const int port)
  6011. {
  6012. return bindSocketToPort (handle, port);
  6013. }
  6014. bool DatagramSocket::connect (const String& remoteHostName,
  6015. const int remotePortNumber,
  6016. const int timeOutMillisecs)
  6017. {
  6018. if (connected)
  6019. close();
  6020. hostName = remoteHostName;
  6021. portNumber = remotePortNumber;
  6022. connected = connectSocket (handle, true, &serverAddress,
  6023. remoteHostName, remotePortNumber,
  6024. timeOutMillisecs);
  6025. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6026. {
  6027. close();
  6028. return false;
  6029. }
  6030. return true;
  6031. }
  6032. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6033. {
  6034. struct sockaddr address;
  6035. juce_socklen_t len = sizeof (sockaddr);
  6036. while (waitUntilReady (true, -1) == 1)
  6037. {
  6038. char buf[1];
  6039. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6040. {
  6041. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6042. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6043. -1, -1);
  6044. }
  6045. }
  6046. return 0;
  6047. }
  6048. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6049. const int timeoutMsecs) const
  6050. {
  6051. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6052. : -1;
  6053. }
  6054. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6055. {
  6056. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6057. : -1;
  6058. }
  6059. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6060. {
  6061. // You need to call connect() first to set the server address..
  6062. jassert (serverAddress != 0 && connected);
  6063. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6064. numBytesToWrite, 0,
  6065. (const struct sockaddr*) serverAddress,
  6066. sizeof (struct sockaddr_in))
  6067. : -1;
  6068. }
  6069. bool DatagramSocket::isLocal() const throw()
  6070. {
  6071. return hostName == "127.0.0.1";
  6072. }
  6073. END_JUCE_NAMESPACE
  6074. /*** End of inlined file: juce_Socket.cpp ***/
  6075. /*** Start of inlined file: juce_URL.cpp ***/
  6076. BEGIN_JUCE_NAMESPACE
  6077. URL::URL()
  6078. {
  6079. }
  6080. URL::URL (const String& url_)
  6081. : url (url_)
  6082. {
  6083. int i = url.indexOfChar ('?');
  6084. if (i >= 0)
  6085. {
  6086. do
  6087. {
  6088. const int nextAmp = url.indexOfChar (i + 1, '&');
  6089. const int equalsPos = url.indexOfChar (i + 1, '=');
  6090. if (equalsPos > i + 1)
  6091. {
  6092. if (nextAmp < 0)
  6093. {
  6094. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6095. removeEscapeChars (url.substring (equalsPos + 1)));
  6096. }
  6097. else if (nextAmp > 0 && equalsPos < nextAmp)
  6098. {
  6099. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6100. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6101. }
  6102. }
  6103. i = nextAmp;
  6104. }
  6105. while (i >= 0);
  6106. url = url.upToFirstOccurrenceOf ("?", false, false);
  6107. }
  6108. }
  6109. URL::URL (const URL& other)
  6110. : url (other.url),
  6111. postData (other.postData),
  6112. parameters (other.parameters),
  6113. filesToUpload (other.filesToUpload),
  6114. mimeTypes (other.mimeTypes)
  6115. {
  6116. }
  6117. URL& URL::operator= (const URL& other)
  6118. {
  6119. url = other.url;
  6120. postData = other.postData;
  6121. parameters = other.parameters;
  6122. filesToUpload = other.filesToUpload;
  6123. mimeTypes = other.mimeTypes;
  6124. return *this;
  6125. }
  6126. URL::~URL()
  6127. {
  6128. }
  6129. static const String getMangledParameters (const StringPairArray& parameters)
  6130. {
  6131. String p;
  6132. for (int i = 0; i < parameters.size(); ++i)
  6133. {
  6134. if (i > 0)
  6135. p += '&';
  6136. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6137. << '='
  6138. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6139. }
  6140. return p;
  6141. }
  6142. const String URL::toString (const bool includeGetParameters) const
  6143. {
  6144. if (includeGetParameters && parameters.size() > 0)
  6145. return url + "?" + getMangledParameters (parameters);
  6146. else
  6147. return url;
  6148. }
  6149. bool URL::isWellFormed() const
  6150. {
  6151. //xxx TODO
  6152. return url.isNotEmpty();
  6153. }
  6154. static int findStartOfDomain (const String& url)
  6155. {
  6156. int i = 0;
  6157. while (CharacterFunctions::isLetterOrDigit (url[i])
  6158. || CharacterFunctions::indexOfChar (L"+-.", url[i], false) >= 0)
  6159. ++i;
  6160. return url[i] == ':' ? i + 1 : 0;
  6161. }
  6162. const String URL::getDomain() const
  6163. {
  6164. int start = findStartOfDomain (url);
  6165. while (url[start] == '/')
  6166. ++start;
  6167. const int end1 = url.indexOfChar (start, '/');
  6168. const int end2 = url.indexOfChar (start, ':');
  6169. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6170. : jmin (end1, end2);
  6171. return url.substring (start, end);
  6172. }
  6173. const String URL::getSubPath() const
  6174. {
  6175. int start = findStartOfDomain (url);
  6176. while (url[start] == '/')
  6177. ++start;
  6178. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6179. return startOfPath <= 0 ? String::empty
  6180. : url.substring (startOfPath);
  6181. }
  6182. const String URL::getScheme() const
  6183. {
  6184. return url.substring (0, findStartOfDomain (url) - 1);
  6185. }
  6186. const URL URL::withNewSubPath (const String& newPath) const
  6187. {
  6188. int start = findStartOfDomain (url);
  6189. while (url[start] == '/')
  6190. ++start;
  6191. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6192. URL u (*this);
  6193. if (startOfPath > 0)
  6194. u.url = url.substring (0, startOfPath);
  6195. if (! u.url.endsWithChar ('/'))
  6196. u.url << '/';
  6197. if (newPath.startsWithChar ('/'))
  6198. u.url << newPath.substring (1);
  6199. else
  6200. u.url << newPath;
  6201. return u;
  6202. }
  6203. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6204. {
  6205. if (possibleURL.startsWithIgnoreCase ("http:")
  6206. || possibleURL.startsWithIgnoreCase ("ftp:"))
  6207. return true;
  6208. if (possibleURL.startsWithIgnoreCase ("file:")
  6209. || possibleURL.containsChar ('@')
  6210. || possibleURL.endsWithChar ('.')
  6211. || (! possibleURL.containsChar ('.')))
  6212. return false;
  6213. if (possibleURL.startsWithIgnoreCase ("www.")
  6214. && possibleURL.substring (5).containsChar ('.'))
  6215. return true;
  6216. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6217. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6218. if ((possibleURL + "/").containsIgnoreCase ("." + String (commonTLDs[i]) + "/"))
  6219. return true;
  6220. return false;
  6221. }
  6222. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6223. {
  6224. const int atSign = possibleEmailAddress.indexOfChar ('@');
  6225. return atSign > 0
  6226. && possibleEmailAddress.lastIndexOfChar ('.') > (atSign + 1)
  6227. && (! possibleEmailAddress.endsWithChar ('.'));
  6228. }
  6229. void* juce_openInternetFile (const String& url,
  6230. const String& headers,
  6231. const MemoryBlock& optionalPostData,
  6232. const bool isPost,
  6233. URL::OpenStreamProgressCallback* callback,
  6234. void* callbackContext,
  6235. int timeOutMs);
  6236. void juce_closeInternetFile (void* handle);
  6237. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6238. int juce_seekInInternetFile (void* handle, int newPosition);
  6239. int64 juce_getInternetFileContentLength (void* handle);
  6240. class WebInputStream : public InputStream
  6241. {
  6242. public:
  6243. WebInputStream (const URL& url,
  6244. const bool isPost_,
  6245. URL::OpenStreamProgressCallback* const progressCallback_,
  6246. void* const progressCallbackContext_,
  6247. const String& extraHeaders,
  6248. int timeOutMs_)
  6249. : position (0),
  6250. finished (false),
  6251. isPost (isPost_),
  6252. progressCallback (progressCallback_),
  6253. progressCallbackContext (progressCallbackContext_),
  6254. timeOutMs (timeOutMs_)
  6255. {
  6256. server = url.toString (! isPost);
  6257. if (isPost_)
  6258. createHeadersAndPostData (url);
  6259. headers += extraHeaders;
  6260. if (! headers.endsWithChar ('\n'))
  6261. headers << "\r\n";
  6262. handle = juce_openInternetFile (server, headers, postData, isPost,
  6263. progressCallback_, progressCallbackContext_,
  6264. timeOutMs);
  6265. }
  6266. ~WebInputStream()
  6267. {
  6268. juce_closeInternetFile (handle);
  6269. }
  6270. bool isError() const { return handle == 0; }
  6271. int64 getTotalLength() { return juce_getInternetFileContentLength (handle); }
  6272. bool isExhausted() { return finished; }
  6273. int64 getPosition() { return position; }
  6274. int read (void* dest, int bytes)
  6275. {
  6276. if (finished || isError())
  6277. {
  6278. return 0;
  6279. }
  6280. else
  6281. {
  6282. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6283. position += bytesRead;
  6284. if (bytesRead == 0)
  6285. finished = true;
  6286. return bytesRead;
  6287. }
  6288. }
  6289. bool setPosition (int64 wantedPos)
  6290. {
  6291. if (wantedPos != position)
  6292. {
  6293. finished = false;
  6294. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6295. if (actualPos == wantedPos)
  6296. {
  6297. position = wantedPos;
  6298. }
  6299. else
  6300. {
  6301. if (wantedPos < position)
  6302. {
  6303. juce_closeInternetFile (handle);
  6304. position = 0;
  6305. finished = false;
  6306. handle = juce_openInternetFile (server, headers, postData, isPost,
  6307. progressCallback, progressCallbackContext,
  6308. timeOutMs);
  6309. }
  6310. skipNextBytes (wantedPos - position);
  6311. }
  6312. }
  6313. return true;
  6314. }
  6315. juce_UseDebuggingNewOperator
  6316. private:
  6317. String server, headers;
  6318. MemoryBlock postData;
  6319. int64 position;
  6320. bool finished;
  6321. const bool isPost;
  6322. void* handle;
  6323. URL::OpenStreamProgressCallback* const progressCallback;
  6324. void* const progressCallbackContext;
  6325. const int timeOutMs;
  6326. void createHeadersAndPostData (const URL& url)
  6327. {
  6328. MemoryOutputStream data (256, 256, &postData);
  6329. if (url.getFilesToUpload().size() > 0)
  6330. {
  6331. // need to upload some files, so do it as multi-part...
  6332. const String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6333. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6334. data << "--" << boundary;
  6335. int i;
  6336. for (i = 0; i < url.getParameters().size(); ++i)
  6337. {
  6338. data << "\r\nContent-Disposition: form-data; name=\""
  6339. << url.getParameters().getAllKeys() [i]
  6340. << "\"\r\n\r\n"
  6341. << url.getParameters().getAllValues() [i]
  6342. << "\r\n--"
  6343. << boundary;
  6344. }
  6345. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6346. {
  6347. const File file (url.getFilesToUpload().getAllValues() [i]);
  6348. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6349. data << "\r\nContent-Disposition: form-data; name=\"" << paramName
  6350. << "\"; filename=\"" << file.getFileName() << "\"\r\n";
  6351. const String mimeType (url.getMimeTypesOfUploadFiles()
  6352. .getValue (paramName, String::empty));
  6353. if (mimeType.isNotEmpty())
  6354. data << "Content-Type: " << mimeType << "\r\n";
  6355. data << "Content-Transfer-Encoding: binary\r\n\r\n"
  6356. << file << "\r\n--" << boundary;
  6357. }
  6358. data << "--\r\n";
  6359. }
  6360. else
  6361. {
  6362. data << getMangledParameters (url.getParameters())
  6363. << url.getPostData();
  6364. // just a short text attachment, so use simple url encoding..
  6365. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6366. + String ((unsigned int) postData.getSize())
  6367. + "\r\n";
  6368. }
  6369. }
  6370. WebInputStream (const WebInputStream&);
  6371. WebInputStream& operator= (const WebInputStream&);
  6372. };
  6373. InputStream* URL::createInputStream (const bool usePostCommand,
  6374. OpenStreamProgressCallback* const progressCallback,
  6375. void* const progressCallbackContext,
  6376. const String& extraHeaders,
  6377. const int timeOutMs) const
  6378. {
  6379. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6380. progressCallback, progressCallbackContext,
  6381. extraHeaders,
  6382. timeOutMs));
  6383. return wi->isError() ? 0 : wi.release();
  6384. }
  6385. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6386. const bool usePostCommand) const
  6387. {
  6388. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6389. if (in != 0)
  6390. {
  6391. in->readIntoMemoryBlock (destData, -1);
  6392. return true;
  6393. }
  6394. return false;
  6395. }
  6396. const String URL::readEntireTextStream (const bool usePostCommand) const
  6397. {
  6398. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6399. if (in != 0)
  6400. return in->readEntireStreamAsString();
  6401. return String::empty;
  6402. }
  6403. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6404. {
  6405. XmlDocument doc (readEntireTextStream (usePostCommand));
  6406. return doc.getDocumentElement();
  6407. }
  6408. const URL URL::withParameter (const String& parameterName,
  6409. const String& parameterValue) const
  6410. {
  6411. URL u (*this);
  6412. u.parameters.set (parameterName, parameterValue);
  6413. return u;
  6414. }
  6415. const URL URL::withFileToUpload (const String& parameterName,
  6416. const File& fileToUpload,
  6417. const String& mimeType) const
  6418. {
  6419. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6420. URL u (*this);
  6421. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6422. u.mimeTypes.set (parameterName, mimeType);
  6423. return u;
  6424. }
  6425. const URL URL::withPOSTData (const String& postData_) const
  6426. {
  6427. URL u (*this);
  6428. u.postData = postData_;
  6429. return u;
  6430. }
  6431. const StringPairArray& URL::getParameters() const
  6432. {
  6433. return parameters;
  6434. }
  6435. const StringPairArray& URL::getFilesToUpload() const
  6436. {
  6437. return filesToUpload;
  6438. }
  6439. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6440. {
  6441. return mimeTypes;
  6442. }
  6443. const String URL::removeEscapeChars (const String& s)
  6444. {
  6445. String result (s.replaceCharacter ('+', ' '));
  6446. int nextPercent = 0;
  6447. for (;;)
  6448. {
  6449. nextPercent = result.indexOfChar (nextPercent, '%');
  6450. if (nextPercent < 0)
  6451. break;
  6452. juce_wchar replacementChar = (juce_wchar) result.substring (nextPercent + 1, nextPercent + 3).getHexValue32();
  6453. result = result.replaceSection (nextPercent, 3, String::charToString (replacementChar));
  6454. ++nextPercent;
  6455. }
  6456. return result;
  6457. }
  6458. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6459. {
  6460. String result;
  6461. result.preallocateStorage (s.length() + 8);
  6462. const char* utf8 = s.toUTF8();
  6463. const char* legalChars = isParameter ? "_-.*!'()"
  6464. : "_-$.*!'(),";
  6465. while (*utf8 != 0)
  6466. {
  6467. const char c = *utf8++;
  6468. if (CharacterFunctions::isLetterOrDigit (c)
  6469. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6470. {
  6471. result << c;
  6472. }
  6473. else
  6474. {
  6475. const int v = (int) (uint8) c;
  6476. result << (v < 0x10 ? "%0" : "%") << String::toHexString (v);
  6477. }
  6478. }
  6479. return result;
  6480. }
  6481. bool URL::launchInDefaultBrowser() const
  6482. {
  6483. String u (toString (true));
  6484. if (u.containsChar ('@') && ! u.containsChar (':'))
  6485. u = "mailto:" + u;
  6486. return PlatformUtilities::openDocument (u, String::empty);
  6487. }
  6488. END_JUCE_NAMESPACE
  6489. /*** End of inlined file: juce_URL.cpp ***/
  6490. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6491. BEGIN_JUCE_NAMESPACE
  6492. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6493. const int bufferSize_,
  6494. const bool deleteSourceWhenDestroyed)
  6495. : source (source_),
  6496. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6497. bufferSize (jmax (256, bufferSize_)),
  6498. position (source_->getPosition()),
  6499. lastReadPos (0),
  6500. bufferOverlap (128)
  6501. {
  6502. const int sourceSize = (int) source_->getTotalLength();
  6503. if (sourceSize >= 0)
  6504. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6505. bufferStart = position;
  6506. buffer.malloc (bufferSize);
  6507. }
  6508. BufferedInputStream::~BufferedInputStream()
  6509. {
  6510. }
  6511. int64 BufferedInputStream::getTotalLength()
  6512. {
  6513. return source->getTotalLength();
  6514. }
  6515. int64 BufferedInputStream::getPosition()
  6516. {
  6517. return position;
  6518. }
  6519. bool BufferedInputStream::setPosition (int64 newPosition)
  6520. {
  6521. position = jmax ((int64) 0, newPosition);
  6522. return true;
  6523. }
  6524. bool BufferedInputStream::isExhausted()
  6525. {
  6526. return (position >= lastReadPos)
  6527. && source->isExhausted();
  6528. }
  6529. void BufferedInputStream::ensureBuffered()
  6530. {
  6531. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6532. if (position < bufferStart || position >= bufferEndOverlap)
  6533. {
  6534. int bytesRead;
  6535. if (position < lastReadPos
  6536. && position >= bufferEndOverlap
  6537. && position >= bufferStart)
  6538. {
  6539. const int bytesToKeep = (int) (lastReadPos - position);
  6540. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6541. bufferStart = position;
  6542. bytesRead = source->read (buffer + bytesToKeep,
  6543. bufferSize - bytesToKeep);
  6544. lastReadPos += bytesRead;
  6545. bytesRead += bytesToKeep;
  6546. }
  6547. else
  6548. {
  6549. bufferStart = position;
  6550. source->setPosition (bufferStart);
  6551. bytesRead = source->read (buffer, bufferSize);
  6552. lastReadPos = bufferStart + bytesRead;
  6553. }
  6554. while (bytesRead < bufferSize)
  6555. buffer [bytesRead++] = 0;
  6556. }
  6557. }
  6558. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6559. {
  6560. if (position >= bufferStart
  6561. && position + maxBytesToRead <= lastReadPos)
  6562. {
  6563. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6564. position += maxBytesToRead;
  6565. return maxBytesToRead;
  6566. }
  6567. else
  6568. {
  6569. if (position < bufferStart || position >= lastReadPos)
  6570. ensureBuffered();
  6571. int bytesRead = 0;
  6572. while (maxBytesToRead > 0)
  6573. {
  6574. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6575. if (bytesAvailable > 0)
  6576. {
  6577. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6578. maxBytesToRead -= bytesAvailable;
  6579. bytesRead += bytesAvailable;
  6580. position += bytesAvailable;
  6581. destBuffer = static_cast <char*> (destBuffer) + bytesAvailable;
  6582. }
  6583. const int64 oldLastReadPos = lastReadPos;
  6584. ensureBuffered();
  6585. if (oldLastReadPos == lastReadPos)
  6586. break; // if ensureBuffered() failed to read any more data, bail out
  6587. if (isExhausted())
  6588. break;
  6589. }
  6590. return bytesRead;
  6591. }
  6592. }
  6593. const String BufferedInputStream::readString()
  6594. {
  6595. if (position >= bufferStart
  6596. && position < lastReadPos)
  6597. {
  6598. const int maxChars = (int) (lastReadPos - position);
  6599. const char* const src = buffer + (int) (position - bufferStart);
  6600. for (int i = 0; i < maxChars; ++i)
  6601. {
  6602. if (src[i] == 0)
  6603. {
  6604. position += i + 1;
  6605. return String::fromUTF8 (src, i);
  6606. }
  6607. }
  6608. }
  6609. return InputStream::readString();
  6610. }
  6611. END_JUCE_NAMESPACE
  6612. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6613. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6614. BEGIN_JUCE_NAMESPACE
  6615. FileInputSource::FileInputSource (const File& file_)
  6616. : file (file_)
  6617. {
  6618. }
  6619. FileInputSource::~FileInputSource()
  6620. {
  6621. }
  6622. InputStream* FileInputSource::createInputStream()
  6623. {
  6624. return file.createInputStream();
  6625. }
  6626. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6627. {
  6628. return file.getSiblingFile (relatedItemPath).createInputStream();
  6629. }
  6630. int64 FileInputSource::hashCode() const
  6631. {
  6632. return file.hashCode();
  6633. }
  6634. END_JUCE_NAMESPACE
  6635. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6636. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6637. BEGIN_JUCE_NAMESPACE
  6638. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6639. const size_t sourceDataSize,
  6640. const bool keepInternalCopy)
  6641. : data (static_cast <const char*> (sourceData)),
  6642. dataSize (sourceDataSize),
  6643. position (0)
  6644. {
  6645. if (keepInternalCopy)
  6646. {
  6647. internalCopy.append (data, sourceDataSize);
  6648. data = static_cast <const char*> (internalCopy.getData());
  6649. }
  6650. }
  6651. MemoryInputStream::MemoryInputStream (const MemoryBlock& sourceData,
  6652. const bool keepInternalCopy)
  6653. : data (static_cast <const char*> (sourceData.getData())),
  6654. dataSize (sourceData.getSize()),
  6655. position (0)
  6656. {
  6657. if (keepInternalCopy)
  6658. {
  6659. internalCopy = sourceData;
  6660. data = static_cast <const char*> (internalCopy.getData());
  6661. }
  6662. }
  6663. MemoryInputStream::~MemoryInputStream()
  6664. {
  6665. }
  6666. int64 MemoryInputStream::getTotalLength()
  6667. {
  6668. return dataSize;
  6669. }
  6670. int MemoryInputStream::read (void* const buffer, const int howMany)
  6671. {
  6672. jassert (howMany >= 0);
  6673. const int num = jmin (howMany, (int) (dataSize - position));
  6674. memcpy (buffer, data + position, num);
  6675. position += num;
  6676. return (int) num;
  6677. }
  6678. bool MemoryInputStream::isExhausted()
  6679. {
  6680. return (position >= dataSize);
  6681. }
  6682. bool MemoryInputStream::setPosition (const int64 pos)
  6683. {
  6684. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6685. return true;
  6686. }
  6687. int64 MemoryInputStream::getPosition()
  6688. {
  6689. return position;
  6690. }
  6691. END_JUCE_NAMESPACE
  6692. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  6693. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  6694. BEGIN_JUCE_NAMESPACE
  6695. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6696. const size_t blockSizeToIncreaseBy,
  6697. MemoryBlock* const memoryBlockToWriteTo)
  6698. : data (memoryBlockToWriteTo),
  6699. position (0),
  6700. size (0),
  6701. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6702. {
  6703. if (data == 0)
  6704. dataToDelete = data = new MemoryBlock (initialSize);
  6705. else
  6706. data->setSize (initialSize, false);
  6707. }
  6708. MemoryOutputStream::~MemoryOutputStream()
  6709. {
  6710. flush();
  6711. }
  6712. void MemoryOutputStream::flush()
  6713. {
  6714. if (dataToDelete == 0)
  6715. data->setSize (size, false);
  6716. }
  6717. void MemoryOutputStream::reset() throw()
  6718. {
  6719. position = 0;
  6720. size = 0;
  6721. }
  6722. bool MemoryOutputStream::write (const void* const buffer, int howMany)
  6723. {
  6724. if (howMany > 0)
  6725. {
  6726. size_t storageNeeded = position + howMany;
  6727. if (storageNeeded >= data->getSize())
  6728. {
  6729. // if we need more space, increase the block by at least 10%..
  6730. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6731. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6732. data->ensureSize (storageNeeded);
  6733. }
  6734. data->copyFrom (buffer, (int) position, howMany);
  6735. position += howMany;
  6736. size = jmax (size, position);
  6737. }
  6738. return true;
  6739. }
  6740. const char* MemoryOutputStream::getData() const throw()
  6741. {
  6742. char* const d = static_cast <char*> (data->getData());
  6743. if (data->getSize() > size)
  6744. d [size] = 0;
  6745. return d;
  6746. }
  6747. bool MemoryOutputStream::setPosition (int64 newPosition)
  6748. {
  6749. if (newPosition <= (int64) size)
  6750. {
  6751. // ok to seek backwards
  6752. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  6753. return true;
  6754. }
  6755. else
  6756. {
  6757. // trying to make it bigger isn't a good thing to do..
  6758. return false;
  6759. }
  6760. }
  6761. const String MemoryOutputStream::toUTF8() const
  6762. {
  6763. return String (getData(), getDataSize());
  6764. }
  6765. END_JUCE_NAMESPACE
  6766. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  6767. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  6768. BEGIN_JUCE_NAMESPACE
  6769. SubregionStream::SubregionStream (InputStream* const sourceStream,
  6770. const int64 startPositionInSourceStream_,
  6771. const int64 lengthOfSourceStream_,
  6772. const bool deleteSourceWhenDestroyed) throw()
  6773. : source (sourceStream),
  6774. startPositionInSourceStream (startPositionInSourceStream_),
  6775. lengthOfSourceStream (lengthOfSourceStream_)
  6776. {
  6777. if (deleteSourceWhenDestroyed)
  6778. sourceToDelete = source;
  6779. setPosition (0);
  6780. }
  6781. SubregionStream::~SubregionStream() throw()
  6782. {
  6783. }
  6784. int64 SubregionStream::getTotalLength()
  6785. {
  6786. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  6787. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  6788. : srcLen;
  6789. }
  6790. int64 SubregionStream::getPosition()
  6791. {
  6792. return source->getPosition() - startPositionInSourceStream;
  6793. }
  6794. bool SubregionStream::setPosition (int64 newPosition)
  6795. {
  6796. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  6797. }
  6798. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  6799. {
  6800. if (lengthOfSourceStream < 0)
  6801. {
  6802. return source->read (destBuffer, maxBytesToRead);
  6803. }
  6804. else
  6805. {
  6806. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  6807. if (maxBytesToRead <= 0)
  6808. return 0;
  6809. return source->read (destBuffer, maxBytesToRead);
  6810. }
  6811. }
  6812. bool SubregionStream::isExhausted()
  6813. {
  6814. if (lengthOfSourceStream >= 0)
  6815. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  6816. else
  6817. return source->isExhausted();
  6818. }
  6819. END_JUCE_NAMESPACE
  6820. /*** End of inlined file: juce_SubregionStream.cpp ***/
  6821. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  6822. BEGIN_JUCE_NAMESPACE
  6823. PerformanceCounter::PerformanceCounter (const String& name_,
  6824. int runsPerPrintout,
  6825. const File& loggingFile)
  6826. : name (name_),
  6827. numRuns (0),
  6828. runsPerPrint (runsPerPrintout),
  6829. totalTime (0),
  6830. outputFile (loggingFile)
  6831. {
  6832. if (outputFile != File::nonexistent)
  6833. {
  6834. String s ("**** Counter for \"");
  6835. s << name_ << "\" started at: "
  6836. << Time::getCurrentTime().toString (true, true)
  6837. << "\r\n";
  6838. outputFile.appendText (s, false, false);
  6839. }
  6840. }
  6841. PerformanceCounter::~PerformanceCounter()
  6842. {
  6843. printStatistics();
  6844. }
  6845. void PerformanceCounter::start()
  6846. {
  6847. started = Time::getHighResolutionTicks();
  6848. }
  6849. void PerformanceCounter::stop()
  6850. {
  6851. const int64 now = Time::getHighResolutionTicks();
  6852. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  6853. if (++numRuns == runsPerPrint)
  6854. printStatistics();
  6855. }
  6856. void PerformanceCounter::printStatistics()
  6857. {
  6858. if (numRuns > 0)
  6859. {
  6860. String s ("Performance count for \"");
  6861. s << name << "\" - average over " << numRuns << " run(s) = ";
  6862. const int micros = (int) (totalTime * (1000.0 / numRuns));
  6863. if (micros > 10000)
  6864. s << (micros/1000) << " millisecs";
  6865. else
  6866. s << micros << " microsecs";
  6867. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  6868. Logger::outputDebugString (s);
  6869. s << "\r\n";
  6870. if (outputFile != File::nonexistent)
  6871. outputFile.appendText (s, false, false);
  6872. numRuns = 0;
  6873. totalTime = 0;
  6874. }
  6875. }
  6876. END_JUCE_NAMESPACE
  6877. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  6878. /*** Start of inlined file: juce_Uuid.cpp ***/
  6879. BEGIN_JUCE_NAMESPACE
  6880. Uuid::Uuid()
  6881. {
  6882. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  6883. // to make it very very unlikely that two UUIDs will ever be the same..
  6884. static int64 macAddresses[2];
  6885. static bool hasCheckedMacAddresses = false;
  6886. if (! hasCheckedMacAddresses)
  6887. {
  6888. hasCheckedMacAddresses = true;
  6889. SystemStats::getMACAddresses (macAddresses, 2);
  6890. }
  6891. value.asInt64[0] = macAddresses[0];
  6892. value.asInt64[1] = macAddresses[1];
  6893. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  6894. // whose seed will carry over between calls to this method.
  6895. Random r (macAddresses[0] ^ macAddresses[1]
  6896. ^ Random::getSystemRandom().nextInt64());
  6897. for (int i = 4; --i >= 0;)
  6898. {
  6899. r.setSeedRandomly(); // calling this repeatedly improves randomness
  6900. value.asInt[i] ^= r.nextInt();
  6901. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  6902. }
  6903. }
  6904. Uuid::~Uuid() throw()
  6905. {
  6906. }
  6907. Uuid::Uuid (const Uuid& other)
  6908. : value (other.value)
  6909. {
  6910. }
  6911. Uuid& Uuid::operator= (const Uuid& other)
  6912. {
  6913. value = other.value;
  6914. return *this;
  6915. }
  6916. bool Uuid::operator== (const Uuid& other) const
  6917. {
  6918. return value.asInt64[0] == other.value.asInt64[0]
  6919. && value.asInt64[1] == other.value.asInt64[1];
  6920. }
  6921. bool Uuid::operator!= (const Uuid& other) const
  6922. {
  6923. return ! operator== (other);
  6924. }
  6925. bool Uuid::isNull() const throw()
  6926. {
  6927. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  6928. }
  6929. const String Uuid::toString() const
  6930. {
  6931. return String::toHexString (value.asBytes, sizeof (value.asBytes), 0);
  6932. }
  6933. Uuid::Uuid (const String& uuidString)
  6934. {
  6935. operator= (uuidString);
  6936. }
  6937. Uuid& Uuid::operator= (const String& uuidString)
  6938. {
  6939. MemoryBlock mb;
  6940. mb.loadFromHexString (uuidString);
  6941. mb.ensureSize (sizeof (value.asBytes), true);
  6942. mb.copyTo (value.asBytes, 0, sizeof (value.asBytes));
  6943. return *this;
  6944. }
  6945. Uuid::Uuid (const uint8* const rawData)
  6946. {
  6947. operator= (rawData);
  6948. }
  6949. Uuid& Uuid::operator= (const uint8* const rawData)
  6950. {
  6951. if (rawData != 0)
  6952. memcpy (value.asBytes, rawData, sizeof (value.asBytes));
  6953. else
  6954. zeromem (value.asBytes, sizeof (value.asBytes));
  6955. return *this;
  6956. }
  6957. END_JUCE_NAMESPACE
  6958. /*** End of inlined file: juce_Uuid.cpp ***/
  6959. /*** Start of inlined file: juce_ZipFile.cpp ***/
  6960. BEGIN_JUCE_NAMESPACE
  6961. class ZipFile::ZipEntryInfo
  6962. {
  6963. public:
  6964. ZipFile::ZipEntry entry;
  6965. int streamOffset;
  6966. int compressedSize;
  6967. bool compressed;
  6968. };
  6969. class ZipFile::ZipInputStream : public InputStream
  6970. {
  6971. public:
  6972. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  6973. : file (file_),
  6974. zipEntryInfo (zei),
  6975. pos (0),
  6976. headerSize (0),
  6977. inputStream (0)
  6978. {
  6979. inputStream = file_.inputStream;
  6980. if (file_.inputSource != 0)
  6981. {
  6982. inputStream = file.inputSource->createInputStream();
  6983. }
  6984. else
  6985. {
  6986. #ifdef JUCE_DEBUG
  6987. file_.numOpenStreams++;
  6988. #endif
  6989. }
  6990. char buffer [30];
  6991. if (inputStream != 0
  6992. && inputStream->setPosition (zei.streamOffset)
  6993. && inputStream->read (buffer, 30) == 30
  6994. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  6995. {
  6996. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  6997. + ByteOrder::littleEndianShort (buffer + 28);
  6998. }
  6999. }
  7000. ~ZipInputStream() throw()
  7001. {
  7002. #ifdef JUCE_DEBUG
  7003. if (inputStream != 0 && inputStream == file.inputStream)
  7004. file.numOpenStreams--;
  7005. #endif
  7006. if (inputStream != file.inputStream)
  7007. delete inputStream;
  7008. }
  7009. int64 getTotalLength() throw()
  7010. {
  7011. return zipEntryInfo.compressedSize;
  7012. }
  7013. int read (void* buffer, int howMany) throw()
  7014. {
  7015. if (headerSize <= 0)
  7016. return 0;
  7017. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7018. if (inputStream == 0)
  7019. return 0;
  7020. int num;
  7021. if (inputStream == file.inputStream)
  7022. {
  7023. const ScopedLock sl (file.lock);
  7024. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7025. num = inputStream->read (buffer, howMany);
  7026. }
  7027. else
  7028. {
  7029. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7030. num = inputStream->read (buffer, howMany);
  7031. }
  7032. pos += num;
  7033. return num;
  7034. }
  7035. bool isExhausted() throw()
  7036. {
  7037. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7038. }
  7039. int64 getPosition() throw()
  7040. {
  7041. return pos;
  7042. }
  7043. bool setPosition (int64 newPos) throw()
  7044. {
  7045. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7046. return true;
  7047. }
  7048. private:
  7049. ZipFile& file;
  7050. ZipEntryInfo zipEntryInfo;
  7051. int64 pos;
  7052. int headerSize;
  7053. InputStream* inputStream;
  7054. ZipInputStream (const ZipInputStream&);
  7055. ZipInputStream& operator= (const ZipInputStream&);
  7056. };
  7057. ZipFile::ZipFile (InputStream* const source_,
  7058. const bool deleteStreamWhenDestroyed) throw()
  7059. : inputStream (source_)
  7060. #ifdef JUCE_DEBUG
  7061. , numOpenStreams (0)
  7062. #endif
  7063. {
  7064. if (deleteStreamWhenDestroyed)
  7065. streamToDelete = inputStream;
  7066. init();
  7067. }
  7068. ZipFile::ZipFile (const File& file)
  7069. : inputStream (0)
  7070. #ifdef JUCE_DEBUG
  7071. , numOpenStreams (0)
  7072. #endif
  7073. {
  7074. inputSource = new FileInputSource (file);
  7075. init();
  7076. }
  7077. ZipFile::ZipFile (InputSource* const inputSource_)
  7078. : inputStream (0),
  7079. inputSource (inputSource_)
  7080. #ifdef JUCE_DEBUG
  7081. , numOpenStreams (0)
  7082. #endif
  7083. {
  7084. init();
  7085. }
  7086. ZipFile::~ZipFile() throw()
  7087. {
  7088. #ifdef JUCE_DEBUG
  7089. entries.clear();
  7090. // If you hit this assertion, it means you've created a stream to read
  7091. // one of the items in the zipfile, but you've forgotten to delete that
  7092. // stream object before deleting the file.. Streams can't be kept open
  7093. // after the file is deleted because they need to share the input
  7094. // stream that the file uses to read itself.
  7095. jassert (numOpenStreams == 0);
  7096. #endif
  7097. }
  7098. int ZipFile::getNumEntries() const throw()
  7099. {
  7100. return entries.size();
  7101. }
  7102. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7103. {
  7104. ZipEntryInfo* const zei = entries [index];
  7105. return zei != 0 ? &(zei->entry) : 0;
  7106. }
  7107. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7108. {
  7109. for (int i = 0; i < entries.size(); ++i)
  7110. if (entries.getUnchecked (i)->entry.filename == fileName)
  7111. return i;
  7112. return -1;
  7113. }
  7114. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7115. {
  7116. return getEntry (getIndexOfFileName (fileName));
  7117. }
  7118. InputStream* ZipFile::createStreamForEntry (const int index)
  7119. {
  7120. ZipEntryInfo* const zei = entries[index];
  7121. InputStream* stream = 0;
  7122. if (zei != 0)
  7123. {
  7124. stream = new ZipInputStream (*this, *zei);
  7125. if (zei->compressed)
  7126. {
  7127. stream = new GZIPDecompressorInputStream (stream, true, true,
  7128. zei->entry.uncompressedSize);
  7129. // (much faster to unzip in big blocks using a buffer..)
  7130. stream = new BufferedInputStream (stream, 32768, true);
  7131. }
  7132. }
  7133. return stream;
  7134. }
  7135. class ZipFile::ZipFilenameComparator
  7136. {
  7137. public:
  7138. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7139. {
  7140. return first->entry.filename.compare (second->entry.filename);
  7141. }
  7142. };
  7143. void ZipFile::sortEntriesByFilename()
  7144. {
  7145. ZipFilenameComparator sorter;
  7146. entries.sort (sorter);
  7147. }
  7148. void ZipFile::init()
  7149. {
  7150. ScopedPointer <InputStream> toDelete;
  7151. InputStream* in = inputStream;
  7152. if (inputSource != 0)
  7153. {
  7154. in = inputSource->createInputStream();
  7155. toDelete = in;
  7156. }
  7157. if (in != 0)
  7158. {
  7159. int numEntries = 0;
  7160. int pos = findEndOfZipEntryTable (in, numEntries);
  7161. if (pos >= 0 && pos < in->getTotalLength())
  7162. {
  7163. const int size = (int) (in->getTotalLength() - pos);
  7164. in->setPosition (pos);
  7165. MemoryBlock headerData;
  7166. if (in->readIntoMemoryBlock (headerData, size) == size)
  7167. {
  7168. pos = 0;
  7169. for (int i = 0; i < numEntries; ++i)
  7170. {
  7171. if (pos + 46 > size)
  7172. break;
  7173. const char* const buffer = static_cast <const char*> (headerData.getData()) + pos;
  7174. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7175. if (pos + 46 + fileNameLen > size)
  7176. break;
  7177. ZipEntryInfo* const zei = new ZipEntryInfo();
  7178. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7179. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7180. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7181. const int year = 1980 + (date >> 9);
  7182. const int month = ((date >> 5) & 15) - 1;
  7183. const int day = date & 31;
  7184. const int hours = time >> 11;
  7185. const int minutes = (time >> 5) & 63;
  7186. const int seconds = (time & 31) << 1;
  7187. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7188. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7189. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7190. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7191. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7192. entries.add (zei);
  7193. pos += 46 + fileNameLen
  7194. + ByteOrder::littleEndianShort (buffer + 30)
  7195. + ByteOrder::littleEndianShort (buffer + 32);
  7196. }
  7197. }
  7198. }
  7199. }
  7200. }
  7201. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7202. {
  7203. BufferedInputStream in (input, 8192, false);
  7204. in.setPosition (in.getTotalLength());
  7205. int64 pos = in.getPosition();
  7206. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7207. char buffer [32];
  7208. zeromem (buffer, sizeof (buffer));
  7209. while (pos > lowestPos)
  7210. {
  7211. in.setPosition (pos - 22);
  7212. pos = in.getPosition();
  7213. memcpy (buffer + 22, buffer, 4);
  7214. if (in.read (buffer, 22) != 22)
  7215. return 0;
  7216. for (int i = 0; i < 22; ++i)
  7217. {
  7218. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7219. {
  7220. in.setPosition (pos + i);
  7221. in.read (buffer, 22);
  7222. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7223. return ByteOrder::littleEndianInt (buffer + 16);
  7224. }
  7225. }
  7226. }
  7227. return 0;
  7228. }
  7229. void ZipFile::uncompressTo (const File& targetDirectory,
  7230. const bool shouldOverwriteFiles)
  7231. {
  7232. for (int i = 0; i < entries.size(); ++i)
  7233. {
  7234. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7235. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7236. if (zei.filename.endsWithChar ('/'))
  7237. {
  7238. targetFile.createDirectory(); // (entry is a directory, not a file)
  7239. }
  7240. else
  7241. {
  7242. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7243. if (in != 0)
  7244. {
  7245. if (shouldOverwriteFiles)
  7246. targetFile.deleteFile();
  7247. if ((! targetFile.exists())
  7248. && targetFile.getParentDirectory().createDirectory())
  7249. {
  7250. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7251. if (out != 0)
  7252. {
  7253. out->writeFromInputStream (*in, -1);
  7254. out = 0;
  7255. targetFile.setCreationTime (zei.fileTime);
  7256. targetFile.setLastModificationTime (zei.fileTime);
  7257. targetFile.setLastAccessTime (zei.fileTime);
  7258. }
  7259. }
  7260. }
  7261. }
  7262. }
  7263. }
  7264. END_JUCE_NAMESPACE
  7265. /*** End of inlined file: juce_ZipFile.cpp ***/
  7266. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7267. #ifdef _MSC_VER
  7268. #pragma warning (disable: 4514 4996)
  7269. #pragma warning (push)
  7270. #endif
  7271. #include <cwctype>
  7272. #include <cctype>
  7273. #include <ctime>
  7274. #ifdef _MSC_VER
  7275. #pragma warning (pop)
  7276. #endif
  7277. BEGIN_JUCE_NAMESPACE
  7278. int CharacterFunctions::length (const char* const s) throw()
  7279. {
  7280. return (int) strlen (s);
  7281. }
  7282. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7283. {
  7284. return (int) wcslen (s);
  7285. }
  7286. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7287. {
  7288. strncpy (dest, src, maxChars);
  7289. }
  7290. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7291. {
  7292. wcsncpy (dest, src, maxChars);
  7293. }
  7294. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7295. {
  7296. mbstowcs (dest, src, maxChars);
  7297. }
  7298. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7299. {
  7300. wcstombs (dest, src, maxChars);
  7301. }
  7302. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7303. {
  7304. return (int) wcstombs (0, src, 0);
  7305. }
  7306. void CharacterFunctions::append (char* dest, const char* src) throw()
  7307. {
  7308. strcat (dest, src);
  7309. }
  7310. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7311. {
  7312. wcscat (dest, src);
  7313. }
  7314. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7315. {
  7316. return strcmp (s1, s2);
  7317. }
  7318. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7319. {
  7320. jassert (s1 != 0 && s2 != 0);
  7321. return wcscmp (s1, s2);
  7322. }
  7323. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7324. {
  7325. jassert (s1 != 0 && s2 != 0);
  7326. return strncmp (s1, s2, maxChars);
  7327. }
  7328. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7329. {
  7330. jassert (s1 != 0 && s2 != 0);
  7331. return wcsncmp (s1, s2, maxChars);
  7332. }
  7333. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7334. {
  7335. jassert (s1 != 0 && s2 != 0);
  7336. for (;;)
  7337. {
  7338. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7339. if (diff != 0)
  7340. return diff;
  7341. else if (*s1 == 0)
  7342. break;
  7343. ++s1;
  7344. ++s2;
  7345. }
  7346. return 0;
  7347. }
  7348. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7349. {
  7350. return -compare (s2, s1);
  7351. }
  7352. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7353. {
  7354. jassert (s1 != 0 && s2 != 0);
  7355. #if JUCE_WIN32
  7356. return stricmp (s1, s2);
  7357. #else
  7358. return strcasecmp (s1, s2);
  7359. #endif
  7360. }
  7361. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7362. {
  7363. jassert (s1 != 0 && s2 != 0);
  7364. #if JUCE_WIN32
  7365. return _wcsicmp (s1, s2);
  7366. #else
  7367. for (;;)
  7368. {
  7369. if (*s1 != *s2)
  7370. {
  7371. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7372. if (diff != 0)
  7373. return diff < 0 ? -1 : 1;
  7374. }
  7375. else if (*s1 == 0)
  7376. break;
  7377. ++s1;
  7378. ++s2;
  7379. }
  7380. return 0;
  7381. #endif
  7382. }
  7383. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const char* s2) throw()
  7384. {
  7385. jassert (s1 != 0 && s2 != 0);
  7386. for (;;)
  7387. {
  7388. if (*s1 != *s2)
  7389. {
  7390. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7391. if (diff != 0)
  7392. return diff < 0 ? -1 : 1;
  7393. }
  7394. else if (*s1 == 0)
  7395. break;
  7396. ++s1;
  7397. ++s2;
  7398. }
  7399. return 0;
  7400. }
  7401. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7402. {
  7403. jassert (s1 != 0 && s2 != 0);
  7404. #if JUCE_WIN32
  7405. return strnicmp (s1, s2, maxChars);
  7406. #else
  7407. return strncasecmp (s1, s2, maxChars);
  7408. #endif
  7409. }
  7410. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7411. {
  7412. jassert (s1 != 0 && s2 != 0);
  7413. #if JUCE_WIN32
  7414. return _wcsnicmp (s1, s2, maxChars);
  7415. #else
  7416. while (--maxChars >= 0)
  7417. {
  7418. if (*s1 != *s2)
  7419. {
  7420. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7421. if (diff != 0)
  7422. return diff < 0 ? -1 : 1;
  7423. }
  7424. else if (*s1 == 0)
  7425. break;
  7426. ++s1;
  7427. ++s2;
  7428. }
  7429. return 0;
  7430. #endif
  7431. }
  7432. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7433. {
  7434. return strstr (haystack, needle);
  7435. }
  7436. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7437. {
  7438. return wcsstr (haystack, needle);
  7439. }
  7440. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7441. {
  7442. if (haystack != 0)
  7443. {
  7444. int i = 0;
  7445. if (ignoreCase)
  7446. {
  7447. const char n1 = toLowerCase (needle);
  7448. const char n2 = toUpperCase (needle);
  7449. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7450. {
  7451. while (haystack[i] != 0)
  7452. {
  7453. if (haystack[i] == n1 || haystack[i] == n2)
  7454. return i;
  7455. ++i;
  7456. }
  7457. return -1;
  7458. }
  7459. jassert (n1 == needle);
  7460. }
  7461. while (haystack[i] != 0)
  7462. {
  7463. if (haystack[i] == needle)
  7464. return i;
  7465. ++i;
  7466. }
  7467. }
  7468. return -1;
  7469. }
  7470. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7471. {
  7472. if (haystack != 0)
  7473. {
  7474. int i = 0;
  7475. if (ignoreCase)
  7476. {
  7477. const juce_wchar n1 = toLowerCase (needle);
  7478. const juce_wchar n2 = toUpperCase (needle);
  7479. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7480. {
  7481. while (haystack[i] != 0)
  7482. {
  7483. if (haystack[i] == n1 || haystack[i] == n2)
  7484. return i;
  7485. ++i;
  7486. }
  7487. return -1;
  7488. }
  7489. jassert (n1 == needle);
  7490. }
  7491. while (haystack[i] != 0)
  7492. {
  7493. if (haystack[i] == needle)
  7494. return i;
  7495. ++i;
  7496. }
  7497. }
  7498. return -1;
  7499. }
  7500. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7501. {
  7502. jassert (haystack != 0);
  7503. int i = 0;
  7504. while (haystack[i] != 0)
  7505. {
  7506. if (haystack[i] == needle)
  7507. return i;
  7508. ++i;
  7509. }
  7510. return -1;
  7511. }
  7512. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7513. {
  7514. jassert (haystack != 0);
  7515. int i = 0;
  7516. while (haystack[i] != 0)
  7517. {
  7518. if (haystack[i] == needle)
  7519. return i;
  7520. ++i;
  7521. }
  7522. return -1;
  7523. }
  7524. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7525. {
  7526. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7527. }
  7528. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7529. {
  7530. if (allowedChars == 0)
  7531. return 0;
  7532. int i = 0;
  7533. for (;;)
  7534. {
  7535. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7536. break;
  7537. ++i;
  7538. }
  7539. return i;
  7540. }
  7541. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7542. {
  7543. return (int) strftime (dest, maxChars, format, tm);
  7544. }
  7545. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7546. {
  7547. return (int) wcsftime (dest, maxChars, format, tm);
  7548. }
  7549. int CharacterFunctions::getIntValue (const char* const s) throw()
  7550. {
  7551. return atoi (s);
  7552. }
  7553. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7554. {
  7555. #if JUCE_WIN32
  7556. return _wtoi (s);
  7557. #else
  7558. int v = 0;
  7559. while (isWhitespace (*s))
  7560. ++s;
  7561. const bool isNeg = *s == '-';
  7562. if (isNeg)
  7563. ++s;
  7564. for (;;)
  7565. {
  7566. const wchar_t c = *s++;
  7567. if (c >= '0' && c <= '9')
  7568. v = v * 10 + (int) (c - '0');
  7569. else
  7570. break;
  7571. }
  7572. return isNeg ? -v : v;
  7573. #endif
  7574. }
  7575. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7576. {
  7577. #if JUCE_LINUX
  7578. return atoll (s);
  7579. #elif defined (JUCE_WIN32)
  7580. return _atoi64 (s);
  7581. #else
  7582. int64 v = 0;
  7583. while (isWhitespace (*s))
  7584. ++s;
  7585. const bool isNeg = *s == '-';
  7586. if (isNeg)
  7587. ++s;
  7588. for (;;)
  7589. {
  7590. const char c = *s++;
  7591. if (c >= '0' && c <= '9')
  7592. v = v * 10 + (int64) (c - '0');
  7593. else
  7594. break;
  7595. }
  7596. return isNeg ? -v : v;
  7597. #endif
  7598. }
  7599. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7600. {
  7601. #if JUCE_WIN32
  7602. return _wtoi64 (s);
  7603. #else
  7604. int64 v = 0;
  7605. while (isWhitespace (*s))
  7606. ++s;
  7607. const bool isNeg = *s == '-';
  7608. if (isNeg)
  7609. ++s;
  7610. for (;;)
  7611. {
  7612. const juce_wchar c = *s++;
  7613. if (c >= '0' && c <= '9')
  7614. v = v * 10 + (int64) (c - '0');
  7615. else
  7616. break;
  7617. }
  7618. return isNeg ? -v : v;
  7619. #endif
  7620. }
  7621. static double juce_mulexp10 (const double value, int exponent) throw()
  7622. {
  7623. if (exponent == 0)
  7624. return value;
  7625. if (value == 0)
  7626. return 0;
  7627. const bool negative = (exponent < 0);
  7628. if (negative)
  7629. exponent = -exponent;
  7630. double result = 1.0, power = 10.0;
  7631. for (int bit = 1; exponent != 0; bit <<= 1)
  7632. {
  7633. if ((exponent & bit) != 0)
  7634. {
  7635. exponent ^= bit;
  7636. result *= power;
  7637. if (exponent == 0)
  7638. break;
  7639. }
  7640. power *= power;
  7641. }
  7642. return negative ? (value / result) : (value * result);
  7643. }
  7644. template <class CharType>
  7645. double juce_atof (const CharType* const original) throw()
  7646. {
  7647. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7648. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7649. int exponent = 0, decPointIndex = 0, digit = 0;
  7650. int lastDigit = 0, numSignificantDigits = 0;
  7651. bool isNegative = false, digitsFound = false;
  7652. const int maxSignificantDigits = 15 + 2;
  7653. const CharType* s = original;
  7654. while (CharacterFunctions::isWhitespace (*s))
  7655. ++s;
  7656. switch (*s)
  7657. {
  7658. case '-': isNegative = true; // fall-through..
  7659. case '+': ++s;
  7660. }
  7661. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7662. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  7663. for (;;)
  7664. {
  7665. if (CharacterFunctions::isDigit (*s))
  7666. {
  7667. lastDigit = digit;
  7668. digit = *s++ - '0';
  7669. digitsFound = true;
  7670. if (decPointIndex != 0)
  7671. exponentAdjustment[1]++;
  7672. if (numSignificantDigits == 0 && digit == 0)
  7673. continue;
  7674. if (++numSignificantDigits > maxSignificantDigits)
  7675. {
  7676. if (digit > 5)
  7677. ++accumulator [decPointIndex];
  7678. else if (digit == 5 && (lastDigit & 1) != 0)
  7679. ++accumulator [decPointIndex];
  7680. if (decPointIndex > 0)
  7681. exponentAdjustment[1]--;
  7682. else
  7683. exponentAdjustment[0]++;
  7684. while (CharacterFunctions::isDigit (*s))
  7685. {
  7686. ++s;
  7687. if (decPointIndex == 0)
  7688. exponentAdjustment[0]++;
  7689. }
  7690. }
  7691. else
  7692. {
  7693. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  7694. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7695. {
  7696. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7697. + accumulator [decPointIndex];
  7698. accumulator [decPointIndex] = 0;
  7699. exponentAccumulator [decPointIndex] = 0;
  7700. }
  7701. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7702. exponentAccumulator [decPointIndex]++;
  7703. }
  7704. }
  7705. else if (decPointIndex == 0 && *s == '.')
  7706. {
  7707. ++s;
  7708. decPointIndex = 1;
  7709. if (numSignificantDigits > maxSignificantDigits)
  7710. {
  7711. while (CharacterFunctions::isDigit (*s))
  7712. ++s;
  7713. break;
  7714. }
  7715. }
  7716. else
  7717. {
  7718. break;
  7719. }
  7720. }
  7721. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7722. if (decPointIndex != 0)
  7723. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7724. if ((*s == 'e' || *s == 'E') && digitsFound)
  7725. {
  7726. bool negativeExponent = false;
  7727. switch (*++s)
  7728. {
  7729. case '-': negativeExponent = true; // fall-through..
  7730. case '+': ++s;
  7731. }
  7732. while (CharacterFunctions::isDigit (*s))
  7733. exponent = (exponent * 10) + (*s++ - '0');
  7734. if (negativeExponent)
  7735. exponent = -exponent;
  7736. }
  7737. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7738. if (decPointIndex != 0)
  7739. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7740. return isNegative ? -r : r;
  7741. }
  7742. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7743. {
  7744. return juce_atof <char> (s);
  7745. }
  7746. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7747. {
  7748. return juce_atof <juce_wchar> (s);
  7749. }
  7750. char CharacterFunctions::toUpperCase (const char character) throw()
  7751. {
  7752. return (char) toupper (character);
  7753. }
  7754. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7755. {
  7756. return towupper (character);
  7757. }
  7758. void CharacterFunctions::toUpperCase (char* s) throw()
  7759. {
  7760. #if JUCE_WIN32
  7761. strupr (s);
  7762. #else
  7763. while (*s != 0)
  7764. {
  7765. *s = toUpperCase (*s);
  7766. ++s;
  7767. }
  7768. #endif
  7769. }
  7770. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  7771. {
  7772. #if JUCE_WIN32
  7773. _wcsupr (s);
  7774. #else
  7775. while (*s != 0)
  7776. {
  7777. *s = toUpperCase (*s);
  7778. ++s;
  7779. }
  7780. #endif
  7781. }
  7782. bool CharacterFunctions::isUpperCase (const char character) throw()
  7783. {
  7784. return isupper (character) != 0;
  7785. }
  7786. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  7787. {
  7788. #if JUCE_WIN32
  7789. return iswupper (character) != 0;
  7790. #else
  7791. return toLowerCase (character) != character;
  7792. #endif
  7793. }
  7794. char CharacterFunctions::toLowerCase (const char character) throw()
  7795. {
  7796. return (char) tolower (character);
  7797. }
  7798. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  7799. {
  7800. return towlower (character);
  7801. }
  7802. void CharacterFunctions::toLowerCase (char* s) throw()
  7803. {
  7804. #if JUCE_WIN32
  7805. strlwr (s);
  7806. #else
  7807. while (*s != 0)
  7808. {
  7809. *s = toLowerCase (*s);
  7810. ++s;
  7811. }
  7812. #endif
  7813. }
  7814. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  7815. {
  7816. #if JUCE_WIN32
  7817. _wcslwr (s);
  7818. #else
  7819. while (*s != 0)
  7820. {
  7821. *s = toLowerCase (*s);
  7822. ++s;
  7823. }
  7824. #endif
  7825. }
  7826. bool CharacterFunctions::isLowerCase (const char character) throw()
  7827. {
  7828. return islower (character) != 0;
  7829. }
  7830. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  7831. {
  7832. #if JUCE_WIN32
  7833. return iswlower (character) != 0;
  7834. #else
  7835. return toUpperCase (character) != character;
  7836. #endif
  7837. }
  7838. bool CharacterFunctions::isWhitespace (const char character) throw()
  7839. {
  7840. return character == ' ' || (character <= 13 && character >= 9);
  7841. }
  7842. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  7843. {
  7844. return iswspace (character) != 0;
  7845. }
  7846. bool CharacterFunctions::isDigit (const char character) throw()
  7847. {
  7848. return (character >= '0' && character <= '9');
  7849. }
  7850. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  7851. {
  7852. return iswdigit (character) != 0;
  7853. }
  7854. bool CharacterFunctions::isLetter (const char character) throw()
  7855. {
  7856. return (character >= 'a' && character <= 'z')
  7857. || (character >= 'A' && character <= 'Z');
  7858. }
  7859. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  7860. {
  7861. return iswalpha (character) != 0;
  7862. }
  7863. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  7864. {
  7865. return (character >= 'a' && character <= 'z')
  7866. || (character >= 'A' && character <= 'Z')
  7867. || (character >= '0' && character <= '9');
  7868. }
  7869. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  7870. {
  7871. return iswalnum (character) != 0;
  7872. }
  7873. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  7874. {
  7875. if (digit >= '0' && digit <= '9')
  7876. return digit - '0';
  7877. else if (digit >= 'a' && digit <= 'f')
  7878. return digit - ('a' - 10);
  7879. else if (digit >= 'A' && digit <= 'F')
  7880. return digit - ('A' - 10);
  7881. return -1;
  7882. }
  7883. END_JUCE_NAMESPACE
  7884. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  7885. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  7886. BEGIN_JUCE_NAMESPACE
  7887. LocalisedStrings::LocalisedStrings (const String& fileContents)
  7888. {
  7889. loadFromText (fileContents);
  7890. }
  7891. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  7892. {
  7893. loadFromText (fileToLoad.loadFileAsString());
  7894. }
  7895. LocalisedStrings::~LocalisedStrings()
  7896. {
  7897. }
  7898. const String LocalisedStrings::translate (const String& text) const
  7899. {
  7900. return translations.getValue (text, text);
  7901. }
  7902. static int findCloseQuote (const String& text, int startPos)
  7903. {
  7904. juce_wchar lastChar = 0;
  7905. for (;;)
  7906. {
  7907. const juce_wchar c = text [startPos];
  7908. if (c == 0 || (c == '"' && lastChar != '\\'))
  7909. break;
  7910. lastChar = c;
  7911. ++startPos;
  7912. }
  7913. return startPos;
  7914. }
  7915. static const String unescapeString (const String& s)
  7916. {
  7917. return s.replace ("\\\"", "\"")
  7918. .replace ("\\\'", "\'")
  7919. .replace ("\\t", "\t")
  7920. .replace ("\\r", "\r")
  7921. .replace ("\\n", "\n");
  7922. }
  7923. void LocalisedStrings::loadFromText (const String& fileContents)
  7924. {
  7925. StringArray lines;
  7926. lines.addLines (fileContents);
  7927. for (int i = 0; i < lines.size(); ++i)
  7928. {
  7929. String line (lines[i].trim());
  7930. if (line.startsWithChar ('"'))
  7931. {
  7932. int closeQuote = findCloseQuote (line, 1);
  7933. const String originalText (unescapeString (line.substring (1, closeQuote)));
  7934. if (originalText.isNotEmpty())
  7935. {
  7936. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  7937. closeQuote = findCloseQuote (line, openingQuote + 1);
  7938. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  7939. if (newText.isNotEmpty())
  7940. translations.set (originalText, newText);
  7941. }
  7942. }
  7943. else if (line.startsWithIgnoreCase ("language:"))
  7944. {
  7945. languageName = line.substring (9).trim();
  7946. }
  7947. else if (line.startsWithIgnoreCase ("countries:"))
  7948. {
  7949. countryCodes.addTokens (line.substring (10).trim(), true);
  7950. countryCodes.trim();
  7951. countryCodes.removeEmptyStrings();
  7952. }
  7953. }
  7954. }
  7955. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  7956. {
  7957. translations.setIgnoresCase (shouldIgnoreCase);
  7958. }
  7959. static CriticalSection currentMappingsLock;
  7960. static LocalisedStrings* currentMappings = 0;
  7961. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  7962. {
  7963. const ScopedLock sl (currentMappingsLock);
  7964. delete currentMappings;
  7965. currentMappings = newTranslations;
  7966. }
  7967. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  7968. {
  7969. return currentMappings;
  7970. }
  7971. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  7972. {
  7973. const ScopedLock sl (currentMappingsLock);
  7974. if (currentMappings != 0)
  7975. return currentMappings->translate (text);
  7976. return text;
  7977. }
  7978. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  7979. {
  7980. return translateWithCurrentMappings (String (text));
  7981. }
  7982. END_JUCE_NAMESPACE
  7983. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  7984. /*** Start of inlined file: juce_String.cpp ***/
  7985. #ifdef _MSC_VER
  7986. #pragma warning (push)
  7987. #pragma warning (disable: 4514)
  7988. #endif
  7989. #include <locale>
  7990. #if JUCE_MSVC
  7991. #include <float.h>
  7992. #endif
  7993. BEGIN_JUCE_NAMESPACE
  7994. #ifdef _MSC_VER
  7995. #pragma warning (pop)
  7996. #endif
  7997. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  7998. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  7999. #endif
  8000. class StringHolder
  8001. {
  8002. public:
  8003. StringHolder()
  8004. : refCount (0x3fffffff), allocatedNumChars (0)
  8005. {
  8006. text[0] = 0;
  8007. }
  8008. static juce_wchar* createUninitialised (const size_t numChars)
  8009. {
  8010. StringHolder* const s = reinterpret_cast <StringHolder*> (new char [sizeof (StringHolder) + numChars * sizeof (juce_wchar)]);
  8011. s->refCount = 0;
  8012. s->allocatedNumChars = numChars;
  8013. return &(s->text[0]);
  8014. }
  8015. static juce_wchar* createCopy (const juce_wchar* const src, const size_t numChars)
  8016. {
  8017. juce_wchar* const dest = createUninitialised (numChars);
  8018. copyChars (dest, src, numChars);
  8019. return dest;
  8020. }
  8021. static juce_wchar* createCopy (const char* const src, const size_t numChars)
  8022. {
  8023. juce_wchar* const dest = createUninitialised (numChars);
  8024. CharacterFunctions::copy (dest, src, (int) numChars);
  8025. dest [numChars] = 0;
  8026. return dest;
  8027. }
  8028. static inline juce_wchar* getEmpty() throw()
  8029. {
  8030. return &(empty.text[0]);
  8031. }
  8032. static void retain (juce_wchar* const text) throw()
  8033. {
  8034. Atomic::increment (bufferFromText (text)->refCount);
  8035. }
  8036. static inline void release (StringHolder* const b) throw()
  8037. {
  8038. if (Atomic::decrementAndReturn (b->refCount) == -1 && b != &empty)
  8039. delete[] reinterpret_cast <char*> (b);
  8040. }
  8041. static void release (juce_wchar* const text) throw()
  8042. {
  8043. release (bufferFromText (text));
  8044. }
  8045. static juce_wchar* makeUnique (juce_wchar* const text)
  8046. {
  8047. StringHolder* const b = bufferFromText (text);
  8048. if (b->refCount <= 0)
  8049. return text;
  8050. juce_wchar* const newText = createCopy (text, b->allocatedNumChars);
  8051. release (b);
  8052. return newText;
  8053. }
  8054. static juce_wchar* makeUniqueWithSize (juce_wchar* const text, size_t numChars)
  8055. {
  8056. StringHolder* const b = bufferFromText (text);
  8057. if (b->refCount <= 0 && b->allocatedNumChars >= numChars)
  8058. return text;
  8059. juce_wchar* const newText = createUninitialised (jmax (b->allocatedNumChars, numChars));
  8060. copyChars (newText, text, b->allocatedNumChars);
  8061. release (b);
  8062. return newText;
  8063. }
  8064. static size_t getAllocatedNumChars (juce_wchar* const text) throw()
  8065. {
  8066. return bufferFromText (text)->allocatedNumChars;
  8067. }
  8068. static void copyChars (juce_wchar* const dest, const juce_wchar* const src, const size_t numChars) throw()
  8069. {
  8070. memcpy (dest, src, numChars * sizeof (juce_wchar));
  8071. dest [numChars] = 0;
  8072. }
  8073. int refCount;
  8074. size_t allocatedNumChars;
  8075. juce_wchar text[1];
  8076. static StringHolder empty;
  8077. private:
  8078. static inline StringHolder* bufferFromText (void* const text) throw()
  8079. {
  8080. // (Can't use offsetof() here because of warnings about this not being a POD)
  8081. return reinterpret_cast <StringHolder*> (static_cast <char*> (text)
  8082. - (reinterpret_cast <size_t> (reinterpret_cast <StringHolder*> (1)->text) - 1));
  8083. }
  8084. };
  8085. StringHolder StringHolder::empty;
  8086. const String String::empty;
  8087. void String::createInternal (const juce_wchar* const t, const size_t numChars)
  8088. {
  8089. jassert (t[numChars] == 0); // must have a null terminator
  8090. text = StringHolder::createCopy (t, numChars);
  8091. }
  8092. void String::appendInternal (const juce_wchar* const newText, const int numExtraChars)
  8093. {
  8094. if (numExtraChars > 0)
  8095. {
  8096. const int oldLen = length();
  8097. const int newTotalLen = oldLen + numExtraChars;
  8098. text = StringHolder::makeUniqueWithSize (text, newTotalLen);
  8099. StringHolder::copyChars (text + oldLen, newText, numExtraChars);
  8100. }
  8101. }
  8102. void String::preallocateStorage (const size_t numChars)
  8103. {
  8104. text = StringHolder::makeUniqueWithSize (text, numChars);
  8105. }
  8106. String::String() throw()
  8107. : text (StringHolder::getEmpty())
  8108. {
  8109. }
  8110. String::~String() throw()
  8111. {
  8112. StringHolder::release (text);
  8113. }
  8114. String::String (const String& other) throw()
  8115. : text (other.text)
  8116. {
  8117. StringHolder::retain (text);
  8118. }
  8119. void String::swapWith (String& other) throw()
  8120. {
  8121. swapVariables (text, other.text);
  8122. }
  8123. String& String::operator= (const String& other) throw()
  8124. {
  8125. juce_wchar* const newText = other.text;
  8126. StringHolder::retain (newText);
  8127. StringHolder::release (static_cast <juce_wchar*> (Atomic::swapPointers ((void* volatile*) &text, newText)));
  8128. return *this;
  8129. }
  8130. String::String (const size_t numChars, const int /*dummyVariable*/)
  8131. : text (StringHolder::createUninitialised (numChars))
  8132. {
  8133. }
  8134. String::String (const String& stringToCopy, const size_t charsToAllocate)
  8135. {
  8136. const size_t otherSize = StringHolder::getAllocatedNumChars (stringToCopy.text);
  8137. text = StringHolder::createUninitialised (jmax (charsToAllocate, otherSize));
  8138. StringHolder::copyChars (text, stringToCopy.text, otherSize);
  8139. }
  8140. String::String (const char* const t)
  8141. {
  8142. if (t != 0 && *t != 0)
  8143. text = StringHolder::createCopy (t, CharacterFunctions::length (t));
  8144. else
  8145. text = StringHolder::getEmpty();
  8146. }
  8147. String::String (const juce_wchar* const t)
  8148. {
  8149. if (t != 0 && *t != 0)
  8150. text = StringHolder::createCopy (t, CharacterFunctions::length (t));
  8151. else
  8152. text = StringHolder::getEmpty();
  8153. }
  8154. String::String (const char* const t, const size_t maxChars)
  8155. {
  8156. int i;
  8157. for (i = 0; (size_t) i < maxChars; ++i)
  8158. if (t[i] == 0)
  8159. break;
  8160. if (i > 0)
  8161. text = StringHolder::createCopy (t, i);
  8162. else
  8163. text = StringHolder::getEmpty();
  8164. }
  8165. String::String (const juce_wchar* const t, const size_t maxChars)
  8166. {
  8167. int i;
  8168. for (i = 0; (size_t) i < maxChars; ++i)
  8169. if (t[i] == 0)
  8170. break;
  8171. if (i > 0)
  8172. text = StringHolder::createCopy (t, i);
  8173. else
  8174. text = StringHolder::getEmpty();
  8175. }
  8176. const String String::charToString (const juce_wchar character)
  8177. {
  8178. String result ((size_t) 1, (int) 0);
  8179. result.text[0] = character;
  8180. result.text[1] = 0;
  8181. return result;
  8182. }
  8183. namespace NumberToStringConverters
  8184. {
  8185. // pass in a pointer to the END of a buffer..
  8186. static juce_wchar* int64ToString (juce_wchar* t, const int64 n) throw()
  8187. {
  8188. *--t = 0;
  8189. int64 v = (n >= 0) ? n : -n;
  8190. do
  8191. {
  8192. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8193. v /= 10;
  8194. } while (v > 0);
  8195. if (n < 0)
  8196. *--t = '-';
  8197. return t;
  8198. }
  8199. static juce_wchar* uint64ToString (juce_wchar* t, int64 v) throw()
  8200. {
  8201. *--t = 0;
  8202. do
  8203. {
  8204. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8205. v /= 10;
  8206. } while (v > 0);
  8207. return t;
  8208. }
  8209. static juce_wchar* intToString (juce_wchar* t, const int n) throw()
  8210. {
  8211. if (n == (int) 0x80000000) // (would cause an overflow)
  8212. return int64ToString (t, n);
  8213. *--t = 0;
  8214. int v = abs (n);
  8215. do
  8216. {
  8217. *--t = (juce_wchar) ('0' + (v % 10));
  8218. v /= 10;
  8219. } while (v > 0);
  8220. if (n < 0)
  8221. *--t = '-';
  8222. return t;
  8223. }
  8224. static juce_wchar* uintToString (juce_wchar* t, unsigned int v) throw()
  8225. {
  8226. *--t = 0;
  8227. do
  8228. {
  8229. *--t = (juce_wchar) ('0' + (v % 10));
  8230. v /= 10;
  8231. } while (v > 0);
  8232. return t;
  8233. }
  8234. static juce_wchar getDecimalPoint()
  8235. {
  8236. #if JUCE_WINDOWS && _MSC_VER < 1400
  8237. static juce_wchar dp = std::_USE (std::locale(), std::numpunct <wchar_t>).decimal_point();
  8238. #else
  8239. static juce_wchar dp = std::use_facet <std::numpunct <wchar_t> > (std::locale()).decimal_point();
  8240. #endif
  8241. return dp;
  8242. }
  8243. static juce_wchar* doubleToString (juce_wchar* buffer, int numChars, double n, int numDecPlaces, size_t& len) throw()
  8244. {
  8245. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8246. {
  8247. juce_wchar* const end = buffer + numChars;
  8248. juce_wchar* t = end;
  8249. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8250. *--t = (juce_wchar) 0;
  8251. while (numDecPlaces >= 0 || v > 0)
  8252. {
  8253. if (numDecPlaces == 0)
  8254. *--t = getDecimalPoint();
  8255. *--t = (juce_wchar) ('0' + (v % 10));
  8256. v /= 10;
  8257. --numDecPlaces;
  8258. }
  8259. if (n < 0)
  8260. *--t = '-';
  8261. len = end - t - 1;
  8262. return t;
  8263. }
  8264. else
  8265. {
  8266. #if JUCE_WIN32
  8267. #if _MSC_VER <= 1400
  8268. len = _snwprintf (buffer, numChars, L"%.9g", n);
  8269. #else
  8270. len = _snwprintf_s (buffer, numChars, _TRUNCATE, L"%.9g", n);
  8271. #endif
  8272. #else
  8273. len = swprintf (buffer, numChars, L"%.9g", n);
  8274. #endif
  8275. return buffer;
  8276. }
  8277. }
  8278. }
  8279. String::String (const int number)
  8280. {
  8281. juce_wchar buffer [16];
  8282. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8283. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8284. createInternal (start, end - start - 1);
  8285. }
  8286. String::String (const unsigned int number)
  8287. {
  8288. juce_wchar buffer [16];
  8289. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8290. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8291. createInternal (start, end - start - 1);
  8292. }
  8293. String::String (const short number)
  8294. {
  8295. juce_wchar buffer [16];
  8296. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8297. juce_wchar* const start = NumberToStringConverters::intToString (end, (int) number);
  8298. createInternal (start, end - start - 1);
  8299. }
  8300. String::String (const unsigned short number)
  8301. {
  8302. juce_wchar buffer [16];
  8303. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8304. juce_wchar* const start = NumberToStringConverters::uintToString (end, (unsigned int) number);
  8305. createInternal (start, end - start - 1);
  8306. }
  8307. String::String (const int64 number)
  8308. {
  8309. juce_wchar buffer [32];
  8310. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8311. juce_wchar* const start = NumberToStringConverters::int64ToString (end, number);
  8312. createInternal (start, end - start - 1);
  8313. }
  8314. String::String (const uint64 number)
  8315. {
  8316. juce_wchar buffer [32];
  8317. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8318. juce_wchar* const start = NumberToStringConverters::uint64ToString (end, number);
  8319. createInternal (start, end - start - 1);
  8320. }
  8321. String::String (const float number, const int numberOfDecimalPlaces)
  8322. {
  8323. juce_wchar buffer [48];
  8324. size_t len;
  8325. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len);
  8326. createInternal (start, len);
  8327. }
  8328. String::String (const double number, const int numberOfDecimalPlaces)
  8329. {
  8330. juce_wchar buffer [48];
  8331. size_t len;
  8332. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), number, numberOfDecimalPlaces, len);
  8333. createInternal (start, len);
  8334. }
  8335. int String::length() const throw()
  8336. {
  8337. return CharacterFunctions::length (text);
  8338. }
  8339. int String::hashCode() const throw()
  8340. {
  8341. const juce_wchar* t = text;
  8342. int result = 0;
  8343. while (*t != (juce_wchar) 0)
  8344. result = 31 * result + *t++;
  8345. return result;
  8346. }
  8347. int64 String::hashCode64() const throw()
  8348. {
  8349. const juce_wchar* t = text;
  8350. int64 result = 0;
  8351. while (*t != (juce_wchar) 0)
  8352. result = 101 * result + *t++;
  8353. return result;
  8354. }
  8355. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8356. {
  8357. return string1.compare (string2) == 0;
  8358. }
  8359. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8360. {
  8361. return string1.compare (string2) == 0;
  8362. }
  8363. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8364. {
  8365. return string1.compare (string2) == 0;
  8366. }
  8367. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8368. {
  8369. return string1.compare (string2) != 0;
  8370. }
  8371. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8372. {
  8373. return string1.compare (string2) != 0;
  8374. }
  8375. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8376. {
  8377. return string1.compare (string2) != 0;
  8378. }
  8379. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8380. {
  8381. return string1.compare (string2) > 0;
  8382. }
  8383. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8384. {
  8385. return string1.compare (string2) < 0;
  8386. }
  8387. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8388. {
  8389. return string1.compare (string2) >= 0;
  8390. }
  8391. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8392. {
  8393. return string1.compare (string2) <= 0;
  8394. }
  8395. bool String::equalsIgnoreCase (const juce_wchar* t) const throw()
  8396. {
  8397. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8398. : isEmpty();
  8399. }
  8400. bool String::equalsIgnoreCase (const char* t) const throw()
  8401. {
  8402. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8403. : isEmpty();
  8404. }
  8405. bool String::equalsIgnoreCase (const String& other) const throw()
  8406. {
  8407. return text == other.text
  8408. || CharacterFunctions::compareIgnoreCase (text, other.text) == 0;
  8409. }
  8410. int String::compare (const String& other) const throw()
  8411. {
  8412. return (text == other.text) ? 0 : CharacterFunctions::compare (text, other.text);
  8413. }
  8414. int String::compare (const char* other) const throw()
  8415. {
  8416. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8417. }
  8418. int String::compare (const juce_wchar* other) const throw()
  8419. {
  8420. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8421. }
  8422. int String::compareIgnoreCase (const String& other) const throw()
  8423. {
  8424. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text, other.text);
  8425. }
  8426. int String::compareLexicographically (const String& other) const throw()
  8427. {
  8428. const juce_wchar* s1 = text;
  8429. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8430. ++s1;
  8431. const juce_wchar* s2 = other.text;
  8432. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8433. ++s2;
  8434. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8435. }
  8436. String& String::operator+= (const juce_wchar* const t)
  8437. {
  8438. if (t != 0)
  8439. appendInternal (t, CharacterFunctions::length (t));
  8440. return *this;
  8441. }
  8442. String& String::operator+= (const String& other)
  8443. {
  8444. if (isEmpty())
  8445. operator= (other);
  8446. else
  8447. appendInternal (other.text, other.length());
  8448. return *this;
  8449. }
  8450. String& String::operator+= (const char ch)
  8451. {
  8452. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8453. return operator+= (static_cast <const juce_wchar*> (asString));
  8454. }
  8455. String& String::operator+= (const juce_wchar ch)
  8456. {
  8457. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8458. return operator+= (static_cast <const juce_wchar*> (asString));
  8459. }
  8460. String& String::operator+= (const int number)
  8461. {
  8462. juce_wchar buffer [16];
  8463. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8464. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8465. appendInternal (start, (int) (end - start));
  8466. return *this;
  8467. }
  8468. String& String::operator+= (const unsigned int number)
  8469. {
  8470. juce_wchar buffer [16];
  8471. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8472. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8473. appendInternal (start, (int) (end - start));
  8474. return *this;
  8475. }
  8476. void String::append (const juce_wchar* const other, const int howMany)
  8477. {
  8478. if (howMany > 0)
  8479. {
  8480. int i;
  8481. for (i = 0; i < howMany; ++i)
  8482. if (other[i] == 0)
  8483. break;
  8484. appendInternal (other, i);
  8485. }
  8486. }
  8487. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8488. {
  8489. String s (string1);
  8490. return s += string2;
  8491. }
  8492. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8493. {
  8494. String s (string1);
  8495. return s += string2;
  8496. }
  8497. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8498. {
  8499. return String::charToString (string1) + string2;
  8500. }
  8501. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8502. {
  8503. return String::charToString (string1) + string2;
  8504. }
  8505. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8506. {
  8507. return string1 += string2;
  8508. }
  8509. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8510. {
  8511. return string1 += string2;
  8512. }
  8513. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8514. {
  8515. return string1 += string2;
  8516. }
  8517. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8518. {
  8519. return string1 += string2;
  8520. }
  8521. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8522. {
  8523. return string1 += string2;
  8524. }
  8525. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8526. {
  8527. return string1 += characterToAppend;
  8528. }
  8529. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8530. {
  8531. return string1 += characterToAppend;
  8532. }
  8533. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8534. {
  8535. return string1 += string2;
  8536. }
  8537. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8538. {
  8539. return string1 += string2;
  8540. }
  8541. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8542. {
  8543. return string1 += string2;
  8544. }
  8545. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8546. {
  8547. return string1 += (int) number;
  8548. }
  8549. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8550. {
  8551. return string1 += number;
  8552. }
  8553. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8554. {
  8555. return string1 += number;
  8556. }
  8557. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8558. {
  8559. return string1 += (int) number;
  8560. }
  8561. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8562. {
  8563. return string1 += (unsigned int) number;
  8564. }
  8565. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8566. {
  8567. return string1 += String (number);
  8568. }
  8569. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8570. {
  8571. return string1 += String (number);
  8572. }
  8573. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8574. {
  8575. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8576. // if lots of large, persistent strings were to be written to streams).
  8577. const int numBytes = text.getNumBytesAsUTF8();
  8578. HeapBlock<char> temp (numBytes + 1);
  8579. text.copyToUTF8 (temp, numBytes + 1);
  8580. stream.write (temp, numBytes);
  8581. return stream;
  8582. }
  8583. int String::indexOfChar (const juce_wchar character) const throw()
  8584. {
  8585. const juce_wchar* t = text;
  8586. for (;;)
  8587. {
  8588. if (*t == character)
  8589. return (int) (t - text);
  8590. if (*t++ == 0)
  8591. return -1;
  8592. }
  8593. }
  8594. int String::lastIndexOfChar (const juce_wchar character) const throw()
  8595. {
  8596. for (int i = length(); --i >= 0;)
  8597. if (text[i] == character)
  8598. return i;
  8599. return -1;
  8600. }
  8601. int String::indexOf (const String& t) const throw()
  8602. {
  8603. const juce_wchar* const r = CharacterFunctions::find (text, t.text);
  8604. return r == 0 ? -1 : (int) (r - text);
  8605. }
  8606. int String::indexOfChar (const int startIndex,
  8607. const juce_wchar character) const throw()
  8608. {
  8609. if (startIndex > 0 && startIndex >= length())
  8610. return -1;
  8611. const juce_wchar* t = text + jmax (0, startIndex);
  8612. for (;;)
  8613. {
  8614. if (*t == character)
  8615. return (int) (t - text);
  8616. if (*t == 0)
  8617. return -1;
  8618. ++t;
  8619. }
  8620. }
  8621. int String::indexOfAnyOf (const String& charactersToLookFor,
  8622. const int startIndex,
  8623. const bool ignoreCase) const throw()
  8624. {
  8625. if (startIndex > 0 && startIndex >= length())
  8626. return -1;
  8627. const juce_wchar* t = text + jmax (0, startIndex);
  8628. while (*t != 0)
  8629. {
  8630. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, *t, ignoreCase) >= 0)
  8631. return (int) (t - text);
  8632. ++t;
  8633. }
  8634. return -1;
  8635. }
  8636. int String::indexOf (const int startIndex, const String& other) const throw()
  8637. {
  8638. if (startIndex > 0 && startIndex >= length())
  8639. return -1;
  8640. const juce_wchar* const found = CharacterFunctions::find (text + jmax (0, startIndex), other.text);
  8641. return found == 0 ? -1 : (int) (found - text);
  8642. }
  8643. int String::indexOfIgnoreCase (const String& other) const throw()
  8644. {
  8645. if (other.isNotEmpty())
  8646. {
  8647. const int len = other.length();
  8648. const int end = length() - len;
  8649. for (int i = 0; i <= end; ++i)
  8650. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8651. return i;
  8652. }
  8653. return -1;
  8654. }
  8655. int String::indexOfIgnoreCase (const int startIndex, const String& other) const throw()
  8656. {
  8657. if (other.isNotEmpty())
  8658. {
  8659. const int len = other.length();
  8660. const int end = length() - len;
  8661. for (int i = jmax (0, startIndex); i <= end; ++i)
  8662. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8663. return i;
  8664. }
  8665. return -1;
  8666. }
  8667. int String::lastIndexOf (const String& other) const throw()
  8668. {
  8669. if (other.isNotEmpty())
  8670. {
  8671. const int len = other.length();
  8672. int i = length() - len;
  8673. if (i >= 0)
  8674. {
  8675. const juce_wchar* n = text + i;
  8676. while (i >= 0)
  8677. {
  8678. if (CharacterFunctions::compare (n--, other.text, len) == 0)
  8679. return i;
  8680. --i;
  8681. }
  8682. }
  8683. }
  8684. return -1;
  8685. }
  8686. int String::lastIndexOfIgnoreCase (const String& other) const throw()
  8687. {
  8688. if (other.isNotEmpty())
  8689. {
  8690. const int len = other.length();
  8691. int i = length() - len;
  8692. if (i >= 0)
  8693. {
  8694. const juce_wchar* n = text + i;
  8695. while (i >= 0)
  8696. {
  8697. if (CharacterFunctions::compareIgnoreCase (n--, other.text, len) == 0)
  8698. return i;
  8699. --i;
  8700. }
  8701. }
  8702. }
  8703. return -1;
  8704. }
  8705. int String::lastIndexOfAnyOf (const String& charactersToLookFor, const bool ignoreCase) const throw()
  8706. {
  8707. for (int i = length(); --i >= 0;)
  8708. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, text[i], ignoreCase) >= 0)
  8709. return i;
  8710. return -1;
  8711. }
  8712. bool String::contains (const String& other) const throw()
  8713. {
  8714. return indexOf (other) >= 0;
  8715. }
  8716. bool String::containsChar (const juce_wchar character) const throw()
  8717. {
  8718. const juce_wchar* t = text;
  8719. for (;;)
  8720. {
  8721. if (*t == 0)
  8722. return false;
  8723. if (*t == character)
  8724. return true;
  8725. ++t;
  8726. }
  8727. }
  8728. bool String::containsIgnoreCase (const String& t) const throw()
  8729. {
  8730. return indexOfIgnoreCase (t) >= 0;
  8731. }
  8732. int String::indexOfWholeWord (const String& word) const throw()
  8733. {
  8734. if (word.isNotEmpty())
  8735. {
  8736. const int wordLen = word.length();
  8737. const int end = length() - wordLen;
  8738. const juce_wchar* t = text;
  8739. for (int i = 0; i <= end; ++i)
  8740. {
  8741. if (CharacterFunctions::compare (t, word.text, wordLen) == 0
  8742. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8743. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8744. {
  8745. return i;
  8746. }
  8747. ++t;
  8748. }
  8749. }
  8750. return -1;
  8751. }
  8752. int String::indexOfWholeWordIgnoreCase (const String& word) const throw()
  8753. {
  8754. if (word.isNotEmpty())
  8755. {
  8756. const int wordLen = word.length();
  8757. const int end = length() - wordLen;
  8758. const juce_wchar* t = text;
  8759. for (int i = 0; i <= end; ++i)
  8760. {
  8761. if (CharacterFunctions::compareIgnoreCase (t, word.text, wordLen) == 0
  8762. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8763. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8764. {
  8765. return i;
  8766. }
  8767. ++t;
  8768. }
  8769. }
  8770. return -1;
  8771. }
  8772. bool String::containsWholeWord (const String& wordToLookFor) const throw()
  8773. {
  8774. return indexOfWholeWord (wordToLookFor) >= 0;
  8775. }
  8776. bool String::containsWholeWordIgnoreCase (const String& wordToLookFor) const throw()
  8777. {
  8778. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  8779. }
  8780. static int indexOfMatch (const juce_wchar* const wildcard,
  8781. const juce_wchar* const test,
  8782. const bool ignoreCase) throw()
  8783. {
  8784. int start = 0;
  8785. while (test [start] != 0)
  8786. {
  8787. int i = 0;
  8788. for (;;)
  8789. {
  8790. const juce_wchar wc = wildcard [i];
  8791. const juce_wchar c = test [i + start];
  8792. if (wc == c
  8793. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  8794. || (wc == '?' && c != 0))
  8795. {
  8796. if (wc == 0)
  8797. return start;
  8798. ++i;
  8799. }
  8800. else
  8801. {
  8802. if (wc == '*' && (wildcard [i + 1] == 0
  8803. || indexOfMatch (wildcard + i + 1,
  8804. test + start + i,
  8805. ignoreCase) >= 0))
  8806. {
  8807. return start;
  8808. }
  8809. break;
  8810. }
  8811. }
  8812. ++start;
  8813. }
  8814. return -1;
  8815. }
  8816. bool String::matchesWildcard (const String& wildcard, const bool ignoreCase) const throw()
  8817. {
  8818. int i = 0;
  8819. for (;;)
  8820. {
  8821. const juce_wchar wc = wildcard.text [i];
  8822. const juce_wchar c = text [i];
  8823. if (wc == c
  8824. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  8825. || (wc == '?' && c != 0))
  8826. {
  8827. if (wc == 0)
  8828. return true;
  8829. ++i;
  8830. }
  8831. else
  8832. {
  8833. return wc == '*' && (wildcard [i + 1] == 0
  8834. || indexOfMatch (wildcard.text + i + 1,
  8835. text + i,
  8836. ignoreCase) >= 0);
  8837. }
  8838. }
  8839. }
  8840. const String String::repeatedString (const String& stringToRepeat, int numberOfTimesToRepeat)
  8841. {
  8842. const int len = stringToRepeat.length();
  8843. String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
  8844. juce_wchar* n = result.text;
  8845. *n = 0;
  8846. while (--numberOfTimesToRepeat >= 0)
  8847. {
  8848. StringHolder::copyChars (n, stringToRepeat.text, len);
  8849. n += len;
  8850. }
  8851. return result;
  8852. }
  8853. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  8854. {
  8855. jassert (padCharacter != 0);
  8856. const int len = length();
  8857. if (len >= minimumLength || padCharacter == 0)
  8858. return *this;
  8859. String result ((size_t) minimumLength + 1, (int) 0);
  8860. juce_wchar* n = result.text;
  8861. minimumLength -= len;
  8862. while (--minimumLength >= 0)
  8863. *n++ = padCharacter;
  8864. StringHolder::copyChars (n, text, len);
  8865. return result;
  8866. }
  8867. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  8868. {
  8869. jassert (padCharacter != 0);
  8870. const int len = length();
  8871. if (len >= minimumLength || padCharacter == 0)
  8872. return *this;
  8873. String result (*this, (size_t) minimumLength);
  8874. juce_wchar* n = result.text + len;
  8875. minimumLength -= len;
  8876. while (--minimumLength >= 0)
  8877. *n++ = padCharacter;
  8878. *n = 0;
  8879. return result;
  8880. }
  8881. const String String::replaceSection (int index, int numCharsToReplace, const String& stringToInsert) const
  8882. {
  8883. if (index < 0)
  8884. {
  8885. // a negative index to replace from?
  8886. jassertfalse
  8887. index = 0;
  8888. }
  8889. if (numCharsToReplace < 0)
  8890. {
  8891. // replacing a negative number of characters?
  8892. numCharsToReplace = 0;
  8893. jassertfalse;
  8894. }
  8895. const int len = length();
  8896. if (index + numCharsToReplace > len)
  8897. {
  8898. if (index > len)
  8899. {
  8900. // replacing beyond the end of the string?
  8901. index = len;
  8902. jassertfalse
  8903. }
  8904. numCharsToReplace = len - index;
  8905. }
  8906. const int newStringLen = stringToInsert.length();
  8907. const int newTotalLen = len + newStringLen - numCharsToReplace;
  8908. if (newTotalLen <= 0)
  8909. return String::empty;
  8910. String result ((size_t) newTotalLen, (int) 0);
  8911. StringHolder::copyChars (result.text, text, index);
  8912. if (newStringLen > 0)
  8913. StringHolder::copyChars (result.text + index, stringToInsert.text, newStringLen);
  8914. const int endStringLen = newTotalLen - (index + newStringLen);
  8915. if (endStringLen > 0)
  8916. StringHolder::copyChars (result.text + (index + newStringLen),
  8917. text + (index + numCharsToReplace),
  8918. endStringLen);
  8919. return result;
  8920. }
  8921. const String String::replace (const String& stringToReplace, const String& stringToInsert, const bool ignoreCase) const
  8922. {
  8923. const int stringToReplaceLen = stringToReplace.length();
  8924. const int stringToInsertLen = stringToInsert.length();
  8925. int i = 0;
  8926. String result (*this);
  8927. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  8928. : result.indexOf (i, stringToReplace))) >= 0)
  8929. {
  8930. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  8931. i += stringToInsertLen;
  8932. }
  8933. return result;
  8934. }
  8935. const String String::replaceCharacter (const juce_wchar charToReplace, const juce_wchar charToInsert) const
  8936. {
  8937. const int index = indexOfChar (charToReplace);
  8938. if (index < 0)
  8939. return *this;
  8940. String result (*this, size_t());
  8941. juce_wchar* t = result.text + index;
  8942. while (*t != 0)
  8943. {
  8944. if (*t == charToReplace)
  8945. *t = charToInsert;
  8946. ++t;
  8947. }
  8948. return result;
  8949. }
  8950. const String String::replaceCharacters (const String& charactersToReplace,
  8951. const String& charactersToInsertInstead) const
  8952. {
  8953. String result (*this, size_t());
  8954. juce_wchar* t = result.text;
  8955. const int len2 = charactersToInsertInstead.length();
  8956. // the two strings passed in are supposed to be the same length!
  8957. jassert (len2 == charactersToReplace.length());
  8958. while (*t != 0)
  8959. {
  8960. const int index = charactersToReplace.indexOfChar (*t);
  8961. if (((unsigned int) index) < (unsigned int) len2)
  8962. *t = charactersToInsertInstead [index];
  8963. ++t;
  8964. }
  8965. return result;
  8966. }
  8967. bool String::startsWith (const String& other) const throw()
  8968. {
  8969. return CharacterFunctions::compare (text, other.text, other.length()) == 0;
  8970. }
  8971. bool String::startsWithIgnoreCase (const String& other) const throw()
  8972. {
  8973. return CharacterFunctions::compareIgnoreCase (text, other.text, other.length()) == 0;
  8974. }
  8975. bool String::startsWithChar (const juce_wchar character) const throw()
  8976. {
  8977. jassert (character != 0); // strings can't contain a null character!
  8978. return text[0] == character;
  8979. }
  8980. bool String::endsWithChar (const juce_wchar character) const throw()
  8981. {
  8982. jassert (character != 0); // strings can't contain a null character!
  8983. return text[0] != 0
  8984. && text [length() - 1] == character;
  8985. }
  8986. bool String::endsWith (const String& other) const throw()
  8987. {
  8988. const int thisLen = length();
  8989. const int otherLen = other.length();
  8990. return thisLen >= otherLen
  8991. && CharacterFunctions::compare (text + thisLen - otherLen, other.text) == 0;
  8992. }
  8993. bool String::endsWithIgnoreCase (const String& other) const throw()
  8994. {
  8995. const int thisLen = length();
  8996. const int otherLen = other.length();
  8997. return thisLen >= otherLen
  8998. && CharacterFunctions::compareIgnoreCase (text + thisLen - otherLen, other.text) == 0;
  8999. }
  9000. const String String::toUpperCase() const
  9001. {
  9002. String result (*this, size_t());
  9003. CharacterFunctions::toUpperCase (result.text);
  9004. return result;
  9005. }
  9006. const String String::toLowerCase() const
  9007. {
  9008. String result (*this, size_t());
  9009. CharacterFunctions::toLowerCase (result.text);
  9010. return result;
  9011. }
  9012. juce_wchar& String::operator[] (const int index)
  9013. {
  9014. jassert (((unsigned int) index) <= (unsigned int) length());
  9015. text = StringHolder::makeUnique (text);
  9016. return text [index];
  9017. }
  9018. juce_wchar String::getLastCharacter() const throw()
  9019. {
  9020. return isEmpty() ? juce_wchar() : text [length() - 1];
  9021. }
  9022. const String String::substring (int start, int end) const
  9023. {
  9024. if (start < 0)
  9025. start = 0;
  9026. else if (end <= start)
  9027. return empty;
  9028. int len = 0;
  9029. while (len <= end && text [len] != 0)
  9030. ++len;
  9031. if (end >= len)
  9032. {
  9033. if (start == 0)
  9034. return *this;
  9035. end = len;
  9036. }
  9037. return String (text + start, end - start);
  9038. }
  9039. const String String::substring (const int start) const
  9040. {
  9041. if (start <= 0)
  9042. return *this;
  9043. const int len = length();
  9044. if (start >= len)
  9045. return empty;
  9046. return String (text + start, len - start);
  9047. }
  9048. const String String::dropLastCharacters (const int numberToDrop) const
  9049. {
  9050. return String (text, jmax (0, length() - numberToDrop));
  9051. }
  9052. const String String::getLastCharacters (const int numCharacters) const
  9053. {
  9054. return String (text + jmax (0, length() - jmax (0, numCharacters)));
  9055. }
  9056. const String String::fromFirstOccurrenceOf (const String& sub,
  9057. const bool includeSubString,
  9058. const bool ignoreCase) const
  9059. {
  9060. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9061. : indexOf (sub);
  9062. if (i < 0)
  9063. return empty;
  9064. return substring (includeSubString ? i : i + sub.length());
  9065. }
  9066. const String String::fromLastOccurrenceOf (const String& sub,
  9067. const bool includeSubString,
  9068. const bool ignoreCase) const
  9069. {
  9070. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9071. : lastIndexOf (sub);
  9072. if (i < 0)
  9073. return *this;
  9074. return substring (includeSubString ? i : i + sub.length());
  9075. }
  9076. const String String::upToFirstOccurrenceOf (const String& sub,
  9077. const bool includeSubString,
  9078. const bool ignoreCase) const
  9079. {
  9080. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9081. : indexOf (sub);
  9082. if (i < 0)
  9083. return *this;
  9084. return substring (0, includeSubString ? i + sub.length() : i);
  9085. }
  9086. const String String::upToLastOccurrenceOf (const String& sub,
  9087. const bool includeSubString,
  9088. const bool ignoreCase) const
  9089. {
  9090. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9091. : lastIndexOf (sub);
  9092. if (i < 0)
  9093. return *this;
  9094. return substring (0, includeSubString ? i + sub.length() : i);
  9095. }
  9096. bool String::isQuotedString() const
  9097. {
  9098. const String trimmed (trimStart());
  9099. return trimmed[0] == '"'
  9100. || trimmed[0] == '\'';
  9101. }
  9102. const String String::unquoted() const
  9103. {
  9104. String s (*this);
  9105. if (s.text[0] == '"' || s.text[0] == '\'')
  9106. s = s.substring (1);
  9107. const int lastCharIndex = s.length() - 1;
  9108. if (lastCharIndex >= 0
  9109. && (s [lastCharIndex] == '"' || s[lastCharIndex] == '\''))
  9110. s [lastCharIndex] = 0;
  9111. return s;
  9112. }
  9113. const String String::quoted (const juce_wchar quoteCharacter) const
  9114. {
  9115. if (isEmpty())
  9116. return charToString (quoteCharacter) + quoteCharacter;
  9117. String t (*this);
  9118. if (! t.startsWithChar (quoteCharacter))
  9119. t = charToString (quoteCharacter) + t;
  9120. if (! t.endsWithChar (quoteCharacter))
  9121. t += quoteCharacter;
  9122. return t;
  9123. }
  9124. const String String::trim() const
  9125. {
  9126. if (isEmpty())
  9127. return empty;
  9128. int start = 0;
  9129. while (CharacterFunctions::isWhitespace (text [start]))
  9130. ++start;
  9131. const int len = length();
  9132. int end = len - 1;
  9133. while ((end >= start) && CharacterFunctions::isWhitespace (text [end]))
  9134. --end;
  9135. ++end;
  9136. if (end <= start)
  9137. return empty;
  9138. else if (start > 0 || end < len)
  9139. return String (text + start, end - start);
  9140. return *this;
  9141. }
  9142. const String String::trimStart() const
  9143. {
  9144. if (isEmpty())
  9145. return empty;
  9146. const juce_wchar* t = text;
  9147. while (CharacterFunctions::isWhitespace (*t))
  9148. ++t;
  9149. if (t == text)
  9150. return *this;
  9151. return String (t);
  9152. }
  9153. const String String::trimEnd() const
  9154. {
  9155. if (isEmpty())
  9156. return empty;
  9157. const juce_wchar* endT = text + (length() - 1);
  9158. while ((endT >= text) && CharacterFunctions::isWhitespace (*endT))
  9159. --endT;
  9160. return String (text, (int) (++endT - text));
  9161. }
  9162. const String String::trimCharactersAtStart (const String& charactersToTrim) const
  9163. {
  9164. const juce_wchar* t = text;
  9165. while (charactersToTrim.containsChar (*t))
  9166. ++t;
  9167. return t == text ? *this : String (t);
  9168. }
  9169. const String String::trimCharactersAtEnd (const String& charactersToTrim) const
  9170. {
  9171. if (isEmpty())
  9172. return empty;
  9173. const int len = length();
  9174. const juce_wchar* endT = text + (len - 1);
  9175. int numToRemove = 0;
  9176. while (numToRemove < len && charactersToTrim.containsChar (*endT))
  9177. {
  9178. ++numToRemove;
  9179. --endT;
  9180. }
  9181. return numToRemove > 0 ? String (text, len - numToRemove) : *this;
  9182. }
  9183. const String String::retainCharacters (const String& charactersToRetain) const
  9184. {
  9185. if (isEmpty())
  9186. return empty;
  9187. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9188. juce_wchar* dst = result.text;
  9189. const juce_wchar* src = text;
  9190. while (*src != 0)
  9191. {
  9192. if (charactersToRetain.containsChar (*src))
  9193. *dst++ = *src;
  9194. ++src;
  9195. }
  9196. *dst = 0;
  9197. return result;
  9198. }
  9199. const String String::removeCharacters (const String& charactersToRemove) const
  9200. {
  9201. if (isEmpty())
  9202. return empty;
  9203. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9204. juce_wchar* dst = result.text;
  9205. const juce_wchar* src = text;
  9206. while (*src != 0)
  9207. {
  9208. if (! charactersToRemove.containsChar (*src))
  9209. *dst++ = *src;
  9210. ++src;
  9211. }
  9212. *dst = 0;
  9213. return result;
  9214. }
  9215. const String String::initialSectionContainingOnly (const String& permittedCharacters) const
  9216. {
  9217. int i = 0;
  9218. for (;;)
  9219. {
  9220. if (! permittedCharacters.containsChar (text[i]))
  9221. break;
  9222. ++i;
  9223. }
  9224. return substring (0, i);
  9225. }
  9226. const String String::initialSectionNotContaining (const String& charactersToStopAt) const
  9227. {
  9228. const juce_wchar* const t = text;
  9229. int i = 0;
  9230. while (t[i] != 0)
  9231. {
  9232. if (charactersToStopAt.containsChar (t[i]))
  9233. return String (text, i);
  9234. ++i;
  9235. }
  9236. return empty;
  9237. }
  9238. bool String::containsOnly (const String& chars) const throw()
  9239. {
  9240. const juce_wchar* t = text;
  9241. while (*t != 0)
  9242. if (! chars.containsChar (*t++))
  9243. return false;
  9244. return true;
  9245. }
  9246. bool String::containsAnyOf (const String& chars) const throw()
  9247. {
  9248. const juce_wchar* t = text;
  9249. while (*t != 0)
  9250. if (chars.containsChar (*t++))
  9251. return true;
  9252. return false;
  9253. }
  9254. bool String::containsNonWhitespaceChars() const throw()
  9255. {
  9256. const juce_wchar* t = text;
  9257. while (*t != 0)
  9258. if (! CharacterFunctions::isWhitespace (*t++))
  9259. return true;
  9260. return false;
  9261. }
  9262. const String String::formatted (const juce_wchar* const pf, ... )
  9263. {
  9264. jassert (pf != 0);
  9265. va_list args;
  9266. va_start (args, pf);
  9267. size_t bufferSize = 256;
  9268. String result (bufferSize, (int) 0);
  9269. result.text[0] = 0;
  9270. for (;;)
  9271. {
  9272. #if JUCE_LINUX && JUCE_64BIT
  9273. va_list tempArgs;
  9274. va_copy (tempArgs, args);
  9275. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, tempArgs);
  9276. va_end (tempArgs);
  9277. #elif JUCE_WINDOWS
  9278. #ifdef _MSC_VER
  9279. #pragma warning (push)
  9280. #pragma warning (disable: 4996)
  9281. #endif
  9282. const int num = (int) _vsnwprintf (result.text, bufferSize - 1, pf, args);
  9283. #ifdef _MSC_VER
  9284. #pragma warning (pop)
  9285. #endif
  9286. #else
  9287. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, args);
  9288. #endif
  9289. if (num > 0)
  9290. return result;
  9291. bufferSize += 256;
  9292. if (num == 0 || bufferSize > 65536) // the upper limit is a sanity check to avoid situations where vprintf repeatedly
  9293. break; // returns -1 because of an error rather than because it needs more space.
  9294. result.preallocateStorage (bufferSize);
  9295. }
  9296. return empty;
  9297. }
  9298. int String::getIntValue() const throw()
  9299. {
  9300. return CharacterFunctions::getIntValue (text);
  9301. }
  9302. int String::getTrailingIntValue() const throw()
  9303. {
  9304. int n = 0;
  9305. int mult = 1;
  9306. const juce_wchar* t = text + length();
  9307. while (--t >= text)
  9308. {
  9309. const juce_wchar c = *t;
  9310. if (! CharacterFunctions::isDigit (c))
  9311. {
  9312. if (c == '-')
  9313. n = -n;
  9314. break;
  9315. }
  9316. n += mult * (c - '0');
  9317. mult *= 10;
  9318. }
  9319. return n;
  9320. }
  9321. int64 String::getLargeIntValue() const throw()
  9322. {
  9323. return CharacterFunctions::getInt64Value (text);
  9324. }
  9325. float String::getFloatValue() const throw()
  9326. {
  9327. return (float) CharacterFunctions::getDoubleValue (text);
  9328. }
  9329. double String::getDoubleValue() const throw()
  9330. {
  9331. return CharacterFunctions::getDoubleValue (text);
  9332. }
  9333. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  9334. const String String::toHexString (const int number)
  9335. {
  9336. juce_wchar buffer[32];
  9337. juce_wchar* const end = buffer + 32;
  9338. juce_wchar* t = end;
  9339. *--t = 0;
  9340. unsigned int v = (unsigned int) number;
  9341. do
  9342. {
  9343. *--t = hexDigits [v & 15];
  9344. v >>= 4;
  9345. } while (v != 0);
  9346. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9347. }
  9348. const String String::toHexString (const int64 number)
  9349. {
  9350. juce_wchar buffer[32];
  9351. juce_wchar* const end = buffer + 32;
  9352. juce_wchar* t = end;
  9353. *--t = 0;
  9354. uint64 v = (uint64) number;
  9355. do
  9356. {
  9357. *--t = hexDigits [(int) (v & 15)];
  9358. v >>= 4;
  9359. } while (v != 0);
  9360. return String (t, (int) (((char*) end) - (char*) t));
  9361. }
  9362. const String String::toHexString (const short number)
  9363. {
  9364. return toHexString ((int) (unsigned short) number);
  9365. }
  9366. const String String::toHexString (const unsigned char* data,
  9367. const int size,
  9368. const int groupSize)
  9369. {
  9370. if (size <= 0)
  9371. return empty;
  9372. int numChars = (size * 2) + 2;
  9373. if (groupSize > 0)
  9374. numChars += size / groupSize;
  9375. String s ((size_t) numChars, (int) 0);
  9376. juce_wchar* d = s.text;
  9377. for (int i = 0; i < size; ++i)
  9378. {
  9379. *d++ = hexDigits [(*data) >> 4];
  9380. *d++ = hexDigits [(*data) & 0xf];
  9381. ++data;
  9382. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9383. *d++ = ' ';
  9384. }
  9385. *d = 0;
  9386. return s;
  9387. }
  9388. int String::getHexValue32() const throw()
  9389. {
  9390. int result = 0;
  9391. const juce_wchar* c = text;
  9392. for (;;)
  9393. {
  9394. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9395. if (hexValue >= 0)
  9396. result = (result << 4) | hexValue;
  9397. else if (*c == 0)
  9398. break;
  9399. ++c;
  9400. }
  9401. return result;
  9402. }
  9403. int64 String::getHexValue64() const throw()
  9404. {
  9405. int64 result = 0;
  9406. const juce_wchar* c = text;
  9407. for (;;)
  9408. {
  9409. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9410. if (hexValue >= 0)
  9411. result = (result << 4) | hexValue;
  9412. else if (*c == 0)
  9413. break;
  9414. ++c;
  9415. }
  9416. return result;
  9417. }
  9418. const String String::createStringFromData (const void* const data_, const int size)
  9419. {
  9420. const char* const data = static_cast <const char*> (data_);
  9421. if (size <= 0 || data == 0)
  9422. {
  9423. return empty;
  9424. }
  9425. else if (size < 2)
  9426. {
  9427. return charToString (data[0]);
  9428. }
  9429. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9430. || (data[0] == (char)-1 && data[1] == (char)-2))
  9431. {
  9432. // assume it's 16-bit unicode
  9433. const bool bigEndian = (data[0] == (char)-2);
  9434. const int numChars = size / 2 - 1;
  9435. String result;
  9436. result.preallocateStorage (numChars + 2);
  9437. const uint16* const src = (const uint16*) (data + 2);
  9438. juce_wchar* const dst = const_cast <juce_wchar*> (static_cast <const juce_wchar*> (result));
  9439. if (bigEndian)
  9440. {
  9441. for (int i = 0; i < numChars; ++i)
  9442. dst[i] = (juce_wchar) ByteOrder::swapIfLittleEndian (src[i]);
  9443. }
  9444. else
  9445. {
  9446. for (int i = 0; i < numChars; ++i)
  9447. dst[i] = (juce_wchar) ByteOrder::swapIfBigEndian (src[i]);
  9448. }
  9449. dst [numChars] = 0;
  9450. return result;
  9451. }
  9452. else
  9453. {
  9454. return String::fromUTF8 (data, size);
  9455. }
  9456. }
  9457. const char* String::toUTF8() const
  9458. {
  9459. if (isEmpty())
  9460. {
  9461. return reinterpret_cast <const char*> (text);
  9462. }
  9463. else
  9464. {
  9465. const int currentLen = length() + 1;
  9466. const int utf8BytesNeeded = getNumBytesAsUTF8();
  9467. String* const mutableThis = const_cast <String*> (this);
  9468. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar));
  9469. char* const otherCopy = reinterpret_cast <char*> (mutableThis->text + currentLen);
  9470. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9471. return otherCopy;
  9472. }
  9473. }
  9474. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9475. {
  9476. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9477. int num = 0, index = 0;
  9478. for (;;)
  9479. {
  9480. const uint32 c = (uint32) text [index++];
  9481. if (c >= 0x80)
  9482. {
  9483. int numExtraBytes = 1;
  9484. if (c >= 0x800)
  9485. {
  9486. ++numExtraBytes;
  9487. if (c >= 0x10000)
  9488. {
  9489. ++numExtraBytes;
  9490. if (c >= 0x200000)
  9491. {
  9492. ++numExtraBytes;
  9493. if (c >= 0x4000000)
  9494. ++numExtraBytes;
  9495. }
  9496. }
  9497. }
  9498. if (buffer != 0)
  9499. {
  9500. if (num + numExtraBytes >= maxBufferSizeBytes)
  9501. {
  9502. buffer [num++] = 0;
  9503. break;
  9504. }
  9505. else
  9506. {
  9507. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9508. while (--numExtraBytes >= 0)
  9509. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9510. }
  9511. }
  9512. else
  9513. {
  9514. num += numExtraBytes + 1;
  9515. }
  9516. }
  9517. else
  9518. {
  9519. if (buffer != 0)
  9520. {
  9521. if (num + 1 >= maxBufferSizeBytes)
  9522. {
  9523. buffer [num++] = 0;
  9524. break;
  9525. }
  9526. buffer [num] = (uint8) c;
  9527. }
  9528. ++num;
  9529. }
  9530. if (c == 0)
  9531. break;
  9532. }
  9533. return num;
  9534. }
  9535. int String::getNumBytesAsUTF8() const throw()
  9536. {
  9537. int num = 0;
  9538. const juce_wchar* t = text;
  9539. for (;;)
  9540. {
  9541. const uint32 c = (uint32) *t;
  9542. if (c >= 0x80)
  9543. {
  9544. ++num;
  9545. if (c >= 0x800)
  9546. {
  9547. ++num;
  9548. if (c >= 0x10000)
  9549. {
  9550. ++num;
  9551. if (c >= 0x200000)
  9552. {
  9553. ++num;
  9554. if (c >= 0x4000000)
  9555. ++num;
  9556. }
  9557. }
  9558. }
  9559. }
  9560. else if (c == 0)
  9561. break;
  9562. ++num;
  9563. ++t;
  9564. }
  9565. return num;
  9566. }
  9567. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9568. {
  9569. if (buffer == 0)
  9570. return empty;
  9571. if (bufferSizeBytes < 0)
  9572. bufferSizeBytes = std::numeric_limits<int>::max();
  9573. size_t numBytes;
  9574. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9575. if (buffer [numBytes] == 0)
  9576. break;
  9577. String result ((size_t) numBytes + 1, (int) 0);
  9578. juce_wchar* dest = result.text;
  9579. size_t i = 0;
  9580. while (i < numBytes)
  9581. {
  9582. const char c = buffer [i++];
  9583. if (c < 0)
  9584. {
  9585. unsigned int mask = 0x7f;
  9586. int bit = 0x40;
  9587. int numExtraValues = 0;
  9588. while (bit != 0 && (c & bit) != 0)
  9589. {
  9590. bit >>= 1;
  9591. mask >>= 1;
  9592. ++numExtraValues;
  9593. }
  9594. int n = (mask & (unsigned char) c);
  9595. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9596. {
  9597. const char nextByte = buffer[i];
  9598. if ((nextByte & 0xc0) != 0x80)
  9599. break;
  9600. n <<= 6;
  9601. n |= (nextByte & 0x3f);
  9602. ++i;
  9603. }
  9604. *dest++ = (juce_wchar) n;
  9605. }
  9606. else
  9607. {
  9608. *dest++ = (juce_wchar) c;
  9609. }
  9610. }
  9611. *dest = 0;
  9612. return result;
  9613. }
  9614. const char* String::toCString() const
  9615. {
  9616. if (isEmpty())
  9617. {
  9618. return reinterpret_cast <const char*> (text);
  9619. }
  9620. else
  9621. {
  9622. const int len = length();
  9623. String* const mutableThis = const_cast <String*> (this);
  9624. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2);
  9625. char* otherCopy = reinterpret_cast <char*> (mutableThis->text + len + 1);
  9626. CharacterFunctions::copy (otherCopy, text, len);
  9627. otherCopy [len] = 0;
  9628. return otherCopy;
  9629. }
  9630. }
  9631. #ifdef _MSC_VER
  9632. #pragma warning (disable: 4514 4996)
  9633. #pragma warning (push)
  9634. #endif
  9635. int String::getNumBytesAsCString() const throw()
  9636. {
  9637. return (int) wcstombs (0, text, 0);
  9638. }
  9639. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  9640. {
  9641. const int numBytes = (int) wcstombs (destBuffer, text, maxBufferSizeBytes);
  9642. if (destBuffer != 0 && numBytes >= 0)
  9643. destBuffer [numBytes] = 0;
  9644. return numBytes;
  9645. }
  9646. #ifdef _MSC_VER
  9647. #pragma warning (pop)
  9648. #endif
  9649. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  9650. {
  9651. StringHolder::copyChars (destBuffer, text, jmin (maxCharsToCopy, length()));
  9652. }
  9653. String::Concatenator::Concatenator (String& stringToAppendTo)
  9654. : result (stringToAppendTo),
  9655. nextIndex (stringToAppendTo.length())
  9656. {
  9657. }
  9658. String::Concatenator::~Concatenator()
  9659. {
  9660. }
  9661. void String::Concatenator::append (const String& s)
  9662. {
  9663. const int len = s.length();
  9664. if (len > 0)
  9665. {
  9666. result.preallocateStorage (nextIndex + len);
  9667. s.copyToUnicode (static_cast <juce_wchar*> (result) + nextIndex, len);
  9668. nextIndex += len;
  9669. }
  9670. }
  9671. END_JUCE_NAMESPACE
  9672. /*** End of inlined file: juce_String.cpp ***/
  9673. /*** Start of inlined file: juce_StringArray.cpp ***/
  9674. BEGIN_JUCE_NAMESPACE
  9675. StringArray::StringArray() throw()
  9676. {
  9677. }
  9678. StringArray::StringArray (const StringArray& other)
  9679. : strings (other.strings)
  9680. {
  9681. }
  9682. StringArray::StringArray (const String& firstValue)
  9683. {
  9684. strings.add (firstValue);
  9685. }
  9686. StringArray::StringArray (const juce_wchar** const initialStrings,
  9687. const int numberOfStrings)
  9688. {
  9689. for (int i = 0; i < numberOfStrings; ++i)
  9690. strings.add (initialStrings [i]);
  9691. }
  9692. StringArray::StringArray (const char** const initialStrings,
  9693. const int numberOfStrings)
  9694. {
  9695. for (int i = 0; i < numberOfStrings; ++i)
  9696. strings.add (initialStrings [i]);
  9697. }
  9698. StringArray::StringArray (const juce_wchar** const initialStrings)
  9699. {
  9700. int i = 0;
  9701. while (initialStrings[i] != 0)
  9702. strings.add (initialStrings [i++]);
  9703. }
  9704. StringArray::StringArray (const char** const initialStrings)
  9705. {
  9706. int i = 0;
  9707. while (initialStrings[i] != 0)
  9708. strings.add (initialStrings [i++]);
  9709. }
  9710. StringArray& StringArray::operator= (const StringArray& other)
  9711. {
  9712. strings = other.strings;
  9713. return *this;
  9714. }
  9715. StringArray::~StringArray()
  9716. {
  9717. }
  9718. bool StringArray::operator== (const StringArray& other) const throw()
  9719. {
  9720. if (other.size() != size())
  9721. return false;
  9722. for (int i = size(); --i >= 0;)
  9723. if (other.strings.getReference(i) != strings.getReference(i))
  9724. return false;
  9725. return true;
  9726. }
  9727. bool StringArray::operator!= (const StringArray& other) const throw()
  9728. {
  9729. return ! operator== (other);
  9730. }
  9731. void StringArray::clear()
  9732. {
  9733. strings.clear();
  9734. }
  9735. const String& StringArray::operator[] (const int index) const throw()
  9736. {
  9737. if (((unsigned int) index) < (unsigned int) strings.size())
  9738. return strings.getReference (index);
  9739. return String::empty;
  9740. }
  9741. String& StringArray::getReference (const int index) throw()
  9742. {
  9743. jassert (((unsigned int) index) < (unsigned int) strings.size());
  9744. return strings.getReference (index);
  9745. }
  9746. void StringArray::add (const String& newString)
  9747. {
  9748. strings.add (newString);
  9749. }
  9750. void StringArray::insert (const int index, const String& newString)
  9751. {
  9752. strings.insert (index, newString);
  9753. }
  9754. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  9755. {
  9756. if (! contains (newString, ignoreCase))
  9757. add (newString);
  9758. }
  9759. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  9760. {
  9761. if (startIndex < 0)
  9762. {
  9763. jassertfalse
  9764. startIndex = 0;
  9765. }
  9766. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  9767. numElementsToAdd = otherArray.size() - startIndex;
  9768. while (--numElementsToAdd >= 0)
  9769. strings.add (otherArray.strings.getReference (startIndex++));
  9770. }
  9771. void StringArray::set (const int index, const String& newString)
  9772. {
  9773. strings.set (index, newString);
  9774. }
  9775. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  9776. {
  9777. if (ignoreCase)
  9778. {
  9779. for (int i = size(); --i >= 0;)
  9780. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  9781. return true;
  9782. }
  9783. else
  9784. {
  9785. for (int i = size(); --i >= 0;)
  9786. if (stringToLookFor == strings.getReference(i))
  9787. return true;
  9788. }
  9789. return false;
  9790. }
  9791. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  9792. {
  9793. if (i < 0)
  9794. i = 0;
  9795. const int numElements = size();
  9796. if (ignoreCase)
  9797. {
  9798. while (i < numElements)
  9799. {
  9800. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  9801. return i;
  9802. ++i;
  9803. }
  9804. }
  9805. else
  9806. {
  9807. while (i < numElements)
  9808. {
  9809. if (stringToLookFor == strings.getReference (i))
  9810. return i;
  9811. ++i;
  9812. }
  9813. }
  9814. return -1;
  9815. }
  9816. void StringArray::remove (const int index)
  9817. {
  9818. strings.remove (index);
  9819. }
  9820. void StringArray::removeString (const String& stringToRemove,
  9821. const bool ignoreCase)
  9822. {
  9823. if (ignoreCase)
  9824. {
  9825. for (int i = size(); --i >= 0;)
  9826. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  9827. strings.remove (i);
  9828. }
  9829. else
  9830. {
  9831. for (int i = size(); --i >= 0;)
  9832. if (stringToRemove == strings.getReference (i))
  9833. strings.remove (i);
  9834. }
  9835. }
  9836. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  9837. {
  9838. if (removeWhitespaceStrings)
  9839. {
  9840. for (int i = size(); --i >= 0;)
  9841. if (! strings.getReference(i).containsNonWhitespaceChars())
  9842. strings.remove (i);
  9843. }
  9844. else
  9845. {
  9846. for (int i = size(); --i >= 0;)
  9847. if (strings.getReference(i).isEmpty())
  9848. strings.remove (i);
  9849. }
  9850. }
  9851. void StringArray::trim()
  9852. {
  9853. for (int i = size(); --i >= 0;)
  9854. {
  9855. String& s = strings.getReference(i);
  9856. s = s.trim();
  9857. }
  9858. }
  9859. class InternalStringArrayComparator_CaseSensitive
  9860. {
  9861. public:
  9862. static int compareElements (String& first, String& second) { return first.compare (second); }
  9863. };
  9864. class InternalStringArrayComparator_CaseInsensitive
  9865. {
  9866. public:
  9867. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  9868. };
  9869. void StringArray::sort (const bool ignoreCase)
  9870. {
  9871. if (ignoreCase)
  9872. {
  9873. InternalStringArrayComparator_CaseInsensitive comp;
  9874. strings.sort (comp);
  9875. }
  9876. else
  9877. {
  9878. InternalStringArrayComparator_CaseSensitive comp;
  9879. strings.sort (comp);
  9880. }
  9881. }
  9882. void StringArray::move (const int currentIndex, int newIndex) throw()
  9883. {
  9884. strings.move (currentIndex, newIndex);
  9885. }
  9886. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  9887. {
  9888. const int last = (numberToJoin < 0) ? size()
  9889. : jmin (size(), start + numberToJoin);
  9890. if (start < 0)
  9891. start = 0;
  9892. if (start >= last)
  9893. return String::empty;
  9894. if (start == last - 1)
  9895. return strings.getReference (start);
  9896. const int separatorLen = separator.length();
  9897. int charsNeeded = separatorLen * (last - start - 1);
  9898. for (int i = start; i < last; ++i)
  9899. charsNeeded += strings.getReference(i).length();
  9900. String result;
  9901. result.preallocateStorage (charsNeeded);
  9902. juce_wchar* dest = result;
  9903. while (start < last)
  9904. {
  9905. const String& s = strings.getReference (start);
  9906. const int len = s.length();
  9907. if (len > 0)
  9908. {
  9909. s.copyToUnicode (dest, len);
  9910. dest += len;
  9911. }
  9912. if (++start < last && separatorLen > 0)
  9913. {
  9914. separator.copyToUnicode (dest, separatorLen);
  9915. dest += separatorLen;
  9916. }
  9917. }
  9918. *dest = 0;
  9919. return result;
  9920. }
  9921. int StringArray::addTokens (const String& text, const bool preserveQuotedStrings)
  9922. {
  9923. return addTokens (text, " \n\r\t", preserveQuotedStrings ? "\"" : "");
  9924. }
  9925. int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters)
  9926. {
  9927. int num = 0;
  9928. if (text.isNotEmpty())
  9929. {
  9930. bool insideQuotes = false;
  9931. juce_wchar currentQuoteChar = 0;
  9932. int i = 0;
  9933. int tokenStart = 0;
  9934. for (;;)
  9935. {
  9936. const juce_wchar c = text[i];
  9937. const bool isBreak = (c == 0) || ((! insideQuotes) && breakCharacters.containsChar (c));
  9938. if (! isBreak)
  9939. {
  9940. if (quoteCharacters.containsChar (c))
  9941. {
  9942. if (insideQuotes)
  9943. {
  9944. // only break out of quotes-mode if we find a matching quote to the
  9945. // one that we opened with..
  9946. if (currentQuoteChar == c)
  9947. insideQuotes = false;
  9948. }
  9949. else
  9950. {
  9951. insideQuotes = true;
  9952. currentQuoteChar = c;
  9953. }
  9954. }
  9955. }
  9956. else
  9957. {
  9958. add (String (static_cast <const juce_wchar*> (text) + tokenStart, i - tokenStart));
  9959. ++num;
  9960. tokenStart = i + 1;
  9961. }
  9962. if (c == 0)
  9963. break;
  9964. ++i;
  9965. }
  9966. }
  9967. return num;
  9968. }
  9969. int StringArray::addLines (const String& sourceText)
  9970. {
  9971. int numLines = 0;
  9972. const juce_wchar* text = sourceText;
  9973. while (*text != 0)
  9974. {
  9975. const juce_wchar* const startOfLine = text;
  9976. while (*text != 0)
  9977. {
  9978. if (*text == '\r')
  9979. {
  9980. ++text;
  9981. if (*text == '\n')
  9982. ++text;
  9983. break;
  9984. }
  9985. if (*text == '\n')
  9986. {
  9987. ++text;
  9988. break;
  9989. }
  9990. ++text;
  9991. }
  9992. const juce_wchar* endOfLine = text;
  9993. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  9994. --endOfLine;
  9995. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  9996. --endOfLine;
  9997. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  9998. ++numLines;
  9999. }
  10000. return numLines;
  10001. }
  10002. void StringArray::removeDuplicates (const bool ignoreCase)
  10003. {
  10004. for (int i = 0; i < size() - 1; ++i)
  10005. {
  10006. const String s (strings.getReference(i));
  10007. int nextIndex = i + 1;
  10008. for (;;)
  10009. {
  10010. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10011. if (nextIndex < 0)
  10012. break;
  10013. strings.remove (nextIndex);
  10014. }
  10015. }
  10016. }
  10017. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10018. const bool appendNumberToFirstInstance,
  10019. const juce_wchar* preNumberString,
  10020. const juce_wchar* postNumberString)
  10021. {
  10022. if (preNumberString == 0)
  10023. preNumberString = L" (";
  10024. if (postNumberString == 0)
  10025. postNumberString = L")";
  10026. for (int i = 0; i < size() - 1; ++i)
  10027. {
  10028. String& s = strings.getReference(i);
  10029. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10030. if (nextIndex >= 0)
  10031. {
  10032. const String original (s);
  10033. int number = 0;
  10034. if (appendNumberToFirstInstance)
  10035. s = original + preNumberString + String (++number) + postNumberString;
  10036. else
  10037. ++number;
  10038. while (nextIndex >= 0)
  10039. {
  10040. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10041. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10042. }
  10043. }
  10044. }
  10045. }
  10046. void StringArray::minimiseStorageOverheads()
  10047. {
  10048. strings.minimiseStorageOverheads();
  10049. }
  10050. END_JUCE_NAMESPACE
  10051. /*** End of inlined file: juce_StringArray.cpp ***/
  10052. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10053. BEGIN_JUCE_NAMESPACE
  10054. StringPairArray::StringPairArray (const bool ignoreCase_)
  10055. : ignoreCase (ignoreCase_)
  10056. {
  10057. }
  10058. StringPairArray::StringPairArray (const StringPairArray& other)
  10059. : keys (other.keys),
  10060. values (other.values),
  10061. ignoreCase (other.ignoreCase)
  10062. {
  10063. }
  10064. StringPairArray::~StringPairArray()
  10065. {
  10066. }
  10067. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  10068. {
  10069. keys = other.keys;
  10070. values = other.values;
  10071. return *this;
  10072. }
  10073. bool StringPairArray::operator== (const StringPairArray& other) const
  10074. {
  10075. for (int i = keys.size(); --i >= 0;)
  10076. if (other [keys[i]] != values[i])
  10077. return false;
  10078. return true;
  10079. }
  10080. bool StringPairArray::operator!= (const StringPairArray& other) const
  10081. {
  10082. return ! operator== (other);
  10083. }
  10084. const String& StringPairArray::operator[] (const String& key) const
  10085. {
  10086. return values [keys.indexOf (key, ignoreCase)];
  10087. }
  10088. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10089. {
  10090. const int i = keys.indexOf (key, ignoreCase);
  10091. if (i >= 0)
  10092. return values[i];
  10093. return defaultReturnValue;
  10094. }
  10095. void StringPairArray::set (const String& key, const String& value)
  10096. {
  10097. const int i = keys.indexOf (key, ignoreCase);
  10098. if (i >= 0)
  10099. {
  10100. values.set (i, value);
  10101. }
  10102. else
  10103. {
  10104. keys.add (key);
  10105. values.add (value);
  10106. }
  10107. }
  10108. void StringPairArray::addArray (const StringPairArray& other)
  10109. {
  10110. for (int i = 0; i < other.size(); ++i)
  10111. set (other.keys[i], other.values[i]);
  10112. }
  10113. void StringPairArray::clear()
  10114. {
  10115. keys.clear();
  10116. values.clear();
  10117. }
  10118. void StringPairArray::remove (const String& key)
  10119. {
  10120. remove (keys.indexOf (key, ignoreCase));
  10121. }
  10122. void StringPairArray::remove (const int index)
  10123. {
  10124. keys.remove (index);
  10125. values.remove (index);
  10126. }
  10127. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  10128. {
  10129. ignoreCase = shouldIgnoreCase;
  10130. }
  10131. const String StringPairArray::getDescription() const
  10132. {
  10133. String s;
  10134. for (int i = 0; i < keys.size(); ++i)
  10135. {
  10136. s << keys[i] << " = " << values[i];
  10137. if (i < keys.size())
  10138. s << ", ";
  10139. }
  10140. return s;
  10141. }
  10142. void StringPairArray::minimiseStorageOverheads()
  10143. {
  10144. keys.minimiseStorageOverheads();
  10145. values.minimiseStorageOverheads();
  10146. }
  10147. END_JUCE_NAMESPACE
  10148. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10149. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10150. BEGIN_JUCE_NAMESPACE
  10151. XmlDocument::XmlDocument (const String& documentText)
  10152. : originalText (documentText),
  10153. ignoreEmptyTextElements (true)
  10154. {
  10155. }
  10156. XmlDocument::XmlDocument (const File& file)
  10157. : ignoreEmptyTextElements (true)
  10158. {
  10159. inputSource = new FileInputSource (file);
  10160. }
  10161. XmlDocument::~XmlDocument()
  10162. {
  10163. }
  10164. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10165. {
  10166. inputSource = newSource;
  10167. }
  10168. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10169. {
  10170. ignoreEmptyTextElements = shouldBeIgnored;
  10171. }
  10172. bool XmlDocument::isXmlIdentifierCharSlow (const juce_wchar c) throw()
  10173. {
  10174. return CharacterFunctions::isLetterOrDigit (c)
  10175. || c == '_' || c == '-' || c == ':' || c == '.';
  10176. }
  10177. inline bool XmlDocument::isXmlIdentifierChar (const juce_wchar c) const throw()
  10178. {
  10179. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10180. : isXmlIdentifierCharSlow (c);
  10181. }
  10182. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10183. {
  10184. String textToParse (originalText);
  10185. if (textToParse.isEmpty() && inputSource != 0)
  10186. {
  10187. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10188. if (in != 0)
  10189. {
  10190. MemoryBlock data;
  10191. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10192. if (data.getSize() >= 2
  10193. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10194. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10195. {
  10196. textToParse = String::createStringFromData (static_cast <const char*> (data.getData()), (int) data.getSize());
  10197. }
  10198. else
  10199. {
  10200. textToParse = String::fromUTF8 (static_cast <const char*> (data.getData()), (int) data.getSize());
  10201. }
  10202. if (! onlyReadOuterDocumentElement)
  10203. originalText = textToParse;
  10204. }
  10205. }
  10206. input = textToParse;
  10207. lastError = String::empty;
  10208. errorOccurred = false;
  10209. outOfData = false;
  10210. needToLoadDTD = true;
  10211. for (int i = 0; i < 128; ++i)
  10212. identifierLookupTable[i] = isXmlIdentifierCharSlow ((juce_wchar) i);
  10213. if (textToParse.isEmpty())
  10214. {
  10215. lastError = "not enough input";
  10216. }
  10217. else
  10218. {
  10219. skipHeader();
  10220. if (input != 0)
  10221. {
  10222. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10223. if (! errorOccurred)
  10224. return result.release();
  10225. }
  10226. else
  10227. {
  10228. lastError = "incorrect xml header";
  10229. }
  10230. }
  10231. return 0;
  10232. }
  10233. const String& XmlDocument::getLastParseError() const throw()
  10234. {
  10235. return lastError;
  10236. }
  10237. void XmlDocument::setLastError (const String& desc, const bool carryOn)
  10238. {
  10239. lastError = desc;
  10240. errorOccurred = ! carryOn;
  10241. }
  10242. const String XmlDocument::getFileContents (const String& filename) const
  10243. {
  10244. if (inputSource != 0)
  10245. {
  10246. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10247. if (in != 0)
  10248. return in->readEntireStreamAsString();
  10249. }
  10250. return String::empty;
  10251. }
  10252. juce_wchar XmlDocument::readNextChar() throw()
  10253. {
  10254. if (*input != 0)
  10255. {
  10256. return *input++;
  10257. }
  10258. else
  10259. {
  10260. outOfData = true;
  10261. return 0;
  10262. }
  10263. }
  10264. int XmlDocument::findNextTokenLength() throw()
  10265. {
  10266. int len = 0;
  10267. juce_wchar c = *input;
  10268. while (isXmlIdentifierChar (c))
  10269. c = input [++len];
  10270. return len;
  10271. }
  10272. void XmlDocument::skipHeader()
  10273. {
  10274. const juce_wchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10275. if (found != 0)
  10276. {
  10277. input = found;
  10278. input = CharacterFunctions::find (input, T("?>"));
  10279. if (input == 0)
  10280. return;
  10281. input += 2;
  10282. }
  10283. skipNextWhiteSpace();
  10284. const juce_wchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10285. if (docType == 0)
  10286. return;
  10287. input = docType + 9;
  10288. int n = 1;
  10289. while (n > 0)
  10290. {
  10291. const juce_wchar c = readNextChar();
  10292. if (outOfData)
  10293. return;
  10294. if (c == '<')
  10295. ++n;
  10296. else if (c == '>')
  10297. --n;
  10298. }
  10299. docType += 9;
  10300. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10301. }
  10302. void XmlDocument::skipNextWhiteSpace()
  10303. {
  10304. for (;;)
  10305. {
  10306. juce_wchar c = *input;
  10307. while (CharacterFunctions::isWhitespace (c))
  10308. c = *++input;
  10309. if (c == 0)
  10310. {
  10311. outOfData = true;
  10312. break;
  10313. }
  10314. else if (c == '<')
  10315. {
  10316. if (input[1] == '!'
  10317. && input[2] == '-'
  10318. && input[3] == '-')
  10319. {
  10320. const juce_wchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10321. if (closeComment == 0)
  10322. {
  10323. outOfData = true;
  10324. break;
  10325. }
  10326. input = closeComment + 3;
  10327. continue;
  10328. }
  10329. else if (input[1] == '?')
  10330. {
  10331. const juce_wchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10332. if (closeBracket == 0)
  10333. {
  10334. outOfData = true;
  10335. break;
  10336. }
  10337. input = closeBracket + 2;
  10338. continue;
  10339. }
  10340. }
  10341. break;
  10342. }
  10343. }
  10344. void XmlDocument::readQuotedString (String& result)
  10345. {
  10346. const juce_wchar quote = readNextChar();
  10347. while (! outOfData)
  10348. {
  10349. const juce_wchar c = readNextChar();
  10350. if (c == quote)
  10351. break;
  10352. if (c == '&')
  10353. {
  10354. --input;
  10355. readEntity (result);
  10356. }
  10357. else
  10358. {
  10359. --input;
  10360. const juce_wchar* const start = input;
  10361. for (;;)
  10362. {
  10363. const juce_wchar character = *input;
  10364. if (character == quote)
  10365. {
  10366. result.append (start, (int) (input - start));
  10367. ++input;
  10368. return;
  10369. }
  10370. else if (character == '&')
  10371. {
  10372. result.append (start, (int) (input - start));
  10373. break;
  10374. }
  10375. else if (character == 0)
  10376. {
  10377. outOfData = true;
  10378. setLastError ("unmatched quotes", false);
  10379. break;
  10380. }
  10381. ++input;
  10382. }
  10383. }
  10384. }
  10385. }
  10386. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements)
  10387. {
  10388. XmlElement* node = 0;
  10389. skipNextWhiteSpace();
  10390. if (outOfData)
  10391. return 0;
  10392. input = CharacterFunctions::find (input, T("<"));
  10393. if (input != 0)
  10394. {
  10395. ++input;
  10396. int tagLen = findNextTokenLength();
  10397. if (tagLen == 0)
  10398. {
  10399. // no tag name - but allow for a gap after the '<' before giving an error
  10400. skipNextWhiteSpace();
  10401. tagLen = findNextTokenLength();
  10402. if (tagLen == 0)
  10403. {
  10404. setLastError ("tag name missing", false);
  10405. return node;
  10406. }
  10407. }
  10408. node = new XmlElement (String (input, tagLen));
  10409. input += tagLen;
  10410. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10411. // look for attributes
  10412. for (;;)
  10413. {
  10414. skipNextWhiteSpace();
  10415. const juce_wchar c = *input;
  10416. // empty tag..
  10417. if (c == '/' && input[1] == '>')
  10418. {
  10419. input += 2;
  10420. break;
  10421. }
  10422. // parse the guts of the element..
  10423. if (c == '>')
  10424. {
  10425. ++input;
  10426. skipNextWhiteSpace();
  10427. if (alsoParseSubElements)
  10428. readChildElements (node);
  10429. break;
  10430. }
  10431. // get an attribute..
  10432. if (isXmlIdentifierChar (c))
  10433. {
  10434. const int attNameLen = findNextTokenLength();
  10435. if (attNameLen > 0)
  10436. {
  10437. const juce_wchar* attNameStart = input;
  10438. input += attNameLen;
  10439. skipNextWhiteSpace();
  10440. if (readNextChar() == '=')
  10441. {
  10442. skipNextWhiteSpace();
  10443. const juce_wchar nextChar = *input;
  10444. if (nextChar == '"' || nextChar == '\'')
  10445. {
  10446. XmlElement::XmlAttributeNode* const newAtt
  10447. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10448. String::empty);
  10449. readQuotedString (newAtt->value);
  10450. if (lastAttribute == 0)
  10451. node->attributes = newAtt;
  10452. else
  10453. lastAttribute->next = newAtt;
  10454. lastAttribute = newAtt;
  10455. continue;
  10456. }
  10457. }
  10458. }
  10459. }
  10460. else
  10461. {
  10462. if (! outOfData)
  10463. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10464. }
  10465. break;
  10466. }
  10467. }
  10468. return node;
  10469. }
  10470. void XmlDocument::readChildElements (XmlElement* parent)
  10471. {
  10472. XmlElement* lastChildNode = 0;
  10473. for (;;)
  10474. {
  10475. skipNextWhiteSpace();
  10476. if (outOfData)
  10477. {
  10478. setLastError ("unmatched tags", false);
  10479. break;
  10480. }
  10481. if (*input == '<')
  10482. {
  10483. if (input[1] == '/')
  10484. {
  10485. // our close tag..
  10486. input = CharacterFunctions::find (input, T(">"));
  10487. ++input;
  10488. break;
  10489. }
  10490. else if (input[1] == '!'
  10491. && input[2] == '['
  10492. && input[3] == 'C'
  10493. && input[4] == 'D'
  10494. && input[5] == 'A'
  10495. && input[6] == 'T'
  10496. && input[7] == 'A'
  10497. && input[8] == '[')
  10498. {
  10499. input += 9;
  10500. const juce_wchar* const inputStart = input;
  10501. int len = 0;
  10502. for (;;)
  10503. {
  10504. if (*input == 0)
  10505. {
  10506. setLastError ("unterminated CDATA section", false);
  10507. outOfData = true;
  10508. break;
  10509. }
  10510. else if (input[0] == ']'
  10511. && input[1] == ']'
  10512. && input[2] == '>')
  10513. {
  10514. input += 3;
  10515. break;
  10516. }
  10517. ++input;
  10518. ++len;
  10519. }
  10520. XmlElement* const e = new XmlElement ((int) 0);
  10521. e->setText (String (inputStart, len));
  10522. if (lastChildNode != 0)
  10523. lastChildNode->nextElement = e;
  10524. else
  10525. parent->addChildElement (e);
  10526. lastChildNode = e;
  10527. }
  10528. else
  10529. {
  10530. // this is some other element, so parse and add it..
  10531. XmlElement* const n = readNextElement (true);
  10532. if (n != 0)
  10533. {
  10534. if (lastChildNode == 0)
  10535. parent->addChildElement (n);
  10536. else
  10537. lastChildNode->nextElement = n;
  10538. lastChildNode = n;
  10539. }
  10540. else
  10541. {
  10542. return;
  10543. }
  10544. }
  10545. }
  10546. else
  10547. {
  10548. // read character block..
  10549. XmlElement* const e = new XmlElement ((int)0);
  10550. if (lastChildNode != 0)
  10551. lastChildNode->nextElement = e;
  10552. else
  10553. parent->addChildElement (e);
  10554. lastChildNode = e;
  10555. String textElementContent;
  10556. for (;;)
  10557. {
  10558. const juce_wchar c = *input;
  10559. if (c == '<')
  10560. break;
  10561. if (c == 0)
  10562. {
  10563. setLastError ("unmatched tags", false);
  10564. outOfData = true;
  10565. return;
  10566. }
  10567. if (c == '&')
  10568. {
  10569. String entity;
  10570. readEntity (entity);
  10571. if (entity.startsWithChar ('<') && entity [1] != 0)
  10572. {
  10573. const juce_wchar* const oldInput = input;
  10574. const bool oldOutOfData = outOfData;
  10575. input = entity;
  10576. outOfData = false;
  10577. for (;;)
  10578. {
  10579. XmlElement* const n = readNextElement (true);
  10580. if (n == 0)
  10581. break;
  10582. if (lastChildNode == 0)
  10583. parent->addChildElement (n);
  10584. else
  10585. lastChildNode->nextElement = n;
  10586. lastChildNode = n;
  10587. }
  10588. input = oldInput;
  10589. outOfData = oldOutOfData;
  10590. }
  10591. else
  10592. {
  10593. textElementContent += entity;
  10594. }
  10595. }
  10596. else
  10597. {
  10598. const juce_wchar* start = input;
  10599. int len = 0;
  10600. for (;;)
  10601. {
  10602. const juce_wchar nextChar = *input;
  10603. if (nextChar == '<' || nextChar == '&')
  10604. {
  10605. break;
  10606. }
  10607. else if (nextChar == 0)
  10608. {
  10609. setLastError ("unmatched tags", false);
  10610. outOfData = true;
  10611. return;
  10612. }
  10613. ++input;
  10614. ++len;
  10615. }
  10616. textElementContent.append (start, len);
  10617. }
  10618. }
  10619. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10620. : textElementContent.isNotEmpty())
  10621. e->setText (textElementContent);
  10622. }
  10623. }
  10624. }
  10625. void XmlDocument::readEntity (String& result)
  10626. {
  10627. // skip over the ampersand
  10628. ++input;
  10629. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10630. {
  10631. input += 4;
  10632. result += '&';
  10633. }
  10634. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10635. {
  10636. input += 5;
  10637. result += '"';
  10638. }
  10639. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  10640. {
  10641. input += 5;
  10642. result += '\'';
  10643. }
  10644. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  10645. {
  10646. input += 3;
  10647. result += '<';
  10648. }
  10649. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  10650. {
  10651. input += 3;
  10652. result += '>';
  10653. }
  10654. else if (*input == '#')
  10655. {
  10656. int charCode = 0;
  10657. ++input;
  10658. if (*input == 'x' || *input == 'X')
  10659. {
  10660. ++input;
  10661. int numChars = 0;
  10662. while (input[0] != ';')
  10663. {
  10664. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  10665. if (hexValue < 0 || ++numChars > 8)
  10666. {
  10667. setLastError ("illegal escape sequence", true);
  10668. break;
  10669. }
  10670. charCode = (charCode << 4) | hexValue;
  10671. ++input;
  10672. }
  10673. ++input;
  10674. }
  10675. else if (input[0] >= '0' && input[0] <= '9')
  10676. {
  10677. int numChars = 0;
  10678. while (input[0] != ';')
  10679. {
  10680. if (++numChars > 12)
  10681. {
  10682. setLastError ("illegal escape sequence", true);
  10683. break;
  10684. }
  10685. charCode = charCode * 10 + (input[0] - '0');
  10686. ++input;
  10687. }
  10688. ++input;
  10689. }
  10690. else
  10691. {
  10692. setLastError ("illegal escape sequence", true);
  10693. result += '&';
  10694. return;
  10695. }
  10696. result << (juce_wchar) charCode;
  10697. }
  10698. else
  10699. {
  10700. const juce_wchar* const entityNameStart = input;
  10701. const juce_wchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  10702. if (closingSemiColon == 0)
  10703. {
  10704. outOfData = true;
  10705. result += '&';
  10706. }
  10707. else
  10708. {
  10709. input = closingSemiColon + 1;
  10710. result += expandExternalEntity (String (entityNameStart,
  10711. (int) (closingSemiColon - entityNameStart)));
  10712. }
  10713. }
  10714. }
  10715. const String XmlDocument::expandEntity (const String& ent)
  10716. {
  10717. if (ent.equalsIgnoreCase ("amp"))
  10718. return String::charToString ('&');
  10719. if (ent.equalsIgnoreCase ("quot"))
  10720. return String::charToString ('"');
  10721. if (ent.equalsIgnoreCase ("apos"))
  10722. return String::charToString ('\'');
  10723. if (ent.equalsIgnoreCase ("lt"))
  10724. return String::charToString ('<');
  10725. if (ent.equalsIgnoreCase ("gt"))
  10726. return String::charToString ('>');
  10727. if (ent[0] == '#')
  10728. {
  10729. if (ent[1] == 'x' || ent[1] == 'X')
  10730. return String::charToString (static_cast <juce_wchar> (ent.substring (2).getHexValue32()));
  10731. if (ent[1] >= '0' && ent[1] <= '9')
  10732. return String::charToString (static_cast <juce_wchar> (ent.substring (1).getIntValue()));
  10733. setLastError ("illegal escape sequence", false);
  10734. return String::charToString ('&');
  10735. }
  10736. return expandExternalEntity (ent);
  10737. }
  10738. const String XmlDocument::expandExternalEntity (const String& entity)
  10739. {
  10740. if (needToLoadDTD)
  10741. {
  10742. if (dtdText.isNotEmpty())
  10743. {
  10744. dtdText = dtdText.trimCharactersAtEnd (">");
  10745. tokenisedDTD.addTokens (dtdText, true);
  10746. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase ("system")
  10747. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  10748. {
  10749. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  10750. tokenisedDTD.clear();
  10751. tokenisedDTD.addTokens (getFileContents (fn), true);
  10752. }
  10753. else
  10754. {
  10755. tokenisedDTD.clear();
  10756. const int openBracket = dtdText.indexOfChar ('[');
  10757. if (openBracket > 0)
  10758. {
  10759. const int closeBracket = dtdText.lastIndexOfChar (']');
  10760. if (closeBracket > openBracket)
  10761. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  10762. closeBracket), true);
  10763. }
  10764. }
  10765. for (int i = tokenisedDTD.size(); --i >= 0;)
  10766. {
  10767. if (tokenisedDTD[i].startsWithChar ('%')
  10768. && tokenisedDTD[i].endsWithChar (';'))
  10769. {
  10770. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  10771. StringArray newToks;
  10772. newToks.addTokens (parsed, true);
  10773. tokenisedDTD.remove (i);
  10774. for (int j = newToks.size(); --j >= 0;)
  10775. tokenisedDTD.insert (i, newToks[j]);
  10776. }
  10777. }
  10778. }
  10779. needToLoadDTD = false;
  10780. }
  10781. for (int i = 0; i < tokenisedDTD.size(); ++i)
  10782. {
  10783. if (tokenisedDTD[i] == entity)
  10784. {
  10785. if (tokenisedDTD[i - 1].equalsIgnoreCase ("<!entity"))
  10786. {
  10787. String ent (tokenisedDTD [i + 1].trimCharactersAtEnd (">").trim().unquoted());
  10788. // check for sub-entities..
  10789. int ampersand = ent.indexOfChar ('&');
  10790. while (ampersand >= 0)
  10791. {
  10792. const int semiColon = ent.indexOf (i + 1, ";");
  10793. if (semiColon < 0)
  10794. {
  10795. setLastError ("entity without terminating semi-colon", false);
  10796. break;
  10797. }
  10798. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  10799. ent = ent.substring (0, ampersand)
  10800. + resolved
  10801. + ent.substring (semiColon + 1);
  10802. ampersand = ent.indexOfChar (semiColon + 1, '&');
  10803. }
  10804. return ent;
  10805. }
  10806. }
  10807. }
  10808. setLastError ("unknown entity", true);
  10809. return entity;
  10810. }
  10811. const String XmlDocument::getParameterEntity (const String& entity)
  10812. {
  10813. for (int i = 0; i < tokenisedDTD.size(); ++i)
  10814. {
  10815. if (tokenisedDTD[i] == entity)
  10816. {
  10817. if (tokenisedDTD [i - 1] == "%"
  10818. && tokenisedDTD [i - 2].equalsIgnoreCase ("<!entity"))
  10819. {
  10820. const String ent (tokenisedDTD [i + 1].trimCharactersAtEnd (">"));
  10821. if (ent.equalsIgnoreCase ("system"))
  10822. return getFileContents (tokenisedDTD [i + 2].trimCharactersAtEnd (">"));
  10823. else
  10824. return ent.trim().unquoted();
  10825. }
  10826. }
  10827. }
  10828. return entity;
  10829. }
  10830. END_JUCE_NAMESPACE
  10831. /*** End of inlined file: juce_XmlDocument.cpp ***/
  10832. /*** Start of inlined file: juce_XmlElement.cpp ***/
  10833. BEGIN_JUCE_NAMESPACE
  10834. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  10835. : name (other.name),
  10836. value (other.value),
  10837. next (0)
  10838. {
  10839. }
  10840. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_, const String& value_) throw()
  10841. : name (name_),
  10842. value (value_),
  10843. next (0)
  10844. {
  10845. }
  10846. XmlElement::XmlElement (const String& tagName_) throw()
  10847. : tagName (tagName_),
  10848. firstChildElement (0),
  10849. nextElement (0),
  10850. attributes (0)
  10851. {
  10852. // the tag name mustn't be empty, or it'll look like a text element!
  10853. jassert (tagName_.containsNonWhitespaceChars())
  10854. // The tag can't contain spaces or other characters that would create invalid XML!
  10855. jassert (! tagName_.containsAnyOf (" <>/&"));
  10856. }
  10857. XmlElement::XmlElement (int /*dummy*/) throw()
  10858. : firstChildElement (0),
  10859. nextElement (0),
  10860. attributes (0)
  10861. {
  10862. }
  10863. XmlElement::XmlElement (const XmlElement& other) throw()
  10864. : tagName (other.tagName),
  10865. firstChildElement (0),
  10866. nextElement (0),
  10867. attributes (0)
  10868. {
  10869. copyChildrenAndAttributesFrom (other);
  10870. }
  10871. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  10872. {
  10873. if (this != &other)
  10874. {
  10875. removeAllAttributes();
  10876. deleteAllChildElements();
  10877. tagName = other.tagName;
  10878. copyChildrenAndAttributesFrom (other);
  10879. }
  10880. return *this;
  10881. }
  10882. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  10883. {
  10884. XmlElement* child = other.firstChildElement;
  10885. XmlElement* lastChild = 0;
  10886. while (child != 0)
  10887. {
  10888. XmlElement* const copiedChild = new XmlElement (*child);
  10889. if (lastChild != 0)
  10890. lastChild->nextElement = copiedChild;
  10891. else
  10892. firstChildElement = copiedChild;
  10893. lastChild = copiedChild;
  10894. child = child->nextElement;
  10895. }
  10896. const XmlAttributeNode* att = other.attributes;
  10897. XmlAttributeNode* lastAtt = 0;
  10898. while (att != 0)
  10899. {
  10900. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  10901. if (lastAtt != 0)
  10902. lastAtt->next = newAtt;
  10903. else
  10904. attributes = newAtt;
  10905. lastAtt = newAtt;
  10906. att = att->next;
  10907. }
  10908. }
  10909. XmlElement::~XmlElement() throw()
  10910. {
  10911. XmlElement* child = firstChildElement;
  10912. while (child != 0)
  10913. {
  10914. XmlElement* const nextChild = child->nextElement;
  10915. delete child;
  10916. child = nextChild;
  10917. }
  10918. XmlAttributeNode* att = attributes;
  10919. while (att != 0)
  10920. {
  10921. XmlAttributeNode* const nextAtt = att->next;
  10922. delete att;
  10923. att = nextAtt;
  10924. }
  10925. }
  10926. namespace XmlOutputFunctions
  10927. {
  10928. static bool isLegalXmlChar (const uint32 c) throw()
  10929. {
  10930. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  10931. return c < sizeof (legalChars) * 8
  10932. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  10933. }
  10934. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  10935. {
  10936. const juce_wchar* t = text;
  10937. for (;;)
  10938. {
  10939. const juce_wchar character = *t++;
  10940. if (character == 0)
  10941. {
  10942. break;
  10943. }
  10944. else if (isLegalXmlChar ((uint32) character))
  10945. {
  10946. outputStream << (char) character;
  10947. }
  10948. else
  10949. {
  10950. switch (character)
  10951. {
  10952. case '&': outputStream << "&amp;"; break;
  10953. case '"': outputStream << "&quot;"; break;
  10954. case '>': outputStream << "&gt;"; break;
  10955. case '<': outputStream << "&lt;"; break;
  10956. case '\n':
  10957. if (changeNewLines)
  10958. outputStream << "&#10;";
  10959. else
  10960. outputStream << (char) character;
  10961. break;
  10962. case '\r':
  10963. if (changeNewLines)
  10964. outputStream << "&#13;";
  10965. else
  10966. outputStream << (char) character;
  10967. break;
  10968. default:
  10969. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  10970. break;
  10971. }
  10972. }
  10973. }
  10974. }
  10975. static void writeSpaces (OutputStream& out, int numSpaces)
  10976. {
  10977. if (numSpaces > 0)
  10978. {
  10979. const char* const blanks = " ";
  10980. const int blankSize = (int) sizeof (blanks) - 1;
  10981. while (numSpaces > blankSize)
  10982. {
  10983. out.write (blanks, blankSize);
  10984. numSpaces -= blankSize;
  10985. }
  10986. out.write (blanks, numSpaces);
  10987. }
  10988. }
  10989. }
  10990. void XmlElement::writeElementAsText (OutputStream& outputStream,
  10991. const int indentationLevel,
  10992. const int lineWrapLength) const
  10993. {
  10994. using namespace XmlOutputFunctions;
  10995. writeSpaces (outputStream, indentationLevel);
  10996. if (! isTextElement())
  10997. {
  10998. outputStream.writeByte ('<');
  10999. outputStream << tagName;
  11000. const int attIndent = indentationLevel + tagName.length() + 1;
  11001. int lineLen = 0;
  11002. const XmlAttributeNode* att = attributes;
  11003. while (att != 0)
  11004. {
  11005. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11006. {
  11007. outputStream.write ("\r\n", 2);
  11008. writeSpaces (outputStream, attIndent);
  11009. lineLen = 0;
  11010. }
  11011. const int64 startPos = outputStream.getPosition();
  11012. outputStream.writeByte (' ');
  11013. outputStream << att->name;
  11014. outputStream.write ("=\"", 2);
  11015. escapeIllegalXmlChars (outputStream, att->value, true);
  11016. outputStream.writeByte ('"');
  11017. lineLen += (int) (outputStream.getPosition() - startPos);
  11018. att = att->next;
  11019. }
  11020. if (firstChildElement != 0)
  11021. {
  11022. XmlElement* child = firstChildElement;
  11023. if (child->nextElement == 0 && child->isTextElement())
  11024. {
  11025. outputStream.writeByte ('>');
  11026. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11027. }
  11028. else
  11029. {
  11030. if (indentationLevel >= 0)
  11031. outputStream.write (">\r\n", 3);
  11032. else
  11033. outputStream.writeByte ('>');
  11034. bool lastWasTextNode = false;
  11035. while (child != 0)
  11036. {
  11037. if (child->isTextElement())
  11038. {
  11039. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11040. writeSpaces (outputStream, indentationLevel + 2);
  11041. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11042. lastWasTextNode = true;
  11043. }
  11044. else
  11045. {
  11046. if (indentationLevel >= 0)
  11047. {
  11048. if (lastWasTextNode)
  11049. outputStream.write ("\r\n", 2);
  11050. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11051. }
  11052. else
  11053. {
  11054. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11055. }
  11056. lastWasTextNode = false;
  11057. }
  11058. child = child->nextElement;
  11059. }
  11060. if (indentationLevel >= 0)
  11061. {
  11062. if (lastWasTextNode)
  11063. outputStream.write ("\r\n", 2);
  11064. writeSpaces (outputStream, indentationLevel);
  11065. }
  11066. }
  11067. outputStream.write ("</", 2);
  11068. outputStream << tagName;
  11069. if (indentationLevel >= 0)
  11070. outputStream.write (">\r\n", 3);
  11071. else
  11072. outputStream.writeByte ('>');
  11073. }
  11074. else
  11075. {
  11076. if (indentationLevel >= 0)
  11077. outputStream.write ("/>\r\n", 4);
  11078. else
  11079. outputStream.write ("/>", 2);
  11080. }
  11081. }
  11082. else
  11083. {
  11084. if (indentationLevel >= 0)
  11085. writeSpaces (outputStream, indentationLevel + 2);
  11086. escapeIllegalXmlChars (outputStream, getText(), false);
  11087. }
  11088. }
  11089. const String XmlElement::createDocument (const String& dtdToUse,
  11090. const bool allOnOneLine,
  11091. const bool includeXmlHeader,
  11092. const String& encodingType,
  11093. const int lineWrapLength) const
  11094. {
  11095. MemoryOutputStream mem (2048, 4096);
  11096. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11097. return mem.toUTF8();
  11098. }
  11099. void XmlElement::writeToStream (OutputStream& output,
  11100. const String& dtdToUse,
  11101. const bool allOnOneLine,
  11102. const bool includeXmlHeader,
  11103. const String& encodingType,
  11104. const int lineWrapLength) const
  11105. {
  11106. if (includeXmlHeader)
  11107. output << "<?xml version=\"1.0\" encoding=\"" << encodingType
  11108. << (allOnOneLine ? "\"?> " : "\"?>\r\n\r\n");
  11109. if (dtdToUse.isNotEmpty())
  11110. output << dtdToUse << (allOnOneLine ? " " : "\r\n");
  11111. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11112. }
  11113. bool XmlElement::writeToFile (const File& file,
  11114. const String& dtdToUse,
  11115. const String& encodingType,
  11116. const int lineWrapLength) const
  11117. {
  11118. if (file.hasWriteAccess())
  11119. {
  11120. TemporaryFile tempFile (file);
  11121. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11122. if (out != 0)
  11123. {
  11124. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11125. out = 0;
  11126. return tempFile.overwriteTargetFileWithTemporary();
  11127. }
  11128. }
  11129. return false;
  11130. }
  11131. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11132. {
  11133. #ifdef JUCE_DEBUG
  11134. // if debugging, check that the case is actually the same, because
  11135. // valid xml is case-sensitive, and although this lets it pass, it's
  11136. // better not to..
  11137. if (tagName.equalsIgnoreCase (tagNameWanted))
  11138. {
  11139. jassert (tagName == tagNameWanted);
  11140. return true;
  11141. }
  11142. else
  11143. {
  11144. return false;
  11145. }
  11146. #else
  11147. return tagName.equalsIgnoreCase (tagNameWanted);
  11148. #endif
  11149. }
  11150. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11151. {
  11152. XmlElement* e = nextElement;
  11153. while (e != 0 && ! e->hasTagName (requiredTagName))
  11154. e = e->nextElement;
  11155. return e;
  11156. }
  11157. int XmlElement::getNumAttributes() const throw()
  11158. {
  11159. const XmlAttributeNode* att = attributes;
  11160. int count = 0;
  11161. while (att != 0)
  11162. {
  11163. att = att->next;
  11164. ++count;
  11165. }
  11166. return count;
  11167. }
  11168. const String& XmlElement::getAttributeName (const int index) const throw()
  11169. {
  11170. const XmlAttributeNode* att = attributes;
  11171. int count = 0;
  11172. while (att != 0)
  11173. {
  11174. if (count == index)
  11175. return att->name;
  11176. att = att->next;
  11177. ++count;
  11178. }
  11179. return String::empty;
  11180. }
  11181. const String& XmlElement::getAttributeValue (const int index) const throw()
  11182. {
  11183. const XmlAttributeNode* att = attributes;
  11184. int count = 0;
  11185. while (att != 0)
  11186. {
  11187. if (count == index)
  11188. return att->value;
  11189. att = att->next;
  11190. ++count;
  11191. }
  11192. return String::empty;
  11193. }
  11194. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11195. {
  11196. const XmlAttributeNode* att = attributes;
  11197. while (att != 0)
  11198. {
  11199. if (att->name.equalsIgnoreCase (attributeName))
  11200. return true;
  11201. att = att->next;
  11202. }
  11203. return false;
  11204. }
  11205. const String& XmlElement::getStringAttribute (const String& attributeName) const throw()
  11206. {
  11207. const XmlAttributeNode* att = attributes;
  11208. while (att != 0)
  11209. {
  11210. if (att->name.equalsIgnoreCase (attributeName))
  11211. return att->value;
  11212. att = att->next;
  11213. }
  11214. return String::empty;
  11215. }
  11216. const String XmlElement::getStringAttribute (const String& attributeName, const String& defaultReturnValue) const
  11217. {
  11218. const XmlAttributeNode* att = attributes;
  11219. while (att != 0)
  11220. {
  11221. if (att->name.equalsIgnoreCase (attributeName))
  11222. return att->value;
  11223. att = att->next;
  11224. }
  11225. return defaultReturnValue;
  11226. }
  11227. int XmlElement::getIntAttribute (const String& attributeName, const int defaultReturnValue) const
  11228. {
  11229. const XmlAttributeNode* att = attributes;
  11230. while (att != 0)
  11231. {
  11232. if (att->name.equalsIgnoreCase (attributeName))
  11233. return att->value.getIntValue();
  11234. att = att->next;
  11235. }
  11236. return defaultReturnValue;
  11237. }
  11238. double XmlElement::getDoubleAttribute (const String& attributeName, const double defaultReturnValue) const
  11239. {
  11240. const XmlAttributeNode* att = attributes;
  11241. while (att != 0)
  11242. {
  11243. if (att->name.equalsIgnoreCase (attributeName))
  11244. return att->value.getDoubleValue();
  11245. att = att->next;
  11246. }
  11247. return defaultReturnValue;
  11248. }
  11249. bool XmlElement::getBoolAttribute (const String& attributeName, const bool defaultReturnValue) const
  11250. {
  11251. const XmlAttributeNode* att = attributes;
  11252. while (att != 0)
  11253. {
  11254. if (att->name.equalsIgnoreCase (attributeName))
  11255. {
  11256. juce_wchar firstChar = att->value[0];
  11257. if (CharacterFunctions::isWhitespace (firstChar))
  11258. firstChar = att->value.trimStart() [0];
  11259. return firstChar == '1'
  11260. || firstChar == 't'
  11261. || firstChar == 'y'
  11262. || firstChar == 'T'
  11263. || firstChar == 'Y';
  11264. }
  11265. att = att->next;
  11266. }
  11267. return defaultReturnValue;
  11268. }
  11269. bool XmlElement::compareAttribute (const String& attributeName,
  11270. const String& stringToCompareAgainst,
  11271. const bool ignoreCase) const throw()
  11272. {
  11273. const XmlAttributeNode* att = attributes;
  11274. while (att != 0)
  11275. {
  11276. if (att->name.equalsIgnoreCase (attributeName))
  11277. {
  11278. if (ignoreCase)
  11279. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11280. else
  11281. return att->value == stringToCompareAgainst;
  11282. }
  11283. att = att->next;
  11284. }
  11285. return false;
  11286. }
  11287. void XmlElement::setAttribute (const String& attributeName, const String& value)
  11288. {
  11289. #ifdef JUCE_DEBUG
  11290. // check the identifier being passed in is legal..
  11291. const juce_wchar* t = attributeName;
  11292. while (*t != 0)
  11293. {
  11294. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11295. || *t == '_'
  11296. || *t == '-'
  11297. || *t == ':');
  11298. ++t;
  11299. }
  11300. #endif
  11301. if (attributes == 0)
  11302. {
  11303. attributes = new XmlAttributeNode (attributeName, value);
  11304. }
  11305. else
  11306. {
  11307. XmlAttributeNode* att = attributes;
  11308. for (;;)
  11309. {
  11310. if (att->name.equalsIgnoreCase (attributeName))
  11311. {
  11312. att->value = value;
  11313. break;
  11314. }
  11315. else if (att->next == 0)
  11316. {
  11317. att->next = new XmlAttributeNode (attributeName, value);
  11318. break;
  11319. }
  11320. att = att->next;
  11321. }
  11322. }
  11323. }
  11324. void XmlElement::setAttribute (const String& attributeName, const int number)
  11325. {
  11326. setAttribute (attributeName, String (number));
  11327. }
  11328. void XmlElement::setAttribute (const String& attributeName, const double number)
  11329. {
  11330. setAttribute (attributeName, String (number));
  11331. }
  11332. void XmlElement::removeAttribute (const String& attributeName) throw()
  11333. {
  11334. XmlAttributeNode* att = attributes;
  11335. XmlAttributeNode* lastAtt = 0;
  11336. while (att != 0)
  11337. {
  11338. if (att->name.equalsIgnoreCase (attributeName))
  11339. {
  11340. if (lastAtt == 0)
  11341. attributes = att->next;
  11342. else
  11343. lastAtt->next = att->next;
  11344. delete att;
  11345. break;
  11346. }
  11347. lastAtt = att;
  11348. att = att->next;
  11349. }
  11350. }
  11351. void XmlElement::removeAllAttributes() throw()
  11352. {
  11353. while (attributes != 0)
  11354. {
  11355. XmlAttributeNode* const nextAtt = attributes->next;
  11356. delete attributes;
  11357. attributes = nextAtt;
  11358. }
  11359. }
  11360. int XmlElement::getNumChildElements() const throw()
  11361. {
  11362. int count = 0;
  11363. const XmlElement* child = firstChildElement;
  11364. while (child != 0)
  11365. {
  11366. ++count;
  11367. child = child->nextElement;
  11368. }
  11369. return count;
  11370. }
  11371. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11372. {
  11373. int count = 0;
  11374. XmlElement* child = firstChildElement;
  11375. while (child != 0 && count < index)
  11376. {
  11377. child = child->nextElement;
  11378. ++count;
  11379. }
  11380. return child;
  11381. }
  11382. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11383. {
  11384. XmlElement* child = firstChildElement;
  11385. while (child != 0)
  11386. {
  11387. if (child->hasTagName (childName))
  11388. break;
  11389. child = child->nextElement;
  11390. }
  11391. return child;
  11392. }
  11393. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11394. {
  11395. if (newNode != 0)
  11396. {
  11397. if (firstChildElement == 0)
  11398. {
  11399. firstChildElement = newNode;
  11400. }
  11401. else
  11402. {
  11403. XmlElement* child = firstChildElement;
  11404. while (child->nextElement != 0)
  11405. child = child->nextElement;
  11406. child->nextElement = newNode;
  11407. // if this is non-zero, then something's probably
  11408. // gone wrong..
  11409. jassert (newNode->nextElement == 0);
  11410. }
  11411. }
  11412. }
  11413. void XmlElement::insertChildElement (XmlElement* const newNode,
  11414. int indexToInsertAt) throw()
  11415. {
  11416. if (newNode != 0)
  11417. {
  11418. removeChildElement (newNode, false);
  11419. if (indexToInsertAt == 0)
  11420. {
  11421. newNode->nextElement = firstChildElement;
  11422. firstChildElement = newNode;
  11423. }
  11424. else
  11425. {
  11426. if (firstChildElement == 0)
  11427. {
  11428. firstChildElement = newNode;
  11429. }
  11430. else
  11431. {
  11432. if (indexToInsertAt < 0)
  11433. indexToInsertAt = std::numeric_limits<int>::max();
  11434. XmlElement* child = firstChildElement;
  11435. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11436. child = child->nextElement;
  11437. newNode->nextElement = child->nextElement;
  11438. child->nextElement = newNode;
  11439. }
  11440. }
  11441. }
  11442. }
  11443. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11444. {
  11445. XmlElement* const newElement = new XmlElement (tagName);
  11446. addChildElement (newElement);
  11447. return newElement;
  11448. }
  11449. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11450. XmlElement* const newNode) throw()
  11451. {
  11452. if (newNode != 0)
  11453. {
  11454. XmlElement* child = firstChildElement;
  11455. XmlElement* previousNode = 0;
  11456. while (child != 0)
  11457. {
  11458. if (child == currentChildElement)
  11459. {
  11460. if (child != newNode)
  11461. {
  11462. if (previousNode == 0)
  11463. firstChildElement = newNode;
  11464. else
  11465. previousNode->nextElement = newNode;
  11466. newNode->nextElement = child->nextElement;
  11467. delete child;
  11468. }
  11469. return true;
  11470. }
  11471. previousNode = child;
  11472. child = child->nextElement;
  11473. }
  11474. }
  11475. return false;
  11476. }
  11477. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11478. const bool shouldDeleteTheChild) throw()
  11479. {
  11480. if (childToRemove != 0)
  11481. {
  11482. if (firstChildElement == childToRemove)
  11483. {
  11484. firstChildElement = childToRemove->nextElement;
  11485. childToRemove->nextElement = 0;
  11486. }
  11487. else
  11488. {
  11489. XmlElement* child = firstChildElement;
  11490. XmlElement* last = 0;
  11491. while (child != 0)
  11492. {
  11493. if (child == childToRemove)
  11494. {
  11495. if (last == 0)
  11496. firstChildElement = child->nextElement;
  11497. else
  11498. last->nextElement = child->nextElement;
  11499. childToRemove->nextElement = 0;
  11500. break;
  11501. }
  11502. last = child;
  11503. child = child->nextElement;
  11504. }
  11505. }
  11506. if (shouldDeleteTheChild)
  11507. delete childToRemove;
  11508. }
  11509. }
  11510. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11511. const bool ignoreOrderOfAttributes) const throw()
  11512. {
  11513. if (this != other)
  11514. {
  11515. if (other == 0 || tagName != other->tagName)
  11516. {
  11517. return false;
  11518. }
  11519. if (ignoreOrderOfAttributes)
  11520. {
  11521. int totalAtts = 0;
  11522. const XmlAttributeNode* att = attributes;
  11523. while (att != 0)
  11524. {
  11525. if (! other->compareAttribute (att->name, att->value))
  11526. return false;
  11527. att = att->next;
  11528. ++totalAtts;
  11529. }
  11530. if (totalAtts != other->getNumAttributes())
  11531. return false;
  11532. }
  11533. else
  11534. {
  11535. const XmlAttributeNode* thisAtt = attributes;
  11536. const XmlAttributeNode* otherAtt = other->attributes;
  11537. for (;;)
  11538. {
  11539. if (thisAtt == 0 || otherAtt == 0)
  11540. {
  11541. if (thisAtt == otherAtt) // both 0, so it's a match
  11542. break;
  11543. return false;
  11544. }
  11545. if (thisAtt->name != otherAtt->name
  11546. || thisAtt->value != otherAtt->value)
  11547. {
  11548. return false;
  11549. }
  11550. thisAtt = thisAtt->next;
  11551. otherAtt = otherAtt->next;
  11552. }
  11553. }
  11554. const XmlElement* thisChild = firstChildElement;
  11555. const XmlElement* otherChild = other->firstChildElement;
  11556. for (;;)
  11557. {
  11558. if (thisChild == 0 || otherChild == 0)
  11559. {
  11560. if (thisChild == otherChild) // both 0, so it's a match
  11561. break;
  11562. return false;
  11563. }
  11564. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11565. return false;
  11566. thisChild = thisChild->nextElement;
  11567. otherChild = otherChild->nextElement;
  11568. }
  11569. }
  11570. return true;
  11571. }
  11572. void XmlElement::deleteAllChildElements() throw()
  11573. {
  11574. while (firstChildElement != 0)
  11575. {
  11576. XmlElement* const nextChild = firstChildElement->nextElement;
  11577. delete firstChildElement;
  11578. firstChildElement = nextChild;
  11579. }
  11580. }
  11581. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  11582. {
  11583. XmlElement* child = firstChildElement;
  11584. while (child != 0)
  11585. {
  11586. if (child->hasTagName (name))
  11587. {
  11588. XmlElement* const nextChild = child->nextElement;
  11589. removeChildElement (child, true);
  11590. child = nextChild;
  11591. }
  11592. else
  11593. {
  11594. child = child->nextElement;
  11595. }
  11596. }
  11597. }
  11598. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  11599. {
  11600. const XmlElement* child = firstChildElement;
  11601. while (child != 0)
  11602. {
  11603. if (child == possibleChild)
  11604. return true;
  11605. child = child->nextElement;
  11606. }
  11607. return false;
  11608. }
  11609. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  11610. {
  11611. if (this == elementToLookFor || elementToLookFor == 0)
  11612. return 0;
  11613. XmlElement* child = firstChildElement;
  11614. while (child != 0)
  11615. {
  11616. if (elementToLookFor == child)
  11617. return this;
  11618. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  11619. if (found != 0)
  11620. return found;
  11621. child = child->nextElement;
  11622. }
  11623. return 0;
  11624. }
  11625. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  11626. {
  11627. XmlElement* e = firstChildElement;
  11628. while (e != 0)
  11629. {
  11630. *elems++ = e;
  11631. e = e->nextElement;
  11632. }
  11633. }
  11634. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  11635. {
  11636. XmlElement* e = firstChildElement = elems[0];
  11637. for (int i = 1; i < num; ++i)
  11638. {
  11639. e->nextElement = elems[i];
  11640. e = e->nextElement;
  11641. }
  11642. e->nextElement = 0;
  11643. }
  11644. bool XmlElement::isTextElement() const throw()
  11645. {
  11646. return tagName.isEmpty();
  11647. }
  11648. static const juce_wchar* const juce_xmltextContentAttributeName = L"text";
  11649. const String XmlElement::getText() const throw()
  11650. {
  11651. jassert (isTextElement()); // you're trying to get the text from an element that
  11652. // isn't actually a text element.. If this contains text sub-nodes, you
  11653. // probably want to use getAllSubText instead.
  11654. return getStringAttribute (juce_xmltextContentAttributeName);
  11655. }
  11656. void XmlElement::setText (const String& newText) throw()
  11657. {
  11658. if (isTextElement())
  11659. {
  11660. setAttribute (juce_xmltextContentAttributeName, newText);
  11661. }
  11662. else
  11663. {
  11664. jassertfalse // you can only change the text in a text element, not a normal one.
  11665. }
  11666. }
  11667. const String XmlElement::getAllSubText() const throw()
  11668. {
  11669. String result;
  11670. String::Concatenator concatenator (result);
  11671. const XmlElement* child = firstChildElement;
  11672. while (child != 0)
  11673. {
  11674. if (child->isTextElement())
  11675. concatenator.append (child->getText());
  11676. child = child->nextElement;
  11677. }
  11678. return result;
  11679. }
  11680. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  11681. const String& defaultReturnValue) const throw()
  11682. {
  11683. const XmlElement* const child = getChildByName (childTagName);
  11684. if (child != 0)
  11685. return child->getAllSubText();
  11686. return defaultReturnValue;
  11687. }
  11688. XmlElement* XmlElement::createTextElement (const String& text) throw()
  11689. {
  11690. XmlElement* const e = new XmlElement ((int) 0);
  11691. e->setAttribute (juce_xmltextContentAttributeName, text);
  11692. return e;
  11693. }
  11694. void XmlElement::addTextElement (const String& text) throw()
  11695. {
  11696. addChildElement (createTextElement (text));
  11697. }
  11698. void XmlElement::deleteAllTextElements() throw()
  11699. {
  11700. XmlElement* child = firstChildElement;
  11701. while (child != 0)
  11702. {
  11703. XmlElement* const next = child->nextElement;
  11704. if (child->isTextElement())
  11705. removeChildElement (child, true);
  11706. child = next;
  11707. }
  11708. }
  11709. END_JUCE_NAMESPACE
  11710. /*** End of inlined file: juce_XmlElement.cpp ***/
  11711. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  11712. BEGIN_JUCE_NAMESPACE
  11713. ReadWriteLock::ReadWriteLock() throw()
  11714. : numWaitingWriters (0),
  11715. numWriters (0),
  11716. writerThreadId (0)
  11717. {
  11718. }
  11719. ReadWriteLock::~ReadWriteLock() throw()
  11720. {
  11721. jassert (readerThreads.size() == 0);
  11722. jassert (numWriters == 0);
  11723. }
  11724. void ReadWriteLock::enterRead() const throw()
  11725. {
  11726. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11727. const ScopedLock sl (accessLock);
  11728. for (;;)
  11729. {
  11730. jassert (readerThreads.size() % 2 == 0);
  11731. int i;
  11732. for (i = 0; i < readerThreads.size(); i += 2)
  11733. if (readerThreads.getUnchecked(i) == threadId)
  11734. break;
  11735. if (i < readerThreads.size()
  11736. || numWriters + numWaitingWriters == 0
  11737. || (threadId == writerThreadId && numWriters > 0))
  11738. {
  11739. if (i < readerThreads.size())
  11740. {
  11741. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  11742. }
  11743. else
  11744. {
  11745. readerThreads.add (threadId);
  11746. readerThreads.add ((Thread::ThreadID) 1);
  11747. }
  11748. return;
  11749. }
  11750. const ScopedUnlock ul (accessLock);
  11751. waitEvent.wait (100);
  11752. }
  11753. }
  11754. void ReadWriteLock::exitRead() const throw()
  11755. {
  11756. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11757. const ScopedLock sl (accessLock);
  11758. for (int i = 0; i < readerThreads.size(); i += 2)
  11759. {
  11760. if (readerThreads.getUnchecked(i) == threadId)
  11761. {
  11762. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  11763. if (newCount == 0)
  11764. {
  11765. readerThreads.removeRange (i, 2);
  11766. waitEvent.signal();
  11767. }
  11768. else
  11769. {
  11770. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  11771. }
  11772. return;
  11773. }
  11774. }
  11775. jassertfalse // unlocking a lock that wasn't locked..
  11776. }
  11777. void ReadWriteLock::enterWrite() const throw()
  11778. {
  11779. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11780. const ScopedLock sl (accessLock);
  11781. for (;;)
  11782. {
  11783. if (readerThreads.size() + numWriters == 0
  11784. || threadId == writerThreadId
  11785. || (readerThreads.size() == 2
  11786. && readerThreads.getUnchecked(0) == threadId))
  11787. {
  11788. writerThreadId = threadId;
  11789. ++numWriters;
  11790. break;
  11791. }
  11792. ++numWaitingWriters;
  11793. accessLock.exit();
  11794. waitEvent.wait (100);
  11795. accessLock.enter();
  11796. --numWaitingWriters;
  11797. }
  11798. }
  11799. bool ReadWriteLock::tryEnterWrite() const throw()
  11800. {
  11801. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11802. const ScopedLock sl (accessLock);
  11803. if (readerThreads.size() + numWriters == 0
  11804. || threadId == writerThreadId
  11805. || (readerThreads.size() == 2
  11806. && readerThreads.getUnchecked(0) == threadId))
  11807. {
  11808. writerThreadId = threadId;
  11809. ++numWriters;
  11810. return true;
  11811. }
  11812. return false;
  11813. }
  11814. void ReadWriteLock::exitWrite() const throw()
  11815. {
  11816. const ScopedLock sl (accessLock);
  11817. // check this thread actually had the lock..
  11818. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  11819. if (--numWriters == 0)
  11820. {
  11821. writerThreadId = 0;
  11822. waitEvent.signal();
  11823. }
  11824. }
  11825. END_JUCE_NAMESPACE
  11826. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  11827. /*** Start of inlined file: juce_Thread.cpp ***/
  11828. BEGIN_JUCE_NAMESPACE
  11829. // these functions are implemented in the platform-specific code.
  11830. void* juce_createThread (void* userData);
  11831. void juce_killThread (void* handle);
  11832. bool juce_setThreadPriority (void* handle, int priority);
  11833. void juce_setCurrentThreadName (const String& name);
  11834. #if JUCE_WIN32
  11835. void juce_CloseThreadHandle (void* handle);
  11836. #endif
  11837. void Thread::threadEntryPoint (Thread* const thread)
  11838. {
  11839. {
  11840. const ScopedLock sl (runningThreadsLock);
  11841. runningThreads.add (thread);
  11842. }
  11843. JUCE_TRY
  11844. {
  11845. thread->threadId_ = Thread::getCurrentThreadId();
  11846. if (thread->threadName_.isNotEmpty())
  11847. juce_setCurrentThreadName (thread->threadName_);
  11848. if (thread->startSuspensionEvent_.wait (10000))
  11849. {
  11850. if (thread->affinityMask_ != 0)
  11851. setCurrentThreadAffinityMask (thread->affinityMask_);
  11852. thread->run();
  11853. }
  11854. }
  11855. JUCE_CATCH_ALL_ASSERT
  11856. {
  11857. const ScopedLock sl (runningThreadsLock);
  11858. jassert (runningThreads.contains (thread));
  11859. runningThreads.removeValue (thread);
  11860. }
  11861. #if JUCE_WIN32
  11862. juce_CloseThreadHandle (thread->threadHandle_);
  11863. #endif
  11864. thread->threadHandle_ = 0;
  11865. thread->threadId_ = 0;
  11866. }
  11867. // used to wrap the incoming call from the platform-specific code
  11868. void JUCE_API juce_threadEntryPoint (void* userData)
  11869. {
  11870. Thread::threadEntryPoint (static_cast <Thread*> (userData));
  11871. }
  11872. Thread::Thread (const String& threadName)
  11873. : threadName_ (threadName),
  11874. threadHandle_ (0),
  11875. threadPriority_ (5),
  11876. threadId_ (0),
  11877. affinityMask_ (0),
  11878. threadShouldExit_ (false)
  11879. {
  11880. }
  11881. Thread::~Thread()
  11882. {
  11883. stopThread (100);
  11884. }
  11885. void Thread::startThread()
  11886. {
  11887. const ScopedLock sl (startStopLock);
  11888. threadShouldExit_ = false;
  11889. if (threadHandle_ == 0)
  11890. {
  11891. threadHandle_ = juce_createThread (this);
  11892. juce_setThreadPriority (threadHandle_, threadPriority_);
  11893. startSuspensionEvent_.signal();
  11894. }
  11895. }
  11896. void Thread::startThread (const int priority)
  11897. {
  11898. const ScopedLock sl (startStopLock);
  11899. if (threadHandle_ == 0)
  11900. {
  11901. threadPriority_ = priority;
  11902. startThread();
  11903. }
  11904. else
  11905. {
  11906. setPriority (priority);
  11907. }
  11908. }
  11909. bool Thread::isThreadRunning() const
  11910. {
  11911. return threadHandle_ != 0;
  11912. }
  11913. void Thread::signalThreadShouldExit()
  11914. {
  11915. threadShouldExit_ = true;
  11916. }
  11917. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  11918. {
  11919. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  11920. jassert (getThreadId() != getCurrentThreadId());
  11921. const int sleepMsPerIteration = 5;
  11922. int count = timeOutMilliseconds / sleepMsPerIteration;
  11923. while (isThreadRunning())
  11924. {
  11925. if (timeOutMilliseconds > 0 && --count < 0)
  11926. return false;
  11927. sleep (sleepMsPerIteration);
  11928. }
  11929. return true;
  11930. }
  11931. void Thread::stopThread (const int timeOutMilliseconds)
  11932. {
  11933. // agh! You can't stop the thread that's calling this method! How on earth
  11934. // would that work??
  11935. jassert (getCurrentThreadId() != getThreadId());
  11936. const ScopedLock sl (startStopLock);
  11937. if (isThreadRunning())
  11938. {
  11939. signalThreadShouldExit();
  11940. notify();
  11941. if (timeOutMilliseconds != 0)
  11942. waitForThreadToExit (timeOutMilliseconds);
  11943. if (isThreadRunning())
  11944. {
  11945. // very bad karma if this point is reached, as
  11946. // there are bound to be locks and events left in
  11947. // silly states when a thread is killed by force..
  11948. jassertfalse
  11949. Logger::writeToLog ("!! killing thread by force !!");
  11950. juce_killThread (threadHandle_);
  11951. threadHandle_ = 0;
  11952. threadId_ = 0;
  11953. const ScopedLock sl2 (runningThreadsLock);
  11954. runningThreads.removeValue (this);
  11955. }
  11956. }
  11957. }
  11958. bool Thread::setPriority (const int priority)
  11959. {
  11960. const ScopedLock sl (startStopLock);
  11961. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  11962. if (worked)
  11963. threadPriority_ = priority;
  11964. return worked;
  11965. }
  11966. bool Thread::setCurrentThreadPriority (const int priority)
  11967. {
  11968. return juce_setThreadPriority (0, priority);
  11969. }
  11970. void Thread::setAffinityMask (const uint32 affinityMask)
  11971. {
  11972. affinityMask_ = affinityMask;
  11973. }
  11974. bool Thread::wait (const int timeOutMilliseconds) const
  11975. {
  11976. return defaultEvent_.wait (timeOutMilliseconds);
  11977. }
  11978. void Thread::notify() const
  11979. {
  11980. defaultEvent_.signal();
  11981. }
  11982. int Thread::getNumRunningThreads()
  11983. {
  11984. return runningThreads.size();
  11985. }
  11986. Thread* Thread::getCurrentThread()
  11987. {
  11988. const ThreadID thisId = getCurrentThreadId();
  11989. const ScopedLock sl (runningThreadsLock);
  11990. for (int i = runningThreads.size(); --i >= 0;)
  11991. {
  11992. Thread* const t = runningThreads.getUnchecked(i);
  11993. if (t->threadId_ == thisId)
  11994. return t;
  11995. }
  11996. return 0;
  11997. }
  11998. void Thread::stopAllThreads (const int timeOutMilliseconds)
  11999. {
  12000. {
  12001. const ScopedLock sl (runningThreadsLock);
  12002. for (int i = runningThreads.size(); --i >= 0;)
  12003. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12004. }
  12005. for (;;)
  12006. {
  12007. Thread* firstThread;
  12008. {
  12009. const ScopedLock sl (runningThreadsLock);
  12010. firstThread = runningThreads.getFirst();
  12011. }
  12012. if (firstThread == 0)
  12013. break;
  12014. firstThread->stopThread (timeOutMilliseconds);
  12015. }
  12016. }
  12017. Array<Thread*> Thread::runningThreads;
  12018. CriticalSection Thread::runningThreadsLock;
  12019. END_JUCE_NAMESPACE
  12020. /*** End of inlined file: juce_Thread.cpp ***/
  12021. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12022. BEGIN_JUCE_NAMESPACE
  12023. ThreadPoolJob::ThreadPoolJob (const String& name)
  12024. : jobName (name),
  12025. pool (0),
  12026. shouldStop (false),
  12027. isActive (false),
  12028. shouldBeDeleted (false)
  12029. {
  12030. }
  12031. ThreadPoolJob::~ThreadPoolJob()
  12032. {
  12033. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12034. // to remove it first!
  12035. jassert (pool == 0 || ! pool->contains (this));
  12036. }
  12037. const String ThreadPoolJob::getJobName() const
  12038. {
  12039. return jobName;
  12040. }
  12041. void ThreadPoolJob::setJobName (const String& newName)
  12042. {
  12043. jobName = newName;
  12044. }
  12045. void ThreadPoolJob::signalJobShouldExit()
  12046. {
  12047. shouldStop = true;
  12048. }
  12049. class ThreadPool::ThreadPoolThread : public Thread
  12050. {
  12051. public:
  12052. ThreadPoolThread (ThreadPool& pool_)
  12053. : Thread ("Pool"),
  12054. pool (pool_),
  12055. busy (false)
  12056. {
  12057. }
  12058. ~ThreadPoolThread()
  12059. {
  12060. }
  12061. void run()
  12062. {
  12063. while (! threadShouldExit())
  12064. {
  12065. if (! pool.runNextJob())
  12066. wait (500);
  12067. }
  12068. }
  12069. private:
  12070. ThreadPool& pool;
  12071. bool volatile busy;
  12072. ThreadPoolThread (const ThreadPoolThread&);
  12073. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12074. };
  12075. ThreadPool::ThreadPool (const int numThreads,
  12076. const bool startThreadsOnlyWhenNeeded,
  12077. const int stopThreadsWhenNotUsedTimeoutMs)
  12078. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12079. priority (5)
  12080. {
  12081. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12082. for (int i = jmax (1, numThreads); --i >= 0;)
  12083. threads.add (new ThreadPoolThread (*this));
  12084. if (! startThreadsOnlyWhenNeeded)
  12085. for (int i = threads.size(); --i >= 0;)
  12086. threads.getUnchecked(i)->startThread (priority);
  12087. }
  12088. ThreadPool::~ThreadPool()
  12089. {
  12090. removeAllJobs (true, 4000);
  12091. int i;
  12092. for (i = threads.size(); --i >= 0;)
  12093. threads.getUnchecked(i)->signalThreadShouldExit();
  12094. for (i = threads.size(); --i >= 0;)
  12095. threads.getUnchecked(i)->stopThread (500);
  12096. }
  12097. void ThreadPool::addJob (ThreadPoolJob* const job)
  12098. {
  12099. jassert (job != 0);
  12100. jassert (job->pool == 0);
  12101. if (job->pool == 0)
  12102. {
  12103. job->pool = this;
  12104. job->shouldStop = false;
  12105. job->isActive = false;
  12106. {
  12107. const ScopedLock sl (lock);
  12108. jobs.add (job);
  12109. int numRunning = 0;
  12110. for (int i = threads.size(); --i >= 0;)
  12111. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12112. ++numRunning;
  12113. if (numRunning < threads.size())
  12114. {
  12115. bool startedOne = false;
  12116. int n = 1000;
  12117. while (--n >= 0 && ! startedOne)
  12118. {
  12119. for (int i = threads.size(); --i >= 0;)
  12120. {
  12121. if (! threads.getUnchecked(i)->isThreadRunning())
  12122. {
  12123. threads.getUnchecked(i)->startThread (priority);
  12124. startedOne = true;
  12125. break;
  12126. }
  12127. }
  12128. if (! startedOne)
  12129. Thread::sleep (2);
  12130. }
  12131. }
  12132. }
  12133. for (int i = threads.size(); --i >= 0;)
  12134. threads.getUnchecked(i)->notify();
  12135. }
  12136. }
  12137. int ThreadPool::getNumJobs() const
  12138. {
  12139. return jobs.size();
  12140. }
  12141. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12142. {
  12143. const ScopedLock sl (lock);
  12144. return jobs [index];
  12145. }
  12146. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12147. {
  12148. const ScopedLock sl (lock);
  12149. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12150. }
  12151. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12152. {
  12153. const ScopedLock sl (lock);
  12154. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12155. }
  12156. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12157. const int timeOutMs) const
  12158. {
  12159. if (job != 0)
  12160. {
  12161. const uint32 start = Time::getMillisecondCounter();
  12162. while (contains (job))
  12163. {
  12164. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12165. return false;
  12166. jobFinishedSignal.wait (2);
  12167. }
  12168. }
  12169. return true;
  12170. }
  12171. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12172. const bool interruptIfRunning,
  12173. const int timeOutMs)
  12174. {
  12175. bool dontWait = true;
  12176. if (job != 0)
  12177. {
  12178. const ScopedLock sl (lock);
  12179. if (jobs.contains (job))
  12180. {
  12181. if (job->isActive)
  12182. {
  12183. if (interruptIfRunning)
  12184. job->signalJobShouldExit();
  12185. dontWait = false;
  12186. }
  12187. else
  12188. {
  12189. jobs.removeValue (job);
  12190. }
  12191. }
  12192. }
  12193. return dontWait || waitForJobToFinish (job, timeOutMs);
  12194. }
  12195. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12196. const int timeOutMs,
  12197. const bool deleteInactiveJobs,
  12198. ThreadPool::JobSelector* selectedJobsToRemove)
  12199. {
  12200. Array <ThreadPoolJob*> jobsToWaitFor;
  12201. {
  12202. const ScopedLock sl (lock);
  12203. for (int i = jobs.size(); --i >= 0;)
  12204. {
  12205. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12206. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12207. {
  12208. if (job->isActive)
  12209. {
  12210. jobsToWaitFor.add (job);
  12211. if (interruptRunningJobs)
  12212. job->signalJobShouldExit();
  12213. }
  12214. else
  12215. {
  12216. jobs.remove (i);
  12217. if (deleteInactiveJobs)
  12218. delete job;
  12219. }
  12220. }
  12221. }
  12222. }
  12223. const uint32 start = Time::getMillisecondCounter();
  12224. for (;;)
  12225. {
  12226. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12227. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12228. jobsToWaitFor.remove (i);
  12229. if (jobsToWaitFor.size() == 0)
  12230. break;
  12231. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12232. return false;
  12233. jobFinishedSignal.wait (20);
  12234. }
  12235. return true;
  12236. }
  12237. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12238. {
  12239. StringArray s;
  12240. const ScopedLock sl (lock);
  12241. for (int i = 0; i < jobs.size(); ++i)
  12242. {
  12243. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12244. if (job->isActive || ! onlyReturnActiveJobs)
  12245. s.add (job->getJobName());
  12246. }
  12247. return s;
  12248. }
  12249. bool ThreadPool::setThreadPriorities (const int newPriority)
  12250. {
  12251. bool ok = true;
  12252. if (priority != newPriority)
  12253. {
  12254. priority = newPriority;
  12255. for (int i = threads.size(); --i >= 0;)
  12256. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12257. ok = false;
  12258. }
  12259. return ok;
  12260. }
  12261. bool ThreadPool::runNextJob()
  12262. {
  12263. ThreadPoolJob* job = 0;
  12264. {
  12265. const ScopedLock sl (lock);
  12266. for (int i = 0; i < jobs.size(); ++i)
  12267. {
  12268. job = jobs[i];
  12269. if (job != 0 && ! (job->isActive || job->shouldStop))
  12270. break;
  12271. job = 0;
  12272. }
  12273. if (job != 0)
  12274. job->isActive = true;
  12275. }
  12276. if (job != 0)
  12277. {
  12278. JUCE_TRY
  12279. {
  12280. ThreadPoolJob::JobStatus result = job->runJob();
  12281. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12282. const ScopedLock sl (lock);
  12283. if (jobs.contains (job))
  12284. {
  12285. job->isActive = false;
  12286. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12287. {
  12288. job->pool = 0;
  12289. job->shouldStop = true;
  12290. jobs.removeValue (job);
  12291. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12292. delete job;
  12293. jobFinishedSignal.signal();
  12294. }
  12295. else
  12296. {
  12297. // move the job to the end of the queue if it wants another go
  12298. jobs.move (jobs.indexOf (job), -1);
  12299. }
  12300. }
  12301. }
  12302. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12303. catch (...)
  12304. {
  12305. const ScopedLock sl (lock);
  12306. jobs.removeValue (job);
  12307. }
  12308. #endif
  12309. }
  12310. else
  12311. {
  12312. if (threadStopTimeout > 0
  12313. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12314. {
  12315. const ScopedLock sl (lock);
  12316. if (jobs.size() == 0)
  12317. for (int i = threads.size(); --i >= 0;)
  12318. threads.getUnchecked(i)->signalThreadShouldExit();
  12319. }
  12320. else
  12321. {
  12322. return false;
  12323. }
  12324. }
  12325. return true;
  12326. }
  12327. END_JUCE_NAMESPACE
  12328. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12329. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12330. BEGIN_JUCE_NAMESPACE
  12331. TimeSliceThread::TimeSliceThread (const String& threadName)
  12332. : Thread (threadName),
  12333. index (0),
  12334. clientBeingCalled (0),
  12335. clientsChanged (false)
  12336. {
  12337. }
  12338. TimeSliceThread::~TimeSliceThread()
  12339. {
  12340. stopThread (2000);
  12341. }
  12342. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12343. {
  12344. const ScopedLock sl (listLock);
  12345. clients.addIfNotAlreadyThere (client);
  12346. clientsChanged = true;
  12347. notify();
  12348. }
  12349. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12350. {
  12351. const ScopedLock sl1 (listLock);
  12352. clientsChanged = true;
  12353. // if there's a chance we're in the middle of calling this client, we need to
  12354. // also lock the outer lock..
  12355. if (clientBeingCalled == client)
  12356. {
  12357. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12358. const ScopedLock sl2 (callbackLock);
  12359. const ScopedLock sl3 (listLock);
  12360. clients.removeValue (client);
  12361. }
  12362. else
  12363. {
  12364. clients.removeValue (client);
  12365. }
  12366. }
  12367. int TimeSliceThread::getNumClients() const
  12368. {
  12369. return clients.size();
  12370. }
  12371. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12372. {
  12373. const ScopedLock sl (listLock);
  12374. return clients [i];
  12375. }
  12376. void TimeSliceThread::run()
  12377. {
  12378. int numCallsSinceBusy = 0;
  12379. while (! threadShouldExit())
  12380. {
  12381. int timeToWait = 500;
  12382. {
  12383. const ScopedLock sl (callbackLock);
  12384. {
  12385. const ScopedLock sl2 (listLock);
  12386. if (clients.size() > 0)
  12387. {
  12388. index = (index + 1) % clients.size();
  12389. clientBeingCalled = clients [index];
  12390. }
  12391. else
  12392. {
  12393. index = 0;
  12394. clientBeingCalled = 0;
  12395. }
  12396. if (clientsChanged)
  12397. {
  12398. clientsChanged = false;
  12399. numCallsSinceBusy = 0;
  12400. }
  12401. }
  12402. if (clientBeingCalled != 0)
  12403. {
  12404. if (clientBeingCalled->useTimeSlice())
  12405. numCallsSinceBusy = 0;
  12406. else
  12407. ++numCallsSinceBusy;
  12408. if (numCallsSinceBusy >= clients.size())
  12409. timeToWait = 500;
  12410. else if (index == 0)
  12411. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12412. else
  12413. timeToWait = 0;
  12414. }
  12415. }
  12416. if (timeToWait > 0)
  12417. wait (timeToWait);
  12418. }
  12419. }
  12420. END_JUCE_NAMESPACE
  12421. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12422. #endif
  12423. #if JUCE_BUILD_MISC
  12424. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12425. BEGIN_JUCE_NAMESPACE
  12426. class ValueTree::SetPropertyAction : public UndoableAction
  12427. {
  12428. public:
  12429. SetPropertyAction (const SharedObjectPtr& target_, const var::identifier& name_,
  12430. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12431. : target (target_), name (name_), newValue (newValue_),
  12432. isAddingNewProperty (isAddingNewProperty_),
  12433. isDeletingProperty (isDeletingProperty_)
  12434. {
  12435. if (! isAddingNewProperty)
  12436. oldValue = target_->getProperty (name_);
  12437. }
  12438. ~SetPropertyAction() {}
  12439. bool perform()
  12440. {
  12441. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12442. if (isDeletingProperty)
  12443. target->removeProperty (name, 0);
  12444. else
  12445. target->setProperty (name, newValue, 0);
  12446. return true;
  12447. }
  12448. bool undo()
  12449. {
  12450. if (isAddingNewProperty)
  12451. target->removeProperty (name, 0);
  12452. else
  12453. target->setProperty (name, oldValue, 0);
  12454. return true;
  12455. }
  12456. int getSizeInUnits()
  12457. {
  12458. return (int) sizeof (*this); //xxx should be more accurate
  12459. }
  12460. private:
  12461. const SharedObjectPtr target;
  12462. const var::identifier name;
  12463. const var newValue;
  12464. var oldValue;
  12465. const bool isAddingNewProperty, isDeletingProperty;
  12466. SetPropertyAction (const SetPropertyAction&);
  12467. SetPropertyAction& operator= (const SetPropertyAction&);
  12468. };
  12469. class ValueTree::AddOrRemoveChildAction : public UndoableAction
  12470. {
  12471. public:
  12472. AddOrRemoveChildAction (const SharedObjectPtr& target_, const int childIndex_,
  12473. const SharedObjectPtr& newChild_)
  12474. : target (target_),
  12475. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12476. childIndex (childIndex_),
  12477. isDeleting (newChild_ == 0)
  12478. {
  12479. jassert (child != 0);
  12480. }
  12481. ~AddOrRemoveChildAction() {}
  12482. bool perform()
  12483. {
  12484. if (isDeleting)
  12485. target->removeChild (childIndex, 0);
  12486. else
  12487. target->addChild (child, childIndex, 0);
  12488. return true;
  12489. }
  12490. bool undo()
  12491. {
  12492. if (isDeleting)
  12493. {
  12494. target->addChild (child, childIndex, 0);
  12495. }
  12496. else
  12497. {
  12498. // If you hit this, it seems that your object's state is getting confused - probably
  12499. // because you've interleaved some undoable and non-undoable operations?
  12500. jassert (childIndex < target->children.size());
  12501. target->removeChild (childIndex, 0);
  12502. }
  12503. return true;
  12504. }
  12505. int getSizeInUnits()
  12506. {
  12507. return (int) sizeof (*this); //xxx should be more accurate
  12508. }
  12509. private:
  12510. const SharedObjectPtr target, child;
  12511. const int childIndex;
  12512. const bool isDeleting;
  12513. AddOrRemoveChildAction (const AddOrRemoveChildAction&);
  12514. AddOrRemoveChildAction& operator= (const AddOrRemoveChildAction&);
  12515. };
  12516. class ValueTree::MoveChildAction : public UndoableAction
  12517. {
  12518. public:
  12519. MoveChildAction (const SharedObjectPtr& target_,
  12520. const int startIndex_, const int endIndex_)
  12521. : target (target_),
  12522. startIndex (startIndex_),
  12523. endIndex (endIndex_)
  12524. {
  12525. }
  12526. ~MoveChildAction() {}
  12527. bool perform()
  12528. {
  12529. target->moveChild (startIndex, endIndex, 0);
  12530. return true;
  12531. }
  12532. bool undo()
  12533. {
  12534. target->moveChild (endIndex, startIndex, 0);
  12535. return true;
  12536. }
  12537. int getSizeInUnits()
  12538. {
  12539. return (int) sizeof (*this); //xxx should be more accurate
  12540. }
  12541. private:
  12542. const SharedObjectPtr target, child;
  12543. const int startIndex, endIndex;
  12544. MoveChildAction (const MoveChildAction&);
  12545. MoveChildAction& operator= (const MoveChildAction&);
  12546. };
  12547. ValueTree::SharedObject::SharedObject (const String& type_)
  12548. : type (type_), parent (0)
  12549. {
  12550. }
  12551. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12552. : type (other.type), properties (other.properties), parent (0)
  12553. {
  12554. for (int i = 0; i < other.children.size(); ++i)
  12555. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12556. }
  12557. ValueTree::SharedObject::~SharedObject()
  12558. {
  12559. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12560. for (int i = children.size(); --i >= 0;)
  12561. {
  12562. const SharedObjectPtr c (children.getUnchecked(i));
  12563. c->parent = 0;
  12564. children.remove (i);
  12565. c->sendParentChangeMessage();
  12566. }
  12567. }
  12568. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12569. {
  12570. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12571. {
  12572. ValueTree* const v = valueTreesWithListeners[i];
  12573. if (v != 0)
  12574. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12575. }
  12576. }
  12577. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12578. {
  12579. ValueTree tree (this);
  12580. ValueTree::SharedObject* t = this;
  12581. while (t != 0)
  12582. {
  12583. t->sendPropertyChangeMessage (tree, property);
  12584. t = t->parent;
  12585. }
  12586. }
  12587. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12588. {
  12589. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12590. {
  12591. ValueTree* const v = valueTreesWithListeners[i];
  12592. if (v != 0)
  12593. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12594. }
  12595. }
  12596. void ValueTree::SharedObject::sendChildChangeMessage()
  12597. {
  12598. ValueTree tree (this);
  12599. ValueTree::SharedObject* t = this;
  12600. while (t != 0)
  12601. {
  12602. t->sendChildChangeMessage (tree);
  12603. t = t->parent;
  12604. }
  12605. }
  12606. void ValueTree::SharedObject::sendParentChangeMessage()
  12607. {
  12608. ValueTree tree (this);
  12609. int i;
  12610. for (i = children.size(); --i >= 0;)
  12611. {
  12612. SharedObject* const t = children[i];
  12613. if (t != 0)
  12614. t->sendParentChangeMessage();
  12615. }
  12616. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12617. {
  12618. ValueTree* const v = valueTreesWithListeners[i];
  12619. if (v != 0)
  12620. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12621. }
  12622. }
  12623. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12624. {
  12625. return properties [name];
  12626. }
  12627. const var ValueTree::SharedObject::getProperty (const var::identifier& name, const var& defaultReturnValue) const
  12628. {
  12629. return properties.getWithDefault (name, defaultReturnValue);
  12630. }
  12631. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12632. {
  12633. if (undoManager == 0)
  12634. {
  12635. if (properties.set (name, newValue))
  12636. sendPropertyChangeMessage (name);
  12637. }
  12638. else
  12639. {
  12640. var* const existingValue = properties.getItem (name);
  12641. if (existingValue != 0)
  12642. {
  12643. if (*existingValue != newValue)
  12644. undoManager->perform (new SetPropertyAction (this, name, newValue, false, false));
  12645. }
  12646. else
  12647. {
  12648. undoManager->perform (new SetPropertyAction (this, name, newValue, true, false));
  12649. }
  12650. }
  12651. }
  12652. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  12653. {
  12654. return properties.contains (name);
  12655. }
  12656. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12657. {
  12658. if (undoManager == 0)
  12659. {
  12660. if (properties.remove (name))
  12661. sendPropertyChangeMessage (name);
  12662. }
  12663. else
  12664. {
  12665. if (properties.contains (name))
  12666. undoManager->perform (new SetPropertyAction (this, name, var::null, false, true));
  12667. }
  12668. }
  12669. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  12670. {
  12671. if (undoManager == 0)
  12672. {
  12673. while (properties.size() > 0)
  12674. {
  12675. const var::identifier name (properties.getName (properties.size() - 1));
  12676. properties.remove (name);
  12677. sendPropertyChangeMessage (name);
  12678. }
  12679. }
  12680. else
  12681. {
  12682. for (int i = properties.size(); --i >= 0;)
  12683. undoManager->perform (new SetPropertyAction (this, properties.getName(i), var::null, false, true));
  12684. }
  12685. }
  12686. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  12687. {
  12688. for (int i = 0; i < children.size(); ++i)
  12689. if (children.getUnchecked(i)->type == typeToMatch)
  12690. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12691. return ValueTree::invalid;
  12692. }
  12693. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12694. {
  12695. for (int i = 0; i < children.size(); ++i)
  12696. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  12697. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12698. return ValueTree::invalid;
  12699. }
  12700. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  12701. {
  12702. const SharedObject* p = parent;
  12703. while (p != 0)
  12704. {
  12705. if (p == possibleParent)
  12706. return true;
  12707. p = p->parent;
  12708. }
  12709. return false;
  12710. }
  12711. int ValueTree::SharedObject::indexOf (const ValueTree& child) const
  12712. {
  12713. return children.indexOf (child.object);
  12714. }
  12715. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  12716. {
  12717. if (child != 0 && child->parent != this)
  12718. {
  12719. if (child != this && ! isAChildOf (child))
  12720. {
  12721. // You should always make sure that a child is removed from its previous parent before
  12722. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  12723. // undomanager should be used when removing it from its current parent..
  12724. jassert (child->parent == 0);
  12725. if (child->parent != 0)
  12726. {
  12727. jassert (child->parent->children.indexOf (child) >= 0);
  12728. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  12729. }
  12730. if (undoManager == 0)
  12731. {
  12732. children.insert (index, child);
  12733. child->parent = this;
  12734. sendChildChangeMessage();
  12735. child->sendParentChangeMessage();
  12736. }
  12737. else
  12738. {
  12739. if (index < 0)
  12740. index = children.size();
  12741. undoManager->perform (new AddOrRemoveChildAction (this, index, child));
  12742. }
  12743. }
  12744. else
  12745. {
  12746. // You're attempting to create a recursive loop! A node
  12747. // can't be a child of one of its own children!
  12748. jassertfalse
  12749. }
  12750. }
  12751. }
  12752. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  12753. {
  12754. const SharedObjectPtr child (children [childIndex]);
  12755. if (child != 0)
  12756. {
  12757. if (undoManager == 0)
  12758. {
  12759. children.remove (childIndex);
  12760. child->parent = 0;
  12761. sendChildChangeMessage();
  12762. child->sendParentChangeMessage();
  12763. }
  12764. else
  12765. {
  12766. undoManager->perform (new AddOrRemoveChildAction (this, childIndex, 0));
  12767. }
  12768. }
  12769. }
  12770. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  12771. {
  12772. while (children.size() > 0)
  12773. removeChild (children.size() - 1, undoManager);
  12774. }
  12775. void ValueTree::SharedObject::moveChild (int currentIndex, int newIndex, UndoManager* undoManager)
  12776. {
  12777. // The source index must be a valid index!
  12778. jassert (((unsigned int) currentIndex) < (unsigned int) children.size());
  12779. if (currentIndex != newIndex
  12780. && ((unsigned int) currentIndex) < (unsigned int) children.size())
  12781. {
  12782. if (undoManager == 0)
  12783. {
  12784. children.move (currentIndex, newIndex);
  12785. sendChildChangeMessage();
  12786. }
  12787. else
  12788. {
  12789. if (((unsigned int) newIndex) >= (unsigned int) children.size())
  12790. newIndex = children.size() - 1;
  12791. undoManager->perform (new MoveChildAction (this, currentIndex, newIndex));
  12792. }
  12793. }
  12794. }
  12795. ValueTree::ValueTree() throw()
  12796. : object (0)
  12797. {
  12798. }
  12799. const ValueTree ValueTree::invalid;
  12800. ValueTree::ValueTree (const String& type_)
  12801. : object (new ValueTree::SharedObject (type_))
  12802. {
  12803. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  12804. }
  12805. ValueTree::ValueTree (SharedObject* const object_)
  12806. : object (object_)
  12807. {
  12808. }
  12809. ValueTree::ValueTree (const ValueTree& other)
  12810. : object (other.object)
  12811. {
  12812. }
  12813. ValueTree& ValueTree::operator= (const ValueTree& other)
  12814. {
  12815. if (listeners.size() > 0)
  12816. {
  12817. if (object != 0)
  12818. object->valueTreesWithListeners.removeValue (this);
  12819. if (other.object != 0)
  12820. other.object->valueTreesWithListeners.add (this);
  12821. }
  12822. object = other.object;
  12823. return *this;
  12824. }
  12825. ValueTree::~ValueTree()
  12826. {
  12827. if (listeners.size() > 0 && object != 0)
  12828. object->valueTreesWithListeners.removeValue (this);
  12829. }
  12830. bool ValueTree::operator== (const ValueTree& other) const
  12831. {
  12832. return object == other.object;
  12833. }
  12834. bool ValueTree::operator!= (const ValueTree& other) const
  12835. {
  12836. return object != other.object;
  12837. }
  12838. ValueTree ValueTree::createCopy() const
  12839. {
  12840. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  12841. }
  12842. bool ValueTree::hasType (const String& typeName) const
  12843. {
  12844. return object != 0 && object->type == typeName;
  12845. }
  12846. const String ValueTree::getType() const
  12847. {
  12848. return object != 0 ? object->type : String::empty;
  12849. }
  12850. ValueTree ValueTree::getParent() const
  12851. {
  12852. return ValueTree (object != 0 ? object->parent : (SharedObject*) 0);
  12853. }
  12854. const var& ValueTree::operator[] (const var::identifier& name) const
  12855. {
  12856. return object == 0 ? var::null : object->getProperty (name);
  12857. }
  12858. const var& ValueTree::getProperty (const var::identifier& name) const
  12859. {
  12860. return object == 0 ? var::null : object->getProperty (name);
  12861. }
  12862. const var ValueTree::getProperty (const var::identifier& name, const var& defaultReturnValue) const
  12863. {
  12864. return object == 0 ? defaultReturnValue : object->getProperty (name, defaultReturnValue);
  12865. }
  12866. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12867. {
  12868. jassert (name.name.isNotEmpty());
  12869. if (object != 0 && name.name.isNotEmpty())
  12870. object->setProperty (name, newValue, undoManager);
  12871. }
  12872. bool ValueTree::hasProperty (const var::identifier& name) const
  12873. {
  12874. return object != 0 && object->hasProperty (name);
  12875. }
  12876. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12877. {
  12878. if (object != 0)
  12879. object->removeProperty (name, undoManager);
  12880. }
  12881. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  12882. {
  12883. if (object != 0)
  12884. object->removeAllProperties (undoManager);
  12885. }
  12886. int ValueTree::getNumProperties() const
  12887. {
  12888. return object == 0 ? 0 : object->properties.size();
  12889. }
  12890. const var::identifier ValueTree::getPropertyName (const int index) const
  12891. {
  12892. return object == 0 ? var::identifier()
  12893. : object->properties.getName (index);
  12894. }
  12895. class ValueTreePropertyValueSource : public Value::ValueSource,
  12896. public ValueTree::Listener
  12897. {
  12898. public:
  12899. ValueTreePropertyValueSource (const ValueTree& tree_,
  12900. const var::identifier& property_,
  12901. UndoManager* const undoManager_)
  12902. : tree (tree_),
  12903. property (property_),
  12904. undoManager (undoManager_)
  12905. {
  12906. tree.addListener (this);
  12907. }
  12908. ~ValueTreePropertyValueSource()
  12909. {
  12910. tree.removeListener (this);
  12911. }
  12912. const var getValue() const
  12913. {
  12914. return tree [property];
  12915. }
  12916. void setValue (const var& newValue)
  12917. {
  12918. tree.setProperty (property, newValue, undoManager);
  12919. }
  12920. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  12921. {
  12922. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  12923. sendChangeMessage (false);
  12924. }
  12925. void valueTreeChildrenChanged (ValueTree&) {}
  12926. void valueTreeParentChanged (ValueTree&) {}
  12927. private:
  12928. ValueTree tree;
  12929. const var::identifier property;
  12930. UndoManager* const undoManager;
  12931. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  12932. };
  12933. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  12934. {
  12935. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  12936. }
  12937. int ValueTree::getNumChildren() const
  12938. {
  12939. return object == 0 ? 0 : object->children.size();
  12940. }
  12941. ValueTree ValueTree::getChild (int index) const
  12942. {
  12943. return ValueTree (object != 0 ? (SharedObject*) object->children [index] : (SharedObject*) 0);
  12944. }
  12945. ValueTree ValueTree::getChildWithName (const String& type) const
  12946. {
  12947. return object != 0 ? object->getChildWithName (type) : ValueTree::invalid;
  12948. }
  12949. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12950. {
  12951. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree::invalid;
  12952. }
  12953. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  12954. {
  12955. return object != 0 && object->isAChildOf (possibleParent.object);
  12956. }
  12957. int ValueTree::indexOf (const ValueTree& child) const
  12958. {
  12959. return object != 0 ? object->indexOf (child) : -1;
  12960. }
  12961. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  12962. {
  12963. if (object != 0)
  12964. object->addChild (child.object, index, undoManager);
  12965. }
  12966. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  12967. {
  12968. if (object != 0)
  12969. object->removeChild (childIndex, undoManager);
  12970. }
  12971. void ValueTree::removeChild (const ValueTree& child, UndoManager* const undoManager)
  12972. {
  12973. if (object != 0)
  12974. object->removeChild (object->children.indexOf (child.object), undoManager);
  12975. }
  12976. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  12977. {
  12978. if (object != 0)
  12979. object->removeAllChildren (undoManager);
  12980. }
  12981. void ValueTree::moveChild (int currentIndex, int newIndex, UndoManager* undoManager)
  12982. {
  12983. if (object != 0)
  12984. object->moveChild (currentIndex, newIndex, undoManager);
  12985. }
  12986. void ValueTree::addListener (Listener* listener)
  12987. {
  12988. if (listener != 0)
  12989. {
  12990. if (listeners.size() == 0 && object != 0)
  12991. object->valueTreesWithListeners.add (this);
  12992. listeners.add (listener);
  12993. }
  12994. }
  12995. void ValueTree::removeListener (Listener* listener)
  12996. {
  12997. listeners.remove (listener);
  12998. if (listeners.size() == 0 && object != 0)
  12999. object->valueTreesWithListeners.removeValue (this);
  13000. }
  13001. XmlElement* ValueTree::SharedObject::createXml() const
  13002. {
  13003. XmlElement* xml = new XmlElement (type);
  13004. int i;
  13005. for (i = 0; i < properties.size(); ++i)
  13006. {
  13007. var::identifier name (properties.getName(i));
  13008. const var& v = properties [name];
  13009. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13010. xml->setAttribute (name.name, v.toString());
  13011. }
  13012. for (i = 0; i < children.size(); ++i)
  13013. xml->addChildElement (children.getUnchecked(i)->createXml());
  13014. return xml;
  13015. }
  13016. XmlElement* ValueTree::createXml() const
  13017. {
  13018. return object != 0 ? object->createXml() : 0;
  13019. }
  13020. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13021. {
  13022. ValueTree v (xml.getTagName());
  13023. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13024. for (int i = 0; i < numAtts; ++i)
  13025. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13026. forEachXmlChildElement (xml, e)
  13027. {
  13028. v.addChild (fromXml (*e), -1, 0);
  13029. }
  13030. return v;
  13031. }
  13032. void ValueTree::writeToStream (OutputStream& output)
  13033. {
  13034. output.writeString (getType());
  13035. const int numProps = getNumProperties();
  13036. output.writeCompressedInt (numProps);
  13037. int i;
  13038. for (i = 0; i < numProps; ++i)
  13039. {
  13040. const var::identifier name (getPropertyName(i));
  13041. output.writeString (name.name);
  13042. getProperty(name).writeToStream (output);
  13043. }
  13044. const int numChildren = getNumChildren();
  13045. output.writeCompressedInt (numChildren);
  13046. for (i = 0; i < numChildren; ++i)
  13047. getChild (i).writeToStream (output);
  13048. }
  13049. ValueTree ValueTree::readFromStream (InputStream& input)
  13050. {
  13051. String type (input.readString());
  13052. if (type.isEmpty())
  13053. return ValueTree::invalid;
  13054. ValueTree v (type);
  13055. const int numProps = input.readCompressedInt();
  13056. if (numProps < 0)
  13057. {
  13058. jassertfalse // trying to read corrupted data!
  13059. return v;
  13060. }
  13061. int i;
  13062. for (i = 0; i < numProps; ++i)
  13063. {
  13064. const String name (input.readString());
  13065. jassert (name.isNotEmpty());
  13066. const var value (var::readFromStream (input));
  13067. v.setProperty (name, value, 0);
  13068. }
  13069. const int numChildren = input.readCompressedInt();
  13070. for (i = 0; i < numChildren; ++i)
  13071. v.addChild (readFromStream (input), -1, 0);
  13072. return v;
  13073. }
  13074. END_JUCE_NAMESPACE
  13075. /*** End of inlined file: juce_ValueTree.cpp ***/
  13076. /*** Start of inlined file: juce_Value.cpp ***/
  13077. BEGIN_JUCE_NAMESPACE
  13078. Value::ValueSource::ValueSource()
  13079. {
  13080. }
  13081. Value::ValueSource::~ValueSource()
  13082. {
  13083. }
  13084. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13085. {
  13086. if (synchronous)
  13087. {
  13088. for (int i = valuesWithListeners.size(); --i >= 0;)
  13089. {
  13090. Value* const v = valuesWithListeners[i];
  13091. if (v != 0)
  13092. v->callListeners();
  13093. }
  13094. }
  13095. else
  13096. {
  13097. triggerAsyncUpdate();
  13098. }
  13099. }
  13100. void Value::ValueSource::handleAsyncUpdate()
  13101. {
  13102. sendChangeMessage (true);
  13103. }
  13104. class SimpleValueSource : public Value::ValueSource
  13105. {
  13106. public:
  13107. SimpleValueSource()
  13108. {
  13109. }
  13110. SimpleValueSource (const var& initialValue)
  13111. : value (initialValue)
  13112. {
  13113. }
  13114. ~SimpleValueSource()
  13115. {
  13116. }
  13117. const var getValue() const
  13118. {
  13119. return value;
  13120. }
  13121. void setValue (const var& newValue)
  13122. {
  13123. if (newValue != value)
  13124. {
  13125. value = newValue;
  13126. sendChangeMessage (false);
  13127. }
  13128. }
  13129. private:
  13130. var value;
  13131. SimpleValueSource (const SimpleValueSource&);
  13132. SimpleValueSource& operator= (const SimpleValueSource&);
  13133. };
  13134. Value::Value()
  13135. : value (new SimpleValueSource())
  13136. {
  13137. }
  13138. Value::Value (ValueSource* const value_)
  13139. : value (value_)
  13140. {
  13141. jassert (value_ != 0);
  13142. }
  13143. Value::Value (const var& initialValue)
  13144. : value (new SimpleValueSource (initialValue))
  13145. {
  13146. }
  13147. Value::Value (const Value& other)
  13148. : value (other.value)
  13149. {
  13150. }
  13151. Value& Value::operator= (const Value& other)
  13152. {
  13153. value = other.value;
  13154. return *this;
  13155. }
  13156. Value::~Value()
  13157. {
  13158. if (listeners.size() > 0)
  13159. value->valuesWithListeners.removeValue (this);
  13160. }
  13161. const var Value::getValue() const
  13162. {
  13163. return value->getValue();
  13164. }
  13165. Value::operator const var() const
  13166. {
  13167. return getValue();
  13168. }
  13169. void Value::setValue (const var& newValue)
  13170. {
  13171. value->setValue (newValue);
  13172. }
  13173. const String Value::toString() const
  13174. {
  13175. return value->getValue().toString();
  13176. }
  13177. Value& Value::operator= (const var& newValue)
  13178. {
  13179. value->setValue (newValue);
  13180. return *this;
  13181. }
  13182. void Value::referTo (const Value& valueToReferTo)
  13183. {
  13184. if (valueToReferTo.value != value)
  13185. {
  13186. if (listeners.size() > 0)
  13187. {
  13188. value->valuesWithListeners.removeValue (this);
  13189. valueToReferTo.value->valuesWithListeners.add (this);
  13190. }
  13191. value = valueToReferTo.value;
  13192. callListeners();
  13193. }
  13194. }
  13195. bool Value::refersToSameSourceAs (const Value& other) const
  13196. {
  13197. return value == other.value;
  13198. }
  13199. bool Value::operator== (const Value& other) const
  13200. {
  13201. return value == other.value || value->getValue() == other.getValue();
  13202. }
  13203. bool Value::operator!= (const Value& other) const
  13204. {
  13205. return value != other.value && value->getValue() != other.getValue();
  13206. }
  13207. void Value::addListener (Listener* const listener)
  13208. {
  13209. if (listener != 0)
  13210. {
  13211. if (listeners.size() == 0)
  13212. value->valuesWithListeners.add (this);
  13213. listeners.add (listener);
  13214. }
  13215. }
  13216. void Value::removeListener (Listener* const listener)
  13217. {
  13218. listeners.remove (listener);
  13219. if (listeners.size() == 0)
  13220. value->valuesWithListeners.removeValue (this);
  13221. }
  13222. void Value::callListeners()
  13223. {
  13224. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13225. listeners.call (&Listener::valueChanged, v);
  13226. }
  13227. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const Value& value)
  13228. {
  13229. return stream << value.toString();
  13230. }
  13231. END_JUCE_NAMESPACE
  13232. /*** End of inlined file: juce_Value.cpp ***/
  13233. /*** Start of inlined file: juce_Application.cpp ***/
  13234. #if JUCE_MSVC
  13235. #pragma warning (push)
  13236. #pragma warning (disable: 4245 4514 4100)
  13237. #include <crtdbg.h>
  13238. #pragma warning (pop)
  13239. #endif
  13240. BEGIN_JUCE_NAMESPACE
  13241. void juce_setCurrentThreadName (const String& name);
  13242. static JUCEApplication* appInstance = 0;
  13243. JUCEApplication::JUCEApplication()
  13244. : appReturnValue (0),
  13245. stillInitialising (true)
  13246. {
  13247. }
  13248. JUCEApplication::~JUCEApplication()
  13249. {
  13250. if (appLock != 0)
  13251. {
  13252. appLock->exit();
  13253. appLock = 0;
  13254. }
  13255. }
  13256. JUCEApplication* JUCEApplication::getInstance() throw()
  13257. {
  13258. return appInstance;
  13259. }
  13260. bool JUCEApplication::isInitialising() const throw()
  13261. {
  13262. return stillInitialising;
  13263. }
  13264. const String JUCEApplication::getApplicationVersion()
  13265. {
  13266. return String::empty;
  13267. }
  13268. bool JUCEApplication::moreThanOneInstanceAllowed()
  13269. {
  13270. return true;
  13271. }
  13272. void JUCEApplication::anotherInstanceStarted (const String&)
  13273. {
  13274. }
  13275. void JUCEApplication::systemRequestedQuit()
  13276. {
  13277. quit();
  13278. }
  13279. void JUCEApplication::quit()
  13280. {
  13281. MessageManager::getInstance()->stopDispatchLoop();
  13282. }
  13283. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13284. {
  13285. appReturnValue = newReturnValue;
  13286. }
  13287. void JUCEApplication::unhandledException (const std::exception*,
  13288. const String&,
  13289. const int)
  13290. {
  13291. jassertfalse
  13292. }
  13293. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13294. const char* const sourceFile,
  13295. const int lineNumber)
  13296. {
  13297. if (appInstance != 0)
  13298. appInstance->unhandledException (e, sourceFile, lineNumber);
  13299. }
  13300. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13301. {
  13302. return 0;
  13303. }
  13304. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13305. {
  13306. commands.add (StandardApplicationCommandIDs::quit);
  13307. }
  13308. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13309. {
  13310. if (commandID == StandardApplicationCommandIDs::quit)
  13311. {
  13312. result.setInfo (TRANS("Quit"),
  13313. TRANS("Quits the application"),
  13314. "Application",
  13315. 0);
  13316. result.defaultKeypresses.add (KeyPress ('q', ModifierKeys::commandModifier, 0));
  13317. }
  13318. }
  13319. bool JUCEApplication::perform (const InvocationInfo& info)
  13320. {
  13321. if (info.commandID == StandardApplicationCommandIDs::quit)
  13322. {
  13323. systemRequestedQuit();
  13324. return true;
  13325. }
  13326. return false;
  13327. }
  13328. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13329. {
  13330. if (! app->initialiseApp (commandLine))
  13331. return 0;
  13332. // now loop until a quit message is received..
  13333. JUCE_TRY
  13334. {
  13335. MessageManager::getInstance()->runDispatchLoop();
  13336. }
  13337. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13338. catch (const std::exception& e)
  13339. {
  13340. app->unhandledException (&e, __FILE__, __LINE__);
  13341. }
  13342. catch (...)
  13343. {
  13344. app->unhandledException (0, __FILE__, __LINE__);
  13345. }
  13346. #endif
  13347. return shutdownAppAndClearUp();
  13348. }
  13349. bool JUCEApplication::initialiseApp (String& commandLine)
  13350. {
  13351. jassert (appInstance == 0);
  13352. appInstance = this;
  13353. commandLineParameters = commandLine.trim();
  13354. commandLine = String::empty;
  13355. initialiseJuce_GUI();
  13356. #if ! JUCE_IPHONE
  13357. jassert (appLock == 0); // initialiseApp must only be called once!
  13358. if (! moreThanOneInstanceAllowed())
  13359. {
  13360. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13361. if (! appLock->enter(0))
  13362. {
  13363. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13364. delete appInstance;
  13365. appInstance = 0;
  13366. DBG ("Another instance is running - quitting...");
  13367. return false;
  13368. }
  13369. }
  13370. #endif
  13371. // let the app do its setting-up..
  13372. initialise (commandLineParameters);
  13373. // register for broadcast new app messages
  13374. MessageManager::getInstance()->registerBroadcastListener (this);
  13375. stillInitialising = false;
  13376. return true;
  13377. }
  13378. int JUCEApplication::shutdownAppAndClearUp()
  13379. {
  13380. jassert (appInstance != 0);
  13381. ScopedPointer<JUCEApplication> app (appInstance);
  13382. int returnValue = 0;
  13383. MessageManager::getInstance()->deregisterBroadcastListener (static_cast <JUCEApplication*> (app));
  13384. static bool reentrancyCheck = false;
  13385. if (! reentrancyCheck)
  13386. {
  13387. reentrancyCheck = true;
  13388. JUCE_TRY
  13389. {
  13390. // give the app a chance to clean up..
  13391. app->shutdown();
  13392. }
  13393. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13394. catch (const std::exception& e)
  13395. {
  13396. app->unhandledException (&e, __FILE__, __LINE__);
  13397. }
  13398. catch (...)
  13399. {
  13400. app->unhandledException (0, __FILE__, __LINE__);
  13401. }
  13402. #endif
  13403. JUCE_TRY
  13404. {
  13405. shutdownJuce_GUI();
  13406. returnValue = app->getApplicationReturnValue();
  13407. appInstance = 0;
  13408. app = 0;
  13409. }
  13410. JUCE_CATCH_ALL_ASSERT
  13411. reentrancyCheck = false;
  13412. }
  13413. return returnValue;
  13414. }
  13415. #if JUCE_IPHONE
  13416. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13417. #endif
  13418. #if ! JUCE_WINDOWS
  13419. extern const char* juce_Argv0;
  13420. #endif
  13421. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13422. {
  13423. #if ! JUCE_WINDOWS
  13424. juce_Argv0 = argv[0];
  13425. #endif
  13426. #if JUCE_IPHONE
  13427. const ScopedAutoReleasePool pool;
  13428. return juce_IPhoneMain (argc, argv, newApp);
  13429. #else
  13430. #if JUCE_MAC
  13431. const ScopedAutoReleasePool pool;
  13432. #endif
  13433. String cmd;
  13434. for (int i = 1; i < argc; ++i)
  13435. cmd << argv[i] << ' ';
  13436. return JUCEApplication::main (cmd, newApp);
  13437. #endif
  13438. }
  13439. void JUCEApplication::actionListenerCallback (const String& message)
  13440. {
  13441. if (message.startsWith (getApplicationName() + "/"))
  13442. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13443. }
  13444. static bool juceInitialisedGUI = false;
  13445. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13446. {
  13447. if (! juceInitialisedGUI)
  13448. {
  13449. #if JUCE_MAC || JUCE_IPHONE
  13450. const ScopedAutoReleasePool pool;
  13451. #endif
  13452. juceInitialisedGUI = true;
  13453. initialiseJuce_NonGUI();
  13454. MessageManager::getInstance();
  13455. LookAndFeel::setDefaultLookAndFeel (0);
  13456. juce_setCurrentThreadName ("Juce Message Thread");
  13457. #if JUCE_WINDOWS && JUCE_DEBUG
  13458. // This section is just for catching people who mess up their project settings and
  13459. // turn RTTI off..
  13460. try
  13461. {
  13462. TextButton tb (String::empty);
  13463. Component* c = &tb;
  13464. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13465. c = dynamic_cast <Button*> (c);
  13466. }
  13467. catch (...)
  13468. {
  13469. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13470. // got as far as this catch statement, then why haven't you got exception catching
  13471. // turned on in the debugger???
  13472. jassertfalse
  13473. }
  13474. #endif
  13475. }
  13476. }
  13477. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13478. {
  13479. if (juceInitialisedGUI)
  13480. {
  13481. #if JUCE_MAC
  13482. const ScopedAutoReleasePool pool;
  13483. #endif
  13484. {
  13485. DeletedAtShutdown::deleteAll();
  13486. LookAndFeel::clearDefaultLookAndFeel();
  13487. }
  13488. delete MessageManager::getInstance();
  13489. shutdownJuce_NonGUI();
  13490. juceInitialisedGUI = false;
  13491. }
  13492. }
  13493. END_JUCE_NAMESPACE
  13494. /*** End of inlined file: juce_Application.cpp ***/
  13495. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13496. BEGIN_JUCE_NAMESPACE
  13497. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13498. : commandID (commandID_),
  13499. flags (0)
  13500. {
  13501. }
  13502. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13503. const String& description_,
  13504. const String& categoryName_,
  13505. const int flags_) throw()
  13506. {
  13507. shortName = shortName_;
  13508. description = description_;
  13509. categoryName = categoryName_;
  13510. flags = flags_;
  13511. }
  13512. void ApplicationCommandInfo::setActive (const bool b) throw()
  13513. {
  13514. if (b)
  13515. flags &= ~isDisabled;
  13516. else
  13517. flags |= isDisabled;
  13518. }
  13519. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13520. {
  13521. if (b)
  13522. flags |= isTicked;
  13523. else
  13524. flags &= ~isTicked;
  13525. }
  13526. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13527. {
  13528. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13529. }
  13530. END_JUCE_NAMESPACE
  13531. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13532. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13533. BEGIN_JUCE_NAMESPACE
  13534. ApplicationCommandManager::ApplicationCommandManager()
  13535. : firstTarget (0)
  13536. {
  13537. keyMappings = new KeyPressMappingSet (this);
  13538. Desktop::getInstance().addFocusChangeListener (this);
  13539. }
  13540. ApplicationCommandManager::~ApplicationCommandManager()
  13541. {
  13542. Desktop::getInstance().removeFocusChangeListener (this);
  13543. keyMappings = 0;
  13544. }
  13545. void ApplicationCommandManager::clearCommands()
  13546. {
  13547. commands.clear();
  13548. keyMappings->clearAllKeyPresses();
  13549. triggerAsyncUpdate();
  13550. }
  13551. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13552. {
  13553. // zero isn't a valid command ID!
  13554. jassert (newCommand.commandID != 0);
  13555. // the name isn't optional!
  13556. jassert (newCommand.shortName.isNotEmpty());
  13557. if (getCommandForID (newCommand.commandID) == 0)
  13558. {
  13559. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13560. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13561. commands.add (newInfo);
  13562. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13563. triggerAsyncUpdate();
  13564. }
  13565. else
  13566. {
  13567. // trying to re-register the same command with different parameters?
  13568. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13569. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13570. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13571. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13572. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13573. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13574. }
  13575. }
  13576. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13577. {
  13578. if (target != 0)
  13579. {
  13580. Array <CommandID> commandIDs;
  13581. target->getAllCommands (commandIDs);
  13582. for (int i = 0; i < commandIDs.size(); ++i)
  13583. {
  13584. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13585. target->getCommandInfo (info.commandID, info);
  13586. registerCommand (info);
  13587. }
  13588. }
  13589. }
  13590. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13591. {
  13592. for (int i = commands.size(); --i >= 0;)
  13593. {
  13594. if (commands.getUnchecked (i)->commandID == commandID)
  13595. {
  13596. commands.remove (i);
  13597. triggerAsyncUpdate();
  13598. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13599. for (int j = keys.size(); --j >= 0;)
  13600. keyMappings->removeKeyPress (keys.getReference (j));
  13601. }
  13602. }
  13603. }
  13604. void ApplicationCommandManager::commandStatusChanged()
  13605. {
  13606. triggerAsyncUpdate();
  13607. }
  13608. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13609. {
  13610. for (int i = commands.size(); --i >= 0;)
  13611. if (commands.getUnchecked(i)->commandID == commandID)
  13612. return commands.getUnchecked(i);
  13613. return 0;
  13614. }
  13615. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13616. {
  13617. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13618. return (ci != 0) ? ci->shortName : String::empty;
  13619. }
  13620. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13621. {
  13622. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13623. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13624. : String::empty;
  13625. }
  13626. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13627. {
  13628. StringArray s;
  13629. for (int i = 0; i < commands.size(); ++i)
  13630. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13631. return s;
  13632. }
  13633. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13634. {
  13635. Array <CommandID> results;
  13636. for (int i = 0; i < commands.size(); ++i)
  13637. if (commands.getUnchecked(i)->categoryName == categoryName)
  13638. results.add (commands.getUnchecked(i)->commandID);
  13639. return results;
  13640. }
  13641. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13642. {
  13643. ApplicationCommandTarget::InvocationInfo info (commandID);
  13644. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13645. return invoke (info, asynchronously);
  13646. }
  13647. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13648. {
  13649. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13650. // manager first..
  13651. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13652. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13653. if (target == 0)
  13654. return false;
  13655. ApplicationCommandInfo commandInfo (0);
  13656. target->getCommandInfo (info_.commandID, commandInfo);
  13657. ApplicationCommandTarget::InvocationInfo info (info_);
  13658. info.commandFlags = commandInfo.flags;
  13659. sendListenerInvokeCallback (info);
  13660. const bool ok = target->invoke (info, asynchronously);
  13661. commandStatusChanged();
  13662. return ok;
  13663. }
  13664. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13665. {
  13666. return firstTarget != 0 ? firstTarget
  13667. : findDefaultComponentTarget();
  13668. }
  13669. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13670. {
  13671. firstTarget = newTarget;
  13672. }
  13673. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13674. ApplicationCommandInfo& upToDateInfo)
  13675. {
  13676. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13677. if (target == 0)
  13678. target = JUCEApplication::getInstance();
  13679. if (target != 0)
  13680. target = target->getTargetForCommand (commandID);
  13681. if (target != 0)
  13682. target->getCommandInfo (commandID, upToDateInfo);
  13683. return target;
  13684. }
  13685. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13686. {
  13687. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13688. if (target == 0 && c != 0)
  13689. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13690. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13691. return target;
  13692. }
  13693. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  13694. {
  13695. Component* c = Component::getCurrentlyFocusedComponent();
  13696. if (c == 0)
  13697. {
  13698. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  13699. if (activeWindow != 0)
  13700. {
  13701. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  13702. if (c == 0)
  13703. c = activeWindow;
  13704. }
  13705. }
  13706. if (c == 0 && Process::isForegroundProcess())
  13707. {
  13708. // getting a bit desperate now - try all desktop comps..
  13709. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  13710. {
  13711. ApplicationCommandTarget* const target
  13712. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  13713. ->getPeer()->getLastFocusedSubcomponent());
  13714. if (target != 0)
  13715. return target;
  13716. }
  13717. }
  13718. if (c != 0)
  13719. {
  13720. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  13721. // if we're focused on a ResizableWindow, chances are that it's the content
  13722. // component that really should get the event. And if not, the event will
  13723. // still be passed up to the top level window anyway, so let's send it to the
  13724. // content comp.
  13725. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  13726. c = resizableWindow->getContentComponent();
  13727. ApplicationCommandTarget* const target = findTargetForComponent (c);
  13728. if (target != 0)
  13729. return target;
  13730. }
  13731. return JUCEApplication::getInstance();
  13732. }
  13733. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  13734. {
  13735. listeners.add (listener);
  13736. }
  13737. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  13738. {
  13739. listeners.remove (listener);
  13740. }
  13741. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  13742. {
  13743. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  13744. }
  13745. void ApplicationCommandManager::handleAsyncUpdate()
  13746. {
  13747. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  13748. }
  13749. void ApplicationCommandManager::globalFocusChanged (Component*)
  13750. {
  13751. commandStatusChanged();
  13752. }
  13753. END_JUCE_NAMESPACE
  13754. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  13755. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13756. BEGIN_JUCE_NAMESPACE
  13757. ApplicationCommandTarget::ApplicationCommandTarget()
  13758. {
  13759. }
  13760. ApplicationCommandTarget::~ApplicationCommandTarget()
  13761. {
  13762. messageInvoker = 0;
  13763. }
  13764. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  13765. {
  13766. if (isCommandActive (info.commandID))
  13767. {
  13768. if (async)
  13769. {
  13770. if (messageInvoker == 0)
  13771. messageInvoker = new CommandTargetMessageInvoker (this);
  13772. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  13773. return true;
  13774. }
  13775. else
  13776. {
  13777. const bool success = perform (info);
  13778. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  13779. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  13780. // returns the command's info.
  13781. return success;
  13782. }
  13783. }
  13784. return false;
  13785. }
  13786. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  13787. {
  13788. Component* c = dynamic_cast <Component*> (this);
  13789. if (c != 0)
  13790. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13791. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13792. return 0;
  13793. }
  13794. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  13795. {
  13796. ApplicationCommandTarget* target = this;
  13797. int depth = 0;
  13798. while (target != 0)
  13799. {
  13800. Array <CommandID> commandIDs;
  13801. target->getAllCommands (commandIDs);
  13802. if (commandIDs.contains (commandID))
  13803. return target;
  13804. target = target->getNextCommandTarget();
  13805. ++depth;
  13806. jassert (depth < 100); // could be a recursive command chain??
  13807. jassert (target != this); // definitely a recursive command chain!
  13808. if (depth > 100 || target == this)
  13809. break;
  13810. }
  13811. if (target == 0)
  13812. {
  13813. target = JUCEApplication::getInstance();
  13814. if (target != 0)
  13815. {
  13816. Array <CommandID> commandIDs;
  13817. target->getAllCommands (commandIDs);
  13818. if (commandIDs.contains (commandID))
  13819. return target;
  13820. }
  13821. }
  13822. return 0;
  13823. }
  13824. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  13825. {
  13826. ApplicationCommandInfo info (commandID);
  13827. info.flags = ApplicationCommandInfo::isDisabled;
  13828. getCommandInfo (commandID, info);
  13829. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  13830. }
  13831. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  13832. {
  13833. ApplicationCommandTarget* target = this;
  13834. int depth = 0;
  13835. while (target != 0)
  13836. {
  13837. if (target->tryToInvoke (info, async))
  13838. return true;
  13839. target = target->getNextCommandTarget();
  13840. ++depth;
  13841. jassert (depth < 100); // could be a recursive command chain??
  13842. jassert (target != this); // definitely a recursive command chain!
  13843. if (depth > 100 || target == this)
  13844. break;
  13845. }
  13846. if (target == 0)
  13847. {
  13848. target = JUCEApplication::getInstance();
  13849. if (target != 0)
  13850. return target->tryToInvoke (info, async);
  13851. }
  13852. return false;
  13853. }
  13854. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13855. {
  13856. ApplicationCommandTarget::InvocationInfo info (commandID);
  13857. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13858. return invoke (info, asynchronously);
  13859. }
  13860. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  13861. : commandID (commandID_),
  13862. commandFlags (0),
  13863. invocationMethod (direct),
  13864. originatingComponent (0),
  13865. isKeyDown (false),
  13866. millisecsSinceKeyPressed (0)
  13867. {
  13868. }
  13869. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  13870. : owner (owner_)
  13871. {
  13872. }
  13873. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  13874. {
  13875. }
  13876. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  13877. {
  13878. const ScopedPointer <InvocationInfo> info (static_cast <InvocationInfo*> (message.pointerParameter));
  13879. owner->tryToInvoke (*info, false);
  13880. }
  13881. END_JUCE_NAMESPACE
  13882. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13883. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  13884. BEGIN_JUCE_NAMESPACE
  13885. juce_ImplementSingleton (ApplicationProperties)
  13886. ApplicationProperties::ApplicationProperties() throw()
  13887. : msBeforeSaving (3000),
  13888. options (PropertiesFile::storeAsBinary),
  13889. commonSettingsAreReadOnly (0)
  13890. {
  13891. }
  13892. ApplicationProperties::~ApplicationProperties()
  13893. {
  13894. closeFiles();
  13895. clearSingletonInstance();
  13896. }
  13897. void ApplicationProperties::setStorageParameters (const String& applicationName,
  13898. const String& fileNameSuffix,
  13899. const String& folderName_,
  13900. const int millisecondsBeforeSaving,
  13901. const int propertiesFileOptions) throw()
  13902. {
  13903. appName = applicationName;
  13904. fileSuffix = fileNameSuffix;
  13905. folderName = folderName_;
  13906. msBeforeSaving = millisecondsBeforeSaving;
  13907. options = propertiesFileOptions;
  13908. }
  13909. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  13910. const bool testCommonSettings,
  13911. const bool showWarningDialogOnFailure)
  13912. {
  13913. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  13914. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  13915. if (! (userOk && commonOk))
  13916. {
  13917. if (showWarningDialogOnFailure)
  13918. {
  13919. String filenames;
  13920. if (userProps != 0 && ! userOk)
  13921. filenames << '\n' << userProps->getFile().getFullPathName();
  13922. if (commonProps != 0 && ! commonOk)
  13923. filenames << '\n' << commonProps->getFile().getFullPathName();
  13924. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  13925. appName + TRANS(" - Unable to save settings"),
  13926. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  13927. + appName + TRANS(" needs to be able to write to the following files:\n")
  13928. + filenames
  13929. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  13930. }
  13931. return false;
  13932. }
  13933. return true;
  13934. }
  13935. void ApplicationProperties::openFiles() throw()
  13936. {
  13937. // You need to call setStorageParameters() before trying to get hold of the
  13938. // properties!
  13939. jassert (appName.isNotEmpty());
  13940. if (appName.isNotEmpty())
  13941. {
  13942. if (userProps == 0)
  13943. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  13944. false, msBeforeSaving, options);
  13945. if (commonProps == 0)
  13946. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  13947. true, msBeforeSaving, options);
  13948. userProps->setFallbackPropertySet (commonProps);
  13949. }
  13950. }
  13951. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  13952. {
  13953. if (userProps == 0)
  13954. openFiles();
  13955. return userProps;
  13956. }
  13957. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  13958. {
  13959. if (commonProps == 0)
  13960. openFiles();
  13961. if (returnUserPropsIfReadOnly)
  13962. {
  13963. if (commonSettingsAreReadOnly == 0)
  13964. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  13965. if (commonSettingsAreReadOnly > 0)
  13966. return userProps;
  13967. }
  13968. return commonProps;
  13969. }
  13970. bool ApplicationProperties::saveIfNeeded()
  13971. {
  13972. return (userProps == 0 || userProps->saveIfNeeded())
  13973. && (commonProps == 0 || commonProps->saveIfNeeded());
  13974. }
  13975. void ApplicationProperties::closeFiles()
  13976. {
  13977. userProps = 0;
  13978. commonProps = 0;
  13979. }
  13980. END_JUCE_NAMESPACE
  13981. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  13982. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  13983. BEGIN_JUCE_NAMESPACE
  13984. static VoidArray objectsToDelete;
  13985. static CriticalSection lock;
  13986. DeletedAtShutdown::DeletedAtShutdown()
  13987. {
  13988. const ScopedLock sl (lock);
  13989. objectsToDelete.add (this);
  13990. }
  13991. DeletedAtShutdown::~DeletedAtShutdown()
  13992. {
  13993. const ScopedLock sl (lock);
  13994. objectsToDelete.removeValue (this);
  13995. }
  13996. void DeletedAtShutdown::deleteAll()
  13997. {
  13998. // make a local copy of the array, so it can't get into a loop if something
  13999. // creates another DeletedAtShutdown object during its destructor.
  14000. VoidArray localCopy;
  14001. {
  14002. const ScopedLock sl (lock);
  14003. localCopy = objectsToDelete;
  14004. }
  14005. for (int i = localCopy.size(); --i >= 0;)
  14006. {
  14007. JUCE_TRY
  14008. {
  14009. DeletedAtShutdown* deletee = static_cast <DeletedAtShutdown*> (localCopy.getUnchecked(i));
  14010. // double-check that it's not already been deleted during another object's destructor.
  14011. {
  14012. const ScopedLock sl (lock);
  14013. if (! objectsToDelete.contains (deletee))
  14014. deletee = 0;
  14015. }
  14016. delete deletee;
  14017. }
  14018. JUCE_CATCH_EXCEPTION
  14019. }
  14020. // if no objects got re-created during shutdown, this should have been emptied by their
  14021. // destructors
  14022. jassert (objectsToDelete.size() == 0);
  14023. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14024. }
  14025. END_JUCE_NAMESPACE
  14026. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14027. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14028. BEGIN_JUCE_NAMESPACE
  14029. namespace PropertyFileConstants
  14030. {
  14031. static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP");
  14032. static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP");
  14033. static const char* const fileTag = "PROPERTIES";
  14034. static const char* const valueTag = "VALUE";
  14035. static const char* const nameAttribute = "name";
  14036. static const char* const valueAttribute = "val";
  14037. }
  14038. PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving,
  14039. const int options_, InterProcessLock* const processLock_)
  14040. : PropertySet (ignoreCaseOfKeyNames),
  14041. file (f),
  14042. timerInterval (millisecondsBeforeSaving),
  14043. options (options_),
  14044. loadedOk (false),
  14045. needsWriting (false),
  14046. processLock (processLock_)
  14047. {
  14048. // You need to correctly specify just one storage format for the file
  14049. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14050. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14051. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14052. ProcessScopedLock pl (createProcessLock());
  14053. if (pl != 0 && ! pl->isLocked())
  14054. return; // locking failure..
  14055. ScopedPointer<InputStream> fileStream (f.createInputStream());
  14056. if (fileStream != 0)
  14057. {
  14058. int magicNumber = fileStream->readInt();
  14059. if (magicNumber == PropertyFileConstants::magicNumberCompressed)
  14060. {
  14061. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true);
  14062. magicNumber = PropertyFileConstants::magicNumber;
  14063. }
  14064. if (magicNumber == PropertyFileConstants::magicNumber)
  14065. {
  14066. loadedOk = true;
  14067. BufferedInputStream in (fileStream.release(), 2048, true);
  14068. int numValues = in.readInt();
  14069. while (--numValues >= 0 && ! in.isExhausted())
  14070. {
  14071. const String key (in.readString());
  14072. const String value (in.readString());
  14073. jassert (key.isNotEmpty());
  14074. if (key.isNotEmpty())
  14075. getAllProperties().set (key, value);
  14076. }
  14077. }
  14078. else
  14079. {
  14080. // Not a binary props file - let's see if it's XML..
  14081. fileStream = 0;
  14082. XmlDocument parser (f);
  14083. ScopedPointer<XmlElement> doc (parser.getDocumentElement (true));
  14084. if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag))
  14085. {
  14086. doc = parser.getDocumentElement();
  14087. if (doc != 0)
  14088. {
  14089. loadedOk = true;
  14090. forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
  14091. {
  14092. const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute));
  14093. if (name.isNotEmpty())
  14094. {
  14095. getAllProperties().set (name,
  14096. e->getFirstChildElement() != 0
  14097. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14098. : e->getStringAttribute (PropertyFileConstants::valueAttribute));
  14099. }
  14100. }
  14101. }
  14102. else
  14103. {
  14104. // must be a pretty broken XML file we're trying to parse here,
  14105. // or a sign that this object needs an InterProcessLock,
  14106. // or just a failure reading the file. This last reason is why
  14107. // we don't jassertfalse here.
  14108. }
  14109. }
  14110. }
  14111. }
  14112. else
  14113. {
  14114. loadedOk = ! f.exists();
  14115. }
  14116. }
  14117. PropertiesFile::~PropertiesFile()
  14118. {
  14119. if (! saveIfNeeded())
  14120. jassertfalse;
  14121. }
  14122. InterProcessLock::ScopedLockType* PropertiesFile::createProcessLock() const
  14123. {
  14124. return processLock != 0 ? new InterProcessLock::ScopedLockType (*processLock) : 0;
  14125. }
  14126. bool PropertiesFile::saveIfNeeded()
  14127. {
  14128. const ScopedLock sl (getLock());
  14129. return (! needsWriting) || save();
  14130. }
  14131. bool PropertiesFile::needsToBeSaved() const
  14132. {
  14133. const ScopedLock sl (getLock());
  14134. return needsWriting;
  14135. }
  14136. void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved)
  14137. {
  14138. const ScopedLock sl (getLock());
  14139. needsWriting = needsToBeSaved;
  14140. }
  14141. bool PropertiesFile::save()
  14142. {
  14143. const ScopedLock sl (getLock());
  14144. stopTimer();
  14145. if (file == File::nonexistent
  14146. || file.isDirectory()
  14147. || ! file.getParentDirectory().createDirectory())
  14148. return false;
  14149. if ((options & storeAsXML) != 0)
  14150. {
  14151. XmlElement doc (PropertyFileConstants::fileTag);
  14152. for (int i = 0; i < getAllProperties().size(); ++i)
  14153. {
  14154. XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag);
  14155. e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]);
  14156. // if the value seems to contain xml, store it as such..
  14157. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14158. XmlElement* const childElement = xmlContent.getDocumentElement();
  14159. if (childElement != 0)
  14160. e->addChildElement (childElement);
  14161. else
  14162. e->setAttribute (PropertyFileConstants::valueAttribute,
  14163. getAllProperties().getAllValues() [i]);
  14164. }
  14165. ProcessScopedLock pl (createProcessLock());
  14166. if (pl != 0 && ! pl->isLocked())
  14167. return false; // locking failure..
  14168. if (doc.writeToFile (file, String::empty))
  14169. {
  14170. needsWriting = false;
  14171. return true;
  14172. }
  14173. }
  14174. else
  14175. {
  14176. ProcessScopedLock pl (createProcessLock());
  14177. if (pl != 0 && ! pl->isLocked())
  14178. return false; // locking failure..
  14179. TemporaryFile tempFile (file);
  14180. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14181. if (out != 0)
  14182. {
  14183. if ((options & storeAsCompressedBinary) != 0)
  14184. {
  14185. out->writeInt (PropertyFileConstants::magicNumberCompressed);
  14186. out->flush();
  14187. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14188. }
  14189. else
  14190. {
  14191. // have you set up the storage option flags correctly?
  14192. jassert ((options & storeAsBinary) != 0);
  14193. out->writeInt (PropertyFileConstants::magicNumber);
  14194. }
  14195. const int numProperties = getAllProperties().size();
  14196. out->writeInt (numProperties);
  14197. for (int i = 0; i < numProperties; ++i)
  14198. {
  14199. out->writeString (getAllProperties().getAllKeys() [i]);
  14200. out->writeString (getAllProperties().getAllValues() [i]);
  14201. }
  14202. out = 0;
  14203. if (tempFile.overwriteTargetFileWithTemporary())
  14204. {
  14205. needsWriting = false;
  14206. return true;
  14207. }
  14208. }
  14209. }
  14210. return false;
  14211. }
  14212. void PropertiesFile::timerCallback()
  14213. {
  14214. saveIfNeeded();
  14215. }
  14216. void PropertiesFile::propertyChanged()
  14217. {
  14218. sendChangeMessage (this);
  14219. needsWriting = true;
  14220. if (timerInterval > 0)
  14221. startTimer (timerInterval);
  14222. else if (timerInterval == 0)
  14223. saveIfNeeded();
  14224. }
  14225. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14226. const String& fileNameSuffix,
  14227. const String& folderName,
  14228. const bool commonToAllUsers)
  14229. {
  14230. // mustn't have illegal characters in this name..
  14231. jassert (applicationName == File::createLegalFileName (applicationName));
  14232. #if JUCE_MAC || JUCE_IPHONE
  14233. File dir (commonToAllUsers ? "/Library/Preferences"
  14234. : "~/Library/Preferences");
  14235. if (folderName.isNotEmpty())
  14236. dir = dir.getChildFile (folderName);
  14237. #endif
  14238. #ifdef JUCE_LINUX
  14239. const File dir ((commonToAllUsers ? "/var/" : "~/")
  14240. + (folderName.isNotEmpty() ? folderName
  14241. : ("." + applicationName)));
  14242. #endif
  14243. #if JUCE_WIN32
  14244. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14245. : File::userApplicationDataDirectory));
  14246. if (dir == File::nonexistent)
  14247. return File::nonexistent;
  14248. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14249. : applicationName);
  14250. #endif
  14251. return dir.getChildFile (applicationName)
  14252. .withFileExtension (fileNameSuffix);
  14253. }
  14254. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14255. const String& fileNameSuffix,
  14256. const String& folderName,
  14257. const bool commonToAllUsers,
  14258. const int millisecondsBeforeSaving,
  14259. const int propertiesFileOptions,
  14260. InterProcessLock* processLock_)
  14261. {
  14262. const File file (getDefaultAppSettingsFile (applicationName,
  14263. fileNameSuffix,
  14264. folderName,
  14265. commonToAllUsers));
  14266. jassert (file != File::nonexistent);
  14267. if (file == File::nonexistent)
  14268. return 0;
  14269. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions,processLock_);
  14270. }
  14271. END_JUCE_NAMESPACE
  14272. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14273. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14274. BEGIN_JUCE_NAMESPACE
  14275. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14276. const String& fileWildcard_,
  14277. const String& openFileDialogTitle_,
  14278. const String& saveFileDialogTitle_)
  14279. : changedSinceSave (false),
  14280. fileExtension (fileExtension_),
  14281. fileWildcard (fileWildcard_),
  14282. openFileDialogTitle (openFileDialogTitle_),
  14283. saveFileDialogTitle (saveFileDialogTitle_)
  14284. {
  14285. }
  14286. FileBasedDocument::~FileBasedDocument()
  14287. {
  14288. }
  14289. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14290. {
  14291. if (changedSinceSave != hasChanged)
  14292. {
  14293. changedSinceSave = hasChanged;
  14294. sendChangeMessage (this);
  14295. }
  14296. }
  14297. void FileBasedDocument::changed()
  14298. {
  14299. changedSinceSave = true;
  14300. sendChangeMessage (this);
  14301. }
  14302. void FileBasedDocument::setFile (const File& newFile)
  14303. {
  14304. if (documentFile != newFile)
  14305. {
  14306. documentFile = newFile;
  14307. changed();
  14308. }
  14309. }
  14310. bool FileBasedDocument::loadFrom (const File& newFile,
  14311. const bool showMessageOnFailure)
  14312. {
  14313. MouseCursor::showWaitCursor();
  14314. const File oldFile (documentFile);
  14315. documentFile = newFile;
  14316. String error;
  14317. if (newFile.existsAsFile())
  14318. {
  14319. error = loadDocument (newFile);
  14320. if (error.isEmpty())
  14321. {
  14322. setChangedFlag (false);
  14323. MouseCursor::hideWaitCursor();
  14324. setLastDocumentOpened (newFile);
  14325. return true;
  14326. }
  14327. }
  14328. else
  14329. {
  14330. error = "The file doesn't exist";
  14331. }
  14332. documentFile = oldFile;
  14333. MouseCursor::hideWaitCursor();
  14334. if (showMessageOnFailure)
  14335. {
  14336. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14337. TRANS("Failed to open file..."),
  14338. TRANS("There was an error while trying to load the file:\n\n")
  14339. + newFile.getFullPathName()
  14340. + "\n\n"
  14341. + error);
  14342. }
  14343. return false;
  14344. }
  14345. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14346. {
  14347. FileChooser fc (openFileDialogTitle,
  14348. getLastDocumentOpened(),
  14349. fileWildcard);
  14350. if (fc.browseForFileToOpen())
  14351. return loadFrom (fc.getResult(), showMessageOnFailure);
  14352. return false;
  14353. }
  14354. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14355. const bool showMessageOnFailure)
  14356. {
  14357. return saveAs (documentFile,
  14358. false,
  14359. askUserForFileIfNotSpecified,
  14360. showMessageOnFailure);
  14361. }
  14362. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14363. const bool warnAboutOverwritingExistingFiles,
  14364. const bool askUserForFileIfNotSpecified,
  14365. const bool showMessageOnFailure)
  14366. {
  14367. if (newFile == File::nonexistent)
  14368. {
  14369. if (askUserForFileIfNotSpecified)
  14370. {
  14371. return saveAsInteractive (true);
  14372. }
  14373. else
  14374. {
  14375. // can't save to an unspecified file
  14376. jassertfalse
  14377. return failedToWriteToFile;
  14378. }
  14379. }
  14380. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14381. {
  14382. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14383. TRANS("File already exists"),
  14384. TRANS("There's already a file called:\n\n")
  14385. + newFile.getFullPathName()
  14386. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14387. TRANS("overwrite"),
  14388. TRANS("cancel")))
  14389. {
  14390. return userCancelledSave;
  14391. }
  14392. }
  14393. MouseCursor::showWaitCursor();
  14394. const File oldFile (documentFile);
  14395. documentFile = newFile;
  14396. String error (saveDocument (newFile));
  14397. if (error.isEmpty())
  14398. {
  14399. setChangedFlag (false);
  14400. MouseCursor::hideWaitCursor();
  14401. return savedOk;
  14402. }
  14403. documentFile = oldFile;
  14404. MouseCursor::hideWaitCursor();
  14405. if (showMessageOnFailure)
  14406. {
  14407. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14408. TRANS("Error writing to file..."),
  14409. TRANS("An error occurred while trying to save \"")
  14410. + getDocumentTitle()
  14411. + TRANS("\" to the file:\n\n")
  14412. + newFile.getFullPathName()
  14413. + "\n\n"
  14414. + error);
  14415. }
  14416. return failedToWriteToFile;
  14417. }
  14418. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14419. {
  14420. if (! hasChangedSinceSaved())
  14421. return savedOk;
  14422. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14423. TRANS("Closing document..."),
  14424. TRANS("Do you want to save the changes to \"")
  14425. + getDocumentTitle() + "\"?",
  14426. TRANS("save"),
  14427. TRANS("discard changes"),
  14428. TRANS("cancel"));
  14429. if (r == 1)
  14430. {
  14431. // save changes
  14432. return save (true, true);
  14433. }
  14434. else if (r == 2)
  14435. {
  14436. // discard changes
  14437. return savedOk;
  14438. }
  14439. return userCancelledSave;
  14440. }
  14441. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14442. {
  14443. File f;
  14444. if (documentFile.existsAsFile())
  14445. f = documentFile;
  14446. else
  14447. f = getLastDocumentOpened();
  14448. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14449. if (legalFilename.isEmpty())
  14450. legalFilename = "unnamed";
  14451. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14452. f = f.getSiblingFile (legalFilename);
  14453. else
  14454. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14455. f = f.withFileExtension (fileExtension)
  14456. .getNonexistentSibling (true);
  14457. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14458. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14459. {
  14460. setLastDocumentOpened (fc.getResult());
  14461. File chosen (fc.getResult());
  14462. if (chosen.getFileExtension().isEmpty())
  14463. {
  14464. chosen = chosen.withFileExtension (fileExtension);
  14465. if (chosen.exists())
  14466. {
  14467. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14468. TRANS("File already exists"),
  14469. TRANS("There's already a file called:")
  14470. + "\n\n" + chosen.getFullPathName()
  14471. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  14472. TRANS("overwrite"),
  14473. TRANS("cancel")))
  14474. {
  14475. return userCancelledSave;
  14476. }
  14477. }
  14478. }
  14479. return saveAs (chosen, false, false, true);
  14480. }
  14481. return userCancelledSave;
  14482. }
  14483. END_JUCE_NAMESPACE
  14484. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14485. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14486. BEGIN_JUCE_NAMESPACE
  14487. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14488. : maxNumberOfItems (10)
  14489. {
  14490. }
  14491. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14492. {
  14493. }
  14494. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14495. {
  14496. maxNumberOfItems = jmax (1, newMaxNumber);
  14497. while (getNumFiles() > maxNumberOfItems)
  14498. files.remove (getNumFiles() - 1);
  14499. }
  14500. int RecentlyOpenedFilesList::getNumFiles() const
  14501. {
  14502. return files.size();
  14503. }
  14504. const File RecentlyOpenedFilesList::getFile (const int index) const
  14505. {
  14506. return File (files [index]);
  14507. }
  14508. void RecentlyOpenedFilesList::clear()
  14509. {
  14510. files.clear();
  14511. }
  14512. void RecentlyOpenedFilesList::addFile (const File& file)
  14513. {
  14514. const String path (file.getFullPathName());
  14515. files.removeString (path, true);
  14516. files.insert (0, path);
  14517. setMaxNumberOfItems (maxNumberOfItems);
  14518. }
  14519. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14520. {
  14521. for (int i = getNumFiles(); --i >= 0;)
  14522. if (! getFile(i).exists())
  14523. files.remove (i);
  14524. }
  14525. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14526. const int baseItemId,
  14527. const bool showFullPaths,
  14528. const bool dontAddNonExistentFiles,
  14529. const File** filesToAvoid)
  14530. {
  14531. int num = 0;
  14532. for (int i = 0; i < getNumFiles(); ++i)
  14533. {
  14534. const File f (getFile(i));
  14535. if ((! dontAddNonExistentFiles) || f.exists())
  14536. {
  14537. bool needsAvoiding = false;
  14538. if (filesToAvoid != 0)
  14539. {
  14540. const File** avoid = filesToAvoid;
  14541. while (*avoid != 0)
  14542. {
  14543. if (f == **avoid)
  14544. {
  14545. needsAvoiding = true;
  14546. break;
  14547. }
  14548. ++avoid;
  14549. }
  14550. }
  14551. if (! needsAvoiding)
  14552. {
  14553. menuToAddTo.addItem (baseItemId + i,
  14554. showFullPaths ? f.getFullPathName()
  14555. : f.getFileName());
  14556. ++num;
  14557. }
  14558. }
  14559. }
  14560. return num;
  14561. }
  14562. const String RecentlyOpenedFilesList::toString() const
  14563. {
  14564. return files.joinIntoString ("\n");
  14565. }
  14566. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14567. {
  14568. clear();
  14569. files.addLines (stringifiedVersion);
  14570. setMaxNumberOfItems (maxNumberOfItems);
  14571. }
  14572. END_JUCE_NAMESPACE
  14573. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14574. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14575. BEGIN_JUCE_NAMESPACE
  14576. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14577. const int minimumTransactions)
  14578. : totalUnitsStored (0),
  14579. nextIndex (0),
  14580. newTransaction (true),
  14581. reentrancyCheck (false)
  14582. {
  14583. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14584. minimumTransactions);
  14585. }
  14586. UndoManager::~UndoManager()
  14587. {
  14588. clearUndoHistory();
  14589. }
  14590. void UndoManager::clearUndoHistory()
  14591. {
  14592. transactions.clear();
  14593. transactionNames.clear();
  14594. totalUnitsStored = 0;
  14595. nextIndex = 0;
  14596. sendChangeMessage (this);
  14597. }
  14598. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14599. {
  14600. return totalUnitsStored;
  14601. }
  14602. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14603. const int minimumTransactions)
  14604. {
  14605. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14606. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14607. }
  14608. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14609. {
  14610. if (command != 0)
  14611. {
  14612. if (actionName.isNotEmpty())
  14613. currentTransactionName = actionName;
  14614. if (reentrancyCheck)
  14615. {
  14616. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14617. // undo() methods, or else these actions won't actually get done.
  14618. return false;
  14619. }
  14620. else
  14621. {
  14622. bool success = false;
  14623. JUCE_TRY
  14624. {
  14625. success = command->perform();
  14626. }
  14627. JUCE_CATCH_EXCEPTION
  14628. jassert (success);
  14629. if (success)
  14630. {
  14631. if (nextIndex > 0 && ! newTransaction)
  14632. {
  14633. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14634. jassert (commandSet != 0);
  14635. if (commandSet == 0)
  14636. return false;
  14637. commandSet->add (command);
  14638. }
  14639. else
  14640. {
  14641. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14642. commandSet->add (command);
  14643. transactions.insert (nextIndex, commandSet);
  14644. transactionNames.insert (nextIndex, currentTransactionName);
  14645. ++nextIndex;
  14646. }
  14647. totalUnitsStored += command->getSizeInUnits();
  14648. newTransaction = false;
  14649. }
  14650. while (nextIndex < transactions.size())
  14651. {
  14652. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14653. for (int i = lastSet->size(); --i >= 0;)
  14654. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14655. transactions.removeLast();
  14656. transactionNames.remove (transactionNames.size() - 1);
  14657. }
  14658. while (nextIndex > 0
  14659. && totalUnitsStored > maxNumUnitsToKeep
  14660. && transactions.size() > minimumTransactionsToKeep)
  14661. {
  14662. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14663. for (int i = firstSet->size(); --i >= 0;)
  14664. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14665. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14666. transactions.remove (0);
  14667. transactionNames.remove (0);
  14668. --nextIndex;
  14669. }
  14670. sendChangeMessage (this);
  14671. return success;
  14672. }
  14673. }
  14674. return false;
  14675. }
  14676. void UndoManager::beginNewTransaction (const String& actionName)
  14677. {
  14678. newTransaction = true;
  14679. currentTransactionName = actionName;
  14680. }
  14681. void UndoManager::setCurrentTransactionName (const String& newName)
  14682. {
  14683. currentTransactionName = newName;
  14684. }
  14685. bool UndoManager::canUndo() const
  14686. {
  14687. return nextIndex > 0;
  14688. }
  14689. bool UndoManager::canRedo() const
  14690. {
  14691. return nextIndex < transactions.size();
  14692. }
  14693. const String UndoManager::getUndoDescription() const
  14694. {
  14695. return transactionNames [nextIndex - 1];
  14696. }
  14697. const String UndoManager::getRedoDescription() const
  14698. {
  14699. return transactionNames [nextIndex];
  14700. }
  14701. bool UndoManager::undo()
  14702. {
  14703. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14704. if (commandSet == 0)
  14705. return false;
  14706. reentrancyCheck = true;
  14707. bool failed = false;
  14708. for (int i = commandSet->size(); --i >= 0;)
  14709. {
  14710. if (! commandSet->getUnchecked(i)->undo())
  14711. {
  14712. jassertfalse
  14713. failed = true;
  14714. break;
  14715. }
  14716. }
  14717. reentrancyCheck = false;
  14718. if (failed)
  14719. {
  14720. clearUndoHistory();
  14721. }
  14722. else
  14723. {
  14724. --nextIndex;
  14725. }
  14726. beginNewTransaction();
  14727. sendChangeMessage (this);
  14728. return true;
  14729. }
  14730. bool UndoManager::redo()
  14731. {
  14732. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14733. if (commandSet == 0)
  14734. return false;
  14735. reentrancyCheck = true;
  14736. bool failed = false;
  14737. for (int i = 0; i < commandSet->size(); ++i)
  14738. {
  14739. if (! commandSet->getUnchecked(i)->perform())
  14740. {
  14741. jassertfalse
  14742. failed = true;
  14743. break;
  14744. }
  14745. }
  14746. reentrancyCheck = false;
  14747. if (failed)
  14748. {
  14749. clearUndoHistory();
  14750. }
  14751. else
  14752. {
  14753. ++nextIndex;
  14754. }
  14755. beginNewTransaction();
  14756. sendChangeMessage (this);
  14757. return true;
  14758. }
  14759. bool UndoManager::undoCurrentTransactionOnly()
  14760. {
  14761. return newTransaction ? false
  14762. : undo();
  14763. }
  14764. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  14765. {
  14766. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14767. if (commandSet != 0 && ! newTransaction)
  14768. {
  14769. for (int i = 0; i < commandSet->size(); ++i)
  14770. actionsFound.add (commandSet->getUnchecked(i));
  14771. }
  14772. }
  14773. int UndoManager::getNumActionsInCurrentTransaction() const
  14774. {
  14775. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14776. if (commandSet != 0 && ! newTransaction)
  14777. return commandSet->size();
  14778. return 0;
  14779. }
  14780. END_JUCE_NAMESPACE
  14781. /*** End of inlined file: juce_UndoManager.cpp ***/
  14782. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  14783. BEGIN_JUCE_NAMESPACE
  14784. static const char* const aiffFormatName = "AIFF file";
  14785. static const juce_wchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  14786. class AiffAudioFormatReader : public AudioFormatReader
  14787. {
  14788. public:
  14789. int bytesPerFrame;
  14790. int64 dataChunkStart;
  14791. bool littleEndian;
  14792. AiffAudioFormatReader (InputStream* in)
  14793. : AudioFormatReader (in, TRANS (aiffFormatName))
  14794. {
  14795. if (input->readInt() == chunkName ("FORM"))
  14796. {
  14797. const int len = input->readIntBigEndian();
  14798. const int64 end = input->getPosition() + len;
  14799. const int nextType = input->readInt();
  14800. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  14801. {
  14802. bool hasGotVer = false;
  14803. bool hasGotData = false;
  14804. bool hasGotType = false;
  14805. while (input->getPosition() < end)
  14806. {
  14807. const int type = input->readInt();
  14808. const uint32 length = (uint32) input->readIntBigEndian();
  14809. const int64 chunkEnd = input->getPosition() + length;
  14810. if (type == chunkName ("FVER"))
  14811. {
  14812. hasGotVer = true;
  14813. const int ver = input->readIntBigEndian();
  14814. if (ver != 0 && ver != (int)0xa2805140)
  14815. break;
  14816. }
  14817. else if (type == chunkName ("COMM"))
  14818. {
  14819. hasGotType = true;
  14820. numChannels = (unsigned int)input->readShortBigEndian();
  14821. lengthInSamples = input->readIntBigEndian();
  14822. bitsPerSample = input->readShortBigEndian();
  14823. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  14824. unsigned char sampleRateBytes[10];
  14825. input->read (sampleRateBytes, 10);
  14826. const int byte0 = sampleRateBytes[0];
  14827. if ((byte0 & 0x80) != 0
  14828. || byte0 <= 0x3F || byte0 > 0x40
  14829. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  14830. break;
  14831. unsigned int sampRate = ByteOrder::bigEndianInt (sampleRateBytes + 2);
  14832. sampRate >>= (16414 - ByteOrder::bigEndianShort (sampleRateBytes));
  14833. sampleRate = (int) sampRate;
  14834. if (length <= 18)
  14835. {
  14836. // some types don't have a chunk large enough to include a compression
  14837. // type, so assume it's just big-endian pcm
  14838. littleEndian = false;
  14839. }
  14840. else
  14841. {
  14842. const int compType = input->readInt();
  14843. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  14844. {
  14845. littleEndian = false;
  14846. }
  14847. else if (compType == chunkName ("sowt"))
  14848. {
  14849. littleEndian = true;
  14850. }
  14851. else
  14852. {
  14853. sampleRate = 0;
  14854. break;
  14855. }
  14856. }
  14857. }
  14858. else if (type == chunkName ("SSND"))
  14859. {
  14860. hasGotData = true;
  14861. const int offset = input->readIntBigEndian();
  14862. dataChunkStart = input->getPosition() + 4 + offset;
  14863. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  14864. }
  14865. else if ((hasGotVer && hasGotData && hasGotType)
  14866. || chunkEnd < input->getPosition()
  14867. || input->isExhausted())
  14868. {
  14869. break;
  14870. }
  14871. input->setPosition (chunkEnd);
  14872. }
  14873. }
  14874. }
  14875. }
  14876. ~AiffAudioFormatReader()
  14877. {
  14878. }
  14879. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  14880. int64 startSampleInFile, int numSamples)
  14881. {
  14882. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  14883. if (samplesAvailable < numSamples)
  14884. {
  14885. for (int i = numDestChannels; --i >= 0;)
  14886. if (destSamples[i] != 0)
  14887. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  14888. numSamples = (int) samplesAvailable;
  14889. }
  14890. if (numSamples <= 0)
  14891. return true;
  14892. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  14893. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  14894. char tempBuffer [tempBufSize];
  14895. while (numSamples > 0)
  14896. {
  14897. int* left = destSamples[0];
  14898. if (left != 0)
  14899. left += startOffsetInDestBuffer;
  14900. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  14901. if (right != 0)
  14902. right += startOffsetInDestBuffer;
  14903. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  14904. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  14905. if (bytesRead < numThisTime * bytesPerFrame)
  14906. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  14907. if (bitsPerSample == 16)
  14908. {
  14909. if (littleEndian)
  14910. {
  14911. const short* src = reinterpret_cast <const short*> (tempBuffer);
  14912. if (numChannels > 1)
  14913. {
  14914. if (left == 0)
  14915. {
  14916. for (int i = numThisTime; --i >= 0;)
  14917. {
  14918. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  14919. ++src;
  14920. }
  14921. }
  14922. else if (right == 0)
  14923. {
  14924. for (int i = numThisTime; --i >= 0;)
  14925. {
  14926. ++src;
  14927. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  14928. }
  14929. }
  14930. else
  14931. {
  14932. for (int i = numThisTime; --i >= 0;)
  14933. {
  14934. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  14935. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  14936. }
  14937. }
  14938. }
  14939. else
  14940. {
  14941. for (int i = numThisTime; --i >= 0;)
  14942. {
  14943. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  14944. }
  14945. }
  14946. }
  14947. else
  14948. {
  14949. const char* src = tempBuffer;
  14950. if (numChannels > 1)
  14951. {
  14952. if (left == 0)
  14953. {
  14954. for (int i = numThisTime; --i >= 0;)
  14955. {
  14956. *right++ = ByteOrder::bigEndianShort (src) << 16;
  14957. src += 4;
  14958. }
  14959. }
  14960. else if (right == 0)
  14961. {
  14962. for (int i = numThisTime; --i >= 0;)
  14963. {
  14964. src += 2;
  14965. *left++ = ByteOrder::bigEndianShort (src) << 16;
  14966. src += 2;
  14967. }
  14968. }
  14969. else
  14970. {
  14971. for (int i = numThisTime; --i >= 0;)
  14972. {
  14973. *left++ = ByteOrder::bigEndianShort (src) << 16;
  14974. src += 2;
  14975. *right++ = ByteOrder::bigEndianShort (src) << 16;
  14976. src += 2;
  14977. }
  14978. }
  14979. }
  14980. else
  14981. {
  14982. for (int i = numThisTime; --i >= 0;)
  14983. {
  14984. *left++ = ByteOrder::bigEndianShort (src) << 16;
  14985. src += 2;
  14986. }
  14987. }
  14988. }
  14989. }
  14990. else if (bitsPerSample == 24)
  14991. {
  14992. const char* src = (const char*)tempBuffer;
  14993. if (littleEndian)
  14994. {
  14995. if (numChannels > 1)
  14996. {
  14997. if (left == 0)
  14998. {
  14999. for (int i = numThisTime; --i >= 0;)
  15000. {
  15001. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15002. src += 6;
  15003. }
  15004. }
  15005. else if (right == 0)
  15006. {
  15007. for (int i = numThisTime; --i >= 0;)
  15008. {
  15009. src += 3;
  15010. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15011. src += 3;
  15012. }
  15013. }
  15014. else
  15015. {
  15016. for (int i = numThisTime; --i >= 0;)
  15017. {
  15018. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15019. src += 3;
  15020. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15021. src += 3;
  15022. }
  15023. }
  15024. }
  15025. else
  15026. {
  15027. for (int i = numThisTime; --i >= 0;)
  15028. {
  15029. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15030. src += 3;
  15031. }
  15032. }
  15033. }
  15034. else
  15035. {
  15036. if (numChannels > 1)
  15037. {
  15038. if (left == 0)
  15039. {
  15040. for (int i = numThisTime; --i >= 0;)
  15041. {
  15042. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15043. src += 6;
  15044. }
  15045. }
  15046. else if (right == 0)
  15047. {
  15048. for (int i = numThisTime; --i >= 0;)
  15049. {
  15050. src += 3;
  15051. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15052. src += 3;
  15053. }
  15054. }
  15055. else
  15056. {
  15057. for (int i = numThisTime; --i >= 0;)
  15058. {
  15059. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15060. src += 3;
  15061. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15062. src += 3;
  15063. }
  15064. }
  15065. }
  15066. else
  15067. {
  15068. for (int i = numThisTime; --i >= 0;)
  15069. {
  15070. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15071. src += 3;
  15072. }
  15073. }
  15074. }
  15075. }
  15076. else if (bitsPerSample == 32)
  15077. {
  15078. const unsigned int* src = reinterpret_cast <const unsigned int*> (tempBuffer);
  15079. unsigned int* l = reinterpret_cast <unsigned int*> (left);
  15080. unsigned int* r = reinterpret_cast <unsigned int*> (right);
  15081. if (littleEndian)
  15082. {
  15083. if (numChannels > 1)
  15084. {
  15085. if (l == 0)
  15086. {
  15087. for (int i = numThisTime; --i >= 0;)
  15088. {
  15089. ++src;
  15090. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15091. }
  15092. }
  15093. else if (r == 0)
  15094. {
  15095. for (int i = numThisTime; --i >= 0;)
  15096. {
  15097. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15098. ++src;
  15099. }
  15100. }
  15101. else
  15102. {
  15103. for (int i = numThisTime; --i >= 0;)
  15104. {
  15105. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15106. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15107. }
  15108. }
  15109. }
  15110. else
  15111. {
  15112. for (int i = numThisTime; --i >= 0;)
  15113. {
  15114. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15115. }
  15116. }
  15117. }
  15118. else
  15119. {
  15120. if (numChannels > 1)
  15121. {
  15122. if (l == 0)
  15123. {
  15124. for (int i = numThisTime; --i >= 0;)
  15125. {
  15126. ++src;
  15127. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15128. }
  15129. }
  15130. else if (r == 0)
  15131. {
  15132. for (int i = numThisTime; --i >= 0;)
  15133. {
  15134. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15135. ++src;
  15136. }
  15137. }
  15138. else
  15139. {
  15140. for (int i = numThisTime; --i >= 0;)
  15141. {
  15142. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15143. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15144. }
  15145. }
  15146. }
  15147. else
  15148. {
  15149. for (int i = numThisTime; --i >= 0;)
  15150. {
  15151. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15152. }
  15153. }
  15154. }
  15155. left = reinterpret_cast <int*> (l);
  15156. right = reinterpret_cast <int*> (r);
  15157. }
  15158. else if (bitsPerSample == 8)
  15159. {
  15160. const char* src = tempBuffer;
  15161. if (numChannels > 1)
  15162. {
  15163. if (left == 0)
  15164. {
  15165. for (int i = numThisTime; --i >= 0;)
  15166. {
  15167. *right++ = ((int) *src++) << 24;
  15168. ++src;
  15169. }
  15170. }
  15171. else if (right == 0)
  15172. {
  15173. for (int i = numThisTime; --i >= 0;)
  15174. {
  15175. ++src;
  15176. *left++ = ((int) *src++) << 24;
  15177. }
  15178. }
  15179. else
  15180. {
  15181. for (int i = numThisTime; --i >= 0;)
  15182. {
  15183. *left++ = ((int) *src++) << 24;
  15184. *right++ = ((int) *src++) << 24;
  15185. }
  15186. }
  15187. }
  15188. else
  15189. {
  15190. for (int i = numThisTime; --i >= 0;)
  15191. {
  15192. *left++ = ((int) *src++) << 24;
  15193. }
  15194. }
  15195. }
  15196. startOffsetInDestBuffer += numThisTime;
  15197. numSamples -= numThisTime;
  15198. }
  15199. if (numSamples > 0)
  15200. {
  15201. for (int i = numDestChannels; --i >= 0;)
  15202. if (destSamples[i] != 0)
  15203. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15204. sizeof (int) * numSamples);
  15205. }
  15206. return true;
  15207. }
  15208. juce_UseDebuggingNewOperator
  15209. private:
  15210. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15211. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15212. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15213. };
  15214. class AiffAudioFormatWriter : public AudioFormatWriter
  15215. {
  15216. MemoryBlock tempBlock;
  15217. uint32 lengthInSamples, bytesWritten;
  15218. int64 headerPosition;
  15219. bool writeFailed;
  15220. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15221. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15222. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15223. void writeHeader()
  15224. {
  15225. const bool couldSeekOk = output->setPosition (headerPosition);
  15226. (void) couldSeekOk;
  15227. // if this fails, you've given it an output stream that can't seek! It needs
  15228. // to be able to seek back to write the header
  15229. jassert (couldSeekOk);
  15230. const int headerLen = 54;
  15231. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15232. audioBytes += (audioBytes & 1);
  15233. output->writeInt (chunkName ("FORM"));
  15234. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15235. output->writeInt (chunkName ("AIFF"));
  15236. output->writeInt (chunkName ("COMM"));
  15237. output->writeIntBigEndian (18);
  15238. output->writeShortBigEndian ((short) numChannels);
  15239. output->writeIntBigEndian (lengthInSamples);
  15240. output->writeShortBigEndian ((short) bitsPerSample);
  15241. uint8 sampleRateBytes[10];
  15242. zeromem (sampleRateBytes, 10);
  15243. if (sampleRate <= 1)
  15244. {
  15245. sampleRateBytes[0] = 0x3f;
  15246. sampleRateBytes[1] = 0xff;
  15247. sampleRateBytes[2] = 0x80;
  15248. }
  15249. else
  15250. {
  15251. int mask = 0x40000000;
  15252. sampleRateBytes[0] = 0x40;
  15253. if (sampleRate >= mask)
  15254. {
  15255. jassertfalse
  15256. sampleRateBytes[1] = 0x1d;
  15257. }
  15258. else
  15259. {
  15260. int n = (int) sampleRate;
  15261. int i;
  15262. for (i = 0; i <= 32 ; ++i)
  15263. {
  15264. if ((n & mask) != 0)
  15265. break;
  15266. mask >>= 1;
  15267. }
  15268. n = n << (i + 1);
  15269. sampleRateBytes[1] = (uint8) (29 - i);
  15270. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15271. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15272. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15273. sampleRateBytes[5] = (uint8) (n & 0xff);
  15274. }
  15275. }
  15276. output->write (sampleRateBytes, 10);
  15277. output->writeInt (chunkName ("SSND"));
  15278. output->writeIntBigEndian (audioBytes + 8);
  15279. output->writeInt (0);
  15280. output->writeInt (0);
  15281. jassert (output->getPosition() == headerLen);
  15282. }
  15283. public:
  15284. AiffAudioFormatWriter (OutputStream* out,
  15285. const double sampleRate_,
  15286. const unsigned int chans,
  15287. const int bits)
  15288. : AudioFormatWriter (out,
  15289. TRANS (aiffFormatName),
  15290. sampleRate_,
  15291. chans,
  15292. bits),
  15293. lengthInSamples (0),
  15294. bytesWritten (0),
  15295. writeFailed (false)
  15296. {
  15297. headerPosition = out->getPosition();
  15298. writeHeader();
  15299. }
  15300. ~AiffAudioFormatWriter()
  15301. {
  15302. if ((bytesWritten & 1) != 0)
  15303. output->writeByte (0);
  15304. writeHeader();
  15305. }
  15306. bool write (const int** data, int numSamples)
  15307. {
  15308. if (writeFailed)
  15309. return false;
  15310. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15311. tempBlock.ensureSize (bytes, false);
  15312. char* buffer = static_cast <char*> (tempBlock.getData());
  15313. const int* left = data[0];
  15314. const int* right = data[1];
  15315. if (right == 0)
  15316. right = left;
  15317. if (bitsPerSample == 16)
  15318. {
  15319. short* b = reinterpret_cast <short*> (buffer);
  15320. if (numChannels > 1)
  15321. {
  15322. for (int i = numSamples; --i >= 0;)
  15323. {
  15324. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15325. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15326. }
  15327. }
  15328. else
  15329. {
  15330. for (int i = numSamples; --i >= 0;)
  15331. {
  15332. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15333. }
  15334. }
  15335. }
  15336. else if (bitsPerSample == 24)
  15337. {
  15338. char* b = buffer;
  15339. if (numChannels > 1)
  15340. {
  15341. for (int i = numSamples; --i >= 0;)
  15342. {
  15343. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15344. b += 3;
  15345. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15346. b += 3;
  15347. }
  15348. }
  15349. else
  15350. {
  15351. for (int i = numSamples; --i >= 0;)
  15352. {
  15353. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15354. b += 3;
  15355. }
  15356. }
  15357. }
  15358. else if (bitsPerSample == 32)
  15359. {
  15360. uint32* b = reinterpret_cast <uint32*> (buffer);
  15361. if (numChannels > 1)
  15362. {
  15363. for (int i = numSamples; --i >= 0;)
  15364. {
  15365. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15366. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15367. }
  15368. }
  15369. else
  15370. {
  15371. for (int i = numSamples; --i >= 0;)
  15372. {
  15373. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15374. }
  15375. }
  15376. }
  15377. else if (bitsPerSample == 8)
  15378. {
  15379. char* b = buffer;
  15380. if (numChannels > 1)
  15381. {
  15382. for (int i = numSamples; --i >= 0;)
  15383. {
  15384. *b++ = (char) (*left++ >> 24);
  15385. *b++ = (char) (*right++ >> 24);
  15386. }
  15387. }
  15388. else
  15389. {
  15390. for (int i = numSamples; --i >= 0;)
  15391. {
  15392. *b++ = (char) (*left++ >> 24);
  15393. }
  15394. }
  15395. }
  15396. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15397. || ! output->write (buffer, bytes))
  15398. {
  15399. // failed to write to disk, so let's try writing the header.
  15400. // If it's just run out of disk space, then if it does manage
  15401. // to write the header, we'll still have a useable file..
  15402. writeHeader();
  15403. writeFailed = true;
  15404. return false;
  15405. }
  15406. else
  15407. {
  15408. bytesWritten += bytes;
  15409. lengthInSamples += numSamples;
  15410. return true;
  15411. }
  15412. }
  15413. juce_UseDebuggingNewOperator
  15414. };
  15415. AiffAudioFormat::AiffAudioFormat()
  15416. : AudioFormat (TRANS (aiffFormatName), (const juce_wchar**) aiffExtensions)
  15417. {
  15418. }
  15419. AiffAudioFormat::~AiffAudioFormat()
  15420. {
  15421. }
  15422. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15423. {
  15424. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15425. return Array <int> (rates);
  15426. }
  15427. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15428. {
  15429. const int depths[] = { 8, 16, 24, 0 };
  15430. return Array <int> (depths);
  15431. }
  15432. bool AiffAudioFormat::canDoStereo()
  15433. {
  15434. return true;
  15435. }
  15436. bool AiffAudioFormat::canDoMono()
  15437. {
  15438. return true;
  15439. }
  15440. #if JUCE_MAC
  15441. bool AiffAudioFormat::canHandleFile (const File& f)
  15442. {
  15443. if (AudioFormat::canHandleFile (f))
  15444. return true;
  15445. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15446. return type == 'AIFF' || type == 'AIFC'
  15447. || type == 'aiff' || type == 'aifc';
  15448. }
  15449. #endif
  15450. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15451. const bool deleteStreamIfOpeningFails)
  15452. {
  15453. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15454. if (w->sampleRate != 0)
  15455. return w.release();
  15456. if (! deleteStreamIfOpeningFails)
  15457. w->input = 0;
  15458. return 0;
  15459. }
  15460. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15461. double sampleRate,
  15462. unsigned int chans,
  15463. int bitsPerSample,
  15464. const StringPairArray& /*metadataValues*/,
  15465. int /*qualityOptionIndex*/)
  15466. {
  15467. if (getPossibleBitDepths().contains (bitsPerSample))
  15468. {
  15469. return new AiffAudioFormatWriter (out,
  15470. sampleRate,
  15471. chans,
  15472. bitsPerSample);
  15473. }
  15474. return 0;
  15475. }
  15476. END_JUCE_NAMESPACE
  15477. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15478. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15479. BEGIN_JUCE_NAMESPACE
  15480. #if JUCE_MAC && JUCE_USE_CDREADER
  15481. // Mac version doesn't need any native code because it's all done with files..
  15482. // Windows + Linux versions are in the platform-dependent code sections.
  15483. static void findCDs (Array<File>& cds)
  15484. {
  15485. File volumes ("/Volumes");
  15486. volumes.findChildFiles (cds, File::findDirectories, false);
  15487. for (int i = cds.size(); --i >= 0;)
  15488. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15489. cds.remove (i);
  15490. }
  15491. const StringArray AudioCDReader::getAvailableCDNames()
  15492. {
  15493. Array<File> cds;
  15494. findCDs (cds);
  15495. StringArray names;
  15496. for (int i = 0; i < cds.size(); ++i)
  15497. names.add (cds.getReference(i).getFileName());
  15498. return names;
  15499. }
  15500. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15501. {
  15502. Array<File> cds;
  15503. findCDs (cds);
  15504. if (cds[index] != File::nonexistent)
  15505. return new AudioCDReader (cds[index]);
  15506. else
  15507. return 0;
  15508. }
  15509. AudioCDReader::AudioCDReader (const File& volume)
  15510. : AudioFormatReader (0, "CD Audio"),
  15511. volumeDir (volume),
  15512. currentReaderTrack (-1),
  15513. reader (0)
  15514. {
  15515. sampleRate = 44100.0;
  15516. bitsPerSample = 16;
  15517. numChannels = 2;
  15518. usesFloatingPointData = false;
  15519. refreshTrackLengths();
  15520. }
  15521. AudioCDReader::~AudioCDReader()
  15522. {
  15523. }
  15524. static int getTrackNumber (const File& file)
  15525. {
  15526. return file.getFileName()
  15527. .initialSectionContainingOnly ("0123456789")
  15528. .getIntValue();
  15529. }
  15530. int AudioCDReader::compareElements (const File& first, const File& second)
  15531. {
  15532. const int firstTrack = getTrackNumber (first);
  15533. const int secondTrack = getTrackNumber (second);
  15534. jassert (firstTrack > 0 && secondTrack > 0);
  15535. return firstTrack - secondTrack;
  15536. }
  15537. void AudioCDReader::refreshTrackLengths()
  15538. {
  15539. tracks.clear();
  15540. trackStartSamples.clear();
  15541. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, "*.aiff");
  15542. tracks.sort (*this);
  15543. AiffAudioFormat format;
  15544. int sample = 0;
  15545. for (int i = 0; i < tracks.size(); ++i)
  15546. {
  15547. trackStartSamples.add (sample);
  15548. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15549. if (in != 0)
  15550. {
  15551. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15552. if (r != 0)
  15553. sample += (int) r->lengthInSamples;
  15554. }
  15555. }
  15556. trackStartSamples.add (sample);
  15557. lengthInSamples = sample;
  15558. }
  15559. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15560. int64 startSampleInFile, int numSamples)
  15561. {
  15562. while (numSamples > 0)
  15563. {
  15564. int track = -1;
  15565. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15566. {
  15567. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15568. {
  15569. track = i;
  15570. break;
  15571. }
  15572. }
  15573. if (track < 0)
  15574. return false;
  15575. if (track != currentReaderTrack)
  15576. {
  15577. reader = 0;
  15578. FileInputStream* const in = tracks [track].createInputStream();
  15579. if (in != 0)
  15580. {
  15581. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15582. AiffAudioFormat format;
  15583. reader = format.createReaderFor (bin, true);
  15584. if (reader == 0)
  15585. currentReaderTrack = -1;
  15586. else
  15587. currentReaderTrack = track;
  15588. }
  15589. }
  15590. if (reader == 0)
  15591. return false;
  15592. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15593. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15594. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15595. numSamples -= numAvailable;
  15596. startSampleInFile += numAvailable;
  15597. }
  15598. return true;
  15599. }
  15600. bool AudioCDReader::isCDStillPresent() const
  15601. {
  15602. return volumeDir.exists();
  15603. }
  15604. int AudioCDReader::getNumTracks() const
  15605. {
  15606. return tracks.size();
  15607. }
  15608. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15609. {
  15610. return trackStartSamples [trackNum];
  15611. }
  15612. bool AudioCDReader::isTrackAudio (int trackNum) const
  15613. {
  15614. return tracks [trackNum] != File::nonexistent;
  15615. }
  15616. void AudioCDReader::enableIndexScanning (bool b)
  15617. {
  15618. // any way to do this on a Mac??
  15619. }
  15620. int AudioCDReader::getLastIndex() const
  15621. {
  15622. return 0;
  15623. }
  15624. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15625. {
  15626. return Array <int>();
  15627. }
  15628. int AudioCDReader::getCDDBId()
  15629. {
  15630. return 0; //xxx
  15631. }
  15632. #endif
  15633. END_JUCE_NAMESPACE
  15634. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15635. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15636. BEGIN_JUCE_NAMESPACE
  15637. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15638. const String& formatName_)
  15639. : sampleRate (0),
  15640. bitsPerSample (0),
  15641. lengthInSamples (0),
  15642. numChannels (0),
  15643. usesFloatingPointData (false),
  15644. input (in),
  15645. formatName (formatName_)
  15646. {
  15647. }
  15648. AudioFormatReader::~AudioFormatReader()
  15649. {
  15650. delete input;
  15651. }
  15652. bool AudioFormatReader::read (int** destSamples,
  15653. int numDestChannels,
  15654. int64 startSampleInSource,
  15655. int numSamplesToRead,
  15656. const bool fillLeftoverChannelsWithCopies)
  15657. {
  15658. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15659. int startOffsetInDestBuffer = 0;
  15660. if (startSampleInSource < 0)
  15661. {
  15662. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15663. for (int i = numDestChannels; --i >= 0;)
  15664. if (destSamples[i] != 0)
  15665. zeromem (destSamples[i], sizeof (int) * silence);
  15666. startOffsetInDestBuffer += silence;
  15667. numSamplesToRead -= silence;
  15668. startSampleInSource = 0;
  15669. }
  15670. if (numSamplesToRead <= 0)
  15671. return true;
  15672. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15673. startSampleInSource, numSamplesToRead))
  15674. return false;
  15675. if (numDestChannels > (int) numChannels)
  15676. {
  15677. if (fillLeftoverChannelsWithCopies)
  15678. {
  15679. int* lastFullChannel = destSamples[0];
  15680. for (int i = numDestChannels; --i > 0;)
  15681. {
  15682. if (destSamples[i] != 0)
  15683. {
  15684. lastFullChannel = destSamples[i];
  15685. break;
  15686. }
  15687. }
  15688. if (lastFullChannel != 0)
  15689. for (int i = numChannels; i < numDestChannels; ++i)
  15690. if (destSamples[i] != 0)
  15691. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15692. }
  15693. else
  15694. {
  15695. for (int i = numChannels; i < numDestChannels; ++i)
  15696. if (destSamples[i] != 0)
  15697. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15698. }
  15699. }
  15700. return true;
  15701. }
  15702. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15703. {
  15704. float mn = buffer[0];
  15705. float mx = mn;
  15706. for (int i = 1; i < num; ++i)
  15707. {
  15708. const float s = buffer[i];
  15709. if (s > mx) mx = s;
  15710. if (s < mn) mn = s;
  15711. }
  15712. maxVal = mx;
  15713. minVal = mn;
  15714. }
  15715. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15716. int64 numSamples,
  15717. float& lowestLeft, float& highestLeft,
  15718. float& lowestRight, float& highestRight)
  15719. {
  15720. if (numSamples <= 0)
  15721. {
  15722. lowestLeft = 0;
  15723. lowestRight = 0;
  15724. highestLeft = 0;
  15725. highestRight = 0;
  15726. return;
  15727. }
  15728. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15729. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15730. int* tempBuffer[3];
  15731. tempBuffer[0] = (int*) tempSpace.getData();
  15732. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15733. tempBuffer[2] = 0;
  15734. if (usesFloatingPointData)
  15735. {
  15736. float lmin = 1.0e6f;
  15737. float lmax = -lmin;
  15738. float rmin = lmin;
  15739. float rmax = lmax;
  15740. while (numSamples > 0)
  15741. {
  15742. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15743. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15744. numSamples -= numToDo;
  15745. startSampleInFile += numToDo;
  15746. float bufmin, bufmax;
  15747. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  15748. lmin = jmin (lmin, bufmin);
  15749. lmax = jmax (lmax, bufmax);
  15750. if (numChannels > 1)
  15751. {
  15752. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  15753. rmin = jmin (rmin, bufmin);
  15754. rmax = jmax (rmax, bufmax);
  15755. }
  15756. }
  15757. if (numChannels <= 1)
  15758. {
  15759. rmax = lmax;
  15760. rmin = lmin;
  15761. }
  15762. lowestLeft = lmin;
  15763. highestLeft = lmax;
  15764. lowestRight = rmin;
  15765. highestRight = rmax;
  15766. }
  15767. else
  15768. {
  15769. int lmax = std::numeric_limits<int>::min();
  15770. int lmin = std::numeric_limits<int>::max();
  15771. int rmax = std::numeric_limits<int>::min();
  15772. int rmin = std::numeric_limits<int>::max();
  15773. while (numSamples > 0)
  15774. {
  15775. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15776. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15777. numSamples -= numToDo;
  15778. startSampleInFile += numToDo;
  15779. for (int j = numChannels; --j >= 0;)
  15780. {
  15781. int bufMax = std::numeric_limits<int>::min();
  15782. int bufMin = std::numeric_limits<int>::max();
  15783. const int* const b = tempBuffer[j];
  15784. for (int i = 0; i < numToDo; ++i)
  15785. {
  15786. const int samp = b[i];
  15787. if (samp < bufMin)
  15788. bufMin = samp;
  15789. if (samp > bufMax)
  15790. bufMax = samp;
  15791. }
  15792. if (j == 0)
  15793. {
  15794. lmax = jmax (lmax, bufMax);
  15795. lmin = jmin (lmin, bufMin);
  15796. }
  15797. else
  15798. {
  15799. rmax = jmax (rmax, bufMax);
  15800. rmin = jmin (rmin, bufMin);
  15801. }
  15802. }
  15803. }
  15804. if (numChannels <= 1)
  15805. {
  15806. rmax = lmax;
  15807. rmin = lmin;
  15808. }
  15809. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  15810. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  15811. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  15812. highestRight = rmax / (float) std::numeric_limits<int>::max();
  15813. }
  15814. }
  15815. int64 AudioFormatReader::searchForLevel (int64 startSample,
  15816. int64 numSamplesToSearch,
  15817. const double magnitudeRangeMinimum,
  15818. const double magnitudeRangeMaximum,
  15819. const int minimumConsecutiveSamples)
  15820. {
  15821. if (numSamplesToSearch == 0)
  15822. return -1;
  15823. const int bufferSize = 4096;
  15824. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15825. int* tempBuffer[3];
  15826. tempBuffer[0] = (int*) tempSpace.getData();
  15827. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15828. tempBuffer[2] = 0;
  15829. int consecutive = 0;
  15830. int64 firstMatchPos = -1;
  15831. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  15832. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  15833. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  15834. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  15835. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  15836. while (numSamplesToSearch != 0)
  15837. {
  15838. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  15839. int64 bufferStart = startSample;
  15840. if (numSamplesToSearch < 0)
  15841. bufferStart -= numThisTime;
  15842. if (bufferStart >= (int) lengthInSamples)
  15843. break;
  15844. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  15845. int num = numThisTime;
  15846. while (--num >= 0)
  15847. {
  15848. if (numSamplesToSearch < 0)
  15849. --startSample;
  15850. bool matches = false;
  15851. const int index = (int) (startSample - bufferStart);
  15852. if (usesFloatingPointData)
  15853. {
  15854. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  15855. if (sample1 >= magnitudeRangeMinimum
  15856. && sample1 <= magnitudeRangeMaximum)
  15857. {
  15858. matches = true;
  15859. }
  15860. else if (numChannels > 1)
  15861. {
  15862. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  15863. matches = (sample2 >= magnitudeRangeMinimum
  15864. && sample2 <= magnitudeRangeMaximum);
  15865. }
  15866. }
  15867. else
  15868. {
  15869. const int sample1 = abs (tempBuffer[0] [index]);
  15870. if (sample1 >= intMagnitudeRangeMinimum
  15871. && sample1 <= intMagnitudeRangeMaximum)
  15872. {
  15873. matches = true;
  15874. }
  15875. else if (numChannels > 1)
  15876. {
  15877. const int sample2 = abs (tempBuffer[1][index]);
  15878. matches = (sample2 >= intMagnitudeRangeMinimum
  15879. && sample2 <= intMagnitudeRangeMaximum);
  15880. }
  15881. }
  15882. if (matches)
  15883. {
  15884. if (firstMatchPos < 0)
  15885. firstMatchPos = startSample;
  15886. if (++consecutive >= minimumConsecutiveSamples)
  15887. {
  15888. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  15889. return -1;
  15890. return firstMatchPos;
  15891. }
  15892. }
  15893. else
  15894. {
  15895. consecutive = 0;
  15896. firstMatchPos = -1;
  15897. }
  15898. if (numSamplesToSearch > 0)
  15899. ++startSample;
  15900. }
  15901. if (numSamplesToSearch > 0)
  15902. numSamplesToSearch -= numThisTime;
  15903. else
  15904. numSamplesToSearch += numThisTime;
  15905. }
  15906. return -1;
  15907. }
  15908. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  15909. const String& formatName_,
  15910. const double rate,
  15911. const unsigned int numChannels_,
  15912. const unsigned int bitsPerSample_)
  15913. : sampleRate (rate),
  15914. numChannels (numChannels_),
  15915. bitsPerSample (bitsPerSample_),
  15916. usesFloatingPointData (false),
  15917. output (out),
  15918. formatName (formatName_)
  15919. {
  15920. }
  15921. AudioFormatWriter::~AudioFormatWriter()
  15922. {
  15923. delete output;
  15924. }
  15925. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  15926. int64 startSample,
  15927. int64 numSamplesToRead)
  15928. {
  15929. const int bufferSize = 16384;
  15930. const int maxChans = 128;
  15931. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  15932. int* buffers [maxChans];
  15933. for (int i = maxChans; --i >= 0;)
  15934. buffers[i] = 0;
  15935. if (numSamplesToRead < 0)
  15936. numSamplesToRead = reader.lengthInSamples;
  15937. while (numSamplesToRead > 0)
  15938. {
  15939. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  15940. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  15941. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  15942. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  15943. return false;
  15944. if (reader.usesFloatingPointData != isFloatingPoint())
  15945. {
  15946. int** bufferChan = buffers;
  15947. while (*bufferChan != 0)
  15948. {
  15949. int* b = *bufferChan++;
  15950. if (isFloatingPoint())
  15951. {
  15952. // int -> float
  15953. const double factor = 1.0 / std::numeric_limits<int>::max();
  15954. for (int i = 0; i < numToDo; ++i)
  15955. ((float*) b)[i] = (float) (factor * b[i]);
  15956. }
  15957. else
  15958. {
  15959. // float -> int
  15960. for (int i = 0; i < numToDo; ++i)
  15961. {
  15962. const double samp = *(const float*) b;
  15963. if (samp <= -1.0)
  15964. *b++ = std::numeric_limits<int>::min();
  15965. else if (samp >= 1.0)
  15966. *b++ = std::numeric_limits<int>::max();
  15967. else
  15968. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  15969. }
  15970. }
  15971. }
  15972. }
  15973. if (! write ((const int**) buffers, numToDo))
  15974. return false;
  15975. numSamplesToRead -= numToDo;
  15976. startSample += numToDo;
  15977. }
  15978. return true;
  15979. }
  15980. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  15981. int numSamplesToRead,
  15982. const int samplesPerBlock)
  15983. {
  15984. const int maxChans = 128;
  15985. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  15986. int* buffers [maxChans];
  15987. while (numSamplesToRead > 0)
  15988. {
  15989. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  15990. AudioSourceChannelInfo info;
  15991. info.buffer = &tempBuffer;
  15992. info.startSample = 0;
  15993. info.numSamples = numToDo;
  15994. info.clearActiveBufferRegion();
  15995. source.getNextAudioBlock (info);
  15996. int i;
  15997. for (i = maxChans; --i >= 0;)
  15998. buffers[i] = 0;
  15999. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16000. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16001. if (! isFloatingPoint())
  16002. {
  16003. int** bufferChan = buffers;
  16004. while (*bufferChan != 0)
  16005. {
  16006. int* b = *bufferChan++;
  16007. // float -> int
  16008. for (int j = numToDo; --j >= 0;)
  16009. {
  16010. const double samp = *(const float*) b;
  16011. if (samp <= -1.0)
  16012. *b++ = std::numeric_limits<int>::min();
  16013. else if (samp >= 1.0)
  16014. *b++ = std::numeric_limits<int>::max();
  16015. else
  16016. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16017. }
  16018. }
  16019. }
  16020. if (! write ((const int**) buffers, numToDo))
  16021. return false;
  16022. numSamplesToRead -= numToDo;
  16023. }
  16024. return true;
  16025. }
  16026. AudioFormat::AudioFormat (const String& name,
  16027. const juce_wchar** const extensions)
  16028. : formatName (name),
  16029. fileExtensions (extensions)
  16030. {
  16031. }
  16032. AudioFormat::~AudioFormat()
  16033. {
  16034. }
  16035. const String& AudioFormat::getFormatName() const
  16036. {
  16037. return formatName;
  16038. }
  16039. const StringArray& AudioFormat::getFileExtensions() const
  16040. {
  16041. return fileExtensions;
  16042. }
  16043. bool AudioFormat::canHandleFile (const File& f)
  16044. {
  16045. for (int i = 0; i < fileExtensions.size(); ++i)
  16046. if (f.hasFileExtension (fileExtensions[i]))
  16047. return true;
  16048. return false;
  16049. }
  16050. bool AudioFormat::isCompressed()
  16051. {
  16052. return false;
  16053. }
  16054. const StringArray AudioFormat::getQualityOptions()
  16055. {
  16056. return StringArray();
  16057. }
  16058. END_JUCE_NAMESPACE
  16059. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16060. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16061. BEGIN_JUCE_NAMESPACE
  16062. AudioFormatManager::AudioFormatManager()
  16063. : defaultFormatIndex (0)
  16064. {
  16065. }
  16066. AudioFormatManager::~AudioFormatManager()
  16067. {
  16068. clearFormats();
  16069. clearSingletonInstance();
  16070. }
  16071. juce_ImplementSingleton (AudioFormatManager);
  16072. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16073. const bool makeThisTheDefaultFormat)
  16074. {
  16075. jassert (newFormat != 0);
  16076. if (newFormat != 0)
  16077. {
  16078. #ifdef JUCE_DEBUG
  16079. for (int i = getNumKnownFormats(); --i >= 0;)
  16080. {
  16081. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16082. {
  16083. jassertfalse // trying to add the same format twice!
  16084. }
  16085. }
  16086. #endif
  16087. if (makeThisTheDefaultFormat)
  16088. defaultFormatIndex = getNumKnownFormats();
  16089. knownFormats.add (newFormat);
  16090. }
  16091. }
  16092. void AudioFormatManager::registerBasicFormats()
  16093. {
  16094. #if JUCE_MAC
  16095. registerFormat (new AiffAudioFormat(), true);
  16096. registerFormat (new WavAudioFormat(), false);
  16097. #else
  16098. registerFormat (new WavAudioFormat(), true);
  16099. registerFormat (new AiffAudioFormat(), false);
  16100. #endif
  16101. #if JUCE_USE_FLAC
  16102. registerFormat (new FlacAudioFormat(), false);
  16103. #endif
  16104. #if JUCE_USE_OGGVORBIS
  16105. registerFormat (new OggVorbisAudioFormat(), false);
  16106. #endif
  16107. }
  16108. void AudioFormatManager::clearFormats()
  16109. {
  16110. knownFormats.clear();
  16111. defaultFormatIndex = 0;
  16112. }
  16113. int AudioFormatManager::getNumKnownFormats() const
  16114. {
  16115. return knownFormats.size();
  16116. }
  16117. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16118. {
  16119. return knownFormats [index];
  16120. }
  16121. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16122. {
  16123. return getKnownFormat (defaultFormatIndex);
  16124. }
  16125. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16126. {
  16127. String e (fileExtension);
  16128. if (! e.startsWithChar ('.'))
  16129. e = "." + e;
  16130. for (int i = 0; i < getNumKnownFormats(); ++i)
  16131. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16132. return getKnownFormat(i);
  16133. return 0;
  16134. }
  16135. const String AudioFormatManager::getWildcardForAllFormats() const
  16136. {
  16137. StringArray allExtensions;
  16138. int i;
  16139. for (i = 0; i < getNumKnownFormats(); ++i)
  16140. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16141. allExtensions.trim();
  16142. allExtensions.removeEmptyStrings();
  16143. String s;
  16144. for (i = 0; i < allExtensions.size(); ++i)
  16145. {
  16146. s << '*';
  16147. if (! allExtensions[i].startsWithChar ('.'))
  16148. s << '.';
  16149. s << allExtensions[i];
  16150. if (i < allExtensions.size() - 1)
  16151. s << ';';
  16152. }
  16153. return s;
  16154. }
  16155. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16156. {
  16157. // you need to actually register some formats before the manager can
  16158. // use them to open a file!
  16159. jassert (getNumKnownFormats() > 0);
  16160. for (int i = 0; i < getNumKnownFormats(); ++i)
  16161. {
  16162. AudioFormat* const af = getKnownFormat(i);
  16163. if (af->canHandleFile (file))
  16164. {
  16165. InputStream* const in = file.createInputStream();
  16166. if (in != 0)
  16167. {
  16168. AudioFormatReader* const r = af->createReaderFor (in, true);
  16169. if (r != 0)
  16170. return r;
  16171. }
  16172. }
  16173. }
  16174. return 0;
  16175. }
  16176. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16177. {
  16178. // you need to actually register some formats before the manager can
  16179. // use them to open a file!
  16180. jassert (getNumKnownFormats() > 0);
  16181. ScopedPointer <InputStream> in (audioFileStream);
  16182. if (in != 0)
  16183. {
  16184. const int64 originalStreamPos = in->getPosition();
  16185. for (int i = 0; i < getNumKnownFormats(); ++i)
  16186. {
  16187. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16188. if (r != 0)
  16189. {
  16190. in.release();
  16191. return r;
  16192. }
  16193. in->setPosition (originalStreamPos);
  16194. // the stream that is passed-in must be capable of being repositioned so
  16195. // that all the formats can have a go at opening it.
  16196. jassert (in->getPosition() == originalStreamPos);
  16197. }
  16198. }
  16199. return 0;
  16200. }
  16201. END_JUCE_NAMESPACE
  16202. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16203. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16204. BEGIN_JUCE_NAMESPACE
  16205. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16206. const int64 startSample_,
  16207. const int64 length_,
  16208. const bool deleteSourceWhenDeleted_)
  16209. : AudioFormatReader (0, source_->getFormatName()),
  16210. source (source_),
  16211. startSample (startSample_),
  16212. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16213. {
  16214. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16215. sampleRate = source->sampleRate;
  16216. bitsPerSample = source->bitsPerSample;
  16217. lengthInSamples = length;
  16218. numChannels = source->numChannels;
  16219. usesFloatingPointData = source->usesFloatingPointData;
  16220. }
  16221. AudioSubsectionReader::~AudioSubsectionReader()
  16222. {
  16223. if (deleteSourceWhenDeleted)
  16224. delete source;
  16225. }
  16226. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16227. int64 startSampleInFile, int numSamples)
  16228. {
  16229. if (startSampleInFile + numSamples > length)
  16230. {
  16231. for (int i = numDestChannels; --i >= 0;)
  16232. if (destSamples[i] != 0)
  16233. zeromem (destSamples[i], sizeof (int) * numSamples);
  16234. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16235. if (numSamples <= 0)
  16236. return true;
  16237. }
  16238. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16239. startSampleInFile + startSample, numSamples);
  16240. }
  16241. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16242. int64 numSamples,
  16243. float& lowestLeft,
  16244. float& highestLeft,
  16245. float& lowestRight,
  16246. float& highestRight)
  16247. {
  16248. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16249. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16250. source->readMaxLevels (startSampleInFile + startSample,
  16251. numSamples,
  16252. lowestLeft,
  16253. highestLeft,
  16254. lowestRight,
  16255. highestRight);
  16256. }
  16257. END_JUCE_NAMESPACE
  16258. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16259. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16260. BEGIN_JUCE_NAMESPACE
  16261. const int timeBeforeDeletingReader = 2000;
  16262. struct AudioThumbnailDataFormat
  16263. {
  16264. char thumbnailMagic[4];
  16265. int samplesPerThumbSample;
  16266. int64 totalSamples; // source samples
  16267. int64 numFinishedSamples; // source samples
  16268. int numThumbnailSamples;
  16269. int numChannels;
  16270. int sampleRate;
  16271. char future[16];
  16272. char data[1];
  16273. void swapEndiannessIfNeeded() throw()
  16274. {
  16275. #if JUCE_BIG_ENDIAN
  16276. flip (samplesPerThumbSample);
  16277. flip (totalSamples);
  16278. flip (numFinishedSamples);
  16279. flip (numThumbnailSamples);
  16280. flip (numChannels);
  16281. flip (sampleRate);
  16282. #endif
  16283. }
  16284. private:
  16285. #if JUCE_BIG_ENDIAN
  16286. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16287. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16288. #endif
  16289. };
  16290. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16291. AudioFormatManager& formatManagerToUse_,
  16292. AudioThumbnailCache& cacheToUse)
  16293. : formatManagerToUse (formatManagerToUse_),
  16294. cache (cacheToUse),
  16295. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16296. {
  16297. clear();
  16298. }
  16299. AudioThumbnail::~AudioThumbnail()
  16300. {
  16301. cache.removeThumbnail (this);
  16302. const ScopedLock sl (readerLock);
  16303. reader = 0;
  16304. }
  16305. void AudioThumbnail::setSource (InputSource* const newSource)
  16306. {
  16307. cache.removeThumbnail (this);
  16308. timerCallback(); // stops the timer and deletes the reader
  16309. source = newSource;
  16310. clear();
  16311. if (newSource != 0
  16312. && ! (cache.loadThumb (*this, newSource->hashCode())
  16313. && isFullyLoaded()))
  16314. {
  16315. {
  16316. const ScopedLock sl (readerLock);
  16317. reader = createReader();
  16318. }
  16319. if (reader != 0)
  16320. {
  16321. initialiseFromAudioFile (*reader);
  16322. cache.addThumbnail (this);
  16323. }
  16324. }
  16325. sendChangeMessage (this);
  16326. }
  16327. bool AudioThumbnail::useTimeSlice()
  16328. {
  16329. const ScopedLock sl (readerLock);
  16330. if (isFullyLoaded())
  16331. {
  16332. if (reader != 0)
  16333. startTimer (timeBeforeDeletingReader);
  16334. cache.removeThumbnail (this);
  16335. return false;
  16336. }
  16337. if (reader == 0)
  16338. reader = createReader();
  16339. if (reader != 0)
  16340. {
  16341. readNextBlockFromAudioFile (*reader);
  16342. stopTimer();
  16343. sendChangeMessage (this);
  16344. const bool justFinished = isFullyLoaded();
  16345. if (justFinished)
  16346. cache.storeThumb (*this, source->hashCode());
  16347. return ! justFinished;
  16348. }
  16349. return false;
  16350. }
  16351. AudioFormatReader* AudioThumbnail::createReader() const
  16352. {
  16353. if (source != 0)
  16354. {
  16355. InputStream* const audioFileStream = source->createInputStream();
  16356. if (audioFileStream != 0)
  16357. return formatManagerToUse.createReaderFor (audioFileStream);
  16358. }
  16359. return 0;
  16360. }
  16361. void AudioThumbnail::timerCallback()
  16362. {
  16363. stopTimer();
  16364. const ScopedLock sl (readerLock);
  16365. reader = 0;
  16366. }
  16367. void AudioThumbnail::clear()
  16368. {
  16369. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16370. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16371. d->thumbnailMagic[0] = 'j';
  16372. d->thumbnailMagic[1] = 'a';
  16373. d->thumbnailMagic[2] = 't';
  16374. d->thumbnailMagic[3] = 'm';
  16375. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16376. d->totalSamples = 0;
  16377. d->numFinishedSamples = 0;
  16378. d->numThumbnailSamples = 0;
  16379. d->numChannels = 0;
  16380. d->sampleRate = 0;
  16381. numSamplesCached = 0;
  16382. cacheNeedsRefilling = true;
  16383. }
  16384. void AudioThumbnail::loadFrom (InputStream& input)
  16385. {
  16386. const ScopedLock sl (readerLock);
  16387. data.setSize (0);
  16388. input.readIntoMemoryBlock (data);
  16389. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16390. d->swapEndiannessIfNeeded();
  16391. if (! (d->thumbnailMagic[0] == 'j'
  16392. && d->thumbnailMagic[1] == 'a'
  16393. && d->thumbnailMagic[2] == 't'
  16394. && d->thumbnailMagic[3] == 'm'))
  16395. {
  16396. clear();
  16397. }
  16398. numSamplesCached = 0;
  16399. cacheNeedsRefilling = true;
  16400. }
  16401. void AudioThumbnail::saveTo (OutputStream& output) const
  16402. {
  16403. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16404. d->swapEndiannessIfNeeded();
  16405. output.write (data.getData(), (int) data.getSize());
  16406. d->swapEndiannessIfNeeded();
  16407. }
  16408. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16409. {
  16410. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16411. d->totalSamples = fileReader.lengthInSamples;
  16412. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16413. d->numFinishedSamples = 0;
  16414. d->sampleRate = roundToInt (fileReader.sampleRate);
  16415. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16416. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16417. d = (AudioThumbnailDataFormat*) data.getData();
  16418. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16419. return d->totalSamples > 0;
  16420. }
  16421. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16422. {
  16423. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16424. if (d->numFinishedSamples < d->totalSamples)
  16425. {
  16426. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16427. generateSection (fileReader,
  16428. d->numFinishedSamples,
  16429. numToDo);
  16430. d->numFinishedSamples += numToDo;
  16431. }
  16432. cacheNeedsRefilling = true;
  16433. return (d->numFinishedSamples < d->totalSamples);
  16434. }
  16435. int AudioThumbnail::getNumChannels() const throw()
  16436. {
  16437. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16438. jassert (d != 0);
  16439. return d->numChannels;
  16440. }
  16441. double AudioThumbnail::getTotalLength() const throw()
  16442. {
  16443. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16444. jassert (d != 0);
  16445. if (d->sampleRate > 0)
  16446. return d->totalSamples / (double)d->sampleRate;
  16447. else
  16448. return 0.0;
  16449. }
  16450. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16451. int64 startSample,
  16452. int numSamples)
  16453. {
  16454. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16455. jassert (d != 0);
  16456. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16457. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16458. char* l = getChannelData (0);
  16459. char* r = getChannelData (1);
  16460. for (int i = firstDataPos; i < lastDataPos; ++i)
  16461. {
  16462. const int sourceStart = i * d->samplesPerThumbSample;
  16463. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16464. float lowestLeft, highestLeft, lowestRight, highestRight;
  16465. fileReader.readMaxLevels (sourceStart,
  16466. sourceEnd - sourceStart,
  16467. lowestLeft,
  16468. highestLeft,
  16469. lowestRight,
  16470. highestRight);
  16471. int n = i * 2;
  16472. if (r != 0)
  16473. {
  16474. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16475. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16476. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16477. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16478. }
  16479. else
  16480. {
  16481. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16482. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16483. }
  16484. }
  16485. }
  16486. char* AudioThumbnail::getChannelData (int channel) const
  16487. {
  16488. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16489. jassert (d != 0);
  16490. if (channel >= 0 && channel < d->numChannels)
  16491. return d->data + (channel * 2 * d->numThumbnailSamples);
  16492. return 0;
  16493. }
  16494. bool AudioThumbnail::isFullyLoaded() const throw()
  16495. {
  16496. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16497. jassert (d != 0);
  16498. return d->numFinishedSamples >= d->totalSamples;
  16499. }
  16500. void AudioThumbnail::refillCache (const int numSamples,
  16501. double startTime,
  16502. const double timePerPixel)
  16503. {
  16504. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16505. jassert (d != 0);
  16506. if (numSamples <= 0
  16507. || timePerPixel <= 0.0
  16508. || d->sampleRate <= 0)
  16509. {
  16510. numSamplesCached = 0;
  16511. cacheNeedsRefilling = true;
  16512. return;
  16513. }
  16514. if (numSamples == numSamplesCached
  16515. && numChannelsCached == d->numChannels
  16516. && startTime == cachedStart
  16517. && timePerPixel == cachedTimePerPixel
  16518. && ! cacheNeedsRefilling)
  16519. {
  16520. return;
  16521. }
  16522. numSamplesCached = numSamples;
  16523. numChannelsCached = d->numChannels;
  16524. cachedStart = startTime;
  16525. cachedTimePerPixel = timePerPixel;
  16526. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16527. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16528. const ScopedLock sl (readerLock);
  16529. cacheNeedsRefilling = false;
  16530. if (needExtraDetail && reader == 0)
  16531. reader = createReader();
  16532. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16533. {
  16534. startTimer (timeBeforeDeletingReader);
  16535. char* cacheData = static_cast <char*> (cachedLevels.getData());
  16536. int sample = roundToInt (startTime * d->sampleRate);
  16537. for (int i = numSamples; --i >= 0;)
  16538. {
  16539. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16540. if (sample >= 0)
  16541. {
  16542. if (sample >= reader->lengthInSamples)
  16543. break;
  16544. float lmin, lmax, rmin, rmax;
  16545. reader->readMaxLevels (sample,
  16546. jmax (1, nextSample - sample),
  16547. lmin, lmax, rmin, rmax);
  16548. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16549. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16550. if (numChannelsCached > 1)
  16551. {
  16552. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16553. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16554. }
  16555. cacheData += 2 * numChannelsCached;
  16556. }
  16557. startTime += timePerPixel;
  16558. sample = nextSample;
  16559. }
  16560. }
  16561. else
  16562. {
  16563. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16564. {
  16565. char* const channelData = getChannelData (channelNum);
  16566. char* cacheData = static_cast <char*> (cachedLevels.getData()) + channelNum * 2;
  16567. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16568. startTime = cachedStart;
  16569. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16570. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16571. for (int i = numSamples; --i >= 0;)
  16572. {
  16573. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16574. if (sample >= 0 && channelData != 0)
  16575. {
  16576. char mx = -128;
  16577. char mn = 127;
  16578. while (sample <= nextSample)
  16579. {
  16580. if (sample >= numFinished)
  16581. break;
  16582. const int n = sample << 1;
  16583. const char sampMin = channelData [n];
  16584. const char sampMax = channelData [n + 1];
  16585. if (sampMin < mn)
  16586. mn = sampMin;
  16587. if (sampMax > mx)
  16588. mx = sampMax;
  16589. ++sample;
  16590. }
  16591. if (mn <= mx)
  16592. {
  16593. cacheData[0] = mn;
  16594. cacheData[1] = mx;
  16595. }
  16596. else
  16597. {
  16598. cacheData[0] = 1;
  16599. cacheData[1] = 0;
  16600. }
  16601. }
  16602. else
  16603. {
  16604. cacheData[0] = 1;
  16605. cacheData[1] = 0;
  16606. }
  16607. cacheData += numChannelsCached * 2;
  16608. startTime += timePerPixel;
  16609. sample = nextSample;
  16610. }
  16611. }
  16612. }
  16613. }
  16614. void AudioThumbnail::drawChannel (Graphics& g,
  16615. int x, int y, int w, int h,
  16616. double startTime,
  16617. double endTime,
  16618. int channelNum,
  16619. const float verticalZoomFactor)
  16620. {
  16621. refillCache (w, startTime, (endTime - startTime) / w);
  16622. if (numSamplesCached >= w
  16623. && channelNum >= 0
  16624. && channelNum < numChannelsCached)
  16625. {
  16626. const float topY = (float) y;
  16627. const float bottomY = topY + h;
  16628. const float midY = topY + h * 0.5f;
  16629. const float vscale = verticalZoomFactor * h / 256.0f;
  16630. const Rectangle<int> clip (g.getClipBounds());
  16631. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16632. w -= skipLeft;
  16633. x += skipLeft;
  16634. const char* cacheData = static_cast <const char*> (cachedLevels.getData())
  16635. + (channelNum << 1)
  16636. + skipLeft * (numChannelsCached << 1);
  16637. while (--w >= 0)
  16638. {
  16639. const char mn = cacheData[0];
  16640. const char mx = cacheData[1];
  16641. cacheData += numChannelsCached << 1;
  16642. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16643. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16644. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16645. ++x;
  16646. if (x >= clip.getRight())
  16647. break;
  16648. }
  16649. }
  16650. }
  16651. END_JUCE_NAMESPACE
  16652. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16653. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16654. BEGIN_JUCE_NAMESPACE
  16655. struct ThumbnailCacheEntry
  16656. {
  16657. int64 hash;
  16658. uint32 lastUsed;
  16659. MemoryBlock data;
  16660. juce_UseDebuggingNewOperator
  16661. };
  16662. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16663. : TimeSliceThread ("thumb cache"),
  16664. maxNumThumbsToStore (maxNumThumbsToStore_)
  16665. {
  16666. startThread (2);
  16667. }
  16668. AudioThumbnailCache::~AudioThumbnailCache()
  16669. {
  16670. }
  16671. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16672. {
  16673. for (int i = thumbs.size(); --i >= 0;)
  16674. {
  16675. if (thumbs[i]->hash == hashCode)
  16676. {
  16677. MemoryInputStream in (thumbs[i]->data, false);
  16678. thumb.loadFrom (in);
  16679. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16680. return true;
  16681. }
  16682. }
  16683. return false;
  16684. }
  16685. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16686. const int64 hashCode)
  16687. {
  16688. MemoryOutputStream out;
  16689. thumb.saveTo (out);
  16690. ThumbnailCacheEntry* te = 0;
  16691. for (int i = thumbs.size(); --i >= 0;)
  16692. {
  16693. if (thumbs[i]->hash == hashCode)
  16694. {
  16695. te = thumbs[i];
  16696. break;
  16697. }
  16698. }
  16699. if (te == 0)
  16700. {
  16701. te = new ThumbnailCacheEntry();
  16702. te->hash = hashCode;
  16703. if (thumbs.size() < maxNumThumbsToStore)
  16704. {
  16705. thumbs.add (te);
  16706. }
  16707. else
  16708. {
  16709. int oldest = 0;
  16710. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16711. int i;
  16712. for (i = thumbs.size(); --i >= 0;)
  16713. if (thumbs[i]->lastUsed < oldestTime)
  16714. oldest = i;
  16715. thumbs.set (i, te);
  16716. }
  16717. }
  16718. te->lastUsed = Time::getMillisecondCounter();
  16719. te->data.setSize (0);
  16720. te->data.append (out.getData(), out.getDataSize());
  16721. }
  16722. void AudioThumbnailCache::clear()
  16723. {
  16724. thumbs.clear();
  16725. }
  16726. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16727. {
  16728. addTimeSliceClient (thumb);
  16729. }
  16730. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  16731. {
  16732. removeTimeSliceClient (thumb);
  16733. }
  16734. END_JUCE_NAMESPACE
  16735. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  16736. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  16737. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  16738. #if ! JUCE_WINDOWS
  16739. #include <QuickTime/Movies.h>
  16740. #include <QuickTime/QTML.h>
  16741. #include <QuickTime/QuickTimeComponents.h>
  16742. #include <QuickTime/MediaHandlers.h>
  16743. #include <QuickTime/ImageCodec.h>
  16744. #else
  16745. #if JUCE_MSVC
  16746. #pragma warning (push)
  16747. #pragma warning (disable : 4100)
  16748. #endif
  16749. #include <Movies.h>
  16750. #include <QTML.h>
  16751. #include <QuickTimeComponents.h>
  16752. #include <MediaHandlers.h>
  16753. #include <ImageCodec.h>
  16754. #if JUCE_MSVC
  16755. #pragma warning (pop)
  16756. #endif
  16757. #endif
  16758. BEGIN_JUCE_NAMESPACE
  16759. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  16760. static const char* const quickTimeFormatName = "QuickTime file";
  16761. static const juce_wchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  16762. class QTAudioReader : public AudioFormatReader
  16763. {
  16764. public:
  16765. QTAudioReader (InputStream* const input_, const int trackNum_)
  16766. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  16767. ok (false),
  16768. movie (0),
  16769. trackNum (trackNum_),
  16770. lastSampleRead (0),
  16771. lastThreadId (0),
  16772. extractor (0),
  16773. dataHandle (0)
  16774. {
  16775. bufferList.calloc (256, 1);
  16776. #ifdef WIN32
  16777. if (InitializeQTML (0) != noErr)
  16778. return;
  16779. #endif
  16780. if (EnterMovies() != noErr)
  16781. return;
  16782. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  16783. if (! opened)
  16784. return;
  16785. {
  16786. const int numTracks = GetMovieTrackCount (movie);
  16787. int trackCount = 0;
  16788. for (int i = 1; i <= numTracks; ++i)
  16789. {
  16790. track = GetMovieIndTrack (movie, i);
  16791. media = GetTrackMedia (track);
  16792. OSType mediaType;
  16793. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  16794. if (mediaType == SoundMediaType
  16795. && trackCount++ == trackNum_)
  16796. {
  16797. ok = true;
  16798. break;
  16799. }
  16800. }
  16801. }
  16802. if (! ok)
  16803. return;
  16804. ok = false;
  16805. lengthInSamples = GetMediaDecodeDuration (media);
  16806. usesFloatingPointData = false;
  16807. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  16808. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  16809. / GetMediaTimeScale (media);
  16810. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  16811. unsigned long output_layout_size;
  16812. err = MovieAudioExtractionGetPropertyInfo (extractor,
  16813. kQTPropertyClass_MovieAudioExtraction_Audio,
  16814. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16815. 0, &output_layout_size, 0);
  16816. if (err != noErr)
  16817. return;
  16818. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  16819. qt_audio_channel_layout.calloc (output_layout_size, 1);
  16820. err = MovieAudioExtractionGetProperty (extractor,
  16821. kQTPropertyClass_MovieAudioExtraction_Audio,
  16822. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16823. output_layout_size, qt_audio_channel_layout, 0);
  16824. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  16825. err = MovieAudioExtractionSetProperty (extractor,
  16826. kQTPropertyClass_MovieAudioExtraction_Audio,
  16827. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16828. output_layout_size,
  16829. qt_audio_channel_layout);
  16830. err = MovieAudioExtractionGetProperty (extractor,
  16831. kQTPropertyClass_MovieAudioExtraction_Audio,
  16832. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16833. sizeof (inputStreamDesc),
  16834. &inputStreamDesc, 0);
  16835. if (err != noErr)
  16836. return;
  16837. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  16838. | kAudioFormatFlagIsPacked
  16839. | kAudioFormatFlagsNativeEndian;
  16840. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  16841. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  16842. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  16843. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  16844. err = MovieAudioExtractionSetProperty (extractor,
  16845. kQTPropertyClass_MovieAudioExtraction_Audio,
  16846. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16847. sizeof (inputStreamDesc),
  16848. &inputStreamDesc);
  16849. if (err != noErr)
  16850. return;
  16851. Boolean allChannelsDiscrete = false;
  16852. err = MovieAudioExtractionSetProperty (extractor,
  16853. kQTPropertyClass_MovieAudioExtraction_Movie,
  16854. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  16855. sizeof (allChannelsDiscrete),
  16856. &allChannelsDiscrete);
  16857. if (err != noErr)
  16858. return;
  16859. bufferList->mNumberBuffers = 1;
  16860. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  16861. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  16862. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  16863. sampleRate = inputStreamDesc.mSampleRate;
  16864. bitsPerSample = 16;
  16865. numChannels = inputStreamDesc.mChannelsPerFrame;
  16866. detachThread();
  16867. ok = true;
  16868. }
  16869. ~QTAudioReader()
  16870. {
  16871. if (dataHandle != 0)
  16872. DisposeHandle (dataHandle);
  16873. if (extractor != 0)
  16874. {
  16875. MovieAudioExtractionEnd (extractor);
  16876. extractor = 0;
  16877. }
  16878. checkThreadIsAttached();
  16879. DisposeMovie (movie);
  16880. juce_free (bufferList->mBuffers[0].mData);
  16881. #if JUCE_MAC
  16882. ExitMoviesOnThread ();
  16883. #endif
  16884. }
  16885. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16886. int64 startSampleInFile, int numSamples)
  16887. {
  16888. checkThreadIsAttached();
  16889. while (numSamples > 0)
  16890. {
  16891. if (! loadFrame ((int) startSampleInFile))
  16892. return false;
  16893. const int numToDo = jmin (numSamples, samplesPerFrame);
  16894. for (int j = numDestChannels; --j >= 0;)
  16895. {
  16896. if (destSamples[j] != 0)
  16897. {
  16898. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  16899. for (int i = 0; i < numToDo; ++i)
  16900. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  16901. }
  16902. }
  16903. startOffsetInDestBuffer += numToDo;
  16904. startSampleInFile += numToDo;
  16905. numSamples -= numToDo;
  16906. }
  16907. detachThread();
  16908. return true;
  16909. }
  16910. bool loadFrame (const int sampleNum)
  16911. {
  16912. if (lastSampleRead != sampleNum)
  16913. {
  16914. TimeRecord time;
  16915. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  16916. time.base = 0;
  16917. time.value.hi = 0;
  16918. time.value.lo = (UInt32) sampleNum;
  16919. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  16920. kQTPropertyClass_MovieAudioExtraction_Movie,
  16921. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  16922. sizeof (time), &time);
  16923. if (err != noErr)
  16924. return false;
  16925. }
  16926. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  16927. UInt32 outFlags = 0;
  16928. UInt32 actualNumSamples = samplesPerFrame;
  16929. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  16930. bufferList, &outFlags);
  16931. lastSampleRead = sampleNum + samplesPerFrame;
  16932. return err == noErr;
  16933. }
  16934. juce_UseDebuggingNewOperator
  16935. bool ok;
  16936. private:
  16937. Movie movie;
  16938. Media media;
  16939. Track track;
  16940. const int trackNum;
  16941. double trackUnitsPerFrame;
  16942. int samplesPerFrame;
  16943. int lastSampleRead;
  16944. Thread::ThreadID lastThreadId;
  16945. MovieAudioExtractionRef extractor;
  16946. AudioStreamBasicDescription inputStreamDesc;
  16947. HeapBlock <AudioBufferList> bufferList;
  16948. Handle dataHandle;
  16949. void checkThreadIsAttached()
  16950. {
  16951. #if JUCE_MAC
  16952. if (Thread::getCurrentThreadId() != lastThreadId)
  16953. EnterMoviesOnThread (0);
  16954. AttachMovieToCurrentThread (movie);
  16955. #endif
  16956. }
  16957. void detachThread()
  16958. {
  16959. #if JUCE_MAC
  16960. DetachMovieFromCurrentThread (movie);
  16961. #endif
  16962. }
  16963. QTAudioReader (const QTAudioReader&);
  16964. QTAudioReader& operator= (const QTAudioReader&);
  16965. };
  16966. QuickTimeAudioFormat::QuickTimeAudioFormat()
  16967. : AudioFormat (TRANS (quickTimeFormatName), (const juce_wchar**) quickTimeExtensions)
  16968. {
  16969. }
  16970. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  16971. {
  16972. }
  16973. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  16974. {
  16975. return Array<int>();
  16976. }
  16977. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  16978. {
  16979. return Array<int>();
  16980. }
  16981. bool QuickTimeAudioFormat::canDoStereo()
  16982. {
  16983. return true;
  16984. }
  16985. bool QuickTimeAudioFormat::canDoMono()
  16986. {
  16987. return true;
  16988. }
  16989. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  16990. const bool deleteStreamIfOpeningFails)
  16991. {
  16992. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  16993. if (r->ok)
  16994. return r.release();
  16995. if (! deleteStreamIfOpeningFails)
  16996. r->input = 0;
  16997. return 0;
  16998. }
  16999. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17000. double /*sampleRateToUse*/,
  17001. unsigned int /*numberOfChannels*/,
  17002. int /*bitsPerSample*/,
  17003. const StringPairArray& /*metadataValues*/,
  17004. int /*qualityOptionIndex*/)
  17005. {
  17006. jassertfalse // not yet implemented!
  17007. return 0;
  17008. }
  17009. END_JUCE_NAMESPACE
  17010. #endif
  17011. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17012. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17013. BEGIN_JUCE_NAMESPACE
  17014. static const char* const wavFormatName = "WAV file";
  17015. static const juce_wchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17016. const char* const WavAudioFormat::bwavDescription = "bwav description";
  17017. const char* const WavAudioFormat::bwavOriginator = "bwav originator";
  17018. const char* const WavAudioFormat::bwavOriginatorRef = "bwav originator ref";
  17019. const char* const WavAudioFormat::bwavOriginationDate = "bwav origination date";
  17020. const char* const WavAudioFormat::bwavOriginationTime = "bwav origination time";
  17021. const char* const WavAudioFormat::bwavTimeReference = "bwav time reference";
  17022. const char* const WavAudioFormat::bwavCodingHistory = "bwav coding history";
  17023. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17024. const String& originator,
  17025. const String& originatorRef,
  17026. const Time& date,
  17027. const int64 timeReferenceSamples,
  17028. const String& codingHistory)
  17029. {
  17030. StringPairArray m;
  17031. m.set (bwavDescription, description);
  17032. m.set (bwavOriginator, originator);
  17033. m.set (bwavOriginatorRef, originatorRef);
  17034. m.set (bwavOriginationDate, date.formatted ("%Y-%m-%d"));
  17035. m.set (bwavOriginationTime, date.formatted ("%H:%M:%S"));
  17036. m.set (bwavTimeReference, String (timeReferenceSamples));
  17037. m.set (bwavCodingHistory, codingHistory);
  17038. return m;
  17039. }
  17040. #if JUCE_MSVC
  17041. #pragma pack (push, 1)
  17042. #define PACKED
  17043. #elif JUCE_GCC
  17044. #define PACKED __attribute__((packed))
  17045. #else
  17046. #define PACKED
  17047. #endif
  17048. struct BWAVChunk
  17049. {
  17050. char description [256];
  17051. char originator [32];
  17052. char originatorRef [32];
  17053. char originationDate [10];
  17054. char originationTime [8];
  17055. uint32 timeRefLow;
  17056. uint32 timeRefHigh;
  17057. uint16 version;
  17058. uint8 umid[64];
  17059. uint8 reserved[190];
  17060. char codingHistory[1];
  17061. void copyTo (StringPairArray& values) const
  17062. {
  17063. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17064. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17065. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17066. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17067. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17068. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17069. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17070. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17071. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17072. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17073. }
  17074. static MemoryBlock createFrom (const StringPairArray& values)
  17075. {
  17076. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17077. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17078. data.fillWith (0);
  17079. BWAVChunk* b = (BWAVChunk*) data.getData();
  17080. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17081. // as they get called in the right order..
  17082. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17083. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17084. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17085. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17086. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17087. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17088. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17089. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17090. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17091. if (b->description[0] != 0
  17092. || b->originator[0] != 0
  17093. || b->originationDate[0] != 0
  17094. || b->originationTime[0] != 0
  17095. || b->codingHistory[0] != 0
  17096. || time != 0)
  17097. {
  17098. return data;
  17099. }
  17100. return MemoryBlock();
  17101. }
  17102. } PACKED;
  17103. struct SMPLChunk
  17104. {
  17105. struct SampleLoop
  17106. {
  17107. uint32 identifier;
  17108. uint32 type;
  17109. uint32 start;
  17110. uint32 end;
  17111. uint32 fraction;
  17112. uint32 playCount;
  17113. } PACKED;
  17114. uint32 manufacturer;
  17115. uint32 product;
  17116. uint32 samplePeriod;
  17117. uint32 midiUnityNote;
  17118. uint32 midiPitchFraction;
  17119. uint32 smpteFormat;
  17120. uint32 smpteOffset;
  17121. uint32 numSampleLoops;
  17122. uint32 samplerData;
  17123. SampleLoop loops[1];
  17124. void copyTo (StringPairArray& values, const int totalSize) const
  17125. {
  17126. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17127. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17128. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17129. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17130. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17131. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17132. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17133. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17134. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17135. for (uint32 i = 0; i < numSampleLoops; ++i)
  17136. {
  17137. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17138. break;
  17139. const String prefix ("Loop" + String(i));
  17140. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17141. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17142. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17143. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17144. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17145. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17146. }
  17147. }
  17148. static MemoryBlock createFrom (const StringPairArray& values)
  17149. {
  17150. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17151. if (numLoops <= 0)
  17152. return MemoryBlock();
  17153. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17154. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17155. data.fillWith (0);
  17156. SMPLChunk* s = (SMPLChunk*) data.getData();
  17157. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17158. // as they get called in the right order..
  17159. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17160. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17161. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17162. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17163. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17164. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17165. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17166. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17167. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17168. for (int i = 0; i < numLoops; ++i)
  17169. {
  17170. const String prefix ("Loop" + String(i));
  17171. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17172. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17173. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17174. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17175. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17176. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17177. }
  17178. return data;
  17179. }
  17180. } PACKED;
  17181. struct ExtensibleWavSubFormat
  17182. {
  17183. uint32 data1;
  17184. uint16 data2;
  17185. uint16 data3;
  17186. uint8 data4[8];
  17187. } PACKED;
  17188. #if JUCE_MSVC
  17189. #pragma pack (pop)
  17190. #endif
  17191. #undef PACKED
  17192. class WavAudioFormatReader : public AudioFormatReader
  17193. {
  17194. int bytesPerFrame;
  17195. int64 dataChunkStart, dataLength;
  17196. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17197. WavAudioFormatReader (const WavAudioFormatReader&);
  17198. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17199. public:
  17200. int64 bwavChunkStart, bwavSize;
  17201. WavAudioFormatReader (InputStream* const in)
  17202. : AudioFormatReader (in, TRANS (wavFormatName)),
  17203. dataLength (0),
  17204. bwavChunkStart (0),
  17205. bwavSize (0)
  17206. {
  17207. if (input->readInt() == chunkName ("RIFF"))
  17208. {
  17209. const uint32 len = (uint32) input->readInt();
  17210. const int64 end = input->getPosition() + len;
  17211. bool hasGotType = false;
  17212. bool hasGotData = false;
  17213. if (input->readInt() == chunkName ("WAVE"))
  17214. {
  17215. while (input->getPosition() < end
  17216. && ! input->isExhausted())
  17217. {
  17218. const int chunkType = input->readInt();
  17219. uint32 length = (uint32) input->readInt();
  17220. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17221. if (chunkType == chunkName ("fmt "))
  17222. {
  17223. // read the format chunk
  17224. const unsigned short format = input->readShort();
  17225. const short numChans = input->readShort();
  17226. sampleRate = input->readInt();
  17227. const int bytesPerSec = input->readInt();
  17228. numChannels = numChans;
  17229. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17230. bitsPerSample = 8 * bytesPerFrame / numChans;
  17231. if (format == 3)
  17232. {
  17233. usesFloatingPointData = true;
  17234. }
  17235. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17236. {
  17237. if (length < 40) // too short
  17238. {
  17239. bytesPerFrame = 0;
  17240. }
  17241. else
  17242. {
  17243. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17244. ExtensibleWavSubFormat subFormat;
  17245. subFormat.data1 = input->readInt();
  17246. subFormat.data2 = input->readShort();
  17247. subFormat.data3 = input->readShort();
  17248. input->read (subFormat.data4, sizeof (subFormat.data4));
  17249. const ExtensibleWavSubFormat pcmFormat
  17250. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17251. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17252. {
  17253. const ExtensibleWavSubFormat ambisonicFormat
  17254. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17255. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17256. bytesPerFrame = 0;
  17257. }
  17258. }
  17259. }
  17260. else if (format != 1)
  17261. {
  17262. bytesPerFrame = 0;
  17263. }
  17264. hasGotType = true;
  17265. }
  17266. else if (chunkType == chunkName ("data"))
  17267. {
  17268. // get the data chunk's position
  17269. dataLength = length;
  17270. dataChunkStart = input->getPosition();
  17271. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17272. hasGotData = true;
  17273. }
  17274. else if (chunkType == chunkName ("bext"))
  17275. {
  17276. bwavChunkStart = input->getPosition();
  17277. bwavSize = length;
  17278. // Broadcast-wav extension chunk..
  17279. HeapBlock <BWAVChunk> bwav;
  17280. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17281. input->read (bwav, length);
  17282. bwav->copyTo (metadataValues);
  17283. }
  17284. else if (chunkType == chunkName ("smpl"))
  17285. {
  17286. HeapBlock <SMPLChunk> smpl;
  17287. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17288. input->read (smpl, length);
  17289. smpl->copyTo (metadataValues, length);
  17290. }
  17291. else if (chunkEnd <= input->getPosition())
  17292. {
  17293. break;
  17294. }
  17295. input->setPosition (chunkEnd);
  17296. }
  17297. }
  17298. }
  17299. }
  17300. ~WavAudioFormatReader()
  17301. {
  17302. }
  17303. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17304. int64 startSampleInFile, int numSamples)
  17305. {
  17306. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17307. if (samplesAvailable < numSamples)
  17308. {
  17309. for (int i = numDestChannels; --i >= 0;)
  17310. if (destSamples[i] != 0)
  17311. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17312. numSamples = (int) samplesAvailable;
  17313. }
  17314. if (numSamples <= 0)
  17315. return true;
  17316. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17317. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17318. char tempBuffer [tempBufSize];
  17319. while (numSamples > 0)
  17320. {
  17321. int* left = destSamples[0];
  17322. if (left != 0)
  17323. left += startOffsetInDestBuffer;
  17324. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17325. if (right != 0)
  17326. right += startOffsetInDestBuffer;
  17327. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17328. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17329. if (bytesRead < numThisTime * bytesPerFrame)
  17330. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17331. if (bitsPerSample == 16)
  17332. {
  17333. const short* src = reinterpret_cast <const short*> (tempBuffer);
  17334. if (numChannels > 1)
  17335. {
  17336. if (left == 0)
  17337. {
  17338. for (int i = numThisTime; --i >= 0;)
  17339. {
  17340. ++src;
  17341. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17342. }
  17343. }
  17344. else if (right == 0)
  17345. {
  17346. for (int i = numThisTime; --i >= 0;)
  17347. {
  17348. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17349. ++src;
  17350. }
  17351. }
  17352. else
  17353. {
  17354. for (int i = numThisTime; --i >= 0;)
  17355. {
  17356. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17357. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17358. }
  17359. }
  17360. }
  17361. else
  17362. {
  17363. for (int i = numThisTime; --i >= 0;)
  17364. {
  17365. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17366. }
  17367. }
  17368. }
  17369. else if (bitsPerSample == 24)
  17370. {
  17371. const char* src = tempBuffer;
  17372. if (numChannels > 1)
  17373. {
  17374. if (left == 0)
  17375. {
  17376. for (int i = numThisTime; --i >= 0;)
  17377. {
  17378. src += 3;
  17379. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17380. src += 3;
  17381. }
  17382. }
  17383. else if (right == 0)
  17384. {
  17385. for (int i = numThisTime; --i >= 0;)
  17386. {
  17387. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17388. src += 6;
  17389. }
  17390. }
  17391. else
  17392. {
  17393. for (int i = 0; i < numThisTime; ++i)
  17394. {
  17395. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17396. src += 3;
  17397. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17398. src += 3;
  17399. }
  17400. }
  17401. }
  17402. else
  17403. {
  17404. for (int i = 0; i < numThisTime; ++i)
  17405. {
  17406. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17407. src += 3;
  17408. }
  17409. }
  17410. }
  17411. else if (bitsPerSample == 32)
  17412. {
  17413. const unsigned int* src = (const unsigned int*) tempBuffer;
  17414. unsigned int* l = (unsigned int*) left;
  17415. unsigned int* r = (unsigned int*) right;
  17416. if (numChannels > 1)
  17417. {
  17418. if (l == 0)
  17419. {
  17420. for (int i = numThisTime; --i >= 0;)
  17421. {
  17422. ++src;
  17423. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17424. }
  17425. }
  17426. else if (r == 0)
  17427. {
  17428. for (int i = numThisTime; --i >= 0;)
  17429. {
  17430. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17431. ++src;
  17432. }
  17433. }
  17434. else
  17435. {
  17436. for (int i = numThisTime; --i >= 0;)
  17437. {
  17438. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17439. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17440. }
  17441. }
  17442. }
  17443. else
  17444. {
  17445. for (int i = numThisTime; --i >= 0;)
  17446. {
  17447. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17448. }
  17449. }
  17450. left = (int*)l;
  17451. right = (int*)r;
  17452. }
  17453. else if (bitsPerSample == 8)
  17454. {
  17455. const unsigned char* src = (const unsigned char*) tempBuffer;
  17456. if (numChannels > 1)
  17457. {
  17458. if (left == 0)
  17459. {
  17460. for (int i = numThisTime; --i >= 0;)
  17461. {
  17462. ++src;
  17463. *right++ = ((int) *src++ - 128) << 24;
  17464. }
  17465. }
  17466. else if (right == 0)
  17467. {
  17468. for (int i = numThisTime; --i >= 0;)
  17469. {
  17470. *left++ = ((int) *src++ - 128) << 24;
  17471. ++src;
  17472. }
  17473. }
  17474. else
  17475. {
  17476. for (int i = numThisTime; --i >= 0;)
  17477. {
  17478. *left++ = ((int) *src++ - 128) << 24;
  17479. *right++ = ((int) *src++ - 128) << 24;
  17480. }
  17481. }
  17482. }
  17483. else
  17484. {
  17485. for (int i = numThisTime; --i >= 0;)
  17486. {
  17487. *left++ = ((int)*src++ - 128) << 24;
  17488. }
  17489. }
  17490. }
  17491. startOffsetInDestBuffer += numThisTime;
  17492. numSamples -= numThisTime;
  17493. }
  17494. if (numSamples > 0)
  17495. {
  17496. for (int i = numDestChannels; --i >= 0;)
  17497. if (destSamples[i] != 0)
  17498. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17499. sizeof (int) * numSamples);
  17500. }
  17501. return true;
  17502. }
  17503. juce_UseDebuggingNewOperator
  17504. };
  17505. class WavAudioFormatWriter : public AudioFormatWriter
  17506. {
  17507. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17508. uint32 lengthInSamples, bytesWritten;
  17509. int64 headerPosition;
  17510. bool writeFailed;
  17511. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17512. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17513. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17514. void writeHeader()
  17515. {
  17516. const bool seekedOk = output->setPosition (headerPosition);
  17517. (void) seekedOk;
  17518. // if this fails, you've given it an output stream that can't seek! It needs
  17519. // to be able to seek back to write the header
  17520. jassert (seekedOk);
  17521. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17522. output->writeInt (chunkName ("RIFF"));
  17523. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17524. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17525. output->writeInt (chunkName ("WAVE"));
  17526. output->writeInt (chunkName ("fmt "));
  17527. output->writeInt (16);
  17528. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17529. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17530. output->writeShort ((short) numChannels);
  17531. output->writeInt ((int) sampleRate);
  17532. output->writeInt (bytesPerFrame * (int) sampleRate);
  17533. output->writeShort ((short) bytesPerFrame);
  17534. output->writeShort ((short) bitsPerSample);
  17535. if (bwavChunk.getSize() > 0)
  17536. {
  17537. output->writeInt (chunkName ("bext"));
  17538. output->writeInt ((int) bwavChunk.getSize());
  17539. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17540. }
  17541. if (smplChunk.getSize() > 0)
  17542. {
  17543. output->writeInt (chunkName ("smpl"));
  17544. output->writeInt ((int) smplChunk.getSize());
  17545. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17546. }
  17547. output->writeInt (chunkName ("data"));
  17548. output->writeInt (lengthInSamples * bytesPerFrame);
  17549. usesFloatingPointData = (bitsPerSample == 32);
  17550. }
  17551. public:
  17552. WavAudioFormatWriter (OutputStream* const out,
  17553. const double sampleRate_,
  17554. const unsigned int numChannels_,
  17555. const int bits,
  17556. const StringPairArray& metadataValues)
  17557. : AudioFormatWriter (out,
  17558. TRANS (wavFormatName),
  17559. sampleRate_,
  17560. numChannels_,
  17561. bits),
  17562. lengthInSamples (0),
  17563. bytesWritten (0),
  17564. writeFailed (false)
  17565. {
  17566. if (metadataValues.size() > 0)
  17567. {
  17568. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17569. smplChunk = SMPLChunk::createFrom (metadataValues);
  17570. }
  17571. headerPosition = out->getPosition();
  17572. writeHeader();
  17573. }
  17574. ~WavAudioFormatWriter()
  17575. {
  17576. writeHeader();
  17577. }
  17578. bool write (const int** data, int numSamples)
  17579. {
  17580. if (writeFailed)
  17581. return false;
  17582. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17583. tempBlock.ensureSize (bytes, false);
  17584. char* buffer = static_cast <char*> (tempBlock.getData());
  17585. const int* left = data[0];
  17586. const int* right = data[1];
  17587. if (right == 0)
  17588. right = left;
  17589. if (bitsPerSample == 16)
  17590. {
  17591. short* b = (short*) buffer;
  17592. if (numChannels > 1)
  17593. {
  17594. for (int i = numSamples; --i >= 0;)
  17595. {
  17596. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17597. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17598. }
  17599. }
  17600. else
  17601. {
  17602. for (int i = numSamples; --i >= 0;)
  17603. {
  17604. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17605. }
  17606. }
  17607. }
  17608. else if (bitsPerSample == 24)
  17609. {
  17610. char* b = buffer;
  17611. if (numChannels > 1)
  17612. {
  17613. for (int i = numSamples; --i >= 0;)
  17614. {
  17615. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17616. b += 3;
  17617. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17618. b += 3;
  17619. }
  17620. }
  17621. else
  17622. {
  17623. for (int i = numSamples; --i >= 0;)
  17624. {
  17625. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17626. b += 3;
  17627. }
  17628. }
  17629. }
  17630. else if (bitsPerSample == 32)
  17631. {
  17632. unsigned int* b = (unsigned int*) buffer;
  17633. if (numChannels > 1)
  17634. {
  17635. for (int i = numSamples; --i >= 0;)
  17636. {
  17637. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17638. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17639. }
  17640. }
  17641. else
  17642. {
  17643. for (int i = numSamples; --i >= 0;)
  17644. {
  17645. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17646. }
  17647. }
  17648. }
  17649. else if (bitsPerSample == 8)
  17650. {
  17651. unsigned char* b = (unsigned char*) buffer;
  17652. if (numChannels > 1)
  17653. {
  17654. for (int i = numSamples; --i >= 0;)
  17655. {
  17656. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17657. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17658. }
  17659. }
  17660. else
  17661. {
  17662. for (int i = numSamples; --i >= 0;)
  17663. {
  17664. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17665. }
  17666. }
  17667. }
  17668. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17669. || ! output->write (buffer, bytes))
  17670. {
  17671. // failed to write to disk, so let's try writing the header.
  17672. // If it's just run out of disk space, then if it does manage
  17673. // to write the header, we'll still have a useable file..
  17674. writeHeader();
  17675. writeFailed = true;
  17676. return false;
  17677. }
  17678. else
  17679. {
  17680. bytesWritten += bytes;
  17681. lengthInSamples += numSamples;
  17682. return true;
  17683. }
  17684. }
  17685. juce_UseDebuggingNewOperator
  17686. };
  17687. WavAudioFormat::WavAudioFormat()
  17688. : AudioFormat (TRANS (wavFormatName), (const juce_wchar**) wavExtensions)
  17689. {
  17690. }
  17691. WavAudioFormat::~WavAudioFormat()
  17692. {
  17693. }
  17694. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17695. {
  17696. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17697. return Array <int> (rates);
  17698. }
  17699. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17700. {
  17701. const int depths[] = { 8, 16, 24, 32, 0 };
  17702. return Array <int> (depths);
  17703. }
  17704. bool WavAudioFormat::canDoStereo()
  17705. {
  17706. return true;
  17707. }
  17708. bool WavAudioFormat::canDoMono()
  17709. {
  17710. return true;
  17711. }
  17712. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17713. const bool deleteStreamIfOpeningFails)
  17714. {
  17715. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17716. if (r->sampleRate != 0)
  17717. return r.release();
  17718. if (! deleteStreamIfOpeningFails)
  17719. r->input = 0;
  17720. return 0;
  17721. }
  17722. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17723. double sampleRate,
  17724. unsigned int numChannels,
  17725. int bitsPerSample,
  17726. const StringPairArray& metadataValues,
  17727. int /*qualityOptionIndex*/)
  17728. {
  17729. if (getPossibleBitDepths().contains (bitsPerSample))
  17730. {
  17731. return new WavAudioFormatWriter (out,
  17732. sampleRate,
  17733. numChannels,
  17734. bitsPerSample,
  17735. metadataValues);
  17736. }
  17737. return 0;
  17738. }
  17739. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  17740. {
  17741. TemporaryFile tempFile (file);
  17742. WavAudioFormat wav;
  17743. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  17744. if (reader != 0)
  17745. {
  17746. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  17747. if (outStream != 0)
  17748. {
  17749. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  17750. reader->numChannels, reader->bitsPerSample,
  17751. metadata, 0));
  17752. if (writer != 0)
  17753. {
  17754. outStream.release();
  17755. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  17756. writer = 0;
  17757. reader = 0;
  17758. return ok && tempFile.overwriteTargetFileWithTemporary();
  17759. }
  17760. }
  17761. }
  17762. return false;
  17763. }
  17764. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  17765. {
  17766. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  17767. if (reader != 0)
  17768. {
  17769. const int64 bwavPos = reader->bwavChunkStart;
  17770. const int64 bwavSize = reader->bwavSize;
  17771. reader = 0;
  17772. if (bwavSize > 0)
  17773. {
  17774. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  17775. if (chunk.getSize() <= (size_t) bwavSize)
  17776. {
  17777. // the new one will fit in the space available, so write it directly..
  17778. const int64 oldSize = wavFile.getSize();
  17779. {
  17780. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  17781. out->setPosition (bwavPos);
  17782. out->write (chunk.getData(), (int) chunk.getSize());
  17783. out->setPosition (oldSize);
  17784. }
  17785. jassert (wavFile.getSize() == oldSize);
  17786. return true;
  17787. }
  17788. }
  17789. }
  17790. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  17791. }
  17792. END_JUCE_NAMESPACE
  17793. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  17794. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17795. BEGIN_JUCE_NAMESPACE
  17796. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  17797. const bool deleteReaderWhenThisIsDeleted)
  17798. : reader (reader_),
  17799. deleteReader (deleteReaderWhenThisIsDeleted),
  17800. nextPlayPos (0),
  17801. looping (false)
  17802. {
  17803. jassert (reader != 0);
  17804. }
  17805. AudioFormatReaderSource::~AudioFormatReaderSource()
  17806. {
  17807. releaseResources();
  17808. if (deleteReader)
  17809. delete reader;
  17810. }
  17811. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  17812. {
  17813. nextPlayPos = newPosition;
  17814. }
  17815. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  17816. {
  17817. looping = shouldLoop;
  17818. }
  17819. int AudioFormatReaderSource::getNextReadPosition() const
  17820. {
  17821. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  17822. : nextPlayPos;
  17823. }
  17824. int AudioFormatReaderSource::getTotalLength() const
  17825. {
  17826. return (int) reader->lengthInSamples;
  17827. }
  17828. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  17829. double /*sampleRate*/)
  17830. {
  17831. }
  17832. void AudioFormatReaderSource::releaseResources()
  17833. {
  17834. }
  17835. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  17836. {
  17837. if (info.numSamples > 0)
  17838. {
  17839. const int start = nextPlayPos;
  17840. if (looping)
  17841. {
  17842. const int newStart = start % (int) reader->lengthInSamples;
  17843. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  17844. if (newEnd > newStart)
  17845. {
  17846. info.buffer->readFromAudioReader (reader,
  17847. info.startSample,
  17848. newEnd - newStart,
  17849. newStart,
  17850. true, true);
  17851. }
  17852. else
  17853. {
  17854. const int endSamps = (int) reader->lengthInSamples - newStart;
  17855. info.buffer->readFromAudioReader (reader,
  17856. info.startSample,
  17857. endSamps,
  17858. newStart,
  17859. true, true);
  17860. info.buffer->readFromAudioReader (reader,
  17861. info.startSample + endSamps,
  17862. newEnd,
  17863. 0,
  17864. true, true);
  17865. }
  17866. nextPlayPos = newEnd;
  17867. }
  17868. else
  17869. {
  17870. info.buffer->readFromAudioReader (reader,
  17871. info.startSample,
  17872. info.numSamples,
  17873. start,
  17874. true, true);
  17875. nextPlayPos += info.numSamples;
  17876. }
  17877. }
  17878. }
  17879. END_JUCE_NAMESPACE
  17880. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17881. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  17882. BEGIN_JUCE_NAMESPACE
  17883. AudioSourcePlayer::AudioSourcePlayer()
  17884. : source (0),
  17885. sampleRate (0),
  17886. bufferSize (0),
  17887. tempBuffer (2, 8),
  17888. lastGain (1.0f),
  17889. gain (1.0f)
  17890. {
  17891. }
  17892. AudioSourcePlayer::~AudioSourcePlayer()
  17893. {
  17894. setSource (0);
  17895. }
  17896. void AudioSourcePlayer::setSource (AudioSource* newSource)
  17897. {
  17898. if (source != newSource)
  17899. {
  17900. AudioSource* const oldSource = source;
  17901. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  17902. newSource->prepareToPlay (bufferSize, sampleRate);
  17903. {
  17904. const ScopedLock sl (readLock);
  17905. source = newSource;
  17906. }
  17907. if (oldSource != 0)
  17908. oldSource->releaseResources();
  17909. }
  17910. }
  17911. void AudioSourcePlayer::setGain (const float newGain) throw()
  17912. {
  17913. gain = newGain;
  17914. }
  17915. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  17916. int totalNumInputChannels,
  17917. float** outputChannelData,
  17918. int totalNumOutputChannels,
  17919. int numSamples)
  17920. {
  17921. // these should have been prepared by audioDeviceAboutToStart()...
  17922. jassert (sampleRate > 0 && bufferSize > 0);
  17923. const ScopedLock sl (readLock);
  17924. if (source != 0)
  17925. {
  17926. AudioSourceChannelInfo info;
  17927. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  17928. // messy stuff needed to compact the channels down into an array
  17929. // of non-zero pointers..
  17930. for (i = 0; i < totalNumInputChannels; ++i)
  17931. {
  17932. if (inputChannelData[i] != 0)
  17933. {
  17934. inputChans [numInputs++] = inputChannelData[i];
  17935. if (numInputs >= numElementsInArray (inputChans))
  17936. break;
  17937. }
  17938. }
  17939. for (i = 0; i < totalNumOutputChannels; ++i)
  17940. {
  17941. if (outputChannelData[i] != 0)
  17942. {
  17943. outputChans [numOutputs++] = outputChannelData[i];
  17944. if (numOutputs >= numElementsInArray (outputChans))
  17945. break;
  17946. }
  17947. }
  17948. if (numInputs > numOutputs)
  17949. {
  17950. // if there aren't enough output channels for the number of
  17951. // inputs, we need to create some temporary extra ones (can't
  17952. // use the input data in case it gets written to)
  17953. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  17954. false, false, true);
  17955. for (i = 0; i < numOutputs; ++i)
  17956. {
  17957. channels[numActiveChans] = outputChans[i];
  17958. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  17959. ++numActiveChans;
  17960. }
  17961. for (i = numOutputs; i < numInputs; ++i)
  17962. {
  17963. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  17964. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  17965. ++numActiveChans;
  17966. }
  17967. }
  17968. else
  17969. {
  17970. for (i = 0; i < numInputs; ++i)
  17971. {
  17972. channels[numActiveChans] = outputChans[i];
  17973. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  17974. ++numActiveChans;
  17975. }
  17976. for (i = numInputs; i < numOutputs; ++i)
  17977. {
  17978. channels[numActiveChans] = outputChans[i];
  17979. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  17980. ++numActiveChans;
  17981. }
  17982. }
  17983. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  17984. info.buffer = &buffer;
  17985. info.startSample = 0;
  17986. info.numSamples = numSamples;
  17987. source->getNextAudioBlock (info);
  17988. for (i = info.buffer->getNumChannels(); --i >= 0;)
  17989. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  17990. lastGain = gain;
  17991. }
  17992. else
  17993. {
  17994. for (int i = 0; i < totalNumOutputChannels; ++i)
  17995. if (outputChannelData[i] != 0)
  17996. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  17997. }
  17998. }
  17999. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18000. {
  18001. sampleRate = device->getCurrentSampleRate();
  18002. bufferSize = device->getCurrentBufferSizeSamples();
  18003. zeromem (channels, sizeof (channels));
  18004. if (source != 0)
  18005. source->prepareToPlay (bufferSize, sampleRate);
  18006. }
  18007. void AudioSourcePlayer::audioDeviceStopped()
  18008. {
  18009. if (source != 0)
  18010. source->releaseResources();
  18011. sampleRate = 0.0;
  18012. bufferSize = 0;
  18013. tempBuffer.setSize (2, 8);
  18014. }
  18015. END_JUCE_NAMESPACE
  18016. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18017. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18018. BEGIN_JUCE_NAMESPACE
  18019. AudioTransportSource::AudioTransportSource()
  18020. : source (0),
  18021. resamplerSource (0),
  18022. bufferingSource (0),
  18023. positionableSource (0),
  18024. masterSource (0),
  18025. gain (1.0f),
  18026. lastGain (1.0f),
  18027. playing (false),
  18028. stopped (true),
  18029. sampleRate (44100.0),
  18030. sourceSampleRate (0.0),
  18031. blockSize (128),
  18032. readAheadBufferSize (0),
  18033. isPrepared (false),
  18034. inputStreamEOF (false)
  18035. {
  18036. }
  18037. AudioTransportSource::~AudioTransportSource()
  18038. {
  18039. setSource (0);
  18040. releaseResources();
  18041. }
  18042. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18043. int readAheadBufferSize_,
  18044. double sourceSampleRateToCorrectFor)
  18045. {
  18046. if (source == newSource)
  18047. {
  18048. if (source == 0)
  18049. return;
  18050. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18051. }
  18052. readAheadBufferSize = readAheadBufferSize_;
  18053. sourceSampleRate = sourceSampleRateToCorrectFor;
  18054. ResamplingAudioSource* newResamplerSource = 0;
  18055. BufferingAudioSource* newBufferingSource = 0;
  18056. PositionableAudioSource* newPositionableSource = 0;
  18057. AudioSource* newMasterSource = 0;
  18058. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18059. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18060. AudioSource* oldMasterSource = masterSource;
  18061. if (newSource != 0)
  18062. {
  18063. newPositionableSource = newSource;
  18064. if (readAheadBufferSize_ > 0)
  18065. newPositionableSource = newBufferingSource
  18066. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18067. newPositionableSource->setNextReadPosition (0);
  18068. if (sourceSampleRateToCorrectFor != 0)
  18069. newMasterSource = newResamplerSource
  18070. = new ResamplingAudioSource (newPositionableSource, false);
  18071. else
  18072. newMasterSource = newPositionableSource;
  18073. if (isPrepared)
  18074. {
  18075. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18076. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18077. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18078. }
  18079. }
  18080. {
  18081. const ScopedLock sl (callbackLock);
  18082. source = newSource;
  18083. resamplerSource = newResamplerSource;
  18084. bufferingSource = newBufferingSource;
  18085. masterSource = newMasterSource;
  18086. positionableSource = newPositionableSource;
  18087. playing = false;
  18088. }
  18089. if (oldMasterSource != 0)
  18090. oldMasterSource->releaseResources();
  18091. }
  18092. void AudioTransportSource::start()
  18093. {
  18094. if ((! playing) && masterSource != 0)
  18095. {
  18096. {
  18097. const ScopedLock sl (callbackLock);
  18098. playing = true;
  18099. stopped = false;
  18100. inputStreamEOF = false;
  18101. }
  18102. sendChangeMessage (this);
  18103. }
  18104. }
  18105. void AudioTransportSource::stop()
  18106. {
  18107. if (playing)
  18108. {
  18109. {
  18110. const ScopedLock sl (callbackLock);
  18111. playing = false;
  18112. }
  18113. int n = 500;
  18114. while (--n >= 0 && ! stopped)
  18115. Thread::sleep (2);
  18116. sendChangeMessage (this);
  18117. }
  18118. }
  18119. void AudioTransportSource::setPosition (double newPosition)
  18120. {
  18121. if (sampleRate > 0.0)
  18122. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18123. }
  18124. double AudioTransportSource::getCurrentPosition() const
  18125. {
  18126. if (sampleRate > 0.0)
  18127. return getNextReadPosition() / sampleRate;
  18128. else
  18129. return 0.0;
  18130. }
  18131. void AudioTransportSource::setNextReadPosition (int newPosition)
  18132. {
  18133. if (positionableSource != 0)
  18134. {
  18135. if (sampleRate > 0 && sourceSampleRate > 0)
  18136. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18137. positionableSource->setNextReadPosition (newPosition);
  18138. }
  18139. }
  18140. int AudioTransportSource::getNextReadPosition() const
  18141. {
  18142. if (positionableSource != 0)
  18143. {
  18144. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18145. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18146. }
  18147. return 0;
  18148. }
  18149. int AudioTransportSource::getTotalLength() const
  18150. {
  18151. const ScopedLock sl (callbackLock);
  18152. if (positionableSource != 0)
  18153. {
  18154. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18155. return roundToInt (positionableSource->getTotalLength() * ratio);
  18156. }
  18157. return 0;
  18158. }
  18159. bool AudioTransportSource::isLooping() const
  18160. {
  18161. const ScopedLock sl (callbackLock);
  18162. return positionableSource != 0
  18163. && positionableSource->isLooping();
  18164. }
  18165. void AudioTransportSource::setGain (const float newGain) throw()
  18166. {
  18167. gain = newGain;
  18168. }
  18169. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18170. double sampleRate_)
  18171. {
  18172. const ScopedLock sl (callbackLock);
  18173. sampleRate = sampleRate_;
  18174. blockSize = samplesPerBlockExpected;
  18175. if (masterSource != 0)
  18176. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18177. if (resamplerSource != 0 && sourceSampleRate != 0)
  18178. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18179. isPrepared = true;
  18180. }
  18181. void AudioTransportSource::releaseResources()
  18182. {
  18183. const ScopedLock sl (callbackLock);
  18184. if (masterSource != 0)
  18185. masterSource->releaseResources();
  18186. isPrepared = false;
  18187. }
  18188. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18189. {
  18190. const ScopedLock sl (callbackLock);
  18191. inputStreamEOF = false;
  18192. if (masterSource != 0 && ! stopped)
  18193. {
  18194. masterSource->getNextAudioBlock (info);
  18195. if (! playing)
  18196. {
  18197. // just stopped playing, so fade out the last block..
  18198. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18199. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18200. if (info.numSamples > 256)
  18201. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18202. }
  18203. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18204. && ! positionableSource->isLooping())
  18205. {
  18206. playing = false;
  18207. inputStreamEOF = true;
  18208. sendChangeMessage (this);
  18209. }
  18210. stopped = ! playing;
  18211. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18212. {
  18213. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18214. lastGain, gain);
  18215. }
  18216. }
  18217. else
  18218. {
  18219. info.clearActiveBufferRegion();
  18220. stopped = true;
  18221. }
  18222. lastGain = gain;
  18223. }
  18224. END_JUCE_NAMESPACE
  18225. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18226. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18227. BEGIN_JUCE_NAMESPACE
  18228. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18229. public Thread,
  18230. private Timer
  18231. {
  18232. public:
  18233. SharedBufferingAudioSourceThread()
  18234. : Thread ("Audio Buffer")
  18235. {
  18236. }
  18237. ~SharedBufferingAudioSourceThread()
  18238. {
  18239. stopThread (10000);
  18240. clearSingletonInstance();
  18241. }
  18242. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18243. void addSource (BufferingAudioSource* source)
  18244. {
  18245. const ScopedLock sl (lock);
  18246. if (! sources.contains (source))
  18247. {
  18248. sources.add (source);
  18249. startThread();
  18250. stopTimer();
  18251. }
  18252. notify();
  18253. }
  18254. void removeSource (BufferingAudioSource* source)
  18255. {
  18256. const ScopedLock sl (lock);
  18257. sources.removeValue (source);
  18258. if (sources.size() == 0)
  18259. startTimer (5000);
  18260. }
  18261. private:
  18262. Array <BufferingAudioSource*> sources;
  18263. CriticalSection lock;
  18264. void run()
  18265. {
  18266. while (! threadShouldExit())
  18267. {
  18268. bool busy = false;
  18269. for (int i = sources.size(); --i >= 0;)
  18270. {
  18271. if (threadShouldExit())
  18272. return;
  18273. const ScopedLock sl (lock);
  18274. BufferingAudioSource* const b = sources[i];
  18275. if (b != 0 && b->readNextBufferChunk())
  18276. busy = true;
  18277. }
  18278. if (! busy)
  18279. wait (500);
  18280. }
  18281. }
  18282. void timerCallback()
  18283. {
  18284. stopTimer();
  18285. if (sources.size() == 0)
  18286. deleteInstance();
  18287. }
  18288. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18289. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18290. };
  18291. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18292. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18293. const bool deleteSourceWhenDeleted_,
  18294. int numberOfSamplesToBuffer_)
  18295. : source (source_),
  18296. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18297. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18298. buffer (2, 0),
  18299. bufferValidStart (0),
  18300. bufferValidEnd (0),
  18301. nextPlayPos (0),
  18302. wasSourceLooping (false)
  18303. {
  18304. jassert (source_ != 0);
  18305. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18306. // not using a larger buffer..
  18307. }
  18308. BufferingAudioSource::~BufferingAudioSource()
  18309. {
  18310. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18311. if (thread != 0)
  18312. thread->removeSource (this);
  18313. if (deleteSourceWhenDeleted)
  18314. delete source;
  18315. }
  18316. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18317. {
  18318. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18319. sampleRate = sampleRate_;
  18320. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18321. buffer.clear();
  18322. bufferValidStart = 0;
  18323. bufferValidEnd = 0;
  18324. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18325. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18326. buffer.getNumSamples() / 2))
  18327. {
  18328. SharedBufferingAudioSourceThread::getInstance()->notify();
  18329. Thread::sleep (5);
  18330. }
  18331. }
  18332. void BufferingAudioSource::releaseResources()
  18333. {
  18334. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18335. if (thread != 0)
  18336. thread->removeSource (this);
  18337. buffer.setSize (2, 0);
  18338. source->releaseResources();
  18339. }
  18340. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18341. {
  18342. const ScopedLock sl (bufferStartPosLock);
  18343. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18344. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18345. if (validStart == validEnd)
  18346. {
  18347. // total cache miss
  18348. info.clearActiveBufferRegion();
  18349. }
  18350. else
  18351. {
  18352. if (validStart > 0)
  18353. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18354. if (validEnd < info.numSamples)
  18355. info.buffer->clear (info.startSample + validEnd,
  18356. info.numSamples - validEnd); // partial cache miss at end
  18357. if (validStart < validEnd)
  18358. {
  18359. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18360. {
  18361. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18362. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18363. if (startBufferIndex < endBufferIndex)
  18364. {
  18365. info.buffer->copyFrom (chan, info.startSample + validStart,
  18366. buffer,
  18367. chan, startBufferIndex,
  18368. validEnd - validStart);
  18369. }
  18370. else
  18371. {
  18372. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18373. info.buffer->copyFrom (chan, info.startSample + validStart,
  18374. buffer,
  18375. chan, startBufferIndex,
  18376. initialSize);
  18377. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18378. buffer,
  18379. chan, 0,
  18380. (validEnd - validStart) - initialSize);
  18381. }
  18382. }
  18383. }
  18384. nextPlayPos += info.numSamples;
  18385. if (source->isLooping() && nextPlayPos > 0)
  18386. nextPlayPos %= source->getTotalLength();
  18387. }
  18388. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18389. if (thread != 0)
  18390. thread->notify();
  18391. }
  18392. int BufferingAudioSource::getNextReadPosition() const
  18393. {
  18394. return (source->isLooping() && nextPlayPos > 0)
  18395. ? nextPlayPos % source->getTotalLength()
  18396. : nextPlayPos;
  18397. }
  18398. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18399. {
  18400. const ScopedLock sl (bufferStartPosLock);
  18401. nextPlayPos = newPosition;
  18402. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18403. if (thread != 0)
  18404. thread->notify();
  18405. }
  18406. bool BufferingAudioSource::readNextBufferChunk()
  18407. {
  18408. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18409. {
  18410. const ScopedLock sl (bufferStartPosLock);
  18411. if (wasSourceLooping != isLooping())
  18412. {
  18413. wasSourceLooping = isLooping();
  18414. bufferValidStart = 0;
  18415. bufferValidEnd = 0;
  18416. }
  18417. newBVS = jmax (0, nextPlayPos);
  18418. newBVE = newBVS + buffer.getNumSamples() - 4;
  18419. sectionToReadStart = 0;
  18420. sectionToReadEnd = 0;
  18421. const int maxChunkSize = 2048;
  18422. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18423. {
  18424. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18425. sectionToReadStart = newBVS;
  18426. sectionToReadEnd = newBVE;
  18427. bufferValidStart = 0;
  18428. bufferValidEnd = 0;
  18429. }
  18430. else if (abs (newBVS - bufferValidStart) > 512
  18431. || abs (newBVE - bufferValidEnd) > 512)
  18432. {
  18433. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18434. sectionToReadStart = bufferValidEnd;
  18435. sectionToReadEnd = newBVE;
  18436. bufferValidStart = newBVS;
  18437. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18438. }
  18439. }
  18440. if (sectionToReadStart != sectionToReadEnd)
  18441. {
  18442. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18443. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18444. if (bufferIndexStart < bufferIndexEnd)
  18445. {
  18446. readBufferSection (sectionToReadStart,
  18447. sectionToReadEnd - sectionToReadStart,
  18448. bufferIndexStart);
  18449. }
  18450. else
  18451. {
  18452. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18453. readBufferSection (sectionToReadStart,
  18454. initialSize,
  18455. bufferIndexStart);
  18456. readBufferSection (sectionToReadStart + initialSize,
  18457. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18458. 0);
  18459. }
  18460. const ScopedLock sl2 (bufferStartPosLock);
  18461. bufferValidStart = newBVS;
  18462. bufferValidEnd = newBVE;
  18463. return true;
  18464. }
  18465. else
  18466. {
  18467. return false;
  18468. }
  18469. }
  18470. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18471. {
  18472. if (source->getNextReadPosition() != start)
  18473. source->setNextReadPosition (start);
  18474. AudioSourceChannelInfo info;
  18475. info.buffer = &buffer;
  18476. info.startSample = bufferOffset;
  18477. info.numSamples = length;
  18478. source->getNextAudioBlock (info);
  18479. }
  18480. END_JUCE_NAMESPACE
  18481. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18482. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18483. BEGIN_JUCE_NAMESPACE
  18484. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18485. const bool deleteSourceWhenDeleted_)
  18486. : requiredNumberOfChannels (2),
  18487. source (source_),
  18488. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18489. buffer (2, 16)
  18490. {
  18491. remappedInfo.buffer = &buffer;
  18492. remappedInfo.startSample = 0;
  18493. }
  18494. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18495. {
  18496. if (deleteSourceWhenDeleted)
  18497. delete source;
  18498. }
  18499. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18500. {
  18501. const ScopedLock sl (lock);
  18502. requiredNumberOfChannels = requiredNumberOfChannels_;
  18503. }
  18504. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18505. {
  18506. const ScopedLock sl (lock);
  18507. remappedInputs.clear();
  18508. remappedOutputs.clear();
  18509. }
  18510. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18511. {
  18512. const ScopedLock sl (lock);
  18513. while (remappedInputs.size() < destIndex)
  18514. remappedInputs.add (-1);
  18515. remappedInputs.set (destIndex, sourceIndex);
  18516. }
  18517. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18518. {
  18519. const ScopedLock sl (lock);
  18520. while (remappedOutputs.size() < sourceIndex)
  18521. remappedOutputs.add (-1);
  18522. remappedOutputs.set (sourceIndex, destIndex);
  18523. }
  18524. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18525. {
  18526. const ScopedLock sl (lock);
  18527. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18528. return remappedInputs.getUnchecked (inputChannelIndex);
  18529. return -1;
  18530. }
  18531. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18532. {
  18533. const ScopedLock sl (lock);
  18534. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18535. return remappedOutputs .getUnchecked (outputChannelIndex);
  18536. return -1;
  18537. }
  18538. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18539. {
  18540. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18541. }
  18542. void ChannelRemappingAudioSource::releaseResources()
  18543. {
  18544. source->releaseResources();
  18545. }
  18546. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18547. {
  18548. const ScopedLock sl (lock);
  18549. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18550. const int numChans = bufferToFill.buffer->getNumChannels();
  18551. int i;
  18552. for (i = 0; i < buffer.getNumChannels(); ++i)
  18553. {
  18554. const int remappedChan = getRemappedInputChannel (i);
  18555. if (remappedChan >= 0 && remappedChan < numChans)
  18556. {
  18557. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18558. remappedChan,
  18559. bufferToFill.startSample,
  18560. bufferToFill.numSamples);
  18561. }
  18562. else
  18563. {
  18564. buffer.clear (i, 0, bufferToFill.numSamples);
  18565. }
  18566. }
  18567. remappedInfo.numSamples = bufferToFill.numSamples;
  18568. source->getNextAudioBlock (remappedInfo);
  18569. bufferToFill.clearActiveBufferRegion();
  18570. for (i = 0; i < requiredNumberOfChannels; ++i)
  18571. {
  18572. const int remappedChan = getRemappedOutputChannel (i);
  18573. if (remappedChan >= 0 && remappedChan < numChans)
  18574. {
  18575. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18576. buffer, i, 0, bufferToFill.numSamples);
  18577. }
  18578. }
  18579. }
  18580. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18581. {
  18582. XmlElement* e = new XmlElement ("MAPPINGS");
  18583. String ins, outs;
  18584. int i;
  18585. const ScopedLock sl (lock);
  18586. for (i = 0; i < remappedInputs.size(); ++i)
  18587. ins << remappedInputs.getUnchecked(i) << ' ';
  18588. for (i = 0; i < remappedOutputs.size(); ++i)
  18589. outs << remappedOutputs.getUnchecked(i) << ' ';
  18590. e->setAttribute ("inputs", ins.trimEnd());
  18591. e->setAttribute ("outputs", outs.trimEnd());
  18592. return e;
  18593. }
  18594. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18595. {
  18596. if (e.hasTagName ("MAPPINGS"))
  18597. {
  18598. const ScopedLock sl (lock);
  18599. clearAllMappings();
  18600. StringArray ins, outs;
  18601. ins.addTokens (e.getStringAttribute ("inputs"), false);
  18602. outs.addTokens (e.getStringAttribute ("outputs"), false);
  18603. int i;
  18604. for (i = 0; i < ins.size(); ++i)
  18605. remappedInputs.add (ins[i].getIntValue());
  18606. for (i = 0; i < outs.size(); ++i)
  18607. remappedOutputs.add (outs[i].getIntValue());
  18608. }
  18609. }
  18610. END_JUCE_NAMESPACE
  18611. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18612. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18613. BEGIN_JUCE_NAMESPACE
  18614. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18615. const bool deleteInputWhenDeleted_)
  18616. : input (inputSource),
  18617. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18618. {
  18619. jassert (inputSource != 0);
  18620. for (int i = 2; --i >= 0;)
  18621. iirFilters.add (new IIRFilter());
  18622. }
  18623. IIRFilterAudioSource::~IIRFilterAudioSource()
  18624. {
  18625. if (deleteInputWhenDeleted)
  18626. delete input;
  18627. }
  18628. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18629. {
  18630. for (int i = iirFilters.size(); --i >= 0;)
  18631. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18632. }
  18633. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18634. {
  18635. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18636. for (int i = iirFilters.size(); --i >= 0;)
  18637. iirFilters.getUnchecked(i)->reset();
  18638. }
  18639. void IIRFilterAudioSource::releaseResources()
  18640. {
  18641. input->releaseResources();
  18642. }
  18643. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18644. {
  18645. input->getNextAudioBlock (bufferToFill);
  18646. const int numChannels = bufferToFill.buffer->getNumChannels();
  18647. while (numChannels > iirFilters.size())
  18648. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18649. for (int i = 0; i < numChannels; ++i)
  18650. iirFilters.getUnchecked(i)
  18651. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18652. bufferToFill.numSamples);
  18653. }
  18654. END_JUCE_NAMESPACE
  18655. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18656. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18657. BEGIN_JUCE_NAMESPACE
  18658. MixerAudioSource::MixerAudioSource()
  18659. : tempBuffer (2, 0),
  18660. currentSampleRate (0.0),
  18661. bufferSizeExpected (0)
  18662. {
  18663. }
  18664. MixerAudioSource::~MixerAudioSource()
  18665. {
  18666. removeAllInputs();
  18667. }
  18668. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18669. {
  18670. if (input != 0 && ! inputs.contains (input))
  18671. {
  18672. double localRate;
  18673. int localBufferSize;
  18674. {
  18675. const ScopedLock sl (lock);
  18676. localRate = currentSampleRate;
  18677. localBufferSize = bufferSizeExpected;
  18678. }
  18679. if (localRate != 0.0)
  18680. input->prepareToPlay (localBufferSize, localRate);
  18681. const ScopedLock sl (lock);
  18682. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18683. inputs.add (input);
  18684. }
  18685. }
  18686. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18687. {
  18688. if (input != 0)
  18689. {
  18690. int index;
  18691. {
  18692. const ScopedLock sl (lock);
  18693. index = inputs.indexOf (input);
  18694. if (index >= 0)
  18695. {
  18696. inputsToDelete.shiftBits (index, 1);
  18697. inputs.remove (index);
  18698. }
  18699. }
  18700. if (index >= 0)
  18701. {
  18702. input->releaseResources();
  18703. if (deleteInput)
  18704. delete input;
  18705. }
  18706. }
  18707. }
  18708. void MixerAudioSource::removeAllInputs()
  18709. {
  18710. VoidArray inputsCopy;
  18711. BigInteger inputsToDeleteCopy;
  18712. {
  18713. const ScopedLock sl (lock);
  18714. inputsCopy = inputs;
  18715. inputsToDeleteCopy = inputsToDelete;
  18716. }
  18717. for (int i = inputsCopy.size(); --i >= 0;)
  18718. if (inputsToDeleteCopy[i])
  18719. delete (AudioSource*) inputsCopy[i];
  18720. }
  18721. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18722. {
  18723. tempBuffer.setSize (2, samplesPerBlockExpected);
  18724. const ScopedLock sl (lock);
  18725. currentSampleRate = sampleRate;
  18726. bufferSizeExpected = samplesPerBlockExpected;
  18727. for (int i = inputs.size(); --i >= 0;)
  18728. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18729. sampleRate);
  18730. }
  18731. void MixerAudioSource::releaseResources()
  18732. {
  18733. const ScopedLock sl (lock);
  18734. for (int i = inputs.size(); --i >= 0;)
  18735. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  18736. tempBuffer.setSize (2, 0);
  18737. currentSampleRate = 0;
  18738. bufferSizeExpected = 0;
  18739. }
  18740. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18741. {
  18742. const ScopedLock sl (lock);
  18743. if (inputs.size() > 0)
  18744. {
  18745. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  18746. if (inputs.size() > 1)
  18747. {
  18748. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  18749. info.buffer->getNumSamples());
  18750. AudioSourceChannelInfo info2;
  18751. info2.buffer = &tempBuffer;
  18752. info2.numSamples = info.numSamples;
  18753. info2.startSample = 0;
  18754. for (int i = 1; i < inputs.size(); ++i)
  18755. {
  18756. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  18757. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  18758. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  18759. }
  18760. }
  18761. }
  18762. else
  18763. {
  18764. info.clearActiveBufferRegion();
  18765. }
  18766. }
  18767. END_JUCE_NAMESPACE
  18768. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  18769. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  18770. BEGIN_JUCE_NAMESPACE
  18771. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  18772. const bool deleteInputWhenDeleted_)
  18773. : input (inputSource),
  18774. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  18775. ratio (1.0),
  18776. lastRatio (1.0),
  18777. buffer (2, 0),
  18778. sampsInBuffer (0)
  18779. {
  18780. jassert (input != 0);
  18781. }
  18782. ResamplingAudioSource::~ResamplingAudioSource()
  18783. {
  18784. if (deleteInputWhenDeleted)
  18785. delete input;
  18786. }
  18787. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  18788. {
  18789. jassert (samplesInPerOutputSample > 0);
  18790. const ScopedLock sl (ratioLock);
  18791. ratio = jmax (0.0, samplesInPerOutputSample);
  18792. }
  18793. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  18794. double sampleRate)
  18795. {
  18796. const ScopedLock sl (ratioLock);
  18797. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18798. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  18799. buffer.clear();
  18800. sampsInBuffer = 0;
  18801. bufferPos = 0;
  18802. subSampleOffset = 0.0;
  18803. createLowPass (ratio);
  18804. resetFilters();
  18805. }
  18806. void ResamplingAudioSource::releaseResources()
  18807. {
  18808. input->releaseResources();
  18809. buffer.setSize (2, 0);
  18810. }
  18811. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18812. {
  18813. const ScopedLock sl (ratioLock);
  18814. if (lastRatio != ratio)
  18815. {
  18816. createLowPass (ratio);
  18817. lastRatio = ratio;
  18818. }
  18819. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  18820. int bufferSize = buffer.getNumSamples();
  18821. if (bufferSize < sampsNeeded + 8)
  18822. {
  18823. bufferPos %= bufferSize;
  18824. bufferSize = sampsNeeded + 32;
  18825. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  18826. }
  18827. bufferPos %= bufferSize;
  18828. int endOfBufferPos = bufferPos + sampsInBuffer;
  18829. while (sampsNeeded > sampsInBuffer)
  18830. {
  18831. endOfBufferPos %= bufferSize;
  18832. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  18833. bufferSize - endOfBufferPos);
  18834. AudioSourceChannelInfo readInfo;
  18835. readInfo.buffer = &buffer;
  18836. readInfo.numSamples = numToDo;
  18837. readInfo.startSample = endOfBufferPos;
  18838. input->getNextAudioBlock (readInfo);
  18839. if (ratio > 1.0001)
  18840. {
  18841. // for down-sampling, pre-apply the filter..
  18842. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18843. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  18844. }
  18845. sampsInBuffer += numToDo;
  18846. endOfBufferPos += numToDo;
  18847. }
  18848. float* dl = info.buffer->getSampleData (0, info.startSample);
  18849. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  18850. const float* const bl = buffer.getSampleData (0, 0);
  18851. const float* const br = buffer.getSampleData (1, 0);
  18852. int nextPos = (bufferPos + 1) % bufferSize;
  18853. for (int m = info.numSamples; --m >= 0;)
  18854. {
  18855. const float alpha = (float) subSampleOffset;
  18856. const float invAlpha = 1.0f - alpha;
  18857. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  18858. if (dr != 0)
  18859. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  18860. subSampleOffset += ratio;
  18861. jassert (sampsInBuffer > 0);
  18862. while (subSampleOffset >= 1.0)
  18863. {
  18864. if (++bufferPos >= bufferSize)
  18865. bufferPos = 0;
  18866. --sampsInBuffer;
  18867. nextPos = (bufferPos + 1) % bufferSize;
  18868. subSampleOffset -= 1.0;
  18869. }
  18870. }
  18871. if (ratio < 0.9999)
  18872. {
  18873. // for up-sampling, apply the filter after transposing..
  18874. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18875. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  18876. }
  18877. else if (ratio <= 1.0001)
  18878. {
  18879. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  18880. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18881. {
  18882. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  18883. FilterState& fs = filterStates[i];
  18884. if (info.numSamples > 1)
  18885. {
  18886. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  18887. }
  18888. else
  18889. {
  18890. fs.y2 = fs.y1;
  18891. fs.x2 = fs.x1;
  18892. }
  18893. fs.y1 = fs.x1 = *endOfBuffer;
  18894. }
  18895. }
  18896. jassert (sampsInBuffer >= 0);
  18897. }
  18898. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  18899. {
  18900. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  18901. : 0.5 * frequencyRatio;
  18902. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  18903. const double nSquared = n * n;
  18904. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  18905. setFilterCoefficients (c1,
  18906. c1 * 2.0f,
  18907. c1,
  18908. 1.0,
  18909. c1 * 2.0 * (1.0 - nSquared),
  18910. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  18911. }
  18912. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  18913. {
  18914. const double a = 1.0 / c4;
  18915. c1 *= a;
  18916. c2 *= a;
  18917. c3 *= a;
  18918. c5 *= a;
  18919. c6 *= a;
  18920. coefficients[0] = c1;
  18921. coefficients[1] = c2;
  18922. coefficients[2] = c3;
  18923. coefficients[3] = c4;
  18924. coefficients[4] = c5;
  18925. coefficients[5] = c6;
  18926. }
  18927. void ResamplingAudioSource::resetFilters()
  18928. {
  18929. zeromem (filterStates, sizeof (filterStates));
  18930. }
  18931. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  18932. {
  18933. while (--num >= 0)
  18934. {
  18935. const double in = *samples;
  18936. double out = coefficients[0] * in
  18937. + coefficients[1] * fs.x1
  18938. + coefficients[2] * fs.x2
  18939. - coefficients[4] * fs.y1
  18940. - coefficients[5] * fs.y2;
  18941. #if JUCE_INTEL
  18942. if (! (out < -1.0e-8 || out > 1.0e-8))
  18943. out = 0;
  18944. #endif
  18945. fs.x2 = fs.x1;
  18946. fs.x1 = in;
  18947. fs.y2 = fs.y1;
  18948. fs.y1 = out;
  18949. *samples++ = (float) out;
  18950. }
  18951. }
  18952. END_JUCE_NAMESPACE
  18953. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  18954. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  18955. BEGIN_JUCE_NAMESPACE
  18956. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  18957. : frequency (1000.0),
  18958. sampleRate (44100.0),
  18959. currentPhase (0.0),
  18960. phasePerSample (0.0),
  18961. amplitude (0.5f)
  18962. {
  18963. }
  18964. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  18965. {
  18966. }
  18967. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  18968. {
  18969. amplitude = newAmplitude;
  18970. }
  18971. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  18972. {
  18973. frequency = newFrequencyHz;
  18974. phasePerSample = 0.0;
  18975. }
  18976. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18977. double sampleRate_)
  18978. {
  18979. currentPhase = 0.0;
  18980. phasePerSample = 0.0;
  18981. sampleRate = sampleRate_;
  18982. }
  18983. void ToneGeneratorAudioSource::releaseResources()
  18984. {
  18985. }
  18986. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18987. {
  18988. if (phasePerSample == 0.0)
  18989. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  18990. for (int i = 0; i < info.numSamples; ++i)
  18991. {
  18992. const float sample = amplitude * (float) sin (currentPhase);
  18993. currentPhase += phasePerSample;
  18994. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  18995. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  18996. }
  18997. }
  18998. END_JUCE_NAMESPACE
  18999. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19000. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19001. BEGIN_JUCE_NAMESPACE
  19002. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19003. : sampleRate (0),
  19004. bufferSize (0),
  19005. useDefaultInputChannels (true),
  19006. useDefaultOutputChannels (true)
  19007. {
  19008. }
  19009. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19010. {
  19011. return outputDeviceName == other.outputDeviceName
  19012. && inputDeviceName == other.inputDeviceName
  19013. && sampleRate == other.sampleRate
  19014. && bufferSize == other.bufferSize
  19015. && inputChannels == other.inputChannels
  19016. && useDefaultInputChannels == other.useDefaultInputChannels
  19017. && outputChannels == other.outputChannels
  19018. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19019. }
  19020. AudioDeviceManager::AudioDeviceManager()
  19021. : currentAudioDevice (0),
  19022. numInputChansNeeded (0),
  19023. numOutputChansNeeded (2),
  19024. listNeedsScanning (true),
  19025. useInputNames (false),
  19026. inputLevelMeasurementEnabledCount (0),
  19027. inputLevel (0),
  19028. tempBuffer (2, 2),
  19029. defaultMidiOutput (0),
  19030. cpuUsageMs (0),
  19031. timeToCpuScale (0)
  19032. {
  19033. callbackHandler.owner = this;
  19034. }
  19035. AudioDeviceManager::~AudioDeviceManager()
  19036. {
  19037. currentAudioDevice = 0;
  19038. defaultMidiOutput = 0;
  19039. }
  19040. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19041. {
  19042. if (availableDeviceTypes.size() == 0)
  19043. {
  19044. createAudioDeviceTypes (availableDeviceTypes);
  19045. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19046. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19047. if (availableDeviceTypes.size() > 0)
  19048. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19049. }
  19050. }
  19051. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19052. {
  19053. scanDevicesIfNeeded();
  19054. return availableDeviceTypes;
  19055. }
  19056. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19057. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19058. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19059. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19060. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19061. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19062. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19063. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19064. {
  19065. (void) list; // (to avoid 'unused param' warnings)
  19066. #if JUCE_WINDOWS
  19067. #if JUCE_WASAPI
  19068. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19069. list.add (juce_createAudioIODeviceType_WASAPI());
  19070. #endif
  19071. #if JUCE_DIRECTSOUND
  19072. list.add (juce_createAudioIODeviceType_DirectSound());
  19073. #endif
  19074. #if JUCE_ASIO
  19075. list.add (juce_createAudioIODeviceType_ASIO());
  19076. #endif
  19077. #endif
  19078. #if JUCE_MAC
  19079. list.add (juce_createAudioIODeviceType_CoreAudio());
  19080. #endif
  19081. #if JUCE_IPHONE
  19082. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19083. #endif
  19084. #if JUCE_LINUX && JUCE_ALSA
  19085. list.add (juce_createAudioIODeviceType_ALSA());
  19086. #endif
  19087. #if JUCE_LINUX && JUCE_JACK
  19088. list.add (juce_createAudioIODeviceType_JACK());
  19089. #endif
  19090. }
  19091. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19092. const int numOutputChannelsNeeded,
  19093. const XmlElement* const e,
  19094. const bool selectDefaultDeviceOnFailure,
  19095. const String& preferredDefaultDeviceName,
  19096. const AudioDeviceSetup* preferredSetupOptions)
  19097. {
  19098. scanDevicesIfNeeded();
  19099. numInputChansNeeded = numInputChannelsNeeded;
  19100. numOutputChansNeeded = numOutputChannelsNeeded;
  19101. if (e != 0 && e->hasTagName ("DEVICESETUP"))
  19102. {
  19103. lastExplicitSettings = new XmlElement (*e);
  19104. String error;
  19105. AudioDeviceSetup setup;
  19106. if (preferredSetupOptions != 0)
  19107. setup = *preferredSetupOptions;
  19108. if (e->getStringAttribute ("audioDeviceName").isNotEmpty())
  19109. {
  19110. setup.inputDeviceName = setup.outputDeviceName
  19111. = e->getStringAttribute ("audioDeviceName");
  19112. }
  19113. else
  19114. {
  19115. setup.inputDeviceName = e->getStringAttribute ("audioInputDeviceName");
  19116. setup.outputDeviceName = e->getStringAttribute ("audioOutputDeviceName");
  19117. }
  19118. currentDeviceType = e->getStringAttribute ("deviceType");
  19119. if (currentDeviceType.isEmpty())
  19120. {
  19121. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19122. if (type != 0)
  19123. currentDeviceType = type->getTypeName();
  19124. else if (availableDeviceTypes.size() > 0)
  19125. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19126. }
  19127. setup.bufferSize = e->getIntAttribute ("audioDeviceBufferSize");
  19128. setup.sampleRate = e->getDoubleAttribute ("audioDeviceRate");
  19129. setup.inputChannels.parseString (e->getStringAttribute ("audioDeviceInChans", "11"), 2);
  19130. setup.outputChannels.parseString (e->getStringAttribute ("audioDeviceOutChans", "11"), 2);
  19131. setup.useDefaultInputChannels = ! e->hasAttribute ("audioDeviceInChans");
  19132. setup.useDefaultOutputChannels = ! e->hasAttribute ("audioDeviceOutChans");
  19133. error = setAudioDeviceSetup (setup, true);
  19134. midiInsFromXml.clear();
  19135. forEachXmlChildElementWithTagName (*e, c, "MIDIINPUT")
  19136. midiInsFromXml.add (c->getStringAttribute ("name"));
  19137. const StringArray allMidiIns (MidiInput::getDevices());
  19138. for (int i = allMidiIns.size(); --i >= 0;)
  19139. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19140. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19141. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19142. false, preferredDefaultDeviceName);
  19143. setDefaultMidiOutput (e->getStringAttribute ("defaultMidiOutput"));
  19144. return error;
  19145. }
  19146. else
  19147. {
  19148. AudioDeviceSetup setup;
  19149. if (preferredSetupOptions != 0)
  19150. {
  19151. setup = *preferredSetupOptions;
  19152. }
  19153. else if (preferredDefaultDeviceName.isNotEmpty())
  19154. {
  19155. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19156. {
  19157. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19158. StringArray outs (type->getDeviceNames (false));
  19159. int i;
  19160. for (i = 0; i < outs.size(); ++i)
  19161. {
  19162. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19163. {
  19164. setup.outputDeviceName = outs[i];
  19165. break;
  19166. }
  19167. }
  19168. StringArray ins (type->getDeviceNames (true));
  19169. for (i = 0; i < ins.size(); ++i)
  19170. {
  19171. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19172. {
  19173. setup.inputDeviceName = ins[i];
  19174. break;
  19175. }
  19176. }
  19177. }
  19178. }
  19179. insertDefaultDeviceNames (setup);
  19180. return setAudioDeviceSetup (setup, false);
  19181. }
  19182. }
  19183. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19184. {
  19185. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19186. if (type != 0)
  19187. {
  19188. if (setup.outputDeviceName.isEmpty())
  19189. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19190. if (setup.inputDeviceName.isEmpty())
  19191. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19192. }
  19193. }
  19194. XmlElement* AudioDeviceManager::createStateXml() const
  19195. {
  19196. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19197. }
  19198. void AudioDeviceManager::scanDevicesIfNeeded()
  19199. {
  19200. if (listNeedsScanning)
  19201. {
  19202. listNeedsScanning = false;
  19203. createDeviceTypesIfNeeded();
  19204. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19205. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19206. }
  19207. }
  19208. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19209. {
  19210. scanDevicesIfNeeded();
  19211. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19212. {
  19213. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19214. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19215. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19216. {
  19217. return type;
  19218. }
  19219. }
  19220. return 0;
  19221. }
  19222. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19223. {
  19224. setup = currentSetup;
  19225. }
  19226. void AudioDeviceManager::deleteCurrentDevice()
  19227. {
  19228. currentAudioDevice = 0;
  19229. currentSetup.inputDeviceName = String::empty;
  19230. currentSetup.outputDeviceName = String::empty;
  19231. }
  19232. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19233. const bool treatAsChosenDevice)
  19234. {
  19235. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19236. {
  19237. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19238. && currentDeviceType != type)
  19239. {
  19240. currentDeviceType = type;
  19241. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19242. insertDefaultDeviceNames (s);
  19243. setAudioDeviceSetup (s, treatAsChosenDevice);
  19244. sendChangeMessage (this);
  19245. break;
  19246. }
  19247. }
  19248. }
  19249. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19250. {
  19251. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19252. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19253. return availableDeviceTypes[i];
  19254. return availableDeviceTypes[0];
  19255. }
  19256. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19257. const bool treatAsChosenDevice)
  19258. {
  19259. jassert (&newSetup != &currentSetup); // this will have no effect
  19260. if (newSetup == currentSetup && currentAudioDevice != 0)
  19261. return String::empty;
  19262. if (! (newSetup == currentSetup))
  19263. sendChangeMessage (this);
  19264. stopDevice();
  19265. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19266. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19267. String error;
  19268. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19269. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19270. {
  19271. deleteCurrentDevice();
  19272. if (treatAsChosenDevice)
  19273. updateXml();
  19274. return String::empty;
  19275. }
  19276. if (currentSetup.inputDeviceName != newInputDeviceName
  19277. || currentSetup.outputDeviceName != newOutputDeviceName
  19278. || currentAudioDevice == 0)
  19279. {
  19280. deleteCurrentDevice();
  19281. scanDevicesIfNeeded();
  19282. if (newOutputDeviceName.isNotEmpty()
  19283. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19284. {
  19285. return "No such device: " + newOutputDeviceName;
  19286. }
  19287. if (newInputDeviceName.isNotEmpty()
  19288. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19289. {
  19290. return "No such device: " + newInputDeviceName;
  19291. }
  19292. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19293. if (currentAudioDevice == 0)
  19294. error = "Can't open the audio device!\n\nThis may be because another application is currently using the same device - if so, you should close any other applications and try again!";
  19295. else
  19296. error = currentAudioDevice->getLastError();
  19297. if (error.isNotEmpty())
  19298. {
  19299. deleteCurrentDevice();
  19300. return error;
  19301. }
  19302. if (newSetup.useDefaultInputChannels)
  19303. {
  19304. inputChannels.clear();
  19305. inputChannels.setRange (0, numInputChansNeeded, true);
  19306. }
  19307. if (newSetup.useDefaultOutputChannels)
  19308. {
  19309. outputChannels.clear();
  19310. outputChannels.setRange (0, numOutputChansNeeded, true);
  19311. }
  19312. if (newInputDeviceName.isEmpty())
  19313. inputChannels.clear();
  19314. if (newOutputDeviceName.isEmpty())
  19315. outputChannels.clear();
  19316. }
  19317. if (! newSetup.useDefaultInputChannels)
  19318. inputChannels = newSetup.inputChannels;
  19319. if (! newSetup.useDefaultOutputChannels)
  19320. outputChannels = newSetup.outputChannels;
  19321. currentSetup = newSetup;
  19322. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19323. error = currentAudioDevice->open (inputChannels,
  19324. outputChannels,
  19325. currentSetup.sampleRate,
  19326. currentSetup.bufferSize);
  19327. if (error.isEmpty())
  19328. {
  19329. currentDeviceType = currentAudioDevice->getTypeName();
  19330. currentAudioDevice->start (&callbackHandler);
  19331. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19332. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19333. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19334. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19335. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19336. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19337. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19338. if (treatAsChosenDevice)
  19339. updateXml();
  19340. }
  19341. else
  19342. {
  19343. deleteCurrentDevice();
  19344. }
  19345. return error;
  19346. }
  19347. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19348. {
  19349. jassert (currentAudioDevice != 0);
  19350. if (rate > 0)
  19351. {
  19352. bool ok = false;
  19353. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19354. {
  19355. const double sr = currentAudioDevice->getSampleRate (i);
  19356. if (sr == rate)
  19357. ok = true;
  19358. }
  19359. if (! ok)
  19360. rate = 0;
  19361. }
  19362. if (rate == 0)
  19363. {
  19364. double lowestAbove44 = 0.0;
  19365. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19366. {
  19367. const double sr = currentAudioDevice->getSampleRate (i);
  19368. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19369. lowestAbove44 = sr;
  19370. }
  19371. if (lowestAbove44 == 0.0)
  19372. rate = currentAudioDevice->getSampleRate (0);
  19373. else
  19374. rate = lowestAbove44;
  19375. }
  19376. return rate;
  19377. }
  19378. void AudioDeviceManager::stopDevice()
  19379. {
  19380. if (currentAudioDevice != 0)
  19381. currentAudioDevice->stop();
  19382. testSound = 0;
  19383. }
  19384. void AudioDeviceManager::closeAudioDevice()
  19385. {
  19386. stopDevice();
  19387. currentAudioDevice = 0;
  19388. }
  19389. void AudioDeviceManager::restartLastAudioDevice()
  19390. {
  19391. if (currentAudioDevice == 0)
  19392. {
  19393. if (currentSetup.inputDeviceName.isEmpty()
  19394. && currentSetup.outputDeviceName.isEmpty())
  19395. {
  19396. // This method will only reload the last device that was running
  19397. // before closeAudioDevice() was called - you need to actually open
  19398. // one first, with setAudioDevice().
  19399. jassertfalse
  19400. return;
  19401. }
  19402. AudioDeviceSetup s (currentSetup);
  19403. setAudioDeviceSetup (s, false);
  19404. }
  19405. }
  19406. void AudioDeviceManager::updateXml()
  19407. {
  19408. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19409. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19410. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19411. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19412. if (currentAudioDevice != 0)
  19413. {
  19414. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19415. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19416. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19417. if (! currentSetup.useDefaultInputChannels)
  19418. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19419. if (! currentSetup.useDefaultOutputChannels)
  19420. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19421. }
  19422. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19423. {
  19424. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19425. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19426. }
  19427. if (midiInsFromXml.size() > 0)
  19428. {
  19429. // Add any midi devices that have been enabled before, but which aren't currently
  19430. // open because the device has been disconnected.
  19431. const StringArray availableMidiDevices (MidiInput::getDevices());
  19432. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19433. {
  19434. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19435. {
  19436. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19437. m->setAttribute ("name", midiInsFromXml[i]);
  19438. }
  19439. }
  19440. }
  19441. if (defaultMidiOutputName.isNotEmpty())
  19442. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19443. }
  19444. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19445. {
  19446. {
  19447. const ScopedLock sl (audioCallbackLock);
  19448. if (callbacks.contains (newCallback))
  19449. return;
  19450. }
  19451. if (currentAudioDevice != 0 && newCallback != 0)
  19452. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19453. const ScopedLock sl (audioCallbackLock);
  19454. callbacks.add (newCallback);
  19455. }
  19456. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19457. {
  19458. if (callback != 0)
  19459. {
  19460. bool needsDeinitialising = currentAudioDevice != 0;
  19461. {
  19462. const ScopedLock sl (audioCallbackLock);
  19463. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19464. callbacks.removeValue (callback);
  19465. }
  19466. if (needsDeinitialising)
  19467. callback->audioDeviceStopped();
  19468. }
  19469. }
  19470. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19471. int numInputChannels,
  19472. float** outputChannelData,
  19473. int numOutputChannels,
  19474. int numSamples)
  19475. {
  19476. const ScopedLock sl (audioCallbackLock);
  19477. if (inputLevelMeasurementEnabledCount > 0)
  19478. {
  19479. for (int j = 0; j < numSamples; ++j)
  19480. {
  19481. float s = 0;
  19482. for (int i = 0; i < numInputChannels; ++i)
  19483. s += fabsf (inputChannelData[i][j]);
  19484. s /= numInputChannels;
  19485. const double decayFactor = 0.99992;
  19486. if (s > inputLevel)
  19487. inputLevel = s;
  19488. else if (inputLevel > 0.001f)
  19489. inputLevel *= decayFactor;
  19490. else
  19491. inputLevel = 0;
  19492. }
  19493. }
  19494. if (callbacks.size() > 0)
  19495. {
  19496. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19497. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19498. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19499. outputChannelData, numOutputChannels, numSamples);
  19500. float** const tempChans = tempBuffer.getArrayOfChannels();
  19501. for (int i = callbacks.size(); --i > 0;)
  19502. {
  19503. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19504. tempChans, numOutputChannels, numSamples);
  19505. for (int chan = 0; chan < numOutputChannels; ++chan)
  19506. {
  19507. const float* const src = tempChans [chan];
  19508. float* const dst = outputChannelData [chan];
  19509. if (src != 0 && dst != 0)
  19510. for (int j = 0; j < numSamples; ++j)
  19511. dst[j] += src[j];
  19512. }
  19513. }
  19514. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19515. const double filterAmount = 0.2;
  19516. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19517. }
  19518. else
  19519. {
  19520. for (int i = 0; i < numOutputChannels; ++i)
  19521. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19522. }
  19523. if (testSound != 0)
  19524. {
  19525. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19526. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19527. for (int i = 0; i < numOutputChannels; ++i)
  19528. for (int j = 0; j < numSamps; ++j)
  19529. outputChannelData [i][j] += src[j];
  19530. testSoundPosition += numSamps;
  19531. if (testSoundPosition >= testSound->getNumSamples())
  19532. testSound = 0;
  19533. }
  19534. }
  19535. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19536. {
  19537. cpuUsageMs = 0;
  19538. const double sampleRate = device->getCurrentSampleRate();
  19539. const int blockSize = device->getCurrentBufferSizeSamples();
  19540. if (sampleRate > 0.0 && blockSize > 0)
  19541. {
  19542. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19543. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19544. }
  19545. {
  19546. const ScopedLock sl (audioCallbackLock);
  19547. for (int i = callbacks.size(); --i >= 0;)
  19548. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19549. }
  19550. sendChangeMessage (this);
  19551. }
  19552. void AudioDeviceManager::audioDeviceStoppedInt()
  19553. {
  19554. cpuUsageMs = 0;
  19555. timeToCpuScale = 0;
  19556. sendChangeMessage (this);
  19557. const ScopedLock sl (audioCallbackLock);
  19558. for (int i = callbacks.size(); --i >= 0;)
  19559. callbacks.getUnchecked(i)->audioDeviceStopped();
  19560. }
  19561. double AudioDeviceManager::getCpuUsage() const
  19562. {
  19563. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19564. }
  19565. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19566. const bool enabled)
  19567. {
  19568. if (enabled != isMidiInputEnabled (name))
  19569. {
  19570. if (enabled)
  19571. {
  19572. const int index = MidiInput::getDevices().indexOf (name);
  19573. if (index >= 0)
  19574. {
  19575. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19576. if (min != 0)
  19577. {
  19578. enabledMidiInputs.add (min);
  19579. min->start();
  19580. }
  19581. }
  19582. }
  19583. else
  19584. {
  19585. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19586. if (enabledMidiInputs[i]->getName() == name)
  19587. enabledMidiInputs.remove (i);
  19588. }
  19589. updateXml();
  19590. sendChangeMessage (this);
  19591. }
  19592. }
  19593. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19594. {
  19595. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19596. if (enabledMidiInputs[i]->getName() == name)
  19597. return true;
  19598. return false;
  19599. }
  19600. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19601. MidiInputCallback* callback)
  19602. {
  19603. removeMidiInputCallback (name, callback);
  19604. if (name.isEmpty())
  19605. {
  19606. midiCallbacks.add (callback);
  19607. midiCallbackDevices.add (0);
  19608. }
  19609. else
  19610. {
  19611. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19612. {
  19613. if (enabledMidiInputs[i]->getName() == name)
  19614. {
  19615. const ScopedLock sl (midiCallbackLock);
  19616. midiCallbacks.add (callback);
  19617. midiCallbackDevices.add (enabledMidiInputs[i]);
  19618. break;
  19619. }
  19620. }
  19621. }
  19622. }
  19623. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19624. MidiInputCallback* /*callback*/)
  19625. {
  19626. const ScopedLock sl (midiCallbackLock);
  19627. for (int i = midiCallbacks.size(); --i >= 0;)
  19628. {
  19629. String devName;
  19630. if (midiCallbackDevices.getUnchecked(i) != 0)
  19631. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19632. if (devName == name)
  19633. {
  19634. midiCallbacks.remove (i);
  19635. midiCallbackDevices.remove (i);
  19636. }
  19637. }
  19638. }
  19639. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19640. const MidiMessage& message)
  19641. {
  19642. if (! message.isActiveSense())
  19643. {
  19644. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19645. const ScopedLock sl (midiCallbackLock);
  19646. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19647. {
  19648. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19649. if (md == source || (md == 0 && isDefaultSource))
  19650. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19651. }
  19652. }
  19653. }
  19654. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19655. {
  19656. if (defaultMidiOutputName != deviceName)
  19657. {
  19658. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19659. {
  19660. const ScopedLock sl (audioCallbackLock);
  19661. oldCallbacks = callbacks;
  19662. callbacks.clear();
  19663. }
  19664. if (currentAudioDevice != 0)
  19665. for (int i = oldCallbacks.size(); --i >= 0;)
  19666. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19667. defaultMidiOutput = 0;
  19668. defaultMidiOutputName = deviceName;
  19669. if (deviceName.isNotEmpty())
  19670. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19671. if (currentAudioDevice != 0)
  19672. for (int i = oldCallbacks.size(); --i >= 0;)
  19673. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19674. {
  19675. const ScopedLock sl (audioCallbackLock);
  19676. callbacks = oldCallbacks;
  19677. }
  19678. updateXml();
  19679. sendChangeMessage (this);
  19680. }
  19681. }
  19682. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19683. int numInputChannels,
  19684. float** outputChannelData,
  19685. int numOutputChannels,
  19686. int numSamples)
  19687. {
  19688. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19689. }
  19690. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19691. {
  19692. owner->audioDeviceAboutToStartInt (device);
  19693. }
  19694. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19695. {
  19696. owner->audioDeviceStoppedInt();
  19697. }
  19698. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19699. {
  19700. owner->handleIncomingMidiMessageInt (source, message);
  19701. }
  19702. void AudioDeviceManager::playTestSound()
  19703. {
  19704. { // cunningly nested to swap, unlock and delete in that order.
  19705. ScopedPointer <AudioSampleBuffer> oldSound;
  19706. {
  19707. const ScopedLock sl (audioCallbackLock);
  19708. oldSound = testSound;
  19709. }
  19710. }
  19711. testSoundPosition = 0;
  19712. if (currentAudioDevice != 0)
  19713. {
  19714. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19715. const int soundLength = (int) sampleRate;
  19716. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19717. float* samples = newSound->getSampleData (0);
  19718. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19719. const float amplitude = 0.5f;
  19720. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19721. for (int i = 0; i < soundLength; ++i)
  19722. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19723. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19724. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19725. const ScopedLock sl (audioCallbackLock);
  19726. testSound = newSound;
  19727. }
  19728. }
  19729. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19730. {
  19731. const ScopedLock sl (audioCallbackLock);
  19732. if (enableMeasurement)
  19733. ++inputLevelMeasurementEnabledCount;
  19734. else
  19735. --inputLevelMeasurementEnabledCount;
  19736. inputLevel = 0;
  19737. }
  19738. double AudioDeviceManager::getCurrentInputLevel() const
  19739. {
  19740. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  19741. return inputLevel;
  19742. }
  19743. END_JUCE_NAMESPACE
  19744. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  19745. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  19746. BEGIN_JUCE_NAMESPACE
  19747. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  19748. : name (deviceName),
  19749. typeName (typeName_)
  19750. {
  19751. }
  19752. AudioIODevice::~AudioIODevice()
  19753. {
  19754. }
  19755. bool AudioIODevice::hasControlPanel() const
  19756. {
  19757. return false;
  19758. }
  19759. bool AudioIODevice::showControlPanel()
  19760. {
  19761. jassertfalse // this should only be called for devices which return true from
  19762. // their hasControlPanel() method.
  19763. return false;
  19764. }
  19765. END_JUCE_NAMESPACE
  19766. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  19767. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  19768. BEGIN_JUCE_NAMESPACE
  19769. AudioIODeviceType::AudioIODeviceType (const String& name)
  19770. : typeName (name)
  19771. {
  19772. }
  19773. AudioIODeviceType::~AudioIODeviceType()
  19774. {
  19775. }
  19776. END_JUCE_NAMESPACE
  19777. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  19778. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  19779. BEGIN_JUCE_NAMESPACE
  19780. MidiOutput::MidiOutput()
  19781. : Thread ("midi out"),
  19782. internal (0),
  19783. firstMessage (0)
  19784. {
  19785. }
  19786. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  19787. const double sampleNumber)
  19788. : message (data, len, sampleNumber)
  19789. {
  19790. }
  19791. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  19792. const double millisecondCounterToStartAt,
  19793. double samplesPerSecondForBuffer)
  19794. {
  19795. // You've got to call startBackgroundThread() for this to actually work..
  19796. jassert (isThreadRunning());
  19797. // this needs to be a value in the future - RTFM for this method!
  19798. jassert (millisecondCounterToStartAt > 0);
  19799. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  19800. MidiBuffer::Iterator i (buffer);
  19801. const uint8* data;
  19802. int len, time;
  19803. while (i.getNextEvent (data, len, time))
  19804. {
  19805. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  19806. PendingMessage* const m
  19807. = new PendingMessage (data, len, eventTime);
  19808. const ScopedLock sl (lock);
  19809. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  19810. {
  19811. m->next = firstMessage;
  19812. firstMessage = m;
  19813. }
  19814. else
  19815. {
  19816. PendingMessage* mm = firstMessage;
  19817. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  19818. mm = mm->next;
  19819. m->next = mm->next;
  19820. mm->next = m;
  19821. }
  19822. }
  19823. notify();
  19824. }
  19825. void MidiOutput::clearAllPendingMessages()
  19826. {
  19827. const ScopedLock sl (lock);
  19828. while (firstMessage != 0)
  19829. {
  19830. PendingMessage* const m = firstMessage;
  19831. firstMessage = firstMessage->next;
  19832. delete m;
  19833. }
  19834. }
  19835. void MidiOutput::startBackgroundThread()
  19836. {
  19837. startThread (9);
  19838. }
  19839. void MidiOutput::stopBackgroundThread()
  19840. {
  19841. stopThread (5000);
  19842. }
  19843. void MidiOutput::run()
  19844. {
  19845. while (! threadShouldExit())
  19846. {
  19847. uint32 now = Time::getMillisecondCounter();
  19848. uint32 eventTime = 0;
  19849. uint32 timeToWait = 500;
  19850. PendingMessage* message;
  19851. {
  19852. const ScopedLock sl (lock);
  19853. message = firstMessage;
  19854. if (message != 0)
  19855. {
  19856. eventTime = roundToInt (message->message.getTimeStamp());
  19857. if (eventTime > now + 20)
  19858. {
  19859. timeToWait = eventTime - (now + 20);
  19860. message = 0;
  19861. }
  19862. else
  19863. {
  19864. firstMessage = message->next;
  19865. }
  19866. }
  19867. }
  19868. if (message != 0)
  19869. {
  19870. if (eventTime > now)
  19871. {
  19872. Time::waitForMillisecondCounter (eventTime);
  19873. if (threadShouldExit())
  19874. break;
  19875. }
  19876. if (eventTime > now - 200)
  19877. sendMessageNow (message->message);
  19878. delete message;
  19879. }
  19880. else
  19881. {
  19882. jassert (timeToWait < 1000 * 30);
  19883. wait (timeToWait);
  19884. }
  19885. }
  19886. clearAllPendingMessages();
  19887. }
  19888. END_JUCE_NAMESPACE
  19889. /*** End of inlined file: juce_MidiOutput.cpp ***/
  19890. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  19891. BEGIN_JUCE_NAMESPACE
  19892. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19893. {
  19894. const double maxVal = (double) 0x7fff;
  19895. char* intData = static_cast <char*> (dest);
  19896. if (dest != (void*) source || destBytesPerSample <= 4)
  19897. {
  19898. for (int i = 0; i < numSamples; ++i)
  19899. {
  19900. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19901. intData += destBytesPerSample;
  19902. }
  19903. }
  19904. else
  19905. {
  19906. intData += destBytesPerSample * numSamples;
  19907. for (int i = numSamples; --i >= 0;)
  19908. {
  19909. intData -= destBytesPerSample;
  19910. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19911. }
  19912. }
  19913. }
  19914. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19915. {
  19916. const double maxVal = (double) 0x7fff;
  19917. char* intData = static_cast <char*> (dest);
  19918. if (dest != (void*) source || destBytesPerSample <= 4)
  19919. {
  19920. for (int i = 0; i < numSamples; ++i)
  19921. {
  19922. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19923. intData += destBytesPerSample;
  19924. }
  19925. }
  19926. else
  19927. {
  19928. intData += destBytesPerSample * numSamples;
  19929. for (int i = numSamples; --i >= 0;)
  19930. {
  19931. intData -= destBytesPerSample;
  19932. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19933. }
  19934. }
  19935. }
  19936. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19937. {
  19938. const double maxVal = (double) 0x7fffff;
  19939. char* intData = static_cast <char*> (dest);
  19940. if (dest != (void*) source || destBytesPerSample <= 4)
  19941. {
  19942. for (int i = 0; i < numSamples; ++i)
  19943. {
  19944. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  19945. intData += destBytesPerSample;
  19946. }
  19947. }
  19948. else
  19949. {
  19950. intData += destBytesPerSample * numSamples;
  19951. for (int i = numSamples; --i >= 0;)
  19952. {
  19953. intData -= destBytesPerSample;
  19954. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  19955. }
  19956. }
  19957. }
  19958. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19959. {
  19960. const double maxVal = (double) 0x7fffff;
  19961. char* intData = static_cast <char*> (dest);
  19962. if (dest != (void*) source || destBytesPerSample <= 4)
  19963. {
  19964. for (int i = 0; i < numSamples; ++i)
  19965. {
  19966. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  19967. intData += destBytesPerSample;
  19968. }
  19969. }
  19970. else
  19971. {
  19972. intData += destBytesPerSample * numSamples;
  19973. for (int i = numSamples; --i >= 0;)
  19974. {
  19975. intData -= destBytesPerSample;
  19976. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  19977. }
  19978. }
  19979. }
  19980. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19981. {
  19982. const double maxVal = (double) 0x7fffffff;
  19983. char* intData = static_cast <char*> (dest);
  19984. if (dest != (void*) source || destBytesPerSample <= 4)
  19985. {
  19986. for (int i = 0; i < numSamples; ++i)
  19987. {
  19988. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19989. intData += destBytesPerSample;
  19990. }
  19991. }
  19992. else
  19993. {
  19994. intData += destBytesPerSample * numSamples;
  19995. for (int i = numSamples; --i >= 0;)
  19996. {
  19997. intData -= destBytesPerSample;
  19998. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19999. }
  20000. }
  20001. }
  20002. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20003. {
  20004. const double maxVal = (double) 0x7fffffff;
  20005. char* intData = static_cast <char*> (dest);
  20006. if (dest != (void*) source || destBytesPerSample <= 4)
  20007. {
  20008. for (int i = 0; i < numSamples; ++i)
  20009. {
  20010. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20011. intData += destBytesPerSample;
  20012. }
  20013. }
  20014. else
  20015. {
  20016. intData += destBytesPerSample * numSamples;
  20017. for (int i = numSamples; --i >= 0;)
  20018. {
  20019. intData -= destBytesPerSample;
  20020. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20021. }
  20022. }
  20023. }
  20024. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20025. {
  20026. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20027. char* d = static_cast <char*> (dest);
  20028. for (int i = 0; i < numSamples; ++i)
  20029. {
  20030. *(float*) d = source[i];
  20031. #if JUCE_BIG_ENDIAN
  20032. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20033. #endif
  20034. d += destBytesPerSample;
  20035. }
  20036. }
  20037. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20038. {
  20039. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20040. char* d = static_cast <char*> (dest);
  20041. for (int i = 0; i < numSamples; ++i)
  20042. {
  20043. *(float*) d = source[i];
  20044. #if JUCE_LITTLE_ENDIAN
  20045. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20046. #endif
  20047. d += destBytesPerSample;
  20048. }
  20049. }
  20050. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20051. {
  20052. const float scale = 1.0f / 0x7fff;
  20053. const char* intData = static_cast <const char*> (source);
  20054. if (source != (void*) dest || srcBytesPerSample >= 4)
  20055. {
  20056. for (int i = 0; i < numSamples; ++i)
  20057. {
  20058. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20059. intData += srcBytesPerSample;
  20060. }
  20061. }
  20062. else
  20063. {
  20064. intData += srcBytesPerSample * numSamples;
  20065. for (int i = numSamples; --i >= 0;)
  20066. {
  20067. intData -= srcBytesPerSample;
  20068. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20069. }
  20070. }
  20071. }
  20072. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20073. {
  20074. const float scale = 1.0f / 0x7fff;
  20075. const char* intData = static_cast <const char*> (source);
  20076. if (source != (void*) dest || srcBytesPerSample >= 4)
  20077. {
  20078. for (int i = 0; i < numSamples; ++i)
  20079. {
  20080. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20081. intData += srcBytesPerSample;
  20082. }
  20083. }
  20084. else
  20085. {
  20086. intData += srcBytesPerSample * numSamples;
  20087. for (int i = numSamples; --i >= 0;)
  20088. {
  20089. intData -= srcBytesPerSample;
  20090. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20091. }
  20092. }
  20093. }
  20094. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20095. {
  20096. const float scale = 1.0f / 0x7fffff;
  20097. const char* intData = static_cast <const char*> (source);
  20098. if (source != (void*) dest || srcBytesPerSample >= 4)
  20099. {
  20100. for (int i = 0; i < numSamples; ++i)
  20101. {
  20102. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20103. intData += srcBytesPerSample;
  20104. }
  20105. }
  20106. else
  20107. {
  20108. intData += srcBytesPerSample * numSamples;
  20109. for (int i = numSamples; --i >= 0;)
  20110. {
  20111. intData -= srcBytesPerSample;
  20112. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20113. }
  20114. }
  20115. }
  20116. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20117. {
  20118. const float scale = 1.0f / 0x7fffff;
  20119. const char* intData = static_cast <const char*> (source);
  20120. if (source != (void*) dest || srcBytesPerSample >= 4)
  20121. {
  20122. for (int i = 0; i < numSamples; ++i)
  20123. {
  20124. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20125. intData += srcBytesPerSample;
  20126. }
  20127. }
  20128. else
  20129. {
  20130. intData += srcBytesPerSample * numSamples;
  20131. for (int i = numSamples; --i >= 0;)
  20132. {
  20133. intData -= srcBytesPerSample;
  20134. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20135. }
  20136. }
  20137. }
  20138. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20139. {
  20140. const float scale = 1.0f / 0x7fffffff;
  20141. const char* intData = static_cast <const char*> (source);
  20142. if (source != (void*) dest || srcBytesPerSample >= 4)
  20143. {
  20144. for (int i = 0; i < numSamples; ++i)
  20145. {
  20146. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20147. intData += srcBytesPerSample;
  20148. }
  20149. }
  20150. else
  20151. {
  20152. intData += srcBytesPerSample * numSamples;
  20153. for (int i = numSamples; --i >= 0;)
  20154. {
  20155. intData -= srcBytesPerSample;
  20156. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20157. }
  20158. }
  20159. }
  20160. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20161. {
  20162. const float scale = 1.0f / 0x7fffffff;
  20163. const char* intData = static_cast <const char*> (source);
  20164. if (source != (void*) dest || srcBytesPerSample >= 4)
  20165. {
  20166. for (int i = 0; i < numSamples; ++i)
  20167. {
  20168. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20169. intData += srcBytesPerSample;
  20170. }
  20171. }
  20172. else
  20173. {
  20174. intData += srcBytesPerSample * numSamples;
  20175. for (int i = numSamples; --i >= 0;)
  20176. {
  20177. intData -= srcBytesPerSample;
  20178. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20179. }
  20180. }
  20181. }
  20182. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20183. {
  20184. const char* s = static_cast <const char*> (source);
  20185. for (int i = 0; i < numSamples; ++i)
  20186. {
  20187. dest[i] = *(float*)s;
  20188. #if JUCE_BIG_ENDIAN
  20189. uint32* const d = (uint32*) (dest + i);
  20190. *d = ByteOrder::swap (*d);
  20191. #endif
  20192. s += srcBytesPerSample;
  20193. }
  20194. }
  20195. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20196. {
  20197. const char* s = static_cast <const char*> (source);
  20198. for (int i = 0; i < numSamples; ++i)
  20199. {
  20200. dest[i] = *(float*)s;
  20201. #if JUCE_LITTLE_ENDIAN
  20202. uint32* const d = (uint32*) (dest + i);
  20203. *d = ByteOrder::swap (*d);
  20204. #endif
  20205. s += srcBytesPerSample;
  20206. }
  20207. }
  20208. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20209. const float* const source,
  20210. void* const dest,
  20211. const int numSamples)
  20212. {
  20213. switch (destFormat)
  20214. {
  20215. case int16LE:
  20216. convertFloatToInt16LE (source, dest, numSamples);
  20217. break;
  20218. case int16BE:
  20219. convertFloatToInt16BE (source, dest, numSamples);
  20220. break;
  20221. case int24LE:
  20222. convertFloatToInt24LE (source, dest, numSamples);
  20223. break;
  20224. case int24BE:
  20225. convertFloatToInt24BE (source, dest, numSamples);
  20226. break;
  20227. case int32LE:
  20228. convertFloatToInt32LE (source, dest, numSamples);
  20229. break;
  20230. case int32BE:
  20231. convertFloatToInt32BE (source, dest, numSamples);
  20232. break;
  20233. case float32LE:
  20234. convertFloatToFloat32LE (source, dest, numSamples);
  20235. break;
  20236. case float32BE:
  20237. convertFloatToFloat32BE (source, dest, numSamples);
  20238. break;
  20239. default:
  20240. jassertfalse
  20241. break;
  20242. }
  20243. }
  20244. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20245. const void* const source,
  20246. float* const dest,
  20247. const int numSamples)
  20248. {
  20249. switch (sourceFormat)
  20250. {
  20251. case int16LE:
  20252. convertInt16LEToFloat (source, dest, numSamples);
  20253. break;
  20254. case int16BE:
  20255. convertInt16BEToFloat (source, dest, numSamples);
  20256. break;
  20257. case int24LE:
  20258. convertInt24LEToFloat (source, dest, numSamples);
  20259. break;
  20260. case int24BE:
  20261. convertInt24BEToFloat (source, dest, numSamples);
  20262. break;
  20263. case int32LE:
  20264. convertInt32LEToFloat (source, dest, numSamples);
  20265. break;
  20266. case int32BE:
  20267. convertInt32BEToFloat (source, dest, numSamples);
  20268. break;
  20269. case float32LE:
  20270. convertFloat32LEToFloat (source, dest, numSamples);
  20271. break;
  20272. case float32BE:
  20273. convertFloat32BEToFloat (source, dest, numSamples);
  20274. break;
  20275. default:
  20276. jassertfalse
  20277. break;
  20278. }
  20279. }
  20280. void AudioDataConverters::interleaveSamples (const float** const source,
  20281. float* const dest,
  20282. const int numSamples,
  20283. const int numChannels)
  20284. {
  20285. for (int chan = 0; chan < numChannels; ++chan)
  20286. {
  20287. int i = chan;
  20288. const float* src = source [chan];
  20289. for (int j = 0; j < numSamples; ++j)
  20290. {
  20291. dest [i] = src [j];
  20292. i += numChannels;
  20293. }
  20294. }
  20295. }
  20296. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20297. float** const dest,
  20298. const int numSamples,
  20299. const int numChannels)
  20300. {
  20301. for (int chan = 0; chan < numChannels; ++chan)
  20302. {
  20303. int i = chan;
  20304. float* dst = dest [chan];
  20305. for (int j = 0; j < numSamples; ++j)
  20306. {
  20307. dst [j] = source [i];
  20308. i += numChannels;
  20309. }
  20310. }
  20311. }
  20312. END_JUCE_NAMESPACE
  20313. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20314. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20315. BEGIN_JUCE_NAMESPACE
  20316. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20317. const int numSamples) throw()
  20318. : numChannels (numChannels_),
  20319. size (numSamples)
  20320. {
  20321. jassert (numSamples >= 0);
  20322. jassert (numChannels_ > 0);
  20323. allocateData();
  20324. }
  20325. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20326. : numChannels (other.numChannels),
  20327. size (other.size)
  20328. {
  20329. allocateData();
  20330. const size_t numBytes = size * sizeof (float);
  20331. for (int i = 0; i < numChannels; ++i)
  20332. memcpy (channels[i], other.channels[i], numBytes);
  20333. }
  20334. void AudioSampleBuffer::allocateData()
  20335. {
  20336. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20337. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20338. allocatedData.malloc (allocatedBytes);
  20339. channels = reinterpret_cast <float**> (allocatedData.getData());
  20340. float* chan = (float*) (allocatedData + channelListSize);
  20341. for (int i = 0; i < numChannels; ++i)
  20342. {
  20343. channels[i] = chan;
  20344. chan += size;
  20345. }
  20346. channels [numChannels] = 0;
  20347. }
  20348. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20349. const int numChannels_,
  20350. const int numSamples) throw()
  20351. : numChannels (numChannels_),
  20352. size (numSamples),
  20353. allocatedBytes (0)
  20354. {
  20355. jassert (numChannels_ > 0);
  20356. allocateChannels (dataToReferTo);
  20357. }
  20358. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20359. const int newNumChannels,
  20360. const int newNumSamples) throw()
  20361. {
  20362. jassert (newNumChannels > 0);
  20363. allocatedBytes = 0;
  20364. allocatedData.free();
  20365. numChannels = newNumChannels;
  20366. size = newNumSamples;
  20367. allocateChannels (dataToReferTo);
  20368. }
  20369. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20370. {
  20371. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20372. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20373. {
  20374. channels = static_cast <float**> (preallocatedChannelSpace);
  20375. }
  20376. else
  20377. {
  20378. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20379. channels = reinterpret_cast <float**> (allocatedData.getData());
  20380. }
  20381. for (int i = 0; i < numChannels; ++i)
  20382. {
  20383. // you have to pass in the same number of valid pointers as numChannels
  20384. jassert (dataToReferTo[i] != 0);
  20385. channels[i] = dataToReferTo[i];
  20386. }
  20387. channels [numChannels] = 0;
  20388. }
  20389. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20390. {
  20391. if (this != &other)
  20392. {
  20393. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20394. const size_t numBytes = size * sizeof (float);
  20395. for (int i = 0; i < numChannels; ++i)
  20396. memcpy (channels[i], other.channels[i], numBytes);
  20397. }
  20398. return *this;
  20399. }
  20400. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20401. {
  20402. }
  20403. void AudioSampleBuffer::setSize (const int newNumChannels,
  20404. const int newNumSamples,
  20405. const bool keepExistingContent,
  20406. const bool clearExtraSpace,
  20407. const bool avoidReallocating) throw()
  20408. {
  20409. jassert (newNumChannels > 0);
  20410. if (newNumSamples != size || newNumChannels != numChannels)
  20411. {
  20412. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20413. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20414. if (keepExistingContent)
  20415. {
  20416. HeapBlock <char> newData;
  20417. newData.allocate (newTotalBytes, clearExtraSpace);
  20418. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20419. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20420. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20421. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20422. for (int i = 0; i < numChansToCopy; ++i)
  20423. {
  20424. memcpy (newChan, channels[i], numBytesToCopy);
  20425. newChannels[i] = newChan;
  20426. newChan += newNumSamples;
  20427. }
  20428. allocatedData.swapWith (newData);
  20429. allocatedBytes = (int) newTotalBytes;
  20430. channels = newChannels;
  20431. }
  20432. else
  20433. {
  20434. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20435. {
  20436. if (clearExtraSpace)
  20437. zeromem (allocatedData, newTotalBytes);
  20438. }
  20439. else
  20440. {
  20441. allocatedBytes = newTotalBytes;
  20442. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20443. channels = reinterpret_cast <float**> (allocatedData.getData());
  20444. }
  20445. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20446. for (int i = 0; i < newNumChannels; ++i)
  20447. {
  20448. channels[i] = chan;
  20449. chan += newNumSamples;
  20450. }
  20451. }
  20452. channels [newNumChannels] = 0;
  20453. size = newNumSamples;
  20454. numChannels = newNumChannels;
  20455. }
  20456. }
  20457. void AudioSampleBuffer::clear() throw()
  20458. {
  20459. for (int i = 0; i < numChannels; ++i)
  20460. zeromem (channels[i], size * sizeof (float));
  20461. }
  20462. void AudioSampleBuffer::clear (const int startSample,
  20463. const int numSamples) throw()
  20464. {
  20465. jassert (startSample >= 0 && startSample + numSamples <= size);
  20466. for (int i = 0; i < numChannels; ++i)
  20467. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20468. }
  20469. void AudioSampleBuffer::clear (const int channel,
  20470. const int startSample,
  20471. const int numSamples) throw()
  20472. {
  20473. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20474. jassert (startSample >= 0 && startSample + numSamples <= size);
  20475. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20476. }
  20477. void AudioSampleBuffer::applyGain (const int channel,
  20478. const int startSample,
  20479. int numSamples,
  20480. const float gain) throw()
  20481. {
  20482. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20483. jassert (startSample >= 0 && startSample + numSamples <= size);
  20484. if (gain != 1.0f)
  20485. {
  20486. float* d = channels [channel] + startSample;
  20487. if (gain == 0.0f)
  20488. {
  20489. zeromem (d, sizeof (float) * numSamples);
  20490. }
  20491. else
  20492. {
  20493. while (--numSamples >= 0)
  20494. *d++ *= gain;
  20495. }
  20496. }
  20497. }
  20498. void AudioSampleBuffer::applyGainRamp (const int channel,
  20499. const int startSample,
  20500. int numSamples,
  20501. float startGain,
  20502. float endGain) throw()
  20503. {
  20504. if (startGain == endGain)
  20505. {
  20506. applyGain (channel, startSample, numSamples, startGain);
  20507. }
  20508. else
  20509. {
  20510. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20511. jassert (startSample >= 0 && startSample + numSamples <= size);
  20512. const float increment = (endGain - startGain) / numSamples;
  20513. float* d = channels [channel] + startSample;
  20514. while (--numSamples >= 0)
  20515. {
  20516. *d++ *= startGain;
  20517. startGain += increment;
  20518. }
  20519. }
  20520. }
  20521. void AudioSampleBuffer::applyGain (const int startSample,
  20522. const int numSamples,
  20523. const float gain) throw()
  20524. {
  20525. for (int i = 0; i < numChannels; ++i)
  20526. applyGain (i, startSample, numSamples, gain);
  20527. }
  20528. void AudioSampleBuffer::addFrom (const int destChannel,
  20529. const int destStartSample,
  20530. const AudioSampleBuffer& source,
  20531. const int sourceChannel,
  20532. const int sourceStartSample,
  20533. int numSamples,
  20534. const float gain) throw()
  20535. {
  20536. jassert (&source != this || sourceChannel != destChannel);
  20537. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20538. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20539. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20540. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20541. if (gain != 0.0f && numSamples > 0)
  20542. {
  20543. float* d = channels [destChannel] + destStartSample;
  20544. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20545. if (gain != 1.0f)
  20546. {
  20547. while (--numSamples >= 0)
  20548. *d++ += gain * *s++;
  20549. }
  20550. else
  20551. {
  20552. while (--numSamples >= 0)
  20553. *d++ += *s++;
  20554. }
  20555. }
  20556. }
  20557. void AudioSampleBuffer::addFrom (const int destChannel,
  20558. const int destStartSample,
  20559. const float* source,
  20560. int numSamples,
  20561. const float gain) throw()
  20562. {
  20563. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20564. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20565. jassert (source != 0);
  20566. if (gain != 0.0f && numSamples > 0)
  20567. {
  20568. float* d = channels [destChannel] + destStartSample;
  20569. if (gain != 1.0f)
  20570. {
  20571. while (--numSamples >= 0)
  20572. *d++ += gain * *source++;
  20573. }
  20574. else
  20575. {
  20576. while (--numSamples >= 0)
  20577. *d++ += *source++;
  20578. }
  20579. }
  20580. }
  20581. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20582. const int destStartSample,
  20583. const float* source,
  20584. int numSamples,
  20585. float startGain,
  20586. const float endGain) throw()
  20587. {
  20588. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20589. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20590. jassert (source != 0);
  20591. if (startGain == endGain)
  20592. {
  20593. addFrom (destChannel,
  20594. destStartSample,
  20595. source,
  20596. numSamples,
  20597. startGain);
  20598. }
  20599. else
  20600. {
  20601. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20602. {
  20603. const float increment = (endGain - startGain) / numSamples;
  20604. float* d = channels [destChannel] + destStartSample;
  20605. while (--numSamples >= 0)
  20606. {
  20607. *d++ += startGain * *source++;
  20608. startGain += increment;
  20609. }
  20610. }
  20611. }
  20612. }
  20613. void AudioSampleBuffer::copyFrom (const int destChannel,
  20614. const int destStartSample,
  20615. const AudioSampleBuffer& source,
  20616. const int sourceChannel,
  20617. const int sourceStartSample,
  20618. int numSamples) throw()
  20619. {
  20620. jassert (&source != this || sourceChannel != destChannel);
  20621. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20622. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20623. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20624. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20625. if (numSamples > 0)
  20626. {
  20627. memcpy (channels [destChannel] + destStartSample,
  20628. source.channels [sourceChannel] + sourceStartSample,
  20629. sizeof (float) * numSamples);
  20630. }
  20631. }
  20632. void AudioSampleBuffer::copyFrom (const int destChannel,
  20633. const int destStartSample,
  20634. const float* source,
  20635. int numSamples) throw()
  20636. {
  20637. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20638. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20639. jassert (source != 0);
  20640. if (numSamples > 0)
  20641. {
  20642. memcpy (channels [destChannel] + destStartSample,
  20643. source,
  20644. sizeof (float) * numSamples);
  20645. }
  20646. }
  20647. void AudioSampleBuffer::copyFrom (const int destChannel,
  20648. const int destStartSample,
  20649. const float* source,
  20650. int numSamples,
  20651. const float gain) throw()
  20652. {
  20653. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20654. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20655. jassert (source != 0);
  20656. if (numSamples > 0)
  20657. {
  20658. float* d = channels [destChannel] + destStartSample;
  20659. if (gain != 1.0f)
  20660. {
  20661. if (gain == 0)
  20662. {
  20663. zeromem (d, sizeof (float) * numSamples);
  20664. }
  20665. else
  20666. {
  20667. while (--numSamples >= 0)
  20668. *d++ = gain * *source++;
  20669. }
  20670. }
  20671. else
  20672. {
  20673. memcpy (d, source, sizeof (float) * numSamples);
  20674. }
  20675. }
  20676. }
  20677. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20678. const int destStartSample,
  20679. const float* source,
  20680. int numSamples,
  20681. float startGain,
  20682. float endGain) throw()
  20683. {
  20684. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20685. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20686. jassert (source != 0);
  20687. if (startGain == endGain)
  20688. {
  20689. copyFrom (destChannel,
  20690. destStartSample,
  20691. source,
  20692. numSamples,
  20693. startGain);
  20694. }
  20695. else
  20696. {
  20697. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20698. {
  20699. const float increment = (endGain - startGain) / numSamples;
  20700. float* d = channels [destChannel] + destStartSample;
  20701. while (--numSamples >= 0)
  20702. {
  20703. *d++ = startGain * *source++;
  20704. startGain += increment;
  20705. }
  20706. }
  20707. }
  20708. }
  20709. void AudioSampleBuffer::findMinMax (const int channel,
  20710. const int startSample,
  20711. int numSamples,
  20712. float& minVal,
  20713. float& maxVal) const throw()
  20714. {
  20715. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20716. jassert (startSample >= 0 && startSample + numSamples <= size);
  20717. if (numSamples <= 0)
  20718. {
  20719. minVal = 0.0f;
  20720. maxVal = 0.0f;
  20721. }
  20722. else
  20723. {
  20724. const float* d = channels [channel] + startSample;
  20725. float mn = *d++;
  20726. float mx = mn;
  20727. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20728. {
  20729. const float samp = *d++;
  20730. if (samp > mx)
  20731. mx = samp;
  20732. if (samp < mn)
  20733. mn = samp;
  20734. }
  20735. maxVal = mx;
  20736. minVal = mn;
  20737. }
  20738. }
  20739. float AudioSampleBuffer::getMagnitude (const int channel,
  20740. const int startSample,
  20741. const int numSamples) const throw()
  20742. {
  20743. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20744. jassert (startSample >= 0 && startSample + numSamples <= size);
  20745. float mn, mx;
  20746. findMinMax (channel, startSample, numSamples, mn, mx);
  20747. return jmax (mn, -mn, mx, -mx);
  20748. }
  20749. float AudioSampleBuffer::getMagnitude (const int startSample,
  20750. const int numSamples) const throw()
  20751. {
  20752. float mag = 0.0f;
  20753. for (int i = 0; i < numChannels; ++i)
  20754. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  20755. return mag;
  20756. }
  20757. float AudioSampleBuffer::getRMSLevel (const int channel,
  20758. const int startSample,
  20759. const int numSamples) const throw()
  20760. {
  20761. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20762. jassert (startSample >= 0 && startSample + numSamples <= size);
  20763. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  20764. return 0.0f;
  20765. const float* const data = channels [channel] + startSample;
  20766. double sum = 0.0;
  20767. for (int i = 0; i < numSamples; ++i)
  20768. {
  20769. const float sample = data [i];
  20770. sum += sample * sample;
  20771. }
  20772. return (float) sqrt (sum / numSamples);
  20773. }
  20774. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  20775. const int startSample,
  20776. const int numSamples,
  20777. const int readerStartSample,
  20778. const bool useLeftChan,
  20779. const bool useRightChan) throw()
  20780. {
  20781. jassert (reader != 0);
  20782. jassert (startSample >= 0 && startSample + numSamples <= size);
  20783. if (numSamples > 0)
  20784. {
  20785. int* chans[3];
  20786. if (useLeftChan == useRightChan)
  20787. {
  20788. chans[0] = (int*) getSampleData (0, startSample);
  20789. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  20790. }
  20791. else if (useLeftChan || (reader->numChannels == 1))
  20792. {
  20793. chans[0] = (int*) getSampleData (0, startSample);
  20794. chans[1] = 0;
  20795. }
  20796. else if (useRightChan)
  20797. {
  20798. chans[0] = 0;
  20799. chans[1] = (int*) getSampleData (0, startSample);
  20800. }
  20801. chans[2] = 0;
  20802. reader->read (chans, 2, readerStartSample, numSamples, true);
  20803. if (! reader->usesFloatingPointData)
  20804. {
  20805. for (int j = 0; j < 2; ++j)
  20806. {
  20807. float* const d = reinterpret_cast <float*> (chans[j]);
  20808. if (d != 0)
  20809. {
  20810. const float multiplier = 1.0f / 0x7fffffff;
  20811. for (int i = 0; i < numSamples; ++i)
  20812. d[i] = *(int*)(d + i) * multiplier;
  20813. }
  20814. }
  20815. }
  20816. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  20817. {
  20818. // if this is a stereo buffer and the source was mono, dupe the first channel..
  20819. memcpy (getSampleData (1, startSample),
  20820. getSampleData (0, startSample),
  20821. sizeof (float) * numSamples);
  20822. }
  20823. }
  20824. }
  20825. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  20826. const int startSample,
  20827. const int numSamples) const throw()
  20828. {
  20829. jassert (startSample >= 0 && startSample + numSamples <= size);
  20830. if (numSamples > 0)
  20831. {
  20832. int* chans [3];
  20833. if (writer->isFloatingPoint())
  20834. {
  20835. chans[0] = (int*) getSampleData (0, startSample);
  20836. if (numChannels > 1)
  20837. chans[1] = (int*) getSampleData (1, startSample);
  20838. else
  20839. chans[1] = 0;
  20840. chans[2] = 0;
  20841. writer->write ((const int**) chans, numSamples);
  20842. }
  20843. else
  20844. {
  20845. HeapBlock <int> tempBuffer (numSamples * 2);
  20846. chans[0] = tempBuffer;
  20847. if (numChannels > 1)
  20848. chans[1] = chans[0] + numSamples;
  20849. else
  20850. chans[1] = 0;
  20851. chans[2] = 0;
  20852. for (int j = 0; j < 2; ++j)
  20853. {
  20854. int* const dest = chans[j];
  20855. if (dest != 0)
  20856. {
  20857. const float* const src = channels [j] + startSample;
  20858. for (int i = 0; i < numSamples; ++i)
  20859. {
  20860. const double samp = src[i];
  20861. if (samp <= -1.0)
  20862. dest[i] = std::numeric_limits<int>::min();
  20863. else if (samp >= 1.0)
  20864. dest[i] = std::numeric_limits<int>::max();
  20865. else
  20866. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  20867. }
  20868. }
  20869. }
  20870. writer->write ((const int**) chans, numSamples);
  20871. }
  20872. }
  20873. }
  20874. END_JUCE_NAMESPACE
  20875. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  20876. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  20877. BEGIN_JUCE_NAMESPACE
  20878. IIRFilter::IIRFilter()
  20879. : active (false)
  20880. {
  20881. reset();
  20882. }
  20883. IIRFilter::IIRFilter (const IIRFilter& other)
  20884. : active (other.active)
  20885. {
  20886. const ScopedLock sl (other.processLock);
  20887. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  20888. reset();
  20889. }
  20890. IIRFilter::~IIRFilter()
  20891. {
  20892. }
  20893. void IIRFilter::reset() throw()
  20894. {
  20895. const ScopedLock sl (processLock);
  20896. x1 = 0;
  20897. x2 = 0;
  20898. y1 = 0;
  20899. y2 = 0;
  20900. }
  20901. float IIRFilter::processSingleSampleRaw (const float in) throw()
  20902. {
  20903. float out = coefficients[0] * in
  20904. + coefficients[1] * x1
  20905. + coefficients[2] * x2
  20906. - coefficients[4] * y1
  20907. - coefficients[5] * y2;
  20908. #if JUCE_INTEL
  20909. if (! (out < -1.0e-8 || out > 1.0e-8))
  20910. out = 0;
  20911. #endif
  20912. x2 = x1;
  20913. x1 = in;
  20914. y2 = y1;
  20915. y1 = out;
  20916. return out;
  20917. }
  20918. void IIRFilter::processSamples (float* const samples,
  20919. const int numSamples) throw()
  20920. {
  20921. const ScopedLock sl (processLock);
  20922. if (active)
  20923. {
  20924. for (int i = 0; i < numSamples; ++i)
  20925. {
  20926. const float in = samples[i];
  20927. float out = coefficients[0] * in
  20928. + coefficients[1] * x1
  20929. + coefficients[2] * x2
  20930. - coefficients[4] * y1
  20931. - coefficients[5] * y2;
  20932. #if JUCE_INTEL
  20933. if (! (out < -1.0e-8 || out > 1.0e-8))
  20934. out = 0;
  20935. #endif
  20936. x2 = x1;
  20937. x1 = in;
  20938. y2 = y1;
  20939. y1 = out;
  20940. samples[i] = out;
  20941. }
  20942. }
  20943. }
  20944. void IIRFilter::makeLowPass (const double sampleRate,
  20945. const double frequency) throw()
  20946. {
  20947. jassert (sampleRate > 0);
  20948. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  20949. const double nSquared = n * n;
  20950. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  20951. setCoefficients (c1,
  20952. c1 * 2.0f,
  20953. c1,
  20954. 1.0,
  20955. c1 * 2.0 * (1.0 - nSquared),
  20956. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  20957. }
  20958. void IIRFilter::makeHighPass (const double sampleRate,
  20959. const double frequency) throw()
  20960. {
  20961. const double n = tan (double_Pi * frequency / sampleRate);
  20962. const double nSquared = n * n;
  20963. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  20964. setCoefficients (c1,
  20965. c1 * -2.0f,
  20966. c1,
  20967. 1.0,
  20968. c1 * 2.0 * (nSquared - 1.0),
  20969. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  20970. }
  20971. void IIRFilter::makeLowShelf (const double sampleRate,
  20972. const double cutOffFrequency,
  20973. const double Q,
  20974. const float gainFactor) throw()
  20975. {
  20976. jassert (sampleRate > 0);
  20977. jassert (Q > 0);
  20978. const double A = jmax (0.0f, gainFactor);
  20979. const double aminus1 = A - 1.0;
  20980. const double aplus1 = A + 1.0;
  20981. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  20982. const double coso = cos (omega);
  20983. const double beta = sin (omega) * sqrt (A) / Q;
  20984. const double aminus1TimesCoso = aminus1 * coso;
  20985. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  20986. A * 2.0 * (aminus1 - aplus1 * coso),
  20987. A * (aplus1 - aminus1TimesCoso - beta),
  20988. aplus1 + aminus1TimesCoso + beta,
  20989. -2.0 * (aminus1 + aplus1 * coso),
  20990. aplus1 + aminus1TimesCoso - beta);
  20991. }
  20992. void IIRFilter::makeHighShelf (const double sampleRate,
  20993. const double cutOffFrequency,
  20994. const double Q,
  20995. const float gainFactor) throw()
  20996. {
  20997. jassert (sampleRate > 0);
  20998. jassert (Q > 0);
  20999. const double A = jmax (0.0f, gainFactor);
  21000. const double aminus1 = A - 1.0;
  21001. const double aplus1 = A + 1.0;
  21002. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21003. const double coso = cos (omega);
  21004. const double beta = sin (omega) * sqrt (A) / Q;
  21005. const double aminus1TimesCoso = aminus1 * coso;
  21006. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21007. A * -2.0 * (aminus1 + aplus1 * coso),
  21008. A * (aplus1 + aminus1TimesCoso - beta),
  21009. aplus1 - aminus1TimesCoso + beta,
  21010. 2.0 * (aminus1 - aplus1 * coso),
  21011. aplus1 - aminus1TimesCoso - beta);
  21012. }
  21013. void IIRFilter::makeBandPass (const double sampleRate,
  21014. const double centreFrequency,
  21015. const double Q,
  21016. const float gainFactor) throw()
  21017. {
  21018. jassert (sampleRate > 0);
  21019. jassert (Q > 0);
  21020. const double A = jmax (0.0f, gainFactor);
  21021. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21022. const double alpha = 0.5 * sin (omega) / Q;
  21023. const double c2 = -2.0 * cos (omega);
  21024. const double alphaTimesA = alpha * A;
  21025. const double alphaOverA = alpha / A;
  21026. setCoefficients (1.0 + alphaTimesA,
  21027. c2,
  21028. 1.0 - alphaTimesA,
  21029. 1.0 + alphaOverA,
  21030. c2,
  21031. 1.0 - alphaOverA);
  21032. }
  21033. void IIRFilter::makeInactive() throw()
  21034. {
  21035. const ScopedLock sl (processLock);
  21036. active = false;
  21037. }
  21038. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21039. {
  21040. const ScopedLock sl (processLock);
  21041. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21042. active = other.active;
  21043. }
  21044. void IIRFilter::setCoefficients (double c1,
  21045. double c2,
  21046. double c3,
  21047. double c4,
  21048. double c5,
  21049. double c6) throw()
  21050. {
  21051. const double a = 1.0 / c4;
  21052. c1 *= a;
  21053. c2 *= a;
  21054. c3 *= a;
  21055. c5 *= a;
  21056. c6 *= a;
  21057. const ScopedLock sl (processLock);
  21058. coefficients[0] = (float) c1;
  21059. coefficients[1] = (float) c2;
  21060. coefficients[2] = (float) c3;
  21061. coefficients[3] = (float) c4;
  21062. coefficients[4] = (float) c5;
  21063. coefficients[5] = (float) c6;
  21064. active = true;
  21065. }
  21066. END_JUCE_NAMESPACE
  21067. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21068. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21069. BEGIN_JUCE_NAMESPACE
  21070. MidiBuffer::MidiBuffer() throw()
  21071. : bytesUsed (0)
  21072. {
  21073. }
  21074. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21075. : bytesUsed (0)
  21076. {
  21077. addEvent (message, 0);
  21078. }
  21079. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21080. : data (other.data),
  21081. bytesUsed (other.bytesUsed)
  21082. {
  21083. }
  21084. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21085. {
  21086. bytesUsed = other.bytesUsed;
  21087. data = other.data;
  21088. return *this;
  21089. }
  21090. void MidiBuffer::swapWith (MidiBuffer& other)
  21091. {
  21092. data.swapWith (other.data);
  21093. swapVariables <int> (bytesUsed, other.bytesUsed);
  21094. }
  21095. MidiBuffer::~MidiBuffer() throw()
  21096. {
  21097. }
  21098. inline uint8* MidiBuffer::getData() const throw()
  21099. {
  21100. return static_cast <uint8*> (data.getData());
  21101. }
  21102. inline int MidiBuffer::getEventTime (const void* const d) throw()
  21103. {
  21104. return *static_cast <const int*> (d);
  21105. }
  21106. inline uint16 MidiBuffer::getEventDataSize (const void* const d) throw()
  21107. {
  21108. return *reinterpret_cast <const uint16*> (static_cast <const char*> (d) + sizeof (int));
  21109. }
  21110. inline uint16 MidiBuffer::getEventTotalSize (const void* const d) throw()
  21111. {
  21112. return getEventDataSize (d) + sizeof (int) + sizeof (uint16);
  21113. }
  21114. void MidiBuffer::clear() throw()
  21115. {
  21116. bytesUsed = 0;
  21117. }
  21118. void MidiBuffer::clear (const int startSample,
  21119. const int numSamples) throw()
  21120. {
  21121. uint8* const start = findEventAfter (getData(), startSample - 1);
  21122. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21123. if (end > start)
  21124. {
  21125. const int bytesToMove = bytesUsed - (int) (end - getData());
  21126. if (bytesToMove > 0)
  21127. memmove (start, end, bytesToMove);
  21128. bytesUsed -= (int) (end - start);
  21129. }
  21130. }
  21131. void MidiBuffer::addEvent (const MidiMessage& m,
  21132. const int sampleNumber) throw()
  21133. {
  21134. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21135. }
  21136. static int findActualEventLength (const uint8* const data,
  21137. const int maxBytes) throw()
  21138. {
  21139. unsigned int byte = (unsigned int) *data;
  21140. int size = 0;
  21141. if (byte == 0xf0 || byte == 0xf7)
  21142. {
  21143. const uint8* d = data + 1;
  21144. while (d < data + maxBytes)
  21145. if (*d++ == 0xf7)
  21146. break;
  21147. size = (int) (d - data);
  21148. }
  21149. else if (byte == 0xff)
  21150. {
  21151. int n;
  21152. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21153. size = jmin (maxBytes, n + 2 + bytesLeft);
  21154. }
  21155. else if (byte >= 0x80)
  21156. {
  21157. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21158. }
  21159. return size;
  21160. }
  21161. void MidiBuffer::addEvent (const uint8* const newData,
  21162. const int maxBytes,
  21163. const int sampleNumber) throw()
  21164. {
  21165. const int numBytes = findActualEventLength (newData, maxBytes);
  21166. if (numBytes > 0)
  21167. {
  21168. int spaceNeeded = bytesUsed + numBytes + sizeof (int) + sizeof (uint16);
  21169. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21170. uint8* d = findEventAfter (getData(), sampleNumber);
  21171. const int bytesToMove = bytesUsed - (int) (d - getData());
  21172. if (bytesToMove > 0)
  21173. memmove (d + numBytes + sizeof (int) + sizeof (uint16), d, bytesToMove);
  21174. *reinterpret_cast <int*> (d) = sampleNumber;
  21175. d += sizeof (int);
  21176. *reinterpret_cast <uint16*> (d) = (uint16) numBytes;
  21177. d += sizeof (uint16);
  21178. memcpy (d, newData, numBytes);
  21179. bytesUsed += numBytes + sizeof (int) + sizeof (uint16);
  21180. }
  21181. }
  21182. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21183. const int startSample,
  21184. const int numSamples,
  21185. const int sampleDeltaToAdd) throw()
  21186. {
  21187. Iterator i (otherBuffer);
  21188. i.setNextSamplePosition (startSample);
  21189. const uint8* eventData;
  21190. int eventSize, position;
  21191. while (i.getNextEvent (eventData, eventSize, position)
  21192. && (position < startSample + numSamples || numSamples < 0))
  21193. {
  21194. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21195. }
  21196. }
  21197. void MidiBuffer::ensureSize (size_t minimumNumBytes)
  21198. {
  21199. data.ensureSize (minimumNumBytes);
  21200. }
  21201. bool MidiBuffer::isEmpty() const throw()
  21202. {
  21203. return bytesUsed == 0;
  21204. }
  21205. int MidiBuffer::getNumEvents() const throw()
  21206. {
  21207. int n = 0;
  21208. const uint8* d = getData();
  21209. const uint8* const end = d + bytesUsed;
  21210. while (d < end)
  21211. {
  21212. d += getEventTotalSize (d);
  21213. ++n;
  21214. }
  21215. return n;
  21216. }
  21217. int MidiBuffer::getFirstEventTime() const throw()
  21218. {
  21219. return bytesUsed > 0 ? getEventTime (data.getData()) : 0;
  21220. }
  21221. int MidiBuffer::getLastEventTime() const throw()
  21222. {
  21223. if (bytesUsed == 0)
  21224. return 0;
  21225. const uint8* d = getData();
  21226. const uint8* const endData = d + bytesUsed;
  21227. for (;;)
  21228. {
  21229. const uint8* const nextOne = d + getEventTotalSize (d);
  21230. if (nextOne >= endData)
  21231. return getEventTime (d);
  21232. d = nextOne;
  21233. }
  21234. }
  21235. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21236. {
  21237. const uint8* const endData = getData() + bytesUsed;
  21238. while (d < endData && getEventTime (d) <= samplePosition)
  21239. d += getEventTotalSize (d);
  21240. return d;
  21241. }
  21242. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21243. : buffer (buffer_),
  21244. data (buffer_.getData())
  21245. {
  21246. }
  21247. MidiBuffer::Iterator::~Iterator() throw()
  21248. {
  21249. }
  21250. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21251. {
  21252. data = buffer.getData();
  21253. const uint8* dataEnd = data + buffer.bytesUsed;
  21254. while (data < dataEnd && getEventTime (data) < samplePosition)
  21255. data += getEventTotalSize (data);
  21256. }
  21257. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, int& samplePosition) throw()
  21258. {
  21259. if (data >= buffer.getData() + buffer.bytesUsed)
  21260. return false;
  21261. samplePosition = getEventTime (data);
  21262. numBytes = getEventDataSize (data);
  21263. data += sizeof (int) + sizeof (uint16);
  21264. midiData = data;
  21265. data += numBytes;
  21266. return true;
  21267. }
  21268. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePosition) throw()
  21269. {
  21270. if (data >= buffer.getData() + buffer.bytesUsed)
  21271. return false;
  21272. samplePosition = getEventTime (data);
  21273. const int numBytes = getEventDataSize (data);
  21274. data += sizeof (int) + sizeof (uint16);
  21275. result = MidiMessage (data, numBytes, samplePosition);
  21276. data += numBytes;
  21277. return true;
  21278. }
  21279. END_JUCE_NAMESPACE
  21280. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21281. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21282. BEGIN_JUCE_NAMESPACE
  21283. namespace MidiFileHelpers
  21284. {
  21285. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21286. {
  21287. unsigned int buffer = v & 0x7F;
  21288. while ((v >>= 7) != 0)
  21289. {
  21290. buffer <<= 8;
  21291. buffer |= ((v & 0x7F) | 0x80);
  21292. }
  21293. for (;;)
  21294. {
  21295. out.writeByte ((char) buffer);
  21296. if (buffer & 0x80)
  21297. buffer >>= 8;
  21298. else
  21299. break;
  21300. }
  21301. }
  21302. static bool parseMidiHeader (const uint8* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21303. {
  21304. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21305. data += 4;
  21306. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21307. {
  21308. bool ok = false;
  21309. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21310. {
  21311. for (int i = 0; i < 8; ++i)
  21312. {
  21313. ch = ByteOrder::bigEndianInt (data);
  21314. data += 4;
  21315. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21316. {
  21317. ok = true;
  21318. break;
  21319. }
  21320. }
  21321. }
  21322. if (! ok)
  21323. return false;
  21324. }
  21325. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21326. data += 4;
  21327. fileType = (short) ByteOrder::bigEndianShort (data);
  21328. data += 2;
  21329. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21330. data += 2;
  21331. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21332. data += 2;
  21333. bytesRemaining -= 6;
  21334. data += bytesRemaining;
  21335. return true;
  21336. }
  21337. static double convertTicksToSeconds (const double time,
  21338. const MidiMessageSequence& tempoEvents,
  21339. const int timeFormat)
  21340. {
  21341. if (timeFormat > 0)
  21342. {
  21343. int numer = 4, denom = 4;
  21344. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21345. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21346. double secsPerTick = 0.5 * tickLen;
  21347. const int numEvents = tempoEvents.getNumEvents();
  21348. for (int i = 0; i < numEvents; ++i)
  21349. {
  21350. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21351. if (time <= m.getTimeStamp())
  21352. break;
  21353. if (timeFormat > 0)
  21354. {
  21355. correctedTempoTime = correctedTempoTime
  21356. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21357. }
  21358. else
  21359. {
  21360. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21361. }
  21362. tempoTime = m.getTimeStamp();
  21363. if (m.isTempoMetaEvent())
  21364. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21365. else if (m.isTimeSignatureMetaEvent())
  21366. m.getTimeSignatureInfo (numer, denom);
  21367. while (i + 1 < numEvents)
  21368. {
  21369. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21370. if (m2.getTimeStamp() == tempoTime)
  21371. {
  21372. ++i;
  21373. if (m2.isTempoMetaEvent())
  21374. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21375. else if (m2.isTimeSignatureMetaEvent())
  21376. m2.getTimeSignatureInfo (numer, denom);
  21377. }
  21378. else
  21379. {
  21380. break;
  21381. }
  21382. }
  21383. }
  21384. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21385. }
  21386. else
  21387. {
  21388. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21389. }
  21390. }
  21391. }
  21392. MidiFile::MidiFile()
  21393. : timeFormat ((short) (unsigned short) 0xe728)
  21394. {
  21395. }
  21396. MidiFile::~MidiFile()
  21397. {
  21398. clear();
  21399. }
  21400. void MidiFile::clear()
  21401. {
  21402. tracks.clear();
  21403. }
  21404. int MidiFile::getNumTracks() const throw()
  21405. {
  21406. return tracks.size();
  21407. }
  21408. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21409. {
  21410. return tracks [index];
  21411. }
  21412. void MidiFile::addTrack (const MidiMessageSequence& trackSequence)
  21413. {
  21414. tracks.add (new MidiMessageSequence (trackSequence));
  21415. }
  21416. short MidiFile::getTimeFormat() const throw()
  21417. {
  21418. return timeFormat;
  21419. }
  21420. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21421. {
  21422. timeFormat = (short) ticks;
  21423. }
  21424. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21425. const int subframeResolution) throw()
  21426. {
  21427. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21428. }
  21429. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21430. {
  21431. for (int i = tracks.size(); --i >= 0;)
  21432. {
  21433. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21434. for (int j = 0; j < numEvents; ++j)
  21435. {
  21436. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21437. if (m.isTempoMetaEvent())
  21438. tempoChangeEvents.addEvent (m);
  21439. }
  21440. }
  21441. }
  21442. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21443. {
  21444. for (int i = tracks.size(); --i >= 0;)
  21445. {
  21446. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21447. for (int j = 0; j < numEvents; ++j)
  21448. {
  21449. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21450. if (m.isTimeSignatureMetaEvent())
  21451. timeSigEvents.addEvent (m);
  21452. }
  21453. }
  21454. }
  21455. double MidiFile::getLastTimestamp() const
  21456. {
  21457. double t = 0.0;
  21458. for (int i = tracks.size(); --i >= 0;)
  21459. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21460. return t;
  21461. }
  21462. bool MidiFile::readFrom (InputStream& sourceStream)
  21463. {
  21464. clear();
  21465. MemoryBlock data;
  21466. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21467. // (put a sanity-check on the file size, as midi files are generally small)
  21468. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21469. {
  21470. size_t size = data.getSize();
  21471. const uint8* d = static_cast <const uint8*> (data.getData());
  21472. short fileType, expectedTracks;
  21473. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21474. {
  21475. size -= (int) (d - static_cast <const uint8*> (data.getData()));
  21476. int track = 0;
  21477. while (size > 0 && track < expectedTracks)
  21478. {
  21479. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21480. d += 4;
  21481. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21482. d += 4;
  21483. if (chunkSize <= 0)
  21484. break;
  21485. if (size < 0)
  21486. return false;
  21487. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21488. {
  21489. readNextTrack (d, chunkSize);
  21490. }
  21491. size -= chunkSize + 8;
  21492. d += chunkSize;
  21493. ++track;
  21494. }
  21495. return true;
  21496. }
  21497. }
  21498. return false;
  21499. }
  21500. // a comparator that puts all the note-offs before note-ons that have the same time
  21501. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21502. const MidiMessageSequence::MidiEventHolder* const second)
  21503. {
  21504. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21505. if (diff == 0)
  21506. {
  21507. if (first->message.isNoteOff() && second->message.isNoteOn())
  21508. return -1;
  21509. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21510. return 1;
  21511. else
  21512. return 0;
  21513. }
  21514. else
  21515. {
  21516. return (diff > 0) ? 1 : -1;
  21517. }
  21518. }
  21519. void MidiFile::readNextTrack (const uint8* data, int size)
  21520. {
  21521. double time = 0;
  21522. char lastStatusByte = 0;
  21523. MidiMessageSequence result;
  21524. while (size > 0)
  21525. {
  21526. int bytesUsed;
  21527. const int delay = MidiMessage::readVariableLengthVal (data, bytesUsed);
  21528. data += bytesUsed;
  21529. size -= bytesUsed;
  21530. time += delay;
  21531. int messSize = 0;
  21532. const MidiMessage mm (data, size, messSize, lastStatusByte, time);
  21533. if (messSize <= 0)
  21534. break;
  21535. size -= messSize;
  21536. data += messSize;
  21537. result.addEvent (mm);
  21538. const char firstByte = *(mm.getRawData());
  21539. if ((firstByte & 0xf0) != 0xf0)
  21540. lastStatusByte = firstByte;
  21541. }
  21542. // use a sort that puts all the note-offs before note-ons that have the same time
  21543. result.list.sort (*this, true);
  21544. result.updateMatchedPairs();
  21545. addTrack (result);
  21546. }
  21547. void MidiFile::convertTimestampTicksToSeconds()
  21548. {
  21549. MidiMessageSequence tempoEvents;
  21550. findAllTempoEvents (tempoEvents);
  21551. findAllTimeSigEvents (tempoEvents);
  21552. for (int i = 0; i < tracks.size(); ++i)
  21553. {
  21554. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21555. for (int j = ms.getNumEvents(); --j >= 0;)
  21556. {
  21557. MidiMessage& m = ms.getEventPointer(j)->message;
  21558. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21559. tempoEvents,
  21560. timeFormat));
  21561. }
  21562. }
  21563. }
  21564. bool MidiFile::writeTo (OutputStream& out)
  21565. {
  21566. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21567. out.writeIntBigEndian (6);
  21568. out.writeShortBigEndian (1); // type
  21569. out.writeShortBigEndian ((short) tracks.size());
  21570. out.writeShortBigEndian (timeFormat);
  21571. for (int i = 0; i < tracks.size(); ++i)
  21572. writeTrack (out, i);
  21573. out.flush();
  21574. return true;
  21575. }
  21576. void MidiFile::writeTrack (OutputStream& mainOut,
  21577. const int trackNum)
  21578. {
  21579. MemoryOutputStream out;
  21580. const MidiMessageSequence& ms = *tracks[trackNum];
  21581. int lastTick = 0;
  21582. char lastStatusByte = 0;
  21583. for (int i = 0; i < ms.getNumEvents(); ++i)
  21584. {
  21585. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21586. const int tick = roundToInt (mm.getTimeStamp());
  21587. const int delta = jmax (0, tick - lastTick);
  21588. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21589. lastTick = tick;
  21590. const char statusByte = *(mm.getRawData());
  21591. if ((statusByte == lastStatusByte)
  21592. && ((statusByte & 0xf0) != 0xf0)
  21593. && i > 0
  21594. && mm.getRawDataSize() > 1)
  21595. {
  21596. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21597. }
  21598. else
  21599. {
  21600. out.write (mm.getRawData(), mm.getRawDataSize());
  21601. }
  21602. lastStatusByte = statusByte;
  21603. }
  21604. out.writeByte (0);
  21605. const MidiMessage m (MidiMessage::endOfTrack());
  21606. out.write (m.getRawData(),
  21607. m.getRawDataSize());
  21608. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21609. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21610. mainOut.write (out.getData(), (int) out.getDataSize());
  21611. }
  21612. END_JUCE_NAMESPACE
  21613. /*** End of inlined file: juce_MidiFile.cpp ***/
  21614. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21615. BEGIN_JUCE_NAMESPACE
  21616. MidiKeyboardState::MidiKeyboardState()
  21617. {
  21618. zerostruct (noteStates);
  21619. }
  21620. MidiKeyboardState::~MidiKeyboardState()
  21621. {
  21622. }
  21623. void MidiKeyboardState::reset()
  21624. {
  21625. const ScopedLock sl (lock);
  21626. zerostruct (noteStates);
  21627. eventsToAdd.clear();
  21628. }
  21629. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21630. {
  21631. jassert (midiChannel >= 0 && midiChannel <= 16);
  21632. return ((unsigned int) n) < 128
  21633. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21634. }
  21635. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21636. {
  21637. return ((unsigned int) n) < 128
  21638. && (noteStates[n] & midiChannelMask) != 0;
  21639. }
  21640. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21641. {
  21642. jassert (midiChannel >= 0 && midiChannel <= 16);
  21643. jassert (((unsigned int) midiNoteNumber) < 128);
  21644. const ScopedLock sl (lock);
  21645. if (((unsigned int) midiNoteNumber) < 128)
  21646. {
  21647. const int timeNow = (int) Time::getMillisecondCounter();
  21648. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21649. eventsToAdd.clear (0, timeNow - 500);
  21650. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21651. }
  21652. }
  21653. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21654. {
  21655. if (((unsigned int) midiNoteNumber) < 128)
  21656. {
  21657. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21658. for (int i = listeners.size(); --i >= 0;)
  21659. listeners.getUnchecked(i)->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21660. }
  21661. }
  21662. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21663. {
  21664. const ScopedLock sl (lock);
  21665. if (isNoteOn (midiChannel, midiNoteNumber))
  21666. {
  21667. const int timeNow = (int) Time::getMillisecondCounter();
  21668. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21669. eventsToAdd.clear (0, timeNow - 500);
  21670. noteOffInternal (midiChannel, midiNoteNumber);
  21671. }
  21672. }
  21673. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21674. {
  21675. if (isNoteOn (midiChannel, midiNoteNumber))
  21676. {
  21677. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21678. for (int i = listeners.size(); --i >= 0;)
  21679. listeners.getUnchecked(i)->handleNoteOff (this, midiChannel, midiNoteNumber);
  21680. }
  21681. }
  21682. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21683. {
  21684. const ScopedLock sl (lock);
  21685. if (midiChannel <= 0)
  21686. {
  21687. for (int i = 1; i <= 16; ++i)
  21688. allNotesOff (i);
  21689. }
  21690. else
  21691. {
  21692. for (int i = 0; i < 128; ++i)
  21693. noteOff (midiChannel, i);
  21694. }
  21695. }
  21696. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21697. {
  21698. if (message.isNoteOn())
  21699. {
  21700. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21701. }
  21702. else if (message.isNoteOff())
  21703. {
  21704. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21705. }
  21706. else if (message.isAllNotesOff())
  21707. {
  21708. for (int i = 0; i < 128; ++i)
  21709. noteOffInternal (message.getChannel(), i);
  21710. }
  21711. }
  21712. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21713. const int startSample,
  21714. const int numSamples,
  21715. const bool injectIndirectEvents)
  21716. {
  21717. MidiBuffer::Iterator i (buffer);
  21718. MidiMessage message (0xf4, 0.0);
  21719. int time;
  21720. const ScopedLock sl (lock);
  21721. while (i.getNextEvent (message, time))
  21722. processNextMidiEvent (message);
  21723. if (injectIndirectEvents)
  21724. {
  21725. MidiBuffer::Iterator i2 (eventsToAdd);
  21726. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21727. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21728. while (i2.getNextEvent (message, time))
  21729. {
  21730. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21731. buffer.addEvent (message, startSample + pos);
  21732. }
  21733. }
  21734. eventsToAdd.clear();
  21735. }
  21736. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  21737. {
  21738. const ScopedLock sl (lock);
  21739. listeners.addIfNotAlreadyThere (listener);
  21740. }
  21741. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  21742. {
  21743. const ScopedLock sl (lock);
  21744. listeners.removeValue (listener);
  21745. }
  21746. END_JUCE_NAMESPACE
  21747. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  21748. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  21749. BEGIN_JUCE_NAMESPACE
  21750. int MidiMessage::readVariableLengthVal (const uint8* data,
  21751. int& numBytesUsed) throw()
  21752. {
  21753. numBytesUsed = 0;
  21754. int v = 0;
  21755. int i;
  21756. do
  21757. {
  21758. i = (int) *data++;
  21759. if (++numBytesUsed > 6)
  21760. break;
  21761. v = (v << 7) + (i & 0x7f);
  21762. } while (i & 0x80);
  21763. return v;
  21764. }
  21765. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  21766. {
  21767. // this method only works for valid starting bytes of a short midi message
  21768. jassert (firstByte >= 0x80
  21769. && firstByte != 0xf0
  21770. && firstByte != 0xf7);
  21771. static const char messageLengths[] =
  21772. {
  21773. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21774. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21775. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21776. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21777. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21778. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21779. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21780. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  21781. };
  21782. return messageLengths [firstByte & 0x7f];
  21783. }
  21784. MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t)
  21785. : timeStamp (t),
  21786. size (dataSize)
  21787. {
  21788. jassert (dataSize > 0);
  21789. if (dataSize <= 4)
  21790. data = static_cast<uint8*> (preallocatedData.asBytes);
  21791. else
  21792. data = static_cast<uint8*> (juce_malloc (dataSize));
  21793. memcpy (data, d, dataSize);
  21794. // check that the length matches the data..
  21795. jassert (size > 3 || data[0] >= 0xf0 || getMessageLengthFromFirstByte (data[0]) == size);
  21796. }
  21797. MidiMessage::MidiMessage (const int byte1, const double t) throw()
  21798. : timeStamp (t),
  21799. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21800. size (1)
  21801. {
  21802. data[0] = (uint8) byte1;
  21803. // check that the length matches the data..
  21804. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  21805. }
  21806. MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) throw()
  21807. : timeStamp (t),
  21808. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21809. size (2)
  21810. {
  21811. data[0] = (uint8) byte1;
  21812. data[1] = (uint8) byte2;
  21813. // check that the length matches the data..
  21814. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  21815. }
  21816. MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, const double t) throw()
  21817. : timeStamp (t),
  21818. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21819. size (3)
  21820. {
  21821. data[0] = (uint8) byte1;
  21822. data[1] = (uint8) byte2;
  21823. data[2] = (uint8) byte3;
  21824. // check that the length matches the data..
  21825. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  21826. }
  21827. MidiMessage::MidiMessage (const MidiMessage& other)
  21828. : timeStamp (other.timeStamp),
  21829. size (other.size)
  21830. {
  21831. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21832. {
  21833. data = static_cast<uint8*> (juce_malloc (size));
  21834. memcpy (data, other.data, size);
  21835. }
  21836. else
  21837. {
  21838. data = static_cast<uint8*> (preallocatedData.asBytes);
  21839. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21840. }
  21841. }
  21842. MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp)
  21843. : timeStamp (newTimeStamp),
  21844. size (other.size)
  21845. {
  21846. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21847. {
  21848. data = static_cast<uint8*> (juce_malloc (size));
  21849. memcpy (data, other.data, size);
  21850. }
  21851. else
  21852. {
  21853. data = static_cast<uint8*> (preallocatedData.asBytes);
  21854. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21855. }
  21856. }
  21857. MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uint8 lastStatusByte, double t)
  21858. : timeStamp (t),
  21859. data (static_cast<uint8*> (preallocatedData.asBytes))
  21860. {
  21861. const uint8* src = static_cast <const uint8*> (src_);
  21862. unsigned int byte = (unsigned int) *src;
  21863. if (byte < 0x80)
  21864. {
  21865. byte = (unsigned int) (uint8) lastStatusByte;
  21866. numBytesUsed = -1;
  21867. }
  21868. else
  21869. {
  21870. numBytesUsed = 0;
  21871. --sz;
  21872. ++src;
  21873. }
  21874. if (byte >= 0x80)
  21875. {
  21876. if (byte == 0xf0)
  21877. {
  21878. const uint8* d = src;
  21879. while (d < src + sz)
  21880. {
  21881. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  21882. {
  21883. if (*d == 0xf7) // include an 0xf7 if we hit one
  21884. ++d;
  21885. break;
  21886. }
  21887. ++d;
  21888. }
  21889. size = 1 + (int) (d - src);
  21890. data = static_cast<uint8*> (juce_malloc (size));
  21891. *data = (uint8) byte;
  21892. memcpy (data + 1, src, size - 1);
  21893. }
  21894. else if (byte == 0xff)
  21895. {
  21896. int n;
  21897. const int bytesLeft = readVariableLengthVal (src + 1, n);
  21898. size = jmin (sz + 1, n + 2 + bytesLeft);
  21899. data = static_cast<uint8*> (juce_malloc (size));
  21900. *data = (uint8) byte;
  21901. memcpy (data + 1, src, size - 1);
  21902. }
  21903. else
  21904. {
  21905. preallocatedData.asInt32 = 0;
  21906. size = getMessageLengthFromFirstByte ((uint8) byte);
  21907. data[0] = (uint8) byte;
  21908. if (size > 1)
  21909. {
  21910. data[1] = src[0];
  21911. if (size > 2)
  21912. data[2] = src[1];
  21913. }
  21914. }
  21915. numBytesUsed += size;
  21916. }
  21917. else
  21918. {
  21919. preallocatedData.asInt32 = 0;
  21920. size = 0;
  21921. }
  21922. }
  21923. MidiMessage& MidiMessage::operator= (const MidiMessage& other)
  21924. {
  21925. if (this != &other)
  21926. {
  21927. timeStamp = other.timeStamp;
  21928. size = other.size;
  21929. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  21930. juce_free (data);
  21931. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21932. {
  21933. data = static_cast<uint8*> (juce_malloc (size));
  21934. memcpy (data, other.data, size);
  21935. }
  21936. else
  21937. {
  21938. data = static_cast<uint8*> (preallocatedData.asBytes);
  21939. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21940. }
  21941. }
  21942. return *this;
  21943. }
  21944. MidiMessage::~MidiMessage()
  21945. {
  21946. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  21947. juce_free (data);
  21948. }
  21949. int MidiMessage::getChannel() const throw()
  21950. {
  21951. if ((data[0] & 0xf0) != 0xf0)
  21952. return (data[0] & 0xf) + 1;
  21953. else
  21954. return 0;
  21955. }
  21956. bool MidiMessage::isForChannel (const int channel) const throw()
  21957. {
  21958. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  21959. return ((data[0] & 0xf) == channel - 1)
  21960. && ((data[0] & 0xf0) != 0xf0);
  21961. }
  21962. void MidiMessage::setChannel (const int channel) throw()
  21963. {
  21964. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  21965. if ((data[0] & 0xf0) != (uint8) 0xf0)
  21966. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  21967. | (uint8)(channel - 1));
  21968. }
  21969. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  21970. {
  21971. return ((data[0] & 0xf0) == 0x90)
  21972. && (returnTrueForVelocity0 || data[2] != 0);
  21973. }
  21974. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  21975. {
  21976. return ((data[0] & 0xf0) == 0x80)
  21977. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  21978. }
  21979. bool MidiMessage::isNoteOnOrOff() const throw()
  21980. {
  21981. const int d = data[0] & 0xf0;
  21982. return (d == 0x90) || (d == 0x80);
  21983. }
  21984. int MidiMessage::getNoteNumber() const throw()
  21985. {
  21986. return data[1];
  21987. }
  21988. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  21989. {
  21990. if (isNoteOnOrOff())
  21991. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  21992. }
  21993. uint8 MidiMessage::getVelocity() const throw()
  21994. {
  21995. if (isNoteOnOrOff())
  21996. return data[2];
  21997. else
  21998. return 0;
  21999. }
  22000. float MidiMessage::getFloatVelocity() const throw()
  22001. {
  22002. return getVelocity() * (1.0f / 127.0f);
  22003. }
  22004. void MidiMessage::setVelocity (const float newVelocity) throw()
  22005. {
  22006. if (isNoteOnOrOff())
  22007. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22008. }
  22009. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22010. {
  22011. if (isNoteOnOrOff())
  22012. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22013. }
  22014. bool MidiMessage::isAftertouch() const throw()
  22015. {
  22016. return (data[0] & 0xf0) == 0xa0;
  22017. }
  22018. int MidiMessage::getAfterTouchValue() const throw()
  22019. {
  22020. return data[2];
  22021. }
  22022. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22023. const int noteNum,
  22024. const int aftertouchValue) throw()
  22025. {
  22026. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22027. jassert (((unsigned int) noteNum) <= 127);
  22028. jassert (((unsigned int) aftertouchValue) <= 127);
  22029. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22030. noteNum & 0x7f,
  22031. aftertouchValue & 0x7f);
  22032. }
  22033. bool MidiMessage::isChannelPressure() const throw()
  22034. {
  22035. return (data[0] & 0xf0) == 0xd0;
  22036. }
  22037. int MidiMessage::getChannelPressureValue() const throw()
  22038. {
  22039. jassert (isChannelPressure());
  22040. return data[1];
  22041. }
  22042. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22043. const int pressure) throw()
  22044. {
  22045. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22046. jassert (((unsigned int) pressure) <= 127);
  22047. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22048. pressure & 0x7f);
  22049. }
  22050. bool MidiMessage::isProgramChange() const throw()
  22051. {
  22052. return (data[0] & 0xf0) == 0xc0;
  22053. }
  22054. int MidiMessage::getProgramChangeNumber() const throw()
  22055. {
  22056. return data[1];
  22057. }
  22058. const MidiMessage MidiMessage::programChange (const int channel,
  22059. const int programNumber) throw()
  22060. {
  22061. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22062. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22063. programNumber & 0x7f);
  22064. }
  22065. bool MidiMessage::isPitchWheel() const throw()
  22066. {
  22067. return (data[0] & 0xf0) == 0xe0;
  22068. }
  22069. int MidiMessage::getPitchWheelValue() const throw()
  22070. {
  22071. return data[1] | (data[2] << 7);
  22072. }
  22073. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22074. const int position) throw()
  22075. {
  22076. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22077. jassert (((unsigned int) position) <= 0x3fff);
  22078. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22079. position & 127,
  22080. (position >> 7) & 127);
  22081. }
  22082. bool MidiMessage::isController() const throw()
  22083. {
  22084. return (data[0] & 0xf0) == 0xb0;
  22085. }
  22086. int MidiMessage::getControllerNumber() const throw()
  22087. {
  22088. jassert (isController());
  22089. return data[1];
  22090. }
  22091. int MidiMessage::getControllerValue() const throw()
  22092. {
  22093. jassert (isController());
  22094. return data[2];
  22095. }
  22096. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22097. const int controllerType,
  22098. const int value) throw()
  22099. {
  22100. // the channel must be between 1 and 16 inclusive
  22101. jassert (channel > 0 && channel <= 16);
  22102. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22103. controllerType & 127,
  22104. value & 127);
  22105. }
  22106. const MidiMessage MidiMessage::noteOn (const int channel,
  22107. const int noteNumber,
  22108. const float velocity) throw()
  22109. {
  22110. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22111. }
  22112. const MidiMessage MidiMessage::noteOn (const int channel,
  22113. const int noteNumber,
  22114. const uint8 velocity) throw()
  22115. {
  22116. jassert (channel > 0 && channel <= 16);
  22117. jassert (((unsigned int) noteNumber) <= 127);
  22118. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22119. noteNumber & 127,
  22120. jlimit (0, 127, roundToInt (velocity)));
  22121. }
  22122. const MidiMessage MidiMessage::noteOff (const int channel,
  22123. const int noteNumber) throw()
  22124. {
  22125. jassert (channel > 0 && channel <= 16);
  22126. jassert (((unsigned int) noteNumber) <= 127);
  22127. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22128. }
  22129. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22130. {
  22131. jassert (channel > 0 && channel <= 16);
  22132. return controllerEvent (channel, 123, 0);
  22133. }
  22134. bool MidiMessage::isAllNotesOff() const throw()
  22135. {
  22136. return (data[0] & 0xf0) == 0xb0
  22137. && data[1] == 123;
  22138. }
  22139. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22140. {
  22141. return controllerEvent (channel, 120, 0);
  22142. }
  22143. bool MidiMessage::isAllSoundOff() const throw()
  22144. {
  22145. return (data[0] & 0xf0) == 0xb0
  22146. && data[1] == 120;
  22147. }
  22148. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22149. {
  22150. return controllerEvent (channel, 121, 0);
  22151. }
  22152. const MidiMessage MidiMessage::masterVolume (const float volume)
  22153. {
  22154. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22155. uint8 buf[8];
  22156. buf[0] = 0xf0;
  22157. buf[1] = 0x7f;
  22158. buf[2] = 0x7f;
  22159. buf[3] = 0x04;
  22160. buf[4] = 0x01;
  22161. buf[5] = (uint8) (vol & 0x7f);
  22162. buf[6] = (uint8) (vol >> 7);
  22163. buf[7] = 0xf7;
  22164. return MidiMessage (buf, 8);
  22165. }
  22166. bool MidiMessage::isSysEx() const throw()
  22167. {
  22168. return *data == 0xf0;
  22169. }
  22170. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData, const int dataSize)
  22171. {
  22172. MemoryBlock mm (dataSize + 2);
  22173. uint8* const m = static_cast <uint8*> (mm.getData());
  22174. m[0] = 0xf0;
  22175. memcpy (m + 1, sysexData, dataSize);
  22176. m[dataSize + 1] = 0xf7;
  22177. return MidiMessage (m, dataSize + 2);
  22178. }
  22179. const uint8* MidiMessage::getSysExData() const throw()
  22180. {
  22181. return (isSysEx()) ? getRawData() + 1 : 0;
  22182. }
  22183. int MidiMessage::getSysExDataSize() const throw()
  22184. {
  22185. return (isSysEx()) ? size - 2 : 0;
  22186. }
  22187. bool MidiMessage::isMetaEvent() const throw()
  22188. {
  22189. return *data == 0xff;
  22190. }
  22191. bool MidiMessage::isActiveSense() const throw()
  22192. {
  22193. return *data == 0xfe;
  22194. }
  22195. int MidiMessage::getMetaEventType() const throw()
  22196. {
  22197. if (*data != 0xff)
  22198. return -1;
  22199. else
  22200. return data[1];
  22201. }
  22202. int MidiMessage::getMetaEventLength() const throw()
  22203. {
  22204. if (*data == 0xff)
  22205. {
  22206. int n;
  22207. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22208. }
  22209. return 0;
  22210. }
  22211. const uint8* MidiMessage::getMetaEventData() const throw()
  22212. {
  22213. int n;
  22214. const uint8* d = data + 2;
  22215. readVariableLengthVal (d, n);
  22216. return d + n;
  22217. }
  22218. bool MidiMessage::isTrackMetaEvent() const throw()
  22219. {
  22220. return getMetaEventType() == 0;
  22221. }
  22222. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22223. {
  22224. return getMetaEventType() == 47;
  22225. }
  22226. bool MidiMessage::isTextMetaEvent() const throw()
  22227. {
  22228. const int t = getMetaEventType();
  22229. return t > 0 && t < 16;
  22230. }
  22231. const String MidiMessage::getTextFromTextMetaEvent() const
  22232. {
  22233. return String (reinterpret_cast <const char*> (getMetaEventData()), getMetaEventLength());
  22234. }
  22235. bool MidiMessage::isTrackNameEvent() const throw()
  22236. {
  22237. return (data[1] == 3)
  22238. && (*data == 0xff);
  22239. }
  22240. bool MidiMessage::isTempoMetaEvent() const throw()
  22241. {
  22242. return (data[1] == 81)
  22243. && (*data == 0xff);
  22244. }
  22245. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22246. {
  22247. return (data[1] == 0x20)
  22248. && (*data == 0xff)
  22249. && (data[2] == 1);
  22250. }
  22251. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22252. {
  22253. return data[3] + 1;
  22254. }
  22255. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22256. {
  22257. if (! isTempoMetaEvent())
  22258. return 0.0;
  22259. const uint8* const d = getMetaEventData();
  22260. return (((unsigned int) d[0] << 16)
  22261. | ((unsigned int) d[1] << 8)
  22262. | d[2])
  22263. / 1000000.0;
  22264. }
  22265. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22266. {
  22267. if (timeFormat > 0)
  22268. {
  22269. if (! isTempoMetaEvent())
  22270. return 0.5 / timeFormat;
  22271. return getTempoSecondsPerQuarterNote() / timeFormat;
  22272. }
  22273. else
  22274. {
  22275. const int frameCode = (-timeFormat) >> 8;
  22276. double framesPerSecond;
  22277. switch (frameCode)
  22278. {
  22279. case 24: framesPerSecond = 24.0; break;
  22280. case 25: framesPerSecond = 25.0; break;
  22281. case 29: framesPerSecond = 29.97; break;
  22282. case 30: framesPerSecond = 30.0; break;
  22283. default: framesPerSecond = 30.0; break;
  22284. }
  22285. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22286. }
  22287. }
  22288. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22289. {
  22290. uint8 d[8];
  22291. d[0] = 0xff;
  22292. d[1] = 81;
  22293. d[2] = 3;
  22294. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22295. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22296. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22297. return MidiMessage (d, 6, 0.0);
  22298. }
  22299. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22300. {
  22301. return (data[1] == 0x58)
  22302. && (*data == (uint8) 0xff);
  22303. }
  22304. void MidiMessage::getTimeSignatureInfo (int& numerator, int& denominator) const throw()
  22305. {
  22306. if (isTimeSignatureMetaEvent())
  22307. {
  22308. const uint8* const d = getMetaEventData();
  22309. numerator = d[0];
  22310. denominator = 1 << d[1];
  22311. }
  22312. else
  22313. {
  22314. numerator = 4;
  22315. denominator = 4;
  22316. }
  22317. }
  22318. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator, const int denominator)
  22319. {
  22320. uint8 d[8];
  22321. d[0] = 0xff;
  22322. d[1] = 0x58;
  22323. d[2] = 0x04;
  22324. d[3] = (uint8) numerator;
  22325. int n = 1;
  22326. int powerOfTwo = 0;
  22327. while (n < denominator)
  22328. {
  22329. n <<= 1;
  22330. ++powerOfTwo;
  22331. }
  22332. d[4] = (uint8) powerOfTwo;
  22333. d[5] = 0x01;
  22334. d[6] = 96;
  22335. return MidiMessage (d, 7, 0.0);
  22336. }
  22337. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22338. {
  22339. uint8 d[8];
  22340. d[0] = 0xff;
  22341. d[1] = 0x20;
  22342. d[2] = 0x01;
  22343. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22344. return MidiMessage (d, 4, 0.0);
  22345. }
  22346. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22347. {
  22348. return getMetaEventType() == 89;
  22349. }
  22350. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22351. {
  22352. return (int) *getMetaEventData();
  22353. }
  22354. const MidiMessage MidiMessage::endOfTrack() throw()
  22355. {
  22356. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22357. }
  22358. bool MidiMessage::isSongPositionPointer() const throw()
  22359. {
  22360. return *data == 0xf2;
  22361. }
  22362. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22363. {
  22364. return data[1] | (data[2] << 7);
  22365. }
  22366. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22367. {
  22368. return MidiMessage (0xf2,
  22369. positionInMidiBeats & 127,
  22370. (positionInMidiBeats >> 7) & 127);
  22371. }
  22372. bool MidiMessage::isMidiStart() const throw()
  22373. {
  22374. return *data == 0xfa;
  22375. }
  22376. const MidiMessage MidiMessage::midiStart() throw()
  22377. {
  22378. return MidiMessage (0xfa);
  22379. }
  22380. bool MidiMessage::isMidiContinue() const throw()
  22381. {
  22382. return *data == 0xfb;
  22383. }
  22384. const MidiMessage MidiMessage::midiContinue() throw()
  22385. {
  22386. return MidiMessage (0xfb);
  22387. }
  22388. bool MidiMessage::isMidiStop() const throw()
  22389. {
  22390. return *data == 0xfc;
  22391. }
  22392. const MidiMessage MidiMessage::midiStop() throw()
  22393. {
  22394. return MidiMessage (0xfc);
  22395. }
  22396. bool MidiMessage::isMidiClock() const throw()
  22397. {
  22398. return *data == 0xf8;
  22399. }
  22400. const MidiMessage MidiMessage::midiClock() throw()
  22401. {
  22402. return MidiMessage (0xf8);
  22403. }
  22404. bool MidiMessage::isQuarterFrame() const throw()
  22405. {
  22406. return *data == 0xf1;
  22407. }
  22408. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22409. {
  22410. return ((int) data[1]) >> 4;
  22411. }
  22412. int MidiMessage::getQuarterFrameValue() const throw()
  22413. {
  22414. return ((int) data[1]) & 0x0f;
  22415. }
  22416. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22417. const int value) throw()
  22418. {
  22419. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22420. }
  22421. bool MidiMessage::isFullFrame() const throw()
  22422. {
  22423. return data[0] == 0xf0
  22424. && data[1] == 0x7f
  22425. && size >= 10
  22426. && data[3] == 0x01
  22427. && data[4] == 0x01;
  22428. }
  22429. void MidiMessage::getFullFrameParameters (int& hours,
  22430. int& minutes,
  22431. int& seconds,
  22432. int& frames,
  22433. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22434. {
  22435. jassert (isFullFrame());
  22436. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22437. hours = data[5] & 0x1f;
  22438. minutes = data[6];
  22439. seconds = data[7];
  22440. frames = data[8];
  22441. }
  22442. const MidiMessage MidiMessage::fullFrame (const int hours,
  22443. const int minutes,
  22444. const int seconds,
  22445. const int frames,
  22446. MidiMessage::SmpteTimecodeType timecodeType)
  22447. {
  22448. uint8 d[10];
  22449. d[0] = 0xf0;
  22450. d[1] = 0x7f;
  22451. d[2] = 0x7f;
  22452. d[3] = 0x01;
  22453. d[4] = 0x01;
  22454. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22455. d[6] = (uint8) minutes;
  22456. d[7] = (uint8) seconds;
  22457. d[8] = (uint8) frames;
  22458. d[9] = 0xf7;
  22459. return MidiMessage (d, 10, 0.0);
  22460. }
  22461. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22462. {
  22463. return data[0] == 0xf0
  22464. && data[1] == 0x7f
  22465. && data[3] == 0x06
  22466. && size > 5;
  22467. }
  22468. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22469. {
  22470. jassert (isMidiMachineControlMessage());
  22471. return (MidiMachineControlCommand) data[4];
  22472. }
  22473. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22474. {
  22475. uint8 d[6];
  22476. d[0] = 0xf0;
  22477. d[1] = 0x7f;
  22478. d[2] = 0x00;
  22479. d[3] = 0x06;
  22480. d[4] = (uint8) command;
  22481. d[5] = 0xf7;
  22482. return MidiMessage (d, 6, 0.0);
  22483. }
  22484. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22485. int& minutes,
  22486. int& seconds,
  22487. int& frames) const throw()
  22488. {
  22489. if (size >= 12
  22490. && data[0] == 0xf0
  22491. && data[1] == 0x7f
  22492. && data[3] == 0x06
  22493. && data[4] == 0x44
  22494. && data[5] == 0x06
  22495. && data[6] == 0x01)
  22496. {
  22497. hours = data[7] % 24; // (that some machines send out hours > 24)
  22498. minutes = data[8];
  22499. seconds = data[9];
  22500. frames = data[10];
  22501. return true;
  22502. }
  22503. return false;
  22504. }
  22505. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22506. int minutes,
  22507. int seconds,
  22508. int frames)
  22509. {
  22510. uint8 d[12];
  22511. d[0] = 0xf0;
  22512. d[1] = 0x7f;
  22513. d[2] = 0x00;
  22514. d[3] = 0x06;
  22515. d[4] = 0x44;
  22516. d[5] = 0x06;
  22517. d[6] = 0x01;
  22518. d[7] = (uint8) hours;
  22519. d[8] = (uint8) minutes;
  22520. d[9] = (uint8) seconds;
  22521. d[10] = (uint8) frames;
  22522. d[11] = 0xf7;
  22523. return MidiMessage (d, 12, 0.0);
  22524. }
  22525. const String MidiMessage::getMidiNoteName (int note,
  22526. bool useSharps,
  22527. bool includeOctaveNumber,
  22528. int octaveNumForMiddleC) throw()
  22529. {
  22530. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22531. "F", "F#", "G", "G#", "A",
  22532. "A#", "B" };
  22533. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22534. "F", "Gb", "G", "Ab", "A",
  22535. "Bb", "B" };
  22536. if (((unsigned int) note) < 128)
  22537. {
  22538. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22539. : flatNoteNames [note % 12]);
  22540. if (includeOctaveNumber)
  22541. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22542. else
  22543. return s;
  22544. }
  22545. return String::empty;
  22546. }
  22547. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22548. {
  22549. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22550. return 440.0 * pow (2.0, noteNumber / 12.0);
  22551. }
  22552. const String MidiMessage::getGMInstrumentName (int n) throw()
  22553. {
  22554. const char *names[] =
  22555. {
  22556. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22557. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22558. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22559. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22560. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22561. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22562. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22563. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22564. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22565. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22566. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22567. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22568. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22569. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22570. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22571. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22572. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22573. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22574. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22575. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22576. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22577. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22578. "Applause", "Gunshot"
  22579. };
  22580. return (((unsigned int) n) < 128) ? names[n]
  22581. : (const char*)0;
  22582. }
  22583. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22584. {
  22585. const char* names[] =
  22586. {
  22587. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22588. "Bass", "Strings", "Ensemble", "Brass",
  22589. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22590. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22591. };
  22592. return (((unsigned int) n) <= 15) ? names[n]
  22593. : (const char*)0;
  22594. }
  22595. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22596. {
  22597. const char* names[] =
  22598. {
  22599. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22600. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22601. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22602. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22603. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22604. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22605. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22606. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22607. "Mute Triangle", "Open Triangle"
  22608. };
  22609. return (n >= 35 && n <= 81) ? names [n - 35]
  22610. : (const char*)0;
  22611. }
  22612. const String MidiMessage::getControllerName (int n) throw()
  22613. {
  22614. const char* names[] =
  22615. {
  22616. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22617. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22618. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22619. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22620. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22621. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22622. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22623. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22624. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22625. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22626. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22627. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22628. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22629. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22630. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22631. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22632. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22633. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22634. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22636. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22637. "Poly Operation"
  22638. };
  22639. return (((unsigned int) n) < 128) ? names[n]
  22640. : (const char*)0;
  22641. }
  22642. END_JUCE_NAMESPACE
  22643. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22644. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22645. BEGIN_JUCE_NAMESPACE
  22646. MidiMessageCollector::MidiMessageCollector()
  22647. : lastCallbackTime (0),
  22648. sampleRate (44100.0001)
  22649. {
  22650. }
  22651. MidiMessageCollector::~MidiMessageCollector()
  22652. {
  22653. }
  22654. void MidiMessageCollector::reset (const double sampleRate_)
  22655. {
  22656. jassert (sampleRate_ > 0);
  22657. const ScopedLock sl (midiCallbackLock);
  22658. sampleRate = sampleRate_;
  22659. incomingMessages.clear();
  22660. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22661. }
  22662. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22663. {
  22664. // you need to call reset() to set the correct sample rate before using this object
  22665. jassert (sampleRate != 44100.0001);
  22666. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22667. // for details of what the number should be.
  22668. jassert (message.getTimeStamp() != 0);
  22669. const ScopedLock sl (midiCallbackLock);
  22670. const int sampleNumber
  22671. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22672. incomingMessages.addEvent (message, sampleNumber);
  22673. // if the messages don't get used for over a second, we'd better
  22674. // get rid of any old ones to avoid the queue getting too big
  22675. if (sampleNumber > sampleRate)
  22676. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22677. }
  22678. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22679. const int numSamples)
  22680. {
  22681. // you need to call reset() to set the correct sample rate before using this object
  22682. jassert (sampleRate != 44100.0001);
  22683. const double timeNow = Time::getMillisecondCounterHiRes();
  22684. const double msElapsed = timeNow - lastCallbackTime;
  22685. const ScopedLock sl (midiCallbackLock);
  22686. lastCallbackTime = timeNow;
  22687. if (! incomingMessages.isEmpty())
  22688. {
  22689. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22690. int startSample = 0;
  22691. int scale = 1 << 16;
  22692. const uint8* midiData;
  22693. int numBytes, samplePosition;
  22694. MidiBuffer::Iterator iter (incomingMessages);
  22695. if (numSourceSamples > numSamples)
  22696. {
  22697. // if our list of events is longer than the buffer we're being
  22698. // asked for, scale them down to squeeze them all in..
  22699. const int maxBlockLengthToUse = numSamples << 5;
  22700. if (numSourceSamples > maxBlockLengthToUse)
  22701. {
  22702. startSample = numSourceSamples - maxBlockLengthToUse;
  22703. numSourceSamples = maxBlockLengthToUse;
  22704. iter.setNextSamplePosition (startSample);
  22705. }
  22706. scale = (numSamples << 10) / numSourceSamples;
  22707. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22708. {
  22709. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22710. destBuffer.addEvent (midiData, numBytes,
  22711. jlimit (0, numSamples - 1, samplePosition));
  22712. }
  22713. }
  22714. else
  22715. {
  22716. // if our event list is shorter than the number we need, put them
  22717. // towards the end of the buffer
  22718. startSample = numSamples - numSourceSamples;
  22719. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22720. {
  22721. destBuffer.addEvent (midiData, numBytes,
  22722. jlimit (0, numSamples - 1, samplePosition + startSample));
  22723. }
  22724. }
  22725. incomingMessages.clear();
  22726. }
  22727. }
  22728. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  22729. {
  22730. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  22731. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22732. addMessageToQueue (m);
  22733. }
  22734. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  22735. {
  22736. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  22737. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22738. addMessageToQueue (m);
  22739. }
  22740. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  22741. {
  22742. addMessageToQueue (message);
  22743. }
  22744. END_JUCE_NAMESPACE
  22745. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  22746. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  22747. BEGIN_JUCE_NAMESPACE
  22748. MidiMessageSequence::MidiMessageSequence()
  22749. {
  22750. }
  22751. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  22752. {
  22753. list.ensureStorageAllocated (other.list.size());
  22754. for (int i = 0; i < other.list.size(); ++i)
  22755. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  22756. }
  22757. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  22758. {
  22759. MidiMessageSequence otherCopy (other);
  22760. swapWith (otherCopy);
  22761. return *this;
  22762. }
  22763. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  22764. {
  22765. list.swapWithArray (other.list);
  22766. }
  22767. MidiMessageSequence::~MidiMessageSequence()
  22768. {
  22769. }
  22770. void MidiMessageSequence::clear()
  22771. {
  22772. list.clear();
  22773. }
  22774. int MidiMessageSequence::getNumEvents() const
  22775. {
  22776. return list.size();
  22777. }
  22778. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  22779. {
  22780. return list [index];
  22781. }
  22782. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  22783. {
  22784. const MidiEventHolder* const meh = list [index];
  22785. if (meh != 0 && meh->noteOffObject != 0)
  22786. return meh->noteOffObject->message.getTimeStamp();
  22787. else
  22788. return 0.0;
  22789. }
  22790. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  22791. {
  22792. const MidiEventHolder* const meh = list [index];
  22793. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  22794. }
  22795. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  22796. {
  22797. return list.indexOf (event);
  22798. }
  22799. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  22800. {
  22801. const int numEvents = list.size();
  22802. int i;
  22803. for (i = 0; i < numEvents; ++i)
  22804. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  22805. break;
  22806. return i;
  22807. }
  22808. double MidiMessageSequence::getStartTime() const
  22809. {
  22810. if (list.size() > 0)
  22811. return list.getUnchecked(0)->message.getTimeStamp();
  22812. else
  22813. return 0;
  22814. }
  22815. double MidiMessageSequence::getEndTime() const
  22816. {
  22817. if (list.size() > 0)
  22818. return list.getLast()->message.getTimeStamp();
  22819. else
  22820. return 0;
  22821. }
  22822. double MidiMessageSequence::getEventTime (const int index) const
  22823. {
  22824. if (((unsigned int) index) < (unsigned int) list.size())
  22825. return list.getUnchecked (index)->message.getTimeStamp();
  22826. return 0.0;
  22827. }
  22828. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  22829. double timeAdjustment)
  22830. {
  22831. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  22832. timeAdjustment += newMessage.getTimeStamp();
  22833. newOne->message.setTimeStamp (timeAdjustment);
  22834. int i;
  22835. for (i = list.size(); --i >= 0;)
  22836. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  22837. break;
  22838. list.insert (i + 1, newOne);
  22839. }
  22840. void MidiMessageSequence::deleteEvent (const int index,
  22841. const bool deleteMatchingNoteUp)
  22842. {
  22843. if (((unsigned int) index) < (unsigned int) list.size())
  22844. {
  22845. if (deleteMatchingNoteUp)
  22846. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  22847. list.remove (index);
  22848. }
  22849. }
  22850. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  22851. double timeAdjustment,
  22852. double firstAllowableTime,
  22853. double endOfAllowableDestTimes)
  22854. {
  22855. firstAllowableTime -= timeAdjustment;
  22856. endOfAllowableDestTimes -= timeAdjustment;
  22857. for (int i = 0; i < other.list.size(); ++i)
  22858. {
  22859. const MidiMessage& m = other.list.getUnchecked(i)->message;
  22860. const double t = m.getTimeStamp();
  22861. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  22862. {
  22863. MidiEventHolder* const newOne = new MidiEventHolder (m);
  22864. newOne->message.setTimeStamp (timeAdjustment + t);
  22865. list.add (newOne);
  22866. }
  22867. }
  22868. sort();
  22869. }
  22870. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  22871. const MidiMessageSequence::MidiEventHolder* const second) throw()
  22872. {
  22873. const double diff = first->message.getTimeStamp()
  22874. - second->message.getTimeStamp();
  22875. return (diff > 0) - (diff < 0);
  22876. }
  22877. void MidiMessageSequence::sort()
  22878. {
  22879. list.sort (*this, true);
  22880. }
  22881. void MidiMessageSequence::updateMatchedPairs()
  22882. {
  22883. for (int i = 0; i < list.size(); ++i)
  22884. {
  22885. const MidiMessage& m1 = list.getUnchecked(i)->message;
  22886. if (m1.isNoteOn())
  22887. {
  22888. list.getUnchecked(i)->noteOffObject = 0;
  22889. const int note = m1.getNoteNumber();
  22890. const int chan = m1.getChannel();
  22891. const int len = list.size();
  22892. for (int j = i + 1; j < len; ++j)
  22893. {
  22894. const MidiMessage& m = list.getUnchecked(j)->message;
  22895. if (m.getNoteNumber() == note && m.getChannel() == chan)
  22896. {
  22897. if (m.isNoteOff())
  22898. {
  22899. list.getUnchecked(i)->noteOffObject = list[j];
  22900. break;
  22901. }
  22902. else if (m.isNoteOn())
  22903. {
  22904. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  22905. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  22906. list.getUnchecked(i)->noteOffObject = list[j];
  22907. break;
  22908. }
  22909. }
  22910. }
  22911. }
  22912. }
  22913. }
  22914. void MidiMessageSequence::addTimeToMessages (const double delta)
  22915. {
  22916. for (int i = list.size(); --i >= 0;)
  22917. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  22918. + delta);
  22919. }
  22920. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  22921. MidiMessageSequence& destSequence,
  22922. const bool alsoIncludeMetaEvents) const
  22923. {
  22924. for (int i = 0; i < list.size(); ++i)
  22925. {
  22926. const MidiMessage& mm = list.getUnchecked(i)->message;
  22927. if (mm.isForChannel (channelNumberToExtract)
  22928. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  22929. {
  22930. destSequence.addEvent (mm);
  22931. }
  22932. }
  22933. }
  22934. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  22935. {
  22936. for (int i = 0; i < list.size(); ++i)
  22937. {
  22938. const MidiMessage& mm = list.getUnchecked(i)->message;
  22939. if (mm.isSysEx())
  22940. destSequence.addEvent (mm);
  22941. }
  22942. }
  22943. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  22944. {
  22945. for (int i = list.size(); --i >= 0;)
  22946. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  22947. list.remove(i);
  22948. }
  22949. void MidiMessageSequence::deleteSysExMessages()
  22950. {
  22951. for (int i = list.size(); --i >= 0;)
  22952. if (list.getUnchecked(i)->message.isSysEx())
  22953. list.remove(i);
  22954. }
  22955. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  22956. const double time,
  22957. OwnedArray<MidiMessage>& dest)
  22958. {
  22959. bool doneProg = false;
  22960. bool donePitchWheel = false;
  22961. Array <int> doneControllers;
  22962. doneControllers.ensureStorageAllocated (32);
  22963. for (int i = list.size(); --i >= 0;)
  22964. {
  22965. const MidiMessage& mm = list.getUnchecked(i)->message;
  22966. if (mm.isForChannel (channelNumber)
  22967. && mm.getTimeStamp() <= time)
  22968. {
  22969. if (mm.isProgramChange())
  22970. {
  22971. if (! doneProg)
  22972. {
  22973. dest.add (new MidiMessage (mm, 0.0));
  22974. doneProg = true;
  22975. }
  22976. }
  22977. else if (mm.isController())
  22978. {
  22979. if (! doneControllers.contains (mm.getControllerNumber()))
  22980. {
  22981. dest.add (new MidiMessage (mm, 0.0));
  22982. doneControllers.add (mm.getControllerNumber());
  22983. }
  22984. }
  22985. else if (mm.isPitchWheel())
  22986. {
  22987. if (! donePitchWheel)
  22988. {
  22989. dest.add (new MidiMessage (mm, 0.0));
  22990. donePitchWheel = true;
  22991. }
  22992. }
  22993. }
  22994. }
  22995. }
  22996. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  22997. : message (message_),
  22998. noteOffObject (0)
  22999. {
  23000. }
  23001. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23002. {
  23003. }
  23004. END_JUCE_NAMESPACE
  23005. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23006. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23007. BEGIN_JUCE_NAMESPACE
  23008. AudioPluginFormat::AudioPluginFormat() throw()
  23009. {
  23010. }
  23011. AudioPluginFormat::~AudioPluginFormat()
  23012. {
  23013. }
  23014. END_JUCE_NAMESPACE
  23015. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23016. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23017. BEGIN_JUCE_NAMESPACE
  23018. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23019. {
  23020. }
  23021. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23022. {
  23023. clearSingletonInstance();
  23024. }
  23025. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23026. void AudioPluginFormatManager::addDefaultFormats()
  23027. {
  23028. #ifdef JUCE_DEBUG
  23029. // you should only call this method once!
  23030. for (int i = formats.size(); --i >= 0;)
  23031. {
  23032. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23033. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23034. #endif
  23035. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23036. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23037. #endif
  23038. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23039. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23040. #endif
  23041. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23042. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23043. #endif
  23044. }
  23045. #endif
  23046. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23047. formats.add (new AudioUnitPluginFormat());
  23048. #endif
  23049. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23050. formats.add (new VSTPluginFormat());
  23051. #endif
  23052. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23053. formats.add (new DirectXPluginFormat());
  23054. #endif
  23055. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23056. formats.add (new LADSPAPluginFormat());
  23057. #endif
  23058. }
  23059. int AudioPluginFormatManager::getNumFormats() throw()
  23060. {
  23061. return formats.size();
  23062. }
  23063. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23064. {
  23065. return formats [index];
  23066. }
  23067. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23068. {
  23069. formats.add (format);
  23070. }
  23071. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23072. String& errorMessage) const
  23073. {
  23074. AudioPluginInstance* result = 0;
  23075. for (int i = 0; i < formats.size(); ++i)
  23076. {
  23077. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23078. if (result != 0)
  23079. break;
  23080. }
  23081. if (result == 0)
  23082. {
  23083. if (! doesPluginStillExist (description))
  23084. errorMessage = TRANS ("This plug-in file no longer exists");
  23085. else
  23086. errorMessage = TRANS ("This plug-in failed to load correctly");
  23087. }
  23088. return result;
  23089. }
  23090. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23091. {
  23092. for (int i = 0; i < formats.size(); ++i)
  23093. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23094. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23095. return false;
  23096. }
  23097. END_JUCE_NAMESPACE
  23098. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23099. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23100. #define JUCE_PLUGIN_HOST 1
  23101. BEGIN_JUCE_NAMESPACE
  23102. AudioPluginInstance::AudioPluginInstance()
  23103. {
  23104. }
  23105. AudioPluginInstance::~AudioPluginInstance()
  23106. {
  23107. }
  23108. END_JUCE_NAMESPACE
  23109. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23110. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23111. BEGIN_JUCE_NAMESPACE
  23112. KnownPluginList::KnownPluginList()
  23113. {
  23114. }
  23115. KnownPluginList::~KnownPluginList()
  23116. {
  23117. }
  23118. void KnownPluginList::clear()
  23119. {
  23120. if (types.size() > 0)
  23121. {
  23122. types.clear();
  23123. sendChangeMessage (this);
  23124. }
  23125. }
  23126. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23127. {
  23128. for (int i = 0; i < types.size(); ++i)
  23129. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23130. return types.getUnchecked(i);
  23131. return 0;
  23132. }
  23133. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23134. {
  23135. for (int i = 0; i < types.size(); ++i)
  23136. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23137. return types.getUnchecked(i);
  23138. return 0;
  23139. }
  23140. bool KnownPluginList::addType (const PluginDescription& type)
  23141. {
  23142. for (int i = types.size(); --i >= 0;)
  23143. {
  23144. if (types.getUnchecked(i)->isDuplicateOf (type))
  23145. {
  23146. // strange - found a duplicate plugin with different info..
  23147. jassert (types.getUnchecked(i)->name == type.name);
  23148. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23149. *types.getUnchecked(i) = type;
  23150. return false;
  23151. }
  23152. }
  23153. types.add (new PluginDescription (type));
  23154. sendChangeMessage (this);
  23155. return true;
  23156. }
  23157. void KnownPluginList::removeType (const int index) throw()
  23158. {
  23159. types.remove (index);
  23160. sendChangeMessage (this);
  23161. }
  23162. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23163. {
  23164. if (fileOrIdentifier.startsWithChar ('/')
  23165. || fileOrIdentifier[1] == ':')
  23166. {
  23167. return File (fileOrIdentifier).getLastModificationTime();
  23168. }
  23169. return Time (0);
  23170. }
  23171. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23172. {
  23173. return t1 != t2 || t1 == Time (0);
  23174. }
  23175. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23176. {
  23177. if (getTypeForFile (fileOrIdentifier) == 0)
  23178. return false;
  23179. for (int i = types.size(); --i >= 0;)
  23180. {
  23181. const PluginDescription* const d = types.getUnchecked(i);
  23182. if (d->fileOrIdentifier == fileOrIdentifier
  23183. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23184. {
  23185. return false;
  23186. }
  23187. }
  23188. return true;
  23189. }
  23190. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23191. const bool dontRescanIfAlreadyInList,
  23192. OwnedArray <PluginDescription>& typesFound,
  23193. AudioPluginFormat& format)
  23194. {
  23195. bool addedOne = false;
  23196. if (dontRescanIfAlreadyInList
  23197. && getTypeForFile (fileOrIdentifier) != 0)
  23198. {
  23199. bool needsRescanning = false;
  23200. for (int i = types.size(); --i >= 0;)
  23201. {
  23202. const PluginDescription* const d = types.getUnchecked(i);
  23203. if (d->fileOrIdentifier == fileOrIdentifier)
  23204. {
  23205. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23206. needsRescanning = true;
  23207. else
  23208. typesFound.add (new PluginDescription (*d));
  23209. }
  23210. }
  23211. if (! needsRescanning)
  23212. return false;
  23213. }
  23214. OwnedArray <PluginDescription> found;
  23215. format.findAllTypesForFile (found, fileOrIdentifier);
  23216. for (int i = 0; i < found.size(); ++i)
  23217. {
  23218. PluginDescription* const desc = found.getUnchecked(i);
  23219. jassert (desc != 0);
  23220. if (addType (*desc))
  23221. addedOne = true;
  23222. typesFound.add (new PluginDescription (*desc));
  23223. }
  23224. return addedOne;
  23225. }
  23226. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23227. OwnedArray <PluginDescription>& typesFound)
  23228. {
  23229. for (int i = 0; i < files.size(); ++i)
  23230. {
  23231. bool loaded = false;
  23232. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23233. {
  23234. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23235. if (scanAndAddFile (files[i], true, typesFound, *format))
  23236. loaded = true;
  23237. }
  23238. if (! loaded)
  23239. {
  23240. const File f (files[i]);
  23241. if (f.isDirectory())
  23242. {
  23243. StringArray s;
  23244. {
  23245. Array<File> subFiles;
  23246. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23247. for (int j = 0; j < subFiles.size(); ++j)
  23248. s.add (subFiles.getReference(j).getFullPathName());
  23249. }
  23250. scanAndAddDragAndDroppedFiles (s, typesFound);
  23251. }
  23252. }
  23253. }
  23254. }
  23255. class PluginSorter
  23256. {
  23257. public:
  23258. KnownPluginList::SortMethod method;
  23259. PluginSorter() throw() {}
  23260. int compareElements (const PluginDescription* const first,
  23261. const PluginDescription* const second) const throw()
  23262. {
  23263. int diff = 0;
  23264. if (method == KnownPluginList::sortByCategory)
  23265. diff = first->category.compareLexicographically (second->category);
  23266. else if (method == KnownPluginList::sortByManufacturer)
  23267. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23268. else if (method == KnownPluginList::sortByFileSystemLocation)
  23269. diff = first->fileOrIdentifier.replaceCharacter ('\\', '/')
  23270. .upToLastOccurrenceOf ("/", false, false)
  23271. .compare (second->fileOrIdentifier.replaceCharacter ('\\', '/')
  23272. .upToLastOccurrenceOf ("/", false, false));
  23273. if (diff == 0)
  23274. diff = first->name.compareLexicographically (second->name);
  23275. return diff;
  23276. }
  23277. };
  23278. void KnownPluginList::sort (const SortMethod method)
  23279. {
  23280. if (method != defaultOrder)
  23281. {
  23282. PluginSorter sorter;
  23283. sorter.method = method;
  23284. types.sort (sorter, true);
  23285. sendChangeMessage (this);
  23286. }
  23287. }
  23288. XmlElement* KnownPluginList::createXml() const
  23289. {
  23290. XmlElement* const e = new XmlElement ("KNOWNPLUGINS");
  23291. for (int i = 0; i < types.size(); ++i)
  23292. e->addChildElement (types.getUnchecked(i)->createXml());
  23293. return e;
  23294. }
  23295. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23296. {
  23297. clear();
  23298. if (xml.hasTagName ("KNOWNPLUGINS"))
  23299. {
  23300. forEachXmlChildElement (xml, e)
  23301. {
  23302. PluginDescription info;
  23303. if (info.loadFromXml (*e))
  23304. addType (info);
  23305. }
  23306. }
  23307. }
  23308. const int menuIdBase = 0x324503f4;
  23309. // This is used to turn a bunch of paths into a nested menu structure.
  23310. struct PluginFilesystemTree
  23311. {
  23312. private:
  23313. String folder;
  23314. OwnedArray <PluginFilesystemTree> subFolders;
  23315. Array <PluginDescription*> plugins;
  23316. void addPlugin (PluginDescription* const pd, const String& path)
  23317. {
  23318. if (path.isEmpty())
  23319. {
  23320. plugins.add (pd);
  23321. }
  23322. else
  23323. {
  23324. const String firstSubFolder (path.upToFirstOccurrenceOf ("/", false, false));
  23325. const String remainingPath (path.fromFirstOccurrenceOf ("/", false, false));
  23326. for (int i = subFolders.size(); --i >= 0;)
  23327. {
  23328. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23329. {
  23330. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23331. return;
  23332. }
  23333. }
  23334. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23335. newFolder->folder = firstSubFolder;
  23336. subFolders.add (newFolder);
  23337. newFolder->addPlugin (pd, remainingPath);
  23338. }
  23339. }
  23340. // removes any deeply nested folders that don't contain any actual plugins
  23341. void optimise()
  23342. {
  23343. for (int i = subFolders.size(); --i >= 0;)
  23344. {
  23345. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23346. sub->optimise();
  23347. if (sub->plugins.size() == 0)
  23348. {
  23349. for (int j = 0; j < sub->subFolders.size(); ++j)
  23350. subFolders.add (sub->subFolders.getUnchecked(j));
  23351. sub->subFolders.clear (false);
  23352. subFolders.remove (i);
  23353. }
  23354. }
  23355. }
  23356. public:
  23357. void buildTree (const Array <PluginDescription*>& allPlugins)
  23358. {
  23359. for (int i = 0; i < allPlugins.size(); ++i)
  23360. {
  23361. String path (allPlugins.getUnchecked(i)
  23362. ->fileOrIdentifier.replaceCharacter ('\\', '/')
  23363. .upToLastOccurrenceOf ("/", false, false));
  23364. if (path.substring (1, 2) == ":")
  23365. path = path.substring (2);
  23366. addPlugin (allPlugins.getUnchecked(i), path);
  23367. }
  23368. optimise();
  23369. }
  23370. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23371. {
  23372. int i;
  23373. for (i = 0; i < subFolders.size(); ++i)
  23374. {
  23375. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23376. PopupMenu subMenu;
  23377. sub->addToMenu (subMenu, allPlugins);
  23378. #if JUCE_MAC
  23379. // avoid the special AU formatting nonsense on Mac..
  23380. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (":", false, false), subMenu);
  23381. #else
  23382. m.addSubMenu (sub->folder, subMenu);
  23383. #endif
  23384. }
  23385. for (i = 0; i < plugins.size(); ++i)
  23386. {
  23387. PluginDescription* const plugin = plugins.getUnchecked(i);
  23388. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23389. plugin->name, true, false);
  23390. }
  23391. }
  23392. };
  23393. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23394. {
  23395. Array <PluginDescription*> sorted;
  23396. {
  23397. PluginSorter sorter;
  23398. sorter.method = sortMethod;
  23399. for (int i = 0; i < types.size(); ++i)
  23400. sorted.addSorted (sorter, types.getUnchecked(i));
  23401. }
  23402. if (sortMethod == sortByCategory
  23403. || sortMethod == sortByManufacturer)
  23404. {
  23405. String lastSubMenuName;
  23406. PopupMenu sub;
  23407. for (int i = 0; i < sorted.size(); ++i)
  23408. {
  23409. const PluginDescription* const pd = sorted.getUnchecked(i);
  23410. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23411. : pd->manufacturerName);
  23412. if (! thisSubMenuName.containsNonWhitespaceChars())
  23413. thisSubMenuName = "Other";
  23414. if (thisSubMenuName != lastSubMenuName)
  23415. {
  23416. if (sub.getNumItems() > 0)
  23417. {
  23418. menu.addSubMenu (lastSubMenuName, sub);
  23419. sub.clear();
  23420. }
  23421. lastSubMenuName = thisSubMenuName;
  23422. }
  23423. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23424. }
  23425. if (sub.getNumItems() > 0)
  23426. menu.addSubMenu (lastSubMenuName, sub);
  23427. }
  23428. else if (sortMethod == sortByFileSystemLocation)
  23429. {
  23430. PluginFilesystemTree root;
  23431. root.buildTree (sorted);
  23432. root.addToMenu (menu, types);
  23433. }
  23434. else
  23435. {
  23436. for (int i = 0; i < sorted.size(); ++i)
  23437. {
  23438. const PluginDescription* const pd = sorted.getUnchecked(i);
  23439. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23440. }
  23441. }
  23442. }
  23443. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23444. {
  23445. const int i = menuResultCode - menuIdBase;
  23446. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23447. }
  23448. END_JUCE_NAMESPACE
  23449. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23450. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23451. BEGIN_JUCE_NAMESPACE
  23452. PluginDescription::PluginDescription() throw()
  23453. : uid (0),
  23454. isInstrument (false),
  23455. numInputChannels (0),
  23456. numOutputChannels (0)
  23457. {
  23458. }
  23459. PluginDescription::~PluginDescription() throw()
  23460. {
  23461. }
  23462. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23463. : name (other.name),
  23464. pluginFormatName (other.pluginFormatName),
  23465. category (other.category),
  23466. manufacturerName (other.manufacturerName),
  23467. version (other.version),
  23468. fileOrIdentifier (other.fileOrIdentifier),
  23469. lastFileModTime (other.lastFileModTime),
  23470. uid (other.uid),
  23471. isInstrument (other.isInstrument),
  23472. numInputChannels (other.numInputChannels),
  23473. numOutputChannels (other.numOutputChannels)
  23474. {
  23475. }
  23476. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23477. {
  23478. name = other.name;
  23479. pluginFormatName = other.pluginFormatName;
  23480. category = other.category;
  23481. manufacturerName = other.manufacturerName;
  23482. version = other.version;
  23483. fileOrIdentifier = other.fileOrIdentifier;
  23484. uid = other.uid;
  23485. isInstrument = other.isInstrument;
  23486. lastFileModTime = other.lastFileModTime;
  23487. numInputChannels = other.numInputChannels;
  23488. numOutputChannels = other.numOutputChannels;
  23489. return *this;
  23490. }
  23491. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23492. {
  23493. return fileOrIdentifier == other.fileOrIdentifier
  23494. && uid == other.uid;
  23495. }
  23496. const String PluginDescription::createIdentifierString() const throw()
  23497. {
  23498. return pluginFormatName
  23499. + "-" + name
  23500. + "-" + String::toHexString (fileOrIdentifier.hashCode())
  23501. + "-" + String::toHexString (uid);
  23502. }
  23503. XmlElement* PluginDescription::createXml() const
  23504. {
  23505. XmlElement* const e = new XmlElement ("PLUGIN");
  23506. e->setAttribute ("name", name);
  23507. e->setAttribute ("format", pluginFormatName);
  23508. e->setAttribute ("category", category);
  23509. e->setAttribute ("manufacturer", manufacturerName);
  23510. e->setAttribute ("version", version);
  23511. e->setAttribute ("file", fileOrIdentifier);
  23512. e->setAttribute ("uid", String::toHexString (uid));
  23513. e->setAttribute ("isInstrument", isInstrument);
  23514. e->setAttribute ("fileTime", String::toHexString (lastFileModTime.toMilliseconds()));
  23515. e->setAttribute ("numInputs", numInputChannels);
  23516. e->setAttribute ("numOutputs", numOutputChannels);
  23517. return e;
  23518. }
  23519. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23520. {
  23521. if (xml.hasTagName ("PLUGIN"))
  23522. {
  23523. name = xml.getStringAttribute ("name");
  23524. pluginFormatName = xml.getStringAttribute ("format");
  23525. category = xml.getStringAttribute ("category");
  23526. manufacturerName = xml.getStringAttribute ("manufacturer");
  23527. version = xml.getStringAttribute ("version");
  23528. fileOrIdentifier = xml.getStringAttribute ("file");
  23529. uid = xml.getStringAttribute ("uid").getHexValue32();
  23530. isInstrument = xml.getBoolAttribute ("isInstrument", false);
  23531. lastFileModTime = Time (xml.getStringAttribute ("fileTime").getHexValue64());
  23532. numInputChannels = xml.getIntAttribute ("numInputs");
  23533. numOutputChannels = xml.getIntAttribute ("numOutputs");
  23534. return true;
  23535. }
  23536. return false;
  23537. }
  23538. END_JUCE_NAMESPACE
  23539. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23540. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23541. BEGIN_JUCE_NAMESPACE
  23542. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23543. AudioPluginFormat& formatToLookFor,
  23544. FileSearchPath directoriesToSearch,
  23545. const bool recursive,
  23546. const File& deadMansPedalFile_)
  23547. : list (listToAddTo),
  23548. format (formatToLookFor),
  23549. deadMansPedalFile (deadMansPedalFile_),
  23550. nextIndex (0),
  23551. progress (0)
  23552. {
  23553. directoriesToSearch.removeRedundantPaths();
  23554. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23555. // If any plugins have crashed recently when being loaded, move them to the
  23556. // end of the list to give the others a chance to load correctly..
  23557. const StringArray crashedPlugins (getDeadMansPedalFile());
  23558. for (int i = 0; i < crashedPlugins.size(); ++i)
  23559. {
  23560. const String f = crashedPlugins[i];
  23561. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23562. if (f == filesOrIdentifiersToScan[j])
  23563. filesOrIdentifiersToScan.move (j, -1);
  23564. }
  23565. }
  23566. PluginDirectoryScanner::~PluginDirectoryScanner()
  23567. {
  23568. }
  23569. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23570. {
  23571. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23572. }
  23573. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23574. {
  23575. String file (filesOrIdentifiersToScan [nextIndex]);
  23576. if (file.isNotEmpty())
  23577. {
  23578. if (! list.isListingUpToDate (file))
  23579. {
  23580. OwnedArray <PluginDescription> typesFound;
  23581. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23582. StringArray crashedPlugins (getDeadMansPedalFile());
  23583. crashedPlugins.removeString (file);
  23584. crashedPlugins.add (file);
  23585. setDeadMansPedalFile (crashedPlugins);
  23586. list.scanAndAddFile (file,
  23587. dontRescanIfAlreadyInList,
  23588. typesFound,
  23589. format);
  23590. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23591. crashedPlugins.removeString (file);
  23592. setDeadMansPedalFile (crashedPlugins);
  23593. if (typesFound.size() == 0)
  23594. failedFiles.add (file);
  23595. }
  23596. ++nextIndex;
  23597. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23598. }
  23599. return nextIndex < filesOrIdentifiersToScan.size();
  23600. }
  23601. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23602. {
  23603. StringArray lines;
  23604. if (deadMansPedalFile != File::nonexistent)
  23605. {
  23606. lines.addLines (deadMansPedalFile.loadFileAsString());
  23607. lines.removeEmptyStrings();
  23608. }
  23609. return lines;
  23610. }
  23611. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23612. {
  23613. if (deadMansPedalFile != File::nonexistent)
  23614. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23615. }
  23616. END_JUCE_NAMESPACE
  23617. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23618. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23619. BEGIN_JUCE_NAMESPACE
  23620. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23621. const File& deadMansPedalFile_,
  23622. PropertiesFile* const propertiesToUse_)
  23623. : list (listToEdit),
  23624. deadMansPedalFile (deadMansPedalFile_),
  23625. propertiesToUse (propertiesToUse_)
  23626. {
  23627. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23628. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23629. optionsButton->addButtonListener (this);
  23630. optionsButton->setTriggeredOnMouseDown (true);
  23631. setSize (400, 600);
  23632. list.addChangeListener (this);
  23633. }
  23634. PluginListComponent::~PluginListComponent()
  23635. {
  23636. list.removeChangeListener (this);
  23637. deleteAllChildren();
  23638. }
  23639. void PluginListComponent::resized()
  23640. {
  23641. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23642. optionsButton->changeWidthToFitText (24);
  23643. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23644. }
  23645. void PluginListComponent::changeListenerCallback (void*)
  23646. {
  23647. listBox->updateContent();
  23648. listBox->repaint();
  23649. }
  23650. int PluginListComponent::getNumRows()
  23651. {
  23652. return list.getNumTypes();
  23653. }
  23654. void PluginListComponent::paintListBoxItem (int row,
  23655. Graphics& g,
  23656. int width, int height,
  23657. bool rowIsSelected)
  23658. {
  23659. if (rowIsSelected)
  23660. g.fillAll (findColour (TextEditor::highlightColourId));
  23661. const PluginDescription* const pd = list.getType (row);
  23662. if (pd != 0)
  23663. {
  23664. GlyphArrangement ga;
  23665. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23666. g.setColour (Colours::black);
  23667. ga.draw (g);
  23668. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  23669. String desc;
  23670. desc << pd->pluginFormatName
  23671. << (pd->isInstrument ? " instrument" : " effect")
  23672. << " - "
  23673. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23674. << " / "
  23675. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23676. if (pd->manufacturerName.isNotEmpty())
  23677. desc << " - " << pd->manufacturerName;
  23678. if (pd->version.isNotEmpty())
  23679. desc << " - " << pd->version;
  23680. if (pd->category.isNotEmpty())
  23681. desc << " - category: '" << pd->category << '\'';
  23682. g.setColour (Colours::grey);
  23683. ga.clear();
  23684. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, bb.getRight() + 10.0f, height * 0.8f, width - bb.getRight() - 12.0f, true);
  23685. ga.draw (g);
  23686. }
  23687. }
  23688. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23689. {
  23690. list.removeType (lastRowSelected);
  23691. }
  23692. void PluginListComponent::buttonClicked (Button* b)
  23693. {
  23694. if (optionsButton == b)
  23695. {
  23696. PopupMenu menu;
  23697. menu.addItem (1, TRANS("Clear list"));
  23698. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23699. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23700. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23701. menu.addSeparator();
  23702. menu.addItem (2, TRANS("Sort alphabetically"));
  23703. menu.addItem (3, TRANS("Sort by category"));
  23704. menu.addItem (4, TRANS("Sort by manufacturer"));
  23705. menu.addSeparator();
  23706. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23707. {
  23708. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23709. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23710. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23711. }
  23712. const int r = menu.showAt (optionsButton);
  23713. if (r == 1)
  23714. {
  23715. list.clear();
  23716. }
  23717. else if (r == 2)
  23718. {
  23719. list.sort (KnownPluginList::sortAlphabetically);
  23720. }
  23721. else if (r == 3)
  23722. {
  23723. list.sort (KnownPluginList::sortByCategory);
  23724. }
  23725. else if (r == 4)
  23726. {
  23727. list.sort (KnownPluginList::sortByManufacturer);
  23728. }
  23729. else if (r == 5)
  23730. {
  23731. const SparseSet <int> selected (listBox->getSelectedRows());
  23732. for (int i = list.getNumTypes(); --i >= 0;)
  23733. if (selected.contains (i))
  23734. list.removeType (i);
  23735. }
  23736. else if (r == 6)
  23737. {
  23738. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  23739. if (desc != 0)
  23740. {
  23741. if (File (desc->fileOrIdentifier).existsAsFile())
  23742. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  23743. }
  23744. }
  23745. else if (r == 7)
  23746. {
  23747. for (int i = list.getNumTypes(); --i >= 0;)
  23748. {
  23749. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  23750. {
  23751. list.removeType (i);
  23752. }
  23753. }
  23754. }
  23755. else if (r != 0)
  23756. {
  23757. typeToScan = r - 10;
  23758. startTimer (1);
  23759. }
  23760. }
  23761. }
  23762. void PluginListComponent::timerCallback()
  23763. {
  23764. stopTimer();
  23765. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  23766. }
  23767. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  23768. {
  23769. return true;
  23770. }
  23771. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  23772. {
  23773. OwnedArray <PluginDescription> typesFound;
  23774. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  23775. }
  23776. void PluginListComponent::scanFor (AudioPluginFormat* format)
  23777. {
  23778. if (format == 0)
  23779. return;
  23780. FileSearchPath path (format->getDefaultLocationsToSearch());
  23781. if (propertiesToUse != 0)
  23782. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23783. {
  23784. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  23785. FileSearchPathListComponent pathList;
  23786. pathList.setSize (500, 300);
  23787. pathList.setPath (path);
  23788. aw.addCustomComponent (&pathList);
  23789. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  23790. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23791. if (aw.runModalLoop() == 0)
  23792. return;
  23793. path = pathList.getPath();
  23794. }
  23795. if (propertiesToUse != 0)
  23796. {
  23797. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23798. propertiesToUse->saveIfNeeded();
  23799. }
  23800. double progress = 0.0;
  23801. AlertWindow aw (TRANS("Scanning for plugins..."),
  23802. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  23803. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23804. aw.addProgressBarComponent (progress);
  23805. aw.enterModalState();
  23806. MessageManager::getInstance()->runDispatchLoopUntil (300);
  23807. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  23808. for (;;)
  23809. {
  23810. aw.setMessage (TRANS("Testing:\n\n")
  23811. + scanner.getNextPluginFileThatWillBeScanned());
  23812. MessageManager::getInstance()->runDispatchLoopUntil (20);
  23813. if (! scanner.scanNextFile (true))
  23814. break;
  23815. if (! aw.isCurrentlyModal())
  23816. break;
  23817. progress = scanner.getProgress();
  23818. }
  23819. if (scanner.getFailedFiles().size() > 0)
  23820. {
  23821. StringArray shortNames;
  23822. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  23823. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  23824. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  23825. TRANS("Scan complete"),
  23826. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  23827. + shortNames.joinIntoString (", "));
  23828. }
  23829. }
  23830. END_JUCE_NAMESPACE
  23831. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  23832. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  23833. #if JUCE_PLUGINHOST_AU && ! (JUCE_LINUX || JUCE_WINDOWS)
  23834. #include <AudioUnit/AudioUnit.h>
  23835. #include <AudioUnit/AUCocoaUIView.h>
  23836. #include <CoreAudioKit/AUGenericView.h>
  23837. #if JUCE_SUPPORT_CARBON
  23838. #include <AudioToolbox/AudioUnitUtilities.h>
  23839. #include <AudioUnit/AudioUnitCarbonView.h>
  23840. #endif
  23841. BEGIN_JUCE_NAMESPACE
  23842. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  23843. #endif
  23844. #if JUCE_MAC
  23845. // Change this to disable logging of various activities
  23846. #ifndef AU_LOGGING
  23847. #define AU_LOGGING 1
  23848. #endif
  23849. #if AU_LOGGING
  23850. #define log(a) Logger::writeToLog(a);
  23851. #else
  23852. #define log(a)
  23853. #endif
  23854. static int insideCallback = 0;
  23855. static const String osTypeToString (OSType type)
  23856. {
  23857. char s[4];
  23858. s[0] = (char) (((uint32) type) >> 24);
  23859. s[1] = (char) (((uint32) type) >> 16);
  23860. s[2] = (char) (((uint32) type) >> 8);
  23861. s[3] = (char) ((uint32) type);
  23862. return String (s, 4);
  23863. }
  23864. static OSType stringToOSType (const String& s1)
  23865. {
  23866. const String s (s1 + " ");
  23867. return (((OSType) (unsigned char) s[0]) << 24)
  23868. | (((OSType) (unsigned char) s[1]) << 16)
  23869. | (((OSType) (unsigned char) s[2]) << 8)
  23870. | ((OSType) (unsigned char) s[3]);
  23871. }
  23872. static const char* auIdentifierPrefix = "AudioUnit:";
  23873. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  23874. {
  23875. jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong..
  23876. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  23877. String s (auIdentifierPrefix);
  23878. if (desc.componentType == kAudioUnitType_MusicDevice)
  23879. s << "Synths/";
  23880. else if (desc.componentType == kAudioUnitType_MusicEffect
  23881. || desc.componentType == kAudioUnitType_Effect)
  23882. s << "Effects/";
  23883. else if (desc.componentType == kAudioUnitType_Generator)
  23884. s << "Generators/";
  23885. else if (desc.componentType == kAudioUnitType_Panner)
  23886. s << "Panners/";
  23887. s << osTypeToString (desc.componentType) << ","
  23888. << osTypeToString (desc.componentSubType) << ","
  23889. << osTypeToString (desc.componentManufacturer);
  23890. return s;
  23891. }
  23892. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  23893. {
  23894. Handle componentNameHandle = NewHandle (sizeof (void*));
  23895. Handle componentInfoHandle = NewHandle (sizeof (void*));
  23896. if (componentNameHandle != 0 && componentInfoHandle != 0)
  23897. {
  23898. ComponentDescription desc;
  23899. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  23900. {
  23901. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  23902. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  23903. if (nameString != 0 && nameString[0] != 0)
  23904. {
  23905. const String all ((const char*) nameString + 1, nameString[0]);
  23906. DBG ("name: "+ all);
  23907. manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim();
  23908. name = all.fromFirstOccurrenceOf (":", false, false).trim();
  23909. }
  23910. if (infoString != 0 && infoString[0] != 0)
  23911. {
  23912. DBG ("info: " + String ((const char*) infoString + 1, infoString[0]));
  23913. }
  23914. if (name.isEmpty())
  23915. name = "<Unknown>";
  23916. }
  23917. DisposeHandle (componentNameHandle);
  23918. DisposeHandle (componentInfoHandle);
  23919. }
  23920. }
  23921. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  23922. String& name, String& version, String& manufacturer)
  23923. {
  23924. zerostruct (desc);
  23925. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  23926. {
  23927. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'),
  23928. fileOrIdentifier.lastIndexOfChar ('/')) + 1));
  23929. StringArray tokens;
  23930. tokens.addTokens (s, ",", String::empty);
  23931. tokens.trim();
  23932. tokens.removeEmptyStrings();
  23933. if (tokens.size() == 3)
  23934. {
  23935. desc.componentType = stringToOSType (tokens[0]);
  23936. desc.componentSubType = stringToOSType (tokens[1]);
  23937. desc.componentManufacturer = stringToOSType (tokens[2]);
  23938. ComponentRecord* comp = FindNextComponent (0, &desc);
  23939. if (comp != 0)
  23940. {
  23941. getAUDetails (comp, name, manufacturer);
  23942. return true;
  23943. }
  23944. }
  23945. }
  23946. return false;
  23947. }
  23948. class AudioUnitPluginWindowCarbon;
  23949. class AudioUnitPluginWindowCocoa;
  23950. class AudioUnitPluginInstance : public AudioPluginInstance
  23951. {
  23952. public:
  23953. ~AudioUnitPluginInstance();
  23954. // AudioPluginInstance methods:
  23955. void fillInPluginDescription (PluginDescription& desc) const
  23956. {
  23957. desc.name = pluginName;
  23958. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  23959. desc.uid = ((int) componentDesc.componentType)
  23960. ^ ((int) componentDesc.componentSubType)
  23961. ^ ((int) componentDesc.componentManufacturer);
  23962. desc.lastFileModTime = 0;
  23963. desc.pluginFormatName = "AudioUnit";
  23964. desc.category = getCategory();
  23965. desc.manufacturerName = manufacturer;
  23966. desc.version = version;
  23967. desc.numInputChannels = getNumInputChannels();
  23968. desc.numOutputChannels = getNumOutputChannels();
  23969. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  23970. }
  23971. const String getName() const { return pluginName; }
  23972. bool acceptsMidi() const { return wantsMidiMessages; }
  23973. bool producesMidi() const { return false; }
  23974. // AudioProcessor methods:
  23975. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  23976. void releaseResources();
  23977. void processBlock (AudioSampleBuffer& buffer,
  23978. MidiBuffer& midiMessages);
  23979. AudioProcessorEditor* createEditor();
  23980. const String getInputChannelName (const int index) const;
  23981. bool isInputChannelStereoPair (int index) const;
  23982. const String getOutputChannelName (const int index) const;
  23983. bool isOutputChannelStereoPair (int index) const;
  23984. int getNumParameters();
  23985. float getParameter (int index);
  23986. void setParameter (int index, float newValue);
  23987. const String getParameterName (int index);
  23988. const String getParameterText (int index);
  23989. bool isParameterAutomatable (int index) const;
  23990. int getNumPrograms();
  23991. int getCurrentProgram();
  23992. void setCurrentProgram (int index);
  23993. const String getProgramName (int index);
  23994. void changeProgramName (int index, const String& newName);
  23995. void getStateInformation (MemoryBlock& destData);
  23996. void getCurrentProgramStateInformation (MemoryBlock& destData);
  23997. void setStateInformation (const void* data, int sizeInBytes);
  23998. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  23999. juce_UseDebuggingNewOperator
  24000. private:
  24001. friend class AudioUnitPluginWindowCarbon;
  24002. friend class AudioUnitPluginWindowCocoa;
  24003. friend class AudioUnitPluginFormat;
  24004. ComponentDescription componentDesc;
  24005. String pluginName, manufacturer, version;
  24006. String fileOrIdentifier;
  24007. CriticalSection lock;
  24008. bool initialised, wantsMidiMessages, wasPlaying;
  24009. HeapBlock <AudioBufferList> outputBufferList;
  24010. AudioTimeStamp timeStamp;
  24011. AudioSampleBuffer* currentBuffer;
  24012. AudioUnit audioUnit;
  24013. Array <int> parameterIds;
  24014. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24015. void initialise();
  24016. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24017. const AudioTimeStamp* inTimeStamp,
  24018. UInt32 inBusNumber,
  24019. UInt32 inNumberFrames,
  24020. AudioBufferList* ioData) const;
  24021. static OSStatus renderGetInputCallback (void* inRefCon,
  24022. AudioUnitRenderActionFlags* ioActionFlags,
  24023. const AudioTimeStamp* inTimeStamp,
  24024. UInt32 inBusNumber,
  24025. UInt32 inNumberFrames,
  24026. AudioBufferList* ioData)
  24027. {
  24028. return ((AudioUnitPluginInstance*) inRefCon)
  24029. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24030. }
  24031. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24032. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24033. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24034. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24035. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24036. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24037. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24038. {
  24039. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24040. }
  24041. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24042. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24043. Float64* outCurrentMeasureDownBeat)
  24044. {
  24045. return ((AudioUnitPluginInstance*) inHostUserData)
  24046. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24047. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24048. }
  24049. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24050. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24051. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24052. {
  24053. return ((AudioUnitPluginInstance*) inHostUserData)
  24054. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24055. outCurrentSampleInTimeLine, outIsCycling,
  24056. outCycleStartBeat, outCycleEndBeat);
  24057. }
  24058. void getNumChannels (int& numIns, int& numOuts)
  24059. {
  24060. numIns = 0;
  24061. numOuts = 0;
  24062. AUChannelInfo supportedChannels [128];
  24063. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24064. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24065. 0, supportedChannels, &supportedChannelsSize) == noErr
  24066. && supportedChannelsSize > 0)
  24067. {
  24068. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24069. {
  24070. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24071. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24072. }
  24073. }
  24074. else
  24075. {
  24076. // (this really means the plugin will take any number of ins/outs as long
  24077. // as they are the same)
  24078. numIns = numOuts = 2;
  24079. }
  24080. }
  24081. const String getCategory() const;
  24082. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24083. };
  24084. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24085. : fileOrIdentifier (fileOrIdentifier),
  24086. initialised (false),
  24087. wantsMidiMessages (false),
  24088. audioUnit (0),
  24089. currentBuffer (0)
  24090. {
  24091. try
  24092. {
  24093. ++insideCallback;
  24094. log ("Opening AU: " + fileOrIdentifier);
  24095. if (getComponentDescFromFile (fileOrIdentifier))
  24096. {
  24097. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24098. if (comp != 0)
  24099. {
  24100. audioUnit = (AudioUnit) OpenComponent (comp);
  24101. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24102. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24103. }
  24104. }
  24105. --insideCallback;
  24106. }
  24107. catch (...)
  24108. {
  24109. --insideCallback;
  24110. }
  24111. }
  24112. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24113. {
  24114. const ScopedLock sl (lock);
  24115. jassert (insideCallback == 0);
  24116. if (audioUnit != 0)
  24117. {
  24118. AudioUnitUninitialize (audioUnit);
  24119. CloseComponent (audioUnit);
  24120. audioUnit = 0;
  24121. }
  24122. }
  24123. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24124. {
  24125. zerostruct (componentDesc);
  24126. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24127. return true;
  24128. const File file (fileOrIdentifier);
  24129. if (! file.hasFileExtension (".component"))
  24130. return false;
  24131. const char* const utf8 = fileOrIdentifier.toUTF8();
  24132. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24133. strlen (utf8), file.isDirectory());
  24134. if (url != 0)
  24135. {
  24136. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24137. CFRelease (url);
  24138. if (bundleRef != 0)
  24139. {
  24140. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24141. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24142. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24143. if (pluginName.isEmpty())
  24144. pluginName = file.getFileNameWithoutExtension();
  24145. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24146. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24147. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24148. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24149. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24150. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24151. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24152. UseResFile (resFileId);
  24153. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24154. {
  24155. Handle h = Get1IndResource ('thng', i);
  24156. if (h != 0)
  24157. {
  24158. HLock (h);
  24159. const uint32* const types = (const uint32*) *h;
  24160. if (types[0] == kAudioUnitType_MusicDevice
  24161. || types[0] == kAudioUnitType_MusicEffect
  24162. || types[0] == kAudioUnitType_Effect
  24163. || types[0] == kAudioUnitType_Generator
  24164. || types[0] == kAudioUnitType_Panner)
  24165. {
  24166. componentDesc.componentType = types[0];
  24167. componentDesc.componentSubType = types[1];
  24168. componentDesc.componentManufacturer = types[2];
  24169. break;
  24170. }
  24171. HUnlock (h);
  24172. ReleaseResource (h);
  24173. }
  24174. }
  24175. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24176. CFRelease (bundleRef);
  24177. }
  24178. }
  24179. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24180. }
  24181. void AudioUnitPluginInstance::initialise()
  24182. {
  24183. if (initialised || audioUnit == 0)
  24184. return;
  24185. log ("Initialising AU: " + pluginName);
  24186. parameterIds.clear();
  24187. {
  24188. UInt32 paramListSize = 0;
  24189. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24190. 0, 0, &paramListSize);
  24191. if (paramListSize > 0)
  24192. {
  24193. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24194. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24195. 0, &parameterIds.getReference(0), &paramListSize);
  24196. }
  24197. }
  24198. {
  24199. AURenderCallbackStruct info;
  24200. zerostruct (info);
  24201. info.inputProcRefCon = this;
  24202. info.inputProc = renderGetInputCallback;
  24203. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24204. 0, &info, sizeof (info));
  24205. }
  24206. {
  24207. HostCallbackInfo info;
  24208. zerostruct (info);
  24209. info.hostUserData = this;
  24210. info.beatAndTempoProc = getBeatAndTempoCallback;
  24211. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24212. info.transportStateProc = getTransportStateCallback;
  24213. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24214. 0, &info, sizeof (info));
  24215. }
  24216. int numIns, numOuts;
  24217. getNumChannels (numIns, numOuts);
  24218. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24219. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24220. setLatencySamples (0);
  24221. }
  24222. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24223. int samplesPerBlockExpected)
  24224. {
  24225. initialise();
  24226. if (initialised)
  24227. {
  24228. int numIns, numOuts;
  24229. getNumChannels (numIns, numOuts);
  24230. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24231. Float64 latencySecs = 0.0;
  24232. UInt32 latencySize = sizeof (latencySecs);
  24233. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24234. 0, &latencySecs, &latencySize);
  24235. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24236. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24237. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24238. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24239. AudioStreamBasicDescription stream;
  24240. zerostruct (stream);
  24241. stream.mSampleRate = sampleRate_;
  24242. stream.mFormatID = kAudioFormatLinearPCM;
  24243. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24244. stream.mFramesPerPacket = 1;
  24245. stream.mBytesPerPacket = 4;
  24246. stream.mBytesPerFrame = 4;
  24247. stream.mBitsPerChannel = 32;
  24248. stream.mChannelsPerFrame = numIns;
  24249. OSStatus err = AudioUnitSetProperty (audioUnit,
  24250. kAudioUnitProperty_StreamFormat,
  24251. kAudioUnitScope_Input,
  24252. 0, &stream, sizeof (stream));
  24253. stream.mChannelsPerFrame = numOuts;
  24254. err = AudioUnitSetProperty (audioUnit,
  24255. kAudioUnitProperty_StreamFormat,
  24256. kAudioUnitScope_Output,
  24257. 0, &stream, sizeof (stream));
  24258. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24259. outputBufferList->mNumberBuffers = numOuts;
  24260. for (int i = numOuts; --i >= 0;)
  24261. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24262. zerostruct (timeStamp);
  24263. timeStamp.mSampleTime = 0;
  24264. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24265. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24266. currentBuffer = 0;
  24267. wasPlaying = false;
  24268. }
  24269. }
  24270. void AudioUnitPluginInstance::releaseResources()
  24271. {
  24272. if (initialised)
  24273. {
  24274. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24275. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24276. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24277. outputBufferList.free();
  24278. currentBuffer = 0;
  24279. }
  24280. }
  24281. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24282. const AudioTimeStamp* inTimeStamp,
  24283. UInt32 inBusNumber,
  24284. UInt32 inNumberFrames,
  24285. AudioBufferList* ioData) const
  24286. {
  24287. if (inBusNumber == 0
  24288. && currentBuffer != 0)
  24289. {
  24290. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24291. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24292. {
  24293. if (i < currentBuffer->getNumChannels())
  24294. {
  24295. memcpy (ioData->mBuffers[i].mData,
  24296. currentBuffer->getSampleData (i, 0),
  24297. sizeof (float) * inNumberFrames);
  24298. }
  24299. else
  24300. {
  24301. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24302. }
  24303. }
  24304. }
  24305. return noErr;
  24306. }
  24307. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24308. MidiBuffer& midiMessages)
  24309. {
  24310. const int numSamples = buffer.getNumSamples();
  24311. if (initialised)
  24312. {
  24313. AudioUnitRenderActionFlags flags = 0;
  24314. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24315. for (int i = getNumOutputChannels(); --i >= 0;)
  24316. {
  24317. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24318. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24319. }
  24320. currentBuffer = &buffer;
  24321. if (wantsMidiMessages)
  24322. {
  24323. const uint8* midiEventData;
  24324. int midiEventSize, midiEventPosition;
  24325. MidiBuffer::Iterator i (midiMessages);
  24326. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24327. {
  24328. if (midiEventSize <= 3)
  24329. MusicDeviceMIDIEvent (audioUnit,
  24330. midiEventData[0], midiEventData[1], midiEventData[2],
  24331. midiEventPosition);
  24332. else
  24333. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24334. }
  24335. midiMessages.clear();
  24336. }
  24337. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24338. 0, numSamples, outputBufferList);
  24339. timeStamp.mSampleTime += numSamples;
  24340. }
  24341. else
  24342. {
  24343. // Not initialised, so just bypass..
  24344. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24345. buffer.clear (i, 0, buffer.getNumSamples());
  24346. }
  24347. }
  24348. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24349. {
  24350. AudioPlayHead* const ph = getPlayHead();
  24351. AudioPlayHead::CurrentPositionInfo result;
  24352. if (ph != 0 && ph->getCurrentPosition (result))
  24353. {
  24354. if (outCurrentBeat != 0)
  24355. *outCurrentBeat = result.ppqPosition;
  24356. if (outCurrentTempo != 0)
  24357. *outCurrentTempo = result.bpm;
  24358. }
  24359. else
  24360. {
  24361. if (outCurrentBeat != 0)
  24362. *outCurrentBeat = 0;
  24363. if (outCurrentTempo != 0)
  24364. *outCurrentTempo = 120.0;
  24365. }
  24366. return noErr;
  24367. }
  24368. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24369. Float32* outTimeSig_Numerator,
  24370. UInt32* outTimeSig_Denominator,
  24371. Float64* outCurrentMeasureDownBeat) const
  24372. {
  24373. AudioPlayHead* const ph = getPlayHead();
  24374. AudioPlayHead::CurrentPositionInfo result;
  24375. if (ph != 0 && ph->getCurrentPosition (result))
  24376. {
  24377. if (outTimeSig_Numerator != 0)
  24378. *outTimeSig_Numerator = result.timeSigNumerator;
  24379. if (outTimeSig_Denominator != 0)
  24380. *outTimeSig_Denominator = result.timeSigDenominator;
  24381. if (outDeltaSampleOffsetToNextBeat != 0)
  24382. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24383. if (outCurrentMeasureDownBeat != 0)
  24384. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24385. }
  24386. else
  24387. {
  24388. if (outDeltaSampleOffsetToNextBeat != 0)
  24389. *outDeltaSampleOffsetToNextBeat = 0;
  24390. if (outTimeSig_Numerator != 0)
  24391. *outTimeSig_Numerator = 4;
  24392. if (outTimeSig_Denominator != 0)
  24393. *outTimeSig_Denominator = 4;
  24394. if (outCurrentMeasureDownBeat != 0)
  24395. *outCurrentMeasureDownBeat = 0;
  24396. }
  24397. return noErr;
  24398. }
  24399. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24400. Boolean* outTransportStateChanged,
  24401. Float64* outCurrentSampleInTimeLine,
  24402. Boolean* outIsCycling,
  24403. Float64* outCycleStartBeat,
  24404. Float64* outCycleEndBeat)
  24405. {
  24406. AudioPlayHead* const ph = getPlayHead();
  24407. AudioPlayHead::CurrentPositionInfo result;
  24408. if (ph != 0 && ph->getCurrentPosition (result))
  24409. {
  24410. if (outIsPlaying != 0)
  24411. *outIsPlaying = result.isPlaying;
  24412. if (outTransportStateChanged != 0)
  24413. {
  24414. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24415. wasPlaying = result.isPlaying;
  24416. }
  24417. if (outCurrentSampleInTimeLine != 0)
  24418. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24419. if (outIsCycling != 0)
  24420. *outIsCycling = false;
  24421. if (outCycleStartBeat != 0)
  24422. *outCycleStartBeat = 0;
  24423. if (outCycleEndBeat != 0)
  24424. *outCycleEndBeat = 0;
  24425. }
  24426. else
  24427. {
  24428. if (outIsPlaying != 0)
  24429. *outIsPlaying = false;
  24430. if (outTransportStateChanged != 0)
  24431. *outTransportStateChanged = false;
  24432. if (outCurrentSampleInTimeLine != 0)
  24433. *outCurrentSampleInTimeLine = 0;
  24434. if (outIsCycling != 0)
  24435. *outIsCycling = false;
  24436. if (outCycleStartBeat != 0)
  24437. *outCycleStartBeat = 0;
  24438. if (outCycleEndBeat != 0)
  24439. *outCycleEndBeat = 0;
  24440. }
  24441. return noErr;
  24442. }
  24443. static VoidArray activeWindows;
  24444. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24445. {
  24446. public:
  24447. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24448. : AudioProcessorEditor (&plugin_),
  24449. plugin (plugin_),
  24450. wrapper (0)
  24451. {
  24452. addAndMakeVisible (wrapper = new NSViewComponent());
  24453. activeWindows.add (this);
  24454. setOpaque (true);
  24455. setVisible (true);
  24456. setSize (100, 100);
  24457. createView (createGenericViewIfNeeded);
  24458. }
  24459. ~AudioUnitPluginWindowCocoa()
  24460. {
  24461. const bool wasValid = isValid();
  24462. wrapper->setView (0);
  24463. activeWindows.removeValue (this);
  24464. if (wasValid)
  24465. plugin.editorBeingDeleted (this);
  24466. delete wrapper;
  24467. }
  24468. bool isValid() const { return wrapper->getView() != 0; }
  24469. void paint (Graphics& g)
  24470. {
  24471. g.fillAll (Colours::white);
  24472. }
  24473. void resized()
  24474. {
  24475. wrapper->setSize (getWidth(), getHeight());
  24476. }
  24477. private:
  24478. AudioUnitPluginInstance& plugin;
  24479. NSViewComponent* wrapper;
  24480. bool createView (const bool createGenericViewIfNeeded)
  24481. {
  24482. NSView* pluginView = 0;
  24483. UInt32 dataSize = 0;
  24484. Boolean isWritable = false;
  24485. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24486. 0, &dataSize, &isWritable) == noErr
  24487. && dataSize != 0
  24488. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24489. 0, &dataSize, &isWritable) == noErr)
  24490. {
  24491. HeapBlock <AudioUnitCocoaViewInfo> info;
  24492. info.calloc (dataSize, 1);
  24493. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24494. 0, info, &dataSize) == noErr)
  24495. {
  24496. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24497. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24498. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24499. Class viewClass = [viewBundle classNamed: viewClassName];
  24500. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24501. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24502. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24503. {
  24504. id factory = [[[viewClass alloc] init] autorelease];
  24505. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24506. withSize: NSMakeSize (getWidth(), getHeight())];
  24507. }
  24508. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24509. {
  24510. CFRelease (info->mCocoaAUViewClass[i]);
  24511. CFRelease (info->mCocoaAUViewBundleLocation);
  24512. }
  24513. }
  24514. }
  24515. if (createGenericViewIfNeeded && (pluginView == 0))
  24516. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24517. wrapper->setView (pluginView);
  24518. if (pluginView != 0)
  24519. setSize ([pluginView frame].size.width,
  24520. [pluginView frame].size.height);
  24521. return pluginView != 0;
  24522. }
  24523. };
  24524. #if JUCE_SUPPORT_CARBON
  24525. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24526. {
  24527. public:
  24528. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24529. : AudioProcessorEditor (&plugin_),
  24530. plugin (plugin_),
  24531. viewComponent (0)
  24532. {
  24533. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24534. activeWindows.add (this);
  24535. setOpaque (true);
  24536. setVisible (true);
  24537. setSize (400, 300);
  24538. ComponentDescription viewList [16];
  24539. UInt32 viewListSize = sizeof (viewList);
  24540. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24541. 0, &viewList, &viewListSize);
  24542. componentRecord = FindNextComponent (0, &viewList[0]);
  24543. }
  24544. ~AudioUnitPluginWindowCarbon()
  24545. {
  24546. innerWrapper = 0;
  24547. activeWindows.removeValue (this);
  24548. if (isValid())
  24549. plugin.editorBeingDeleted (this);
  24550. }
  24551. bool isValid() const throw() { return componentRecord != 0; }
  24552. void paint (Graphics& g)
  24553. {
  24554. g.fillAll (Colours::black);
  24555. }
  24556. void resized()
  24557. {
  24558. innerWrapper->setSize (getWidth(), getHeight());
  24559. }
  24560. bool keyStateChanged (bool)
  24561. {
  24562. return false;
  24563. }
  24564. bool keyPressed (const KeyPress&)
  24565. {
  24566. return false;
  24567. }
  24568. void broughtToFront()
  24569. {
  24570. activeWindows.removeValue (this);
  24571. activeWindows.add (this);
  24572. }
  24573. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24574. AudioUnitCarbonView getViewComponent()
  24575. {
  24576. if (viewComponent == 0 && componentRecord != 0)
  24577. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24578. return viewComponent;
  24579. }
  24580. void closeViewComponent()
  24581. {
  24582. if (viewComponent != 0)
  24583. {
  24584. CloseComponent (viewComponent);
  24585. viewComponent = 0;
  24586. }
  24587. }
  24588. juce_UseDebuggingNewOperator
  24589. private:
  24590. AudioUnitPluginInstance& plugin;
  24591. ComponentRecord* componentRecord;
  24592. AudioUnitCarbonView viewComponent;
  24593. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24594. {
  24595. public:
  24596. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24597. : owner (owner_)
  24598. {
  24599. }
  24600. ~InnerWrapperComponent()
  24601. {
  24602. deleteWindow();
  24603. }
  24604. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24605. {
  24606. log ("Opening AU GUI: " + owner->plugin.getName());
  24607. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24608. if (viewComponent == 0)
  24609. return 0;
  24610. Float32Point pos = { 0, 0 };
  24611. Float32Point size = { 250, 200 };
  24612. HIViewRef pluginView = 0;
  24613. AudioUnitCarbonViewCreate (viewComponent,
  24614. owner->getAudioUnit(),
  24615. windowRef,
  24616. rootView,
  24617. &pos,
  24618. &size,
  24619. (ControlRef*) &pluginView);
  24620. return pluginView;
  24621. }
  24622. void removeView (HIViewRef)
  24623. {
  24624. log ("Closing AU GUI: " + owner->plugin.getName());
  24625. owner->closeViewComponent();
  24626. }
  24627. private:
  24628. AudioUnitPluginWindowCarbon* const owner;
  24629. };
  24630. friend class InnerWrapperComponent;
  24631. ScopedPointer<InnerWrapperComponent> innerWrapper;
  24632. };
  24633. #endif
  24634. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24635. {
  24636. ScopedPointer<AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24637. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24638. w = 0;
  24639. #if JUCE_SUPPORT_CARBON
  24640. if (w == 0)
  24641. {
  24642. w = new AudioUnitPluginWindowCarbon (*this);
  24643. if (! static_cast <AudioUnitPluginWindowCarbon*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24644. w = 0;
  24645. }
  24646. #endif
  24647. if (w == 0)
  24648. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24649. return w.release();
  24650. }
  24651. const String AudioUnitPluginInstance::getCategory() const
  24652. {
  24653. const char* result = 0;
  24654. switch (componentDesc.componentType)
  24655. {
  24656. case kAudioUnitType_Effect:
  24657. case kAudioUnitType_MusicEffect:
  24658. result = "Effect";
  24659. break;
  24660. case kAudioUnitType_MusicDevice:
  24661. result = "Synth";
  24662. break;
  24663. case kAudioUnitType_Generator:
  24664. result = "Generator";
  24665. break;
  24666. case kAudioUnitType_Panner:
  24667. result = "Panner";
  24668. break;
  24669. default:
  24670. break;
  24671. }
  24672. return result;
  24673. }
  24674. int AudioUnitPluginInstance::getNumParameters()
  24675. {
  24676. return parameterIds.size();
  24677. }
  24678. float AudioUnitPluginInstance::getParameter (int index)
  24679. {
  24680. const ScopedLock sl (lock);
  24681. Float32 value = 0.0f;
  24682. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24683. {
  24684. AudioUnitGetParameter (audioUnit,
  24685. (UInt32) parameterIds.getUnchecked (index),
  24686. kAudioUnitScope_Global, 0,
  24687. &value);
  24688. }
  24689. return value;
  24690. }
  24691. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24692. {
  24693. const ScopedLock sl (lock);
  24694. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24695. {
  24696. AudioUnitSetParameter (audioUnit,
  24697. (UInt32) parameterIds.getUnchecked (index),
  24698. kAudioUnitScope_Global, 0,
  24699. newValue, 0);
  24700. }
  24701. }
  24702. const String AudioUnitPluginInstance::getParameterName (int index)
  24703. {
  24704. AudioUnitParameterInfo info;
  24705. zerostruct (info);
  24706. UInt32 sz = sizeof (info);
  24707. String name;
  24708. if (AudioUnitGetProperty (audioUnit,
  24709. kAudioUnitProperty_ParameterInfo,
  24710. kAudioUnitScope_Global,
  24711. parameterIds [index], &info, &sz) == noErr)
  24712. {
  24713. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  24714. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  24715. else
  24716. name = String (info.name, sizeof (info.name));
  24717. }
  24718. return name;
  24719. }
  24720. const String AudioUnitPluginInstance::getParameterText (int index)
  24721. {
  24722. return String (getParameter (index));
  24723. }
  24724. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  24725. {
  24726. AudioUnitParameterInfo info;
  24727. UInt32 sz = sizeof (info);
  24728. if (AudioUnitGetProperty (audioUnit,
  24729. kAudioUnitProperty_ParameterInfo,
  24730. kAudioUnitScope_Global,
  24731. parameterIds [index], &info, &sz) == noErr)
  24732. {
  24733. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  24734. }
  24735. return true;
  24736. }
  24737. int AudioUnitPluginInstance::getNumPrograms()
  24738. {
  24739. CFArrayRef presets;
  24740. UInt32 sz = sizeof (CFArrayRef);
  24741. int num = 0;
  24742. if (AudioUnitGetProperty (audioUnit,
  24743. kAudioUnitProperty_FactoryPresets,
  24744. kAudioUnitScope_Global,
  24745. 0, &presets, &sz) == noErr)
  24746. {
  24747. num = (int) CFArrayGetCount (presets);
  24748. CFRelease (presets);
  24749. }
  24750. return num;
  24751. }
  24752. int AudioUnitPluginInstance::getCurrentProgram()
  24753. {
  24754. AUPreset current;
  24755. current.presetNumber = 0;
  24756. UInt32 sz = sizeof (AUPreset);
  24757. AudioUnitGetProperty (audioUnit,
  24758. kAudioUnitProperty_FactoryPresets,
  24759. kAudioUnitScope_Global,
  24760. 0, &current, &sz);
  24761. return current.presetNumber;
  24762. }
  24763. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  24764. {
  24765. AUPreset current;
  24766. current.presetNumber = newIndex;
  24767. current.presetName = 0;
  24768. AudioUnitSetProperty (audioUnit,
  24769. kAudioUnitProperty_FactoryPresets,
  24770. kAudioUnitScope_Global,
  24771. 0, &current, sizeof (AUPreset));
  24772. }
  24773. const String AudioUnitPluginInstance::getProgramName (int index)
  24774. {
  24775. String s;
  24776. CFArrayRef presets;
  24777. UInt32 sz = sizeof (CFArrayRef);
  24778. if (AudioUnitGetProperty (audioUnit,
  24779. kAudioUnitProperty_FactoryPresets,
  24780. kAudioUnitScope_Global,
  24781. 0, &presets, &sz) == noErr)
  24782. {
  24783. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  24784. {
  24785. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  24786. if (p != 0 && p->presetNumber == index)
  24787. {
  24788. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  24789. break;
  24790. }
  24791. }
  24792. CFRelease (presets);
  24793. }
  24794. return s;
  24795. }
  24796. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  24797. {
  24798. jassertfalse // xxx not implemented!
  24799. }
  24800. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  24801. {
  24802. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  24803. return "Input " + String (index + 1);
  24804. return String::empty;
  24805. }
  24806. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  24807. {
  24808. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  24809. return false;
  24810. return true;
  24811. }
  24812. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  24813. {
  24814. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  24815. return "Output " + String (index + 1);
  24816. return String::empty;
  24817. }
  24818. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  24819. {
  24820. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  24821. return false;
  24822. return true;
  24823. }
  24824. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  24825. {
  24826. getCurrentProgramStateInformation (destData);
  24827. }
  24828. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  24829. {
  24830. CFPropertyListRef propertyList = 0;
  24831. UInt32 sz = sizeof (CFPropertyListRef);
  24832. if (AudioUnitGetProperty (audioUnit,
  24833. kAudioUnitProperty_ClassInfo,
  24834. kAudioUnitScope_Global,
  24835. 0, &propertyList, &sz) == noErr)
  24836. {
  24837. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  24838. CFWriteStreamOpen (stream);
  24839. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  24840. CFWriteStreamClose (stream);
  24841. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  24842. destData.setSize (bytesWritten);
  24843. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  24844. CFRelease (data);
  24845. CFRelease (stream);
  24846. CFRelease (propertyList);
  24847. }
  24848. }
  24849. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  24850. {
  24851. setCurrentProgramStateInformation (data, sizeInBytes);
  24852. }
  24853. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  24854. {
  24855. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  24856. (const UInt8*) data,
  24857. sizeInBytes,
  24858. kCFAllocatorNull);
  24859. CFReadStreamOpen (stream);
  24860. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  24861. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  24862. stream,
  24863. 0,
  24864. kCFPropertyListImmutable,
  24865. &format,
  24866. 0);
  24867. CFRelease (stream);
  24868. if (propertyList != 0)
  24869. AudioUnitSetProperty (audioUnit,
  24870. kAudioUnitProperty_ClassInfo,
  24871. kAudioUnitScope_Global,
  24872. 0, &propertyList, sizeof (propertyList));
  24873. }
  24874. AudioUnitPluginFormat::AudioUnitPluginFormat()
  24875. {
  24876. }
  24877. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  24878. {
  24879. }
  24880. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  24881. const String& fileOrIdentifier)
  24882. {
  24883. if (! fileMightContainThisPluginType (fileOrIdentifier))
  24884. return;
  24885. PluginDescription desc;
  24886. desc.fileOrIdentifier = fileOrIdentifier;
  24887. desc.uid = 0;
  24888. try
  24889. {
  24890. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  24891. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  24892. if (auInstance != 0)
  24893. {
  24894. auInstance->fillInPluginDescription (desc);
  24895. results.add (new PluginDescription (desc));
  24896. }
  24897. }
  24898. catch (...)
  24899. {
  24900. // crashed while loading...
  24901. }
  24902. }
  24903. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  24904. {
  24905. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  24906. {
  24907. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  24908. if (result->audioUnit != 0)
  24909. {
  24910. result->initialise();
  24911. return result.release();
  24912. }
  24913. }
  24914. return 0;
  24915. }
  24916. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  24917. const bool /*recursive*/)
  24918. {
  24919. StringArray result;
  24920. ComponentRecord* comp = 0;
  24921. ComponentDescription desc;
  24922. zerostruct (desc);
  24923. for (;;)
  24924. {
  24925. zerostruct (desc);
  24926. comp = FindNextComponent (comp, &desc);
  24927. if (comp == 0)
  24928. break;
  24929. GetComponentInfo (comp, &desc, 0, 0, 0);
  24930. if (desc.componentType == kAudioUnitType_MusicDevice
  24931. || desc.componentType == kAudioUnitType_MusicEffect
  24932. || desc.componentType == kAudioUnitType_Effect
  24933. || desc.componentType == kAudioUnitType_Generator
  24934. || desc.componentType == kAudioUnitType_Panner)
  24935. {
  24936. const String s (createAUPluginIdentifier (desc));
  24937. DBG (s);
  24938. result.add (s);
  24939. }
  24940. }
  24941. return result;
  24942. }
  24943. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  24944. {
  24945. ComponentDescription desc;
  24946. String name, version, manufacturer;
  24947. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  24948. return FindNextComponent (0, &desc) != 0;
  24949. const File f (fileOrIdentifier);
  24950. return f.hasFileExtension (".component")
  24951. && f.isDirectory();
  24952. }
  24953. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  24954. {
  24955. ComponentDescription desc;
  24956. String name, version, manufacturer;
  24957. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  24958. if (name.isEmpty())
  24959. name = fileOrIdentifier;
  24960. return name;
  24961. }
  24962. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  24963. {
  24964. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24965. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  24966. else
  24967. return File (desc.fileOrIdentifier).exists();
  24968. }
  24969. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  24970. {
  24971. return FileSearchPath ("/(Default AudioUnit locations)");
  24972. }
  24973. #endif
  24974. END_JUCE_NAMESPACE
  24975. #undef log
  24976. #endif
  24977. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24978. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  24979. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  24980. #define JUCE_MAC_VST_INCLUDED 1
  24981. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  24982. #if JUCE_PLUGINHOST_VST
  24983. #if JUCE_WINDOWS
  24984. #undef _WIN32_WINNT
  24985. #define _WIN32_WINNT 0x500
  24986. #undef STRICT
  24987. #define STRICT
  24988. #include <windows.h>
  24989. #include <float.h>
  24990. #pragma warning (disable : 4312 4355)
  24991. #elif JUCE_LINUX
  24992. #include <float.h>
  24993. #include <sys/time.h>
  24994. #include <X11/Xlib.h>
  24995. #include <X11/Xutil.h>
  24996. #include <X11/Xatom.h>
  24997. #undef Font
  24998. #undef KeyPress
  24999. #undef Drawable
  25000. #undef Time
  25001. #else
  25002. #ifndef JUCE_MAC_VST_INCLUDED
  25003. // On the mac, this file needs to be compiled indirectly, by using
  25004. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25005. #error
  25006. #endif
  25007. #include <Cocoa/Cocoa.h>
  25008. #include <Carbon/Carbon.h>
  25009. #endif
  25010. #if ! (JUCE_MAC && JUCE_64BIT)
  25011. BEGIN_JUCE_NAMESPACE
  25012. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25013. #endif
  25014. #undef PRAGMA_ALIGN_SUPPORTED
  25015. #define VST_FORCE_DEPRECATED 0
  25016. #ifdef _MSC_VER
  25017. #pragma warning (push)
  25018. #pragma warning (disable: 4996)
  25019. #endif
  25020. #include "pluginterfaces/vst2.x/aeffectx.h"
  25021. #ifdef _MSC_VER
  25022. #pragma warning (pop)
  25023. #endif
  25024. #if JUCE_LINUX
  25025. #define Font JUCE_NAMESPACE::Font
  25026. #define KeyPress JUCE_NAMESPACE::KeyPress
  25027. #define Drawable JUCE_NAMESPACE::Drawable
  25028. #define Time JUCE_NAMESPACE::Time
  25029. #endif
  25030. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25031. #ifdef __aeffect__
  25032. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25033. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25034. class VSTMidiEventList
  25035. {
  25036. public:
  25037. VSTMidiEventList()
  25038. : numEventsUsed (0), numEventsAllocated (0)
  25039. {
  25040. }
  25041. ~VSTMidiEventList()
  25042. {
  25043. freeEvents();
  25044. }
  25045. void clear()
  25046. {
  25047. numEventsUsed = 0;
  25048. if (events != 0)
  25049. events->numEvents = 0;
  25050. }
  25051. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25052. {
  25053. ensureSize (numEventsUsed + 1);
  25054. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25055. events->numEvents = ++numEventsUsed;
  25056. if (numBytes <= 4)
  25057. {
  25058. if (e->type == kVstSysExType)
  25059. {
  25060. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25061. e->type = kVstMidiType;
  25062. e->byteSize = sizeof (VstMidiEvent);
  25063. e->noteLength = 0;
  25064. e->noteOffset = 0;
  25065. e->detune = 0;
  25066. e->noteOffVelocity = 0;
  25067. }
  25068. e->deltaFrames = frameOffset;
  25069. memcpy (e->midiData, midiData, numBytes);
  25070. }
  25071. else
  25072. {
  25073. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25074. if (se->type == kVstSysExType)
  25075. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25076. else
  25077. se->sysexDump = (char*) juce_malloc (numBytes);
  25078. memcpy (se->sysexDump, midiData, numBytes);
  25079. se->type = kVstSysExType;
  25080. se->byteSize = sizeof (VstMidiSysexEvent);
  25081. se->deltaFrames = frameOffset;
  25082. se->flags = 0;
  25083. se->dumpBytes = numBytes;
  25084. se->resvd1 = 0;
  25085. se->resvd2 = 0;
  25086. }
  25087. }
  25088. // Handy method to pull the events out of an event buffer supplied by the host
  25089. // or plugin.
  25090. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25091. {
  25092. for (int i = 0; i < events->numEvents; ++i)
  25093. {
  25094. const VstEvent* const e = events->events[i];
  25095. if (e != 0)
  25096. {
  25097. if (e->type == kVstMidiType)
  25098. {
  25099. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25100. 4, e->deltaFrames);
  25101. }
  25102. else if (e->type == kVstSysExType)
  25103. {
  25104. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25105. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25106. e->deltaFrames);
  25107. }
  25108. }
  25109. }
  25110. }
  25111. void ensureSize (int numEventsNeeded)
  25112. {
  25113. if (numEventsNeeded > numEventsAllocated)
  25114. {
  25115. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25116. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25117. if (events == 0)
  25118. events.calloc (size, 1);
  25119. else
  25120. events.realloc (size, 1);
  25121. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25122. {
  25123. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25124. (int) sizeof (VstMidiSysexEvent)));
  25125. e->type = kVstMidiType;
  25126. e->byteSize = sizeof (VstMidiEvent);
  25127. events->events[i] = (VstEvent*) e;
  25128. }
  25129. numEventsAllocated = numEventsNeeded;
  25130. }
  25131. }
  25132. void freeEvents()
  25133. {
  25134. if (events != 0)
  25135. {
  25136. for (int i = numEventsAllocated; --i >= 0;)
  25137. {
  25138. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25139. if (e->type == kVstSysExType)
  25140. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25141. juce_free (e);
  25142. }
  25143. events.free();
  25144. numEventsUsed = 0;
  25145. numEventsAllocated = 0;
  25146. }
  25147. }
  25148. HeapBlock <VstEvents> events;
  25149. private:
  25150. int numEventsUsed, numEventsAllocated;
  25151. };
  25152. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25153. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25154. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25155. #if ! JUCE_WIN32
  25156. static void _fpreset() {}
  25157. static void _clearfp() {}
  25158. #endif
  25159. extern void juce_callAnyTimersSynchronously();
  25160. const int fxbVersionNum = 1;
  25161. struct fxProgram
  25162. {
  25163. long chunkMagic; // 'CcnK'
  25164. long byteSize; // of this chunk, excl. magic + byteSize
  25165. long fxMagic; // 'FxCk'
  25166. long version;
  25167. long fxID; // fx unique id
  25168. long fxVersion;
  25169. long numParams;
  25170. char prgName[28];
  25171. float params[1]; // variable no. of parameters
  25172. };
  25173. struct fxSet
  25174. {
  25175. long chunkMagic; // 'CcnK'
  25176. long byteSize; // of this chunk, excl. magic + byteSize
  25177. long fxMagic; // 'FxBk'
  25178. long version;
  25179. long fxID; // fx unique id
  25180. long fxVersion;
  25181. long numPrograms;
  25182. char future[128];
  25183. fxProgram programs[1]; // variable no. of programs
  25184. };
  25185. struct fxChunkSet
  25186. {
  25187. long chunkMagic; // 'CcnK'
  25188. long byteSize; // of this chunk, excl. magic + byteSize
  25189. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25190. long version;
  25191. long fxID; // fx unique id
  25192. long fxVersion;
  25193. long numPrograms;
  25194. char future[128];
  25195. long chunkSize;
  25196. char chunk[8]; // variable
  25197. };
  25198. struct fxProgramSet
  25199. {
  25200. long chunkMagic; // 'CcnK'
  25201. long byteSize; // of this chunk, excl. magic + byteSize
  25202. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25203. long version;
  25204. long fxID; // fx unique id
  25205. long fxVersion;
  25206. long numPrograms;
  25207. char name[28];
  25208. long chunkSize;
  25209. char chunk[8]; // variable
  25210. };
  25211. static long vst_swap (const long x) throw()
  25212. {
  25213. #ifdef JUCE_LITTLE_ENDIAN
  25214. return (long) ByteOrder::swap ((uint32) x);
  25215. #else
  25216. return x;
  25217. #endif
  25218. }
  25219. static float vst_swapFloat (const float x) throw()
  25220. {
  25221. #ifdef JUCE_LITTLE_ENDIAN
  25222. union { uint32 asInt; float asFloat; } n;
  25223. n.asFloat = x;
  25224. n.asInt = ByteOrder::swap (n.asInt);
  25225. return n.asFloat;
  25226. #else
  25227. return x;
  25228. #endif
  25229. }
  25230. typedef AEffect* (*MainCall) (audioMasterCallback);
  25231. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25232. static int shellUIDToCreate = 0;
  25233. static int insideVSTCallback = 0;
  25234. class VSTPluginWindow;
  25235. // Change this to disable logging of various VST activities
  25236. #ifndef VST_LOGGING
  25237. #define VST_LOGGING 1
  25238. #endif
  25239. #if VST_LOGGING
  25240. #define log(a) Logger::writeToLog(a);
  25241. #else
  25242. #define log(a)
  25243. #endif
  25244. #if JUCE_MAC && JUCE_PPC
  25245. static void* NewCFMFromMachO (void* const machofp) throw()
  25246. {
  25247. void* result = juce_malloc (8);
  25248. ((void**) result)[0] = machofp;
  25249. ((void**) result)[1] = result;
  25250. return result;
  25251. }
  25252. #endif
  25253. #if JUCE_LINUX
  25254. extern Display* display;
  25255. extern XContext improbableNumber;
  25256. typedef void (*EventProcPtr) (XEvent* ev);
  25257. static bool xErrorTriggered;
  25258. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25259. {
  25260. xErrorTriggered = true;
  25261. return 0;
  25262. }
  25263. static int getPropertyFromXWindow (Window handle, Atom atom)
  25264. {
  25265. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25266. xErrorTriggered = false;
  25267. int userSize;
  25268. unsigned long bytes, userCount;
  25269. unsigned char* data;
  25270. Atom userType;
  25271. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25272. &userType, &userSize, &userCount, &bytes, &data);
  25273. XSetErrorHandler (oldErrorHandler);
  25274. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25275. : 0;
  25276. }
  25277. static Window getChildWindow (Window windowToCheck)
  25278. {
  25279. Window rootWindow, parentWindow;
  25280. Window* childWindows;
  25281. unsigned int numChildren;
  25282. XQueryTree (display,
  25283. windowToCheck,
  25284. &rootWindow,
  25285. &parentWindow,
  25286. &childWindows,
  25287. &numChildren);
  25288. if (numChildren > 0)
  25289. return childWindows [0];
  25290. return 0;
  25291. }
  25292. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25293. {
  25294. if (e.mods.isLeftButtonDown())
  25295. {
  25296. ev.xbutton.button = Button1;
  25297. ev.xbutton.state |= Button1Mask;
  25298. }
  25299. else if (e.mods.isRightButtonDown())
  25300. {
  25301. ev.xbutton.button = Button3;
  25302. ev.xbutton.state |= Button3Mask;
  25303. }
  25304. else if (e.mods.isMiddleButtonDown())
  25305. {
  25306. ev.xbutton.button = Button2;
  25307. ev.xbutton.state |= Button2Mask;
  25308. }
  25309. }
  25310. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25311. {
  25312. if (e.mods.isLeftButtonDown())
  25313. ev.xmotion.state |= Button1Mask;
  25314. else if (e.mods.isRightButtonDown())
  25315. ev.xmotion.state |= Button3Mask;
  25316. else if (e.mods.isMiddleButtonDown())
  25317. ev.xmotion.state |= Button2Mask;
  25318. }
  25319. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25320. {
  25321. if (e.mods.isLeftButtonDown())
  25322. ev.xcrossing.state |= Button1Mask;
  25323. else if (e.mods.isRightButtonDown())
  25324. ev.xcrossing.state |= Button3Mask;
  25325. else if (e.mods.isMiddleButtonDown())
  25326. ev.xcrossing.state |= Button2Mask;
  25327. }
  25328. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25329. {
  25330. if (increment < 0)
  25331. {
  25332. ev.xbutton.button = Button5;
  25333. ev.xbutton.state |= Button5Mask;
  25334. }
  25335. else if (increment > 0)
  25336. {
  25337. ev.xbutton.button = Button4;
  25338. ev.xbutton.state |= Button4Mask;
  25339. }
  25340. }
  25341. #endif
  25342. static VoidArray activeModules;
  25343. class ModuleHandle : public ReferenceCountedObject
  25344. {
  25345. public:
  25346. File file;
  25347. MainCall moduleMain;
  25348. String pluginName;
  25349. static ModuleHandle* findOrCreateModule (const File& file)
  25350. {
  25351. for (int i = activeModules.size(); --i >= 0;)
  25352. {
  25353. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25354. if (module->file == file)
  25355. return module;
  25356. }
  25357. _fpreset(); // (doesn't do any harm)
  25358. ++insideVSTCallback;
  25359. shellUIDToCreate = 0;
  25360. log ("Attempting to load VST: " + file.getFullPathName());
  25361. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25362. if (! m->open())
  25363. m = 0;
  25364. --insideVSTCallback;
  25365. _fpreset(); // (doesn't do any harm)
  25366. return m.release();
  25367. }
  25368. ModuleHandle (const File& file_)
  25369. : file (file_),
  25370. moduleMain (0),
  25371. #if JUCE_WIN32 || JUCE_LINUX
  25372. hModule (0)
  25373. #elif JUCE_MAC
  25374. fragId (0),
  25375. resHandle (0),
  25376. bundleRef (0),
  25377. resFileId (0)
  25378. #endif
  25379. {
  25380. activeModules.add (this);
  25381. #if JUCE_WIN32 || JUCE_LINUX
  25382. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25383. #elif JUCE_MAC
  25384. FSRef ref;
  25385. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25386. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25387. #endif
  25388. }
  25389. ~ModuleHandle()
  25390. {
  25391. activeModules.removeValue (this);
  25392. close();
  25393. }
  25394. juce_UseDebuggingNewOperator
  25395. #if JUCE_WIN32 || JUCE_LINUX
  25396. void* hModule;
  25397. String fullParentDirectoryPathName;
  25398. bool open()
  25399. {
  25400. #if JUCE_WIN32
  25401. static bool timePeriodSet = false;
  25402. if (! timePeriodSet)
  25403. {
  25404. timePeriodSet = true;
  25405. timeBeginPeriod (2);
  25406. }
  25407. #endif
  25408. pluginName = file.getFileNameWithoutExtension();
  25409. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25410. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25411. if (moduleMain == 0)
  25412. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25413. return moduleMain != 0;
  25414. }
  25415. void close()
  25416. {
  25417. _fpreset(); // (doesn't do any harm)
  25418. PlatformUtilities::freeDynamicLibrary (hModule);
  25419. }
  25420. void closeEffect (AEffect* eff)
  25421. {
  25422. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25423. }
  25424. #else
  25425. CFragConnectionID fragId;
  25426. Handle resHandle;
  25427. CFBundleRef bundleRef;
  25428. FSSpec parentDirFSSpec;
  25429. short resFileId;
  25430. bool open()
  25431. {
  25432. bool ok = false;
  25433. const String filename (file.getFullPathName());
  25434. if (file.hasFileExtension (".vst"))
  25435. {
  25436. const char* const utf8 = filename.toUTF8();
  25437. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25438. strlen (utf8), file.isDirectory());
  25439. if (url != 0)
  25440. {
  25441. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25442. CFRelease (url);
  25443. if (bundleRef != 0)
  25444. {
  25445. if (CFBundleLoadExecutable (bundleRef))
  25446. {
  25447. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25448. if (moduleMain == 0)
  25449. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25450. if (moduleMain != 0)
  25451. {
  25452. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25453. if (name != 0)
  25454. {
  25455. if (CFGetTypeID (name) == CFStringGetTypeID())
  25456. {
  25457. char buffer[1024];
  25458. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25459. pluginName = buffer;
  25460. }
  25461. }
  25462. if (pluginName.isEmpty())
  25463. pluginName = file.getFileNameWithoutExtension();
  25464. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25465. ok = true;
  25466. }
  25467. }
  25468. if (! ok)
  25469. {
  25470. CFBundleUnloadExecutable (bundleRef);
  25471. CFRelease (bundleRef);
  25472. bundleRef = 0;
  25473. }
  25474. }
  25475. }
  25476. }
  25477. #if JUCE_PPC
  25478. else
  25479. {
  25480. FSRef fn;
  25481. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25482. {
  25483. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25484. if (resFileId != -1)
  25485. {
  25486. const int numEffs = Count1Resources ('aEff');
  25487. for (int i = 0; i < numEffs; ++i)
  25488. {
  25489. resHandle = Get1IndResource ('aEff', i + 1);
  25490. if (resHandle != 0)
  25491. {
  25492. OSType type;
  25493. Str255 name;
  25494. SInt16 id;
  25495. GetResInfo (resHandle, &id, &type, name);
  25496. pluginName = String ((const char*) name + 1, name[0]);
  25497. DetachResource (resHandle);
  25498. HLock (resHandle);
  25499. Ptr ptr;
  25500. Str255 errorText;
  25501. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25502. name, kPrivateCFragCopy,
  25503. &fragId, &ptr, errorText);
  25504. if (err == noErr)
  25505. {
  25506. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25507. ok = true;
  25508. }
  25509. else
  25510. {
  25511. HUnlock (resHandle);
  25512. }
  25513. break;
  25514. }
  25515. }
  25516. if (! ok)
  25517. CloseResFile (resFileId);
  25518. }
  25519. }
  25520. }
  25521. #endif
  25522. return ok;
  25523. }
  25524. void close()
  25525. {
  25526. #if JUCE_PPC
  25527. if (fragId != 0)
  25528. {
  25529. if (moduleMain != 0)
  25530. disposeMachOFromCFM ((void*) moduleMain);
  25531. CloseConnection (&fragId);
  25532. HUnlock (resHandle);
  25533. if (resFileId != 0)
  25534. CloseResFile (resFileId);
  25535. }
  25536. else
  25537. #endif
  25538. if (bundleRef != 0)
  25539. {
  25540. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25541. if (CFGetRetainCount (bundleRef) == 1)
  25542. CFBundleUnloadExecutable (bundleRef);
  25543. if (CFGetRetainCount (bundleRef) > 0)
  25544. CFRelease (bundleRef);
  25545. }
  25546. }
  25547. void closeEffect (AEffect* eff)
  25548. {
  25549. #if JUCE_PPC
  25550. if (fragId != 0)
  25551. {
  25552. VoidArray thingsToDelete;
  25553. thingsToDelete.add ((void*) eff->dispatcher);
  25554. thingsToDelete.add ((void*) eff->process);
  25555. thingsToDelete.add ((void*) eff->setParameter);
  25556. thingsToDelete.add ((void*) eff->getParameter);
  25557. thingsToDelete.add ((void*) eff->processReplacing);
  25558. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25559. for (int i = thingsToDelete.size(); --i >= 0;)
  25560. disposeMachOFromCFM (thingsToDelete[i]);
  25561. }
  25562. else
  25563. #endif
  25564. {
  25565. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25566. }
  25567. }
  25568. #if JUCE_PPC
  25569. static void* newMachOFromCFM (void* cfmfp)
  25570. {
  25571. if (cfmfp == 0)
  25572. return 0;
  25573. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25574. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25575. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25576. mfp[2] = 0x800c0000;
  25577. mfp[3] = 0x804c0004;
  25578. mfp[4] = 0x7c0903a6;
  25579. mfp[5] = 0x4e800420;
  25580. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25581. return mfp;
  25582. }
  25583. static void disposeMachOFromCFM (void* ptr)
  25584. {
  25585. juce_free (ptr);
  25586. }
  25587. void coerceAEffectFunctionCalls (AEffect* eff)
  25588. {
  25589. if (fragId != 0)
  25590. {
  25591. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25592. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25593. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25594. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25595. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25596. }
  25597. }
  25598. #endif
  25599. #endif
  25600. };
  25601. class VSTPluginInstance : public AudioPluginInstance,
  25602. private Timer,
  25603. private AsyncUpdater
  25604. {
  25605. public:
  25606. ~VSTPluginInstance();
  25607. // AudioPluginInstance methods:
  25608. void fillInPluginDescription (PluginDescription& desc) const
  25609. {
  25610. desc.name = name;
  25611. desc.fileOrIdentifier = module->file.getFullPathName();
  25612. desc.uid = getUID();
  25613. desc.lastFileModTime = module->file.getLastModificationTime();
  25614. desc.pluginFormatName = "VST";
  25615. desc.category = getCategory();
  25616. {
  25617. char buffer [kVstMaxVendorStrLen + 8];
  25618. zerostruct (buffer);
  25619. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25620. desc.manufacturerName = buffer;
  25621. }
  25622. desc.version = getVersion();
  25623. desc.numInputChannels = getNumInputChannels();
  25624. desc.numOutputChannels = getNumOutputChannels();
  25625. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25626. }
  25627. const String getName() const { return name; }
  25628. int getUID() const throw();
  25629. bool acceptsMidi() const { return wantsMidiMessages; }
  25630. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25631. // AudioProcessor methods:
  25632. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25633. void releaseResources();
  25634. void processBlock (AudioSampleBuffer& buffer,
  25635. MidiBuffer& midiMessages);
  25636. AudioProcessorEditor* createEditor();
  25637. const String getInputChannelName (const int index) const;
  25638. bool isInputChannelStereoPair (int index) const;
  25639. const String getOutputChannelName (const int index) const;
  25640. bool isOutputChannelStereoPair (int index) const;
  25641. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25642. float getParameter (int index);
  25643. void setParameter (int index, float newValue);
  25644. const String getParameterName (int index);
  25645. const String getParameterText (int index);
  25646. bool isParameterAutomatable (int index) const;
  25647. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25648. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25649. void setCurrentProgram (int index);
  25650. const String getProgramName (int index);
  25651. void changeProgramName (int index, const String& newName);
  25652. void getStateInformation (MemoryBlock& destData);
  25653. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25654. void setStateInformation (const void* data, int sizeInBytes);
  25655. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25656. void timerCallback();
  25657. void handleAsyncUpdate();
  25658. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25659. juce_UseDebuggingNewOperator
  25660. private:
  25661. friend class VSTPluginWindow;
  25662. friend class VSTPluginFormat;
  25663. AEffect* effect;
  25664. String name;
  25665. CriticalSection lock;
  25666. bool wantsMidiMessages, initialised, isPowerOn;
  25667. mutable StringArray programNames;
  25668. AudioSampleBuffer tempBuffer;
  25669. CriticalSection midiInLock;
  25670. MidiBuffer incomingMidi;
  25671. VSTMidiEventList midiEventsToSend;
  25672. VstTimeInfo vstHostTime;
  25673. HeapBlock <float*> channels;
  25674. ReferenceCountedObjectPtr <ModuleHandle> module;
  25675. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25676. bool restoreProgramSettings (const fxProgram* const prog);
  25677. const String getCurrentProgramName();
  25678. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25679. void updateStoredProgramNames();
  25680. void initialise();
  25681. void handleMidiFromPlugin (const VstEvents* const events);
  25682. void createTempParameterStore (MemoryBlock& dest);
  25683. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25684. const String getParameterLabel (int index) const;
  25685. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25686. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25687. void setChunkData (const char* data, int size, bool isPreset);
  25688. bool loadFromFXBFile (const void* data, int numBytes);
  25689. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25690. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25691. const String getVersion() const throw();
  25692. const String getCategory() const throw();
  25693. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25694. void setPower (const bool on);
  25695. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25696. };
  25697. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25698. : effect (0),
  25699. wantsMidiMessages (false),
  25700. initialised (false),
  25701. isPowerOn (false),
  25702. tempBuffer (1, 1),
  25703. module (module_)
  25704. {
  25705. try
  25706. {
  25707. _fpreset();
  25708. ++insideVSTCallback;
  25709. name = module->pluginName;
  25710. log ("Creating VST instance: " + name);
  25711. #if JUCE_MAC
  25712. if (module->resFileId != 0)
  25713. UseResFile (module->resFileId);
  25714. #if JUCE_PPC
  25715. if (module->fragId != 0)
  25716. {
  25717. static void* audioMasterCoerced = 0;
  25718. if (audioMasterCoerced == 0)
  25719. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  25720. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  25721. }
  25722. else
  25723. #endif
  25724. #endif
  25725. {
  25726. effect = module->moduleMain (&audioMaster);
  25727. }
  25728. --insideVSTCallback;
  25729. if (effect != 0 && effect->magic == kEffectMagic)
  25730. {
  25731. #if JUCE_PPC
  25732. module->coerceAEffectFunctionCalls (effect);
  25733. #endif
  25734. jassert (effect->resvd2 == 0);
  25735. jassert (effect->object != 0);
  25736. _fpreset(); // some dodgy plugs fuck around with this
  25737. }
  25738. else
  25739. {
  25740. effect = 0;
  25741. }
  25742. }
  25743. catch (...)
  25744. {
  25745. --insideVSTCallback;
  25746. }
  25747. }
  25748. VSTPluginInstance::~VSTPluginInstance()
  25749. {
  25750. {
  25751. const ScopedLock sl (lock);
  25752. jassert (insideVSTCallback == 0);
  25753. if (effect != 0 && effect->magic == kEffectMagic)
  25754. {
  25755. try
  25756. {
  25757. #if JUCE_MAC
  25758. if (module->resFileId != 0)
  25759. UseResFile (module->resFileId);
  25760. #endif
  25761. // Must delete any editors before deleting the plugin instance!
  25762. jassert (getActiveEditor() == 0);
  25763. _fpreset(); // some dodgy plugs fuck around with this
  25764. module->closeEffect (effect);
  25765. }
  25766. catch (...)
  25767. {}
  25768. }
  25769. module = 0;
  25770. effect = 0;
  25771. }
  25772. }
  25773. void VSTPluginInstance::initialise()
  25774. {
  25775. if (initialised || effect == 0)
  25776. return;
  25777. log ("Initialising VST: " + module->pluginName);
  25778. initialised = true;
  25779. dispatch (effIdentify, 0, 0, 0, 0);
  25780. // this code would ask the plugin for its name, but so few plugins
  25781. // actually bother implementing this correctly, that it's better to
  25782. // just ignore it and use the file name instead.
  25783. if (getSampleRate() > 0)
  25784. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  25785. if (getBlockSize() > 0)
  25786. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  25787. dispatch (effOpen, 0, 0, 0, 0);
  25788. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25789. getSampleRate(), getBlockSize());
  25790. if (getNumPrograms() > 1)
  25791. setCurrentProgram (0);
  25792. else
  25793. dispatch (effSetProgram, 0, 0, 0, 0);
  25794. int i;
  25795. for (i = effect->numInputs; --i >= 0;)
  25796. dispatch (effConnectInput, i, 1, 0, 0);
  25797. for (i = effect->numOutputs; --i >= 0;)
  25798. dispatch (effConnectOutput, i, 1, 0, 0);
  25799. updateStoredProgramNames();
  25800. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  25801. setLatencySamples (effect->initialDelay);
  25802. }
  25803. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  25804. int samplesPerBlockExpected)
  25805. {
  25806. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25807. sampleRate_, samplesPerBlockExpected);
  25808. setLatencySamples (effect->initialDelay);
  25809. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  25810. vstHostTime.tempo = 120.0;
  25811. vstHostTime.timeSigNumerator = 4;
  25812. vstHostTime.timeSigDenominator = 4;
  25813. vstHostTime.sampleRate = sampleRate_;
  25814. vstHostTime.samplePos = 0;
  25815. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  25816. initialise();
  25817. if (initialised)
  25818. {
  25819. wantsMidiMessages = wantsMidiMessages
  25820. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  25821. if (wantsMidiMessages)
  25822. midiEventsToSend.ensureSize (256);
  25823. else
  25824. midiEventsToSend.freeEvents();
  25825. incomingMidi.clear();
  25826. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  25827. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  25828. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  25829. if (! isPowerOn)
  25830. setPower (true);
  25831. // dodgy hack to force some plugins to initialise the sample rate..
  25832. if ((! hasEditor()) && getNumParameters() > 0)
  25833. {
  25834. const float old = getParameter (0);
  25835. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  25836. setParameter (0, old);
  25837. }
  25838. dispatch (effStartProcess, 0, 0, 0, 0);
  25839. }
  25840. }
  25841. void VSTPluginInstance::releaseResources()
  25842. {
  25843. if (initialised)
  25844. {
  25845. dispatch (effStopProcess, 0, 0, 0, 0);
  25846. setPower (false);
  25847. }
  25848. tempBuffer.setSize (1, 1);
  25849. incomingMidi.clear();
  25850. midiEventsToSend.freeEvents();
  25851. channels.free();
  25852. }
  25853. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  25854. MidiBuffer& midiMessages)
  25855. {
  25856. const int numSamples = buffer.getNumSamples();
  25857. if (initialised)
  25858. {
  25859. AudioPlayHead* playHead = getPlayHead();
  25860. if (playHead != 0)
  25861. {
  25862. AudioPlayHead::CurrentPositionInfo position;
  25863. playHead->getCurrentPosition (position);
  25864. vstHostTime.tempo = position.bpm;
  25865. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  25866. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  25867. vstHostTime.ppqPos = position.ppqPosition;
  25868. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  25869. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  25870. if (position.isPlaying)
  25871. vstHostTime.flags |= kVstTransportPlaying;
  25872. else
  25873. vstHostTime.flags &= ~kVstTransportPlaying;
  25874. }
  25875. #if JUCE_WIN32
  25876. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  25877. #elif JUCE_LINUX
  25878. timeval micro;
  25879. gettimeofday (&micro, 0);
  25880. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  25881. #elif JUCE_MAC
  25882. UnsignedWide micro;
  25883. Microseconds (&micro);
  25884. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  25885. #endif
  25886. if (wantsMidiMessages)
  25887. {
  25888. midiEventsToSend.clear();
  25889. midiEventsToSend.ensureSize (1);
  25890. MidiBuffer::Iterator iter (midiMessages);
  25891. const uint8* midiData;
  25892. int numBytesOfMidiData, samplePosition;
  25893. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  25894. {
  25895. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  25896. jlimit (0, numSamples - 1, samplePosition));
  25897. }
  25898. try
  25899. {
  25900. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  25901. }
  25902. catch (...)
  25903. {}
  25904. }
  25905. int i;
  25906. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  25907. for (i = 0; i < maxChans; ++i)
  25908. channels[i] = buffer.getSampleData (i);
  25909. channels [maxChans] = 0;
  25910. _clearfp();
  25911. if ((effect->flags & effFlagsCanReplacing) != 0)
  25912. {
  25913. try
  25914. {
  25915. effect->processReplacing (effect, channels, channels, numSamples);
  25916. }
  25917. catch (...)
  25918. {}
  25919. }
  25920. else
  25921. {
  25922. tempBuffer.setSize (effect->numOutputs, numSamples);
  25923. tempBuffer.clear();
  25924. float* outs [64];
  25925. for (i = effect->numOutputs; --i >= 0;)
  25926. outs[i] = tempBuffer.getSampleData (i);
  25927. outs [effect->numOutputs] = 0;
  25928. try
  25929. {
  25930. effect->process (effect, channels, outs, numSamples);
  25931. }
  25932. catch (...)
  25933. {}
  25934. for (i = effect->numOutputs; --i >= 0;)
  25935. buffer.copyFrom (i, 0, outs[i], numSamples);
  25936. }
  25937. }
  25938. else
  25939. {
  25940. // Not initialised, so just bypass..
  25941. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  25942. buffer.clear (i, 0, buffer.getNumSamples());
  25943. }
  25944. {
  25945. // copy any incoming midi..
  25946. const ScopedLock sl (midiInLock);
  25947. midiMessages.swapWith (incomingMidi);
  25948. incomingMidi.clear();
  25949. }
  25950. }
  25951. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  25952. {
  25953. if (events != 0)
  25954. {
  25955. const ScopedLock sl (midiInLock);
  25956. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  25957. }
  25958. }
  25959. static Array <VSTPluginWindow*> activeVSTWindows;
  25960. class VSTPluginWindow : public AudioProcessorEditor,
  25961. #if ! JUCE_MAC
  25962. public ComponentMovementWatcher,
  25963. #endif
  25964. public Timer
  25965. {
  25966. public:
  25967. VSTPluginWindow (VSTPluginInstance& plugin_)
  25968. : AudioProcessorEditor (&plugin_),
  25969. #if ! JUCE_MAC
  25970. ComponentMovementWatcher (this),
  25971. #endif
  25972. plugin (plugin_),
  25973. isOpen (false),
  25974. wasShowing (false),
  25975. pluginRefusesToResize (false),
  25976. pluginWantsKeys (false),
  25977. alreadyInside (false),
  25978. recursiveResize (false)
  25979. {
  25980. #if JUCE_WIN32
  25981. sizeCheckCount = 0;
  25982. pluginHWND = 0;
  25983. #elif JUCE_LINUX
  25984. pluginWindow = None;
  25985. pluginProc = None;
  25986. #else
  25987. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  25988. #endif
  25989. activeVSTWindows.add (this);
  25990. setSize (1, 1);
  25991. setOpaque (true);
  25992. setVisible (true);
  25993. }
  25994. ~VSTPluginWindow()
  25995. {
  25996. #if JUCE_MAC
  25997. innerWrapper = 0;
  25998. #else
  25999. closePluginWindow();
  26000. #endif
  26001. activeVSTWindows.removeValue (this);
  26002. plugin.editorBeingDeleted (this);
  26003. }
  26004. #if ! JUCE_MAC
  26005. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26006. {
  26007. if (recursiveResize)
  26008. return;
  26009. Component* const topComp = getTopLevelComponent();
  26010. if (topComp->getPeer() != 0)
  26011. {
  26012. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26013. recursiveResize = true;
  26014. #if JUCE_WIN32
  26015. if (pluginHWND != 0)
  26016. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26017. #elif JUCE_LINUX
  26018. if (pluginWindow != 0)
  26019. {
  26020. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26021. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26022. XMapRaised (display, pluginWindow);
  26023. }
  26024. #endif
  26025. recursiveResize = false;
  26026. }
  26027. }
  26028. void componentVisibilityChanged (Component&)
  26029. {
  26030. const bool isShowingNow = isShowing();
  26031. if (wasShowing != isShowingNow)
  26032. {
  26033. wasShowing = isShowingNow;
  26034. if (isShowingNow)
  26035. openPluginWindow();
  26036. else
  26037. closePluginWindow();
  26038. }
  26039. componentMovedOrResized (true, true);
  26040. }
  26041. void componentPeerChanged()
  26042. {
  26043. closePluginWindow();
  26044. openPluginWindow();
  26045. }
  26046. #endif
  26047. bool keyStateChanged (bool)
  26048. {
  26049. return pluginWantsKeys;
  26050. }
  26051. bool keyPressed (const KeyPress&)
  26052. {
  26053. return pluginWantsKeys;
  26054. }
  26055. #if JUCE_MAC
  26056. void paint (Graphics& g)
  26057. {
  26058. g.fillAll (Colours::black);
  26059. }
  26060. #else
  26061. void paint (Graphics& g)
  26062. {
  26063. if (isOpen)
  26064. {
  26065. ComponentPeer* const peer = getPeer();
  26066. if (peer != 0)
  26067. {
  26068. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26069. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26070. #if JUCE_LINUX
  26071. if (pluginWindow != 0)
  26072. {
  26073. const Rectangle<int> clip (g.getClipBounds());
  26074. XEvent ev;
  26075. zerostruct (ev);
  26076. ev.xexpose.type = Expose;
  26077. ev.xexpose.display = display;
  26078. ev.xexpose.window = pluginWindow;
  26079. ev.xexpose.x = clip.getX();
  26080. ev.xexpose.y = clip.getY();
  26081. ev.xexpose.width = clip.getWidth();
  26082. ev.xexpose.height = clip.getHeight();
  26083. sendEventToChild (&ev);
  26084. }
  26085. #endif
  26086. }
  26087. }
  26088. else
  26089. {
  26090. g.fillAll (Colours::black);
  26091. }
  26092. }
  26093. #endif
  26094. void timerCallback()
  26095. {
  26096. #if JUCE_WIN32
  26097. if (--sizeCheckCount <= 0)
  26098. {
  26099. sizeCheckCount = 10;
  26100. checkPluginWindowSize();
  26101. }
  26102. #endif
  26103. try
  26104. {
  26105. static bool reentrant = false;
  26106. if (! reentrant)
  26107. {
  26108. reentrant = true;
  26109. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26110. reentrant = false;
  26111. }
  26112. }
  26113. catch (...)
  26114. {}
  26115. }
  26116. void mouseDown (const MouseEvent& e)
  26117. {
  26118. #if JUCE_LINUX
  26119. if (pluginWindow == 0)
  26120. return;
  26121. toFront (true);
  26122. XEvent ev;
  26123. zerostruct (ev);
  26124. ev.xbutton.display = display;
  26125. ev.xbutton.type = ButtonPress;
  26126. ev.xbutton.window = pluginWindow;
  26127. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26128. ev.xbutton.time = CurrentTime;
  26129. ev.xbutton.x = e.x;
  26130. ev.xbutton.y = e.y;
  26131. ev.xbutton.x_root = e.getScreenX();
  26132. ev.xbutton.y_root = e.getScreenY();
  26133. translateJuceToXButtonModifiers (e, ev);
  26134. sendEventToChild (&ev);
  26135. #elif JUCE_WIN32
  26136. (void) e;
  26137. toFront (true);
  26138. #endif
  26139. }
  26140. void broughtToFront()
  26141. {
  26142. activeVSTWindows.removeValue (this);
  26143. activeVSTWindows.add (this);
  26144. #if JUCE_MAC
  26145. dispatch (effEditTop, 0, 0, 0, 0);
  26146. #endif
  26147. }
  26148. juce_UseDebuggingNewOperator
  26149. private:
  26150. VSTPluginInstance& plugin;
  26151. bool isOpen, wasShowing, recursiveResize;
  26152. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26153. #if JUCE_WIN32
  26154. HWND pluginHWND;
  26155. void* originalWndProc;
  26156. int sizeCheckCount;
  26157. #elif JUCE_LINUX
  26158. Window pluginWindow;
  26159. EventProcPtr pluginProc;
  26160. #endif
  26161. #if JUCE_MAC
  26162. void openPluginWindow (WindowRef parentWindow)
  26163. {
  26164. if (isOpen || parentWindow == 0)
  26165. return;
  26166. isOpen = true;
  26167. ERect* rect = 0;
  26168. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26169. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26170. // do this before and after like in the steinberg example
  26171. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26172. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26173. // Install keyboard hooks
  26174. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26175. // double-check it's not too tiny
  26176. int w = 250, h = 150;
  26177. if (rect != 0)
  26178. {
  26179. w = rect->right - rect->left;
  26180. h = rect->bottom - rect->top;
  26181. if (w == 0 || h == 0)
  26182. {
  26183. w = 250;
  26184. h = 150;
  26185. }
  26186. }
  26187. w = jmax (w, 32);
  26188. h = jmax (h, 32);
  26189. setSize (w, h);
  26190. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26191. repaint();
  26192. }
  26193. #else
  26194. void openPluginWindow()
  26195. {
  26196. if (isOpen || getWindowHandle() == 0)
  26197. return;
  26198. log ("Opening VST UI: " + plugin.name);
  26199. isOpen = true;
  26200. ERect* rect = 0;
  26201. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26202. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26203. // do this before and after like in the steinberg example
  26204. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26205. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26206. // Install keyboard hooks
  26207. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26208. #if JUCE_WIN32
  26209. originalWndProc = 0;
  26210. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26211. if (pluginHWND == 0)
  26212. {
  26213. isOpen = false;
  26214. setSize (300, 150);
  26215. return;
  26216. }
  26217. #pragma warning (push)
  26218. #pragma warning (disable: 4244)
  26219. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26220. if (! pluginWantsKeys)
  26221. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) vstHookWndProc);
  26222. #pragma warning (pop)
  26223. int w, h;
  26224. RECT r;
  26225. GetWindowRect (pluginHWND, &r);
  26226. w = r.right - r.left;
  26227. h = r.bottom - r.top;
  26228. if (rect != 0)
  26229. {
  26230. const int rw = rect->right - rect->left;
  26231. const int rh = rect->bottom - rect->top;
  26232. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26233. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26234. {
  26235. // very dodgy logic to decide which size is right.
  26236. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26237. {
  26238. SetWindowPos (pluginHWND, 0,
  26239. 0, 0, rw, rh,
  26240. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26241. GetWindowRect (pluginHWND, &r);
  26242. w = r.right - r.left;
  26243. h = r.bottom - r.top;
  26244. pluginRefusesToResize = (w != rw) || (h != rh);
  26245. w = rw;
  26246. h = rh;
  26247. }
  26248. }
  26249. }
  26250. #elif JUCE_LINUX
  26251. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26252. if (pluginWindow != 0)
  26253. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26254. XInternAtom (display, "_XEventProc", False));
  26255. int w = 250, h = 150;
  26256. if (rect != 0)
  26257. {
  26258. w = rect->right - rect->left;
  26259. h = rect->bottom - rect->top;
  26260. if (w == 0 || h == 0)
  26261. {
  26262. w = 250;
  26263. h = 150;
  26264. }
  26265. }
  26266. if (pluginWindow != 0)
  26267. XMapRaised (display, pluginWindow);
  26268. #endif
  26269. // double-check it's not too tiny
  26270. w = jmax (w, 32);
  26271. h = jmax (h, 32);
  26272. setSize (w, h);
  26273. #if JUCE_WIN32
  26274. checkPluginWindowSize();
  26275. #endif
  26276. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26277. repaint();
  26278. }
  26279. #endif
  26280. #if ! JUCE_MAC
  26281. void closePluginWindow()
  26282. {
  26283. if (isOpen)
  26284. {
  26285. log ("Closing VST UI: " + plugin.getName());
  26286. isOpen = false;
  26287. dispatch (effEditClose, 0, 0, 0, 0);
  26288. #if JUCE_WIN32
  26289. #pragma warning (push)
  26290. #pragma warning (disable: 4244)
  26291. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26292. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) originalWndProc);
  26293. #pragma warning (pop)
  26294. stopTimer();
  26295. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26296. DestroyWindow (pluginHWND);
  26297. pluginHWND = 0;
  26298. #elif JUCE_LINUX
  26299. stopTimer();
  26300. pluginWindow = 0;
  26301. pluginProc = 0;
  26302. #endif
  26303. }
  26304. }
  26305. #endif
  26306. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26307. {
  26308. return plugin.dispatch (opcode, index, value, ptr, opt);
  26309. }
  26310. #if JUCE_WIN32
  26311. void checkPluginWindowSize() throw()
  26312. {
  26313. RECT r;
  26314. GetWindowRect (pluginHWND, &r);
  26315. const int w = r.right - r.left;
  26316. const int h = r.bottom - r.top;
  26317. if (isShowing() && w > 0 && h > 0
  26318. && (w != getWidth() || h != getHeight())
  26319. && ! pluginRefusesToResize)
  26320. {
  26321. setSize (w, h);
  26322. sizeCheckCount = 0;
  26323. }
  26324. }
  26325. // hooks to get keyboard events from VST windows..
  26326. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26327. {
  26328. for (int i = activeVSTWindows.size(); --i >= 0;)
  26329. {
  26330. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26331. if (w->pluginHWND == hW)
  26332. {
  26333. if (message == WM_CHAR
  26334. || message == WM_KEYDOWN
  26335. || message == WM_SYSKEYDOWN
  26336. || message == WM_KEYUP
  26337. || message == WM_SYSKEYUP
  26338. || message == WM_APPCOMMAND)
  26339. {
  26340. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26341. message, wParam, lParam);
  26342. }
  26343. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26344. (HWND) w->pluginHWND,
  26345. message,
  26346. wParam,
  26347. lParam);
  26348. }
  26349. }
  26350. return DefWindowProc (hW, message, wParam, lParam);
  26351. }
  26352. #endif
  26353. #if JUCE_LINUX
  26354. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26355. void sendEventToChild (XEvent* event)
  26356. {
  26357. if (pluginProc != 0)
  26358. {
  26359. // if the plugin publishes an event procedure, pass the event directly..
  26360. pluginProc (event);
  26361. }
  26362. else if (pluginWindow != 0)
  26363. {
  26364. // if the plugin has a window, then send the event to the window so that
  26365. // its message thread will pick it up..
  26366. XSendEvent (display, pluginWindow, False, 0L, event);
  26367. XFlush (display);
  26368. }
  26369. }
  26370. void mouseEnter (const MouseEvent& e)
  26371. {
  26372. if (pluginWindow != 0)
  26373. {
  26374. XEvent ev;
  26375. zerostruct (ev);
  26376. ev.xcrossing.display = display;
  26377. ev.xcrossing.type = EnterNotify;
  26378. ev.xcrossing.window = pluginWindow;
  26379. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26380. ev.xcrossing.time = CurrentTime;
  26381. ev.xcrossing.x = e.x;
  26382. ev.xcrossing.y = e.y;
  26383. ev.xcrossing.x_root = e.getScreenX();
  26384. ev.xcrossing.y_root = e.getScreenY();
  26385. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26386. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26387. translateJuceToXCrossingModifiers (e, ev);
  26388. sendEventToChild (&ev);
  26389. }
  26390. }
  26391. void mouseExit (const MouseEvent& e)
  26392. {
  26393. if (pluginWindow != 0)
  26394. {
  26395. XEvent ev;
  26396. zerostruct (ev);
  26397. ev.xcrossing.display = display;
  26398. ev.xcrossing.type = LeaveNotify;
  26399. ev.xcrossing.window = pluginWindow;
  26400. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26401. ev.xcrossing.time = CurrentTime;
  26402. ev.xcrossing.x = e.x;
  26403. ev.xcrossing.y = e.y;
  26404. ev.xcrossing.x_root = e.getScreenX();
  26405. ev.xcrossing.y_root = e.getScreenY();
  26406. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26407. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26408. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26409. translateJuceToXCrossingModifiers (e, ev);
  26410. sendEventToChild (&ev);
  26411. }
  26412. }
  26413. void mouseMove (const MouseEvent& e)
  26414. {
  26415. if (pluginWindow != 0)
  26416. {
  26417. XEvent ev;
  26418. zerostruct (ev);
  26419. ev.xmotion.display = display;
  26420. ev.xmotion.type = MotionNotify;
  26421. ev.xmotion.window = pluginWindow;
  26422. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26423. ev.xmotion.time = CurrentTime;
  26424. ev.xmotion.is_hint = NotifyNormal;
  26425. ev.xmotion.x = e.x;
  26426. ev.xmotion.y = e.y;
  26427. ev.xmotion.x_root = e.getScreenX();
  26428. ev.xmotion.y_root = e.getScreenY();
  26429. sendEventToChild (&ev);
  26430. }
  26431. }
  26432. void mouseDrag (const MouseEvent& e)
  26433. {
  26434. if (pluginWindow != 0)
  26435. {
  26436. XEvent ev;
  26437. zerostruct (ev);
  26438. ev.xmotion.display = display;
  26439. ev.xmotion.type = MotionNotify;
  26440. ev.xmotion.window = pluginWindow;
  26441. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26442. ev.xmotion.time = CurrentTime;
  26443. ev.xmotion.x = e.x ;
  26444. ev.xmotion.y = e.y;
  26445. ev.xmotion.x_root = e.getScreenX();
  26446. ev.xmotion.y_root = e.getScreenY();
  26447. ev.xmotion.is_hint = NotifyNormal;
  26448. translateJuceToXMotionModifiers (e, ev);
  26449. sendEventToChild (&ev);
  26450. }
  26451. }
  26452. void mouseUp (const MouseEvent& e)
  26453. {
  26454. if (pluginWindow != 0)
  26455. {
  26456. XEvent ev;
  26457. zerostruct (ev);
  26458. ev.xbutton.display = display;
  26459. ev.xbutton.type = ButtonRelease;
  26460. ev.xbutton.window = pluginWindow;
  26461. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26462. ev.xbutton.time = CurrentTime;
  26463. ev.xbutton.x = e.x;
  26464. ev.xbutton.y = e.y;
  26465. ev.xbutton.x_root = e.getScreenX();
  26466. ev.xbutton.y_root = e.getScreenY();
  26467. translateJuceToXButtonModifiers (e, ev);
  26468. sendEventToChild (&ev);
  26469. }
  26470. }
  26471. void mouseWheelMove (const MouseEvent& e,
  26472. float incrementX,
  26473. float incrementY)
  26474. {
  26475. if (pluginWindow != 0)
  26476. {
  26477. XEvent ev;
  26478. zerostruct (ev);
  26479. ev.xbutton.display = display;
  26480. ev.xbutton.type = ButtonPress;
  26481. ev.xbutton.window = pluginWindow;
  26482. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26483. ev.xbutton.time = CurrentTime;
  26484. ev.xbutton.x = e.x;
  26485. ev.xbutton.y = e.y;
  26486. ev.xbutton.x_root = e.getScreenX();
  26487. ev.xbutton.y_root = e.getScreenY();
  26488. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26489. sendEventToChild (&ev);
  26490. // TODO - put a usleep here ?
  26491. ev.xbutton.type = ButtonRelease;
  26492. sendEventToChild (&ev);
  26493. }
  26494. }
  26495. #endif
  26496. #if JUCE_MAC
  26497. #if ! JUCE_SUPPORT_CARBON
  26498. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26499. #endif
  26500. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26501. {
  26502. public:
  26503. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26504. : owner (owner_),
  26505. alreadyInside (false)
  26506. {
  26507. }
  26508. ~InnerWrapperComponent()
  26509. {
  26510. deleteWindow();
  26511. }
  26512. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26513. {
  26514. owner->openPluginWindow (windowRef);
  26515. return 0;
  26516. }
  26517. void removeView (HIViewRef)
  26518. {
  26519. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26520. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26521. }
  26522. bool getEmbeddedViewSize (int& w, int& h)
  26523. {
  26524. ERect* rect = 0;
  26525. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26526. w = rect->right - rect->left;
  26527. h = rect->bottom - rect->top;
  26528. return true;
  26529. }
  26530. void mouseDown (int x, int y)
  26531. {
  26532. if (! alreadyInside)
  26533. {
  26534. alreadyInside = true;
  26535. getTopLevelComponent()->toFront (true);
  26536. owner->dispatch (effEditMouse, x, y, 0, 0);
  26537. alreadyInside = false;
  26538. }
  26539. else
  26540. {
  26541. PostEvent (::mouseDown, 0);
  26542. }
  26543. }
  26544. void paint()
  26545. {
  26546. ComponentPeer* const peer = getPeer();
  26547. if (peer != 0)
  26548. {
  26549. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26550. ERect r;
  26551. r.left = pos.getX();
  26552. r.right = r.left + getWidth();
  26553. r.top = pos.getY();
  26554. r.bottom = r.top + getHeight();
  26555. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26556. }
  26557. }
  26558. private:
  26559. VSTPluginWindow* const owner;
  26560. bool alreadyInside;
  26561. };
  26562. friend class InnerWrapperComponent;
  26563. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26564. void resized()
  26565. {
  26566. innerWrapper->setSize (getWidth(), getHeight());
  26567. }
  26568. #endif
  26569. };
  26570. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26571. {
  26572. if (hasEditor())
  26573. return new VSTPluginWindow (*this);
  26574. return 0;
  26575. }
  26576. void VSTPluginInstance::handleAsyncUpdate()
  26577. {
  26578. // indicates that something about the plugin has changed..
  26579. updateHostDisplay();
  26580. }
  26581. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26582. {
  26583. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26584. {
  26585. changeProgramName (getCurrentProgram(), prog->prgName);
  26586. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26587. setParameter (i, vst_swapFloat (prog->params[i]));
  26588. return true;
  26589. }
  26590. return false;
  26591. }
  26592. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26593. const int dataSize)
  26594. {
  26595. if (dataSize < 28)
  26596. return false;
  26597. const fxSet* const set = (const fxSet*) data;
  26598. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26599. || vst_swap (set->version) > fxbVersionNum)
  26600. return false;
  26601. if (vst_swap (set->fxMagic) == 'FxBk')
  26602. {
  26603. // bank of programs
  26604. if (vst_swap (set->numPrograms) >= 0)
  26605. {
  26606. const int oldProg = getCurrentProgram();
  26607. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26608. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26609. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26610. {
  26611. if (i != oldProg)
  26612. {
  26613. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26614. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26615. return false;
  26616. if (vst_swap (set->numPrograms) > 0)
  26617. setCurrentProgram (i);
  26618. if (! restoreProgramSettings (prog))
  26619. return false;
  26620. }
  26621. }
  26622. if (vst_swap (set->numPrograms) > 0)
  26623. setCurrentProgram (oldProg);
  26624. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26625. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26626. return false;
  26627. if (! restoreProgramSettings (prog))
  26628. return false;
  26629. }
  26630. }
  26631. else if (vst_swap (set->fxMagic) == 'FxCk')
  26632. {
  26633. // single program
  26634. const fxProgram* const prog = (const fxProgram*) data;
  26635. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26636. return false;
  26637. changeProgramName (getCurrentProgram(), prog->prgName);
  26638. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26639. setParameter (i, vst_swapFloat (prog->params[i]));
  26640. }
  26641. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26642. {
  26643. // non-preset chunk
  26644. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26645. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26646. return false;
  26647. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26648. }
  26649. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26650. {
  26651. // preset chunk
  26652. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26653. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26654. return false;
  26655. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26656. changeProgramName (getCurrentProgram(), cset->name);
  26657. }
  26658. else
  26659. {
  26660. return false;
  26661. }
  26662. return true;
  26663. }
  26664. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26665. {
  26666. const int numParams = getNumParameters();
  26667. prog->chunkMagic = vst_swap ('CcnK');
  26668. prog->byteSize = 0;
  26669. prog->fxMagic = vst_swap ('FxCk');
  26670. prog->version = vst_swap (fxbVersionNum);
  26671. prog->fxID = vst_swap (getUID());
  26672. prog->fxVersion = vst_swap (getVersionNumber());
  26673. prog->numParams = vst_swap (numParams);
  26674. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26675. for (int i = 0; i < numParams; ++i)
  26676. prog->params[i] = vst_swapFloat (getParameter (i));
  26677. }
  26678. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26679. {
  26680. const int numPrograms = getNumPrograms();
  26681. const int numParams = getNumParameters();
  26682. if (usesChunks())
  26683. {
  26684. if (isFXB)
  26685. {
  26686. MemoryBlock chunk;
  26687. getChunkData (chunk, false, maxSizeMB);
  26688. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26689. dest.setSize (totalLen, true);
  26690. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26691. set->chunkMagic = vst_swap ('CcnK');
  26692. set->byteSize = 0;
  26693. set->fxMagic = vst_swap ('FBCh');
  26694. set->version = vst_swap (fxbVersionNum);
  26695. set->fxID = vst_swap (getUID());
  26696. set->fxVersion = vst_swap (getVersionNumber());
  26697. set->numPrograms = vst_swap (numPrograms);
  26698. set->chunkSize = vst_swap ((long) chunk.getSize());
  26699. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26700. }
  26701. else
  26702. {
  26703. MemoryBlock chunk;
  26704. getChunkData (chunk, true, maxSizeMB);
  26705. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26706. dest.setSize (totalLen, true);
  26707. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26708. set->chunkMagic = vst_swap ('CcnK');
  26709. set->byteSize = 0;
  26710. set->fxMagic = vst_swap ('FPCh');
  26711. set->version = vst_swap (fxbVersionNum);
  26712. set->fxID = vst_swap (getUID());
  26713. set->fxVersion = vst_swap (getVersionNumber());
  26714. set->numPrograms = vst_swap (numPrograms);
  26715. set->chunkSize = vst_swap ((long) chunk.getSize());
  26716. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  26717. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26718. }
  26719. }
  26720. else
  26721. {
  26722. if (isFXB)
  26723. {
  26724. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26725. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  26726. dest.setSize (len, true);
  26727. fxSet* const set = (fxSet*) dest.getData();
  26728. set->chunkMagic = vst_swap ('CcnK');
  26729. set->byteSize = 0;
  26730. set->fxMagic = vst_swap ('FxBk');
  26731. set->version = vst_swap (fxbVersionNum);
  26732. set->fxID = vst_swap (getUID());
  26733. set->fxVersion = vst_swap (getVersionNumber());
  26734. set->numPrograms = vst_swap (numPrograms);
  26735. const int oldProgram = getCurrentProgram();
  26736. MemoryBlock oldSettings;
  26737. createTempParameterStore (oldSettings);
  26738. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  26739. for (int i = 0; i < numPrograms; ++i)
  26740. {
  26741. if (i != oldProgram)
  26742. {
  26743. setCurrentProgram (i);
  26744. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  26745. }
  26746. }
  26747. setCurrentProgram (oldProgram);
  26748. restoreFromTempParameterStore (oldSettings);
  26749. }
  26750. else
  26751. {
  26752. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26753. dest.setSize (totalLen, true);
  26754. setParamsInProgramBlock ((fxProgram*) dest.getData());
  26755. }
  26756. }
  26757. return true;
  26758. }
  26759. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  26760. {
  26761. if (usesChunks())
  26762. {
  26763. void* data = 0;
  26764. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  26765. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  26766. {
  26767. mb.setSize (bytes);
  26768. mb.copyFrom (data, 0, bytes);
  26769. }
  26770. }
  26771. }
  26772. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  26773. {
  26774. if (size > 0 && usesChunks())
  26775. {
  26776. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  26777. if (! isPreset)
  26778. updateStoredProgramNames();
  26779. }
  26780. }
  26781. void VSTPluginInstance::timerCallback()
  26782. {
  26783. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  26784. stopTimer();
  26785. }
  26786. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  26787. {
  26788. const ScopedLock sl (lock);
  26789. ++insideVSTCallback;
  26790. int result = 0;
  26791. try
  26792. {
  26793. if (effect != 0)
  26794. {
  26795. #if JUCE_MAC
  26796. if (module->resFileId != 0)
  26797. UseResFile (module->resFileId);
  26798. CGrafPtr oldPort;
  26799. if (getActiveEditor() != 0)
  26800. {
  26801. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  26802. GetPort (&oldPort);
  26803. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  26804. SetOrigin (-pos.getX(), -pos.getY());
  26805. }
  26806. #endif
  26807. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  26808. #if JUCE_MAC
  26809. if (getActiveEditor() != 0)
  26810. SetPort (oldPort);
  26811. module->resFileId = CurResFile();
  26812. #endif
  26813. --insideVSTCallback;
  26814. return result;
  26815. }
  26816. }
  26817. catch (...)
  26818. {
  26819. }
  26820. --insideVSTCallback;
  26821. return result;
  26822. }
  26823. // handles non plugin-specific callbacks..
  26824. static const int defaultVSTSampleRateValue = 16384;
  26825. static const int defaultVSTBlockSizeValue = 512;
  26826. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26827. {
  26828. (void) index;
  26829. (void) value;
  26830. (void) opt;
  26831. switch (opcode)
  26832. {
  26833. case audioMasterCanDo:
  26834. {
  26835. static const char* canDos[] = { "supplyIdle",
  26836. "sendVstEvents",
  26837. "sendVstMidiEvent",
  26838. "sendVstTimeInfo",
  26839. "receiveVstEvents",
  26840. "receiveVstMidiEvent",
  26841. "supportShell",
  26842. "shellCategory" };
  26843. for (int i = 0; i < numElementsInArray (canDos); ++i)
  26844. if (strcmp (canDos[i], (const char*) ptr) == 0)
  26845. return 1;
  26846. return 0;
  26847. }
  26848. case audioMasterVersion:
  26849. return 0x2400;
  26850. case audioMasterCurrentId:
  26851. return shellUIDToCreate;
  26852. case audioMasterGetNumAutomatableParameters:
  26853. return 0;
  26854. case audioMasterGetAutomationState:
  26855. return 1;
  26856. case audioMasterGetVendorVersion:
  26857. return 0x0101;
  26858. case audioMasterGetVendorString:
  26859. case audioMasterGetProductString:
  26860. {
  26861. String hostName ("Juce VST Host");
  26862. if (JUCEApplication::getInstance() != 0)
  26863. hostName = JUCEApplication::getInstance()->getApplicationName();
  26864. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  26865. }
  26866. break;
  26867. case audioMasterGetSampleRate:
  26868. return (VstIntPtr) defaultVSTSampleRateValue;
  26869. case audioMasterGetBlockSize:
  26870. return (VstIntPtr) defaultVSTBlockSizeValue;
  26871. case audioMasterSetOutputSampleRate:
  26872. return 0;
  26873. default:
  26874. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  26875. break;
  26876. }
  26877. return 0;
  26878. }
  26879. // handles callbacks for a specific plugin
  26880. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26881. {
  26882. switch (opcode)
  26883. {
  26884. case audioMasterAutomate:
  26885. sendParamChangeMessageToListeners (index, opt);
  26886. break;
  26887. case audioMasterProcessEvents:
  26888. handleMidiFromPlugin ((const VstEvents*) ptr);
  26889. break;
  26890. case audioMasterGetTime:
  26891. #ifdef _MSC_VER
  26892. #pragma warning (push)
  26893. #pragma warning (disable: 4311)
  26894. #endif
  26895. return (VstIntPtr) &vstHostTime;
  26896. #ifdef _MSC_VER
  26897. #pragma warning (pop)
  26898. #endif
  26899. break;
  26900. case audioMasterIdle:
  26901. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  26902. {
  26903. ++insideVSTCallback;
  26904. #if JUCE_MAC
  26905. if (getActiveEditor() != 0)
  26906. dispatch (effEditIdle, 0, 0, 0, 0);
  26907. #endif
  26908. juce_callAnyTimersSynchronously();
  26909. handleUpdateNowIfNeeded();
  26910. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  26911. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  26912. --insideVSTCallback;
  26913. }
  26914. break;
  26915. case audioMasterUpdateDisplay:
  26916. triggerAsyncUpdate();
  26917. break;
  26918. case audioMasterTempoAt:
  26919. // returns (10000 * bpm)
  26920. break;
  26921. case audioMasterNeedIdle:
  26922. startTimer (50);
  26923. break;
  26924. case audioMasterSizeWindow:
  26925. if (getActiveEditor() != 0)
  26926. getActiveEditor()->setSize (index, value);
  26927. return 1;
  26928. case audioMasterGetSampleRate:
  26929. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  26930. case audioMasterGetBlockSize:
  26931. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  26932. case audioMasterWantMidi:
  26933. wantsMidiMessages = true;
  26934. break;
  26935. case audioMasterGetDirectory:
  26936. #if JUCE_MAC
  26937. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  26938. #else
  26939. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  26940. #endif
  26941. case audioMasterGetAutomationState:
  26942. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  26943. break;
  26944. // none of these are handled (yet)..
  26945. case audioMasterBeginEdit:
  26946. case audioMasterEndEdit:
  26947. case audioMasterSetTime:
  26948. case audioMasterPinConnected:
  26949. case audioMasterGetParameterQuantization:
  26950. case audioMasterIOChanged:
  26951. case audioMasterGetInputLatency:
  26952. case audioMasterGetOutputLatency:
  26953. case audioMasterGetPreviousPlug:
  26954. case audioMasterGetNextPlug:
  26955. case audioMasterWillReplaceOrAccumulate:
  26956. case audioMasterGetCurrentProcessLevel:
  26957. case audioMasterOfflineStart:
  26958. case audioMasterOfflineRead:
  26959. case audioMasterOfflineWrite:
  26960. case audioMasterOfflineGetCurrentPass:
  26961. case audioMasterOfflineGetCurrentMetaPass:
  26962. case audioMasterVendorSpecific:
  26963. case audioMasterSetIcon:
  26964. case audioMasterGetLanguage:
  26965. case audioMasterOpenWindow:
  26966. case audioMasterCloseWindow:
  26967. break;
  26968. default:
  26969. return handleGeneralCallback (opcode, index, value, ptr, opt);
  26970. }
  26971. return 0;
  26972. }
  26973. // entry point for all callbacks from the plugin
  26974. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  26975. {
  26976. try
  26977. {
  26978. if (effect != 0 && effect->resvd2 != 0)
  26979. {
  26980. return ((VSTPluginInstance*)(effect->resvd2))
  26981. ->handleCallback (opcode, index, value, ptr, opt);
  26982. }
  26983. return handleGeneralCallback (opcode, index, value, ptr, opt);
  26984. }
  26985. catch (...)
  26986. {
  26987. return 0;
  26988. }
  26989. }
  26990. const String VSTPluginInstance::getVersion() const throw()
  26991. {
  26992. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  26993. String s;
  26994. if (v == 0 || v == -1)
  26995. v = getVersionNumber();
  26996. if (v != 0)
  26997. {
  26998. int versionBits[4];
  26999. int n = 0;
  27000. while (v != 0)
  27001. {
  27002. versionBits [n++] = (v & 0xff);
  27003. v >>= 8;
  27004. }
  27005. s << 'V';
  27006. while (n > 0)
  27007. {
  27008. s << versionBits [--n];
  27009. if (n > 0)
  27010. s << '.';
  27011. }
  27012. }
  27013. return s;
  27014. }
  27015. int VSTPluginInstance::getUID() const throw()
  27016. {
  27017. int uid = effect != 0 ? effect->uniqueID : 0;
  27018. if (uid == 0)
  27019. uid = module->file.hashCode();
  27020. return uid;
  27021. }
  27022. const String VSTPluginInstance::getCategory() const throw()
  27023. {
  27024. const char* result = 0;
  27025. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27026. {
  27027. case kPlugCategEffect:
  27028. result = "Effect";
  27029. break;
  27030. case kPlugCategSynth:
  27031. result = "Synth";
  27032. break;
  27033. case kPlugCategAnalysis:
  27034. result = "Anaylsis";
  27035. break;
  27036. case kPlugCategMastering:
  27037. result = "Mastering";
  27038. break;
  27039. case kPlugCategSpacializer:
  27040. result = "Spacial";
  27041. break;
  27042. case kPlugCategRoomFx:
  27043. result = "Reverb";
  27044. break;
  27045. case kPlugSurroundFx:
  27046. result = "Surround";
  27047. break;
  27048. case kPlugCategRestoration:
  27049. result = "Restoration";
  27050. break;
  27051. case kPlugCategGenerator:
  27052. result = "Tone generation";
  27053. break;
  27054. default:
  27055. break;
  27056. }
  27057. return result;
  27058. }
  27059. float VSTPluginInstance::getParameter (int index)
  27060. {
  27061. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27062. {
  27063. try
  27064. {
  27065. const ScopedLock sl (lock);
  27066. return effect->getParameter (effect, index);
  27067. }
  27068. catch (...)
  27069. {
  27070. }
  27071. }
  27072. return 0.0f;
  27073. }
  27074. void VSTPluginInstance::setParameter (int index, float newValue)
  27075. {
  27076. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27077. {
  27078. try
  27079. {
  27080. const ScopedLock sl (lock);
  27081. if (effect->getParameter (effect, index) != newValue)
  27082. effect->setParameter (effect, index, newValue);
  27083. }
  27084. catch (...)
  27085. {
  27086. }
  27087. }
  27088. }
  27089. const String VSTPluginInstance::getParameterName (int index)
  27090. {
  27091. if (effect != 0)
  27092. {
  27093. jassert (index >= 0 && index < effect->numParams);
  27094. char nm [256];
  27095. zerostruct (nm);
  27096. dispatch (effGetParamName, index, 0, nm, 0);
  27097. return String (nm).trim();
  27098. }
  27099. return String::empty;
  27100. }
  27101. const String VSTPluginInstance::getParameterLabel (int index) const
  27102. {
  27103. if (effect != 0)
  27104. {
  27105. jassert (index >= 0 && index < effect->numParams);
  27106. char nm [256];
  27107. zerostruct (nm);
  27108. dispatch (effGetParamLabel, index, 0, nm, 0);
  27109. return String (nm).trim();
  27110. }
  27111. return String::empty;
  27112. }
  27113. const String VSTPluginInstance::getParameterText (int index)
  27114. {
  27115. if (effect != 0)
  27116. {
  27117. jassert (index >= 0 && index < effect->numParams);
  27118. char nm [256];
  27119. zerostruct (nm);
  27120. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27121. return String (nm).trim();
  27122. }
  27123. return String::empty;
  27124. }
  27125. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27126. {
  27127. if (effect != 0)
  27128. {
  27129. jassert (index >= 0 && index < effect->numParams);
  27130. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27131. }
  27132. return false;
  27133. }
  27134. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27135. {
  27136. dest.setSize (64 + 4 * getNumParameters());
  27137. dest.fillWith (0);
  27138. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27139. float* const p = (float*) (((char*) dest.getData()) + 64);
  27140. for (int i = 0; i < getNumParameters(); ++i)
  27141. p[i] = getParameter(i);
  27142. }
  27143. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27144. {
  27145. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27146. float* p = (float*) (((char*) m.getData()) + 64);
  27147. for (int i = 0; i < getNumParameters(); ++i)
  27148. setParameter (i, p[i]);
  27149. }
  27150. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27151. {
  27152. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27153. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27154. }
  27155. const String VSTPluginInstance::getProgramName (int index)
  27156. {
  27157. if (index == getCurrentProgram())
  27158. {
  27159. return getCurrentProgramName();
  27160. }
  27161. else if (effect != 0)
  27162. {
  27163. char nm [256];
  27164. zerostruct (nm);
  27165. if (dispatch (effGetProgramNameIndexed,
  27166. jlimit (0, getNumPrograms(), index),
  27167. -1, nm, 0) != 0)
  27168. {
  27169. return String (nm).trim();
  27170. }
  27171. }
  27172. return programNames [index];
  27173. }
  27174. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27175. {
  27176. if (index == getCurrentProgram())
  27177. {
  27178. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27179. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27180. }
  27181. else
  27182. {
  27183. jassertfalse // xxx not implemented!
  27184. }
  27185. }
  27186. void VSTPluginInstance::updateStoredProgramNames()
  27187. {
  27188. if (effect != 0 && getNumPrograms() > 0)
  27189. {
  27190. char nm [256];
  27191. zerostruct (nm);
  27192. // only do this if the plugin can't use indexed names..
  27193. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27194. {
  27195. const int oldProgram = getCurrentProgram();
  27196. MemoryBlock oldSettings;
  27197. createTempParameterStore (oldSettings);
  27198. for (int i = 0; i < getNumPrograms(); ++i)
  27199. {
  27200. setCurrentProgram (i);
  27201. getCurrentProgramName(); // (this updates the list)
  27202. }
  27203. setCurrentProgram (oldProgram);
  27204. restoreFromTempParameterStore (oldSettings);
  27205. }
  27206. }
  27207. }
  27208. const String VSTPluginInstance::getCurrentProgramName()
  27209. {
  27210. if (effect != 0)
  27211. {
  27212. char nm [256];
  27213. zerostruct (nm);
  27214. dispatch (effGetProgramName, 0, 0, nm, 0);
  27215. const int index = getCurrentProgram();
  27216. if (programNames[index].isEmpty())
  27217. {
  27218. while (programNames.size() < index)
  27219. programNames.add (String::empty);
  27220. programNames.set (index, String (nm).trim());
  27221. }
  27222. return String (nm).trim();
  27223. }
  27224. return String::empty;
  27225. }
  27226. const String VSTPluginInstance::getInputChannelName (const int index) const
  27227. {
  27228. if (index >= 0 && index < getNumInputChannels())
  27229. {
  27230. VstPinProperties pinProps;
  27231. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27232. return String (pinProps.label, sizeof (pinProps.label));
  27233. }
  27234. return String::empty;
  27235. }
  27236. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27237. {
  27238. if (index < 0 || index >= getNumInputChannels())
  27239. return false;
  27240. VstPinProperties pinProps;
  27241. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27242. return (pinProps.flags & kVstPinIsStereo) != 0;
  27243. return true;
  27244. }
  27245. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27246. {
  27247. if (index >= 0 && index < getNumOutputChannels())
  27248. {
  27249. VstPinProperties pinProps;
  27250. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27251. return String (pinProps.label, sizeof (pinProps.label));
  27252. }
  27253. return String::empty;
  27254. }
  27255. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27256. {
  27257. if (index < 0 || index >= getNumOutputChannels())
  27258. return false;
  27259. VstPinProperties pinProps;
  27260. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27261. return (pinProps.flags & kVstPinIsStereo) != 0;
  27262. return true;
  27263. }
  27264. void VSTPluginInstance::setPower (const bool on)
  27265. {
  27266. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27267. isPowerOn = on;
  27268. }
  27269. const int defaultMaxSizeMB = 64;
  27270. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27271. {
  27272. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27273. }
  27274. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27275. {
  27276. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27277. }
  27278. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27279. {
  27280. loadFromFXBFile (data, sizeInBytes);
  27281. }
  27282. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27283. {
  27284. loadFromFXBFile (data, sizeInBytes);
  27285. }
  27286. VSTPluginFormat::VSTPluginFormat()
  27287. {
  27288. }
  27289. VSTPluginFormat::~VSTPluginFormat()
  27290. {
  27291. }
  27292. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27293. const String& fileOrIdentifier)
  27294. {
  27295. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27296. return;
  27297. PluginDescription desc;
  27298. desc.fileOrIdentifier = fileOrIdentifier;
  27299. desc.uid = 0;
  27300. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27301. if (instance == 0)
  27302. return;
  27303. try
  27304. {
  27305. #if JUCE_MAC
  27306. if (instance->module->resFileId != 0)
  27307. UseResFile (instance->module->resFileId);
  27308. #endif
  27309. instance->fillInPluginDescription (desc);
  27310. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27311. if (category != kPlugCategShell)
  27312. {
  27313. // Normal plugin...
  27314. results.add (new PluginDescription (desc));
  27315. ++insideVSTCallback;
  27316. instance->dispatch (effOpen, 0, 0, 0, 0);
  27317. --insideVSTCallback;
  27318. }
  27319. else
  27320. {
  27321. // It's a shell plugin, so iterate all the subtypes...
  27322. char shellEffectName [64];
  27323. for (;;)
  27324. {
  27325. zerostruct (shellEffectName);
  27326. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27327. if (uid == 0)
  27328. {
  27329. break;
  27330. }
  27331. else
  27332. {
  27333. desc.uid = uid;
  27334. desc.name = shellEffectName;
  27335. bool alreadyThere = false;
  27336. for (int i = results.size(); --i >= 0;)
  27337. {
  27338. PluginDescription* const d = results.getUnchecked(i);
  27339. if (d->isDuplicateOf (desc))
  27340. {
  27341. alreadyThere = true;
  27342. break;
  27343. }
  27344. }
  27345. if (! alreadyThere)
  27346. results.add (new PluginDescription (desc));
  27347. }
  27348. }
  27349. }
  27350. }
  27351. catch (...)
  27352. {
  27353. // crashed while loading...
  27354. }
  27355. }
  27356. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27357. {
  27358. ScopedPointer <VSTPluginInstance> result;
  27359. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27360. {
  27361. File file (desc.fileOrIdentifier);
  27362. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27363. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27364. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27365. if (module != 0)
  27366. {
  27367. shellUIDToCreate = desc.uid;
  27368. result = new VSTPluginInstance (module);
  27369. if (result->effect != 0)
  27370. {
  27371. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27372. result->initialise();
  27373. }
  27374. else
  27375. {
  27376. result = 0;
  27377. }
  27378. }
  27379. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27380. }
  27381. return result.release();
  27382. }
  27383. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27384. {
  27385. const File f (fileOrIdentifier);
  27386. #if JUCE_MAC
  27387. if (f.isDirectory() && f.hasFileExtension (".vst"))
  27388. return true;
  27389. #if JUCE_PPC
  27390. FSRef fileRef;
  27391. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27392. {
  27393. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27394. if (resFileId != -1)
  27395. {
  27396. const int numEffects = Count1Resources ('aEff');
  27397. CloseResFile (resFileId);
  27398. if (numEffects > 0)
  27399. return true;
  27400. }
  27401. }
  27402. #endif
  27403. return false;
  27404. #elif JUCE_WIN32
  27405. return f.existsAsFile()
  27406. && f.hasFileExtension (".dll");
  27407. #elif JUCE_LINUX
  27408. return f.existsAsFile()
  27409. && f.hasFileExtension (".so");
  27410. #endif
  27411. }
  27412. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27413. {
  27414. return fileOrIdentifier;
  27415. }
  27416. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27417. {
  27418. return File (desc.fileOrIdentifier).exists();
  27419. }
  27420. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27421. {
  27422. StringArray results;
  27423. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27424. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27425. return results;
  27426. }
  27427. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27428. {
  27429. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27430. // .component or .vst directories.
  27431. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27432. while (iter.next())
  27433. {
  27434. const File f (iter.getFile());
  27435. bool isPlugin = false;
  27436. if (fileMightContainThisPluginType (f.getFullPathName()))
  27437. {
  27438. isPlugin = true;
  27439. results.add (f.getFullPathName());
  27440. }
  27441. if (recursive && (! isPlugin) && f.isDirectory())
  27442. recursiveFileSearch (results, f, true);
  27443. }
  27444. }
  27445. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27446. {
  27447. #if JUCE_MAC
  27448. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27449. #elif JUCE_WIN32
  27450. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27451. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27452. #elif JUCE_LINUX
  27453. return FileSearchPath ("/usr/lib/vst");
  27454. #endif
  27455. }
  27456. END_JUCE_NAMESPACE
  27457. #endif
  27458. #undef log
  27459. #endif
  27460. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27461. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27462. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27463. BEGIN_JUCE_NAMESPACE
  27464. AudioProcessor::AudioProcessor()
  27465. : playHead (0),
  27466. activeEditor (0),
  27467. sampleRate (0),
  27468. blockSize (0),
  27469. numInputChannels (0),
  27470. numOutputChannels (0),
  27471. latencySamples (0),
  27472. suspended (false),
  27473. nonRealtime (false)
  27474. {
  27475. }
  27476. AudioProcessor::~AudioProcessor()
  27477. {
  27478. // ooh, nasty - the editor should have been deleted before the filter
  27479. // that it refers to is deleted..
  27480. jassert (activeEditor == 0);
  27481. #ifdef JUCE_DEBUG
  27482. // This will fail if you've called beginParameterChangeGesture() for one
  27483. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27484. jassert (changingParams.countNumberOfSetBits() == 0);
  27485. #endif
  27486. }
  27487. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27488. {
  27489. playHead = newPlayHead;
  27490. }
  27491. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27492. {
  27493. const ScopedLock sl (listenerLock);
  27494. listeners.addIfNotAlreadyThere (newListener);
  27495. }
  27496. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27497. {
  27498. const ScopedLock sl (listenerLock);
  27499. listeners.removeValue (listenerToRemove);
  27500. }
  27501. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27502. const int numOuts,
  27503. const double sampleRate_,
  27504. const int blockSize_) throw()
  27505. {
  27506. numInputChannels = numIns;
  27507. numOutputChannels = numOuts;
  27508. sampleRate = sampleRate_;
  27509. blockSize = blockSize_;
  27510. }
  27511. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27512. {
  27513. nonRealtime = nonRealtime_;
  27514. }
  27515. void AudioProcessor::setLatencySamples (const int newLatency)
  27516. {
  27517. if (latencySamples != newLatency)
  27518. {
  27519. latencySamples = newLatency;
  27520. updateHostDisplay();
  27521. }
  27522. }
  27523. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27524. const float newValue)
  27525. {
  27526. setParameter (parameterIndex, newValue);
  27527. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27528. }
  27529. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27530. {
  27531. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27532. for (int i = listeners.size(); --i >= 0;)
  27533. {
  27534. AudioProcessorListener* l;
  27535. {
  27536. const ScopedLock sl (listenerLock);
  27537. l = (AudioProcessorListener*) listeners [i];
  27538. }
  27539. if (l != 0)
  27540. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27541. }
  27542. }
  27543. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27544. {
  27545. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27546. #ifdef JUCE_DEBUG
  27547. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27548. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27549. jassert (! changingParams [parameterIndex]);
  27550. changingParams.setBit (parameterIndex);
  27551. #endif
  27552. for (int i = listeners.size(); --i >= 0;)
  27553. {
  27554. AudioProcessorListener* l;
  27555. {
  27556. const ScopedLock sl (listenerLock);
  27557. l = (AudioProcessorListener*) listeners [i];
  27558. }
  27559. if (l != 0)
  27560. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27561. }
  27562. }
  27563. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27564. {
  27565. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27566. #ifdef JUCE_DEBUG
  27567. // This means you've called endParameterChangeGesture without having previously called
  27568. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27569. // calls matched correctly.
  27570. jassert (changingParams [parameterIndex]);
  27571. changingParams.clearBit (parameterIndex);
  27572. #endif
  27573. for (int i = listeners.size(); --i >= 0;)
  27574. {
  27575. AudioProcessorListener* l;
  27576. {
  27577. const ScopedLock sl (listenerLock);
  27578. l = (AudioProcessorListener*) listeners [i];
  27579. }
  27580. if (l != 0)
  27581. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27582. }
  27583. }
  27584. void AudioProcessor::updateHostDisplay()
  27585. {
  27586. for (int i = listeners.size(); --i >= 0;)
  27587. {
  27588. AudioProcessorListener* l;
  27589. {
  27590. const ScopedLock sl (listenerLock);
  27591. l = (AudioProcessorListener*) listeners [i];
  27592. }
  27593. if (l != 0)
  27594. l->audioProcessorChanged (this);
  27595. }
  27596. }
  27597. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27598. {
  27599. return true;
  27600. }
  27601. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27602. {
  27603. return false;
  27604. }
  27605. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27606. {
  27607. const ScopedLock sl (callbackLock);
  27608. suspended = shouldBeSuspended;
  27609. }
  27610. void AudioProcessor::reset()
  27611. {
  27612. }
  27613. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27614. {
  27615. const ScopedLock sl (callbackLock);
  27616. jassert (activeEditor == editor);
  27617. if (activeEditor == editor)
  27618. activeEditor = 0;
  27619. }
  27620. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27621. {
  27622. if (activeEditor != 0)
  27623. return activeEditor;
  27624. AudioProcessorEditor* const ed = createEditor();
  27625. if (ed != 0)
  27626. {
  27627. // you must give your editor comp a size before returning it..
  27628. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27629. const ScopedLock sl (callbackLock);
  27630. activeEditor = ed;
  27631. }
  27632. return ed;
  27633. }
  27634. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27635. {
  27636. getStateInformation (destData);
  27637. }
  27638. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27639. {
  27640. setStateInformation (data, sizeInBytes);
  27641. }
  27642. // magic number to identify memory blocks that we've stored as XML
  27643. const uint32 magicXmlNumber = 0x21324356;
  27644. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27645. JUCE_NAMESPACE::MemoryBlock& destData)
  27646. {
  27647. const String xmlString (xml.createDocument (String::empty, true, false));
  27648. const int stringLength = xmlString.getNumBytesAsUTF8();
  27649. destData.setSize (stringLength + 10);
  27650. char* const d = (char*) destData.getData();
  27651. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27652. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27653. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27654. }
  27655. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27656. const int sizeInBytes)
  27657. {
  27658. if (sizeInBytes > 8
  27659. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27660. {
  27661. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27662. if (stringLength > 0)
  27663. {
  27664. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27665. jmin ((sizeInBytes - 8), stringLength)));
  27666. return doc.getDocumentElement();
  27667. }
  27668. }
  27669. return 0;
  27670. }
  27671. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27672. {
  27673. }
  27674. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27675. {
  27676. }
  27677. bool AudioPlayHead::CurrentPositionInfo::operator== (const CurrentPositionInfo& other) const throw()
  27678. {
  27679. return timeInSeconds == other.timeInSeconds
  27680. && ppqPosition == other.ppqPosition
  27681. && editOriginTime == other.editOriginTime
  27682. && ppqPositionOfLastBarStart == other.ppqPositionOfLastBarStart
  27683. && frameRate == other.frameRate
  27684. && isPlaying == other.isPlaying
  27685. && isRecording == other.isRecording
  27686. && bpm == other.bpm
  27687. && timeSigNumerator == other.timeSigNumerator
  27688. && timeSigDenominator == other.timeSigDenominator;
  27689. }
  27690. bool AudioPlayHead::CurrentPositionInfo::operator!= (const CurrentPositionInfo& other) const throw()
  27691. {
  27692. return ! operator== (other);
  27693. }
  27694. void AudioPlayHead::CurrentPositionInfo::resetToDefault()
  27695. {
  27696. zerostruct (*this);
  27697. timeSigNumerator = 4;
  27698. timeSigDenominator = 4;
  27699. bpm = 120;
  27700. }
  27701. END_JUCE_NAMESPACE
  27702. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27703. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27704. BEGIN_JUCE_NAMESPACE
  27705. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27706. : owner (owner_)
  27707. {
  27708. // the filter must be valid..
  27709. jassert (owner != 0);
  27710. }
  27711. AudioProcessorEditor::~AudioProcessorEditor()
  27712. {
  27713. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27714. // filter for some reason..
  27715. jassert (owner->getActiveEditor() != this);
  27716. }
  27717. END_JUCE_NAMESPACE
  27718. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27719. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27720. BEGIN_JUCE_NAMESPACE
  27721. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27722. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27723. : id (id_),
  27724. processor (processor_),
  27725. isPrepared (false)
  27726. {
  27727. jassert (processor_ != 0);
  27728. }
  27729. AudioProcessorGraph::Node::~Node()
  27730. {
  27731. delete processor;
  27732. }
  27733. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27734. AudioProcessorGraph* const graph)
  27735. {
  27736. if (! isPrepared)
  27737. {
  27738. isPrepared = true;
  27739. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27740. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  27741. if (ioProc != 0)
  27742. ioProc->setParentGraph (graph);
  27743. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  27744. processor->getNumOutputChannels(),
  27745. sampleRate, blockSize);
  27746. processor->prepareToPlay (sampleRate, blockSize);
  27747. }
  27748. }
  27749. void AudioProcessorGraph::Node::unprepare()
  27750. {
  27751. if (isPrepared)
  27752. {
  27753. isPrepared = false;
  27754. processor->releaseResources();
  27755. }
  27756. }
  27757. AudioProcessorGraph::AudioProcessorGraph()
  27758. : lastNodeId (0),
  27759. renderingBuffers (1, 1),
  27760. currentAudioOutputBuffer (1, 1)
  27761. {
  27762. }
  27763. AudioProcessorGraph::~AudioProcessorGraph()
  27764. {
  27765. clearRenderingSequence();
  27766. clear();
  27767. }
  27768. const String AudioProcessorGraph::getName() const
  27769. {
  27770. return "Audio Graph";
  27771. }
  27772. void AudioProcessorGraph::clear()
  27773. {
  27774. nodes.clear();
  27775. connections.clear();
  27776. triggerAsyncUpdate();
  27777. }
  27778. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  27779. {
  27780. for (int i = nodes.size(); --i >= 0;)
  27781. if (nodes.getUnchecked(i)->id == nodeId)
  27782. return nodes.getUnchecked(i);
  27783. return 0;
  27784. }
  27785. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  27786. uint32 nodeId)
  27787. {
  27788. if (newProcessor == 0)
  27789. {
  27790. jassertfalse
  27791. return 0;
  27792. }
  27793. if (nodeId == 0)
  27794. {
  27795. nodeId = ++lastNodeId;
  27796. }
  27797. else
  27798. {
  27799. // you can't add a node with an id that already exists in the graph..
  27800. jassert (getNodeForId (nodeId) == 0);
  27801. removeNode (nodeId);
  27802. }
  27803. lastNodeId = nodeId;
  27804. Node* const n = new Node (nodeId, newProcessor);
  27805. nodes.add (n);
  27806. triggerAsyncUpdate();
  27807. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27808. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  27809. if (ioProc != 0)
  27810. ioProc->setParentGraph (this);
  27811. return n;
  27812. }
  27813. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  27814. {
  27815. disconnectNode (nodeId);
  27816. for (int i = nodes.size(); --i >= 0;)
  27817. {
  27818. if (nodes.getUnchecked(i)->id == nodeId)
  27819. {
  27820. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27821. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  27822. if (ioProc != 0)
  27823. ioProc->setParentGraph (0);
  27824. nodes.remove (i);
  27825. triggerAsyncUpdate();
  27826. return true;
  27827. }
  27828. }
  27829. return false;
  27830. }
  27831. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  27832. const int sourceChannelIndex,
  27833. const uint32 destNodeId,
  27834. const int destChannelIndex) const
  27835. {
  27836. for (int i = connections.size(); --i >= 0;)
  27837. {
  27838. const Connection* const c = connections.getUnchecked(i);
  27839. if (c->sourceNodeId == sourceNodeId
  27840. && c->destNodeId == destNodeId
  27841. && c->sourceChannelIndex == sourceChannelIndex
  27842. && c->destChannelIndex == destChannelIndex)
  27843. {
  27844. return c;
  27845. }
  27846. }
  27847. return 0;
  27848. }
  27849. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  27850. const uint32 possibleDestNodeId) const
  27851. {
  27852. for (int i = connections.size(); --i >= 0;)
  27853. {
  27854. const Connection* const c = connections.getUnchecked(i);
  27855. if (c->sourceNodeId == possibleSourceNodeId
  27856. && c->destNodeId == possibleDestNodeId)
  27857. {
  27858. return true;
  27859. }
  27860. }
  27861. return false;
  27862. }
  27863. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  27864. const int sourceChannelIndex,
  27865. const uint32 destNodeId,
  27866. const int destChannelIndex) const
  27867. {
  27868. if (sourceChannelIndex < 0
  27869. || destChannelIndex < 0
  27870. || sourceNodeId == destNodeId
  27871. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  27872. return false;
  27873. const Node* const source = getNodeForId (sourceNodeId);
  27874. if (source == 0
  27875. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  27876. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  27877. return false;
  27878. const Node* const dest = getNodeForId (destNodeId);
  27879. if (dest == 0
  27880. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  27881. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  27882. return false;
  27883. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  27884. destNodeId, destChannelIndex) == 0;
  27885. }
  27886. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  27887. const int sourceChannelIndex,
  27888. const uint32 destNodeId,
  27889. const int destChannelIndex)
  27890. {
  27891. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  27892. return false;
  27893. Connection* const c = new Connection();
  27894. c->sourceNodeId = sourceNodeId;
  27895. c->sourceChannelIndex = sourceChannelIndex;
  27896. c->destNodeId = destNodeId;
  27897. c->destChannelIndex = destChannelIndex;
  27898. connections.add (c);
  27899. triggerAsyncUpdate();
  27900. return true;
  27901. }
  27902. void AudioProcessorGraph::removeConnection (const int index)
  27903. {
  27904. connections.remove (index);
  27905. triggerAsyncUpdate();
  27906. }
  27907. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  27908. const uint32 destNodeId, const int destChannelIndex)
  27909. {
  27910. bool doneAnything = false;
  27911. for (int i = connections.size(); --i >= 0;)
  27912. {
  27913. const Connection* const c = connections.getUnchecked(i);
  27914. if (c->sourceNodeId == sourceNodeId
  27915. && c->destNodeId == destNodeId
  27916. && c->sourceChannelIndex == sourceChannelIndex
  27917. && c->destChannelIndex == destChannelIndex)
  27918. {
  27919. removeConnection (i);
  27920. doneAnything = true;
  27921. triggerAsyncUpdate();
  27922. }
  27923. }
  27924. return doneAnything;
  27925. }
  27926. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  27927. {
  27928. bool doneAnything = false;
  27929. for (int i = connections.size(); --i >= 0;)
  27930. {
  27931. const Connection* const c = connections.getUnchecked(i);
  27932. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  27933. {
  27934. removeConnection (i);
  27935. doneAnything = true;
  27936. triggerAsyncUpdate();
  27937. }
  27938. }
  27939. return doneAnything;
  27940. }
  27941. bool AudioProcessorGraph::removeIllegalConnections()
  27942. {
  27943. bool doneAnything = false;
  27944. for (int i = connections.size(); --i >= 0;)
  27945. {
  27946. const Connection* const c = connections.getUnchecked(i);
  27947. const Node* const source = getNodeForId (c->sourceNodeId);
  27948. const Node* const dest = getNodeForId (c->destNodeId);
  27949. if (source == 0 || dest == 0
  27950. || (c->sourceChannelIndex != midiChannelIndex
  27951. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  27952. || (c->sourceChannelIndex == midiChannelIndex
  27953. && ! source->processor->producesMidi())
  27954. || (c->destChannelIndex != midiChannelIndex
  27955. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  27956. || (c->destChannelIndex == midiChannelIndex
  27957. && ! dest->processor->acceptsMidi()))
  27958. {
  27959. removeConnection (i);
  27960. doneAnything = true;
  27961. triggerAsyncUpdate();
  27962. }
  27963. }
  27964. return doneAnything;
  27965. }
  27966. namespace GraphRenderingOps
  27967. {
  27968. class AudioGraphRenderingOp
  27969. {
  27970. public:
  27971. AudioGraphRenderingOp() {}
  27972. virtual ~AudioGraphRenderingOp() {}
  27973. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  27974. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  27975. const int numSamples) = 0;
  27976. juce_UseDebuggingNewOperator
  27977. };
  27978. class ClearChannelOp : public AudioGraphRenderingOp
  27979. {
  27980. public:
  27981. ClearChannelOp (const int channelNum_)
  27982. : channelNum (channelNum_)
  27983. {}
  27984. ~ClearChannelOp() {}
  27985. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  27986. {
  27987. sharedBufferChans.clear (channelNum, 0, numSamples);
  27988. }
  27989. private:
  27990. const int channelNum;
  27991. ClearChannelOp (const ClearChannelOp&);
  27992. ClearChannelOp& operator= (const ClearChannelOp&);
  27993. };
  27994. class CopyChannelOp : public AudioGraphRenderingOp
  27995. {
  27996. public:
  27997. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  27998. : srcChannelNum (srcChannelNum_),
  27999. dstChannelNum (dstChannelNum_)
  28000. {}
  28001. ~CopyChannelOp() {}
  28002. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28003. {
  28004. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28005. }
  28006. private:
  28007. const int srcChannelNum, dstChannelNum;
  28008. CopyChannelOp (const CopyChannelOp&);
  28009. CopyChannelOp& operator= (const CopyChannelOp&);
  28010. };
  28011. class AddChannelOp : public AudioGraphRenderingOp
  28012. {
  28013. public:
  28014. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28015. : srcChannelNum (srcChannelNum_),
  28016. dstChannelNum (dstChannelNum_)
  28017. {}
  28018. ~AddChannelOp() {}
  28019. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28020. {
  28021. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28022. }
  28023. private:
  28024. const int srcChannelNum, dstChannelNum;
  28025. AddChannelOp (const AddChannelOp&);
  28026. AddChannelOp& operator= (const AddChannelOp&);
  28027. };
  28028. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28029. {
  28030. public:
  28031. ClearMidiBufferOp (const int bufferNum_)
  28032. : bufferNum (bufferNum_)
  28033. {}
  28034. ~ClearMidiBufferOp() {}
  28035. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28036. {
  28037. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28038. }
  28039. private:
  28040. const int bufferNum;
  28041. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28042. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28043. };
  28044. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28045. {
  28046. public:
  28047. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28048. : srcBufferNum (srcBufferNum_),
  28049. dstBufferNum (dstBufferNum_)
  28050. {}
  28051. ~CopyMidiBufferOp() {}
  28052. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28053. {
  28054. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28055. }
  28056. private:
  28057. const int srcBufferNum, dstBufferNum;
  28058. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28059. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28060. };
  28061. class AddMidiBufferOp : public AudioGraphRenderingOp
  28062. {
  28063. public:
  28064. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28065. : srcBufferNum (srcBufferNum_),
  28066. dstBufferNum (dstBufferNum_)
  28067. {}
  28068. ~AddMidiBufferOp() {}
  28069. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28070. {
  28071. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28072. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28073. }
  28074. private:
  28075. const int srcBufferNum, dstBufferNum;
  28076. AddMidiBufferOp (const AddMidiBufferOp&);
  28077. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28078. };
  28079. class ProcessBufferOp : public AudioGraphRenderingOp
  28080. {
  28081. public:
  28082. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28083. const Array <int>& audioChannelsToUse_,
  28084. const int totalChans_,
  28085. const int midiBufferToUse_)
  28086. : node (node_),
  28087. processor (node_->processor),
  28088. audioChannelsToUse (audioChannelsToUse_),
  28089. totalChans (jmax (1, totalChans_)),
  28090. midiBufferToUse (midiBufferToUse_)
  28091. {
  28092. channels.calloc (totalChans);
  28093. while (audioChannelsToUse.size() < totalChans)
  28094. audioChannelsToUse.add (0);
  28095. }
  28096. ~ProcessBufferOp()
  28097. {
  28098. }
  28099. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28100. {
  28101. for (int i = totalChans; --i >= 0;)
  28102. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28103. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28104. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28105. }
  28106. const AudioProcessorGraph::Node::Ptr node;
  28107. AudioProcessor* const processor;
  28108. private:
  28109. Array <int> audioChannelsToUse;
  28110. HeapBlock <float*> channels;
  28111. int totalChans;
  28112. int midiBufferToUse;
  28113. ProcessBufferOp (const ProcessBufferOp&);
  28114. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28115. };
  28116. class RenderingOpSequenceCalculator
  28117. {
  28118. public:
  28119. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28120. const VoidArray& orderedNodes_,
  28121. VoidArray& renderingOps)
  28122. : graph (graph_),
  28123. orderedNodes (orderedNodes_)
  28124. {
  28125. nodeIds.add (-2); // first buffer is read-only zeros
  28126. channels.add (0);
  28127. midiNodeIds.add (-2);
  28128. for (int i = 0; i < orderedNodes.size(); ++i)
  28129. {
  28130. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28131. renderingOps, i);
  28132. markAnyUnusedBuffersAsFree (i);
  28133. }
  28134. }
  28135. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28136. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28137. juce_UseDebuggingNewOperator
  28138. private:
  28139. AudioProcessorGraph& graph;
  28140. const VoidArray& orderedNodes;
  28141. Array <int> nodeIds, channels, midiNodeIds;
  28142. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28143. VoidArray& renderingOps,
  28144. const int ourRenderingIndex)
  28145. {
  28146. const int numIns = node->processor->getNumInputChannels();
  28147. const int numOuts = node->processor->getNumOutputChannels();
  28148. const int totalChans = jmax (numIns, numOuts);
  28149. Array <int> audioChannelsToUse;
  28150. int midiBufferToUse = -1;
  28151. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28152. {
  28153. // get a list of all the inputs to this node
  28154. Array <int> sourceNodes, sourceOutputChans;
  28155. for (int i = graph.getNumConnections(); --i >= 0;)
  28156. {
  28157. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28158. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28159. {
  28160. sourceNodes.add (c->sourceNodeId);
  28161. sourceOutputChans.add (c->sourceChannelIndex);
  28162. }
  28163. }
  28164. int bufIndex = -1;
  28165. if (sourceNodes.size() == 0)
  28166. {
  28167. // unconnected input channel
  28168. if (inputChan >= numOuts)
  28169. {
  28170. bufIndex = getReadOnlyEmptyBuffer();
  28171. jassert (bufIndex >= 0);
  28172. }
  28173. else
  28174. {
  28175. bufIndex = getFreeBuffer (false);
  28176. renderingOps.add (new ClearChannelOp (bufIndex));
  28177. }
  28178. }
  28179. else if (sourceNodes.size() == 1)
  28180. {
  28181. // channel with a straightforward single input..
  28182. const int srcNode = sourceNodes.getUnchecked(0);
  28183. const int srcChan = sourceOutputChans.getUnchecked(0);
  28184. bufIndex = getBufferContaining (srcNode, srcChan);
  28185. if (bufIndex < 0)
  28186. {
  28187. // if not found, this is probably a feedback loop
  28188. bufIndex = getReadOnlyEmptyBuffer();
  28189. jassert (bufIndex >= 0);
  28190. }
  28191. if (inputChan < numOuts
  28192. && isBufferNeededLater (ourRenderingIndex,
  28193. inputChan,
  28194. srcNode, srcChan))
  28195. {
  28196. // can't mess up this channel because it's needed later by another node, so we
  28197. // need to use a copy of it..
  28198. const int newFreeBuffer = getFreeBuffer (false);
  28199. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28200. bufIndex = newFreeBuffer;
  28201. }
  28202. }
  28203. else
  28204. {
  28205. // channel with a mix of several inputs..
  28206. // try to find a re-usable channel from our inputs..
  28207. int reusableInputIndex = -1;
  28208. for (int i = 0; i < sourceNodes.size(); ++i)
  28209. {
  28210. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28211. sourceOutputChans.getUnchecked(i));
  28212. if (sourceBufIndex >= 0
  28213. && ! isBufferNeededLater (ourRenderingIndex,
  28214. inputChan,
  28215. sourceNodes.getUnchecked(i),
  28216. sourceOutputChans.getUnchecked(i)))
  28217. {
  28218. // we've found one of our input chans that can be re-used..
  28219. reusableInputIndex = i;
  28220. bufIndex = sourceBufIndex;
  28221. break;
  28222. }
  28223. }
  28224. if (reusableInputIndex < 0)
  28225. {
  28226. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28227. bufIndex = getFreeBuffer (false);
  28228. jassert (bufIndex != 0);
  28229. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28230. sourceOutputChans.getUnchecked (0));
  28231. if (srcIndex < 0)
  28232. {
  28233. // if not found, this is probably a feedback loop
  28234. renderingOps.add (new ClearChannelOp (bufIndex));
  28235. }
  28236. else
  28237. {
  28238. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28239. }
  28240. reusableInputIndex = 0;
  28241. }
  28242. for (int j = 0; j < sourceNodes.size(); ++j)
  28243. {
  28244. if (j != reusableInputIndex)
  28245. {
  28246. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28247. sourceOutputChans.getUnchecked(j));
  28248. if (srcIndex >= 0)
  28249. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28250. }
  28251. }
  28252. }
  28253. jassert (bufIndex >= 0);
  28254. audioChannelsToUse.add (bufIndex);
  28255. if (inputChan < numOuts)
  28256. markBufferAsContaining (bufIndex, node->id, inputChan);
  28257. }
  28258. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28259. {
  28260. const int bufIndex = getFreeBuffer (false);
  28261. jassert (bufIndex != 0);
  28262. audioChannelsToUse.add (bufIndex);
  28263. markBufferAsContaining (bufIndex, node->id, outputChan);
  28264. }
  28265. // Now the same thing for midi..
  28266. Array <int> midiSourceNodes;
  28267. for (int i = graph.getNumConnections(); --i >= 0;)
  28268. {
  28269. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28270. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28271. midiSourceNodes.add (c->sourceNodeId);
  28272. }
  28273. if (midiSourceNodes.size() == 0)
  28274. {
  28275. // No midi inputs..
  28276. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28277. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28278. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28279. }
  28280. else if (midiSourceNodes.size() == 1)
  28281. {
  28282. // One midi input..
  28283. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28284. AudioProcessorGraph::midiChannelIndex);
  28285. if (midiBufferToUse >= 0)
  28286. {
  28287. if (isBufferNeededLater (ourRenderingIndex,
  28288. AudioProcessorGraph::midiChannelIndex,
  28289. midiSourceNodes.getUnchecked(0),
  28290. AudioProcessorGraph::midiChannelIndex))
  28291. {
  28292. // can't mess up this channel because it's needed later by another node, so we
  28293. // need to use a copy of it..
  28294. const int newFreeBuffer = getFreeBuffer (true);
  28295. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28296. midiBufferToUse = newFreeBuffer;
  28297. }
  28298. }
  28299. else
  28300. {
  28301. // probably a feedback loop, so just use an empty one..
  28302. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28303. }
  28304. }
  28305. else
  28306. {
  28307. // More than one midi input being mixed..
  28308. int reusableInputIndex = -1;
  28309. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28310. {
  28311. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28312. AudioProcessorGraph::midiChannelIndex);
  28313. if (sourceBufIndex >= 0
  28314. && ! isBufferNeededLater (ourRenderingIndex,
  28315. AudioProcessorGraph::midiChannelIndex,
  28316. midiSourceNodes.getUnchecked(i),
  28317. AudioProcessorGraph::midiChannelIndex))
  28318. {
  28319. // we've found one of our input buffers that can be re-used..
  28320. reusableInputIndex = i;
  28321. midiBufferToUse = sourceBufIndex;
  28322. break;
  28323. }
  28324. }
  28325. if (reusableInputIndex < 0)
  28326. {
  28327. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28328. midiBufferToUse = getFreeBuffer (true);
  28329. jassert (midiBufferToUse >= 0);
  28330. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28331. AudioProcessorGraph::midiChannelIndex);
  28332. if (srcIndex >= 0)
  28333. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28334. else
  28335. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28336. reusableInputIndex = 0;
  28337. }
  28338. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28339. {
  28340. if (j != reusableInputIndex)
  28341. {
  28342. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28343. AudioProcessorGraph::midiChannelIndex);
  28344. if (srcIndex >= 0)
  28345. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28346. }
  28347. }
  28348. }
  28349. if (node->processor->producesMidi())
  28350. markBufferAsContaining (midiBufferToUse, node->id,
  28351. AudioProcessorGraph::midiChannelIndex);
  28352. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28353. totalChans, midiBufferToUse));
  28354. }
  28355. int getFreeBuffer (const bool forMidi)
  28356. {
  28357. if (forMidi)
  28358. {
  28359. for (int i = 1; i < midiNodeIds.size(); ++i)
  28360. if (midiNodeIds.getUnchecked(i) < 0)
  28361. return i;
  28362. midiNodeIds.add (-1);
  28363. return midiNodeIds.size() - 1;
  28364. }
  28365. else
  28366. {
  28367. for (int i = 1; i < nodeIds.size(); ++i)
  28368. if (nodeIds.getUnchecked(i) < 0)
  28369. return i;
  28370. nodeIds.add (-1);
  28371. channels.add (0);
  28372. return nodeIds.size() - 1;
  28373. }
  28374. }
  28375. int getReadOnlyEmptyBuffer() const
  28376. {
  28377. return 0;
  28378. }
  28379. int getBufferContaining (const int nodeId, const int outputChannel) const
  28380. {
  28381. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28382. {
  28383. for (int i = midiNodeIds.size(); --i >= 0;)
  28384. if (midiNodeIds.getUnchecked(i) == nodeId)
  28385. return i;
  28386. }
  28387. else
  28388. {
  28389. for (int i = nodeIds.size(); --i >= 0;)
  28390. if (nodeIds.getUnchecked(i) == nodeId
  28391. && channels.getUnchecked(i) == outputChannel)
  28392. return i;
  28393. }
  28394. return -1;
  28395. }
  28396. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28397. {
  28398. int i;
  28399. for (i = 0; i < nodeIds.size(); ++i)
  28400. {
  28401. if (nodeIds.getUnchecked(i) >= 0
  28402. && ! isBufferNeededLater (stepIndex, -1,
  28403. nodeIds.getUnchecked(i),
  28404. channels.getUnchecked(i)))
  28405. {
  28406. nodeIds.set (i, -1);
  28407. }
  28408. }
  28409. for (i = 0; i < midiNodeIds.size(); ++i)
  28410. {
  28411. if (midiNodeIds.getUnchecked(i) >= 0
  28412. && ! isBufferNeededLater (stepIndex, -1,
  28413. midiNodeIds.getUnchecked(i),
  28414. AudioProcessorGraph::midiChannelIndex))
  28415. {
  28416. midiNodeIds.set (i, -1);
  28417. }
  28418. }
  28419. }
  28420. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28421. int inputChannelOfIndexToIgnore,
  28422. const int nodeId,
  28423. const int outputChanIndex) const
  28424. {
  28425. while (stepIndexToSearchFrom < orderedNodes.size())
  28426. {
  28427. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28428. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28429. {
  28430. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28431. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28432. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28433. return true;
  28434. }
  28435. else
  28436. {
  28437. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28438. if (i != inputChannelOfIndexToIgnore
  28439. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28440. node->id, i) != 0)
  28441. return true;
  28442. }
  28443. inputChannelOfIndexToIgnore = -1;
  28444. ++stepIndexToSearchFrom;
  28445. }
  28446. return false;
  28447. }
  28448. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28449. {
  28450. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28451. {
  28452. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28453. midiNodeIds.set (bufferNum, nodeId);
  28454. }
  28455. else
  28456. {
  28457. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28458. nodeIds.set (bufferNum, nodeId);
  28459. channels.set (bufferNum, outputIndex);
  28460. }
  28461. }
  28462. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28463. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28464. };
  28465. }
  28466. void AudioProcessorGraph::clearRenderingSequence()
  28467. {
  28468. const ScopedLock sl (renderLock);
  28469. for (int i = renderingOps.size(); --i >= 0;)
  28470. {
  28471. GraphRenderingOps::AudioGraphRenderingOp* const r
  28472. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28473. renderingOps.remove (i);
  28474. delete r;
  28475. }
  28476. }
  28477. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28478. const uint32 possibleDestinationId,
  28479. const int recursionCheck) const
  28480. {
  28481. if (recursionCheck > 0)
  28482. {
  28483. for (int i = connections.size(); --i >= 0;)
  28484. {
  28485. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28486. if (c->destNodeId == possibleDestinationId
  28487. && (c->sourceNodeId == possibleInputId
  28488. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28489. return true;
  28490. }
  28491. }
  28492. return false;
  28493. }
  28494. void AudioProcessorGraph::buildRenderingSequence()
  28495. {
  28496. VoidArray newRenderingOps;
  28497. int numRenderingBuffersNeeded = 2;
  28498. int numMidiBuffersNeeded = 1;
  28499. {
  28500. MessageManagerLock mml;
  28501. VoidArray orderedNodes;
  28502. int i;
  28503. for (i = 0; i < nodes.size(); ++i)
  28504. {
  28505. Node* const node = nodes.getUnchecked(i);
  28506. node->prepare (getSampleRate(), getBlockSize(), this);
  28507. int j = 0;
  28508. for (; j < orderedNodes.size(); ++j)
  28509. if (isAnInputTo (node->id,
  28510. ((Node*) orderedNodes.getUnchecked (j))->id,
  28511. nodes.size() + 1))
  28512. break;
  28513. orderedNodes.insert (j, node);
  28514. }
  28515. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28516. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28517. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28518. }
  28519. VoidArray oldRenderingOps (renderingOps);
  28520. {
  28521. // swap over to the new rendering sequence..
  28522. const ScopedLock sl (renderLock);
  28523. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28524. renderingBuffers.clear();
  28525. for (int i = midiBuffers.size(); --i >= 0;)
  28526. midiBuffers.getUnchecked(i)->clear();
  28527. while (midiBuffers.size() < numMidiBuffersNeeded)
  28528. midiBuffers.add (new MidiBuffer());
  28529. renderingOps = newRenderingOps;
  28530. }
  28531. for (int i = oldRenderingOps.size(); --i >= 0;)
  28532. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28533. }
  28534. void AudioProcessorGraph::handleAsyncUpdate()
  28535. {
  28536. buildRenderingSequence();
  28537. }
  28538. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28539. {
  28540. currentAudioInputBuffer = 0;
  28541. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28542. currentMidiInputBuffer = 0;
  28543. currentMidiOutputBuffer.clear();
  28544. clearRenderingSequence();
  28545. buildRenderingSequence();
  28546. }
  28547. void AudioProcessorGraph::releaseResources()
  28548. {
  28549. for (int i = 0; i < nodes.size(); ++i)
  28550. nodes.getUnchecked(i)->unprepare();
  28551. renderingBuffers.setSize (1, 1);
  28552. midiBuffers.clear();
  28553. currentAudioInputBuffer = 0;
  28554. currentAudioOutputBuffer.setSize (1, 1);
  28555. currentMidiInputBuffer = 0;
  28556. currentMidiOutputBuffer.clear();
  28557. }
  28558. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28559. {
  28560. const int numSamples = buffer.getNumSamples();
  28561. const ScopedLock sl (renderLock);
  28562. currentAudioInputBuffer = &buffer;
  28563. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28564. currentAudioOutputBuffer.clear();
  28565. currentMidiInputBuffer = &midiMessages;
  28566. currentMidiOutputBuffer.clear();
  28567. int i;
  28568. for (i = 0; i < renderingOps.size(); ++i)
  28569. {
  28570. GraphRenderingOps::AudioGraphRenderingOp* const op
  28571. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28572. op->perform (renderingBuffers, midiBuffers, numSamples);
  28573. }
  28574. for (i = 0; i < buffer.getNumChannels(); ++i)
  28575. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28576. midiMessages.clear();
  28577. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28578. }
  28579. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28580. {
  28581. return "Input " + String (channelIndex + 1);
  28582. }
  28583. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28584. {
  28585. return "Output " + String (channelIndex + 1);
  28586. }
  28587. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28588. {
  28589. return true;
  28590. }
  28591. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28592. {
  28593. return true;
  28594. }
  28595. bool AudioProcessorGraph::acceptsMidi() const
  28596. {
  28597. return true;
  28598. }
  28599. bool AudioProcessorGraph::producesMidi() const
  28600. {
  28601. return true;
  28602. }
  28603. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28604. {
  28605. }
  28606. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28607. {
  28608. }
  28609. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28610. : type (type_),
  28611. graph (0)
  28612. {
  28613. }
  28614. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28615. {
  28616. }
  28617. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28618. {
  28619. switch (type)
  28620. {
  28621. case audioOutputNode:
  28622. return "Audio Output";
  28623. case audioInputNode:
  28624. return "Audio Input";
  28625. case midiOutputNode:
  28626. return "Midi Output";
  28627. case midiInputNode:
  28628. return "Midi Input";
  28629. default:
  28630. break;
  28631. }
  28632. return String::empty;
  28633. }
  28634. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28635. {
  28636. d.name = getName();
  28637. d.uid = d.name.hashCode();
  28638. d.category = "I/O devices";
  28639. d.pluginFormatName = "Internal";
  28640. d.manufacturerName = "Raw Material Software";
  28641. d.version = "1.0";
  28642. d.isInstrument = false;
  28643. d.numInputChannels = getNumInputChannels();
  28644. if (type == audioOutputNode && graph != 0)
  28645. d.numInputChannels = graph->getNumInputChannels();
  28646. d.numOutputChannels = getNumOutputChannels();
  28647. if (type == audioInputNode && graph != 0)
  28648. d.numOutputChannels = graph->getNumOutputChannels();
  28649. }
  28650. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28651. {
  28652. jassert (graph != 0);
  28653. }
  28654. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28655. {
  28656. }
  28657. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28658. MidiBuffer& midiMessages)
  28659. {
  28660. jassert (graph != 0);
  28661. switch (type)
  28662. {
  28663. case audioOutputNode:
  28664. {
  28665. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28666. buffer.getNumChannels()); --i >= 0;)
  28667. {
  28668. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28669. }
  28670. break;
  28671. }
  28672. case audioInputNode:
  28673. {
  28674. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28675. buffer.getNumChannels()); --i >= 0;)
  28676. {
  28677. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28678. }
  28679. break;
  28680. }
  28681. case midiOutputNode:
  28682. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28683. break;
  28684. case midiInputNode:
  28685. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28686. break;
  28687. default:
  28688. break;
  28689. }
  28690. }
  28691. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28692. {
  28693. return type == midiOutputNode;
  28694. }
  28695. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28696. {
  28697. return type == midiInputNode;
  28698. }
  28699. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28700. {
  28701. switch (type)
  28702. {
  28703. case audioOutputNode:
  28704. return "Output " + String (channelIndex + 1);
  28705. case midiOutputNode:
  28706. return "Midi Output";
  28707. default:
  28708. break;
  28709. }
  28710. return String::empty;
  28711. }
  28712. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28713. {
  28714. switch (type)
  28715. {
  28716. case audioInputNode:
  28717. return "Input " + String (channelIndex + 1);
  28718. case midiInputNode:
  28719. return "Midi Input";
  28720. default:
  28721. break;
  28722. }
  28723. return String::empty;
  28724. }
  28725. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28726. {
  28727. return type == audioInputNode || type == audioOutputNode;
  28728. }
  28729. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28730. {
  28731. return isInputChannelStereoPair (index);
  28732. }
  28733. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28734. {
  28735. return type == audioInputNode || type == midiInputNode;
  28736. }
  28737. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  28738. {
  28739. return type == audioOutputNode || type == midiOutputNode;
  28740. }
  28741. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  28742. {
  28743. return 0;
  28744. }
  28745. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  28746. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  28747. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  28748. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  28749. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  28750. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  28751. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  28752. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  28753. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  28754. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  28755. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  28756. {
  28757. }
  28758. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  28759. {
  28760. }
  28761. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  28762. {
  28763. graph = newGraph;
  28764. if (graph != 0)
  28765. {
  28766. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  28767. type == audioInputNode ? graph->getNumInputChannels() : 0,
  28768. getSampleRate(),
  28769. getBlockSize());
  28770. updateHostDisplay();
  28771. }
  28772. }
  28773. END_JUCE_NAMESPACE
  28774. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  28775. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28776. BEGIN_JUCE_NAMESPACE
  28777. AudioProcessorPlayer::AudioProcessorPlayer()
  28778. : processor (0),
  28779. sampleRate (0),
  28780. blockSize (0),
  28781. isPrepared (false),
  28782. numInputChans (0),
  28783. numOutputChans (0),
  28784. tempBuffer (1, 1)
  28785. {
  28786. }
  28787. AudioProcessorPlayer::~AudioProcessorPlayer()
  28788. {
  28789. setProcessor (0);
  28790. }
  28791. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  28792. {
  28793. if (processor != processorToPlay)
  28794. {
  28795. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  28796. {
  28797. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  28798. sampleRate, blockSize);
  28799. processorToPlay->prepareToPlay (sampleRate, blockSize);
  28800. }
  28801. AudioProcessor* oldOne;
  28802. {
  28803. const ScopedLock sl (lock);
  28804. oldOne = isPrepared ? processor : 0;
  28805. processor = processorToPlay;
  28806. isPrepared = true;
  28807. }
  28808. if (oldOne != 0)
  28809. oldOne->releaseResources();
  28810. }
  28811. }
  28812. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  28813. int numInputChannels,
  28814. float** outputChannelData,
  28815. int numOutputChannels,
  28816. int numSamples)
  28817. {
  28818. // these should have been prepared by audioDeviceAboutToStart()...
  28819. jassert (sampleRate > 0 && blockSize > 0);
  28820. incomingMidi.clear();
  28821. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  28822. int i, totalNumChans = 0;
  28823. if (numInputChannels > numOutputChannels)
  28824. {
  28825. // if there aren't enough output channels for the number of
  28826. // inputs, we need to create some temporary extra ones (can't
  28827. // use the input data in case it gets written to)
  28828. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  28829. false, false, true);
  28830. for (i = 0; i < numOutputChannels; ++i)
  28831. {
  28832. channels[totalNumChans] = outputChannelData[i];
  28833. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28834. ++totalNumChans;
  28835. }
  28836. for (i = numOutputChannels; i < numInputChannels; ++i)
  28837. {
  28838. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  28839. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28840. ++totalNumChans;
  28841. }
  28842. }
  28843. else
  28844. {
  28845. for (i = 0; i < numInputChannels; ++i)
  28846. {
  28847. channels[totalNumChans] = outputChannelData[i];
  28848. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28849. ++totalNumChans;
  28850. }
  28851. for (i = numInputChannels; i < numOutputChannels; ++i)
  28852. {
  28853. channels[totalNumChans] = outputChannelData[i];
  28854. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  28855. ++totalNumChans;
  28856. }
  28857. }
  28858. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  28859. const ScopedLock sl (lock);
  28860. if (processor != 0)
  28861. processor->processBlock (buffer, incomingMidi);
  28862. }
  28863. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  28864. {
  28865. const ScopedLock sl (lock);
  28866. sampleRate = device->getCurrentSampleRate();
  28867. blockSize = device->getCurrentBufferSizeSamples();
  28868. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  28869. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  28870. messageCollector.reset (sampleRate);
  28871. zeromem (channels, sizeof (channels));
  28872. if (processor != 0)
  28873. {
  28874. if (isPrepared)
  28875. processor->releaseResources();
  28876. AudioProcessor* const oldProcessor = processor;
  28877. setProcessor (0);
  28878. setProcessor (oldProcessor);
  28879. }
  28880. }
  28881. void AudioProcessorPlayer::audioDeviceStopped()
  28882. {
  28883. const ScopedLock sl (lock);
  28884. if (processor != 0 && isPrepared)
  28885. processor->releaseResources();
  28886. sampleRate = 0.0;
  28887. blockSize = 0;
  28888. isPrepared = false;
  28889. tempBuffer.setSize (1, 1);
  28890. }
  28891. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  28892. {
  28893. messageCollector.addMessageToQueue (message);
  28894. }
  28895. END_JUCE_NAMESPACE
  28896. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28897. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  28898. BEGIN_JUCE_NAMESPACE
  28899. class ProcessorParameterPropertyComp : public PropertyComponent,
  28900. public AudioProcessorListener,
  28901. public AsyncUpdater
  28902. {
  28903. public:
  28904. ProcessorParameterPropertyComp (const String& name,
  28905. AudioProcessor* const owner_,
  28906. const int index_)
  28907. : PropertyComponent (name),
  28908. owner (owner_),
  28909. index (index_)
  28910. {
  28911. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  28912. owner_->addListener (this);
  28913. }
  28914. ~ProcessorParameterPropertyComp()
  28915. {
  28916. owner->removeListener (this);
  28917. deleteAllChildren();
  28918. }
  28919. void refresh()
  28920. {
  28921. slider->setValue (owner->getParameter (index), false);
  28922. }
  28923. void audioProcessorChanged (AudioProcessor*) {}
  28924. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  28925. {
  28926. if (parameterIndex == index)
  28927. triggerAsyncUpdate();
  28928. }
  28929. void handleAsyncUpdate()
  28930. {
  28931. refresh();
  28932. }
  28933. juce_UseDebuggingNewOperator
  28934. private:
  28935. AudioProcessor* const owner;
  28936. const int index;
  28937. Slider* slider;
  28938. class ParamSlider : public Slider
  28939. {
  28940. public:
  28941. ParamSlider (AudioProcessor* const owner_, const int index_)
  28942. : Slider (String::empty),
  28943. owner (owner_),
  28944. index (index_)
  28945. {
  28946. setRange (0.0, 1.0, 0.0);
  28947. setSliderStyle (Slider::LinearBar);
  28948. setTextBoxIsEditable (false);
  28949. setScrollWheelEnabled (false);
  28950. }
  28951. ~ParamSlider()
  28952. {
  28953. }
  28954. void valueChanged()
  28955. {
  28956. const float newVal = (float) getValue();
  28957. if (owner->getParameter (index) != newVal)
  28958. owner->setParameter (index, newVal);
  28959. }
  28960. const String getTextFromValue (double /*value*/)
  28961. {
  28962. return owner->getParameterText (index);
  28963. }
  28964. juce_UseDebuggingNewOperator
  28965. private:
  28966. AudioProcessor* const owner;
  28967. const int index;
  28968. ParamSlider (const ParamSlider&);
  28969. ParamSlider& operator= (const ParamSlider&);
  28970. };
  28971. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  28972. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  28973. };
  28974. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  28975. : AudioProcessorEditor (owner_)
  28976. {
  28977. setOpaque (true);
  28978. addAndMakeVisible (panel = new PropertyPanel());
  28979. Array <PropertyComponent*> params;
  28980. const int numParams = owner_->getNumParameters();
  28981. int totalHeight = 0;
  28982. for (int i = 0; i < numParams; ++i)
  28983. {
  28984. String name (owner_->getParameterName (i));
  28985. if (name.trim().isEmpty())
  28986. name = "Unnamed";
  28987. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  28988. params.add (pc);
  28989. totalHeight += pc->getPreferredHeight();
  28990. }
  28991. panel->addProperties (params);
  28992. setSize (400, jlimit (25, 400, totalHeight));
  28993. }
  28994. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  28995. {
  28996. deleteAllChildren();
  28997. }
  28998. void GenericAudioProcessorEditor::paint (Graphics& g)
  28999. {
  29000. g.fillAll (Colours::white);
  29001. }
  29002. void GenericAudioProcessorEditor::resized()
  29003. {
  29004. panel->setSize (getWidth(), getHeight());
  29005. }
  29006. END_JUCE_NAMESPACE
  29007. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29008. /*** Start of inlined file: juce_Sampler.cpp ***/
  29009. BEGIN_JUCE_NAMESPACE
  29010. SamplerSound::SamplerSound (const String& name_,
  29011. AudioFormatReader& source,
  29012. const BigInteger& midiNotes_,
  29013. const int midiNoteForNormalPitch,
  29014. const double attackTimeSecs,
  29015. const double releaseTimeSecs,
  29016. const double maxSampleLengthSeconds)
  29017. : name (name_),
  29018. midiNotes (midiNotes_),
  29019. midiRootNote (midiNoteForNormalPitch)
  29020. {
  29021. sourceSampleRate = source.sampleRate;
  29022. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29023. {
  29024. length = 0;
  29025. attackSamples = 0;
  29026. releaseSamples = 0;
  29027. }
  29028. else
  29029. {
  29030. length = jmin ((int) source.lengthInSamples,
  29031. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29032. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29033. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29034. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29035. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29036. }
  29037. }
  29038. SamplerSound::~SamplerSound()
  29039. {
  29040. }
  29041. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29042. {
  29043. return midiNotes [midiNoteNumber];
  29044. }
  29045. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29046. {
  29047. return true;
  29048. }
  29049. SamplerVoice::SamplerVoice()
  29050. : pitchRatio (0.0),
  29051. sourceSamplePosition (0.0),
  29052. lgain (0.0f),
  29053. rgain (0.0f),
  29054. isInAttack (false),
  29055. isInRelease (false)
  29056. {
  29057. }
  29058. SamplerVoice::~SamplerVoice()
  29059. {
  29060. }
  29061. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29062. {
  29063. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29064. }
  29065. void SamplerVoice::startNote (const int midiNoteNumber,
  29066. const float velocity,
  29067. SynthesiserSound* s,
  29068. const int /*currentPitchWheelPosition*/)
  29069. {
  29070. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29071. jassert (sound != 0); // this object can only play SamplerSounds!
  29072. if (sound != 0)
  29073. {
  29074. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29075. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29076. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29077. sourceSamplePosition = 0.0;
  29078. lgain = velocity;
  29079. rgain = velocity;
  29080. isInAttack = (sound->attackSamples > 0);
  29081. isInRelease = false;
  29082. if (isInAttack)
  29083. {
  29084. attackReleaseLevel = 0.0f;
  29085. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29086. }
  29087. else
  29088. {
  29089. attackReleaseLevel = 1.0f;
  29090. attackDelta = 0.0f;
  29091. }
  29092. if (sound->releaseSamples > 0)
  29093. {
  29094. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29095. }
  29096. else
  29097. {
  29098. releaseDelta = 0.0f;
  29099. }
  29100. }
  29101. }
  29102. void SamplerVoice::stopNote (const bool allowTailOff)
  29103. {
  29104. if (allowTailOff)
  29105. {
  29106. isInAttack = false;
  29107. isInRelease = true;
  29108. }
  29109. else
  29110. {
  29111. clearCurrentNote();
  29112. }
  29113. }
  29114. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29115. {
  29116. }
  29117. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29118. const int /*newValue*/)
  29119. {
  29120. }
  29121. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29122. {
  29123. const SamplerSound* const playingSound = static_cast <SamplerSound*> (getCurrentlyPlayingSound().getObject());
  29124. if (playingSound != 0)
  29125. {
  29126. const float* const inL = playingSound->data->getSampleData (0, 0);
  29127. const float* const inR = playingSound->data->getNumChannels() > 1
  29128. ? playingSound->data->getSampleData (1, 0) : 0;
  29129. float* outL = outputBuffer.getSampleData (0, startSample);
  29130. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29131. while (--numSamples >= 0)
  29132. {
  29133. const int pos = (int) sourceSamplePosition;
  29134. const float alpha = (float) (sourceSamplePosition - pos);
  29135. const float invAlpha = 1.0f - alpha;
  29136. // just using a very simple linear interpolation here..
  29137. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29138. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29139. : l;
  29140. l *= lgain;
  29141. r *= rgain;
  29142. if (isInAttack)
  29143. {
  29144. l *= attackReleaseLevel;
  29145. r *= attackReleaseLevel;
  29146. attackReleaseLevel += attackDelta;
  29147. if (attackReleaseLevel >= 1.0f)
  29148. {
  29149. attackReleaseLevel = 1.0f;
  29150. isInAttack = false;
  29151. }
  29152. }
  29153. else if (isInRelease)
  29154. {
  29155. l *= attackReleaseLevel;
  29156. r *= attackReleaseLevel;
  29157. attackReleaseLevel += releaseDelta;
  29158. if (attackReleaseLevel <= 0.0f)
  29159. {
  29160. stopNote (false);
  29161. break;
  29162. }
  29163. }
  29164. if (outR != 0)
  29165. {
  29166. *outL++ += l;
  29167. *outR++ += r;
  29168. }
  29169. else
  29170. {
  29171. *outL++ += (l + r) * 0.5f;
  29172. }
  29173. sourceSamplePosition += pitchRatio;
  29174. if (sourceSamplePosition > playingSound->length)
  29175. {
  29176. stopNote (false);
  29177. break;
  29178. }
  29179. }
  29180. }
  29181. }
  29182. END_JUCE_NAMESPACE
  29183. /*** End of inlined file: juce_Sampler.cpp ***/
  29184. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29185. BEGIN_JUCE_NAMESPACE
  29186. SynthesiserSound::SynthesiserSound()
  29187. {
  29188. }
  29189. SynthesiserSound::~SynthesiserSound()
  29190. {
  29191. }
  29192. SynthesiserVoice::SynthesiserVoice()
  29193. : currentSampleRate (44100.0),
  29194. currentlyPlayingNote (-1),
  29195. noteOnTime (0),
  29196. currentlyPlayingSound (0)
  29197. {
  29198. }
  29199. SynthesiserVoice::~SynthesiserVoice()
  29200. {
  29201. }
  29202. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29203. {
  29204. return currentlyPlayingSound != 0
  29205. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29206. }
  29207. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29208. {
  29209. currentSampleRate = newRate;
  29210. }
  29211. void SynthesiserVoice::clearCurrentNote()
  29212. {
  29213. currentlyPlayingNote = -1;
  29214. currentlyPlayingSound = 0;
  29215. }
  29216. Synthesiser::Synthesiser()
  29217. : sampleRate (0),
  29218. lastNoteOnCounter (0),
  29219. shouldStealNotes (true)
  29220. {
  29221. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29222. lastPitchWheelValues[i] = 0x2000;
  29223. }
  29224. Synthesiser::~Synthesiser()
  29225. {
  29226. }
  29227. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29228. {
  29229. const ScopedLock sl (lock);
  29230. return voices [index];
  29231. }
  29232. void Synthesiser::clearVoices()
  29233. {
  29234. const ScopedLock sl (lock);
  29235. voices.clear();
  29236. }
  29237. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29238. {
  29239. const ScopedLock sl (lock);
  29240. voices.add (newVoice);
  29241. }
  29242. void Synthesiser::removeVoice (const int index)
  29243. {
  29244. const ScopedLock sl (lock);
  29245. voices.remove (index);
  29246. }
  29247. void Synthesiser::clearSounds()
  29248. {
  29249. const ScopedLock sl (lock);
  29250. sounds.clear();
  29251. }
  29252. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29253. {
  29254. const ScopedLock sl (lock);
  29255. sounds.add (newSound);
  29256. }
  29257. void Synthesiser::removeSound (const int index)
  29258. {
  29259. const ScopedLock sl (lock);
  29260. sounds.remove (index);
  29261. }
  29262. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29263. {
  29264. shouldStealNotes = shouldStealNotes_;
  29265. }
  29266. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29267. {
  29268. if (sampleRate != newRate)
  29269. {
  29270. const ScopedLock sl (lock);
  29271. allNotesOff (0, false);
  29272. sampleRate = newRate;
  29273. for (int i = voices.size(); --i >= 0;)
  29274. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29275. }
  29276. }
  29277. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29278. const MidiBuffer& midiData,
  29279. int startSample,
  29280. int numSamples)
  29281. {
  29282. // must set the sample rate before using this!
  29283. jassert (sampleRate != 0);
  29284. const ScopedLock sl (lock);
  29285. MidiBuffer::Iterator midiIterator (midiData);
  29286. midiIterator.setNextSamplePosition (startSample);
  29287. MidiMessage m (0xf4, 0.0);
  29288. while (numSamples > 0)
  29289. {
  29290. int midiEventPos;
  29291. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29292. && midiEventPos < startSample + numSamples;
  29293. const int numThisTime = useEvent ? midiEventPos - startSample
  29294. : numSamples;
  29295. if (numThisTime > 0)
  29296. {
  29297. for (int i = voices.size(); --i >= 0;)
  29298. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29299. }
  29300. if (useEvent)
  29301. {
  29302. if (m.isNoteOn())
  29303. {
  29304. const int channel = m.getChannel();
  29305. noteOn (channel,
  29306. m.getNoteNumber(),
  29307. m.getFloatVelocity());
  29308. }
  29309. else if (m.isNoteOff())
  29310. {
  29311. noteOff (m.getChannel(),
  29312. m.getNoteNumber(),
  29313. true);
  29314. }
  29315. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29316. {
  29317. allNotesOff (m.getChannel(), true);
  29318. }
  29319. else if (m.isPitchWheel())
  29320. {
  29321. const int channel = m.getChannel();
  29322. const int wheelPos = m.getPitchWheelValue();
  29323. lastPitchWheelValues [channel - 1] = wheelPos;
  29324. handlePitchWheel (channel, wheelPos);
  29325. }
  29326. else if (m.isController())
  29327. {
  29328. handleController (m.getChannel(),
  29329. m.getControllerNumber(),
  29330. m.getControllerValue());
  29331. }
  29332. }
  29333. startSample += numThisTime;
  29334. numSamples -= numThisTime;
  29335. }
  29336. }
  29337. void Synthesiser::noteOn (const int midiChannel,
  29338. const int midiNoteNumber,
  29339. const float velocity)
  29340. {
  29341. const ScopedLock sl (lock);
  29342. for (int i = sounds.size(); --i >= 0;)
  29343. {
  29344. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29345. if (sound->appliesToNote (midiNoteNumber)
  29346. && sound->appliesToChannel (midiChannel))
  29347. {
  29348. startVoice (findFreeVoice (sound, shouldStealNotes),
  29349. sound, midiChannel, midiNoteNumber, velocity);
  29350. }
  29351. }
  29352. }
  29353. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29354. SynthesiserSound* const sound,
  29355. const int midiChannel,
  29356. const int midiNoteNumber,
  29357. const float velocity)
  29358. {
  29359. if (voice != 0 && sound != 0)
  29360. {
  29361. if (voice->currentlyPlayingSound != 0)
  29362. voice->stopNote (false);
  29363. voice->startNote (midiNoteNumber,
  29364. velocity,
  29365. sound,
  29366. lastPitchWheelValues [midiChannel - 1]);
  29367. voice->currentlyPlayingNote = midiNoteNumber;
  29368. voice->noteOnTime = ++lastNoteOnCounter;
  29369. voice->currentlyPlayingSound = sound;
  29370. }
  29371. }
  29372. void Synthesiser::noteOff (const int midiChannel,
  29373. const int midiNoteNumber,
  29374. const bool allowTailOff)
  29375. {
  29376. const ScopedLock sl (lock);
  29377. for (int i = voices.size(); --i >= 0;)
  29378. {
  29379. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29380. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29381. {
  29382. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29383. if (sound != 0
  29384. && sound->appliesToNote (midiNoteNumber)
  29385. && sound->appliesToChannel (midiChannel))
  29386. {
  29387. voice->stopNote (allowTailOff);
  29388. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29389. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29390. }
  29391. }
  29392. }
  29393. }
  29394. void Synthesiser::allNotesOff (const int midiChannel,
  29395. const bool allowTailOff)
  29396. {
  29397. const ScopedLock sl (lock);
  29398. for (int i = voices.size(); --i >= 0;)
  29399. {
  29400. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29401. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29402. voice->stopNote (allowTailOff);
  29403. }
  29404. }
  29405. void Synthesiser::handlePitchWheel (const int midiChannel,
  29406. const int wheelValue)
  29407. {
  29408. const ScopedLock sl (lock);
  29409. for (int i = voices.size(); --i >= 0;)
  29410. {
  29411. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29412. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29413. {
  29414. voice->pitchWheelMoved (wheelValue);
  29415. }
  29416. }
  29417. }
  29418. void Synthesiser::handleController (const int midiChannel,
  29419. const int controllerNumber,
  29420. const int controllerValue)
  29421. {
  29422. const ScopedLock sl (lock);
  29423. for (int i = voices.size(); --i >= 0;)
  29424. {
  29425. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29426. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29427. voice->controllerMoved (controllerNumber, controllerValue);
  29428. }
  29429. }
  29430. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29431. const bool stealIfNoneAvailable) const
  29432. {
  29433. const ScopedLock sl (lock);
  29434. for (int i = voices.size(); --i >= 0;)
  29435. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29436. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29437. return voices.getUnchecked (i);
  29438. if (stealIfNoneAvailable)
  29439. {
  29440. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29441. SynthesiserVoice* oldest = 0;
  29442. for (int i = voices.size(); --i >= 0;)
  29443. {
  29444. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29445. if (voice->canPlaySound (soundToPlay)
  29446. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29447. oldest = voice;
  29448. }
  29449. jassert (oldest != 0);
  29450. return oldest;
  29451. }
  29452. return 0;
  29453. }
  29454. END_JUCE_NAMESPACE
  29455. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29456. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29457. BEGIN_JUCE_NAMESPACE
  29458. ActionBroadcaster::ActionBroadcaster() throw()
  29459. {
  29460. // are you trying to create this object before or after juce has been intialised??
  29461. jassert (MessageManager::instance != 0);
  29462. }
  29463. ActionBroadcaster::~ActionBroadcaster()
  29464. {
  29465. // all event-based objects must be deleted BEFORE juce is shut down!
  29466. jassert (MessageManager::instance != 0);
  29467. }
  29468. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29469. {
  29470. actionListenerList.addActionListener (listener);
  29471. }
  29472. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29473. {
  29474. jassert (actionListenerList.isValidMessageListener());
  29475. if (actionListenerList.isValidMessageListener())
  29476. actionListenerList.removeActionListener (listener);
  29477. }
  29478. void ActionBroadcaster::removeAllActionListeners()
  29479. {
  29480. actionListenerList.removeAllActionListeners();
  29481. }
  29482. void ActionBroadcaster::sendActionMessage (const String& message) const
  29483. {
  29484. actionListenerList.sendActionMessage (message);
  29485. }
  29486. END_JUCE_NAMESPACE
  29487. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29488. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29489. BEGIN_JUCE_NAMESPACE
  29490. // special message of our own with a string in it
  29491. class ActionMessage : public Message
  29492. {
  29493. public:
  29494. const String message;
  29495. ActionMessage (const String& messageText,
  29496. void* const listener_) throw()
  29497. : message (messageText)
  29498. {
  29499. pointerParameter = listener_;
  29500. }
  29501. ~ActionMessage() throw()
  29502. {
  29503. }
  29504. private:
  29505. ActionMessage (const ActionMessage&);
  29506. ActionMessage& operator= (const ActionMessage&);
  29507. };
  29508. ActionListenerList::ActionListenerList() throw()
  29509. {
  29510. }
  29511. ActionListenerList::~ActionListenerList() throw()
  29512. {
  29513. }
  29514. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29515. {
  29516. const ScopedLock sl (actionListenerLock_);
  29517. jassert (listener != 0);
  29518. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29519. if (listener != 0)
  29520. actionListeners_.add (listener);
  29521. }
  29522. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29523. {
  29524. const ScopedLock sl (actionListenerLock_);
  29525. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29526. actionListeners_.removeValue (listener);
  29527. }
  29528. void ActionListenerList::removeAllActionListeners() throw()
  29529. {
  29530. const ScopedLock sl (actionListenerLock_);
  29531. actionListeners_.clear();
  29532. }
  29533. void ActionListenerList::sendActionMessage (const String& message) const
  29534. {
  29535. const ScopedLock sl (actionListenerLock_);
  29536. for (int i = actionListeners_.size(); --i >= 0;)
  29537. postMessage (new ActionMessage (message, static_cast <ActionListener*> (actionListeners_.getUnchecked(i))));
  29538. }
  29539. void ActionListenerList::handleMessage (const Message& message)
  29540. {
  29541. const ActionMessage& am = (const ActionMessage&) message;
  29542. if (actionListeners_.contains (am.pointerParameter))
  29543. static_cast <ActionListener*> (am.pointerParameter)->actionListenerCallback (am.message);
  29544. }
  29545. END_JUCE_NAMESPACE
  29546. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29547. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29548. BEGIN_JUCE_NAMESPACE
  29549. AsyncUpdater::AsyncUpdater() throw()
  29550. : asyncMessagePending (false)
  29551. {
  29552. internalAsyncHandler.owner = this;
  29553. }
  29554. AsyncUpdater::~AsyncUpdater()
  29555. {
  29556. }
  29557. void AsyncUpdater::triggerAsyncUpdate() throw()
  29558. {
  29559. if (! asyncMessagePending)
  29560. {
  29561. asyncMessagePending = true;
  29562. internalAsyncHandler.postMessage (new Message());
  29563. }
  29564. }
  29565. void AsyncUpdater::cancelPendingUpdate() throw()
  29566. {
  29567. asyncMessagePending = false;
  29568. }
  29569. void AsyncUpdater::handleUpdateNowIfNeeded()
  29570. {
  29571. if (asyncMessagePending)
  29572. {
  29573. asyncMessagePending = false;
  29574. handleAsyncUpdate();
  29575. }
  29576. }
  29577. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29578. {
  29579. owner->handleUpdateNowIfNeeded();
  29580. }
  29581. END_JUCE_NAMESPACE
  29582. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29583. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29584. BEGIN_JUCE_NAMESPACE
  29585. ChangeBroadcaster::ChangeBroadcaster() throw()
  29586. {
  29587. // are you trying to create this object before or after juce has been intialised??
  29588. jassert (MessageManager::instance != 0);
  29589. }
  29590. ChangeBroadcaster::~ChangeBroadcaster()
  29591. {
  29592. // all event-based objects must be deleted BEFORE juce is shut down!
  29593. jassert (MessageManager::instance != 0);
  29594. }
  29595. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29596. {
  29597. changeListenerList.addChangeListener (listener);
  29598. }
  29599. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29600. {
  29601. jassert (changeListenerList.isValidMessageListener());
  29602. if (changeListenerList.isValidMessageListener())
  29603. changeListenerList.removeChangeListener (listener);
  29604. }
  29605. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29606. {
  29607. changeListenerList.removeAllChangeListeners();
  29608. }
  29609. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29610. {
  29611. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29612. }
  29613. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29614. {
  29615. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29616. }
  29617. void ChangeBroadcaster::dispatchPendingMessages()
  29618. {
  29619. changeListenerList.dispatchPendingMessages();
  29620. }
  29621. END_JUCE_NAMESPACE
  29622. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29623. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29624. BEGIN_JUCE_NAMESPACE
  29625. ChangeListenerList::ChangeListenerList() throw()
  29626. : lastChangedObject (0),
  29627. messagePending (false)
  29628. {
  29629. }
  29630. ChangeListenerList::~ChangeListenerList() throw()
  29631. {
  29632. }
  29633. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29634. {
  29635. const ScopedLock sl (lock);
  29636. jassert (listener != 0);
  29637. if (listener != 0)
  29638. listeners.add (listener);
  29639. }
  29640. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29641. {
  29642. const ScopedLock sl (lock);
  29643. listeners.removeValue (listener);
  29644. }
  29645. void ChangeListenerList::removeAllChangeListeners() throw()
  29646. {
  29647. const ScopedLock sl (lock);
  29648. listeners.clear();
  29649. }
  29650. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29651. {
  29652. const ScopedLock sl (lock);
  29653. if ((! messagePending) && (listeners.size() > 0))
  29654. {
  29655. lastChangedObject = objectThatHasChanged;
  29656. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29657. messagePending = true;
  29658. }
  29659. }
  29660. void ChangeListenerList::handleMessage (const Message& message)
  29661. {
  29662. sendSynchronousChangeMessage (message.pointerParameter);
  29663. }
  29664. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29665. {
  29666. const ScopedLock sl (lock);
  29667. messagePending = false;
  29668. for (int i = listeners.size(); --i >= 0;)
  29669. {
  29670. ChangeListener* const l = static_cast <ChangeListener*> (listeners.getUnchecked (i));
  29671. {
  29672. const ScopedUnlock tempUnlocker (lock);
  29673. l->changeListenerCallback (objectThatHasChanged);
  29674. }
  29675. i = jmin (i, listeners.size());
  29676. }
  29677. }
  29678. void ChangeListenerList::dispatchPendingMessages()
  29679. {
  29680. if (messagePending)
  29681. sendSynchronousChangeMessage (lastChangedObject);
  29682. }
  29683. END_JUCE_NAMESPACE
  29684. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29685. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29686. BEGIN_JUCE_NAMESPACE
  29687. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29688. const uint32 magicMessageHeaderNumber)
  29689. : Thread ("Juce IPC connection"),
  29690. callbackConnectionState (false),
  29691. useMessageThread (callbacksOnMessageThread),
  29692. magicMessageHeader (magicMessageHeaderNumber),
  29693. pipeReceiveMessageTimeout (-1)
  29694. {
  29695. }
  29696. InterprocessConnection::~InterprocessConnection()
  29697. {
  29698. callbackConnectionState = false;
  29699. disconnect();
  29700. }
  29701. bool InterprocessConnection::connectToSocket (const String& hostName,
  29702. const int portNumber,
  29703. const int timeOutMillisecs)
  29704. {
  29705. disconnect();
  29706. const ScopedLock sl (pipeAndSocketLock);
  29707. socket = new StreamingSocket();
  29708. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29709. {
  29710. connectionMadeInt();
  29711. startThread();
  29712. return true;
  29713. }
  29714. else
  29715. {
  29716. socket = 0;
  29717. return false;
  29718. }
  29719. }
  29720. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29721. const int pipeReceiveMessageTimeoutMs)
  29722. {
  29723. disconnect();
  29724. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29725. if (newPipe->openExisting (pipeName))
  29726. {
  29727. const ScopedLock sl (pipeAndSocketLock);
  29728. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29729. initialiseWithPipe (newPipe.release());
  29730. return true;
  29731. }
  29732. return false;
  29733. }
  29734. bool InterprocessConnection::createPipe (const String& pipeName,
  29735. const int pipeReceiveMessageTimeoutMs)
  29736. {
  29737. disconnect();
  29738. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29739. if (newPipe->createNewPipe (pipeName))
  29740. {
  29741. const ScopedLock sl (pipeAndSocketLock);
  29742. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29743. initialiseWithPipe (newPipe.release());
  29744. return true;
  29745. }
  29746. return false;
  29747. }
  29748. void InterprocessConnection::disconnect()
  29749. {
  29750. if (socket != 0)
  29751. socket->close();
  29752. if (pipe != 0)
  29753. {
  29754. pipe->cancelPendingReads();
  29755. pipe->close();
  29756. }
  29757. stopThread (4000);
  29758. {
  29759. const ScopedLock sl (pipeAndSocketLock);
  29760. socket = 0;
  29761. pipe = 0;
  29762. }
  29763. connectionLostInt();
  29764. }
  29765. bool InterprocessConnection::isConnected() const
  29766. {
  29767. const ScopedLock sl (pipeAndSocketLock);
  29768. return ((socket != 0 && socket->isConnected())
  29769. || (pipe != 0 && pipe->isOpen()))
  29770. && isThreadRunning();
  29771. }
  29772. const String InterprocessConnection::getConnectedHostName() const
  29773. {
  29774. if (pipe != 0)
  29775. {
  29776. return "localhost";
  29777. }
  29778. else if (socket != 0)
  29779. {
  29780. if (! socket->isLocal())
  29781. return socket->getHostName();
  29782. return "localhost";
  29783. }
  29784. return String::empty;
  29785. }
  29786. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  29787. {
  29788. uint32 messageHeader[2];
  29789. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  29790. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  29791. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  29792. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  29793. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  29794. size_t bytesWritten = 0;
  29795. const ScopedLock sl (pipeAndSocketLock);
  29796. if (socket != 0)
  29797. {
  29798. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  29799. }
  29800. else if (pipe != 0)
  29801. {
  29802. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  29803. }
  29804. if (bytesWritten < 0)
  29805. {
  29806. // error..
  29807. return false;
  29808. }
  29809. return (bytesWritten == messageData.getSize());
  29810. }
  29811. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  29812. {
  29813. jassert (socket == 0);
  29814. socket = socket_;
  29815. connectionMadeInt();
  29816. startThread();
  29817. }
  29818. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  29819. {
  29820. jassert (pipe == 0);
  29821. pipe = pipe_;
  29822. connectionMadeInt();
  29823. startThread();
  29824. }
  29825. const int messageMagicNumber = 0xb734128b;
  29826. void InterprocessConnection::handleMessage (const Message& message)
  29827. {
  29828. if (message.intParameter1 == messageMagicNumber)
  29829. {
  29830. switch (message.intParameter2)
  29831. {
  29832. case 0:
  29833. {
  29834. ScopedPointer <MemoryBlock> data (static_cast <MemoryBlock*> (message.pointerParameter));
  29835. messageReceived (*data);
  29836. break;
  29837. }
  29838. case 1:
  29839. connectionMade();
  29840. break;
  29841. case 2:
  29842. connectionLost();
  29843. break;
  29844. }
  29845. }
  29846. }
  29847. void InterprocessConnection::connectionMadeInt()
  29848. {
  29849. if (! callbackConnectionState)
  29850. {
  29851. callbackConnectionState = true;
  29852. if (useMessageThread)
  29853. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  29854. else
  29855. connectionMade();
  29856. }
  29857. }
  29858. void InterprocessConnection::connectionLostInt()
  29859. {
  29860. if (callbackConnectionState)
  29861. {
  29862. callbackConnectionState = false;
  29863. if (useMessageThread)
  29864. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  29865. else
  29866. connectionLost();
  29867. }
  29868. }
  29869. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  29870. {
  29871. jassert (callbackConnectionState);
  29872. if (useMessageThread)
  29873. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  29874. else
  29875. messageReceived (data);
  29876. }
  29877. bool InterprocessConnection::readNextMessageInt()
  29878. {
  29879. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  29880. uint32 messageHeader[2];
  29881. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  29882. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  29883. if (bytes == sizeof (messageHeader)
  29884. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  29885. {
  29886. int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  29887. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  29888. {
  29889. MemoryBlock messageData (bytesInMessage, true);
  29890. int bytesRead = 0;
  29891. while (bytesInMessage > 0)
  29892. {
  29893. if (threadShouldExit())
  29894. return false;
  29895. const int numThisTime = jmin (bytesInMessage, 65536);
  29896. const int bytesIn = (socket != 0) ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
  29897. : pipe->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
  29898. if (bytesIn <= 0)
  29899. break;
  29900. bytesRead += bytesIn;
  29901. bytesInMessage -= bytesIn;
  29902. }
  29903. if (bytesRead >= 0)
  29904. deliverDataInt (messageData);
  29905. }
  29906. }
  29907. else if (bytes < 0)
  29908. {
  29909. {
  29910. const ScopedLock sl (pipeAndSocketLock);
  29911. socket = 0;
  29912. }
  29913. connectionLostInt();
  29914. return false;
  29915. }
  29916. return true;
  29917. }
  29918. void InterprocessConnection::run()
  29919. {
  29920. while (! threadShouldExit())
  29921. {
  29922. if (socket != 0)
  29923. {
  29924. const int ready = socket->waitUntilReady (true, 0);
  29925. if (ready < 0)
  29926. {
  29927. {
  29928. const ScopedLock sl (pipeAndSocketLock);
  29929. socket = 0;
  29930. }
  29931. connectionLostInt();
  29932. break;
  29933. }
  29934. else if (ready > 0)
  29935. {
  29936. if (! readNextMessageInt())
  29937. break;
  29938. }
  29939. else
  29940. {
  29941. Thread::sleep (2);
  29942. }
  29943. }
  29944. else if (pipe != 0)
  29945. {
  29946. if (! pipe->isOpen())
  29947. {
  29948. {
  29949. const ScopedLock sl (pipeAndSocketLock);
  29950. pipe = 0;
  29951. }
  29952. connectionLostInt();
  29953. break;
  29954. }
  29955. else
  29956. {
  29957. if (! readNextMessageInt())
  29958. break;
  29959. }
  29960. }
  29961. else
  29962. {
  29963. break;
  29964. }
  29965. }
  29966. }
  29967. END_JUCE_NAMESPACE
  29968. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  29969. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  29970. BEGIN_JUCE_NAMESPACE
  29971. InterprocessConnectionServer::InterprocessConnectionServer()
  29972. : Thread ("Juce IPC server")
  29973. {
  29974. }
  29975. InterprocessConnectionServer::~InterprocessConnectionServer()
  29976. {
  29977. stop();
  29978. }
  29979. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  29980. {
  29981. stop();
  29982. socket = new StreamingSocket();
  29983. if (socket->createListener (portNumber))
  29984. {
  29985. startThread();
  29986. return true;
  29987. }
  29988. socket = 0;
  29989. return false;
  29990. }
  29991. void InterprocessConnectionServer::stop()
  29992. {
  29993. signalThreadShouldExit();
  29994. if (socket != 0)
  29995. socket->close();
  29996. stopThread (4000);
  29997. socket = 0;
  29998. }
  29999. void InterprocessConnectionServer::run()
  30000. {
  30001. while ((! threadShouldExit()) && socket != 0)
  30002. {
  30003. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30004. if (clientSocket != 0)
  30005. {
  30006. InterprocessConnection* newConnection = createConnectionObject();
  30007. if (newConnection != 0)
  30008. newConnection->initialiseWithSocket (clientSocket.release());
  30009. }
  30010. }
  30011. }
  30012. END_JUCE_NAMESPACE
  30013. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30014. /*** Start of inlined file: juce_Message.cpp ***/
  30015. BEGIN_JUCE_NAMESPACE
  30016. Message::Message() throw()
  30017. : intParameter1 (0),
  30018. intParameter2 (0),
  30019. intParameter3 (0),
  30020. pointerParameter (0)
  30021. {
  30022. }
  30023. Message::Message (const int intParameter1_,
  30024. const int intParameter2_,
  30025. const int intParameter3_,
  30026. void* const pointerParameter_) throw()
  30027. : intParameter1 (intParameter1_),
  30028. intParameter2 (intParameter2_),
  30029. intParameter3 (intParameter3_),
  30030. pointerParameter (pointerParameter_)
  30031. {
  30032. }
  30033. Message::~Message() throw()
  30034. {
  30035. }
  30036. END_JUCE_NAMESPACE
  30037. /*** End of inlined file: juce_Message.cpp ***/
  30038. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30039. BEGIN_JUCE_NAMESPACE
  30040. MessageListener::MessageListener() throw()
  30041. {
  30042. // are you trying to create a messagelistener before or after juce has been intialised??
  30043. jassert (MessageManager::instance != 0);
  30044. if (MessageManager::instance != 0)
  30045. MessageManager::instance->messageListeners.add (this);
  30046. }
  30047. MessageListener::~MessageListener()
  30048. {
  30049. if (MessageManager::instance != 0)
  30050. MessageManager::instance->messageListeners.removeValue (this);
  30051. }
  30052. void MessageListener::postMessage (Message* const message) const throw()
  30053. {
  30054. message->messageRecipient = const_cast <MessageListener*> (this);
  30055. if (MessageManager::instance == 0)
  30056. MessageManager::getInstance();
  30057. MessageManager::instance->postMessageToQueue (message);
  30058. }
  30059. bool MessageListener::isValidMessageListener() const throw()
  30060. {
  30061. return (MessageManager::instance != 0)
  30062. && MessageManager::instance->messageListeners.contains (this);
  30063. }
  30064. END_JUCE_NAMESPACE
  30065. /*** End of inlined file: juce_MessageListener.cpp ***/
  30066. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30067. BEGIN_JUCE_NAMESPACE
  30068. // platform-specific functions..
  30069. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30070. bool juce_postMessageToSystemQueue (void* message);
  30071. MessageManager* MessageManager::instance = 0;
  30072. static const int quitMessageId = 0xfffff321;
  30073. MessageManager::MessageManager() throw()
  30074. : quitMessagePosted (false),
  30075. quitMessageReceived (false),
  30076. threadWithLock (0)
  30077. {
  30078. messageThreadId = Thread::getCurrentThreadId();
  30079. }
  30080. MessageManager::~MessageManager() throw()
  30081. {
  30082. broadcastListeners = 0;
  30083. doPlatformSpecificShutdown();
  30084. jassert (instance == this);
  30085. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30086. }
  30087. MessageManager* MessageManager::getInstance() throw()
  30088. {
  30089. if (instance == 0)
  30090. {
  30091. instance = new MessageManager();
  30092. doPlatformSpecificInitialisation();
  30093. }
  30094. return instance;
  30095. }
  30096. void MessageManager::postMessageToQueue (Message* const message)
  30097. {
  30098. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30099. delete message;
  30100. }
  30101. CallbackMessage::CallbackMessage() throw() {}
  30102. CallbackMessage::~CallbackMessage() throw() {}
  30103. void CallbackMessage::post()
  30104. {
  30105. if (MessageManager::instance != 0)
  30106. MessageManager::instance->postCallbackMessage (this);
  30107. }
  30108. void MessageManager::postCallbackMessage (Message* const message)
  30109. {
  30110. message->messageRecipient = 0;
  30111. postMessageToQueue (message);
  30112. }
  30113. // not for public use..
  30114. void MessageManager::deliverMessage (void* const message)
  30115. {
  30116. const ScopedPointer <Message> m (static_cast <Message*> (message));
  30117. MessageListener* const recipient = m->messageRecipient;
  30118. JUCE_TRY
  30119. {
  30120. if (messageListeners.contains (recipient))
  30121. {
  30122. recipient->handleMessage (*m);
  30123. }
  30124. else if (recipient == 0)
  30125. {
  30126. if (m->intParameter1 == quitMessageId)
  30127. {
  30128. quitMessageReceived = true;
  30129. }
  30130. else
  30131. {
  30132. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> (static_cast <Message*> (m));
  30133. if (cm != 0)
  30134. cm->messageCallback();
  30135. }
  30136. }
  30137. }
  30138. JUCE_CATCH_EXCEPTION
  30139. }
  30140. #if ! (JUCE_MAC || JUCE_IPHONE)
  30141. void MessageManager::runDispatchLoop()
  30142. {
  30143. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30144. runDispatchLoopUntil (-1);
  30145. }
  30146. void MessageManager::stopDispatchLoop()
  30147. {
  30148. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30149. m->messageRecipient = 0;
  30150. postMessageToQueue (m);
  30151. quitMessagePosted = true;
  30152. }
  30153. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30154. {
  30155. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30156. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30157. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30158. && ! quitMessageReceived)
  30159. {
  30160. JUCE_TRY
  30161. {
  30162. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30163. {
  30164. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30165. if (msToWait > 0)
  30166. Thread::sleep (jmin (5, msToWait));
  30167. }
  30168. }
  30169. JUCE_CATCH_EXCEPTION
  30170. }
  30171. return ! quitMessageReceived;
  30172. }
  30173. #endif
  30174. void MessageManager::deliverBroadcastMessage (const String& value)
  30175. {
  30176. if (broadcastListeners != 0)
  30177. broadcastListeners->sendActionMessage (value);
  30178. }
  30179. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30180. {
  30181. if (broadcastListeners == 0)
  30182. broadcastListeners = new ActionListenerList();
  30183. broadcastListeners->addActionListener (listener);
  30184. }
  30185. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30186. {
  30187. if (broadcastListeners != 0)
  30188. broadcastListeners->removeActionListener (listener);
  30189. }
  30190. bool MessageManager::isThisTheMessageThread() const throw()
  30191. {
  30192. return Thread::getCurrentThreadId() == messageThreadId;
  30193. }
  30194. void MessageManager::setCurrentThreadAsMessageThread()
  30195. {
  30196. if (messageThreadId != Thread::getCurrentThreadId())
  30197. {
  30198. messageThreadId = Thread::getCurrentThreadId();
  30199. // This is needed on windows to make sure the message window is created by this thread
  30200. doPlatformSpecificShutdown();
  30201. doPlatformSpecificInitialisation();
  30202. }
  30203. }
  30204. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30205. {
  30206. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30207. return thisThread == messageThreadId || thisThread == threadWithLock;
  30208. }
  30209. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30210. {
  30211. public:
  30212. SharedEvents() {}
  30213. ~SharedEvents() {}
  30214. WaitableEvent lockedEvent, releaseEvent;
  30215. private:
  30216. SharedEvents (const SharedEvents&);
  30217. SharedEvents& operator= (const SharedEvents&);
  30218. };
  30219. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30220. {
  30221. public:
  30222. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30223. ~BlockingMessage() throw() {}
  30224. void messageCallback()
  30225. {
  30226. events->lockedEvent.signal();
  30227. events->releaseEvent.wait();
  30228. }
  30229. juce_UseDebuggingNewOperator
  30230. private:
  30231. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30232. BlockingMessage (const BlockingMessage&);
  30233. BlockingMessage& operator= (const BlockingMessage&);
  30234. };
  30235. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30236. : sharedEvents (0),
  30237. locked (false)
  30238. {
  30239. init (threadToCheck, 0);
  30240. }
  30241. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30242. : sharedEvents (0),
  30243. locked (false)
  30244. {
  30245. init (0, jobToCheckForExitSignal);
  30246. }
  30247. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30248. {
  30249. if (MessageManager::instance != 0)
  30250. {
  30251. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30252. {
  30253. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30254. }
  30255. else
  30256. {
  30257. if (threadToCheck == 0 && job == 0)
  30258. {
  30259. MessageManager::instance->lockingLock.enter();
  30260. }
  30261. else
  30262. {
  30263. while (! MessageManager::instance->lockingLock.tryEnter())
  30264. {
  30265. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30266. || (job != 0 && job->shouldExit()))
  30267. return;
  30268. Thread::sleep (1);
  30269. }
  30270. }
  30271. sharedEvents = new SharedEvents();
  30272. sharedEvents->incReferenceCount();
  30273. (new BlockingMessage (sharedEvents))->post();
  30274. while (! sharedEvents->lockedEvent.wait (50))
  30275. {
  30276. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30277. || (job != 0 && job->shouldExit()))
  30278. {
  30279. sharedEvents->releaseEvent.signal();
  30280. sharedEvents->decReferenceCount();
  30281. sharedEvents = 0;
  30282. MessageManager::instance->lockingLock.exit();
  30283. return;
  30284. }
  30285. }
  30286. jassert (MessageManager::instance->threadWithLock == 0);
  30287. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30288. locked = true;
  30289. }
  30290. }
  30291. }
  30292. MessageManagerLock::~MessageManagerLock() throw()
  30293. {
  30294. if (sharedEvents != 0)
  30295. {
  30296. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30297. sharedEvents->releaseEvent.signal();
  30298. sharedEvents->decReferenceCount();
  30299. if (MessageManager::instance != 0)
  30300. {
  30301. MessageManager::instance->threadWithLock = 0;
  30302. MessageManager::instance->lockingLock.exit();
  30303. }
  30304. }
  30305. }
  30306. END_JUCE_NAMESPACE
  30307. /*** End of inlined file: juce_MessageManager.cpp ***/
  30308. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30309. BEGIN_JUCE_NAMESPACE
  30310. class MultiTimer::MultiTimerCallback : public Timer
  30311. {
  30312. public:
  30313. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30314. : timerId (timerId_),
  30315. owner (owner_)
  30316. {
  30317. }
  30318. ~MultiTimerCallback()
  30319. {
  30320. }
  30321. void timerCallback()
  30322. {
  30323. owner.timerCallback (timerId);
  30324. }
  30325. const int timerId;
  30326. private:
  30327. MultiTimer& owner;
  30328. };
  30329. MultiTimer::MultiTimer() throw()
  30330. {
  30331. }
  30332. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30333. {
  30334. }
  30335. MultiTimer::~MultiTimer()
  30336. {
  30337. const ScopedLock sl (timerListLock);
  30338. timers.clear();
  30339. }
  30340. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30341. {
  30342. const ScopedLock sl (timerListLock);
  30343. for (int i = timers.size(); --i >= 0;)
  30344. {
  30345. MultiTimerCallback* const t = timers.getUnchecked(i);
  30346. if (t->timerId == timerId)
  30347. {
  30348. t->startTimer (intervalInMilliseconds);
  30349. return;
  30350. }
  30351. }
  30352. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30353. timers.add (newTimer);
  30354. newTimer->startTimer (intervalInMilliseconds);
  30355. }
  30356. void MultiTimer::stopTimer (const int timerId) throw()
  30357. {
  30358. const ScopedLock sl (timerListLock);
  30359. for (int i = timers.size(); --i >= 0;)
  30360. {
  30361. MultiTimerCallback* const t = timers.getUnchecked(i);
  30362. if (t->timerId == timerId)
  30363. t->stopTimer();
  30364. }
  30365. }
  30366. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30367. {
  30368. const ScopedLock sl (timerListLock);
  30369. for (int i = timers.size(); --i >= 0;)
  30370. {
  30371. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30372. if (t->timerId == timerId)
  30373. return t->isTimerRunning();
  30374. }
  30375. return false;
  30376. }
  30377. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30378. {
  30379. const ScopedLock sl (timerListLock);
  30380. for (int i = timers.size(); --i >= 0;)
  30381. {
  30382. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30383. if (t->timerId == timerId)
  30384. return t->getTimerInterval();
  30385. }
  30386. return 0;
  30387. }
  30388. END_JUCE_NAMESPACE
  30389. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30390. /*** Start of inlined file: juce_Timer.cpp ***/
  30391. BEGIN_JUCE_NAMESPACE
  30392. class InternalTimerThread : private Thread,
  30393. private MessageListener,
  30394. private DeletedAtShutdown,
  30395. private AsyncUpdater
  30396. {
  30397. public:
  30398. InternalTimerThread()
  30399. : Thread ("Juce Timer"),
  30400. firstTimer (0),
  30401. callbackNeeded (false)
  30402. {
  30403. triggerAsyncUpdate();
  30404. }
  30405. ~InternalTimerThread() throw()
  30406. {
  30407. stopThread (4000);
  30408. jassert (instance == this || instance == 0);
  30409. if (instance == this)
  30410. instance = 0;
  30411. }
  30412. void run()
  30413. {
  30414. uint32 lastTime = Time::getMillisecondCounter();
  30415. while (! threadShouldExit())
  30416. {
  30417. const uint32 now = Time::getMillisecondCounter();
  30418. if (now <= lastTime)
  30419. {
  30420. wait (2);
  30421. continue;
  30422. }
  30423. const int elapsed = now - lastTime;
  30424. lastTime = now;
  30425. int timeUntilFirstTimer = 1000;
  30426. {
  30427. const ScopedLock sl (lock);
  30428. decrementAllCounters (elapsed);
  30429. if (firstTimer != 0)
  30430. timeUntilFirstTimer = firstTimer->countdownMs;
  30431. }
  30432. if (timeUntilFirstTimer <= 0)
  30433. {
  30434. if (callbackNeeded.set (true))
  30435. {
  30436. postMessage (new Message());
  30437. const uint32 messageDeliveryTimeout = now + 2000;
  30438. while (callbackNeeded.get())
  30439. {
  30440. wait (4);
  30441. if (threadShouldExit())
  30442. return;
  30443. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30444. break;
  30445. }
  30446. }
  30447. }
  30448. else
  30449. {
  30450. // don't wait for too long because running this loop also helps keep the
  30451. // Time::getApproximateMillisecondTimer value stay up-to-date
  30452. wait (jlimit (1, 50, timeUntilFirstTimer));
  30453. }
  30454. }
  30455. }
  30456. void callTimers()
  30457. {
  30458. const ScopedLock sl (lock);
  30459. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30460. {
  30461. Timer* const t = firstTimer;
  30462. t->countdownMs = t->periodMs;
  30463. removeTimer (t);
  30464. addTimer (t);
  30465. const ScopedUnlock ul (lock);
  30466. JUCE_TRY
  30467. {
  30468. t->timerCallback();
  30469. }
  30470. JUCE_CATCH_EXCEPTION
  30471. }
  30472. callbackNeeded.set (false);
  30473. }
  30474. void handleMessage (const Message&)
  30475. {
  30476. callTimers();
  30477. }
  30478. void callTimersSynchronously()
  30479. {
  30480. if (! isThreadRunning())
  30481. {
  30482. // (This is relied on by some plugins in cases where the MM has
  30483. // had to restart and the async callback never started)
  30484. cancelPendingUpdate();
  30485. triggerAsyncUpdate();
  30486. }
  30487. callTimers();
  30488. }
  30489. static void callAnyTimersSynchronously()
  30490. {
  30491. if (InternalTimerThread::instance != 0)
  30492. InternalTimerThread::instance->callTimersSynchronously();
  30493. }
  30494. static inline void add (Timer* const tim) throw()
  30495. {
  30496. if (instance == 0)
  30497. instance = new InternalTimerThread();
  30498. const ScopedLock sl (instance->lock);
  30499. instance->addTimer (tim);
  30500. }
  30501. static inline void remove (Timer* const tim) throw()
  30502. {
  30503. if (instance != 0)
  30504. {
  30505. const ScopedLock sl (instance->lock);
  30506. instance->removeTimer (tim);
  30507. }
  30508. }
  30509. static inline void resetCounter (Timer* const tim,
  30510. const int newCounter) throw()
  30511. {
  30512. if (instance != 0)
  30513. {
  30514. tim->countdownMs = newCounter;
  30515. tim->periodMs = newCounter;
  30516. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30517. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30518. {
  30519. const ScopedLock sl (instance->lock);
  30520. instance->removeTimer (tim);
  30521. instance->addTimer (tim);
  30522. }
  30523. }
  30524. }
  30525. private:
  30526. friend class Timer;
  30527. static InternalTimerThread* instance;
  30528. static CriticalSection lock;
  30529. Timer* volatile firstTimer;
  30530. class AtomicBool
  30531. {
  30532. public:
  30533. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30534. ~AtomicBool() throw() {}
  30535. bool get() const throw() { return value != 0; }
  30536. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30537. private:
  30538. int32 value;
  30539. AtomicBool (const AtomicBool&);
  30540. AtomicBool& operator= (const AtomicBool&);
  30541. };
  30542. AtomicBool callbackNeeded;
  30543. void addTimer (Timer* const t) throw()
  30544. {
  30545. #ifdef JUCE_DEBUG
  30546. Timer* tt = firstTimer;
  30547. while (tt != 0)
  30548. {
  30549. // trying to add a timer that's already here - shouldn't get to this point,
  30550. // so if you get this assertion, let me know!
  30551. jassert (tt != t);
  30552. tt = tt->next;
  30553. }
  30554. jassert (t->previous == 0 && t->next == 0);
  30555. #endif
  30556. Timer* i = firstTimer;
  30557. if (i == 0 || i->countdownMs > t->countdownMs)
  30558. {
  30559. t->next = firstTimer;
  30560. firstTimer = t;
  30561. }
  30562. else
  30563. {
  30564. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30565. i = i->next;
  30566. jassert (i != 0);
  30567. t->next = i->next;
  30568. t->previous = i;
  30569. i->next = t;
  30570. }
  30571. if (t->next != 0)
  30572. t->next->previous = t;
  30573. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30574. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30575. notify();
  30576. }
  30577. void removeTimer (Timer* const t) throw()
  30578. {
  30579. #ifdef JUCE_DEBUG
  30580. Timer* tt = firstTimer;
  30581. bool found = false;
  30582. while (tt != 0)
  30583. {
  30584. if (tt == t)
  30585. {
  30586. found = true;
  30587. break;
  30588. }
  30589. tt = tt->next;
  30590. }
  30591. // trying to remove a timer that's not here - shouldn't get to this point,
  30592. // so if you get this assertion, let me know!
  30593. jassert (found);
  30594. #endif
  30595. if (t->previous != 0)
  30596. {
  30597. jassert (firstTimer != t);
  30598. t->previous->next = t->next;
  30599. }
  30600. else
  30601. {
  30602. jassert (firstTimer == t);
  30603. firstTimer = t->next;
  30604. }
  30605. if (t->next != 0)
  30606. t->next->previous = t->previous;
  30607. t->next = 0;
  30608. t->previous = 0;
  30609. }
  30610. void decrementAllCounters (const int numMillisecs) const
  30611. {
  30612. Timer* t = firstTimer;
  30613. while (t != 0)
  30614. {
  30615. t->countdownMs -= numMillisecs;
  30616. t = t->next;
  30617. }
  30618. }
  30619. void handleAsyncUpdate()
  30620. {
  30621. startThread (7);
  30622. }
  30623. InternalTimerThread (const InternalTimerThread&);
  30624. InternalTimerThread& operator= (const InternalTimerThread&);
  30625. };
  30626. InternalTimerThread* InternalTimerThread::instance = 0;
  30627. CriticalSection InternalTimerThread::lock;
  30628. void juce_callAnyTimersSynchronously()
  30629. {
  30630. InternalTimerThread::callAnyTimersSynchronously();
  30631. }
  30632. #ifdef JUCE_DEBUG
  30633. static SortedSet <Timer*> activeTimers;
  30634. #endif
  30635. Timer::Timer() throw()
  30636. : countdownMs (0),
  30637. periodMs (0),
  30638. previous (0),
  30639. next (0)
  30640. {
  30641. #ifdef JUCE_DEBUG
  30642. activeTimers.add (this);
  30643. #endif
  30644. }
  30645. Timer::Timer (const Timer&) throw()
  30646. : countdownMs (0),
  30647. periodMs (0),
  30648. previous (0),
  30649. next (0)
  30650. {
  30651. #ifdef JUCE_DEBUG
  30652. activeTimers.add (this);
  30653. #endif
  30654. }
  30655. Timer::~Timer()
  30656. {
  30657. stopTimer();
  30658. #ifdef JUCE_DEBUG
  30659. activeTimers.removeValue (this);
  30660. #endif
  30661. }
  30662. void Timer::startTimer (const int interval) throw()
  30663. {
  30664. const ScopedLock sl (InternalTimerThread::lock);
  30665. #ifdef JUCE_DEBUG
  30666. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30667. jassert (activeTimers.contains (this));
  30668. #endif
  30669. if (periodMs == 0)
  30670. {
  30671. countdownMs = interval;
  30672. periodMs = jmax (1, interval);
  30673. InternalTimerThread::add (this);
  30674. }
  30675. else
  30676. {
  30677. InternalTimerThread::resetCounter (this, interval);
  30678. }
  30679. }
  30680. void Timer::stopTimer() throw()
  30681. {
  30682. const ScopedLock sl (InternalTimerThread::lock);
  30683. #ifdef JUCE_DEBUG
  30684. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30685. jassert (activeTimers.contains (this));
  30686. #endif
  30687. if (periodMs > 0)
  30688. {
  30689. InternalTimerThread::remove (this);
  30690. periodMs = 0;
  30691. }
  30692. }
  30693. END_JUCE_NAMESPACE
  30694. /*** End of inlined file: juce_Timer.cpp ***/
  30695. #endif
  30696. #if JUCE_BUILD_GUI
  30697. /*** Start of inlined file: juce_Component.cpp ***/
  30698. BEGIN_JUCE_NAMESPACE
  30699. Component* Component::currentlyFocusedComponent = 0;
  30700. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30701. static Array <int> modalReturnValues;
  30702. enum ComponentMessageNumbers
  30703. {
  30704. customCommandMessage = 0x7fff0001,
  30705. exitModalStateMessage = 0x7fff0002
  30706. };
  30707. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30708. static uint32 nextComponentUID = 0;
  30709. Component::Component()
  30710. : parentComponent_ (0),
  30711. componentUID (++nextComponentUID),
  30712. numDeepMouseListeners (0),
  30713. lookAndFeel_ (0),
  30714. effect_ (0),
  30715. bufferedImage_ (0),
  30716. mouseListeners_ (0),
  30717. keyListeners_ (0),
  30718. componentFlags_ (0)
  30719. {
  30720. }
  30721. Component::Component (const String& name)
  30722. : componentName_ (name),
  30723. parentComponent_ (0),
  30724. componentUID (++nextComponentUID),
  30725. numDeepMouseListeners (0),
  30726. lookAndFeel_ (0),
  30727. effect_ (0),
  30728. bufferedImage_ (0),
  30729. mouseListeners_ (0),
  30730. keyListeners_ (0),
  30731. componentFlags_ (0)
  30732. {
  30733. }
  30734. Component::~Component()
  30735. {
  30736. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  30737. if (parentComponent_ != 0)
  30738. {
  30739. parentComponent_->removeChildComponent (this);
  30740. }
  30741. else if ((currentlyFocusedComponent == this)
  30742. || isParentOf (currentlyFocusedComponent))
  30743. {
  30744. giveAwayFocus();
  30745. }
  30746. if (flags.hasHeavyweightPeerFlag)
  30747. removeFromDesktop();
  30748. modalComponentStack.removeValue (this);
  30749. for (int i = childComponentList_.size(); --i >= 0;)
  30750. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  30751. delete bufferedImage_;
  30752. delete mouseListeners_;
  30753. delete keyListeners_;
  30754. }
  30755. void Component::setName (const String& name)
  30756. {
  30757. // if component methods are being called from threads other than the message
  30758. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30759. checkMessageManagerIsLocked
  30760. if (componentName_ != name)
  30761. {
  30762. componentName_ = name;
  30763. if (flags.hasHeavyweightPeerFlag)
  30764. {
  30765. ComponentPeer* const peer = getPeer();
  30766. jassert (peer != 0);
  30767. if (peer != 0)
  30768. peer->setTitle (name);
  30769. }
  30770. BailOutChecker checker (this);
  30771. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  30772. }
  30773. }
  30774. void Component::setVisible (bool shouldBeVisible)
  30775. {
  30776. if (flags.visibleFlag != shouldBeVisible)
  30777. {
  30778. // if component methods are being called from threads other than the message
  30779. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30780. checkMessageManagerIsLocked
  30781. SafePointer<Component> safePointer (this);
  30782. flags.visibleFlag = shouldBeVisible;
  30783. internalRepaint (0, 0, getWidth(), getHeight());
  30784. sendFakeMouseMove();
  30785. if (! shouldBeVisible)
  30786. {
  30787. if (currentlyFocusedComponent == this
  30788. || isParentOf (currentlyFocusedComponent))
  30789. {
  30790. if (parentComponent_ != 0)
  30791. parentComponent_->grabKeyboardFocus();
  30792. else
  30793. giveAwayFocus();
  30794. }
  30795. }
  30796. if (safePointer != 0)
  30797. {
  30798. sendVisibilityChangeMessage();
  30799. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  30800. {
  30801. ComponentPeer* const peer = getPeer();
  30802. jassert (peer != 0);
  30803. if (peer != 0)
  30804. {
  30805. peer->setVisible (shouldBeVisible);
  30806. internalHierarchyChanged();
  30807. }
  30808. }
  30809. }
  30810. }
  30811. }
  30812. void Component::visibilityChanged()
  30813. {
  30814. }
  30815. void Component::sendVisibilityChangeMessage()
  30816. {
  30817. BailOutChecker checker (this);
  30818. visibilityChanged();
  30819. if (! checker.shouldBailOut())
  30820. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  30821. }
  30822. bool Component::isShowing() const
  30823. {
  30824. if (flags.visibleFlag)
  30825. {
  30826. if (parentComponent_ != 0)
  30827. {
  30828. return parentComponent_->isShowing();
  30829. }
  30830. else
  30831. {
  30832. const ComponentPeer* const peer = getPeer();
  30833. return peer != 0 && ! peer->isMinimised();
  30834. }
  30835. }
  30836. return false;
  30837. }
  30838. class FadeOutProxyComponent : public Component,
  30839. public Timer
  30840. {
  30841. public:
  30842. FadeOutProxyComponent (Component* comp,
  30843. const int fadeLengthMs,
  30844. const int deltaXToMove,
  30845. const int deltaYToMove,
  30846. const float scaleFactorAtEnd)
  30847. : lastTime (0),
  30848. alpha (1.0f),
  30849. scale (1.0f)
  30850. {
  30851. image = comp->createComponentSnapshot (comp->getLocalBounds());
  30852. setBounds (comp->getBounds());
  30853. comp->getParentComponent()->addAndMakeVisible (this);
  30854. toBehind (comp);
  30855. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  30856. centreX = comp->getX() + comp->getWidth() * 0.5f;
  30857. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  30858. centreY = comp->getY() + comp->getHeight() * 0.5f;
  30859. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  30860. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  30861. setInterceptsMouseClicks (false, false);
  30862. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  30863. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  30864. }
  30865. ~FadeOutProxyComponent()
  30866. {
  30867. delete image;
  30868. }
  30869. void paint (Graphics& g)
  30870. {
  30871. g.setOpacity (alpha);
  30872. g.drawImage (image,
  30873. 0, 0, getWidth(), getHeight(),
  30874. 0, 0, image->getWidth(), image->getHeight());
  30875. }
  30876. void timerCallback()
  30877. {
  30878. const uint32 now = Time::getMillisecondCounter();
  30879. if (lastTime == 0)
  30880. lastTime = now;
  30881. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  30882. lastTime = now;
  30883. alpha += alphaChangePerMs * msPassed;
  30884. if (alpha > 0)
  30885. {
  30886. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  30887. {
  30888. centreX += xChangePerMs * msPassed;
  30889. centreY += yChangePerMs * msPassed;
  30890. scale += scaleChangePerMs * msPassed;
  30891. const int w = roundToInt (image->getWidth() * scale);
  30892. const int h = roundToInt (image->getHeight() * scale);
  30893. setBounds (roundToInt (centreX) - w / 2,
  30894. roundToInt (centreY) - h / 2,
  30895. w, h);
  30896. }
  30897. repaint();
  30898. }
  30899. else
  30900. {
  30901. delete this;
  30902. }
  30903. }
  30904. juce_UseDebuggingNewOperator
  30905. private:
  30906. Image* image;
  30907. uint32 lastTime;
  30908. float alpha, alphaChangePerMs;
  30909. float centreX, xChangePerMs;
  30910. float centreY, yChangePerMs;
  30911. float scale, scaleChangePerMs;
  30912. FadeOutProxyComponent (const FadeOutProxyComponent&);
  30913. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  30914. };
  30915. void Component::fadeOutComponent (const int millisecondsToFade,
  30916. const int deltaXToMove,
  30917. const int deltaYToMove,
  30918. const float scaleFactorAtEnd)
  30919. {
  30920. //xxx won't work for comps without parents
  30921. if (isShowing() && millisecondsToFade > 0)
  30922. new FadeOutProxyComponent (this, millisecondsToFade,
  30923. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  30924. setVisible (false);
  30925. }
  30926. bool Component::isValidComponent() const
  30927. {
  30928. return (this != 0) && isValidMessageListener();
  30929. }
  30930. void* Component::getWindowHandle() const
  30931. {
  30932. const ComponentPeer* const peer = getPeer();
  30933. if (peer != 0)
  30934. return peer->getNativeHandle();
  30935. return 0;
  30936. }
  30937. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  30938. {
  30939. // if component methods are being called from threads other than the message
  30940. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30941. checkMessageManagerIsLocked
  30942. if (isOpaque())
  30943. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  30944. else
  30945. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  30946. int currentStyleFlags = 0;
  30947. // don't use getPeer(), so that we only get the peer that's specifically
  30948. // for this comp, and not for one of its parents.
  30949. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  30950. if (peer != 0)
  30951. currentStyleFlags = peer->getStyleFlags();
  30952. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  30953. {
  30954. SafePointer<Component> safePointer (this);
  30955. #if JUCE_LINUX
  30956. // it's wise to give the component a non-zero size before
  30957. // putting it on the desktop, as X windows get confused by this, and
  30958. // a (1, 1) minimum size is enforced here.
  30959. setSize (jmax (1, getWidth()),
  30960. jmax (1, getHeight()));
  30961. #endif
  30962. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  30963. bool wasFullscreen = false;
  30964. bool wasMinimised = false;
  30965. ComponentBoundsConstrainer* currentConstainer = 0;
  30966. Rectangle<int> oldNonFullScreenBounds;
  30967. if (peer != 0)
  30968. {
  30969. wasFullscreen = peer->isFullScreen();
  30970. wasMinimised = peer->isMinimised();
  30971. currentConstainer = peer->getConstrainer();
  30972. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  30973. removeFromDesktop();
  30974. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  30975. }
  30976. if (parentComponent_ != 0)
  30977. parentComponent_->removeChildComponent (this);
  30978. if (safePointer != 0)
  30979. {
  30980. flags.hasHeavyweightPeerFlag = true;
  30981. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  30982. Desktop::getInstance().addDesktopComponent (this);
  30983. bounds_.setPosition (topLeft);
  30984. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  30985. peer->setVisible (isVisible());
  30986. if (wasFullscreen)
  30987. {
  30988. peer->setFullScreen (true);
  30989. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  30990. }
  30991. if (wasMinimised)
  30992. peer->setMinimised (true);
  30993. if (isAlwaysOnTop())
  30994. peer->setAlwaysOnTop (true);
  30995. peer->setConstrainer (currentConstainer);
  30996. repaint();
  30997. }
  30998. internalHierarchyChanged();
  30999. }
  31000. }
  31001. void Component::removeFromDesktop()
  31002. {
  31003. // if component methods are being called from threads other than the message
  31004. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31005. checkMessageManagerIsLocked
  31006. if (flags.hasHeavyweightPeerFlag)
  31007. {
  31008. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31009. flags.hasHeavyweightPeerFlag = false;
  31010. jassert (peer != 0);
  31011. delete peer;
  31012. Desktop::getInstance().removeDesktopComponent (this);
  31013. }
  31014. }
  31015. bool Component::isOnDesktop() const throw()
  31016. {
  31017. return flags.hasHeavyweightPeerFlag;
  31018. }
  31019. void Component::userTriedToCloseWindow()
  31020. {
  31021. /* This means that the user's trying to get rid of your window with the 'close window' system
  31022. menu option (on windows) or possibly the task manager - you should really handle this
  31023. and delete or hide your component in an appropriate way.
  31024. If you want to ignore the event and don't want to trigger this assertion, just override
  31025. this method and do nothing.
  31026. */
  31027. jassertfalse
  31028. }
  31029. void Component::minimisationStateChanged (bool)
  31030. {
  31031. }
  31032. void Component::setOpaque (const bool shouldBeOpaque)
  31033. {
  31034. if (shouldBeOpaque != flags.opaqueFlag)
  31035. {
  31036. flags.opaqueFlag = shouldBeOpaque;
  31037. if (flags.hasHeavyweightPeerFlag)
  31038. {
  31039. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31040. if (peer != 0)
  31041. {
  31042. // to make it recreate the heavyweight window
  31043. addToDesktop (peer->getStyleFlags());
  31044. }
  31045. }
  31046. repaint();
  31047. }
  31048. }
  31049. bool Component::isOpaque() const throw()
  31050. {
  31051. return flags.opaqueFlag;
  31052. }
  31053. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31054. {
  31055. if (shouldBeBuffered != flags.bufferToImageFlag)
  31056. {
  31057. deleteAndZero (bufferedImage_);
  31058. flags.bufferToImageFlag = shouldBeBuffered;
  31059. }
  31060. }
  31061. void Component::toFront (const bool setAsForeground)
  31062. {
  31063. // if component methods are being called from threads other than the message
  31064. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31065. checkMessageManagerIsLocked
  31066. if (flags.hasHeavyweightPeerFlag)
  31067. {
  31068. ComponentPeer* const peer = getPeer();
  31069. if (peer != 0)
  31070. {
  31071. peer->toFront (setAsForeground);
  31072. if (setAsForeground && ! hasKeyboardFocus (true))
  31073. grabKeyboardFocus();
  31074. }
  31075. }
  31076. else if (parentComponent_ != 0)
  31077. {
  31078. Array<Component*>& childList = parentComponent_->childComponentList_;
  31079. if (childList.getLast() != this)
  31080. {
  31081. const int index = childList.indexOf (this);
  31082. if (index >= 0)
  31083. {
  31084. int insertIndex = -1;
  31085. if (! flags.alwaysOnTopFlag)
  31086. {
  31087. insertIndex = childList.size() - 1;
  31088. while (insertIndex > 0 && childList.getUnchecked (insertIndex)->isAlwaysOnTop())
  31089. --insertIndex;
  31090. }
  31091. if (index != insertIndex)
  31092. {
  31093. childList.move (index, insertIndex);
  31094. sendFakeMouseMove();
  31095. repaintParent();
  31096. }
  31097. }
  31098. }
  31099. if (setAsForeground)
  31100. {
  31101. internalBroughtToFront();
  31102. grabKeyboardFocus();
  31103. }
  31104. }
  31105. }
  31106. void Component::toBehind (Component* const other)
  31107. {
  31108. if (other != 0 && other != this)
  31109. {
  31110. // the two components must belong to the same parent..
  31111. jassert (parentComponent_ == other->parentComponent_);
  31112. if (parentComponent_ != 0)
  31113. {
  31114. Array<Component*>& childList = parentComponent_->childComponentList_;
  31115. const int index = childList.indexOf (this);
  31116. if (index >= 0 && childList [index + 1] != other)
  31117. {
  31118. int otherIndex = childList.indexOf (other);
  31119. if (otherIndex >= 0)
  31120. {
  31121. if (index < otherIndex)
  31122. --otherIndex;
  31123. childList.move (index, otherIndex);
  31124. sendFakeMouseMove();
  31125. repaintParent();
  31126. }
  31127. }
  31128. }
  31129. else if (isOnDesktop())
  31130. {
  31131. jassert (other->isOnDesktop());
  31132. if (other->isOnDesktop())
  31133. {
  31134. ComponentPeer* const us = getPeer();
  31135. ComponentPeer* const them = other->getPeer();
  31136. jassert (us != 0 && them != 0);
  31137. if (us != 0 && them != 0)
  31138. us->toBehind (them);
  31139. }
  31140. }
  31141. }
  31142. }
  31143. void Component::toBack()
  31144. {
  31145. Array<Component*>& childList = parentComponent_->childComponentList_;
  31146. if (isOnDesktop())
  31147. {
  31148. jassertfalse //xxx need to add this to native window
  31149. }
  31150. else if (parentComponent_ != 0 && childList.getFirst() != this)
  31151. {
  31152. const int index = childList.indexOf (this);
  31153. if (index > 0)
  31154. {
  31155. int insertIndex = 0;
  31156. if (flags.alwaysOnTopFlag)
  31157. {
  31158. while (insertIndex < childList.size()
  31159. && ! childList.getUnchecked (insertIndex)->isAlwaysOnTop())
  31160. {
  31161. ++insertIndex;
  31162. }
  31163. }
  31164. if (index != insertIndex)
  31165. {
  31166. childList.move (index, insertIndex);
  31167. sendFakeMouseMove();
  31168. repaintParent();
  31169. }
  31170. }
  31171. }
  31172. }
  31173. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31174. {
  31175. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31176. {
  31177. flags.alwaysOnTopFlag = shouldStayOnTop;
  31178. if (isOnDesktop())
  31179. {
  31180. ComponentPeer* const peer = getPeer();
  31181. jassert (peer != 0);
  31182. if (peer != 0)
  31183. {
  31184. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31185. {
  31186. // some kinds of peer can't change their always-on-top status, so
  31187. // for these, we'll need to create a new window
  31188. const int oldFlags = peer->getStyleFlags();
  31189. removeFromDesktop();
  31190. addToDesktop (oldFlags);
  31191. }
  31192. }
  31193. }
  31194. if (shouldStayOnTop)
  31195. toFront (false);
  31196. internalHierarchyChanged();
  31197. }
  31198. }
  31199. bool Component::isAlwaysOnTop() const throw()
  31200. {
  31201. return flags.alwaysOnTopFlag;
  31202. }
  31203. int Component::proportionOfWidth (const float proportion) const throw()
  31204. {
  31205. return roundToInt (proportion * bounds_.getWidth());
  31206. }
  31207. int Component::proportionOfHeight (const float proportion) const throw()
  31208. {
  31209. return roundToInt (proportion * bounds_.getHeight());
  31210. }
  31211. int Component::getParentWidth() const throw()
  31212. {
  31213. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31214. : getParentMonitorArea().getWidth();
  31215. }
  31216. int Component::getParentHeight() const throw()
  31217. {
  31218. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31219. : getParentMonitorArea().getHeight();
  31220. }
  31221. int Component::getScreenX() const
  31222. {
  31223. return getScreenPosition().getX();
  31224. }
  31225. int Component::getScreenY() const
  31226. {
  31227. return getScreenPosition().getY();
  31228. }
  31229. const Point<int> Component::getScreenPosition() const
  31230. {
  31231. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31232. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31233. : getPosition());
  31234. }
  31235. const Rectangle<int> Component::getScreenBounds() const
  31236. {
  31237. return bounds_.withPosition (getScreenPosition());
  31238. }
  31239. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31240. {
  31241. const Component* c = this;
  31242. Point<int> p (relativePosition);
  31243. do
  31244. {
  31245. if (c->flags.hasHeavyweightPeerFlag)
  31246. return c->getPeer()->relativePositionToGlobal (p);
  31247. p += c->getPosition();
  31248. c = c->parentComponent_;
  31249. }
  31250. while (c != 0);
  31251. return p;
  31252. }
  31253. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31254. {
  31255. if (flags.hasHeavyweightPeerFlag)
  31256. {
  31257. return getPeer()->globalPositionToRelative (screenPosition);
  31258. }
  31259. else
  31260. {
  31261. if (parentComponent_ != 0)
  31262. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31263. return screenPosition - getPosition();
  31264. }
  31265. }
  31266. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31267. {
  31268. Point<int> p (positionRelativeToThis);
  31269. if (targetComponent != 0)
  31270. {
  31271. const Component* c = this;
  31272. do
  31273. {
  31274. if (c == targetComponent)
  31275. return p;
  31276. if (c->flags.hasHeavyweightPeerFlag)
  31277. {
  31278. p = c->getPeer()->relativePositionToGlobal (p);
  31279. break;
  31280. }
  31281. p += c->getPosition();
  31282. c = c->parentComponent_;
  31283. }
  31284. while (c != 0);
  31285. p = targetComponent->globalPositionToRelative (p);
  31286. }
  31287. return p;
  31288. }
  31289. void Component::setBounds (int x, int y, int w, int h)
  31290. {
  31291. // if component methods are being called from threads other than the message
  31292. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31293. checkMessageManagerIsLocked
  31294. if (w < 0) w = 0;
  31295. if (h < 0) h = 0;
  31296. const bool wasResized = (getWidth() != w || getHeight() != h);
  31297. const bool wasMoved = (getX() != x || getY() != y);
  31298. #ifdef JUCE_DEBUG
  31299. // It's a very bad idea to try to resize a window during its paint() method!
  31300. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31301. #endif
  31302. if (wasMoved || wasResized)
  31303. {
  31304. if (flags.visibleFlag)
  31305. {
  31306. // send a fake mouse move to trigger enter/exit messages if needed..
  31307. sendFakeMouseMove();
  31308. if (! flags.hasHeavyweightPeerFlag)
  31309. repaintParent();
  31310. }
  31311. bounds_.setBounds (x, y, w, h);
  31312. if (wasResized)
  31313. repaint();
  31314. else if (! flags.hasHeavyweightPeerFlag)
  31315. repaintParent();
  31316. if (flags.hasHeavyweightPeerFlag)
  31317. {
  31318. ComponentPeer* const peer = getPeer();
  31319. if (peer != 0)
  31320. {
  31321. if (wasMoved && wasResized)
  31322. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31323. else if (wasMoved)
  31324. peer->setPosition (getX(), getY());
  31325. else if (wasResized)
  31326. peer->setSize (getWidth(), getHeight());
  31327. }
  31328. }
  31329. sendMovedResizedMessages (wasMoved, wasResized);
  31330. }
  31331. }
  31332. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31333. {
  31334. JUCE_TRY
  31335. {
  31336. if (wasMoved)
  31337. moved();
  31338. if (wasResized)
  31339. {
  31340. resized();
  31341. for (int i = childComponentList_.size(); --i >= 0;)
  31342. {
  31343. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31344. i = jmin (i, childComponentList_.size());
  31345. }
  31346. }
  31347. BailOutChecker checker (this);
  31348. if (parentComponent_ != 0)
  31349. parentComponent_->childBoundsChanged (this);
  31350. if (! checker.shouldBailOut())
  31351. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31352. *this, wasMoved, wasResized);
  31353. }
  31354. JUCE_CATCH_EXCEPTION
  31355. }
  31356. void Component::setSize (const int w, const int h)
  31357. {
  31358. setBounds (getX(), getY(), w, h);
  31359. }
  31360. void Component::setTopLeftPosition (const int x, const int y)
  31361. {
  31362. setBounds (x, y, getWidth(), getHeight());
  31363. }
  31364. void Component::setTopRightPosition (const int x, const int y)
  31365. {
  31366. setTopLeftPosition (x - getWidth(), y);
  31367. }
  31368. void Component::setBounds (const Rectangle<int>& r)
  31369. {
  31370. setBounds (r.getX(),
  31371. r.getY(),
  31372. r.getWidth(),
  31373. r.getHeight());
  31374. }
  31375. void Component::setBoundsRelative (const float x, const float y,
  31376. const float w, const float h)
  31377. {
  31378. const int pw = getParentWidth();
  31379. const int ph = getParentHeight();
  31380. setBounds (roundToInt (x * pw),
  31381. roundToInt (y * ph),
  31382. roundToInt (w * pw),
  31383. roundToInt (h * ph));
  31384. }
  31385. void Component::setCentrePosition (const int x, const int y)
  31386. {
  31387. setTopLeftPosition (x - getWidth() / 2,
  31388. y - getHeight() / 2);
  31389. }
  31390. void Component::setCentreRelative (const float x, const float y)
  31391. {
  31392. setCentrePosition (roundToInt (getParentWidth() * x),
  31393. roundToInt (getParentHeight() * y));
  31394. }
  31395. void Component::centreWithSize (const int width, const int height)
  31396. {
  31397. setBounds ((getParentWidth() - width) / 2,
  31398. (getParentHeight() - height) / 2,
  31399. width,
  31400. height);
  31401. }
  31402. void Component::setBoundsInset (const BorderSize& borders)
  31403. {
  31404. setBounds (borders.getLeft(),
  31405. borders.getTop(),
  31406. getParentWidth() - (borders.getLeftAndRight()),
  31407. getParentHeight() - (borders.getTopAndBottom()));
  31408. }
  31409. void Component::setBoundsToFit (int x, int y, int width, int height,
  31410. const Justification& justification,
  31411. const bool onlyReduceInSize)
  31412. {
  31413. // it's no good calling this method unless both the component and
  31414. // target rectangle have a finite size.
  31415. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31416. if (getWidth() > 0 && getHeight() > 0
  31417. && width > 0 && height > 0)
  31418. {
  31419. int newW, newH;
  31420. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31421. {
  31422. newW = getWidth();
  31423. newH = getHeight();
  31424. }
  31425. else
  31426. {
  31427. const double imageRatio = getHeight() / (double) getWidth();
  31428. const double targetRatio = height / (double) width;
  31429. if (imageRatio <= targetRatio)
  31430. {
  31431. newW = width;
  31432. newH = jmin (height, roundToInt (newW * imageRatio));
  31433. }
  31434. else
  31435. {
  31436. newH = height;
  31437. newW = jmin (width, roundToInt (newH / imageRatio));
  31438. }
  31439. }
  31440. if (newW > 0 && newH > 0)
  31441. {
  31442. int newX, newY;
  31443. justification.applyToRectangle (newX, newY, newW, newH,
  31444. x, y, width, height);
  31445. setBounds (newX, newY, newW, newH);
  31446. }
  31447. }
  31448. }
  31449. bool Component::hitTest (int x, int y)
  31450. {
  31451. if (! flags.ignoresMouseClicksFlag)
  31452. return true;
  31453. if (flags.allowChildMouseClicksFlag)
  31454. {
  31455. for (int i = getNumChildComponents(); --i >= 0;)
  31456. {
  31457. Component* const c = getChildComponent (i);
  31458. if (c->isVisible()
  31459. && c->bounds_.contains (x, y)
  31460. && c->hitTest (x - c->getX(),
  31461. y - c->getY()))
  31462. {
  31463. return true;
  31464. }
  31465. }
  31466. }
  31467. return false;
  31468. }
  31469. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31470. const bool allowClicksOnChildComponents) throw()
  31471. {
  31472. flags.ignoresMouseClicksFlag = ! allowClicks;
  31473. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31474. }
  31475. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31476. bool& allowsClicksOnChildComponents) const throw()
  31477. {
  31478. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31479. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31480. }
  31481. bool Component::contains (const int x, const int y)
  31482. {
  31483. if (((unsigned int) x) < (unsigned int) getWidth()
  31484. && ((unsigned int) y) < (unsigned int) getHeight()
  31485. && hitTest (x, y))
  31486. {
  31487. if (parentComponent_ != 0)
  31488. {
  31489. return parentComponent_->contains (x + getX(),
  31490. y + getY());
  31491. }
  31492. else if (flags.hasHeavyweightPeerFlag)
  31493. {
  31494. const ComponentPeer* const peer = getPeer();
  31495. if (peer != 0)
  31496. return peer->contains (Point<int> (x, y), true);
  31497. }
  31498. }
  31499. return false;
  31500. }
  31501. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31502. {
  31503. if (! contains (x, y))
  31504. return false;
  31505. Component* p = this;
  31506. while (p->parentComponent_ != 0)
  31507. {
  31508. x += p->getX();
  31509. y += p->getY();
  31510. p = p->parentComponent_;
  31511. }
  31512. const Component* const c = p->getComponentAt (x, y);
  31513. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31514. }
  31515. Component* Component::getComponentAt (const Point<int>& position)
  31516. {
  31517. return getComponentAt (position.getX(), position.getY());
  31518. }
  31519. Component* Component::getComponentAt (const int x, const int y)
  31520. {
  31521. if (flags.visibleFlag
  31522. && ((unsigned int) x) < (unsigned int) getWidth()
  31523. && ((unsigned int) y) < (unsigned int) getHeight()
  31524. && hitTest (x, y))
  31525. {
  31526. for (int i = childComponentList_.size(); --i >= 0;)
  31527. {
  31528. Component* const child = childComponentList_.getUnchecked(i);
  31529. Component* const c = child->getComponentAt (x - child->getX(),
  31530. y - child->getY());
  31531. if (c != 0)
  31532. return c;
  31533. }
  31534. return this;
  31535. }
  31536. return 0;
  31537. }
  31538. void Component::addChildComponent (Component* const child, int zOrder)
  31539. {
  31540. // if component methods are being called from threads other than the message
  31541. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31542. checkMessageManagerIsLocked
  31543. if (child != 0 && child->parentComponent_ != this)
  31544. {
  31545. if (child->parentComponent_ != 0)
  31546. child->parentComponent_->removeChildComponent (child);
  31547. else
  31548. child->removeFromDesktop();
  31549. child->parentComponent_ = this;
  31550. if (child->isVisible())
  31551. child->repaintParent();
  31552. if (! child->isAlwaysOnTop())
  31553. {
  31554. if (zOrder < 0 || zOrder > childComponentList_.size())
  31555. zOrder = childComponentList_.size();
  31556. while (zOrder > 0)
  31557. {
  31558. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31559. break;
  31560. --zOrder;
  31561. }
  31562. }
  31563. childComponentList_.insert (zOrder, child);
  31564. child->internalHierarchyChanged();
  31565. internalChildrenChanged();
  31566. }
  31567. }
  31568. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31569. {
  31570. if (child != 0)
  31571. {
  31572. child->setVisible (true);
  31573. addChildComponent (child, zOrder);
  31574. }
  31575. }
  31576. void Component::removeChildComponent (Component* const child)
  31577. {
  31578. removeChildComponent (childComponentList_.indexOf (child));
  31579. }
  31580. Component* Component::removeChildComponent (const int index)
  31581. {
  31582. // if component methods are being called from threads other than the message
  31583. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31584. checkMessageManagerIsLocked
  31585. Component* const child = childComponentList_ [index];
  31586. if (child != 0)
  31587. {
  31588. sendFakeMouseMove();
  31589. child->repaintParent();
  31590. childComponentList_.remove (index);
  31591. child->parentComponent_ = 0;
  31592. JUCE_TRY
  31593. {
  31594. if ((currentlyFocusedComponent == child)
  31595. || child->isParentOf (currentlyFocusedComponent))
  31596. {
  31597. // get rid first to force the grabKeyboardFocus to change to us.
  31598. giveAwayFocus();
  31599. grabKeyboardFocus();
  31600. }
  31601. }
  31602. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31603. catch (const std::exception& e)
  31604. {
  31605. currentlyFocusedComponent = 0;
  31606. Desktop::getInstance().triggerFocusCallback();
  31607. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31608. }
  31609. catch (...)
  31610. {
  31611. currentlyFocusedComponent = 0;
  31612. Desktop::getInstance().triggerFocusCallback();
  31613. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31614. }
  31615. #endif
  31616. child->internalHierarchyChanged();
  31617. internalChildrenChanged();
  31618. }
  31619. return child;
  31620. }
  31621. void Component::removeAllChildren()
  31622. {
  31623. while (childComponentList_.size() > 0)
  31624. removeChildComponent (childComponentList_.size() - 1);
  31625. }
  31626. void Component::deleteAllChildren()
  31627. {
  31628. while (childComponentList_.size() > 0)
  31629. delete (removeChildComponent (childComponentList_.size() - 1));
  31630. }
  31631. int Component::getNumChildComponents() const throw()
  31632. {
  31633. return childComponentList_.size();
  31634. }
  31635. Component* Component::getChildComponent (const int index) const throw()
  31636. {
  31637. return childComponentList_ [index];
  31638. }
  31639. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31640. {
  31641. return childComponentList_.indexOf (const_cast <Component*> (child));
  31642. }
  31643. Component* Component::getTopLevelComponent() const throw()
  31644. {
  31645. const Component* comp = this;
  31646. while (comp->parentComponent_ != 0)
  31647. comp = comp->parentComponent_;
  31648. return const_cast <Component*> (comp);
  31649. }
  31650. bool Component::isParentOf (const Component* possibleChild) const throw()
  31651. {
  31652. if (! possibleChild->isValidComponent())
  31653. {
  31654. jassert (possibleChild == 0);
  31655. return false;
  31656. }
  31657. while (possibleChild != 0)
  31658. {
  31659. possibleChild = possibleChild->parentComponent_;
  31660. if (possibleChild == this)
  31661. return true;
  31662. }
  31663. return false;
  31664. }
  31665. void Component::parentHierarchyChanged()
  31666. {
  31667. }
  31668. void Component::childrenChanged()
  31669. {
  31670. }
  31671. void Component::internalChildrenChanged()
  31672. {
  31673. if (componentListeners.isEmpty())
  31674. {
  31675. childrenChanged();
  31676. }
  31677. else
  31678. {
  31679. BailOutChecker checker (this);
  31680. childrenChanged();
  31681. if (! checker.shouldBailOut())
  31682. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31683. }
  31684. }
  31685. void Component::internalHierarchyChanged()
  31686. {
  31687. BailOutChecker checker (this);
  31688. parentHierarchyChanged();
  31689. if (checker.shouldBailOut())
  31690. return;
  31691. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31692. if (checker.shouldBailOut())
  31693. return;
  31694. for (int i = childComponentList_.size(); --i >= 0;)
  31695. {
  31696. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31697. if (checker.shouldBailOut())
  31698. {
  31699. // you really shouldn't delete the parent component during a callback telling you
  31700. // that it's changed..
  31701. jassertfalse;
  31702. return;
  31703. }
  31704. i = jmin (i, childComponentList_.size());
  31705. }
  31706. }
  31707. void* Component::runModalLoopCallback (void* userData)
  31708. {
  31709. return (void*) (pointer_sized_int) static_cast <Component*> (userData)->runModalLoop();
  31710. }
  31711. int Component::runModalLoop()
  31712. {
  31713. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31714. {
  31715. // use a callback so this can be called from non-gui threads
  31716. return (int) (pointer_sized_int)
  31717. MessageManager::getInstance()
  31718. ->callFunctionOnMessageThread (&runModalLoopCallback, this);
  31719. }
  31720. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31721. if (! isCurrentlyModal())
  31722. enterModalState();
  31723. JUCE_TRY
  31724. {
  31725. while (flags.currentlyModalFlag && flags.visibleFlag)
  31726. {
  31727. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31728. break;
  31729. // check whether this component was deleted during the last message
  31730. if (! isValidMessageListener())
  31731. break;
  31732. }
  31733. }
  31734. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31735. catch (const std::exception& e)
  31736. {
  31737. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31738. return 0;
  31739. }
  31740. catch (...)
  31741. {
  31742. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31743. return 0;
  31744. }
  31745. #endif
  31746. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31747. int returnValue = 0;
  31748. if (modalIndex >= 0)
  31749. {
  31750. modalComponentReturnValueKeys.remove (modalIndex);
  31751. returnValue = modalReturnValues.remove (modalIndex);
  31752. }
  31753. modalComponentStack.removeValue (this);
  31754. if (prevFocused != 0)
  31755. prevFocused->grabKeyboardFocus();
  31756. return returnValue;
  31757. }
  31758. void Component::enterModalState (const bool takeKeyboardFocus_)
  31759. {
  31760. // if component methods are being called from threads other than the message
  31761. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31762. checkMessageManagerIsLocked
  31763. // Check for an attempt to make a component modal when it already is!
  31764. // This can cause nasty problems..
  31765. jassert (! flags.currentlyModalFlag);
  31766. if (! isCurrentlyModal())
  31767. {
  31768. modalComponentStack.add (this);
  31769. modalComponentReturnValueKeys.add (this);
  31770. modalReturnValues.add (0);
  31771. flags.currentlyModalFlag = true;
  31772. setVisible (true);
  31773. if (takeKeyboardFocus_)
  31774. grabKeyboardFocus();
  31775. }
  31776. }
  31777. void Component::exitModalState (const int returnValue)
  31778. {
  31779. if (isCurrentlyModal())
  31780. {
  31781. if (MessageManager::getInstance()->isThisTheMessageThread())
  31782. {
  31783. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31784. if (modalIndex >= 0)
  31785. {
  31786. modalReturnValues.set (modalIndex, returnValue);
  31787. }
  31788. else
  31789. {
  31790. modalComponentReturnValueKeys.add (this);
  31791. modalReturnValues.add (returnValue);
  31792. }
  31793. modalComponentStack.removeValue (this);
  31794. flags.currentlyModalFlag = false;
  31795. bringModalComponentToFront();
  31796. }
  31797. else
  31798. {
  31799. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  31800. }
  31801. }
  31802. }
  31803. bool Component::isCurrentlyModal() const throw()
  31804. {
  31805. return flags.currentlyModalFlag
  31806. && getCurrentlyModalComponent() == this;
  31807. }
  31808. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  31809. {
  31810. Component* const mc = getCurrentlyModalComponent();
  31811. return mc != 0
  31812. && mc != this
  31813. && (! mc->isParentOf (this))
  31814. && ! mc->canModalEventBeSentToComponent (this);
  31815. }
  31816. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  31817. {
  31818. return modalComponentStack.size();
  31819. }
  31820. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  31821. {
  31822. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  31823. return c->isValidComponent() ? c : 0;
  31824. }
  31825. void Component::bringModalComponentToFront()
  31826. {
  31827. ComponentPeer* lastOne = 0;
  31828. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  31829. {
  31830. Component* const c = getCurrentlyModalComponent (i);
  31831. if (c == 0)
  31832. break;
  31833. ComponentPeer* peer = c->getPeer();
  31834. if (peer != 0 && peer != lastOne)
  31835. {
  31836. if (lastOne == 0)
  31837. {
  31838. peer->toFront (true);
  31839. peer->grabFocus();
  31840. }
  31841. else
  31842. peer->toBehind (lastOne);
  31843. lastOne = peer;
  31844. }
  31845. }
  31846. }
  31847. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  31848. {
  31849. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  31850. }
  31851. bool Component::isBroughtToFrontOnMouseClick() const throw()
  31852. {
  31853. return flags.bringToFrontOnClickFlag;
  31854. }
  31855. void Component::setMouseCursor (const MouseCursor& cursor)
  31856. {
  31857. if (cursor_ != cursor)
  31858. {
  31859. cursor_ = cursor;
  31860. if (flags.visibleFlag)
  31861. updateMouseCursor();
  31862. }
  31863. }
  31864. const MouseCursor Component::getMouseCursor()
  31865. {
  31866. return cursor_;
  31867. }
  31868. void Component::updateMouseCursor() const
  31869. {
  31870. sendFakeMouseMove();
  31871. }
  31872. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  31873. {
  31874. flags.repaintOnMouseActivityFlag = shouldRepaint;
  31875. }
  31876. void Component::repaintParent()
  31877. {
  31878. if (flags.visibleFlag)
  31879. internalRepaint (0, 0, getWidth(), getHeight());
  31880. }
  31881. void Component::repaint()
  31882. {
  31883. repaint (0, 0, getWidth(), getHeight());
  31884. }
  31885. void Component::repaint (const int x, const int y,
  31886. const int w, const int h)
  31887. {
  31888. deleteAndZero (bufferedImage_);
  31889. if (flags.visibleFlag)
  31890. internalRepaint (x, y, w, h);
  31891. }
  31892. void Component::internalRepaint (int x, int y, int w, int h)
  31893. {
  31894. // if component methods are being called from threads other than the message
  31895. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31896. checkMessageManagerIsLocked
  31897. if (x < 0)
  31898. {
  31899. w += x;
  31900. x = 0;
  31901. }
  31902. if (x + w > getWidth())
  31903. w = getWidth() - x;
  31904. if (w > 0)
  31905. {
  31906. if (y < 0)
  31907. {
  31908. h += y;
  31909. y = 0;
  31910. }
  31911. if (y + h > getHeight())
  31912. h = getHeight() - y;
  31913. if (h > 0)
  31914. {
  31915. if (parentComponent_ != 0)
  31916. {
  31917. x += getX();
  31918. y += getY();
  31919. if (parentComponent_->flags.visibleFlag)
  31920. parentComponent_->internalRepaint (x, y, w, h);
  31921. }
  31922. else if (flags.hasHeavyweightPeerFlag)
  31923. {
  31924. ComponentPeer* const peer = getPeer();
  31925. if (peer != 0)
  31926. peer->repaint (x, y, w, h);
  31927. }
  31928. }
  31929. }
  31930. }
  31931. void Component::renderComponent (Graphics& g)
  31932. {
  31933. const Rectangle<int> clipBounds (g.getClipBounds());
  31934. g.saveState();
  31935. clipObscuredRegions (g, clipBounds, 0, 0);
  31936. if (! g.isClipEmpty())
  31937. {
  31938. if (flags.bufferToImageFlag)
  31939. {
  31940. if (bufferedImage_ == 0)
  31941. {
  31942. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  31943. getWidth(), getHeight(), ! flags.opaqueFlag);
  31944. Graphics imG (*bufferedImage_);
  31945. paint (imG);
  31946. }
  31947. g.setColour (Colours::black);
  31948. g.drawImageAt (bufferedImage_, 0, 0);
  31949. }
  31950. else
  31951. {
  31952. paint (g);
  31953. }
  31954. }
  31955. g.restoreState();
  31956. for (int i = 0; i < childComponentList_.size(); ++i)
  31957. {
  31958. Component* const child = childComponentList_.getUnchecked (i);
  31959. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  31960. {
  31961. g.saveState();
  31962. if (g.reduceClipRegion (child->getX(), child->getY(),
  31963. child->getWidth(), child->getHeight()))
  31964. {
  31965. for (int j = i + 1; j < childComponentList_.size(); ++j)
  31966. {
  31967. const Component* const sibling = childComponentList_.getUnchecked (j);
  31968. if (sibling->flags.opaqueFlag && sibling->isVisible())
  31969. g.excludeClipRegion (sibling->getBounds());
  31970. }
  31971. if (! g.isClipEmpty())
  31972. {
  31973. g.setOrigin (child->getX(), child->getY());
  31974. child->paintEntireComponent (g);
  31975. }
  31976. }
  31977. g.restoreState();
  31978. }
  31979. }
  31980. g.saveState();
  31981. paintOverChildren (g);
  31982. g.restoreState();
  31983. }
  31984. void Component::paintEntireComponent (Graphics& g)
  31985. {
  31986. jassert (! g.isClipEmpty());
  31987. #ifdef JUCE_DEBUG
  31988. flags.isInsidePaintCall = true;
  31989. #endif
  31990. if (effect_ != 0)
  31991. {
  31992. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  31993. getWidth(), getHeight(),
  31994. ! flags.opaqueFlag));
  31995. {
  31996. Graphics g2 (*effectImage);
  31997. renderComponent (g2);
  31998. }
  31999. effect_->applyEffect (*effectImage, g);
  32000. }
  32001. else
  32002. {
  32003. renderComponent (g);
  32004. }
  32005. #ifdef JUCE_DEBUG
  32006. flags.isInsidePaintCall = false;
  32007. #endif
  32008. }
  32009. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32010. const bool clipImageToComponentBounds)
  32011. {
  32012. Rectangle<int> r (areaToGrab);
  32013. if (clipImageToComponentBounds)
  32014. r = r.getIntersection (getLocalBounds());
  32015. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32016. jmax (1, r.getWidth()),
  32017. jmax (1, r.getHeight()),
  32018. true));
  32019. Graphics imageContext (*componentImage);
  32020. imageContext.setOrigin (-r.getX(), -r.getY());
  32021. paintEntireComponent (imageContext);
  32022. return componentImage.release();
  32023. }
  32024. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32025. {
  32026. if (effect_ != effect)
  32027. {
  32028. effect_ = effect;
  32029. repaint();
  32030. }
  32031. }
  32032. LookAndFeel& Component::getLookAndFeel() const throw()
  32033. {
  32034. const Component* c = this;
  32035. do
  32036. {
  32037. if (c->lookAndFeel_ != 0)
  32038. return *(c->lookAndFeel_);
  32039. c = c->parentComponent_;
  32040. }
  32041. while (c != 0);
  32042. return LookAndFeel::getDefaultLookAndFeel();
  32043. }
  32044. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32045. {
  32046. if (lookAndFeel_ != newLookAndFeel)
  32047. {
  32048. lookAndFeel_ = newLookAndFeel;
  32049. sendLookAndFeelChange();
  32050. }
  32051. }
  32052. void Component::lookAndFeelChanged()
  32053. {
  32054. }
  32055. void Component::sendLookAndFeelChange()
  32056. {
  32057. repaint();
  32058. lookAndFeelChanged();
  32059. // (it's not a great idea to do anything that would delete this component
  32060. // during the lookAndFeelChanged() callback)
  32061. jassert (isValidComponent());
  32062. SafePointer<Component> safePointer (this);
  32063. for (int i = childComponentList_.size(); --i >= 0;)
  32064. {
  32065. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32066. if (safePointer == 0)
  32067. return;
  32068. i = jmin (i, childComponentList_.size());
  32069. }
  32070. }
  32071. static const var::identifier getColourPropertyId (const int colourId)
  32072. {
  32073. String s;
  32074. s.preallocateStorage (18);
  32075. s << "jcclr_" << String::toHexString (colourId);
  32076. return s;
  32077. }
  32078. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32079. {
  32080. var* v = properties.getItem (getColourPropertyId (colourId));
  32081. if (v != 0)
  32082. return Colour ((int) *v);
  32083. if (inheritFromParent && parentComponent_ != 0)
  32084. return parentComponent_->findColour (colourId, true);
  32085. return getLookAndFeel().findColour (colourId);
  32086. }
  32087. bool Component::isColourSpecified (const int colourId) const
  32088. {
  32089. return properties.contains (getColourPropertyId (colourId));
  32090. }
  32091. void Component::removeColour (const int colourId)
  32092. {
  32093. if (properties.remove (getColourPropertyId (colourId)))
  32094. colourChanged();
  32095. }
  32096. void Component::setColour (const int colourId, const Colour& colour)
  32097. {
  32098. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32099. colourChanged();
  32100. }
  32101. void Component::copyAllExplicitColoursTo (Component& target) const
  32102. {
  32103. bool changed = false;
  32104. for (int i = properties.size(); --i >= 0;)
  32105. {
  32106. const var::identifier name (properties.getName(i));
  32107. if (name.name.startsWith ("jcclr_"))
  32108. if (target.properties.set (name, properties [name]))
  32109. changed = true;
  32110. }
  32111. if (changed)
  32112. target.colourChanged();
  32113. }
  32114. void Component::colourChanged()
  32115. {
  32116. }
  32117. const Rectangle<int> Component::getLocalBounds() const throw()
  32118. {
  32119. return Rectangle<int> (0, 0, getWidth(), getHeight());
  32120. }
  32121. const Rectangle<int> Component::getUnclippedArea() const
  32122. {
  32123. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32124. Component* p = parentComponent_;
  32125. int px = getX();
  32126. int py = getY();
  32127. while (p != 0)
  32128. {
  32129. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32130. return Rectangle<int>();
  32131. px += p->getX();
  32132. py += p->getY();
  32133. p = p->parentComponent_;
  32134. }
  32135. return Rectangle<int> (x, y, w, h);
  32136. }
  32137. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32138. const int deltaX, const int deltaY) const
  32139. {
  32140. for (int i = childComponentList_.size(); --i >= 0;)
  32141. {
  32142. const Component* const c = childComponentList_.getUnchecked(i);
  32143. if (c->isVisible())
  32144. {
  32145. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32146. if (! newClip.isEmpty())
  32147. {
  32148. if (c->isOpaque())
  32149. {
  32150. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32151. }
  32152. else
  32153. {
  32154. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32155. c->getX() + deltaX,
  32156. c->getY() + deltaY);
  32157. }
  32158. }
  32159. }
  32160. }
  32161. }
  32162. void Component::getVisibleArea (RectangleList& result, const bool includeSiblings) const
  32163. {
  32164. result.clear();
  32165. const Rectangle<int> unclipped (getUnclippedArea());
  32166. if (! unclipped.isEmpty())
  32167. {
  32168. result.add (unclipped);
  32169. if (includeSiblings)
  32170. {
  32171. const Component* const c = getTopLevelComponent();
  32172. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32173. c->getLocalBounds(), this);
  32174. }
  32175. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32176. result.consolidate();
  32177. }
  32178. }
  32179. void Component::subtractObscuredRegions (RectangleList& result,
  32180. const Point<int>& delta,
  32181. const Rectangle<int>& clipRect,
  32182. const Component* const compToAvoid) const
  32183. {
  32184. for (int i = childComponentList_.size(); --i >= 0;)
  32185. {
  32186. const Component* const c = childComponentList_.getUnchecked(i);
  32187. if (c != compToAvoid && c->isVisible())
  32188. {
  32189. if (c->isOpaque())
  32190. {
  32191. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32192. childBounds.translate (delta.getX(), delta.getY());
  32193. result.subtract (childBounds);
  32194. }
  32195. else
  32196. {
  32197. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32198. newClip.translate (-c->getX(), -c->getY());
  32199. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32200. newClip, compToAvoid);
  32201. }
  32202. }
  32203. }
  32204. }
  32205. void Component::mouseEnter (const MouseEvent&)
  32206. {
  32207. // base class does nothing
  32208. }
  32209. void Component::mouseExit (const MouseEvent&)
  32210. {
  32211. // base class does nothing
  32212. }
  32213. void Component::mouseDown (const MouseEvent&)
  32214. {
  32215. // base class does nothing
  32216. }
  32217. void Component::mouseUp (const MouseEvent&)
  32218. {
  32219. // base class does nothing
  32220. }
  32221. void Component::mouseDrag (const MouseEvent&)
  32222. {
  32223. // base class does nothing
  32224. }
  32225. void Component::mouseMove (const MouseEvent&)
  32226. {
  32227. // base class does nothing
  32228. }
  32229. void Component::mouseDoubleClick (const MouseEvent&)
  32230. {
  32231. // base class does nothing
  32232. }
  32233. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32234. {
  32235. // the base class just passes this event up to its parent..
  32236. if (parentComponent_ != 0)
  32237. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32238. wheelIncrementX, wheelIncrementY);
  32239. }
  32240. void Component::resized()
  32241. {
  32242. // base class does nothing
  32243. }
  32244. void Component::moved()
  32245. {
  32246. // base class does nothing
  32247. }
  32248. void Component::childBoundsChanged (Component*)
  32249. {
  32250. // base class does nothing
  32251. }
  32252. void Component::parentSizeChanged()
  32253. {
  32254. // base class does nothing
  32255. }
  32256. void Component::addComponentListener (ComponentListener* const newListener)
  32257. {
  32258. jassert (isValidComponent());
  32259. componentListeners.add (newListener);
  32260. }
  32261. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32262. {
  32263. jassert (isValidComponent());
  32264. componentListeners.remove (listenerToRemove);
  32265. }
  32266. void Component::inputAttemptWhenModal()
  32267. {
  32268. bringModalComponentToFront();
  32269. getLookAndFeel().playAlertSound();
  32270. }
  32271. bool Component::canModalEventBeSentToComponent (const Component*)
  32272. {
  32273. return false;
  32274. }
  32275. void Component::internalModalInputAttempt()
  32276. {
  32277. Component* const current = getCurrentlyModalComponent();
  32278. if (current != 0)
  32279. current->inputAttemptWhenModal();
  32280. }
  32281. void Component::paint (Graphics&)
  32282. {
  32283. // all painting is done in the subclasses
  32284. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32285. }
  32286. void Component::paintOverChildren (Graphics&)
  32287. {
  32288. // all painting is done in the subclasses
  32289. }
  32290. void Component::handleMessage (const Message& message)
  32291. {
  32292. if (message.intParameter1 == exitModalStateMessage)
  32293. {
  32294. exitModalState (message.intParameter2);
  32295. }
  32296. else if (message.intParameter1 == customCommandMessage)
  32297. {
  32298. handleCommandMessage (message.intParameter2);
  32299. }
  32300. }
  32301. void Component::postCommandMessage (const int commandId)
  32302. {
  32303. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32304. }
  32305. void Component::handleCommandMessage (int)
  32306. {
  32307. // used by subclasses
  32308. }
  32309. void Component::addMouseListener (MouseListener* const newListener,
  32310. const bool wantsEventsForAllNestedChildComponents)
  32311. {
  32312. // if component methods are being called from threads other than the message
  32313. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32314. checkMessageManagerIsLocked
  32315. if (mouseListeners_ == 0)
  32316. mouseListeners_ = new Array<MouseListener*>();
  32317. if (! mouseListeners_->contains (newListener))
  32318. {
  32319. if (wantsEventsForAllNestedChildComponents)
  32320. {
  32321. mouseListeners_->insert (0, newListener);
  32322. ++numDeepMouseListeners;
  32323. }
  32324. else
  32325. {
  32326. mouseListeners_->add (newListener);
  32327. }
  32328. }
  32329. }
  32330. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32331. {
  32332. // if component methods are being called from threads other than the message
  32333. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32334. checkMessageManagerIsLocked
  32335. if (mouseListeners_ != 0)
  32336. {
  32337. const int index = mouseListeners_->indexOf (listenerToRemove);
  32338. if (index >= 0)
  32339. {
  32340. if (index < numDeepMouseListeners)
  32341. --numDeepMouseListeners;
  32342. mouseListeners_->remove (index);
  32343. }
  32344. }
  32345. }
  32346. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32347. {
  32348. if (isCurrentlyBlockedByAnotherModalComponent())
  32349. {
  32350. // if something else is modal, always just show a normal mouse cursor
  32351. source.showMouseCursor (MouseCursor::NormalCursor);
  32352. return;
  32353. }
  32354. if (! flags.mouseInsideFlag)
  32355. {
  32356. flags.mouseInsideFlag = true;
  32357. flags.mouseOverFlag = true;
  32358. flags.draggingFlag = false;
  32359. BailOutChecker checker (this);
  32360. if (flags.repaintOnMouseActivityFlag)
  32361. repaint();
  32362. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32363. this, time, relativePos,
  32364. time, 0, false);
  32365. mouseEnter (me);
  32366. if (checker.shouldBailOut())
  32367. return;
  32368. Desktop::getInstance().resetTimer();
  32369. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32370. if (checker.shouldBailOut())
  32371. return;
  32372. if (mouseListeners_ != 0)
  32373. {
  32374. for (int i = mouseListeners_->size(); --i >= 0;)
  32375. {
  32376. mouseListeners_->getUnchecked(i)->mouseEnter (me);
  32377. if (checker.shouldBailOut())
  32378. return;
  32379. i = jmin (i, mouseListeners_->size());
  32380. }
  32381. }
  32382. Component* p = parentComponent_;
  32383. while (p != 0)
  32384. {
  32385. if (p->numDeepMouseListeners > 0)
  32386. {
  32387. BailOutChecker checker (this, p);
  32388. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32389. {
  32390. p->mouseListeners_->getUnchecked(i)->mouseEnter (me);
  32391. if (checker.shouldBailOut())
  32392. return;
  32393. i = jmin (i, p->numDeepMouseListeners);
  32394. }
  32395. }
  32396. p = p->parentComponent_;
  32397. }
  32398. }
  32399. }
  32400. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32401. {
  32402. BailOutChecker checker (this);
  32403. if (flags.draggingFlag)
  32404. {
  32405. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32406. if (checker.shouldBailOut())
  32407. return;
  32408. }
  32409. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32410. {
  32411. flags.mouseInsideFlag = false;
  32412. flags.mouseOverFlag = false;
  32413. flags.draggingFlag = false;
  32414. if (flags.repaintOnMouseActivityFlag)
  32415. repaint();
  32416. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32417. this, time, relativePos,
  32418. time, 0, false);
  32419. mouseExit (me);
  32420. if (checker.shouldBailOut())
  32421. return;
  32422. Desktop::getInstance().resetTimer();
  32423. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32424. if (checker.shouldBailOut())
  32425. return;
  32426. if (mouseListeners_ != 0)
  32427. {
  32428. for (int i = mouseListeners_->size(); --i >= 0;)
  32429. {
  32430. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32431. if (checker.shouldBailOut())
  32432. return;
  32433. i = jmin (i, mouseListeners_->size());
  32434. }
  32435. }
  32436. Component* p = parentComponent_;
  32437. while (p != 0)
  32438. {
  32439. if (p->numDeepMouseListeners > 0)
  32440. {
  32441. BailOutChecker checker (this, p);
  32442. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32443. {
  32444. p->mouseListeners_->getUnchecked (i)->mouseExit (me);
  32445. if (checker.shouldBailOut())
  32446. return;
  32447. i = jmin (i, p->numDeepMouseListeners);
  32448. }
  32449. }
  32450. p = p->parentComponent_;
  32451. }
  32452. }
  32453. }
  32454. class InternalDragRepeater : public Timer
  32455. {
  32456. public:
  32457. InternalDragRepeater()
  32458. {}
  32459. ~InternalDragRepeater()
  32460. {
  32461. clearSingletonInstance();
  32462. }
  32463. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32464. void timerCallback()
  32465. {
  32466. Desktop& desktop = Desktop::getInstance();
  32467. int numMiceDown = 0;
  32468. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32469. {
  32470. MouseInputSource* const source = desktop.getMouseSource(i);
  32471. if (source->isDragging())
  32472. {
  32473. source->triggerFakeMove();
  32474. ++numMiceDown;
  32475. }
  32476. }
  32477. if (numMiceDown == 0)
  32478. deleteInstance();
  32479. }
  32480. juce_UseDebuggingNewOperator
  32481. private:
  32482. InternalDragRepeater (const InternalDragRepeater&);
  32483. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32484. };
  32485. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32486. void Component::beginDragAutoRepeat (const int interval)
  32487. {
  32488. if (interval > 0)
  32489. {
  32490. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32491. InternalDragRepeater::getInstance()->startTimer (interval);
  32492. }
  32493. else
  32494. {
  32495. InternalDragRepeater::deleteInstance();
  32496. }
  32497. }
  32498. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32499. {
  32500. Desktop& desktop = Desktop::getInstance();
  32501. BailOutChecker checker (this);
  32502. if (isCurrentlyBlockedByAnotherModalComponent())
  32503. {
  32504. internalModalInputAttempt();
  32505. if (checker.shouldBailOut())
  32506. return;
  32507. // If processing the input attempt has exited the modal loop, we'll allow the event
  32508. // to be delivered..
  32509. if (isCurrentlyBlockedByAnotherModalComponent())
  32510. {
  32511. // allow blocked mouse-events to go to global listeners..
  32512. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32513. this, time, relativePos, time,
  32514. source.getNumberOfMultipleClicks(), false);
  32515. desktop.resetTimer();
  32516. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32517. return;
  32518. }
  32519. }
  32520. {
  32521. Component* c = this;
  32522. while (c != 0)
  32523. {
  32524. if (c->isBroughtToFrontOnMouseClick())
  32525. {
  32526. c->toFront (true);
  32527. if (checker.shouldBailOut())
  32528. return;
  32529. }
  32530. c = c->parentComponent_;
  32531. }
  32532. }
  32533. if (! flags.dontFocusOnMouseClickFlag)
  32534. {
  32535. grabFocusInternal (focusChangedByMouseClick);
  32536. if (checker.shouldBailOut())
  32537. return;
  32538. }
  32539. flags.draggingFlag = true;
  32540. flags.mouseOverFlag = true;
  32541. if (flags.repaintOnMouseActivityFlag)
  32542. repaint();
  32543. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32544. this, time, relativePos, time,
  32545. source.getNumberOfMultipleClicks(), false);
  32546. mouseDown (me);
  32547. if (checker.shouldBailOut())
  32548. return;
  32549. desktop.resetTimer();
  32550. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32551. if (checker.shouldBailOut())
  32552. return;
  32553. if (mouseListeners_ != 0)
  32554. {
  32555. for (int i = mouseListeners_->size(); --i >= 0;)
  32556. {
  32557. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32558. if (checker.shouldBailOut())
  32559. return;
  32560. i = jmin (i, mouseListeners_->size());
  32561. }
  32562. }
  32563. Component* p = parentComponent_;
  32564. while (p != 0)
  32565. {
  32566. if (p->numDeepMouseListeners > 0)
  32567. {
  32568. BailOutChecker checker (this, p);
  32569. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32570. {
  32571. p->mouseListeners_->getUnchecked (i)->mouseDown (me);
  32572. if (checker.shouldBailOut())
  32573. return;
  32574. i = jmin (i, p->numDeepMouseListeners);
  32575. }
  32576. }
  32577. p = p->parentComponent_;
  32578. }
  32579. }
  32580. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32581. {
  32582. if (flags.draggingFlag)
  32583. {
  32584. Desktop& desktop = Desktop::getInstance();
  32585. flags.draggingFlag = false;
  32586. BailOutChecker checker (this);
  32587. if (flags.repaintOnMouseActivityFlag)
  32588. repaint();
  32589. const MouseEvent me (source, relativePos,
  32590. oldModifiers, this, time,
  32591. globalPositionToRelative (source.getLastMouseDownPosition()),
  32592. source.getLastMouseDownTime(),
  32593. source.getNumberOfMultipleClicks(),
  32594. source.hasMouseMovedSignificantlySincePressed());
  32595. mouseUp (me);
  32596. if (checker.shouldBailOut())
  32597. return;
  32598. desktop.resetTimer();
  32599. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32600. if (checker.shouldBailOut())
  32601. return;
  32602. if (mouseListeners_ != 0)
  32603. {
  32604. for (int i = mouseListeners_->size(); --i >= 0;)
  32605. {
  32606. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32607. if (checker.shouldBailOut())
  32608. return;
  32609. i = jmin (i, mouseListeners_->size());
  32610. }
  32611. }
  32612. {
  32613. Component* p = parentComponent_;
  32614. while (p != 0)
  32615. {
  32616. if (p->numDeepMouseListeners > 0)
  32617. {
  32618. BailOutChecker checker (this, p);
  32619. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32620. {
  32621. p->mouseListeners_->getUnchecked (i)->mouseUp (me);
  32622. if (checker.shouldBailOut())
  32623. return;
  32624. i = jmin (i, p->numDeepMouseListeners);
  32625. }
  32626. }
  32627. p = p->parentComponent_;
  32628. }
  32629. }
  32630. // check for double-click
  32631. if (me.getNumberOfClicks() >= 2)
  32632. {
  32633. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32634. mouseDoubleClick (me);
  32635. if (checker.shouldBailOut())
  32636. return;
  32637. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32638. if (checker.shouldBailOut())
  32639. return;
  32640. for (int i = numListeners; --i >= 0;)
  32641. {
  32642. if (checker.shouldBailOut())
  32643. return;
  32644. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32645. if (ml != 0)
  32646. ml->mouseDoubleClick (me);
  32647. }
  32648. if (checker.shouldBailOut())
  32649. return;
  32650. Component* p = parentComponent_;
  32651. while (p != 0)
  32652. {
  32653. if (p->numDeepMouseListeners > 0)
  32654. {
  32655. BailOutChecker checker (this, p);
  32656. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32657. {
  32658. p->mouseListeners_->getUnchecked (i)->mouseDoubleClick (me);
  32659. if (checker.shouldBailOut())
  32660. return;
  32661. i = jmin (i, p->numDeepMouseListeners);
  32662. }
  32663. }
  32664. p = p->parentComponent_;
  32665. }
  32666. }
  32667. }
  32668. }
  32669. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32670. {
  32671. if (flags.draggingFlag)
  32672. {
  32673. Desktop& desktop = Desktop::getInstance();
  32674. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32675. BailOutChecker checker (this);
  32676. const MouseEvent me (source, relativePos,
  32677. source.getCurrentModifiers(), this, time,
  32678. globalPositionToRelative (source.getLastMouseDownPosition()),
  32679. source.getLastMouseDownTime(),
  32680. source.getNumberOfMultipleClicks(),
  32681. source.hasMouseMovedSignificantlySincePressed());
  32682. mouseDrag (me);
  32683. if (checker.shouldBailOut())
  32684. return;
  32685. desktop.resetTimer();
  32686. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32687. if (checker.shouldBailOut())
  32688. return;
  32689. if (mouseListeners_ != 0)
  32690. {
  32691. for (int i = mouseListeners_->size(); --i >= 0;)
  32692. {
  32693. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32694. if (checker.shouldBailOut())
  32695. return;
  32696. i = jmin (i, mouseListeners_->size());
  32697. }
  32698. }
  32699. Component* p = parentComponent_;
  32700. while (p != 0)
  32701. {
  32702. if (p->numDeepMouseListeners > 0)
  32703. {
  32704. BailOutChecker checker (this, p);
  32705. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32706. {
  32707. p->mouseListeners_->getUnchecked (i)->mouseDrag (me);
  32708. if (checker.shouldBailOut())
  32709. return;
  32710. i = jmin (i, p->numDeepMouseListeners);
  32711. }
  32712. }
  32713. p = p->parentComponent_;
  32714. }
  32715. }
  32716. }
  32717. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32718. {
  32719. Desktop& desktop = Desktop::getInstance();
  32720. BailOutChecker checker (this);
  32721. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32722. this, time, relativePos,
  32723. time, 0, false);
  32724. if (isCurrentlyBlockedByAnotherModalComponent())
  32725. {
  32726. // allow blocked mouse-events to go to global listeners..
  32727. desktop.sendMouseMove();
  32728. }
  32729. else
  32730. {
  32731. flags.mouseOverFlag = true;
  32732. mouseMove (me);
  32733. if (checker.shouldBailOut())
  32734. return;
  32735. desktop.resetTimer();
  32736. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32737. if (checker.shouldBailOut())
  32738. return;
  32739. if (mouseListeners_ != 0)
  32740. {
  32741. for (int i = mouseListeners_->size(); --i >= 0;)
  32742. {
  32743. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  32744. if (checker.shouldBailOut())
  32745. return;
  32746. i = jmin (i, mouseListeners_->size());
  32747. }
  32748. }
  32749. Component* p = parentComponent_;
  32750. while (p != 0)
  32751. {
  32752. if (p->numDeepMouseListeners > 0)
  32753. {
  32754. BailOutChecker checker (this, p);
  32755. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32756. {
  32757. p->mouseListeners_->getUnchecked (i)->mouseMove (me);
  32758. if (checker.shouldBailOut())
  32759. return;
  32760. i = jmin (i, p->numDeepMouseListeners);
  32761. }
  32762. }
  32763. p = p->parentComponent_;
  32764. }
  32765. }
  32766. }
  32767. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  32768. const Time& time, const float amountX, const float amountY)
  32769. {
  32770. Desktop& desktop = Desktop::getInstance();
  32771. BailOutChecker checker (this);
  32772. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  32773. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  32774. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32775. this, time, relativePos, time, 0, false);
  32776. if (isCurrentlyBlockedByAnotherModalComponent())
  32777. {
  32778. // allow blocked mouse-events to go to global listeners..
  32779. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32780. }
  32781. else
  32782. {
  32783. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32784. if (checker.shouldBailOut())
  32785. return;
  32786. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32787. if (checker.shouldBailOut())
  32788. return;
  32789. if (mouseListeners_ != 0)
  32790. {
  32791. for (int i = mouseListeners_->size(); --i >= 0;)
  32792. {
  32793. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32794. if (checker.shouldBailOut())
  32795. return;
  32796. i = jmin (i, mouseListeners_->size());
  32797. }
  32798. }
  32799. Component* p = parentComponent_;
  32800. while (p != 0)
  32801. {
  32802. if (p->numDeepMouseListeners > 0)
  32803. {
  32804. BailOutChecker checker (this, p);
  32805. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32806. {
  32807. p->mouseListeners_->getUnchecked (i)->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32808. if (checker.shouldBailOut())
  32809. return;
  32810. i = jmin (i, p->numDeepMouseListeners);
  32811. }
  32812. }
  32813. p = p->parentComponent_;
  32814. }
  32815. }
  32816. }
  32817. void Component::sendFakeMouseMove() const
  32818. {
  32819. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  32820. }
  32821. void Component::broughtToFront()
  32822. {
  32823. }
  32824. void Component::internalBroughtToFront()
  32825. {
  32826. if (! isValidComponent())
  32827. return;
  32828. if (flags.hasHeavyweightPeerFlag)
  32829. Desktop::getInstance().componentBroughtToFront (this);
  32830. BailOutChecker checker (this);
  32831. broughtToFront();
  32832. if (checker.shouldBailOut())
  32833. return;
  32834. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  32835. if (checker.shouldBailOut())
  32836. return;
  32837. // When brought to the front and there's a modal component blocking this one,
  32838. // we need to bring the modal one to the front instead..
  32839. Component* const cm = getCurrentlyModalComponent();
  32840. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  32841. bringModalComponentToFront();
  32842. }
  32843. void Component::focusGained (FocusChangeType)
  32844. {
  32845. // base class does nothing
  32846. }
  32847. void Component::internalFocusGain (const FocusChangeType cause)
  32848. {
  32849. SafePointer<Component> safePointer (this);
  32850. focusGained (cause);
  32851. if (safePointer != 0)
  32852. internalChildFocusChange (cause);
  32853. }
  32854. void Component::focusLost (FocusChangeType)
  32855. {
  32856. // base class does nothing
  32857. }
  32858. void Component::internalFocusLoss (const FocusChangeType cause)
  32859. {
  32860. SafePointer<Component> safePointer (this);
  32861. focusLost (focusChangedDirectly);
  32862. if (safePointer != 0)
  32863. internalChildFocusChange (cause);
  32864. }
  32865. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  32866. {
  32867. // base class does nothing
  32868. }
  32869. void Component::internalChildFocusChange (FocusChangeType cause)
  32870. {
  32871. const bool childIsNowFocused = hasKeyboardFocus (true);
  32872. if (flags.childCompFocusedFlag != childIsNowFocused)
  32873. {
  32874. flags.childCompFocusedFlag = childIsNowFocused;
  32875. SafePointer<Component> safePointer (this);
  32876. focusOfChildComponentChanged (cause);
  32877. if (safePointer == 0)
  32878. return;
  32879. }
  32880. if (parentComponent_ != 0)
  32881. parentComponent_->internalChildFocusChange (cause);
  32882. }
  32883. bool Component::isEnabled() const throw()
  32884. {
  32885. return (! flags.isDisabledFlag)
  32886. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  32887. }
  32888. void Component::setEnabled (const bool shouldBeEnabled)
  32889. {
  32890. if (flags.isDisabledFlag == shouldBeEnabled)
  32891. {
  32892. flags.isDisabledFlag = ! shouldBeEnabled;
  32893. // if any parent components are disabled, setting our flag won't make a difference,
  32894. // so no need to send a change message
  32895. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  32896. sendEnablementChangeMessage();
  32897. }
  32898. }
  32899. void Component::sendEnablementChangeMessage()
  32900. {
  32901. SafePointer<Component> safePointer (this);
  32902. enablementChanged();
  32903. if (safePointer == 0)
  32904. return;
  32905. for (int i = getNumChildComponents(); --i >= 0;)
  32906. {
  32907. Component* const c = getChildComponent (i);
  32908. if (c != 0)
  32909. {
  32910. c->sendEnablementChangeMessage();
  32911. if (safePointer == 0)
  32912. return;
  32913. }
  32914. }
  32915. }
  32916. void Component::enablementChanged()
  32917. {
  32918. }
  32919. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  32920. {
  32921. flags.wantsFocusFlag = wantsFocus;
  32922. }
  32923. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  32924. {
  32925. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  32926. }
  32927. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  32928. {
  32929. return ! flags.dontFocusOnMouseClickFlag;
  32930. }
  32931. bool Component::getWantsKeyboardFocus() const throw()
  32932. {
  32933. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  32934. }
  32935. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  32936. {
  32937. flags.isFocusContainerFlag = shouldBeFocusContainer;
  32938. }
  32939. bool Component::isFocusContainer() const throw()
  32940. {
  32941. return flags.isFocusContainerFlag;
  32942. }
  32943. int Component::getExplicitFocusOrder() const
  32944. {
  32945. return properties ["_jexfo"];
  32946. }
  32947. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  32948. {
  32949. properties.set ("_jexfo", newFocusOrderIndex);
  32950. }
  32951. KeyboardFocusTraverser* Component::createFocusTraverser()
  32952. {
  32953. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  32954. return new KeyboardFocusTraverser();
  32955. return parentComponent_->createFocusTraverser();
  32956. }
  32957. void Component::takeKeyboardFocus (const FocusChangeType cause)
  32958. {
  32959. // give the focus to this component
  32960. if (currentlyFocusedComponent != this)
  32961. {
  32962. JUCE_TRY
  32963. {
  32964. // get the focus onto our desktop window
  32965. ComponentPeer* const peer = getPeer();
  32966. if (peer != 0)
  32967. {
  32968. SafePointer<Component> safePointer (this);
  32969. peer->grabFocus();
  32970. if (peer->isFocused() && currentlyFocusedComponent != this)
  32971. {
  32972. Component* const componentLosingFocus = currentlyFocusedComponent;
  32973. currentlyFocusedComponent = this;
  32974. Desktop::getInstance().triggerFocusCallback();
  32975. // call this after setting currentlyFocusedComponent so that the one that's
  32976. // losing it has a chance to see where focus is going
  32977. if (componentLosingFocus->isValidComponent())
  32978. componentLosingFocus->internalFocusLoss (cause);
  32979. if (currentlyFocusedComponent == this)
  32980. {
  32981. focusGained (cause);
  32982. if (safePointer != 0)
  32983. internalChildFocusChange (cause);
  32984. }
  32985. }
  32986. }
  32987. }
  32988. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32989. catch (const std::exception& e)
  32990. {
  32991. currentlyFocusedComponent = 0;
  32992. Desktop::getInstance().triggerFocusCallback();
  32993. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32994. }
  32995. catch (...)
  32996. {
  32997. currentlyFocusedComponent = 0;
  32998. Desktop::getInstance().triggerFocusCallback();
  32999. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33000. }
  33001. #endif
  33002. }
  33003. }
  33004. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33005. {
  33006. if (isShowing())
  33007. {
  33008. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33009. {
  33010. takeKeyboardFocus (cause);
  33011. }
  33012. else
  33013. {
  33014. if (isParentOf (currentlyFocusedComponent)
  33015. && currentlyFocusedComponent->isShowing())
  33016. {
  33017. // do nothing if the focused component is actually a child of ours..
  33018. }
  33019. else
  33020. {
  33021. // find the default child component..
  33022. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33023. if (traverser != 0)
  33024. {
  33025. Component* const defaultComp = traverser->getDefaultComponent (this);
  33026. traverser = 0;
  33027. if (defaultComp != 0)
  33028. {
  33029. defaultComp->grabFocusInternal (cause, false);
  33030. return;
  33031. }
  33032. }
  33033. if (canTryParent && parentComponent_ != 0)
  33034. {
  33035. // if no children want it and we're allowed to try our parent comp,
  33036. // then pass up to parent, which will try our siblings.
  33037. parentComponent_->grabFocusInternal (cause, true);
  33038. }
  33039. }
  33040. }
  33041. }
  33042. }
  33043. void Component::grabKeyboardFocus()
  33044. {
  33045. // if component methods are being called from threads other than the message
  33046. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33047. checkMessageManagerIsLocked
  33048. grabFocusInternal (focusChangedDirectly);
  33049. }
  33050. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33051. {
  33052. // if component methods are being called from threads other than the message
  33053. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33054. checkMessageManagerIsLocked
  33055. if (parentComponent_ != 0)
  33056. {
  33057. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33058. if (traverser != 0)
  33059. {
  33060. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33061. : traverser->getPreviousComponent (this);
  33062. traverser = 0;
  33063. if (nextComp != 0)
  33064. {
  33065. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33066. {
  33067. SafePointer<Component> nextCompPointer (nextComp);
  33068. internalModalInputAttempt();
  33069. if (nextCompPointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33070. return;
  33071. }
  33072. nextComp->grabFocusInternal (focusChangedByTabKey);
  33073. return;
  33074. }
  33075. }
  33076. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33077. }
  33078. }
  33079. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33080. {
  33081. return (currentlyFocusedComponent == this)
  33082. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33083. }
  33084. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33085. {
  33086. return currentlyFocusedComponent;
  33087. }
  33088. void Component::giveAwayFocus()
  33089. {
  33090. // use a copy so we can clear the value before the call
  33091. Component* const componentLosingFocus = currentlyFocusedComponent;
  33092. currentlyFocusedComponent = 0;
  33093. Desktop::getInstance().triggerFocusCallback();
  33094. if (componentLosingFocus->isValidComponent())
  33095. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33096. }
  33097. bool Component::isMouseOver() const throw()
  33098. {
  33099. return flags.mouseOverFlag;
  33100. }
  33101. bool Component::isMouseButtonDown() const throw()
  33102. {
  33103. return flags.draggingFlag;
  33104. }
  33105. bool Component::isMouseOverOrDragging() const throw()
  33106. {
  33107. return flags.mouseOverFlag || flags.draggingFlag;
  33108. }
  33109. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33110. {
  33111. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33112. }
  33113. const Point<int> Component::getMouseXYRelative() const
  33114. {
  33115. return globalPositionToRelative (Desktop::getMousePosition());
  33116. }
  33117. const Rectangle<int> Component::getParentMonitorArea() const
  33118. {
  33119. return Desktop::getInstance()
  33120. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33121. getHeight() / 2)));
  33122. }
  33123. void Component::addKeyListener (KeyListener* const newListener)
  33124. {
  33125. if (keyListeners_ == 0)
  33126. keyListeners_ = new VoidArray();
  33127. keyListeners_->addIfNotAlreadyThere (newListener);
  33128. }
  33129. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33130. {
  33131. if (keyListeners_ != 0)
  33132. keyListeners_->removeValue (listenerToRemove);
  33133. }
  33134. bool Component::keyPressed (const KeyPress&)
  33135. {
  33136. return false;
  33137. }
  33138. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33139. {
  33140. return false;
  33141. }
  33142. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33143. {
  33144. if (parentComponent_ != 0)
  33145. parentComponent_->modifierKeysChanged (modifiers);
  33146. }
  33147. void Component::internalModifierKeysChanged()
  33148. {
  33149. sendFakeMouseMove();
  33150. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33151. }
  33152. ComponentPeer* Component::getPeer() const
  33153. {
  33154. if (flags.hasHeavyweightPeerFlag)
  33155. return ComponentPeer::getPeerFor (this);
  33156. else if (parentComponent_ != 0)
  33157. return parentComponent_->getPeer();
  33158. else
  33159. return 0;
  33160. }
  33161. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33162. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33163. {
  33164. jassert (component1 != 0);
  33165. }
  33166. bool Component::BailOutChecker::shouldBailOut() const throw()
  33167. {
  33168. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33169. }
  33170. END_JUCE_NAMESPACE
  33171. /*** End of inlined file: juce_Component.cpp ***/
  33172. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33173. BEGIN_JUCE_NAMESPACE
  33174. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33175. void ComponentListener::componentBroughtToFront (Component&) {}
  33176. void ComponentListener::componentVisibilityChanged (Component&) {}
  33177. void ComponentListener::componentChildrenChanged (Component&) {}
  33178. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33179. void ComponentListener::componentNameChanged (Component&) {}
  33180. void ComponentListener::componentBeingDeleted (Component&) {}
  33181. END_JUCE_NAMESPACE
  33182. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33183. /*** Start of inlined file: juce_Desktop.cpp ***/
  33184. BEGIN_JUCE_NAMESPACE
  33185. Desktop::Desktop()
  33186. : mouseClickCounter (0),
  33187. kioskModeComponent (0)
  33188. {
  33189. createMouseInputSources();
  33190. refreshMonitorSizes();
  33191. }
  33192. Desktop::~Desktop()
  33193. {
  33194. jassert (instance == this);
  33195. instance = 0;
  33196. // doh! If you don't delete all your windows before exiting, you're going to
  33197. // be leaking memory!
  33198. jassert (desktopComponents.size() == 0);
  33199. }
  33200. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33201. {
  33202. if (instance == 0)
  33203. instance = new Desktop();
  33204. return *instance;
  33205. }
  33206. Desktop* Desktop::instance = 0;
  33207. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33208. const bool clipToWorkArea);
  33209. void Desktop::refreshMonitorSizes()
  33210. {
  33211. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33212. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33213. monitorCoordsClipped.clear();
  33214. monitorCoordsUnclipped.clear();
  33215. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33216. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33217. jassert (monitorCoordsClipped.size() > 0
  33218. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33219. if (oldClipped != monitorCoordsClipped
  33220. || oldUnclipped != monitorCoordsUnclipped)
  33221. {
  33222. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33223. {
  33224. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33225. if (p != 0)
  33226. p->handleScreenSizeChange();
  33227. }
  33228. }
  33229. }
  33230. int Desktop::getNumDisplayMonitors() const throw()
  33231. {
  33232. return monitorCoordsClipped.size();
  33233. }
  33234. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33235. {
  33236. return clippedToWorkArea ? monitorCoordsClipped [index]
  33237. : monitorCoordsUnclipped [index];
  33238. }
  33239. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33240. {
  33241. RectangleList rl;
  33242. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33243. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33244. return rl;
  33245. }
  33246. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33247. {
  33248. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33249. }
  33250. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33251. {
  33252. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33253. double bestDistance = 1.0e10;
  33254. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33255. {
  33256. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33257. if (rect.contains (position))
  33258. return rect;
  33259. const double distance = rect.getCentre().getDistanceFrom (position);
  33260. if (distance < bestDistance)
  33261. {
  33262. bestDistance = distance;
  33263. best = rect;
  33264. }
  33265. }
  33266. return best;
  33267. }
  33268. int Desktop::getNumComponents() const throw()
  33269. {
  33270. return desktopComponents.size();
  33271. }
  33272. Component* Desktop::getComponent (const int index) const throw()
  33273. {
  33274. return desktopComponents [index];
  33275. }
  33276. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33277. {
  33278. for (int i = desktopComponents.size(); --i >= 0;)
  33279. {
  33280. Component* const c = desktopComponents.getUnchecked(i);
  33281. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33282. if (c->contains (relative.getX(), relative.getY()))
  33283. return c->getComponentAt (relative.getX(), relative.getY());
  33284. }
  33285. return 0;
  33286. }
  33287. void Desktop::addDesktopComponent (Component* const c)
  33288. {
  33289. jassert (c != 0);
  33290. jassert (! desktopComponents.contains (c));
  33291. desktopComponents.addIfNotAlreadyThere (c);
  33292. }
  33293. void Desktop::removeDesktopComponent (Component* const c)
  33294. {
  33295. desktopComponents.removeValue (c);
  33296. }
  33297. void Desktop::componentBroughtToFront (Component* const c)
  33298. {
  33299. const int index = desktopComponents.indexOf (c);
  33300. jassert (index >= 0);
  33301. if (index >= 0)
  33302. {
  33303. int newIndex = -1;
  33304. if (! c->isAlwaysOnTop())
  33305. {
  33306. newIndex = desktopComponents.size();
  33307. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33308. --newIndex;
  33309. --newIndex;
  33310. }
  33311. desktopComponents.move (index, newIndex);
  33312. }
  33313. }
  33314. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33315. {
  33316. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33317. }
  33318. int Desktop::getMouseButtonClickCounter() throw()
  33319. {
  33320. return getInstance().mouseClickCounter;
  33321. }
  33322. void Desktop::incrementMouseClickCounter() throw()
  33323. {
  33324. ++mouseClickCounter;
  33325. }
  33326. int Desktop::getNumDraggingMouseSources() const throw()
  33327. {
  33328. int num = 0;
  33329. for (int i = mouseSources.size(); --i >= 0;)
  33330. if (mouseSources.getUnchecked(i)->isDragging())
  33331. ++num;
  33332. return num;
  33333. }
  33334. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33335. {
  33336. int num = 0;
  33337. for (int i = mouseSources.size(); --i >= 0;)
  33338. {
  33339. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33340. if (mi->isDragging())
  33341. {
  33342. if (index == num)
  33343. return mi;
  33344. ++num;
  33345. }
  33346. }
  33347. return 0;
  33348. }
  33349. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33350. {
  33351. focusListeners.add (listener);
  33352. }
  33353. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33354. {
  33355. focusListeners.remove (listener);
  33356. }
  33357. void Desktop::triggerFocusCallback()
  33358. {
  33359. triggerAsyncUpdate();
  33360. }
  33361. void Desktop::handleAsyncUpdate()
  33362. {
  33363. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33364. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33365. }
  33366. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33367. {
  33368. mouseListeners.add (listener);
  33369. resetTimer();
  33370. }
  33371. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33372. {
  33373. mouseListeners.remove (listener);
  33374. resetTimer();
  33375. }
  33376. void Desktop::timerCallback()
  33377. {
  33378. if (lastFakeMouseMove != getMousePosition())
  33379. sendMouseMove();
  33380. }
  33381. void Desktop::sendMouseMove()
  33382. {
  33383. if (! mouseListeners.isEmpty())
  33384. {
  33385. startTimer (20);
  33386. lastFakeMouseMove = getMousePosition();
  33387. Component* const target = findComponentAt (lastFakeMouseMove);
  33388. if (target != 0)
  33389. {
  33390. Component::BailOutChecker checker (target);
  33391. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33392. const Time now (Time::getCurrentTime());
  33393. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33394. target, now, pos, now, 0, false);
  33395. if (me.mods.isAnyMouseButtonDown())
  33396. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33397. else
  33398. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33399. }
  33400. }
  33401. }
  33402. void Desktop::resetTimer()
  33403. {
  33404. if (mouseListeners.size() == 0)
  33405. stopTimer();
  33406. else
  33407. startTimer (100);
  33408. lastFakeMouseMove = getMousePosition();
  33409. }
  33410. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33411. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33412. {
  33413. if (kioskModeComponent != componentToUse)
  33414. {
  33415. // agh! Don't delete a component without first stopping it being the kiosk comp
  33416. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33417. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33418. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33419. if (kioskModeComponent->isValidComponent())
  33420. {
  33421. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33422. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33423. }
  33424. kioskModeComponent = componentToUse;
  33425. if (kioskModeComponent != 0)
  33426. {
  33427. jassert (kioskModeComponent->isValidComponent());
  33428. // Only components that are already on the desktop can be put into kiosk mode!
  33429. jassert (kioskModeComponent->isOnDesktop());
  33430. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33431. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33432. }
  33433. }
  33434. }
  33435. END_JUCE_NAMESPACE
  33436. /*** End of inlined file: juce_Desktop.cpp ***/
  33437. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33438. BEGIN_JUCE_NAMESPACE
  33439. ArrowButton::ArrowButton (const String& name,
  33440. float arrowDirectionInRadians,
  33441. const Colour& arrowColour)
  33442. : Button (name),
  33443. colour (arrowColour)
  33444. {
  33445. path.lineTo (0.0f, 1.0f);
  33446. path.lineTo (1.0f, 0.5f);
  33447. path.closeSubPath();
  33448. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33449. 0.5f, 0.5f));
  33450. setComponentEffect (&shadow);
  33451. buttonStateChanged();
  33452. }
  33453. ArrowButton::~ArrowButton()
  33454. {
  33455. }
  33456. void ArrowButton::paintButton (Graphics& g,
  33457. bool /*isMouseOverButton*/,
  33458. bool /*isButtonDown*/)
  33459. {
  33460. g.setColour (colour);
  33461. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33462. (float) offset,
  33463. (float) (getWidth() - 3),
  33464. (float) (getHeight() - 3),
  33465. false));
  33466. }
  33467. void ArrowButton::buttonStateChanged()
  33468. {
  33469. offset = (isDown()) ? 1 : 0;
  33470. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33471. 0.3f, -1, 0);
  33472. }
  33473. END_JUCE_NAMESPACE
  33474. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33475. /*** Start of inlined file: juce_Button.cpp ***/
  33476. BEGIN_JUCE_NAMESPACE
  33477. class Button::RepeatTimer : public Timer
  33478. {
  33479. public:
  33480. RepeatTimer (Button& owner_) : owner (owner_) {}
  33481. void timerCallback() { owner.repeatTimerCallback(); }
  33482. juce_UseDebuggingNewOperator
  33483. private:
  33484. Button& owner;
  33485. RepeatTimer (const RepeatTimer&);
  33486. RepeatTimer& operator= (const RepeatTimer&);
  33487. };
  33488. Button::Button (const String& name)
  33489. : Component (name),
  33490. text (name),
  33491. buttonPressTime (0),
  33492. lastTimeCallbackTime (0),
  33493. commandManagerToUse (0),
  33494. autoRepeatDelay (-1),
  33495. autoRepeatSpeed (0),
  33496. autoRepeatMinimumDelay (-1),
  33497. radioGroupId (0),
  33498. commandID (0),
  33499. connectedEdgeFlags (0),
  33500. buttonState (buttonNormal),
  33501. lastToggleState (false),
  33502. clickTogglesState (false),
  33503. needsToRelease (false),
  33504. needsRepainting (false),
  33505. isKeyDown (false),
  33506. triggerOnMouseDown (false),
  33507. generateTooltip (false)
  33508. {
  33509. setWantsKeyboardFocus (true);
  33510. isOn.addListener (this);
  33511. }
  33512. Button::~Button()
  33513. {
  33514. isOn.removeListener (this);
  33515. if (commandManagerToUse != 0)
  33516. commandManagerToUse->removeListener (this);
  33517. repeatTimer = 0;
  33518. clearShortcuts();
  33519. }
  33520. void Button::setButtonText (const String& newText)
  33521. {
  33522. if (text != newText)
  33523. {
  33524. text = newText;
  33525. repaint();
  33526. }
  33527. }
  33528. void Button::setTooltip (const String& newTooltip)
  33529. {
  33530. SettableTooltipClient::setTooltip (newTooltip);
  33531. generateTooltip = false;
  33532. }
  33533. const String Button::getTooltip()
  33534. {
  33535. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33536. {
  33537. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33538. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33539. for (int i = 0; i < keyPresses.size(); ++i)
  33540. {
  33541. const String key (keyPresses.getReference(i).getTextDescription());
  33542. tt << " [";
  33543. if (key.length() == 1)
  33544. tt << TRANS("shortcut") << ": '" << key << "']";
  33545. else
  33546. tt << key << ']';
  33547. }
  33548. return tt;
  33549. }
  33550. return SettableTooltipClient::getTooltip();
  33551. }
  33552. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33553. {
  33554. if (connectedEdgeFlags != connectedEdgeFlags_)
  33555. {
  33556. connectedEdgeFlags = connectedEdgeFlags_;
  33557. repaint();
  33558. }
  33559. }
  33560. void Button::setToggleState (const bool shouldBeOn,
  33561. const bool sendChangeNotification)
  33562. {
  33563. if (shouldBeOn != lastToggleState)
  33564. {
  33565. isOn = shouldBeOn;
  33566. lastToggleState = shouldBeOn;
  33567. repaint();
  33568. if (sendChangeNotification)
  33569. {
  33570. Component::SafePointer<Component> deletionWatcher (this);
  33571. sendClickMessage (ModifierKeys());
  33572. if (deletionWatcher == 0)
  33573. return;
  33574. }
  33575. if (lastToggleState)
  33576. turnOffOtherButtonsInGroup (sendChangeNotification);
  33577. }
  33578. }
  33579. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33580. {
  33581. clickTogglesState = shouldToggle;
  33582. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33583. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33584. // it is that this button represents, and the button will update its state to reflect this
  33585. // in the applicationCommandListChanged() method.
  33586. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33587. }
  33588. bool Button::getClickingTogglesState() const throw()
  33589. {
  33590. return clickTogglesState;
  33591. }
  33592. void Button::valueChanged (Value& value)
  33593. {
  33594. if (value.refersToSameSourceAs (isOn))
  33595. setToggleState (isOn.getValue(), true);
  33596. }
  33597. void Button::setRadioGroupId (const int newGroupId)
  33598. {
  33599. if (radioGroupId != newGroupId)
  33600. {
  33601. radioGroupId = newGroupId;
  33602. if (lastToggleState)
  33603. turnOffOtherButtonsInGroup (true);
  33604. }
  33605. }
  33606. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33607. {
  33608. Component* const p = getParentComponent();
  33609. if (p != 0 && radioGroupId != 0)
  33610. {
  33611. Component::SafePointer<Component> deletionWatcher (this);
  33612. for (int i = p->getNumChildComponents(); --i >= 0;)
  33613. {
  33614. Component* const c = p->getChildComponent (i);
  33615. if (c != this)
  33616. {
  33617. Button* const b = dynamic_cast <Button*> (c);
  33618. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33619. {
  33620. b->setToggleState (false, sendChangeNotification);
  33621. if (deletionWatcher == 0)
  33622. return;
  33623. }
  33624. }
  33625. }
  33626. }
  33627. }
  33628. void Button::enablementChanged()
  33629. {
  33630. updateState (0);
  33631. repaint();
  33632. }
  33633. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33634. {
  33635. ButtonState state = buttonNormal;
  33636. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33637. {
  33638. Point<int> mousePos;
  33639. if (e == 0)
  33640. mousePos = getMouseXYRelative();
  33641. else
  33642. mousePos = e->getEventRelativeTo (this).getPosition();
  33643. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33644. const bool down = isMouseButtonDown();
  33645. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33646. state = buttonDown;
  33647. else if (over)
  33648. state = buttonOver;
  33649. }
  33650. setState (state);
  33651. return state;
  33652. }
  33653. void Button::setState (const ButtonState newState)
  33654. {
  33655. if (buttonState != newState)
  33656. {
  33657. buttonState = newState;
  33658. repaint();
  33659. if (buttonState == buttonDown)
  33660. {
  33661. buttonPressTime = Time::getApproximateMillisecondCounter();
  33662. lastTimeCallbackTime = buttonPressTime;
  33663. }
  33664. sendStateMessage();
  33665. }
  33666. }
  33667. bool Button::isDown() const throw()
  33668. {
  33669. return buttonState == buttonDown;
  33670. }
  33671. bool Button::isOver() const throw()
  33672. {
  33673. return buttonState != buttonNormal;
  33674. }
  33675. void Button::buttonStateChanged()
  33676. {
  33677. }
  33678. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33679. {
  33680. const uint32 now = Time::getApproximateMillisecondCounter();
  33681. return now > buttonPressTime ? now - buttonPressTime : 0;
  33682. }
  33683. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33684. {
  33685. triggerOnMouseDown = isTriggeredOnMouseDown;
  33686. }
  33687. void Button::clicked()
  33688. {
  33689. }
  33690. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33691. {
  33692. clicked();
  33693. }
  33694. static const int clickMessageId = 0x2f3f4f99;
  33695. void Button::triggerClick()
  33696. {
  33697. postCommandMessage (clickMessageId);
  33698. }
  33699. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33700. {
  33701. if (clickTogglesState)
  33702. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33703. sendClickMessage (modifiers);
  33704. }
  33705. void Button::flashButtonState()
  33706. {
  33707. if (isEnabled())
  33708. {
  33709. needsToRelease = true;
  33710. setState (buttonDown);
  33711. getRepeatTimer().startTimer (100);
  33712. }
  33713. }
  33714. void Button::handleCommandMessage (int commandId)
  33715. {
  33716. if (commandId == clickMessageId)
  33717. {
  33718. if (isEnabled())
  33719. {
  33720. flashButtonState();
  33721. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33722. }
  33723. }
  33724. else
  33725. {
  33726. Component::handleCommandMessage (commandId);
  33727. }
  33728. }
  33729. void Button::addButtonListener (ButtonListener* const newListener)
  33730. {
  33731. buttonListeners.add (newListener);
  33732. }
  33733. void Button::removeButtonListener (ButtonListener* const listener)
  33734. {
  33735. buttonListeners.remove (listener);
  33736. }
  33737. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33738. {
  33739. Component::BailOutChecker checker (this);
  33740. if (commandManagerToUse != 0 && commandID != 0)
  33741. {
  33742. ApplicationCommandTarget::InvocationInfo info (commandID);
  33743. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  33744. info.originatingComponent = this;
  33745. commandManagerToUse->invoke (info, true);
  33746. }
  33747. clicked (modifiers);
  33748. if (! checker.shouldBailOut())
  33749. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  33750. }
  33751. void Button::sendStateMessage()
  33752. {
  33753. Component::BailOutChecker checker (this);
  33754. buttonStateChanged();
  33755. if (! checker.shouldBailOut())
  33756. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  33757. }
  33758. void Button::paint (Graphics& g)
  33759. {
  33760. if (needsToRelease && isEnabled())
  33761. {
  33762. needsToRelease = false;
  33763. needsRepainting = true;
  33764. }
  33765. paintButton (g, isOver(), isDown());
  33766. }
  33767. void Button::mouseEnter (const MouseEvent& e)
  33768. {
  33769. updateState (&e);
  33770. }
  33771. void Button::mouseExit (const MouseEvent& e)
  33772. {
  33773. updateState (&e);
  33774. }
  33775. void Button::mouseDown (const MouseEvent& e)
  33776. {
  33777. updateState (&e);
  33778. if (isDown())
  33779. {
  33780. if (autoRepeatDelay >= 0)
  33781. getRepeatTimer().startTimer (autoRepeatDelay);
  33782. if (triggerOnMouseDown)
  33783. internalClickCallback (e.mods);
  33784. }
  33785. }
  33786. void Button::mouseUp (const MouseEvent& e)
  33787. {
  33788. const bool wasDown = isDown();
  33789. updateState (&e);
  33790. if (wasDown && isOver() && ! triggerOnMouseDown)
  33791. internalClickCallback (e.mods);
  33792. }
  33793. void Button::mouseDrag (const MouseEvent& e)
  33794. {
  33795. const ButtonState oldState = buttonState;
  33796. updateState (&e);
  33797. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  33798. getRepeatTimer().startTimer (autoRepeatSpeed);
  33799. }
  33800. void Button::focusGained (FocusChangeType)
  33801. {
  33802. updateState (0);
  33803. repaint();
  33804. }
  33805. void Button::focusLost (FocusChangeType)
  33806. {
  33807. updateState (0);
  33808. repaint();
  33809. }
  33810. void Button::setVisible (bool shouldBeVisible)
  33811. {
  33812. if (shouldBeVisible != isVisible())
  33813. {
  33814. Component::setVisible (shouldBeVisible);
  33815. if (! shouldBeVisible)
  33816. needsToRelease = false;
  33817. updateState (0);
  33818. }
  33819. else
  33820. {
  33821. Component::setVisible (shouldBeVisible);
  33822. }
  33823. }
  33824. void Button::parentHierarchyChanged()
  33825. {
  33826. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  33827. if (newKeySource != keySource.getComponent())
  33828. {
  33829. if (keySource != 0)
  33830. keySource->removeKeyListener (this);
  33831. keySource = newKeySource;
  33832. if (keySource != 0)
  33833. keySource->addKeyListener (this);
  33834. }
  33835. }
  33836. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  33837. const int commandID_,
  33838. const bool generateTooltip_)
  33839. {
  33840. commandID = commandID_;
  33841. generateTooltip = generateTooltip_;
  33842. if (commandManagerToUse != commandManagerToUse_)
  33843. {
  33844. if (commandManagerToUse != 0)
  33845. commandManagerToUse->removeListener (this);
  33846. commandManagerToUse = commandManagerToUse_;
  33847. if (commandManagerToUse != 0)
  33848. commandManagerToUse->addListener (this);
  33849. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33850. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33851. // it is that this button represents, and the button will update its state to reflect this
  33852. // in the applicationCommandListChanged() method.
  33853. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33854. }
  33855. if (commandManagerToUse != 0)
  33856. applicationCommandListChanged();
  33857. else
  33858. setEnabled (true);
  33859. }
  33860. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  33861. {
  33862. if (info.commandID == commandID
  33863. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  33864. {
  33865. flashButtonState();
  33866. }
  33867. }
  33868. void Button::applicationCommandListChanged()
  33869. {
  33870. if (commandManagerToUse != 0)
  33871. {
  33872. ApplicationCommandInfo info (0);
  33873. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  33874. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  33875. if (target != 0)
  33876. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  33877. }
  33878. }
  33879. void Button::addShortcut (const KeyPress& key)
  33880. {
  33881. if (key.isValid())
  33882. {
  33883. jassert (! isRegisteredForShortcut (key)); // already registered!
  33884. shortcuts.add (key);
  33885. parentHierarchyChanged();
  33886. }
  33887. }
  33888. void Button::clearShortcuts()
  33889. {
  33890. shortcuts.clear();
  33891. parentHierarchyChanged();
  33892. }
  33893. bool Button::isShortcutPressed() const
  33894. {
  33895. if (! isCurrentlyBlockedByAnotherModalComponent())
  33896. {
  33897. for (int i = shortcuts.size(); --i >= 0;)
  33898. if (shortcuts.getReference(i).isCurrentlyDown())
  33899. return true;
  33900. }
  33901. return false;
  33902. }
  33903. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  33904. {
  33905. for (int i = shortcuts.size(); --i >= 0;)
  33906. if (key == shortcuts.getReference(i))
  33907. return true;
  33908. return false;
  33909. }
  33910. bool Button::keyStateChanged (const bool, Component*)
  33911. {
  33912. if (! isEnabled())
  33913. return false;
  33914. const bool wasDown = isKeyDown;
  33915. isKeyDown = isShortcutPressed();
  33916. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  33917. getRepeatTimer().startTimer (autoRepeatDelay);
  33918. updateState (0);
  33919. if (isEnabled() && wasDown && ! isKeyDown)
  33920. {
  33921. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33922. // (return immediately - this button may now have been deleted)
  33923. return true;
  33924. }
  33925. return wasDown || isKeyDown;
  33926. }
  33927. bool Button::keyPressed (const KeyPress&, Component*)
  33928. {
  33929. // returning true will avoid forwarding events for keys that we're using as shortcuts
  33930. return isShortcutPressed();
  33931. }
  33932. bool Button::keyPressed (const KeyPress& key)
  33933. {
  33934. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  33935. {
  33936. triggerClick();
  33937. return true;
  33938. }
  33939. return false;
  33940. }
  33941. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  33942. const int repeatMillisecs,
  33943. const int minimumDelayInMillisecs) throw()
  33944. {
  33945. autoRepeatDelay = initialDelayMillisecs;
  33946. autoRepeatSpeed = repeatMillisecs;
  33947. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  33948. }
  33949. void Button::repeatTimerCallback()
  33950. {
  33951. if (needsRepainting)
  33952. {
  33953. getRepeatTimer().stopTimer();
  33954. updateState (0);
  33955. needsRepainting = false;
  33956. }
  33957. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  33958. {
  33959. int repeatSpeed = autoRepeatSpeed;
  33960. if (autoRepeatMinimumDelay >= 0)
  33961. {
  33962. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  33963. timeHeldDown *= timeHeldDown;
  33964. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  33965. }
  33966. repeatSpeed = jmax (1, repeatSpeed);
  33967. getRepeatTimer().startTimer (repeatSpeed);
  33968. const uint32 now = Time::getApproximateMillisecondCounter();
  33969. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  33970. lastTimeCallbackTime = now;
  33971. Component::SafePointer<Component> deletionWatcher (this);
  33972. for (int i = numTimesToCallback; --i >= 0;)
  33973. {
  33974. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33975. if (deletionWatcher == 0 || ! isDown())
  33976. return;
  33977. }
  33978. }
  33979. else if (! needsToRelease)
  33980. {
  33981. getRepeatTimer().stopTimer();
  33982. }
  33983. }
  33984. Button::RepeatTimer& Button::getRepeatTimer()
  33985. {
  33986. if (repeatTimer == 0)
  33987. repeatTimer = new RepeatTimer (*this);
  33988. return *repeatTimer;
  33989. }
  33990. END_JUCE_NAMESPACE
  33991. /*** End of inlined file: juce_Button.cpp ***/
  33992. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  33993. BEGIN_JUCE_NAMESPACE
  33994. DrawableButton::DrawableButton (const String& name,
  33995. const DrawableButton::ButtonStyle buttonStyle)
  33996. : Button (name),
  33997. style (buttonStyle),
  33998. edgeIndent (3)
  33999. {
  34000. if (buttonStyle == ImageOnButtonBackground)
  34001. {
  34002. backgroundOff = Colour (0xffbbbbff);
  34003. backgroundOn = Colour (0xff3333ff);
  34004. }
  34005. else
  34006. {
  34007. backgroundOff = Colours::transparentBlack;
  34008. backgroundOn = Colour (0xaabbbbff);
  34009. }
  34010. }
  34011. DrawableButton::~DrawableButton()
  34012. {
  34013. deleteImages();
  34014. }
  34015. void DrawableButton::deleteImages()
  34016. {
  34017. }
  34018. void DrawableButton::setImages (const Drawable* normal,
  34019. const Drawable* over,
  34020. const Drawable* down,
  34021. const Drawable* disabled,
  34022. const Drawable* normalOn,
  34023. const Drawable* overOn,
  34024. const Drawable* downOn,
  34025. const Drawable* disabledOn)
  34026. {
  34027. deleteImages();
  34028. jassert (normal != 0); // you really need to give it at least a normal image..
  34029. if (normal != 0)
  34030. normalImage = normal->createCopy();
  34031. if (over != 0)
  34032. overImage = over->createCopy();
  34033. if (down != 0)
  34034. downImage = down->createCopy();
  34035. if (disabled != 0)
  34036. disabledImage = disabled->createCopy();
  34037. if (normalOn != 0)
  34038. normalImageOn = normalOn->createCopy();
  34039. if (overOn != 0)
  34040. overImageOn = overOn->createCopy();
  34041. if (downOn != 0)
  34042. downImageOn = downOn->createCopy();
  34043. if (disabledOn != 0)
  34044. disabledImageOn = disabledOn->createCopy();
  34045. repaint();
  34046. }
  34047. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34048. {
  34049. if (style != newStyle)
  34050. {
  34051. style = newStyle;
  34052. repaint();
  34053. }
  34054. }
  34055. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34056. const Colour& toggledOnColour)
  34057. {
  34058. if (backgroundOff != toggledOffColour
  34059. || backgroundOn != toggledOnColour)
  34060. {
  34061. backgroundOff = toggledOffColour;
  34062. backgroundOn = toggledOnColour;
  34063. repaint();
  34064. }
  34065. }
  34066. const Colour& DrawableButton::getBackgroundColour() const throw()
  34067. {
  34068. return getToggleState() ? backgroundOn
  34069. : backgroundOff;
  34070. }
  34071. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34072. {
  34073. edgeIndent = numPixelsIndent;
  34074. repaint();
  34075. }
  34076. void DrawableButton::paintButton (Graphics& g,
  34077. bool isMouseOverButton,
  34078. bool isButtonDown)
  34079. {
  34080. Rectangle<int> imageSpace;
  34081. if (style == ImageOnButtonBackground)
  34082. {
  34083. const int insetX = getWidth() / 4;
  34084. const int insetY = getHeight() / 4;
  34085. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34086. getLookAndFeel().drawButtonBackground (g, *this,
  34087. getBackgroundColour(),
  34088. isMouseOverButton,
  34089. isButtonDown);
  34090. }
  34091. else
  34092. {
  34093. g.fillAll (getBackgroundColour());
  34094. const int textH = (style == ImageAboveTextLabel)
  34095. ? jmin (16, proportionOfHeight (0.25f))
  34096. : 0;
  34097. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34098. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34099. imageSpace.setBounds (indentX, indentY,
  34100. getWidth() - indentX * 2,
  34101. getHeight() - indentY * 2 - textH);
  34102. if (textH > 0)
  34103. {
  34104. g.setFont ((float) textH);
  34105. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34106. g.drawFittedText (getButtonText(),
  34107. 2, getHeight() - textH - 1,
  34108. getWidth() - 4, textH,
  34109. Justification::centred, 1);
  34110. }
  34111. }
  34112. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34113. g.setOpacity (1.0f);
  34114. const Drawable* imageToDraw = 0;
  34115. if (isEnabled())
  34116. {
  34117. imageToDraw = getCurrentImage();
  34118. }
  34119. else
  34120. {
  34121. imageToDraw = getToggleState() ? disabledImageOn
  34122. : disabledImage;
  34123. if (imageToDraw == 0)
  34124. {
  34125. g.setOpacity (0.4f);
  34126. imageToDraw = getNormalImage();
  34127. }
  34128. }
  34129. if (imageToDraw != 0)
  34130. {
  34131. if (style == ImageRaw)
  34132. {
  34133. imageToDraw->draw (g, 1.0f);
  34134. }
  34135. else
  34136. {
  34137. imageToDraw->drawWithin (g,
  34138. imageSpace.getX(),
  34139. imageSpace.getY(),
  34140. imageSpace.getWidth(),
  34141. imageSpace.getHeight(),
  34142. RectanglePlacement::centred,
  34143. 1.0f);
  34144. }
  34145. }
  34146. }
  34147. const Drawable* DrawableButton::getCurrentImage() const throw()
  34148. {
  34149. if (isDown())
  34150. return getDownImage();
  34151. if (isOver())
  34152. return getOverImage();
  34153. return getNormalImage();
  34154. }
  34155. const Drawable* DrawableButton::getNormalImage() const throw()
  34156. {
  34157. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34158. : normalImage;
  34159. }
  34160. const Drawable* DrawableButton::getOverImage() const throw()
  34161. {
  34162. const Drawable* d = normalImage;
  34163. if (getToggleState())
  34164. {
  34165. if (overImageOn != 0)
  34166. d = overImageOn;
  34167. else if (normalImageOn != 0)
  34168. d = normalImageOn;
  34169. else if (overImage != 0)
  34170. d = overImage;
  34171. }
  34172. else
  34173. {
  34174. if (overImage != 0)
  34175. d = overImage;
  34176. }
  34177. return d;
  34178. }
  34179. const Drawable* DrawableButton::getDownImage() const throw()
  34180. {
  34181. const Drawable* d = normalImage;
  34182. if (getToggleState())
  34183. {
  34184. if (downImageOn != 0)
  34185. d = downImageOn;
  34186. else if (overImageOn != 0)
  34187. d = overImageOn;
  34188. else if (normalImageOn != 0)
  34189. d = normalImageOn;
  34190. else if (downImage != 0)
  34191. d = downImage;
  34192. else
  34193. d = getOverImage();
  34194. }
  34195. else
  34196. {
  34197. if (downImage != 0)
  34198. d = downImage;
  34199. else
  34200. d = getOverImage();
  34201. }
  34202. return d;
  34203. }
  34204. END_JUCE_NAMESPACE
  34205. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34206. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34207. BEGIN_JUCE_NAMESPACE
  34208. HyperlinkButton::HyperlinkButton (const String& linkText,
  34209. const URL& linkURL)
  34210. : Button (linkText),
  34211. url (linkURL),
  34212. font (14.0f, Font::underlined),
  34213. resizeFont (true),
  34214. justification (Justification::centred)
  34215. {
  34216. setMouseCursor (MouseCursor::PointingHandCursor);
  34217. setTooltip (linkURL.toString (false));
  34218. }
  34219. HyperlinkButton::~HyperlinkButton()
  34220. {
  34221. }
  34222. void HyperlinkButton::setFont (const Font& newFont,
  34223. const bool resizeToMatchComponentHeight,
  34224. const Justification& justificationType)
  34225. {
  34226. font = newFont;
  34227. resizeFont = resizeToMatchComponentHeight;
  34228. justification = justificationType;
  34229. repaint();
  34230. }
  34231. void HyperlinkButton::setURL (const URL& newURL) throw()
  34232. {
  34233. url = newURL;
  34234. setTooltip (newURL.toString (false));
  34235. }
  34236. const Font HyperlinkButton::getFontToUse() const
  34237. {
  34238. Font f (font);
  34239. if (resizeFont)
  34240. f.setHeight (getHeight() * 0.7f);
  34241. return f;
  34242. }
  34243. void HyperlinkButton::changeWidthToFitText()
  34244. {
  34245. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34246. }
  34247. void HyperlinkButton::colourChanged()
  34248. {
  34249. repaint();
  34250. }
  34251. void HyperlinkButton::clicked()
  34252. {
  34253. if (url.isWellFormed())
  34254. url.launchInDefaultBrowser();
  34255. }
  34256. void HyperlinkButton::paintButton (Graphics& g,
  34257. bool isMouseOverButton,
  34258. bool isButtonDown)
  34259. {
  34260. const Colour textColour (findColour (textColourId));
  34261. if (isEnabled())
  34262. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34263. : textColour);
  34264. else
  34265. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34266. g.setFont (getFontToUse());
  34267. g.drawText (getButtonText(),
  34268. 2, 0, getWidth() - 2, getHeight(),
  34269. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34270. true);
  34271. }
  34272. END_JUCE_NAMESPACE
  34273. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34274. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34275. BEGIN_JUCE_NAMESPACE
  34276. ImageButton::ImageButton (const String& text_)
  34277. : Button (text_),
  34278. scaleImageToFit (true),
  34279. preserveProportions (true),
  34280. alphaThreshold (0),
  34281. imageX (0),
  34282. imageY (0),
  34283. imageW (0),
  34284. imageH (0),
  34285. normalImage (0),
  34286. overImage (0),
  34287. downImage (0)
  34288. {
  34289. }
  34290. ImageButton::~ImageButton()
  34291. {
  34292. deleteImages();
  34293. }
  34294. void ImageButton::deleteImages()
  34295. {
  34296. ImageCache::releaseOrDelete (normalImage);
  34297. ImageCache::releaseOrDelete (overImage);
  34298. ImageCache::releaseOrDelete (downImage);
  34299. }
  34300. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34301. const bool rescaleImagesWhenButtonSizeChanges,
  34302. const bool preserveImageProportions,
  34303. Image* const normalImage_,
  34304. const float imageOpacityWhenNormal,
  34305. const Colour& overlayColourWhenNormal,
  34306. Image* const overImage_,
  34307. const float imageOpacityWhenOver,
  34308. const Colour& overlayColourWhenOver,
  34309. Image* const downImage_,
  34310. const float imageOpacityWhenDown,
  34311. const Colour& overlayColourWhenDown,
  34312. const float hitTestAlphaThreshold)
  34313. {
  34314. deleteImages();
  34315. normalImage = normalImage_;
  34316. overImage = overImage_;
  34317. downImage = downImage_;
  34318. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34319. {
  34320. imageW = normalImage->getWidth();
  34321. imageH = normalImage->getHeight();
  34322. setSize (imageW, imageH);
  34323. }
  34324. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34325. preserveProportions = preserveImageProportions;
  34326. normalOpacity = imageOpacityWhenNormal;
  34327. normalOverlay = overlayColourWhenNormal;
  34328. overOpacity = imageOpacityWhenOver;
  34329. overOverlay = overlayColourWhenOver;
  34330. downOpacity = imageOpacityWhenDown;
  34331. downOverlay = overlayColourWhenDown;
  34332. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34333. repaint();
  34334. }
  34335. Image* ImageButton::getCurrentImage() const
  34336. {
  34337. if (isDown() || getToggleState())
  34338. return getDownImage();
  34339. if (isOver())
  34340. return getOverImage();
  34341. return getNormalImage();
  34342. }
  34343. Image* ImageButton::getNormalImage() const throw()
  34344. {
  34345. return normalImage;
  34346. }
  34347. Image* ImageButton::getOverImage() const throw()
  34348. {
  34349. return (overImage != 0) ? overImage
  34350. : normalImage;
  34351. }
  34352. Image* ImageButton::getDownImage() const throw()
  34353. {
  34354. return (downImage != 0) ? downImage
  34355. : getOverImage();
  34356. }
  34357. void ImageButton::paintButton (Graphics& g,
  34358. bool isMouseOverButton,
  34359. bool isButtonDown)
  34360. {
  34361. if (! isEnabled())
  34362. {
  34363. isMouseOverButton = false;
  34364. isButtonDown = false;
  34365. }
  34366. Image* const im = getCurrentImage();
  34367. if (im != 0)
  34368. {
  34369. const int iw = im->getWidth();
  34370. const int ih = im->getHeight();
  34371. imageW = getWidth();
  34372. imageH = getHeight();
  34373. imageX = (imageW - iw) >> 1;
  34374. imageY = (imageH - ih) >> 1;
  34375. if (scaleImageToFit)
  34376. {
  34377. if (preserveProportions)
  34378. {
  34379. int newW, newH;
  34380. const float imRatio = ih / (float)iw;
  34381. const float destRatio = imageH / (float)imageW;
  34382. if (imRatio > destRatio)
  34383. {
  34384. newW = roundToInt (imageH / imRatio);
  34385. newH = imageH;
  34386. }
  34387. else
  34388. {
  34389. newW = imageW;
  34390. newH = roundToInt (imageW * imRatio);
  34391. }
  34392. imageX = (imageW - newW) / 2;
  34393. imageY = (imageH - newH) / 2;
  34394. imageW = newW;
  34395. imageH = newH;
  34396. }
  34397. else
  34398. {
  34399. imageX = 0;
  34400. imageY = 0;
  34401. }
  34402. }
  34403. if (! scaleImageToFit)
  34404. {
  34405. imageW = iw;
  34406. imageH = ih;
  34407. }
  34408. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34409. isButtonDown ? downOverlay
  34410. : (isMouseOverButton ? overOverlay
  34411. : normalOverlay),
  34412. isButtonDown ? downOpacity
  34413. : (isMouseOverButton ? overOpacity
  34414. : normalOpacity),
  34415. *this);
  34416. }
  34417. }
  34418. bool ImageButton::hitTest (int x, int y)
  34419. {
  34420. if (alphaThreshold == 0)
  34421. return true;
  34422. Image* const im = getCurrentImage();
  34423. return im == 0
  34424. || (imageW > 0 && imageH > 0
  34425. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34426. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34427. }
  34428. END_JUCE_NAMESPACE
  34429. /*** End of inlined file: juce_ImageButton.cpp ***/
  34430. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34431. BEGIN_JUCE_NAMESPACE
  34432. ShapeButton::ShapeButton (const String& text_,
  34433. const Colour& normalColour_,
  34434. const Colour& overColour_,
  34435. const Colour& downColour_)
  34436. : Button (text_),
  34437. normalColour (normalColour_),
  34438. overColour (overColour_),
  34439. downColour (downColour_),
  34440. maintainShapeProportions (false),
  34441. outlineWidth (0.0f)
  34442. {
  34443. }
  34444. ShapeButton::~ShapeButton()
  34445. {
  34446. }
  34447. void ShapeButton::setColours (const Colour& newNormalColour,
  34448. const Colour& newOverColour,
  34449. const Colour& newDownColour)
  34450. {
  34451. normalColour = newNormalColour;
  34452. overColour = newOverColour;
  34453. downColour = newDownColour;
  34454. }
  34455. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34456. const float newOutlineWidth)
  34457. {
  34458. outlineColour = newOutlineColour;
  34459. outlineWidth = newOutlineWidth;
  34460. }
  34461. void ShapeButton::setShape (const Path& newShape,
  34462. const bool resizeNowToFitThisShape,
  34463. const bool maintainShapeProportions_,
  34464. const bool hasShadow)
  34465. {
  34466. shape = newShape;
  34467. maintainShapeProportions = maintainShapeProportions_;
  34468. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34469. setComponentEffect ((hasShadow) ? &shadow : 0);
  34470. if (resizeNowToFitThisShape)
  34471. {
  34472. Rectangle<float> bounds (shape.getBounds());
  34473. if (hasShadow)
  34474. bounds.expand (4.0f, 4.0f);
  34475. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34476. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34477. 1 + (int) (bounds.getHeight() + outlineWidth));
  34478. }
  34479. }
  34480. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34481. {
  34482. if (! isEnabled())
  34483. {
  34484. isMouseOverButton = false;
  34485. isButtonDown = false;
  34486. }
  34487. g.setColour ((isButtonDown) ? downColour
  34488. : (isMouseOverButton) ? overColour
  34489. : normalColour);
  34490. int w = getWidth();
  34491. int h = getHeight();
  34492. if (getComponentEffect() != 0)
  34493. {
  34494. w -= 4;
  34495. h -= 4;
  34496. }
  34497. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34498. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34499. w - offset - outlineWidth,
  34500. h - offset - outlineWidth,
  34501. maintainShapeProportions));
  34502. g.fillPath (shape, trans);
  34503. if (outlineWidth > 0.0f)
  34504. {
  34505. g.setColour (outlineColour);
  34506. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34507. }
  34508. }
  34509. END_JUCE_NAMESPACE
  34510. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34511. /*** Start of inlined file: juce_TextButton.cpp ***/
  34512. BEGIN_JUCE_NAMESPACE
  34513. TextButton::TextButton (const String& name,
  34514. const String& toolTip)
  34515. : Button (name)
  34516. {
  34517. setTooltip (toolTip);
  34518. }
  34519. TextButton::~TextButton()
  34520. {
  34521. }
  34522. void TextButton::paintButton (Graphics& g,
  34523. bool isMouseOverButton,
  34524. bool isButtonDown)
  34525. {
  34526. getLookAndFeel().drawButtonBackground (g, *this,
  34527. findColour (getToggleState() ? buttonOnColourId
  34528. : buttonColourId),
  34529. isMouseOverButton,
  34530. isButtonDown);
  34531. getLookAndFeel().drawButtonText (g, *this,
  34532. isMouseOverButton,
  34533. isButtonDown);
  34534. }
  34535. void TextButton::colourChanged()
  34536. {
  34537. repaint();
  34538. }
  34539. const Font TextButton::getFont()
  34540. {
  34541. return Font (jmin (15.0f, getHeight() * 0.6f));
  34542. }
  34543. void TextButton::changeWidthToFitText (const int newHeight)
  34544. {
  34545. if (newHeight >= 0)
  34546. setSize (jmax (1, getWidth()), newHeight);
  34547. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34548. getHeight());
  34549. }
  34550. END_JUCE_NAMESPACE
  34551. /*** End of inlined file: juce_TextButton.cpp ***/
  34552. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34553. BEGIN_JUCE_NAMESPACE
  34554. ToggleButton::ToggleButton (const String& buttonText)
  34555. : Button (buttonText)
  34556. {
  34557. setClickingTogglesState (true);
  34558. }
  34559. ToggleButton::~ToggleButton()
  34560. {
  34561. }
  34562. void ToggleButton::paintButton (Graphics& g,
  34563. bool isMouseOverButton,
  34564. bool isButtonDown)
  34565. {
  34566. getLookAndFeel().drawToggleButton (g, *this,
  34567. isMouseOverButton,
  34568. isButtonDown);
  34569. }
  34570. void ToggleButton::changeWidthToFitText()
  34571. {
  34572. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34573. }
  34574. void ToggleButton::colourChanged()
  34575. {
  34576. repaint();
  34577. }
  34578. END_JUCE_NAMESPACE
  34579. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34580. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34581. BEGIN_JUCE_NAMESPACE
  34582. ToolbarButton::ToolbarButton (const int itemId_,
  34583. const String& buttonText,
  34584. Drawable* const normalImage_,
  34585. Drawable* const toggledOnImage_)
  34586. : ToolbarItemComponent (itemId_, buttonText, true),
  34587. normalImage (normalImage_),
  34588. toggledOnImage (toggledOnImage_)
  34589. {
  34590. }
  34591. ToolbarButton::~ToolbarButton()
  34592. {
  34593. }
  34594. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34595. bool /*isToolbarVertical*/,
  34596. int& preferredSize,
  34597. int& minSize, int& maxSize)
  34598. {
  34599. preferredSize = minSize = maxSize = toolbarDepth;
  34600. return true;
  34601. }
  34602. void ToolbarButton::paintButtonArea (Graphics& g,
  34603. int width, int height,
  34604. bool /*isMouseOver*/,
  34605. bool /*isMouseDown*/)
  34606. {
  34607. Drawable* d = normalImage;
  34608. if (getToggleState() && toggledOnImage != 0)
  34609. d = toggledOnImage;
  34610. if (! isEnabled())
  34611. {
  34612. Image im (Image::ARGB, width, height, true);
  34613. Graphics g2 (im);
  34614. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34615. im.desaturate();
  34616. g.drawImageAt (&im, 0, 0);
  34617. }
  34618. else
  34619. {
  34620. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34621. }
  34622. }
  34623. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34624. {
  34625. }
  34626. END_JUCE_NAMESPACE
  34627. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34628. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34629. BEGIN_JUCE_NAMESPACE
  34630. class CodeDocumentLine
  34631. {
  34632. public:
  34633. CodeDocumentLine (const juce_wchar* const line_,
  34634. const int lineLength_,
  34635. const int numNewLineChars,
  34636. const int lineStartInFile_)
  34637. : line (line_, lineLength_),
  34638. lineStartInFile (lineStartInFile_),
  34639. lineLength (lineLength_),
  34640. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34641. {
  34642. }
  34643. ~CodeDocumentLine()
  34644. {
  34645. }
  34646. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34647. {
  34648. const juce_wchar* const t = text;
  34649. int pos = 0;
  34650. while (t [pos] != 0)
  34651. {
  34652. const int startOfLine = pos;
  34653. int numNewLineChars = 0;
  34654. while (t[pos] != 0)
  34655. {
  34656. if (t[pos] == '\r')
  34657. {
  34658. ++numNewLineChars;
  34659. ++pos;
  34660. if (t[pos] == '\n')
  34661. {
  34662. ++numNewLineChars;
  34663. ++pos;
  34664. }
  34665. break;
  34666. }
  34667. if (t[pos] == '\n')
  34668. {
  34669. ++numNewLineChars;
  34670. ++pos;
  34671. break;
  34672. }
  34673. ++pos;
  34674. }
  34675. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34676. numNewLineChars, startOfLine));
  34677. }
  34678. jassert (pos == text.length());
  34679. }
  34680. bool endsWithLineBreak() const throw()
  34681. {
  34682. return lineLengthWithoutNewLines != lineLength;
  34683. }
  34684. void updateLength() throw()
  34685. {
  34686. lineLengthWithoutNewLines = lineLength = line.length();
  34687. while (lineLengthWithoutNewLines > 0
  34688. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34689. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34690. {
  34691. --lineLengthWithoutNewLines;
  34692. }
  34693. }
  34694. String line;
  34695. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34696. };
  34697. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34698. : document (document_),
  34699. currentLine (document_->lines[0]),
  34700. line (0),
  34701. position (0)
  34702. {
  34703. }
  34704. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34705. : document (other.document),
  34706. currentLine (other.currentLine),
  34707. line (other.line),
  34708. position (other.position)
  34709. {
  34710. }
  34711. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34712. {
  34713. document = other.document;
  34714. currentLine = other.currentLine;
  34715. line = other.line;
  34716. position = other.position;
  34717. return *this;
  34718. }
  34719. CodeDocument::Iterator::~Iterator() throw()
  34720. {
  34721. }
  34722. juce_wchar CodeDocument::Iterator::nextChar()
  34723. {
  34724. if (currentLine == 0)
  34725. return 0;
  34726. jassert (currentLine == document->lines.getUnchecked (line));
  34727. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34728. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34729. {
  34730. ++line;
  34731. currentLine = document->lines [line];
  34732. }
  34733. return result;
  34734. }
  34735. void CodeDocument::Iterator::skip()
  34736. {
  34737. if (currentLine != 0)
  34738. {
  34739. jassert (currentLine == document->lines.getUnchecked (line));
  34740. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34741. {
  34742. ++line;
  34743. currentLine = document->lines [line];
  34744. }
  34745. }
  34746. }
  34747. void CodeDocument::Iterator::skipToEndOfLine()
  34748. {
  34749. if (currentLine != 0)
  34750. {
  34751. jassert (currentLine == document->lines.getUnchecked (line));
  34752. ++line;
  34753. currentLine = document->lines [line];
  34754. if (currentLine != 0)
  34755. position = currentLine->lineStartInFile;
  34756. else
  34757. position = document->getNumCharacters();
  34758. }
  34759. }
  34760. juce_wchar CodeDocument::Iterator::peekNextChar() const
  34761. {
  34762. if (currentLine == 0)
  34763. return 0;
  34764. jassert (currentLine == document->lines.getUnchecked (line));
  34765. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  34766. }
  34767. void CodeDocument::Iterator::skipWhitespace()
  34768. {
  34769. while (CharacterFunctions::isWhitespace (peekNextChar()))
  34770. skip();
  34771. }
  34772. bool CodeDocument::Iterator::isEOF() const throw()
  34773. {
  34774. return currentLine == 0;
  34775. }
  34776. CodeDocument::Position::Position() throw()
  34777. : owner (0), characterPos (0), line (0),
  34778. indexInLine (0), positionMaintained (false)
  34779. {
  34780. }
  34781. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34782. const int line_, const int indexInLine_) throw()
  34783. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34784. characterPos (0), line (line_),
  34785. indexInLine (indexInLine_), positionMaintained (false)
  34786. {
  34787. setLineAndIndex (line_, indexInLine_);
  34788. }
  34789. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34790. const int characterPos_) throw()
  34791. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34792. positionMaintained (false)
  34793. {
  34794. setPosition (characterPos_);
  34795. }
  34796. CodeDocument::Position::Position (const Position& other) throw()
  34797. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  34798. indexInLine (other.indexInLine), positionMaintained (false)
  34799. {
  34800. jassert (*this == other);
  34801. }
  34802. CodeDocument::Position::~Position() throw()
  34803. {
  34804. setPositionMaintained (false);
  34805. }
  34806. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  34807. {
  34808. if (this != &other)
  34809. {
  34810. const bool wasPositionMaintained = positionMaintained;
  34811. if (owner != other.owner)
  34812. setPositionMaintained (false);
  34813. owner = other.owner;
  34814. line = other.line;
  34815. indexInLine = other.indexInLine;
  34816. characterPos = other.characterPos;
  34817. setPositionMaintained (wasPositionMaintained);
  34818. jassert (*this == other);
  34819. }
  34820. return *this;
  34821. }
  34822. bool CodeDocument::Position::operator== (const Position& other) const throw()
  34823. {
  34824. jassert ((characterPos == other.characterPos)
  34825. == (line == other.line && indexInLine == other.indexInLine));
  34826. return characterPos == other.characterPos
  34827. && line == other.line
  34828. && indexInLine == other.indexInLine
  34829. && owner == other.owner;
  34830. }
  34831. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  34832. {
  34833. return ! operator== (other);
  34834. }
  34835. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  34836. {
  34837. jassert (owner != 0);
  34838. if (owner->lines.size() == 0)
  34839. {
  34840. line = 0;
  34841. indexInLine = 0;
  34842. characterPos = 0;
  34843. }
  34844. else
  34845. {
  34846. if (newLine >= owner->lines.size())
  34847. {
  34848. line = owner->lines.size() - 1;
  34849. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34850. jassert (l != 0);
  34851. indexInLine = l->lineLengthWithoutNewLines;
  34852. characterPos = l->lineStartInFile + indexInLine;
  34853. }
  34854. else
  34855. {
  34856. line = jmax (0, newLine);
  34857. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34858. jassert (l != 0);
  34859. if (l->lineLengthWithoutNewLines > 0)
  34860. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  34861. else
  34862. indexInLine = 0;
  34863. characterPos = l->lineStartInFile + indexInLine;
  34864. }
  34865. }
  34866. }
  34867. void CodeDocument::Position::setPosition (const int newPosition) throw()
  34868. {
  34869. jassert (owner != 0);
  34870. line = 0;
  34871. indexInLine = 0;
  34872. characterPos = 0;
  34873. if (newPosition > 0)
  34874. {
  34875. int lineStart = 0;
  34876. int lineEnd = owner->lines.size();
  34877. for (;;)
  34878. {
  34879. if (lineEnd - lineStart < 4)
  34880. {
  34881. for (int i = lineStart; i < lineEnd; ++i)
  34882. {
  34883. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  34884. int index = newPosition - l->lineStartInFile;
  34885. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  34886. {
  34887. line = i;
  34888. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  34889. characterPos = l->lineStartInFile + indexInLine;
  34890. }
  34891. }
  34892. break;
  34893. }
  34894. else
  34895. {
  34896. const int midIndex = (lineStart + lineEnd + 1) / 2;
  34897. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  34898. if (newPosition >= mid->lineStartInFile)
  34899. lineStart = midIndex;
  34900. else
  34901. lineEnd = midIndex;
  34902. }
  34903. }
  34904. }
  34905. }
  34906. void CodeDocument::Position::moveBy (int characterDelta) throw()
  34907. {
  34908. jassert (owner != 0);
  34909. if (characterDelta == 1)
  34910. {
  34911. setPosition (getPosition());
  34912. // If moving right, make sure we don't get stuck between the \r and \n characters..
  34913. if (line < owner->lines.size())
  34914. {
  34915. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34916. if (indexInLine + characterDelta < l->lineLength
  34917. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  34918. ++characterDelta;
  34919. }
  34920. }
  34921. setPosition (characterPos + characterDelta);
  34922. }
  34923. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  34924. {
  34925. CodeDocument::Position p (*this);
  34926. p.moveBy (characterDelta);
  34927. return p;
  34928. }
  34929. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  34930. {
  34931. CodeDocument::Position p (*this);
  34932. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  34933. return p;
  34934. }
  34935. const juce_wchar CodeDocument::Position::getCharacter() const throw()
  34936. {
  34937. const CodeDocumentLine* const l = owner->lines [line];
  34938. return l == 0 ? 0 : l->line [getIndexInLine()];
  34939. }
  34940. const String CodeDocument::Position::getLineText() const throw()
  34941. {
  34942. const CodeDocumentLine* const l = owner->lines [line];
  34943. return l == 0 ? String::empty : l->line;
  34944. }
  34945. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  34946. {
  34947. if (isMaintained != positionMaintained)
  34948. {
  34949. positionMaintained = isMaintained;
  34950. if (owner != 0)
  34951. {
  34952. if (isMaintained)
  34953. {
  34954. jassert (! owner->positionsToMaintain.contains (this));
  34955. owner->positionsToMaintain.add (this);
  34956. }
  34957. else
  34958. {
  34959. jassert (owner->positionsToMaintain.contains (this));
  34960. owner->positionsToMaintain.removeValue (this);
  34961. }
  34962. }
  34963. }
  34964. }
  34965. CodeDocument::CodeDocument()
  34966. : undoManager (std::numeric_limits<int>::max(), 10000),
  34967. currentActionIndex (0),
  34968. indexOfSavedState (-1),
  34969. maximumLineLength (-1),
  34970. newLineChars ("\r\n")
  34971. {
  34972. }
  34973. CodeDocument::~CodeDocument()
  34974. {
  34975. }
  34976. const String CodeDocument::getAllContent() const throw()
  34977. {
  34978. return getTextBetween (Position (this, 0),
  34979. Position (this, lines.size(), 0));
  34980. }
  34981. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  34982. {
  34983. if (end.getPosition() <= start.getPosition())
  34984. return String::empty;
  34985. const int startLine = start.getLineNumber();
  34986. const int endLine = end.getLineNumber();
  34987. if (startLine == endLine)
  34988. {
  34989. CodeDocumentLine* const line = lines [startLine];
  34990. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  34991. }
  34992. String result;
  34993. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  34994. String::Concatenator concatenator (result);
  34995. const int maxLine = jmin (lines.size() - 1, endLine);
  34996. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  34997. {
  34998. const CodeDocumentLine* line = lines.getUnchecked(i);
  34999. int len = line->lineLength;
  35000. if (i == startLine)
  35001. {
  35002. const int index = start.getIndexInLine();
  35003. concatenator.append (line->line.substring (index, len));
  35004. }
  35005. else if (i == endLine)
  35006. {
  35007. len = end.getIndexInLine();
  35008. concatenator.append (line->line.substring (0, len));
  35009. }
  35010. else
  35011. {
  35012. concatenator.append (line->line);
  35013. }
  35014. }
  35015. return result;
  35016. }
  35017. int CodeDocument::getNumCharacters() const throw()
  35018. {
  35019. const CodeDocumentLine* const lastLine = lines.getLast();
  35020. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35021. }
  35022. const String CodeDocument::getLine (const int lineIndex) const throw()
  35023. {
  35024. const CodeDocumentLine* const line = lines [lineIndex];
  35025. return (line == 0) ? String::empty : line->line;
  35026. }
  35027. int CodeDocument::getMaximumLineLength() throw()
  35028. {
  35029. if (maximumLineLength < 0)
  35030. {
  35031. maximumLineLength = 0;
  35032. for (int i = lines.size(); --i >= 0;)
  35033. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35034. }
  35035. return maximumLineLength;
  35036. }
  35037. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35038. {
  35039. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35040. }
  35041. void CodeDocument::insertText (const Position& position, const String& text)
  35042. {
  35043. insert (text, position.getPosition(), true);
  35044. }
  35045. void CodeDocument::replaceAllContent (const String& newContent)
  35046. {
  35047. remove (0, getNumCharacters(), true);
  35048. insert (newContent, 0, true);
  35049. }
  35050. bool CodeDocument::loadFromStream (InputStream& stream)
  35051. {
  35052. replaceAllContent (stream.readEntireStreamAsString());
  35053. setSavePoint();
  35054. clearUndoHistory();
  35055. return true;
  35056. }
  35057. bool CodeDocument::writeToStream (OutputStream& stream)
  35058. {
  35059. for (int i = 0; i < lines.size(); ++i)
  35060. {
  35061. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35062. const char* utf8 = temp.toUTF8();
  35063. if (! stream.write (utf8, (int) strlen (utf8)))
  35064. return false;
  35065. }
  35066. return true;
  35067. }
  35068. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35069. {
  35070. jassert (newLine == "\r\n" || newLine == "\n" || newLine == "\r");
  35071. newLineChars = newLine;
  35072. }
  35073. void CodeDocument::newTransaction()
  35074. {
  35075. undoManager.beginNewTransaction (String::empty);
  35076. }
  35077. void CodeDocument::undo()
  35078. {
  35079. newTransaction();
  35080. undoManager.undo();
  35081. }
  35082. void CodeDocument::redo()
  35083. {
  35084. undoManager.redo();
  35085. }
  35086. void CodeDocument::clearUndoHistory()
  35087. {
  35088. undoManager.clearUndoHistory();
  35089. }
  35090. void CodeDocument::setSavePoint() throw()
  35091. {
  35092. indexOfSavedState = currentActionIndex;
  35093. }
  35094. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35095. {
  35096. return currentActionIndex != indexOfSavedState;
  35097. }
  35098. static int getCodeCharacterCategory (const juce_wchar character) throw()
  35099. {
  35100. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35101. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35102. }
  35103. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35104. {
  35105. Position p (position);
  35106. const int maxDistance = 256;
  35107. int i = 0;
  35108. while (i < maxDistance
  35109. && CharacterFunctions::isWhitespace (p.getCharacter())
  35110. && (i == 0 || (p.getCharacter() != '\n'
  35111. && p.getCharacter() != '\r')))
  35112. {
  35113. ++i;
  35114. p.moveBy (1);
  35115. }
  35116. if (i == 0)
  35117. {
  35118. const int type = getCodeCharacterCategory (p.getCharacter());
  35119. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35120. {
  35121. ++i;
  35122. p.moveBy (1);
  35123. }
  35124. while (i < maxDistance
  35125. && CharacterFunctions::isWhitespace (p.getCharacter())
  35126. && (i == 0 || (p.getCharacter() != '\n'
  35127. && p.getCharacter() != '\r')))
  35128. {
  35129. ++i;
  35130. p.moveBy (1);
  35131. }
  35132. }
  35133. return p;
  35134. }
  35135. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35136. {
  35137. Position p (position);
  35138. const int maxDistance = 256;
  35139. int i = 0;
  35140. bool stoppedAtLineStart = false;
  35141. while (i < maxDistance)
  35142. {
  35143. const juce_wchar c = p.movedBy (-1).getCharacter();
  35144. if (c == '\r' || c == '\n')
  35145. {
  35146. stoppedAtLineStart = true;
  35147. if (i > 0)
  35148. break;
  35149. }
  35150. if (! CharacterFunctions::isWhitespace (c))
  35151. break;
  35152. p.moveBy (-1);
  35153. ++i;
  35154. }
  35155. if (i < maxDistance && ! stoppedAtLineStart)
  35156. {
  35157. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35158. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35159. {
  35160. p.moveBy (-1);
  35161. ++i;
  35162. }
  35163. }
  35164. return p;
  35165. }
  35166. void CodeDocument::checkLastLineStatus()
  35167. {
  35168. while (lines.size() > 0
  35169. && lines.getLast()->lineLength == 0
  35170. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35171. {
  35172. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35173. lines.removeLast();
  35174. }
  35175. const CodeDocumentLine* const lastLine = lines.getLast();
  35176. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35177. {
  35178. // check that there's an empty line at the end if the preceding one ends in a newline..
  35179. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35180. }
  35181. }
  35182. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35183. {
  35184. listeners.add (listener);
  35185. }
  35186. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35187. {
  35188. listeners.remove (listener);
  35189. }
  35190. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35191. {
  35192. Position startPos (this, startLine, 0);
  35193. Position endPos (this, endLine, 0);
  35194. listeners.call (&Listener::codeDocumentChanged, startPos, endPos);
  35195. }
  35196. class CodeDocumentInsertAction : public UndoableAction
  35197. {
  35198. CodeDocument& owner;
  35199. const String text;
  35200. int insertPos;
  35201. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35202. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35203. public:
  35204. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35205. : owner (owner_),
  35206. text (text_),
  35207. insertPos (insertPos_)
  35208. {
  35209. }
  35210. ~CodeDocumentInsertAction() {}
  35211. bool perform()
  35212. {
  35213. owner.currentActionIndex++;
  35214. owner.insert (text, insertPos, false);
  35215. return true;
  35216. }
  35217. bool undo()
  35218. {
  35219. owner.currentActionIndex--;
  35220. owner.remove (insertPos, insertPos + text.length(), false);
  35221. return true;
  35222. }
  35223. int getSizeInUnits() { return text.length() + 32; }
  35224. };
  35225. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35226. {
  35227. if (text.isEmpty())
  35228. return;
  35229. if (undoable)
  35230. {
  35231. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35232. }
  35233. else
  35234. {
  35235. Position pos (this, insertPos);
  35236. const int firstAffectedLine = pos.getLineNumber();
  35237. int lastAffectedLine = firstAffectedLine + 1;
  35238. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35239. String textInsideOriginalLine (text);
  35240. if (firstLine != 0)
  35241. {
  35242. const int index = pos.getIndexInLine();
  35243. textInsideOriginalLine = firstLine->line.substring (0, index)
  35244. + textInsideOriginalLine
  35245. + firstLine->line.substring (index);
  35246. }
  35247. maximumLineLength = -1;
  35248. Array <CodeDocumentLine*> newLines;
  35249. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35250. jassert (newLines.size() > 0);
  35251. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35252. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35253. lines.set (firstAffectedLine, newFirstLine);
  35254. if (newLines.size() > 1)
  35255. {
  35256. for (int i = 1; i < newLines.size(); ++i)
  35257. {
  35258. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35259. lines.insert (firstAffectedLine + i, l);
  35260. }
  35261. lastAffectedLine = lines.size();
  35262. }
  35263. int i, lineStart = newFirstLine->lineStartInFile;
  35264. for (i = firstAffectedLine; i < lines.size(); ++i)
  35265. {
  35266. CodeDocumentLine* const l = lines.getUnchecked (i);
  35267. l->lineStartInFile = lineStart;
  35268. lineStart += l->lineLength;
  35269. }
  35270. checkLastLineStatus();
  35271. const int newTextLength = text.length();
  35272. for (i = 0; i < positionsToMaintain.size(); ++i)
  35273. {
  35274. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35275. if (p->getPosition() >= insertPos)
  35276. p->setPosition (p->getPosition() + newTextLength);
  35277. }
  35278. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35279. }
  35280. }
  35281. class CodeDocumentDeleteAction : public UndoableAction
  35282. {
  35283. CodeDocument& owner;
  35284. int startPos, endPos;
  35285. String removedText;
  35286. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35287. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35288. public:
  35289. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35290. : owner (owner_),
  35291. startPos (startPos_),
  35292. endPos (endPos_)
  35293. {
  35294. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35295. CodeDocument::Position (&owner, endPos));
  35296. }
  35297. ~CodeDocumentDeleteAction() {}
  35298. bool perform()
  35299. {
  35300. owner.currentActionIndex++;
  35301. owner.remove (startPos, endPos, false);
  35302. return true;
  35303. }
  35304. bool undo()
  35305. {
  35306. owner.currentActionIndex--;
  35307. owner.insert (removedText, startPos, false);
  35308. return true;
  35309. }
  35310. int getSizeInUnits() { return removedText.length() + 32; }
  35311. };
  35312. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35313. {
  35314. if (endPos <= startPos)
  35315. return;
  35316. if (undoable)
  35317. {
  35318. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35319. }
  35320. else
  35321. {
  35322. Position startPosition (this, startPos);
  35323. Position endPosition (this, endPos);
  35324. maximumLineLength = -1;
  35325. const int firstAffectedLine = startPosition.getLineNumber();
  35326. const int endLine = endPosition.getLineNumber();
  35327. int lastAffectedLine = firstAffectedLine + 1;
  35328. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35329. if (firstAffectedLine == endLine)
  35330. {
  35331. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35332. + firstLine->line.substring (endPosition.getIndexInLine());
  35333. firstLine->updateLength();
  35334. }
  35335. else
  35336. {
  35337. lastAffectedLine = lines.size();
  35338. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35339. jassert (lastLine != 0);
  35340. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35341. + lastLine->line.substring (endPosition.getIndexInLine());
  35342. firstLine->updateLength();
  35343. int numLinesToRemove = endLine - firstAffectedLine;
  35344. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35345. }
  35346. int i;
  35347. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35348. {
  35349. CodeDocumentLine* const l = lines.getUnchecked (i);
  35350. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35351. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35352. }
  35353. checkLastLineStatus();
  35354. const int totalChars = getNumCharacters();
  35355. for (i = 0; i < positionsToMaintain.size(); ++i)
  35356. {
  35357. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35358. if (p->getPosition() > startPosition.getPosition())
  35359. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35360. if (p->getPosition() > totalChars)
  35361. p->setPosition (totalChars);
  35362. }
  35363. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35364. }
  35365. }
  35366. END_JUCE_NAMESPACE
  35367. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35368. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35369. BEGIN_JUCE_NAMESPACE
  35370. class CodeEditorComponent::CaretComponent : public Component,
  35371. public Timer
  35372. {
  35373. public:
  35374. CaretComponent()
  35375. {
  35376. setAlwaysOnTop (true);
  35377. setInterceptsMouseClicks (false, false);
  35378. }
  35379. ~CaretComponent()
  35380. {
  35381. }
  35382. void paint (Graphics& g)
  35383. {
  35384. if (getParentComponent()->hasKeyboardFocus (true))
  35385. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35386. }
  35387. void timerCallback()
  35388. {
  35389. setVisible (! isVisible());
  35390. }
  35391. void updatePosition (CodeEditorComponent& owner)
  35392. {
  35393. startTimer (400);
  35394. setVisible (true);
  35395. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35396. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35397. }
  35398. private:
  35399. CaretComponent (const CaretComponent&);
  35400. CaretComponent& operator= (const CaretComponent&);
  35401. };
  35402. class CodeEditorComponent::CodeEditorLine
  35403. {
  35404. public:
  35405. CodeEditorLine() throw()
  35406. : highlightColumnStart (0), highlightColumnEnd (0)
  35407. {
  35408. }
  35409. ~CodeEditorLine() throw()
  35410. {
  35411. }
  35412. bool update (CodeDocument& document, int lineNum,
  35413. CodeDocument::Iterator& source,
  35414. CodeTokeniser* analyser, const int spacesPerTab,
  35415. const CodeDocument::Position& selectionStart,
  35416. const CodeDocument::Position& selectionEnd)
  35417. {
  35418. Array <SyntaxToken> newTokens;
  35419. newTokens.ensureStorageAllocated (8);
  35420. if (analyser == 0)
  35421. {
  35422. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35423. }
  35424. else if (lineNum < document.getNumLines())
  35425. {
  35426. const CodeDocument::Position pos (&document, lineNum, 0);
  35427. createTokens (pos.getPosition(), pos.getLineText(),
  35428. source, analyser, newTokens);
  35429. }
  35430. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35431. int newHighlightStart = 0;
  35432. int newHighlightEnd = 0;
  35433. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35434. {
  35435. const String line (document.getLine (lineNum));
  35436. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35437. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35438. line, spacesPerTab);
  35439. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35440. line, spacesPerTab);
  35441. }
  35442. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35443. {
  35444. highlightColumnStart = newHighlightStart;
  35445. highlightColumnEnd = newHighlightEnd;
  35446. }
  35447. else
  35448. {
  35449. if (tokens.size() == newTokens.size())
  35450. {
  35451. bool allTheSame = true;
  35452. for (int i = newTokens.size(); --i >= 0;)
  35453. {
  35454. if (tokens.getReference(i) != newTokens.getReference(i))
  35455. {
  35456. allTheSame = false;
  35457. break;
  35458. }
  35459. }
  35460. if (allTheSame)
  35461. return false;
  35462. }
  35463. }
  35464. tokens.swapWithArray (newTokens);
  35465. return true;
  35466. }
  35467. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35468. float x, const int y, const int baselineOffset, const int lineHeight,
  35469. const Colour& highlightColour) const throw()
  35470. {
  35471. if (highlightColumnStart < highlightColumnEnd)
  35472. {
  35473. g.setColour (highlightColour);
  35474. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35475. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35476. }
  35477. int lastType = std::numeric_limits<int>::min();
  35478. for (int i = 0; i < tokens.size(); ++i)
  35479. {
  35480. SyntaxToken& token = tokens.getReference(i);
  35481. if (lastType != token.tokenType)
  35482. {
  35483. lastType = token.tokenType;
  35484. g.setColour (owner.getColourForTokenType (lastType));
  35485. }
  35486. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35487. if (i < tokens.size() - 1)
  35488. {
  35489. if (token.width < 0)
  35490. token.width = font.getStringWidthFloat (token.text);
  35491. x += token.width;
  35492. }
  35493. }
  35494. }
  35495. private:
  35496. struct SyntaxToken
  35497. {
  35498. String text;
  35499. int tokenType;
  35500. float width;
  35501. SyntaxToken (const String& text_, const int type) throw()
  35502. : text (text_), tokenType (type), width (-1.0f)
  35503. {
  35504. }
  35505. bool operator!= (const SyntaxToken& other) const throw()
  35506. {
  35507. return text != other.text || tokenType != other.tokenType;
  35508. }
  35509. };
  35510. Array <SyntaxToken> tokens;
  35511. int highlightColumnStart, highlightColumnEnd;
  35512. static void createTokens (int startPosition, const String& lineText,
  35513. CodeDocument::Iterator& source,
  35514. CodeTokeniser* analyser,
  35515. Array <SyntaxToken>& newTokens)
  35516. {
  35517. CodeDocument::Iterator lastIterator (source);
  35518. const int lineLength = lineText.length();
  35519. for (;;)
  35520. {
  35521. int tokenType = analyser->readNextToken (source);
  35522. int tokenStart = lastIterator.getPosition();
  35523. int tokenEnd = source.getPosition();
  35524. if (tokenEnd <= tokenStart)
  35525. break;
  35526. tokenEnd -= startPosition;
  35527. if (tokenEnd > 0)
  35528. {
  35529. tokenStart -= startPosition;
  35530. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35531. tokenType));
  35532. if (tokenEnd >= lineLength)
  35533. break;
  35534. }
  35535. lastIterator = source;
  35536. }
  35537. source = lastIterator;
  35538. }
  35539. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35540. {
  35541. int x = 0;
  35542. for (int i = 0; i < tokens.size(); ++i)
  35543. {
  35544. SyntaxToken& t = tokens.getReference(i);
  35545. for (;;)
  35546. {
  35547. int tabPos = t.text.indexOfChar ('\t');
  35548. if (tabPos < 0)
  35549. break;
  35550. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35551. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (" ", spacesNeeded));
  35552. }
  35553. x += t.text.length();
  35554. }
  35555. }
  35556. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35557. {
  35558. jassert (index <= line.length());
  35559. int col = 0;
  35560. for (int i = 0; i < index; ++i)
  35561. {
  35562. if (line[i] != '\t')
  35563. ++col;
  35564. else
  35565. col += spacesPerTab - (col % spacesPerTab);
  35566. }
  35567. return col;
  35568. }
  35569. };
  35570. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35571. CodeTokeniser* const codeTokeniser_)
  35572. : document (document_),
  35573. firstLineOnScreen (0),
  35574. gutter (5),
  35575. spacesPerTab (4),
  35576. lineHeight (0),
  35577. linesOnScreen (0),
  35578. columnsOnScreen (0),
  35579. scrollbarThickness (16),
  35580. columnToTryToMaintain (-1),
  35581. useSpacesForTabs (false),
  35582. xOffset (0),
  35583. codeTokeniser (codeTokeniser_)
  35584. {
  35585. caretPos = CodeDocument::Position (&document_, 0, 0);
  35586. caretPos.setPositionMaintained (true);
  35587. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35588. selectionStart.setPositionMaintained (true);
  35589. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35590. selectionEnd.setPositionMaintained (true);
  35591. setOpaque (true);
  35592. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35593. setWantsKeyboardFocus (true);
  35594. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35595. verticalScrollBar->setSingleStepSize (1.0);
  35596. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35597. horizontalScrollBar->setSingleStepSize (1.0);
  35598. addAndMakeVisible (caret = new CaretComponent());
  35599. Font f (12.0f);
  35600. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35601. setFont (f);
  35602. resetToDefaultColours();
  35603. verticalScrollBar->addListener (this);
  35604. horizontalScrollBar->addListener (this);
  35605. document.addListener (this);
  35606. }
  35607. CodeEditorComponent::~CodeEditorComponent()
  35608. {
  35609. document.removeListener (this);
  35610. deleteAllChildren();
  35611. }
  35612. void CodeEditorComponent::loadContent (const String& newContent)
  35613. {
  35614. clearCachedIterators (0);
  35615. document.replaceAllContent (newContent);
  35616. document.clearUndoHistory();
  35617. document.setSavePoint();
  35618. caretPos.setPosition (0);
  35619. selectionStart.setPosition (0);
  35620. selectionEnd.setPosition (0);
  35621. scrollToLine (0);
  35622. }
  35623. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35624. const CodeDocument::Position& affectedTextEnd)
  35625. {
  35626. clearCachedIterators (affectedTextStart.getLineNumber());
  35627. triggerAsyncUpdate();
  35628. caret->updatePosition (*this);
  35629. columnToTryToMaintain = -1;
  35630. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35631. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35632. deselectAll();
  35633. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35634. || caretPos.getPosition() < affectedTextStart.getPosition())
  35635. moveCaretTo (affectedTextStart, false);
  35636. updateScrollBars();
  35637. }
  35638. void CodeEditorComponent::resized()
  35639. {
  35640. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35641. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35642. lines.clear();
  35643. rebuildLineTokens();
  35644. caret->updatePosition (*this);
  35645. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35646. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35647. updateScrollBars();
  35648. }
  35649. void CodeEditorComponent::paint (Graphics& g)
  35650. {
  35651. handleUpdateNowIfNeeded();
  35652. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35653. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35654. g.setFont (font);
  35655. const int baselineOffset = (int) font.getAscent();
  35656. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35657. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35658. const Rectangle<int> clip (g.getClipBounds());
  35659. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35660. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35661. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35662. {
  35663. lines.getUnchecked(j)->draw (*this, g, font,
  35664. (float) (gutter - xOffset * charWidth),
  35665. lineHeight * j, baselineOffset, lineHeight,
  35666. highlightColour);
  35667. }
  35668. }
  35669. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35670. {
  35671. if (scrollbarThickness != thickness)
  35672. {
  35673. scrollbarThickness = thickness;
  35674. resized();
  35675. }
  35676. }
  35677. void CodeEditorComponent::handleAsyncUpdate()
  35678. {
  35679. rebuildLineTokens();
  35680. }
  35681. void CodeEditorComponent::rebuildLineTokens()
  35682. {
  35683. cancelPendingUpdate();
  35684. const int numNeeded = linesOnScreen + 1;
  35685. int minLineToRepaint = numNeeded;
  35686. int maxLineToRepaint = 0;
  35687. if (numNeeded != lines.size())
  35688. {
  35689. lines.clear();
  35690. for (int i = numNeeded; --i >= 0;)
  35691. lines.add (new CodeEditorLine());
  35692. minLineToRepaint = 0;
  35693. maxLineToRepaint = numNeeded;
  35694. }
  35695. jassert (numNeeded == lines.size());
  35696. CodeDocument::Iterator source (&document);
  35697. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35698. for (int i = 0; i < numNeeded; ++i)
  35699. {
  35700. CodeEditorLine* const line = lines.getUnchecked(i);
  35701. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35702. selectionStart, selectionEnd))
  35703. {
  35704. minLineToRepaint = jmin (minLineToRepaint, i);
  35705. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35706. }
  35707. }
  35708. if (minLineToRepaint <= maxLineToRepaint)
  35709. {
  35710. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35711. verticalScrollBar->getX() - gutter,
  35712. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35713. }
  35714. }
  35715. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35716. {
  35717. caretPos = newPos;
  35718. columnToTryToMaintain = -1;
  35719. if (highlighting)
  35720. {
  35721. if (dragType == notDragging)
  35722. {
  35723. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35724. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35725. dragType = draggingSelectionStart;
  35726. else
  35727. dragType = draggingSelectionEnd;
  35728. }
  35729. if (dragType == draggingSelectionStart)
  35730. {
  35731. selectionStart = caretPos;
  35732. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35733. {
  35734. const CodeDocument::Position temp (selectionStart);
  35735. selectionStart = selectionEnd;
  35736. selectionEnd = temp;
  35737. dragType = draggingSelectionEnd;
  35738. }
  35739. }
  35740. else
  35741. {
  35742. selectionEnd = caretPos;
  35743. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35744. {
  35745. const CodeDocument::Position temp (selectionStart);
  35746. selectionStart = selectionEnd;
  35747. selectionEnd = temp;
  35748. dragType = draggingSelectionStart;
  35749. }
  35750. }
  35751. triggerAsyncUpdate();
  35752. }
  35753. else
  35754. {
  35755. deselectAll();
  35756. }
  35757. caret->updatePosition (*this);
  35758. scrollToKeepCaretOnScreen();
  35759. updateScrollBars();
  35760. }
  35761. void CodeEditorComponent::deselectAll()
  35762. {
  35763. if (selectionStart != selectionEnd)
  35764. triggerAsyncUpdate();
  35765. selectionStart = caretPos;
  35766. selectionEnd = caretPos;
  35767. }
  35768. void CodeEditorComponent::updateScrollBars()
  35769. {
  35770. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  35771. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  35772. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  35773. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  35774. }
  35775. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  35776. {
  35777. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  35778. newFirstLineOnScreen);
  35779. if (newFirstLineOnScreen != firstLineOnScreen)
  35780. {
  35781. firstLineOnScreen = newFirstLineOnScreen;
  35782. caret->updatePosition (*this);
  35783. updateCachedIterators (firstLineOnScreen);
  35784. triggerAsyncUpdate();
  35785. }
  35786. }
  35787. void CodeEditorComponent::scrollToColumnInternal (double column)
  35788. {
  35789. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  35790. if (xOffset != newOffset)
  35791. {
  35792. xOffset = newOffset;
  35793. caret->updatePosition (*this);
  35794. repaint();
  35795. }
  35796. }
  35797. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  35798. {
  35799. scrollToLineInternal (newFirstLineOnScreen);
  35800. updateScrollBars();
  35801. }
  35802. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  35803. {
  35804. scrollToColumnInternal (newFirstColumnOnScreen);
  35805. updateScrollBars();
  35806. }
  35807. void CodeEditorComponent::scrollBy (int deltaLines)
  35808. {
  35809. scrollToLine (firstLineOnScreen + deltaLines);
  35810. }
  35811. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  35812. {
  35813. if (caretPos.getLineNumber() < firstLineOnScreen)
  35814. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  35815. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35816. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  35817. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35818. if (column >= xOffset + columnsOnScreen - 1)
  35819. scrollToColumn (column + 1 - columnsOnScreen);
  35820. else if (column < xOffset)
  35821. scrollToColumn (column);
  35822. }
  35823. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  35824. {
  35825. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  35826. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  35827. roundToInt (charWidth),
  35828. lineHeight);
  35829. }
  35830. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  35831. {
  35832. const int line = y / lineHeight + firstLineOnScreen;
  35833. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  35834. const int index = columnToIndex (line, column);
  35835. return CodeDocument::Position (&document, line, index);
  35836. }
  35837. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  35838. {
  35839. document.deleteSection (selectionStart, selectionEnd);
  35840. if (newText.isNotEmpty())
  35841. document.insertText (caretPos, newText);
  35842. scrollToKeepCaretOnScreen();
  35843. }
  35844. void CodeEditorComponent::insertTabAtCaret()
  35845. {
  35846. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  35847. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  35848. {
  35849. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  35850. }
  35851. if (useSpacesForTabs)
  35852. {
  35853. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35854. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  35855. insertTextAtCaret (String::repeatedString (" ", spacesNeeded));
  35856. }
  35857. else
  35858. {
  35859. insertTextAtCaret ("\t");
  35860. }
  35861. }
  35862. void CodeEditorComponent::cut()
  35863. {
  35864. insertTextAtCaret (String::empty);
  35865. }
  35866. void CodeEditorComponent::copy()
  35867. {
  35868. newTransaction();
  35869. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  35870. if (selection.isNotEmpty())
  35871. SystemClipboard::copyTextToClipboard (selection);
  35872. }
  35873. void CodeEditorComponent::copyThenCut()
  35874. {
  35875. copy();
  35876. cut();
  35877. newTransaction();
  35878. }
  35879. void CodeEditorComponent::paste()
  35880. {
  35881. newTransaction();
  35882. const String clip (SystemClipboard::getTextFromClipboard());
  35883. if (clip.isNotEmpty())
  35884. insertTextAtCaret (clip);
  35885. newTransaction();
  35886. }
  35887. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  35888. {
  35889. newTransaction();
  35890. if (moveInWholeWordSteps)
  35891. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  35892. else
  35893. moveCaretTo (caretPos.movedBy (-1), selecting);
  35894. }
  35895. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  35896. {
  35897. newTransaction();
  35898. if (moveInWholeWordSteps)
  35899. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  35900. else
  35901. moveCaretTo (caretPos.movedBy (1), selecting);
  35902. }
  35903. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  35904. {
  35905. CodeDocument::Position pos (caretPos);
  35906. const int newLineNum = pos.getLineNumber() + delta;
  35907. if (columnToTryToMaintain < 0)
  35908. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  35909. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  35910. const int colToMaintain = columnToTryToMaintain;
  35911. moveCaretTo (pos, selecting);
  35912. columnToTryToMaintain = colToMaintain;
  35913. }
  35914. void CodeEditorComponent::cursorDown (const bool selecting)
  35915. {
  35916. newTransaction();
  35917. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  35918. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  35919. else
  35920. moveLineDelta (1, selecting);
  35921. }
  35922. void CodeEditorComponent::cursorUp (const bool selecting)
  35923. {
  35924. newTransaction();
  35925. if (caretPos.getLineNumber() == 0)
  35926. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  35927. else
  35928. moveLineDelta (-1, selecting);
  35929. }
  35930. void CodeEditorComponent::pageDown (const bool selecting)
  35931. {
  35932. newTransaction();
  35933. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  35934. moveLineDelta (linesOnScreen, selecting);
  35935. }
  35936. void CodeEditorComponent::pageUp (const bool selecting)
  35937. {
  35938. newTransaction();
  35939. scrollBy (-linesOnScreen);
  35940. moveLineDelta (-linesOnScreen, selecting);
  35941. }
  35942. void CodeEditorComponent::scrollUp()
  35943. {
  35944. newTransaction();
  35945. scrollBy (1);
  35946. if (caretPos.getLineNumber() < firstLineOnScreen)
  35947. moveLineDelta (1, false);
  35948. }
  35949. void CodeEditorComponent::scrollDown()
  35950. {
  35951. newTransaction();
  35952. scrollBy (-1);
  35953. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35954. moveLineDelta (-1, false);
  35955. }
  35956. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  35957. {
  35958. newTransaction();
  35959. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  35960. }
  35961. static int findFirstNonWhitespaceChar (const String& line) throw()
  35962. {
  35963. const int len = line.length();
  35964. for (int i = 0; i < len; ++i)
  35965. if (! CharacterFunctions::isWhitespace (line [i]))
  35966. return i;
  35967. return 0;
  35968. }
  35969. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  35970. {
  35971. newTransaction();
  35972. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  35973. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  35974. index = 0;
  35975. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  35976. }
  35977. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  35978. {
  35979. newTransaction();
  35980. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  35981. }
  35982. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  35983. {
  35984. newTransaction();
  35985. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  35986. }
  35987. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  35988. {
  35989. if (moveInWholeWordSteps)
  35990. {
  35991. cut(); // in case something is already highlighted
  35992. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  35993. }
  35994. else
  35995. {
  35996. if (selectionStart == selectionEnd)
  35997. selectionStart.moveBy (-1);
  35998. }
  35999. cut();
  36000. }
  36001. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36002. {
  36003. if (moveInWholeWordSteps)
  36004. {
  36005. cut(); // in case something is already highlighted
  36006. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36007. }
  36008. else
  36009. {
  36010. if (selectionStart == selectionEnd)
  36011. selectionEnd.moveBy (1);
  36012. else
  36013. newTransaction();
  36014. }
  36015. cut();
  36016. }
  36017. void CodeEditorComponent::selectAll()
  36018. {
  36019. newTransaction();
  36020. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36021. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36022. }
  36023. void CodeEditorComponent::undo()
  36024. {
  36025. document.undo();
  36026. scrollToKeepCaretOnScreen();
  36027. }
  36028. void CodeEditorComponent::redo()
  36029. {
  36030. document.redo();
  36031. scrollToKeepCaretOnScreen();
  36032. }
  36033. void CodeEditorComponent::newTransaction()
  36034. {
  36035. document.newTransaction();
  36036. startTimer (600);
  36037. }
  36038. void CodeEditorComponent::timerCallback()
  36039. {
  36040. newTransaction();
  36041. }
  36042. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36043. {
  36044. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36045. }
  36046. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36047. {
  36048. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36049. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36050. }
  36051. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36052. {
  36053. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36054. CodeDocument::Position (&document, range.getEnd()));
  36055. }
  36056. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36057. {
  36058. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36059. const bool shiftDown = key.getModifiers().isShiftDown();
  36060. if (key.isKeyCode (KeyPress::leftKey))
  36061. {
  36062. cursorLeft (moveInWholeWordSteps, shiftDown);
  36063. }
  36064. else if (key.isKeyCode (KeyPress::rightKey))
  36065. {
  36066. cursorRight (moveInWholeWordSteps, shiftDown);
  36067. }
  36068. else if (key.isKeyCode (KeyPress::upKey))
  36069. {
  36070. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36071. scrollDown();
  36072. #if JUCE_MAC
  36073. else if (key.getModifiers().isCommandDown())
  36074. goToStartOfDocument (shiftDown);
  36075. #endif
  36076. else
  36077. cursorUp (shiftDown);
  36078. }
  36079. else if (key.isKeyCode (KeyPress::downKey))
  36080. {
  36081. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36082. scrollUp();
  36083. #if JUCE_MAC
  36084. else if (key.getModifiers().isCommandDown())
  36085. goToEndOfDocument (shiftDown);
  36086. #endif
  36087. else
  36088. cursorDown (shiftDown);
  36089. }
  36090. else if (key.isKeyCode (KeyPress::pageDownKey))
  36091. {
  36092. pageDown (shiftDown);
  36093. }
  36094. else if (key.isKeyCode (KeyPress::pageUpKey))
  36095. {
  36096. pageUp (shiftDown);
  36097. }
  36098. else if (key.isKeyCode (KeyPress::homeKey))
  36099. {
  36100. if (moveInWholeWordSteps)
  36101. goToStartOfDocument (shiftDown);
  36102. else
  36103. goToStartOfLine (shiftDown);
  36104. }
  36105. else if (key.isKeyCode (KeyPress::endKey))
  36106. {
  36107. if (moveInWholeWordSteps)
  36108. goToEndOfDocument (shiftDown);
  36109. else
  36110. goToEndOfLine (shiftDown);
  36111. }
  36112. else if (key.isKeyCode (KeyPress::backspaceKey))
  36113. {
  36114. backspace (moveInWholeWordSteps);
  36115. }
  36116. else if (key.isKeyCode (KeyPress::deleteKey))
  36117. {
  36118. deleteForward (moveInWholeWordSteps);
  36119. }
  36120. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0))
  36121. {
  36122. copy();
  36123. }
  36124. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  36125. {
  36126. copyThenCut();
  36127. }
  36128. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0))
  36129. {
  36130. paste();
  36131. }
  36132. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  36133. {
  36134. undo();
  36135. }
  36136. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0)
  36137. || key == KeyPress ('z', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36138. {
  36139. redo();
  36140. }
  36141. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  36142. {
  36143. selectAll();
  36144. }
  36145. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36146. {
  36147. insertTabAtCaret();
  36148. }
  36149. else if (key == KeyPress::returnKey)
  36150. {
  36151. newTransaction();
  36152. insertTextAtCaret (document.getNewLineCharacters());
  36153. }
  36154. else if (key.isKeyCode (KeyPress::escapeKey))
  36155. {
  36156. newTransaction();
  36157. }
  36158. else if (key.getTextCharacter() >= ' ')
  36159. {
  36160. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36161. }
  36162. else
  36163. {
  36164. return false;
  36165. }
  36166. return true;
  36167. }
  36168. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36169. {
  36170. newTransaction();
  36171. dragType = notDragging;
  36172. if (! e.mods.isPopupMenu())
  36173. {
  36174. beginDragAutoRepeat (100);
  36175. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36176. }
  36177. else
  36178. {
  36179. }
  36180. }
  36181. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36182. {
  36183. if (! e.mods.isPopupMenu())
  36184. moveCaretTo (getPositionAt (e.x, e.y), true);
  36185. }
  36186. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36187. {
  36188. newTransaction();
  36189. beginDragAutoRepeat (0);
  36190. dragType = notDragging;
  36191. }
  36192. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36193. {
  36194. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36195. CodeDocument::Position tokenEnd (tokenStart);
  36196. if (e.getNumberOfClicks() > 2)
  36197. {
  36198. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36199. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36200. }
  36201. else
  36202. {
  36203. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36204. tokenEnd.moveBy (1);
  36205. tokenStart = tokenEnd;
  36206. while (tokenStart.getIndexInLine() > 0
  36207. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36208. tokenStart.moveBy (-1);
  36209. }
  36210. moveCaretTo (tokenEnd, false);
  36211. moveCaretTo (tokenStart, true);
  36212. }
  36213. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36214. {
  36215. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36216. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36217. }
  36218. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36219. {
  36220. if (scrollBarThatHasMoved == verticalScrollBar)
  36221. scrollToLineInternal ((int) newRangeStart);
  36222. else
  36223. scrollToColumnInternal (newRangeStart);
  36224. }
  36225. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36226. {
  36227. useSpacesForTabs = insertSpaces;
  36228. if (spacesPerTab != numSpaces)
  36229. {
  36230. spacesPerTab = numSpaces;
  36231. triggerAsyncUpdate();
  36232. }
  36233. }
  36234. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36235. {
  36236. const String line (document.getLine (lineNum));
  36237. jassert (index <= line.length());
  36238. int col = 0;
  36239. for (int i = 0; i < index; ++i)
  36240. {
  36241. if (line[i] != '\t')
  36242. ++col;
  36243. else
  36244. col += getTabSize() - (col % getTabSize());
  36245. }
  36246. return col;
  36247. }
  36248. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36249. {
  36250. const String line (document.getLine (lineNum));
  36251. const int lineLength = line.length();
  36252. int i, col = 0;
  36253. for (i = 0; i < lineLength; ++i)
  36254. {
  36255. if (line[i] != '\t')
  36256. ++col;
  36257. else
  36258. col += getTabSize() - (col % getTabSize());
  36259. if (col > column)
  36260. break;
  36261. }
  36262. return i;
  36263. }
  36264. void CodeEditorComponent::setFont (const Font& newFont)
  36265. {
  36266. font = newFont;
  36267. charWidth = font.getStringWidthFloat ("0");
  36268. lineHeight = roundToInt (font.getHeight());
  36269. resized();
  36270. }
  36271. void CodeEditorComponent::resetToDefaultColours()
  36272. {
  36273. coloursForTokenCategories.clear();
  36274. if (codeTokeniser != 0)
  36275. {
  36276. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36277. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36278. }
  36279. }
  36280. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36281. {
  36282. jassert (tokenType < 256);
  36283. while (coloursForTokenCategories.size() < tokenType)
  36284. coloursForTokenCategories.add (Colours::black);
  36285. coloursForTokenCategories.set (tokenType, colour);
  36286. repaint();
  36287. }
  36288. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36289. {
  36290. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36291. return findColour (CodeEditorComponent::defaultTextColourId);
  36292. return coloursForTokenCategories.getReference (tokenType);
  36293. }
  36294. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36295. {
  36296. int i;
  36297. for (i = cachedIterators.size(); --i >= 0;)
  36298. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36299. break;
  36300. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36301. }
  36302. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36303. {
  36304. const int maxNumCachedPositions = 5000;
  36305. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36306. if (cachedIterators.size() == 0)
  36307. cachedIterators.add (new CodeDocument::Iterator (&document));
  36308. if (codeTokeniser == 0)
  36309. return;
  36310. for (;;)
  36311. {
  36312. CodeDocument::Iterator* last = cachedIterators.getLast();
  36313. if (last->getLine() >= maxLineNum)
  36314. break;
  36315. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36316. cachedIterators.add (t);
  36317. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36318. for (;;)
  36319. {
  36320. codeTokeniser->readNextToken (*t);
  36321. if (t->getLine() >= targetLine)
  36322. break;
  36323. if (t->isEOF())
  36324. return;
  36325. }
  36326. }
  36327. }
  36328. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36329. {
  36330. if (codeTokeniser == 0)
  36331. return;
  36332. for (int i = cachedIterators.size(); --i >= 0;)
  36333. {
  36334. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36335. if (t->getPosition() <= position)
  36336. {
  36337. source = *t;
  36338. break;
  36339. }
  36340. }
  36341. while (source.getPosition() < position)
  36342. {
  36343. const CodeDocument::Iterator original (source);
  36344. codeTokeniser->readNextToken (source);
  36345. if (source.getPosition() > position || source.isEOF())
  36346. {
  36347. source = original;
  36348. break;
  36349. }
  36350. }
  36351. }
  36352. END_JUCE_NAMESPACE
  36353. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36354. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36355. BEGIN_JUCE_NAMESPACE
  36356. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36357. {
  36358. }
  36359. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36360. {
  36361. }
  36362. namespace CppTokeniser
  36363. {
  36364. static bool isIdentifierStart (const juce_wchar c) throw()
  36365. {
  36366. return CharacterFunctions::isLetter (c)
  36367. || c == '_' || c == '@';
  36368. }
  36369. static bool isIdentifierBody (const juce_wchar c) throw()
  36370. {
  36371. return CharacterFunctions::isLetter (c)
  36372. || CharacterFunctions::isDigit (c)
  36373. || c == '_' || c == '@';
  36374. }
  36375. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36376. {
  36377. static const juce_wchar* keywords2Char[] =
  36378. { T("if"), T("do"), T("or"), 0 };
  36379. static const juce_wchar* keywords3Char[] =
  36380. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36381. static const juce_wchar* keywords4Char[] =
  36382. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36383. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36384. static const juce_wchar* keywords5Char[] =
  36385. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36386. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36387. static const juce_wchar* keywords6Char[] =
  36388. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36389. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36390. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36391. static const juce_wchar* keywordsOther[] =
  36392. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36393. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36394. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36395. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36396. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36397. int tokenLength = 0;
  36398. juce_wchar possibleIdentifier [19];
  36399. while (isIdentifierBody (source.peekNextChar()))
  36400. {
  36401. const juce_wchar c = source.nextChar();
  36402. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36403. possibleIdentifier [tokenLength] = c;
  36404. ++tokenLength;
  36405. }
  36406. if (tokenLength > 1 && tokenLength <= 16)
  36407. {
  36408. possibleIdentifier [tokenLength] = 0;
  36409. const juce_wchar** k;
  36410. switch (tokenLength)
  36411. {
  36412. case 2: k = keywords2Char; break;
  36413. case 3: k = keywords3Char; break;
  36414. case 4: k = keywords4Char; break;
  36415. case 5: k = keywords5Char; break;
  36416. case 6: k = keywords6Char; break;
  36417. default: k = keywordsOther; break;
  36418. }
  36419. int i = 0;
  36420. while (k[i] != 0)
  36421. {
  36422. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36423. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36424. ++i;
  36425. }
  36426. }
  36427. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36428. }
  36429. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36430. {
  36431. const juce_wchar c = source.peekNextChar();
  36432. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36433. source.skip();
  36434. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36435. return false;
  36436. return true;
  36437. }
  36438. static bool isHexDigit (const juce_wchar c) throw()
  36439. {
  36440. return (c >= '0' && c <= '9')
  36441. || (c >= 'a' && c <= 'f')
  36442. || (c >= 'A' && c <= 'F');
  36443. }
  36444. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36445. {
  36446. if (source.nextChar() != '0')
  36447. return false;
  36448. juce_wchar c = source.nextChar();
  36449. if (c != 'x' && c != 'X')
  36450. return false;
  36451. int numDigits = 0;
  36452. while (isHexDigit (source.peekNextChar()))
  36453. {
  36454. ++numDigits;
  36455. source.skip();
  36456. }
  36457. if (numDigits == 0)
  36458. return false;
  36459. return skipNumberSuffix (source);
  36460. }
  36461. static bool isOctalDigit (const juce_wchar c) throw()
  36462. {
  36463. return c >= '0' && c <= '7';
  36464. }
  36465. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36466. {
  36467. if (source.nextChar() != '0')
  36468. return false;
  36469. if (! isOctalDigit (source.nextChar()))
  36470. return false;
  36471. while (isOctalDigit (source.peekNextChar()))
  36472. source.skip();
  36473. return skipNumberSuffix (source);
  36474. }
  36475. static bool isDecimalDigit (const juce_wchar c) throw()
  36476. {
  36477. return c >= '0' && c <= '9';
  36478. }
  36479. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36480. {
  36481. int numChars = 0;
  36482. while (isDecimalDigit (source.peekNextChar()))
  36483. {
  36484. ++numChars;
  36485. source.skip();
  36486. }
  36487. if (numChars == 0)
  36488. return false;
  36489. return skipNumberSuffix (source);
  36490. }
  36491. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36492. {
  36493. int numDigits = 0;
  36494. while (isDecimalDigit (source.peekNextChar()))
  36495. {
  36496. source.skip();
  36497. ++numDigits;
  36498. }
  36499. const bool hasPoint = (source.peekNextChar() == '.');
  36500. if (hasPoint)
  36501. {
  36502. source.skip();
  36503. while (isDecimalDigit (source.peekNextChar()))
  36504. {
  36505. source.skip();
  36506. ++numDigits;
  36507. }
  36508. }
  36509. if (numDigits == 0)
  36510. return false;
  36511. juce_wchar c = source.peekNextChar();
  36512. const bool hasExponent = (c == 'e' || c == 'E');
  36513. if (hasExponent)
  36514. {
  36515. source.skip();
  36516. c = source.peekNextChar();
  36517. if (c == '+' || c == '-')
  36518. source.skip();
  36519. int numExpDigits = 0;
  36520. while (isDecimalDigit (source.peekNextChar()))
  36521. {
  36522. source.skip();
  36523. ++numExpDigits;
  36524. }
  36525. if (numExpDigits == 0)
  36526. return false;
  36527. }
  36528. c = source.peekNextChar();
  36529. if (c == 'f' || c == 'F')
  36530. source.skip();
  36531. else if (! (hasExponent || hasPoint))
  36532. return false;
  36533. return true;
  36534. }
  36535. static int parseNumber (CodeDocument::Iterator& source)
  36536. {
  36537. const CodeDocument::Iterator original (source);
  36538. if (parseFloatLiteral (source))
  36539. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36540. source = original;
  36541. if (parseHexLiteral (source))
  36542. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36543. source = original;
  36544. if (parseOctalLiteral (source))
  36545. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36546. source = original;
  36547. if (parseDecimalLiteral (source))
  36548. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36549. source = original;
  36550. source.skip();
  36551. return CPlusPlusCodeTokeniser::tokenType_error;
  36552. }
  36553. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36554. {
  36555. const juce_wchar quote = source.nextChar();
  36556. for (;;)
  36557. {
  36558. const juce_wchar c = source.nextChar();
  36559. if (c == quote || c == 0)
  36560. break;
  36561. if (c == '\\')
  36562. source.skip();
  36563. }
  36564. }
  36565. static void skipComment (CodeDocument::Iterator& source) throw()
  36566. {
  36567. bool lastWasStar = false;
  36568. for (;;)
  36569. {
  36570. const juce_wchar c = source.nextChar();
  36571. if (c == 0 || (c == '/' && lastWasStar))
  36572. break;
  36573. lastWasStar = (c == '*');
  36574. }
  36575. }
  36576. }
  36577. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36578. {
  36579. int result = tokenType_error;
  36580. source.skipWhitespace();
  36581. juce_wchar firstChar = source.peekNextChar();
  36582. switch (firstChar)
  36583. {
  36584. case 0:
  36585. source.skip();
  36586. break;
  36587. case '0':
  36588. case '1':
  36589. case '2':
  36590. case '3':
  36591. case '4':
  36592. case '5':
  36593. case '6':
  36594. case '7':
  36595. case '8':
  36596. case '9':
  36597. result = CppTokeniser::parseNumber (source);
  36598. break;
  36599. case '.':
  36600. result = CppTokeniser::parseNumber (source);
  36601. if (result == tokenType_error)
  36602. result = tokenType_punctuation;
  36603. break;
  36604. case ',':
  36605. case ';':
  36606. case ':':
  36607. source.skip();
  36608. result = tokenType_punctuation;
  36609. break;
  36610. case '(':
  36611. case ')':
  36612. case '{':
  36613. case '}':
  36614. case '[':
  36615. case ']':
  36616. source.skip();
  36617. result = tokenType_bracket;
  36618. break;
  36619. case '"':
  36620. case '\'':
  36621. CppTokeniser::skipQuotedString (source);
  36622. result = tokenType_stringLiteral;
  36623. break;
  36624. case '+':
  36625. result = tokenType_operator;
  36626. source.skip();
  36627. if (source.peekNextChar() == '+')
  36628. source.skip();
  36629. else if (source.peekNextChar() == '=')
  36630. source.skip();
  36631. break;
  36632. case '-':
  36633. source.skip();
  36634. result = CppTokeniser::parseNumber (source);
  36635. if (result == tokenType_error)
  36636. {
  36637. result = tokenType_operator;
  36638. if (source.peekNextChar() == '-')
  36639. source.skip();
  36640. else if (source.peekNextChar() == '=')
  36641. source.skip();
  36642. }
  36643. break;
  36644. case '*':
  36645. case '%':
  36646. case '=':
  36647. case '!':
  36648. result = tokenType_operator;
  36649. source.skip();
  36650. if (source.peekNextChar() == '=')
  36651. source.skip();
  36652. break;
  36653. case '/':
  36654. result = tokenType_operator;
  36655. source.skip();
  36656. if (source.peekNextChar() == '=')
  36657. {
  36658. source.skip();
  36659. }
  36660. else if (source.peekNextChar() == '/')
  36661. {
  36662. result = tokenType_comment;
  36663. source.skipToEndOfLine();
  36664. }
  36665. else if (source.peekNextChar() == '*')
  36666. {
  36667. source.skip();
  36668. result = tokenType_comment;
  36669. CppTokeniser::skipComment (source);
  36670. }
  36671. break;
  36672. case '?':
  36673. case '~':
  36674. source.skip();
  36675. result = tokenType_operator;
  36676. break;
  36677. case '<':
  36678. source.skip();
  36679. result = tokenType_operator;
  36680. if (source.peekNextChar() == '=')
  36681. {
  36682. source.skip();
  36683. }
  36684. else if (source.peekNextChar() == '<')
  36685. {
  36686. source.skip();
  36687. if (source.peekNextChar() == '=')
  36688. source.skip();
  36689. }
  36690. break;
  36691. case '>':
  36692. source.skip();
  36693. result = tokenType_operator;
  36694. if (source.peekNextChar() == '=')
  36695. {
  36696. source.skip();
  36697. }
  36698. else if (source.peekNextChar() == '<')
  36699. {
  36700. source.skip();
  36701. if (source.peekNextChar() == '=')
  36702. source.skip();
  36703. }
  36704. break;
  36705. case '|':
  36706. source.skip();
  36707. result = tokenType_operator;
  36708. if (source.peekNextChar() == '=')
  36709. {
  36710. source.skip();
  36711. }
  36712. else if (source.peekNextChar() == '|')
  36713. {
  36714. source.skip();
  36715. if (source.peekNextChar() == '=')
  36716. source.skip();
  36717. }
  36718. break;
  36719. case '&':
  36720. source.skip();
  36721. result = tokenType_operator;
  36722. if (source.peekNextChar() == '=')
  36723. {
  36724. source.skip();
  36725. }
  36726. else if (source.peekNextChar() == '&')
  36727. {
  36728. source.skip();
  36729. if (source.peekNextChar() == '=')
  36730. source.skip();
  36731. }
  36732. break;
  36733. case '^':
  36734. source.skip();
  36735. result = tokenType_operator;
  36736. if (source.peekNextChar() == '=')
  36737. {
  36738. source.skip();
  36739. }
  36740. else if (source.peekNextChar() == '^')
  36741. {
  36742. source.skip();
  36743. if (source.peekNextChar() == '=')
  36744. source.skip();
  36745. }
  36746. break;
  36747. case '#':
  36748. result = tokenType_preprocessor;
  36749. source.skipToEndOfLine();
  36750. break;
  36751. default:
  36752. if (CppTokeniser::isIdentifierStart (firstChar))
  36753. result = CppTokeniser::parseIdentifier (source);
  36754. else
  36755. source.skip();
  36756. break;
  36757. }
  36758. //jassert (result != tokenType_unknown);
  36759. return result;
  36760. }
  36761. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  36762. {
  36763. StringArray s;
  36764. s.add ("Error");
  36765. s.add ("Comment");
  36766. s.add ("C++ keyword");
  36767. s.add ("Identifier");
  36768. s.add ("Integer literal");
  36769. s.add ("Float literal");
  36770. s.add ("String literal");
  36771. s.add ("Operator");
  36772. s.add ("Bracket");
  36773. s.add ("Punctuation");
  36774. s.add ("Preprocessor line");
  36775. return s;
  36776. }
  36777. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  36778. {
  36779. const uint32 colours[] =
  36780. {
  36781. 0xffcc0000, // error
  36782. 0xff00aa00, // comment
  36783. 0xff0000cc, // keyword
  36784. 0xff000000, // identifier
  36785. 0xff880000, // int literal
  36786. 0xff885500, // float literal
  36787. 0xff990099, // string literal
  36788. 0xff225500, // operator
  36789. 0xff000055, // bracket
  36790. 0xff004400, // punctuation
  36791. 0xff660000 // preprocessor
  36792. };
  36793. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  36794. return Colour (colours [tokenType]);
  36795. return Colours::black;
  36796. }
  36797. END_JUCE_NAMESPACE
  36798. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36799. /*** Start of inlined file: juce_ComboBox.cpp ***/
  36800. BEGIN_JUCE_NAMESPACE
  36801. ComboBox::ComboBox (const String& name)
  36802. : Component (name),
  36803. lastCurrentId (0),
  36804. isButtonDown (false),
  36805. separatorPending (false),
  36806. menuActive (false),
  36807. label (0)
  36808. {
  36809. noChoicesMessage = TRANS("(no choices)");
  36810. setRepaintsOnMouseActivity (true);
  36811. lookAndFeelChanged();
  36812. currentId.addListener (this);
  36813. }
  36814. ComboBox::~ComboBox()
  36815. {
  36816. currentId.removeListener (this);
  36817. if (menuActive)
  36818. PopupMenu::dismissAllActiveMenus();
  36819. label = 0;
  36820. deleteAllChildren();
  36821. }
  36822. void ComboBox::setEditableText (const bool isEditable)
  36823. {
  36824. label->setEditable (isEditable, isEditable, false);
  36825. setWantsKeyboardFocus (! isEditable);
  36826. resized();
  36827. }
  36828. bool ComboBox::isTextEditable() const throw()
  36829. {
  36830. return label->isEditable();
  36831. }
  36832. void ComboBox::setJustificationType (const Justification& justification) throw()
  36833. {
  36834. label->setJustificationType (justification);
  36835. }
  36836. const Justification ComboBox::getJustificationType() const throw()
  36837. {
  36838. return label->getJustificationType();
  36839. }
  36840. void ComboBox::setTooltip (const String& newTooltip)
  36841. {
  36842. SettableTooltipClient::setTooltip (newTooltip);
  36843. label->setTooltip (newTooltip);
  36844. }
  36845. void ComboBox::addItem (const String& newItemText,
  36846. const int newItemId) throw()
  36847. {
  36848. // you can't add empty strings to the list..
  36849. jassert (newItemText.isNotEmpty());
  36850. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  36851. jassert (newItemId != 0);
  36852. // you shouldn't use duplicate item IDs!
  36853. jassert (getItemForId (newItemId) == 0);
  36854. if (newItemText.isNotEmpty() && newItemId != 0)
  36855. {
  36856. if (separatorPending)
  36857. {
  36858. separatorPending = false;
  36859. ItemInfo* const item = new ItemInfo();
  36860. item->itemId = 0;
  36861. item->isEnabled = false;
  36862. item->isHeading = false;
  36863. items.add (item);
  36864. }
  36865. ItemInfo* const item = new ItemInfo();
  36866. item->name = newItemText;
  36867. item->itemId = newItemId;
  36868. item->isEnabled = true;
  36869. item->isHeading = false;
  36870. items.add (item);
  36871. }
  36872. }
  36873. void ComboBox::addSeparator() throw()
  36874. {
  36875. separatorPending = (items.size() > 0);
  36876. }
  36877. void ComboBox::addSectionHeading (const String& headingName) throw()
  36878. {
  36879. // you can't add empty strings to the list..
  36880. jassert (headingName.isNotEmpty());
  36881. if (headingName.isNotEmpty())
  36882. {
  36883. if (separatorPending)
  36884. {
  36885. separatorPending = false;
  36886. ItemInfo* const item = new ItemInfo();
  36887. item->itemId = 0;
  36888. item->isEnabled = false;
  36889. item->isHeading = false;
  36890. items.add (item);
  36891. }
  36892. ItemInfo* const item = new ItemInfo();
  36893. item->name = headingName;
  36894. item->itemId = 0;
  36895. item->isEnabled = true;
  36896. item->isHeading = true;
  36897. items.add (item);
  36898. }
  36899. }
  36900. void ComboBox::setItemEnabled (const int itemId,
  36901. const bool shouldBeEnabled) throw()
  36902. {
  36903. ItemInfo* const item = getItemForId (itemId);
  36904. if (item != 0)
  36905. item->isEnabled = shouldBeEnabled;
  36906. }
  36907. void ComboBox::changeItemText (const int itemId,
  36908. const String& newText) throw()
  36909. {
  36910. ItemInfo* const item = getItemForId (itemId);
  36911. jassert (item != 0);
  36912. if (item != 0)
  36913. item->name = newText;
  36914. }
  36915. void ComboBox::clear (const bool dontSendChangeMessage)
  36916. {
  36917. items.clear();
  36918. separatorPending = false;
  36919. if (! label->isEditable())
  36920. setSelectedItemIndex (-1, dontSendChangeMessage);
  36921. }
  36922. bool ComboBox::ItemInfo::isSeparator() const throw()
  36923. {
  36924. return name.isEmpty();
  36925. }
  36926. bool ComboBox::ItemInfo::isRealItem() const throw()
  36927. {
  36928. return ! (isHeading || name.isEmpty());
  36929. }
  36930. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  36931. {
  36932. if (itemId != 0)
  36933. {
  36934. for (int i = items.size(); --i >= 0;)
  36935. if (items.getUnchecked(i)->itemId == itemId)
  36936. return items.getUnchecked(i);
  36937. }
  36938. return 0;
  36939. }
  36940. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  36941. {
  36942. int n = 0;
  36943. for (int i = 0; i < items.size(); ++i)
  36944. {
  36945. ItemInfo* const item = items.getUnchecked(i);
  36946. if (item->isRealItem())
  36947. if (n++ == index)
  36948. return item;
  36949. }
  36950. return 0;
  36951. }
  36952. int ComboBox::getNumItems() const throw()
  36953. {
  36954. int n = 0;
  36955. for (int i = items.size(); --i >= 0;)
  36956. if (items.getUnchecked(i)->isRealItem())
  36957. ++n;
  36958. return n;
  36959. }
  36960. const String ComboBox::getItemText (const int index) const throw()
  36961. {
  36962. const ItemInfo* const item = getItemForIndex (index);
  36963. if (item != 0)
  36964. return item->name;
  36965. return String::empty;
  36966. }
  36967. int ComboBox::getItemId (const int index) const throw()
  36968. {
  36969. const ItemInfo* const item = getItemForIndex (index);
  36970. return (item != 0) ? item->itemId : 0;
  36971. }
  36972. int ComboBox::indexOfItemId (const int itemId) const throw()
  36973. {
  36974. int n = 0;
  36975. for (int i = 0; i < items.size(); ++i)
  36976. {
  36977. const ItemInfo* const item = items.getUnchecked(i);
  36978. if (item->isRealItem())
  36979. {
  36980. if (item->itemId == itemId)
  36981. return n;
  36982. ++n;
  36983. }
  36984. }
  36985. return -1;
  36986. }
  36987. int ComboBox::getSelectedItemIndex() const throw()
  36988. {
  36989. int index = indexOfItemId (currentId.getValue());
  36990. if (getText() != getItemText (index))
  36991. index = -1;
  36992. return index;
  36993. }
  36994. void ComboBox::setSelectedItemIndex (const int index,
  36995. const bool dontSendChangeMessage) throw()
  36996. {
  36997. setSelectedId (getItemId (index), dontSendChangeMessage);
  36998. }
  36999. int ComboBox::getSelectedId() const throw()
  37000. {
  37001. const ItemInfo* const item = getItemForId (currentId.getValue());
  37002. return (item != 0 && getText() == item->name)
  37003. ? item->itemId
  37004. : 0;
  37005. }
  37006. void ComboBox::setSelectedId (const int newItemId,
  37007. const bool dontSendChangeMessage) throw()
  37008. {
  37009. const ItemInfo* const item = getItemForId (newItemId);
  37010. const String newItemText (item != 0 ? item->name : String::empty);
  37011. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37012. {
  37013. if (! dontSendChangeMessage)
  37014. triggerAsyncUpdate();
  37015. label->setText (newItemText, false);
  37016. lastCurrentId = newItemId;
  37017. currentId = newItemId;
  37018. repaint(); // for the benefit of the 'none selected' text
  37019. }
  37020. }
  37021. void ComboBox::valueChanged (Value&)
  37022. {
  37023. if (lastCurrentId != (int) currentId.getValue())
  37024. setSelectedId (currentId.getValue(), false);
  37025. }
  37026. const String ComboBox::getText() const throw()
  37027. {
  37028. return label->getText();
  37029. }
  37030. void ComboBox::setText (const String& newText,
  37031. const bool dontSendChangeMessage) throw()
  37032. {
  37033. for (int i = items.size(); --i >= 0;)
  37034. {
  37035. const ItemInfo* const item = items.getUnchecked(i);
  37036. if (item->isRealItem()
  37037. && item->name == newText)
  37038. {
  37039. setSelectedId (item->itemId, dontSendChangeMessage);
  37040. return;
  37041. }
  37042. }
  37043. lastCurrentId = 0;
  37044. currentId = 0;
  37045. if (label->getText() != newText)
  37046. {
  37047. label->setText (newText, false);
  37048. if (! dontSendChangeMessage)
  37049. triggerAsyncUpdate();
  37050. }
  37051. repaint();
  37052. }
  37053. void ComboBox::showEditor()
  37054. {
  37055. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37056. label->showEditor();
  37057. }
  37058. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37059. {
  37060. textWhenNothingSelected = newMessage;
  37061. repaint();
  37062. }
  37063. const String ComboBox::getTextWhenNothingSelected() const throw()
  37064. {
  37065. return textWhenNothingSelected;
  37066. }
  37067. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37068. {
  37069. noChoicesMessage = newMessage;
  37070. }
  37071. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37072. {
  37073. return noChoicesMessage;
  37074. }
  37075. void ComboBox::paint (Graphics& g)
  37076. {
  37077. getLookAndFeel().drawComboBox (g,
  37078. getWidth(),
  37079. getHeight(),
  37080. isButtonDown,
  37081. label->getRight(),
  37082. 0,
  37083. getWidth() - label->getRight(),
  37084. getHeight(),
  37085. *this);
  37086. if (textWhenNothingSelected.isNotEmpty()
  37087. && label->getText().isEmpty()
  37088. && ! label->isBeingEdited())
  37089. {
  37090. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37091. g.setFont (label->getFont());
  37092. g.drawFittedText (textWhenNothingSelected,
  37093. label->getX() + 2, label->getY() + 1,
  37094. label->getWidth() - 4, label->getHeight() - 2,
  37095. label->getJustificationType(),
  37096. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37097. }
  37098. }
  37099. void ComboBox::resized()
  37100. {
  37101. if (getHeight() > 0 && getWidth() > 0)
  37102. getLookAndFeel().positionComboBoxText (*this, *label);
  37103. }
  37104. void ComboBox::enablementChanged()
  37105. {
  37106. repaint();
  37107. }
  37108. void ComboBox::lookAndFeelChanged()
  37109. {
  37110. repaint();
  37111. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37112. if (label != 0)
  37113. {
  37114. newLabel->setEditable (label->isEditable());
  37115. newLabel->setJustificationType (label->getJustificationType());
  37116. newLabel->setTooltip (label->getTooltip());
  37117. newLabel->setText (label->getText(), false);
  37118. }
  37119. label = newLabel;
  37120. addAndMakeVisible (newLabel);
  37121. newLabel->addListener (this);
  37122. newLabel->addMouseListener (this, false);
  37123. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37124. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37125. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37126. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37127. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37128. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37129. resized();
  37130. }
  37131. void ComboBox::colourChanged()
  37132. {
  37133. lookAndFeelChanged();
  37134. }
  37135. bool ComboBox::keyPressed (const KeyPress& key)
  37136. {
  37137. bool used = false;
  37138. if (key.isKeyCode (KeyPress::upKey)
  37139. || key.isKeyCode (KeyPress::leftKey))
  37140. {
  37141. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37142. used = true;
  37143. }
  37144. else if (key.isKeyCode (KeyPress::downKey)
  37145. || key.isKeyCode (KeyPress::rightKey))
  37146. {
  37147. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37148. used = true;
  37149. }
  37150. else if (key.isKeyCode (KeyPress::returnKey))
  37151. {
  37152. showPopup();
  37153. used = true;
  37154. }
  37155. return used;
  37156. }
  37157. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37158. {
  37159. // only forward key events that aren't used by this component
  37160. return isKeyDown
  37161. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37162. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37163. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37164. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37165. }
  37166. void ComboBox::focusGained (FocusChangeType)
  37167. {
  37168. repaint();
  37169. }
  37170. void ComboBox::focusLost (FocusChangeType)
  37171. {
  37172. repaint();
  37173. }
  37174. void ComboBox::labelTextChanged (Label*)
  37175. {
  37176. triggerAsyncUpdate();
  37177. }
  37178. void ComboBox::showPopup()
  37179. {
  37180. if (! menuActive)
  37181. {
  37182. const int selectedId = getSelectedId();
  37183. Component::SafePointer<Component> deletionWatcher (this);
  37184. PopupMenu menu;
  37185. menu.setLookAndFeel (&getLookAndFeel());
  37186. for (int i = 0; i < items.size(); ++i)
  37187. {
  37188. const ItemInfo* const item = items.getUnchecked(i);
  37189. if (item->isSeparator())
  37190. menu.addSeparator();
  37191. else if (item->isHeading)
  37192. menu.addSectionHeader (item->name);
  37193. else
  37194. menu.addItem (item->itemId, item->name,
  37195. item->isEnabled, item->itemId == selectedId);
  37196. }
  37197. if (items.size() == 0)
  37198. menu.addItem (1, noChoicesMessage, false);
  37199. const int itemHeight = jlimit (12, 24, getHeight());
  37200. menuActive = true;
  37201. const int resultId = menu.showAt (this, selectedId,
  37202. getWidth(), 1, itemHeight);
  37203. if (deletionWatcher == 0)
  37204. return;
  37205. menuActive = false;
  37206. if (resultId != 0)
  37207. setSelectedId (resultId);
  37208. }
  37209. }
  37210. void ComboBox::mouseDown (const MouseEvent& e)
  37211. {
  37212. beginDragAutoRepeat (300);
  37213. isButtonDown = isEnabled();
  37214. if (isButtonDown
  37215. && (e.eventComponent == this || ! label->isEditable()))
  37216. {
  37217. showPopup();
  37218. }
  37219. }
  37220. void ComboBox::mouseDrag (const MouseEvent& e)
  37221. {
  37222. beginDragAutoRepeat (50);
  37223. if (isButtonDown && ! e.mouseWasClicked())
  37224. showPopup();
  37225. }
  37226. void ComboBox::mouseUp (const MouseEvent& e2)
  37227. {
  37228. if (isButtonDown)
  37229. {
  37230. isButtonDown = false;
  37231. repaint();
  37232. const MouseEvent e (e2.getEventRelativeTo (this));
  37233. if (reallyContains (e.x, e.y, true)
  37234. && (e2.eventComponent == this || ! label->isEditable()))
  37235. {
  37236. showPopup();
  37237. }
  37238. }
  37239. }
  37240. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37241. {
  37242. listeners.add (listener);
  37243. }
  37244. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37245. {
  37246. listeners.remove (listener);
  37247. }
  37248. void ComboBox::handleAsyncUpdate()
  37249. {
  37250. Component::BailOutChecker checker (this);
  37251. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37252. }
  37253. END_JUCE_NAMESPACE
  37254. /*** End of inlined file: juce_ComboBox.cpp ***/
  37255. /*** Start of inlined file: juce_Label.cpp ***/
  37256. BEGIN_JUCE_NAMESPACE
  37257. Label::Label (const String& componentName,
  37258. const String& labelText)
  37259. : Component (componentName),
  37260. textValue (labelText),
  37261. lastTextValue (labelText),
  37262. font (15.0f),
  37263. justification (Justification::centredLeft),
  37264. ownerComponent (0),
  37265. horizontalBorderSize (5),
  37266. verticalBorderSize (1),
  37267. minimumHorizontalScale (0.7f),
  37268. editSingleClick (false),
  37269. editDoubleClick (false),
  37270. lossOfFocusDiscardsChanges (false)
  37271. {
  37272. setColour (TextEditor::textColourId, Colours::black);
  37273. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37274. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37275. textValue.addListener (this);
  37276. }
  37277. Label::~Label()
  37278. {
  37279. textValue.removeListener (this);
  37280. if (ownerComponent != 0)
  37281. ownerComponent->removeComponentListener (this);
  37282. editor = 0;
  37283. }
  37284. void Label::setText (const String& newText,
  37285. const bool broadcastChangeMessage)
  37286. {
  37287. hideEditor (true);
  37288. if (lastTextValue != newText)
  37289. {
  37290. lastTextValue = newText;
  37291. textValue = newText;
  37292. repaint();
  37293. textWasChanged();
  37294. if (ownerComponent != 0)
  37295. componentMovedOrResized (*ownerComponent, true, true);
  37296. if (broadcastChangeMessage)
  37297. callChangeListeners();
  37298. }
  37299. }
  37300. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37301. {
  37302. return (returnActiveEditorContents && isBeingEdited())
  37303. ? editor->getText()
  37304. : textValue.toString();
  37305. }
  37306. void Label::valueChanged (Value&)
  37307. {
  37308. if (lastTextValue != textValue.toString())
  37309. setText (textValue.toString(), true);
  37310. }
  37311. void Label::setFont (const Font& newFont) throw()
  37312. {
  37313. font = newFont;
  37314. repaint();
  37315. }
  37316. const Font& Label::getFont() const throw()
  37317. {
  37318. return font;
  37319. }
  37320. void Label::setEditable (const bool editOnSingleClick,
  37321. const bool editOnDoubleClick,
  37322. const bool lossOfFocusDiscardsChanges_) throw()
  37323. {
  37324. editSingleClick = editOnSingleClick;
  37325. editDoubleClick = editOnDoubleClick;
  37326. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37327. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37328. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37329. }
  37330. void Label::setJustificationType (const Justification& justification_) throw()
  37331. {
  37332. justification = justification_;
  37333. repaint();
  37334. }
  37335. void Label::setBorderSize (int h, int v)
  37336. {
  37337. horizontalBorderSize = h;
  37338. verticalBorderSize = v;
  37339. repaint();
  37340. }
  37341. Component* Label::getAttachedComponent() const
  37342. {
  37343. return static_cast<Component*> (ownerComponent);
  37344. }
  37345. void Label::attachToComponent (Component* owner,
  37346. const bool onLeft)
  37347. {
  37348. if (ownerComponent != 0)
  37349. ownerComponent->removeComponentListener (this);
  37350. ownerComponent = owner;
  37351. leftOfOwnerComp = onLeft;
  37352. if (ownerComponent != 0)
  37353. {
  37354. setVisible (owner->isVisible());
  37355. ownerComponent->addComponentListener (this);
  37356. componentParentHierarchyChanged (*ownerComponent);
  37357. componentMovedOrResized (*ownerComponent, true, true);
  37358. }
  37359. }
  37360. void Label::componentMovedOrResized (Component& component,
  37361. bool /*wasMoved*/,
  37362. bool /*wasResized*/)
  37363. {
  37364. if (leftOfOwnerComp)
  37365. {
  37366. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37367. component.getHeight());
  37368. setTopRightPosition (component.getX(), component.getY());
  37369. }
  37370. else
  37371. {
  37372. setSize (component.getWidth(),
  37373. 8 + roundToInt (getFont().getHeight()));
  37374. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37375. }
  37376. }
  37377. void Label::componentParentHierarchyChanged (Component& component)
  37378. {
  37379. if (component.getParentComponent() != 0)
  37380. component.getParentComponent()->addChildComponent (this);
  37381. }
  37382. void Label::componentVisibilityChanged (Component& component)
  37383. {
  37384. setVisible (component.isVisible());
  37385. }
  37386. void Label::textWasEdited()
  37387. {
  37388. }
  37389. void Label::textWasChanged()
  37390. {
  37391. }
  37392. void Label::showEditor()
  37393. {
  37394. if (editor == 0)
  37395. {
  37396. addAndMakeVisible (editor = createEditorComponent());
  37397. editor->setText (getText(), false);
  37398. editor->addListener (this);
  37399. editor->grabKeyboardFocus();
  37400. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37401. editor->addListener (this);
  37402. resized();
  37403. repaint();
  37404. editorShown (editor);
  37405. enterModalState (false);
  37406. editor->grabKeyboardFocus();
  37407. }
  37408. }
  37409. void Label::editorShown (TextEditor* /*editorComponent*/)
  37410. {
  37411. }
  37412. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37413. {
  37414. }
  37415. bool Label::updateFromTextEditorContents()
  37416. {
  37417. jassert (editor != 0);
  37418. const String newText (editor->getText());
  37419. if (textValue.toString() != newText)
  37420. {
  37421. lastTextValue = newText;
  37422. textValue = newText;
  37423. repaint();
  37424. textWasChanged();
  37425. if (ownerComponent != 0)
  37426. componentMovedOrResized (*ownerComponent, true, true);
  37427. return true;
  37428. }
  37429. return false;
  37430. }
  37431. void Label::hideEditor (const bool discardCurrentEditorContents)
  37432. {
  37433. if (editor != 0)
  37434. {
  37435. Component::SafePointer<Component> deletionChecker (this);
  37436. editorAboutToBeHidden (editor);
  37437. const bool changed = (! discardCurrentEditorContents)
  37438. && updateFromTextEditorContents();
  37439. editor = 0;
  37440. repaint();
  37441. if (changed)
  37442. textWasEdited();
  37443. if (deletionChecker != 0)
  37444. exitModalState (0);
  37445. if (changed && deletionChecker != 0)
  37446. callChangeListeners();
  37447. }
  37448. }
  37449. void Label::inputAttemptWhenModal()
  37450. {
  37451. if (editor != 0)
  37452. {
  37453. if (lossOfFocusDiscardsChanges)
  37454. textEditorEscapeKeyPressed (*editor);
  37455. else
  37456. textEditorReturnKeyPressed (*editor);
  37457. }
  37458. }
  37459. bool Label::isBeingEdited() const throw()
  37460. {
  37461. return editor != 0;
  37462. }
  37463. TextEditor* Label::createEditorComponent()
  37464. {
  37465. TextEditor* const ed = new TextEditor (getName());
  37466. ed->setFont (font);
  37467. // copy these colours from our own settings..
  37468. const int cols[] = { TextEditor::backgroundColourId,
  37469. TextEditor::textColourId,
  37470. TextEditor::highlightColourId,
  37471. TextEditor::highlightedTextColourId,
  37472. TextEditor::caretColourId,
  37473. TextEditor::outlineColourId,
  37474. TextEditor::focusedOutlineColourId,
  37475. TextEditor::shadowColourId };
  37476. for (int i = 0; i < numElementsInArray (cols); ++i)
  37477. ed->setColour (cols[i], findColour (cols[i]));
  37478. return ed;
  37479. }
  37480. void Label::paint (Graphics& g)
  37481. {
  37482. getLookAndFeel().drawLabel (g, *this);
  37483. }
  37484. void Label::mouseUp (const MouseEvent& e)
  37485. {
  37486. if (editSingleClick
  37487. && e.mouseWasClicked()
  37488. && contains (e.x, e.y)
  37489. && ! e.mods.isPopupMenu())
  37490. {
  37491. showEditor();
  37492. }
  37493. }
  37494. void Label::mouseDoubleClick (const MouseEvent& e)
  37495. {
  37496. if (editDoubleClick && ! e.mods.isPopupMenu())
  37497. showEditor();
  37498. }
  37499. void Label::resized()
  37500. {
  37501. if (editor != 0)
  37502. editor->setBoundsInset (BorderSize (0));
  37503. }
  37504. void Label::focusGained (FocusChangeType cause)
  37505. {
  37506. if (editSingleClick && cause == focusChangedByTabKey)
  37507. showEditor();
  37508. }
  37509. void Label::enablementChanged()
  37510. {
  37511. repaint();
  37512. }
  37513. void Label::colourChanged()
  37514. {
  37515. repaint();
  37516. }
  37517. void Label::setMinimumHorizontalScale (const float newScale)
  37518. {
  37519. if (minimumHorizontalScale != newScale)
  37520. {
  37521. minimumHorizontalScale = newScale;
  37522. repaint();
  37523. }
  37524. }
  37525. // We'll use a custom focus traverser here to make sure focus goes from the
  37526. // text editor to another component rather than back to the label itself.
  37527. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37528. {
  37529. public:
  37530. LabelKeyboardFocusTraverser() {}
  37531. Component* getNextComponent (Component* current)
  37532. {
  37533. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37534. ? current->getParentComponent() : current);
  37535. }
  37536. Component* getPreviousComponent (Component* current)
  37537. {
  37538. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37539. ? current->getParentComponent() : current);
  37540. }
  37541. };
  37542. KeyboardFocusTraverser* Label::createFocusTraverser()
  37543. {
  37544. return new LabelKeyboardFocusTraverser();
  37545. }
  37546. void Label::addListener (LabelListener* const listener) throw()
  37547. {
  37548. listeners.add (listener);
  37549. }
  37550. void Label::removeListener (LabelListener* const listener) throw()
  37551. {
  37552. listeners.remove (listener);
  37553. }
  37554. void Label::callChangeListeners()
  37555. {
  37556. Component::BailOutChecker checker (this);
  37557. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37558. }
  37559. void Label::textEditorTextChanged (TextEditor& ed)
  37560. {
  37561. if (editor != 0)
  37562. {
  37563. jassert (&ed == editor);
  37564. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37565. {
  37566. if (lossOfFocusDiscardsChanges)
  37567. textEditorEscapeKeyPressed (ed);
  37568. else
  37569. textEditorReturnKeyPressed (ed);
  37570. }
  37571. }
  37572. }
  37573. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37574. {
  37575. if (editor != 0)
  37576. {
  37577. jassert (&ed == editor);
  37578. (void) ed;
  37579. const bool changed = updateFromTextEditorContents();
  37580. hideEditor (true);
  37581. if (changed)
  37582. {
  37583. Component::SafePointer<Component> deletionChecker (this);
  37584. textWasEdited();
  37585. if (deletionChecker != 0)
  37586. callChangeListeners();
  37587. }
  37588. }
  37589. }
  37590. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37591. {
  37592. if (editor != 0)
  37593. {
  37594. jassert (&ed == editor);
  37595. (void) ed;
  37596. editor->setText (textValue.toString(), false);
  37597. hideEditor (true);
  37598. }
  37599. }
  37600. void Label::textEditorFocusLost (TextEditor& ed)
  37601. {
  37602. textEditorTextChanged (ed);
  37603. }
  37604. END_JUCE_NAMESPACE
  37605. /*** End of inlined file: juce_Label.cpp ***/
  37606. /*** Start of inlined file: juce_ListBox.cpp ***/
  37607. BEGIN_JUCE_NAMESPACE
  37608. class ListBoxRowComponent : public Component,
  37609. public TooltipClient
  37610. {
  37611. public:
  37612. ListBoxRowComponent (ListBox& owner_)
  37613. : owner (owner_),
  37614. row (-1),
  37615. selected (false),
  37616. isDragging (false)
  37617. {
  37618. }
  37619. ~ListBoxRowComponent()
  37620. {
  37621. deleteAllChildren();
  37622. }
  37623. void paint (Graphics& g)
  37624. {
  37625. if (owner.getModel() != 0)
  37626. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37627. }
  37628. void update (const int row_, const bool selected_)
  37629. {
  37630. if (row != row_ || selected != selected_)
  37631. {
  37632. repaint();
  37633. row = row_;
  37634. selected = selected_;
  37635. }
  37636. if (owner.getModel() != 0)
  37637. {
  37638. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37639. if (customComp != 0)
  37640. {
  37641. addAndMakeVisible (customComp);
  37642. customComp->setBounds (0, 0, getWidth(), getHeight());
  37643. for (int i = getNumChildComponents(); --i >= 0;)
  37644. if (getChildComponent (i) != customComp)
  37645. delete getChildComponent (i);
  37646. }
  37647. else
  37648. {
  37649. deleteAllChildren();
  37650. }
  37651. }
  37652. }
  37653. void mouseDown (const MouseEvent& e)
  37654. {
  37655. isDragging = false;
  37656. selectRowOnMouseUp = false;
  37657. if (isEnabled())
  37658. {
  37659. if (! selected)
  37660. {
  37661. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37662. if (owner.getModel() != 0)
  37663. owner.getModel()->listBoxItemClicked (row, e);
  37664. }
  37665. else
  37666. {
  37667. selectRowOnMouseUp = true;
  37668. }
  37669. }
  37670. }
  37671. void mouseUp (const MouseEvent& e)
  37672. {
  37673. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37674. {
  37675. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37676. if (owner.getModel() != 0)
  37677. owner.getModel()->listBoxItemClicked (row, e);
  37678. }
  37679. }
  37680. void mouseDoubleClick (const MouseEvent& e)
  37681. {
  37682. if (owner.getModel() != 0 && isEnabled())
  37683. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37684. }
  37685. void mouseDrag (const MouseEvent& e)
  37686. {
  37687. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37688. {
  37689. const SparseSet<int> selectedRows (owner.getSelectedRows());
  37690. if (selectedRows.size() > 0)
  37691. {
  37692. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37693. if (dragDescription.isNotEmpty())
  37694. {
  37695. isDragging = true;
  37696. owner.startDragAndDrop (e, dragDescription);
  37697. }
  37698. }
  37699. }
  37700. }
  37701. void resized()
  37702. {
  37703. if (getNumChildComponents() > 0)
  37704. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37705. }
  37706. const String getTooltip()
  37707. {
  37708. if (owner.getModel() != 0)
  37709. return owner.getModel()->getTooltipForRow (row);
  37710. return String::empty;
  37711. }
  37712. juce_UseDebuggingNewOperator
  37713. bool neededFlag;
  37714. private:
  37715. ListBox& owner;
  37716. int row;
  37717. bool selected, isDragging, selectRowOnMouseUp;
  37718. ListBoxRowComponent (const ListBoxRowComponent&);
  37719. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37720. };
  37721. class ListViewport : public Viewport
  37722. {
  37723. public:
  37724. int firstIndex, firstWholeIndex, lastWholeIndex;
  37725. bool hasUpdated;
  37726. ListViewport (ListBox& owner_)
  37727. : owner (owner_)
  37728. {
  37729. setWantsKeyboardFocus (false);
  37730. setViewedComponent (new Component());
  37731. getViewedComponent()->addMouseListener (this, false);
  37732. getViewedComponent()->setWantsKeyboardFocus (false);
  37733. }
  37734. ~ListViewport()
  37735. {
  37736. getViewedComponent()->removeMouseListener (this);
  37737. getViewedComponent()->deleteAllChildren();
  37738. }
  37739. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37740. {
  37741. return static_cast <ListBoxRowComponent*>
  37742. (getViewedComponent()->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents())));
  37743. }
  37744. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  37745. {
  37746. const int index = getIndexOfChildComponent (rowComponent);
  37747. const int num = getViewedComponent()->getNumChildComponents();
  37748. for (int i = num; --i >= 0;)
  37749. if (((firstIndex + i) % jmax (1, num)) == index)
  37750. return firstIndex + i;
  37751. return -1;
  37752. }
  37753. Component* getComponentForRowIfOnscreen (const int row) const throw()
  37754. {
  37755. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  37756. ? getComponentForRow (row) : 0;
  37757. }
  37758. void visibleAreaChanged (int, int, int, int)
  37759. {
  37760. updateVisibleArea (true);
  37761. if (owner.getModel() != 0)
  37762. owner.getModel()->listWasScrolled();
  37763. }
  37764. void updateVisibleArea (const bool makeSureItUpdatesContent)
  37765. {
  37766. hasUpdated = false;
  37767. const int newX = getViewedComponent()->getX();
  37768. int newY = getViewedComponent()->getY();
  37769. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  37770. const int newH = owner.totalItems * owner.getRowHeight();
  37771. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  37772. newY = getMaximumVisibleHeight() - newH;
  37773. getViewedComponent()->setBounds (newX, newY, newW, newH);
  37774. if (makeSureItUpdatesContent && ! hasUpdated)
  37775. updateContents();
  37776. }
  37777. void updateContents()
  37778. {
  37779. hasUpdated = true;
  37780. const int rowHeight = owner.getRowHeight();
  37781. if (rowHeight > 0)
  37782. {
  37783. const int y = getViewPositionY();
  37784. const int w = getViewedComponent()->getWidth();
  37785. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  37786. while (numNeeded > getViewedComponent()->getNumChildComponents())
  37787. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  37788. jassert (numNeeded >= 0);
  37789. while (numNeeded < getViewedComponent()->getNumChildComponents())
  37790. {
  37791. Component* const rowToRemove
  37792. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  37793. delete rowToRemove;
  37794. }
  37795. firstIndex = y / rowHeight;
  37796. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  37797. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  37798. for (int i = 0; i < numNeeded; ++i)
  37799. {
  37800. const int row = i + firstIndex;
  37801. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  37802. if (rowComp != 0)
  37803. {
  37804. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  37805. rowComp->update (row, owner.isRowSelected (row));
  37806. }
  37807. }
  37808. }
  37809. if (owner.headerComponent != 0)
  37810. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  37811. owner.outlineThickness,
  37812. jmax (owner.getWidth() - owner.outlineThickness * 2,
  37813. getViewedComponent()->getWidth()),
  37814. owner.headerComponent->getHeight());
  37815. }
  37816. void paint (Graphics& g)
  37817. {
  37818. if (isOpaque())
  37819. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  37820. }
  37821. bool keyPressed (const KeyPress& key)
  37822. {
  37823. if (key.isKeyCode (KeyPress::upKey)
  37824. || key.isKeyCode (KeyPress::downKey)
  37825. || key.isKeyCode (KeyPress::pageUpKey)
  37826. || key.isKeyCode (KeyPress::pageDownKey)
  37827. || key.isKeyCode (KeyPress::homeKey)
  37828. || key.isKeyCode (KeyPress::endKey))
  37829. {
  37830. // we want to avoid these keypresses going to the viewport, and instead allow
  37831. // them to pass up to our listbox..
  37832. return false;
  37833. }
  37834. return Viewport::keyPressed (key);
  37835. }
  37836. juce_UseDebuggingNewOperator
  37837. private:
  37838. ListBox& owner;
  37839. ListViewport (const ListViewport&);
  37840. ListViewport& operator= (const ListViewport&);
  37841. };
  37842. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  37843. : Component (name),
  37844. model (model_),
  37845. headerComponent (0),
  37846. totalItems (0),
  37847. rowHeight (22),
  37848. minimumRowWidth (0),
  37849. outlineThickness (0),
  37850. lastRowSelected (-1),
  37851. mouseMoveSelects (false),
  37852. multipleSelection (false),
  37853. hasDoneInitialUpdate (false)
  37854. {
  37855. addAndMakeVisible (viewport = new ListViewport (*this));
  37856. setWantsKeyboardFocus (true);
  37857. colourChanged();
  37858. }
  37859. ListBox::~ListBox()
  37860. {
  37861. deleteAllChildren();
  37862. }
  37863. void ListBox::setModel (ListBoxModel* const newModel)
  37864. {
  37865. if (model != newModel)
  37866. {
  37867. model = newModel;
  37868. updateContent();
  37869. }
  37870. }
  37871. void ListBox::setMultipleSelectionEnabled (bool b)
  37872. {
  37873. multipleSelection = b;
  37874. }
  37875. void ListBox::setMouseMoveSelectsRows (bool b)
  37876. {
  37877. mouseMoveSelects = b;
  37878. if (b)
  37879. addMouseListener (this, true);
  37880. }
  37881. void ListBox::paint (Graphics& g)
  37882. {
  37883. if (! hasDoneInitialUpdate)
  37884. updateContent();
  37885. g.fillAll (findColour (backgroundColourId));
  37886. }
  37887. void ListBox::paintOverChildren (Graphics& g)
  37888. {
  37889. if (outlineThickness > 0)
  37890. {
  37891. g.setColour (findColour (outlineColourId));
  37892. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  37893. }
  37894. }
  37895. void ListBox::resized()
  37896. {
  37897. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  37898. outlineThickness,
  37899. outlineThickness,
  37900. outlineThickness));
  37901. viewport->setSingleStepSizes (20, getRowHeight());
  37902. viewport->updateVisibleArea (false);
  37903. }
  37904. void ListBox::visibilityChanged()
  37905. {
  37906. viewport->updateVisibleArea (true);
  37907. }
  37908. Viewport* ListBox::getViewport() const throw()
  37909. {
  37910. return viewport;
  37911. }
  37912. void ListBox::updateContent()
  37913. {
  37914. hasDoneInitialUpdate = true;
  37915. totalItems = (model != 0) ? model->getNumRows() : 0;
  37916. bool selectionChanged = false;
  37917. if (selected [selected.size() - 1] >= totalItems)
  37918. {
  37919. selected.removeRange (Range <int> (totalItems, std::numeric_limits<int>::max()));
  37920. lastRowSelected = getSelectedRow (0);
  37921. selectionChanged = true;
  37922. }
  37923. viewport->updateVisibleArea (isVisible());
  37924. viewport->resized();
  37925. if (selectionChanged && model != 0)
  37926. model->selectedRowsChanged (lastRowSelected);
  37927. }
  37928. void ListBox::selectRow (const int row,
  37929. bool dontScroll,
  37930. bool deselectOthersFirst)
  37931. {
  37932. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  37933. }
  37934. void ListBox::selectRowInternal (const int row,
  37935. bool dontScroll,
  37936. bool deselectOthersFirst,
  37937. bool isMouseClick)
  37938. {
  37939. if (! multipleSelection)
  37940. deselectOthersFirst = true;
  37941. if ((! isRowSelected (row))
  37942. || (deselectOthersFirst && getNumSelectedRows() > 1))
  37943. {
  37944. if (((unsigned int) row) < (unsigned int) totalItems)
  37945. {
  37946. if (deselectOthersFirst)
  37947. selected.clear();
  37948. selected.addRange (Range<int> (row, row + 1));
  37949. if (getHeight() == 0 || getWidth() == 0)
  37950. dontScroll = true;
  37951. viewport->hasUpdated = false;
  37952. if (row < viewport->firstWholeIndex && ! dontScroll)
  37953. {
  37954. viewport->setViewPosition (viewport->getViewPositionX(),
  37955. row * getRowHeight());
  37956. }
  37957. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  37958. {
  37959. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  37960. if (row >= lastRowSelected + rowsOnScreen
  37961. && rowsOnScreen < totalItems - 1
  37962. && ! isMouseClick)
  37963. {
  37964. viewport->setViewPosition (viewport->getViewPositionX(),
  37965. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  37966. * getRowHeight());
  37967. }
  37968. else
  37969. {
  37970. viewport->setViewPosition (viewport->getViewPositionX(),
  37971. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  37972. }
  37973. }
  37974. if (! viewport->hasUpdated)
  37975. viewport->updateContents();
  37976. lastRowSelected = row;
  37977. model->selectedRowsChanged (row);
  37978. }
  37979. else
  37980. {
  37981. if (deselectOthersFirst)
  37982. deselectAllRows();
  37983. }
  37984. }
  37985. }
  37986. void ListBox::deselectRow (const int row)
  37987. {
  37988. if (selected.contains (row))
  37989. {
  37990. selected.removeRange (Range <int> (row, row + 1));
  37991. if (row == lastRowSelected)
  37992. lastRowSelected = getSelectedRow (0);
  37993. viewport->updateContents();
  37994. model->selectedRowsChanged (lastRowSelected);
  37995. }
  37996. }
  37997. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  37998. const bool sendNotificationEventToModel)
  37999. {
  38000. selected = setOfRowsToBeSelected;
  38001. selected.removeRange (Range <int> (totalItems, std::numeric_limits<int>::max()));
  38002. if (! isRowSelected (lastRowSelected))
  38003. lastRowSelected = getSelectedRow (0);
  38004. viewport->updateContents();
  38005. if ((model != 0) && sendNotificationEventToModel)
  38006. model->selectedRowsChanged (lastRowSelected);
  38007. }
  38008. const SparseSet<int> ListBox::getSelectedRows() const
  38009. {
  38010. return selected;
  38011. }
  38012. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38013. {
  38014. if (multipleSelection && (firstRow != lastRow))
  38015. {
  38016. const int numRows = totalItems - 1;
  38017. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38018. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38019. selected.addRange (Range <int> (jmin (firstRow, lastRow),
  38020. jmax (firstRow, lastRow) + 1));
  38021. selected.removeRange (Range <int> (lastRow, lastRow + 1));
  38022. }
  38023. selectRowInternal (lastRow, false, false, true);
  38024. }
  38025. void ListBox::flipRowSelection (const int row)
  38026. {
  38027. if (isRowSelected (row))
  38028. deselectRow (row);
  38029. else
  38030. selectRowInternal (row, false, false, true);
  38031. }
  38032. void ListBox::deselectAllRows()
  38033. {
  38034. if (! selected.isEmpty())
  38035. {
  38036. selected.clear();
  38037. lastRowSelected = -1;
  38038. viewport->updateContents();
  38039. if (model != 0)
  38040. model->selectedRowsChanged (lastRowSelected);
  38041. }
  38042. }
  38043. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38044. const ModifierKeys& mods)
  38045. {
  38046. if (multipleSelection && mods.isCommandDown())
  38047. {
  38048. flipRowSelection (row);
  38049. }
  38050. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38051. {
  38052. selectRangeOfRows (lastRowSelected, row);
  38053. }
  38054. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38055. {
  38056. selectRowInternal (row, false, true, true);
  38057. }
  38058. }
  38059. int ListBox::getNumSelectedRows() const
  38060. {
  38061. return selected.size();
  38062. }
  38063. int ListBox::getSelectedRow (const int index) const
  38064. {
  38065. return (((unsigned int) index) < (unsigned int) selected.size())
  38066. ? selected [index] : -1;
  38067. }
  38068. bool ListBox::isRowSelected (const int row) const
  38069. {
  38070. return selected.contains (row);
  38071. }
  38072. int ListBox::getLastRowSelected() const
  38073. {
  38074. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38075. }
  38076. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38077. {
  38078. if (((unsigned int) x) < (unsigned int) getWidth())
  38079. {
  38080. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38081. if (((unsigned int) row) < (unsigned int) totalItems)
  38082. return row;
  38083. }
  38084. return -1;
  38085. }
  38086. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38087. {
  38088. if (((unsigned int) x) < (unsigned int) getWidth())
  38089. {
  38090. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38091. return jlimit (0, totalItems, row);
  38092. }
  38093. return -1;
  38094. }
  38095. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38096. {
  38097. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38098. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38099. }
  38100. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38101. {
  38102. return viewport->getRowNumberOfComponent (rowComponent);
  38103. }
  38104. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38105. const bool relativeToComponentTopLeft) const throw()
  38106. {
  38107. const int rowHeight = getRowHeight();
  38108. int y = viewport->getY() + rowHeight * rowNumber;
  38109. if (relativeToComponentTopLeft)
  38110. y -= viewport->getViewPositionY();
  38111. return Rectangle<int> (viewport->getX(), y,
  38112. viewport->getViewedComponent()->getWidth(), rowHeight);
  38113. }
  38114. void ListBox::setVerticalPosition (const double proportion)
  38115. {
  38116. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38117. viewport->setViewPosition (viewport->getViewPositionX(),
  38118. jmax (0, roundToInt (proportion * offscreen)));
  38119. }
  38120. double ListBox::getVerticalPosition() const
  38121. {
  38122. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38123. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38124. : 0;
  38125. }
  38126. int ListBox::getVisibleRowWidth() const throw()
  38127. {
  38128. return viewport->getViewWidth();
  38129. }
  38130. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38131. {
  38132. if (row < viewport->firstWholeIndex)
  38133. {
  38134. viewport->setViewPosition (viewport->getViewPositionX(),
  38135. row * getRowHeight());
  38136. }
  38137. else if (row >= viewport->lastWholeIndex)
  38138. {
  38139. viewport->setViewPosition (viewport->getViewPositionX(),
  38140. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38141. }
  38142. }
  38143. bool ListBox::keyPressed (const KeyPress& key)
  38144. {
  38145. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38146. const bool multiple = multipleSelection
  38147. && (lastRowSelected >= 0)
  38148. && (key.getModifiers().isShiftDown()
  38149. || key.getModifiers().isCtrlDown()
  38150. || key.getModifiers().isCommandDown());
  38151. if (key.isKeyCode (KeyPress::upKey))
  38152. {
  38153. if (multiple)
  38154. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38155. else
  38156. selectRow (jmax (0, lastRowSelected - 1));
  38157. }
  38158. else if (key.isKeyCode (KeyPress::returnKey)
  38159. && isRowSelected (lastRowSelected))
  38160. {
  38161. if (model != 0)
  38162. model->returnKeyPressed (lastRowSelected);
  38163. }
  38164. else if (key.isKeyCode (KeyPress::pageUpKey))
  38165. {
  38166. if (multiple)
  38167. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38168. else
  38169. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38170. }
  38171. else if (key.isKeyCode (KeyPress::pageDownKey))
  38172. {
  38173. if (multiple)
  38174. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38175. else
  38176. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38177. }
  38178. else if (key.isKeyCode (KeyPress::homeKey))
  38179. {
  38180. if (multiple && key.getModifiers().isShiftDown())
  38181. selectRangeOfRows (lastRowSelected, 0);
  38182. else
  38183. selectRow (0);
  38184. }
  38185. else if (key.isKeyCode (KeyPress::endKey))
  38186. {
  38187. if (multiple && key.getModifiers().isShiftDown())
  38188. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38189. else
  38190. selectRow (totalItems - 1);
  38191. }
  38192. else if (key.isKeyCode (KeyPress::downKey))
  38193. {
  38194. if (multiple)
  38195. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38196. else
  38197. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38198. }
  38199. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38200. && isRowSelected (lastRowSelected))
  38201. {
  38202. if (model != 0)
  38203. model->deleteKeyPressed (lastRowSelected);
  38204. }
  38205. else if (multiple && key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  38206. {
  38207. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38208. }
  38209. else
  38210. {
  38211. return false;
  38212. }
  38213. return true;
  38214. }
  38215. bool ListBox::keyStateChanged (const bool isKeyDown)
  38216. {
  38217. return isKeyDown
  38218. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38219. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38220. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38221. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38222. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38223. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38224. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38225. }
  38226. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38227. {
  38228. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38229. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38230. }
  38231. void ListBox::mouseMove (const MouseEvent& e)
  38232. {
  38233. if (mouseMoveSelects)
  38234. {
  38235. const MouseEvent e2 (e.getEventRelativeTo (this));
  38236. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38237. }
  38238. }
  38239. void ListBox::mouseExit (const MouseEvent& e)
  38240. {
  38241. mouseMove (e);
  38242. }
  38243. void ListBox::mouseUp (const MouseEvent& e)
  38244. {
  38245. if (e.mouseWasClicked() && model != 0)
  38246. model->backgroundClicked();
  38247. }
  38248. void ListBox::setRowHeight (const int newHeight)
  38249. {
  38250. rowHeight = jmax (1, newHeight);
  38251. viewport->setSingleStepSizes (20, rowHeight);
  38252. updateContent();
  38253. }
  38254. int ListBox::getNumRowsOnScreen() const throw()
  38255. {
  38256. return viewport->getMaximumVisibleHeight() / rowHeight;
  38257. }
  38258. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38259. {
  38260. minimumRowWidth = newMinimumWidth;
  38261. updateContent();
  38262. }
  38263. int ListBox::getVisibleContentWidth() const throw()
  38264. {
  38265. return viewport->getMaximumVisibleWidth();
  38266. }
  38267. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38268. {
  38269. return viewport->getVerticalScrollBar();
  38270. }
  38271. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38272. {
  38273. return viewport->getHorizontalScrollBar();
  38274. }
  38275. void ListBox::colourChanged()
  38276. {
  38277. setOpaque (findColour (backgroundColourId).isOpaque());
  38278. viewport->setOpaque (isOpaque());
  38279. repaint();
  38280. }
  38281. void ListBox::setOutlineThickness (const int outlineThickness_)
  38282. {
  38283. outlineThickness = outlineThickness_;
  38284. resized();
  38285. }
  38286. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38287. {
  38288. if (headerComponent != newHeaderComponent)
  38289. {
  38290. delete headerComponent;
  38291. headerComponent = newHeaderComponent;
  38292. addAndMakeVisible (newHeaderComponent);
  38293. ListBox::resized();
  38294. }
  38295. }
  38296. void ListBox::repaintRow (const int rowNumber) throw()
  38297. {
  38298. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38299. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38300. }
  38301. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38302. {
  38303. Rectangle<int> imageArea;
  38304. const int firstRow = getRowContainingPosition (0, 0);
  38305. int i;
  38306. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38307. {
  38308. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38309. if (rowComp != 0 && isRowSelected (firstRow + i))
  38310. {
  38311. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38312. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38313. if (imageArea.isEmpty())
  38314. imageArea = rowRect;
  38315. else
  38316. imageArea = imageArea.getUnion (rowRect);
  38317. }
  38318. }
  38319. imageArea = imageArea.getIntersection (getLocalBounds());
  38320. imageX = imageArea.getX();
  38321. imageY = imageArea.getY();
  38322. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38323. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38324. {
  38325. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38326. if (rowComp != 0 && isRowSelected (firstRow + i))
  38327. {
  38328. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38329. Graphics g (*snapshot);
  38330. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38331. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38332. rowComp->paintEntireComponent (g);
  38333. }
  38334. }
  38335. return snapshot;
  38336. }
  38337. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38338. {
  38339. DragAndDropContainer* const dragContainer
  38340. = DragAndDropContainer::findParentDragContainerFor (this);
  38341. if (dragContainer != 0)
  38342. {
  38343. int x, y;
  38344. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38345. dragImage->multiplyAllAlphas (0.6f);
  38346. MouseEvent e2 (e.getEventRelativeTo (this));
  38347. const Point<int> p (x - e2.x, y - e2.y);
  38348. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38349. }
  38350. else
  38351. {
  38352. // to be able to do a drag-and-drop operation, the listbox needs to
  38353. // be inside a component which is also a DragAndDropContainer.
  38354. jassertfalse
  38355. }
  38356. }
  38357. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38358. {
  38359. (void) existingComponentToUpdate;
  38360. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38361. return 0;
  38362. }
  38363. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38364. {
  38365. }
  38366. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38367. {
  38368. }
  38369. void ListBoxModel::backgroundClicked()
  38370. {
  38371. }
  38372. void ListBoxModel::selectedRowsChanged (int)
  38373. {
  38374. }
  38375. void ListBoxModel::deleteKeyPressed (int)
  38376. {
  38377. }
  38378. void ListBoxModel::returnKeyPressed (int)
  38379. {
  38380. }
  38381. void ListBoxModel::listWasScrolled()
  38382. {
  38383. }
  38384. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38385. {
  38386. return String::empty;
  38387. }
  38388. const String ListBoxModel::getTooltipForRow (int)
  38389. {
  38390. return String::empty;
  38391. }
  38392. END_JUCE_NAMESPACE
  38393. /*** End of inlined file: juce_ListBox.cpp ***/
  38394. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38395. BEGIN_JUCE_NAMESPACE
  38396. ProgressBar::ProgressBar (double& progress_)
  38397. : progress (progress_),
  38398. displayPercentage (true),
  38399. lastCallbackTime (0)
  38400. {
  38401. currentValue = jlimit (0.0, 1.0, progress);
  38402. }
  38403. ProgressBar::~ProgressBar()
  38404. {
  38405. }
  38406. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38407. {
  38408. displayPercentage = shouldDisplayPercentage;
  38409. repaint();
  38410. }
  38411. void ProgressBar::setTextToDisplay (const String& text)
  38412. {
  38413. displayPercentage = false;
  38414. displayedMessage = text;
  38415. }
  38416. void ProgressBar::lookAndFeelChanged()
  38417. {
  38418. setOpaque (findColour (backgroundColourId).isOpaque());
  38419. }
  38420. void ProgressBar::colourChanged()
  38421. {
  38422. lookAndFeelChanged();
  38423. }
  38424. void ProgressBar::paint (Graphics& g)
  38425. {
  38426. String text;
  38427. if (displayPercentage)
  38428. {
  38429. if (currentValue >= 0 && currentValue <= 1.0)
  38430. text << roundToInt (currentValue * 100.0) << '%';
  38431. }
  38432. else
  38433. {
  38434. text = displayedMessage;
  38435. }
  38436. getLookAndFeel().drawProgressBar (g, *this,
  38437. getWidth(), getHeight(),
  38438. currentValue, text);
  38439. }
  38440. void ProgressBar::visibilityChanged()
  38441. {
  38442. if (isVisible())
  38443. startTimer (30);
  38444. else
  38445. stopTimer();
  38446. }
  38447. void ProgressBar::timerCallback()
  38448. {
  38449. double newProgress = progress;
  38450. const uint32 now = Time::getMillisecondCounter();
  38451. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38452. lastCallbackTime = now;
  38453. if (currentValue != newProgress
  38454. || newProgress < 0 || newProgress >= 1.0
  38455. || currentMessage != displayedMessage)
  38456. {
  38457. if (currentValue < newProgress
  38458. && newProgress >= 0 && newProgress < 1.0
  38459. && currentValue >= 0 && currentValue < 1.0)
  38460. {
  38461. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38462. newProgress);
  38463. }
  38464. currentValue = newProgress;
  38465. currentMessage = displayedMessage;
  38466. repaint();
  38467. }
  38468. }
  38469. END_JUCE_NAMESPACE
  38470. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38471. /*** Start of inlined file: juce_Slider.cpp ***/
  38472. BEGIN_JUCE_NAMESPACE
  38473. class SliderPopupDisplayComponent : public BubbleComponent
  38474. {
  38475. public:
  38476. SliderPopupDisplayComponent (Slider* const owner_)
  38477. : owner (owner_),
  38478. font (15.0f, Font::bold)
  38479. {
  38480. setAlwaysOnTop (true);
  38481. }
  38482. ~SliderPopupDisplayComponent()
  38483. {
  38484. }
  38485. void paintContent (Graphics& g, int w, int h)
  38486. {
  38487. g.setFont (font);
  38488. g.setColour (Colours::black);
  38489. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38490. }
  38491. void getContentSize (int& w, int& h)
  38492. {
  38493. w = font.getStringWidth (text) + 18;
  38494. h = (int) (font.getHeight() * 1.6f);
  38495. }
  38496. void updatePosition (const String& newText)
  38497. {
  38498. if (text != newText)
  38499. {
  38500. text = newText;
  38501. repaint();
  38502. }
  38503. BubbleComponent::setPosition (owner);
  38504. }
  38505. juce_UseDebuggingNewOperator
  38506. private:
  38507. Slider* owner;
  38508. Font font;
  38509. String text;
  38510. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38511. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38512. };
  38513. Slider::Slider (const String& name)
  38514. : Component (name),
  38515. lastCurrentValue (0),
  38516. lastValueMin (0),
  38517. lastValueMax (0),
  38518. minimum (0),
  38519. maximum (10),
  38520. interval (0),
  38521. skewFactor (1.0),
  38522. velocityModeSensitivity (1.0),
  38523. velocityModeOffset (0.0),
  38524. velocityModeThreshold (1),
  38525. rotaryStart (float_Pi * 1.2f),
  38526. rotaryEnd (float_Pi * 2.8f),
  38527. numDecimalPlaces (7),
  38528. sliderRegionStart (0),
  38529. sliderRegionSize (1),
  38530. sliderBeingDragged (-1),
  38531. pixelsForFullDragExtent (250),
  38532. style (LinearHorizontal),
  38533. textBoxPos (TextBoxLeft),
  38534. textBoxWidth (80),
  38535. textBoxHeight (20),
  38536. incDecButtonMode (incDecButtonsNotDraggable),
  38537. editableText (true),
  38538. doubleClickToValue (false),
  38539. isVelocityBased (false),
  38540. userKeyOverridesVelocity (true),
  38541. rotaryStop (true),
  38542. incDecButtonsSideBySide (false),
  38543. sendChangeOnlyOnRelease (false),
  38544. popupDisplayEnabled (false),
  38545. menuEnabled (false),
  38546. menuShown (false),
  38547. scrollWheelEnabled (true),
  38548. snapsToMousePos (true),
  38549. valueBox (0),
  38550. incButton (0),
  38551. decButton (0),
  38552. popupDisplay (0),
  38553. parentForPopupDisplay (0)
  38554. {
  38555. setWantsKeyboardFocus (false);
  38556. setRepaintsOnMouseActivity (true);
  38557. lookAndFeelChanged();
  38558. updateText();
  38559. currentValue.addListener (this);
  38560. valueMin.addListener (this);
  38561. valueMax.addListener (this);
  38562. }
  38563. Slider::~Slider()
  38564. {
  38565. currentValue.removeListener (this);
  38566. valueMin.removeListener (this);
  38567. valueMax.removeListener (this);
  38568. popupDisplay = 0;
  38569. deleteAllChildren();
  38570. }
  38571. void Slider::handleAsyncUpdate()
  38572. {
  38573. cancelPendingUpdate();
  38574. Component::BailOutChecker checker (this);
  38575. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38576. }
  38577. void Slider::sendDragStart()
  38578. {
  38579. startedDragging();
  38580. Component::BailOutChecker checker (this);
  38581. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38582. }
  38583. void Slider::sendDragEnd()
  38584. {
  38585. stoppedDragging();
  38586. sliderBeingDragged = -1;
  38587. Component::BailOutChecker checker (this);
  38588. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38589. }
  38590. void Slider::addListener (SliderListener* const listener)
  38591. {
  38592. listeners.add (listener);
  38593. }
  38594. void Slider::removeListener (SliderListener* const listener)
  38595. {
  38596. listeners.remove (listener);
  38597. }
  38598. void Slider::setSliderStyle (const SliderStyle newStyle)
  38599. {
  38600. if (style != newStyle)
  38601. {
  38602. style = newStyle;
  38603. repaint();
  38604. lookAndFeelChanged();
  38605. }
  38606. }
  38607. void Slider::setRotaryParameters (const float startAngleRadians,
  38608. const float endAngleRadians,
  38609. const bool stopAtEnd)
  38610. {
  38611. // make sure the values are sensible..
  38612. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38613. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38614. jassert (rotaryStart < rotaryEnd);
  38615. rotaryStart = startAngleRadians;
  38616. rotaryEnd = endAngleRadians;
  38617. rotaryStop = stopAtEnd;
  38618. }
  38619. void Slider::setVelocityBasedMode (const bool velBased)
  38620. {
  38621. isVelocityBased = velBased;
  38622. }
  38623. void Slider::setVelocityModeParameters (const double sensitivity,
  38624. const int threshold,
  38625. const double offset,
  38626. const bool userCanPressKeyToSwapMode)
  38627. {
  38628. jassert (threshold >= 0);
  38629. jassert (sensitivity > 0);
  38630. jassert (offset >= 0);
  38631. velocityModeSensitivity = sensitivity;
  38632. velocityModeOffset = offset;
  38633. velocityModeThreshold = threshold;
  38634. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38635. }
  38636. void Slider::setSkewFactor (const double factor)
  38637. {
  38638. skewFactor = factor;
  38639. }
  38640. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38641. {
  38642. if (maximum > minimum)
  38643. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38644. / (maximum - minimum));
  38645. }
  38646. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38647. {
  38648. jassert (distanceForFullScaleDrag > 0);
  38649. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38650. }
  38651. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38652. {
  38653. if (incDecButtonMode != mode)
  38654. {
  38655. incDecButtonMode = mode;
  38656. lookAndFeelChanged();
  38657. }
  38658. }
  38659. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38660. const bool isReadOnly,
  38661. const int textEntryBoxWidth,
  38662. const int textEntryBoxHeight)
  38663. {
  38664. textBoxPos = newPosition;
  38665. editableText = ! isReadOnly;
  38666. textBoxWidth = textEntryBoxWidth;
  38667. textBoxHeight = textEntryBoxHeight;
  38668. repaint();
  38669. lookAndFeelChanged();
  38670. }
  38671. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38672. {
  38673. editableText = shouldBeEditable;
  38674. if (valueBox != 0)
  38675. valueBox->setEditable (shouldBeEditable && isEnabled());
  38676. }
  38677. void Slider::showTextBox()
  38678. {
  38679. jassert (editableText); // this should probably be avoided in read-only sliders.
  38680. if (valueBox != 0)
  38681. valueBox->showEditor();
  38682. }
  38683. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38684. {
  38685. if (valueBox != 0)
  38686. {
  38687. valueBox->hideEditor (discardCurrentEditorContents);
  38688. if (discardCurrentEditorContents)
  38689. updateText();
  38690. }
  38691. }
  38692. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38693. {
  38694. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38695. }
  38696. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38697. {
  38698. snapsToMousePos = shouldSnapToMouse;
  38699. }
  38700. void Slider::setPopupDisplayEnabled (const bool enabled,
  38701. Component* const parentComponentToUse)
  38702. {
  38703. popupDisplayEnabled = enabled;
  38704. parentForPopupDisplay = parentComponentToUse;
  38705. }
  38706. void Slider::colourChanged()
  38707. {
  38708. lookAndFeelChanged();
  38709. }
  38710. void Slider::lookAndFeelChanged()
  38711. {
  38712. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38713. : getTextFromValue (currentValue.getValue()));
  38714. deleteAllChildren();
  38715. valueBox = 0;
  38716. LookAndFeel& lf = getLookAndFeel();
  38717. if (textBoxPos != NoTextBox)
  38718. {
  38719. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38720. valueBox->setWantsKeyboardFocus (false);
  38721. valueBox->setText (previousTextBoxContent, false);
  38722. valueBox->setEditable (editableText && isEnabled());
  38723. valueBox->addListener (this);
  38724. if (style == LinearBar)
  38725. valueBox->addMouseListener (this, false);
  38726. valueBox->setTooltip (getTooltip());
  38727. }
  38728. if (style == IncDecButtons)
  38729. {
  38730. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38731. incButton->addButtonListener (this);
  38732. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38733. decButton->addButtonListener (this);
  38734. if (incDecButtonMode != incDecButtonsNotDraggable)
  38735. {
  38736. incButton->addMouseListener (this, false);
  38737. decButton->addMouseListener (this, false);
  38738. }
  38739. else
  38740. {
  38741. incButton->setRepeatSpeed (300, 100, 20);
  38742. incButton->addMouseListener (decButton, false);
  38743. decButton->setRepeatSpeed (300, 100, 20);
  38744. decButton->addMouseListener (incButton, false);
  38745. }
  38746. incButton->setTooltip (getTooltip());
  38747. decButton->setTooltip (getTooltip());
  38748. }
  38749. setComponentEffect (lf.getSliderEffect());
  38750. resized();
  38751. repaint();
  38752. }
  38753. void Slider::setRange (const double newMin,
  38754. const double newMax,
  38755. const double newInt)
  38756. {
  38757. if (minimum != newMin
  38758. || maximum != newMax
  38759. || interval != newInt)
  38760. {
  38761. minimum = newMin;
  38762. maximum = newMax;
  38763. interval = newInt;
  38764. // figure out the number of DPs needed to display all values at this
  38765. // interval setting.
  38766. numDecimalPlaces = 7;
  38767. if (newInt != 0)
  38768. {
  38769. int v = abs ((int) (newInt * 10000000));
  38770. while ((v % 10) == 0)
  38771. {
  38772. --numDecimalPlaces;
  38773. v /= 10;
  38774. }
  38775. }
  38776. // keep the current values inside the new range..
  38777. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38778. {
  38779. setValue (getValue(), false, false);
  38780. }
  38781. else
  38782. {
  38783. setMinValue (getMinValue(), false, false);
  38784. setMaxValue (getMaxValue(), false, false);
  38785. }
  38786. updateText();
  38787. }
  38788. }
  38789. void Slider::triggerChangeMessage (const bool synchronous)
  38790. {
  38791. if (synchronous)
  38792. handleAsyncUpdate();
  38793. else
  38794. triggerAsyncUpdate();
  38795. valueChanged();
  38796. }
  38797. void Slider::valueChanged (Value& value)
  38798. {
  38799. if (value.refersToSameSourceAs (currentValue))
  38800. {
  38801. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38802. setValue (currentValue.getValue(), false, false);
  38803. }
  38804. else if (value.refersToSameSourceAs (valueMin))
  38805. setMinValue (valueMin.getValue(), false, false, true);
  38806. else if (value.refersToSameSourceAs (valueMax))
  38807. setMaxValue (valueMax.getValue(), false, false, true);
  38808. }
  38809. double Slider::getValue() const
  38810. {
  38811. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  38812. // methods to get the two values.
  38813. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38814. return currentValue.getValue();
  38815. }
  38816. void Slider::setValue (double newValue,
  38817. const bool sendUpdateMessage,
  38818. const bool sendMessageSynchronously)
  38819. {
  38820. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  38821. // methods to set the two values.
  38822. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38823. newValue = constrainedValue (newValue);
  38824. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  38825. {
  38826. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  38827. newValue = jlimit ((double) valueMin.getValue(),
  38828. (double) valueMax.getValue(),
  38829. newValue);
  38830. }
  38831. if (newValue != lastCurrentValue)
  38832. {
  38833. if (valueBox != 0)
  38834. valueBox->hideEditor (true);
  38835. lastCurrentValue = newValue;
  38836. currentValue = newValue;
  38837. updateText();
  38838. repaint();
  38839. if (popupDisplay != 0)
  38840. {
  38841. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38842. ->updatePosition (getTextFromValue (newValue));
  38843. popupDisplay->repaint();
  38844. }
  38845. if (sendUpdateMessage)
  38846. triggerChangeMessage (sendMessageSynchronously);
  38847. }
  38848. }
  38849. double Slider::getMinValue() const
  38850. {
  38851. // The minimum value only applies to sliders that are in two- or three-value mode.
  38852. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38853. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38854. return valueMin.getValue();
  38855. }
  38856. double Slider::getMaxValue() const
  38857. {
  38858. // The maximum value only applies to sliders that are in two- or three-value mode.
  38859. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38860. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38861. return valueMax.getValue();
  38862. }
  38863. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38864. {
  38865. // The minimum value only applies to sliders that are in two- or three-value mode.
  38866. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38867. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38868. newValue = constrainedValue (newValue);
  38869. if (style == TwoValueHorizontal || style == TwoValueVertical)
  38870. {
  38871. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  38872. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38873. newValue = jmin ((double) valueMax.getValue(), newValue);
  38874. }
  38875. else
  38876. {
  38877. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  38878. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38879. newValue = jmin (lastCurrentValue, newValue);
  38880. }
  38881. if (lastValueMin != newValue)
  38882. {
  38883. lastValueMin = newValue;
  38884. valueMin = newValue;
  38885. repaint();
  38886. if (popupDisplay != 0)
  38887. {
  38888. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38889. ->updatePosition (getTextFromValue (newValue));
  38890. popupDisplay->repaint();
  38891. }
  38892. if (sendUpdateMessage)
  38893. triggerChangeMessage (sendMessageSynchronously);
  38894. }
  38895. }
  38896. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38897. {
  38898. // The maximum value only applies to sliders that are in two- or three-value mode.
  38899. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38900. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38901. newValue = constrainedValue (newValue);
  38902. if (style == TwoValueHorizontal || style == TwoValueVertical)
  38903. {
  38904. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  38905. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38906. newValue = jmax ((double) valueMin.getValue(), newValue);
  38907. }
  38908. else
  38909. {
  38910. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  38911. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38912. newValue = jmax (lastCurrentValue, newValue);
  38913. }
  38914. if (lastValueMax != newValue)
  38915. {
  38916. lastValueMax = newValue;
  38917. valueMax = newValue;
  38918. repaint();
  38919. if (popupDisplay != 0)
  38920. {
  38921. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38922. ->updatePosition (getTextFromValue (valueMax.getValue()));
  38923. popupDisplay->repaint();
  38924. }
  38925. if (sendUpdateMessage)
  38926. triggerChangeMessage (sendMessageSynchronously);
  38927. }
  38928. }
  38929. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  38930. const double valueToSetOnDoubleClick)
  38931. {
  38932. doubleClickToValue = isDoubleClickEnabled;
  38933. doubleClickReturnValue = valueToSetOnDoubleClick;
  38934. }
  38935. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  38936. {
  38937. isEnabled_ = doubleClickToValue;
  38938. return doubleClickReturnValue;
  38939. }
  38940. void Slider::updateText()
  38941. {
  38942. if (valueBox != 0)
  38943. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  38944. }
  38945. void Slider::setTextValueSuffix (const String& suffix)
  38946. {
  38947. if (textSuffix != suffix)
  38948. {
  38949. textSuffix = suffix;
  38950. updateText();
  38951. }
  38952. }
  38953. const String Slider::getTextValueSuffix() const
  38954. {
  38955. return textSuffix;
  38956. }
  38957. const String Slider::getTextFromValue (double v)
  38958. {
  38959. if (getNumDecimalPlacesToDisplay() > 0)
  38960. return String (v, getNumDecimalPlacesToDisplay()) + getTextValueSuffix();
  38961. else
  38962. return String (roundToInt (v)) + getTextValueSuffix();
  38963. }
  38964. double Slider::getValueFromText (const String& text)
  38965. {
  38966. String t (text.trimStart());
  38967. if (t.endsWith (textSuffix))
  38968. t = t.substring (0, t.length() - textSuffix.length());
  38969. while (t.startsWithChar ('+'))
  38970. t = t.substring (1).trimStart();
  38971. return t.initialSectionContainingOnly ("0123456789.,-")
  38972. .getDoubleValue();
  38973. }
  38974. double Slider::proportionOfLengthToValue (double proportion)
  38975. {
  38976. if (skewFactor != 1.0 && proportion > 0.0)
  38977. proportion = exp (log (proportion) / skewFactor);
  38978. return minimum + (maximum - minimum) * proportion;
  38979. }
  38980. double Slider::valueToProportionOfLength (double value)
  38981. {
  38982. const double n = (value - minimum) / (maximum - minimum);
  38983. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  38984. }
  38985. double Slider::snapValue (double attemptedValue, const bool)
  38986. {
  38987. return attemptedValue;
  38988. }
  38989. void Slider::startedDragging()
  38990. {
  38991. }
  38992. void Slider::stoppedDragging()
  38993. {
  38994. }
  38995. void Slider::valueChanged()
  38996. {
  38997. }
  38998. void Slider::enablementChanged()
  38999. {
  39000. repaint();
  39001. }
  39002. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39003. {
  39004. menuEnabled = menuEnabled_;
  39005. }
  39006. void Slider::setScrollWheelEnabled (const bool enabled)
  39007. {
  39008. scrollWheelEnabled = enabled;
  39009. }
  39010. void Slider::labelTextChanged (Label* label)
  39011. {
  39012. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39013. if (newValue != (double) currentValue.getValue())
  39014. {
  39015. sendDragStart();
  39016. setValue (newValue, true, true);
  39017. sendDragEnd();
  39018. }
  39019. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39020. }
  39021. void Slider::buttonClicked (Button* button)
  39022. {
  39023. if (style == IncDecButtons)
  39024. {
  39025. sendDragStart();
  39026. if (button == incButton)
  39027. setValue (snapValue (getValue() + interval, false), true, true);
  39028. else if (button == decButton)
  39029. setValue (snapValue (getValue() - interval, false), true, true);
  39030. sendDragEnd();
  39031. }
  39032. }
  39033. double Slider::constrainedValue (double value) const
  39034. {
  39035. if (interval > 0)
  39036. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39037. if (value <= minimum || maximum <= minimum)
  39038. value = minimum;
  39039. else if (value >= maximum)
  39040. value = maximum;
  39041. return value;
  39042. }
  39043. float Slider::getLinearSliderPos (const double value)
  39044. {
  39045. double sliderPosProportional;
  39046. if (maximum > minimum)
  39047. {
  39048. if (value < minimum)
  39049. {
  39050. sliderPosProportional = 0.0;
  39051. }
  39052. else if (value > maximum)
  39053. {
  39054. sliderPosProportional = 1.0;
  39055. }
  39056. else
  39057. {
  39058. sliderPosProportional = valueToProportionOfLength (value);
  39059. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39060. }
  39061. }
  39062. else
  39063. {
  39064. sliderPosProportional = 0.5;
  39065. }
  39066. if (isVertical() || style == IncDecButtons)
  39067. sliderPosProportional = 1.0 - sliderPosProportional;
  39068. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39069. }
  39070. bool Slider::isHorizontal() const
  39071. {
  39072. return style == LinearHorizontal
  39073. || style == LinearBar
  39074. || style == TwoValueHorizontal
  39075. || style == ThreeValueHorizontal;
  39076. }
  39077. bool Slider::isVertical() const
  39078. {
  39079. return style == LinearVertical
  39080. || style == TwoValueVertical
  39081. || style == ThreeValueVertical;
  39082. }
  39083. bool Slider::incDecDragDirectionIsHorizontal() const
  39084. {
  39085. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39086. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39087. }
  39088. float Slider::getPositionOfValue (const double value)
  39089. {
  39090. if (isHorizontal() || isVertical())
  39091. {
  39092. return getLinearSliderPos (value);
  39093. }
  39094. else
  39095. {
  39096. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39097. return 0.0f;
  39098. }
  39099. }
  39100. void Slider::paint (Graphics& g)
  39101. {
  39102. if (style != IncDecButtons)
  39103. {
  39104. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39105. {
  39106. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39107. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39108. getLookAndFeel().drawRotarySlider (g,
  39109. sliderRect.getX(),
  39110. sliderRect.getY(),
  39111. sliderRect.getWidth(),
  39112. sliderRect.getHeight(),
  39113. sliderPos,
  39114. rotaryStart, rotaryEnd,
  39115. *this);
  39116. }
  39117. else
  39118. {
  39119. getLookAndFeel().drawLinearSlider (g,
  39120. sliderRect.getX(),
  39121. sliderRect.getY(),
  39122. sliderRect.getWidth(),
  39123. sliderRect.getHeight(),
  39124. getLinearSliderPos (lastCurrentValue),
  39125. getLinearSliderPos (lastValueMin),
  39126. getLinearSliderPos (lastValueMax),
  39127. style,
  39128. *this);
  39129. }
  39130. if (style == LinearBar && valueBox == 0)
  39131. {
  39132. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39133. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39134. }
  39135. }
  39136. }
  39137. void Slider::resized()
  39138. {
  39139. int minXSpace = 0;
  39140. int minYSpace = 0;
  39141. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39142. minXSpace = 30;
  39143. else
  39144. minYSpace = 15;
  39145. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39146. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39147. if (style == LinearBar)
  39148. {
  39149. if (valueBox != 0)
  39150. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39151. }
  39152. else
  39153. {
  39154. if (textBoxPos == NoTextBox)
  39155. {
  39156. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39157. }
  39158. else if (textBoxPos == TextBoxLeft)
  39159. {
  39160. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39161. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39162. }
  39163. else if (textBoxPos == TextBoxRight)
  39164. {
  39165. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39166. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39167. }
  39168. else if (textBoxPos == TextBoxAbove)
  39169. {
  39170. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39171. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39172. }
  39173. else if (textBoxPos == TextBoxBelow)
  39174. {
  39175. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39176. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39177. }
  39178. }
  39179. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39180. if (style == LinearBar)
  39181. {
  39182. const int barIndent = 1;
  39183. sliderRegionStart = barIndent;
  39184. sliderRegionSize = getWidth() - barIndent * 2;
  39185. sliderRect.setBounds (sliderRegionStart, barIndent,
  39186. sliderRegionSize, getHeight() - barIndent * 2);
  39187. }
  39188. else if (isHorizontal())
  39189. {
  39190. sliderRegionStart = sliderRect.getX() + indent;
  39191. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39192. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39193. sliderRegionSize, sliderRect.getHeight());
  39194. }
  39195. else if (isVertical())
  39196. {
  39197. sliderRegionStart = sliderRect.getY() + indent;
  39198. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39199. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39200. sliderRect.getWidth(), sliderRegionSize);
  39201. }
  39202. else
  39203. {
  39204. sliderRegionStart = 0;
  39205. sliderRegionSize = 100;
  39206. }
  39207. if (style == IncDecButtons)
  39208. {
  39209. Rectangle<int> buttonRect (sliderRect);
  39210. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39211. buttonRect.expand (-2, 0);
  39212. else
  39213. buttonRect.expand (0, -2);
  39214. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39215. if (incDecButtonsSideBySide)
  39216. {
  39217. decButton->setBounds (buttonRect.getX(),
  39218. buttonRect.getY(),
  39219. buttonRect.getWidth() / 2,
  39220. buttonRect.getHeight());
  39221. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39222. incButton->setBounds (buttonRect.getCentreX(),
  39223. buttonRect.getY(),
  39224. buttonRect.getWidth() / 2,
  39225. buttonRect.getHeight());
  39226. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39227. }
  39228. else
  39229. {
  39230. incButton->setBounds (buttonRect.getX(),
  39231. buttonRect.getY(),
  39232. buttonRect.getWidth(),
  39233. buttonRect.getHeight() / 2);
  39234. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39235. decButton->setBounds (buttonRect.getX(),
  39236. buttonRect.getCentreY(),
  39237. buttonRect.getWidth(),
  39238. buttonRect.getHeight() / 2);
  39239. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39240. }
  39241. }
  39242. }
  39243. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39244. {
  39245. repaint();
  39246. }
  39247. void Slider::mouseDown (const MouseEvent& e)
  39248. {
  39249. mouseWasHidden = false;
  39250. incDecDragged = false;
  39251. mouseXWhenLastDragged = e.x;
  39252. mouseYWhenLastDragged = e.y;
  39253. mouseDragStartX = e.getMouseDownX();
  39254. mouseDragStartY = e.getMouseDownY();
  39255. if (isEnabled())
  39256. {
  39257. if (e.mods.isPopupMenu() && menuEnabled)
  39258. {
  39259. menuShown = true;
  39260. PopupMenu m;
  39261. m.setLookAndFeel (&getLookAndFeel());
  39262. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39263. m.addSeparator();
  39264. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39265. {
  39266. PopupMenu rotaryMenu;
  39267. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39268. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39269. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39270. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39271. }
  39272. const int r = m.show();
  39273. if (r == 1)
  39274. {
  39275. setVelocityBasedMode (! isVelocityBased);
  39276. }
  39277. else if (r == 2)
  39278. {
  39279. setSliderStyle (Rotary);
  39280. }
  39281. else if (r == 3)
  39282. {
  39283. setSliderStyle (RotaryHorizontalDrag);
  39284. }
  39285. else if (r == 4)
  39286. {
  39287. setSliderStyle (RotaryVerticalDrag);
  39288. }
  39289. }
  39290. else if (maximum > minimum)
  39291. {
  39292. menuShown = false;
  39293. if (valueBox != 0)
  39294. valueBox->hideEditor (true);
  39295. sliderBeingDragged = 0;
  39296. if (style == TwoValueHorizontal
  39297. || style == TwoValueVertical
  39298. || style == ThreeValueHorizontal
  39299. || style == ThreeValueVertical)
  39300. {
  39301. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39302. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39303. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39304. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39305. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39306. {
  39307. if (maxPosDistance <= minPosDistance)
  39308. sliderBeingDragged = 2;
  39309. else
  39310. sliderBeingDragged = 1;
  39311. }
  39312. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39313. {
  39314. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39315. sliderBeingDragged = 1;
  39316. else if (normalPosDistance >= maxPosDistance)
  39317. sliderBeingDragged = 2;
  39318. }
  39319. }
  39320. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39321. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39322. * valueToProportionOfLength (currentValue.getValue());
  39323. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39324. : ((sliderBeingDragged == 1) ? valueMin
  39325. : currentValue)).getValue();
  39326. valueOnMouseDown = valueWhenLastDragged;
  39327. if (popupDisplayEnabled)
  39328. {
  39329. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39330. popupDisplay = popup;
  39331. if (parentForPopupDisplay != 0)
  39332. {
  39333. parentForPopupDisplay->addChildComponent (popup);
  39334. }
  39335. else
  39336. {
  39337. popup->addToDesktop (0);
  39338. }
  39339. popup->setVisible (true);
  39340. }
  39341. sendDragStart();
  39342. mouseDrag (e);
  39343. }
  39344. }
  39345. }
  39346. void Slider::mouseUp (const MouseEvent&)
  39347. {
  39348. if (isEnabled()
  39349. && (! menuShown)
  39350. && (maximum > minimum)
  39351. && (style != IncDecButtons || incDecDragged))
  39352. {
  39353. restoreMouseIfHidden();
  39354. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39355. triggerChangeMessage (false);
  39356. sendDragEnd();
  39357. popupDisplay = 0;
  39358. if (style == IncDecButtons)
  39359. {
  39360. incButton->setState (Button::buttonNormal);
  39361. decButton->setState (Button::buttonNormal);
  39362. }
  39363. }
  39364. }
  39365. void Slider::restoreMouseIfHidden()
  39366. {
  39367. if (mouseWasHidden)
  39368. {
  39369. mouseWasHidden = false;
  39370. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39371. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39372. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39373. : ((sliderBeingDragged == 1) ? getMinValue()
  39374. : (double) currentValue.getValue());
  39375. Point<int> mousePos;
  39376. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39377. {
  39378. mousePos = Desktop::getLastMouseDownPosition();
  39379. if (style == RotaryHorizontalDrag)
  39380. {
  39381. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39382. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39383. }
  39384. else
  39385. {
  39386. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39387. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39388. }
  39389. }
  39390. else
  39391. {
  39392. const int pixelPos = (int) getLinearSliderPos (pos);
  39393. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39394. isVertical() ? pixelPos : (getHeight() / 2)));
  39395. }
  39396. Desktop::setMousePosition (mousePos);
  39397. }
  39398. }
  39399. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39400. {
  39401. if (isEnabled()
  39402. && style != IncDecButtons
  39403. && style != Rotary
  39404. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39405. {
  39406. restoreMouseIfHidden();
  39407. }
  39408. }
  39409. static double smallestAngleBetween (double a1, double a2)
  39410. {
  39411. return jmin (fabs (a1 - a2),
  39412. fabs (a1 + double_Pi * 2.0 - a2),
  39413. fabs (a2 + double_Pi * 2.0 - a1));
  39414. }
  39415. void Slider::mouseDrag (const MouseEvent& e)
  39416. {
  39417. if (isEnabled()
  39418. && (! menuShown)
  39419. && (maximum > minimum))
  39420. {
  39421. if (style == Rotary)
  39422. {
  39423. int dx = e.x - sliderRect.getCentreX();
  39424. int dy = e.y - sliderRect.getCentreY();
  39425. if (dx * dx + dy * dy > 25)
  39426. {
  39427. double angle = atan2 ((double) dx, (double) -dy);
  39428. while (angle < 0.0)
  39429. angle += double_Pi * 2.0;
  39430. if (rotaryStop && ! e.mouseWasClicked())
  39431. {
  39432. if (fabs (angle - lastAngle) > double_Pi)
  39433. {
  39434. if (angle >= lastAngle)
  39435. angle -= double_Pi * 2.0;
  39436. else
  39437. angle += double_Pi * 2.0;
  39438. }
  39439. if (angle >= lastAngle)
  39440. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39441. else
  39442. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39443. }
  39444. else
  39445. {
  39446. while (angle < rotaryStart)
  39447. angle += double_Pi * 2.0;
  39448. if (angle > rotaryEnd)
  39449. {
  39450. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39451. angle = rotaryStart;
  39452. else
  39453. angle = rotaryEnd;
  39454. }
  39455. }
  39456. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39457. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39458. lastAngle = angle;
  39459. }
  39460. }
  39461. else
  39462. {
  39463. if (style == LinearBar && e.mouseWasClicked()
  39464. && valueBox != 0 && valueBox->isEditable())
  39465. return;
  39466. if (style == IncDecButtons && ! incDecDragged)
  39467. {
  39468. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39469. return;
  39470. incDecDragged = true;
  39471. mouseDragStartX = e.x;
  39472. mouseDragStartY = e.y;
  39473. }
  39474. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39475. : false))
  39476. || ((maximum - minimum) / sliderRegionSize < interval))
  39477. {
  39478. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39479. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39480. if (style == RotaryHorizontalDrag
  39481. || style == RotaryVerticalDrag
  39482. || style == IncDecButtons
  39483. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39484. && ! snapsToMousePos))
  39485. {
  39486. const int mouseDiff = (style == RotaryHorizontalDrag
  39487. || style == LinearHorizontal
  39488. || style == LinearBar
  39489. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39490. ? e.x - mouseDragStartX
  39491. : mouseDragStartY - e.y;
  39492. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39493. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39494. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39495. if (style == IncDecButtons)
  39496. {
  39497. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39498. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39499. }
  39500. }
  39501. else
  39502. {
  39503. if (isVertical())
  39504. scaledMousePos = 1.0 - scaledMousePos;
  39505. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39506. }
  39507. }
  39508. else
  39509. {
  39510. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39511. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39512. ? e.x - mouseXWhenLastDragged
  39513. : e.y - mouseYWhenLastDragged;
  39514. const double maxSpeed = jmax (200, sliderRegionSize);
  39515. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39516. if (speed != 0)
  39517. {
  39518. speed = 0.2 * velocityModeSensitivity
  39519. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39520. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39521. / maxSpeed))));
  39522. if (mouseDiff < 0)
  39523. speed = -speed;
  39524. if (isVertical() || style == RotaryVerticalDrag
  39525. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39526. speed = -speed;
  39527. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39528. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39529. e.source.enableUnboundedMouseMovement (true, false);
  39530. mouseWasHidden = true;
  39531. }
  39532. }
  39533. }
  39534. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39535. if (sliderBeingDragged == 0)
  39536. {
  39537. setValue (snapValue (valueWhenLastDragged, true),
  39538. ! sendChangeOnlyOnRelease, true);
  39539. }
  39540. else if (sliderBeingDragged == 1)
  39541. {
  39542. setMinValue (snapValue (valueWhenLastDragged, true),
  39543. ! sendChangeOnlyOnRelease, false, true);
  39544. if (e.mods.isShiftDown())
  39545. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39546. else
  39547. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39548. }
  39549. else
  39550. {
  39551. jassert (sliderBeingDragged == 2);
  39552. setMaxValue (snapValue (valueWhenLastDragged, true),
  39553. ! sendChangeOnlyOnRelease, false, true);
  39554. if (e.mods.isShiftDown())
  39555. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39556. else
  39557. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39558. }
  39559. mouseXWhenLastDragged = e.x;
  39560. mouseYWhenLastDragged = e.y;
  39561. }
  39562. }
  39563. void Slider::mouseDoubleClick (const MouseEvent&)
  39564. {
  39565. if (doubleClickToValue
  39566. && isEnabled()
  39567. && style != IncDecButtons
  39568. && minimum <= doubleClickReturnValue
  39569. && maximum >= doubleClickReturnValue)
  39570. {
  39571. sendDragStart();
  39572. setValue (doubleClickReturnValue, true, true);
  39573. sendDragEnd();
  39574. }
  39575. }
  39576. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39577. {
  39578. if (scrollWheelEnabled && isEnabled()
  39579. && style != TwoValueHorizontal
  39580. && style != TwoValueVertical)
  39581. {
  39582. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39583. {
  39584. if (valueBox != 0)
  39585. valueBox->hideEditor (false);
  39586. const double value = (double) currentValue.getValue();
  39587. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39588. const double currentPos = valueToProportionOfLength (value);
  39589. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39590. double delta = (newValue != value)
  39591. ? jmax (fabs (newValue - value), interval) : 0;
  39592. if (value > newValue)
  39593. delta = -delta;
  39594. sendDragStart();
  39595. setValue (snapValue (value + delta, false), true, true);
  39596. sendDragEnd();
  39597. }
  39598. }
  39599. else
  39600. {
  39601. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39602. }
  39603. }
  39604. void SliderListener::sliderDragStarted (Slider*)
  39605. {
  39606. }
  39607. void SliderListener::sliderDragEnded (Slider*)
  39608. {
  39609. }
  39610. END_JUCE_NAMESPACE
  39611. /*** End of inlined file: juce_Slider.cpp ***/
  39612. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39613. BEGIN_JUCE_NAMESPACE
  39614. class DragOverlayComp : public Component
  39615. {
  39616. public:
  39617. DragOverlayComp (Image* const image_)
  39618. : image (image_)
  39619. {
  39620. image->multiplyAllAlphas (0.8f);
  39621. setAlwaysOnTop (true);
  39622. }
  39623. ~DragOverlayComp()
  39624. {
  39625. }
  39626. void paint (Graphics& g)
  39627. {
  39628. g.drawImageAt (image, 0, 0);
  39629. }
  39630. private:
  39631. ScopedPointer <Image> image;
  39632. DragOverlayComp (const DragOverlayComp&);
  39633. DragOverlayComp& operator= (const DragOverlayComp&);
  39634. };
  39635. TableHeaderComponent::TableHeaderComponent()
  39636. : columnsChanged (false),
  39637. columnsResized (false),
  39638. sortChanged (false),
  39639. menuActive (true),
  39640. stretchToFit (false),
  39641. columnIdBeingResized (0),
  39642. columnIdBeingDragged (0),
  39643. columnIdUnderMouse (0),
  39644. lastDeliberateWidth (0)
  39645. {
  39646. }
  39647. TableHeaderComponent::~TableHeaderComponent()
  39648. {
  39649. dragOverlayComp = 0;
  39650. }
  39651. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39652. {
  39653. menuActive = hasMenu;
  39654. }
  39655. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39656. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39657. {
  39658. if (onlyCountVisibleColumns)
  39659. {
  39660. int num = 0;
  39661. for (int i = columns.size(); --i >= 0;)
  39662. if (columns.getUnchecked(i)->isVisible())
  39663. ++num;
  39664. return num;
  39665. }
  39666. else
  39667. {
  39668. return columns.size();
  39669. }
  39670. }
  39671. const String TableHeaderComponent::getColumnName (const int columnId) const
  39672. {
  39673. const ColumnInfo* const ci = getInfoForId (columnId);
  39674. return ci != 0 ? ci->name : String::empty;
  39675. }
  39676. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39677. {
  39678. ColumnInfo* const ci = getInfoForId (columnId);
  39679. if (ci != 0 && ci->name != newName)
  39680. {
  39681. ci->name = newName;
  39682. sendColumnsChanged();
  39683. }
  39684. }
  39685. void TableHeaderComponent::addColumn (const String& columnName,
  39686. const int columnId,
  39687. const int width,
  39688. const int minimumWidth,
  39689. const int maximumWidth,
  39690. const int propertyFlags,
  39691. const int insertIndex)
  39692. {
  39693. // can't have a duplicate or null ID!
  39694. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39695. jassert (width > 0);
  39696. ColumnInfo* const ci = new ColumnInfo();
  39697. ci->name = columnName;
  39698. ci->id = columnId;
  39699. ci->width = width;
  39700. ci->lastDeliberateWidth = width;
  39701. ci->minimumWidth = minimumWidth;
  39702. ci->maximumWidth = maximumWidth;
  39703. if (ci->maximumWidth < 0)
  39704. ci->maximumWidth = std::numeric_limits<int>::max();
  39705. jassert (ci->maximumWidth >= ci->minimumWidth);
  39706. ci->propertyFlags = propertyFlags;
  39707. columns.insert (insertIndex, ci);
  39708. sendColumnsChanged();
  39709. }
  39710. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39711. {
  39712. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39713. if (index >= 0)
  39714. {
  39715. columns.remove (index);
  39716. sortChanged = true;
  39717. sendColumnsChanged();
  39718. }
  39719. }
  39720. void TableHeaderComponent::removeAllColumns()
  39721. {
  39722. if (columns.size() > 0)
  39723. {
  39724. columns.clear();
  39725. sendColumnsChanged();
  39726. }
  39727. }
  39728. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39729. {
  39730. const int currentIndex = getIndexOfColumnId (columnId, false);
  39731. newIndex = visibleIndexToTotalIndex (newIndex);
  39732. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39733. {
  39734. columns.move (currentIndex, newIndex);
  39735. sendColumnsChanged();
  39736. }
  39737. }
  39738. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39739. {
  39740. const ColumnInfo* const ci = getInfoForId (columnId);
  39741. return ci != 0 ? ci->width : 0;
  39742. }
  39743. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39744. {
  39745. ColumnInfo* const ci = getInfoForId (columnId);
  39746. if (ci != 0 && ci->width != newWidth)
  39747. {
  39748. const int numColumns = getNumColumns (true);
  39749. ci->lastDeliberateWidth = ci->width
  39750. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  39751. if (stretchToFit)
  39752. {
  39753. const int index = getIndexOfColumnId (columnId, true) + 1;
  39754. if (((unsigned int) index) < (unsigned int) numColumns)
  39755. {
  39756. const int x = getColumnPosition (index).getX();
  39757. if (lastDeliberateWidth == 0)
  39758. lastDeliberateWidth = getTotalWidth();
  39759. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  39760. }
  39761. }
  39762. repaint();
  39763. columnsResized = true;
  39764. triggerAsyncUpdate();
  39765. }
  39766. }
  39767. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  39768. {
  39769. int n = 0;
  39770. for (int i = 0; i < columns.size(); ++i)
  39771. {
  39772. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  39773. {
  39774. if (columns.getUnchecked(i)->id == columnId)
  39775. return n;
  39776. ++n;
  39777. }
  39778. }
  39779. return -1;
  39780. }
  39781. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  39782. {
  39783. if (onlyCountVisibleColumns)
  39784. index = visibleIndexToTotalIndex (index);
  39785. const ColumnInfo* const ci = columns [index];
  39786. return (ci != 0) ? ci->id : 0;
  39787. }
  39788. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  39789. {
  39790. int x = 0, width = 0, n = 0;
  39791. for (int i = 0; i < columns.size(); ++i)
  39792. {
  39793. x += width;
  39794. if (columns.getUnchecked(i)->isVisible())
  39795. {
  39796. width = columns.getUnchecked(i)->width;
  39797. if (n++ == index)
  39798. break;
  39799. }
  39800. else
  39801. {
  39802. width = 0;
  39803. }
  39804. }
  39805. return Rectangle<int> (x, 0, width, getHeight());
  39806. }
  39807. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  39808. {
  39809. if (xToFind >= 0)
  39810. {
  39811. int x = 0;
  39812. for (int i = 0; i < columns.size(); ++i)
  39813. {
  39814. const ColumnInfo* const ci = columns.getUnchecked(i);
  39815. if (ci->isVisible())
  39816. {
  39817. x += ci->width;
  39818. if (xToFind < x)
  39819. return ci->id;
  39820. }
  39821. }
  39822. }
  39823. return 0;
  39824. }
  39825. int TableHeaderComponent::getTotalWidth() const
  39826. {
  39827. int w = 0;
  39828. for (int i = columns.size(); --i >= 0;)
  39829. if (columns.getUnchecked(i)->isVisible())
  39830. w += columns.getUnchecked(i)->width;
  39831. return w;
  39832. }
  39833. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  39834. {
  39835. stretchToFit = shouldStretchToFit;
  39836. lastDeliberateWidth = getTotalWidth();
  39837. resized();
  39838. }
  39839. bool TableHeaderComponent::isStretchToFitActive() const
  39840. {
  39841. return stretchToFit;
  39842. }
  39843. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  39844. {
  39845. if (stretchToFit && getWidth() > 0
  39846. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  39847. {
  39848. lastDeliberateWidth = targetTotalWidth;
  39849. resizeColumnsToFit (0, targetTotalWidth);
  39850. }
  39851. }
  39852. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  39853. {
  39854. targetTotalWidth = jmax (targetTotalWidth, 0);
  39855. StretchableObjectResizer sor;
  39856. int i;
  39857. for (i = firstColumnIndex; i < columns.size(); ++i)
  39858. {
  39859. ColumnInfo* const ci = columns.getUnchecked(i);
  39860. if (ci->isVisible())
  39861. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  39862. }
  39863. sor.resizeToFit (targetTotalWidth);
  39864. int visIndex = 0;
  39865. for (i = firstColumnIndex; i < columns.size(); ++i)
  39866. {
  39867. ColumnInfo* const ci = columns.getUnchecked(i);
  39868. if (ci->isVisible())
  39869. {
  39870. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  39871. (int) floor (sor.getItemSize (visIndex++)));
  39872. if (newWidth != ci->width)
  39873. {
  39874. ci->width = newWidth;
  39875. repaint();
  39876. columnsResized = true;
  39877. triggerAsyncUpdate();
  39878. }
  39879. }
  39880. }
  39881. }
  39882. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  39883. {
  39884. ColumnInfo* const ci = getInfoForId (columnId);
  39885. if (ci != 0 && shouldBeVisible != ci->isVisible())
  39886. {
  39887. if (shouldBeVisible)
  39888. ci->propertyFlags |= visible;
  39889. else
  39890. ci->propertyFlags &= ~visible;
  39891. sendColumnsChanged();
  39892. resized();
  39893. }
  39894. }
  39895. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  39896. {
  39897. const ColumnInfo* const ci = getInfoForId (columnId);
  39898. return ci != 0 && ci->isVisible();
  39899. }
  39900. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  39901. {
  39902. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  39903. {
  39904. for (int i = columns.size(); --i >= 0;)
  39905. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  39906. ColumnInfo* const ci = getInfoForId (columnId);
  39907. if (ci != 0)
  39908. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  39909. reSortTable();
  39910. }
  39911. }
  39912. int TableHeaderComponent::getSortColumnId() const
  39913. {
  39914. for (int i = columns.size(); --i >= 0;)
  39915. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  39916. return columns.getUnchecked(i)->id;
  39917. return 0;
  39918. }
  39919. bool TableHeaderComponent::isSortedForwards() const
  39920. {
  39921. for (int i = columns.size(); --i >= 0;)
  39922. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  39923. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  39924. return true;
  39925. }
  39926. void TableHeaderComponent::reSortTable()
  39927. {
  39928. sortChanged = true;
  39929. repaint();
  39930. triggerAsyncUpdate();
  39931. }
  39932. const String TableHeaderComponent::toString() const
  39933. {
  39934. String s;
  39935. XmlElement doc ("TABLELAYOUT");
  39936. doc.setAttribute ("sortedCol", getSortColumnId());
  39937. doc.setAttribute ("sortForwards", isSortedForwards());
  39938. for (int i = 0; i < columns.size(); ++i)
  39939. {
  39940. const ColumnInfo* const ci = columns.getUnchecked (i);
  39941. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  39942. e->setAttribute ("id", ci->id);
  39943. e->setAttribute ("visible", ci->isVisible());
  39944. e->setAttribute ("width", ci->width);
  39945. }
  39946. return doc.createDocument (String::empty, true, false);
  39947. }
  39948. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  39949. {
  39950. XmlDocument doc (storedVersion);
  39951. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  39952. int index = 0;
  39953. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  39954. {
  39955. forEachXmlChildElement (*storedXml, col)
  39956. {
  39957. const int tabId = col->getIntAttribute ("id");
  39958. ColumnInfo* const ci = getInfoForId (tabId);
  39959. if (ci != 0)
  39960. {
  39961. columns.move (columns.indexOf (ci), index);
  39962. ci->width = col->getIntAttribute ("width");
  39963. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  39964. }
  39965. ++index;
  39966. }
  39967. columnsResized = true;
  39968. sendColumnsChanged();
  39969. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  39970. storedXml->getBoolAttribute ("sortForwards", true));
  39971. }
  39972. }
  39973. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  39974. {
  39975. listeners.addIfNotAlreadyThere (newListener);
  39976. }
  39977. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  39978. {
  39979. listeners.removeValue (listenerToRemove);
  39980. }
  39981. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  39982. {
  39983. const ColumnInfo* const ci = getInfoForId (columnId);
  39984. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  39985. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  39986. }
  39987. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  39988. {
  39989. for (int i = 0; i < columns.size(); ++i)
  39990. {
  39991. const ColumnInfo* const ci = columns.getUnchecked(i);
  39992. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  39993. menu.addItem (ci->id, ci->name,
  39994. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  39995. isColumnVisible (ci->id));
  39996. }
  39997. }
  39998. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  39999. {
  40000. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40001. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40002. }
  40003. void TableHeaderComponent::paint (Graphics& g)
  40004. {
  40005. LookAndFeel& lf = getLookAndFeel();
  40006. lf.drawTableHeaderBackground (g, *this);
  40007. const Rectangle<int> clip (g.getClipBounds());
  40008. int x = 0;
  40009. for (int i = 0; i < columns.size(); ++i)
  40010. {
  40011. const ColumnInfo* const ci = columns.getUnchecked(i);
  40012. if (ci->isVisible())
  40013. {
  40014. if (x + ci->width > clip.getX()
  40015. && (ci->id != columnIdBeingDragged
  40016. || dragOverlayComp == 0
  40017. || ! dragOverlayComp->isVisible()))
  40018. {
  40019. g.saveState();
  40020. g.setOrigin (x, 0);
  40021. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40022. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40023. ci->id == columnIdUnderMouse,
  40024. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40025. ci->propertyFlags);
  40026. g.restoreState();
  40027. }
  40028. x += ci->width;
  40029. if (x >= clip.getRight())
  40030. break;
  40031. }
  40032. }
  40033. }
  40034. void TableHeaderComponent::resized()
  40035. {
  40036. }
  40037. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40038. {
  40039. updateColumnUnderMouse (e.x, e.y);
  40040. }
  40041. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40042. {
  40043. updateColumnUnderMouse (e.x, e.y);
  40044. }
  40045. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40046. {
  40047. updateColumnUnderMouse (e.x, e.y);
  40048. }
  40049. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40050. {
  40051. repaint();
  40052. columnIdBeingResized = 0;
  40053. columnIdBeingDragged = 0;
  40054. if (columnIdUnderMouse != 0)
  40055. {
  40056. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40057. if (e.mods.isPopupMenu())
  40058. columnClicked (columnIdUnderMouse, e.mods);
  40059. }
  40060. if (menuActive && e.mods.isPopupMenu())
  40061. showColumnChooserMenu (columnIdUnderMouse);
  40062. }
  40063. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40064. {
  40065. if (columnIdBeingResized == 0
  40066. && columnIdBeingDragged == 0
  40067. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40068. {
  40069. dragOverlayComp = 0;
  40070. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40071. if (columnIdBeingResized != 0)
  40072. {
  40073. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40074. initialColumnWidth = ci->width;
  40075. }
  40076. else
  40077. {
  40078. beginDrag (e);
  40079. }
  40080. }
  40081. if (columnIdBeingResized != 0)
  40082. {
  40083. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40084. if (ci != 0)
  40085. {
  40086. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40087. initialColumnWidth + e.getDistanceFromDragStartX());
  40088. if (stretchToFit)
  40089. {
  40090. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40091. int minWidthOnRight = 0;
  40092. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40093. if (columns.getUnchecked (i)->isVisible())
  40094. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40095. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40096. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40097. }
  40098. setColumnWidth (columnIdBeingResized, w);
  40099. }
  40100. }
  40101. else if (columnIdBeingDragged != 0)
  40102. {
  40103. if (e.y >= -50 && e.y < getHeight() + 50)
  40104. {
  40105. if (dragOverlayComp != 0)
  40106. {
  40107. dragOverlayComp->setVisible (true);
  40108. dragOverlayComp->setBounds (jlimit (0,
  40109. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40110. e.x - draggingColumnOffset),
  40111. 0,
  40112. dragOverlayComp->getWidth(),
  40113. getHeight());
  40114. for (int i = columns.size(); --i >= 0;)
  40115. {
  40116. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40117. int newIndex = currentIndex;
  40118. if (newIndex > 0)
  40119. {
  40120. // if the previous column isn't draggable, we can't move our column
  40121. // past it, because that'd change the undraggable column's position..
  40122. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40123. if ((previous->propertyFlags & draggable) != 0)
  40124. {
  40125. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40126. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40127. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40128. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40129. {
  40130. --newIndex;
  40131. }
  40132. }
  40133. }
  40134. if (newIndex < columns.size() - 1)
  40135. {
  40136. // if the next column isn't draggable, we can't move our column
  40137. // past it, because that'd change the undraggable column's position..
  40138. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40139. if ((nextCol->propertyFlags & draggable) != 0)
  40140. {
  40141. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40142. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40143. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40144. > abs (dragOverlayComp->getRight() - rightOfNext))
  40145. {
  40146. ++newIndex;
  40147. }
  40148. }
  40149. }
  40150. if (newIndex != currentIndex)
  40151. moveColumn (columnIdBeingDragged, newIndex);
  40152. else
  40153. break;
  40154. }
  40155. }
  40156. }
  40157. else
  40158. {
  40159. endDrag (draggingColumnOriginalIndex);
  40160. }
  40161. }
  40162. }
  40163. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40164. {
  40165. if (columnIdBeingDragged == 0)
  40166. {
  40167. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40168. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40169. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40170. {
  40171. columnIdBeingDragged = 0;
  40172. }
  40173. else
  40174. {
  40175. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40176. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40177. const int temp = columnIdBeingDragged;
  40178. columnIdBeingDragged = 0;
  40179. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40180. columnIdBeingDragged = temp;
  40181. dragOverlayComp->setBounds (columnRect);
  40182. for (int i = listeners.size(); --i >= 0;)
  40183. {
  40184. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40185. i = jmin (i, listeners.size() - 1);
  40186. }
  40187. }
  40188. }
  40189. }
  40190. void TableHeaderComponent::endDrag (const int finalIndex)
  40191. {
  40192. if (columnIdBeingDragged != 0)
  40193. {
  40194. moveColumn (columnIdBeingDragged, finalIndex);
  40195. columnIdBeingDragged = 0;
  40196. repaint();
  40197. for (int i = listeners.size(); --i >= 0;)
  40198. {
  40199. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40200. i = jmin (i, listeners.size() - 1);
  40201. }
  40202. }
  40203. }
  40204. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40205. {
  40206. mouseDrag (e);
  40207. for (int i = columns.size(); --i >= 0;)
  40208. if (columns.getUnchecked (i)->isVisible())
  40209. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40210. columnIdBeingResized = 0;
  40211. repaint();
  40212. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40213. updateColumnUnderMouse (e.x, e.y);
  40214. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40215. columnClicked (columnIdUnderMouse, e.mods);
  40216. dragOverlayComp = 0;
  40217. }
  40218. const MouseCursor TableHeaderComponent::getMouseCursor()
  40219. {
  40220. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40221. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40222. return Component::getMouseCursor();
  40223. }
  40224. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40225. {
  40226. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40227. }
  40228. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40229. {
  40230. for (int i = columns.size(); --i >= 0;)
  40231. if (columns.getUnchecked(i)->id == id)
  40232. return columns.getUnchecked(i);
  40233. return 0;
  40234. }
  40235. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40236. {
  40237. int n = 0;
  40238. for (int i = 0; i < columns.size(); ++i)
  40239. {
  40240. if (columns.getUnchecked(i)->isVisible())
  40241. {
  40242. if (n == visibleIndex)
  40243. return i;
  40244. ++n;
  40245. }
  40246. }
  40247. return -1;
  40248. }
  40249. void TableHeaderComponent::sendColumnsChanged()
  40250. {
  40251. if (stretchToFit && lastDeliberateWidth > 0)
  40252. resizeAllColumnsToFit (lastDeliberateWidth);
  40253. repaint();
  40254. columnsChanged = true;
  40255. triggerAsyncUpdate();
  40256. }
  40257. void TableHeaderComponent::handleAsyncUpdate()
  40258. {
  40259. const bool changed = columnsChanged || sortChanged;
  40260. const bool sized = columnsResized || changed;
  40261. const bool sorted = sortChanged;
  40262. columnsChanged = false;
  40263. columnsResized = false;
  40264. sortChanged = false;
  40265. if (sorted)
  40266. {
  40267. for (int i = listeners.size(); --i >= 0;)
  40268. {
  40269. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40270. i = jmin (i, listeners.size() - 1);
  40271. }
  40272. }
  40273. if (changed)
  40274. {
  40275. for (int i = listeners.size(); --i >= 0;)
  40276. {
  40277. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40278. i = jmin (i, listeners.size() - 1);
  40279. }
  40280. }
  40281. if (sized)
  40282. {
  40283. for (int i = listeners.size(); --i >= 0;)
  40284. {
  40285. listeners.getUnchecked(i)->tableColumnsResized (this);
  40286. i = jmin (i, listeners.size() - 1);
  40287. }
  40288. }
  40289. }
  40290. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40291. {
  40292. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40293. {
  40294. const int draggableDistance = 3;
  40295. int x = 0;
  40296. for (int i = 0; i < columns.size(); ++i)
  40297. {
  40298. const ColumnInfo* const ci = columns.getUnchecked(i);
  40299. if (ci->isVisible())
  40300. {
  40301. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40302. && (ci->propertyFlags & resizable) != 0)
  40303. return ci->id;
  40304. x += ci->width;
  40305. }
  40306. }
  40307. }
  40308. return 0;
  40309. }
  40310. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40311. {
  40312. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40313. ? getColumnIdAtX (x) : 0;
  40314. if (newCol != columnIdUnderMouse)
  40315. {
  40316. columnIdUnderMouse = newCol;
  40317. repaint();
  40318. }
  40319. }
  40320. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40321. {
  40322. PopupMenu m;
  40323. addMenuItems (m, columnIdClicked);
  40324. if (m.getNumItems() > 0)
  40325. {
  40326. m.setLookAndFeel (&getLookAndFeel());
  40327. const int result = m.show();
  40328. if (result != 0)
  40329. reactToMenuItem (result, columnIdClicked);
  40330. }
  40331. }
  40332. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40333. {
  40334. }
  40335. END_JUCE_NAMESPACE
  40336. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40337. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40338. BEGIN_JUCE_NAMESPACE
  40339. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40340. class TableListRowComp : public Component,
  40341. public TooltipClient
  40342. {
  40343. public:
  40344. TableListRowComp (TableListBox& owner_)
  40345. : owner (owner_),
  40346. row (-1),
  40347. isSelected (false)
  40348. {
  40349. }
  40350. ~TableListRowComp()
  40351. {
  40352. deleteAllChildren();
  40353. }
  40354. void paint (Graphics& g)
  40355. {
  40356. TableListBoxModel* const model = owner.getModel();
  40357. if (model != 0)
  40358. {
  40359. const TableHeaderComponent* const header = owner.getHeader();
  40360. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40361. const int numColumns = header->getNumColumns (true);
  40362. for (int i = 0; i < numColumns; ++i)
  40363. {
  40364. if (! columnsWithComponents [i])
  40365. {
  40366. const int columnId = header->getColumnIdOfIndex (i, true);
  40367. Rectangle<int> columnRect (header->getColumnPosition (i));
  40368. columnRect.setSize (columnRect.getWidth(), getHeight());
  40369. g.saveState();
  40370. g.reduceClipRegion (columnRect);
  40371. g.setOrigin (columnRect.getX(), 0);
  40372. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40373. g.restoreState();
  40374. }
  40375. }
  40376. }
  40377. }
  40378. void update (const int newRow, const bool isNowSelected)
  40379. {
  40380. if (newRow != row || isNowSelected != isSelected)
  40381. {
  40382. row = newRow;
  40383. isSelected = isNowSelected;
  40384. repaint();
  40385. }
  40386. if (row < owner.getNumRows())
  40387. {
  40388. jassert (row >= 0);
  40389. const var::identifier tagPropertyName ("_tableLastUseNum");
  40390. const int newTag = Random::getSystemRandom().nextInt();
  40391. const TableHeaderComponent* const header = owner.getHeader();
  40392. const int numColumns = header->getNumColumns (true);
  40393. int i;
  40394. columnsWithComponents.clear();
  40395. if (owner.getModel() != 0)
  40396. {
  40397. for (i = 0; i < numColumns; ++i)
  40398. {
  40399. const int columnId = header->getColumnIdOfIndex (i, true);
  40400. Component* const newComp
  40401. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40402. findChildComponentForColumn (columnId));
  40403. if (newComp != 0)
  40404. {
  40405. addAndMakeVisible (newComp);
  40406. newComp->getProperties().set (tagPropertyName, newTag);
  40407. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40408. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40409. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40410. columnsWithComponents.setBit (i);
  40411. }
  40412. }
  40413. }
  40414. for (i = getNumChildComponents(); --i >= 0;)
  40415. {
  40416. Component* const c = getChildComponent (i);
  40417. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40418. delete c;
  40419. }
  40420. }
  40421. else
  40422. {
  40423. columnsWithComponents.clear();
  40424. deleteAllChildren();
  40425. }
  40426. }
  40427. void resized()
  40428. {
  40429. for (int i = getNumChildComponents(); --i >= 0;)
  40430. {
  40431. Component* const c = getChildComponent (i);
  40432. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40433. if (columnId != 0)
  40434. {
  40435. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40436. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40437. }
  40438. }
  40439. }
  40440. void mouseDown (const MouseEvent& e)
  40441. {
  40442. isDragging = false;
  40443. selectRowOnMouseUp = false;
  40444. if (isEnabled())
  40445. {
  40446. if (! isSelected)
  40447. {
  40448. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40449. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40450. if (columnId != 0 && owner.getModel() != 0)
  40451. owner.getModel()->cellClicked (row, columnId, e);
  40452. }
  40453. else
  40454. {
  40455. selectRowOnMouseUp = true;
  40456. }
  40457. }
  40458. }
  40459. void mouseDrag (const MouseEvent& e)
  40460. {
  40461. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40462. {
  40463. const SparseSet<int> selectedRows (owner.getSelectedRows());
  40464. if (selectedRows.size() > 0)
  40465. {
  40466. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40467. if (dragDescription.isNotEmpty())
  40468. {
  40469. isDragging = true;
  40470. owner.startDragAndDrop (e, dragDescription);
  40471. }
  40472. }
  40473. }
  40474. }
  40475. void mouseUp (const MouseEvent& e)
  40476. {
  40477. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40478. {
  40479. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40480. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40481. if (columnId != 0 && owner.getModel() != 0)
  40482. owner.getModel()->cellClicked (row, columnId, e);
  40483. }
  40484. }
  40485. void mouseDoubleClick (const MouseEvent& e)
  40486. {
  40487. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40488. if (columnId != 0 && owner.getModel() != 0)
  40489. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40490. }
  40491. const String getTooltip()
  40492. {
  40493. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40494. if (columnId != 0 && owner.getModel() != 0)
  40495. return owner.getModel()->getCellTooltip (row, columnId);
  40496. return String::empty;
  40497. }
  40498. juce_UseDebuggingNewOperator
  40499. private:
  40500. TableListBox& owner;
  40501. int row;
  40502. bool isSelected, isDragging, selectRowOnMouseUp;
  40503. BigInteger columnsWithComponents;
  40504. Component* findChildComponentForColumn (const int columnId) const
  40505. {
  40506. for (int i = getNumChildComponents(); --i >= 0;)
  40507. {
  40508. Component* const c = getChildComponent (i);
  40509. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40510. return c;
  40511. }
  40512. return 0;
  40513. }
  40514. TableListRowComp (const TableListRowComp&);
  40515. TableListRowComp& operator= (const TableListRowComp&);
  40516. };
  40517. class TableListBoxHeader : public TableHeaderComponent
  40518. {
  40519. public:
  40520. TableListBoxHeader (TableListBox& owner_)
  40521. : owner (owner_)
  40522. {
  40523. }
  40524. ~TableListBoxHeader()
  40525. {
  40526. }
  40527. void addMenuItems (PopupMenu& menu, int columnIdClicked)
  40528. {
  40529. if (owner.isAutoSizeMenuOptionShown())
  40530. {
  40531. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40532. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40533. menu.addSeparator();
  40534. }
  40535. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40536. }
  40537. void reactToMenuItem (int menuReturnId, int columnIdClicked)
  40538. {
  40539. if (menuReturnId == 0xf836743)
  40540. {
  40541. owner.autoSizeColumn (columnIdClicked);
  40542. }
  40543. else if (menuReturnId == 0xf836744)
  40544. {
  40545. owner.autoSizeAllColumns();
  40546. }
  40547. else
  40548. {
  40549. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40550. }
  40551. }
  40552. juce_UseDebuggingNewOperator
  40553. private:
  40554. TableListBox& owner;
  40555. TableListBoxHeader (const TableListBoxHeader&);
  40556. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40557. };
  40558. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40559. : ListBox (name, 0),
  40560. model (model_),
  40561. autoSizeOptionsShown (true)
  40562. {
  40563. ListBox::model = this;
  40564. header = new TableListBoxHeader (*this);
  40565. header->setSize (100, 28);
  40566. header->addListener (this);
  40567. setHeaderComponent (header);
  40568. }
  40569. TableListBox::~TableListBox()
  40570. {
  40571. deleteAllChildren();
  40572. }
  40573. void TableListBox::setModel (TableListBoxModel* const newModel)
  40574. {
  40575. if (model != newModel)
  40576. {
  40577. model = newModel;
  40578. updateContent();
  40579. }
  40580. }
  40581. int TableListBox::getHeaderHeight() const
  40582. {
  40583. return header->getHeight();
  40584. }
  40585. void TableListBox::setHeaderHeight (const int newHeight)
  40586. {
  40587. header->setSize (header->getWidth(), newHeight);
  40588. resized();
  40589. }
  40590. void TableListBox::autoSizeColumn (const int columnId)
  40591. {
  40592. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40593. if (width > 0)
  40594. header->setColumnWidth (columnId, width);
  40595. }
  40596. void TableListBox::autoSizeAllColumns()
  40597. {
  40598. for (int i = 0; i < header->getNumColumns (true); ++i)
  40599. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40600. }
  40601. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40602. {
  40603. autoSizeOptionsShown = shouldBeShown;
  40604. }
  40605. bool TableListBox::isAutoSizeMenuOptionShown() const
  40606. {
  40607. return autoSizeOptionsShown;
  40608. }
  40609. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40610. const int rowNumber,
  40611. const bool relativeToComponentTopLeft) const
  40612. {
  40613. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40614. if (relativeToComponentTopLeft)
  40615. headerCell.translate (header->getX(), 0);
  40616. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40617. return Rectangle<int> (headerCell.getX(), row.getY(),
  40618. headerCell.getWidth(), row.getHeight());
  40619. }
  40620. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40621. {
  40622. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40623. if (scrollbar != 0)
  40624. {
  40625. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40626. double x = scrollbar->getCurrentRangeStart();
  40627. const double w = scrollbar->getCurrentRangeSize();
  40628. if (pos.getX() < x)
  40629. x = pos.getX();
  40630. else if (pos.getRight() > x + w)
  40631. x += jmax (0.0, pos.getRight() - (x + w));
  40632. scrollbar->setCurrentRangeStart (x);
  40633. }
  40634. }
  40635. int TableListBox::getNumRows()
  40636. {
  40637. return model != 0 ? model->getNumRows() : 0;
  40638. }
  40639. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40640. {
  40641. }
  40642. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40643. {
  40644. if (existingComponentToUpdate == 0)
  40645. existingComponentToUpdate = new TableListRowComp (*this);
  40646. static_cast <TableListRowComp*> (existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40647. return existingComponentToUpdate;
  40648. }
  40649. void TableListBox::selectedRowsChanged (int row)
  40650. {
  40651. if (model != 0)
  40652. model->selectedRowsChanged (row);
  40653. }
  40654. void TableListBox::deleteKeyPressed (int row)
  40655. {
  40656. if (model != 0)
  40657. model->deleteKeyPressed (row);
  40658. }
  40659. void TableListBox::returnKeyPressed (int row)
  40660. {
  40661. if (model != 0)
  40662. model->returnKeyPressed (row);
  40663. }
  40664. void TableListBox::backgroundClicked()
  40665. {
  40666. if (model != 0)
  40667. model->backgroundClicked();
  40668. }
  40669. void TableListBox::listWasScrolled()
  40670. {
  40671. if (model != 0)
  40672. model->listWasScrolled();
  40673. }
  40674. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40675. {
  40676. setMinimumContentWidth (header->getTotalWidth());
  40677. repaint();
  40678. updateColumnComponents();
  40679. }
  40680. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40681. {
  40682. setMinimumContentWidth (header->getTotalWidth());
  40683. repaint();
  40684. updateColumnComponents();
  40685. }
  40686. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40687. {
  40688. if (model != 0)
  40689. model->sortOrderChanged (header->getSortColumnId(),
  40690. header->isSortedForwards());
  40691. }
  40692. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40693. {
  40694. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40695. repaint();
  40696. }
  40697. void TableListBox::resized()
  40698. {
  40699. ListBox::resized();
  40700. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40701. setMinimumContentWidth (header->getTotalWidth());
  40702. }
  40703. void TableListBox::updateColumnComponents() const
  40704. {
  40705. const int firstRow = getRowContainingPosition (0, 0);
  40706. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40707. {
  40708. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40709. if (rowComp != 0)
  40710. rowComp->resized();
  40711. }
  40712. }
  40713. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40714. {
  40715. }
  40716. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40717. {
  40718. }
  40719. void TableListBoxModel::backgroundClicked()
  40720. {
  40721. }
  40722. void TableListBoxModel::sortOrderChanged (int, const bool)
  40723. {
  40724. }
  40725. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40726. {
  40727. return 0;
  40728. }
  40729. void TableListBoxModel::selectedRowsChanged (int)
  40730. {
  40731. }
  40732. void TableListBoxModel::deleteKeyPressed (int)
  40733. {
  40734. }
  40735. void TableListBoxModel::returnKeyPressed (int)
  40736. {
  40737. }
  40738. void TableListBoxModel::listWasScrolled()
  40739. {
  40740. }
  40741. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40742. {
  40743. return String::empty;
  40744. }
  40745. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40746. {
  40747. return String::empty;
  40748. }
  40749. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  40750. {
  40751. (void) existingComponentToUpdate;
  40752. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  40753. return 0;
  40754. }
  40755. END_JUCE_NAMESPACE
  40756. /*** End of inlined file: juce_TableListBox.cpp ***/
  40757. /*** Start of inlined file: juce_TextEditor.cpp ***/
  40758. BEGIN_JUCE_NAMESPACE
  40759. // a word or space that can't be broken down any further
  40760. struct TextAtom
  40761. {
  40762. String atomText;
  40763. float width;
  40764. uint16 numChars;
  40765. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  40766. bool isNewLine() const { return atomText[0] == '\r' || atomText[0] == '\n'; }
  40767. const String getText (const juce_wchar passwordCharacter) const
  40768. {
  40769. if (passwordCharacter == 0)
  40770. return atomText;
  40771. else
  40772. return String::repeatedString (String::charToString (passwordCharacter),
  40773. atomText.length());
  40774. }
  40775. const String getTrimmedText (const juce_wchar passwordCharacter) const
  40776. {
  40777. if (passwordCharacter == 0)
  40778. return atomText.substring (0, numChars);
  40779. else if (isNewLine())
  40780. return String::empty;
  40781. else
  40782. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  40783. }
  40784. };
  40785. // a run of text with a single font and colour
  40786. class TextEditor::UniformTextSection
  40787. {
  40788. public:
  40789. UniformTextSection (const String& text,
  40790. const Font& font_,
  40791. const Colour& colour_,
  40792. const juce_wchar passwordCharacter)
  40793. : font (font_),
  40794. colour (colour_)
  40795. {
  40796. initialiseAtoms (text, passwordCharacter);
  40797. }
  40798. UniformTextSection (const UniformTextSection& other)
  40799. : font (other.font),
  40800. colour (other.colour)
  40801. {
  40802. atoms.ensureStorageAllocated (other.atoms.size());
  40803. for (int i = 0; i < other.atoms.size(); ++i)
  40804. atoms.add (new TextAtom (*other.atoms.getUnchecked(i)));
  40805. }
  40806. ~UniformTextSection()
  40807. {
  40808. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  40809. }
  40810. void clear()
  40811. {
  40812. for (int i = atoms.size(); --i >= 0;)
  40813. delete getAtom(i);
  40814. atoms.clear();
  40815. }
  40816. int getNumAtoms() const
  40817. {
  40818. return atoms.size();
  40819. }
  40820. TextAtom* getAtom (const int index) const throw()
  40821. {
  40822. return atoms.getUnchecked (index);
  40823. }
  40824. void append (const UniformTextSection& other, const juce_wchar passwordCharacter)
  40825. {
  40826. if (other.atoms.size() > 0)
  40827. {
  40828. TextAtom* const lastAtom = atoms.getLast();
  40829. int i = 0;
  40830. if (lastAtom != 0)
  40831. {
  40832. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  40833. {
  40834. TextAtom* const first = other.getAtom(0);
  40835. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  40836. {
  40837. lastAtom->atomText += first->atomText;
  40838. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  40839. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  40840. delete first;
  40841. ++i;
  40842. }
  40843. }
  40844. }
  40845. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  40846. while (i < other.atoms.size())
  40847. {
  40848. atoms.add (other.getAtom(i));
  40849. ++i;
  40850. }
  40851. }
  40852. }
  40853. UniformTextSection* split (const int indexToBreakAt,
  40854. const juce_wchar passwordCharacter)
  40855. {
  40856. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  40857. font, colour,
  40858. passwordCharacter);
  40859. int index = 0;
  40860. for (int i = 0; i < atoms.size(); ++i)
  40861. {
  40862. TextAtom* const atom = getAtom(i);
  40863. const int nextIndex = index + atom->numChars;
  40864. if (index == indexToBreakAt)
  40865. {
  40866. int j;
  40867. for (j = i; j < atoms.size(); ++j)
  40868. section2->atoms.add (getAtom (j));
  40869. for (j = atoms.size(); --j >= i;)
  40870. atoms.remove (j);
  40871. break;
  40872. }
  40873. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  40874. {
  40875. TextAtom* const secondAtom = new TextAtom();
  40876. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  40877. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  40878. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  40879. section2->atoms.add (secondAtom);
  40880. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  40881. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  40882. atom->numChars = (uint16) (indexToBreakAt - index);
  40883. int j;
  40884. for (j = i + 1; j < atoms.size(); ++j)
  40885. section2->atoms.add (getAtom (j));
  40886. for (j = atoms.size(); --j > i;)
  40887. atoms.remove (j);
  40888. break;
  40889. }
  40890. index = nextIndex;
  40891. }
  40892. return section2;
  40893. }
  40894. void appendAllText (String::Concatenator& concatenator) const
  40895. {
  40896. for (int i = 0; i < atoms.size(); ++i)
  40897. concatenator.append (getAtom(i)->atomText);
  40898. }
  40899. void appendSubstring (String::Concatenator& concatenator,
  40900. const Range<int>& range) const
  40901. {
  40902. int index = 0;
  40903. for (int i = 0; i < atoms.size(); ++i)
  40904. {
  40905. const TextAtom* const atom = getAtom (i);
  40906. const int nextIndex = index + atom->numChars;
  40907. if (range.getStart() < nextIndex)
  40908. {
  40909. if (range.getEnd() <= index)
  40910. break;
  40911. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  40912. if (! r.isEmpty())
  40913. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  40914. }
  40915. index = nextIndex;
  40916. }
  40917. }
  40918. int getTotalLength() const
  40919. {
  40920. int total = 0;
  40921. for (int i = atoms.size(); --i >= 0;)
  40922. total += getAtom(i)->numChars;
  40923. return total;
  40924. }
  40925. void setFont (const Font& newFont,
  40926. const juce_wchar passwordCharacter)
  40927. {
  40928. if (font != newFont)
  40929. {
  40930. font = newFont;
  40931. for (int i = atoms.size(); --i >= 0;)
  40932. {
  40933. TextAtom* const atom = atoms.getUnchecked(i);
  40934. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  40935. }
  40936. }
  40937. }
  40938. juce_UseDebuggingNewOperator
  40939. Font font;
  40940. Colour colour;
  40941. private:
  40942. Array <TextAtom*> atoms;
  40943. void initialiseAtoms (const String& textToParse,
  40944. const juce_wchar passwordCharacter)
  40945. {
  40946. int i = 0;
  40947. const int len = textToParse.length();
  40948. const juce_wchar* const text = textToParse;
  40949. while (i < len)
  40950. {
  40951. int start = i;
  40952. // create a whitespace atom unless it starts with non-ws
  40953. if (CharacterFunctions::isWhitespace (text[i])
  40954. && text[i] != '\r'
  40955. && text[i] != '\n')
  40956. {
  40957. while (i < len
  40958. && CharacterFunctions::isWhitespace (text[i])
  40959. && text[i] != '\r'
  40960. && text[i] != '\n')
  40961. {
  40962. ++i;
  40963. }
  40964. }
  40965. else
  40966. {
  40967. if (text[i] == '\r')
  40968. {
  40969. ++i;
  40970. if ((i < len) && (text[i] == '\n'))
  40971. {
  40972. ++start;
  40973. ++i;
  40974. }
  40975. }
  40976. else if (text[i] == '\n')
  40977. {
  40978. ++i;
  40979. }
  40980. else
  40981. {
  40982. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  40983. ++i;
  40984. }
  40985. }
  40986. TextAtom* const atom = new TextAtom();
  40987. atom->atomText = String (text + start, i - start);
  40988. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  40989. atom->numChars = (uint16) (i - start);
  40990. atoms.add (atom);
  40991. }
  40992. }
  40993. UniformTextSection& operator= (const UniformTextSection& other);
  40994. };
  40995. class TextEditor::Iterator
  40996. {
  40997. public:
  40998. Iterator (const Array <UniformTextSection*>& sections_,
  40999. const float wordWrapWidth_,
  41000. const juce_wchar passwordCharacter_)
  41001. : indexInText (0),
  41002. lineY (0),
  41003. lineHeight (0),
  41004. maxDescent (0),
  41005. atomX (0),
  41006. atomRight (0),
  41007. atom (0),
  41008. currentSection (0),
  41009. sections (sections_),
  41010. sectionIndex (0),
  41011. atomIndex (0),
  41012. wordWrapWidth (wordWrapWidth_),
  41013. passwordCharacter (passwordCharacter_)
  41014. {
  41015. jassert (wordWrapWidth_ > 0);
  41016. if (sections.size() > 0)
  41017. {
  41018. currentSection = sections.getUnchecked (sectionIndex);
  41019. if (currentSection != 0)
  41020. beginNewLine();
  41021. }
  41022. }
  41023. Iterator (const Iterator& other)
  41024. : indexInText (other.indexInText),
  41025. lineY (other.lineY),
  41026. lineHeight (other.lineHeight),
  41027. maxDescent (other.maxDescent),
  41028. atomX (other.atomX),
  41029. atomRight (other.atomRight),
  41030. atom (other.atom),
  41031. currentSection (other.currentSection),
  41032. sections (other.sections),
  41033. sectionIndex (other.sectionIndex),
  41034. atomIndex (other.atomIndex),
  41035. wordWrapWidth (other.wordWrapWidth),
  41036. passwordCharacter (other.passwordCharacter),
  41037. tempAtom (other.tempAtom)
  41038. {
  41039. }
  41040. ~Iterator()
  41041. {
  41042. }
  41043. bool next()
  41044. {
  41045. if (atom == &tempAtom)
  41046. {
  41047. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41048. if (numRemaining > 0)
  41049. {
  41050. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41051. atomX = 0;
  41052. if (tempAtom.numChars > 0)
  41053. lineY += lineHeight;
  41054. indexInText += tempAtom.numChars;
  41055. GlyphArrangement g;
  41056. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41057. int split;
  41058. for (split = 0; split < g.getNumGlyphs(); ++split)
  41059. if (shouldWrap (g.getGlyph (split).getRight()))
  41060. break;
  41061. if (split > 0 && split <= numRemaining)
  41062. {
  41063. tempAtom.numChars = (uint16) split;
  41064. tempAtom.width = g.getGlyph (split - 1).getRight();
  41065. atomRight = atomX + tempAtom.width;
  41066. return true;
  41067. }
  41068. }
  41069. }
  41070. bool forceNewLine = false;
  41071. if (sectionIndex >= sections.size())
  41072. {
  41073. moveToEndOfLastAtom();
  41074. return false;
  41075. }
  41076. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41077. {
  41078. if (atomIndex >= currentSection->getNumAtoms())
  41079. {
  41080. if (++sectionIndex >= sections.size())
  41081. {
  41082. moveToEndOfLastAtom();
  41083. return false;
  41084. }
  41085. atomIndex = 0;
  41086. currentSection = sections.getUnchecked (sectionIndex);
  41087. }
  41088. else
  41089. {
  41090. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41091. if (! lastAtom->isWhitespace())
  41092. {
  41093. // handle the case where the last atom in a section is actually part of the same
  41094. // word as the first atom of the next section...
  41095. float right = atomRight + lastAtom->width;
  41096. float lineHeight2 = lineHeight;
  41097. float maxDescent2 = maxDescent;
  41098. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41099. {
  41100. const UniformTextSection* const s = sections.getUnchecked (section);
  41101. if (s->getNumAtoms() == 0)
  41102. break;
  41103. const TextAtom* const nextAtom = s->getAtom (0);
  41104. if (nextAtom->isWhitespace())
  41105. break;
  41106. right += nextAtom->width;
  41107. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41108. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41109. if (shouldWrap (right))
  41110. {
  41111. lineHeight = lineHeight2;
  41112. maxDescent = maxDescent2;
  41113. forceNewLine = true;
  41114. break;
  41115. }
  41116. if (s->getNumAtoms() > 1)
  41117. break;
  41118. }
  41119. }
  41120. }
  41121. }
  41122. if (atom != 0)
  41123. {
  41124. atomX = atomRight;
  41125. indexInText += atom->numChars;
  41126. if (atom->isNewLine())
  41127. beginNewLine();
  41128. }
  41129. atom = currentSection->getAtom (atomIndex);
  41130. atomRight = atomX + atom->width;
  41131. ++atomIndex;
  41132. if (shouldWrap (atomRight) || forceNewLine)
  41133. {
  41134. if (atom->isWhitespace())
  41135. {
  41136. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41137. atomRight = jmin (atomRight, wordWrapWidth);
  41138. }
  41139. else
  41140. {
  41141. atomRight = atom->width;
  41142. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41143. {
  41144. tempAtom = *atom;
  41145. tempAtom.width = 0;
  41146. tempAtom.numChars = 0;
  41147. atom = &tempAtom;
  41148. if (atomX > 0)
  41149. beginNewLine();
  41150. return next();
  41151. }
  41152. beginNewLine();
  41153. return true;
  41154. }
  41155. }
  41156. return true;
  41157. }
  41158. void beginNewLine()
  41159. {
  41160. atomX = 0;
  41161. lineY += lineHeight;
  41162. int tempSectionIndex = sectionIndex;
  41163. int tempAtomIndex = atomIndex;
  41164. const UniformTextSection* section = sections.getUnchecked (tempSectionIndex);
  41165. lineHeight = section->font.getHeight();
  41166. maxDescent = section->font.getDescent();
  41167. float x = (atom != 0) ? atom->width : 0;
  41168. while (! shouldWrap (x))
  41169. {
  41170. if (tempSectionIndex >= sections.size())
  41171. break;
  41172. bool checkSize = false;
  41173. if (tempAtomIndex >= section->getNumAtoms())
  41174. {
  41175. if (++tempSectionIndex >= sections.size())
  41176. break;
  41177. tempAtomIndex = 0;
  41178. section = sections.getUnchecked (tempSectionIndex);
  41179. checkSize = true;
  41180. }
  41181. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41182. if (nextAtom == 0)
  41183. break;
  41184. x += nextAtom->width;
  41185. if (shouldWrap (x) || nextAtom->isNewLine())
  41186. break;
  41187. if (checkSize)
  41188. {
  41189. lineHeight = jmax (lineHeight, section->font.getHeight());
  41190. maxDescent = jmax (maxDescent, section->font.getDescent());
  41191. }
  41192. ++tempAtomIndex;
  41193. }
  41194. }
  41195. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41196. {
  41197. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41198. {
  41199. if (lastSection != currentSection)
  41200. {
  41201. lastSection = currentSection;
  41202. g.setColour (currentSection->colour);
  41203. g.setFont (currentSection->font);
  41204. }
  41205. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41206. GlyphArrangement ga;
  41207. ga.addLineOfText (currentSection->font,
  41208. atom->getTrimmedText (passwordCharacter),
  41209. atomX,
  41210. (float) roundToInt (lineY + lineHeight - maxDescent));
  41211. ga.draw (g);
  41212. }
  41213. }
  41214. void drawSelection (Graphics& g,
  41215. const Range<int>& selection) const
  41216. {
  41217. const int startX = roundToInt (indexToX (selection.getStart()));
  41218. const int endX = roundToInt (indexToX (selection.getEnd()));
  41219. const int y = roundToInt (lineY);
  41220. const int nextY = roundToInt (lineY + lineHeight);
  41221. g.fillRect (startX, y, endX - startX, nextY - y);
  41222. }
  41223. void drawSelectedText (Graphics& g,
  41224. const Range<int>& selection,
  41225. const Colour& selectedTextColour) const
  41226. {
  41227. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41228. {
  41229. GlyphArrangement ga;
  41230. ga.addLineOfText (currentSection->font,
  41231. atom->getTrimmedText (passwordCharacter),
  41232. atomX,
  41233. (float) roundToInt (lineY + lineHeight - maxDescent));
  41234. if (selection.getEnd() < indexInText + atom->numChars)
  41235. {
  41236. GlyphArrangement ga2 (ga);
  41237. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41238. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41239. g.setColour (currentSection->colour);
  41240. ga2.draw (g);
  41241. }
  41242. if (selection.getStart() > indexInText)
  41243. {
  41244. GlyphArrangement ga2 (ga);
  41245. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41246. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41247. g.setColour (currentSection->colour);
  41248. ga2.draw (g);
  41249. }
  41250. g.setColour (selectedTextColour);
  41251. ga.draw (g);
  41252. }
  41253. }
  41254. float indexToX (const int indexToFind) const
  41255. {
  41256. if (indexToFind <= indexInText)
  41257. return atomX;
  41258. if (indexToFind >= indexInText + atom->numChars)
  41259. return atomRight;
  41260. GlyphArrangement g;
  41261. g.addLineOfText (currentSection->font,
  41262. atom->getText (passwordCharacter),
  41263. atomX, 0.0f);
  41264. if (indexToFind - indexInText >= g.getNumGlyphs())
  41265. return atomRight;
  41266. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41267. }
  41268. int xToIndex (const float xToFind) const
  41269. {
  41270. if (xToFind <= atomX || atom->isNewLine())
  41271. return indexInText;
  41272. if (xToFind >= atomRight)
  41273. return indexInText + atom->numChars;
  41274. GlyphArrangement g;
  41275. g.addLineOfText (currentSection->font,
  41276. atom->getText (passwordCharacter),
  41277. atomX, 0.0f);
  41278. int j;
  41279. for (j = 0; j < g.getNumGlyphs(); ++j)
  41280. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41281. break;
  41282. return indexInText + j;
  41283. }
  41284. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41285. {
  41286. while (next())
  41287. {
  41288. if (indexInText + atom->numChars > index)
  41289. {
  41290. cx = indexToX (index);
  41291. cy = lineY;
  41292. lineHeight_ = lineHeight;
  41293. return true;
  41294. }
  41295. }
  41296. cx = atomX;
  41297. cy = lineY;
  41298. lineHeight_ = lineHeight;
  41299. return false;
  41300. }
  41301. juce_UseDebuggingNewOperator
  41302. int indexInText;
  41303. float lineY, lineHeight, maxDescent;
  41304. float atomX, atomRight;
  41305. const TextAtom* atom;
  41306. const UniformTextSection* currentSection;
  41307. private:
  41308. const Array <UniformTextSection*>& sections;
  41309. int sectionIndex, atomIndex;
  41310. const float wordWrapWidth;
  41311. const juce_wchar passwordCharacter;
  41312. TextAtom tempAtom;
  41313. Iterator& operator= (const Iterator&);
  41314. void moveToEndOfLastAtom()
  41315. {
  41316. if (atom != 0)
  41317. {
  41318. atomX = atomRight;
  41319. if (atom->isNewLine())
  41320. {
  41321. atomX = 0.0f;
  41322. lineY += lineHeight;
  41323. }
  41324. }
  41325. }
  41326. bool shouldWrap (const float x) const
  41327. {
  41328. return (x - 0.0001f) >= wordWrapWidth;
  41329. }
  41330. };
  41331. class TextEditor::InsertAction : public UndoableAction
  41332. {
  41333. TextEditor& owner;
  41334. const String text;
  41335. const int insertIndex, oldCaretPos, newCaretPos;
  41336. const Font font;
  41337. const Colour colour;
  41338. InsertAction (const InsertAction&);
  41339. InsertAction& operator= (const InsertAction&);
  41340. public:
  41341. InsertAction (TextEditor& owner_,
  41342. const String& text_,
  41343. const int insertIndex_,
  41344. const Font& font_,
  41345. const Colour& colour_,
  41346. const int oldCaretPos_,
  41347. const int newCaretPos_)
  41348. : owner (owner_),
  41349. text (text_),
  41350. insertIndex (insertIndex_),
  41351. oldCaretPos (oldCaretPos_),
  41352. newCaretPos (newCaretPos_),
  41353. font (font_),
  41354. colour (colour_)
  41355. {
  41356. }
  41357. ~InsertAction()
  41358. {
  41359. }
  41360. bool perform()
  41361. {
  41362. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41363. return true;
  41364. }
  41365. bool undo()
  41366. {
  41367. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41368. return true;
  41369. }
  41370. int getSizeInUnits()
  41371. {
  41372. return text.length() + 16;
  41373. }
  41374. };
  41375. class TextEditor::RemoveAction : public UndoableAction
  41376. {
  41377. TextEditor& owner;
  41378. const Range<int> range;
  41379. const int oldCaretPos, newCaretPos;
  41380. Array <UniformTextSection*> removedSections;
  41381. RemoveAction (const RemoveAction&);
  41382. RemoveAction& operator= (const RemoveAction&);
  41383. public:
  41384. RemoveAction (TextEditor& owner_,
  41385. const Range<int> range_,
  41386. const int oldCaretPos_,
  41387. const int newCaretPos_,
  41388. const Array <UniformTextSection*>& removedSections_)
  41389. : owner (owner_),
  41390. range (range_),
  41391. oldCaretPos (oldCaretPos_),
  41392. newCaretPos (newCaretPos_),
  41393. removedSections (removedSections_)
  41394. {
  41395. }
  41396. ~RemoveAction()
  41397. {
  41398. for (int i = removedSections.size(); --i >= 0;)
  41399. {
  41400. UniformTextSection* const section = removedSections.getUnchecked (i);
  41401. section->clear();
  41402. delete section;
  41403. }
  41404. }
  41405. bool perform()
  41406. {
  41407. owner.remove (range, 0, newCaretPos);
  41408. return true;
  41409. }
  41410. bool undo()
  41411. {
  41412. owner.reinsert (range.getStart(), removedSections);
  41413. owner.moveCursorTo (oldCaretPos, false);
  41414. return true;
  41415. }
  41416. int getSizeInUnits()
  41417. {
  41418. int n = 0;
  41419. for (int i = removedSections.size(); --i >= 0;)
  41420. n += removedSections.getUnchecked (i)->getTotalLength();
  41421. return n + 16;
  41422. }
  41423. };
  41424. class TextEditor::TextHolderComponent : public Component,
  41425. public Timer,
  41426. public Value::Listener
  41427. {
  41428. public:
  41429. TextHolderComponent (TextEditor& owner_)
  41430. : owner (owner_)
  41431. {
  41432. setWantsKeyboardFocus (false);
  41433. setInterceptsMouseClicks (false, true);
  41434. owner.getTextValue().addListener (this);
  41435. }
  41436. ~TextHolderComponent()
  41437. {
  41438. owner.getTextValue().removeListener (this);
  41439. }
  41440. void paint (Graphics& g)
  41441. {
  41442. owner.drawContent (g);
  41443. }
  41444. void timerCallback()
  41445. {
  41446. owner.timerCallbackInt();
  41447. }
  41448. const MouseCursor getMouseCursor()
  41449. {
  41450. return owner.getMouseCursor();
  41451. }
  41452. void valueChanged (Value&)
  41453. {
  41454. owner.textWasChangedByValue();
  41455. }
  41456. private:
  41457. TextEditor& owner;
  41458. TextHolderComponent (const TextHolderComponent&);
  41459. TextHolderComponent& operator= (const TextHolderComponent&);
  41460. };
  41461. class TextEditorViewport : public Viewport
  41462. {
  41463. public:
  41464. TextEditorViewport (TextEditor* const owner_)
  41465. : owner (owner_),
  41466. lastWordWrapWidth (0)
  41467. {
  41468. }
  41469. ~TextEditorViewport()
  41470. {
  41471. }
  41472. void visibleAreaChanged (int, int, int, int)
  41473. {
  41474. const float wordWrapWidth = owner->getWordWrapWidth();
  41475. if (wordWrapWidth != lastWordWrapWidth)
  41476. {
  41477. lastWordWrapWidth = wordWrapWidth;
  41478. owner->updateTextHolderSize();
  41479. }
  41480. }
  41481. private:
  41482. TextEditor* const owner;
  41483. float lastWordWrapWidth;
  41484. TextEditorViewport (const TextEditorViewport&);
  41485. TextEditorViewport& operator= (const TextEditorViewport&);
  41486. };
  41487. namespace TextEditorDefs
  41488. {
  41489. const int flashSpeedIntervalMs = 380;
  41490. const int textChangeMessageId = 0x10003001;
  41491. const int returnKeyMessageId = 0x10003002;
  41492. const int escapeKeyMessageId = 0x10003003;
  41493. const int focusLossMessageId = 0x10003004;
  41494. const int maxActionsPerTransaction = 100;
  41495. }
  41496. TextEditor::TextEditor (const String& name,
  41497. const juce_wchar passwordCharacter_)
  41498. : Component (name),
  41499. borderSize (1, 1, 1, 3),
  41500. readOnly (false),
  41501. multiline (false),
  41502. wordWrap (false),
  41503. returnKeyStartsNewLine (false),
  41504. caretVisible (true),
  41505. popupMenuEnabled (true),
  41506. selectAllTextWhenFocused (false),
  41507. scrollbarVisible (true),
  41508. wasFocused (false),
  41509. caretFlashState (true),
  41510. keepCursorOnScreen (true),
  41511. tabKeyUsed (false),
  41512. menuActive (false),
  41513. valueTextNeedsUpdating (false),
  41514. cursorX (0),
  41515. cursorY (0),
  41516. cursorHeight (0),
  41517. maxTextLength (0),
  41518. leftIndent (4),
  41519. topIndent (4),
  41520. lastTransactionTime (0),
  41521. currentFont (14.0f),
  41522. totalNumChars (0),
  41523. caretPosition (0),
  41524. passwordCharacter (passwordCharacter_),
  41525. dragType (notDragging)
  41526. {
  41527. setOpaque (true);
  41528. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41529. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41530. viewport->setWantsKeyboardFocus (false);
  41531. viewport->setScrollBarsShown (false, false);
  41532. setMouseCursor (MouseCursor::IBeamCursor);
  41533. setWantsKeyboardFocus (true);
  41534. }
  41535. TextEditor::~TextEditor()
  41536. {
  41537. textValue.referTo (Value());
  41538. clearInternal (0);
  41539. viewport = 0;
  41540. textHolder = 0;
  41541. }
  41542. void TextEditor::newTransaction()
  41543. {
  41544. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41545. undoManager.beginNewTransaction();
  41546. }
  41547. void TextEditor::doUndoRedo (const bool isRedo)
  41548. {
  41549. if (! isReadOnly())
  41550. {
  41551. if (isRedo ? undoManager.redo()
  41552. : undoManager.undo())
  41553. {
  41554. scrollToMakeSureCursorIsVisible();
  41555. repaint();
  41556. textChanged();
  41557. }
  41558. }
  41559. }
  41560. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41561. const bool shouldWordWrap)
  41562. {
  41563. multiline = shouldBeMultiLine;
  41564. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41565. setScrollbarsShown (scrollbarVisible);
  41566. viewport->setViewPosition (0, 0);
  41567. resized();
  41568. scrollToMakeSureCursorIsVisible();
  41569. }
  41570. bool TextEditor::isMultiLine() const
  41571. {
  41572. return multiline;
  41573. }
  41574. void TextEditor::setScrollbarsShown (bool enabled)
  41575. {
  41576. scrollbarVisible = enabled;
  41577. enabled = enabled && isMultiLine();
  41578. viewport->setScrollBarsShown (enabled, enabled);
  41579. }
  41580. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41581. {
  41582. readOnly = shouldBeReadOnly;
  41583. enablementChanged();
  41584. }
  41585. bool TextEditor::isReadOnly() const
  41586. {
  41587. return readOnly || ! isEnabled();
  41588. }
  41589. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41590. {
  41591. returnKeyStartsNewLine = shouldStartNewLine;
  41592. }
  41593. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41594. {
  41595. tabKeyUsed = shouldTabKeyBeUsed;
  41596. }
  41597. void TextEditor::setPopupMenuEnabled (const bool b)
  41598. {
  41599. popupMenuEnabled = b;
  41600. }
  41601. void TextEditor::setSelectAllWhenFocused (const bool b)
  41602. {
  41603. selectAllTextWhenFocused = b;
  41604. }
  41605. const Font TextEditor::getFont() const
  41606. {
  41607. return currentFont;
  41608. }
  41609. void TextEditor::setFont (const Font& newFont)
  41610. {
  41611. currentFont = newFont;
  41612. scrollToMakeSureCursorIsVisible();
  41613. }
  41614. void TextEditor::applyFontToAllText (const Font& newFont)
  41615. {
  41616. currentFont = newFont;
  41617. const Colour overallColour (findColour (textColourId));
  41618. for (int i = sections.size(); --i >= 0;)
  41619. {
  41620. UniformTextSection* const uts = sections.getUnchecked (i);
  41621. uts->setFont (newFont, passwordCharacter);
  41622. uts->colour = overallColour;
  41623. }
  41624. coalesceSimilarSections();
  41625. updateTextHolderSize();
  41626. scrollToMakeSureCursorIsVisible();
  41627. repaint();
  41628. }
  41629. void TextEditor::colourChanged()
  41630. {
  41631. setOpaque (findColour (backgroundColourId).isOpaque());
  41632. repaint();
  41633. }
  41634. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41635. {
  41636. caretVisible = shouldCaretBeVisible;
  41637. if (shouldCaretBeVisible)
  41638. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41639. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41640. : MouseCursor::NormalCursor);
  41641. }
  41642. void TextEditor::setInputRestrictions (const int maxLen,
  41643. const String& chars)
  41644. {
  41645. maxTextLength = jmax (0, maxLen);
  41646. allowedCharacters = chars;
  41647. }
  41648. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41649. {
  41650. textToShowWhenEmpty = text;
  41651. colourForTextWhenEmpty = colourToUse;
  41652. }
  41653. void TextEditor::setPasswordCharacter (const juce_wchar newPasswordCharacter)
  41654. {
  41655. if (passwordCharacter != newPasswordCharacter)
  41656. {
  41657. passwordCharacter = newPasswordCharacter;
  41658. resized();
  41659. repaint();
  41660. }
  41661. }
  41662. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41663. {
  41664. viewport->setScrollBarThickness (newThicknessPixels);
  41665. }
  41666. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41667. {
  41668. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41669. }
  41670. void TextEditor::clear()
  41671. {
  41672. clearInternal (0);
  41673. updateTextHolderSize();
  41674. undoManager.clearUndoHistory();
  41675. }
  41676. void TextEditor::setText (const String& newText,
  41677. const bool sendTextChangeMessage)
  41678. {
  41679. const int newLength = newText.length();
  41680. if (newLength != getTotalNumChars() || getText() != newText)
  41681. {
  41682. const int oldCursorPos = caretPosition;
  41683. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41684. clearInternal (0);
  41685. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41686. // if you're adding text with line-feeds to a single-line text editor, it
  41687. // ain't gonna look right!
  41688. jassert (multiline || ! newText.containsAnyOf ("\r\n"));
  41689. if (cursorWasAtEnd && ! isMultiLine())
  41690. moveCursorTo (getTotalNumChars(), false);
  41691. else
  41692. moveCursorTo (oldCursorPos, false);
  41693. if (sendTextChangeMessage)
  41694. textChanged();
  41695. repaint();
  41696. }
  41697. updateTextHolderSize();
  41698. scrollToMakeSureCursorIsVisible();
  41699. undoManager.clearUndoHistory();
  41700. }
  41701. Value& TextEditor::getTextValue()
  41702. {
  41703. if (valueTextNeedsUpdating)
  41704. {
  41705. valueTextNeedsUpdating = false;
  41706. textValue = getText();
  41707. }
  41708. return textValue;
  41709. }
  41710. void TextEditor::textWasChangedByValue()
  41711. {
  41712. if (textValue.getValueSource().getReferenceCount() > 1)
  41713. setText (textValue.getValue());
  41714. }
  41715. void TextEditor::textChanged()
  41716. {
  41717. updateTextHolderSize();
  41718. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41719. if (textValue.getValueSource().getReferenceCount() > 1)
  41720. {
  41721. valueTextNeedsUpdating = false;
  41722. textValue = getText();
  41723. }
  41724. }
  41725. void TextEditor::returnPressed()
  41726. {
  41727. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41728. }
  41729. void TextEditor::escapePressed()
  41730. {
  41731. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41732. }
  41733. void TextEditor::addListener (TextEditorListener* const newListener)
  41734. {
  41735. listeners.add (newListener);
  41736. }
  41737. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41738. {
  41739. listeners.remove (listenerToRemove);
  41740. }
  41741. void TextEditor::timerCallbackInt()
  41742. {
  41743. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41744. if (caretFlashState != newState)
  41745. {
  41746. caretFlashState = newState;
  41747. if (caretFlashState)
  41748. wasFocused = true;
  41749. if (caretVisible
  41750. && hasKeyboardFocus (false)
  41751. && ! isReadOnly())
  41752. {
  41753. repaintCaret();
  41754. }
  41755. }
  41756. const unsigned int now = Time::getApproximateMillisecondCounter();
  41757. if (now > lastTransactionTime + 200)
  41758. newTransaction();
  41759. }
  41760. void TextEditor::repaintCaret()
  41761. {
  41762. if (! findColour (caretColourId).isTransparent())
  41763. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  41764. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  41765. 4,
  41766. roundToInt (cursorHeight) + 2);
  41767. }
  41768. void TextEditor::repaintText (const Range<int>& range)
  41769. {
  41770. if (! range.isEmpty())
  41771. {
  41772. float x = 0, y = 0, lh = currentFont.getHeight();
  41773. const float wordWrapWidth = getWordWrapWidth();
  41774. if (wordWrapWidth > 0)
  41775. {
  41776. Iterator i (sections, wordWrapWidth, passwordCharacter);
  41777. i.getCharPosition (range.getStart(), x, y, lh);
  41778. const int y1 = (int) y;
  41779. int y2;
  41780. if (range.getEnd() >= getTotalNumChars())
  41781. {
  41782. y2 = textHolder->getHeight();
  41783. }
  41784. else
  41785. {
  41786. i.getCharPosition (range.getEnd(), x, y, lh);
  41787. y2 = (int) (y + lh * 2.0f);
  41788. }
  41789. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  41790. }
  41791. }
  41792. }
  41793. void TextEditor::moveCaret (int newCaretPos)
  41794. {
  41795. if (newCaretPos < 0)
  41796. newCaretPos = 0;
  41797. else if (newCaretPos > getTotalNumChars())
  41798. newCaretPos = getTotalNumChars();
  41799. if (newCaretPos != getCaretPosition())
  41800. {
  41801. repaintCaret();
  41802. caretFlashState = true;
  41803. caretPosition = newCaretPos;
  41804. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41805. scrollToMakeSureCursorIsVisible();
  41806. repaintCaret();
  41807. }
  41808. }
  41809. void TextEditor::setCaretPosition (const int newIndex)
  41810. {
  41811. moveCursorTo (newIndex, false);
  41812. }
  41813. int TextEditor::getCaretPosition() const
  41814. {
  41815. return caretPosition;
  41816. }
  41817. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  41818. const int desiredCaretY)
  41819. {
  41820. updateCaretPosition();
  41821. int vx = roundToInt (cursorX) - desiredCaretX;
  41822. int vy = roundToInt (cursorY) - desiredCaretY;
  41823. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  41824. {
  41825. vx += desiredCaretX - proportionOfWidth (0.2f);
  41826. }
  41827. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41828. {
  41829. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41830. }
  41831. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  41832. if (! isMultiLine())
  41833. {
  41834. vy = viewport->getViewPositionY();
  41835. }
  41836. else
  41837. {
  41838. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  41839. const int curH = roundToInt (cursorHeight);
  41840. if (desiredCaretY < 0)
  41841. {
  41842. vy = jmax (0, desiredCaretY + vy);
  41843. }
  41844. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  41845. {
  41846. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  41847. }
  41848. }
  41849. viewport->setViewPosition (vx, vy);
  41850. }
  41851. const Rectangle<int> TextEditor::getCaretRectangle()
  41852. {
  41853. updateCaretPosition();
  41854. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  41855. roundToInt (cursorY) - viewport->getY(),
  41856. 1, roundToInt (cursorHeight));
  41857. }
  41858. float TextEditor::getWordWrapWidth() const
  41859. {
  41860. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  41861. : 1.0e10f;
  41862. }
  41863. void TextEditor::updateTextHolderSize()
  41864. {
  41865. const float wordWrapWidth = getWordWrapWidth();
  41866. if (wordWrapWidth > 0)
  41867. {
  41868. float maxWidth = 0.0f;
  41869. Iterator i (sections, wordWrapWidth, passwordCharacter);
  41870. while (i.next())
  41871. maxWidth = jmax (maxWidth, i.atomRight);
  41872. const int w = leftIndent + roundToInt (maxWidth);
  41873. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  41874. currentFont.getHeight()));
  41875. textHolder->setSize (w + 1, h + 1);
  41876. }
  41877. }
  41878. int TextEditor::getTextWidth() const
  41879. {
  41880. return textHolder->getWidth();
  41881. }
  41882. int TextEditor::getTextHeight() const
  41883. {
  41884. return textHolder->getHeight();
  41885. }
  41886. void TextEditor::setIndents (const int newLeftIndent,
  41887. const int newTopIndent)
  41888. {
  41889. leftIndent = newLeftIndent;
  41890. topIndent = newTopIndent;
  41891. }
  41892. void TextEditor::setBorder (const BorderSize& border)
  41893. {
  41894. borderSize = border;
  41895. resized();
  41896. }
  41897. const BorderSize TextEditor::getBorder() const
  41898. {
  41899. return borderSize;
  41900. }
  41901. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  41902. {
  41903. keepCursorOnScreen = shouldScrollToShowCursor;
  41904. }
  41905. void TextEditor::updateCaretPosition()
  41906. {
  41907. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  41908. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  41909. }
  41910. void TextEditor::scrollToMakeSureCursorIsVisible()
  41911. {
  41912. updateCaretPosition();
  41913. if (keepCursorOnScreen)
  41914. {
  41915. int x = viewport->getViewPositionX();
  41916. int y = viewport->getViewPositionY();
  41917. const int relativeCursorX = roundToInt (cursorX) - x;
  41918. const int relativeCursorY = roundToInt (cursorY) - y;
  41919. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  41920. {
  41921. x += relativeCursorX - proportionOfWidth (0.2f);
  41922. }
  41923. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41924. {
  41925. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41926. }
  41927. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  41928. if (! isMultiLine())
  41929. {
  41930. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  41931. }
  41932. else
  41933. {
  41934. const int curH = roundToInt (cursorHeight);
  41935. if (relativeCursorY < 0)
  41936. {
  41937. y = jmax (0, relativeCursorY + y);
  41938. }
  41939. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  41940. {
  41941. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  41942. }
  41943. }
  41944. viewport->setViewPosition (x, y);
  41945. }
  41946. }
  41947. void TextEditor::moveCursorTo (const int newPosition,
  41948. const bool isSelecting)
  41949. {
  41950. if (isSelecting)
  41951. {
  41952. moveCaret (newPosition);
  41953. const Range<int> oldSelection (selection);
  41954. if (dragType == notDragging)
  41955. {
  41956. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  41957. dragType = draggingSelectionStart;
  41958. else
  41959. dragType = draggingSelectionEnd;
  41960. }
  41961. if (dragType == draggingSelectionStart)
  41962. {
  41963. if (getCaretPosition() >= selection.getEnd())
  41964. dragType = draggingSelectionEnd;
  41965. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  41966. }
  41967. else
  41968. {
  41969. if (getCaretPosition() < selection.getStart())
  41970. dragType = draggingSelectionStart;
  41971. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  41972. }
  41973. repaintText (selection.getUnionWith (oldSelection));
  41974. }
  41975. else
  41976. {
  41977. dragType = notDragging;
  41978. repaintText (selection);
  41979. moveCaret (newPosition);
  41980. selection = Range<int>::emptyRange (getCaretPosition());
  41981. }
  41982. }
  41983. int TextEditor::getTextIndexAt (const int x,
  41984. const int y)
  41985. {
  41986. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  41987. (float) (y + viewport->getViewPositionY() - topIndent));
  41988. }
  41989. void TextEditor::insertTextAtCaret (const String& newText_)
  41990. {
  41991. String newText (newText_);
  41992. if (allowedCharacters.isNotEmpty())
  41993. newText = newText.retainCharacters (allowedCharacters);
  41994. if ((! returnKeyStartsNewLine) && newText == "\n")
  41995. {
  41996. returnPressed();
  41997. return;
  41998. }
  41999. if (! isMultiLine())
  42000. newText = newText.replaceCharacters ("\r\n", " ");
  42001. else
  42002. newText = newText.replace ("\r\n", "\n");
  42003. const int newCaretPos = selection.getStart() + newText.length();
  42004. const int insertIndex = selection.getStart();
  42005. remove (selection, getUndoManager(),
  42006. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42007. if (maxTextLength > 0)
  42008. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42009. if (newText.isNotEmpty())
  42010. insert (newText,
  42011. insertIndex,
  42012. currentFont,
  42013. findColour (textColourId),
  42014. getUndoManager(),
  42015. newCaretPos);
  42016. textChanged();
  42017. }
  42018. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42019. {
  42020. moveCursorTo (newSelection.getStart(), false);
  42021. moveCursorTo (newSelection.getEnd(), true);
  42022. }
  42023. void TextEditor::copy()
  42024. {
  42025. if (passwordCharacter == 0)
  42026. {
  42027. const String selection (getHighlightedText());
  42028. if (selection.isNotEmpty())
  42029. SystemClipboard::copyTextToClipboard (selection);
  42030. }
  42031. }
  42032. void TextEditor::paste()
  42033. {
  42034. if (! isReadOnly())
  42035. {
  42036. const String clip (SystemClipboard::getTextFromClipboard());
  42037. if (clip.isNotEmpty())
  42038. insertTextAtCaret (clip);
  42039. }
  42040. }
  42041. void TextEditor::cut()
  42042. {
  42043. if (! isReadOnly())
  42044. {
  42045. moveCaret (selection.getEnd());
  42046. insertTextAtCaret (String::empty);
  42047. }
  42048. }
  42049. void TextEditor::drawContent (Graphics& g)
  42050. {
  42051. const float wordWrapWidth = getWordWrapWidth();
  42052. if (wordWrapWidth > 0)
  42053. {
  42054. g.setOrigin (leftIndent, topIndent);
  42055. const Rectangle<int> clip (g.getClipBounds());
  42056. Colour selectedTextColour;
  42057. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42058. while (i.lineY + 200.0 < clip.getY() && i.next())
  42059. {}
  42060. if (! selection.isEmpty())
  42061. {
  42062. g.setColour (findColour (highlightColourId)
  42063. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42064. selectedTextColour = findColour (highlightedTextColourId);
  42065. Iterator i2 (i);
  42066. while (i2.next() && i2.lineY < clip.getBottom())
  42067. {
  42068. if (i2.lineY + i2.lineHeight >= clip.getY()
  42069. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42070. {
  42071. i2.drawSelection (g, selection);
  42072. }
  42073. }
  42074. }
  42075. const UniformTextSection* lastSection = 0;
  42076. while (i.next() && i.lineY < clip.getBottom())
  42077. {
  42078. if (i.lineY + i.lineHeight >= clip.getY())
  42079. {
  42080. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42081. {
  42082. i.drawSelectedText (g, selection, selectedTextColour);
  42083. lastSection = 0;
  42084. }
  42085. else
  42086. {
  42087. i.draw (g, lastSection);
  42088. }
  42089. }
  42090. }
  42091. }
  42092. }
  42093. void TextEditor::paint (Graphics& g)
  42094. {
  42095. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42096. }
  42097. void TextEditor::paintOverChildren (Graphics& g)
  42098. {
  42099. if (caretFlashState
  42100. && hasKeyboardFocus (false)
  42101. && caretVisible
  42102. && ! isReadOnly())
  42103. {
  42104. g.setColour (findColour (caretColourId));
  42105. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42106. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42107. 2.0f, cursorHeight);
  42108. }
  42109. if (textToShowWhenEmpty.isNotEmpty()
  42110. && (! hasKeyboardFocus (false))
  42111. && getTotalNumChars() == 0)
  42112. {
  42113. g.setColour (colourForTextWhenEmpty);
  42114. g.setFont (getFont());
  42115. if (isMultiLine())
  42116. {
  42117. g.drawText (textToShowWhenEmpty,
  42118. 0, 0, getWidth(), getHeight(),
  42119. Justification::centred, true);
  42120. }
  42121. else
  42122. {
  42123. g.drawText (textToShowWhenEmpty,
  42124. leftIndent, topIndent,
  42125. viewport->getWidth() - leftIndent,
  42126. viewport->getHeight() - topIndent,
  42127. Justification::centredLeft, true);
  42128. }
  42129. }
  42130. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42131. }
  42132. void TextEditor::mouseDown (const MouseEvent& e)
  42133. {
  42134. beginDragAutoRepeat (100);
  42135. newTransaction();
  42136. if (wasFocused || ! selectAllTextWhenFocused)
  42137. {
  42138. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42139. {
  42140. moveCursorTo (getTextIndexAt (e.x, e.y),
  42141. e.mods.isShiftDown());
  42142. }
  42143. else
  42144. {
  42145. PopupMenu m;
  42146. m.setLookAndFeel (&getLookAndFeel());
  42147. addPopupMenuItems (m, &e);
  42148. menuActive = true;
  42149. const int result = m.show();
  42150. menuActive = false;
  42151. if (result != 0)
  42152. performPopupMenuAction (result);
  42153. }
  42154. }
  42155. }
  42156. void TextEditor::mouseDrag (const MouseEvent& e)
  42157. {
  42158. if (wasFocused || ! selectAllTextWhenFocused)
  42159. {
  42160. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42161. {
  42162. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42163. }
  42164. }
  42165. }
  42166. void TextEditor::mouseUp (const MouseEvent& e)
  42167. {
  42168. newTransaction();
  42169. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42170. if (wasFocused || ! selectAllTextWhenFocused)
  42171. {
  42172. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42173. {
  42174. moveCaret (getTextIndexAt (e.x, e.y));
  42175. }
  42176. }
  42177. wasFocused = true;
  42178. }
  42179. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42180. {
  42181. int tokenEnd = getTextIndexAt (e.x, e.y);
  42182. int tokenStart = tokenEnd;
  42183. if (e.getNumberOfClicks() > 3)
  42184. {
  42185. tokenStart = 0;
  42186. tokenEnd = getTotalNumChars();
  42187. }
  42188. else
  42189. {
  42190. const String t (getText());
  42191. const int totalLength = getTotalNumChars();
  42192. while (tokenEnd < totalLength)
  42193. {
  42194. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42195. ++tokenEnd;
  42196. else
  42197. break;
  42198. }
  42199. tokenStart = tokenEnd;
  42200. while (tokenStart > 0)
  42201. {
  42202. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42203. --tokenStart;
  42204. else
  42205. break;
  42206. }
  42207. if (e.getNumberOfClicks() > 2)
  42208. {
  42209. while (tokenEnd < totalLength)
  42210. {
  42211. if (t [tokenEnd] != '\r' && t [tokenEnd] != '\n')
  42212. ++tokenEnd;
  42213. else
  42214. break;
  42215. }
  42216. while (tokenStart > 0)
  42217. {
  42218. if (t [tokenStart - 1] != '\r' && t [tokenStart - 1] != '\n')
  42219. --tokenStart;
  42220. else
  42221. break;
  42222. }
  42223. }
  42224. }
  42225. moveCursorTo (tokenEnd, false);
  42226. moveCursorTo (tokenStart, true);
  42227. }
  42228. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42229. {
  42230. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42231. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42232. }
  42233. bool TextEditor::keyPressed (const KeyPress& key)
  42234. {
  42235. if (isReadOnly() && key != KeyPress ('c', ModifierKeys::commandModifier, 0))
  42236. return false;
  42237. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42238. if (key.isKeyCode (KeyPress::leftKey)
  42239. || key.isKeyCode (KeyPress::upKey))
  42240. {
  42241. newTransaction();
  42242. int newPos;
  42243. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42244. newPos = indexAtPosition (cursorX, cursorY - 1);
  42245. else if (moveInWholeWordSteps)
  42246. newPos = findWordBreakBefore (getCaretPosition());
  42247. else
  42248. newPos = getCaretPosition() - 1;
  42249. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42250. }
  42251. else if (key.isKeyCode (KeyPress::rightKey)
  42252. || key.isKeyCode (KeyPress::downKey))
  42253. {
  42254. newTransaction();
  42255. int newPos;
  42256. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42257. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42258. else if (moveInWholeWordSteps)
  42259. newPos = findWordBreakAfter (getCaretPosition());
  42260. else
  42261. newPos = getCaretPosition() + 1;
  42262. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42263. }
  42264. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42265. {
  42266. newTransaction();
  42267. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42268. key.getModifiers().isShiftDown());
  42269. }
  42270. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42271. {
  42272. newTransaction();
  42273. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42274. key.getModifiers().isShiftDown());
  42275. }
  42276. else if (key.isKeyCode (KeyPress::homeKey))
  42277. {
  42278. newTransaction();
  42279. if (isMultiLine() && ! moveInWholeWordSteps)
  42280. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42281. key.getModifiers().isShiftDown());
  42282. else
  42283. moveCursorTo (0, key.getModifiers().isShiftDown());
  42284. }
  42285. else if (key.isKeyCode (KeyPress::endKey))
  42286. {
  42287. newTransaction();
  42288. if (isMultiLine() && ! moveInWholeWordSteps)
  42289. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42290. key.getModifiers().isShiftDown());
  42291. else
  42292. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42293. }
  42294. else if (key.isKeyCode (KeyPress::backspaceKey))
  42295. {
  42296. if (moveInWholeWordSteps)
  42297. {
  42298. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42299. }
  42300. else
  42301. {
  42302. if (selection.isEmpty() && selection.getStart() > 0)
  42303. selection.setStart (selection.getEnd() - 1);
  42304. }
  42305. cut();
  42306. }
  42307. else if (key.isKeyCode (KeyPress::deleteKey))
  42308. {
  42309. if (key.getModifiers().isShiftDown())
  42310. copy();
  42311. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42312. selection.setEnd (selection.getStart() + 1);
  42313. cut();
  42314. }
  42315. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0)
  42316. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42317. {
  42318. newTransaction();
  42319. copy();
  42320. }
  42321. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  42322. {
  42323. newTransaction();
  42324. copy();
  42325. cut();
  42326. }
  42327. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0)
  42328. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42329. {
  42330. newTransaction();
  42331. paste();
  42332. }
  42333. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  42334. {
  42335. newTransaction();
  42336. doUndoRedo (false);
  42337. }
  42338. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0))
  42339. {
  42340. newTransaction();
  42341. doUndoRedo (true);
  42342. }
  42343. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  42344. {
  42345. newTransaction();
  42346. moveCursorTo (getTotalNumChars(), false);
  42347. moveCursorTo (0, true);
  42348. }
  42349. else if (key == KeyPress::returnKey)
  42350. {
  42351. newTransaction();
  42352. insertTextAtCaret ("\n");
  42353. }
  42354. else if (key.isKeyCode (KeyPress::escapeKey))
  42355. {
  42356. newTransaction();
  42357. moveCursorTo (getCaretPosition(), false);
  42358. escapePressed();
  42359. }
  42360. else if (key.getTextCharacter() >= ' '
  42361. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42362. {
  42363. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42364. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42365. }
  42366. else
  42367. {
  42368. return false;
  42369. }
  42370. return true;
  42371. }
  42372. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42373. {
  42374. if (! isKeyDown)
  42375. return false;
  42376. #if JUCE_WIN32
  42377. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42378. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42379. #endif
  42380. // (overridden to avoid forwarding key events to the parent)
  42381. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42382. }
  42383. const int baseMenuItemID = 0x7fff0000;
  42384. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42385. {
  42386. const bool writable = ! isReadOnly();
  42387. if (passwordCharacter == 0)
  42388. {
  42389. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42390. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42391. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42392. }
  42393. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42394. m.addSeparator();
  42395. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42396. m.addSeparator();
  42397. if (getUndoManager() != 0)
  42398. {
  42399. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42400. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42401. }
  42402. }
  42403. void TextEditor::performPopupMenuAction (const int menuItemID)
  42404. {
  42405. switch (menuItemID)
  42406. {
  42407. case baseMenuItemID + 1:
  42408. copy();
  42409. cut();
  42410. break;
  42411. case baseMenuItemID + 2:
  42412. copy();
  42413. break;
  42414. case baseMenuItemID + 3:
  42415. paste();
  42416. break;
  42417. case baseMenuItemID + 4:
  42418. cut();
  42419. break;
  42420. case baseMenuItemID + 5:
  42421. moveCursorTo (getTotalNumChars(), false);
  42422. moveCursorTo (0, true);
  42423. break;
  42424. case baseMenuItemID + 6:
  42425. doUndoRedo (false);
  42426. break;
  42427. case baseMenuItemID + 7:
  42428. doUndoRedo (true);
  42429. break;
  42430. default:
  42431. break;
  42432. }
  42433. }
  42434. void TextEditor::focusGained (FocusChangeType)
  42435. {
  42436. newTransaction();
  42437. caretFlashState = true;
  42438. if (selectAllTextWhenFocused)
  42439. {
  42440. moveCursorTo (0, false);
  42441. moveCursorTo (getTotalNumChars(), true);
  42442. }
  42443. repaint();
  42444. if (caretVisible)
  42445. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42446. ComponentPeer* const peer = getPeer();
  42447. if (peer != 0 && ! isReadOnly())
  42448. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42449. }
  42450. void TextEditor::focusLost (FocusChangeType)
  42451. {
  42452. newTransaction();
  42453. wasFocused = false;
  42454. textHolder->stopTimer();
  42455. caretFlashState = false;
  42456. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42457. repaint();
  42458. }
  42459. void TextEditor::resized()
  42460. {
  42461. viewport->setBoundsInset (borderSize);
  42462. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42463. updateTextHolderSize();
  42464. if (! isMultiLine())
  42465. {
  42466. scrollToMakeSureCursorIsVisible();
  42467. }
  42468. else
  42469. {
  42470. updateCaretPosition();
  42471. }
  42472. }
  42473. void TextEditor::handleCommandMessage (const int commandId)
  42474. {
  42475. Component::BailOutChecker checker (this);
  42476. switch (commandId)
  42477. {
  42478. case TextEditorDefs::textChangeMessageId:
  42479. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42480. break;
  42481. case TextEditorDefs::returnKeyMessageId:
  42482. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42483. break;
  42484. case TextEditorDefs::escapeKeyMessageId:
  42485. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42486. break;
  42487. case TextEditorDefs::focusLossMessageId:
  42488. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42489. break;
  42490. default:
  42491. jassertfalse
  42492. break;
  42493. }
  42494. }
  42495. void TextEditor::enablementChanged()
  42496. {
  42497. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42498. : MouseCursor::IBeamCursor);
  42499. repaint();
  42500. }
  42501. UndoManager* TextEditor::getUndoManager() throw()
  42502. {
  42503. return isReadOnly() ? &undoManager : 0;
  42504. }
  42505. void TextEditor::clearInternal (UndoManager* const um)
  42506. {
  42507. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42508. }
  42509. void TextEditor::insert (const String& text,
  42510. const int insertIndex,
  42511. const Font& font,
  42512. const Colour& colour,
  42513. UndoManager* const um,
  42514. const int caretPositionToMoveTo)
  42515. {
  42516. if (text.isNotEmpty())
  42517. {
  42518. if (um != 0)
  42519. {
  42520. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42521. newTransaction();
  42522. um->perform (new InsertAction (*this, text, insertIndex, font, colour,
  42523. caretPosition, caretPositionToMoveTo));
  42524. }
  42525. else
  42526. {
  42527. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42528. // a line gets moved due to word wrap
  42529. int index = 0;
  42530. int nextIndex = 0;
  42531. for (int i = 0; i < sections.size(); ++i)
  42532. {
  42533. nextIndex = index + sections.getUnchecked (i)->getTotalLength();
  42534. if (insertIndex == index)
  42535. {
  42536. sections.insert (i, new UniformTextSection (text,
  42537. font, colour,
  42538. passwordCharacter));
  42539. break;
  42540. }
  42541. else if (insertIndex > index && insertIndex < nextIndex)
  42542. {
  42543. splitSection (i, insertIndex - index);
  42544. sections.insert (i + 1, new UniformTextSection (text,
  42545. font, colour,
  42546. passwordCharacter));
  42547. break;
  42548. }
  42549. index = nextIndex;
  42550. }
  42551. if (nextIndex == insertIndex)
  42552. sections.add (new UniformTextSection (text,
  42553. font, colour,
  42554. passwordCharacter));
  42555. coalesceSimilarSections();
  42556. totalNumChars = -1;
  42557. valueTextNeedsUpdating = true;
  42558. moveCursorTo (caretPositionToMoveTo, false);
  42559. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42560. }
  42561. }
  42562. }
  42563. void TextEditor::reinsert (const int insertIndex,
  42564. const Array <UniformTextSection*>& sectionsToInsert)
  42565. {
  42566. int index = 0;
  42567. int nextIndex = 0;
  42568. for (int i = 0; i < sections.size(); ++i)
  42569. {
  42570. nextIndex = index + sections.getUnchecked (i)->getTotalLength();
  42571. if (insertIndex == index)
  42572. {
  42573. for (int j = sectionsToInsert.size(); --j >= 0;)
  42574. sections.insert (i, new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42575. break;
  42576. }
  42577. else if (insertIndex > index && insertIndex < nextIndex)
  42578. {
  42579. splitSection (i, insertIndex - index);
  42580. for (int j = sectionsToInsert.size(); --j >= 0;)
  42581. sections.insert (i + 1, new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42582. break;
  42583. }
  42584. index = nextIndex;
  42585. }
  42586. if (nextIndex == insertIndex)
  42587. {
  42588. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42589. sections.add (new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42590. }
  42591. coalesceSimilarSections();
  42592. totalNumChars = -1;
  42593. valueTextNeedsUpdating = true;
  42594. }
  42595. void TextEditor::remove (const Range<int>& range,
  42596. UndoManager* const um,
  42597. const int caretPositionToMoveTo)
  42598. {
  42599. if (! range.isEmpty())
  42600. {
  42601. int index = 0;
  42602. for (int i = 0; i < sections.size(); ++i)
  42603. {
  42604. const int nextIndex = index + sections.getUnchecked(i)->getTotalLength();
  42605. if (range.getStart() > index && range.getStart() < nextIndex)
  42606. {
  42607. splitSection (i, range.getStart() - index);
  42608. --i;
  42609. }
  42610. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42611. {
  42612. splitSection (i, range.getEnd() - index);
  42613. --i;
  42614. }
  42615. else
  42616. {
  42617. index = nextIndex;
  42618. if (index > range.getEnd())
  42619. break;
  42620. }
  42621. }
  42622. index = 0;
  42623. if (um != 0)
  42624. {
  42625. Array <UniformTextSection*> removedSections;
  42626. for (int i = 0; i < sections.size(); ++i)
  42627. {
  42628. if (range.getEnd() <= range.getStart())
  42629. break;
  42630. UniformTextSection* const section = sections.getUnchecked (i);
  42631. const int nextIndex = index + section->getTotalLength();
  42632. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42633. removedSections.add (new UniformTextSection (*section));
  42634. index = nextIndex;
  42635. }
  42636. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42637. newTransaction();
  42638. um->perform (new RemoveAction (*this, range, caretPosition,
  42639. caretPositionToMoveTo, removedSections));
  42640. }
  42641. else
  42642. {
  42643. Range<int> remainingRange (range);
  42644. for (int i = 0; i < sections.size(); ++i)
  42645. {
  42646. UniformTextSection* const section = sections.getUnchecked (i);
  42647. const int nextIndex = index + section->getTotalLength();
  42648. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42649. {
  42650. sections.remove(i);
  42651. section->clear();
  42652. delete section;
  42653. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42654. if (remainingRange.isEmpty())
  42655. break;
  42656. --i;
  42657. }
  42658. else
  42659. {
  42660. index = nextIndex;
  42661. }
  42662. }
  42663. coalesceSimilarSections();
  42664. totalNumChars = -1;
  42665. valueTextNeedsUpdating = true;
  42666. moveCursorTo (caretPositionToMoveTo, false);
  42667. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42668. }
  42669. }
  42670. }
  42671. const String TextEditor::getText() const
  42672. {
  42673. String t;
  42674. t.preallocateStorage (getTotalNumChars());
  42675. String::Concatenator concatenator (t);
  42676. for (int i = 0; i < sections.size(); ++i)
  42677. sections.getUnchecked (i)->appendAllText (concatenator);
  42678. return t;
  42679. }
  42680. const String TextEditor::getTextInRange (const Range<int>& range) const
  42681. {
  42682. String t;
  42683. if (! range.isEmpty())
  42684. {
  42685. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42686. String::Concatenator concatenator (t);
  42687. int index = 0;
  42688. for (int i = 0; i < sections.size(); ++i)
  42689. {
  42690. const UniformTextSection* const s = sections.getUnchecked (i);
  42691. const int nextIndex = index + s->getTotalLength();
  42692. if (range.getStart() < nextIndex)
  42693. {
  42694. if (range.getEnd() <= index)
  42695. break;
  42696. s->appendSubstring (concatenator, range - index);
  42697. }
  42698. index = nextIndex;
  42699. }
  42700. }
  42701. return t;
  42702. }
  42703. const String TextEditor::getHighlightedText() const
  42704. {
  42705. return getTextInRange (selection);
  42706. }
  42707. int TextEditor::getTotalNumChars() const
  42708. {
  42709. if (totalNumChars < 0)
  42710. {
  42711. totalNumChars = 0;
  42712. for (int i = sections.size(); --i >= 0;)
  42713. totalNumChars += sections.getUnchecked (i)->getTotalLength();
  42714. }
  42715. return totalNumChars;
  42716. }
  42717. bool TextEditor::isEmpty() const
  42718. {
  42719. return getTotalNumChars() == 0;
  42720. }
  42721. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42722. {
  42723. const float wordWrapWidth = getWordWrapWidth();
  42724. if (wordWrapWidth > 0 && sections.size() > 0)
  42725. {
  42726. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42727. i.getCharPosition (index, cx, cy, lineHeight);
  42728. }
  42729. else
  42730. {
  42731. cx = cy = 0;
  42732. lineHeight = currentFont.getHeight();
  42733. }
  42734. }
  42735. int TextEditor::indexAtPosition (const float x, const float y)
  42736. {
  42737. const float wordWrapWidth = getWordWrapWidth();
  42738. if (wordWrapWidth > 0)
  42739. {
  42740. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42741. while (i.next())
  42742. {
  42743. if (i.lineY + i.lineHeight > y)
  42744. {
  42745. if (i.lineY > y)
  42746. return jmax (0, i.indexInText - 1);
  42747. if (i.atomX >= x)
  42748. return i.indexInText;
  42749. if (x < i.atomRight)
  42750. return i.xToIndex (x);
  42751. }
  42752. }
  42753. }
  42754. return getTotalNumChars();
  42755. }
  42756. static int getCharacterCategory (const juce_wchar character)
  42757. {
  42758. return CharacterFunctions::isLetterOrDigit (character)
  42759. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  42760. }
  42761. int TextEditor::findWordBreakAfter (const int position) const
  42762. {
  42763. const String t (getTextInRange (Range<int> (position, position + 512)));
  42764. const int totalLength = t.length();
  42765. int i = 0;
  42766. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42767. ++i;
  42768. const int type = getCharacterCategory (t[i]);
  42769. while (i < totalLength && type == getCharacterCategory (t[i]))
  42770. ++i;
  42771. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42772. ++i;
  42773. return position + i;
  42774. }
  42775. int TextEditor::findWordBreakBefore (const int position) const
  42776. {
  42777. if (position <= 0)
  42778. return 0;
  42779. const int startOfBuffer = jmax (0, position - 512);
  42780. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  42781. int i = position - startOfBuffer;
  42782. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  42783. --i;
  42784. if (i > 0)
  42785. {
  42786. const int type = getCharacterCategory (t [i - 1]);
  42787. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  42788. --i;
  42789. }
  42790. jassert (startOfBuffer + i >= 0);
  42791. return startOfBuffer + i;
  42792. }
  42793. void TextEditor::splitSection (const int sectionIndex,
  42794. const int charToSplitAt)
  42795. {
  42796. jassert (sections[sectionIndex] != 0);
  42797. sections.insert (sectionIndex + 1,
  42798. sections.getUnchecked (sectionIndex)->split (charToSplitAt, passwordCharacter));
  42799. }
  42800. void TextEditor::coalesceSimilarSections()
  42801. {
  42802. for (int i = 0; i < sections.size() - 1; ++i)
  42803. {
  42804. UniformTextSection* const s1 = sections.getUnchecked (i);
  42805. UniformTextSection* const s2 = sections.getUnchecked (i + 1);
  42806. if (s1->font == s2->font
  42807. && s1->colour == s2->colour)
  42808. {
  42809. s1->append (*s2, passwordCharacter);
  42810. sections.remove (i + 1);
  42811. delete s2;
  42812. --i;
  42813. }
  42814. }
  42815. }
  42816. END_JUCE_NAMESPACE
  42817. /*** End of inlined file: juce_TextEditor.cpp ***/
  42818. /*** Start of inlined file: juce_Toolbar.cpp ***/
  42819. BEGIN_JUCE_NAMESPACE
  42820. const char* const Toolbar::toolbarDragDescriptor = "_toolbarItem_";
  42821. class ToolbarSpacerComp : public ToolbarItemComponent
  42822. {
  42823. public:
  42824. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  42825. : ToolbarItemComponent (itemId_, String::empty, false),
  42826. fixedSize (fixedSize_),
  42827. drawBar (drawBar_)
  42828. {
  42829. }
  42830. ~ToolbarSpacerComp()
  42831. {
  42832. }
  42833. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  42834. int& preferredSize, int& minSize, int& maxSize)
  42835. {
  42836. if (fixedSize <= 0)
  42837. {
  42838. preferredSize = toolbarThickness * 2;
  42839. minSize = 4;
  42840. maxSize = 32768;
  42841. }
  42842. else
  42843. {
  42844. maxSize = roundToInt (toolbarThickness * fixedSize);
  42845. minSize = drawBar ? maxSize : jmin (4, maxSize);
  42846. preferredSize = maxSize;
  42847. if (getEditingMode() == editableOnPalette)
  42848. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  42849. }
  42850. return true;
  42851. }
  42852. void paintButtonArea (Graphics&, int, int, bool, bool)
  42853. {
  42854. }
  42855. void contentAreaChanged (const Rectangle<int>&)
  42856. {
  42857. }
  42858. int getResizeOrder() const throw()
  42859. {
  42860. return fixedSize <= 0 ? 0 : 1;
  42861. }
  42862. void paint (Graphics& g)
  42863. {
  42864. const int w = getWidth();
  42865. const int h = getHeight();
  42866. if (drawBar)
  42867. {
  42868. g.setColour (findColour (Toolbar::separatorColourId, true));
  42869. const float thickness = 0.2f;
  42870. if (isToolbarVertical())
  42871. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  42872. else
  42873. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  42874. }
  42875. if (getEditingMode() != normalMode && ! drawBar)
  42876. {
  42877. g.setColour (findColour (Toolbar::separatorColourId, true));
  42878. const int indentX = jmin (2, (w - 3) / 2);
  42879. const int indentY = jmin (2, (h - 3) / 2);
  42880. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  42881. if (fixedSize <= 0)
  42882. {
  42883. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  42884. if (isToolbarVertical())
  42885. {
  42886. x1 = w * 0.5f;
  42887. y1 = h * 0.4f;
  42888. x2 = x1;
  42889. y2 = indentX * 2.0f;
  42890. x3 = x1;
  42891. y3 = h * 0.6f;
  42892. x4 = x1;
  42893. y4 = h - y2;
  42894. hw = w * 0.15f;
  42895. hl = w * 0.2f;
  42896. }
  42897. else
  42898. {
  42899. x1 = w * 0.4f;
  42900. y1 = h * 0.5f;
  42901. x2 = indentX * 2.0f;
  42902. y2 = y1;
  42903. x3 = w * 0.6f;
  42904. y3 = y1;
  42905. x4 = w - x2;
  42906. y4 = y1;
  42907. hw = h * 0.15f;
  42908. hl = h * 0.2f;
  42909. }
  42910. Path p;
  42911. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  42912. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  42913. g.fillPath (p);
  42914. }
  42915. }
  42916. }
  42917. juce_UseDebuggingNewOperator
  42918. private:
  42919. const float fixedSize;
  42920. const bool drawBar;
  42921. ToolbarSpacerComp (const ToolbarSpacerComp&);
  42922. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  42923. };
  42924. class MissingItemsComponent : public PopupMenuCustomComponent
  42925. {
  42926. public:
  42927. MissingItemsComponent (Toolbar& owner_, const int height_)
  42928. : PopupMenuCustomComponent (true),
  42929. owner (owner_),
  42930. height (height_)
  42931. {
  42932. for (int i = owner_.items.size(); --i >= 0;)
  42933. {
  42934. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  42935. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  42936. {
  42937. oldIndexes.insert (0, i);
  42938. addAndMakeVisible (tc, 0);
  42939. }
  42940. }
  42941. layout (400);
  42942. }
  42943. ~MissingItemsComponent()
  42944. {
  42945. // deleting the toolbar while its menu it open??
  42946. jassert (owner.isValidComponent());
  42947. for (int i = 0; i < getNumChildComponents(); ++i)
  42948. {
  42949. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  42950. if (tc != 0)
  42951. {
  42952. tc->setVisible (false);
  42953. const int index = oldIndexes.remove (i);
  42954. owner.addChildComponent (tc, index);
  42955. --i;
  42956. }
  42957. }
  42958. owner.resized();
  42959. }
  42960. void layout (const int preferredWidth)
  42961. {
  42962. const int indent = 8;
  42963. int x = indent;
  42964. int y = indent;
  42965. int maxX = 0;
  42966. for (int i = 0; i < getNumChildComponents(); ++i)
  42967. {
  42968. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  42969. if (tc != 0)
  42970. {
  42971. int preferredSize = 1, minSize = 1, maxSize = 1;
  42972. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  42973. {
  42974. if (x + preferredSize > preferredWidth && x > indent)
  42975. {
  42976. x = indent;
  42977. y += height;
  42978. }
  42979. tc->setBounds (x, y, preferredSize, height);
  42980. x += preferredSize;
  42981. maxX = jmax (maxX, x);
  42982. }
  42983. }
  42984. }
  42985. setSize (maxX + 8, y + height + 8);
  42986. }
  42987. void getIdealSize (int& idealWidth, int& idealHeight)
  42988. {
  42989. idealWidth = getWidth();
  42990. idealHeight = getHeight();
  42991. }
  42992. juce_UseDebuggingNewOperator
  42993. private:
  42994. Toolbar& owner;
  42995. const int height;
  42996. Array <int> oldIndexes;
  42997. MissingItemsComponent (const MissingItemsComponent&);
  42998. MissingItemsComponent& operator= (const MissingItemsComponent&);
  42999. };
  43000. Toolbar::Toolbar()
  43001. : vertical (false),
  43002. isEditingActive (false),
  43003. toolbarStyle (Toolbar::iconsOnly)
  43004. {
  43005. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43006. missingItemsButton->setAlwaysOnTop (true);
  43007. missingItemsButton->addButtonListener (this);
  43008. }
  43009. Toolbar::~Toolbar()
  43010. {
  43011. animator.cancelAllAnimations (true);
  43012. deleteAllChildren();
  43013. }
  43014. void Toolbar::setVertical (const bool shouldBeVertical)
  43015. {
  43016. if (vertical != shouldBeVertical)
  43017. {
  43018. vertical = shouldBeVertical;
  43019. resized();
  43020. }
  43021. }
  43022. void Toolbar::clear()
  43023. {
  43024. for (int i = items.size(); --i >= 0;)
  43025. {
  43026. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43027. items.remove (i);
  43028. delete tc;
  43029. }
  43030. resized();
  43031. }
  43032. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43033. {
  43034. if (itemId == ToolbarItemFactory::separatorBarId)
  43035. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43036. else if (itemId == ToolbarItemFactory::spacerId)
  43037. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43038. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43039. return new ToolbarSpacerComp (itemId, 0, false);
  43040. return factory.createItem (itemId);
  43041. }
  43042. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43043. const int itemId,
  43044. const int insertIndex)
  43045. {
  43046. // An ID can't be zero - this might indicate a mistake somewhere?
  43047. jassert (itemId != 0);
  43048. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43049. if (tc != 0)
  43050. {
  43051. #ifdef JUCE_DEBUG
  43052. Array <int> allowedIds;
  43053. factory.getAllToolbarItemIds (allowedIds);
  43054. // If your factory can create an item for a given ID, it must also return
  43055. // that ID from its getAllToolbarItemIds() method!
  43056. jassert (allowedIds.contains (itemId));
  43057. #endif
  43058. items.insert (insertIndex, tc);
  43059. addAndMakeVisible (tc, insertIndex);
  43060. }
  43061. }
  43062. void Toolbar::addItem (ToolbarItemFactory& factory,
  43063. const int itemId,
  43064. const int insertIndex)
  43065. {
  43066. addItemInternal (factory, itemId, insertIndex);
  43067. resized();
  43068. }
  43069. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43070. {
  43071. Array <int> ids;
  43072. factoryToUse.getDefaultItemSet (ids);
  43073. clear();
  43074. for (int i = 0; i < ids.size(); ++i)
  43075. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43076. resized();
  43077. }
  43078. void Toolbar::removeToolbarItem (const int itemIndex)
  43079. {
  43080. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43081. if (tc != 0)
  43082. {
  43083. items.removeValue (tc);
  43084. delete tc;
  43085. resized();
  43086. }
  43087. }
  43088. int Toolbar::getNumItems() const throw()
  43089. {
  43090. return items.size();
  43091. }
  43092. int Toolbar::getItemId (const int itemIndex) const throw()
  43093. {
  43094. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43095. return tc != 0 ? tc->getItemId() : 0;
  43096. }
  43097. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43098. {
  43099. return items [itemIndex];
  43100. }
  43101. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43102. {
  43103. for (;;)
  43104. {
  43105. index += delta;
  43106. ToolbarItemComponent* const tc = getItemComponent (index);
  43107. if (tc == 0)
  43108. break;
  43109. if (tc->isActive)
  43110. return tc;
  43111. }
  43112. return 0;
  43113. }
  43114. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43115. {
  43116. if (toolbarStyle != newStyle)
  43117. {
  43118. toolbarStyle = newStyle;
  43119. updateAllItemPositions (false);
  43120. }
  43121. }
  43122. const String Toolbar::toString() const
  43123. {
  43124. String s ("TB:");
  43125. for (int i = 0; i < getNumItems(); ++i)
  43126. s << getItemId(i) << ' ';
  43127. return s.trimEnd();
  43128. }
  43129. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43130. const String& savedVersion)
  43131. {
  43132. if (! savedVersion.startsWith ("TB:"))
  43133. return false;
  43134. StringArray tokens;
  43135. tokens.addTokens (savedVersion.substring (3), false);
  43136. clear();
  43137. for (int i = 0; i < tokens.size(); ++i)
  43138. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43139. resized();
  43140. return true;
  43141. }
  43142. void Toolbar::paint (Graphics& g)
  43143. {
  43144. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43145. }
  43146. int Toolbar::getThickness() const throw()
  43147. {
  43148. return vertical ? getWidth() : getHeight();
  43149. }
  43150. int Toolbar::getLength() const throw()
  43151. {
  43152. return vertical ? getHeight() : getWidth();
  43153. }
  43154. void Toolbar::setEditingActive (const bool active)
  43155. {
  43156. if (isEditingActive != active)
  43157. {
  43158. isEditingActive = active;
  43159. updateAllItemPositions (false);
  43160. }
  43161. }
  43162. void Toolbar::resized()
  43163. {
  43164. updateAllItemPositions (false);
  43165. }
  43166. void Toolbar::updateAllItemPositions (const bool animate)
  43167. {
  43168. if (getWidth() > 0 && getHeight() > 0)
  43169. {
  43170. StretchableObjectResizer resizer;
  43171. int i;
  43172. for (i = 0; i < items.size(); ++i)
  43173. {
  43174. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43175. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43176. : ToolbarItemComponent::normalMode);
  43177. tc->setStyle (toolbarStyle);
  43178. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43179. int preferredSize = 1, minSize = 1, maxSize = 1;
  43180. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43181. preferredSize, minSize, maxSize))
  43182. {
  43183. tc->isActive = true;
  43184. resizer.addItem (preferredSize, minSize, maxSize,
  43185. spacer != 0 ? spacer->getResizeOrder() : 2);
  43186. }
  43187. else
  43188. {
  43189. tc->isActive = false;
  43190. tc->setVisible (false);
  43191. }
  43192. }
  43193. resizer.resizeToFit (getLength());
  43194. int totalLength = 0;
  43195. for (i = 0; i < resizer.getNumItems(); ++i)
  43196. totalLength += (int) resizer.getItemSize (i);
  43197. const bool itemsOffTheEnd = totalLength > getLength();
  43198. const int extrasButtonSize = getThickness() / 2;
  43199. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43200. missingItemsButton->setVisible (itemsOffTheEnd);
  43201. missingItemsButton->setEnabled (! isEditingActive);
  43202. if (vertical)
  43203. missingItemsButton->setCentrePosition (getWidth() / 2,
  43204. getHeight() - 4 - extrasButtonSize / 2);
  43205. else
  43206. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43207. getHeight() / 2);
  43208. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43209. : missingItemsButton->getX()) - 4
  43210. : getLength();
  43211. int pos = 0, activeIndex = 0;
  43212. for (i = 0; i < items.size(); ++i)
  43213. {
  43214. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43215. if (tc->isActive)
  43216. {
  43217. const int size = (int) resizer.getItemSize (activeIndex++);
  43218. Rectangle<int> newBounds;
  43219. if (vertical)
  43220. newBounds.setBounds (0, pos, getWidth(), size);
  43221. else
  43222. newBounds.setBounds (pos, 0, size, getHeight());
  43223. if (animate)
  43224. {
  43225. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43226. }
  43227. else
  43228. {
  43229. animator.cancelAnimation (tc, false);
  43230. tc->setBounds (newBounds);
  43231. }
  43232. pos += size;
  43233. tc->setVisible (pos <= maxLength
  43234. && ((! tc->isBeingDragged)
  43235. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43236. }
  43237. }
  43238. }
  43239. }
  43240. void Toolbar::buttonClicked (Button*)
  43241. {
  43242. jassert (missingItemsButton->isShowing());
  43243. if (missingItemsButton->isShowing())
  43244. {
  43245. PopupMenu m;
  43246. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43247. m.showAt (missingItemsButton);
  43248. }
  43249. }
  43250. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43251. Component* /*sourceComponent*/)
  43252. {
  43253. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43254. }
  43255. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43256. {
  43257. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43258. if (tc != 0)
  43259. {
  43260. if (getNumItems() == 0)
  43261. {
  43262. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43263. {
  43264. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43265. if (palette != 0)
  43266. palette->replaceComponent (tc);
  43267. }
  43268. else
  43269. {
  43270. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43271. }
  43272. items.add (tc);
  43273. addChildComponent (tc);
  43274. updateAllItemPositions (false);
  43275. }
  43276. else
  43277. {
  43278. for (int i = getNumItems(); --i >= 0;)
  43279. {
  43280. int currentIndex = getIndexOfChildComponent (tc);
  43281. if (currentIndex < 0)
  43282. {
  43283. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43284. {
  43285. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43286. if (palette != 0)
  43287. palette->replaceComponent (tc);
  43288. }
  43289. else
  43290. {
  43291. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43292. }
  43293. items.add (tc);
  43294. addChildComponent (tc);
  43295. currentIndex = getIndexOfChildComponent (tc);
  43296. updateAllItemPositions (true);
  43297. }
  43298. int newIndex = currentIndex;
  43299. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43300. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43301. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43302. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43303. if (prev != 0)
  43304. {
  43305. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43306. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43307. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43308. {
  43309. newIndex = getIndexOfChildComponent (prev);
  43310. }
  43311. }
  43312. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43313. if (next != 0)
  43314. {
  43315. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43316. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43317. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43318. {
  43319. newIndex = getIndexOfChildComponent (next) + 1;
  43320. }
  43321. }
  43322. if (newIndex != currentIndex)
  43323. {
  43324. items.removeValue (tc);
  43325. removeChildComponent (tc);
  43326. addChildComponent (tc, newIndex);
  43327. items.insert (newIndex, tc);
  43328. updateAllItemPositions (true);
  43329. }
  43330. else
  43331. {
  43332. break;
  43333. }
  43334. }
  43335. }
  43336. }
  43337. }
  43338. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43339. {
  43340. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43341. if (tc != 0)
  43342. {
  43343. if (isParentOf (tc))
  43344. {
  43345. items.removeValue (tc);
  43346. removeChildComponent (tc);
  43347. updateAllItemPositions (true);
  43348. }
  43349. }
  43350. }
  43351. void Toolbar::itemDropped (const String&, Component*, int, int)
  43352. {
  43353. }
  43354. void Toolbar::mouseDown (const MouseEvent& e)
  43355. {
  43356. if (e.mods.isPopupMenu())
  43357. {
  43358. }
  43359. }
  43360. class ToolbarCustomisationDialog : public DialogWindow
  43361. {
  43362. public:
  43363. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43364. Toolbar* const toolbar_,
  43365. const int optionFlags)
  43366. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43367. toolbar (toolbar_)
  43368. {
  43369. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43370. setResizable (true, true);
  43371. setResizeLimits (400, 300, 1500, 1000);
  43372. positionNearBar();
  43373. }
  43374. ~ToolbarCustomisationDialog()
  43375. {
  43376. setContentComponent (0, true);
  43377. }
  43378. void closeButtonPressed()
  43379. {
  43380. setVisible (false);
  43381. }
  43382. bool canModalEventBeSentToComponent (const Component* comp)
  43383. {
  43384. return toolbar->isParentOf (comp);
  43385. }
  43386. void positionNearBar()
  43387. {
  43388. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43389. const int tbx = toolbar->getScreenX();
  43390. const int tby = toolbar->getScreenY();
  43391. const int gap = 8;
  43392. int x, y;
  43393. if (toolbar->isVertical())
  43394. {
  43395. y = tby;
  43396. if (tbx > screenSize.getCentreX())
  43397. x = tbx - getWidth() - gap;
  43398. else
  43399. x = tbx + toolbar->getWidth() + gap;
  43400. }
  43401. else
  43402. {
  43403. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43404. if (tby > screenSize.getCentreY())
  43405. y = tby - getHeight() - gap;
  43406. else
  43407. y = tby + toolbar->getHeight() + gap;
  43408. }
  43409. setTopLeftPosition (x, y);
  43410. }
  43411. private:
  43412. Toolbar* const toolbar;
  43413. class CustomiserPanel : public Component,
  43414. private ComboBoxListener,
  43415. private ButtonListener
  43416. {
  43417. public:
  43418. CustomiserPanel (ToolbarItemFactory& factory_,
  43419. Toolbar* const toolbar_,
  43420. const int optionFlags)
  43421. : factory (factory_),
  43422. toolbar (toolbar_),
  43423. styleBox (0),
  43424. defaultButton (0)
  43425. {
  43426. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43427. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43428. | Toolbar::allowIconsWithTextChoice
  43429. | Toolbar::allowTextOnlyChoice)) != 0)
  43430. {
  43431. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43432. styleBox->setEditableText (false);
  43433. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43434. styleBox->addItem (TRANS("Show icons only"), 1);
  43435. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43436. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43437. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43438. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43439. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43440. styleBox->setSelectedId (1);
  43441. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43442. styleBox->setSelectedId (2);
  43443. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43444. styleBox->setSelectedId (3);
  43445. styleBox->addListener (this);
  43446. }
  43447. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43448. {
  43449. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43450. defaultButton->addButtonListener (this);
  43451. }
  43452. addAndMakeVisible (instructions = new Label (String::empty,
  43453. TRANS ("You can drag the items above and drop them onto a toolbar to add them.\n\nItems on the toolbar can also be dragged around to change their order, or dragged off the edge to delete them.")));
  43454. instructions->setFont (Font (13.0f));
  43455. setSize (500, 300);
  43456. }
  43457. ~CustomiserPanel()
  43458. {
  43459. deleteAllChildren();
  43460. }
  43461. void comboBoxChanged (ComboBox*)
  43462. {
  43463. if (styleBox->getSelectedId() == 1)
  43464. toolbar->setStyle (Toolbar::iconsOnly);
  43465. else if (styleBox->getSelectedId() == 2)
  43466. toolbar->setStyle (Toolbar::iconsWithText);
  43467. else if (styleBox->getSelectedId() == 3)
  43468. toolbar->setStyle (Toolbar::textOnly);
  43469. palette->resized(); // to make it update the styles
  43470. }
  43471. void buttonClicked (Button*)
  43472. {
  43473. toolbar->addDefaultItems (factory);
  43474. }
  43475. void paint (Graphics& g)
  43476. {
  43477. Colour background;
  43478. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43479. if (dw != 0)
  43480. background = dw->getBackgroundColour();
  43481. g.setColour (background.contrasting().withAlpha (0.3f));
  43482. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43483. }
  43484. void resized()
  43485. {
  43486. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43487. if (styleBox != 0)
  43488. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43489. if (defaultButton != 0)
  43490. {
  43491. defaultButton->changeWidthToFitText (22);
  43492. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43493. }
  43494. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43495. }
  43496. private:
  43497. ToolbarItemFactory& factory;
  43498. Toolbar* const toolbar;
  43499. Label* instructions;
  43500. ToolbarItemPalette* palette;
  43501. ComboBox* styleBox;
  43502. TextButton* defaultButton;
  43503. };
  43504. };
  43505. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43506. {
  43507. setEditingActive (true);
  43508. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43509. dw.runModalLoop();
  43510. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43511. setEditingActive (false);
  43512. }
  43513. END_JUCE_NAMESPACE
  43514. /*** End of inlined file: juce_Toolbar.cpp ***/
  43515. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43516. BEGIN_JUCE_NAMESPACE
  43517. ToolbarItemFactory::ToolbarItemFactory()
  43518. {
  43519. }
  43520. ToolbarItemFactory::~ToolbarItemFactory()
  43521. {
  43522. }
  43523. class ItemDragAndDropOverlayComponent : public Component
  43524. {
  43525. public:
  43526. ItemDragAndDropOverlayComponent()
  43527. : isDragging (false)
  43528. {
  43529. setAlwaysOnTop (true);
  43530. setRepaintsOnMouseActivity (true);
  43531. setMouseCursor (MouseCursor::DraggingHandCursor);
  43532. }
  43533. ~ItemDragAndDropOverlayComponent()
  43534. {
  43535. }
  43536. void paint (Graphics& g)
  43537. {
  43538. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43539. if (isMouseOverOrDragging()
  43540. && tc != 0
  43541. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43542. {
  43543. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43544. g.drawRect (0, 0, getWidth(), getHeight(),
  43545. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43546. }
  43547. }
  43548. void mouseDown (const MouseEvent& e)
  43549. {
  43550. isDragging = false;
  43551. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43552. if (tc != 0)
  43553. {
  43554. tc->dragOffsetX = e.x;
  43555. tc->dragOffsetY = e.y;
  43556. }
  43557. }
  43558. void mouseDrag (const MouseEvent& e)
  43559. {
  43560. if (! (isDragging || e.mouseWasClicked()))
  43561. {
  43562. isDragging = true;
  43563. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43564. if (dnd != 0)
  43565. {
  43566. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43567. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43568. if (tc != 0)
  43569. {
  43570. tc->isBeingDragged = true;
  43571. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43572. tc->setVisible (false);
  43573. }
  43574. }
  43575. }
  43576. }
  43577. void mouseUp (const MouseEvent&)
  43578. {
  43579. isDragging = false;
  43580. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43581. if (tc != 0)
  43582. {
  43583. tc->isBeingDragged = false;
  43584. Toolbar* const tb = tc->getToolbar();
  43585. if (tb != 0)
  43586. tb->updateAllItemPositions (true);
  43587. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43588. delete tc;
  43589. }
  43590. }
  43591. void parentSizeChanged()
  43592. {
  43593. setBounds (0, 0, getParentWidth(), getParentHeight());
  43594. }
  43595. juce_UseDebuggingNewOperator
  43596. private:
  43597. bool isDragging;
  43598. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43599. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43600. };
  43601. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43602. const String& labelText,
  43603. const bool isBeingUsedAsAButton_)
  43604. : Button (labelText),
  43605. itemId (itemId_),
  43606. mode (normalMode),
  43607. toolbarStyle (Toolbar::iconsOnly),
  43608. dragOffsetX (0),
  43609. dragOffsetY (0),
  43610. isActive (true),
  43611. isBeingDragged (false),
  43612. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43613. {
  43614. // Your item ID can't be 0!
  43615. jassert (itemId_ != 0);
  43616. }
  43617. ToolbarItemComponent::~ToolbarItemComponent()
  43618. {
  43619. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43620. overlayComp = 0;
  43621. }
  43622. Toolbar* ToolbarItemComponent::getToolbar() const
  43623. {
  43624. return dynamic_cast <Toolbar*> (getParentComponent());
  43625. }
  43626. bool ToolbarItemComponent::isToolbarVertical() const
  43627. {
  43628. const Toolbar* const t = getToolbar();
  43629. return t != 0 && t->isVertical();
  43630. }
  43631. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43632. {
  43633. if (toolbarStyle != newStyle)
  43634. {
  43635. toolbarStyle = newStyle;
  43636. repaint();
  43637. resized();
  43638. }
  43639. }
  43640. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43641. {
  43642. if (isBeingUsedAsAButton)
  43643. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43644. isMouseOver, isMouseDown, *this);
  43645. if (toolbarStyle != Toolbar::iconsOnly)
  43646. {
  43647. const int indent = contentArea.getX();
  43648. int y = indent;
  43649. int h = getHeight() - indent * 2;
  43650. if (toolbarStyle == Toolbar::iconsWithText)
  43651. {
  43652. y = contentArea.getBottom() + indent / 2;
  43653. h -= contentArea.getHeight();
  43654. }
  43655. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43656. getButtonText(), *this);
  43657. }
  43658. if (! contentArea.isEmpty())
  43659. {
  43660. g.saveState();
  43661. g.setOrigin (contentArea.getX(), contentArea.getY());
  43662. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43663. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43664. g.restoreState();
  43665. }
  43666. }
  43667. void ToolbarItemComponent::resized()
  43668. {
  43669. if (toolbarStyle != Toolbar::textOnly)
  43670. {
  43671. const int indent = jmin (proportionOfWidth (0.08f),
  43672. proportionOfHeight (0.08f));
  43673. contentArea = Rectangle<int> (indent, indent,
  43674. getWidth() - indent * 2,
  43675. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43676. : (getHeight() - indent * 2));
  43677. }
  43678. else
  43679. {
  43680. contentArea = Rectangle<int>();
  43681. }
  43682. contentAreaChanged (contentArea);
  43683. }
  43684. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43685. {
  43686. if (mode != newMode)
  43687. {
  43688. mode = newMode;
  43689. repaint();
  43690. if (mode == normalMode)
  43691. {
  43692. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43693. overlayComp = 0;
  43694. }
  43695. else if (overlayComp == 0)
  43696. {
  43697. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43698. overlayComp->parentSizeChanged();
  43699. }
  43700. resized();
  43701. }
  43702. }
  43703. END_JUCE_NAMESPACE
  43704. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43705. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43706. BEGIN_JUCE_NAMESPACE
  43707. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43708. Toolbar* const toolbar_)
  43709. : factory (factory_),
  43710. toolbar (toolbar_)
  43711. {
  43712. Component* const itemHolder = new Component();
  43713. Array <int> allIds;
  43714. factory_.getAllToolbarItemIds (allIds);
  43715. for (int i = 0; i < allIds.size(); ++i)
  43716. {
  43717. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43718. jassert (tc != 0);
  43719. if (tc != 0)
  43720. {
  43721. itemHolder->addAndMakeVisible (tc);
  43722. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43723. }
  43724. }
  43725. viewport = new Viewport();
  43726. viewport->setViewedComponent (itemHolder);
  43727. addAndMakeVisible (viewport);
  43728. }
  43729. ToolbarItemPalette::~ToolbarItemPalette()
  43730. {
  43731. viewport->getViewedComponent()->deleteAllChildren();
  43732. deleteAllChildren();
  43733. }
  43734. void ToolbarItemPalette::resized()
  43735. {
  43736. viewport->setBoundsInset (BorderSize (1));
  43737. Component* const itemHolder = viewport->getViewedComponent();
  43738. const int indent = 8;
  43739. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  43740. const int height = toolbar->getThickness();
  43741. int x = indent;
  43742. int y = indent;
  43743. int maxX = 0;
  43744. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  43745. {
  43746. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  43747. if (tc != 0)
  43748. {
  43749. tc->setStyle (toolbar->getStyle());
  43750. int preferredSize = 1, minSize = 1, maxSize = 1;
  43751. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43752. {
  43753. if (x + preferredSize > preferredWidth && x > indent)
  43754. {
  43755. x = indent;
  43756. y += height;
  43757. }
  43758. tc->setBounds (x, y, preferredSize, height);
  43759. x += preferredSize + 8;
  43760. maxX = jmax (maxX, x);
  43761. }
  43762. }
  43763. }
  43764. itemHolder->setSize (maxX, y + height + 8);
  43765. }
  43766. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  43767. {
  43768. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  43769. jassert (tc != 0);
  43770. if (tc != 0)
  43771. {
  43772. tc->setBounds (comp->getBounds());
  43773. tc->setStyle (toolbar->getStyle());
  43774. tc->setEditingMode (comp->getEditingMode());
  43775. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  43776. }
  43777. }
  43778. END_JUCE_NAMESPACE
  43779. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  43780. /*** Start of inlined file: juce_TreeView.cpp ***/
  43781. BEGIN_JUCE_NAMESPACE
  43782. class TreeViewContentComponent : public Component,
  43783. public TooltipClient
  43784. {
  43785. public:
  43786. TreeViewContentComponent (TreeView* const owner_)
  43787. : owner (owner_),
  43788. buttonUnderMouse (0),
  43789. isDragging (false)
  43790. {
  43791. }
  43792. ~TreeViewContentComponent()
  43793. {
  43794. deleteAllChildren();
  43795. }
  43796. void mouseDown (const MouseEvent& e)
  43797. {
  43798. updateButtonUnderMouse (e);
  43799. isDragging = false;
  43800. needSelectionOnMouseUp = false;
  43801. Rectangle<int> pos;
  43802. TreeViewItem* const item = findItemAt (e.y, pos);
  43803. if (item == 0)
  43804. return;
  43805. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  43806. // as selection clicks)
  43807. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  43808. {
  43809. if (e.x >= pos.getX() - owner->getIndentSize())
  43810. item->setOpen (! item->isOpen());
  43811. // (clicks to the left of an open/close button are ignored)
  43812. }
  43813. else
  43814. {
  43815. // mouse-down inside the body of the item..
  43816. if (! owner->isMultiSelectEnabled())
  43817. item->setSelected (true, true);
  43818. else if (item->isSelected())
  43819. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  43820. else
  43821. selectBasedOnModifiers (item, e.mods);
  43822. if (e.x >= pos.getX())
  43823. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43824. }
  43825. }
  43826. void mouseUp (const MouseEvent& e)
  43827. {
  43828. updateButtonUnderMouse (e);
  43829. if (needSelectionOnMouseUp && e.mouseWasClicked())
  43830. {
  43831. Rectangle<int> pos;
  43832. TreeViewItem* const item = findItemAt (e.y, pos);
  43833. if (item != 0)
  43834. selectBasedOnModifiers (item, e.mods);
  43835. }
  43836. }
  43837. void mouseDoubleClick (const MouseEvent& e)
  43838. {
  43839. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  43840. {
  43841. Rectangle<int> pos;
  43842. TreeViewItem* const item = findItemAt (e.y, pos);
  43843. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  43844. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43845. }
  43846. }
  43847. void mouseDrag (const MouseEvent& e)
  43848. {
  43849. if (isEnabled()
  43850. && ! (isDragging || e.mouseWasClicked()
  43851. || e.getDistanceFromDragStart() < 5
  43852. || e.mods.isPopupMenu()))
  43853. {
  43854. isDragging = true;
  43855. Rectangle<int> pos;
  43856. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  43857. if (item != 0 && e.getMouseDownX() >= pos.getX())
  43858. {
  43859. const String dragDescription (item->getDragSourceDescription());
  43860. if (dragDescription.isNotEmpty())
  43861. {
  43862. DragAndDropContainer* const dragContainer
  43863. = DragAndDropContainer::findParentDragContainerFor (this);
  43864. if (dragContainer != 0)
  43865. {
  43866. pos.setSize (pos.getWidth(), item->itemHeight);
  43867. Image* dragImage = Component::createComponentSnapshot (pos, true);
  43868. dragImage->multiplyAllAlphas (0.6f);
  43869. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  43870. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  43871. }
  43872. else
  43873. {
  43874. // to be able to do a drag-and-drop operation, the treeview needs to
  43875. // be inside a component which is also a DragAndDropContainer.
  43876. jassertfalse
  43877. }
  43878. }
  43879. }
  43880. }
  43881. }
  43882. void mouseMove (const MouseEvent& e)
  43883. {
  43884. updateButtonUnderMouse (e);
  43885. }
  43886. void mouseExit (const MouseEvent& e)
  43887. {
  43888. updateButtonUnderMouse (e);
  43889. }
  43890. void paint (Graphics& g);
  43891. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  43892. static bool isMouseDraggingInChildCompOf (Component* const comp)
  43893. {
  43894. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  43895. {
  43896. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  43897. if (source->isDragging())
  43898. {
  43899. Component* const underMouse = source->getComponentUnderMouse();
  43900. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  43901. return true;
  43902. }
  43903. }
  43904. return false;
  43905. }
  43906. void updateComponents()
  43907. {
  43908. const int visibleTop = -getY();
  43909. const int visibleBottom = visibleTop + getParentHeight();
  43910. BigInteger itemsToKeep;
  43911. TreeViewItem* item = owner->rootItem;
  43912. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  43913. while (item != 0 && y < visibleBottom)
  43914. {
  43915. y += item->itemHeight;
  43916. if (y >= visibleTop)
  43917. {
  43918. const int index = rowComponentIds.indexOf (item->uid);
  43919. if (index < 0)
  43920. {
  43921. Component* const comp = item->createItemComponent();
  43922. if (comp != 0)
  43923. {
  43924. addAndMakeVisible (comp);
  43925. itemsToKeep.setBit (rowComponentItems.size());
  43926. rowComponentItems.add (item);
  43927. rowComponentIds.add (item->uid);
  43928. rowComponents.add (comp);
  43929. }
  43930. }
  43931. else
  43932. {
  43933. itemsToKeep.setBit (index);
  43934. }
  43935. }
  43936. item = item->getNextVisibleItem (true);
  43937. }
  43938. for (int i = rowComponentItems.size(); --i >= 0;)
  43939. {
  43940. Component* const comp = rowComponents.getUnchecked(i);
  43941. bool keep = false;
  43942. if (isParentOf (comp))
  43943. {
  43944. if (itemsToKeep[i])
  43945. {
  43946. const TreeViewItem* const item = rowComponentItems.getUnchecked(i);
  43947. Rectangle<int> pos (item->getItemPosition (false));
  43948. pos.setSize (pos.getWidth(), item->itemHeight);
  43949. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  43950. {
  43951. keep = true;
  43952. comp->setBounds (pos);
  43953. }
  43954. }
  43955. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  43956. {
  43957. keep = true;
  43958. comp->setSize (0, 0);
  43959. }
  43960. }
  43961. if (! keep)
  43962. {
  43963. delete comp;
  43964. rowComponents.remove (i);
  43965. rowComponentIds.remove (i);
  43966. rowComponentItems.remove (i);
  43967. }
  43968. }
  43969. }
  43970. void updateButtonUnderMouse (const MouseEvent& e)
  43971. {
  43972. TreeViewItem* newItem = 0;
  43973. if (owner->openCloseButtonsVisible)
  43974. {
  43975. Rectangle<int> pos;
  43976. TreeViewItem* item = findItemAt (e.y, pos);
  43977. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  43978. {
  43979. newItem = item;
  43980. if (! newItem->mightContainSubItems())
  43981. newItem = 0;
  43982. }
  43983. }
  43984. if (buttonUnderMouse != newItem)
  43985. {
  43986. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  43987. {
  43988. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  43989. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  43990. }
  43991. buttonUnderMouse = newItem;
  43992. if (buttonUnderMouse != 0)
  43993. {
  43994. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  43995. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  43996. }
  43997. }
  43998. }
  43999. bool isMouseOverButton (TreeViewItem* item) const throw()
  44000. {
  44001. return item == buttonUnderMouse;
  44002. }
  44003. void resized()
  44004. {
  44005. owner->itemsChanged();
  44006. }
  44007. const String getTooltip()
  44008. {
  44009. Rectangle<int> pos;
  44010. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44011. if (item != 0)
  44012. return item->getTooltip();
  44013. return owner->getTooltip();
  44014. }
  44015. juce_UseDebuggingNewOperator
  44016. private:
  44017. TreeView* const owner;
  44018. Array <TreeViewItem*> rowComponentItems;
  44019. Array <int> rowComponentIds;
  44020. Array <Component*> rowComponents;
  44021. TreeViewItem* buttonUnderMouse;
  44022. bool isDragging, needSelectionOnMouseUp;
  44023. TreeViewContentComponent (const TreeViewContentComponent&);
  44024. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44025. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44026. {
  44027. TreeViewItem* firstSelected = 0;
  44028. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44029. {
  44030. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44031. jassert (lastSelected != 0);
  44032. int rowStart = firstSelected->getRowNumberInTree();
  44033. int rowEnd = lastSelected->getRowNumberInTree();
  44034. if (rowStart > rowEnd)
  44035. swapVariables (rowStart, rowEnd);
  44036. int ourRow = item->getRowNumberInTree();
  44037. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44038. if (ourRow > otherEnd)
  44039. swapVariables (ourRow, otherEnd);
  44040. for (int i = ourRow; i <= otherEnd; ++i)
  44041. owner->getItemOnRow (i)->setSelected (true, false);
  44042. }
  44043. else
  44044. {
  44045. const bool cmd = modifiers.isCommandDown();
  44046. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44047. }
  44048. }
  44049. bool containsItem (TreeViewItem* const item) const
  44050. {
  44051. for (int i = rowComponentItems.size(); --i >= 0;)
  44052. if (rowComponentItems.getUnchecked(i) == item)
  44053. return true;
  44054. return false;
  44055. }
  44056. };
  44057. class TreeView::TreeViewport : public Viewport
  44058. {
  44059. public:
  44060. TreeViewport() throw() {}
  44061. ~TreeViewport() throw() {}
  44062. void updateComponents()
  44063. {
  44064. TreeViewContentComponent* const tvc = static_cast <TreeViewContentComponent*> (getViewedComponent());
  44065. if (tvc != 0)
  44066. tvc->updateComponents();
  44067. repaint();
  44068. }
  44069. void visibleAreaChanged (int, int, int, int)
  44070. {
  44071. updateComponents();
  44072. }
  44073. juce_UseDebuggingNewOperator
  44074. private:
  44075. TreeViewport (const TreeViewport&);
  44076. TreeViewport& operator= (const TreeViewport&);
  44077. };
  44078. TreeView::TreeView (const String& componentName)
  44079. : Component (componentName),
  44080. rootItem (0),
  44081. dragInsertPointHighlight (0),
  44082. dragTargetGroupHighlight (0),
  44083. indentSize (24),
  44084. defaultOpenness (false),
  44085. needsRecalculating (true),
  44086. rootItemVisible (true),
  44087. multiSelectEnabled (false),
  44088. openCloseButtonsVisible (true)
  44089. {
  44090. addAndMakeVisible (viewport = new TreeViewport());
  44091. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44092. viewport->setWantsKeyboardFocus (false);
  44093. setWantsKeyboardFocus (true);
  44094. }
  44095. TreeView::~TreeView()
  44096. {
  44097. if (rootItem != 0)
  44098. rootItem->setOwnerView (0);
  44099. deleteAllChildren();
  44100. }
  44101. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44102. {
  44103. if (rootItem != newRootItem)
  44104. {
  44105. if (newRootItem != 0)
  44106. {
  44107. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44108. if (newRootItem->ownerView != 0)
  44109. newRootItem->ownerView->setRootItem (0);
  44110. }
  44111. if (rootItem != 0)
  44112. rootItem->setOwnerView (0);
  44113. rootItem = newRootItem;
  44114. if (newRootItem != 0)
  44115. newRootItem->setOwnerView (this);
  44116. needsRecalculating = true;
  44117. handleAsyncUpdate();
  44118. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44119. {
  44120. rootItem->setOpen (false); // force a re-open
  44121. rootItem->setOpen (true);
  44122. }
  44123. }
  44124. }
  44125. void TreeView::deleteRootItem()
  44126. {
  44127. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44128. setRootItem (0);
  44129. }
  44130. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44131. {
  44132. rootItemVisible = shouldBeVisible;
  44133. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44134. {
  44135. rootItem->setOpen (false); // force a re-open
  44136. rootItem->setOpen (true);
  44137. }
  44138. itemsChanged();
  44139. }
  44140. void TreeView::colourChanged()
  44141. {
  44142. setOpaque (findColour (backgroundColourId).isOpaque());
  44143. repaint();
  44144. }
  44145. void TreeView::setIndentSize (const int newIndentSize)
  44146. {
  44147. if (indentSize != newIndentSize)
  44148. {
  44149. indentSize = newIndentSize;
  44150. resized();
  44151. }
  44152. }
  44153. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44154. {
  44155. if (defaultOpenness != isOpenByDefault)
  44156. {
  44157. defaultOpenness = isOpenByDefault;
  44158. itemsChanged();
  44159. }
  44160. }
  44161. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44162. {
  44163. multiSelectEnabled = canMultiSelect;
  44164. }
  44165. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44166. {
  44167. if (openCloseButtonsVisible != shouldBeVisible)
  44168. {
  44169. openCloseButtonsVisible = shouldBeVisible;
  44170. itemsChanged();
  44171. }
  44172. }
  44173. Viewport* TreeView::getViewport() const throw()
  44174. {
  44175. return viewport;
  44176. }
  44177. void TreeView::clearSelectedItems()
  44178. {
  44179. if (rootItem != 0)
  44180. rootItem->deselectAllRecursively();
  44181. }
  44182. int TreeView::getNumSelectedItems() const throw()
  44183. {
  44184. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44185. }
  44186. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44187. {
  44188. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44189. }
  44190. int TreeView::getNumRowsInTree() const
  44191. {
  44192. if (rootItem != 0)
  44193. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44194. return 0;
  44195. }
  44196. TreeViewItem* TreeView::getItemOnRow (int index) const
  44197. {
  44198. if (! rootItemVisible)
  44199. ++index;
  44200. if (rootItem != 0 && index >= 0)
  44201. return rootItem->getItemOnRow (index);
  44202. return 0;
  44203. }
  44204. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44205. {
  44206. TreeViewContentComponent* const tc = static_cast <TreeViewContentComponent*> (viewport->getViewedComponent());
  44207. Rectangle<int> pos;
  44208. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44209. }
  44210. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44211. {
  44212. if (rootItem == 0)
  44213. return 0;
  44214. return rootItem->findItemFromIdentifierString (identifierString);
  44215. }
  44216. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44217. {
  44218. XmlElement* e = 0;
  44219. if (rootItem != 0)
  44220. {
  44221. e = rootItem->getOpennessState();
  44222. if (e != 0 && alsoIncludeScrollPosition)
  44223. e->setAttribute ("scrollPos", viewport->getViewPositionY());
  44224. }
  44225. return e;
  44226. }
  44227. void TreeView::restoreOpennessState (const XmlElement& newState)
  44228. {
  44229. if (rootItem != 0)
  44230. {
  44231. rootItem->restoreOpennessState (newState);
  44232. if (newState.hasAttribute ("scrollPos"))
  44233. viewport->setViewPosition (viewport->getViewPositionX(),
  44234. newState.getIntAttribute ("scrollPos"));
  44235. }
  44236. }
  44237. void TreeView::paint (Graphics& g)
  44238. {
  44239. g.fillAll (findColour (backgroundColourId));
  44240. }
  44241. void TreeView::resized()
  44242. {
  44243. viewport->setBounds (0, 0, getWidth(), getHeight());
  44244. itemsChanged();
  44245. handleAsyncUpdate();
  44246. }
  44247. void TreeView::enablementChanged()
  44248. {
  44249. repaint();
  44250. }
  44251. void TreeView::moveSelectedRow (int delta)
  44252. {
  44253. if (delta == 0)
  44254. return;
  44255. int rowSelected = 0;
  44256. TreeViewItem* const firstSelected = getSelectedItem (0);
  44257. if (firstSelected != 0)
  44258. rowSelected = firstSelected->getRowNumberInTree();
  44259. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44260. for (;;)
  44261. {
  44262. TreeViewItem* item = getItemOnRow (rowSelected);
  44263. if (item != 0)
  44264. {
  44265. if (! item->canBeSelected())
  44266. {
  44267. // if the row we want to highlight doesn't allow it, try skipping
  44268. // to the next item..
  44269. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44270. rowSelected + (delta < 0 ? -1 : 1));
  44271. if (rowSelected != nextRowToTry)
  44272. {
  44273. rowSelected = nextRowToTry;
  44274. continue;
  44275. }
  44276. else
  44277. {
  44278. break;
  44279. }
  44280. }
  44281. item->setSelected (true, true);
  44282. scrollToKeepItemVisible (item);
  44283. }
  44284. break;
  44285. }
  44286. }
  44287. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44288. {
  44289. if (item != 0 && item->ownerView == this)
  44290. {
  44291. handleAsyncUpdate();
  44292. item = item->getDeepestOpenParentItem();
  44293. int y = item->y;
  44294. int viewTop = viewport->getViewPositionY();
  44295. if (y < viewTop)
  44296. {
  44297. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44298. }
  44299. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44300. {
  44301. viewport->setViewPosition (viewport->getViewPositionX(),
  44302. (y + item->itemHeight) - viewport->getViewHeight());
  44303. }
  44304. }
  44305. }
  44306. bool TreeView::keyPressed (const KeyPress& key)
  44307. {
  44308. if (key.isKeyCode (KeyPress::upKey))
  44309. {
  44310. moveSelectedRow (-1);
  44311. }
  44312. else if (key.isKeyCode (KeyPress::downKey))
  44313. {
  44314. moveSelectedRow (1);
  44315. }
  44316. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44317. {
  44318. if (rootItem != 0)
  44319. {
  44320. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44321. if (key.isKeyCode (KeyPress::pageUpKey))
  44322. rowsOnScreen = -rowsOnScreen;
  44323. moveSelectedRow (rowsOnScreen);
  44324. }
  44325. }
  44326. else if (key.isKeyCode (KeyPress::homeKey))
  44327. {
  44328. moveSelectedRow (-0x3fffffff);
  44329. }
  44330. else if (key.isKeyCode (KeyPress::endKey))
  44331. {
  44332. moveSelectedRow (0x3fffffff);
  44333. }
  44334. else if (key.isKeyCode (KeyPress::returnKey))
  44335. {
  44336. TreeViewItem* const firstSelected = getSelectedItem (0);
  44337. if (firstSelected != 0)
  44338. firstSelected->setOpen (! firstSelected->isOpen());
  44339. }
  44340. else if (key.isKeyCode (KeyPress::leftKey))
  44341. {
  44342. TreeViewItem* const firstSelected = getSelectedItem (0);
  44343. if (firstSelected != 0)
  44344. {
  44345. if (firstSelected->isOpen())
  44346. {
  44347. firstSelected->setOpen (false);
  44348. }
  44349. else
  44350. {
  44351. TreeViewItem* parent = firstSelected->parentItem;
  44352. if ((! rootItemVisible) && parent == rootItem)
  44353. parent = 0;
  44354. if (parent != 0)
  44355. {
  44356. parent->setSelected (true, true);
  44357. scrollToKeepItemVisible (parent);
  44358. }
  44359. }
  44360. }
  44361. }
  44362. else if (key.isKeyCode (KeyPress::rightKey))
  44363. {
  44364. TreeViewItem* const firstSelected = getSelectedItem (0);
  44365. if (firstSelected != 0)
  44366. {
  44367. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44368. moveSelectedRow (1);
  44369. else
  44370. firstSelected->setOpen (true);
  44371. }
  44372. }
  44373. else
  44374. {
  44375. return false;
  44376. }
  44377. return true;
  44378. }
  44379. void TreeView::itemsChanged() throw()
  44380. {
  44381. needsRecalculating = true;
  44382. repaint();
  44383. triggerAsyncUpdate();
  44384. }
  44385. void TreeView::handleAsyncUpdate()
  44386. {
  44387. if (needsRecalculating)
  44388. {
  44389. needsRecalculating = false;
  44390. const ScopedLock sl (nodeAlterationLock);
  44391. if (rootItem != 0)
  44392. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44393. viewport->updateComponents();
  44394. if (rootItem != 0)
  44395. {
  44396. viewport->getViewedComponent()
  44397. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44398. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44399. }
  44400. else
  44401. {
  44402. viewport->getViewedComponent()->setSize (0, 0);
  44403. }
  44404. }
  44405. }
  44406. class TreeView::InsertPointHighlight : public Component
  44407. {
  44408. public:
  44409. InsertPointHighlight()
  44410. : lastItem (0)
  44411. {
  44412. setSize (100, 12);
  44413. setAlwaysOnTop (true);
  44414. setInterceptsMouseClicks (false, false);
  44415. }
  44416. ~InsertPointHighlight() {}
  44417. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44418. {
  44419. lastItem = item;
  44420. lastIndex = insertIndex;
  44421. const int offset = getHeight() / 2;
  44422. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44423. }
  44424. void paint (Graphics& g)
  44425. {
  44426. Path p;
  44427. const float h = (float) getHeight();
  44428. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44429. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44430. p.lineTo ((float) getWidth(), h / 2.0f);
  44431. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44432. g.strokePath (p, PathStrokeType (2.0f));
  44433. }
  44434. TreeViewItem* lastItem;
  44435. int lastIndex;
  44436. private:
  44437. InsertPointHighlight (const InsertPointHighlight&);
  44438. InsertPointHighlight& operator= (const InsertPointHighlight&);
  44439. };
  44440. class TreeView::TargetGroupHighlight : public Component
  44441. {
  44442. public:
  44443. TargetGroupHighlight()
  44444. {
  44445. setAlwaysOnTop (true);
  44446. setInterceptsMouseClicks (false, false);
  44447. }
  44448. ~TargetGroupHighlight() {}
  44449. void setTargetPosition (TreeViewItem* const item) throw()
  44450. {
  44451. Rectangle<int> r (item->getItemPosition (true));
  44452. r.setHeight (item->getItemHeight());
  44453. setBounds (r);
  44454. }
  44455. void paint (Graphics& g)
  44456. {
  44457. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44458. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44459. }
  44460. private:
  44461. TargetGroupHighlight (const TargetGroupHighlight&);
  44462. TargetGroupHighlight& operator= (const TargetGroupHighlight&);
  44463. };
  44464. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44465. {
  44466. beginDragAutoRepeat (1000 / 30);
  44467. if (dragInsertPointHighlight == 0)
  44468. {
  44469. addAndMakeVisible (dragInsertPointHighlight = new InsertPointHighlight());
  44470. addAndMakeVisible (dragTargetGroupHighlight = new TargetGroupHighlight());
  44471. }
  44472. dragInsertPointHighlight->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44473. dragTargetGroupHighlight->setTargetPosition (item);
  44474. }
  44475. void TreeView::hideDragHighlight() throw()
  44476. {
  44477. deleteAndZero (dragInsertPointHighlight);
  44478. deleteAndZero (dragTargetGroupHighlight);
  44479. }
  44480. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44481. const StringArray& files, const String& sourceDescription,
  44482. Component* sourceComponent) const throw()
  44483. {
  44484. insertIndex = 0;
  44485. TreeViewItem* item = getItemAt (y);
  44486. if (item == 0)
  44487. return 0;
  44488. Rectangle<int> itemPos (item->getItemPosition (true));
  44489. insertIndex = item->getIndexInParent();
  44490. const int oldY = y;
  44491. y = itemPos.getY();
  44492. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44493. {
  44494. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44495. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44496. {
  44497. // Check if we're trying to drag into an empty group item..
  44498. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44499. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44500. {
  44501. insertIndex = 0;
  44502. x = itemPos.getX() + getIndentSize();
  44503. y = itemPos.getBottom();
  44504. return item;
  44505. }
  44506. }
  44507. }
  44508. if (oldY > itemPos.getCentreY())
  44509. {
  44510. y += item->getItemHeight();
  44511. while (item->isLastOfSiblings() && item->parentItem != 0
  44512. && item->parentItem->parentItem != 0)
  44513. {
  44514. if (x > itemPos.getX())
  44515. break;
  44516. item = item->parentItem;
  44517. itemPos = item->getItemPosition (true);
  44518. insertIndex = item->getIndexInParent();
  44519. }
  44520. ++insertIndex;
  44521. }
  44522. x = itemPos.getX();
  44523. return item->parentItem;
  44524. }
  44525. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44526. {
  44527. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44528. int insertIndex;
  44529. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44530. if (item != 0)
  44531. {
  44532. if (scrolled || dragInsertPointHighlight == 0
  44533. || dragInsertPointHighlight->lastItem != item
  44534. || dragInsertPointHighlight->lastIndex != insertIndex)
  44535. {
  44536. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44537. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44538. showDragHighlight (item, insertIndex, x, y);
  44539. else
  44540. hideDragHighlight();
  44541. }
  44542. }
  44543. else
  44544. {
  44545. hideDragHighlight();
  44546. }
  44547. }
  44548. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44549. {
  44550. hideDragHighlight();
  44551. int insertIndex;
  44552. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44553. if (item != 0)
  44554. {
  44555. if (files.size() > 0)
  44556. {
  44557. if (item->isInterestedInFileDrag (files))
  44558. item->filesDropped (files, insertIndex);
  44559. }
  44560. else
  44561. {
  44562. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44563. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44564. }
  44565. }
  44566. }
  44567. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44568. {
  44569. return true;
  44570. }
  44571. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44572. {
  44573. fileDragMove (files, x, y);
  44574. }
  44575. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44576. {
  44577. handleDrag (files, String::empty, 0, x, y);
  44578. }
  44579. void TreeView::fileDragExit (const StringArray&)
  44580. {
  44581. hideDragHighlight();
  44582. }
  44583. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44584. {
  44585. handleDrop (files, String::empty, 0, x, y);
  44586. }
  44587. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44588. {
  44589. return true;
  44590. }
  44591. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44592. {
  44593. itemDragMove (sourceDescription, sourceComponent, x, y);
  44594. }
  44595. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44596. {
  44597. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44598. }
  44599. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44600. {
  44601. hideDragHighlight();
  44602. }
  44603. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44604. {
  44605. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44606. }
  44607. void TreeViewContentComponent::paint (Graphics& g)
  44608. {
  44609. if (owner->rootItem != 0)
  44610. {
  44611. owner->handleAsyncUpdate();
  44612. if (! owner->rootItemVisible)
  44613. g.setOrigin (0, -owner->rootItem->itemHeight);
  44614. owner->rootItem->paintRecursively (g, getWidth());
  44615. }
  44616. }
  44617. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44618. {
  44619. if (owner->rootItem != 0)
  44620. {
  44621. owner->handleAsyncUpdate();
  44622. if (! owner->rootItemVisible)
  44623. y += owner->rootItem->itemHeight;
  44624. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44625. if (ti != 0)
  44626. itemPosition = ti->getItemPosition (false);
  44627. return ti;
  44628. }
  44629. return 0;
  44630. }
  44631. enum TreeViewOpenness
  44632. {
  44633. opennessDefault = 0,
  44634. opennessClosed = 1,
  44635. opennessOpen = 2
  44636. };
  44637. TreeViewItem::TreeViewItem()
  44638. : ownerView (0),
  44639. parentItem (0),
  44640. y (0),
  44641. itemHeight (0),
  44642. totalHeight (0),
  44643. selected (false),
  44644. redrawNeeded (true),
  44645. drawLinesInside (true),
  44646. drawsInLeftMargin (false),
  44647. openness (opennessDefault)
  44648. {
  44649. static int nextUID = 0;
  44650. uid = nextUID++;
  44651. }
  44652. TreeViewItem::~TreeViewItem()
  44653. {
  44654. }
  44655. const String TreeViewItem::getUniqueName() const
  44656. {
  44657. return String::empty;
  44658. }
  44659. void TreeViewItem::itemOpennessChanged (bool)
  44660. {
  44661. }
  44662. int TreeViewItem::getNumSubItems() const throw()
  44663. {
  44664. return subItems.size();
  44665. }
  44666. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44667. {
  44668. return subItems [index];
  44669. }
  44670. void TreeViewItem::clearSubItems()
  44671. {
  44672. if (subItems.size() > 0)
  44673. {
  44674. if (ownerView != 0)
  44675. {
  44676. const ScopedLock sl (ownerView->nodeAlterationLock);
  44677. subItems.clear();
  44678. treeHasChanged();
  44679. }
  44680. else
  44681. {
  44682. subItems.clear();
  44683. }
  44684. }
  44685. }
  44686. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44687. {
  44688. if (newItem != 0)
  44689. {
  44690. newItem->parentItem = this;
  44691. newItem->setOwnerView (ownerView);
  44692. newItem->y = 0;
  44693. newItem->itemHeight = newItem->getItemHeight();
  44694. newItem->totalHeight = 0;
  44695. newItem->itemWidth = newItem->getItemWidth();
  44696. newItem->totalWidth = 0;
  44697. if (ownerView != 0)
  44698. {
  44699. const ScopedLock sl (ownerView->nodeAlterationLock);
  44700. subItems.insert (insertPosition, newItem);
  44701. treeHasChanged();
  44702. if (newItem->isOpen())
  44703. newItem->itemOpennessChanged (true);
  44704. }
  44705. else
  44706. {
  44707. subItems.insert (insertPosition, newItem);
  44708. if (newItem->isOpen())
  44709. newItem->itemOpennessChanged (true);
  44710. }
  44711. }
  44712. }
  44713. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44714. {
  44715. if (ownerView != 0)
  44716. {
  44717. const ScopedLock sl (ownerView->nodeAlterationLock);
  44718. if (((unsigned int) index) < (unsigned int) subItems.size())
  44719. {
  44720. subItems.remove (index, deleteItem);
  44721. treeHasChanged();
  44722. }
  44723. }
  44724. else
  44725. {
  44726. subItems.remove (index, deleteItem);
  44727. }
  44728. }
  44729. bool TreeViewItem::isOpen() const throw()
  44730. {
  44731. if (openness == opennessDefault)
  44732. return ownerView != 0 && ownerView->defaultOpenness;
  44733. else
  44734. return openness == opennessOpen;
  44735. }
  44736. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44737. {
  44738. if (isOpen() != shouldBeOpen)
  44739. {
  44740. openness = shouldBeOpen ? opennessOpen
  44741. : opennessClosed;
  44742. treeHasChanged();
  44743. itemOpennessChanged (isOpen());
  44744. }
  44745. }
  44746. bool TreeViewItem::isSelected() const throw()
  44747. {
  44748. return selected;
  44749. }
  44750. void TreeViewItem::deselectAllRecursively()
  44751. {
  44752. setSelected (false, false);
  44753. for (int i = 0; i < subItems.size(); ++i)
  44754. subItems.getUnchecked(i)->deselectAllRecursively();
  44755. }
  44756. void TreeViewItem::setSelected (const bool shouldBeSelected,
  44757. const bool deselectOtherItemsFirst)
  44758. {
  44759. if (shouldBeSelected && ! canBeSelected())
  44760. return;
  44761. if (deselectOtherItemsFirst)
  44762. getTopLevelItem()->deselectAllRecursively();
  44763. if (shouldBeSelected != selected)
  44764. {
  44765. selected = shouldBeSelected;
  44766. if (ownerView != 0)
  44767. ownerView->repaint();
  44768. itemSelectionChanged (shouldBeSelected);
  44769. }
  44770. }
  44771. void TreeViewItem::paintItem (Graphics&, int, int)
  44772. {
  44773. }
  44774. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  44775. {
  44776. ownerView->getLookAndFeel()
  44777. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  44778. }
  44779. void TreeViewItem::itemClicked (const MouseEvent&)
  44780. {
  44781. }
  44782. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  44783. {
  44784. if (mightContainSubItems())
  44785. setOpen (! isOpen());
  44786. }
  44787. void TreeViewItem::itemSelectionChanged (bool)
  44788. {
  44789. }
  44790. const String TreeViewItem::getTooltip()
  44791. {
  44792. return String::empty;
  44793. }
  44794. const String TreeViewItem::getDragSourceDescription()
  44795. {
  44796. return String::empty;
  44797. }
  44798. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  44799. {
  44800. return false;
  44801. }
  44802. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  44803. {
  44804. }
  44805. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44806. {
  44807. return false;
  44808. }
  44809. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  44810. {
  44811. }
  44812. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  44813. {
  44814. const int indentX = getIndentX();
  44815. int width = itemWidth;
  44816. if (ownerView != 0 && width < 0)
  44817. width = ownerView->viewport->getViewWidth() - indentX;
  44818. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  44819. if (relativeToTreeViewTopLeft)
  44820. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  44821. r.getY() - ownerView->viewport->getViewPositionY());
  44822. return r;
  44823. }
  44824. void TreeViewItem::treeHasChanged() const throw()
  44825. {
  44826. if (ownerView != 0)
  44827. ownerView->itemsChanged();
  44828. }
  44829. void TreeViewItem::repaintItem() const
  44830. {
  44831. if (ownerView != 0 && areAllParentsOpen())
  44832. {
  44833. const Rectangle<int> r (getItemPosition (true));
  44834. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  44835. }
  44836. }
  44837. bool TreeViewItem::areAllParentsOpen() const throw()
  44838. {
  44839. return parentItem == 0
  44840. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  44841. }
  44842. void TreeViewItem::updatePositions (int newY)
  44843. {
  44844. y = newY;
  44845. itemHeight = getItemHeight();
  44846. totalHeight = itemHeight;
  44847. itemWidth = getItemWidth();
  44848. totalWidth = jmax (itemWidth, 0) + getIndentX();
  44849. if (isOpen())
  44850. {
  44851. newY += totalHeight;
  44852. for (int i = 0; i < subItems.size(); ++i)
  44853. {
  44854. TreeViewItem* const ti = subItems.getUnchecked(i);
  44855. ti->updatePositions (newY);
  44856. newY += ti->totalHeight;
  44857. totalHeight += ti->totalHeight;
  44858. totalWidth = jmax (totalWidth, ti->totalWidth);
  44859. }
  44860. }
  44861. }
  44862. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  44863. {
  44864. TreeViewItem* result = this;
  44865. TreeViewItem* item = this;
  44866. while (item->parentItem != 0)
  44867. {
  44868. item = item->parentItem;
  44869. if (! item->isOpen())
  44870. result = item;
  44871. }
  44872. return result;
  44873. }
  44874. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  44875. {
  44876. ownerView = newOwner;
  44877. for (int i = subItems.size(); --i >= 0;)
  44878. subItems.getUnchecked(i)->setOwnerView (newOwner);
  44879. }
  44880. int TreeViewItem::getIndentX() const throw()
  44881. {
  44882. const int indentWidth = ownerView->getIndentSize();
  44883. int x = ownerView->rootItemVisible ? indentWidth : 0;
  44884. if (! ownerView->openCloseButtonsVisible)
  44885. x -= indentWidth;
  44886. TreeViewItem* p = parentItem;
  44887. while (p != 0)
  44888. {
  44889. x += indentWidth;
  44890. p = p->parentItem;
  44891. }
  44892. return x;
  44893. }
  44894. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  44895. {
  44896. drawsInLeftMargin = canDrawInLeftMargin;
  44897. }
  44898. void TreeViewItem::paintRecursively (Graphics& g, int width)
  44899. {
  44900. jassert (ownerView != 0);
  44901. if (ownerView == 0)
  44902. return;
  44903. const int indent = getIndentX();
  44904. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  44905. g.setColour (ownerView->findColour (TreeView::linesColourId));
  44906. const float halfH = itemHeight * 0.5f;
  44907. int depth = 0;
  44908. TreeViewItem* p = parentItem;
  44909. while (p != 0)
  44910. {
  44911. ++depth;
  44912. p = p->parentItem;
  44913. }
  44914. if (! ownerView->rootItemVisible)
  44915. --depth;
  44916. const int indentWidth = ownerView->getIndentSize();
  44917. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  44918. {
  44919. float x = (depth + 0.5f) * indentWidth;
  44920. if (depth >= 0)
  44921. {
  44922. if (parentItem != 0 && parentItem->drawLinesInside)
  44923. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  44924. if ((parentItem != 0 && parentItem->drawLinesInside)
  44925. || (parentItem == 0 && drawLinesInside))
  44926. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  44927. }
  44928. p = parentItem;
  44929. int d = depth;
  44930. while (p != 0 && --d >= 0)
  44931. {
  44932. x -= (float) indentWidth;
  44933. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  44934. && ! p->isLastOfSiblings())
  44935. {
  44936. g.drawLine (x, 0, x, (float) itemHeight);
  44937. }
  44938. p = p->parentItem;
  44939. }
  44940. if (mightContainSubItems())
  44941. {
  44942. g.saveState();
  44943. g.setOrigin (depth * indentWidth, 0);
  44944. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  44945. paintOpenCloseButton (g, indentWidth, itemHeight,
  44946. static_cast <TreeViewContentComponent*> (ownerView->viewport->getViewedComponent())
  44947. ->isMouseOverButton (this));
  44948. g.restoreState();
  44949. }
  44950. }
  44951. {
  44952. g.saveState();
  44953. g.setOrigin (indent, 0);
  44954. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  44955. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  44956. paintItem (g, itemW, itemHeight);
  44957. g.restoreState();
  44958. }
  44959. if (isOpen())
  44960. {
  44961. const Rectangle<int> clip (g.getClipBounds());
  44962. for (int i = 0; i < subItems.size(); ++i)
  44963. {
  44964. TreeViewItem* const ti = subItems.getUnchecked(i);
  44965. const int relY = ti->y - y;
  44966. if (relY >= clip.getBottom())
  44967. break;
  44968. if (relY + ti->totalHeight >= clip.getY())
  44969. {
  44970. g.saveState();
  44971. g.setOrigin (0, relY);
  44972. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  44973. ti->paintRecursively (g, width);
  44974. g.restoreState();
  44975. }
  44976. }
  44977. }
  44978. }
  44979. bool TreeViewItem::isLastOfSiblings() const throw()
  44980. {
  44981. return parentItem == 0
  44982. || parentItem->subItems.getLast() == this;
  44983. }
  44984. int TreeViewItem::getIndexInParent() const throw()
  44985. {
  44986. if (parentItem == 0)
  44987. return 0;
  44988. return parentItem->subItems.indexOf (this);
  44989. }
  44990. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  44991. {
  44992. return (parentItem == 0) ? this
  44993. : parentItem->getTopLevelItem();
  44994. }
  44995. int TreeViewItem::getNumRows() const throw()
  44996. {
  44997. int num = 1;
  44998. if (isOpen())
  44999. {
  45000. for (int i = subItems.size(); --i >= 0;)
  45001. num += subItems.getUnchecked(i)->getNumRows();
  45002. }
  45003. return num;
  45004. }
  45005. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45006. {
  45007. if (index == 0)
  45008. return this;
  45009. if (index > 0 && isOpen())
  45010. {
  45011. --index;
  45012. for (int i = 0; i < subItems.size(); ++i)
  45013. {
  45014. TreeViewItem* const item = subItems.getUnchecked(i);
  45015. if (index == 0)
  45016. return item;
  45017. const int numRows = item->getNumRows();
  45018. if (numRows > index)
  45019. return item->getItemOnRow (index);
  45020. index -= numRows;
  45021. }
  45022. }
  45023. return 0;
  45024. }
  45025. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45026. {
  45027. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45028. {
  45029. const int h = itemHeight;
  45030. if (targetY < h)
  45031. return this;
  45032. if (isOpen())
  45033. {
  45034. targetY -= h;
  45035. for (int i = 0; i < subItems.size(); ++i)
  45036. {
  45037. TreeViewItem* const ti = subItems.getUnchecked(i);
  45038. if (targetY < ti->totalHeight)
  45039. return ti->findItemRecursively (targetY);
  45040. targetY -= ti->totalHeight;
  45041. }
  45042. }
  45043. }
  45044. return 0;
  45045. }
  45046. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45047. {
  45048. int total = 0;
  45049. if (isSelected())
  45050. ++total;
  45051. for (int i = subItems.size(); --i >= 0;)
  45052. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45053. return total;
  45054. }
  45055. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45056. {
  45057. if (isSelected())
  45058. {
  45059. if (index == 0)
  45060. return this;
  45061. --index;
  45062. }
  45063. if (index >= 0)
  45064. {
  45065. for (int i = 0; i < subItems.size(); ++i)
  45066. {
  45067. TreeViewItem* const item = subItems.getUnchecked(i);
  45068. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45069. if (found != 0)
  45070. return found;
  45071. index -= item->countSelectedItemsRecursively();
  45072. }
  45073. }
  45074. return 0;
  45075. }
  45076. int TreeViewItem::getRowNumberInTree() const throw()
  45077. {
  45078. if (parentItem != 0 && ownerView != 0)
  45079. {
  45080. int n = 1 + parentItem->getRowNumberInTree();
  45081. int ourIndex = parentItem->subItems.indexOf (this);
  45082. jassert (ourIndex >= 0);
  45083. while (--ourIndex >= 0)
  45084. n += parentItem->subItems [ourIndex]->getNumRows();
  45085. if (parentItem->parentItem == 0
  45086. && ! ownerView->rootItemVisible)
  45087. --n;
  45088. return n;
  45089. }
  45090. else
  45091. {
  45092. return 0;
  45093. }
  45094. }
  45095. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45096. {
  45097. drawLinesInside = drawLines;
  45098. }
  45099. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45100. {
  45101. if (recurse && isOpen() && subItems.size() > 0)
  45102. return subItems [0];
  45103. if (parentItem != 0)
  45104. {
  45105. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45106. if (nextIndex >= parentItem->subItems.size())
  45107. return parentItem->getNextVisibleItem (false);
  45108. return parentItem->subItems [nextIndex];
  45109. }
  45110. return 0;
  45111. }
  45112. const String TreeViewItem::getItemIdentifierString() const
  45113. {
  45114. String s;
  45115. if (parentItem != 0)
  45116. s = parentItem->getItemIdentifierString();
  45117. return s + "/" + getUniqueName().replaceCharacter ('/', '\\');
  45118. }
  45119. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45120. {
  45121. const String uid (getUniqueName());
  45122. if (uid == identifierString)
  45123. return this;
  45124. if (identifierString.startsWith (uid + "/"))
  45125. {
  45126. const String remainingPath (identifierString.substring (uid.length() + 1));
  45127. bool wasOpen = isOpen();
  45128. setOpen (true);
  45129. for (int i = subItems.size(); --i >= 0;)
  45130. {
  45131. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45132. if (item != 0)
  45133. return item;
  45134. }
  45135. setOpen (wasOpen);
  45136. }
  45137. return 0;
  45138. }
  45139. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45140. {
  45141. if (e.hasTagName ("CLOSED"))
  45142. {
  45143. setOpen (false);
  45144. }
  45145. else if (e.hasTagName ("OPEN"))
  45146. {
  45147. setOpen (true);
  45148. forEachXmlChildElement (e, n)
  45149. {
  45150. const String id (n->getStringAttribute ("id"));
  45151. for (int i = 0; i < subItems.size(); ++i)
  45152. {
  45153. TreeViewItem* const ti = subItems.getUnchecked(i);
  45154. if (ti->getUniqueName() == id)
  45155. {
  45156. ti->restoreOpennessState (*n);
  45157. break;
  45158. }
  45159. }
  45160. }
  45161. }
  45162. }
  45163. XmlElement* TreeViewItem::getOpennessState() const throw()
  45164. {
  45165. const String name (getUniqueName());
  45166. if (name.isNotEmpty())
  45167. {
  45168. XmlElement* e;
  45169. if (isOpen())
  45170. {
  45171. e = new XmlElement ("OPEN");
  45172. for (int i = 0; i < subItems.size(); ++i)
  45173. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45174. }
  45175. else
  45176. {
  45177. e = new XmlElement ("CLOSED");
  45178. }
  45179. e->setAttribute ("id", name);
  45180. return e;
  45181. }
  45182. else
  45183. {
  45184. // trying to save the openness for an element that has no name - this won't
  45185. // work because it needs the names to identify what to open.
  45186. jassertfalse
  45187. }
  45188. return 0;
  45189. }
  45190. END_JUCE_NAMESPACE
  45191. /*** End of inlined file: juce_TreeView.cpp ***/
  45192. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45193. BEGIN_JUCE_NAMESPACE
  45194. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45195. : fileList (listToShow)
  45196. {
  45197. }
  45198. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45199. {
  45200. }
  45201. FileBrowserListener::~FileBrowserListener()
  45202. {
  45203. }
  45204. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener)
  45205. {
  45206. listeners.add (listener);
  45207. }
  45208. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener)
  45209. {
  45210. listeners.remove (listener);
  45211. }
  45212. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45213. {
  45214. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45215. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45216. }
  45217. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45218. {
  45219. if (fileList.getDirectory().exists())
  45220. {
  45221. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45222. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45223. }
  45224. }
  45225. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45226. {
  45227. if (fileList.getDirectory().exists())
  45228. {
  45229. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45230. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45231. }
  45232. }
  45233. END_JUCE_NAMESPACE
  45234. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45235. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45236. BEGIN_JUCE_NAMESPACE
  45237. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45238. TimeSliceThread& thread_)
  45239. : fileFilter (fileFilter_),
  45240. thread (thread_),
  45241. fileTypeFlags (File::ignoreHiddenFiles | File::findFiles),
  45242. fileFindHandle (0),
  45243. shouldStop (true)
  45244. {
  45245. }
  45246. DirectoryContentsList::~DirectoryContentsList()
  45247. {
  45248. clear();
  45249. }
  45250. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45251. {
  45252. setTypeFlags (shouldIgnoreHiddenFiles ? (fileTypeFlags | File::ignoreHiddenFiles)
  45253. : (fileTypeFlags & ~File::ignoreHiddenFiles));
  45254. }
  45255. bool DirectoryContentsList::ignoresHiddenFiles() const
  45256. {
  45257. return (fileTypeFlags & File::ignoreHiddenFiles) != 0;
  45258. }
  45259. const File& DirectoryContentsList::getDirectory() const
  45260. {
  45261. return root;
  45262. }
  45263. void DirectoryContentsList::setDirectory (const File& directory,
  45264. const bool includeDirectories,
  45265. const bool includeFiles)
  45266. {
  45267. jassert (includeDirectories || includeFiles); // you have to speciify at least one of these!
  45268. if (directory != root)
  45269. {
  45270. clear();
  45271. root = directory;
  45272. // (this forces a refresh when setTypeFlags() is called, rather than triggering two refreshes)
  45273. fileTypeFlags &= ~(File::findDirectories | File::findFiles);
  45274. }
  45275. int newFlags = fileTypeFlags;
  45276. if (includeDirectories) newFlags |= File::findDirectories; else newFlags &= ~File::findDirectories;
  45277. if (includeFiles) newFlags |= File::findFiles; else newFlags &= ~File::findFiles;
  45278. setTypeFlags (newFlags);
  45279. }
  45280. void DirectoryContentsList::setTypeFlags (const int newFlags)
  45281. {
  45282. if (fileTypeFlags != newFlags)
  45283. {
  45284. fileTypeFlags = newFlags;
  45285. refresh();
  45286. }
  45287. }
  45288. void DirectoryContentsList::clear()
  45289. {
  45290. shouldStop = true;
  45291. thread.removeTimeSliceClient (this);
  45292. fileFindHandle = 0;
  45293. if (files.size() > 0)
  45294. {
  45295. files.clear();
  45296. changed();
  45297. }
  45298. }
  45299. void DirectoryContentsList::refresh()
  45300. {
  45301. clear();
  45302. if (root.isDirectory())
  45303. {
  45304. fileFindHandle = new DirectoryIterator (root, false, "*", fileTypeFlags);
  45305. shouldStop = false;
  45306. thread.addTimeSliceClient (this);
  45307. }
  45308. }
  45309. int DirectoryContentsList::getNumFiles() const
  45310. {
  45311. return files.size();
  45312. }
  45313. bool DirectoryContentsList::getFileInfo (const int index,
  45314. FileInfo& result) const
  45315. {
  45316. const ScopedLock sl (fileListLock);
  45317. const FileInfo* const info = files [index];
  45318. if (info != 0)
  45319. {
  45320. result = *info;
  45321. return true;
  45322. }
  45323. return false;
  45324. }
  45325. const File DirectoryContentsList::getFile (const int index) const
  45326. {
  45327. const ScopedLock sl (fileListLock);
  45328. const FileInfo* const info = files [index];
  45329. if (info != 0)
  45330. return root.getChildFile (info->filename);
  45331. return File::nonexistent;
  45332. }
  45333. bool DirectoryContentsList::isStillLoading() const
  45334. {
  45335. return fileFindHandle != 0;
  45336. }
  45337. void DirectoryContentsList::changed()
  45338. {
  45339. sendChangeMessage (this);
  45340. }
  45341. bool DirectoryContentsList::useTimeSlice()
  45342. {
  45343. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45344. bool hasChanged = false;
  45345. for (int i = 100; --i >= 0;)
  45346. {
  45347. if (! checkNextFile (hasChanged))
  45348. {
  45349. if (hasChanged)
  45350. changed();
  45351. return false;
  45352. }
  45353. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45354. break;
  45355. }
  45356. if (hasChanged)
  45357. changed();
  45358. return true;
  45359. }
  45360. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45361. {
  45362. if (fileFindHandle != 0)
  45363. {
  45364. bool fileFoundIsDir, isHidden, isReadOnly;
  45365. int64 fileSize;
  45366. Time modTime, creationTime;
  45367. if (fileFindHandle->next (&fileFoundIsDir, &isHidden, &fileSize,
  45368. &modTime, &creationTime, &isReadOnly))
  45369. {
  45370. if (addFile (fileFindHandle->getFile(), fileFoundIsDir,
  45371. fileSize, modTime, creationTime, isReadOnly))
  45372. {
  45373. hasChanged = true;
  45374. }
  45375. return true;
  45376. }
  45377. else
  45378. {
  45379. fileFindHandle = 0;
  45380. }
  45381. }
  45382. return false;
  45383. }
  45384. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45385. const DirectoryContentsList::FileInfo* const second)
  45386. {
  45387. #if JUCE_WINDOWS
  45388. if (first->isDirectory != second->isDirectory)
  45389. return first->isDirectory ? -1 : 1;
  45390. #endif
  45391. return first->filename.compareIgnoreCase (second->filename);
  45392. }
  45393. bool DirectoryContentsList::addFile (const File& file,
  45394. const bool isDir,
  45395. const int64 fileSize,
  45396. const Time& modTime,
  45397. const Time& creationTime,
  45398. const bool isReadOnly)
  45399. {
  45400. if (fileFilter == 0
  45401. || ((! isDir) && fileFilter->isFileSuitable (file))
  45402. || (isDir && fileFilter->isDirectorySuitable (file)))
  45403. {
  45404. ScopedPointer <FileInfo> info (new FileInfo());
  45405. info->filename = file.getFileName();
  45406. info->fileSize = fileSize;
  45407. info->modificationTime = modTime;
  45408. info->creationTime = creationTime;
  45409. info->isDirectory = isDir;
  45410. info->isReadOnly = isReadOnly;
  45411. const ScopedLock sl (fileListLock);
  45412. for (int i = files.size(); --i >= 0;)
  45413. if (files.getUnchecked(i)->filename == info->filename)
  45414. return false;
  45415. files.addSorted (*this, info.release());
  45416. return true;
  45417. }
  45418. return false;
  45419. }
  45420. END_JUCE_NAMESPACE
  45421. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45422. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45423. BEGIN_JUCE_NAMESPACE
  45424. FileBrowserComponent::FileBrowserComponent (int flags_,
  45425. const File& initialFileOrDirectory,
  45426. const FileFilter* fileFilter_,
  45427. FilePreviewComponent* previewComp_)
  45428. : FileFilter (String::empty),
  45429. fileFilter (fileFilter_),
  45430. flags (flags_),
  45431. previewComp (previewComp_),
  45432. thread ("Juce FileBrowser")
  45433. {
  45434. // You need to specify one or other of the open/save flags..
  45435. jassert ((flags & (saveMode | openMode)) != 0);
  45436. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45437. // You need to specify at least one of these flags..
  45438. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45439. String filename;
  45440. if (initialFileOrDirectory == File::nonexistent)
  45441. {
  45442. currentRoot = File::getCurrentWorkingDirectory();
  45443. }
  45444. else if (initialFileOrDirectory.isDirectory())
  45445. {
  45446. currentRoot = initialFileOrDirectory;
  45447. }
  45448. else
  45449. {
  45450. chosenFiles.add (initialFileOrDirectory);
  45451. currentRoot = initialFileOrDirectory.getParentDirectory();
  45452. filename = initialFileOrDirectory.getFileName();
  45453. }
  45454. fileList = new DirectoryContentsList (this, thread);
  45455. if ((flags & useTreeView) != 0)
  45456. {
  45457. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45458. if ((flags & canSelectMultipleItems) != 0)
  45459. tree->setMultiSelectEnabled (true);
  45460. addAndMakeVisible (tree);
  45461. fileListComponent = tree;
  45462. }
  45463. else
  45464. {
  45465. FileListComponent* const list = new FileListComponent (*fileList);
  45466. list->setOutlineThickness (1);
  45467. if ((flags & canSelectMultipleItems) != 0)
  45468. list->setMultipleSelectionEnabled (true);
  45469. addAndMakeVisible (list);
  45470. fileListComponent = list;
  45471. }
  45472. fileListComponent->addListener (this);
  45473. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45474. currentPathBox->setEditableText (true);
  45475. StringArray rootNames, rootPaths;
  45476. const BigInteger separators (getRoots (rootNames, rootPaths));
  45477. for (int i = 0; i < rootNames.size(); ++i)
  45478. {
  45479. if (separators [i])
  45480. currentPathBox->addSeparator();
  45481. currentPathBox->addItem (rootNames[i], i + 1);
  45482. }
  45483. currentPathBox->addSeparator();
  45484. currentPathBox->addListener (this);
  45485. addAndMakeVisible (filenameBox = new TextEditor());
  45486. filenameBox->setMultiLine (false);
  45487. filenameBox->setSelectAllWhenFocused (true);
  45488. filenameBox->setText (filename, false);
  45489. filenameBox->addListener (this);
  45490. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45491. Label* label = new Label ("f", TRANS("file:"));
  45492. addAndMakeVisible (label);
  45493. label->attachToComponent (filenameBox, true);
  45494. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45495. goUpButton->addButtonListener (this);
  45496. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45497. if (previewComp != 0)
  45498. addAndMakeVisible (previewComp);
  45499. setRoot (currentRoot);
  45500. thread.startThread (4);
  45501. }
  45502. FileBrowserComponent::~FileBrowserComponent()
  45503. {
  45504. if (previewComp != 0)
  45505. removeChildComponent (previewComp);
  45506. deleteAllChildren();
  45507. fileList = 0;
  45508. thread.stopThread (10000);
  45509. }
  45510. void FileBrowserComponent::addListener (FileBrowserListener* const newListener)
  45511. {
  45512. listeners.add (newListener);
  45513. }
  45514. void FileBrowserComponent::removeListener (FileBrowserListener* const listener)
  45515. {
  45516. listeners.remove (listener);
  45517. }
  45518. bool FileBrowserComponent::isSaveMode() const throw()
  45519. {
  45520. return (flags & saveMode) != 0;
  45521. }
  45522. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45523. {
  45524. if (chosenFiles.size() == 0 && currentFileIsValid())
  45525. return 1;
  45526. return chosenFiles.size();
  45527. }
  45528. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45529. {
  45530. if (! filenameBox->isReadOnly())
  45531. return currentRoot.getChildFile (filenameBox->getText());
  45532. else
  45533. return chosenFiles[index];
  45534. }
  45535. bool FileBrowserComponent::currentFileIsValid() const
  45536. {
  45537. if (isSaveMode())
  45538. return ! getSelectedFile (0).isDirectory();
  45539. else
  45540. return getSelectedFile (0).exists();
  45541. }
  45542. const File FileBrowserComponent::getHighlightedFile() const throw()
  45543. {
  45544. return fileListComponent->getSelectedFile (0);
  45545. }
  45546. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45547. {
  45548. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45549. : false;
  45550. }
  45551. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45552. {
  45553. return true;
  45554. }
  45555. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45556. {
  45557. if (f.isDirectory())
  45558. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45559. return (flags & canSelectFiles) != 0 && f.exists()
  45560. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45561. }
  45562. const File FileBrowserComponent::getRoot() const
  45563. {
  45564. return currentRoot;
  45565. }
  45566. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45567. {
  45568. if (currentRoot != newRootDirectory)
  45569. {
  45570. fileListComponent->scrollToTop();
  45571. String path (newRootDirectory.getFullPathName());
  45572. if (path.isEmpty())
  45573. path = File::separatorString;
  45574. StringArray rootNames, rootPaths;
  45575. getRoots (rootNames, rootPaths);
  45576. if (! rootPaths.contains (path, true))
  45577. {
  45578. bool alreadyListed = false;
  45579. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45580. {
  45581. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45582. {
  45583. alreadyListed = true;
  45584. break;
  45585. }
  45586. }
  45587. if (! alreadyListed)
  45588. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45589. }
  45590. }
  45591. currentRoot = newRootDirectory;
  45592. fileList->setDirectory (currentRoot, true, true);
  45593. String currentRootName (currentRoot.getFullPathName());
  45594. if (currentRootName.isEmpty())
  45595. currentRootName = File::separatorString;
  45596. currentPathBox->setText (currentRootName, true);
  45597. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45598. && currentRoot.getParentDirectory() != currentRoot);
  45599. }
  45600. void FileBrowserComponent::goUp()
  45601. {
  45602. setRoot (getRoot().getParentDirectory());
  45603. }
  45604. void FileBrowserComponent::refresh()
  45605. {
  45606. fileList->refresh();
  45607. }
  45608. const String FileBrowserComponent::getActionVerb() const
  45609. {
  45610. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45611. }
  45612. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45613. {
  45614. return previewComp;
  45615. }
  45616. void FileBrowserComponent::resized()
  45617. {
  45618. getLookAndFeel()
  45619. .layoutFileBrowserComponent (*this, fileListComponent,
  45620. previewComp, currentPathBox,
  45621. filenameBox, goUpButton);
  45622. }
  45623. void FileBrowserComponent::sendListenerChangeMessage()
  45624. {
  45625. Component::BailOutChecker checker (this);
  45626. if (previewComp != 0)
  45627. previewComp->selectedFileChanged (getSelectedFile (0));
  45628. // You shouldn't delete the browser when the file gets changed!
  45629. jassert (! checker.shouldBailOut());
  45630. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45631. }
  45632. void FileBrowserComponent::selectionChanged()
  45633. {
  45634. StringArray newFilenames;
  45635. bool resetChosenFiles = true;
  45636. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45637. {
  45638. const File f (fileListComponent->getSelectedFile (i));
  45639. if (isFileOrDirSuitable (f))
  45640. {
  45641. if (resetChosenFiles)
  45642. {
  45643. chosenFiles.clear();
  45644. resetChosenFiles = false;
  45645. }
  45646. chosenFiles.add (f);
  45647. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45648. }
  45649. }
  45650. if (newFilenames.size() > 0)
  45651. filenameBox->setText (newFilenames.joinIntoString (", "), false);
  45652. sendListenerChangeMessage();
  45653. }
  45654. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45655. {
  45656. Component::BailOutChecker checker (this);
  45657. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45658. }
  45659. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45660. {
  45661. if (f.isDirectory())
  45662. {
  45663. setRoot (f);
  45664. }
  45665. else
  45666. {
  45667. Component::BailOutChecker checker (this);
  45668. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45669. }
  45670. }
  45671. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45672. {
  45673. #if JUCE_LINUX || JUCE_WINDOWS
  45674. if (key.getModifiers().isCommandDown()
  45675. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45676. {
  45677. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45678. fileList->refresh();
  45679. return true;
  45680. }
  45681. #endif
  45682. return false;
  45683. }
  45684. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45685. {
  45686. sendListenerChangeMessage();
  45687. }
  45688. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45689. {
  45690. if (filenameBox->getText().containsChar (File::separator))
  45691. {
  45692. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45693. if (f.isDirectory())
  45694. {
  45695. setRoot (f);
  45696. chosenFiles.clear();
  45697. filenameBox->setText (String::empty);
  45698. }
  45699. else
  45700. {
  45701. setRoot (f.getParentDirectory());
  45702. chosenFiles.clear();
  45703. chosenFiles.add (f);
  45704. filenameBox->setText (f.getFileName());
  45705. }
  45706. }
  45707. else
  45708. {
  45709. fileDoubleClicked (getSelectedFile (0));
  45710. }
  45711. }
  45712. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45713. {
  45714. }
  45715. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  45716. {
  45717. if (! isSaveMode())
  45718. selectionChanged();
  45719. }
  45720. void FileBrowserComponent::buttonClicked (Button*)
  45721. {
  45722. goUp();
  45723. }
  45724. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  45725. {
  45726. const String newText (currentPathBox->getText().trim().unquoted());
  45727. if (newText.isNotEmpty())
  45728. {
  45729. const int index = currentPathBox->getSelectedId() - 1;
  45730. StringArray rootNames, rootPaths;
  45731. getRoots (rootNames, rootPaths);
  45732. if (rootPaths [index].isNotEmpty())
  45733. {
  45734. setRoot (File (rootPaths [index]));
  45735. }
  45736. else
  45737. {
  45738. File f (newText);
  45739. for (;;)
  45740. {
  45741. if (f.isDirectory())
  45742. {
  45743. setRoot (f);
  45744. break;
  45745. }
  45746. if (f.getParentDirectory() == f)
  45747. break;
  45748. f = f.getParentDirectory();
  45749. }
  45750. }
  45751. }
  45752. }
  45753. const BigInteger FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  45754. {
  45755. BigInteger separators;
  45756. #if JUCE_WINDOWS
  45757. Array<File> roots;
  45758. File::findFileSystemRoots (roots);
  45759. rootPaths.clear();
  45760. for (int i = 0; i < roots.size(); ++i)
  45761. {
  45762. const File& drive = roots.getReference(i);
  45763. String name (drive.getFullPathName());
  45764. rootPaths.add (name);
  45765. if (drive.isOnHardDisk())
  45766. {
  45767. String volume (drive.getVolumeLabel());
  45768. if (volume.isEmpty())
  45769. volume = TRANS("Hard Drive");
  45770. name << " [" << drive.getVolumeLabel() << ']';
  45771. }
  45772. else if (drive.isOnCDRomDrive())
  45773. {
  45774. name << TRANS(" [CD/DVD drive]");
  45775. }
  45776. rootNames.add (name);
  45777. }
  45778. separators.setBit (rootPaths.size());
  45779. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45780. rootNames.add ("Documents");
  45781. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45782. rootNames.add ("Desktop");
  45783. #endif
  45784. #if JUCE_MAC
  45785. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45786. rootNames.add ("Home folder");
  45787. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45788. rootNames.add ("Documents");
  45789. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45790. rootNames.add ("Desktop");
  45791. separators.setBit (rootPaths.size());
  45792. Array <File> volumes;
  45793. File vol ("/Volumes");
  45794. vol.findChildFiles (volumes, File::findDirectories, false);
  45795. for (int i = 0; i < volumes.size(); ++i)
  45796. {
  45797. const File& volume = volumes.getReference(i);
  45798. if (volume.isDirectory() && ! volume.getFileName().startsWithChar ('.'))
  45799. {
  45800. rootPaths.add (volume.getFullPathName());
  45801. rootNames.add (volume.getFileName());
  45802. }
  45803. }
  45804. #endif
  45805. #if JUCE_LINUX
  45806. rootPaths.add ("/");
  45807. rootNames.add ("/");
  45808. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45809. rootNames.add ("Home folder");
  45810. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45811. rootNames.add ("Desktop");
  45812. #endif
  45813. return separators;
  45814. }
  45815. END_JUCE_NAMESPACE
  45816. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  45817. /*** Start of inlined file: juce_FileChooser.cpp ***/
  45818. BEGIN_JUCE_NAMESPACE
  45819. FileChooser::FileChooser (const String& chooserBoxTitle,
  45820. const File& currentFileOrDirectory,
  45821. const String& fileFilters,
  45822. const bool useNativeDialogBox_)
  45823. : title (chooserBoxTitle),
  45824. filters (fileFilters),
  45825. startingFile (currentFileOrDirectory),
  45826. useNativeDialogBox (useNativeDialogBox_)
  45827. {
  45828. #if JUCE_LINUX
  45829. useNativeDialogBox = false;
  45830. #endif
  45831. if (! fileFilters.containsNonWhitespaceChars())
  45832. filters = "*";
  45833. }
  45834. FileChooser::~FileChooser()
  45835. {
  45836. }
  45837. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  45838. {
  45839. return showDialog (false, true, false, false, false, previewComponent);
  45840. }
  45841. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  45842. {
  45843. return showDialog (false, true, false, false, true, previewComponent);
  45844. }
  45845. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  45846. {
  45847. return showDialog (true, true, false, false, true, previewComponent);
  45848. }
  45849. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  45850. {
  45851. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  45852. }
  45853. bool FileChooser::browseForDirectory()
  45854. {
  45855. return showDialog (true, false, false, false, false, 0);
  45856. }
  45857. const File FileChooser::getResult() const
  45858. {
  45859. // if you've used a multiple-file select, you should use the getResults() method
  45860. // to retrieve all the files that were chosen.
  45861. jassert (results.size() <= 1);
  45862. return results.getFirst();
  45863. }
  45864. const Array<File>& FileChooser::getResults() const
  45865. {
  45866. return results;
  45867. }
  45868. bool FileChooser::showDialog (const bool selectsDirectories,
  45869. const bool selectsFiles,
  45870. const bool isSave,
  45871. const bool warnAboutOverwritingExistingFiles,
  45872. const bool selectMultipleFiles,
  45873. FilePreviewComponent* const previewComponent)
  45874. {
  45875. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  45876. results.clear();
  45877. // the preview component needs to be the right size before you pass it in here..
  45878. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  45879. && previewComponent->getHeight() > 10));
  45880. #if JUCE_WINDOWS
  45881. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  45882. #elif JUCE_MAC
  45883. if (useNativeDialogBox && (previewComponent == 0))
  45884. #else
  45885. if (false)
  45886. #endif
  45887. {
  45888. showPlatformDialog (results, title, startingFile, filters,
  45889. selectsDirectories, selectsFiles, isSave,
  45890. warnAboutOverwritingExistingFiles,
  45891. selectMultipleFiles,
  45892. previewComponent);
  45893. }
  45894. else
  45895. {
  45896. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  45897. selectsDirectories ? "*" : String::empty,
  45898. String::empty);
  45899. int flags = isSave ? FileBrowserComponent::saveMode
  45900. : FileBrowserComponent::openMode;
  45901. if (selectsFiles)
  45902. flags |= FileBrowserComponent::canSelectFiles;
  45903. if (selectsDirectories)
  45904. flags |= FileBrowserComponent::canSelectDirectories;
  45905. if (selectMultipleFiles)
  45906. flags |= FileBrowserComponent::canSelectMultipleItems;
  45907. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  45908. FileChooserDialogBox box (title, String::empty,
  45909. browserComponent,
  45910. warnAboutOverwritingExistingFiles,
  45911. browserComponent.findColour (AlertWindow::backgroundColourId));
  45912. if (box.show())
  45913. {
  45914. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  45915. results.add (browserComponent.getSelectedFile (i));
  45916. }
  45917. }
  45918. if (previouslyFocused != 0)
  45919. previouslyFocused->grabKeyboardFocus();
  45920. return results.size() > 0;
  45921. }
  45922. FilePreviewComponent::FilePreviewComponent()
  45923. {
  45924. }
  45925. FilePreviewComponent::~FilePreviewComponent()
  45926. {
  45927. }
  45928. END_JUCE_NAMESPACE
  45929. /*** End of inlined file: juce_FileChooser.cpp ***/
  45930. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  45931. BEGIN_JUCE_NAMESPACE
  45932. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  45933. const String& instructions,
  45934. FileBrowserComponent& chooserComponent,
  45935. const bool warnAboutOverwritingExistingFiles_,
  45936. const Colour& backgroundColour)
  45937. : ResizableWindow (name, backgroundColour, true),
  45938. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  45939. {
  45940. content = new ContentComponent();
  45941. content->setName (name);
  45942. content->instructions = instructions;
  45943. content->chooserComponent = &chooserComponent;
  45944. content->addAndMakeVisible (&chooserComponent);
  45945. content->okButton = new TextButton (chooserComponent.getActionVerb());
  45946. content->addAndMakeVisible (content->okButton);
  45947. content->okButton->addButtonListener (this);
  45948. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  45949. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  45950. content->cancelButton = new TextButton (TRANS("Cancel"));
  45951. content->addAndMakeVisible (content->cancelButton);
  45952. content->cancelButton->addButtonListener (this);
  45953. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  45954. setContentComponent (content);
  45955. setResizable (true, true);
  45956. setResizeLimits (300, 300, 1200, 1000);
  45957. content->chooserComponent->addListener (this);
  45958. }
  45959. FileChooserDialogBox::~FileChooserDialogBox()
  45960. {
  45961. content->chooserComponent->removeListener (this);
  45962. }
  45963. bool FileChooserDialogBox::show (int w, int h)
  45964. {
  45965. if (w <= 0)
  45966. {
  45967. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  45968. if (previewComp != 0)
  45969. w = 400 + previewComp->getWidth();
  45970. else
  45971. w = 600;
  45972. }
  45973. if (h <= 0)
  45974. h = 500;
  45975. centreWithSize (w, h);
  45976. const bool ok = (runModalLoop() != 0);
  45977. setVisible (false);
  45978. return ok;
  45979. }
  45980. void FileChooserDialogBox::buttonClicked (Button* button)
  45981. {
  45982. if (button == content->okButton)
  45983. {
  45984. if (warnAboutOverwritingExistingFiles
  45985. && content->chooserComponent->isSaveMode()
  45986. && content->chooserComponent->getSelectedFile(0).exists())
  45987. {
  45988. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  45989. TRANS("File already exists"),
  45990. TRANS("There's already a file called:")
  45991. + "\n\n" + content->chooserComponent->getSelectedFile(0).getFullPathName()
  45992. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  45993. TRANS("overwrite"),
  45994. TRANS("cancel")))
  45995. {
  45996. return;
  45997. }
  45998. }
  45999. exitModalState (1);
  46000. }
  46001. else if (button == content->cancelButton)
  46002. closeButtonPressed();
  46003. }
  46004. void FileChooserDialogBox::closeButtonPressed()
  46005. {
  46006. setVisible (false);
  46007. }
  46008. void FileChooserDialogBox::selectionChanged()
  46009. {
  46010. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46011. }
  46012. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46013. {
  46014. }
  46015. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46016. {
  46017. selectionChanged();
  46018. content->okButton->triggerClick();
  46019. }
  46020. FileChooserDialogBox::ContentComponent::ContentComponent()
  46021. {
  46022. setInterceptsMouseClicks (false, true);
  46023. }
  46024. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46025. {
  46026. delete okButton;
  46027. delete cancelButton;
  46028. }
  46029. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46030. {
  46031. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46032. text.draw (g);
  46033. }
  46034. void FileChooserDialogBox::ContentComponent::resized()
  46035. {
  46036. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46037. const Rectangle<float> bb (text.getBoundingBox (0, text.getNumGlyphs(), false));
  46038. const int y = roundToInt (bb.getBottom()) + 10;
  46039. const int buttonHeight = 26;
  46040. const int buttonY = getHeight() - buttonHeight - 8;
  46041. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46042. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46043. proportionOfWidth (0.2f), buttonHeight);
  46044. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46045. proportionOfWidth (0.2f), buttonHeight);
  46046. }
  46047. END_JUCE_NAMESPACE
  46048. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46049. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46050. BEGIN_JUCE_NAMESPACE
  46051. FileFilter::FileFilter (const String& filterDescription)
  46052. : description (filterDescription)
  46053. {
  46054. }
  46055. FileFilter::~FileFilter()
  46056. {
  46057. }
  46058. const String& FileFilter::getDescription() const throw()
  46059. {
  46060. return description;
  46061. }
  46062. END_JUCE_NAMESPACE
  46063. /*** End of inlined file: juce_FileFilter.cpp ***/
  46064. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46065. BEGIN_JUCE_NAMESPACE
  46066. Image* juce_createIconForFile (const File& file);
  46067. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46068. : ListBox (String::empty, 0),
  46069. DirectoryContentsDisplayComponent (listToShow)
  46070. {
  46071. setModel (this);
  46072. fileList.addChangeListener (this);
  46073. }
  46074. FileListComponent::~FileListComponent()
  46075. {
  46076. fileList.removeChangeListener (this);
  46077. deleteAllChildren();
  46078. }
  46079. int FileListComponent::getNumSelectedFiles() const
  46080. {
  46081. return getNumSelectedRows();
  46082. }
  46083. const File FileListComponent::getSelectedFile (int index) const
  46084. {
  46085. return fileList.getFile (getSelectedRow (index));
  46086. }
  46087. void FileListComponent::scrollToTop()
  46088. {
  46089. getVerticalScrollBar()->setCurrentRangeStart (0);
  46090. }
  46091. void FileListComponent::changeListenerCallback (void*)
  46092. {
  46093. updateContent();
  46094. if (lastDirectory != fileList.getDirectory())
  46095. {
  46096. lastDirectory = fileList.getDirectory();
  46097. deselectAllRows();
  46098. }
  46099. }
  46100. class FileListItemComponent : public Component,
  46101. public TimeSliceClient,
  46102. public AsyncUpdater
  46103. {
  46104. public:
  46105. FileListItemComponent (FileListComponent& owner_, TimeSliceThread& thread_)
  46106. : owner (owner_), thread (thread_),
  46107. highlighted (false), index (0), icon (0)
  46108. {
  46109. }
  46110. ~FileListItemComponent()
  46111. {
  46112. thread.removeTimeSliceClient (this);
  46113. clearIcon();
  46114. }
  46115. void paint (Graphics& g)
  46116. {
  46117. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46118. file.getFileName(),
  46119. icon,
  46120. fileSize, modTime,
  46121. isDirectory, highlighted,
  46122. index);
  46123. }
  46124. void mouseDown (const MouseEvent& e)
  46125. {
  46126. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46127. owner.sendMouseClickMessage (file, e);
  46128. }
  46129. void mouseDoubleClick (const MouseEvent&)
  46130. {
  46131. owner.sendDoubleClickMessage (file);
  46132. }
  46133. void update (const File& root,
  46134. const DirectoryContentsList::FileInfo* const fileInfo,
  46135. const int index_,
  46136. const bool highlighted_)
  46137. {
  46138. thread.removeTimeSliceClient (this);
  46139. if (highlighted_ != highlighted
  46140. || index_ != index)
  46141. {
  46142. index = index_;
  46143. highlighted = highlighted_;
  46144. repaint();
  46145. }
  46146. File newFile;
  46147. String newFileSize;
  46148. String newModTime;
  46149. if (fileInfo != 0)
  46150. {
  46151. newFile = root.getChildFile (fileInfo->filename);
  46152. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46153. newModTime = fileInfo->modificationTime.formatted ("%d %b '%y %H:%M");
  46154. }
  46155. if (newFile != file
  46156. || fileSize != newFileSize
  46157. || modTime != newModTime)
  46158. {
  46159. file = newFile;
  46160. fileSize = newFileSize;
  46161. modTime = newModTime;
  46162. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46163. repaint();
  46164. clearIcon();
  46165. }
  46166. if (file != File::nonexistent
  46167. && icon == 0 && ! isDirectory)
  46168. {
  46169. updateIcon (true);
  46170. if (icon == 0)
  46171. thread.addTimeSliceClient (this);
  46172. }
  46173. }
  46174. bool useTimeSlice()
  46175. {
  46176. updateIcon (false);
  46177. return false;
  46178. }
  46179. void handleAsyncUpdate()
  46180. {
  46181. repaint();
  46182. }
  46183. juce_UseDebuggingNewOperator
  46184. private:
  46185. FileListComponent& owner;
  46186. TimeSliceThread& thread;
  46187. bool highlighted;
  46188. int index;
  46189. File file;
  46190. String fileSize;
  46191. String modTime;
  46192. Image* icon;
  46193. bool isDirectory;
  46194. void clearIcon()
  46195. {
  46196. ImageCache::release (icon);
  46197. icon = 0;
  46198. }
  46199. void updateIcon (const bool onlyUpdateIfCached)
  46200. {
  46201. if (icon == 0)
  46202. {
  46203. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46204. Image* im = ImageCache::getFromHashCode (hashCode);
  46205. if (im == 0 && ! onlyUpdateIfCached)
  46206. {
  46207. im = juce_createIconForFile (file);
  46208. if (im != 0)
  46209. ImageCache::addImageToCache (im, hashCode);
  46210. }
  46211. if (im != 0)
  46212. {
  46213. icon = im;
  46214. triggerAsyncUpdate();
  46215. }
  46216. }
  46217. }
  46218. };
  46219. int FileListComponent::getNumRows()
  46220. {
  46221. return fileList.getNumFiles();
  46222. }
  46223. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46224. {
  46225. }
  46226. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46227. {
  46228. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46229. if (comp == 0)
  46230. {
  46231. delete existingComponentToUpdate;
  46232. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46233. }
  46234. DirectoryContentsList::FileInfo fileInfo;
  46235. if (fileList.getFileInfo (row, fileInfo))
  46236. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46237. else
  46238. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46239. return comp;
  46240. }
  46241. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46242. {
  46243. sendSelectionChangeMessage();
  46244. }
  46245. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46246. {
  46247. }
  46248. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46249. {
  46250. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46251. }
  46252. END_JUCE_NAMESPACE
  46253. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46254. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46255. BEGIN_JUCE_NAMESPACE
  46256. FilenameComponent::FilenameComponent (const String& name,
  46257. const File& currentFile,
  46258. const bool canEditFilename,
  46259. const bool isDirectory,
  46260. const bool isForSaving,
  46261. const String& fileBrowserWildcard,
  46262. const String& enforcedSuffix_,
  46263. const String& textWhenNothingSelected)
  46264. : Component (name),
  46265. maxRecentFiles (30),
  46266. isDir (isDirectory),
  46267. isSaving (isForSaving),
  46268. isFileDragOver (false),
  46269. wildcard (fileBrowserWildcard),
  46270. enforcedSuffix (enforcedSuffix_)
  46271. {
  46272. addAndMakeVisible (filenameBox = new ComboBox ("fn"));
  46273. filenameBox->setEditableText (canEditFilename);
  46274. filenameBox->addListener (this);
  46275. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46276. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46277. browseButton = 0;
  46278. setBrowseButtonText ("...");
  46279. setCurrentFile (currentFile, true);
  46280. }
  46281. FilenameComponent::~FilenameComponent()
  46282. {
  46283. deleteAllChildren();
  46284. }
  46285. void FilenameComponent::paintOverChildren (Graphics& g)
  46286. {
  46287. if (isFileDragOver)
  46288. {
  46289. g.setColour (Colours::red.withAlpha (0.2f));
  46290. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46291. }
  46292. }
  46293. void FilenameComponent::resized()
  46294. {
  46295. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46296. }
  46297. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46298. {
  46299. browseButtonText = newBrowseButtonText;
  46300. lookAndFeelChanged();
  46301. }
  46302. void FilenameComponent::lookAndFeelChanged()
  46303. {
  46304. deleteAndZero (browseButton);
  46305. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46306. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46307. resized();
  46308. browseButton->addButtonListener (this);
  46309. }
  46310. void FilenameComponent::setTooltip (const String& newTooltip)
  46311. {
  46312. SettableTooltipClient::setTooltip (newTooltip);
  46313. filenameBox->setTooltip (newTooltip);
  46314. }
  46315. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46316. {
  46317. defaultBrowseFile = newDefaultDirectory;
  46318. }
  46319. void FilenameComponent::buttonClicked (Button*)
  46320. {
  46321. FileChooser fc (TRANS("Choose a new file"),
  46322. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46323. : getCurrentFile(),
  46324. wildcard);
  46325. if (isDir ? fc.browseForDirectory()
  46326. : (isSaving ? fc.browseForFileToSave (false)
  46327. : fc.browseForFileToOpen()))
  46328. {
  46329. setCurrentFile (fc.getResult(), true);
  46330. }
  46331. }
  46332. void FilenameComponent::comboBoxChanged (ComboBox*)
  46333. {
  46334. setCurrentFile (getCurrentFile(), true);
  46335. }
  46336. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46337. {
  46338. return true;
  46339. }
  46340. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46341. {
  46342. isFileDragOver = false;
  46343. repaint();
  46344. const File f (filenames[0]);
  46345. if (f.exists() && (f.isDirectory() == isDir))
  46346. setCurrentFile (f, true);
  46347. }
  46348. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46349. {
  46350. isFileDragOver = true;
  46351. repaint();
  46352. }
  46353. void FilenameComponent::fileDragExit (const StringArray&)
  46354. {
  46355. isFileDragOver = false;
  46356. repaint();
  46357. }
  46358. const File FilenameComponent::getCurrentFile() const
  46359. {
  46360. File f (filenameBox->getText());
  46361. if (enforcedSuffix.isNotEmpty())
  46362. f = f.withFileExtension (enforcedSuffix);
  46363. return f;
  46364. }
  46365. void FilenameComponent::setCurrentFile (File newFile,
  46366. const bool addToRecentlyUsedList,
  46367. const bool sendChangeNotification)
  46368. {
  46369. if (enforcedSuffix.isNotEmpty())
  46370. newFile = newFile.withFileExtension (enforcedSuffix);
  46371. if (newFile.getFullPathName() != lastFilename)
  46372. {
  46373. lastFilename = newFile.getFullPathName();
  46374. if (addToRecentlyUsedList)
  46375. addRecentlyUsedFile (newFile);
  46376. filenameBox->setText (lastFilename, true);
  46377. if (sendChangeNotification)
  46378. triggerAsyncUpdate();
  46379. }
  46380. }
  46381. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46382. {
  46383. filenameBox->setEditableText (shouldBeEditable);
  46384. }
  46385. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46386. {
  46387. StringArray names;
  46388. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46389. names.add (filenameBox->getItemText (i));
  46390. return names;
  46391. }
  46392. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46393. {
  46394. if (filenames != getRecentlyUsedFilenames())
  46395. {
  46396. filenameBox->clear();
  46397. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46398. filenameBox->addItem (filenames[i], i + 1);
  46399. }
  46400. }
  46401. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46402. {
  46403. maxRecentFiles = jmax (1, newMaximum);
  46404. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46405. }
  46406. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46407. {
  46408. StringArray files (getRecentlyUsedFilenames());
  46409. if (file.getFullPathName().isNotEmpty())
  46410. {
  46411. files.removeString (file.getFullPathName(), true);
  46412. files.insert (0, file.getFullPathName());
  46413. setRecentlyUsedFilenames (files);
  46414. }
  46415. }
  46416. void FilenameComponent::addListener (FilenameComponentListener* const listener)
  46417. {
  46418. listeners.add (listener);
  46419. }
  46420. void FilenameComponent::removeListener (FilenameComponentListener* const listener)
  46421. {
  46422. listeners.remove (listener);
  46423. }
  46424. void FilenameComponent::handleAsyncUpdate()
  46425. {
  46426. Component::BailOutChecker checker (this);
  46427. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46428. }
  46429. END_JUCE_NAMESPACE
  46430. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46431. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46432. BEGIN_JUCE_NAMESPACE
  46433. FileSearchPathListComponent::FileSearchPathListComponent()
  46434. {
  46435. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46436. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46437. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46438. listBox->setOutlineThickness (1);
  46439. addAndMakeVisible (addButton = new TextButton ("+"));
  46440. addButton->addButtonListener (this);
  46441. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46442. addAndMakeVisible (removeButton = new TextButton ("-"));
  46443. removeButton->addButtonListener (this);
  46444. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46445. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46446. changeButton->addButtonListener (this);
  46447. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46448. upButton->addButtonListener (this);
  46449. {
  46450. Path arrowPath;
  46451. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46452. DrawablePath arrowImage;
  46453. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46454. arrowImage.setPath (arrowPath);
  46455. upButton->setImages (&arrowImage);
  46456. }
  46457. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46458. downButton->addButtonListener (this);
  46459. {
  46460. Path arrowPath;
  46461. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46462. DrawablePath arrowImage;
  46463. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46464. arrowImage.setPath (arrowPath);
  46465. downButton->setImages (&arrowImage);
  46466. }
  46467. updateButtons();
  46468. }
  46469. FileSearchPathListComponent::~FileSearchPathListComponent()
  46470. {
  46471. deleteAllChildren();
  46472. }
  46473. void FileSearchPathListComponent::updateButtons()
  46474. {
  46475. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46476. removeButton->setEnabled (anythingSelected);
  46477. changeButton->setEnabled (anythingSelected);
  46478. upButton->setEnabled (anythingSelected);
  46479. downButton->setEnabled (anythingSelected);
  46480. }
  46481. void FileSearchPathListComponent::changed()
  46482. {
  46483. listBox->updateContent();
  46484. listBox->repaint();
  46485. updateButtons();
  46486. }
  46487. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46488. {
  46489. if (newPath.toString() != path.toString())
  46490. {
  46491. path = newPath;
  46492. changed();
  46493. }
  46494. }
  46495. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46496. {
  46497. defaultBrowseTarget = newDefaultDirectory;
  46498. }
  46499. int FileSearchPathListComponent::getNumRows()
  46500. {
  46501. return path.getNumPaths();
  46502. }
  46503. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46504. {
  46505. if (rowIsSelected)
  46506. g.fillAll (findColour (TextEditor::highlightColourId));
  46507. g.setColour (findColour (ListBox::textColourId));
  46508. Font f (height * 0.7f);
  46509. f.setHorizontalScale (0.9f);
  46510. g.setFont (f);
  46511. g.drawText (path [rowNumber].getFullPathName(),
  46512. 4, 0, width - 6, height,
  46513. Justification::centredLeft, true);
  46514. }
  46515. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46516. {
  46517. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46518. {
  46519. path.remove (row);
  46520. changed();
  46521. }
  46522. }
  46523. void FileSearchPathListComponent::returnKeyPressed (int row)
  46524. {
  46525. FileChooser chooser (TRANS("Change folder..."), path [row], "*");
  46526. if (chooser.browseForDirectory())
  46527. {
  46528. path.remove (row);
  46529. path.add (chooser.getResult(), row);
  46530. changed();
  46531. }
  46532. }
  46533. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46534. {
  46535. returnKeyPressed (row);
  46536. }
  46537. void FileSearchPathListComponent::selectedRowsChanged (int)
  46538. {
  46539. updateButtons();
  46540. }
  46541. void FileSearchPathListComponent::paint (Graphics& g)
  46542. {
  46543. g.fillAll (findColour (backgroundColourId));
  46544. }
  46545. void FileSearchPathListComponent::resized()
  46546. {
  46547. const int buttonH = 22;
  46548. const int buttonY = getHeight() - buttonH - 4;
  46549. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46550. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46551. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46552. changeButton->changeWidthToFitText (buttonH);
  46553. downButton->setSize (buttonH * 2, buttonH);
  46554. upButton->setSize (buttonH * 2, buttonH);
  46555. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46556. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46557. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46558. }
  46559. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46560. {
  46561. return true;
  46562. }
  46563. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46564. {
  46565. for (int i = filenames.size(); --i >= 0;)
  46566. {
  46567. const File f (filenames[i]);
  46568. if (f.isDirectory())
  46569. {
  46570. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46571. path.add (f, row);
  46572. changed();
  46573. }
  46574. }
  46575. }
  46576. void FileSearchPathListComponent::buttonClicked (Button* button)
  46577. {
  46578. const int currentRow = listBox->getSelectedRow();
  46579. if (button == removeButton)
  46580. {
  46581. deleteKeyPressed (currentRow);
  46582. }
  46583. else if (button == addButton)
  46584. {
  46585. File start (defaultBrowseTarget);
  46586. if (start == File::nonexistent)
  46587. start = path [0];
  46588. if (start == File::nonexistent)
  46589. start = File::getCurrentWorkingDirectory();
  46590. FileChooser chooser (TRANS("Add a folder..."), start, "*");
  46591. if (chooser.browseForDirectory())
  46592. {
  46593. path.add (chooser.getResult(), currentRow);
  46594. }
  46595. }
  46596. else if (button == changeButton)
  46597. {
  46598. returnKeyPressed (currentRow);
  46599. }
  46600. else if (button == upButton)
  46601. {
  46602. if (currentRow > 0 && currentRow < path.getNumPaths())
  46603. {
  46604. const File f (path[currentRow]);
  46605. path.remove (currentRow);
  46606. path.add (f, currentRow - 1);
  46607. listBox->selectRow (currentRow - 1);
  46608. }
  46609. }
  46610. else if (button == downButton)
  46611. {
  46612. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46613. {
  46614. const File f (path[currentRow]);
  46615. path.remove (currentRow);
  46616. path.add (f, currentRow + 1);
  46617. listBox->selectRow (currentRow + 1);
  46618. }
  46619. }
  46620. changed();
  46621. }
  46622. END_JUCE_NAMESPACE
  46623. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46624. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46625. BEGIN_JUCE_NAMESPACE
  46626. Image* juce_createIconForFile (const File& file);
  46627. class FileListTreeItem : public TreeViewItem,
  46628. public TimeSliceClient,
  46629. public AsyncUpdater,
  46630. public ChangeListener
  46631. {
  46632. public:
  46633. FileListTreeItem (FileTreeComponent& owner_,
  46634. DirectoryContentsList* const parentContentsList_,
  46635. const int indexInContentsList_,
  46636. const File& file_,
  46637. TimeSliceThread& thread_)
  46638. : file (file_),
  46639. owner (owner_),
  46640. parentContentsList (parentContentsList_),
  46641. indexInContentsList (indexInContentsList_),
  46642. subContentsList (0),
  46643. canDeleteSubContentsList (false),
  46644. thread (thread_),
  46645. icon (0)
  46646. {
  46647. DirectoryContentsList::FileInfo fileInfo;
  46648. if (parentContentsList_ != 0
  46649. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46650. {
  46651. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46652. modTime = fileInfo.modificationTime.formatted ("%d %b '%y %H:%M");
  46653. isDirectory = fileInfo.isDirectory;
  46654. }
  46655. else
  46656. {
  46657. isDirectory = true;
  46658. }
  46659. }
  46660. ~FileListTreeItem()
  46661. {
  46662. thread.removeTimeSliceClient (this);
  46663. clearSubItems();
  46664. ImageCache::release (icon);
  46665. if (canDeleteSubContentsList)
  46666. delete subContentsList;
  46667. }
  46668. bool mightContainSubItems() { return isDirectory; }
  46669. const String getUniqueName() const { return file.getFullPathName(); }
  46670. int getItemHeight() const { return 22; }
  46671. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46672. void itemOpennessChanged (bool isNowOpen)
  46673. {
  46674. if (isNowOpen)
  46675. {
  46676. clearSubItems();
  46677. isDirectory = file.isDirectory();
  46678. if (isDirectory)
  46679. {
  46680. if (subContentsList == 0)
  46681. {
  46682. jassert (parentContentsList != 0);
  46683. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46684. l->setDirectory (file, true, true);
  46685. setSubContentsList (l);
  46686. canDeleteSubContentsList = true;
  46687. }
  46688. changeListenerCallback (0);
  46689. }
  46690. }
  46691. }
  46692. void setSubContentsList (DirectoryContentsList* newList)
  46693. {
  46694. jassert (subContentsList == 0);
  46695. subContentsList = newList;
  46696. newList->addChangeListener (this);
  46697. }
  46698. void changeListenerCallback (void*)
  46699. {
  46700. clearSubItems();
  46701. if (isOpen() && subContentsList != 0)
  46702. {
  46703. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46704. {
  46705. FileListTreeItem* const item
  46706. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46707. addSubItem (item);
  46708. }
  46709. }
  46710. }
  46711. void paintItem (Graphics& g, int width, int height)
  46712. {
  46713. if (file != File::nonexistent)
  46714. {
  46715. updateIcon (true);
  46716. if (icon == 0)
  46717. thread.addTimeSliceClient (this);
  46718. }
  46719. owner.getLookAndFeel()
  46720. .drawFileBrowserRow (g, width, height,
  46721. file.getFileName(),
  46722. icon,
  46723. fileSize, modTime,
  46724. isDirectory, isSelected(),
  46725. indexInContentsList);
  46726. }
  46727. void itemClicked (const MouseEvent& e)
  46728. {
  46729. owner.sendMouseClickMessage (file, e);
  46730. }
  46731. void itemDoubleClicked (const MouseEvent& e)
  46732. {
  46733. TreeViewItem::itemDoubleClicked (e);
  46734. owner.sendDoubleClickMessage (file);
  46735. }
  46736. void itemSelectionChanged (bool)
  46737. {
  46738. owner.sendSelectionChangeMessage();
  46739. }
  46740. bool useTimeSlice()
  46741. {
  46742. updateIcon (false);
  46743. thread.removeTimeSliceClient (this);
  46744. return false;
  46745. }
  46746. void handleAsyncUpdate()
  46747. {
  46748. owner.repaint();
  46749. }
  46750. const File file;
  46751. juce_UseDebuggingNewOperator
  46752. private:
  46753. FileTreeComponent& owner;
  46754. DirectoryContentsList* parentContentsList;
  46755. int indexInContentsList;
  46756. DirectoryContentsList* subContentsList;
  46757. bool isDirectory, canDeleteSubContentsList;
  46758. TimeSliceThread& thread;
  46759. Image* icon;
  46760. String fileSize;
  46761. String modTime;
  46762. void updateIcon (const bool onlyUpdateIfCached)
  46763. {
  46764. if (icon == 0)
  46765. {
  46766. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46767. Image* im = ImageCache::getFromHashCode (hashCode);
  46768. if (im == 0 && ! onlyUpdateIfCached)
  46769. {
  46770. im = juce_createIconForFile (file);
  46771. if (im != 0)
  46772. ImageCache::addImageToCache (im, hashCode);
  46773. }
  46774. if (im != 0)
  46775. {
  46776. icon = im;
  46777. triggerAsyncUpdate();
  46778. }
  46779. }
  46780. }
  46781. };
  46782. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  46783. : DirectoryContentsDisplayComponent (listToShow)
  46784. {
  46785. FileListTreeItem* const root
  46786. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  46787. listToShow.getTimeSliceThread());
  46788. root->setSubContentsList (&listToShow);
  46789. setRootItemVisible (false);
  46790. setRootItem (root);
  46791. }
  46792. FileTreeComponent::~FileTreeComponent()
  46793. {
  46794. deleteRootItem();
  46795. }
  46796. const File FileTreeComponent::getSelectedFile (const int index) const
  46797. {
  46798. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  46799. if (item != 0)
  46800. return item->file;
  46801. return File::nonexistent;
  46802. }
  46803. void FileTreeComponent::scrollToTop()
  46804. {
  46805. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  46806. }
  46807. void FileTreeComponent::setDragAndDropDescription (const String& description)
  46808. {
  46809. dragAndDropDescription = description;
  46810. }
  46811. END_JUCE_NAMESPACE
  46812. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  46813. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  46814. BEGIN_JUCE_NAMESPACE
  46815. ImagePreviewComponent::ImagePreviewComponent()
  46816. {
  46817. }
  46818. ImagePreviewComponent::~ImagePreviewComponent()
  46819. {
  46820. }
  46821. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  46822. {
  46823. const int availableW = proportionOfWidth (0.97f);
  46824. const int availableH = getHeight() - 13 * 4;
  46825. const double scale = jmin (1.0,
  46826. availableW / (double) w,
  46827. availableH / (double) h);
  46828. w = roundToInt (scale * w);
  46829. h = roundToInt (scale * h);
  46830. }
  46831. void ImagePreviewComponent::selectedFileChanged (const File& file)
  46832. {
  46833. if (fileToLoad != file)
  46834. {
  46835. fileToLoad = file;
  46836. startTimer (100);
  46837. }
  46838. }
  46839. void ImagePreviewComponent::timerCallback()
  46840. {
  46841. stopTimer();
  46842. currentThumbnail = 0;
  46843. currentDetails = String::empty;
  46844. repaint();
  46845. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  46846. if (in != 0)
  46847. {
  46848. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  46849. if (format != 0)
  46850. {
  46851. currentThumbnail = format->decodeImage (*in);
  46852. if (currentThumbnail != 0)
  46853. {
  46854. int w = currentThumbnail->getWidth();
  46855. int h = currentThumbnail->getHeight();
  46856. currentDetails
  46857. << fileToLoad.getFileName() << "\n"
  46858. << format->getFormatName() << "\n"
  46859. << w << " x " << h << " pixels\n"
  46860. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  46861. getThumbSize (w, h);
  46862. currentThumbnail = currentThumbnail->createCopy (w, h);
  46863. }
  46864. }
  46865. }
  46866. }
  46867. void ImagePreviewComponent::paint (Graphics& g)
  46868. {
  46869. if (currentThumbnail != 0)
  46870. {
  46871. g.setFont (13.0f);
  46872. int w = currentThumbnail->getWidth();
  46873. int h = currentThumbnail->getHeight();
  46874. getThumbSize (w, h);
  46875. const int numLines = 4;
  46876. const int totalH = 13 * numLines + h + 4;
  46877. const int y = (getHeight() - totalH) / 2;
  46878. g.drawImageWithin (currentThumbnail,
  46879. (getWidth() - w) / 2, y, w, h,
  46880. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  46881. false);
  46882. g.drawFittedText (currentDetails,
  46883. 0, y + h + 4, getWidth(), 100,
  46884. Justification::centredTop, numLines);
  46885. }
  46886. }
  46887. END_JUCE_NAMESPACE
  46888. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  46889. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  46890. BEGIN_JUCE_NAMESPACE
  46891. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  46892. const String& directoryWildcardPatterns,
  46893. const String& description_)
  46894. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  46895. : (description_ + " (" + fileWildcardPatterns + ")"))
  46896. {
  46897. parse (fileWildcardPatterns, fileWildcards);
  46898. parse (directoryWildcardPatterns, directoryWildcards);
  46899. }
  46900. WildcardFileFilter::~WildcardFileFilter()
  46901. {
  46902. }
  46903. bool WildcardFileFilter::isFileSuitable (const File& file) const
  46904. {
  46905. return match (file, fileWildcards);
  46906. }
  46907. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  46908. {
  46909. return match (file, directoryWildcards);
  46910. }
  46911. void WildcardFileFilter::parse (const String& pattern, StringArray& result)
  46912. {
  46913. result.addTokens (pattern.toLowerCase(), ";,", "\"'");
  46914. result.trim();
  46915. result.removeEmptyStrings();
  46916. // special case for *.*, because people use it to mean "any file", but it
  46917. // would actually ignore files with no extension.
  46918. for (int i = result.size(); --i >= 0;)
  46919. if (result[i] == "*.*")
  46920. result.set (i, "*");
  46921. }
  46922. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards)
  46923. {
  46924. const String filename (file.getFileName());
  46925. for (int i = wildcards.size(); --i >= 0;)
  46926. if (filename.matchesWildcard (wildcards[i], true))
  46927. return true;
  46928. return false;
  46929. }
  46930. END_JUCE_NAMESPACE
  46931. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  46932. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  46933. BEGIN_JUCE_NAMESPACE
  46934. KeyboardFocusTraverser::KeyboardFocusTraverser()
  46935. {
  46936. }
  46937. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  46938. {
  46939. }
  46940. namespace KeyboardFocusHelpers
  46941. {
  46942. // This will sort a set of components, so that they are ordered in terms of
  46943. // left-to-right and then top-to-bottom.
  46944. class ScreenPositionComparator
  46945. {
  46946. public:
  46947. ScreenPositionComparator() {}
  46948. static int compareElements (const Component* const first, const Component* const second)
  46949. {
  46950. int explicitOrder1 = first->getExplicitFocusOrder();
  46951. if (explicitOrder1 <= 0)
  46952. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  46953. int explicitOrder2 = second->getExplicitFocusOrder();
  46954. if (explicitOrder2 <= 0)
  46955. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  46956. if (explicitOrder1 != explicitOrder2)
  46957. return explicitOrder1 - explicitOrder2;
  46958. const int diff = first->getY() - second->getY();
  46959. return (diff == 0) ? first->getX() - second->getX()
  46960. : diff;
  46961. }
  46962. };
  46963. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  46964. {
  46965. if (parent->getNumChildComponents() > 0)
  46966. {
  46967. Array <Component*> localComps;
  46968. ScreenPositionComparator comparator;
  46969. int i;
  46970. for (i = parent->getNumChildComponents(); --i >= 0;)
  46971. {
  46972. Component* const c = parent->getChildComponent (i);
  46973. if (c->isVisible() && c->isEnabled())
  46974. localComps.addSorted (comparator, c);
  46975. }
  46976. for (i = 0; i < localComps.size(); ++i)
  46977. {
  46978. Component* const c = localComps.getUnchecked (i);
  46979. if (c->getWantsKeyboardFocus())
  46980. comps.add (c);
  46981. if (! c->isFocusContainer())
  46982. findAllFocusableComponents (c, comps);
  46983. }
  46984. }
  46985. }
  46986. }
  46987. static Component* getIncrementedComponent (Component* const current, const int delta)
  46988. {
  46989. Component* focusContainer = current->getParentComponent();
  46990. if (focusContainer != 0)
  46991. {
  46992. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  46993. focusContainer = focusContainer->getParentComponent();
  46994. if (focusContainer != 0)
  46995. {
  46996. Array <Component*> comps;
  46997. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  46998. if (comps.size() > 0)
  46999. {
  47000. const int index = comps.indexOf (current);
  47001. return comps [(index + comps.size() + delta) % comps.size()];
  47002. }
  47003. }
  47004. }
  47005. return 0;
  47006. }
  47007. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47008. {
  47009. return getIncrementedComponent (current, 1);
  47010. }
  47011. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47012. {
  47013. return getIncrementedComponent (current, -1);
  47014. }
  47015. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47016. {
  47017. Array <Component*> comps;
  47018. if (parentComponent != 0)
  47019. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47020. return comps.getFirst();
  47021. }
  47022. END_JUCE_NAMESPACE
  47023. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47024. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47025. BEGIN_JUCE_NAMESPACE
  47026. bool KeyListener::keyStateChanged (const bool, Component*)
  47027. {
  47028. return false;
  47029. }
  47030. END_JUCE_NAMESPACE
  47031. /*** End of inlined file: juce_KeyListener.cpp ***/
  47032. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47033. BEGIN_JUCE_NAMESPACE
  47034. // N.B. these two includes are put here deliberately to avoid problems with
  47035. // old GCCs failing on long include paths
  47036. const int maxKeys = 3;
  47037. class KeyMappingChangeButton : public Button
  47038. {
  47039. public:
  47040. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47041. const CommandID commandID_,
  47042. const String& keyName,
  47043. const int keyNum_)
  47044. : Button (keyName),
  47045. owner (owner_),
  47046. commandID (commandID_),
  47047. keyNum (keyNum_)
  47048. {
  47049. setWantsKeyboardFocus (false);
  47050. setTriggeredOnMouseDown (keyNum >= 0);
  47051. if (keyNum_ < 0)
  47052. setTooltip (TRANS("adds a new key-mapping"));
  47053. else
  47054. setTooltip (TRANS("click to change this key-mapping"));
  47055. }
  47056. ~KeyMappingChangeButton()
  47057. {
  47058. }
  47059. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47060. {
  47061. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47062. keyNum >= 0 ? getName() : String::empty);
  47063. }
  47064. void clicked()
  47065. {
  47066. if (keyNum >= 0)
  47067. {
  47068. // existing key clicked..
  47069. PopupMenu m;
  47070. m.addItem (1, TRANS("change this key-mapping"));
  47071. m.addSeparator();
  47072. m.addItem (2, TRANS("remove this key-mapping"));
  47073. const int res = m.show();
  47074. if (res == 1)
  47075. {
  47076. owner->assignNewKey (commandID, keyNum);
  47077. }
  47078. else if (res == 2)
  47079. {
  47080. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47081. }
  47082. }
  47083. else
  47084. {
  47085. // + button pressed..
  47086. owner->assignNewKey (commandID, -1);
  47087. }
  47088. }
  47089. void fitToContent (const int h) throw()
  47090. {
  47091. if (keyNum < 0)
  47092. {
  47093. setSize (h, h);
  47094. }
  47095. else
  47096. {
  47097. Font f (h * 0.6f);
  47098. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47099. }
  47100. }
  47101. juce_UseDebuggingNewOperator
  47102. private:
  47103. KeyMappingEditorComponent* const owner;
  47104. const CommandID commandID;
  47105. const int keyNum;
  47106. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47107. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47108. };
  47109. class KeyMappingItemComponent : public Component
  47110. {
  47111. public:
  47112. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47113. const CommandID commandID_)
  47114. : owner (owner_),
  47115. commandID (commandID_)
  47116. {
  47117. setInterceptsMouseClicks (false, true);
  47118. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47119. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47120. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47121. {
  47122. KeyMappingChangeButton* const kb
  47123. = new KeyMappingChangeButton (owner_, commandID,
  47124. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47125. kb->setEnabled (! isReadOnly);
  47126. addAndMakeVisible (kb);
  47127. }
  47128. KeyMappingChangeButton* const kb
  47129. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47130. addChildComponent (kb);
  47131. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47132. }
  47133. ~KeyMappingItemComponent()
  47134. {
  47135. deleteAllChildren();
  47136. }
  47137. void paint (Graphics& g)
  47138. {
  47139. g.setFont (getHeight() * 0.7f);
  47140. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47141. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47142. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47143. Justification::centredLeft, true);
  47144. }
  47145. void resized()
  47146. {
  47147. int x = getWidth() - 4;
  47148. for (int i = getNumChildComponents(); --i >= 0;)
  47149. {
  47150. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47151. kb->fitToContent (getHeight() - 2);
  47152. kb->setTopRightPosition (x, 1);
  47153. x -= kb->getWidth() + 5;
  47154. }
  47155. }
  47156. juce_UseDebuggingNewOperator
  47157. private:
  47158. KeyMappingEditorComponent* const owner;
  47159. const CommandID commandID;
  47160. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47161. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47162. };
  47163. class KeyMappingTreeViewItem : public TreeViewItem
  47164. {
  47165. public:
  47166. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47167. const CommandID commandID_)
  47168. : owner (owner_),
  47169. commandID (commandID_)
  47170. {
  47171. }
  47172. ~KeyMappingTreeViewItem()
  47173. {
  47174. }
  47175. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47176. bool mightContainSubItems() { return false; }
  47177. int getItemHeight() const { return 20; }
  47178. Component* createItemComponent()
  47179. {
  47180. return new KeyMappingItemComponent (owner, commandID);
  47181. }
  47182. juce_UseDebuggingNewOperator
  47183. private:
  47184. KeyMappingEditorComponent* const owner;
  47185. const CommandID commandID;
  47186. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47187. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47188. };
  47189. class KeyCategoryTreeViewItem : public TreeViewItem
  47190. {
  47191. public:
  47192. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47193. const String& name)
  47194. : owner (owner_),
  47195. categoryName (name)
  47196. {
  47197. }
  47198. ~KeyCategoryTreeViewItem()
  47199. {
  47200. }
  47201. const String getUniqueName() const { return categoryName + "_cat"; }
  47202. bool mightContainSubItems() { return true; }
  47203. int getItemHeight() const { return 28; }
  47204. void paintItem (Graphics& g, int width, int height)
  47205. {
  47206. g.setFont (height * 0.6f, Font::bold);
  47207. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47208. g.drawText (categoryName,
  47209. 2, 0, width - 2, height,
  47210. Justification::centredLeft, true);
  47211. }
  47212. void itemOpennessChanged (bool isNowOpen)
  47213. {
  47214. if (isNowOpen)
  47215. {
  47216. if (getNumSubItems() == 0)
  47217. {
  47218. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47219. for (int i = 0; i < commands.size(); ++i)
  47220. {
  47221. if (owner->shouldCommandBeIncluded (commands[i]))
  47222. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47223. }
  47224. }
  47225. }
  47226. else
  47227. {
  47228. clearSubItems();
  47229. }
  47230. }
  47231. juce_UseDebuggingNewOperator
  47232. private:
  47233. KeyMappingEditorComponent* owner;
  47234. String categoryName;
  47235. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47236. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47237. };
  47238. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47239. const bool showResetToDefaultButton)
  47240. : mappings (mappingManager)
  47241. {
  47242. jassert (mappingManager != 0); // can't be null!
  47243. mappingManager->addChangeListener (this);
  47244. setLinesDrawnForSubItems (false);
  47245. resetButton = 0;
  47246. if (showResetToDefaultButton)
  47247. {
  47248. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47249. resetButton->addButtonListener (this);
  47250. }
  47251. addAndMakeVisible (tree = new TreeView());
  47252. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47253. tree->setRootItemVisible (false);
  47254. tree->setDefaultOpenness (true);
  47255. tree->setRootItem (this);
  47256. }
  47257. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47258. {
  47259. mappings->removeChangeListener (this);
  47260. deleteAllChildren();
  47261. }
  47262. bool KeyMappingEditorComponent::mightContainSubItems()
  47263. {
  47264. return true;
  47265. }
  47266. const String KeyMappingEditorComponent::getUniqueName() const
  47267. {
  47268. return "keys";
  47269. }
  47270. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47271. const Colour& textColour)
  47272. {
  47273. setColour (backgroundColourId, mainBackground);
  47274. setColour (textColourId, textColour);
  47275. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47276. }
  47277. void KeyMappingEditorComponent::parentHierarchyChanged()
  47278. {
  47279. changeListenerCallback (0);
  47280. }
  47281. void KeyMappingEditorComponent::resized()
  47282. {
  47283. int h = getHeight();
  47284. if (resetButton != 0)
  47285. {
  47286. const int buttonHeight = 20;
  47287. h -= buttonHeight + 8;
  47288. int x = getWidth() - 8;
  47289. const int y = h + 6;
  47290. resetButton->changeWidthToFitText (buttonHeight);
  47291. resetButton->setTopRightPosition (x, y);
  47292. }
  47293. tree->setBounds (0, 0, getWidth(), h);
  47294. }
  47295. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47296. {
  47297. if (button == resetButton)
  47298. {
  47299. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47300. TRANS("Reset to defaults"),
  47301. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47302. TRANS("Reset")))
  47303. {
  47304. mappings->resetToDefaultMappings();
  47305. }
  47306. }
  47307. }
  47308. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47309. {
  47310. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47311. clearSubItems();
  47312. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47313. for (int i = 0; i < categories.size(); ++i)
  47314. {
  47315. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47316. int count = 0;
  47317. for (int j = 0; j < commands.size(); ++j)
  47318. if (shouldCommandBeIncluded (commands[j]))
  47319. ++count;
  47320. if (count > 0)
  47321. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47322. }
  47323. if (openness != 0)
  47324. tree->restoreOpennessState (*openness);
  47325. }
  47326. class KeyEntryWindow : public AlertWindow
  47327. {
  47328. public:
  47329. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47330. : AlertWindow (TRANS("New key-mapping"),
  47331. TRANS("Please press a key combination now..."),
  47332. AlertWindow::NoIcon),
  47333. owner (owner_)
  47334. {
  47335. addButton (TRANS("ok"), 1);
  47336. addButton (TRANS("cancel"), 0);
  47337. // (avoid return + escape keys getting processed by the buttons..)
  47338. for (int i = getNumChildComponents(); --i >= 0;)
  47339. getChildComponent (i)->setWantsKeyboardFocus (false);
  47340. setWantsKeyboardFocus (true);
  47341. grabKeyboardFocus();
  47342. }
  47343. ~KeyEntryWindow()
  47344. {
  47345. }
  47346. bool keyPressed (const KeyPress& key)
  47347. {
  47348. lastPress = key;
  47349. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47350. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47351. if (previousCommand != 0)
  47352. {
  47353. message << "\n\n"
  47354. << TRANS("(Currently assigned to \"")
  47355. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47356. << "\")";
  47357. }
  47358. setMessage (message);
  47359. return true;
  47360. }
  47361. bool keyStateChanged (bool)
  47362. {
  47363. return true;
  47364. }
  47365. KeyPress lastPress;
  47366. juce_UseDebuggingNewOperator
  47367. private:
  47368. KeyMappingEditorComponent* owner;
  47369. KeyEntryWindow (const KeyEntryWindow&);
  47370. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47371. };
  47372. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47373. {
  47374. KeyEntryWindow entryWindow (this);
  47375. if (entryWindow.runModalLoop() != 0)
  47376. {
  47377. entryWindow.setVisible (false);
  47378. if (entryWindow.lastPress.isValid())
  47379. {
  47380. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47381. if (previousCommand != 0)
  47382. {
  47383. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47384. TRANS("Change key-mapping"),
  47385. TRANS("This key is already assigned to the command \"")
  47386. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47387. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47388. TRANS("re-assign"),
  47389. TRANS("cancel")))
  47390. {
  47391. return;
  47392. }
  47393. }
  47394. mappings->removeKeyPress (entryWindow.lastPress);
  47395. if (index >= 0)
  47396. mappings->removeKeyPress (commandID, index);
  47397. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47398. }
  47399. }
  47400. }
  47401. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47402. {
  47403. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47404. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47405. }
  47406. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47407. {
  47408. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47409. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47410. }
  47411. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47412. {
  47413. return key.getTextDescription();
  47414. }
  47415. END_JUCE_NAMESPACE
  47416. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47417. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47418. BEGIN_JUCE_NAMESPACE
  47419. KeyPress::KeyPress() throw()
  47420. : keyCode (0),
  47421. mods (0),
  47422. textCharacter (0)
  47423. {
  47424. }
  47425. KeyPress::KeyPress (const int keyCode_,
  47426. const ModifierKeys& mods_,
  47427. const juce_wchar textCharacter_) throw()
  47428. : keyCode (keyCode_),
  47429. mods (mods_),
  47430. textCharacter (textCharacter_)
  47431. {
  47432. }
  47433. KeyPress::KeyPress (const int keyCode_) throw()
  47434. : keyCode (keyCode_),
  47435. textCharacter (0)
  47436. {
  47437. }
  47438. KeyPress::KeyPress (const KeyPress& other) throw()
  47439. : keyCode (other.keyCode),
  47440. mods (other.mods),
  47441. textCharacter (other.textCharacter)
  47442. {
  47443. }
  47444. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47445. {
  47446. keyCode = other.keyCode;
  47447. mods = other.mods;
  47448. textCharacter = other.textCharacter;
  47449. return *this;
  47450. }
  47451. bool KeyPress::operator== (const KeyPress& other) const throw()
  47452. {
  47453. return mods.getRawFlags() == other.mods.getRawFlags()
  47454. && (textCharacter == other.textCharacter
  47455. || textCharacter == 0
  47456. || other.textCharacter == 0)
  47457. && (keyCode == other.keyCode
  47458. || (keyCode < 256
  47459. && other.keyCode < 256
  47460. && CharacterFunctions::toLowerCase ((juce_wchar) keyCode)
  47461. == CharacterFunctions::toLowerCase ((juce_wchar) other.keyCode)));
  47462. }
  47463. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47464. {
  47465. return ! operator== (other);
  47466. }
  47467. bool KeyPress::isCurrentlyDown() const
  47468. {
  47469. return isKeyCurrentlyDown (keyCode)
  47470. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47471. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47472. }
  47473. namespace KeyPressHelpers
  47474. {
  47475. struct KeyNameAndCode
  47476. {
  47477. const char* name;
  47478. int code;
  47479. };
  47480. static const KeyNameAndCode translations[] =
  47481. {
  47482. { "spacebar", KeyPress::spaceKey },
  47483. { "return", KeyPress::returnKey },
  47484. { "escape", KeyPress::escapeKey },
  47485. { "backspace", KeyPress::backspaceKey },
  47486. { "cursor left", KeyPress::leftKey },
  47487. { "cursor right", KeyPress::rightKey },
  47488. { "cursor up", KeyPress::upKey },
  47489. { "cursor down", KeyPress::downKey },
  47490. { "page up", KeyPress::pageUpKey },
  47491. { "page down", KeyPress::pageDownKey },
  47492. { "home", KeyPress::homeKey },
  47493. { "end", KeyPress::endKey },
  47494. { "delete", KeyPress::deleteKey },
  47495. { "insert", KeyPress::insertKey },
  47496. { "tab", KeyPress::tabKey },
  47497. { "play", KeyPress::playKey },
  47498. { "stop", KeyPress::stopKey },
  47499. { "fast forward", KeyPress::fastForwardKey },
  47500. { "rewind", KeyPress::rewindKey }
  47501. };
  47502. static const String numberPadPrefix() { return "numpad "; }
  47503. }
  47504. const KeyPress KeyPress::createFromDescription (const String& desc)
  47505. {
  47506. int modifiers = 0;
  47507. if (desc.containsWholeWordIgnoreCase ("ctrl")
  47508. || desc.containsWholeWordIgnoreCase ("control")
  47509. || desc.containsWholeWordIgnoreCase ("ctl"))
  47510. modifiers |= ModifierKeys::ctrlModifier;
  47511. if (desc.containsWholeWordIgnoreCase ("shift")
  47512. || desc.containsWholeWordIgnoreCase ("shft"))
  47513. modifiers |= ModifierKeys::shiftModifier;
  47514. if (desc.containsWholeWordIgnoreCase ("alt")
  47515. || desc.containsWholeWordIgnoreCase ("option"))
  47516. modifiers |= ModifierKeys::altModifier;
  47517. if (desc.containsWholeWordIgnoreCase ("command")
  47518. || desc.containsWholeWordIgnoreCase ("cmd"))
  47519. modifiers |= ModifierKeys::commandModifier;
  47520. int key = 0;
  47521. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47522. {
  47523. if (desc.containsWholeWordIgnoreCase (String (KeyPressHelpers::translations[i].name)))
  47524. {
  47525. key = KeyPressHelpers::translations[i].code;
  47526. break;
  47527. }
  47528. }
  47529. if (key == 0)
  47530. {
  47531. // see if it's a numpad key..
  47532. if (desc.containsIgnoreCase (KeyPressHelpers::numberPadPrefix()))
  47533. {
  47534. const juce_wchar lastChar = desc.trimEnd().getLastCharacter();
  47535. if (lastChar >= '0' && lastChar <= '9')
  47536. key = numberPad0 + lastChar - '0';
  47537. else if (lastChar == '+')
  47538. key = numberPadAdd;
  47539. else if (lastChar == '-')
  47540. key = numberPadSubtract;
  47541. else if (lastChar == '*')
  47542. key = numberPadMultiply;
  47543. else if (lastChar == '/')
  47544. key = numberPadDivide;
  47545. else if (lastChar == '.')
  47546. key = numberPadDecimalPoint;
  47547. else if (lastChar == '=')
  47548. key = numberPadEquals;
  47549. else if (desc.endsWith ("separator"))
  47550. key = numberPadSeparator;
  47551. else if (desc.endsWith ("delete"))
  47552. key = numberPadDelete;
  47553. }
  47554. if (key == 0)
  47555. {
  47556. // see if it's a function key..
  47557. for (int i = 1; i <= 12; ++i)
  47558. if (desc.containsWholeWordIgnoreCase ("f" + String (i)))
  47559. key = F1Key + i - 1;
  47560. if (key == 0)
  47561. {
  47562. // give up and use the hex code..
  47563. const int hexCode = desc.fromFirstOccurrenceOf ("#", false, false)
  47564. .toLowerCase()
  47565. .retainCharacters ("0123456789abcdef")
  47566. .getHexValue32();
  47567. if (hexCode > 0)
  47568. key = hexCode;
  47569. else
  47570. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47571. }
  47572. }
  47573. }
  47574. return KeyPress (key, ModifierKeys (modifiers), 0);
  47575. }
  47576. const String KeyPress::getTextDescription() const
  47577. {
  47578. String desc;
  47579. if (keyCode > 0)
  47580. {
  47581. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47582. // want to store it as being a slash, not shift+whatever.
  47583. if (textCharacter == '/')
  47584. return "/";
  47585. if (mods.isCtrlDown())
  47586. desc << "ctrl + ";
  47587. if (mods.isShiftDown())
  47588. desc << "shift + ";
  47589. #if JUCE_MAC
  47590. // only do this on the mac, because on Windows ctrl and command are the same,
  47591. // and this would get confusing
  47592. if (mods.isCommandDown())
  47593. desc << "command + ";
  47594. if (mods.isAltDown())
  47595. desc << "option + ";
  47596. #else
  47597. if (mods.isAltDown())
  47598. desc << "alt + ";
  47599. #endif
  47600. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47601. if (keyCode == KeyPressHelpers::translations[i].code)
  47602. return desc + KeyPressHelpers::translations[i].name;
  47603. if (keyCode >= F1Key && keyCode <= F16Key)
  47604. desc << 'F' << (1 + keyCode - F1Key);
  47605. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47606. desc << KeyPressHelpers::numberPadPrefix() << (keyCode - numberPad0);
  47607. else if (keyCode >= 33 && keyCode < 176)
  47608. desc += CharacterFunctions::toUpperCase ((juce_wchar) keyCode);
  47609. else if (keyCode == numberPadAdd)
  47610. desc << KeyPressHelpers::numberPadPrefix() << '+';
  47611. else if (keyCode == numberPadSubtract)
  47612. desc << KeyPressHelpers::numberPadPrefix() << '-';
  47613. else if (keyCode == numberPadMultiply)
  47614. desc << KeyPressHelpers::numberPadPrefix() << '*';
  47615. else if (keyCode == numberPadDivide)
  47616. desc << KeyPressHelpers::numberPadPrefix() << '/';
  47617. else if (keyCode == numberPadSeparator)
  47618. desc << KeyPressHelpers::numberPadPrefix() << "separator";
  47619. else if (keyCode == numberPadDecimalPoint)
  47620. desc << KeyPressHelpers::numberPadPrefix() << '.';
  47621. else if (keyCode == numberPadDelete)
  47622. desc << KeyPressHelpers::numberPadPrefix() << "delete";
  47623. else
  47624. desc << '#' << String::toHexString (keyCode);
  47625. }
  47626. return desc;
  47627. }
  47628. END_JUCE_NAMESPACE
  47629. /*** End of inlined file: juce_KeyPress.cpp ***/
  47630. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47631. BEGIN_JUCE_NAMESPACE
  47632. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_)
  47633. : commandManager (commandManager_)
  47634. {
  47635. // A manager is needed to get the descriptions of commands, and will be called when
  47636. // a command is invoked. So you can't leave this null..
  47637. jassert (commandManager_ != 0);
  47638. Desktop::getInstance().addFocusChangeListener (this);
  47639. }
  47640. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other)
  47641. : commandManager (other.commandManager)
  47642. {
  47643. Desktop::getInstance().addFocusChangeListener (this);
  47644. }
  47645. KeyPressMappingSet::~KeyPressMappingSet()
  47646. {
  47647. Desktop::getInstance().removeFocusChangeListener (this);
  47648. }
  47649. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const
  47650. {
  47651. for (int i = 0; i < mappings.size(); ++i)
  47652. if (mappings.getUnchecked(i)->commandID == commandID)
  47653. return mappings.getUnchecked (i)->keypresses;
  47654. return Array <KeyPress> ();
  47655. }
  47656. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47657. const KeyPress& newKeyPress,
  47658. int insertIndex)
  47659. {
  47660. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47661. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47662. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47663. && ! newKeyPress.getModifiers().isShiftDown()));
  47664. if (findCommandForKeyPress (newKeyPress) != commandID)
  47665. {
  47666. removeKeyPress (newKeyPress);
  47667. if (newKeyPress.isValid())
  47668. {
  47669. for (int i = mappings.size(); --i >= 0;)
  47670. {
  47671. if (mappings.getUnchecked(i)->commandID == commandID)
  47672. {
  47673. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47674. sendChangeMessage (this);
  47675. return;
  47676. }
  47677. }
  47678. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47679. if (ci != 0)
  47680. {
  47681. CommandMapping* const cm = new CommandMapping();
  47682. cm->commandID = commandID;
  47683. cm->keypresses.add (newKeyPress);
  47684. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47685. mappings.add (cm);
  47686. sendChangeMessage (this);
  47687. }
  47688. }
  47689. }
  47690. }
  47691. void KeyPressMappingSet::resetToDefaultMappings()
  47692. {
  47693. mappings.clear();
  47694. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47695. {
  47696. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47697. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47698. {
  47699. addKeyPress (ci->commandID,
  47700. ci->defaultKeypresses.getReference (j));
  47701. }
  47702. }
  47703. sendChangeMessage (this);
  47704. }
  47705. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID)
  47706. {
  47707. clearAllKeyPresses (commandID);
  47708. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47709. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47710. {
  47711. addKeyPress (ci->commandID,
  47712. ci->defaultKeypresses.getReference (j));
  47713. }
  47714. }
  47715. void KeyPressMappingSet::clearAllKeyPresses()
  47716. {
  47717. if (mappings.size() > 0)
  47718. {
  47719. sendChangeMessage (this);
  47720. mappings.clear();
  47721. }
  47722. }
  47723. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID)
  47724. {
  47725. for (int i = mappings.size(); --i >= 0;)
  47726. {
  47727. if (mappings.getUnchecked(i)->commandID == commandID)
  47728. {
  47729. mappings.remove (i);
  47730. sendChangeMessage (this);
  47731. }
  47732. }
  47733. }
  47734. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress)
  47735. {
  47736. if (keypress.isValid())
  47737. {
  47738. for (int i = mappings.size(); --i >= 0;)
  47739. {
  47740. CommandMapping* const cm = mappings.getUnchecked(i);
  47741. for (int j = cm->keypresses.size(); --j >= 0;)
  47742. {
  47743. if (keypress == cm->keypresses [j])
  47744. {
  47745. cm->keypresses.remove (j);
  47746. sendChangeMessage (this);
  47747. }
  47748. }
  47749. }
  47750. }
  47751. }
  47752. void KeyPressMappingSet::removeKeyPress (const CommandID commandID, const int keyPressIndex)
  47753. {
  47754. for (int i = mappings.size(); --i >= 0;)
  47755. {
  47756. if (mappings.getUnchecked(i)->commandID == commandID)
  47757. {
  47758. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  47759. sendChangeMessage (this);
  47760. break;
  47761. }
  47762. }
  47763. }
  47764. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  47765. {
  47766. for (int i = 0; i < mappings.size(); ++i)
  47767. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  47768. return mappings.getUnchecked(i)->commandID;
  47769. return 0;
  47770. }
  47771. bool KeyPressMappingSet::containsMapping (const CommandID commandID, const KeyPress& keyPress) const throw()
  47772. {
  47773. for (int i = mappings.size(); --i >= 0;)
  47774. if (mappings.getUnchecked(i)->commandID == commandID)
  47775. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  47776. return false;
  47777. }
  47778. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  47779. const KeyPress& key,
  47780. const bool isKeyDown,
  47781. const int millisecsSinceKeyPressed,
  47782. Component* const originatingComponent) const
  47783. {
  47784. ApplicationCommandTarget::InvocationInfo info (commandID);
  47785. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  47786. info.isKeyDown = isKeyDown;
  47787. info.keyPress = key;
  47788. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  47789. info.originatingComponent = originatingComponent;
  47790. commandManager->invoke (info, false);
  47791. }
  47792. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  47793. {
  47794. if (xmlVersion.hasTagName ("KEYMAPPINGS"))
  47795. {
  47796. if (xmlVersion.getBoolAttribute ("basedOnDefaults", true))
  47797. {
  47798. // if the XML was created as a set of differences from the default mappings,
  47799. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  47800. resetToDefaultMappings();
  47801. }
  47802. else
  47803. {
  47804. // if the XML was created calling createXml (false), then we need to clear all
  47805. // the keys and treat the xml as describing the entire set of mappings.
  47806. clearAllKeyPresses();
  47807. }
  47808. forEachXmlChildElement (xmlVersion, map)
  47809. {
  47810. const CommandID commandId = map->getStringAttribute ("commandId").getHexValue32();
  47811. if (commandId != 0)
  47812. {
  47813. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute ("key")));
  47814. if (map->hasTagName ("MAPPING"))
  47815. {
  47816. addKeyPress (commandId, key);
  47817. }
  47818. else if (map->hasTagName ("UNMAPPING"))
  47819. {
  47820. if (containsMapping (commandId, key))
  47821. removeKeyPress (key);
  47822. }
  47823. }
  47824. }
  47825. return true;
  47826. }
  47827. return false;
  47828. }
  47829. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  47830. {
  47831. ScopedPointer <KeyPressMappingSet> defaultSet;
  47832. if (saveDifferencesFromDefaultSet)
  47833. {
  47834. defaultSet = new KeyPressMappingSet (commandManager);
  47835. defaultSet->resetToDefaultMappings();
  47836. }
  47837. XmlElement* const doc = new XmlElement ("KEYMAPPINGS");
  47838. doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet);
  47839. int i;
  47840. for (i = 0; i < mappings.size(); ++i)
  47841. {
  47842. const CommandMapping* const cm = mappings.getUnchecked(i);
  47843. for (int j = 0; j < cm->keypresses.size(); ++j)
  47844. {
  47845. if (defaultSet == 0
  47846. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  47847. {
  47848. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  47849. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  47850. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  47851. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  47852. }
  47853. }
  47854. }
  47855. if (defaultSet != 0)
  47856. {
  47857. for (i = 0; i < defaultSet->mappings.size(); ++i)
  47858. {
  47859. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  47860. for (int j = 0; j < cm->keypresses.size(); ++j)
  47861. {
  47862. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  47863. {
  47864. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  47865. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  47866. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  47867. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  47868. }
  47869. }
  47870. }
  47871. }
  47872. return doc;
  47873. }
  47874. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  47875. Component* originatingComponent)
  47876. {
  47877. bool used = false;
  47878. const CommandID commandID = findCommandForKeyPress (key);
  47879. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47880. if (ci != 0
  47881. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  47882. {
  47883. ApplicationCommandInfo info (0);
  47884. if (commandManager->getTargetForCommand (commandID, info) != 0
  47885. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  47886. {
  47887. invokeCommand (commandID, key, true, 0, originatingComponent);
  47888. used = true;
  47889. }
  47890. else
  47891. {
  47892. if (originatingComponent != 0)
  47893. originatingComponent->getLookAndFeel().playAlertSound();
  47894. }
  47895. }
  47896. return used;
  47897. }
  47898. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  47899. {
  47900. bool used = false;
  47901. const uint32 now = Time::getMillisecondCounter();
  47902. for (int i = mappings.size(); --i >= 0;)
  47903. {
  47904. CommandMapping* const cm = mappings.getUnchecked(i);
  47905. if (cm->wantsKeyUpDownCallbacks)
  47906. {
  47907. for (int j = cm->keypresses.size(); --j >= 0;)
  47908. {
  47909. const KeyPress key (cm->keypresses.getReference (j));
  47910. const bool isDown = key.isCurrentlyDown();
  47911. int keyPressEntryIndex = 0;
  47912. bool wasDown = false;
  47913. for (int k = keysDown.size(); --k >= 0;)
  47914. {
  47915. if (key == keysDown.getUnchecked(k)->key)
  47916. {
  47917. keyPressEntryIndex = k;
  47918. wasDown = true;
  47919. used = true;
  47920. break;
  47921. }
  47922. }
  47923. if (isDown != wasDown)
  47924. {
  47925. int millisecs = 0;
  47926. if (isDown)
  47927. {
  47928. KeyPressTime* const k = new KeyPressTime();
  47929. k->key = key;
  47930. k->timeWhenPressed = now;
  47931. keysDown.add (k);
  47932. }
  47933. else
  47934. {
  47935. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  47936. if (now > pressTime)
  47937. millisecs = now - pressTime;
  47938. keysDown.remove (keyPressEntryIndex);
  47939. }
  47940. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  47941. used = true;
  47942. }
  47943. }
  47944. }
  47945. }
  47946. return used;
  47947. }
  47948. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  47949. {
  47950. if (focusedComponent != 0)
  47951. focusedComponent->keyStateChanged (false);
  47952. }
  47953. END_JUCE_NAMESPACE
  47954. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  47955. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  47956. BEGIN_JUCE_NAMESPACE
  47957. ModifierKeys::ModifierKeys (const int flags_) throw()
  47958. : flags (flags_)
  47959. {
  47960. }
  47961. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  47962. : flags (other.flags)
  47963. {
  47964. }
  47965. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  47966. {
  47967. flags = other.flags;
  47968. return *this;
  47969. }
  47970. ModifierKeys ModifierKeys::currentModifiers;
  47971. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  47972. {
  47973. return currentModifiers;
  47974. }
  47975. int ModifierKeys::getNumMouseButtonsDown() const throw()
  47976. {
  47977. int num = 0;
  47978. if (isLeftButtonDown()) ++num;
  47979. if (isRightButtonDown()) ++num;
  47980. if (isMiddleButtonDown()) ++num;
  47981. return num;
  47982. }
  47983. END_JUCE_NAMESPACE
  47984. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  47985. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  47986. BEGIN_JUCE_NAMESPACE
  47987. class ComponentAnimator::AnimationTask
  47988. {
  47989. public:
  47990. AnimationTask (Component* const comp)
  47991. : component (comp)
  47992. {
  47993. }
  47994. Component::SafePointer<Component> component;
  47995. Rectangle<int> destination;
  47996. int msElapsed, msTotal;
  47997. double startSpeed, midSpeed, endSpeed, lastProgress;
  47998. double left, top, right, bottom;
  47999. bool useTimeslice (const int elapsed)
  48000. {
  48001. if (component == 0)
  48002. return false;
  48003. msElapsed += elapsed;
  48004. double newProgress = msElapsed / (double) msTotal;
  48005. if (newProgress >= 0 && newProgress < 1.0)
  48006. {
  48007. newProgress = timeToDistance (newProgress);
  48008. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48009. jassert (newProgress >= lastProgress);
  48010. lastProgress = newProgress;
  48011. left += (destination.getX() - left) * delta;
  48012. top += (destination.getY() - top) * delta;
  48013. right += (destination.getRight() - right) * delta;
  48014. bottom += (destination.getBottom() - bottom) * delta;
  48015. if (delta < 1.0)
  48016. {
  48017. const Rectangle<int> newBounds (roundToInt (left),
  48018. roundToInt (top),
  48019. roundToInt (right - left),
  48020. roundToInt (bottom - top));
  48021. if (newBounds != destination)
  48022. {
  48023. component->setBounds (newBounds);
  48024. return true;
  48025. }
  48026. }
  48027. }
  48028. component->setBounds (destination);
  48029. return false;
  48030. }
  48031. void moveToFinalDestination()
  48032. {
  48033. if (component != 0)
  48034. component->setBounds (destination);
  48035. }
  48036. private:
  48037. inline double timeToDistance (const double time) const
  48038. {
  48039. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48040. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48041. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48042. }
  48043. };
  48044. ComponentAnimator::ComponentAnimator()
  48045. : lastTime (0)
  48046. {
  48047. }
  48048. ComponentAnimator::~ComponentAnimator()
  48049. {
  48050. cancelAllAnimations (false);
  48051. jassert (tasks.size() == 0);
  48052. }
  48053. ComponentAnimator::AnimationTask* ComponentAnimator::findTaskFor (Component* const component) const
  48054. {
  48055. for (int i = tasks.size(); --i >= 0;)
  48056. if (component == tasks.getUnchecked(i)->component.getComponent())
  48057. return tasks.getUnchecked(i);
  48058. return 0;
  48059. }
  48060. void ComponentAnimator::animateComponent (Component* const component,
  48061. const Rectangle<int>& finalPosition,
  48062. const int millisecondsToSpendMoving,
  48063. const double startSpeed,
  48064. const double endSpeed)
  48065. {
  48066. if (component != 0)
  48067. {
  48068. AnimationTask* at = findTaskFor (component);
  48069. if (at == 0)
  48070. {
  48071. at = new AnimationTask (component);
  48072. tasks.add (at);
  48073. sendChangeMessage (this);
  48074. }
  48075. at->msElapsed = 0;
  48076. at->lastProgress = 0;
  48077. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48078. at->destination = finalPosition;
  48079. // the speeds must be 0 or greater!
  48080. jassert (startSpeed >= 0 && endSpeed >= 0)
  48081. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48082. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48083. at->midSpeed = invTotalDistance;
  48084. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48085. at->left = component->getX();
  48086. at->top = component->getY();
  48087. at->right = component->getRight();
  48088. at->bottom = component->getBottom();
  48089. if (! isTimerRunning())
  48090. {
  48091. lastTime = Time::getMillisecondCounter();
  48092. startTimer (1000 / 50);
  48093. }
  48094. }
  48095. }
  48096. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48097. {
  48098. for (int i = tasks.size(); --i >= 0;)
  48099. {
  48100. AnimationTask* const at = tasks.getUnchecked(i);
  48101. if (moveComponentsToTheirFinalPositions)
  48102. at->moveToFinalDestination();
  48103. delete at;
  48104. tasks.remove (i);
  48105. sendChangeMessage (this);
  48106. }
  48107. }
  48108. void ComponentAnimator::cancelAnimation (Component* const component,
  48109. const bool moveComponentToItsFinalPosition)
  48110. {
  48111. AnimationTask* const at = findTaskFor (component);
  48112. if (at != 0)
  48113. {
  48114. if (moveComponentToItsFinalPosition)
  48115. at->moveToFinalDestination();
  48116. tasks.removeValue (at);
  48117. delete at;
  48118. sendChangeMessage (this);
  48119. }
  48120. }
  48121. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48122. {
  48123. AnimationTask* const at = findTaskFor (component);
  48124. if (at != 0)
  48125. return at->destination;
  48126. else if (component != 0)
  48127. return component->getBounds();
  48128. return Rectangle<int>();
  48129. }
  48130. bool ComponentAnimator::isAnimating (Component* component) const
  48131. {
  48132. return findTaskFor (component) != 0;
  48133. }
  48134. void ComponentAnimator::timerCallback()
  48135. {
  48136. const uint32 timeNow = Time::getMillisecondCounter();
  48137. if (lastTime == 0 || lastTime == timeNow)
  48138. lastTime = timeNow;
  48139. const int elapsed = timeNow - lastTime;
  48140. for (int i = tasks.size(); --i >= 0;)
  48141. {
  48142. AnimationTask* const at = tasks.getUnchecked(i);
  48143. if (! at->useTimeslice (elapsed))
  48144. {
  48145. tasks.remove (i);
  48146. delete at;
  48147. sendChangeMessage (this);
  48148. }
  48149. }
  48150. lastTime = timeNow;
  48151. if (tasks.size() == 0)
  48152. stopTimer();
  48153. }
  48154. END_JUCE_NAMESPACE
  48155. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48156. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48157. BEGIN_JUCE_NAMESPACE
  48158. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48159. : minW (0),
  48160. maxW (0x3fffffff),
  48161. minH (0),
  48162. maxH (0x3fffffff),
  48163. minOffTop (0),
  48164. minOffLeft (0),
  48165. minOffBottom (0),
  48166. minOffRight (0),
  48167. aspectRatio (0.0)
  48168. {
  48169. }
  48170. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48171. {
  48172. }
  48173. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48174. {
  48175. minW = minimumWidth;
  48176. }
  48177. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48178. {
  48179. maxW = maximumWidth;
  48180. }
  48181. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48182. {
  48183. minH = minimumHeight;
  48184. }
  48185. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48186. {
  48187. maxH = maximumHeight;
  48188. }
  48189. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48190. {
  48191. jassert (maxW >= minimumWidth);
  48192. jassert (maxH >= minimumHeight);
  48193. jassert (minimumWidth > 0 && minimumHeight > 0);
  48194. minW = minimumWidth;
  48195. minH = minimumHeight;
  48196. if (minW > maxW)
  48197. maxW = minW;
  48198. if (minH > maxH)
  48199. maxH = minH;
  48200. }
  48201. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48202. {
  48203. jassert (maximumWidth >= minW);
  48204. jassert (maximumHeight >= minH);
  48205. jassert (maximumWidth > 0 && maximumHeight > 0);
  48206. maxW = jmax (minW, maximumWidth);
  48207. maxH = jmax (minH, maximumHeight);
  48208. }
  48209. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48210. const int minimumHeight,
  48211. const int maximumWidth,
  48212. const int maximumHeight) throw()
  48213. {
  48214. jassert (maximumWidth >= minimumWidth);
  48215. jassert (maximumHeight >= minimumHeight);
  48216. jassert (maximumWidth > 0 && maximumHeight > 0);
  48217. jassert (minimumWidth > 0 && minimumHeight > 0);
  48218. minW = jmax (0, minimumWidth);
  48219. minH = jmax (0, minimumHeight);
  48220. maxW = jmax (minW, maximumWidth);
  48221. maxH = jmax (minH, maximumHeight);
  48222. }
  48223. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48224. const int minimumWhenOffTheLeft,
  48225. const int minimumWhenOffTheBottom,
  48226. const int minimumWhenOffTheRight) throw()
  48227. {
  48228. minOffTop = minimumWhenOffTheTop;
  48229. minOffLeft = minimumWhenOffTheLeft;
  48230. minOffBottom = minimumWhenOffTheBottom;
  48231. minOffRight = minimumWhenOffTheRight;
  48232. }
  48233. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48234. {
  48235. aspectRatio = jmax (0.0, widthOverHeight);
  48236. }
  48237. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48238. {
  48239. return aspectRatio;
  48240. }
  48241. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48242. const Rectangle<int>& targetBounds,
  48243. const bool isStretchingTop,
  48244. const bool isStretchingLeft,
  48245. const bool isStretchingBottom,
  48246. const bool isStretchingRight)
  48247. {
  48248. jassert (component != 0);
  48249. Rectangle<int> limits, bounds (targetBounds);
  48250. BorderSize border;
  48251. Component* const parent = component->getParentComponent();
  48252. if (parent == 0)
  48253. {
  48254. ComponentPeer* peer = component->getPeer();
  48255. if (peer != 0)
  48256. border = peer->getFrameSize();
  48257. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48258. }
  48259. else
  48260. {
  48261. limits.setSize (parent->getWidth(), parent->getHeight());
  48262. }
  48263. border.addTo (bounds);
  48264. checkBounds (bounds,
  48265. border.addedTo (component->getBounds()), limits,
  48266. isStretchingTop, isStretchingLeft,
  48267. isStretchingBottom, isStretchingRight);
  48268. border.subtractFrom (bounds);
  48269. applyBoundsToComponent (component, bounds);
  48270. }
  48271. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48272. {
  48273. setBoundsForComponent (component, component->getBounds(),
  48274. false, false, false, false);
  48275. }
  48276. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48277. const Rectangle<int>& bounds)
  48278. {
  48279. component->setBounds (bounds);
  48280. }
  48281. void ComponentBoundsConstrainer::resizeStart()
  48282. {
  48283. }
  48284. void ComponentBoundsConstrainer::resizeEnd()
  48285. {
  48286. }
  48287. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48288. const Rectangle<int>& old,
  48289. const Rectangle<int>& limits,
  48290. const bool isStretchingTop,
  48291. const bool isStretchingLeft,
  48292. const bool isStretchingBottom,
  48293. const bool isStretchingRight)
  48294. {
  48295. int x = bounds.getX();
  48296. int y = bounds.getY();
  48297. int w = bounds.getWidth();
  48298. int h = bounds.getHeight();
  48299. // constrain the size if it's being stretched..
  48300. if (isStretchingLeft)
  48301. {
  48302. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48303. w = old.getRight() - x;
  48304. }
  48305. if (isStretchingRight)
  48306. {
  48307. w = jlimit (minW, maxW, w);
  48308. }
  48309. if (isStretchingTop)
  48310. {
  48311. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48312. h = old.getBottom() - y;
  48313. }
  48314. if (isStretchingBottom)
  48315. {
  48316. h = jlimit (minH, maxH, h);
  48317. }
  48318. // constrain the aspect ratio if one has been specified..
  48319. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48320. {
  48321. bool adjustWidth;
  48322. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48323. {
  48324. adjustWidth = true;
  48325. }
  48326. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48327. {
  48328. adjustWidth = false;
  48329. }
  48330. else
  48331. {
  48332. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48333. const double newRatio = fabs (w / (double) h);
  48334. adjustWidth = (oldRatio > newRatio);
  48335. }
  48336. if (adjustWidth)
  48337. {
  48338. w = roundToInt (h * aspectRatio);
  48339. if (w > maxW || w < minW)
  48340. {
  48341. w = jlimit (minW, maxW, w);
  48342. h = roundToInt (w / aspectRatio);
  48343. }
  48344. }
  48345. else
  48346. {
  48347. h = roundToInt (w / aspectRatio);
  48348. if (h > maxH || h < minH)
  48349. {
  48350. h = jlimit (minH, maxH, h);
  48351. w = roundToInt (h * aspectRatio);
  48352. }
  48353. }
  48354. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48355. {
  48356. x = old.getX() + (old.getWidth() - w) / 2;
  48357. }
  48358. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48359. {
  48360. y = old.getY() + (old.getHeight() - h) / 2;
  48361. }
  48362. else
  48363. {
  48364. if (isStretchingLeft)
  48365. x = old.getRight() - w;
  48366. if (isStretchingTop)
  48367. y = old.getBottom() - h;
  48368. }
  48369. }
  48370. // ...and constrain the position if limits have been set for that.
  48371. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48372. {
  48373. if (minOffTop > 0)
  48374. {
  48375. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48376. if (y < limit)
  48377. {
  48378. if (isStretchingTop)
  48379. h -= (limit - y);
  48380. y = limit;
  48381. }
  48382. }
  48383. if (minOffLeft > 0)
  48384. {
  48385. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48386. if (x < limit)
  48387. {
  48388. if (isStretchingLeft)
  48389. w -= (limit - x);
  48390. x = limit;
  48391. }
  48392. }
  48393. if (minOffBottom > 0)
  48394. {
  48395. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48396. if (y > limit)
  48397. {
  48398. if (isStretchingBottom)
  48399. h += (limit - y);
  48400. else
  48401. y = limit;
  48402. }
  48403. }
  48404. if (minOffRight > 0)
  48405. {
  48406. const int limit = limits.getRight() - jmin (minOffRight, w);
  48407. if (x > limit)
  48408. {
  48409. if (isStretchingRight)
  48410. w += (limit - x);
  48411. else
  48412. x = limit;
  48413. }
  48414. }
  48415. }
  48416. jassert (w >= 0 && h >= 0);
  48417. bounds = Rectangle<int> (x, y, w, h);
  48418. }
  48419. END_JUCE_NAMESPACE
  48420. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48421. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48422. BEGIN_JUCE_NAMESPACE
  48423. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48424. : component (component_),
  48425. lastPeer (0),
  48426. reentrant (false)
  48427. {
  48428. jassert (component != 0); // can't use this with a null pointer..
  48429. component->addComponentListener (this);
  48430. registerWithParentComps();
  48431. }
  48432. ComponentMovementWatcher::~ComponentMovementWatcher()
  48433. {
  48434. component->removeComponentListener (this);
  48435. unregister();
  48436. }
  48437. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48438. {
  48439. // agh! don't delete the target component without deleting this object first!
  48440. jassert (component != 0);
  48441. if (! reentrant)
  48442. {
  48443. reentrant = true;
  48444. ComponentPeer* const peer = component->getPeer();
  48445. if (peer != lastPeer)
  48446. {
  48447. componentPeerChanged();
  48448. if (component == 0)
  48449. return;
  48450. lastPeer = peer;
  48451. }
  48452. unregister();
  48453. registerWithParentComps();
  48454. reentrant = false;
  48455. componentMovedOrResized (*component, true, true);
  48456. }
  48457. }
  48458. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48459. {
  48460. // agh! don't delete the target component without deleting this object first!
  48461. jassert (component != 0);
  48462. if (wasMoved)
  48463. {
  48464. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48465. wasMoved = lastBounds.getPosition() != pos;
  48466. lastBounds.setPosition (pos);
  48467. }
  48468. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48469. lastBounds.setSize (component->getWidth(), component->getHeight());
  48470. if (wasMoved || wasResized)
  48471. componentMovedOrResized (wasMoved, wasResized);
  48472. }
  48473. void ComponentMovementWatcher::registerWithParentComps() throw()
  48474. {
  48475. Component* p = component->getParentComponent();
  48476. while (p != 0)
  48477. {
  48478. p->addComponentListener (this);
  48479. registeredParentComps.add (p);
  48480. p = p->getParentComponent();
  48481. }
  48482. }
  48483. void ComponentMovementWatcher::unregister() throw()
  48484. {
  48485. for (int i = registeredParentComps.size(); --i >= 0;)
  48486. static_cast <Component*> (registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48487. registeredParentComps.clear();
  48488. }
  48489. END_JUCE_NAMESPACE
  48490. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48491. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48492. BEGIN_JUCE_NAMESPACE
  48493. GroupComponent::GroupComponent (const String& componentName,
  48494. const String& labelText)
  48495. : Component (componentName),
  48496. text (labelText),
  48497. justification (Justification::left)
  48498. {
  48499. setInterceptsMouseClicks (false, true);
  48500. }
  48501. GroupComponent::~GroupComponent()
  48502. {
  48503. }
  48504. void GroupComponent::setText (const String& newText)
  48505. {
  48506. if (text != newText)
  48507. {
  48508. text = newText;
  48509. repaint();
  48510. }
  48511. }
  48512. const String GroupComponent::getText() const
  48513. {
  48514. return text;
  48515. }
  48516. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48517. {
  48518. if (justification.getFlags() != newJustification.getFlags())
  48519. {
  48520. justification = newJustification;
  48521. repaint();
  48522. }
  48523. }
  48524. void GroupComponent::paint (Graphics& g)
  48525. {
  48526. getLookAndFeel()
  48527. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48528. text, justification,
  48529. *this);
  48530. }
  48531. void GroupComponent::enablementChanged()
  48532. {
  48533. repaint();
  48534. }
  48535. void GroupComponent::colourChanged()
  48536. {
  48537. repaint();
  48538. }
  48539. END_JUCE_NAMESPACE
  48540. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48541. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48542. BEGIN_JUCE_NAMESPACE
  48543. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48544. : DocumentWindow (String::empty, backgroundColour,
  48545. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48546. {
  48547. }
  48548. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48549. {
  48550. }
  48551. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48552. {
  48553. MultiDocumentPanel* const owner = getOwner();
  48554. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48555. if (owner != 0)
  48556. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48557. }
  48558. void MultiDocumentPanelWindow::closeButtonPressed()
  48559. {
  48560. MultiDocumentPanel* const owner = getOwner();
  48561. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48562. if (owner != 0)
  48563. owner->closeDocument (getContentComponent(), true);
  48564. }
  48565. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48566. {
  48567. DocumentWindow::activeWindowStatusChanged();
  48568. updateOrder();
  48569. }
  48570. void MultiDocumentPanelWindow::broughtToFront()
  48571. {
  48572. DocumentWindow::broughtToFront();
  48573. updateOrder();
  48574. }
  48575. void MultiDocumentPanelWindow::updateOrder()
  48576. {
  48577. MultiDocumentPanel* const owner = getOwner();
  48578. if (owner != 0)
  48579. owner->updateOrder();
  48580. }
  48581. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48582. {
  48583. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48584. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48585. }
  48586. class MDITabbedComponentInternal : public TabbedComponent
  48587. {
  48588. public:
  48589. MDITabbedComponentInternal()
  48590. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48591. {
  48592. }
  48593. ~MDITabbedComponentInternal()
  48594. {
  48595. }
  48596. void currentTabChanged (int, const String&)
  48597. {
  48598. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48599. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48600. if (owner != 0)
  48601. owner->updateOrder();
  48602. }
  48603. };
  48604. MultiDocumentPanel::MultiDocumentPanel()
  48605. : mode (MaximisedWindowsWithTabs),
  48606. tabComponent (0),
  48607. backgroundColour (Colours::lightblue),
  48608. maximumNumDocuments (0),
  48609. numDocsBeforeTabsUsed (0)
  48610. {
  48611. setOpaque (true);
  48612. }
  48613. MultiDocumentPanel::~MultiDocumentPanel()
  48614. {
  48615. closeAllDocuments (false);
  48616. }
  48617. static bool shouldDeleteComp (Component* const c)
  48618. {
  48619. return c->getProperties() ["mdiDocumentDelete_"];
  48620. }
  48621. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48622. {
  48623. while (components.size() > 0)
  48624. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48625. return false;
  48626. return true;
  48627. }
  48628. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48629. {
  48630. return new MultiDocumentPanelWindow (backgroundColour);
  48631. }
  48632. void MultiDocumentPanel::addWindow (Component* component)
  48633. {
  48634. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48635. dw->setResizable (true, false);
  48636. dw->setContentComponent (component, false, true);
  48637. dw->setName (component->getName());
  48638. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48639. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48640. int x = 4;
  48641. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48642. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48643. x += 16;
  48644. dw->setTopLeftPosition (x, x);
  48645. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48646. if (pos.toString().isNotEmpty())
  48647. dw->restoreWindowStateFromString (pos.toString());
  48648. addAndMakeVisible (dw);
  48649. dw->toFront (true);
  48650. }
  48651. bool MultiDocumentPanel::addDocument (Component* const component,
  48652. const Colour& docColour,
  48653. const bool deleteWhenRemoved)
  48654. {
  48655. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48656. // with a frame-within-a-frame! Just pass in the bare content component.
  48657. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48658. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48659. return false;
  48660. components.add (component);
  48661. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48662. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48663. component->addComponentListener (this);
  48664. if (mode == FloatingWindows)
  48665. {
  48666. if (isFullscreenWhenOneDocument())
  48667. {
  48668. if (components.size() == 1)
  48669. {
  48670. addAndMakeVisible (component);
  48671. }
  48672. else
  48673. {
  48674. if (components.size() == 2)
  48675. addWindow (components.getFirst());
  48676. addWindow (component);
  48677. }
  48678. }
  48679. else
  48680. {
  48681. addWindow (component);
  48682. }
  48683. }
  48684. else
  48685. {
  48686. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48687. {
  48688. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48689. Array <Component*> temp (components);
  48690. for (int i = 0; i < temp.size(); ++i)
  48691. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48692. resized();
  48693. }
  48694. else
  48695. {
  48696. if (tabComponent != 0)
  48697. tabComponent->addTab (component->getName(), docColour, component, false);
  48698. else
  48699. addAndMakeVisible (component);
  48700. }
  48701. setActiveDocument (component);
  48702. }
  48703. resized();
  48704. activeDocumentChanged();
  48705. return true;
  48706. }
  48707. bool MultiDocumentPanel::closeDocument (Component* component,
  48708. const bool checkItsOkToCloseFirst)
  48709. {
  48710. if (components.contains (component))
  48711. {
  48712. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48713. return false;
  48714. component->removeComponentListener (this);
  48715. const bool shouldDelete = shouldDeleteComp (component);
  48716. component->getProperties().remove ("mdiDocumentDelete_");
  48717. component->getProperties().remove ("mdiDocumentBkg_");
  48718. if (mode == FloatingWindows)
  48719. {
  48720. for (int i = getNumChildComponents(); --i >= 0;)
  48721. {
  48722. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48723. if (dw != 0 && dw->getContentComponent() == component)
  48724. {
  48725. dw->setContentComponent (0, false);
  48726. delete dw;
  48727. break;
  48728. }
  48729. }
  48730. if (shouldDelete)
  48731. delete component;
  48732. components.removeValue (component);
  48733. if (isFullscreenWhenOneDocument() && components.size() == 1)
  48734. {
  48735. for (int i = getNumChildComponents(); --i >= 0;)
  48736. {
  48737. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48738. if (dw != 0)
  48739. {
  48740. dw->setContentComponent (0, false);
  48741. delete dw;
  48742. }
  48743. }
  48744. addAndMakeVisible (components.getFirst());
  48745. }
  48746. }
  48747. else
  48748. {
  48749. jassert (components.indexOf (component) >= 0);
  48750. if (tabComponent != 0)
  48751. {
  48752. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48753. if (tabComponent->getTabContentComponent (i) == component)
  48754. tabComponent->removeTab (i);
  48755. }
  48756. else
  48757. {
  48758. removeChildComponent (component);
  48759. }
  48760. if (shouldDelete)
  48761. delete component;
  48762. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  48763. deleteAndZero (tabComponent);
  48764. components.removeValue (component);
  48765. if (components.size() > 0 && tabComponent == 0)
  48766. addAndMakeVisible (components.getFirst());
  48767. }
  48768. resized();
  48769. activeDocumentChanged();
  48770. }
  48771. else
  48772. {
  48773. jassertfalse
  48774. }
  48775. return true;
  48776. }
  48777. int MultiDocumentPanel::getNumDocuments() const throw()
  48778. {
  48779. return components.size();
  48780. }
  48781. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  48782. {
  48783. return components [index];
  48784. }
  48785. Component* MultiDocumentPanel::getActiveDocument() const throw()
  48786. {
  48787. if (mode == FloatingWindows)
  48788. {
  48789. for (int i = getNumChildComponents(); --i >= 0;)
  48790. {
  48791. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48792. if (dw != 0 && dw->isActiveWindow())
  48793. return dw->getContentComponent();
  48794. }
  48795. }
  48796. return components.getLast();
  48797. }
  48798. void MultiDocumentPanel::setActiveDocument (Component* component)
  48799. {
  48800. if (mode == FloatingWindows)
  48801. {
  48802. component = getContainerComp (component);
  48803. if (component != 0)
  48804. component->toFront (true);
  48805. }
  48806. else if (tabComponent != 0)
  48807. {
  48808. jassert (components.indexOf (component) >= 0);
  48809. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48810. {
  48811. if (tabComponent->getTabContentComponent (i) == component)
  48812. {
  48813. tabComponent->setCurrentTabIndex (i);
  48814. break;
  48815. }
  48816. }
  48817. }
  48818. else
  48819. {
  48820. component->grabKeyboardFocus();
  48821. }
  48822. }
  48823. void MultiDocumentPanel::activeDocumentChanged()
  48824. {
  48825. }
  48826. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  48827. {
  48828. maximumNumDocuments = newNumber;
  48829. }
  48830. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  48831. {
  48832. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  48833. }
  48834. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  48835. {
  48836. return numDocsBeforeTabsUsed != 0;
  48837. }
  48838. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  48839. {
  48840. if (mode != newLayoutMode)
  48841. {
  48842. mode = newLayoutMode;
  48843. if (mode == FloatingWindows)
  48844. {
  48845. deleteAndZero (tabComponent);
  48846. }
  48847. else
  48848. {
  48849. for (int i = getNumChildComponents(); --i >= 0;)
  48850. {
  48851. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48852. if (dw != 0)
  48853. {
  48854. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  48855. dw->setContentComponent (0, false);
  48856. delete dw;
  48857. }
  48858. }
  48859. }
  48860. resized();
  48861. const Array <Component*> tempComps (components);
  48862. components.clear();
  48863. for (int i = 0; i < tempComps.size(); ++i)
  48864. {
  48865. Component* const c = tempComps.getUnchecked(i);
  48866. addDocument (c,
  48867. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  48868. shouldDeleteComp (c));
  48869. }
  48870. }
  48871. }
  48872. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  48873. {
  48874. if (backgroundColour != newBackgroundColour)
  48875. {
  48876. backgroundColour = newBackgroundColour;
  48877. setOpaque (newBackgroundColour.isOpaque());
  48878. repaint();
  48879. }
  48880. }
  48881. void MultiDocumentPanel::paint (Graphics& g)
  48882. {
  48883. g.fillAll (backgroundColour);
  48884. }
  48885. void MultiDocumentPanel::resized()
  48886. {
  48887. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  48888. {
  48889. for (int i = getNumChildComponents(); --i >= 0;)
  48890. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  48891. }
  48892. setWantsKeyboardFocus (components.size() == 0);
  48893. }
  48894. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  48895. {
  48896. if (mode == FloatingWindows)
  48897. {
  48898. for (int i = 0; i < getNumChildComponents(); ++i)
  48899. {
  48900. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48901. if (dw != 0 && dw->getContentComponent() == c)
  48902. {
  48903. c = dw;
  48904. break;
  48905. }
  48906. }
  48907. }
  48908. return c;
  48909. }
  48910. void MultiDocumentPanel::componentNameChanged (Component&)
  48911. {
  48912. if (mode == FloatingWindows)
  48913. {
  48914. for (int i = 0; i < getNumChildComponents(); ++i)
  48915. {
  48916. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48917. if (dw != 0)
  48918. dw->setName (dw->getContentComponent()->getName());
  48919. }
  48920. }
  48921. else if (tabComponent != 0)
  48922. {
  48923. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48924. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  48925. }
  48926. }
  48927. void MultiDocumentPanel::updateOrder()
  48928. {
  48929. const Array <Component*> oldList (components);
  48930. if (mode == FloatingWindows)
  48931. {
  48932. components.clear();
  48933. for (int i = 0; i < getNumChildComponents(); ++i)
  48934. {
  48935. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48936. if (dw != 0)
  48937. components.add (dw->getContentComponent());
  48938. }
  48939. }
  48940. else
  48941. {
  48942. if (tabComponent != 0)
  48943. {
  48944. Component* const current = tabComponent->getCurrentContentComponent();
  48945. if (current != 0)
  48946. {
  48947. components.removeValue (current);
  48948. components.add (current);
  48949. }
  48950. }
  48951. }
  48952. if (components != oldList)
  48953. activeDocumentChanged();
  48954. }
  48955. END_JUCE_NAMESPACE
  48956. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  48957. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  48958. BEGIN_JUCE_NAMESPACE
  48959. ResizableBorderComponent::Zone::Zone (int zoneFlags) throw()
  48960. : zone (zoneFlags)
  48961. {
  48962. }
  48963. ResizableBorderComponent::Zone::Zone (const ResizableBorderComponent::Zone& other) throw() : zone (other.zone) {}
  48964. ResizableBorderComponent::Zone& ResizableBorderComponent::Zone::operator= (const ResizableBorderComponent::Zone& other) throw() { zone = other.zone; return *this; }
  48965. bool ResizableBorderComponent::Zone::operator== (const ResizableBorderComponent::Zone& other) const throw() { return zone == other.zone; }
  48966. bool ResizableBorderComponent::Zone::operator!= (const ResizableBorderComponent::Zone& other) const throw() { return zone != other.zone; }
  48967. const ResizableBorderComponent::Zone ResizableBorderComponent::Zone::fromPositionOnBorder (const Rectangle<int>& totalSize,
  48968. const BorderSize& border,
  48969. const Point<int>& position)
  48970. {
  48971. int z = 0;
  48972. if (totalSize.contains (position)
  48973. && ! border.subtractedFrom (totalSize).contains (position))
  48974. {
  48975. const int minW = jmax (totalSize.getWidth() / 10, jmin (10, totalSize.getWidth() / 3));
  48976. if (position.getX() < jmax (border.getLeft(), minW))
  48977. z |= left;
  48978. else if (position.getX() >= totalSize.getWidth() - jmax (border.getRight(), minW))
  48979. z |= right;
  48980. const int minH = jmax (totalSize.getHeight() / 10, jmin (10, totalSize.getHeight() / 3));
  48981. if (position.getY() < jmax (border.getTop(), minH))
  48982. z |= top;
  48983. else if (position.getY() >= totalSize.getHeight() - jmax (border.getBottom(), minH))
  48984. z |= bottom;
  48985. }
  48986. return Zone (z);
  48987. }
  48988. const MouseCursor ResizableBorderComponent::Zone::getMouseCursor() const throw()
  48989. {
  48990. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  48991. switch (zone)
  48992. {
  48993. case (left | top): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  48994. case top: mc = MouseCursor::TopEdgeResizeCursor; break;
  48995. case (right | top): mc = MouseCursor::TopRightCornerResizeCursor; break;
  48996. case left: mc = MouseCursor::LeftEdgeResizeCursor; break;
  48997. case right: mc = MouseCursor::RightEdgeResizeCursor; break;
  48998. case (left | bottom): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  48999. case bottom: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49000. case (right | bottom): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49001. default: break;
  49002. }
  49003. return mc;
  49004. }
  49005. const Rectangle<int> ResizableBorderComponent::Zone::resizeRectangleBy (Rectangle<int> b, const Point<int>& offset) const throw()
  49006. {
  49007. if (isDraggingWholeObject())
  49008. return b + offset;
  49009. if (isDraggingLeftEdge())
  49010. b.setLeft (b.getX() + offset.getX());
  49011. if (isDraggingRightEdge())
  49012. b.setWidth (jmax (0, b.getWidth() + offset.getX()));
  49013. if (isDraggingTopEdge())
  49014. b.setTop (b.getY() + offset.getY());
  49015. if (isDraggingBottomEdge())
  49016. b.setHeight (jmax (0, b.getHeight() + offset.getY()));
  49017. return b;
  49018. }
  49019. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49020. ComponentBoundsConstrainer* const constrainer_)
  49021. : component (componentToResize),
  49022. constrainer (constrainer_),
  49023. borderSize (5),
  49024. mouseZone (0)
  49025. {
  49026. }
  49027. ResizableBorderComponent::~ResizableBorderComponent()
  49028. {
  49029. }
  49030. void ResizableBorderComponent::paint (Graphics& g)
  49031. {
  49032. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49033. }
  49034. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49035. {
  49036. updateMouseZone (e);
  49037. }
  49038. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49039. {
  49040. updateMouseZone (e);
  49041. }
  49042. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49043. {
  49044. if (component == 0)
  49045. {
  49046. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49047. return;
  49048. }
  49049. updateMouseZone (e);
  49050. originalBounds = component->getBounds();
  49051. if (constrainer != 0)
  49052. constrainer->resizeStart();
  49053. }
  49054. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49055. {
  49056. if (component == 0)
  49057. {
  49058. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49059. return;
  49060. }
  49061. const Rectangle<int> bounds (mouseZone.resizeRectangleBy (originalBounds, e.getOffsetFromDragStart()));
  49062. if (constrainer != 0)
  49063. constrainer->setBoundsForComponent (component, bounds,
  49064. mouseZone.isDraggingTopEdge(),
  49065. mouseZone.isDraggingLeftEdge(),
  49066. mouseZone.isDraggingBottomEdge(),
  49067. mouseZone.isDraggingRightEdge());
  49068. else
  49069. component->setBounds (bounds);
  49070. }
  49071. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49072. {
  49073. if (constrainer != 0)
  49074. constrainer->resizeEnd();
  49075. }
  49076. bool ResizableBorderComponent::hitTest (int x, int y)
  49077. {
  49078. return x < borderSize.getLeft()
  49079. || x >= getWidth() - borderSize.getRight()
  49080. || y < borderSize.getTop()
  49081. || y >= getHeight() - borderSize.getBottom();
  49082. }
  49083. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49084. {
  49085. if (borderSize != newBorderSize)
  49086. {
  49087. borderSize = newBorderSize;
  49088. repaint();
  49089. }
  49090. }
  49091. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49092. {
  49093. return borderSize;
  49094. }
  49095. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49096. {
  49097. Zone newZone (Zone::fromPositionOnBorder (getLocalBounds(), borderSize, e.getPosition()));
  49098. if (mouseZone != newZone)
  49099. {
  49100. mouseZone = newZone;
  49101. setMouseCursor (newZone.getMouseCursor());
  49102. }
  49103. }
  49104. END_JUCE_NAMESPACE
  49105. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49106. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49107. BEGIN_JUCE_NAMESPACE
  49108. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49109. ComponentBoundsConstrainer* const constrainer_)
  49110. : component (componentToResize),
  49111. constrainer (constrainer_)
  49112. {
  49113. setRepaintsOnMouseActivity (true);
  49114. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49115. }
  49116. ResizableCornerComponent::~ResizableCornerComponent()
  49117. {
  49118. }
  49119. void ResizableCornerComponent::paint (Graphics& g)
  49120. {
  49121. getLookAndFeel()
  49122. .drawCornerResizer (g, getWidth(), getHeight(),
  49123. isMouseOverOrDragging(),
  49124. isMouseButtonDown());
  49125. }
  49126. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49127. {
  49128. if (component == 0)
  49129. {
  49130. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49131. return;
  49132. }
  49133. originalBounds = component->getBounds();
  49134. if (constrainer != 0)
  49135. constrainer->resizeStart();
  49136. }
  49137. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49138. {
  49139. if (component == 0)
  49140. {
  49141. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49142. return;
  49143. }
  49144. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49145. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49146. if (constrainer != 0)
  49147. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49148. else
  49149. component->setBounds (r);
  49150. }
  49151. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49152. {
  49153. if (constrainer != 0)
  49154. constrainer->resizeStart();
  49155. }
  49156. bool ResizableCornerComponent::hitTest (int x, int y)
  49157. {
  49158. if (getWidth() <= 0)
  49159. return false;
  49160. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49161. return y >= yAtX - getHeight() / 4;
  49162. }
  49163. END_JUCE_NAMESPACE
  49164. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49165. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49166. BEGIN_JUCE_NAMESPACE
  49167. class ScrollBar::ScrollbarButton : public Button
  49168. {
  49169. public:
  49170. int direction;
  49171. ScrollbarButton (const int direction_, ScrollBar& owner_)
  49172. : Button (String::empty),
  49173. direction (direction_),
  49174. owner (owner_)
  49175. {
  49176. setWantsKeyboardFocus (false);
  49177. }
  49178. ~ScrollbarButton()
  49179. {
  49180. }
  49181. void paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  49182. {
  49183. getLookAndFeel()
  49184. .drawScrollbarButton (g, owner,
  49185. getWidth(), getHeight(),
  49186. direction,
  49187. owner.isVertical(),
  49188. isMouseOver, isMouseDown);
  49189. }
  49190. void clicked()
  49191. {
  49192. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49193. }
  49194. juce_UseDebuggingNewOperator
  49195. private:
  49196. ScrollBar& owner;
  49197. ScrollbarButton (const ScrollbarButton&);
  49198. ScrollbarButton& operator= (const ScrollbarButton&);
  49199. };
  49200. ScrollBar::ScrollBar (const bool vertical_,
  49201. const bool buttonsAreVisible)
  49202. : totalRange (0.0, 1.0),
  49203. visibleRange (0.0, 0.1),
  49204. singleStepSize (0.1),
  49205. thumbAreaStart (0),
  49206. thumbAreaSize (0),
  49207. thumbStart (0),
  49208. thumbSize (0),
  49209. initialDelayInMillisecs (100),
  49210. repeatDelayInMillisecs (50),
  49211. minimumDelayInMillisecs (10),
  49212. vertical (vertical_),
  49213. isDraggingThumb (false),
  49214. autohides (true),
  49215. upButton (0),
  49216. downButton (0)
  49217. {
  49218. setButtonVisibility (buttonsAreVisible);
  49219. setRepaintsOnMouseActivity (true);
  49220. setFocusContainer (true);
  49221. }
  49222. ScrollBar::~ScrollBar()
  49223. {
  49224. deleteAllChildren();
  49225. }
  49226. void ScrollBar::setRangeLimits (const Range<double>& newRangeLimit)
  49227. {
  49228. if (totalRange != newRangeLimit)
  49229. {
  49230. totalRange = newRangeLimit;
  49231. setCurrentRange (visibleRange);
  49232. updateThumbPosition();
  49233. }
  49234. }
  49235. void ScrollBar::setRangeLimits (const double newMinimum, const double newMaximum)
  49236. {
  49237. jassert (newMaximum >= newMinimum); // these can't be the wrong way round!
  49238. setRangeLimits (Range<double> (newMinimum, newMaximum));
  49239. }
  49240. void ScrollBar::setCurrentRange (const Range<double>& newRange)
  49241. {
  49242. const Range<double> constrainedRange (totalRange.constrainRange (newRange));
  49243. if (visibleRange != constrainedRange)
  49244. {
  49245. visibleRange = constrainedRange;
  49246. updateThumbPosition();
  49247. triggerAsyncUpdate();
  49248. }
  49249. }
  49250. void ScrollBar::setCurrentRange (const double newStart, const double newSize)
  49251. {
  49252. setCurrentRange (Range<double> (newStart, newStart + newSize));
  49253. }
  49254. void ScrollBar::setCurrentRangeStart (const double newStart)
  49255. {
  49256. setCurrentRange (visibleRange.movedToStartAt (newStart));
  49257. }
  49258. void ScrollBar::setSingleStepSize (const double newSingleStepSize)
  49259. {
  49260. singleStepSize = newSingleStepSize;
  49261. }
  49262. void ScrollBar::moveScrollbarInSteps (const int howManySteps)
  49263. {
  49264. setCurrentRange (visibleRange + howManySteps * singleStepSize);
  49265. }
  49266. void ScrollBar::moveScrollbarInPages (const int howManyPages)
  49267. {
  49268. setCurrentRange (visibleRange + howManyPages * visibleRange.getLength());
  49269. }
  49270. void ScrollBar::scrollToTop()
  49271. {
  49272. setCurrentRange (visibleRange.movedToStartAt (getMinimumRangeLimit()));
  49273. }
  49274. void ScrollBar::scrollToBottom()
  49275. {
  49276. setCurrentRange (visibleRange.movedToEndAt (getMaximumRangeLimit()));
  49277. }
  49278. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49279. const int repeatDelayInMillisecs_,
  49280. const int minimumDelayInMillisecs_)
  49281. {
  49282. initialDelayInMillisecs = initialDelayInMillisecs_;
  49283. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49284. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49285. if (upButton != 0)
  49286. {
  49287. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49288. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49289. }
  49290. }
  49291. void ScrollBar::addListener (ScrollBarListener* const listener)
  49292. {
  49293. listeners.add (listener);
  49294. }
  49295. void ScrollBar::removeListener (ScrollBarListener* const listener)
  49296. {
  49297. listeners.remove (listener);
  49298. }
  49299. void ScrollBar::handleAsyncUpdate()
  49300. {
  49301. double start = visibleRange.getStart(); // (need to use a temp variable for VC7 compatibility)
  49302. listeners.call (&ScrollBarListener::scrollBarMoved, this, start);
  49303. }
  49304. void ScrollBar::updateThumbPosition()
  49305. {
  49306. int newThumbSize = roundToInt (totalRange.getLength() > 0 ? (visibleRange.getLength() * thumbAreaSize) / totalRange.getLength()
  49307. : thumbAreaSize);
  49308. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49309. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49310. if (newThumbSize > thumbAreaSize)
  49311. newThumbSize = thumbAreaSize;
  49312. int newThumbStart = thumbAreaStart;
  49313. if (totalRange.getLength() > visibleRange.getLength())
  49314. newThumbStart += roundToInt (((visibleRange.getStart() - totalRange.getStart()) * (thumbAreaSize - newThumbSize))
  49315. / (totalRange.getLength() - visibleRange.getLength()));
  49316. setVisible ((! autohides) || (totalRange.getLength() > visibleRange.getLength() && visibleRange.getLength() > 0.0));
  49317. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49318. {
  49319. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49320. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49321. if (vertical)
  49322. repaint (0, repaintStart, getWidth(), repaintSize);
  49323. else
  49324. repaint (repaintStart, 0, repaintSize, getHeight());
  49325. thumbStart = newThumbStart;
  49326. thumbSize = newThumbSize;
  49327. }
  49328. }
  49329. void ScrollBar::setOrientation (const bool shouldBeVertical)
  49330. {
  49331. if (vertical != shouldBeVertical)
  49332. {
  49333. vertical = shouldBeVertical;
  49334. if (upButton != 0)
  49335. {
  49336. upButton->direction = vertical ? 0 : 3;
  49337. downButton->direction = vertical ? 2 : 1;
  49338. }
  49339. updateThumbPosition();
  49340. }
  49341. }
  49342. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49343. {
  49344. delete upButton;
  49345. upButton = 0;
  49346. delete downButton;
  49347. downButton = 0;
  49348. if (buttonsAreVisible)
  49349. {
  49350. addAndMakeVisible (upButton = new ScrollbarButton (vertical ? 0 : 3, *this));
  49351. addAndMakeVisible (downButton = new ScrollbarButton (vertical ? 2 : 1, *this));
  49352. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49353. }
  49354. updateThumbPosition();
  49355. }
  49356. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49357. {
  49358. autohides = shouldHideWhenFullRange;
  49359. updateThumbPosition();
  49360. }
  49361. bool ScrollBar::autoHides() const throw()
  49362. {
  49363. return autohides;
  49364. }
  49365. void ScrollBar::paint (Graphics& g)
  49366. {
  49367. if (thumbAreaSize > 0)
  49368. {
  49369. LookAndFeel& lf = getLookAndFeel();
  49370. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49371. ? thumbSize : 0;
  49372. if (vertical)
  49373. {
  49374. lf.drawScrollbar (g, *this,
  49375. 0, thumbAreaStart,
  49376. getWidth(), thumbAreaSize,
  49377. vertical,
  49378. thumbStart, thumb,
  49379. isMouseOver(), isMouseButtonDown());
  49380. }
  49381. else
  49382. {
  49383. lf.drawScrollbar (g, *this,
  49384. thumbAreaStart, 0,
  49385. thumbAreaSize, getHeight(),
  49386. vertical,
  49387. thumbStart, thumb,
  49388. isMouseOver(), isMouseButtonDown());
  49389. }
  49390. }
  49391. }
  49392. void ScrollBar::lookAndFeelChanged()
  49393. {
  49394. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49395. }
  49396. void ScrollBar::resized()
  49397. {
  49398. const int length = ((vertical) ? getHeight() : getWidth());
  49399. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49400. : 0;
  49401. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49402. {
  49403. thumbAreaStart = length >> 1;
  49404. thumbAreaSize = 0;
  49405. }
  49406. else
  49407. {
  49408. thumbAreaStart = buttonSize;
  49409. thumbAreaSize = length - (buttonSize << 1);
  49410. }
  49411. if (upButton != 0)
  49412. {
  49413. if (vertical)
  49414. {
  49415. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49416. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49417. }
  49418. else
  49419. {
  49420. upButton->setBounds (0, 0, buttonSize, getHeight());
  49421. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49422. }
  49423. }
  49424. updateThumbPosition();
  49425. }
  49426. void ScrollBar::mouseDown (const MouseEvent& e)
  49427. {
  49428. isDraggingThumb = false;
  49429. lastMousePos = vertical ? e.y : e.x;
  49430. dragStartMousePos = lastMousePos;
  49431. dragStartRange = visibleRange.getStart();
  49432. if (dragStartMousePos < thumbStart)
  49433. {
  49434. moveScrollbarInPages (-1);
  49435. startTimer (400);
  49436. }
  49437. else if (dragStartMousePos >= thumbStart + thumbSize)
  49438. {
  49439. moveScrollbarInPages (1);
  49440. startTimer (400);
  49441. }
  49442. else
  49443. {
  49444. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49445. && (thumbAreaSize > thumbSize);
  49446. }
  49447. }
  49448. void ScrollBar::mouseDrag (const MouseEvent& e)
  49449. {
  49450. if (isDraggingThumb)
  49451. {
  49452. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49453. setCurrentRangeStart (dragStartRange
  49454. + deltaPixels * (totalRange.getLength() - visibleRange.getLength())
  49455. / (thumbAreaSize - thumbSize));
  49456. }
  49457. else
  49458. {
  49459. lastMousePos = (vertical) ? e.y : e.x;
  49460. }
  49461. }
  49462. void ScrollBar::mouseUp (const MouseEvent&)
  49463. {
  49464. isDraggingThumb = false;
  49465. stopTimer();
  49466. repaint();
  49467. }
  49468. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49469. float wheelIncrementX,
  49470. float wheelIncrementY)
  49471. {
  49472. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49473. if (increment < 0)
  49474. increment = jmin (increment * 10.0f, -1.0f);
  49475. else if (increment > 0)
  49476. increment = jmax (increment * 10.0f, 1.0f);
  49477. setCurrentRange (visibleRange - singleStepSize * increment);
  49478. }
  49479. void ScrollBar::timerCallback()
  49480. {
  49481. if (isMouseButtonDown())
  49482. {
  49483. startTimer (40);
  49484. if (lastMousePos < thumbStart)
  49485. setCurrentRange (visibleRange - visibleRange.getLength());
  49486. else if (lastMousePos > thumbStart + thumbSize)
  49487. setCurrentRangeStart (visibleRange.getEnd());
  49488. }
  49489. else
  49490. {
  49491. stopTimer();
  49492. }
  49493. }
  49494. bool ScrollBar::keyPressed (const KeyPress& key)
  49495. {
  49496. if (! isVisible())
  49497. return false;
  49498. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49499. moveScrollbarInSteps (-1);
  49500. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49501. moveScrollbarInSteps (1);
  49502. else if (key.isKeyCode (KeyPress::pageUpKey))
  49503. moveScrollbarInPages (-1);
  49504. else if (key.isKeyCode (KeyPress::pageDownKey))
  49505. moveScrollbarInPages (1);
  49506. else if (key.isKeyCode (KeyPress::homeKey))
  49507. scrollToTop();
  49508. else if (key.isKeyCode (KeyPress::endKey))
  49509. scrollToBottom();
  49510. else
  49511. return false;
  49512. return true;
  49513. }
  49514. END_JUCE_NAMESPACE
  49515. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49516. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49517. BEGIN_JUCE_NAMESPACE
  49518. StretchableLayoutManager::StretchableLayoutManager()
  49519. : totalSize (0)
  49520. {
  49521. }
  49522. StretchableLayoutManager::~StretchableLayoutManager()
  49523. {
  49524. }
  49525. void StretchableLayoutManager::clearAllItems()
  49526. {
  49527. items.clear();
  49528. totalSize = 0;
  49529. }
  49530. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49531. const double minimumSize,
  49532. const double maximumSize,
  49533. const double preferredSize)
  49534. {
  49535. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49536. if (layout == 0)
  49537. {
  49538. layout = new ItemLayoutProperties();
  49539. layout->itemIndex = itemIndex;
  49540. int i;
  49541. for (i = 0; i < items.size(); ++i)
  49542. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49543. break;
  49544. items.insert (i, layout);
  49545. }
  49546. layout->minSize = minimumSize;
  49547. layout->maxSize = maximumSize;
  49548. layout->preferredSize = preferredSize;
  49549. layout->currentSize = 0;
  49550. }
  49551. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49552. double& minimumSize,
  49553. double& maximumSize,
  49554. double& preferredSize) const
  49555. {
  49556. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49557. if (layout != 0)
  49558. {
  49559. minimumSize = layout->minSize;
  49560. maximumSize = layout->maxSize;
  49561. preferredSize = layout->preferredSize;
  49562. return true;
  49563. }
  49564. return false;
  49565. }
  49566. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49567. {
  49568. totalSize = newTotalSize;
  49569. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49570. }
  49571. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49572. {
  49573. int pos = 0;
  49574. for (int i = 0; i < itemIndex; ++i)
  49575. {
  49576. const ItemLayoutProperties* const layout = getInfoFor (i);
  49577. if (layout != 0)
  49578. pos += layout->currentSize;
  49579. }
  49580. return pos;
  49581. }
  49582. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49583. {
  49584. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49585. if (layout != 0)
  49586. return layout->currentSize;
  49587. return 0;
  49588. }
  49589. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49590. {
  49591. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49592. if (layout != 0)
  49593. return -layout->currentSize / (double) totalSize;
  49594. return 0;
  49595. }
  49596. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49597. int newPosition)
  49598. {
  49599. for (int i = items.size(); --i >= 0;)
  49600. {
  49601. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49602. if (layout->itemIndex == itemIndex)
  49603. {
  49604. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49605. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49606. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49607. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49608. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49609. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49610. endPos += layout->currentSize;
  49611. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49612. updatePrefSizesToMatchCurrentPositions();
  49613. break;
  49614. }
  49615. }
  49616. }
  49617. void StretchableLayoutManager::layOutComponents (Component** const components,
  49618. int numComponents,
  49619. int x, int y, int w, int h,
  49620. const bool vertically,
  49621. const bool resizeOtherDimension)
  49622. {
  49623. setTotalSize (vertically ? h : w);
  49624. int pos = vertically ? y : x;
  49625. for (int i = 0; i < numComponents; ++i)
  49626. {
  49627. const ItemLayoutProperties* const layout = getInfoFor (i);
  49628. if (layout != 0)
  49629. {
  49630. Component* const c = components[i];
  49631. if (c != 0)
  49632. {
  49633. if (i == numComponents - 1)
  49634. {
  49635. // if it's the last item, crop it to exactly fit the available space..
  49636. if (resizeOtherDimension)
  49637. {
  49638. if (vertically)
  49639. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49640. else
  49641. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49642. }
  49643. else
  49644. {
  49645. if (vertically)
  49646. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49647. else
  49648. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49649. }
  49650. }
  49651. else
  49652. {
  49653. if (resizeOtherDimension)
  49654. {
  49655. if (vertically)
  49656. c->setBounds (x, pos, w, layout->currentSize);
  49657. else
  49658. c->setBounds (pos, y, layout->currentSize, h);
  49659. }
  49660. else
  49661. {
  49662. if (vertically)
  49663. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49664. else
  49665. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49666. }
  49667. }
  49668. }
  49669. pos += layout->currentSize;
  49670. }
  49671. }
  49672. }
  49673. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49674. {
  49675. for (int i = items.size(); --i >= 0;)
  49676. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49677. return items.getUnchecked(i);
  49678. return 0;
  49679. }
  49680. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49681. const int endIndex,
  49682. const int availableSpace,
  49683. int startPos)
  49684. {
  49685. // calculate the total sizes
  49686. int i;
  49687. double totalIdealSize = 0.0;
  49688. int totalMinimums = 0;
  49689. for (i = startIndex; i < endIndex; ++i)
  49690. {
  49691. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49692. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49693. totalMinimums += layout->currentSize;
  49694. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49695. }
  49696. if (totalIdealSize <= 0)
  49697. totalIdealSize = 1.0;
  49698. // now calc the best sizes..
  49699. int extraSpace = availableSpace - totalMinimums;
  49700. while (extraSpace > 0)
  49701. {
  49702. int numWantingMoreSpace = 0;
  49703. int numHavingTakenExtraSpace = 0;
  49704. // first figure out how many comps want a slice of the extra space..
  49705. for (i = startIndex; i < endIndex; ++i)
  49706. {
  49707. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49708. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49709. const int bestSize = jlimit (layout->currentSize,
  49710. jmax (layout->currentSize,
  49711. sizeToRealSize (layout->maxSize, totalSize)),
  49712. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49713. if (bestSize > layout->currentSize)
  49714. ++numWantingMoreSpace;
  49715. }
  49716. // ..share out the extra space..
  49717. for (i = startIndex; i < endIndex; ++i)
  49718. {
  49719. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49720. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49721. int bestSize = jlimit (layout->currentSize,
  49722. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49723. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49724. const int extraWanted = bestSize - layout->currentSize;
  49725. if (extraWanted > 0)
  49726. {
  49727. const int extraAllowed = jmin (extraWanted,
  49728. extraSpace / jmax (1, numWantingMoreSpace));
  49729. if (extraAllowed > 0)
  49730. {
  49731. ++numHavingTakenExtraSpace;
  49732. --numWantingMoreSpace;
  49733. layout->currentSize += extraAllowed;
  49734. extraSpace -= extraAllowed;
  49735. }
  49736. }
  49737. }
  49738. if (numHavingTakenExtraSpace <= 0)
  49739. break;
  49740. }
  49741. // ..and calculate the end position
  49742. for (i = startIndex; i < endIndex; ++i)
  49743. {
  49744. ItemLayoutProperties* const layout = items.getUnchecked(i);
  49745. startPos += layout->currentSize;
  49746. }
  49747. return startPos;
  49748. }
  49749. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  49750. const int endIndex) const
  49751. {
  49752. int totalMinimums = 0;
  49753. for (int i = startIndex; i < endIndex; ++i)
  49754. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  49755. return totalMinimums;
  49756. }
  49757. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  49758. {
  49759. int totalMaximums = 0;
  49760. for (int i = startIndex; i < endIndex; ++i)
  49761. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  49762. return totalMaximums;
  49763. }
  49764. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  49765. {
  49766. for (int i = 0; i < items.size(); ++i)
  49767. {
  49768. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49769. layout->preferredSize
  49770. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  49771. : getItemCurrentAbsoluteSize (i);
  49772. }
  49773. }
  49774. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  49775. {
  49776. if (size < 0)
  49777. size *= -totalSpace;
  49778. return roundToInt (size);
  49779. }
  49780. END_JUCE_NAMESPACE
  49781. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  49782. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49783. BEGIN_JUCE_NAMESPACE
  49784. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  49785. const int itemIndex_,
  49786. const bool isVertical_)
  49787. : layout (layout_),
  49788. itemIndex (itemIndex_),
  49789. isVertical (isVertical_)
  49790. {
  49791. setRepaintsOnMouseActivity (true);
  49792. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  49793. : MouseCursor::UpDownResizeCursor));
  49794. }
  49795. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  49796. {
  49797. }
  49798. void StretchableLayoutResizerBar::paint (Graphics& g)
  49799. {
  49800. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  49801. getWidth(), getHeight(),
  49802. isVertical,
  49803. isMouseOver(),
  49804. isMouseButtonDown());
  49805. }
  49806. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  49807. {
  49808. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  49809. }
  49810. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  49811. {
  49812. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  49813. : e.getDistanceFromDragStartY());
  49814. layout->setItemPosition (itemIndex, desiredPos);
  49815. hasBeenMoved();
  49816. }
  49817. void StretchableLayoutResizerBar::hasBeenMoved()
  49818. {
  49819. if (getParentComponent() != 0)
  49820. getParentComponent()->resized();
  49821. }
  49822. END_JUCE_NAMESPACE
  49823. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49824. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  49825. BEGIN_JUCE_NAMESPACE
  49826. StretchableObjectResizer::StretchableObjectResizer()
  49827. {
  49828. }
  49829. StretchableObjectResizer::~StretchableObjectResizer()
  49830. {
  49831. }
  49832. void StretchableObjectResizer::addItem (const double size,
  49833. const double minSize, const double maxSize,
  49834. const int order)
  49835. {
  49836. // the order must be >= 0 but less than the maximum integer value.
  49837. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  49838. Item* const item = new Item();
  49839. item->size = size;
  49840. item->minSize = minSize;
  49841. item->maxSize = maxSize;
  49842. item->order = order;
  49843. items.add (item);
  49844. }
  49845. double StretchableObjectResizer::getItemSize (const int index) const throw()
  49846. {
  49847. const Item* const it = items [index];
  49848. return it != 0 ? it->size : 0;
  49849. }
  49850. void StretchableObjectResizer::resizeToFit (const double targetSize)
  49851. {
  49852. int order = 0;
  49853. for (;;)
  49854. {
  49855. double currentSize = 0;
  49856. double minSize = 0;
  49857. double maxSize = 0;
  49858. int nextHighestOrder = std::numeric_limits<int>::max();
  49859. for (int i = 0; i < items.size(); ++i)
  49860. {
  49861. const Item* const it = items.getUnchecked(i);
  49862. currentSize += it->size;
  49863. if (it->order <= order)
  49864. {
  49865. minSize += it->minSize;
  49866. maxSize += it->maxSize;
  49867. }
  49868. else
  49869. {
  49870. minSize += it->size;
  49871. maxSize += it->size;
  49872. nextHighestOrder = jmin (nextHighestOrder, it->order);
  49873. }
  49874. }
  49875. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  49876. if (thisIterationTarget >= currentSize)
  49877. {
  49878. const double availableExtraSpace = maxSize - currentSize;
  49879. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  49880. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  49881. for (int i = 0; i < items.size(); ++i)
  49882. {
  49883. Item* const it = items.getUnchecked(i);
  49884. if (it->order <= order)
  49885. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  49886. }
  49887. }
  49888. else
  49889. {
  49890. const double amountOfSlack = currentSize - minSize;
  49891. const double targetAmountOfSlack = thisIterationTarget - minSize;
  49892. const double scale = targetAmountOfSlack / amountOfSlack;
  49893. for (int i = 0; i < items.size(); ++i)
  49894. {
  49895. Item* const it = items.getUnchecked(i);
  49896. if (it->order <= order)
  49897. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  49898. }
  49899. }
  49900. if (nextHighestOrder < std::numeric_limits<int>::max())
  49901. order = nextHighestOrder;
  49902. else
  49903. break;
  49904. }
  49905. }
  49906. END_JUCE_NAMESPACE
  49907. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  49908. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  49909. BEGIN_JUCE_NAMESPACE
  49910. TabBarButton::TabBarButton (const String& name,
  49911. TabbedButtonBar* const owner_,
  49912. const int index)
  49913. : Button (name),
  49914. owner (owner_),
  49915. tabIndex (index),
  49916. overlapPixels (0)
  49917. {
  49918. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  49919. setComponentEffect (&shadow);
  49920. setWantsKeyboardFocus (false);
  49921. }
  49922. TabBarButton::~TabBarButton()
  49923. {
  49924. }
  49925. void TabBarButton::paintButton (Graphics& g,
  49926. bool isMouseOverButton,
  49927. bool isButtonDown)
  49928. {
  49929. int x, y, w, h;
  49930. getActiveArea (x, y, w, h);
  49931. g.setOrigin (x, y);
  49932. getLookAndFeel()
  49933. .drawTabButton (g, w, h,
  49934. owner->getTabBackgroundColour (tabIndex),
  49935. tabIndex, getButtonText(), *this,
  49936. owner->getOrientation(),
  49937. isMouseOverButton, isButtonDown,
  49938. getToggleState());
  49939. }
  49940. void TabBarButton::clicked (const ModifierKeys& mods)
  49941. {
  49942. if (mods.isPopupMenu())
  49943. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  49944. else
  49945. owner->setCurrentTabIndex (tabIndex);
  49946. }
  49947. bool TabBarButton::hitTest (int mx, int my)
  49948. {
  49949. int x, y, w, h;
  49950. getActiveArea (x, y, w, h);
  49951. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  49952. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  49953. {
  49954. if (((unsigned int) mx) < (unsigned int) getWidth()
  49955. && my >= y + overlapPixels
  49956. && my < y + h - overlapPixels)
  49957. return true;
  49958. }
  49959. else
  49960. {
  49961. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  49962. && ((unsigned int) my) < (unsigned int) getHeight())
  49963. return true;
  49964. }
  49965. Path p;
  49966. getLookAndFeel()
  49967. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  49968. owner->getOrientation(),
  49969. false, false, getToggleState());
  49970. return p.contains ((float) (mx - x),
  49971. (float) (my - y));
  49972. }
  49973. int TabBarButton::getBestTabLength (const int depth)
  49974. {
  49975. return jlimit (depth * 2,
  49976. depth * 7,
  49977. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  49978. }
  49979. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  49980. {
  49981. x = 0;
  49982. y = 0;
  49983. int r = getWidth();
  49984. int b = getHeight();
  49985. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  49986. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  49987. r -= spaceAroundImage;
  49988. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  49989. x += spaceAroundImage;
  49990. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  49991. y += spaceAroundImage;
  49992. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  49993. b -= spaceAroundImage;
  49994. w = r - x;
  49995. h = b - y;
  49996. }
  49997. class TabAreaBehindFrontButtonComponent : public Component
  49998. {
  49999. public:
  50000. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50001. : owner (owner_)
  50002. {
  50003. setInterceptsMouseClicks (false, false);
  50004. }
  50005. ~TabAreaBehindFrontButtonComponent()
  50006. {
  50007. }
  50008. void paint (Graphics& g)
  50009. {
  50010. getLookAndFeel()
  50011. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50012. *owner, owner->getOrientation());
  50013. }
  50014. void enablementChanged()
  50015. {
  50016. repaint();
  50017. }
  50018. private:
  50019. TabbedButtonBar* const owner;
  50020. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50021. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50022. };
  50023. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50024. : orientation (orientation_),
  50025. currentTabIndex (-1),
  50026. extraTabsButton (0)
  50027. {
  50028. setInterceptsMouseClicks (false, true);
  50029. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50030. setFocusContainer (true);
  50031. }
  50032. TabbedButtonBar::~TabbedButtonBar()
  50033. {
  50034. deleteAllChildren();
  50035. }
  50036. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50037. {
  50038. orientation = newOrientation;
  50039. for (int i = getNumChildComponents(); --i >= 0;)
  50040. getChildComponent (i)->resized();
  50041. resized();
  50042. }
  50043. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50044. {
  50045. return new TabBarButton (name, this, index);
  50046. }
  50047. void TabbedButtonBar::clearTabs()
  50048. {
  50049. tabs.clear();
  50050. tabColours.clear();
  50051. currentTabIndex = -1;
  50052. deleteAndZero (extraTabsButton);
  50053. removeChildComponent (behindFrontTab);
  50054. deleteAllChildren();
  50055. addChildComponent (behindFrontTab);
  50056. setCurrentTabIndex (-1);
  50057. }
  50058. void TabbedButtonBar::addTab (const String& tabName,
  50059. const Colour& tabBackgroundColour,
  50060. int insertIndex)
  50061. {
  50062. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50063. if (tabName.isNotEmpty())
  50064. {
  50065. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50066. insertIndex = tabs.size();
  50067. for (int i = tabs.size(); --i >= insertIndex;)
  50068. {
  50069. TabBarButton* const tb = getTabButton (i);
  50070. if (tb != 0)
  50071. tb->tabIndex++;
  50072. }
  50073. tabs.insert (insertIndex, tabName);
  50074. tabColours.insert (insertIndex, tabBackgroundColour);
  50075. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50076. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50077. addAndMakeVisible (tb, insertIndex);
  50078. resized();
  50079. if (currentTabIndex < 0)
  50080. setCurrentTabIndex (0);
  50081. }
  50082. }
  50083. void TabbedButtonBar::setTabName (const int tabIndex,
  50084. const String& newName)
  50085. {
  50086. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50087. && tabs[tabIndex] != newName)
  50088. {
  50089. tabs.set (tabIndex, newName);
  50090. TabBarButton* const tb = getTabButton (tabIndex);
  50091. if (tb != 0)
  50092. tb->setButtonText (newName);
  50093. resized();
  50094. }
  50095. }
  50096. void TabbedButtonBar::removeTab (const int tabIndex)
  50097. {
  50098. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50099. {
  50100. const int oldTabIndex = currentTabIndex;
  50101. if (currentTabIndex == tabIndex)
  50102. currentTabIndex = -1;
  50103. tabs.remove (tabIndex);
  50104. tabColours.remove (tabIndex);
  50105. delete getTabButton (tabIndex);
  50106. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50107. {
  50108. TabBarButton* const tb = getTabButton (i);
  50109. if (tb != 0)
  50110. tb->tabIndex--;
  50111. }
  50112. resized();
  50113. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50114. }
  50115. }
  50116. void TabbedButtonBar::moveTab (const int currentIndex,
  50117. const int newIndex)
  50118. {
  50119. tabs.move (currentIndex, newIndex);
  50120. tabColours.move (currentIndex, newIndex);
  50121. resized();
  50122. }
  50123. int TabbedButtonBar::getNumTabs() const
  50124. {
  50125. return tabs.size();
  50126. }
  50127. const StringArray TabbedButtonBar::getTabNames() const
  50128. {
  50129. return tabs;
  50130. }
  50131. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50132. {
  50133. if (currentTabIndex != newIndex)
  50134. {
  50135. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50136. newIndex = -1;
  50137. currentTabIndex = newIndex;
  50138. for (int i = 0; i < getNumChildComponents(); ++i)
  50139. {
  50140. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50141. if (tb != 0)
  50142. tb->setToggleState (tb->tabIndex == newIndex, false);
  50143. }
  50144. resized();
  50145. if (sendChangeMessage_)
  50146. sendChangeMessage (this);
  50147. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50148. }
  50149. }
  50150. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50151. {
  50152. for (int i = getNumChildComponents(); --i >= 0;)
  50153. {
  50154. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50155. if (tb != 0 && tb->tabIndex == index)
  50156. return tb;
  50157. }
  50158. return 0;
  50159. }
  50160. void TabbedButtonBar::lookAndFeelChanged()
  50161. {
  50162. deleteAndZero (extraTabsButton);
  50163. resized();
  50164. }
  50165. void TabbedButtonBar::resized()
  50166. {
  50167. const double minimumScale = 0.7;
  50168. int depth = getWidth();
  50169. int length = getHeight();
  50170. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50171. swapVariables (depth, length);
  50172. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50173. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50174. int i, totalLength = overlap;
  50175. int numVisibleButtons = tabs.size();
  50176. for (i = 0; i < getNumChildComponents(); ++i)
  50177. {
  50178. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50179. if (tb != 0)
  50180. {
  50181. totalLength += tb->getBestTabLength (depth) - overlap;
  50182. tb->overlapPixels = overlap / 2;
  50183. }
  50184. }
  50185. double scale = 1.0;
  50186. if (totalLength > length)
  50187. scale = jmax (minimumScale, length / (double) totalLength);
  50188. const bool isTooBig = totalLength * scale > length;
  50189. int tabsButtonPos = 0;
  50190. if (isTooBig)
  50191. {
  50192. if (extraTabsButton == 0)
  50193. {
  50194. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50195. extraTabsButton->addButtonListener (this);
  50196. extraTabsButton->setAlwaysOnTop (true);
  50197. extraTabsButton->setTriggeredOnMouseDown (true);
  50198. }
  50199. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50200. extraTabsButton->setSize (buttonSize, buttonSize);
  50201. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50202. {
  50203. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50204. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50205. }
  50206. else
  50207. {
  50208. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50209. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50210. }
  50211. totalLength = 0;
  50212. for (i = 0; i < tabs.size(); ++i)
  50213. {
  50214. TabBarButton* const tb = getTabButton (i);
  50215. if (tb != 0)
  50216. {
  50217. const int newLength = totalLength + tb->getBestTabLength (depth);
  50218. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50219. {
  50220. totalLength += overlap;
  50221. break;
  50222. }
  50223. numVisibleButtons = i + 1;
  50224. totalLength = newLength - overlap;
  50225. }
  50226. }
  50227. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50228. }
  50229. else
  50230. {
  50231. deleteAndZero (extraTabsButton);
  50232. }
  50233. int pos = 0;
  50234. TabBarButton* frontTab = 0;
  50235. for (i = 0; i < tabs.size(); ++i)
  50236. {
  50237. TabBarButton* const tb = getTabButton (i);
  50238. if (tb != 0)
  50239. {
  50240. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50241. if (i < numVisibleButtons)
  50242. {
  50243. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50244. tb->setBounds (pos, 0, bestLength, getHeight());
  50245. else
  50246. tb->setBounds (0, pos, getWidth(), bestLength);
  50247. tb->toBack();
  50248. if (tb->tabIndex == currentTabIndex)
  50249. frontTab = tb;
  50250. tb->setVisible (true);
  50251. }
  50252. else
  50253. {
  50254. tb->setVisible (false);
  50255. }
  50256. pos += bestLength - overlap;
  50257. }
  50258. }
  50259. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50260. if (frontTab != 0)
  50261. {
  50262. frontTab->toFront (false);
  50263. behindFrontTab->toBehind (frontTab);
  50264. }
  50265. }
  50266. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50267. {
  50268. return tabColours [tabIndex];
  50269. }
  50270. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50271. {
  50272. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50273. && tabColours [tabIndex] != newColour)
  50274. {
  50275. tabColours.set (tabIndex, newColour);
  50276. repaint();
  50277. }
  50278. }
  50279. void TabbedButtonBar::buttonClicked (Button* button)
  50280. {
  50281. if (extraTabsButton == button)
  50282. {
  50283. PopupMenu m;
  50284. for (int i = 0; i < tabs.size(); ++i)
  50285. {
  50286. TabBarButton* const tb = getTabButton (i);
  50287. if (tb != 0 && ! tb->isVisible())
  50288. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50289. }
  50290. const int res = m.showAt (extraTabsButton);
  50291. if (res != 0)
  50292. setCurrentTabIndex (res - 1);
  50293. }
  50294. }
  50295. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50296. {
  50297. }
  50298. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50299. {
  50300. }
  50301. END_JUCE_NAMESPACE
  50302. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50303. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50304. BEGIN_JUCE_NAMESPACE
  50305. class TabCompButtonBar : public TabbedButtonBar
  50306. {
  50307. public:
  50308. TabCompButtonBar (TabbedComponent* const owner_,
  50309. const TabbedButtonBar::Orientation orientation)
  50310. : TabbedButtonBar (orientation),
  50311. owner (owner_)
  50312. {
  50313. }
  50314. ~TabCompButtonBar()
  50315. {
  50316. }
  50317. void currentTabChanged (int newCurrentTabIndex,
  50318. const String& newTabName)
  50319. {
  50320. owner->changeCallback (newCurrentTabIndex, newTabName);
  50321. }
  50322. void popupMenuClickOnTab (int tabIndex,
  50323. const String& tabName)
  50324. {
  50325. owner->popupMenuClickOnTab (tabIndex, tabName);
  50326. }
  50327. const Colour getTabBackgroundColour (const int tabIndex)
  50328. {
  50329. return owner->tabs->getTabBackgroundColour (tabIndex);
  50330. }
  50331. TabBarButton* createTabButton (const String& tabName, int tabIndex)
  50332. {
  50333. return owner->createTabButton (tabName, tabIndex);
  50334. }
  50335. juce_UseDebuggingNewOperator
  50336. private:
  50337. TabbedComponent* const owner;
  50338. TabCompButtonBar (const TabCompButtonBar&);
  50339. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50340. };
  50341. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50342. : panelComponent (0),
  50343. tabDepth (30),
  50344. outlineThickness (1),
  50345. edgeIndent (0)
  50346. {
  50347. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50348. }
  50349. TabbedComponent::~TabbedComponent()
  50350. {
  50351. clearTabs();
  50352. delete tabs;
  50353. }
  50354. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50355. {
  50356. tabs->setOrientation (orientation);
  50357. resized();
  50358. }
  50359. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50360. {
  50361. return tabs->getOrientation();
  50362. }
  50363. void TabbedComponent::setTabBarDepth (const int newDepth)
  50364. {
  50365. if (tabDepth != newDepth)
  50366. {
  50367. tabDepth = newDepth;
  50368. resized();
  50369. }
  50370. }
  50371. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50372. {
  50373. return new TabBarButton (tabName, tabs, tabIndex);
  50374. }
  50375. void TabbedComponent::clearTabs()
  50376. {
  50377. if (panelComponent != 0)
  50378. {
  50379. panelComponent->setVisible (false);
  50380. removeChildComponent (panelComponent);
  50381. panelComponent = 0;
  50382. }
  50383. tabs->clearTabs();
  50384. for (int i = contentComponents.size(); --i >= 0;)
  50385. {
  50386. Component* const c = contentComponents.getUnchecked(i);
  50387. // be careful not to delete these components until they've been removed from the tab component
  50388. jassert (c == 0 || c->isValidComponent());
  50389. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50390. delete c;
  50391. }
  50392. contentComponents.clear();
  50393. }
  50394. void TabbedComponent::addTab (const String& tabName,
  50395. const Colour& tabBackgroundColour,
  50396. Component* const contentComponent,
  50397. const bool deleteComponentWhenNotNeeded,
  50398. const int insertIndex)
  50399. {
  50400. contentComponents.insert (insertIndex, contentComponent);
  50401. if (contentComponent != 0)
  50402. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50403. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50404. }
  50405. void TabbedComponent::setTabName (const int tabIndex,
  50406. const String& newName)
  50407. {
  50408. tabs->setTabName (tabIndex, newName);
  50409. }
  50410. void TabbedComponent::removeTab (const int tabIndex)
  50411. {
  50412. Component* const c = contentComponents [tabIndex];
  50413. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50414. {
  50415. if (c == panelComponent)
  50416. panelComponent = 0;
  50417. delete c;
  50418. }
  50419. contentComponents.remove (tabIndex);
  50420. tabs->removeTab (tabIndex);
  50421. }
  50422. int TabbedComponent::getNumTabs() const
  50423. {
  50424. return tabs->getNumTabs();
  50425. }
  50426. const StringArray TabbedComponent::getTabNames() const
  50427. {
  50428. return tabs->getTabNames();
  50429. }
  50430. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50431. {
  50432. return contentComponents [tabIndex];
  50433. }
  50434. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50435. {
  50436. return tabs->getTabBackgroundColour (tabIndex);
  50437. }
  50438. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50439. {
  50440. tabs->setTabBackgroundColour (tabIndex, newColour);
  50441. if (getCurrentTabIndex() == tabIndex)
  50442. repaint();
  50443. }
  50444. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50445. {
  50446. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50447. }
  50448. int TabbedComponent::getCurrentTabIndex() const
  50449. {
  50450. return tabs->getCurrentTabIndex();
  50451. }
  50452. const String& TabbedComponent::getCurrentTabName() const
  50453. {
  50454. return tabs->getCurrentTabName();
  50455. }
  50456. void TabbedComponent::setOutline (int thickness)
  50457. {
  50458. outlineThickness = thickness;
  50459. repaint();
  50460. }
  50461. void TabbedComponent::setIndent (const int indentThickness)
  50462. {
  50463. edgeIndent = indentThickness;
  50464. }
  50465. void TabbedComponent::paint (Graphics& g)
  50466. {
  50467. g.fillAll (findColour (backgroundColourId));
  50468. const TabbedButtonBar::Orientation o = getOrientation();
  50469. int x = 0;
  50470. int y = 0;
  50471. int r = getWidth();
  50472. int b = getHeight();
  50473. if (o == TabbedButtonBar::TabsAtTop)
  50474. y += tabDepth;
  50475. else if (o == TabbedButtonBar::TabsAtBottom)
  50476. b -= tabDepth;
  50477. else if (o == TabbedButtonBar::TabsAtLeft)
  50478. x += tabDepth;
  50479. else if (o == TabbedButtonBar::TabsAtRight)
  50480. r -= tabDepth;
  50481. g.reduceClipRegion (x, y, r - x, b - y);
  50482. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50483. if (outlineThickness > 0)
  50484. {
  50485. if (o == TabbedButtonBar::TabsAtTop)
  50486. --y;
  50487. else if (o == TabbedButtonBar::TabsAtBottom)
  50488. ++b;
  50489. else if (o == TabbedButtonBar::TabsAtLeft)
  50490. --x;
  50491. else if (o == TabbedButtonBar::TabsAtRight)
  50492. ++r;
  50493. g.setColour (findColour (outlineColourId));
  50494. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50495. }
  50496. }
  50497. void TabbedComponent::resized()
  50498. {
  50499. const TabbedButtonBar::Orientation o = getOrientation();
  50500. const int indent = edgeIndent + outlineThickness;
  50501. BorderSize indents (indent);
  50502. if (o == TabbedButtonBar::TabsAtTop)
  50503. {
  50504. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50505. indents.setTop (tabDepth + edgeIndent);
  50506. }
  50507. else if (o == TabbedButtonBar::TabsAtBottom)
  50508. {
  50509. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50510. indents.setBottom (tabDepth + edgeIndent);
  50511. }
  50512. else if (o == TabbedButtonBar::TabsAtLeft)
  50513. {
  50514. tabs->setBounds (0, 0, tabDepth, getHeight());
  50515. indents.setLeft (tabDepth + edgeIndent);
  50516. }
  50517. else if (o == TabbedButtonBar::TabsAtRight)
  50518. {
  50519. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50520. indents.setRight (tabDepth + edgeIndent);
  50521. }
  50522. const Rectangle<int> bounds (indents.subtractedFrom (getLocalBounds()));
  50523. for (int i = contentComponents.size(); --i >= 0;)
  50524. if (contentComponents.getUnchecked (i) != 0)
  50525. contentComponents.getUnchecked (i)->setBounds (bounds);
  50526. }
  50527. void TabbedComponent::lookAndFeelChanged()
  50528. {
  50529. for (int i = contentComponents.size(); --i >= 0;)
  50530. if (contentComponents.getUnchecked (i) != 0)
  50531. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50532. }
  50533. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50534. const String& newTabName)
  50535. {
  50536. if (panelComponent != 0)
  50537. {
  50538. panelComponent->setVisible (false);
  50539. removeChildComponent (panelComponent);
  50540. panelComponent = 0;
  50541. }
  50542. if (getCurrentTabIndex() >= 0)
  50543. {
  50544. panelComponent = contentComponents [getCurrentTabIndex()];
  50545. if (panelComponent != 0)
  50546. {
  50547. // do these ops as two stages instead of addAndMakeVisible() so that the
  50548. // component has always got a parent when it gets the visibilityChanged() callback
  50549. addChildComponent (panelComponent);
  50550. panelComponent->setVisible (true);
  50551. panelComponent->toFront (true);
  50552. }
  50553. repaint();
  50554. }
  50555. resized();
  50556. currentTabChanged (newCurrentTabIndex, newTabName);
  50557. }
  50558. void TabbedComponent::currentTabChanged (const int, const String&)
  50559. {
  50560. }
  50561. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50562. {
  50563. }
  50564. END_JUCE_NAMESPACE
  50565. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50566. /*** Start of inlined file: juce_Viewport.cpp ***/
  50567. BEGIN_JUCE_NAMESPACE
  50568. Viewport::Viewport (const String& componentName)
  50569. : Component (componentName),
  50570. contentComp (0),
  50571. lastVX (0),
  50572. lastVY (0),
  50573. lastVW (0),
  50574. lastVH (0),
  50575. scrollBarThickness (0),
  50576. singleStepX (16),
  50577. singleStepY (16),
  50578. showHScrollbar (true),
  50579. showVScrollbar (true)
  50580. {
  50581. // content holder is used to clip the contents so they don't overlap the scrollbars
  50582. addAndMakeVisible (contentHolder = new Component());
  50583. contentHolder->setInterceptsMouseClicks (false, true);
  50584. verticalScrollBar = new ScrollBar (true);
  50585. horizontalScrollBar = new ScrollBar (false);
  50586. addChildComponent (verticalScrollBar);
  50587. addChildComponent (horizontalScrollBar);
  50588. verticalScrollBar->addListener (this);
  50589. horizontalScrollBar->addListener (this);
  50590. setInterceptsMouseClicks (false, true);
  50591. setWantsKeyboardFocus (true);
  50592. }
  50593. Viewport::~Viewport()
  50594. {
  50595. contentHolder->deleteAllChildren();
  50596. deleteAllChildren();
  50597. }
  50598. void Viewport::visibleAreaChanged (int, int, int, int)
  50599. {
  50600. }
  50601. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50602. {
  50603. if (contentComp.getComponent() != newViewedComponent)
  50604. {
  50605. {
  50606. ScopedPointer<Component> oldCompDeleter (contentComp);
  50607. contentComp = 0;
  50608. }
  50609. contentComp = newViewedComponent;
  50610. if (contentComp != 0)
  50611. {
  50612. contentComp->setTopLeftPosition (0, 0);
  50613. contentHolder->addAndMakeVisible (contentComp);
  50614. contentComp->addComponentListener (this);
  50615. }
  50616. updateVisibleRegion();
  50617. }
  50618. }
  50619. int Viewport::getMaximumVisibleWidth() const throw()
  50620. {
  50621. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50622. }
  50623. int Viewport::getMaximumVisibleHeight() const throw()
  50624. {
  50625. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50626. }
  50627. void Viewport::setViewPosition (const int xPixelsOffset,
  50628. const int yPixelsOffset)
  50629. {
  50630. if (contentComp != 0)
  50631. contentComp->setTopLeftPosition (-xPixelsOffset,
  50632. -yPixelsOffset);
  50633. }
  50634. void Viewport::setViewPositionProportionately (const double x,
  50635. const double y)
  50636. {
  50637. if (contentComp != 0)
  50638. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50639. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50640. }
  50641. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50642. {
  50643. if (contentComp != 0)
  50644. {
  50645. int dx = 0, dy = 0;
  50646. if (mouseX < activeBorderThickness)
  50647. dx = activeBorderThickness - mouseX;
  50648. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50649. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50650. if (dx < 0)
  50651. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50652. else
  50653. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50654. if (mouseY < activeBorderThickness)
  50655. dy = activeBorderThickness - mouseY;
  50656. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50657. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50658. if (dy < 0)
  50659. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50660. else
  50661. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50662. if (dx != 0 || dy != 0)
  50663. {
  50664. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50665. contentComp->getY() + dy);
  50666. return true;
  50667. }
  50668. }
  50669. return false;
  50670. }
  50671. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50672. {
  50673. updateVisibleRegion();
  50674. }
  50675. void Viewport::resized()
  50676. {
  50677. updateVisibleRegion();
  50678. }
  50679. void Viewport::updateVisibleRegion()
  50680. {
  50681. if (contentComp != 0)
  50682. {
  50683. const int newVX = -contentComp->getX();
  50684. const int newVY = -contentComp->getY();
  50685. if (newVX == 0 && newVY == 0
  50686. && contentComp->getWidth() <= getWidth()
  50687. && contentComp->getHeight() <= getHeight())
  50688. {
  50689. horizontalScrollBar->setVisible (! horizontalScrollBar->autoHides());
  50690. verticalScrollBar->setVisible (! verticalScrollBar->autoHides());
  50691. }
  50692. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50693. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50694. horizontalScrollBar->setSingleStepSize (singleStepX);
  50695. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50696. horizontalScrollBar->setVisible (! horizontalScrollBar->autoHides());
  50697. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50698. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50699. verticalScrollBar->setSingleStepSize (singleStepY);
  50700. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50701. verticalScrollBar->setVisible (! verticalScrollBar->autoHides());
  50702. if (verticalScrollBar->isVisible())
  50703. {
  50704. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50705. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50706. verticalScrollBar
  50707. ->setBounds (getMaximumVisibleWidth(), 0,
  50708. getScrollBarThickness(), getMaximumVisibleHeight());
  50709. }
  50710. if (horizontalScrollBar->isVisible())
  50711. {
  50712. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50713. horizontalScrollBar
  50714. ->setBounds (0, getMaximumVisibleHeight(),
  50715. getMaximumVisibleWidth(), getScrollBarThickness());
  50716. }
  50717. contentHolder->setSize (getMaximumVisibleWidth(),
  50718. getMaximumVisibleHeight());
  50719. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50720. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50721. if (newVX != lastVX
  50722. || newVY != lastVY
  50723. || newVW != lastVW
  50724. || newVH != lastVH)
  50725. {
  50726. lastVX = newVX;
  50727. lastVY = newVY;
  50728. lastVW = newVW;
  50729. lastVH = newVH;
  50730. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50731. }
  50732. horizontalScrollBar->handleUpdateNowIfNeeded();
  50733. verticalScrollBar->handleUpdateNowIfNeeded();
  50734. }
  50735. else
  50736. {
  50737. horizontalScrollBar->setVisible (! horizontalScrollBar->autoHides());
  50738. verticalScrollBar->setVisible (! verticalScrollBar->autoHides());
  50739. }
  50740. }
  50741. void Viewport::setSingleStepSizes (const int stepX,
  50742. const int stepY)
  50743. {
  50744. singleStepX = stepX;
  50745. singleStepY = stepY;
  50746. updateVisibleRegion();
  50747. }
  50748. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  50749. const bool showHorizontalScrollbarIfNeeded)
  50750. {
  50751. showVScrollbar = showVerticalScrollbarIfNeeded;
  50752. showHScrollbar = showHorizontalScrollbarIfNeeded;
  50753. updateVisibleRegion();
  50754. }
  50755. void Viewport::setScrollBarThickness (const int thickness)
  50756. {
  50757. scrollBarThickness = thickness;
  50758. updateVisibleRegion();
  50759. }
  50760. int Viewport::getScrollBarThickness() const throw()
  50761. {
  50762. return (scrollBarThickness > 0) ? scrollBarThickness
  50763. : getLookAndFeel().getDefaultScrollbarWidth();
  50764. }
  50765. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  50766. {
  50767. verticalScrollBar->setButtonVisibility (buttonsVisible);
  50768. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  50769. }
  50770. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  50771. {
  50772. if (scrollBarThatHasMoved == horizontalScrollBar)
  50773. {
  50774. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  50775. }
  50776. else if (scrollBarThatHasMoved == verticalScrollBar)
  50777. {
  50778. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  50779. }
  50780. }
  50781. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50782. {
  50783. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  50784. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  50785. }
  50786. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50787. {
  50788. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  50789. {
  50790. const bool hasVertBar = verticalScrollBar->isVisible();
  50791. const bool hasHorzBar = horizontalScrollBar->isVisible();
  50792. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  50793. {
  50794. if (wheelIncrementX == 0 && ! hasVertBar)
  50795. wheelIncrementX = wheelIncrementY;
  50796. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  50797. wheelIncrementX, wheelIncrementY);
  50798. return true;
  50799. }
  50800. else if (hasVertBar && wheelIncrementY != 0)
  50801. {
  50802. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  50803. wheelIncrementX, wheelIncrementY);
  50804. return true;
  50805. }
  50806. }
  50807. return false;
  50808. }
  50809. bool Viewport::keyPressed (const KeyPress& key)
  50810. {
  50811. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  50812. || key.isKeyCode (KeyPress::downKey)
  50813. || key.isKeyCode (KeyPress::pageUpKey)
  50814. || key.isKeyCode (KeyPress::pageDownKey)
  50815. || key.isKeyCode (KeyPress::homeKey)
  50816. || key.isKeyCode (KeyPress::endKey);
  50817. if (verticalScrollBar->isVisible() && isUpDownKey)
  50818. return verticalScrollBar->keyPressed (key);
  50819. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  50820. || key.isKeyCode (KeyPress::rightKey);
  50821. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  50822. return horizontalScrollBar->keyPressed (key);
  50823. return false;
  50824. }
  50825. END_JUCE_NAMESPACE
  50826. /*** End of inlined file: juce_Viewport.cpp ***/
  50827. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  50828. BEGIN_JUCE_NAMESPACE
  50829. static const Colour createBaseColour (const Colour& buttonColour,
  50830. const bool hasKeyboardFocus,
  50831. const bool isMouseOverButton,
  50832. const bool isButtonDown) throw()
  50833. {
  50834. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  50835. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  50836. if (isButtonDown)
  50837. return baseColour.contrasting (0.2f);
  50838. else if (isMouseOverButton)
  50839. return baseColour.contrasting (0.1f);
  50840. return baseColour;
  50841. }
  50842. LookAndFeel::LookAndFeel()
  50843. {
  50844. /* if this fails it means you're trying to create a LookAndFeel object before
  50845. the static Colours have been initialised. That ain't gonna work. It probably
  50846. means that you're using a static LookAndFeel object and that your compiler has
  50847. decided to intialise it before the Colours class.
  50848. */
  50849. jassert (Colours::white == Colour (0xffffffff));
  50850. // set up the standard set of colours..
  50851. const int textButtonColour = 0xffbbbbff;
  50852. const int textHighlightColour = 0x401111ee;
  50853. const int standardOutlineColour = 0xb2808080;
  50854. static const int standardColours[] =
  50855. {
  50856. TextButton::buttonColourId, textButtonColour,
  50857. TextButton::buttonOnColourId, 0xff4444ff,
  50858. TextButton::textColourOnId, 0xff000000,
  50859. TextButton::textColourOffId, 0xff000000,
  50860. ComboBox::buttonColourId, 0xffbbbbff,
  50861. ComboBox::outlineColourId, standardOutlineColour,
  50862. ToggleButton::textColourId, 0xff000000,
  50863. TextEditor::backgroundColourId, 0xffffffff,
  50864. TextEditor::textColourId, 0xff000000,
  50865. TextEditor::highlightColourId, textHighlightColour,
  50866. TextEditor::highlightedTextColourId, 0xff000000,
  50867. TextEditor::caretColourId, 0xff000000,
  50868. TextEditor::outlineColourId, 0x00000000,
  50869. TextEditor::focusedOutlineColourId, textButtonColour,
  50870. TextEditor::shadowColourId, 0x38000000,
  50871. Label::backgroundColourId, 0x00000000,
  50872. Label::textColourId, 0xff000000,
  50873. Label::outlineColourId, 0x00000000,
  50874. ScrollBar::backgroundColourId, 0x00000000,
  50875. ScrollBar::thumbColourId, 0xffffffff,
  50876. ScrollBar::trackColourId, 0xffffffff,
  50877. TreeView::linesColourId, 0x4c000000,
  50878. TreeView::backgroundColourId, 0x00000000,
  50879. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  50880. PopupMenu::backgroundColourId, 0xffffffff,
  50881. PopupMenu::textColourId, 0xff000000,
  50882. PopupMenu::headerTextColourId, 0xff000000,
  50883. PopupMenu::highlightedTextColourId, 0xffffffff,
  50884. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  50885. ComboBox::textColourId, 0xff000000,
  50886. ComboBox::backgroundColourId, 0xffffffff,
  50887. ComboBox::arrowColourId, 0x99000000,
  50888. ListBox::backgroundColourId, 0xffffffff,
  50889. ListBox::outlineColourId, standardOutlineColour,
  50890. ListBox::textColourId, 0xff000000,
  50891. Slider::backgroundColourId, 0x00000000,
  50892. Slider::thumbColourId, textButtonColour,
  50893. Slider::trackColourId, 0x7fffffff,
  50894. Slider::rotarySliderFillColourId, 0x7f0000ff,
  50895. Slider::rotarySliderOutlineColourId, 0x66000000,
  50896. Slider::textBoxTextColourId, 0xff000000,
  50897. Slider::textBoxBackgroundColourId, 0xffffffff,
  50898. Slider::textBoxHighlightColourId, textHighlightColour,
  50899. Slider::textBoxOutlineColourId, standardOutlineColour,
  50900. ResizableWindow::backgroundColourId, 0xff777777,
  50901. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  50902. AlertWindow::backgroundColourId, 0xffededed,
  50903. AlertWindow::textColourId, 0xff000000,
  50904. AlertWindow::outlineColourId, 0xff666666,
  50905. ProgressBar::backgroundColourId, 0xffeeeeee,
  50906. ProgressBar::foregroundColourId, 0xffaaaaee,
  50907. TooltipWindow::backgroundColourId, 0xffeeeebb,
  50908. TooltipWindow::textColourId, 0xff000000,
  50909. TooltipWindow::outlineColourId, 0x4c000000,
  50910. TabbedComponent::backgroundColourId, 0x00000000,
  50911. TabbedComponent::outlineColourId, 0xff777777,
  50912. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  50913. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  50914. Toolbar::backgroundColourId, 0xfff6f8f9,
  50915. Toolbar::separatorColourId, 0x4c000000,
  50916. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  50917. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  50918. Toolbar::labelTextColourId, 0xff000000,
  50919. Toolbar::editingModeOutlineColourId, 0xffff0000,
  50920. HyperlinkButton::textColourId, 0xcc1111ee,
  50921. GroupComponent::outlineColourId, 0x66000000,
  50922. GroupComponent::textColourId, 0xff000000,
  50923. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  50924. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  50925. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  50926. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  50927. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  50928. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  50929. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  50930. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  50931. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  50932. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  50933. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  50934. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  50935. CodeEditorComponent::backgroundColourId, 0xffffffff,
  50936. CodeEditorComponent::caretColourId, 0xff000000,
  50937. CodeEditorComponent::highlightColourId, textHighlightColour,
  50938. CodeEditorComponent::defaultTextColourId, 0xff000000,
  50939. ColourSelector::backgroundColourId, 0xffe5e5e5,
  50940. ColourSelector::labelTextColourId, 0xff000000,
  50941. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  50942. KeyMappingEditorComponent::textColourId, 0xff000000,
  50943. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  50944. FileChooserDialogBox::titleTextColourId, 0xff000000,
  50945. };
  50946. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  50947. setColour (standardColours [i], Colour (standardColours [i + 1]));
  50948. static String defaultSansName, defaultSerifName, defaultFixedName;
  50949. if (defaultSansName.isEmpty())
  50950. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  50951. defaultSans = defaultSansName;
  50952. defaultSerif = defaultSerifName;
  50953. defaultFixed = defaultFixedName;
  50954. }
  50955. LookAndFeel::~LookAndFeel()
  50956. {
  50957. }
  50958. const Colour LookAndFeel::findColour (const int colourId) const throw()
  50959. {
  50960. const int index = colourIds.indexOf (colourId);
  50961. if (index >= 0)
  50962. return colours [index];
  50963. jassertfalse
  50964. return Colours::black;
  50965. }
  50966. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  50967. {
  50968. const int index = colourIds.indexOf (colourId);
  50969. if (index >= 0)
  50970. colours.set (index, colour);
  50971. colourIds.add (colourId);
  50972. colours.add (colour);
  50973. }
  50974. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  50975. {
  50976. return colourIds.contains (colourId);
  50977. }
  50978. static LookAndFeel* defaultLF = 0;
  50979. static LookAndFeel* currentDefaultLF = 0;
  50980. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  50981. {
  50982. // if this happens, your app hasn't initialised itself properly.. if you're
  50983. // trying to hack your own main() function, have a look at
  50984. // JUCEApplication::initialiseForGUI()
  50985. jassert (currentDefaultLF != 0);
  50986. return *currentDefaultLF;
  50987. }
  50988. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  50989. {
  50990. if (newDefaultLookAndFeel == 0)
  50991. {
  50992. if (defaultLF == 0)
  50993. defaultLF = new LookAndFeel();
  50994. newDefaultLookAndFeel = defaultLF;
  50995. }
  50996. currentDefaultLF = newDefaultLookAndFeel;
  50997. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  50998. {
  50999. Component* const c = Desktop::getInstance().getComponent (i);
  51000. if (c != 0)
  51001. c->sendLookAndFeelChange();
  51002. }
  51003. }
  51004. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51005. {
  51006. if (currentDefaultLF == defaultLF)
  51007. currentDefaultLF = 0;
  51008. deleteAndZero (defaultLF);
  51009. }
  51010. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51011. {
  51012. String faceName (font.getTypefaceName());
  51013. if (faceName == Font::getDefaultSansSerifFontName())
  51014. faceName = defaultSans;
  51015. else if (faceName == Font::getDefaultSerifFontName())
  51016. faceName = defaultSerif;
  51017. else if (faceName == Font::getDefaultMonospacedFontName())
  51018. faceName = defaultFixed;
  51019. Font f (font);
  51020. f.setTypefaceName (faceName);
  51021. return Typeface::createSystemTypefaceFor (f);
  51022. }
  51023. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51024. {
  51025. defaultSans = newName;
  51026. }
  51027. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51028. {
  51029. return component.getMouseCursor();
  51030. }
  51031. void LookAndFeel::drawButtonBackground (Graphics& g,
  51032. Button& button,
  51033. const Colour& backgroundColour,
  51034. bool isMouseOverButton,
  51035. bool isButtonDown)
  51036. {
  51037. const int width = button.getWidth();
  51038. const int height = button.getHeight();
  51039. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51040. const float halfThickness = outlineThickness * 0.5f;
  51041. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51042. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51043. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51044. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51045. const Colour baseColour (createBaseColour (backgroundColour,
  51046. button.hasKeyboardFocus (true),
  51047. isMouseOverButton, isButtonDown)
  51048. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51049. drawGlassLozenge (g,
  51050. indentL,
  51051. indentT,
  51052. width - indentL - indentR,
  51053. height - indentT - indentB,
  51054. baseColour, outlineThickness, -1.0f,
  51055. button.isConnectedOnLeft(),
  51056. button.isConnectedOnRight(),
  51057. button.isConnectedOnTop(),
  51058. button.isConnectedOnBottom());
  51059. }
  51060. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51061. {
  51062. return button.getFont();
  51063. }
  51064. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51065. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51066. {
  51067. Font font (getFontForTextButton (button));
  51068. g.setFont (font);
  51069. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51070. : TextButton::textColourOffId)
  51071. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51072. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51073. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51074. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51075. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51076. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51077. g.drawFittedText (button.getButtonText(),
  51078. leftIndent,
  51079. yIndent,
  51080. button.getWidth() - leftIndent - rightIndent,
  51081. button.getHeight() - yIndent * 2,
  51082. Justification::centred, 2);
  51083. }
  51084. void LookAndFeel::drawTickBox (Graphics& g,
  51085. Component& component,
  51086. float x, float y, float w, float h,
  51087. const bool ticked,
  51088. const bool isEnabled,
  51089. const bool isMouseOverButton,
  51090. const bool isButtonDown)
  51091. {
  51092. const float boxSize = w * 0.7f;
  51093. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51094. createBaseColour (component.findColour (TextButton::buttonColourId)
  51095. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51096. true,
  51097. isMouseOverButton,
  51098. isButtonDown),
  51099. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51100. if (ticked)
  51101. {
  51102. Path tick;
  51103. tick.startNewSubPath (1.5f, 3.0f);
  51104. tick.lineTo (3.0f, 6.0f);
  51105. tick.lineTo (6.0f, 0.0f);
  51106. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51107. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51108. .translated (x, y));
  51109. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51110. }
  51111. }
  51112. void LookAndFeel::drawToggleButton (Graphics& g,
  51113. ToggleButton& button,
  51114. bool isMouseOverButton,
  51115. bool isButtonDown)
  51116. {
  51117. if (button.hasKeyboardFocus (true))
  51118. {
  51119. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51120. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51121. }
  51122. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51123. const float tickWidth = fontSize * 1.1f;
  51124. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51125. tickWidth, tickWidth,
  51126. button.getToggleState(),
  51127. button.isEnabled(),
  51128. isMouseOverButton,
  51129. isButtonDown);
  51130. g.setColour (button.findColour (ToggleButton::textColourId));
  51131. g.setFont (fontSize);
  51132. if (! button.isEnabled())
  51133. g.setOpacity (0.5f);
  51134. const int textX = (int) tickWidth + 5;
  51135. g.drawFittedText (button.getButtonText(),
  51136. textX, 0,
  51137. button.getWidth() - textX - 2, button.getHeight(),
  51138. Justification::centredLeft, 10);
  51139. }
  51140. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51141. {
  51142. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51143. const int tickWidth = jmin (24, button.getHeight());
  51144. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51145. button.getHeight());
  51146. }
  51147. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51148. const String& message,
  51149. const String& button1,
  51150. const String& button2,
  51151. const String& button3,
  51152. AlertWindow::AlertIconType iconType,
  51153. int numButtons,
  51154. Component* associatedComponent)
  51155. {
  51156. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51157. if (numButtons == 1)
  51158. {
  51159. aw->addButton (button1, 0,
  51160. KeyPress (KeyPress::escapeKey, 0, 0),
  51161. KeyPress (KeyPress::returnKey, 0, 0));
  51162. }
  51163. else
  51164. {
  51165. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51166. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51167. if (button1ShortCut == button2ShortCut)
  51168. button2ShortCut = KeyPress();
  51169. if (numButtons == 2)
  51170. {
  51171. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51172. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51173. }
  51174. else if (numButtons == 3)
  51175. {
  51176. aw->addButton (button1, 1, button1ShortCut);
  51177. aw->addButton (button2, 2, button2ShortCut);
  51178. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51179. }
  51180. }
  51181. return aw;
  51182. }
  51183. void LookAndFeel::drawAlertBox (Graphics& g,
  51184. AlertWindow& alert,
  51185. const Rectangle<int>& textArea,
  51186. TextLayout& textLayout)
  51187. {
  51188. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51189. int iconSpaceUsed = 0;
  51190. Justification alignment (Justification::horizontallyCentred);
  51191. const int iconWidth = 80;
  51192. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51193. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51194. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51195. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51196. iconSize, iconSize);
  51197. if (alert.getAlertType() != AlertWindow::NoIcon)
  51198. {
  51199. Path icon;
  51200. uint32 colour;
  51201. char character;
  51202. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51203. {
  51204. colour = 0x55ff5555;
  51205. character = '!';
  51206. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51207. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51208. (float) iconRect.getX(), (float) iconRect.getBottom());
  51209. icon = icon.createPathWithRoundedCorners (5.0f);
  51210. }
  51211. else
  51212. {
  51213. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51214. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51215. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51216. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51217. }
  51218. GlyphArrangement ga;
  51219. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51220. String::charToString (character),
  51221. (float) iconRect.getX(), (float) iconRect.getY(),
  51222. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51223. Justification::centred, false);
  51224. ga.createPath (icon);
  51225. icon.setUsingNonZeroWinding (false);
  51226. g.setColour (Colour (colour));
  51227. g.fillPath (icon);
  51228. iconSpaceUsed = iconWidth;
  51229. alignment = Justification::left;
  51230. }
  51231. g.setColour (alert.findColour (AlertWindow::textColourId));
  51232. textLayout.drawWithin (g,
  51233. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51234. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51235. alignment.getFlags() | Justification::top);
  51236. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51237. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51238. }
  51239. int LookAndFeel::getAlertBoxWindowFlags()
  51240. {
  51241. return ComponentPeer::windowAppearsOnTaskbar
  51242. | ComponentPeer::windowHasDropShadow;
  51243. }
  51244. int LookAndFeel::getAlertWindowButtonHeight()
  51245. {
  51246. return 28;
  51247. }
  51248. const Font LookAndFeel::getAlertWindowFont()
  51249. {
  51250. return Font (12.0f);
  51251. }
  51252. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51253. int width, int height,
  51254. double progress, const String& textToShow)
  51255. {
  51256. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51257. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51258. g.fillAll (background);
  51259. if (progress >= 0.0f && progress < 1.0f)
  51260. {
  51261. drawGlassLozenge (g, 1.0f, 1.0f,
  51262. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51263. (float) (height - 2),
  51264. foreground,
  51265. 0.5f, 0.0f,
  51266. true, true, true, true);
  51267. }
  51268. else
  51269. {
  51270. // spinning bar..
  51271. g.setColour (foreground);
  51272. const int stripeWidth = height * 2;
  51273. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51274. Path p;
  51275. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51276. p.addQuadrilateral (x, 0.0f,
  51277. x + stripeWidth * 0.5f, 0.0f,
  51278. x, (float) height,
  51279. x - stripeWidth * 0.5f, (float) height);
  51280. Image im (Image::ARGB, width, height, true);
  51281. {
  51282. Graphics g2 (im);
  51283. drawGlassLozenge (g2, 1.0f, 1.0f,
  51284. (float) (width - 2),
  51285. (float) (height - 2),
  51286. foreground,
  51287. 0.5f, 0.0f,
  51288. true, true, true, true);
  51289. }
  51290. g.setTiledImageFill (im, 0, 0, 0.85f);
  51291. g.fillPath (p);
  51292. }
  51293. if (textToShow.isNotEmpty())
  51294. {
  51295. g.setColour (Colour::contrasting (background, foreground));
  51296. g.setFont (height * 0.6f);
  51297. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51298. }
  51299. }
  51300. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51301. {
  51302. const float radius = jmin (w, h) * 0.4f;
  51303. const float thickness = radius * 0.15f;
  51304. Path p;
  51305. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51306. radius * 0.6f, thickness,
  51307. thickness * 0.5f);
  51308. const float cx = x + w * 0.5f;
  51309. const float cy = y + h * 0.5f;
  51310. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51311. for (int i = 0; i < 12; ++i)
  51312. {
  51313. const int n = (i + 12 - animationIndex) % 12;
  51314. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51315. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51316. .translated (cx, cy));
  51317. }
  51318. }
  51319. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51320. ScrollBar& scrollbar,
  51321. int width, int height,
  51322. int buttonDirection,
  51323. bool /*isScrollbarVertical*/,
  51324. bool /*isMouseOverButton*/,
  51325. bool isButtonDown)
  51326. {
  51327. Path p;
  51328. if (buttonDirection == 0)
  51329. p.addTriangle (width * 0.5f, height * 0.2f,
  51330. width * 0.1f, height * 0.7f,
  51331. width * 0.9f, height * 0.7f);
  51332. else if (buttonDirection == 1)
  51333. p.addTriangle (width * 0.8f, height * 0.5f,
  51334. width * 0.3f, height * 0.1f,
  51335. width * 0.3f, height * 0.9f);
  51336. else if (buttonDirection == 2)
  51337. p.addTriangle (width * 0.5f, height * 0.8f,
  51338. width * 0.1f, height * 0.3f,
  51339. width * 0.9f, height * 0.3f);
  51340. else if (buttonDirection == 3)
  51341. p.addTriangle (width * 0.2f, height * 0.5f,
  51342. width * 0.7f, height * 0.1f,
  51343. width * 0.7f, height * 0.9f);
  51344. if (isButtonDown)
  51345. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51346. else
  51347. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51348. g.fillPath (p);
  51349. g.setColour (Colour (0x80000000));
  51350. g.strokePath (p, PathStrokeType (0.5f));
  51351. }
  51352. void LookAndFeel::drawScrollbar (Graphics& g,
  51353. ScrollBar& scrollbar,
  51354. int x, int y,
  51355. int width, int height,
  51356. bool isScrollbarVertical,
  51357. int thumbStartPosition,
  51358. int thumbSize,
  51359. bool /*isMouseOver*/,
  51360. bool /*isMouseDown*/)
  51361. {
  51362. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51363. Path slotPath, thumbPath;
  51364. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51365. const float slotIndentx2 = slotIndent * 2.0f;
  51366. const float thumbIndent = slotIndent + 1.0f;
  51367. const float thumbIndentx2 = thumbIndent * 2.0f;
  51368. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51369. if (isScrollbarVertical)
  51370. {
  51371. slotPath.addRoundedRectangle (x + slotIndent,
  51372. y + slotIndent,
  51373. width - slotIndentx2,
  51374. height - slotIndentx2,
  51375. (width - slotIndentx2) * 0.5f);
  51376. if (thumbSize > 0)
  51377. thumbPath.addRoundedRectangle (x + thumbIndent,
  51378. thumbStartPosition + thumbIndent,
  51379. width - thumbIndentx2,
  51380. thumbSize - thumbIndentx2,
  51381. (width - thumbIndentx2) * 0.5f);
  51382. gx1 = (float) x;
  51383. gx2 = x + width * 0.7f;
  51384. }
  51385. else
  51386. {
  51387. slotPath.addRoundedRectangle (x + slotIndent,
  51388. y + slotIndent,
  51389. width - slotIndentx2,
  51390. height - slotIndentx2,
  51391. (height - slotIndentx2) * 0.5f);
  51392. if (thumbSize > 0)
  51393. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51394. y + thumbIndent,
  51395. thumbSize - thumbIndentx2,
  51396. height - thumbIndentx2,
  51397. (height - thumbIndentx2) * 0.5f);
  51398. gy1 = (float) y;
  51399. gy2 = y + height * 0.7f;
  51400. }
  51401. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51402. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51403. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51404. g.fillPath (slotPath);
  51405. if (isScrollbarVertical)
  51406. {
  51407. gx1 = x + width * 0.6f;
  51408. gx2 = (float) x + width;
  51409. }
  51410. else
  51411. {
  51412. gy1 = y + height * 0.6f;
  51413. gy2 = (float) y + height;
  51414. }
  51415. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51416. Colour (0x19000000), gx2, gy2, false));
  51417. g.fillPath (slotPath);
  51418. g.setColour (thumbColour);
  51419. g.fillPath (thumbPath);
  51420. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51421. Colours::transparentBlack, gx2, gy2, false));
  51422. g.saveState();
  51423. if (isScrollbarVertical)
  51424. g.reduceClipRegion (x + width / 2, y, width, height);
  51425. else
  51426. g.reduceClipRegion (x, y + height / 2, width, height);
  51427. g.fillPath (thumbPath);
  51428. g.restoreState();
  51429. g.setColour (Colour (0x4c000000));
  51430. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51431. }
  51432. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51433. {
  51434. return 0;
  51435. }
  51436. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51437. {
  51438. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51439. }
  51440. int LookAndFeel::getDefaultScrollbarWidth()
  51441. {
  51442. return 18;
  51443. }
  51444. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51445. {
  51446. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51447. : scrollbar.getHeight());
  51448. }
  51449. const Path LookAndFeel::getTickShape (const float height)
  51450. {
  51451. static const unsigned char tickShapeData[] =
  51452. {
  51453. 109,0,224,168,68,0,0,119,67,108,0,224,172,68,0,128,146,67,113,0,192,148,68,0,0,219,67,0,96,110,68,0,224,56,68,113,0,64,51,68,0,32,130,68,0,64,20,68,0,224,
  51454. 162,68,108,0,128,3,68,0,128,168,68,113,0,128,221,67,0,192,175,68,0,0,207,67,0,32,179,68,113,0,0,201,67,0,224,173,68,0,0,181,67,0,224,161,68,108,0,128,168,67,
  51455. 0,128,154,68,113,0,128,141,67,0,192,138,68,0,128,108,67,0,64,131,68,113,0,0,62,67,0,128,119,68,0,0,5,67,0,128,114,68,113,0,0,102,67,0,192,88,68,0,128,155,
  51456. 67,0,192,88,68,113,0,0,190,67,0,192,88,68,0,128,232,67,0,224,131,68,108,0,128,246,67,0,192,139,68,113,0,64,33,68,0,128,87,68,0,0,93,68,0,224,26,68,113,0,
  51457. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51458. };
  51459. Path p;
  51460. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51461. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51462. return p;
  51463. }
  51464. const Path LookAndFeel::getCrossShape (const float height)
  51465. {
  51466. static const unsigned char crossShapeData[] =
  51467. {
  51468. 109,0,0,17,68,0,96,145,68,108,0,192,13,68,0,192,147,68,113,0,0,213,67,0,64,174,68,0,0,168,67,0,64,174,68,113,0,0,104,67,0,64,174,68,0,0,5,67,0,64,
  51469. 153,68,113,0,0,18,67,0,64,153,68,0,0,24,67,0,64,153,68,113,0,0,135,67,0,64,153,68,0,128,207,67,0,224,130,68,108,0,0,220,67,0,0,126,68,108,0,0,204,67,
  51470. 0,128,117,68,113,0,0,138,67,0,64,82,68,0,0,138,67,0,192,57,68,113,0,0,138,67,0,192,37,68,0,128,210,67,0,64,10,68,113,0,128,220,67,0,64,45,68,0,0,8,
  51471. 68,0,128,78,68,108,0,192,14,68,0,0,87,68,108,0,64,20,68,0,0,80,68,113,0,192,57,68,0,0,32,68,0,128,88,68,0,0,32,68,113,0,64,112,68,0,0,32,68,0,
  51472. 128,124,68,0,64,68,68,113,0,0,121,68,0,192,67,68,0,128,119,68,0,192,67,68,113,0,192,108,68,0,192,67,68,0,32,89,68,0,96,82,68,113,0,128,69,68,0,0,97,68,
  51473. 0,0,56,68,0,64,115,68,108,0,64,49,68,0,128,124,68,108,0,192,55,68,0,96,129,68,113,0,0,92,68,0,224,146,68,0,192,129,68,0,224,146,68,113,0,64,110,68,0,64,
  51474. 168,68,0,64,87,68,0,64,168,68,113,0,128,66,68,0,64,168,68,0,64,27,68,0,32,150,68,99,101
  51475. };
  51476. Path p;
  51477. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51478. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51479. return p;
  51480. }
  51481. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51482. {
  51483. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51484. x += (w - boxSize) >> 1;
  51485. y += (h - boxSize) >> 1;
  51486. w = boxSize;
  51487. h = boxSize;
  51488. g.setColour (Colour (0xe5ffffff));
  51489. g.fillRect (x, y, w, h);
  51490. g.setColour (Colour (0x80000000));
  51491. g.drawRect (x, y, w, h);
  51492. const float size = boxSize / 2 + 1.0f;
  51493. const float centre = (float) (boxSize / 2);
  51494. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51495. if (isPlus)
  51496. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51497. }
  51498. void LookAndFeel::drawBubble (Graphics& g,
  51499. float tipX, float tipY,
  51500. float boxX, float boxY,
  51501. float boxW, float boxH)
  51502. {
  51503. int side = 0;
  51504. if (tipX < boxX)
  51505. side = 1;
  51506. else if (tipX > boxX + boxW)
  51507. side = 3;
  51508. else if (tipY > boxY + boxH)
  51509. side = 2;
  51510. const float indent = 2.0f;
  51511. Path p;
  51512. p.addBubble (boxX + indent,
  51513. boxY + indent,
  51514. boxW - indent * 2.0f,
  51515. boxH - indent * 2.0f,
  51516. 5.0f,
  51517. tipX, tipY,
  51518. side,
  51519. 0.5f,
  51520. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51521. //xxx need to take comp as param for colour
  51522. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51523. g.fillPath (p);
  51524. //xxx as above
  51525. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51526. g.strokePath (p, PathStrokeType (1.33f));
  51527. }
  51528. const Font LookAndFeel::getPopupMenuFont()
  51529. {
  51530. return Font (17.0f);
  51531. }
  51532. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51533. const bool isSeparator,
  51534. int standardMenuItemHeight,
  51535. int& idealWidth,
  51536. int& idealHeight)
  51537. {
  51538. if (isSeparator)
  51539. {
  51540. idealWidth = 50;
  51541. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51542. }
  51543. else
  51544. {
  51545. Font font (getPopupMenuFont());
  51546. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51547. font.setHeight (standardMenuItemHeight / 1.3f);
  51548. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51549. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51550. }
  51551. }
  51552. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51553. {
  51554. const Colour background (findColour (PopupMenu::backgroundColourId));
  51555. g.fillAll (background);
  51556. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51557. for (int i = 0; i < height; i += 3)
  51558. g.fillRect (0, i, width, 1);
  51559. #if ! JUCE_MAC
  51560. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51561. g.drawRect (0, 0, width, height);
  51562. #endif
  51563. }
  51564. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51565. int width, int height,
  51566. bool isScrollUpArrow)
  51567. {
  51568. const Colour background (findColour (PopupMenu::backgroundColourId));
  51569. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51570. background.withAlpha (0.0f),
  51571. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51572. false));
  51573. g.fillRect (1, 1, width - 2, height - 2);
  51574. const float hw = width * 0.5f;
  51575. const float arrowW = height * 0.3f;
  51576. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51577. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51578. Path p;
  51579. p.addTriangle (hw - arrowW, y1,
  51580. hw + arrowW, y1,
  51581. hw, y2);
  51582. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51583. g.fillPath (p);
  51584. }
  51585. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51586. int width, int height,
  51587. const bool isSeparator,
  51588. const bool isActive,
  51589. const bool isHighlighted,
  51590. const bool isTicked,
  51591. const bool hasSubMenu,
  51592. const String& text,
  51593. const String& shortcutKeyText,
  51594. Image* image,
  51595. const Colour* const textColourToUse)
  51596. {
  51597. const float halfH = height * 0.5f;
  51598. if (isSeparator)
  51599. {
  51600. const float separatorIndent = 5.5f;
  51601. g.setColour (Colour (0x33000000));
  51602. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51603. g.setColour (Colour (0x66ffffff));
  51604. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51605. }
  51606. else
  51607. {
  51608. Colour textColour (findColour (PopupMenu::textColourId));
  51609. if (textColourToUse != 0)
  51610. textColour = *textColourToUse;
  51611. if (isHighlighted)
  51612. {
  51613. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51614. g.fillRect (1, 1, width - 2, height - 2);
  51615. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51616. }
  51617. else
  51618. {
  51619. g.setColour (textColour);
  51620. }
  51621. if (! isActive)
  51622. g.setOpacity (0.3f);
  51623. Font font (getPopupMenuFont());
  51624. if (font.getHeight() > height / 1.3f)
  51625. font.setHeight (height / 1.3f);
  51626. g.setFont (font);
  51627. const int leftBorder = (height * 5) / 4;
  51628. const int rightBorder = 4;
  51629. if (image != 0)
  51630. {
  51631. g.drawImageWithin (image,
  51632. 2, 1, leftBorder - 4, height - 2,
  51633. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51634. }
  51635. else if (isTicked)
  51636. {
  51637. const Path tick (getTickShape (1.0f));
  51638. const float th = font.getAscent();
  51639. const float ty = halfH - th * 0.5f;
  51640. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51641. th, true));
  51642. }
  51643. g.drawFittedText (text,
  51644. leftBorder, 0,
  51645. width - (leftBorder + rightBorder), height,
  51646. Justification::centredLeft, 1);
  51647. if (shortcutKeyText.isNotEmpty())
  51648. {
  51649. Font f2 (font);
  51650. f2.setHeight (f2.getHeight() * 0.75f);
  51651. f2.setHorizontalScale (0.95f);
  51652. g.setFont (f2);
  51653. g.drawText (shortcutKeyText,
  51654. leftBorder,
  51655. 0,
  51656. width - (leftBorder + rightBorder + 4),
  51657. height,
  51658. Justification::centredRight,
  51659. true);
  51660. }
  51661. if (hasSubMenu)
  51662. {
  51663. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51664. const float x = width - height * 0.6f;
  51665. Path p;
  51666. p.addTriangle (x, halfH - arrowH * 0.5f,
  51667. x, halfH + arrowH * 0.5f,
  51668. x + arrowH * 0.6f, halfH);
  51669. g.fillPath (p);
  51670. }
  51671. }
  51672. }
  51673. int LookAndFeel::getMenuWindowFlags()
  51674. {
  51675. return ComponentPeer::windowHasDropShadow;
  51676. }
  51677. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51678. bool, MenuBarComponent& menuBar)
  51679. {
  51680. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51681. if (menuBar.isEnabled())
  51682. {
  51683. drawShinyButtonShape (g,
  51684. -4.0f, 0.0f,
  51685. width + 8.0f, (float) height,
  51686. 0.0f,
  51687. baseColour,
  51688. 0.4f,
  51689. true, true, true, true);
  51690. }
  51691. else
  51692. {
  51693. g.fillAll (baseColour);
  51694. }
  51695. }
  51696. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51697. {
  51698. return Font (menuBar.getHeight() * 0.7f);
  51699. }
  51700. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51701. {
  51702. return getMenuBarFont (menuBar, itemIndex, itemText)
  51703. .getStringWidth (itemText) + menuBar.getHeight();
  51704. }
  51705. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51706. int width, int height,
  51707. int itemIndex,
  51708. const String& itemText,
  51709. bool isMouseOverItem,
  51710. bool isMenuOpen,
  51711. bool /*isMouseOverBar*/,
  51712. MenuBarComponent& menuBar)
  51713. {
  51714. if (! menuBar.isEnabled())
  51715. {
  51716. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51717. .withMultipliedAlpha (0.5f));
  51718. }
  51719. else if (isMenuOpen || isMouseOverItem)
  51720. {
  51721. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51722. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51723. }
  51724. else
  51725. {
  51726. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51727. }
  51728. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  51729. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  51730. }
  51731. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  51732. TextEditor& textEditor)
  51733. {
  51734. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  51735. }
  51736. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  51737. {
  51738. if (textEditor.isEnabled())
  51739. {
  51740. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  51741. {
  51742. const int border = 2;
  51743. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  51744. g.drawRect (0, 0, width, height, border);
  51745. g.setOpacity (1.0f);
  51746. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  51747. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  51748. }
  51749. else
  51750. {
  51751. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  51752. g.drawRect (0, 0, width, height);
  51753. g.setOpacity (1.0f);
  51754. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  51755. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  51756. }
  51757. }
  51758. }
  51759. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  51760. const bool isButtonDown,
  51761. int buttonX, int buttonY,
  51762. int buttonW, int buttonH,
  51763. ComboBox& box)
  51764. {
  51765. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  51766. if (box.isEnabled() && box.hasKeyboardFocus (false))
  51767. {
  51768. g.setColour (box.findColour (TextButton::buttonColourId));
  51769. g.drawRect (0, 0, width, height, 2);
  51770. }
  51771. else
  51772. {
  51773. g.setColour (box.findColour (ComboBox::outlineColourId));
  51774. g.drawRect (0, 0, width, height);
  51775. }
  51776. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  51777. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  51778. box.hasKeyboardFocus (true),
  51779. false, isButtonDown)
  51780. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  51781. drawGlassLozenge (g,
  51782. buttonX + outlineThickness, buttonY + outlineThickness,
  51783. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  51784. baseColour, outlineThickness, -1.0f,
  51785. true, true, true, true);
  51786. if (box.isEnabled())
  51787. {
  51788. const float arrowX = 0.3f;
  51789. const float arrowH = 0.2f;
  51790. Path p;
  51791. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  51792. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  51793. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  51794. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  51795. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  51796. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  51797. g.setColour (box.findColour (ComboBox::arrowColourId));
  51798. g.fillPath (p);
  51799. }
  51800. }
  51801. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  51802. {
  51803. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  51804. }
  51805. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  51806. {
  51807. return new Label (String::empty, String::empty);
  51808. }
  51809. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  51810. {
  51811. label.setBounds (1, 1,
  51812. box.getWidth() + 3 - box.getHeight(),
  51813. box.getHeight() - 2);
  51814. label.setFont (getComboBoxFont (box));
  51815. }
  51816. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  51817. {
  51818. g.fillAll (label.findColour (Label::backgroundColourId));
  51819. if (! label.isBeingEdited())
  51820. {
  51821. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  51822. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  51823. g.setFont (label.getFont());
  51824. g.drawFittedText (label.getText(),
  51825. label.getHorizontalBorderSize(),
  51826. label.getVerticalBorderSize(),
  51827. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  51828. label.getHeight() - 2 * label.getVerticalBorderSize(),
  51829. label.getJustificationType(),
  51830. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  51831. label.getMinimumHorizontalScale());
  51832. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  51833. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51834. }
  51835. else if (label.isEnabled())
  51836. {
  51837. g.setColour (label.findColour (Label::outlineColourId));
  51838. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51839. }
  51840. }
  51841. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  51842. int x, int y,
  51843. int width, int height,
  51844. float /*sliderPos*/,
  51845. float /*minSliderPos*/,
  51846. float /*maxSliderPos*/,
  51847. const Slider::SliderStyle /*style*/,
  51848. Slider& slider)
  51849. {
  51850. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  51851. const Colour trackColour (slider.findColour (Slider::trackColourId));
  51852. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  51853. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  51854. Path indent;
  51855. if (slider.isHorizontal())
  51856. {
  51857. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  51858. const float ih = sliderRadius;
  51859. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  51860. gradCol2, 0.0f, iy + ih, false));
  51861. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  51862. width + sliderRadius, ih,
  51863. 5.0f);
  51864. g.fillPath (indent);
  51865. }
  51866. else
  51867. {
  51868. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  51869. const float iw = sliderRadius;
  51870. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  51871. gradCol2, ix + iw, 0.0f, false));
  51872. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  51873. iw, height + sliderRadius,
  51874. 5.0f);
  51875. g.fillPath (indent);
  51876. }
  51877. g.setColour (Colour (0x4c000000));
  51878. g.strokePath (indent, PathStrokeType (0.5f));
  51879. }
  51880. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  51881. int x, int y,
  51882. int width, int height,
  51883. float sliderPos,
  51884. float minSliderPos,
  51885. float maxSliderPos,
  51886. const Slider::SliderStyle style,
  51887. Slider& slider)
  51888. {
  51889. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  51890. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  51891. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  51892. slider.isMouseOverOrDragging() && slider.isEnabled(),
  51893. slider.isMouseButtonDown() && slider.isEnabled()));
  51894. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  51895. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  51896. {
  51897. float kx, ky;
  51898. if (style == Slider::LinearVertical)
  51899. {
  51900. kx = x + width * 0.5f;
  51901. ky = sliderPos;
  51902. }
  51903. else
  51904. {
  51905. kx = sliderPos;
  51906. ky = y + height * 0.5f;
  51907. }
  51908. drawGlassSphere (g,
  51909. kx - sliderRadius,
  51910. ky - sliderRadius,
  51911. sliderRadius * 2.0f,
  51912. knobColour, outlineThickness);
  51913. }
  51914. else
  51915. {
  51916. if (style == Slider::ThreeValueVertical)
  51917. {
  51918. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  51919. sliderPos - sliderRadius,
  51920. sliderRadius * 2.0f,
  51921. knobColour, outlineThickness);
  51922. }
  51923. else if (style == Slider::ThreeValueHorizontal)
  51924. {
  51925. drawGlassSphere (g,sliderPos - sliderRadius,
  51926. y + height * 0.5f - sliderRadius,
  51927. sliderRadius * 2.0f,
  51928. knobColour, outlineThickness);
  51929. }
  51930. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  51931. {
  51932. const float sr = jmin (sliderRadius, width * 0.4f);
  51933. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  51934. minSliderPos - sliderRadius,
  51935. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  51936. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  51937. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  51938. }
  51939. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  51940. {
  51941. const float sr = jmin (sliderRadius, height * 0.4f);
  51942. drawGlassPointer (g, minSliderPos - sr,
  51943. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  51944. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  51945. drawGlassPointer (g, maxSliderPos - sliderRadius,
  51946. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  51947. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  51948. }
  51949. }
  51950. }
  51951. void LookAndFeel::drawLinearSlider (Graphics& g,
  51952. int x, int y,
  51953. int width, int height,
  51954. float sliderPos,
  51955. float minSliderPos,
  51956. float maxSliderPos,
  51957. const Slider::SliderStyle style,
  51958. Slider& slider)
  51959. {
  51960. g.fillAll (slider.findColour (Slider::backgroundColourId));
  51961. if (style == Slider::LinearBar)
  51962. {
  51963. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  51964. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  51965. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  51966. false,
  51967. isMouseOver,
  51968. isMouseOver || slider.isMouseButtonDown()));
  51969. drawShinyButtonShape (g,
  51970. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  51971. baseColour,
  51972. slider.isEnabled() ? 0.9f : 0.3f,
  51973. true, true, true, true);
  51974. }
  51975. else
  51976. {
  51977. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  51978. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  51979. }
  51980. }
  51981. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  51982. {
  51983. return jmin (7,
  51984. slider.getHeight() / 2,
  51985. slider.getWidth() / 2) + 2;
  51986. }
  51987. void LookAndFeel::drawRotarySlider (Graphics& g,
  51988. int x, int y,
  51989. int width, int height,
  51990. float sliderPos,
  51991. const float rotaryStartAngle,
  51992. const float rotaryEndAngle,
  51993. Slider& slider)
  51994. {
  51995. const float radius = jmin (width / 2, height / 2) - 2.0f;
  51996. const float centreX = x + width * 0.5f;
  51997. const float centreY = y + height * 0.5f;
  51998. const float rx = centreX - radius;
  51999. const float ry = centreY - radius;
  52000. const float rw = radius * 2.0f;
  52001. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52002. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52003. if (radius > 12.0f)
  52004. {
  52005. if (slider.isEnabled())
  52006. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52007. else
  52008. g.setColour (Colour (0x80808080));
  52009. const float thickness = 0.7f;
  52010. {
  52011. Path filledArc;
  52012. filledArc.addPieSegment (rx, ry, rw, rw,
  52013. rotaryStartAngle,
  52014. angle,
  52015. thickness);
  52016. g.fillPath (filledArc);
  52017. }
  52018. if (thickness > 0)
  52019. {
  52020. const float innerRadius = radius * 0.2f;
  52021. Path p;
  52022. p.addTriangle (-innerRadius, 0.0f,
  52023. 0.0f, -radius * thickness * 1.1f,
  52024. innerRadius, 0.0f);
  52025. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52026. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52027. }
  52028. if (slider.isEnabled())
  52029. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52030. else
  52031. g.setColour (Colour (0x80808080));
  52032. Path outlineArc;
  52033. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52034. outlineArc.closeSubPath();
  52035. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52036. }
  52037. else
  52038. {
  52039. if (slider.isEnabled())
  52040. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52041. else
  52042. g.setColour (Colour (0x80808080));
  52043. Path p;
  52044. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52045. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52046. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52047. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52048. }
  52049. }
  52050. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52051. {
  52052. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52053. }
  52054. class SliderLabelComp : public Label
  52055. {
  52056. public:
  52057. SliderLabelComp() : Label (String::empty, String::empty) {}
  52058. ~SliderLabelComp() {}
  52059. void mouseWheelMove (const MouseEvent&, float, float) {}
  52060. };
  52061. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52062. {
  52063. Label* const l = new SliderLabelComp();
  52064. l->setJustificationType (Justification::centred);
  52065. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52066. l->setColour (Label::backgroundColourId,
  52067. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52068. : slider.findColour (Slider::textBoxBackgroundColourId));
  52069. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52070. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52071. l->setColour (TextEditor::backgroundColourId,
  52072. slider.findColour (Slider::textBoxBackgroundColourId)
  52073. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52074. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52075. return l;
  52076. }
  52077. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52078. {
  52079. return 0;
  52080. }
  52081. static const TextLayout layoutTooltipText (const String& text) throw()
  52082. {
  52083. const float tooltipFontSize = 12.0f;
  52084. const int maxToolTipWidth = 400;
  52085. const Font f (tooltipFontSize, Font::bold);
  52086. TextLayout tl (text, f);
  52087. tl.layout (maxToolTipWidth, Justification::left, true);
  52088. return tl;
  52089. }
  52090. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52091. {
  52092. const TextLayout tl (layoutTooltipText (tipText));
  52093. width = tl.getWidth() + 14;
  52094. height = tl.getHeight() + 6;
  52095. }
  52096. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52097. {
  52098. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52099. const Colour textCol (findColour (TooltipWindow::textColourId));
  52100. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52101. g.setColour (findColour (TooltipWindow::outlineColourId));
  52102. g.drawRect (0, 0, width, height, 1);
  52103. #endif
  52104. const TextLayout tl (layoutTooltipText (text));
  52105. g.setColour (findColour (TooltipWindow::textColourId));
  52106. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52107. }
  52108. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52109. {
  52110. return new TextButton (text, TRANS("click to browse for a different file"));
  52111. }
  52112. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52113. ComboBox* filenameBox,
  52114. Button* browseButton)
  52115. {
  52116. browseButton->setSize (80, filenameComp.getHeight());
  52117. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52118. if (tb != 0)
  52119. tb->changeWidthToFitText();
  52120. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52121. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52122. }
  52123. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52124. int imageX, int imageY, int imageW, int imageH,
  52125. const Colour& overlayColour,
  52126. float imageOpacity,
  52127. ImageButton& button)
  52128. {
  52129. if (! button.isEnabled())
  52130. imageOpacity *= 0.3f;
  52131. if (! overlayColour.isOpaque())
  52132. {
  52133. g.setOpacity (imageOpacity);
  52134. g.drawImage (image, imageX, imageY, imageW, imageH,
  52135. 0, 0, image->getWidth(), image->getHeight(), false);
  52136. }
  52137. if (! overlayColour.isTransparent())
  52138. {
  52139. g.setColour (overlayColour);
  52140. g.drawImage (image, imageX, imageY, imageW, imageH,
  52141. 0, 0, image->getWidth(), image->getHeight(), true);
  52142. }
  52143. }
  52144. void LookAndFeel::drawCornerResizer (Graphics& g,
  52145. int w, int h,
  52146. bool /*isMouseOver*/,
  52147. bool /*isMouseDragging*/)
  52148. {
  52149. const float lineThickness = jmin (w, h) * 0.075f;
  52150. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52151. {
  52152. g.setColour (Colours::lightgrey);
  52153. g.drawLine (w * i,
  52154. h + 1.0f,
  52155. w + 1.0f,
  52156. h * i,
  52157. lineThickness);
  52158. g.setColour (Colours::darkgrey);
  52159. g.drawLine (w * i + lineThickness,
  52160. h + 1.0f,
  52161. w + 1.0f,
  52162. h * i + lineThickness,
  52163. lineThickness);
  52164. }
  52165. }
  52166. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52167. const BorderSize& /*borders*/)
  52168. {
  52169. }
  52170. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52171. const BorderSize& /*border*/, ResizableWindow& window)
  52172. {
  52173. g.fillAll (window.getBackgroundColour());
  52174. }
  52175. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52176. const BorderSize& border, ResizableWindow&)
  52177. {
  52178. g.setColour (Colour (0x80000000));
  52179. g.drawRect (0, 0, w, h);
  52180. g.setColour (Colour (0x19000000));
  52181. g.drawRect (border.getLeft() - 1,
  52182. border.getTop() - 1,
  52183. w + 2 - border.getLeftAndRight(),
  52184. h + 2 - border.getTopAndBottom());
  52185. }
  52186. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52187. Graphics& g, int w, int h,
  52188. int titleSpaceX, int titleSpaceW,
  52189. const Image* icon,
  52190. bool drawTitleTextOnLeft)
  52191. {
  52192. const bool isActive = window.isActiveWindow();
  52193. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52194. 0.0f, 0.0f,
  52195. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52196. 0.0f, (float) h, false));
  52197. g.fillAll();
  52198. Font font (h * 0.65f, Font::bold);
  52199. g.setFont (font);
  52200. int textW = font.getStringWidth (window.getName());
  52201. int iconW = 0;
  52202. int iconH = 0;
  52203. if (icon != 0)
  52204. {
  52205. iconH = (int) font.getHeight();
  52206. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52207. }
  52208. textW = jmin (titleSpaceW, textW + iconW);
  52209. int textX = drawTitleTextOnLeft ? titleSpaceX
  52210. : jmax (titleSpaceX, (w - textW) / 2);
  52211. if (textX + textW > titleSpaceX + titleSpaceW)
  52212. textX = titleSpaceX + titleSpaceW - textW;
  52213. if (icon != 0)
  52214. {
  52215. g.setOpacity (isActive ? 1.0f : 0.6f);
  52216. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52217. RectanglePlacement::centred, false);
  52218. textX += iconW;
  52219. textW -= iconW;
  52220. }
  52221. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52222. g.setColour (findColour (DocumentWindow::textColourId));
  52223. else
  52224. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52225. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52226. }
  52227. class GlassWindowButton : public Button
  52228. {
  52229. public:
  52230. GlassWindowButton (const String& name, const Colour& col,
  52231. const Path& normalShape_,
  52232. const Path& toggledShape_) throw()
  52233. : Button (name),
  52234. colour (col),
  52235. normalShape (normalShape_),
  52236. toggledShape (toggledShape_)
  52237. {
  52238. }
  52239. ~GlassWindowButton()
  52240. {
  52241. }
  52242. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52243. {
  52244. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52245. if (! isEnabled())
  52246. alpha *= 0.5f;
  52247. float x = 0, y = 0, diam;
  52248. if (getWidth() < getHeight())
  52249. {
  52250. diam = (float) getWidth();
  52251. y = (getHeight() - getWidth()) * 0.5f;
  52252. }
  52253. else
  52254. {
  52255. diam = (float) getHeight();
  52256. y = (getWidth() - getHeight()) * 0.5f;
  52257. }
  52258. x += diam * 0.05f;
  52259. y += diam * 0.05f;
  52260. diam *= 0.9f;
  52261. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52262. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52263. g.fillEllipse (x, y, diam, diam);
  52264. x += 2.0f;
  52265. y += 2.0f;
  52266. diam -= 4.0f;
  52267. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52268. Path& p = getToggleState() ? toggledShape : normalShape;
  52269. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52270. diam * 0.4f, diam * 0.4f, true));
  52271. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52272. g.fillPath (p, t);
  52273. }
  52274. juce_UseDebuggingNewOperator
  52275. private:
  52276. Colour colour;
  52277. Path normalShape, toggledShape;
  52278. GlassWindowButton (const GlassWindowButton&);
  52279. GlassWindowButton& operator= (const GlassWindowButton&);
  52280. };
  52281. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52282. {
  52283. Path shape;
  52284. const float crossThickness = 0.25f;
  52285. if (buttonType == DocumentWindow::closeButton)
  52286. {
  52287. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52288. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52289. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52290. }
  52291. else if (buttonType == DocumentWindow::minimiseButton)
  52292. {
  52293. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52294. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52295. }
  52296. else if (buttonType == DocumentWindow::maximiseButton)
  52297. {
  52298. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52299. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52300. Path fullscreenShape;
  52301. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52302. fullscreenShape.lineTo (0.0f, 100.0f);
  52303. fullscreenShape.lineTo (0.0f, 0.0f);
  52304. fullscreenShape.lineTo (100.0f, 0.0f);
  52305. fullscreenShape.lineTo (100.0f, 45.0f);
  52306. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52307. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52308. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52309. }
  52310. jassertfalse
  52311. return 0;
  52312. }
  52313. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52314. int titleBarX,
  52315. int titleBarY,
  52316. int titleBarW,
  52317. int titleBarH,
  52318. Button* minimiseButton,
  52319. Button* maximiseButton,
  52320. Button* closeButton,
  52321. bool positionTitleBarButtonsOnLeft)
  52322. {
  52323. const int buttonW = titleBarH - titleBarH / 8;
  52324. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52325. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52326. if (closeButton != 0)
  52327. {
  52328. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52329. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52330. }
  52331. if (positionTitleBarButtonsOnLeft)
  52332. swapVariables (minimiseButton, maximiseButton);
  52333. if (maximiseButton != 0)
  52334. {
  52335. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52336. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52337. }
  52338. if (minimiseButton != 0)
  52339. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52340. }
  52341. int LookAndFeel::getDefaultMenuBarHeight()
  52342. {
  52343. return 24;
  52344. }
  52345. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52346. {
  52347. return new DropShadower (0.4f, 1, 5, 10);
  52348. }
  52349. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52350. int w, int h,
  52351. bool /*isVerticalBar*/,
  52352. bool isMouseOver,
  52353. bool isMouseDragging)
  52354. {
  52355. float alpha = 0.5f;
  52356. if (isMouseOver || isMouseDragging)
  52357. {
  52358. g.fillAll (Colour (0x190000ff));
  52359. alpha = 1.0f;
  52360. }
  52361. const float cx = w * 0.5f;
  52362. const float cy = h * 0.5f;
  52363. const float cr = jmin (w, h) * 0.4f;
  52364. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52365. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52366. true));
  52367. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52368. }
  52369. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52370. const String& text,
  52371. const Justification& position,
  52372. GroupComponent& group)
  52373. {
  52374. const float textH = 15.0f;
  52375. const float indent = 3.0f;
  52376. const float textEdgeGap = 4.0f;
  52377. float cs = 5.0f;
  52378. Font f (textH);
  52379. Path p;
  52380. float x = indent;
  52381. float y = f.getAscent() - 3.0f;
  52382. float w = jmax (0.0f, width - x * 2.0f);
  52383. float h = jmax (0.0f, height - y - indent);
  52384. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52385. const float cs2 = 2.0f * cs;
  52386. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52387. float textX = cs + textEdgeGap;
  52388. if (position.testFlags (Justification::horizontallyCentred))
  52389. textX = cs + (w - cs2 - textW) * 0.5f;
  52390. else if (position.testFlags (Justification::right))
  52391. textX = w - cs - textW - textEdgeGap;
  52392. p.startNewSubPath (x + textX + textW, y);
  52393. p.lineTo (x + w - cs, y);
  52394. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52395. p.lineTo (x + w, y + h - cs);
  52396. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52397. p.lineTo (x + cs, y + h);
  52398. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52399. p.lineTo (x, y + cs);
  52400. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52401. p.lineTo (x + textX, y);
  52402. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52403. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52404. .withMultipliedAlpha (alpha));
  52405. g.strokePath (p, PathStrokeType (2.0f));
  52406. g.setColour (group.findColour (GroupComponent::textColourId)
  52407. .withMultipliedAlpha (alpha));
  52408. g.setFont (f);
  52409. g.drawText (text,
  52410. roundToInt (x + textX), 0,
  52411. roundToInt (textW),
  52412. roundToInt (textH),
  52413. Justification::centred, true);
  52414. }
  52415. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52416. {
  52417. return 1 + tabDepth / 3;
  52418. }
  52419. int LookAndFeel::getTabButtonSpaceAroundImage()
  52420. {
  52421. return 4;
  52422. }
  52423. void LookAndFeel::createTabButtonShape (Path& p,
  52424. int width, int height,
  52425. int /*tabIndex*/,
  52426. const String& /*text*/,
  52427. Button& /*button*/,
  52428. TabbedButtonBar::Orientation orientation,
  52429. const bool /*isMouseOver*/,
  52430. const bool /*isMouseDown*/,
  52431. const bool /*isFrontTab*/)
  52432. {
  52433. const float w = (float) width;
  52434. const float h = (float) height;
  52435. float length = w;
  52436. float depth = h;
  52437. if (orientation == TabbedButtonBar::TabsAtLeft
  52438. || orientation == TabbedButtonBar::TabsAtRight)
  52439. {
  52440. swapVariables (length, depth);
  52441. }
  52442. const float indent = (float) getTabButtonOverlap ((int) depth);
  52443. const float overhang = 4.0f;
  52444. if (orientation == TabbedButtonBar::TabsAtLeft)
  52445. {
  52446. p.startNewSubPath (w, 0.0f);
  52447. p.lineTo (0.0f, indent);
  52448. p.lineTo (0.0f, h - indent);
  52449. p.lineTo (w, h);
  52450. p.lineTo (w + overhang, h + overhang);
  52451. p.lineTo (w + overhang, -overhang);
  52452. }
  52453. else if (orientation == TabbedButtonBar::TabsAtRight)
  52454. {
  52455. p.startNewSubPath (0.0f, 0.0f);
  52456. p.lineTo (w, indent);
  52457. p.lineTo (w, h - indent);
  52458. p.lineTo (0.0f, h);
  52459. p.lineTo (-overhang, h + overhang);
  52460. p.lineTo (-overhang, -overhang);
  52461. }
  52462. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52463. {
  52464. p.startNewSubPath (0.0f, 0.0f);
  52465. p.lineTo (indent, h);
  52466. p.lineTo (w - indent, h);
  52467. p.lineTo (w, 0.0f);
  52468. p.lineTo (w + overhang, -overhang);
  52469. p.lineTo (-overhang, -overhang);
  52470. }
  52471. else
  52472. {
  52473. p.startNewSubPath (0.0f, h);
  52474. p.lineTo (indent, 0.0f);
  52475. p.lineTo (w - indent, 0.0f);
  52476. p.lineTo (w, h);
  52477. p.lineTo (w + overhang, h + overhang);
  52478. p.lineTo (-overhang, h + overhang);
  52479. }
  52480. p.closeSubPath();
  52481. p = p.createPathWithRoundedCorners (3.0f);
  52482. }
  52483. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52484. const Path& path,
  52485. const Colour& preferredColour,
  52486. int /*tabIndex*/,
  52487. const String& /*text*/,
  52488. Button& button,
  52489. TabbedButtonBar::Orientation /*orientation*/,
  52490. const bool /*isMouseOver*/,
  52491. const bool /*isMouseDown*/,
  52492. const bool isFrontTab)
  52493. {
  52494. g.setColour (isFrontTab ? preferredColour
  52495. : preferredColour.withMultipliedAlpha (0.9f));
  52496. g.fillPath (path);
  52497. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52498. : TabbedButtonBar::tabOutlineColourId, false)
  52499. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52500. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52501. }
  52502. void LookAndFeel::drawTabButtonText (Graphics& g,
  52503. int x, int y, int w, int h,
  52504. const Colour& preferredBackgroundColour,
  52505. int /*tabIndex*/,
  52506. const String& text,
  52507. Button& button,
  52508. TabbedButtonBar::Orientation orientation,
  52509. const bool isMouseOver,
  52510. const bool isMouseDown,
  52511. const bool isFrontTab)
  52512. {
  52513. int length = w;
  52514. int depth = h;
  52515. if (orientation == TabbedButtonBar::TabsAtLeft
  52516. || orientation == TabbedButtonBar::TabsAtRight)
  52517. {
  52518. swapVariables (length, depth);
  52519. }
  52520. Font font (depth * 0.6f);
  52521. font.setUnderline (button.hasKeyboardFocus (false));
  52522. GlyphArrangement textLayout;
  52523. textLayout.addFittedText (font, text.trim(),
  52524. 0.0f, 0.0f, (float) length, (float) depth,
  52525. Justification::centred,
  52526. jmax (1, depth / 12));
  52527. AffineTransform transform;
  52528. if (orientation == TabbedButtonBar::TabsAtLeft)
  52529. {
  52530. transform = transform.rotated (float_Pi * -0.5f)
  52531. .translated ((float) x, (float) (y + h));
  52532. }
  52533. else if (orientation == TabbedButtonBar::TabsAtRight)
  52534. {
  52535. transform = transform.rotated (float_Pi * 0.5f)
  52536. .translated ((float) (x + w), (float) y);
  52537. }
  52538. else
  52539. {
  52540. transform = transform.translated ((float) x, (float) y);
  52541. }
  52542. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52543. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52544. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52545. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52546. else
  52547. g.setColour (preferredBackgroundColour.contrasting());
  52548. if (! (isMouseOver || isMouseDown))
  52549. g.setOpacity (0.8f);
  52550. if (! button.isEnabled())
  52551. g.setOpacity (0.3f);
  52552. textLayout.draw (g, transform);
  52553. }
  52554. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52555. const String& text,
  52556. int tabDepth,
  52557. Button&)
  52558. {
  52559. Font f (tabDepth * 0.6f);
  52560. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52561. }
  52562. void LookAndFeel::drawTabButton (Graphics& g,
  52563. int w, int h,
  52564. const Colour& preferredColour,
  52565. int tabIndex,
  52566. const String& text,
  52567. Button& button,
  52568. TabbedButtonBar::Orientation orientation,
  52569. const bool isMouseOver,
  52570. const bool isMouseDown,
  52571. const bool isFrontTab)
  52572. {
  52573. int length = w;
  52574. int depth = h;
  52575. if (orientation == TabbedButtonBar::TabsAtLeft
  52576. || orientation == TabbedButtonBar::TabsAtRight)
  52577. {
  52578. swapVariables (length, depth);
  52579. }
  52580. Path tabShape;
  52581. createTabButtonShape (tabShape, w, h,
  52582. tabIndex, text, button, orientation,
  52583. isMouseOver, isMouseDown, isFrontTab);
  52584. fillTabButtonShape (g, tabShape, preferredColour,
  52585. tabIndex, text, button, orientation,
  52586. isMouseOver, isMouseDown, isFrontTab);
  52587. const int indent = getTabButtonOverlap (depth);
  52588. int x = 0, y = 0;
  52589. if (orientation == TabbedButtonBar::TabsAtLeft
  52590. || orientation == TabbedButtonBar::TabsAtRight)
  52591. {
  52592. y += indent;
  52593. h -= indent * 2;
  52594. }
  52595. else
  52596. {
  52597. x += indent;
  52598. w -= indent * 2;
  52599. }
  52600. drawTabButtonText (g, x, y, w, h, preferredColour,
  52601. tabIndex, text, button, orientation,
  52602. isMouseOver, isMouseDown, isFrontTab);
  52603. }
  52604. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52605. int w, int h,
  52606. TabbedButtonBar& tabBar,
  52607. TabbedButtonBar::Orientation orientation)
  52608. {
  52609. const float shadowSize = 0.2f;
  52610. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52611. Rectangle<int> shadowRect;
  52612. if (orientation == TabbedButtonBar::TabsAtLeft)
  52613. {
  52614. x1 = (float) w;
  52615. x2 = w * (1.0f - shadowSize);
  52616. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52617. }
  52618. else if (orientation == TabbedButtonBar::TabsAtRight)
  52619. {
  52620. x2 = w * shadowSize;
  52621. shadowRect.setBounds (0, 0, (int) x2, h);
  52622. }
  52623. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52624. {
  52625. y2 = h * shadowSize;
  52626. shadowRect.setBounds (0, 0, w, (int) y2);
  52627. }
  52628. else
  52629. {
  52630. y1 = (float) h;
  52631. y2 = h * (1.0f - shadowSize);
  52632. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52633. }
  52634. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52635. Colours::transparentBlack, x2, y2, false));
  52636. shadowRect.expand (2, 2);
  52637. g.fillRect (shadowRect);
  52638. g.setColour (Colour (0x80000000));
  52639. if (orientation == TabbedButtonBar::TabsAtLeft)
  52640. {
  52641. g.fillRect (w - 1, 0, 1, h);
  52642. }
  52643. else if (orientation == TabbedButtonBar::TabsAtRight)
  52644. {
  52645. g.fillRect (0, 0, 1, h);
  52646. }
  52647. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52648. {
  52649. g.fillRect (0, 0, w, 1);
  52650. }
  52651. else
  52652. {
  52653. g.fillRect (0, h - 1, w, 1);
  52654. }
  52655. }
  52656. Button* LookAndFeel::createTabBarExtrasButton()
  52657. {
  52658. const float thickness = 7.0f;
  52659. const float indent = 22.0f;
  52660. Path p;
  52661. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52662. DrawablePath ellipse;
  52663. ellipse.setPath (p);
  52664. ellipse.setFill (Colour (0x99ffffff));
  52665. p.clear();
  52666. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52667. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52668. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52669. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52670. p.setUsingNonZeroWinding (false);
  52671. DrawablePath dp;
  52672. dp.setPath (p);
  52673. dp.setFill (Colour (0x59000000));
  52674. DrawableComposite normalImage;
  52675. normalImage.insertDrawable (ellipse);
  52676. normalImage.insertDrawable (dp);
  52677. dp.setFill (Colour (0xcc000000));
  52678. DrawableComposite overImage;
  52679. overImage.insertDrawable (ellipse);
  52680. overImage.insertDrawable (dp);
  52681. DrawableButton* db = new DrawableButton ("tabs", DrawableButton::ImageFitted);
  52682. db->setImages (&normalImage, &overImage, 0);
  52683. return db;
  52684. }
  52685. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52686. {
  52687. g.fillAll (Colours::white);
  52688. const int w = header.getWidth();
  52689. const int h = header.getHeight();
  52690. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52691. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52692. false));
  52693. g.fillRect (0, h / 2, w, h);
  52694. g.setColour (Colour (0x33000000));
  52695. g.fillRect (0, h - 1, w, 1);
  52696. for (int i = header.getNumColumns (true); --i >= 0;)
  52697. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52698. }
  52699. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52700. int width, int height,
  52701. bool isMouseOver, bool isMouseDown,
  52702. int columnFlags)
  52703. {
  52704. if (isMouseDown)
  52705. g.fillAll (Colour (0x8899aadd));
  52706. else if (isMouseOver)
  52707. g.fillAll (Colour (0x5599aadd));
  52708. int rightOfText = width - 4;
  52709. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52710. {
  52711. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52712. const float bottom = height - top;
  52713. const float w = height * 0.5f;
  52714. const float x = rightOfText - (w * 1.25f);
  52715. rightOfText = (int) x;
  52716. Path sortArrow;
  52717. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52718. g.setColour (Colour (0x99000000));
  52719. g.fillPath (sortArrow);
  52720. }
  52721. g.setColour (Colours::black);
  52722. g.setFont (height * 0.5f, Font::bold);
  52723. const int textX = 4;
  52724. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52725. }
  52726. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52727. {
  52728. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  52729. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  52730. background.darker (0.1f),
  52731. toolbar.isVertical() ? w - 1.0f : 0.0f,
  52732. toolbar.isVertical() ? 0.0f : h - 1.0f,
  52733. false));
  52734. g.fillAll();
  52735. }
  52736. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  52737. {
  52738. return createTabBarExtrasButton();
  52739. }
  52740. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  52741. bool isMouseOver, bool isMouseDown,
  52742. ToolbarItemComponent& component)
  52743. {
  52744. if (isMouseDown)
  52745. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  52746. else if (isMouseOver)
  52747. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  52748. }
  52749. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  52750. const String& text, ToolbarItemComponent& component)
  52751. {
  52752. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  52753. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  52754. const float fontHeight = jmin (14.0f, height * 0.85f);
  52755. g.setFont (fontHeight);
  52756. g.drawFittedText (text,
  52757. x, y, width, height,
  52758. Justification::centred,
  52759. jmax (1, height / (int) fontHeight));
  52760. }
  52761. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  52762. bool isOpen, int width, int height)
  52763. {
  52764. const int buttonSize = (height * 3) / 4;
  52765. const int buttonIndent = (height - buttonSize) / 2;
  52766. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  52767. const int textX = buttonIndent * 2 + buttonSize + 2;
  52768. g.setColour (Colours::black);
  52769. g.setFont (height * 0.7f, Font::bold);
  52770. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  52771. }
  52772. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  52773. PropertyComponent&)
  52774. {
  52775. g.setColour (Colour (0x66ffffff));
  52776. g.fillRect (0, 0, width, height - 1);
  52777. }
  52778. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  52779. PropertyComponent& component)
  52780. {
  52781. g.setColour (Colours::black);
  52782. if (! component.isEnabled())
  52783. g.setOpacity (0.6f);
  52784. g.setFont (jmin (height, 24) * 0.65f);
  52785. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  52786. g.drawFittedText (component.getName(),
  52787. 3, r.getY(), r.getX() - 5, r.getHeight(),
  52788. Justification::centredLeft, 2);
  52789. }
  52790. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  52791. {
  52792. return Rectangle<int> (component.getWidth() / 3, 1,
  52793. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  52794. }
  52795. void LookAndFeel::createFileChooserHeaderText (const String& title,
  52796. const String& instructions,
  52797. GlyphArrangement& text,
  52798. int width)
  52799. {
  52800. text.clear();
  52801. text.addJustifiedText (Font (17.0f, Font::bold), title,
  52802. 8.0f, 22.0f, width - 16.0f,
  52803. Justification::centred);
  52804. text.addJustifiedText (Font (14.0f), instructions,
  52805. 8.0f, 24.0f + 16.0f, width - 16.0f,
  52806. Justification::centred);
  52807. }
  52808. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  52809. const String& filename, Image* icon,
  52810. const String& fileSizeDescription,
  52811. const String& fileTimeDescription,
  52812. const bool isDirectory,
  52813. const bool isItemSelected,
  52814. const int /*itemIndex*/)
  52815. {
  52816. if (isItemSelected)
  52817. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  52818. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  52819. g.setFont (height * 0.7f);
  52820. Image* im = icon;
  52821. Image* toRelease = 0;
  52822. if (im == 0)
  52823. {
  52824. toRelease = im = (isDirectory ? getDefaultFolderImage()
  52825. : getDefaultDocumentFileImage());
  52826. }
  52827. const int x = 32;
  52828. if (im != 0)
  52829. {
  52830. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  52831. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  52832. false);
  52833. ImageCache::release (toRelease);
  52834. }
  52835. if (width > 450 && ! isDirectory)
  52836. {
  52837. const int sizeX = roundToInt (width * 0.7f);
  52838. const int dateX = roundToInt (width * 0.8f);
  52839. g.drawFittedText (filename,
  52840. x, 0, sizeX - x, height,
  52841. Justification::centredLeft, 1);
  52842. g.setFont (height * 0.5f);
  52843. g.setColour (Colours::darkgrey);
  52844. if (! isDirectory)
  52845. {
  52846. g.drawFittedText (fileSizeDescription,
  52847. sizeX, 0, dateX - sizeX - 8, height,
  52848. Justification::centredRight, 1);
  52849. g.drawFittedText (fileTimeDescription,
  52850. dateX, 0, width - 8 - dateX, height,
  52851. Justification::centredRight, 1);
  52852. }
  52853. }
  52854. else
  52855. {
  52856. g.drawFittedText (filename,
  52857. x, 0, width - x, height,
  52858. Justification::centredLeft, 1);
  52859. }
  52860. }
  52861. Button* LookAndFeel::createFileBrowserGoUpButton()
  52862. {
  52863. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  52864. Path arrowPath;
  52865. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  52866. DrawablePath arrowImage;
  52867. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  52868. arrowImage.setPath (arrowPath);
  52869. goUpButton->setImages (&arrowImage);
  52870. return goUpButton;
  52871. }
  52872. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  52873. DirectoryContentsDisplayComponent* fileListComponent,
  52874. FilePreviewComponent* previewComp,
  52875. ComboBox* currentPathBox,
  52876. TextEditor* filenameBox,
  52877. Button* goUpButton)
  52878. {
  52879. const int x = 8;
  52880. int w = browserComp.getWidth() - x - x;
  52881. if (previewComp != 0)
  52882. {
  52883. const int previewWidth = w / 3;
  52884. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  52885. w -= previewWidth + 4;
  52886. }
  52887. int y = 4;
  52888. const int controlsHeight = 22;
  52889. const int bottomSectionHeight = controlsHeight + 8;
  52890. const int upButtonWidth = 50;
  52891. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  52892. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  52893. y += controlsHeight + 4;
  52894. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  52895. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  52896. y = listAsComp->getBottom() + 4;
  52897. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  52898. }
  52899. Image* LookAndFeel::getDefaultFolderImage()
  52900. {
  52901. static const unsigned char foldericon_png[] = { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,28,8,6,0,0,0,0,194,189,34,0,0,0,4,103,65,77,65,0,0,175,200,55,5,
  52902. 138,233,0,0,0,25,116,69,88,116,83,111,102,116,119,97,114,101,0,65,100,111,98,101,32,73,109,97,103,101,82,101,97,100,121,113,201,101,60,0,0,9,46,73,68,65,84,120,218,98,252,255,255,63,3,50,240,41,95,192,
  52903. 197,205,198,32,202,204,202,33,241,254,235,47,133,47,191,24,180,213,164,133,152,69,24,222,44,234,42,77,188,245,31,170,129,145,145,145,1,29,128,164,226,91,86,113,252,248,207,200,171,37,39,204,239,170,43,
  52904. 254,206,218,88,231,61,62,61,0,1,196,2,149,96,116,200,158,102,194,202,201,227,197,193,206,166,194,204,193,33,195,202,204,38,42,197,197,42,196,193,202,33,240,241,231,15,134,151,95,127,9,2,149,22,0,241,47,
  52905. 152,230,128,134,245,204,63,191,188,103,83,144,16,16,228,229,102,151,76,239,217,32,199,204,198,169,205,254,159,65,245,203,79,6,169,131,151,30,47,1,42,91,10,196,127,208,236,101,76,235,90,43,101,160,40,242,
  52906. 19,32,128,64,78,98,52,12,41,149,145,215,52,89,162,38,35,107,39,196,203,203,192,206,194,206,192,197,198,202,192,203,197,198,192,205,193,206,240,252,227,103,134,139,55,175,191,127,243,242,78,219,187,207,
  52907. 63,215,255,98,23,48,228,227,96,83,98,102,102,85,225,224,228,80,20,224,230,86,226,225,228,150,103,101,97,101,230,227,228,96,224,0,234,191,243,252,5,195,222,19,199,38,191,127,112,161,83,66,199,86,141,131,
  52908. 149,69,146,133,153,69,137,149,133,89,157,141,131,77,83,140,143,243,219,255,31,159,123,0,2,136,69,90,207,129,157,71,68,42,66,71,73,209,210,81,91,27,24,142,140,12,127,255,253,103,0,185,236,31,3,144,6,50,
  52909. 148,68,216,25,216,24,117,4,239,11,243,214,49,50,51,84,178,48,114,240,112,177,114,177,240,115,113,49,241,112,112,48,176,179,178,51,176,48,49,3,85,255,99,248,253,247,15,195,247,159,191,25,30,191,126,253,
  52910. 71,74,76,200,66,75,197,119,138,168,144,160,150,168,0,183,160,152,32,15,175,188,184,32,199,175,191,127,25,214,31,184,120,247,236,209,253,159,0,2,136,133,95,70,93,74,88,80,196,83,69,66,130,149,9,104,219,
  52911. 151,31,191,193,150,194,146,6,136,102,102,98,100,16,227,231,103,16,23,210,230,101,101,102,100,248,255,143,137,225,223,63,6,6,22,102,38,134,239,191,126,49,220,123,241,134,225,227,247,175,64,7,252,101,96,
  52912. 97,249,207,192,193,198,200,160,171,34,192,108,165,235,104,42,204,207,101,42,194,199,197,192,199,201,198,192,197,193,202,192,198,202,194,176,247,194,3,134,155,183,110,61,188,127,124,221,19,128,0,92,146,
  52913. 49,14,64,64,16,69,63,153,85,16,52,18,74,71,112,6,87,119,0,165,160,86,138,32,172,216,29,49,182,84,253,169,94,94,230,127,17,87,133,34,146,174,3,88,126,240,219,164,147,113,31,145,244,152,112,179,211,130,
  52914. 34,31,203,113,162,233,6,36,49,163,174,74,124,140,60,141,144,165,161,220,228,25,3,24,105,255,17,168,101,1,139,245,188,93,104,251,73,239,235,50,90,189,111,175,0,98,249,254,254,249,175,239,223,190,126,6,
  52915. 5,27,19,47,90,170,102,0,249,158,129,129,141,133,25,228,20,6,38,38,72,74,7,185,243,243,247,239,12,23,31,60,98,228,231,253,207,144,227,107,206,32,202,199,193,240,249,251,127,134,95,191,255,49,124,249,250,
  52916. 159,225,237,239,95,12,63,127,1,35,229,31,194,71,32,71,63,123,251,245,223,197,27,183,159,189,187,178,103,61,80,232,59,64,0,177,48,252,5,134,225,255,191,223,126,254,250,13,182,132,1,41,167,176,3,53,128,
  52917. 188,254,226,253,103,96,212,252,96,120,247,249,203,255,79,223,191,254,255,250,235,199,191,239,63,191,255,87,145,17,100,73,116,181,100,252,249,243,63,195,149,123,223,193,14,132,101,55,96,52,3,125,255,15,
  52918. 204,254,15,132,160,232,253,13,20,124,248,226,227,223,23,207,30,221,120,119,255,226,109,160,210,31,0,1,196,242,231,219,135,175,140,255,126,190,7,197,37,35,19,34,216,65,248,211,143,111,255,79,223,121,240,
  52919. 255,211,183,79,76,220,156,172,12,236,204,140,140,252,124,28,140,250,226,82,140,106,82,34,140,124,156,156,12,175,222,253,1,90,4,137,162,63,127,33,161,6,178,242,215,239,255,224,160,255,15,198,12,64,7,48,
  52920. 128,211,200,253,151,111,254,254,248,240,236,44,80,217,71,80,246,4,8,32,160,31,255,255,100,102,248,243,238,199,159,63,16,221,16,19,128,248,31,195,181,199,207,254,255,253,247,133,49,212,78,27,104,8,11,40,
  52921. 94,25,184,216,89,129,108,38,70,144,242,183,31,17,105,230,63,148,248,15,97,49,252,248,249,15,20,85,72,105,9,148,187,254,49,220,127,254,242,207,243,75,135,14,128,130,31,84,64,1,4,16,203,247,143,175,127,
  52922. 48,253,254,246,234,7,48,206,96,137,13,4,64,65,248,234,195,7,6,7,3,57,70,33,46,97,134,111,63,254,50,252,5,250,244,51,216,103,255,192,185,0,150,91,80,44,135,242,127,253,129,164,23,24,96,102,250,207,112,
  52923. 255,213,219,255,247,31,63,188,251,246,201,173,199,176,2,13,32,128,88,62,188,121,241,243,211,231,207,31,126,2,147,236,63,168,6,144,193,223,190,255,254,207,198,198,192,40,35,44,206,240,252,205,79,6,132,
  52924. 223,24,224,150,32,251,28,25,128,211,29,19,170,24,51,48,88,111,61,127,206,248,254,245,179,139,192,18,247,219,239,239,95,192,249,9,32,128,88,126,124,249,248,231,203,183,111,159,128,33,240,15,24,68,160,180,
  52925. 2,204,223,140,12,111,63,127,102,16,228,229,4,6,53,35,195,31,176,119,25,112,3,70,84,55,0,203,50,112,33,134,108,249,103,160,7,159,189,126,253,235,235,227,203,7,255,255,251,247,13,86,63,0,4,16,168,46,248,
  52926. 199,250,231,243,235,159,191,126,254,248,245,251,47,23,11,51,51,48,184,152,24,94,127,250,248,95,68,136,151,241,243,55,96,208,51,160,218,255,31,139,27,144,197,254,98,201,202,79,223,124,96,120,245,232,250,
  52927. 185,119,143,174,95,250,243,243,219,119,152,60,64,0,129,2,234,223,183,215,15,95,48,254,255,253,3,146,109,192,229,5,195,135,47,159,25,248,184,121,24,126,0,227,29,88,240,49,252,101,36,14,255,1,90,249,7,156,
  52928. 222,17,24,24,164,12,207,223,189,99,248,250,252,230,97,96,229,245,2,104,231,111,152,3,0,2,8,228,128,191,15,239,220,120,255,255,223,159,47,160,116,0,42,44,222,124,250,244,239,207,255,63,12,236,108,236,64,
  52929. 67,65,81,0,52,244,63,113,248,47,52,10,96,14,98,2,230,191,119,223,127,48,60,121,254,248,235,151,55,207,46,1,163,252,35,114,128,1,4,16,40,10,254,191,121,249,252,199,175,159,63,191,254,2,230,45,118,22,22,
  52930. 134,219,207,94,252,231,224,100,103,250,247,15,148,32,64,85,12,34,14,254,227,72,6,255,225,9,240,63,138,26,46,96,214,189,249,244,37,195,139,167,143,30,124,253,246,253,9,40,245,255,71,202,30,0,1,196,2,226,
  52931. 0,243,232,159,239,63,127,124,253,11,202,94,64,169,23,31,62,50,138,137,242,49,50,0,211,195,223,255,80,7,252,199,159,6,224,137,145,9,146,231,153,160,165,218,23,96,29,240,244,237,59,134,111,175,31,95,250,
  52932. 252,230,241,83,244,182,1,64,0,177,192,28,14,76,132,31,128,169,19,88,220,126,253,207,206,198,196,32,38,36,0,244,61,11,176,148,251,139,145,3,208,29,0,178,16,82,228,66,42,174,223,192,26,8,152,162,25,222,
  52933. 125,248,200,240,242,253,39,134,151,79,238,126,254,242,242,238,177,15,47,30,190,5,215,242,72,0,32,128,224,14,96,254,255,231,61,168,92,123,241,254,253,127,1,62,78,6,78,110,78,134,223,64,195,254,50,98,183,
  52934. 24,36,12,202,179,224,202,9,88,228,253,132,90,250,246,211,71,134,55,175,94,254,122,255,250,249,247,15,175,159,126,249,251,237,195,135,95,175,110,31,122,117,251,244,49,160,150,111,255,209,218,128,0,1,152,
  52935. 44,183,21,0,65,32,136,110,247,254,255,243,122,9,187,64,105,174,74,22,138,25,173,80,208,194,188,238,156,151,217,217,15,32,182,197,37,83,201,4,31,243,178,169,232,242,214,224,223,252,103,175,35,85,1,41,129,
  52936. 228,148,142,8,214,30,32,149,6,161,204,109,182,53,236,184,156,78,142,147,195,153,89,35,198,3,87,166,249,220,227,198,59,218,48,252,223,185,111,30,1,132,228,128,127,31,222,124,248,248,27,24,152,28,60,220,
  52937. 220,12,44,172,172,224,224,103,5,102,98,144,133,160,236,244,229,231,47,134,239,223,127,49,188,121,251,158,225,241,179,103,12,31,223,189,254,251,227,221,139,55,191,62,188,120,246,235,205,189,59,207,238,
  52938. 94,58,241,228,254,109,144,101,159,128,248,51,40,9,32,97,80,217,255,15,221,1,0,1,4,143,130,207,159,191,126,252,246,234,213,111,94,126,94,118,73,94,9,198,127,64,223,126,252,246,147,225,243,215,239,12,223,
  52939. 128,229,198,251,15,239,24,62,189,126,249,227,203,171,135,47,63,189,122,252,228,235,155,199,247,95,63,188,118,227,197,227,123,247,127,255,250,249,30,104,198,7,32,126,11,181,252,7,212,183,160,4,247,7,155,
  52940. 197,48,0,16,64,112,7,60,121,241,238,189,16,207,15,134,63,63,216,25,95,125,248,198,112,227,241,27,134,15,239,223,50,124,126,245,228,253,143,55,143,158,191,123,116,237,226,171,135,55,175,126,253,252,225,
  52941. 229,183,47,159,95,254,253,245,227,253,175,159,223,223,193,124,7,181,20,84,105,252,70,143,103,124,0,32,128,224,14,224,102,253,251,81,144,253,223,235,167,207,30,254,124,127,231,252,155,143,175,159,188,250,
  52942. 246,254,249,125,96,60,62,248,250,233,253,147,119,207,238,221,6,150,214,175,129,106,191,130,18,19,146,133,120,125,72,8,0,4,16,34,27,190,121,112,251,3,211,159,69,143,110,223,229,120,255,232,230,221,215,
  52943. 79,239,62,4,102,203,207,72,241,9,11,218,63,72,89,137,20,207,98,100,93,16,0,8,32,70,144,1,64,14,168,209,199,7,196,194,160,166,27,212,135,95,96,65,10,173,95,254,34,219,6,51,128,88,7,96,235,21,129,0,64,0,
  52944. 193,28,192,8,174,53,33,152,1,155,133,184,12,196,165,4,151,133,232,0,32,192,0,151,97,210,163,246,134,208,52,0,0,0,0,73,69,78,68,174,66,96,130,0,0};
  52945. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  52946. }
  52947. Image* LookAndFeel::getDefaultDocumentFileImage()
  52948. {
  52949. static const unsigned char fileicon_png[] = { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,32,8,6,0,0,0,115,122,122,244,0,0,0,4,103,65,77,65,0,0,175,200,55,5,
  52950. 138,233,0,0,0,25,116,69,88,116,83,111,102,116,119,97,114,101,0,65,100,111,98,101,32,73,109,97,103,101,82,101,97,100,121,113,201,101,60,0,0,4,99,73,68,65,84,120,218,98,252,255,255,63,3,12,48,50,50,50,1,
  52951. 169,127,200,98,148,2,160,153,204,64,243,254,226,146,7,8,32,22,52,203,255,107,233,233,91,76,93,176,184,232,239,239,95,127,24,40,112,8,19,51,203,255,179,23,175,108,1,90,190,28,104,54,43,80,232,207,127,44,
  52952. 62,3,8,32,6,144,24,84,156,25,132,189,252,3,146,255,83,9,220,127,254,242,134,162,138,170,10,208,92,144,3,152,97,118,33,99,128,0,98,66,114,11,200,1,92,255,254,252,225,32,215,215,32,127,64,240,127,80,60,
  52953. 50,40,72,136,169,47,95,179,118,130,136,148,140,0,40,80,128,33,193,136,174,7,32,128,144,29,192,8,117,41,59,209,22,66,241,191,255,16,12,244,19,195,63,48,134,240,255,0,9,115,125,93,239,252,130,130,108,168,
  52954. 249,44,232,102,0,4,16,19,22,62,51,33,11,255,195,44,4,211,255,25,96,16,33,6,117,24,56,226,25,24,202,139,10,75,226,51,115,66,160,105,13,197,17,0,1,196,68,172,79,255,33,91,206,192,192,128,176,22,17,10,200,
  52955. 234,32,161,240,31,24,10,255,24,152,153,153,184,39,244,247,117,107,234,234,105,131,66,1,154,224,193,0,32,128,240,58,0,22,180,255,144,18,13,40,136,33,113,140,36,255,15,17,26,48,12,81,15,145,255,254,251,
  52956. 31,131,0,59,171,84,81,73,105,33,208,216,191,200,161,12,16,64,44,248,131,251,63,10,31,198,253,143,38,6,83,7,11,33,228,232,2,123,4,202,226,228,96,151,132,166,49,144,35,126,131,196,0,2,136,5,103,60,51,252,
  52957. 71,49,12,213,130,255,168,226,232,150,254,255,15,143,6,80,202,3,133,16,200,198,63,127,193,229,17,39,16,127,135,217,7,16,64,88,67,0,28,143,255,25,225,46,135,249,18,155,133,240,178,4,205,145,8,62,52,186,
  52958. 32,234,152,160,118,194,179,35,64,0,177,96,11,123,144,236,95,104,92,162,228,113,36,11,81,125,140,112,56,186,131,96,226,176,172,137,148,229,193,0,32,128,88,112,167,248,255,112,223,48,34,165,110,6,124,190,
  52959. 253,143,61,106,192,9,19,73,28,25,0,4,16,206,40,248,251,15,45,104,209,130,21,51,222,145,18,238,127,180,68,8,244,250,95,164,16,66,6,0,1,196,130,45,253,195,12,250,135,53,206,255,195,131,18,213,98,236,81,
  52960. 243,31,154,11,144,115,8,50,0,8,32,156,81,0,203,227,12,80,223,98,230,4,68,72,96,38,78,84,11,65,9,250,47,146,3,145,1,64,0,97,117,192,95,112,34,68,138,130,255,176,224,251,143,226,51,6,6,68,29,192,136,20,
  52961. 77,200,69,54,35,3,36,49,255,69,77,132,112,0,16,64,44,56,139,94,36,7,96,102,59,164,108,249,31,181,82,98,64,203,174,255,144,234,142,127,88,146,33,64,0,97,205,134,240,120,67,75,76,136,224,198,140,22,6,44,
  52962. 142,66,201,41,255,177,231,2,128,0,194,25,5,255,254,161,134,192,127,6,28,229,0,129,242,1,150,56,33,81,138,209,28,96,0,8,32,172,81,0,78,3,104,190,68,182,224,31,146,197,224,56,6,146,140,176,202,135,17,169,
  52963. 96,130,40,64,56,0,139,93,0,1,132,61,10,64,248,31,106,156,162,199,55,204,65,255,144,178,38,74,84,252,71,51,239,63,246,68,8,16,64,44,216,74,1,88,217,13,203,191,32,1,80,58,7,133,224,127,6,68,114,6,241,65,
  52964. 81,197,8,101,255,71,114,33,92,237,127,228,52,128,233,2,128,0,98,193,149,3,64,117,193,255,127,255,81,75,191,127,168,5,18,136,255,31,45,161,49,32,151,134,72,252,127,12,216,203,98,128,0,98,193,210,144,135,
  52965. 248,30,201,242,127,208,252,140,145,27,160,113,206,136,148,197,192,121,159,17,53,184,225,149,17,22,23,0,4,16,11,182,150,237,63,168,207,96,142,248,143,163,72,6,203,253,67,13,61,6,104,14,66,46,17,254,65,
  52966. 19,40,182,16,0,8,32,22,108,109,235,255,176,234,24,35,79,255,199,222,30,64,81,135,90,35,194,211,4,142,92,0,16,64,88,29,0,107,7,254,251,247,31,53,78,241,54,207,80,29,135,209,96,249,143,189,46,0,8,32,116,
  52967. 7,252,101,102,103,103,228,103,99,96,248,193,198,137,53,248,49,125,204,128,225,227,255,88,18,54,47,176,25,202,205,195,205,6,109,11,194,149,0,4,16,35,204,85,208,254,27,159,128,176,176,142,166,182,142,21,
  52968. 48,4,248,129,41,143,13,217,16,70,52,95,147,0,254,0,187,69,95,223,188,122,125,235,206,141,107,7,129,252,247,64,123,193,237,66,128,0,66,118,0,168,189,198,3,196,252,32,135,64,105,54,228,230,19,185,29,100,
  52969. 168,175,191,0,241,7,32,254,4,196,159,129,246,254,2,73,2,4,16,11,90,72,125,135,210,63,161,138,153,169,212,75,255,15,117,196,15,40,134,119,215,1,2,12,0,187,0,132,247,216,161,197,124,0,0,0,0,73,69,78,68,
  52970. 174,66,96,130,0,0};
  52971. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  52972. }
  52973. void LookAndFeel::playAlertSound()
  52974. {
  52975. PlatformUtilities::beep();
  52976. }
  52977. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  52978. {
  52979. g.setColour (Colours::white.withAlpha (0.7f));
  52980. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  52981. g.setColour (Colours::black.withAlpha (0.2f));
  52982. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  52983. const int totalBlocks = 7;
  52984. const int numBlocks = roundToInt (totalBlocks * level);
  52985. const float w = (width - 6.0f) / (float) totalBlocks;
  52986. for (int i = 0; i < totalBlocks; ++i)
  52987. {
  52988. if (i >= numBlocks)
  52989. g.setColour (Colours::lightblue.withAlpha (0.6f));
  52990. else
  52991. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  52992. : Colours::red);
  52993. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  52994. }
  52995. }
  52996. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  52997. {
  52998. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  52999. if (keyDescription.isNotEmpty())
  53000. {
  53001. if (button.isEnabled())
  53002. {
  53003. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53004. g.fillAll (textColour.withAlpha (alpha));
  53005. g.setOpacity (0.3f);
  53006. g.drawBevel (0, 0, width, height, 2);
  53007. }
  53008. g.setColour (textColour);
  53009. g.setFont (height * 0.6f);
  53010. g.drawFittedText (keyDescription,
  53011. 3, 0, width - 6, height,
  53012. Justification::centred, 1);
  53013. }
  53014. else
  53015. {
  53016. const float thickness = 7.0f;
  53017. const float indent = 22.0f;
  53018. Path p;
  53019. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53020. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53021. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53022. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53023. p.setUsingNonZeroWinding (false);
  53024. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53025. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53026. }
  53027. if (button.hasKeyboardFocus (false))
  53028. {
  53029. g.setColour (textColour.withAlpha (0.4f));
  53030. g.drawRect (0, 0, width, height);
  53031. }
  53032. }
  53033. static void createRoundedPath (Path& p,
  53034. const float x, const float y,
  53035. const float w, const float h,
  53036. const float cs,
  53037. const bool curveTopLeft, const bool curveTopRight,
  53038. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53039. {
  53040. const float cs2 = 2.0f * cs;
  53041. if (curveTopLeft)
  53042. {
  53043. p.startNewSubPath (x, y + cs);
  53044. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53045. }
  53046. else
  53047. {
  53048. p.startNewSubPath (x, y);
  53049. }
  53050. if (curveTopRight)
  53051. {
  53052. p.lineTo (x + w - cs, y);
  53053. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53054. }
  53055. else
  53056. {
  53057. p.lineTo (x + w, y);
  53058. }
  53059. if (curveBottomRight)
  53060. {
  53061. p.lineTo (x + w, y + h - cs);
  53062. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53063. }
  53064. else
  53065. {
  53066. p.lineTo (x + w, y + h);
  53067. }
  53068. if (curveBottomLeft)
  53069. {
  53070. p.lineTo (x + cs, y + h);
  53071. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53072. }
  53073. else
  53074. {
  53075. p.lineTo (x, y + h);
  53076. }
  53077. p.closeSubPath();
  53078. }
  53079. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53080. float x, float y, float w, float h,
  53081. float maxCornerSize,
  53082. const Colour& baseColour,
  53083. const float strokeWidth,
  53084. const bool flatOnLeft,
  53085. const bool flatOnRight,
  53086. const bool flatOnTop,
  53087. const bool flatOnBottom) throw()
  53088. {
  53089. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53090. return;
  53091. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53092. Path outline;
  53093. createRoundedPath (outline, x, y, w, h, cs,
  53094. ! (flatOnLeft || flatOnTop),
  53095. ! (flatOnRight || flatOnTop),
  53096. ! (flatOnLeft || flatOnBottom),
  53097. ! (flatOnRight || flatOnBottom));
  53098. ColourGradient cg (baseColour, 0.0f, y,
  53099. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53100. false);
  53101. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53102. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53103. g.setGradientFill (cg);
  53104. g.fillPath (outline);
  53105. g.setColour (Colour (0x80000000));
  53106. g.strokePath (outline, PathStrokeType (strokeWidth));
  53107. }
  53108. void LookAndFeel::drawGlassSphere (Graphics& g,
  53109. const float x, const float y,
  53110. const float diameter,
  53111. const Colour& colour,
  53112. const float outlineThickness) throw()
  53113. {
  53114. if (diameter <= outlineThickness)
  53115. return;
  53116. Path p;
  53117. p.addEllipse (x, y, diameter, diameter);
  53118. {
  53119. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53120. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53121. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53122. g.setGradientFill (cg);
  53123. g.fillPath (p);
  53124. }
  53125. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53126. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53127. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53128. ColourGradient cg (Colours::transparentBlack,
  53129. x + diameter * 0.5f, y + diameter * 0.5f,
  53130. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53131. x, y + diameter * 0.5f, true);
  53132. cg.addColour (0.7, Colours::transparentBlack);
  53133. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53134. g.setGradientFill (cg);
  53135. g.fillPath (p);
  53136. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53137. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53138. }
  53139. void LookAndFeel::drawGlassPointer (Graphics& g,
  53140. const float x, const float y,
  53141. const float diameter,
  53142. const Colour& colour, const float outlineThickness,
  53143. const int direction) throw()
  53144. {
  53145. if (diameter <= outlineThickness)
  53146. return;
  53147. Path p;
  53148. p.startNewSubPath (x + diameter * 0.5f, y);
  53149. p.lineTo (x + diameter, y + diameter * 0.6f);
  53150. p.lineTo (x + diameter, y + diameter);
  53151. p.lineTo (x, y + diameter);
  53152. p.lineTo (x, y + diameter * 0.6f);
  53153. p.closeSubPath();
  53154. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53155. {
  53156. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53157. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53158. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53159. g.setGradientFill (cg);
  53160. g.fillPath (p);
  53161. }
  53162. ColourGradient cg (Colours::transparentBlack,
  53163. x + diameter * 0.5f, y + diameter * 0.5f,
  53164. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53165. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53166. cg.addColour (0.5, Colours::transparentBlack);
  53167. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53168. g.setGradientFill (cg);
  53169. g.fillPath (p);
  53170. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53171. g.strokePath (p, PathStrokeType (outlineThickness));
  53172. }
  53173. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53174. const float x, const float y,
  53175. const float width, const float height,
  53176. const Colour& colour,
  53177. const float outlineThickness,
  53178. const float cornerSize,
  53179. const bool flatOnLeft,
  53180. const bool flatOnRight,
  53181. const bool flatOnTop,
  53182. const bool flatOnBottom) throw()
  53183. {
  53184. if (width <= outlineThickness || height <= outlineThickness)
  53185. return;
  53186. const int intX = (int) x;
  53187. const int intY = (int) y;
  53188. const int intW = (int) width;
  53189. const int intH = (int) height;
  53190. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53191. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53192. const int intEdge = (int) edgeBlurRadius;
  53193. Path outline;
  53194. createRoundedPath (outline, x, y, width, height, cs,
  53195. ! (flatOnLeft || flatOnTop),
  53196. ! (flatOnRight || flatOnTop),
  53197. ! (flatOnLeft || flatOnBottom),
  53198. ! (flatOnRight || flatOnBottom));
  53199. {
  53200. ColourGradient cg (colour.darker (0.2f), 0, y,
  53201. colour.darker (0.2f), 0, y + height, false);
  53202. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53203. cg.addColour (0.4, colour);
  53204. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53205. g.setGradientFill (cg);
  53206. g.fillPath (outline);
  53207. }
  53208. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53209. colour.darker (0.2f), x, y + height * 0.5f, true);
  53210. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53211. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53212. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53213. {
  53214. g.saveState();
  53215. g.setGradientFill (cg);
  53216. g.reduceClipRegion (intX, intY, intEdge, intH);
  53217. g.fillPath (outline);
  53218. g.restoreState();
  53219. }
  53220. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53221. {
  53222. cg.x1 = x + width - edgeBlurRadius;
  53223. cg.x2 = x + width;
  53224. g.saveState();
  53225. g.setGradientFill (cg);
  53226. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53227. g.fillPath (outline);
  53228. g.restoreState();
  53229. }
  53230. {
  53231. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53232. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53233. Path highlight;
  53234. createRoundedPath (highlight,
  53235. x + leftIndent,
  53236. y + cs * 0.1f,
  53237. width - (leftIndent + rightIndent),
  53238. height * 0.4f, cs * 0.4f,
  53239. ! (flatOnLeft || flatOnTop),
  53240. ! (flatOnRight || flatOnTop),
  53241. ! (flatOnLeft || flatOnBottom),
  53242. ! (flatOnRight || flatOnBottom));
  53243. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53244. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53245. g.fillPath (highlight);
  53246. }
  53247. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53248. g.strokePath (outline, PathStrokeType (outlineThickness));
  53249. }
  53250. END_JUCE_NAMESPACE
  53251. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53252. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53253. BEGIN_JUCE_NAMESPACE
  53254. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53255. {
  53256. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53257. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53258. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53259. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53260. setColour (Slider::thumbColourId, Colours::white);
  53261. setColour (Slider::trackColourId, Colour (0x7f000000));
  53262. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53263. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53264. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53265. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53266. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53267. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53268. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53269. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53270. }
  53271. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53272. {
  53273. }
  53274. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53275. Button& button,
  53276. const Colour& backgroundColour,
  53277. bool isMouseOverButton,
  53278. bool isButtonDown)
  53279. {
  53280. const int width = button.getWidth();
  53281. const int height = button.getHeight();
  53282. const float indent = 2.0f;
  53283. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53284. roundToInt (height * 0.4f));
  53285. Path p;
  53286. p.addRoundedRectangle (indent, indent,
  53287. width - indent * 2.0f,
  53288. height - indent * 2.0f,
  53289. (float) cornerSize);
  53290. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53291. if (isMouseOverButton)
  53292. {
  53293. if (isButtonDown)
  53294. bc = bc.brighter();
  53295. else if (bc.getBrightness() > 0.5f)
  53296. bc = bc.darker (0.1f);
  53297. else
  53298. bc = bc.brighter (0.1f);
  53299. }
  53300. g.setColour (bc);
  53301. g.fillPath (p);
  53302. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53303. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53304. }
  53305. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53306. Component& /*component*/,
  53307. float x, float y, float w, float h,
  53308. const bool ticked,
  53309. const bool isEnabled,
  53310. const bool /*isMouseOverButton*/,
  53311. const bool isButtonDown)
  53312. {
  53313. Path box;
  53314. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53315. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53316. : Colours::lightgrey.withAlpha (0.1f));
  53317. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53318. g.fillPath (box, trans);
  53319. g.setColour (Colours::black.withAlpha (0.6f));
  53320. g.strokePath (box, PathStrokeType (0.9f), trans);
  53321. if (ticked)
  53322. {
  53323. Path tick;
  53324. tick.startNewSubPath (1.5f, 3.0f);
  53325. tick.lineTo (3.0f, 6.0f);
  53326. tick.lineTo (6.0f, 0.0f);
  53327. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53328. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53329. }
  53330. }
  53331. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53332. ToggleButton& button,
  53333. bool isMouseOverButton,
  53334. bool isButtonDown)
  53335. {
  53336. if (button.hasKeyboardFocus (true))
  53337. {
  53338. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53339. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53340. }
  53341. const int tickWidth = jmin (20, button.getHeight() - 4);
  53342. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53343. (float) tickWidth, (float) tickWidth,
  53344. button.getToggleState(),
  53345. button.isEnabled(),
  53346. isMouseOverButton,
  53347. isButtonDown);
  53348. g.setColour (button.findColour (ToggleButton::textColourId));
  53349. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53350. if (! button.isEnabled())
  53351. g.setOpacity (0.5f);
  53352. const int textX = tickWidth + 5;
  53353. g.drawFittedText (button.getButtonText(),
  53354. textX, 4,
  53355. button.getWidth() - textX - 2, button.getHeight() - 8,
  53356. Justification::centredLeft, 10);
  53357. }
  53358. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53359. int width, int height,
  53360. double progress, const String& textToShow)
  53361. {
  53362. if (progress < 0 || progress >= 1.0)
  53363. {
  53364. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53365. }
  53366. else
  53367. {
  53368. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53369. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53370. g.fillAll (background);
  53371. g.setColour (foreground);
  53372. g.fillRect (1, 1,
  53373. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53374. height - 2);
  53375. if (textToShow.isNotEmpty())
  53376. {
  53377. g.setColour (Colour::contrasting (background, foreground));
  53378. g.setFont (height * 0.6f);
  53379. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53380. }
  53381. }
  53382. }
  53383. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53384. ScrollBar& bar,
  53385. int width, int height,
  53386. int buttonDirection,
  53387. bool isScrollbarVertical,
  53388. bool isMouseOverButton,
  53389. bool isButtonDown)
  53390. {
  53391. if (isScrollbarVertical)
  53392. width -= 2;
  53393. else
  53394. height -= 2;
  53395. Path p;
  53396. if (buttonDirection == 0)
  53397. p.addTriangle (width * 0.5f, height * 0.2f,
  53398. width * 0.1f, height * 0.7f,
  53399. width * 0.9f, height * 0.7f);
  53400. else if (buttonDirection == 1)
  53401. p.addTriangle (width * 0.8f, height * 0.5f,
  53402. width * 0.3f, height * 0.1f,
  53403. width * 0.3f, height * 0.9f);
  53404. else if (buttonDirection == 2)
  53405. p.addTriangle (width * 0.5f, height * 0.8f,
  53406. width * 0.1f, height * 0.3f,
  53407. width * 0.9f, height * 0.3f);
  53408. else if (buttonDirection == 3)
  53409. p.addTriangle (width * 0.2f, height * 0.5f,
  53410. width * 0.7f, height * 0.1f,
  53411. width * 0.7f, height * 0.9f);
  53412. if (isButtonDown)
  53413. g.setColour (Colours::white);
  53414. else if (isMouseOverButton)
  53415. g.setColour (Colours::white.withAlpha (0.7f));
  53416. else
  53417. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53418. g.fillPath (p);
  53419. g.setColour (Colours::black.withAlpha (0.5f));
  53420. g.strokePath (p, PathStrokeType (0.5f));
  53421. }
  53422. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53423. ScrollBar& bar,
  53424. int x, int y,
  53425. int width, int height,
  53426. bool isScrollbarVertical,
  53427. int thumbStartPosition,
  53428. int thumbSize,
  53429. bool isMouseOver,
  53430. bool isMouseDown)
  53431. {
  53432. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53433. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53434. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53435. if (thumbSize > 0.0f)
  53436. {
  53437. Rectangle<int> thumb;
  53438. if (isScrollbarVertical)
  53439. {
  53440. width -= 2;
  53441. g.fillRect (x + roundToInt (width * 0.35f), y,
  53442. roundToInt (width * 0.3f), height);
  53443. thumb.setBounds (x + 1, thumbStartPosition,
  53444. width - 2, thumbSize);
  53445. }
  53446. else
  53447. {
  53448. height -= 2;
  53449. g.fillRect (x, y + roundToInt (height * 0.35f),
  53450. width, roundToInt (height * 0.3f));
  53451. thumb.setBounds (thumbStartPosition, y + 1,
  53452. thumbSize, height - 2);
  53453. }
  53454. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53455. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53456. g.fillRect (thumb);
  53457. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53458. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53459. if (thumbSize > 16)
  53460. {
  53461. for (int i = 3; --i >= 0;)
  53462. {
  53463. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53464. g.setColour (Colours::black.withAlpha (0.15f));
  53465. if (isScrollbarVertical)
  53466. {
  53467. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53468. g.setColour (Colours::white.withAlpha (0.15f));
  53469. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53470. }
  53471. else
  53472. {
  53473. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53474. g.setColour (Colours::white.withAlpha (0.15f));
  53475. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53476. }
  53477. }
  53478. }
  53479. }
  53480. }
  53481. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53482. {
  53483. return &scrollbarShadow;
  53484. }
  53485. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53486. {
  53487. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53488. g.setColour (Colours::black.withAlpha (0.6f));
  53489. g.drawRect (0, 0, width, height);
  53490. }
  53491. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53492. bool, MenuBarComponent& menuBar)
  53493. {
  53494. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53495. }
  53496. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53497. {
  53498. if (textEditor.isEnabled())
  53499. {
  53500. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53501. g.drawRect (0, 0, width, height);
  53502. }
  53503. }
  53504. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53505. const bool isButtonDown,
  53506. int buttonX, int buttonY,
  53507. int buttonW, int buttonH,
  53508. ComboBox& box)
  53509. {
  53510. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53511. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53512. : ComboBox::backgroundColourId));
  53513. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53514. g.setColour (box.findColour (ComboBox::outlineColourId));
  53515. g.drawRect (0, 0, width, height);
  53516. const float arrowX = 0.2f;
  53517. const float arrowH = 0.3f;
  53518. if (box.isEnabled())
  53519. {
  53520. Path p;
  53521. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53522. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53523. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53524. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53525. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53526. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53527. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53528. : ComboBox::buttonColourId));
  53529. g.fillPath (p);
  53530. }
  53531. }
  53532. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53533. {
  53534. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53535. f.setHorizontalScale (0.9f);
  53536. return f;
  53537. }
  53538. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53539. {
  53540. Path p;
  53541. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53542. g.setColour (fill);
  53543. g.fillPath (p);
  53544. g.setColour (outline);
  53545. g.strokePath (p, PathStrokeType (0.3f));
  53546. }
  53547. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53548. int x, int y,
  53549. int w, int h,
  53550. float sliderPos,
  53551. float minSliderPos,
  53552. float maxSliderPos,
  53553. const Slider::SliderStyle style,
  53554. Slider& slider)
  53555. {
  53556. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53557. if (style == Slider::LinearBar)
  53558. {
  53559. g.setColour (slider.findColour (Slider::thumbColourId));
  53560. g.fillRect (x, y, (int) sliderPos - x, h);
  53561. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53562. g.drawRect (x, y, (int) sliderPos - x, h);
  53563. }
  53564. else
  53565. {
  53566. g.setColour (slider.findColour (Slider::trackColourId)
  53567. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53568. if (slider.isHorizontal())
  53569. {
  53570. g.fillRect (x, y + roundToInt (h * 0.6f),
  53571. w, roundToInt (h * 0.2f));
  53572. }
  53573. else
  53574. {
  53575. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53576. jmin (4, roundToInt (w * 0.2f)), h);
  53577. }
  53578. float alpha = 0.35f;
  53579. if (slider.isEnabled())
  53580. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53581. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53582. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53583. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53584. {
  53585. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53586. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53587. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53588. fill, outline);
  53589. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53590. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53591. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53592. fill, outline);
  53593. }
  53594. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53595. {
  53596. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53597. minSliderPos - 7.0f, y + h * 0.9f ,
  53598. minSliderPos, y + h * 0.9f,
  53599. fill, outline);
  53600. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53601. maxSliderPos, y + h * 0.9f,
  53602. maxSliderPos + 7.0f, y + h * 0.9f,
  53603. fill, outline);
  53604. }
  53605. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53606. {
  53607. drawTriangle (g, sliderPos, y + h * 0.9f,
  53608. sliderPos - 7.0f, y + h * 0.2f,
  53609. sliderPos + 7.0f, y + h * 0.2f,
  53610. fill, outline);
  53611. }
  53612. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53613. {
  53614. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53615. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53616. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53617. fill, outline);
  53618. }
  53619. }
  53620. }
  53621. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53622. {
  53623. if (isIncrement)
  53624. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53625. else
  53626. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53627. }
  53628. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53629. {
  53630. return &scrollbarShadow;
  53631. }
  53632. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53633. {
  53634. return 8;
  53635. }
  53636. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53637. int w, int h,
  53638. bool isMouseOver,
  53639. bool isMouseDragging)
  53640. {
  53641. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53642. : Colours::darkgrey);
  53643. const float lineThickness = jmin (w, h) * 0.1f;
  53644. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53645. {
  53646. g.drawLine (w * i,
  53647. h + 1.0f,
  53648. w + 1.0f,
  53649. h * i,
  53650. lineThickness);
  53651. }
  53652. }
  53653. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53654. {
  53655. Path shape;
  53656. if (buttonType == DocumentWindow::closeButton)
  53657. {
  53658. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53659. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53660. ShapeButton* const b = new ShapeButton ("close",
  53661. Colour (0x7fff3333),
  53662. Colour (0xd7ff3333),
  53663. Colour (0xf7ff3333));
  53664. b->setShape (shape, true, true, true);
  53665. return b;
  53666. }
  53667. else if (buttonType == DocumentWindow::minimiseButton)
  53668. {
  53669. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53670. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53671. DrawablePath dp;
  53672. dp.setPath (shape);
  53673. dp.setFill (Colours::black.withAlpha (0.3f));
  53674. b->setImages (&dp);
  53675. return b;
  53676. }
  53677. else if (buttonType == DocumentWindow::maximiseButton)
  53678. {
  53679. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53680. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53681. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53682. DrawablePath dp;
  53683. dp.setPath (shape);
  53684. dp.setFill (Colours::black.withAlpha (0.3f));
  53685. b->setImages (&dp);
  53686. return b;
  53687. }
  53688. jassertfalse
  53689. return 0;
  53690. }
  53691. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53692. int titleBarX,
  53693. int titleBarY,
  53694. int titleBarW,
  53695. int titleBarH,
  53696. Button* minimiseButton,
  53697. Button* maximiseButton,
  53698. Button* closeButton,
  53699. bool positionTitleBarButtonsOnLeft)
  53700. {
  53701. titleBarY += titleBarH / 8;
  53702. titleBarH -= titleBarH / 4;
  53703. const int buttonW = titleBarH;
  53704. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53705. : titleBarX + titleBarW - buttonW - 4;
  53706. if (closeButton != 0)
  53707. {
  53708. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53709. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53710. : -(buttonW + buttonW / 5);
  53711. }
  53712. if (positionTitleBarButtonsOnLeft)
  53713. swapVariables (minimiseButton, maximiseButton);
  53714. if (maximiseButton != 0)
  53715. {
  53716. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53717. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53718. }
  53719. if (minimiseButton != 0)
  53720. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53721. }
  53722. END_JUCE_NAMESPACE
  53723. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53724. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53725. BEGIN_JUCE_NAMESPACE
  53726. class DummyMenuComponent : public Component
  53727. {
  53728. DummyMenuComponent (const DummyMenuComponent&);
  53729. DummyMenuComponent& operator= (const DummyMenuComponent&);
  53730. public:
  53731. DummyMenuComponent() {}
  53732. ~DummyMenuComponent() {}
  53733. void inputAttemptWhenModal()
  53734. {
  53735. exitModalState (0);
  53736. }
  53737. };
  53738. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  53739. : model (0),
  53740. itemUnderMouse (-1),
  53741. currentPopupIndex (-1),
  53742. indexToShowAgain (-1),
  53743. lastMouseX (0),
  53744. lastMouseY (0),
  53745. inModalState (false)
  53746. {
  53747. setRepaintsOnMouseActivity (true);
  53748. setWantsKeyboardFocus (false);
  53749. setMouseClickGrabsKeyboardFocus (false);
  53750. setModel (model_);
  53751. }
  53752. MenuBarComponent::~MenuBarComponent()
  53753. {
  53754. setModel (0);
  53755. Desktop::getInstance().removeGlobalMouseListener (this);
  53756. currentPopup = 0;
  53757. }
  53758. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  53759. {
  53760. if (model != newModel)
  53761. {
  53762. if (model != 0)
  53763. model->removeListener (this);
  53764. model = newModel;
  53765. if (model != 0)
  53766. model->addListener (this);
  53767. repaint();
  53768. menuBarItemsChanged (0);
  53769. }
  53770. }
  53771. void MenuBarComponent::paint (Graphics& g)
  53772. {
  53773. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  53774. getLookAndFeel().drawMenuBarBackground (g,
  53775. getWidth(),
  53776. getHeight(),
  53777. isMouseOverBar,
  53778. *this);
  53779. if (model != 0)
  53780. {
  53781. for (int i = 0; i < menuNames.size(); ++i)
  53782. {
  53783. g.saveState();
  53784. g.setOrigin (xPositions [i], 0);
  53785. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  53786. getLookAndFeel().drawMenuBarItem (g,
  53787. xPositions[i + 1] - xPositions[i],
  53788. getHeight(),
  53789. i,
  53790. menuNames[i],
  53791. i == itemUnderMouse,
  53792. i == currentPopupIndex,
  53793. isMouseOverBar,
  53794. *this);
  53795. g.restoreState();
  53796. }
  53797. }
  53798. }
  53799. void MenuBarComponent::resized()
  53800. {
  53801. xPositions.clear();
  53802. int x = 2;
  53803. xPositions.add (x);
  53804. for (int i = 0; i < menuNames.size(); ++i)
  53805. {
  53806. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  53807. xPositions.add (x);
  53808. }
  53809. }
  53810. int MenuBarComponent::getItemAt (const int x, const int y)
  53811. {
  53812. for (int i = 0; i < xPositions.size(); ++i)
  53813. if (x >= xPositions[i] && x < xPositions[i + 1])
  53814. return reallyContains (x, y, true) ? i : -1;
  53815. return -1;
  53816. }
  53817. void MenuBarComponent::repaintMenuItem (int index)
  53818. {
  53819. if (((unsigned int) index) < (unsigned int) xPositions.size())
  53820. {
  53821. const int x1 = xPositions [index];
  53822. const int x2 = xPositions [index + 1];
  53823. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  53824. }
  53825. }
  53826. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  53827. {
  53828. const int newItem = getItemAt (x, y);
  53829. if (itemUnderMouse != newItem)
  53830. {
  53831. repaintMenuItem (itemUnderMouse);
  53832. itemUnderMouse = newItem;
  53833. repaintMenuItem (itemUnderMouse);
  53834. }
  53835. }
  53836. void MenuBarComponent::hideCurrentMenu()
  53837. {
  53838. currentPopup = 0;
  53839. repaint();
  53840. }
  53841. void MenuBarComponent::showMenu (int index)
  53842. {
  53843. if (index != currentPopupIndex)
  53844. {
  53845. if (inModalState)
  53846. {
  53847. hideCurrentMenu();
  53848. indexToShowAgain = index;
  53849. return;
  53850. }
  53851. indexToShowAgain = -1;
  53852. currentPopupIndex = -1;
  53853. itemUnderMouse = index;
  53854. currentPopup = 0;
  53855. menuBarItemsChanged (0);
  53856. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  53857. Component::SafePointer<Component> deletionChecker (this);
  53858. enterModalState (false);
  53859. inModalState = true;
  53860. int result = 0;
  53861. ApplicationCommandManager* managerOfChosenCommand = 0;
  53862. Desktop::getInstance().addGlobalMouseListener (this);
  53863. for (;;)
  53864. {
  53865. const int x = getScreenX() + xPositions [itemUnderMouse];
  53866. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  53867. currentPopupIndex = itemUnderMouse;
  53868. indexToShowAgain = -1;
  53869. repaint();
  53870. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  53871. {
  53872. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  53873. menuNames [itemUnderMouse]));
  53874. if (m.lookAndFeel == 0)
  53875. m.setLookAndFeel (&getLookAndFeel());
  53876. currentPopup = m.createMenuComponent (x, getScreenY(),
  53877. w, getHeight(),
  53878. 0, w, 0, 0,
  53879. true, this,
  53880. &managerOfChosenCommand,
  53881. this);
  53882. }
  53883. if (currentPopup == 0)
  53884. {
  53885. currentPopup = new DummyMenuComponent();
  53886. addAndMakeVisible (currentPopup);
  53887. }
  53888. currentPopup->enterModalState (false);
  53889. currentPopup->toFront (false); // need to do this after making it modal, or it could
  53890. // be stuck behind other comps that are already modal..
  53891. result = currentPopup->runModalLoop();
  53892. if (deletionChecker == 0)
  53893. return;
  53894. const int lastPopupIndex = currentPopupIndex;
  53895. currentPopup = 0;
  53896. currentPopupIndex = -1;
  53897. if (result != 0)
  53898. {
  53899. topLevelIndexClicked = lastPopupIndex;
  53900. break;
  53901. }
  53902. else if (indexToShowAgain >= 0)
  53903. {
  53904. menuBarItemsChanged (0);
  53905. repaint();
  53906. itemUnderMouse = indexToShowAgain;
  53907. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  53908. break;
  53909. }
  53910. else
  53911. {
  53912. break;
  53913. }
  53914. }
  53915. Desktop::getInstance().removeGlobalMouseListener (this);
  53916. inModalState = false;
  53917. exitModalState (0);
  53918. if (prevFocused != 0)
  53919. prevFocused->grabKeyboardFocus();
  53920. const Point<int> mousePos (getMouseXYRelative());
  53921. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  53922. repaint();
  53923. if (result != 0)
  53924. {
  53925. if (managerOfChosenCommand != 0)
  53926. {
  53927. ApplicationCommandTarget::InvocationInfo info (result);
  53928. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  53929. managerOfChosenCommand->invoke (info, true);
  53930. }
  53931. postCommandMessage (result);
  53932. }
  53933. }
  53934. }
  53935. void MenuBarComponent::handleCommandMessage (int commandId)
  53936. {
  53937. if (model != 0)
  53938. model->menuItemSelected (commandId, topLevelIndexClicked);
  53939. }
  53940. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  53941. {
  53942. if (e.eventComponent == this)
  53943. updateItemUnderMouse (e.x, e.y);
  53944. }
  53945. void MenuBarComponent::mouseExit (const MouseEvent& e)
  53946. {
  53947. if (e.eventComponent == this)
  53948. updateItemUnderMouse (e.x, e.y);
  53949. }
  53950. void MenuBarComponent::mouseDown (const MouseEvent& e)
  53951. {
  53952. if (currentPopupIndex < 0)
  53953. {
  53954. const MouseEvent e2 (e.getEventRelativeTo (this));
  53955. updateItemUnderMouse (e2.x, e2.y);
  53956. currentPopupIndex = -2;
  53957. showMenu (itemUnderMouse);
  53958. }
  53959. }
  53960. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  53961. {
  53962. const MouseEvent e2 (e.getEventRelativeTo (this));
  53963. const int item = getItemAt (e2.x, e2.y);
  53964. if (item >= 0)
  53965. showMenu (item);
  53966. }
  53967. void MenuBarComponent::mouseUp (const MouseEvent& e)
  53968. {
  53969. const MouseEvent e2 (e.getEventRelativeTo (this));
  53970. updateItemUnderMouse (e2.x, e2.y);
  53971. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> (static_cast <Component*> (currentPopup)) != 0)
  53972. hideCurrentMenu();
  53973. }
  53974. void MenuBarComponent::mouseMove (const MouseEvent& e)
  53975. {
  53976. const MouseEvent e2 (e.getEventRelativeTo (this));
  53977. if (lastMouseX != e2.x || lastMouseY != e2.y)
  53978. {
  53979. if (currentPopupIndex >= 0)
  53980. {
  53981. const int item = getItemAt (e2.x, e2.y);
  53982. if (item >= 0)
  53983. showMenu (item);
  53984. }
  53985. else
  53986. {
  53987. updateItemUnderMouse (e2.x, e2.y);
  53988. }
  53989. lastMouseX = e2.x;
  53990. lastMouseY = e2.y;
  53991. }
  53992. }
  53993. bool MenuBarComponent::keyPressed (const KeyPress& key)
  53994. {
  53995. bool used = false;
  53996. const int numMenus = menuNames.size();
  53997. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  53998. if (key.isKeyCode (KeyPress::leftKey))
  53999. {
  54000. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54001. used = true;
  54002. }
  54003. else if (key.isKeyCode (KeyPress::rightKey))
  54004. {
  54005. showMenu ((currentIndex + 1) % numMenus);
  54006. used = true;
  54007. }
  54008. return used;
  54009. }
  54010. void MenuBarComponent::inputAttemptWhenModal()
  54011. {
  54012. hideCurrentMenu();
  54013. }
  54014. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54015. {
  54016. StringArray newNames;
  54017. if (model != 0)
  54018. newNames = model->getMenuBarNames();
  54019. if (newNames != menuNames)
  54020. {
  54021. menuNames = newNames;
  54022. repaint();
  54023. resized();
  54024. }
  54025. }
  54026. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54027. const ApplicationCommandTarget::InvocationInfo& info)
  54028. {
  54029. if (model == 0
  54030. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54031. return;
  54032. for (int i = 0; i < menuNames.size(); ++i)
  54033. {
  54034. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54035. if (menu.containsCommandItem (info.commandID))
  54036. {
  54037. itemUnderMouse = i;
  54038. repaintMenuItem (i);
  54039. startTimer (200);
  54040. break;
  54041. }
  54042. }
  54043. }
  54044. void MenuBarComponent::timerCallback()
  54045. {
  54046. stopTimer();
  54047. const Point<int> mousePos (getMouseXYRelative());
  54048. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54049. }
  54050. END_JUCE_NAMESPACE
  54051. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54052. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54053. BEGIN_JUCE_NAMESPACE
  54054. MenuBarModel::MenuBarModel() throw()
  54055. : manager (0)
  54056. {
  54057. }
  54058. MenuBarModel::~MenuBarModel()
  54059. {
  54060. setApplicationCommandManagerToWatch (0);
  54061. }
  54062. void MenuBarModel::menuItemsChanged()
  54063. {
  54064. triggerAsyncUpdate();
  54065. }
  54066. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54067. {
  54068. if (manager != newManager)
  54069. {
  54070. if (manager != 0)
  54071. manager->removeListener (this);
  54072. manager = newManager;
  54073. if (manager != 0)
  54074. manager->addListener (this);
  54075. }
  54076. }
  54077. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54078. {
  54079. listeners.add (newListener);
  54080. }
  54081. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54082. {
  54083. // Trying to remove a listener that isn't on the list!
  54084. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54085. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54086. jassert (listeners.contains (listenerToRemove));
  54087. listeners.remove (listenerToRemove);
  54088. }
  54089. void MenuBarModel::handleAsyncUpdate()
  54090. {
  54091. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54092. }
  54093. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54094. {
  54095. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54096. }
  54097. void MenuBarModel::applicationCommandListChanged()
  54098. {
  54099. menuItemsChanged();
  54100. }
  54101. END_JUCE_NAMESPACE
  54102. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54103. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54104. BEGIN_JUCE_NAMESPACE
  54105. class PopupMenu::Item
  54106. {
  54107. public:
  54108. Item()
  54109. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54110. usesColour (false), customComp (0), commandManager (0)
  54111. {
  54112. }
  54113. Item (const int itemId_,
  54114. const String& text_,
  54115. const bool active_,
  54116. const bool isTicked_,
  54117. const Image* im,
  54118. const Colour& textColour_,
  54119. const bool usesColour_,
  54120. PopupMenuCustomComponent* const customComp_,
  54121. const PopupMenu* const subMenu_,
  54122. ApplicationCommandManager* const commandManager_)
  54123. : itemId (itemId_), text (text_), textColour (textColour_),
  54124. active (active_), isSeparator (false), isTicked (isTicked_),
  54125. usesColour (usesColour_), customComp (customComp_),
  54126. commandManager (commandManager_)
  54127. {
  54128. if (subMenu_ != 0)
  54129. subMenu = new PopupMenu (*subMenu_);
  54130. if (im != 0)
  54131. image = im->createCopy();
  54132. if (commandManager_ != 0 && itemId_ != 0)
  54133. {
  54134. String shortcutKey;
  54135. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54136. ->getKeyPressesAssignedToCommand (itemId_));
  54137. for (int i = 0; i < keyPresses.size(); ++i)
  54138. {
  54139. const String key (keyPresses.getReference(i).getTextDescription());
  54140. if (shortcutKey.isNotEmpty())
  54141. shortcutKey << ", ";
  54142. if (key.length() == 1)
  54143. shortcutKey << "shortcut: '" << key << '\'';
  54144. else
  54145. shortcutKey << key;
  54146. }
  54147. shortcutKey = shortcutKey.trim();
  54148. if (shortcutKey.isNotEmpty())
  54149. text << "<end>" << shortcutKey;
  54150. }
  54151. }
  54152. Item (const Item& other)
  54153. : itemId (other.itemId),
  54154. text (other.text),
  54155. textColour (other.textColour),
  54156. active (other.active),
  54157. isSeparator (other.isSeparator),
  54158. isTicked (other.isTicked),
  54159. usesColour (other.usesColour),
  54160. customComp (other.customComp),
  54161. commandManager (other.commandManager)
  54162. {
  54163. if (other.subMenu != 0)
  54164. subMenu = new PopupMenu (*(other.subMenu));
  54165. if (other.image != 0)
  54166. image = other.image->createCopy();
  54167. }
  54168. ~Item()
  54169. {
  54170. customComp = 0;
  54171. }
  54172. bool canBeTriggered() const throw()
  54173. {
  54174. return active && ! (isSeparator || (subMenu != 0));
  54175. }
  54176. bool hasActiveSubMenu() const throw()
  54177. {
  54178. return active && (subMenu != 0);
  54179. }
  54180. const int itemId;
  54181. String text;
  54182. const Colour textColour;
  54183. const bool active, isSeparator, isTicked, usesColour;
  54184. ScopedPointer <Image> image;
  54185. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54186. ScopedPointer <PopupMenu> subMenu;
  54187. ApplicationCommandManager* const commandManager;
  54188. juce_UseDebuggingNewOperator
  54189. private:
  54190. Item& operator= (const Item&);
  54191. };
  54192. class PopupMenu::ItemComponent : public Component
  54193. {
  54194. public:
  54195. ItemComponent (const PopupMenu::Item& itemInfo_)
  54196. : itemInfo (itemInfo_),
  54197. isHighlighted (false)
  54198. {
  54199. if (itemInfo.customComp != 0)
  54200. addAndMakeVisible (itemInfo.customComp);
  54201. }
  54202. ~ItemComponent()
  54203. {
  54204. if (itemInfo.customComp != 0)
  54205. removeChildComponent (itemInfo.customComp);
  54206. }
  54207. void getIdealSize (int& idealWidth,
  54208. int& idealHeight,
  54209. const int standardItemHeight)
  54210. {
  54211. if (itemInfo.customComp != 0)
  54212. {
  54213. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54214. }
  54215. else
  54216. {
  54217. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54218. itemInfo.isSeparator,
  54219. standardItemHeight,
  54220. idealWidth,
  54221. idealHeight);
  54222. }
  54223. }
  54224. void paint (Graphics& g)
  54225. {
  54226. if (itemInfo.customComp == 0)
  54227. {
  54228. String mainText (itemInfo.text);
  54229. String endText;
  54230. const int endIndex = mainText.indexOf ("<end>");
  54231. if (endIndex >= 0)
  54232. {
  54233. endText = mainText.substring (endIndex + 5).trim();
  54234. mainText = mainText.substring (0, endIndex);
  54235. }
  54236. getLookAndFeel()
  54237. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54238. itemInfo.isSeparator,
  54239. itemInfo.active,
  54240. isHighlighted,
  54241. itemInfo.isTicked,
  54242. itemInfo.subMenu != 0,
  54243. mainText, endText,
  54244. itemInfo.image,
  54245. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54246. }
  54247. }
  54248. void resized()
  54249. {
  54250. if (getNumChildComponents() > 0)
  54251. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54252. }
  54253. void setHighlighted (bool shouldBeHighlighted)
  54254. {
  54255. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54256. if (isHighlighted != shouldBeHighlighted)
  54257. {
  54258. isHighlighted = shouldBeHighlighted;
  54259. if (itemInfo.customComp != 0)
  54260. {
  54261. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54262. itemInfo.customComp->repaint();
  54263. }
  54264. repaint();
  54265. }
  54266. }
  54267. PopupMenu::Item itemInfo;
  54268. juce_UseDebuggingNewOperator
  54269. private:
  54270. bool isHighlighted;
  54271. ItemComponent (const ItemComponent&);
  54272. ItemComponent& operator= (const ItemComponent&);
  54273. };
  54274. namespace PopupMenuSettings
  54275. {
  54276. static const int scrollZone = 24;
  54277. static const int borderSize = 2;
  54278. static const int timerInterval = 50;
  54279. static const int dismissCommandId = 0x6287345f;
  54280. }
  54281. class PopupMenu::Window : public Component,
  54282. private Timer
  54283. {
  54284. public:
  54285. Window()
  54286. : Component ("menu"),
  54287. owner (0),
  54288. currentChild (0),
  54289. activeSubMenu (0),
  54290. menuBarComponent (0),
  54291. managerOfChosenCommand (0),
  54292. minimumWidth (0),
  54293. maximumNumColumns (7),
  54294. standardItemHeight (0),
  54295. isOver (false),
  54296. hasBeenOver (false),
  54297. isDown (false),
  54298. needsToScroll (false),
  54299. hideOnExit (false),
  54300. disableMouseMoves (false),
  54301. hasAnyJuceCompHadFocus (false),
  54302. numColumns (0),
  54303. contentHeight (0),
  54304. childYOffset (0),
  54305. timeEnteredCurrentChildComp (0),
  54306. scrollAcceleration (1.0)
  54307. {
  54308. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54309. setWantsKeyboardFocus (true);
  54310. setMouseClickGrabsKeyboardFocus (false);
  54311. setOpaque (true);
  54312. setAlwaysOnTop (true);
  54313. Desktop::getInstance().addGlobalMouseListener (this);
  54314. getActiveWindows().add (this);
  54315. }
  54316. ~Window()
  54317. {
  54318. getActiveWindows().removeValue (this);
  54319. Desktop::getInstance().removeGlobalMouseListener (this);
  54320. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54321. activeSubMenu = 0;
  54322. deleteAllChildren();
  54323. }
  54324. static Window* create (const PopupMenu& menu,
  54325. const bool dismissOnMouseUp,
  54326. Window* const owner_,
  54327. const int minX, const int maxX,
  54328. const int minY, const int maxY,
  54329. const int minimumWidth,
  54330. const int maximumNumColumns,
  54331. const int standardItemHeight,
  54332. const bool alignToRectangle,
  54333. const int itemIdThatMustBeVisible,
  54334. Component* const menuBarComponent,
  54335. ApplicationCommandManager** managerOfChosenCommand,
  54336. Component* const componentAttachedTo)
  54337. {
  54338. if (menu.items.size() > 0)
  54339. {
  54340. int totalItems = 0;
  54341. ScopedPointer <Window> mw (new Window());
  54342. mw->setLookAndFeel (menu.lookAndFeel);
  54343. mw->setWantsKeyboardFocus (false);
  54344. mw->minimumWidth = minimumWidth;
  54345. mw->maximumNumColumns = maximumNumColumns;
  54346. mw->standardItemHeight = standardItemHeight;
  54347. mw->dismissOnMouseUp = dismissOnMouseUp;
  54348. for (int i = 0; i < menu.items.size(); ++i)
  54349. {
  54350. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54351. mw->addItem (*item);
  54352. ++totalItems;
  54353. }
  54354. if (totalItems > 0)
  54355. {
  54356. mw->owner = owner_;
  54357. mw->menuBarComponent = menuBarComponent;
  54358. mw->managerOfChosenCommand = managerOfChosenCommand;
  54359. mw->componentAttachedTo = componentAttachedTo;
  54360. mw->componentAttachedToOriginal = componentAttachedTo;
  54361. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54362. mw->setTopLeftPosition (mw->windowPos.getX(),
  54363. mw->windowPos.getY());
  54364. mw->updateYPositions();
  54365. if (itemIdThatMustBeVisible != 0)
  54366. {
  54367. const int y = minY - mw->windowPos.getY();
  54368. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54369. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54370. }
  54371. mw->resizeToBestWindowPos();
  54372. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54373. | mw->getLookAndFeel().getMenuWindowFlags());
  54374. return mw.release();
  54375. }
  54376. }
  54377. return 0;
  54378. }
  54379. void paint (Graphics& g)
  54380. {
  54381. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54382. }
  54383. void paintOverChildren (Graphics& g)
  54384. {
  54385. if (isScrolling())
  54386. {
  54387. LookAndFeel& lf = getLookAndFeel();
  54388. if (isScrollZoneActive (false))
  54389. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54390. if (isScrollZoneActive (true))
  54391. {
  54392. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54393. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54394. }
  54395. }
  54396. }
  54397. bool isScrollZoneActive (bool bottomOne) const
  54398. {
  54399. return isScrolling()
  54400. && (bottomOne
  54401. ? childYOffset < contentHeight - windowPos.getHeight()
  54402. : childYOffset > 0);
  54403. }
  54404. void addItem (const PopupMenu::Item& item)
  54405. {
  54406. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54407. addAndMakeVisible (mic);
  54408. int itemW = 80;
  54409. int itemH = 16;
  54410. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54411. mic->setSize (itemW, jlimit (2, 600, itemH));
  54412. mic->addMouseListener (this, false);
  54413. }
  54414. // hide this and all sub-comps
  54415. void hide (const PopupMenu::Item* const item)
  54416. {
  54417. if (isVisible())
  54418. {
  54419. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54420. activeSubMenu = 0;
  54421. currentChild = 0;
  54422. exitModalState (item != 0 ? item->itemId : 0);
  54423. setVisible (false);
  54424. if (item != 0
  54425. && item->commandManager != 0
  54426. && item->itemId != 0)
  54427. {
  54428. *managerOfChosenCommand = item->commandManager;
  54429. }
  54430. }
  54431. }
  54432. void dismissMenu (const PopupMenu::Item* const item)
  54433. {
  54434. if (owner != 0)
  54435. {
  54436. owner->dismissMenu (item);
  54437. }
  54438. else
  54439. {
  54440. if (item != 0)
  54441. {
  54442. // need a copy of this on the stack as the one passed in will get deleted during this call
  54443. const PopupMenu::Item mi (*item);
  54444. hide (&mi);
  54445. }
  54446. else
  54447. {
  54448. hide (0);
  54449. }
  54450. }
  54451. }
  54452. void mouseMove (const MouseEvent&)
  54453. {
  54454. timerCallback();
  54455. }
  54456. void mouseDown (const MouseEvent&)
  54457. {
  54458. timerCallback();
  54459. }
  54460. void mouseDrag (const MouseEvent&)
  54461. {
  54462. timerCallback();
  54463. }
  54464. void mouseUp (const MouseEvent&)
  54465. {
  54466. timerCallback();
  54467. }
  54468. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54469. {
  54470. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54471. lastMouse = Point<int> (-1, -1);
  54472. }
  54473. bool keyPressed (const KeyPress& key)
  54474. {
  54475. if (key.isKeyCode (KeyPress::downKey))
  54476. {
  54477. selectNextItem (1);
  54478. }
  54479. else if (key.isKeyCode (KeyPress::upKey))
  54480. {
  54481. selectNextItem (-1);
  54482. }
  54483. else if (key.isKeyCode (KeyPress::leftKey))
  54484. {
  54485. if (owner != 0)
  54486. {
  54487. Component::SafePointer<Window> parentWindow (owner);
  54488. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54489. hide (0);
  54490. if (parentWindow != 0)
  54491. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54492. disableTimerUntilMouseMoves();
  54493. }
  54494. else if (menuBarComponent != 0)
  54495. {
  54496. menuBarComponent->keyPressed (key);
  54497. }
  54498. }
  54499. else if (key.isKeyCode (KeyPress::rightKey))
  54500. {
  54501. disableTimerUntilMouseMoves();
  54502. if (showSubMenuFor (currentChild))
  54503. {
  54504. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54505. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54506. activeSubMenu->selectNextItem (1);
  54507. }
  54508. else if (menuBarComponent != 0)
  54509. {
  54510. menuBarComponent->keyPressed (key);
  54511. }
  54512. }
  54513. else if (key.isKeyCode (KeyPress::returnKey))
  54514. {
  54515. triggerCurrentlyHighlightedItem();
  54516. }
  54517. else if (key.isKeyCode (KeyPress::escapeKey))
  54518. {
  54519. dismissMenu (0);
  54520. }
  54521. else
  54522. {
  54523. return false;
  54524. }
  54525. return true;
  54526. }
  54527. void inputAttemptWhenModal()
  54528. {
  54529. timerCallback();
  54530. if (! isOverAnyMenu())
  54531. {
  54532. if (componentAttachedTo != 0)
  54533. {
  54534. // we want to dismiss the menu, but if we do it synchronously, then
  54535. // the mouse-click will be allowed to pass through. That's good, except
  54536. // when the user clicks on the button that orginally popped the menu up,
  54537. // as they'll expect the menu to go away, and in fact it'll just
  54538. // come back. So only dismiss synchronously if they're not on the original
  54539. // comp that we're attached to.
  54540. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54541. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54542. {
  54543. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54544. return;
  54545. }
  54546. }
  54547. dismissMenu (0);
  54548. }
  54549. }
  54550. void handleCommandMessage (int commandId)
  54551. {
  54552. Component::handleCommandMessage (commandId);
  54553. if (commandId == PopupMenuSettings::dismissCommandId)
  54554. dismissMenu (0);
  54555. }
  54556. void timerCallback()
  54557. {
  54558. if (! isVisible())
  54559. return;
  54560. if (componentAttachedTo != componentAttachedToOriginal)
  54561. {
  54562. dismissMenu (0);
  54563. return;
  54564. }
  54565. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54566. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54567. return;
  54568. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54569. // move rather than a real timer callback
  54570. const Point<int> globalMousePos (Desktop::getMousePosition());
  54571. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54572. const uint32 now = Time::getMillisecondCounter();
  54573. if (now > timeEnteredCurrentChildComp + 100
  54574. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54575. && currentChild->isValidComponent()
  54576. && (! disableMouseMoves)
  54577. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54578. {
  54579. showSubMenuFor (currentChild);
  54580. }
  54581. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54582. {
  54583. highlightItemUnderMouse (globalMousePos, localMousePos);
  54584. }
  54585. bool overScrollArea = false;
  54586. if (isScrolling()
  54587. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54588. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54589. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54590. {
  54591. if (now > lastScroll + 20)
  54592. {
  54593. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54594. int amount = 0;
  54595. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54596. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54597. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54598. lastScroll = now;
  54599. }
  54600. overScrollArea = true;
  54601. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54602. }
  54603. else
  54604. {
  54605. scrollAcceleration = 1.0;
  54606. }
  54607. const bool wasDown = isDown;
  54608. bool isOverAny = isOverAnyMenu();
  54609. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54610. {
  54611. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54612. isOverAny = isOverAnyMenu();
  54613. }
  54614. if (hideOnExit && hasBeenOver && ! isOverAny)
  54615. {
  54616. hide (0);
  54617. }
  54618. else
  54619. {
  54620. isDown = hasBeenOver
  54621. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54622. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54623. bool anyFocused = Process::isForegroundProcess();
  54624. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54625. {
  54626. // because no component at all may have focus, our test here will
  54627. // only be triggered when something has focus and then loses it.
  54628. anyFocused = ! hasAnyJuceCompHadFocus;
  54629. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54630. {
  54631. if (ComponentPeer::getPeer (i)->isFocused())
  54632. {
  54633. anyFocused = true;
  54634. hasAnyJuceCompHadFocus = true;
  54635. break;
  54636. }
  54637. }
  54638. }
  54639. if (! anyFocused)
  54640. {
  54641. if (now > lastFocused + 10)
  54642. {
  54643. wasHiddenBecauseOfAppChange() = true;
  54644. dismissMenu (0);
  54645. return; // may have been deleted by the previous call..
  54646. }
  54647. }
  54648. else if (wasDown && now > menuCreationTime + 250
  54649. && ! (isDown || overScrollArea))
  54650. {
  54651. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54652. if (isOver)
  54653. {
  54654. triggerCurrentlyHighlightedItem();
  54655. }
  54656. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54657. {
  54658. dismissMenu (0);
  54659. }
  54660. return; // may have been deleted by the previous calls..
  54661. }
  54662. else
  54663. {
  54664. lastFocused = now;
  54665. }
  54666. }
  54667. }
  54668. static Array<Window*>& getActiveWindows()
  54669. {
  54670. static Array<Window*> activeMenuWindows;
  54671. return activeMenuWindows;
  54672. }
  54673. static bool& wasHiddenBecauseOfAppChange() throw()
  54674. {
  54675. static bool b = false;
  54676. return b;
  54677. }
  54678. juce_UseDebuggingNewOperator
  54679. private:
  54680. Window* owner;
  54681. PopupMenu::ItemComponent* currentChild;
  54682. ScopedPointer <Window> activeSubMenu;
  54683. Component* menuBarComponent;
  54684. ApplicationCommandManager** managerOfChosenCommand;
  54685. Component::SafePointer<Component> componentAttachedTo;
  54686. Component* componentAttachedToOriginal;
  54687. Rectangle<int> windowPos;
  54688. Point<int> lastMouse;
  54689. int minimumWidth, maximumNumColumns, standardItemHeight;
  54690. bool isOver, hasBeenOver, isDown, needsToScroll;
  54691. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54692. int numColumns, contentHeight, childYOffset;
  54693. Array <int> columnWidths;
  54694. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54695. double scrollAcceleration;
  54696. bool overlaps (const Rectangle<int>& r) const
  54697. {
  54698. return r.intersects (getBounds())
  54699. || (owner != 0 && owner->overlaps (r));
  54700. }
  54701. bool isOverAnyMenu() const
  54702. {
  54703. return (owner != 0) ? owner->isOverAnyMenu()
  54704. : isOverChildren();
  54705. }
  54706. bool isOverChildren() const
  54707. {
  54708. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54709. return isVisible()
  54710. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54711. }
  54712. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54713. {
  54714. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54715. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54716. if (activeSubMenu != 0)
  54717. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54718. }
  54719. bool treeContains (const Window* const window) const throw()
  54720. {
  54721. const Window* mw = this;
  54722. while (mw->owner != 0)
  54723. mw = mw->owner;
  54724. while (mw != 0)
  54725. {
  54726. if (mw == window)
  54727. return true;
  54728. mw = mw->activeSubMenu;
  54729. }
  54730. return false;
  54731. }
  54732. void calculateWindowPos (const int minX, const int maxX,
  54733. const int minY, const int maxY,
  54734. const bool alignToRectangle)
  54735. {
  54736. const Rectangle<int> mon (Desktop::getInstance()
  54737. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  54738. (minY + maxY) / 2),
  54739. #if JUCE_MAC
  54740. true));
  54741. #else
  54742. false)); // on windows, don't stop the menu overlapping the taskbar
  54743. #endif
  54744. int x, y, widthToUse, heightToUse;
  54745. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  54746. if (alignToRectangle)
  54747. {
  54748. x = minX;
  54749. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  54750. const int spaceOver = minY - mon.getY();
  54751. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  54752. y = maxY;
  54753. else
  54754. y = minY - heightToUse;
  54755. }
  54756. else
  54757. {
  54758. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  54759. if (owner != 0)
  54760. {
  54761. if (owner->owner != 0)
  54762. {
  54763. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  54764. > owner->owner->getX() + owner->owner->getWidth() / 2);
  54765. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  54766. tendTowardsRight = true;
  54767. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  54768. tendTowardsRight = false;
  54769. }
  54770. else if (maxX + widthToUse < mon.getRight() - 32)
  54771. {
  54772. tendTowardsRight = true;
  54773. }
  54774. }
  54775. const int biggestSpace = jmax (mon.getRight() - maxX,
  54776. minX - mon.getX()) - 32;
  54777. if (biggestSpace < widthToUse)
  54778. {
  54779. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  54780. if (numColumns > 1)
  54781. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  54782. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  54783. }
  54784. if (tendTowardsRight)
  54785. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  54786. else
  54787. x = jmax (mon.getX() + 4, minX - widthToUse);
  54788. y = minY;
  54789. if ((minY + maxY) / 2 > mon.getCentreY())
  54790. y = jmax (mon.getY(), maxY - heightToUse);
  54791. }
  54792. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  54793. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  54794. windowPos.setBounds (x, y, widthToUse, heightToUse);
  54795. // sets this flag if it's big enough to obscure any of its parent menus
  54796. hideOnExit = (owner != 0)
  54797. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  54798. }
  54799. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  54800. {
  54801. numColumns = 0;
  54802. contentHeight = 0;
  54803. const int maxMenuH = getParentHeight() - 24;
  54804. int totalW;
  54805. do
  54806. {
  54807. ++numColumns;
  54808. totalW = workOutBestSize (maxMenuW);
  54809. if (totalW > maxMenuW)
  54810. {
  54811. numColumns = jmax (1, numColumns - 1);
  54812. totalW = workOutBestSize (maxMenuW); // to update col widths
  54813. break;
  54814. }
  54815. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  54816. {
  54817. break;
  54818. }
  54819. } while (numColumns < maximumNumColumns);
  54820. const int actualH = jmin (contentHeight, maxMenuH);
  54821. needsToScroll = contentHeight > actualH;
  54822. width = updateYPositions();
  54823. height = actualH + PopupMenuSettings::borderSize * 2;
  54824. }
  54825. int workOutBestSize (const int maxMenuW)
  54826. {
  54827. int totalW = 0;
  54828. contentHeight = 0;
  54829. int childNum = 0;
  54830. for (int col = 0; col < numColumns; ++col)
  54831. {
  54832. int i, colW = 50, colH = 0;
  54833. const int numChildren = jmin (getNumChildComponents() - childNum,
  54834. (getNumChildComponents() + numColumns - 1) / numColumns);
  54835. for (i = numChildren; --i >= 0;)
  54836. {
  54837. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  54838. colH += getChildComponent (childNum + i)->getHeight();
  54839. }
  54840. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  54841. columnWidths.set (col, colW);
  54842. totalW += colW;
  54843. contentHeight = jmax (contentHeight, colH);
  54844. childNum += numChildren;
  54845. }
  54846. if (totalW < minimumWidth)
  54847. {
  54848. totalW = minimumWidth;
  54849. for (int col = 0; col < numColumns; ++col)
  54850. columnWidths.set (0, totalW / numColumns);
  54851. }
  54852. return totalW;
  54853. }
  54854. void ensureItemIsVisible (const int itemId, int wantedY)
  54855. {
  54856. jassert (itemId != 0)
  54857. for (int i = getNumChildComponents(); --i >= 0;)
  54858. {
  54859. PopupMenu::ItemComponent* const m = static_cast <PopupMenu::ItemComponent*> (getChildComponent (i));
  54860. if (m != 0
  54861. && m->itemInfo.itemId == itemId
  54862. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  54863. {
  54864. const int currentY = m->getY();
  54865. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  54866. {
  54867. if (wantedY < 0)
  54868. wantedY = jlimit (PopupMenuSettings::scrollZone,
  54869. jmax (PopupMenuSettings::scrollZone,
  54870. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  54871. currentY);
  54872. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  54873. int deltaY = wantedY - currentY;
  54874. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  54875. jmin (windowPos.getHeight(), mon.getHeight()));
  54876. const int newY = jlimit (mon.getY(),
  54877. mon.getBottom() - windowPos.getHeight(),
  54878. windowPos.getY() + deltaY);
  54879. deltaY -= newY - windowPos.getY();
  54880. childYOffset -= deltaY;
  54881. windowPos.setPosition (windowPos.getX(), newY);
  54882. updateYPositions();
  54883. }
  54884. break;
  54885. }
  54886. }
  54887. }
  54888. void resizeToBestWindowPos()
  54889. {
  54890. Rectangle<int> r (windowPos);
  54891. if (childYOffset < 0)
  54892. {
  54893. r.setBounds (r.getX(), r.getY() - childYOffset,
  54894. r.getWidth(), r.getHeight() + childYOffset);
  54895. }
  54896. else if (childYOffset > 0)
  54897. {
  54898. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  54899. if (spaceAtBottom > 0)
  54900. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  54901. }
  54902. setBounds (r);
  54903. updateYPositions();
  54904. }
  54905. void alterChildYPos (const int delta)
  54906. {
  54907. if (isScrolling())
  54908. {
  54909. childYOffset += delta;
  54910. if (delta < 0)
  54911. {
  54912. childYOffset = jmax (childYOffset, 0);
  54913. }
  54914. else if (delta > 0)
  54915. {
  54916. childYOffset = jmin (childYOffset,
  54917. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  54918. }
  54919. updateYPositions();
  54920. }
  54921. else
  54922. {
  54923. childYOffset = 0;
  54924. }
  54925. resizeToBestWindowPos();
  54926. repaint();
  54927. }
  54928. int updateYPositions()
  54929. {
  54930. int x = 0;
  54931. int childNum = 0;
  54932. for (int col = 0; col < numColumns; ++col)
  54933. {
  54934. const int numChildren = jmin (getNumChildComponents() - childNum,
  54935. (getNumChildComponents() + numColumns - 1) / numColumns);
  54936. const int colW = columnWidths [col];
  54937. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  54938. for (int i = 0; i < numChildren; ++i)
  54939. {
  54940. Component* const c = getChildComponent (childNum + i);
  54941. c->setBounds (x, y, colW, c->getHeight());
  54942. y += c->getHeight();
  54943. }
  54944. x += colW;
  54945. childNum += numChildren;
  54946. }
  54947. return x;
  54948. }
  54949. bool isScrolling() const throw()
  54950. {
  54951. return childYOffset != 0 || needsToScroll;
  54952. }
  54953. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  54954. {
  54955. if (currentChild->isValidComponent())
  54956. currentChild->setHighlighted (false);
  54957. currentChild = child;
  54958. if (currentChild != 0)
  54959. {
  54960. currentChild->setHighlighted (true);
  54961. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  54962. }
  54963. }
  54964. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  54965. {
  54966. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54967. activeSubMenu = 0;
  54968. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  54969. {
  54970. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  54971. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  54972. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  54973. dismissOnMouseUp,
  54974. this,
  54975. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  54976. 0, maximumNumColumns,
  54977. standardItemHeight,
  54978. false, 0, menuBarComponent,
  54979. managerOfChosenCommand,
  54980. componentAttachedTo);
  54981. if (activeSubMenu != 0)
  54982. {
  54983. activeSubMenu->setVisible (true);
  54984. activeSubMenu->enterModalState (false);
  54985. activeSubMenu->toFront (false);
  54986. return true;
  54987. }
  54988. }
  54989. return false;
  54990. }
  54991. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  54992. {
  54993. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54994. if (isOver)
  54995. hasBeenOver = true;
  54996. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  54997. {
  54998. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  54999. if (disableMouseMoves && isOver)
  55000. disableMouseMoves = false;
  55001. }
  55002. if (disableMouseMoves || (activeSubMenu != 0 && activeSubMenu->isOverChildren()))
  55003. return;
  55004. bool isMovingTowardsMenu = false;
  55005. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55006. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55007. {
  55008. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55009. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55010. // extends from the last mouse pos to the submenu's rectangle..
  55011. float subX = (float) activeSubMenu->getScreenX();
  55012. if (activeSubMenu->getX() > getX())
  55013. {
  55014. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55015. }
  55016. else
  55017. {
  55018. lastMouse += Point<int> (2, 0);
  55019. subX += activeSubMenu->getWidth();
  55020. }
  55021. Path areaTowardsSubMenu;
  55022. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55023. (float) lastMouse.getY(),
  55024. subX,
  55025. (float) activeSubMenu->getScreenY(),
  55026. subX,
  55027. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55028. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55029. }
  55030. lastMouse = globalMousePos;
  55031. if (! isMovingTowardsMenu)
  55032. {
  55033. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55034. if (c == this)
  55035. c = 0;
  55036. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55037. if (mic == 0 && c != 0)
  55038. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55039. if (mic != currentChild
  55040. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55041. {
  55042. if (isOver && (c != 0) && (activeSubMenu != 0))
  55043. {
  55044. activeSubMenu->hide (0);
  55045. }
  55046. if (! isOver)
  55047. mic = 0;
  55048. setCurrentlyHighlightedChild (mic);
  55049. }
  55050. }
  55051. }
  55052. void triggerCurrentlyHighlightedItem()
  55053. {
  55054. if (currentChild->isValidComponent()
  55055. && currentChild->itemInfo.canBeTriggered()
  55056. && (currentChild->itemInfo.customComp == 0
  55057. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55058. {
  55059. dismissMenu (&currentChild->itemInfo);
  55060. }
  55061. }
  55062. void selectNextItem (const int delta)
  55063. {
  55064. disableTimerUntilMouseMoves();
  55065. PopupMenu::ItemComponent* mic = 0;
  55066. bool wasLastOne = (currentChild == 0);
  55067. const int numItems = getNumChildComponents();
  55068. for (int i = 0; i < numItems + 1; ++i)
  55069. {
  55070. int index = (delta > 0) ? i : (numItems - 1 - i);
  55071. index = (index + numItems) % numItems;
  55072. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55073. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55074. && wasLastOne)
  55075. break;
  55076. if (mic == currentChild)
  55077. wasLastOne = true;
  55078. }
  55079. setCurrentlyHighlightedChild (mic);
  55080. }
  55081. void disableTimerUntilMouseMoves()
  55082. {
  55083. disableMouseMoves = true;
  55084. if (owner != 0)
  55085. owner->disableTimerUntilMouseMoves();
  55086. }
  55087. Window (const Window&);
  55088. Window& operator= (const Window&);
  55089. };
  55090. PopupMenu::PopupMenu()
  55091. : lookAndFeel (0),
  55092. separatorPending (false)
  55093. {
  55094. }
  55095. PopupMenu::PopupMenu (const PopupMenu& other)
  55096. : lookAndFeel (other.lookAndFeel),
  55097. separatorPending (false)
  55098. {
  55099. items.ensureStorageAllocated (other.items.size());
  55100. for (int i = 0; i < other.items.size(); ++i)
  55101. items.add (new Item (*other.items.getUnchecked(i)));
  55102. }
  55103. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55104. {
  55105. if (this != &other)
  55106. {
  55107. lookAndFeel = other.lookAndFeel;
  55108. clear();
  55109. items.ensureStorageAllocated (other.items.size());
  55110. for (int i = 0; i < other.items.size(); ++i)
  55111. items.add (new Item (*other.items.getUnchecked(i)));
  55112. }
  55113. return *this;
  55114. }
  55115. PopupMenu::~PopupMenu()
  55116. {
  55117. clear();
  55118. }
  55119. void PopupMenu::clear()
  55120. {
  55121. items.clear();
  55122. separatorPending = false;
  55123. }
  55124. void PopupMenu::addSeparatorIfPending()
  55125. {
  55126. if (separatorPending)
  55127. {
  55128. separatorPending = false;
  55129. if (items.size() > 0)
  55130. items.add (new Item());
  55131. }
  55132. }
  55133. void PopupMenu::addItem (const int itemResultId,
  55134. const String& itemText,
  55135. const bool isActive,
  55136. const bool isTicked,
  55137. const Image* const iconToUse)
  55138. {
  55139. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55140. // didn't pick anything, so you shouldn't use it as the id
  55141. // for an item..
  55142. addSeparatorIfPending();
  55143. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55144. iconToUse, Colours::black, false, 0, 0, 0));
  55145. }
  55146. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55147. const int commandID,
  55148. const String& displayName)
  55149. {
  55150. jassert (commandManager != 0 && commandID != 0);
  55151. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55152. if (registeredInfo != 0)
  55153. {
  55154. ApplicationCommandInfo info (*registeredInfo);
  55155. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55156. addSeparatorIfPending();
  55157. items.add (new Item (commandID,
  55158. displayName.isNotEmpty() ? displayName
  55159. : info.shortName,
  55160. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55161. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55162. 0,
  55163. Colours::black,
  55164. false,
  55165. 0, 0,
  55166. commandManager));
  55167. }
  55168. }
  55169. void PopupMenu::addColouredItem (const int itemResultId,
  55170. const String& itemText,
  55171. const Colour& itemTextColour,
  55172. const bool isActive,
  55173. const bool isTicked,
  55174. const Image* const iconToUse)
  55175. {
  55176. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55177. // didn't pick anything, so you shouldn't use it as the id
  55178. // for an item..
  55179. addSeparatorIfPending();
  55180. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55181. iconToUse, itemTextColour, true, 0, 0, 0));
  55182. }
  55183. void PopupMenu::addCustomItem (const int itemResultId,
  55184. PopupMenuCustomComponent* const customComponent)
  55185. {
  55186. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55187. // didn't pick anything, so you shouldn't use it as the id
  55188. // for an item..
  55189. addSeparatorIfPending();
  55190. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55191. Colours::black, false, customComponent, 0, 0));
  55192. }
  55193. class NormalComponentWrapper : public PopupMenuCustomComponent
  55194. {
  55195. public:
  55196. NormalComponentWrapper (Component* const comp,
  55197. const int w, const int h,
  55198. const bool triggerMenuItemAutomaticallyWhenClicked)
  55199. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55200. width (w),
  55201. height (h)
  55202. {
  55203. addAndMakeVisible (comp);
  55204. }
  55205. ~NormalComponentWrapper() {}
  55206. void getIdealSize (int& idealWidth, int& idealHeight)
  55207. {
  55208. idealWidth = width;
  55209. idealHeight = height;
  55210. }
  55211. void resized()
  55212. {
  55213. if (getChildComponent(0) != 0)
  55214. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55215. }
  55216. juce_UseDebuggingNewOperator
  55217. private:
  55218. const int width, height;
  55219. NormalComponentWrapper (const NormalComponentWrapper&);
  55220. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55221. };
  55222. void PopupMenu::addCustomItem (const int itemResultId,
  55223. Component* customComponent,
  55224. int idealWidth, int idealHeight,
  55225. const bool triggerMenuItemAutomaticallyWhenClicked)
  55226. {
  55227. addCustomItem (itemResultId,
  55228. new NormalComponentWrapper (customComponent,
  55229. idealWidth, idealHeight,
  55230. triggerMenuItemAutomaticallyWhenClicked));
  55231. }
  55232. void PopupMenu::addSubMenu (const String& subMenuName,
  55233. const PopupMenu& subMenu,
  55234. const bool isActive,
  55235. Image* const iconToUse,
  55236. const bool isTicked)
  55237. {
  55238. addSeparatorIfPending();
  55239. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55240. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55241. }
  55242. void PopupMenu::addSeparator()
  55243. {
  55244. separatorPending = true;
  55245. }
  55246. class HeaderItemComponent : public PopupMenuCustomComponent
  55247. {
  55248. public:
  55249. HeaderItemComponent (const String& name)
  55250. : PopupMenuCustomComponent (false)
  55251. {
  55252. setName (name);
  55253. }
  55254. ~HeaderItemComponent()
  55255. {
  55256. }
  55257. void paint (Graphics& g)
  55258. {
  55259. Font f (getLookAndFeel().getPopupMenuFont());
  55260. f.setBold (true);
  55261. g.setFont (f);
  55262. g.setColour (findColour (PopupMenu::headerTextColourId));
  55263. g.drawFittedText (getName(),
  55264. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55265. Justification::bottomLeft, 1);
  55266. }
  55267. void getIdealSize (int& idealWidth,
  55268. int& idealHeight)
  55269. {
  55270. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55271. idealHeight += idealHeight / 2;
  55272. idealWidth += idealWidth / 4;
  55273. }
  55274. juce_UseDebuggingNewOperator
  55275. };
  55276. void PopupMenu::addSectionHeader (const String& title)
  55277. {
  55278. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55279. }
  55280. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55281. const int itemIdThatMustBeVisible,
  55282. const int minimumWidth,
  55283. const int maximumNumColumns,
  55284. const int standardItemHeight,
  55285. const bool alignToRectangle,
  55286. Component* menuBarComponent,
  55287. ApplicationCommandManager** managerOfChosenCommand,
  55288. Component* const componentAttachedTo)
  55289. {
  55290. Window* const pw
  55291. = Window::create (*this,
  55292. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55293. 0,
  55294. x, x + w,
  55295. y, y + h,
  55296. minimumWidth,
  55297. maximumNumColumns,
  55298. standardItemHeight,
  55299. alignToRectangle,
  55300. itemIdThatMustBeVisible,
  55301. menuBarComponent,
  55302. managerOfChosenCommand,
  55303. componentAttachedTo);
  55304. if (pw != 0)
  55305. pw->setVisible (true);
  55306. return pw;
  55307. }
  55308. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55309. const int itemIdThatMustBeVisible,
  55310. const int minimumWidth,
  55311. const int maximumNumColumns,
  55312. const int standardItemHeight,
  55313. const bool alignToRectangle,
  55314. Component* const componentAttachedTo)
  55315. {
  55316. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55317. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55318. Window::wasHiddenBecauseOfAppChange() = false;
  55319. int result = 0;
  55320. ApplicationCommandManager* managerOfChosenCommand = 0;
  55321. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55322. itemIdThatMustBeVisible,
  55323. minimumWidth,
  55324. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55325. standardItemHeight,
  55326. alignToRectangle, 0,
  55327. &managerOfChosenCommand,
  55328. componentAttachedTo));
  55329. if (popupComp != 0)
  55330. {
  55331. popupComp->enterModalState (false);
  55332. popupComp->toFront (false); // need to do this after making it modal, or it could
  55333. // be stuck behind other comps that are already modal..
  55334. result = popupComp->runModalLoop();
  55335. popupComp = 0;
  55336. if (! Window::wasHiddenBecauseOfAppChange())
  55337. {
  55338. if (prevTopLevel != 0)
  55339. prevTopLevel->toFront (true);
  55340. if (prevFocused != 0)
  55341. prevFocused->grabKeyboardFocus();
  55342. }
  55343. }
  55344. if (managerOfChosenCommand != 0 && result != 0)
  55345. {
  55346. ApplicationCommandTarget::InvocationInfo info (result);
  55347. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55348. managerOfChosenCommand->invoke (info, true);
  55349. }
  55350. return result;
  55351. }
  55352. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55353. const int minimumWidth,
  55354. const int maximumNumColumns,
  55355. const int standardItemHeight)
  55356. {
  55357. const Point<int> mousePos (Desktop::getMousePosition());
  55358. return showAt (mousePos.getX(), mousePos.getY(),
  55359. itemIdThatMustBeVisible,
  55360. minimumWidth,
  55361. maximumNumColumns,
  55362. standardItemHeight);
  55363. }
  55364. int PopupMenu::showAt (const int screenX,
  55365. const int screenY,
  55366. const int itemIdThatMustBeVisible,
  55367. const int minimumWidth,
  55368. const int maximumNumColumns,
  55369. const int standardItemHeight)
  55370. {
  55371. return showMenu (screenX, screenY, 1, 1,
  55372. itemIdThatMustBeVisible,
  55373. minimumWidth, maximumNumColumns,
  55374. standardItemHeight,
  55375. false, 0);
  55376. }
  55377. int PopupMenu::showAt (Component* componentToAttachTo,
  55378. const int itemIdThatMustBeVisible,
  55379. const int minimumWidth,
  55380. const int maximumNumColumns,
  55381. const int standardItemHeight)
  55382. {
  55383. if (componentToAttachTo != 0)
  55384. {
  55385. return showMenu (componentToAttachTo->getScreenX(),
  55386. componentToAttachTo->getScreenY(),
  55387. componentToAttachTo->getWidth(),
  55388. componentToAttachTo->getHeight(),
  55389. itemIdThatMustBeVisible,
  55390. minimumWidth,
  55391. maximumNumColumns,
  55392. standardItemHeight,
  55393. true, componentToAttachTo);
  55394. }
  55395. else
  55396. {
  55397. return show (itemIdThatMustBeVisible,
  55398. minimumWidth,
  55399. maximumNumColumns,
  55400. standardItemHeight);
  55401. }
  55402. }
  55403. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55404. {
  55405. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55406. {
  55407. Window* const pmw = Window::getActiveWindows()[i];
  55408. if (pmw != 0)
  55409. pmw->dismissMenu (0);
  55410. }
  55411. }
  55412. int PopupMenu::getNumItems() const throw()
  55413. {
  55414. int num = 0;
  55415. for (int i = items.size(); --i >= 0;)
  55416. if (! (items.getUnchecked(i))->isSeparator)
  55417. ++num;
  55418. return num;
  55419. }
  55420. bool PopupMenu::containsCommandItem (const int commandID) const
  55421. {
  55422. for (int i = items.size(); --i >= 0;)
  55423. {
  55424. const Item* mi = items.getUnchecked (i);
  55425. if ((mi->itemId == commandID && mi->commandManager != 0)
  55426. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55427. {
  55428. return true;
  55429. }
  55430. }
  55431. return false;
  55432. }
  55433. bool PopupMenu::containsAnyActiveItems() const throw()
  55434. {
  55435. for (int i = items.size(); --i >= 0;)
  55436. {
  55437. const Item* const mi = items.getUnchecked (i);
  55438. if (mi->subMenu != 0)
  55439. {
  55440. if (mi->subMenu->containsAnyActiveItems())
  55441. return true;
  55442. }
  55443. else if (mi->active)
  55444. {
  55445. return true;
  55446. }
  55447. }
  55448. return false;
  55449. }
  55450. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55451. {
  55452. lookAndFeel = newLookAndFeel;
  55453. }
  55454. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55455. : isHighlighted (false),
  55456. isTriggeredAutomatically (isTriggeredAutomatically_)
  55457. {
  55458. }
  55459. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55460. {
  55461. }
  55462. void PopupMenuCustomComponent::triggerMenuItem()
  55463. {
  55464. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55465. if (mic != 0)
  55466. {
  55467. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55468. if (pmw != 0)
  55469. {
  55470. pmw->dismissMenu (&mic->itemInfo);
  55471. }
  55472. else
  55473. {
  55474. // something must have gone wrong with the component hierarchy if this happens..
  55475. jassertfalse
  55476. }
  55477. }
  55478. else
  55479. {
  55480. // why isn't this component inside a menu? Not much point triggering the item if
  55481. // there's no menu.
  55482. jassertfalse
  55483. }
  55484. }
  55485. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55486. : subMenu (0),
  55487. itemId (0),
  55488. isSeparator (false),
  55489. isTicked (false),
  55490. isEnabled (false),
  55491. isCustomComponent (false),
  55492. isSectionHeader (false),
  55493. customColour (0),
  55494. customImage (0),
  55495. menu (menu_),
  55496. index (0)
  55497. {
  55498. }
  55499. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55500. {
  55501. }
  55502. bool PopupMenu::MenuItemIterator::next()
  55503. {
  55504. if (index >= menu.items.size())
  55505. return false;
  55506. const Item* const item = menu.items.getUnchecked (index);
  55507. ++index;
  55508. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55509. subMenu = item->subMenu;
  55510. itemId = item->itemId;
  55511. isSeparator = item->isSeparator;
  55512. isTicked = item->isTicked;
  55513. isEnabled = item->active;
  55514. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55515. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55516. customColour = item->usesColour ? &(item->textColour) : 0;
  55517. customImage = item->image;
  55518. commandManager = item->commandManager;
  55519. return true;
  55520. }
  55521. END_JUCE_NAMESPACE
  55522. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55523. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55524. BEGIN_JUCE_NAMESPACE
  55525. ComponentDragger::ComponentDragger()
  55526. : constrainer (0)
  55527. {
  55528. }
  55529. ComponentDragger::~ComponentDragger()
  55530. {
  55531. }
  55532. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55533. ComponentBoundsConstrainer* const constrainer_)
  55534. {
  55535. jassert (componentToDrag->isValidComponent());
  55536. if (componentToDrag != 0)
  55537. {
  55538. constrainer = constrainer_;
  55539. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55540. }
  55541. }
  55542. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55543. {
  55544. jassert (componentToDrag->isValidComponent());
  55545. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55546. if (componentToDrag != 0)
  55547. {
  55548. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55549. const Component* const parentComp = componentToDrag->getParentComponent();
  55550. if (parentComp != 0)
  55551. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55552. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55553. if (constrainer != 0)
  55554. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55555. else
  55556. componentToDrag->setBounds (bounds);
  55557. }
  55558. }
  55559. END_JUCE_NAMESPACE
  55560. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55561. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55562. BEGIN_JUCE_NAMESPACE
  55563. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55564. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55565. class DragImageComponent : public Component,
  55566. public Timer
  55567. {
  55568. public:
  55569. DragImageComponent (Image* const im,
  55570. const String& desc,
  55571. Component* const sourceComponent,
  55572. Component* const mouseDragSource_,
  55573. DragAndDropContainer* const o,
  55574. const Point<int>& imageOffset_)
  55575. : image (im),
  55576. source (sourceComponent),
  55577. mouseDragSource (mouseDragSource_),
  55578. owner (o),
  55579. dragDesc (desc),
  55580. imageOffset (imageOffset_),
  55581. hasCheckedForExternalDrag (false),
  55582. drawImage (true)
  55583. {
  55584. setSize (im->getWidth(), im->getHeight());
  55585. if (mouseDragSource == 0)
  55586. mouseDragSource = source;
  55587. mouseDragSource->addMouseListener (this, false);
  55588. startTimer (200);
  55589. setInterceptsMouseClicks (false, false);
  55590. setAlwaysOnTop (true);
  55591. }
  55592. ~DragImageComponent()
  55593. {
  55594. if (owner->dragImageComponent == this)
  55595. owner->dragImageComponent.release();
  55596. if (mouseDragSource != 0)
  55597. {
  55598. mouseDragSource->removeMouseListener (this);
  55599. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55600. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55601. }
  55602. }
  55603. void paint (Graphics& g)
  55604. {
  55605. if (isOpaque())
  55606. g.fillAll (Colours::white);
  55607. if (drawImage)
  55608. {
  55609. g.setOpacity (1.0f);
  55610. g.drawImageAt (image, 0, 0);
  55611. }
  55612. }
  55613. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55614. {
  55615. Component* hit = getParentComponent();
  55616. if (hit == 0)
  55617. {
  55618. hit = Desktop::getInstance().findComponentAt (screenPos);
  55619. }
  55620. else
  55621. {
  55622. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55623. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55624. }
  55625. // (note: use a local copy of the dragDesc member in case the callback runs
  55626. // a modal loop and deletes this object before the method completes)
  55627. const String dragDescLocal (dragDesc);
  55628. while (hit != 0)
  55629. {
  55630. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55631. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55632. {
  55633. relativePos = hit->globalPositionToRelative (screenPos);
  55634. return ddt;
  55635. }
  55636. hit = hit->getParentComponent();
  55637. }
  55638. return 0;
  55639. }
  55640. void mouseUp (const MouseEvent& e)
  55641. {
  55642. if (e.originalComponent != this)
  55643. {
  55644. if (mouseDragSource != 0)
  55645. mouseDragSource->removeMouseListener (this);
  55646. bool dropAccepted = false;
  55647. DragAndDropTarget* ddt = 0;
  55648. Point<int> relPos;
  55649. if (isVisible())
  55650. {
  55651. setVisible (false);
  55652. ddt = findTarget (e.getScreenPosition(), relPos);
  55653. // fade this component and remove it - it'll be deleted later by the timer callback
  55654. dropAccepted = ddt != 0;
  55655. setVisible (true);
  55656. if (dropAccepted || source == 0)
  55657. {
  55658. fadeOutComponent (120);
  55659. }
  55660. else
  55661. {
  55662. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55663. source->getHeight() / 2)));
  55664. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55665. getHeight() / 2)));
  55666. fadeOutComponent (120,
  55667. target.getX() - ourCentre.getX(),
  55668. target.getY() - ourCentre.getY());
  55669. }
  55670. }
  55671. if (getParentComponent() != 0)
  55672. getParentComponent()->removeChildComponent (this);
  55673. if (dropAccepted && ddt != 0)
  55674. {
  55675. // (note: use a local copy of the dragDesc member in case the callback runs
  55676. // a modal loop and deletes this object before the method completes)
  55677. const String dragDescLocal (dragDesc);
  55678. currentlyOverComp = 0;
  55679. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55680. }
  55681. // careful - this object could now be deleted..
  55682. }
  55683. }
  55684. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55685. {
  55686. // (note: use a local copy of the dragDesc member in case the callback runs
  55687. // a modal loop and deletes this object before it returns)
  55688. const String dragDescLocal (dragDesc);
  55689. Point<int> newPos (screenPos + imageOffset);
  55690. if (getParentComponent() != 0)
  55691. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55692. //if (newX != getX() || newY != getY())
  55693. {
  55694. setTopLeftPosition (newPos.getX(), newPos.getY());
  55695. Point<int> relPos;
  55696. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55697. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55698. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55699. if (ddtComp != currentlyOverComp)
  55700. {
  55701. if (currentlyOverComp != 0 && source != 0
  55702. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55703. {
  55704. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55705. }
  55706. currentlyOverComp = ddtComp;
  55707. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55708. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55709. }
  55710. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55711. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55712. if (getCurrentlyOver() == 0
  55713. && canDoExternalDrag
  55714. && ! hasCheckedForExternalDrag)
  55715. {
  55716. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55717. {
  55718. hasCheckedForExternalDrag = true;
  55719. StringArray files;
  55720. bool canMoveFiles = false;
  55721. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55722. && files.size() > 0)
  55723. {
  55724. Component::SafePointer<Component> cdw (this);
  55725. setVisible (false);
  55726. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55727. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  55728. if (cdw != 0)
  55729. delete this;
  55730. return;
  55731. }
  55732. }
  55733. }
  55734. }
  55735. }
  55736. void mouseDrag (const MouseEvent& e)
  55737. {
  55738. if (e.originalComponent != this)
  55739. updateLocation (true, e.getScreenPosition());
  55740. }
  55741. void timerCallback()
  55742. {
  55743. if (source == 0)
  55744. {
  55745. delete this;
  55746. }
  55747. else if (! isMouseButtonDownAnywhere())
  55748. {
  55749. if (mouseDragSource != 0)
  55750. mouseDragSource->removeMouseListener (this);
  55751. delete this;
  55752. }
  55753. }
  55754. private:
  55755. ScopedPointer<Image> image;
  55756. Component::SafePointer<Component> source;
  55757. Component::SafePointer<Component> mouseDragSource;
  55758. DragAndDropContainer* const owner;
  55759. Component::SafePointer<Component> currentlyOverComp;
  55760. DragAndDropTarget* getCurrentlyOver()
  55761. {
  55762. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  55763. }
  55764. String dragDesc;
  55765. const Point<int> imageOffset;
  55766. bool hasCheckedForExternalDrag, drawImage;
  55767. DragImageComponent (const DragImageComponent&);
  55768. DragImageComponent& operator= (const DragImageComponent&);
  55769. };
  55770. DragAndDropContainer::DragAndDropContainer()
  55771. {
  55772. }
  55773. DragAndDropContainer::~DragAndDropContainer()
  55774. {
  55775. dragImageComponent = 0;
  55776. }
  55777. void DragAndDropContainer::startDragging (const String& sourceDescription,
  55778. Component* sourceComponent,
  55779. Image* dragImage_,
  55780. const bool allowDraggingToExternalWindows,
  55781. const Point<int>* imageOffsetFromMouse)
  55782. {
  55783. ScopedPointer <Image> dragImage (dragImage_);
  55784. if (dragImageComponent == 0)
  55785. {
  55786. Component* const thisComp = dynamic_cast <Component*> (this);
  55787. if (thisComp == 0)
  55788. {
  55789. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  55790. return;
  55791. }
  55792. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  55793. if (draggingSource == 0 || ! draggingSource->isDragging())
  55794. {
  55795. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  55796. return;
  55797. }
  55798. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  55799. Point<int> imageOffset;
  55800. if (dragImage == 0)
  55801. {
  55802. dragImage = sourceComponent->createComponentSnapshot (sourceComponent->getLocalBounds());
  55803. if (dragImage->getFormat() != Image::ARGB)
  55804. {
  55805. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  55806. Graphics g2 (*newIm);
  55807. g2.drawImageAt (dragImage, 0, 0);
  55808. dragImage = newIm;
  55809. }
  55810. dragImage->multiplyAllAlphas (0.6f);
  55811. const int lo = 150;
  55812. const int hi = 400;
  55813. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  55814. Point<int> clipped (dragImage->getBounds().getConstrainedPoint (relPos));
  55815. for (int y = dragImage->getHeight(); --y >= 0;)
  55816. {
  55817. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  55818. for (int x = dragImage->getWidth(); --x >= 0;)
  55819. {
  55820. const int dx = x - clipped.getX();
  55821. const int distance = roundToInt (sqrt (dx * dx + dy));
  55822. if (distance > lo)
  55823. {
  55824. const float alpha = (distance > hi) ? 0
  55825. : (hi - distance) / (float) (hi - lo)
  55826. + Random::getSystemRandom().nextFloat() * 0.008f;
  55827. dragImage->multiplyAlphaAt (x, y, alpha);
  55828. }
  55829. }
  55830. }
  55831. imageOffset = -clipped;
  55832. }
  55833. else
  55834. {
  55835. if (imageOffsetFromMouse == 0)
  55836. imageOffset = Point<int> (dragImage->getWidth() / -2,
  55837. dragImage->getHeight() / -2);
  55838. else
  55839. imageOffset = *imageOffsetFromMouse;
  55840. }
  55841. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  55842. draggingSource->getComponentUnderMouse(), this, imageOffset);
  55843. currentDragDesc = sourceDescription;
  55844. if (allowDraggingToExternalWindows)
  55845. {
  55846. if (! Desktop::canUseSemiTransparentWindows())
  55847. dragImageComponent->setOpaque (true);
  55848. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  55849. | ComponentPeer::windowIsTemporary
  55850. | ComponentPeer::windowIgnoresKeyPresses);
  55851. }
  55852. else
  55853. thisComp->addChildComponent (dragImageComponent);
  55854. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  55855. dragImageComponent->setVisible (true);
  55856. }
  55857. }
  55858. bool DragAndDropContainer::isDragAndDropActive() const
  55859. {
  55860. return dragImageComponent != 0;
  55861. }
  55862. const String DragAndDropContainer::getCurrentDragDescription() const
  55863. {
  55864. return (dragImageComponent != 0) ? currentDragDesc
  55865. : String::empty;
  55866. }
  55867. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  55868. {
  55869. if (c == 0)
  55870. return 0;
  55871. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  55872. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  55873. }
  55874. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  55875. {
  55876. return false;
  55877. }
  55878. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  55879. {
  55880. }
  55881. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  55882. {
  55883. }
  55884. void DragAndDropTarget::itemDragExit (const String&, Component*)
  55885. {
  55886. }
  55887. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  55888. {
  55889. return true;
  55890. }
  55891. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  55892. {
  55893. }
  55894. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  55895. {
  55896. }
  55897. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  55898. {
  55899. }
  55900. END_JUCE_NAMESPACE
  55901. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  55902. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  55903. BEGIN_JUCE_NAMESPACE
  55904. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY);
  55905. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type);
  55906. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard);
  55907. class MouseCursor::SharedCursorHandle
  55908. {
  55909. public:
  55910. explicit SharedCursorHandle (const MouseCursor::StandardCursorType type)
  55911. : handle (juce_createStandardMouseCursor (type)),
  55912. refCount (1),
  55913. standardType (type),
  55914. isStandard (true)
  55915. {
  55916. }
  55917. SharedCursorHandle (const Image& image, const int hotSpotX, const int hotSpotY)
  55918. : handle (juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY)),
  55919. refCount (1),
  55920. standardType (MouseCursor::NormalCursor),
  55921. isStandard (false)
  55922. {
  55923. }
  55924. static SharedCursorHandle* createStandard (const MouseCursor::StandardCursorType type)
  55925. {
  55926. const ScopedLock sl (getLock());
  55927. for (int i = getCursors().size(); --i >= 0;)
  55928. {
  55929. SharedCursorHandle* const sc = getCursors().getUnchecked(i);
  55930. if (sc->standardType == type)
  55931. return sc->retain();
  55932. }
  55933. SharedCursorHandle* const sc = new SharedCursorHandle (type);
  55934. getCursors().add (sc);
  55935. return sc;
  55936. }
  55937. SharedCursorHandle* retain() throw()
  55938. {
  55939. Atomic::increment (refCount);
  55940. return this;
  55941. }
  55942. void release()
  55943. {
  55944. if (Atomic::decrementAndReturn (refCount) == 0)
  55945. {
  55946. if (isStandard)
  55947. {
  55948. const ScopedLock sl (getLock());
  55949. getCursors().removeValue (this);
  55950. }
  55951. delete this;
  55952. }
  55953. }
  55954. void* getHandle() const throw() { return handle; }
  55955. juce_UseDebuggingNewOperator
  55956. private:
  55957. void* const handle;
  55958. int32 refCount;
  55959. const MouseCursor::StandardCursorType standardType;
  55960. const bool isStandard;
  55961. static CriticalSection& getLock()
  55962. {
  55963. static CriticalSection lock;
  55964. return lock;
  55965. }
  55966. static Array <SharedCursorHandle*>& getCursors()
  55967. {
  55968. static Array <SharedCursorHandle*> cursors;
  55969. return cursors;
  55970. }
  55971. ~SharedCursorHandle()
  55972. {
  55973. juce_deleteMouseCursor (handle, isStandard);
  55974. }
  55975. SharedCursorHandle& operator= (const SharedCursorHandle&);
  55976. };
  55977. MouseCursor::MouseCursor()
  55978. : cursorHandle (SharedCursorHandle::createStandard (NormalCursor))
  55979. {
  55980. jassert (cursorHandle != 0);
  55981. }
  55982. MouseCursor::MouseCursor (const StandardCursorType type)
  55983. : cursorHandle (SharedCursorHandle::createStandard (type))
  55984. {
  55985. jassert (cursorHandle != 0);
  55986. }
  55987. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY)
  55988. : cursorHandle (new SharedCursorHandle (image, hotSpotX, hotSpotY))
  55989. {
  55990. }
  55991. MouseCursor::MouseCursor (const MouseCursor& other)
  55992. : cursorHandle (other.cursorHandle->retain())
  55993. {
  55994. }
  55995. MouseCursor::~MouseCursor()
  55996. {
  55997. cursorHandle->release();
  55998. }
  55999. MouseCursor& MouseCursor::operator= (const MouseCursor& other)
  56000. {
  56001. other.cursorHandle->retain();
  56002. cursorHandle->release();
  56003. cursorHandle = other.cursorHandle;
  56004. return *this;
  56005. }
  56006. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56007. {
  56008. return getHandle() == other.getHandle();
  56009. }
  56010. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56011. {
  56012. return getHandle() != other.getHandle();
  56013. }
  56014. void* MouseCursor::getHandle() const throw()
  56015. {
  56016. return cursorHandle->getHandle();
  56017. }
  56018. void MouseCursor::showWaitCursor() throw()
  56019. {
  56020. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56021. }
  56022. void MouseCursor::hideWaitCursor() throw()
  56023. {
  56024. Desktop::getInstance().getMainMouseSource().revealCursor();
  56025. }
  56026. END_JUCE_NAMESPACE
  56027. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56028. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56029. BEGIN_JUCE_NAMESPACE
  56030. MouseEvent::MouseEvent (MouseInputSource& source_,
  56031. const Point<int>& position,
  56032. const ModifierKeys& mods_,
  56033. Component* const originator,
  56034. const Time& eventTime_,
  56035. const Point<int> mouseDownPos_,
  56036. const Time& mouseDownTime_,
  56037. const int numberOfClicks_,
  56038. const bool mouseWasDragged) throw()
  56039. : x (position.getX()),
  56040. y (position.getY()),
  56041. mods (mods_),
  56042. eventComponent (originator),
  56043. originalComponent (originator),
  56044. eventTime (eventTime_),
  56045. source (source_),
  56046. mouseDownPos (mouseDownPos_),
  56047. mouseDownTime (mouseDownTime_),
  56048. numberOfClicks (numberOfClicks_),
  56049. wasMovedSinceMouseDown (mouseWasDragged)
  56050. {
  56051. }
  56052. MouseEvent::~MouseEvent() throw()
  56053. {
  56054. }
  56055. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56056. {
  56057. if (otherComponent == 0)
  56058. {
  56059. jassertfalse
  56060. return *this;
  56061. }
  56062. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56063. mods, originalComponent, eventTime,
  56064. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56065. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56066. }
  56067. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56068. {
  56069. return MouseEvent (source, newPosition, mods, originalComponent,
  56070. eventTime, mouseDownPos, mouseDownTime,
  56071. numberOfClicks, wasMovedSinceMouseDown);
  56072. }
  56073. bool MouseEvent::mouseWasClicked() const throw()
  56074. {
  56075. return ! wasMovedSinceMouseDown;
  56076. }
  56077. int MouseEvent::getMouseDownX() const throw()
  56078. {
  56079. return mouseDownPos.getX();
  56080. }
  56081. int MouseEvent::getMouseDownY() const throw()
  56082. {
  56083. return mouseDownPos.getY();
  56084. }
  56085. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56086. {
  56087. return mouseDownPos;
  56088. }
  56089. int MouseEvent::getDistanceFromDragStartX() const throw()
  56090. {
  56091. return x - mouseDownPos.getX();
  56092. }
  56093. int MouseEvent::getDistanceFromDragStartY() const throw()
  56094. {
  56095. return y - mouseDownPos.getY();
  56096. }
  56097. int MouseEvent::getDistanceFromDragStart() const throw()
  56098. {
  56099. return mouseDownPos.getDistanceFrom (getPosition());
  56100. }
  56101. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56102. {
  56103. return getPosition() - mouseDownPos;
  56104. }
  56105. int MouseEvent::getLengthOfMousePress() const throw()
  56106. {
  56107. if (mouseDownTime.toMilliseconds() > 0)
  56108. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56109. return 0;
  56110. }
  56111. const Point<int> MouseEvent::getPosition() const throw()
  56112. {
  56113. return Point<int> (x, y);
  56114. }
  56115. int MouseEvent::getScreenX() const
  56116. {
  56117. return getScreenPosition().getX();
  56118. }
  56119. int MouseEvent::getScreenY() const
  56120. {
  56121. return getScreenPosition().getY();
  56122. }
  56123. const Point<int> MouseEvent::getScreenPosition() const
  56124. {
  56125. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56126. }
  56127. int MouseEvent::getMouseDownScreenX() const
  56128. {
  56129. return getMouseDownScreenPosition().getX();
  56130. }
  56131. int MouseEvent::getMouseDownScreenY() const
  56132. {
  56133. return getMouseDownScreenPosition().getY();
  56134. }
  56135. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56136. {
  56137. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56138. }
  56139. static int doubleClickTimeOutMs = 400;
  56140. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56141. {
  56142. doubleClickTimeOutMs = newTime;
  56143. }
  56144. int MouseEvent::getDoubleClickTimeout() throw()
  56145. {
  56146. return doubleClickTimeOutMs;
  56147. }
  56148. END_JUCE_NAMESPACE
  56149. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56150. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56151. BEGIN_JUCE_NAMESPACE
  56152. class MouseInputSourceInternal : public AsyncUpdater
  56153. {
  56154. public:
  56155. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56156. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56157. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56158. {
  56159. zerostruct (mouseDowns);
  56160. }
  56161. ~MouseInputSourceInternal()
  56162. {
  56163. }
  56164. bool isDragging() const throw()
  56165. {
  56166. return buttonState.isAnyMouseButtonDown();
  56167. }
  56168. Component* getComponentUnderMouse() const
  56169. {
  56170. return static_cast <Component*> (componentUnderMouse);
  56171. }
  56172. const ModifierKeys getCurrentModifiers() const
  56173. {
  56174. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56175. }
  56176. ComponentPeer* getPeer()
  56177. {
  56178. if (! ComponentPeer::isValidPeer (lastPeer))
  56179. lastPeer = 0;
  56180. return lastPeer;
  56181. }
  56182. Component* findComponentAt (const Point<int>& screenPos)
  56183. {
  56184. ComponentPeer* const peer = getPeer();
  56185. if (peer != 0)
  56186. {
  56187. Component* const comp = peer->getComponent();
  56188. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56189. // (the contains() call is needed to test for overlapping desktop windows)
  56190. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56191. return comp->getComponentAt (relativePos);
  56192. }
  56193. return 0;
  56194. }
  56195. const Point<int> getScreenPosition() const throw()
  56196. {
  56197. return lastScreenPos + unboundedMouseOffset;
  56198. }
  56199. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56200. {
  56201. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56202. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56203. }
  56204. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56205. {
  56206. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56207. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56208. }
  56209. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56210. {
  56211. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56212. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56213. }
  56214. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56215. {
  56216. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56217. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56218. }
  56219. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56220. {
  56221. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56222. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56223. }
  56224. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56225. {
  56226. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56227. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56228. }
  56229. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56230. {
  56231. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56232. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56233. }
  56234. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56235. {
  56236. if (buttonState != newButtonState)
  56237. {
  56238. // (ignore secondary clicks when there's already a button down)
  56239. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56240. {
  56241. buttonState = newButtonState;
  56242. return;
  56243. }
  56244. if (buttonState.isAnyMouseButtonDown())
  56245. {
  56246. Component* const current = getComponentUnderMouse();
  56247. if (current != 0)
  56248. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56249. enableUnboundedMouseMovement (false, false);
  56250. }
  56251. buttonState = newButtonState;
  56252. if (buttonState.isAnyMouseButtonDown())
  56253. {
  56254. Desktop::getInstance().incrementMouseClickCounter();
  56255. Component* const current = getComponentUnderMouse();
  56256. if (current != 0)
  56257. {
  56258. registerMouseDown (screenPos, time, current);
  56259. sendMouseDown (current, screenPos, time);
  56260. }
  56261. }
  56262. }
  56263. }
  56264. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56265. {
  56266. Component* current = getComponentUnderMouse();
  56267. if (newComponent != current)
  56268. {
  56269. Component::SafePointer<Component> safeNewComp (newComponent);
  56270. const ModifierKeys originalButtonState (buttonState);
  56271. if (current != 0)
  56272. {
  56273. setButtons (screenPos, time, ModifierKeys());
  56274. sendMouseExit (current, screenPos, time);
  56275. buttonState = originalButtonState;
  56276. }
  56277. componentUnderMouse = safeNewComp;
  56278. current = getComponentUnderMouse();
  56279. if (current != 0)
  56280. sendMouseEnter (current, screenPos, time);
  56281. revealCursor (false);
  56282. setButtons (screenPos, time, originalButtonState);
  56283. }
  56284. }
  56285. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56286. {
  56287. ModifierKeys::updateCurrentModifiers();
  56288. if (newPeer != lastPeer)
  56289. {
  56290. setComponentUnderMouse (0, screenPos, time);
  56291. lastPeer = newPeer;
  56292. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56293. }
  56294. }
  56295. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56296. {
  56297. if (! isDragging())
  56298. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56299. if (newScreenPos != lastScreenPos || forceUpdate)
  56300. {
  56301. cancelPendingUpdate();
  56302. lastScreenPos = newScreenPos;
  56303. Component* const current = getComponentUnderMouse();
  56304. if (current != 0)
  56305. {
  56306. if (isDragging())
  56307. {
  56308. registerMouseDrag (newScreenPos);
  56309. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56310. if (isUnboundedMouseModeOn)
  56311. handleUnboundedDrag (current);
  56312. }
  56313. else
  56314. {
  56315. sendMouseMove (current, newScreenPos, time);
  56316. }
  56317. }
  56318. revealCursor (false);
  56319. }
  56320. }
  56321. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56322. {
  56323. jassert (newPeer != 0);
  56324. lastTime = time;
  56325. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56326. if (isDragging() && newMods.isAnyMouseButtonDown())
  56327. {
  56328. setScreenPos (screenPos, time, false);
  56329. }
  56330. else
  56331. {
  56332. setPeer (newPeer, screenPos, time);
  56333. ComponentPeer* peer = getPeer();
  56334. if (peer != 0)
  56335. {
  56336. setButtons (screenPos, time, newMods);
  56337. peer = getPeer();
  56338. if (peer != 0)
  56339. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56340. }
  56341. }
  56342. }
  56343. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56344. {
  56345. jassert (peer != 0);
  56346. lastTime = time;
  56347. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56348. setPeer (peer, screenPos, time);
  56349. setScreenPos (screenPos, time, false);
  56350. triggerFakeMove();
  56351. if (! isDragging())
  56352. {
  56353. Component* current = getComponentUnderMouse();
  56354. if (current != 0)
  56355. sendMouseWheel (current, screenPos, time, x, y);
  56356. }
  56357. }
  56358. const Time getLastMouseDownTime() const throw()
  56359. {
  56360. return Time (mouseDowns[0].time);
  56361. }
  56362. const Point<int> getLastMouseDownPosition() const throw()
  56363. {
  56364. return mouseDowns[0].position;
  56365. }
  56366. int getNumberOfMultipleClicks() const throw()
  56367. {
  56368. int numClicks = 0;
  56369. if (mouseDowns[0].time != 0)
  56370. {
  56371. if (! mouseMovedSignificantlySincePressed)
  56372. ++numClicks;
  56373. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56374. {
  56375. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56376. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56377. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56378. && mouseDowns[0].component == mouseDowns[i].component)
  56379. {
  56380. ++numClicks;
  56381. }
  56382. else
  56383. {
  56384. break;
  56385. }
  56386. }
  56387. }
  56388. return numClicks;
  56389. }
  56390. bool hasMouseMovedSignificantlySincePressed() const throw()
  56391. {
  56392. return mouseMovedSignificantlySincePressed
  56393. || lastTime > mouseDowns[0].time + 300;
  56394. }
  56395. void triggerFakeMove()
  56396. {
  56397. triggerAsyncUpdate();
  56398. }
  56399. void handleAsyncUpdate()
  56400. {
  56401. if (! isDragging())
  56402. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56403. }
  56404. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56405. {
  56406. enable = enable && isDragging();
  56407. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56408. if (enable != isUnboundedMouseModeOn)
  56409. {
  56410. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56411. {
  56412. // when released, return the mouse to within the component's bounds
  56413. Component* current = getComponentUnderMouse();
  56414. if (current != 0)
  56415. Desktop::setMousePosition (current->getScreenBounds()
  56416. .getConstrainedPoint (current->getMouseXYRelative()));
  56417. }
  56418. isUnboundedMouseModeOn = enable;
  56419. unboundedMouseOffset = Point<int>();
  56420. revealCursor (true);
  56421. }
  56422. }
  56423. void handleUnboundedDrag (Component* current)
  56424. {
  56425. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56426. if (! screenArea.contains (lastScreenPos))
  56427. {
  56428. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  56429. unboundedMouseOffset += (lastScreenPos - componentCentre);
  56430. Desktop::setMousePosition (componentCentre);
  56431. }
  56432. else if (isCursorVisibleUntilOffscreen
  56433. && (! unboundedMouseOffset.isOrigin())
  56434. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56435. {
  56436. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56437. unboundedMouseOffset = Point<int>();
  56438. }
  56439. }
  56440. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56441. {
  56442. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56443. {
  56444. cursor = MouseCursor::NoCursor;
  56445. forcedUpdate = true;
  56446. }
  56447. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56448. {
  56449. currentCursorHandle = cursor.getHandle();
  56450. cursor.showInWindow (getPeer());
  56451. }
  56452. }
  56453. void hideCursor()
  56454. {
  56455. showMouseCursor (MouseCursor::NoCursor, true);
  56456. }
  56457. void revealCursor (bool forcedUpdate)
  56458. {
  56459. MouseCursor mc (MouseCursor::NormalCursor);
  56460. Component* current = getComponentUnderMouse();
  56461. if (current != 0)
  56462. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56463. showMouseCursor (mc, forcedUpdate);
  56464. }
  56465. int index;
  56466. bool isMouseDevice;
  56467. Point<int> lastScreenPos;
  56468. ModifierKeys buttonState;
  56469. private:
  56470. MouseInputSource& source;
  56471. Component::SafePointer<Component> componentUnderMouse;
  56472. ComponentPeer* lastPeer;
  56473. Point<int> unboundedMouseOffset;
  56474. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56475. void* currentCursorHandle;
  56476. struct RecentMouseDown
  56477. {
  56478. Point<int> position;
  56479. int64 time;
  56480. Component* component;
  56481. };
  56482. RecentMouseDown mouseDowns[4];
  56483. bool mouseMovedSignificantlySincePressed;
  56484. int64 lastTime;
  56485. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56486. {
  56487. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56488. mouseDowns[i] = mouseDowns[i - 1];
  56489. mouseDowns[0].position = screenPos;
  56490. mouseDowns[0].time = time;
  56491. mouseDowns[0].component = component;
  56492. mouseMovedSignificantlySincePressed = false;
  56493. }
  56494. void registerMouseDrag (const Point<int>& screenPos) throw()
  56495. {
  56496. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56497. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56498. }
  56499. MouseInputSourceInternal (const MouseInputSourceInternal&);
  56500. MouseInputSourceInternal& operator= (const MouseInputSourceInternal&);
  56501. };
  56502. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56503. {
  56504. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56505. }
  56506. MouseInputSource::~MouseInputSource()
  56507. {
  56508. }
  56509. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56510. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56511. bool MouseInputSource::canHover() const { return isMouse(); }
  56512. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56513. int MouseInputSource::getIndex() const { return pimpl->index; }
  56514. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56515. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56516. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56517. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56518. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56519. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56520. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56521. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56522. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56523. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56524. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56525. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56526. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56527. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56528. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56529. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56530. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56531. {
  56532. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56533. }
  56534. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56535. {
  56536. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56537. }
  56538. END_JUCE_NAMESPACE
  56539. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56540. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56541. BEGIN_JUCE_NAMESPACE
  56542. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56543. : source (0),
  56544. hoverTimeMillisecs (hoverTimeMillisecs_),
  56545. hasJustHovered (false)
  56546. {
  56547. internalTimer.owner = this;
  56548. }
  56549. MouseHoverDetector::~MouseHoverDetector()
  56550. {
  56551. setHoverComponent (0);
  56552. }
  56553. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56554. {
  56555. hoverTimeMillisecs = newTimeInMillisecs;
  56556. }
  56557. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56558. {
  56559. if (source != newSourceComponent)
  56560. {
  56561. internalTimer.stopTimer();
  56562. hasJustHovered = false;
  56563. if (source != 0)
  56564. {
  56565. // ! you need to delete the hover detector before deleting its component
  56566. jassert (source->isValidComponent());
  56567. source->removeMouseListener (&internalTimer);
  56568. }
  56569. source = newSourceComponent;
  56570. if (newSourceComponent != 0)
  56571. newSourceComponent->addMouseListener (&internalTimer, false);
  56572. }
  56573. }
  56574. void MouseHoverDetector::hoverTimerCallback()
  56575. {
  56576. internalTimer.stopTimer();
  56577. if (source != 0)
  56578. {
  56579. const Point<int> pos (source->getMouseXYRelative());
  56580. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56581. {
  56582. hasJustHovered = true;
  56583. mouseHovered (pos.getX(), pos.getY());
  56584. }
  56585. }
  56586. }
  56587. void MouseHoverDetector::checkJustHoveredCallback()
  56588. {
  56589. if (hasJustHovered)
  56590. {
  56591. hasJustHovered = false;
  56592. mouseMovedAfterHover();
  56593. }
  56594. }
  56595. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56596. {
  56597. owner->hoverTimerCallback();
  56598. }
  56599. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56600. {
  56601. stopTimer();
  56602. owner->checkJustHoveredCallback();
  56603. }
  56604. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56605. {
  56606. stopTimer();
  56607. owner->checkJustHoveredCallback();
  56608. }
  56609. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56610. {
  56611. stopTimer();
  56612. owner->checkJustHoveredCallback();
  56613. }
  56614. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56615. {
  56616. stopTimer();
  56617. owner->checkJustHoveredCallback();
  56618. }
  56619. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56620. {
  56621. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56622. {
  56623. lastX = e.x;
  56624. lastY = e.y;
  56625. if (owner->source != 0)
  56626. startTimer (owner->hoverTimeMillisecs);
  56627. owner->checkJustHoveredCallback();
  56628. }
  56629. }
  56630. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56631. {
  56632. stopTimer();
  56633. owner->checkJustHoveredCallback();
  56634. }
  56635. END_JUCE_NAMESPACE
  56636. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56637. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56638. BEGIN_JUCE_NAMESPACE
  56639. void MouseListener::mouseEnter (const MouseEvent&)
  56640. {
  56641. }
  56642. void MouseListener::mouseExit (const MouseEvent&)
  56643. {
  56644. }
  56645. void MouseListener::mouseDown (const MouseEvent&)
  56646. {
  56647. }
  56648. void MouseListener::mouseUp (const MouseEvent&)
  56649. {
  56650. }
  56651. void MouseListener::mouseDrag (const MouseEvent&)
  56652. {
  56653. }
  56654. void MouseListener::mouseMove (const MouseEvent&)
  56655. {
  56656. }
  56657. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56658. {
  56659. }
  56660. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56661. {
  56662. }
  56663. END_JUCE_NAMESPACE
  56664. /*** End of inlined file: juce_MouseListener.cpp ***/
  56665. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56666. BEGIN_JUCE_NAMESPACE
  56667. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56668. const String& buttonTextWhenTrue,
  56669. const String& buttonTextWhenFalse)
  56670. : PropertyComponent (name),
  56671. onText (buttonTextWhenTrue),
  56672. offText (buttonTextWhenFalse)
  56673. {
  56674. createButton();
  56675. button->addButtonListener (this);
  56676. }
  56677. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56678. const String& name,
  56679. const String& buttonText)
  56680. : PropertyComponent (name),
  56681. onText (buttonText),
  56682. offText (buttonText)
  56683. {
  56684. createButton();
  56685. button->setButtonText (buttonText);
  56686. button->getToggleStateValue().referTo (valueToControl);
  56687. button->setClickingTogglesState (true);
  56688. }
  56689. BooleanPropertyComponent::~BooleanPropertyComponent()
  56690. {
  56691. deleteAllChildren();
  56692. }
  56693. void BooleanPropertyComponent::createButton()
  56694. {
  56695. addAndMakeVisible (button = new ToggleButton (String::empty));
  56696. button->setClickingTogglesState (false);
  56697. }
  56698. void BooleanPropertyComponent::setState (const bool newState)
  56699. {
  56700. button->setToggleState (newState, true);
  56701. }
  56702. bool BooleanPropertyComponent::getState() const
  56703. {
  56704. return button->getToggleState();
  56705. }
  56706. void BooleanPropertyComponent::paint (Graphics& g)
  56707. {
  56708. PropertyComponent::paint (g);
  56709. const Rectangle<int> r (button->getBounds());
  56710. g.setColour (Colours::white);
  56711. g.fillRect (r);
  56712. g.setColour (findColour (ComboBox::outlineColourId));
  56713. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56714. }
  56715. void BooleanPropertyComponent::refresh()
  56716. {
  56717. button->setToggleState (getState(), false);
  56718. button->setButtonText (button->getToggleState() ? onText : offText);
  56719. }
  56720. void BooleanPropertyComponent::buttonClicked (Button*)
  56721. {
  56722. setState (! getState());
  56723. }
  56724. END_JUCE_NAMESPACE
  56725. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56726. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56727. BEGIN_JUCE_NAMESPACE
  56728. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56729. const bool triggerOnMouseDown)
  56730. : PropertyComponent (name)
  56731. {
  56732. addAndMakeVisible (button = new TextButton (String::empty));
  56733. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56734. button->addButtonListener (this);
  56735. }
  56736. ButtonPropertyComponent::~ButtonPropertyComponent()
  56737. {
  56738. deleteAllChildren();
  56739. }
  56740. void ButtonPropertyComponent::refresh()
  56741. {
  56742. button->setButtonText (getButtonText());
  56743. }
  56744. void ButtonPropertyComponent::buttonClicked (Button*)
  56745. {
  56746. buttonClicked();
  56747. }
  56748. END_JUCE_NAMESPACE
  56749. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56750. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56751. BEGIN_JUCE_NAMESPACE
  56752. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  56753. : PropertyComponent (name),
  56754. comboBox (0)
  56755. {
  56756. }
  56757. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  56758. const String& name,
  56759. const StringArray& choices_,
  56760. const Array <int>* choiceIDs)
  56761. : PropertyComponent (name),
  56762. choices (choices_),
  56763. comboBox (0)
  56764. {
  56765. createComboBox (choiceIDs);
  56766. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  56767. }
  56768. ChoicePropertyComponent::~ChoicePropertyComponent()
  56769. {
  56770. deleteAllChildren();
  56771. }
  56772. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  56773. {
  56774. // The array of IDs must contain the same number of values as the choices list!
  56775. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  56776. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  56777. for (int i = 0; i < choices.size(); ++i)
  56778. {
  56779. if (choices[i].isNotEmpty())
  56780. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  56781. : ((*choiceIDs)[i]));
  56782. else
  56783. comboBox->addSeparator();
  56784. }
  56785. comboBox->setEditableText (false);
  56786. }
  56787. void ChoicePropertyComponent::setIndex (const int newIndex)
  56788. {
  56789. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  56790. }
  56791. int ChoicePropertyComponent::getIndex() const
  56792. {
  56793. return comboBox->getSelectedItemIndex();
  56794. }
  56795. const StringArray& ChoicePropertyComponent::getChoices() const
  56796. {
  56797. return choices;
  56798. }
  56799. void ChoicePropertyComponent::refresh()
  56800. {
  56801. if (comboBox == 0)
  56802. {
  56803. createComboBox (0);
  56804. comboBox->addListener (this);
  56805. }
  56806. comboBox->setSelectedId (getIndex() + 1, true);
  56807. }
  56808. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  56809. {
  56810. const int newIndex = comboBox->getSelectedId() - 1;
  56811. if (newIndex != getIndex())
  56812. setIndex (newIndex);
  56813. }
  56814. END_JUCE_NAMESPACE
  56815. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56816. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  56817. BEGIN_JUCE_NAMESPACE
  56818. PropertyComponent::PropertyComponent (const String& name,
  56819. const int preferredHeight_)
  56820. : Component (name),
  56821. preferredHeight (preferredHeight_)
  56822. {
  56823. jassert (name.isNotEmpty());
  56824. }
  56825. PropertyComponent::~PropertyComponent()
  56826. {
  56827. }
  56828. void PropertyComponent::paint (Graphics& g)
  56829. {
  56830. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  56831. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  56832. }
  56833. void PropertyComponent::resized()
  56834. {
  56835. if (getNumChildComponents() > 0)
  56836. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  56837. }
  56838. void PropertyComponent::enablementChanged()
  56839. {
  56840. repaint();
  56841. }
  56842. END_JUCE_NAMESPACE
  56843. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  56844. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  56845. BEGIN_JUCE_NAMESPACE
  56846. class PropertyPanel::PropertyHolderComponent : public Component
  56847. {
  56848. public:
  56849. PropertyHolderComponent()
  56850. {
  56851. }
  56852. ~PropertyHolderComponent()
  56853. {
  56854. deleteAllChildren();
  56855. }
  56856. void paint (Graphics&)
  56857. {
  56858. }
  56859. void updateLayout (int width);
  56860. void refreshAll() const;
  56861. private:
  56862. PropertyHolderComponent (const PropertyHolderComponent&);
  56863. PropertyHolderComponent& operator= (const PropertyHolderComponent&);
  56864. };
  56865. class PropertySectionComponent : public Component
  56866. {
  56867. public:
  56868. PropertySectionComponent (const String& sectionTitle,
  56869. const Array <PropertyComponent*>& newProperties,
  56870. const bool open)
  56871. : Component (sectionTitle),
  56872. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  56873. isOpen_ (open)
  56874. {
  56875. for (int i = newProperties.size(); --i >= 0;)
  56876. {
  56877. addAndMakeVisible (newProperties.getUnchecked(i));
  56878. newProperties.getUnchecked(i)->refresh();
  56879. }
  56880. }
  56881. ~PropertySectionComponent()
  56882. {
  56883. deleteAllChildren();
  56884. }
  56885. void paint (Graphics& g)
  56886. {
  56887. if (titleHeight > 0)
  56888. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  56889. }
  56890. void resized()
  56891. {
  56892. int y = titleHeight;
  56893. for (int i = getNumChildComponents(); --i >= 0;)
  56894. {
  56895. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  56896. if (pec != 0)
  56897. {
  56898. const int prefH = pec->getPreferredHeight();
  56899. pec->setBounds (1, y, getWidth() - 2, prefH);
  56900. y += prefH;
  56901. }
  56902. }
  56903. }
  56904. int getPreferredHeight() const
  56905. {
  56906. int y = titleHeight;
  56907. if (isOpen())
  56908. {
  56909. for (int i = 0; i < getNumChildComponents(); ++i)
  56910. {
  56911. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  56912. if (pec != 0)
  56913. y += pec->getPreferredHeight();
  56914. }
  56915. }
  56916. return y;
  56917. }
  56918. void setOpen (const bool open)
  56919. {
  56920. if (isOpen_ != open)
  56921. {
  56922. isOpen_ = open;
  56923. for (int i = 0; i < getNumChildComponents(); ++i)
  56924. {
  56925. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  56926. if (pec != 0)
  56927. pec->setVisible (open);
  56928. }
  56929. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56930. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  56931. if (pp != 0)
  56932. pp->resized();
  56933. }
  56934. }
  56935. bool isOpen() const
  56936. {
  56937. return isOpen_;
  56938. }
  56939. void refreshAll() const
  56940. {
  56941. for (int i = 0; i < getNumChildComponents(); ++i)
  56942. {
  56943. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  56944. if (pec != 0)
  56945. pec->refresh();
  56946. }
  56947. }
  56948. void mouseDown (const MouseEvent&)
  56949. {
  56950. }
  56951. void mouseUp (const MouseEvent& e)
  56952. {
  56953. if (e.getMouseDownX() < titleHeight
  56954. && e.x < titleHeight
  56955. && e.y < titleHeight
  56956. && e.getNumberOfClicks() != 2)
  56957. {
  56958. setOpen (! isOpen());
  56959. }
  56960. }
  56961. void mouseDoubleClick (const MouseEvent& e)
  56962. {
  56963. if (e.y < titleHeight)
  56964. setOpen (! isOpen());
  56965. }
  56966. private:
  56967. int titleHeight;
  56968. bool isOpen_;
  56969. PropertySectionComponent (const PropertySectionComponent&);
  56970. PropertySectionComponent& operator= (const PropertySectionComponent&);
  56971. };
  56972. void PropertyPanel::PropertyHolderComponent::updateLayout (const int width)
  56973. {
  56974. int y = 0;
  56975. for (int i = getNumChildComponents(); --i >= 0;)
  56976. {
  56977. PropertySectionComponent* const section
  56978. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  56979. if (section != 0)
  56980. {
  56981. const int prefH = section->getPreferredHeight();
  56982. section->setBounds (0, y, width, prefH);
  56983. y += prefH;
  56984. }
  56985. }
  56986. setSize (width, y);
  56987. repaint();
  56988. }
  56989. void PropertyPanel::PropertyHolderComponent::refreshAll() const
  56990. {
  56991. for (int i = getNumChildComponents(); --i >= 0;)
  56992. {
  56993. PropertySectionComponent* const section
  56994. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  56995. if (section != 0)
  56996. section->refreshAll();
  56997. }
  56998. }
  56999. PropertyPanel::PropertyPanel()
  57000. {
  57001. messageWhenEmpty = TRANS("(nothing selected)");
  57002. addAndMakeVisible (viewport = new Viewport());
  57003. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57004. viewport->setFocusContainer (true);
  57005. }
  57006. PropertyPanel::~PropertyPanel()
  57007. {
  57008. clear();
  57009. deleteAllChildren();
  57010. }
  57011. void PropertyPanel::paint (Graphics& g)
  57012. {
  57013. if (propertyHolderComponent->getNumChildComponents() == 0)
  57014. {
  57015. g.setColour (Colours::black.withAlpha (0.5f));
  57016. g.setFont (14.0f);
  57017. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57018. Justification::centred, true);
  57019. }
  57020. }
  57021. void PropertyPanel::resized()
  57022. {
  57023. viewport->setBounds (0, 0, getWidth(), getHeight());
  57024. updatePropHolderLayout();
  57025. }
  57026. void PropertyPanel::clear()
  57027. {
  57028. if (propertyHolderComponent->getNumChildComponents() > 0)
  57029. {
  57030. propertyHolderComponent->deleteAllChildren();
  57031. repaint();
  57032. }
  57033. }
  57034. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57035. {
  57036. if (propertyHolderComponent->getNumChildComponents() == 0)
  57037. repaint();
  57038. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57039. newProperties,
  57040. true), 0);
  57041. updatePropHolderLayout();
  57042. }
  57043. void PropertyPanel::addSection (const String& sectionTitle,
  57044. const Array <PropertyComponent*>& newProperties,
  57045. const bool shouldBeOpen)
  57046. {
  57047. jassert (sectionTitle.isNotEmpty());
  57048. if (propertyHolderComponent->getNumChildComponents() == 0)
  57049. repaint();
  57050. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57051. newProperties,
  57052. shouldBeOpen), 0);
  57053. updatePropHolderLayout();
  57054. }
  57055. void PropertyPanel::updatePropHolderLayout() const
  57056. {
  57057. const int maxWidth = viewport->getMaximumVisibleWidth();
  57058. propertyHolderComponent->updateLayout (maxWidth);
  57059. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57060. if (maxWidth != newMaxWidth)
  57061. {
  57062. // need to do this twice because of scrollbars changing the size, etc.
  57063. propertyHolderComponent->updateLayout (newMaxWidth);
  57064. }
  57065. }
  57066. void PropertyPanel::refreshAll() const
  57067. {
  57068. propertyHolderComponent->refreshAll();
  57069. }
  57070. const StringArray PropertyPanel::getSectionNames() const
  57071. {
  57072. StringArray s;
  57073. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57074. {
  57075. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57076. if (section != 0 && section->getName().isNotEmpty())
  57077. s.add (section->getName());
  57078. }
  57079. return s;
  57080. }
  57081. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57082. {
  57083. int index = 0;
  57084. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57085. {
  57086. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57087. if (section != 0 && section->getName().isNotEmpty())
  57088. {
  57089. if (index == sectionIndex)
  57090. return section->isOpen();
  57091. ++index;
  57092. }
  57093. }
  57094. return false;
  57095. }
  57096. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57097. {
  57098. int index = 0;
  57099. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57100. {
  57101. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57102. if (section != 0 && section->getName().isNotEmpty())
  57103. {
  57104. if (index == sectionIndex)
  57105. {
  57106. section->setOpen (shouldBeOpen);
  57107. break;
  57108. }
  57109. ++index;
  57110. }
  57111. }
  57112. }
  57113. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57114. {
  57115. int index = 0;
  57116. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57117. {
  57118. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57119. if (section != 0 && section->getName().isNotEmpty())
  57120. {
  57121. if (index == sectionIndex)
  57122. {
  57123. section->setEnabled (shouldBeEnabled);
  57124. break;
  57125. }
  57126. ++index;
  57127. }
  57128. }
  57129. }
  57130. XmlElement* PropertyPanel::getOpennessState() const
  57131. {
  57132. XmlElement* const xml = new XmlElement ("PROPERTYPANELSTATE");
  57133. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57134. const StringArray sections (getSectionNames());
  57135. for (int i = 0; i < sections.size(); ++i)
  57136. {
  57137. if (sections[i].isNotEmpty())
  57138. {
  57139. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57140. e->setAttribute ("name", sections[i]);
  57141. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57142. }
  57143. }
  57144. return xml;
  57145. }
  57146. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57147. {
  57148. if (xml.hasTagName ("PROPERTYPANELSTATE"))
  57149. {
  57150. const StringArray sections (getSectionNames());
  57151. forEachXmlChildElementWithTagName (xml, e, "SECTION")
  57152. {
  57153. setSectionOpen (sections.indexOf (e->getStringAttribute ("name")),
  57154. e->getBoolAttribute ("open"));
  57155. }
  57156. viewport->setViewPosition (viewport->getViewPositionX(),
  57157. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57158. }
  57159. }
  57160. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57161. {
  57162. if (messageWhenEmpty != newMessage)
  57163. {
  57164. messageWhenEmpty = newMessage;
  57165. repaint();
  57166. }
  57167. }
  57168. const String& PropertyPanel::getMessageWhenEmpty() const
  57169. {
  57170. return messageWhenEmpty;
  57171. }
  57172. END_JUCE_NAMESPACE
  57173. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57174. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57175. BEGIN_JUCE_NAMESPACE
  57176. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57177. const double rangeMin,
  57178. const double rangeMax,
  57179. const double interval,
  57180. const double skewFactor)
  57181. : PropertyComponent (name)
  57182. {
  57183. addAndMakeVisible (slider = new Slider (name));
  57184. slider->setRange (rangeMin, rangeMax, interval);
  57185. slider->setSkewFactor (skewFactor);
  57186. slider->setSliderStyle (Slider::LinearBar);
  57187. slider->addListener (this);
  57188. }
  57189. SliderPropertyComponent::SliderPropertyComponent (const Value& valueToControl,
  57190. const String& name,
  57191. const double rangeMin,
  57192. const double rangeMax,
  57193. const double interval,
  57194. const double skewFactor)
  57195. : PropertyComponent (name)
  57196. {
  57197. addAndMakeVisible (slider = new Slider (name));
  57198. slider->setRange (rangeMin, rangeMax, interval);
  57199. slider->setSkewFactor (skewFactor);
  57200. slider->setSliderStyle (Slider::LinearBar);
  57201. slider->getValueObject().referTo (valueToControl);
  57202. }
  57203. SliderPropertyComponent::~SliderPropertyComponent()
  57204. {
  57205. deleteAllChildren();
  57206. }
  57207. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57208. {
  57209. }
  57210. double SliderPropertyComponent::getValue() const
  57211. {
  57212. return slider->getValue();
  57213. }
  57214. void SliderPropertyComponent::refresh()
  57215. {
  57216. slider->setValue (getValue(), false);
  57217. }
  57218. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57219. {
  57220. if (getValue() != slider->getValue())
  57221. setValue (slider->getValue());
  57222. }
  57223. END_JUCE_NAMESPACE
  57224. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57225. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57226. BEGIN_JUCE_NAMESPACE
  57227. class TextPropLabel : public Label
  57228. {
  57229. TextPropertyComponent& owner;
  57230. int maxChars;
  57231. bool isMultiline;
  57232. public:
  57233. TextPropLabel (TextPropertyComponent& owner_,
  57234. const int maxChars_, const bool isMultiline_)
  57235. : Label (String::empty, String::empty),
  57236. owner (owner_),
  57237. maxChars (maxChars_),
  57238. isMultiline (isMultiline_)
  57239. {
  57240. setEditable (true, true, false);
  57241. setColour (backgroundColourId, Colours::white);
  57242. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57243. }
  57244. ~TextPropLabel()
  57245. {
  57246. }
  57247. TextEditor* createEditorComponent()
  57248. {
  57249. TextEditor* const textEditor = Label::createEditorComponent();
  57250. textEditor->setInputRestrictions (maxChars);
  57251. if (isMultiline)
  57252. {
  57253. textEditor->setMultiLine (true, true);
  57254. textEditor->setReturnKeyStartsNewLine (true);
  57255. }
  57256. return textEditor;
  57257. }
  57258. void textWasEdited()
  57259. {
  57260. owner.textWasEdited();
  57261. }
  57262. };
  57263. TextPropertyComponent::TextPropertyComponent (const String& name,
  57264. const int maxNumChars,
  57265. const bool isMultiLine)
  57266. : PropertyComponent (name)
  57267. {
  57268. createEditor (maxNumChars, isMultiLine);
  57269. }
  57270. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57271. const String& name,
  57272. const int maxNumChars,
  57273. const bool isMultiLine)
  57274. : PropertyComponent (name)
  57275. {
  57276. createEditor (maxNumChars, isMultiLine);
  57277. textEditor->getTextValue().referTo (valueToControl);
  57278. }
  57279. TextPropertyComponent::~TextPropertyComponent()
  57280. {
  57281. deleteAllChildren();
  57282. }
  57283. void TextPropertyComponent::setText (const String& newText)
  57284. {
  57285. textEditor->setText (newText, true);
  57286. }
  57287. const String TextPropertyComponent::getText() const
  57288. {
  57289. return textEditor->getText();
  57290. }
  57291. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57292. {
  57293. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57294. if (isMultiLine)
  57295. {
  57296. textEditor->setJustificationType (Justification::topLeft);
  57297. preferredHeight = 120;
  57298. }
  57299. }
  57300. void TextPropertyComponent::refresh()
  57301. {
  57302. textEditor->setText (getText(), false);
  57303. }
  57304. void TextPropertyComponent::textWasEdited()
  57305. {
  57306. const String newText (textEditor->getText());
  57307. if (getText() != newText)
  57308. setText (newText);
  57309. }
  57310. END_JUCE_NAMESPACE
  57311. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57312. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57313. BEGIN_JUCE_NAMESPACE
  57314. class SimpleDeviceManagerInputLevelMeter : public Component,
  57315. public Timer
  57316. {
  57317. public:
  57318. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57319. : manager (manager_),
  57320. level (0)
  57321. {
  57322. startTimer (50);
  57323. manager->enableInputLevelMeasurement (true);
  57324. }
  57325. ~SimpleDeviceManagerInputLevelMeter()
  57326. {
  57327. manager->enableInputLevelMeasurement (false);
  57328. }
  57329. void timerCallback()
  57330. {
  57331. const float newLevel = (float) manager->getCurrentInputLevel();
  57332. if (fabsf (level - newLevel) > 0.005f)
  57333. {
  57334. level = newLevel;
  57335. repaint();
  57336. }
  57337. }
  57338. void paint (Graphics& g)
  57339. {
  57340. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57341. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57342. }
  57343. private:
  57344. AudioDeviceManager* const manager;
  57345. float level;
  57346. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57347. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57348. };
  57349. class AudioDeviceSelectorComponent::MidiInputSelectorComponentListBox : public ListBox,
  57350. public ListBoxModel
  57351. {
  57352. public:
  57353. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57354. const String& noItemsMessage_,
  57355. const int minNumber_,
  57356. const int maxNumber_)
  57357. : ListBox (String::empty, 0),
  57358. deviceManager (deviceManager_),
  57359. noItemsMessage (noItemsMessage_),
  57360. minNumber (minNumber_),
  57361. maxNumber (maxNumber_)
  57362. {
  57363. items = MidiInput::getDevices();
  57364. setModel (this);
  57365. setOutlineThickness (1);
  57366. }
  57367. ~MidiInputSelectorComponentListBox()
  57368. {
  57369. }
  57370. int getNumRows()
  57371. {
  57372. return items.size();
  57373. }
  57374. void paintListBoxItem (int row,
  57375. Graphics& g,
  57376. int width, int height,
  57377. bool rowIsSelected)
  57378. {
  57379. if (((unsigned int) row) < (unsigned int) items.size())
  57380. {
  57381. if (rowIsSelected)
  57382. g.fillAll (findColour (TextEditor::highlightColourId)
  57383. .withMultipliedAlpha (0.3f));
  57384. const String item (items [row]);
  57385. bool enabled = deviceManager.isMidiInputEnabled (item);
  57386. const int x = getTickX();
  57387. const float tickW = height * 0.75f;
  57388. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57389. enabled, true, true, false);
  57390. g.setFont (height * 0.6f);
  57391. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57392. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57393. }
  57394. }
  57395. void listBoxItemClicked (int row, const MouseEvent& e)
  57396. {
  57397. selectRow (row);
  57398. if (e.x < getTickX())
  57399. flipEnablement (row);
  57400. }
  57401. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57402. {
  57403. flipEnablement (row);
  57404. }
  57405. void returnKeyPressed (int row)
  57406. {
  57407. flipEnablement (row);
  57408. }
  57409. void paint (Graphics& g)
  57410. {
  57411. ListBox::paint (g);
  57412. if (items.size() == 0)
  57413. {
  57414. g.setColour (Colours::grey);
  57415. g.setFont (13.0f);
  57416. g.drawText (noItemsMessage,
  57417. 0, 0, getWidth(), getHeight() / 2,
  57418. Justification::centred, true);
  57419. }
  57420. }
  57421. int getBestHeight (const int preferredHeight)
  57422. {
  57423. const int extra = getOutlineThickness() * 2;
  57424. return jmax (getRowHeight() * 2 + extra,
  57425. jmin (getRowHeight() * getNumRows() + extra,
  57426. preferredHeight));
  57427. }
  57428. juce_UseDebuggingNewOperator
  57429. private:
  57430. AudioDeviceManager& deviceManager;
  57431. const String noItemsMessage;
  57432. StringArray items;
  57433. int minNumber, maxNumber;
  57434. void flipEnablement (const int row)
  57435. {
  57436. if (((unsigned int) row) < (unsigned int) items.size())
  57437. {
  57438. const String item (items [row]);
  57439. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57440. }
  57441. }
  57442. int getTickX() const
  57443. {
  57444. return getRowHeight() + 5;
  57445. }
  57446. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57447. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57448. };
  57449. class AudioDeviceSettingsPanel : public Component,
  57450. public ComboBoxListener,
  57451. public ChangeListener,
  57452. public ButtonListener
  57453. {
  57454. public:
  57455. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57456. AudioIODeviceType::DeviceSetupDetails& setup_,
  57457. const bool hideAdvancedOptionsWithButton)
  57458. : type (type_),
  57459. setup (setup_)
  57460. {
  57461. sampleRateDropDown = 0;
  57462. sampleRateLabel = 0;
  57463. bufferSizeDropDown = 0;
  57464. bufferSizeLabel = 0;
  57465. outputDeviceDropDown = 0;
  57466. outputDeviceLabel = 0;
  57467. inputDeviceDropDown = 0;
  57468. inputDeviceLabel = 0;
  57469. testButton = 0;
  57470. inputLevelMeter = 0;
  57471. showUIButton = 0;
  57472. inputChanList = 0;
  57473. outputChanList = 0;
  57474. inputChanLabel = 0;
  57475. outputChanLabel = 0;
  57476. showAdvancedSettingsButton = 0;
  57477. if (hideAdvancedOptionsWithButton)
  57478. {
  57479. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57480. showAdvancedSettingsButton->addButtonListener (this);
  57481. }
  57482. type->scanForDevices();
  57483. setup.manager->addChangeListener (this);
  57484. changeListenerCallback (0);
  57485. }
  57486. ~AudioDeviceSettingsPanel()
  57487. {
  57488. setup.manager->removeChangeListener (this);
  57489. deleteAndZero (outputDeviceLabel);
  57490. deleteAndZero (inputDeviceLabel);
  57491. deleteAndZero (sampleRateLabel);
  57492. deleteAndZero (bufferSizeLabel);
  57493. deleteAndZero (showUIButton);
  57494. deleteAndZero (inputChanLabel);
  57495. deleteAndZero (outputChanLabel);
  57496. deleteAndZero (showAdvancedSettingsButton);
  57497. deleteAllChildren();
  57498. }
  57499. void resized()
  57500. {
  57501. const int lx = proportionOfWidth (0.35f);
  57502. const int w = proportionOfWidth (0.4f);
  57503. const int h = 24;
  57504. const int space = 6;
  57505. const int dh = h + space;
  57506. int y = 0;
  57507. if (outputDeviceDropDown != 0)
  57508. {
  57509. outputDeviceDropDown->setBounds (lx, y, w, h);
  57510. if (testButton != 0)
  57511. testButton->setBounds (proportionOfWidth (0.77f),
  57512. outputDeviceDropDown->getY(),
  57513. proportionOfWidth (0.18f),
  57514. h);
  57515. y += dh;
  57516. }
  57517. if (inputDeviceDropDown != 0)
  57518. {
  57519. inputDeviceDropDown->setBounds (lx, y, w, h);
  57520. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57521. inputDeviceDropDown->getY(),
  57522. proportionOfWidth (0.18f),
  57523. h);
  57524. y += dh;
  57525. }
  57526. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57527. if (outputChanList != 0)
  57528. {
  57529. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57530. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57531. y += bh + space;
  57532. }
  57533. if (inputChanList != 0)
  57534. {
  57535. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57536. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57537. y += bh + space;
  57538. }
  57539. y += space * 2;
  57540. if (showAdvancedSettingsButton != 0)
  57541. {
  57542. showAdvancedSettingsButton->changeWidthToFitText (h);
  57543. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57544. }
  57545. if (sampleRateDropDown != 0)
  57546. {
  57547. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57548. || ! showAdvancedSettingsButton->isVisible());
  57549. sampleRateDropDown->setBounds (lx, y, w, h);
  57550. y += dh;
  57551. }
  57552. if (bufferSizeDropDown != 0)
  57553. {
  57554. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57555. || ! showAdvancedSettingsButton->isVisible());
  57556. bufferSizeDropDown->setBounds (lx, y, w, h);
  57557. y += dh;
  57558. }
  57559. if (showUIButton != 0)
  57560. {
  57561. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57562. || ! showAdvancedSettingsButton->isVisible());
  57563. showUIButton->changeWidthToFitText (h);
  57564. showUIButton->setTopLeftPosition (lx, y);
  57565. }
  57566. }
  57567. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57568. {
  57569. if (comboBoxThatHasChanged == 0)
  57570. return;
  57571. AudioDeviceManager::AudioDeviceSetup config;
  57572. setup.manager->getAudioDeviceSetup (config);
  57573. String error;
  57574. if (comboBoxThatHasChanged == outputDeviceDropDown
  57575. || comboBoxThatHasChanged == inputDeviceDropDown)
  57576. {
  57577. if (outputDeviceDropDown != 0)
  57578. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57579. : outputDeviceDropDown->getText();
  57580. if (inputDeviceDropDown != 0)
  57581. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57582. : inputDeviceDropDown->getText();
  57583. if (! type->hasSeparateInputsAndOutputs())
  57584. config.inputDeviceName = config.outputDeviceName;
  57585. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57586. config.useDefaultInputChannels = true;
  57587. else
  57588. config.useDefaultOutputChannels = true;
  57589. error = setup.manager->setAudioDeviceSetup (config, true);
  57590. showCorrectDeviceName (inputDeviceDropDown, true);
  57591. showCorrectDeviceName (outputDeviceDropDown, false);
  57592. updateControlPanelButton();
  57593. resized();
  57594. }
  57595. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57596. {
  57597. if (sampleRateDropDown->getSelectedId() > 0)
  57598. {
  57599. config.sampleRate = sampleRateDropDown->getSelectedId();
  57600. error = setup.manager->setAudioDeviceSetup (config, true);
  57601. }
  57602. }
  57603. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57604. {
  57605. if (bufferSizeDropDown->getSelectedId() > 0)
  57606. {
  57607. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57608. error = setup.manager->setAudioDeviceSetup (config, true);
  57609. }
  57610. }
  57611. if (error.isNotEmpty())
  57612. {
  57613. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57614. "Error when trying to open audio device!",
  57615. error);
  57616. }
  57617. }
  57618. void buttonClicked (Button* button)
  57619. {
  57620. if (button == showAdvancedSettingsButton)
  57621. {
  57622. showAdvancedSettingsButton->setVisible (false);
  57623. resized();
  57624. }
  57625. else if (button == showUIButton)
  57626. {
  57627. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57628. if (device != 0 && device->showControlPanel())
  57629. {
  57630. setup.manager->closeAudioDevice();
  57631. setup.manager->restartLastAudioDevice();
  57632. getTopLevelComponent()->toFront (true);
  57633. }
  57634. }
  57635. else if (button == testButton && testButton != 0)
  57636. {
  57637. setup.manager->playTestSound();
  57638. }
  57639. }
  57640. void updateControlPanelButton()
  57641. {
  57642. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57643. deleteAndZero (showUIButton);
  57644. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57645. {
  57646. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57647. TRANS ("opens the device's own control panel")));
  57648. showUIButton->addButtonListener (this);
  57649. }
  57650. resized();
  57651. }
  57652. void changeListenerCallback (void*)
  57653. {
  57654. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57655. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57656. {
  57657. if (outputDeviceDropDown == 0)
  57658. {
  57659. outputDeviceDropDown = new ComboBox (String::empty);
  57660. outputDeviceDropDown->addListener (this);
  57661. addAndMakeVisible (outputDeviceDropDown);
  57662. outputDeviceLabel = new Label (String::empty,
  57663. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57664. : TRANS ("device:"));
  57665. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57666. if (setup.maxNumOutputChannels > 0)
  57667. {
  57668. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57669. testButton->addButtonListener (this);
  57670. }
  57671. }
  57672. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57673. }
  57674. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57675. {
  57676. if (inputDeviceDropDown == 0)
  57677. {
  57678. inputDeviceDropDown = new ComboBox (String::empty);
  57679. inputDeviceDropDown->addListener (this);
  57680. addAndMakeVisible (inputDeviceDropDown);
  57681. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57682. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57683. addAndMakeVisible (inputLevelMeter
  57684. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57685. }
  57686. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57687. }
  57688. updateControlPanelButton();
  57689. showCorrectDeviceName (inputDeviceDropDown, true);
  57690. showCorrectDeviceName (outputDeviceDropDown, false);
  57691. if (currentDevice != 0)
  57692. {
  57693. if (setup.maxNumOutputChannels > 0
  57694. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57695. {
  57696. if (outputChanList == 0)
  57697. {
  57698. addAndMakeVisible (outputChanList
  57699. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57700. TRANS ("(no audio output channels found)")));
  57701. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57702. outputChanLabel->attachToComponent (outputChanList, true);
  57703. }
  57704. outputChanList->refresh();
  57705. }
  57706. else
  57707. {
  57708. deleteAndZero (outputChanLabel);
  57709. deleteAndZero (outputChanList);
  57710. }
  57711. if (setup.maxNumInputChannels > 0
  57712. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57713. {
  57714. if (inputChanList == 0)
  57715. {
  57716. addAndMakeVisible (inputChanList
  57717. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57718. TRANS ("(no audio input channels found)")));
  57719. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57720. inputChanLabel->attachToComponent (inputChanList, true);
  57721. }
  57722. inputChanList->refresh();
  57723. }
  57724. else
  57725. {
  57726. deleteAndZero (inputChanLabel);
  57727. deleteAndZero (inputChanList);
  57728. }
  57729. // sample rate..
  57730. {
  57731. if (sampleRateDropDown == 0)
  57732. {
  57733. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57734. sampleRateDropDown->addListener (this);
  57735. delete sampleRateLabel;
  57736. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57737. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57738. }
  57739. else
  57740. {
  57741. sampleRateDropDown->clear();
  57742. sampleRateDropDown->removeListener (this);
  57743. }
  57744. const int numRates = currentDevice->getNumSampleRates();
  57745. for (int i = 0; i < numRates; ++i)
  57746. {
  57747. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57748. sampleRateDropDown->addItem (String (rate) + " Hz", rate);
  57749. }
  57750. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57751. sampleRateDropDown->addListener (this);
  57752. }
  57753. // buffer size
  57754. {
  57755. if (bufferSizeDropDown == 0)
  57756. {
  57757. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  57758. bufferSizeDropDown->addListener (this);
  57759. delete bufferSizeLabel;
  57760. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  57761. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  57762. }
  57763. else
  57764. {
  57765. bufferSizeDropDown->clear();
  57766. }
  57767. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  57768. double currentRate = currentDevice->getCurrentSampleRate();
  57769. if (currentRate == 0)
  57770. currentRate = 48000.0;
  57771. for (int i = 0; i < numBufferSizes; ++i)
  57772. {
  57773. const int bs = currentDevice->getBufferSizeSamples (i);
  57774. bufferSizeDropDown->addItem (String (bs)
  57775. + " samples ("
  57776. + String (bs * 1000.0 / currentRate, 1)
  57777. + " ms)",
  57778. bs);
  57779. }
  57780. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  57781. }
  57782. }
  57783. else
  57784. {
  57785. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  57786. deleteAndZero (sampleRateLabel);
  57787. deleteAndZero (bufferSizeLabel);
  57788. deleteAndZero (sampleRateDropDown);
  57789. deleteAndZero (bufferSizeDropDown);
  57790. if (outputDeviceDropDown != 0)
  57791. outputDeviceDropDown->setSelectedId (-1, true);
  57792. if (inputDeviceDropDown != 0)
  57793. inputDeviceDropDown->setSelectedId (-1, true);
  57794. }
  57795. resized();
  57796. setSize (getWidth(), getLowestY() + 4);
  57797. }
  57798. private:
  57799. AudioIODeviceType* const type;
  57800. const AudioIODeviceType::DeviceSetupDetails setup;
  57801. ComboBox* outputDeviceDropDown;
  57802. ComboBox* inputDeviceDropDown;
  57803. ComboBox* sampleRateDropDown;
  57804. ComboBox* bufferSizeDropDown;
  57805. Label* outputDeviceLabel;
  57806. Label* inputDeviceLabel;
  57807. Label* sampleRateLabel;
  57808. Label* bufferSizeLabel;
  57809. Label* inputChanLabel;
  57810. Label* outputChanLabel;
  57811. TextButton* testButton;
  57812. Component* inputLevelMeter;
  57813. TextButton* showUIButton;
  57814. TextButton* showAdvancedSettingsButton;
  57815. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  57816. {
  57817. if (box != 0)
  57818. {
  57819. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  57820. const int index = type->getIndexOfDevice (currentDevice, isInput);
  57821. box->setSelectedId (index + 1, true);
  57822. if (testButton != 0 && ! isInput)
  57823. testButton->setEnabled (index >= 0);
  57824. }
  57825. }
  57826. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  57827. {
  57828. const StringArray devs (type->getDeviceNames (isInputs));
  57829. combo.clear (true);
  57830. for (int i = 0; i < devs.size(); ++i)
  57831. combo.addItem (devs[i], i + 1);
  57832. combo.addItem (TRANS("<< none >>"), -1);
  57833. combo.setSelectedId (-1, true);
  57834. }
  57835. int getLowestY() const
  57836. {
  57837. int y = 0;
  57838. for (int i = getNumChildComponents(); --i >= 0;)
  57839. y = jmax (y, getChildComponent (i)->getBottom());
  57840. return y;
  57841. }
  57842. public:
  57843. class ChannelSelectorListBox : public ListBox,
  57844. public ListBoxModel
  57845. {
  57846. public:
  57847. enum BoxType
  57848. {
  57849. audioInputType,
  57850. audioOutputType
  57851. };
  57852. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  57853. const BoxType type_,
  57854. const String& noItemsMessage_)
  57855. : ListBox (String::empty, 0),
  57856. setup (setup_),
  57857. type (type_),
  57858. noItemsMessage (noItemsMessage_)
  57859. {
  57860. refresh();
  57861. setModel (this);
  57862. setOutlineThickness (1);
  57863. }
  57864. ~ChannelSelectorListBox()
  57865. {
  57866. }
  57867. void refresh()
  57868. {
  57869. items.clear();
  57870. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57871. if (currentDevice != 0)
  57872. {
  57873. if (type == audioInputType)
  57874. items = currentDevice->getInputChannelNames();
  57875. else if (type == audioOutputType)
  57876. items = currentDevice->getOutputChannelNames();
  57877. if (setup.useStereoPairs)
  57878. {
  57879. StringArray pairs;
  57880. for (int i = 0; i < items.size(); i += 2)
  57881. {
  57882. const String name (items[i]);
  57883. const String name2 (items[i + 1]);
  57884. String commonBit;
  57885. for (int j = 0; j < name.length(); ++j)
  57886. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  57887. commonBit = name.substring (0, j);
  57888. // Make sure we only split the name at a space, because otherwise, things
  57889. // like "input 11" + "input 12" would become "input 11 + 2"
  57890. while (commonBit.isNotEmpty() && ! CharacterFunctions::isWhitespace (commonBit.getLastCharacter()))
  57891. commonBit = commonBit.dropLastCharacters (1);
  57892. pairs.add (name.trim() + " + " + name2.substring (commonBit.length()).trim());
  57893. }
  57894. items = pairs;
  57895. }
  57896. }
  57897. updateContent();
  57898. repaint();
  57899. }
  57900. int getNumRows()
  57901. {
  57902. return items.size();
  57903. }
  57904. void paintListBoxItem (int row,
  57905. Graphics& g,
  57906. int width, int height,
  57907. bool rowIsSelected)
  57908. {
  57909. if (((unsigned int) row) < (unsigned int) items.size())
  57910. {
  57911. if (rowIsSelected)
  57912. g.fillAll (findColour (TextEditor::highlightColourId)
  57913. .withMultipliedAlpha (0.3f));
  57914. const String item (items [row]);
  57915. bool enabled = false;
  57916. AudioDeviceManager::AudioDeviceSetup config;
  57917. setup.manager->getAudioDeviceSetup (config);
  57918. if (setup.useStereoPairs)
  57919. {
  57920. if (type == audioInputType)
  57921. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  57922. else if (type == audioOutputType)
  57923. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  57924. }
  57925. else
  57926. {
  57927. if (type == audioInputType)
  57928. enabled = config.inputChannels [row];
  57929. else if (type == audioOutputType)
  57930. enabled = config.outputChannels [row];
  57931. }
  57932. const int x = getTickX();
  57933. const float tickW = height * 0.75f;
  57934. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57935. enabled, true, true, false);
  57936. g.setFont (height * 0.6f);
  57937. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57938. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57939. }
  57940. }
  57941. void listBoxItemClicked (int row, const MouseEvent& e)
  57942. {
  57943. selectRow (row);
  57944. if (e.x < getTickX())
  57945. flipEnablement (row);
  57946. }
  57947. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57948. {
  57949. flipEnablement (row);
  57950. }
  57951. void returnKeyPressed (int row)
  57952. {
  57953. flipEnablement (row);
  57954. }
  57955. void paint (Graphics& g)
  57956. {
  57957. ListBox::paint (g);
  57958. if (items.size() == 0)
  57959. {
  57960. g.setColour (Colours::grey);
  57961. g.setFont (13.0f);
  57962. g.drawText (noItemsMessage,
  57963. 0, 0, getWidth(), getHeight() / 2,
  57964. Justification::centred, true);
  57965. }
  57966. }
  57967. int getBestHeight (int maxHeight)
  57968. {
  57969. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  57970. getNumRows())
  57971. + getOutlineThickness() * 2;
  57972. }
  57973. juce_UseDebuggingNewOperator
  57974. private:
  57975. const AudioIODeviceType::DeviceSetupDetails setup;
  57976. const BoxType type;
  57977. const String noItemsMessage;
  57978. StringArray items;
  57979. void flipEnablement (const int row)
  57980. {
  57981. jassert (type == audioInputType || type == audioOutputType);
  57982. if (((unsigned int) row) < (unsigned int) items.size())
  57983. {
  57984. AudioDeviceManager::AudioDeviceSetup config;
  57985. setup.manager->getAudioDeviceSetup (config);
  57986. if (setup.useStereoPairs)
  57987. {
  57988. BigInteger bits;
  57989. BigInteger& original = (type == audioInputType ? config.inputChannels
  57990. : config.outputChannels);
  57991. int i;
  57992. for (i = 0; i < 256; i += 2)
  57993. bits.setBit (i / 2, original [i] || original [i + 1]);
  57994. if (type == audioInputType)
  57995. {
  57996. config.useDefaultInputChannels = false;
  57997. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  57998. }
  57999. else
  58000. {
  58001. config.useDefaultOutputChannels = false;
  58002. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58003. }
  58004. for (i = 0; i < 256; ++i)
  58005. original.setBit (i, bits [i / 2]);
  58006. }
  58007. else
  58008. {
  58009. if (type == audioInputType)
  58010. {
  58011. config.useDefaultInputChannels = false;
  58012. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58013. }
  58014. else
  58015. {
  58016. config.useDefaultOutputChannels = false;
  58017. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58018. }
  58019. }
  58020. String error (setup.manager->setAudioDeviceSetup (config, true));
  58021. if (! error.isEmpty())
  58022. {
  58023. //xxx
  58024. }
  58025. }
  58026. }
  58027. static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber)
  58028. {
  58029. const int numActive = chans.countNumberOfSetBits();
  58030. if (chans [index])
  58031. {
  58032. if (numActive > minNumber)
  58033. chans.setBit (index, false);
  58034. }
  58035. else
  58036. {
  58037. if (numActive >= maxNumber)
  58038. {
  58039. const int firstActiveChan = chans.findNextSetBit();
  58040. chans.setBit (index > firstActiveChan
  58041. ? firstActiveChan : chans.getHighestBit(),
  58042. false);
  58043. }
  58044. chans.setBit (index, true);
  58045. }
  58046. }
  58047. int getTickX() const
  58048. {
  58049. return getRowHeight() + 5;
  58050. }
  58051. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58052. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58053. };
  58054. private:
  58055. ChannelSelectorListBox* inputChanList;
  58056. ChannelSelectorListBox* outputChanList;
  58057. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58058. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58059. };
  58060. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58061. const int minInputChannels_,
  58062. const int maxInputChannels_,
  58063. const int minOutputChannels_,
  58064. const int maxOutputChannels_,
  58065. const bool showMidiInputOptions,
  58066. const bool showMidiOutputSelector,
  58067. const bool showChannelsAsStereoPairs_,
  58068. const bool hideAdvancedOptionsWithButton_)
  58069. : deviceManager (deviceManager_),
  58070. deviceTypeDropDown (0),
  58071. deviceTypeDropDownLabel (0),
  58072. audioDeviceSettingsComp (0),
  58073. minOutputChannels (minOutputChannels_),
  58074. maxOutputChannels (maxOutputChannels_),
  58075. minInputChannels (minInputChannels_),
  58076. maxInputChannels (maxInputChannels_),
  58077. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58078. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58079. {
  58080. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58081. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58082. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58083. {
  58084. deviceTypeDropDown = new ComboBox (String::empty);
  58085. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58086. {
  58087. deviceTypeDropDown
  58088. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58089. i + 1);
  58090. }
  58091. addAndMakeVisible (deviceTypeDropDown);
  58092. deviceTypeDropDown->addListener (this);
  58093. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58094. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58095. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58096. }
  58097. if (showMidiInputOptions)
  58098. {
  58099. addAndMakeVisible (midiInputsList
  58100. = new MidiInputSelectorComponentListBox (deviceManager,
  58101. TRANS("(no midi inputs available)"),
  58102. 0, 0));
  58103. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58104. midiInputsLabel->setJustificationType (Justification::topRight);
  58105. midiInputsLabel->attachToComponent (midiInputsList, true);
  58106. }
  58107. else
  58108. {
  58109. midiInputsList = 0;
  58110. midiInputsLabel = 0;
  58111. }
  58112. if (showMidiOutputSelector)
  58113. {
  58114. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58115. midiOutputSelector->addListener (this);
  58116. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58117. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58118. }
  58119. else
  58120. {
  58121. midiOutputSelector = 0;
  58122. midiOutputLabel = 0;
  58123. }
  58124. deviceManager_.addChangeListener (this);
  58125. changeListenerCallback (0);
  58126. }
  58127. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58128. {
  58129. deviceManager.removeChangeListener (this);
  58130. deleteAllChildren();
  58131. }
  58132. void AudioDeviceSelectorComponent::resized()
  58133. {
  58134. const int lx = proportionOfWidth (0.35f);
  58135. const int w = proportionOfWidth (0.4f);
  58136. const int h = 24;
  58137. const int space = 6;
  58138. const int dh = h + space;
  58139. int y = 15;
  58140. if (deviceTypeDropDown != 0)
  58141. {
  58142. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58143. y += dh + space * 2;
  58144. }
  58145. if (audioDeviceSettingsComp != 0)
  58146. {
  58147. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58148. y += audioDeviceSettingsComp->getHeight() + space;
  58149. }
  58150. if (midiInputsList != 0)
  58151. {
  58152. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58153. midiInputsList->setBounds (lx, y, w, bh);
  58154. y += bh + space;
  58155. }
  58156. if (midiOutputSelector != 0)
  58157. midiOutputSelector->setBounds (lx, y, w, h);
  58158. }
  58159. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58160. {
  58161. if (child == audioDeviceSettingsComp)
  58162. resized();
  58163. }
  58164. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58165. {
  58166. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58167. if (device != 0 && device->hasControlPanel())
  58168. {
  58169. if (device->showControlPanel())
  58170. deviceManager.restartLastAudioDevice();
  58171. getTopLevelComponent()->toFront (true);
  58172. }
  58173. }
  58174. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58175. {
  58176. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58177. {
  58178. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58179. if (type != 0)
  58180. {
  58181. deleteAndZero (audioDeviceSettingsComp);
  58182. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58183. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58184. }
  58185. }
  58186. else if (comboBoxThatHasChanged == midiOutputSelector)
  58187. {
  58188. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58189. }
  58190. }
  58191. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58192. {
  58193. if (deviceTypeDropDown != 0)
  58194. {
  58195. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58196. }
  58197. if (audioDeviceSettingsComp == 0
  58198. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58199. {
  58200. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58201. deleteAndZero (audioDeviceSettingsComp);
  58202. AudioIODeviceType* const type
  58203. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58204. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58205. if (type != 0)
  58206. {
  58207. AudioIODeviceType::DeviceSetupDetails details;
  58208. details.manager = &deviceManager;
  58209. details.minNumInputChannels = minInputChannels;
  58210. details.maxNumInputChannels = maxInputChannels;
  58211. details.minNumOutputChannels = minOutputChannels;
  58212. details.maxNumOutputChannels = maxOutputChannels;
  58213. details.useStereoPairs = showChannelsAsStereoPairs;
  58214. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58215. if (audioDeviceSettingsComp != 0)
  58216. {
  58217. addAndMakeVisible (audioDeviceSettingsComp);
  58218. audioDeviceSettingsComp->resized();
  58219. }
  58220. }
  58221. }
  58222. if (midiInputsList != 0)
  58223. {
  58224. midiInputsList->updateContent();
  58225. midiInputsList->repaint();
  58226. }
  58227. if (midiOutputSelector != 0)
  58228. {
  58229. midiOutputSelector->clear();
  58230. const StringArray midiOuts (MidiOutput::getDevices());
  58231. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58232. midiOutputSelector->addSeparator();
  58233. for (int i = 0; i < midiOuts.size(); ++i)
  58234. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58235. int current = -1;
  58236. if (deviceManager.getDefaultMidiOutput() != 0)
  58237. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58238. midiOutputSelector->setSelectedId (current, true);
  58239. }
  58240. resized();
  58241. }
  58242. END_JUCE_NAMESPACE
  58243. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58244. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58245. BEGIN_JUCE_NAMESPACE
  58246. BubbleComponent::BubbleComponent()
  58247. : side (0),
  58248. allowablePlacements (above | below | left | right),
  58249. arrowTipX (0.0f),
  58250. arrowTipY (0.0f)
  58251. {
  58252. setInterceptsMouseClicks (false, false);
  58253. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58254. setComponentEffect (&shadow);
  58255. }
  58256. BubbleComponent::~BubbleComponent()
  58257. {
  58258. }
  58259. void BubbleComponent::paint (Graphics& g)
  58260. {
  58261. int x = content.getX();
  58262. int y = content.getY();
  58263. int w = content.getWidth();
  58264. int h = content.getHeight();
  58265. int cw, ch;
  58266. getContentSize (cw, ch);
  58267. if (side == 3)
  58268. x += w - cw;
  58269. else if (side != 1)
  58270. x += (w - cw) / 2;
  58271. w = cw;
  58272. if (side == 2)
  58273. y += h - ch;
  58274. else if (side != 0)
  58275. y += (h - ch) / 2;
  58276. h = ch;
  58277. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58278. (float) x, (float) y,
  58279. (float) w, (float) h);
  58280. const int cx = x + (w - cw) / 2;
  58281. const int cy = y + (h - ch) / 2;
  58282. const int indent = 3;
  58283. g.setOrigin (cx + indent, cy + indent);
  58284. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58285. paintContent (g, cw - indent * 2, ch - indent * 2);
  58286. }
  58287. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58288. {
  58289. allowablePlacements = newPlacement;
  58290. }
  58291. void BubbleComponent::setPosition (Component* componentToPointTo)
  58292. {
  58293. jassert (componentToPointTo->isValidComponent());
  58294. Point<int> pos;
  58295. if (getParentComponent() != 0)
  58296. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58297. else
  58298. pos = componentToPointTo->relativePositionToGlobal (pos);
  58299. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58300. }
  58301. void BubbleComponent::setPosition (const int arrowTipX_,
  58302. const int arrowTipY_)
  58303. {
  58304. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58305. }
  58306. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58307. {
  58308. Rectangle<int> availableSpace;
  58309. if (getParentComponent() != 0)
  58310. {
  58311. availableSpace.setSize (getParentComponent()->getWidth(),
  58312. getParentComponent()->getHeight());
  58313. }
  58314. else
  58315. {
  58316. availableSpace = getParentMonitorArea();
  58317. }
  58318. int x = 0;
  58319. int y = 0;
  58320. int w = 150;
  58321. int h = 30;
  58322. getContentSize (w, h);
  58323. w += 30;
  58324. h += 30;
  58325. const float edgeIndent = 2.0f;
  58326. const int arrowLength = jmin (10, h / 3, w / 3);
  58327. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58328. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58329. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58330. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58331. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58332. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58333. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58334. {
  58335. spaceLeft = spaceRight = 0;
  58336. }
  58337. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58338. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58339. {
  58340. spaceAbove = spaceBelow = 0;
  58341. }
  58342. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58343. {
  58344. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58345. arrowTipX = w * 0.5f;
  58346. content.setSize (w, h - arrowLength);
  58347. if (spaceAbove >= spaceBelow)
  58348. {
  58349. // above
  58350. y = rectangleToPointTo.getY() - h;
  58351. content.setPosition (0, 0);
  58352. arrowTipY = h - edgeIndent;
  58353. side = 2;
  58354. }
  58355. else
  58356. {
  58357. // below
  58358. y = rectangleToPointTo.getBottom();
  58359. content.setPosition (0, arrowLength);
  58360. arrowTipY = edgeIndent;
  58361. side = 0;
  58362. }
  58363. }
  58364. else
  58365. {
  58366. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58367. arrowTipY = h * 0.5f;
  58368. content.setSize (w - arrowLength, h);
  58369. if (spaceLeft > spaceRight)
  58370. {
  58371. // on the left
  58372. x = rectangleToPointTo.getX() - w;
  58373. content.setPosition (0, 0);
  58374. arrowTipX = w - edgeIndent;
  58375. side = 3;
  58376. }
  58377. else
  58378. {
  58379. // on the right
  58380. x = rectangleToPointTo.getRight();
  58381. content.setPosition (arrowLength, 0);
  58382. arrowTipX = edgeIndent;
  58383. side = 1;
  58384. }
  58385. }
  58386. setBounds (x, y, w, h);
  58387. }
  58388. END_JUCE_NAMESPACE
  58389. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58390. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58391. BEGIN_JUCE_NAMESPACE
  58392. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58393. : fadeOutLength (fadeOutLengthMs),
  58394. deleteAfterUse (false)
  58395. {
  58396. }
  58397. BubbleMessageComponent::~BubbleMessageComponent()
  58398. {
  58399. fadeOutComponent (fadeOutLength);
  58400. }
  58401. void BubbleMessageComponent::showAt (int x, int y,
  58402. const String& text,
  58403. const int numMillisecondsBeforeRemoving,
  58404. const bool removeWhenMouseClicked,
  58405. const bool deleteSelfAfterUse)
  58406. {
  58407. textLayout.clear();
  58408. textLayout.setText (text, Font (14.0f));
  58409. textLayout.layout (256, Justification::centredLeft, true);
  58410. setPosition (x, y);
  58411. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58412. }
  58413. void BubbleMessageComponent::showAt (Component* const component,
  58414. const String& text,
  58415. const int numMillisecondsBeforeRemoving,
  58416. const bool removeWhenMouseClicked,
  58417. const bool deleteSelfAfterUse)
  58418. {
  58419. textLayout.clear();
  58420. textLayout.setText (text, Font (14.0f));
  58421. textLayout.layout (256, Justification::centredLeft, true);
  58422. setPosition (component);
  58423. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58424. }
  58425. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58426. const bool removeWhenMouseClicked,
  58427. const bool deleteSelfAfterUse)
  58428. {
  58429. setVisible (true);
  58430. deleteAfterUse = deleteSelfAfterUse;
  58431. if (numMillisecondsBeforeRemoving > 0)
  58432. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58433. else
  58434. expiryTime = 0;
  58435. startTimer (77);
  58436. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58437. if (! (removeWhenMouseClicked && isShowing()))
  58438. mouseClickCounter += 0xfffff;
  58439. repaint();
  58440. }
  58441. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58442. {
  58443. w = textLayout.getWidth() + 16;
  58444. h = textLayout.getHeight() + 16;
  58445. }
  58446. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58447. {
  58448. g.setColour (findColour (TooltipWindow::textColourId));
  58449. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58450. }
  58451. void BubbleMessageComponent::timerCallback()
  58452. {
  58453. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58454. {
  58455. stopTimer();
  58456. setVisible (false);
  58457. if (deleteAfterUse)
  58458. delete this;
  58459. }
  58460. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58461. {
  58462. stopTimer();
  58463. fadeOutComponent (fadeOutLength);
  58464. if (deleteAfterUse)
  58465. delete this;
  58466. }
  58467. }
  58468. END_JUCE_NAMESPACE
  58469. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58470. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58471. BEGIN_JUCE_NAMESPACE
  58472. static const int swatchesPerRow = 8;
  58473. static const int swatchHeight = 22;
  58474. class ColourComponentSlider : public Slider
  58475. {
  58476. public:
  58477. ColourComponentSlider (const String& name)
  58478. : Slider (name)
  58479. {
  58480. setRange (0.0, 255.0, 1.0);
  58481. }
  58482. ~ColourComponentSlider()
  58483. {
  58484. }
  58485. const String getTextFromValue (double value)
  58486. {
  58487. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58488. }
  58489. double getValueFromText (const String& text)
  58490. {
  58491. return (double) text.getHexValue32();
  58492. }
  58493. private:
  58494. ColourComponentSlider (const ColourComponentSlider&);
  58495. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58496. };
  58497. class ColourSpaceMarker : public Component
  58498. {
  58499. public:
  58500. ColourSpaceMarker()
  58501. {
  58502. setInterceptsMouseClicks (false, false);
  58503. }
  58504. ~ColourSpaceMarker()
  58505. {
  58506. }
  58507. void paint (Graphics& g)
  58508. {
  58509. g.setColour (Colour::greyLevel (0.1f));
  58510. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58511. g.setColour (Colour::greyLevel (0.9f));
  58512. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58513. }
  58514. private:
  58515. ColourSpaceMarker (const ColourSpaceMarker&);
  58516. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58517. };
  58518. class ColourSelector::ColourSpaceView : public Component
  58519. {
  58520. public:
  58521. ColourSpaceView (ColourSelector* owner_,
  58522. float& h_, float& s_, float& v_,
  58523. const int edgeSize)
  58524. : owner (owner_),
  58525. h (h_), s (s_), v (v_),
  58526. lastHue (0.0f),
  58527. edge (edgeSize)
  58528. {
  58529. addAndMakeVisible (marker = new ColourSpaceMarker());
  58530. setMouseCursor (MouseCursor::CrosshairCursor);
  58531. }
  58532. ~ColourSpaceView()
  58533. {
  58534. deleteAllChildren();
  58535. }
  58536. void paint (Graphics& g)
  58537. {
  58538. if (colours == 0)
  58539. {
  58540. const int width = getWidth() / 2;
  58541. const int height = getHeight() / 2;
  58542. colours = new Image (Image::RGB, width, height, false);
  58543. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58544. for (int y = 0; y < height; ++y)
  58545. {
  58546. const float v = 1.0f - y / (float) height;
  58547. for (int x = 0; x < width; ++x)
  58548. {
  58549. const float s = x / (float) width;
  58550. const Colour col (h, s, v, 1.0f);
  58551. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58552. pix->set (col.getPixelARGB());
  58553. }
  58554. }
  58555. }
  58556. g.setOpacity (1.0f);
  58557. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58558. 0, 0, colours->getWidth(), colours->getHeight());
  58559. }
  58560. void mouseDown (const MouseEvent& e)
  58561. {
  58562. mouseDrag (e);
  58563. }
  58564. void mouseDrag (const MouseEvent& e)
  58565. {
  58566. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58567. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58568. owner->setSV (s, v);
  58569. }
  58570. void updateIfNeeded()
  58571. {
  58572. if (lastHue != h)
  58573. {
  58574. lastHue = h;
  58575. colours = 0;
  58576. repaint();
  58577. }
  58578. updateMarker();
  58579. }
  58580. void resized()
  58581. {
  58582. colours = 0;
  58583. updateMarker();
  58584. }
  58585. private:
  58586. ColourSelector* const owner;
  58587. float& h;
  58588. float& s;
  58589. float& v;
  58590. float lastHue;
  58591. ColourSpaceMarker* marker;
  58592. const int edge;
  58593. ScopedPointer <Image> colours;
  58594. void updateMarker() const throw()
  58595. {
  58596. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58597. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58598. edge * 2, edge * 2);
  58599. }
  58600. ColourSpaceView (const ColourSpaceView&);
  58601. ColourSpaceView& operator= (const ColourSpaceView&);
  58602. };
  58603. class HueSelectorMarker : public Component
  58604. {
  58605. public:
  58606. HueSelectorMarker()
  58607. {
  58608. setInterceptsMouseClicks (false, false);
  58609. }
  58610. ~HueSelectorMarker()
  58611. {
  58612. }
  58613. void paint (Graphics& g)
  58614. {
  58615. Path p;
  58616. p.addTriangle (1.0f, 1.0f,
  58617. getWidth() * 0.3f, getHeight() * 0.5f,
  58618. 1.0f, getHeight() - 1.0f);
  58619. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58620. getWidth() * 0.7f, getHeight() * 0.5f,
  58621. getWidth() - 1.0f, getHeight() - 1.0f);
  58622. g.setColour (Colours::white.withAlpha (0.75f));
  58623. g.fillPath (p);
  58624. g.setColour (Colours::black.withAlpha (0.75f));
  58625. g.strokePath (p, PathStrokeType (1.2f));
  58626. }
  58627. private:
  58628. HueSelectorMarker (const HueSelectorMarker&);
  58629. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58630. };
  58631. class ColourSelector::HueSelectorComp : public Component
  58632. {
  58633. public:
  58634. HueSelectorComp (ColourSelector* owner_,
  58635. float& h_, float& s_, float& v_,
  58636. const int edgeSize)
  58637. : owner (owner_),
  58638. h (h_), s (s_), v (v_),
  58639. lastHue (0.0f),
  58640. edge (edgeSize)
  58641. {
  58642. addAndMakeVisible (marker = new HueSelectorMarker());
  58643. }
  58644. ~HueSelectorComp()
  58645. {
  58646. deleteAllChildren();
  58647. }
  58648. void paint (Graphics& g)
  58649. {
  58650. const float yScale = 1.0f / (getHeight() - edge * 2);
  58651. const Rectangle<int> clip (g.getClipBounds());
  58652. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58653. {
  58654. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58655. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58656. }
  58657. }
  58658. void resized()
  58659. {
  58660. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58661. getWidth(), edge * 2);
  58662. }
  58663. void mouseDown (const MouseEvent& e)
  58664. {
  58665. mouseDrag (e);
  58666. }
  58667. void mouseDrag (const MouseEvent& e)
  58668. {
  58669. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58670. owner->setHue (hue);
  58671. }
  58672. void updateIfNeeded()
  58673. {
  58674. resized();
  58675. }
  58676. private:
  58677. ColourSelector* const owner;
  58678. float& h;
  58679. float& s;
  58680. float& v;
  58681. float lastHue;
  58682. HueSelectorMarker* marker;
  58683. const int edge;
  58684. HueSelectorComp (const HueSelectorComp&);
  58685. HueSelectorComp& operator= (const HueSelectorComp&);
  58686. };
  58687. class ColourSelector::SwatchComponent : public Component
  58688. {
  58689. public:
  58690. SwatchComponent (ColourSelector* owner_, int index_)
  58691. : owner (owner_),
  58692. index (index_)
  58693. {
  58694. }
  58695. ~SwatchComponent()
  58696. {
  58697. }
  58698. void paint (Graphics& g)
  58699. {
  58700. const Colour colour (owner->getSwatchColour (index));
  58701. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58702. 6, 6,
  58703. Colour (0xffdddddd).overlaidWith (colour),
  58704. Colour (0xffffffff).overlaidWith (colour));
  58705. }
  58706. void mouseDown (const MouseEvent&)
  58707. {
  58708. PopupMenu m;
  58709. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58710. m.addSeparator();
  58711. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58712. const int r = m.showAt (this);
  58713. if (r == 1)
  58714. {
  58715. owner->setCurrentColour (owner->getSwatchColour (index));
  58716. }
  58717. else if (r == 2)
  58718. {
  58719. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58720. {
  58721. owner->setSwatchColour (index, owner->getCurrentColour());
  58722. repaint();
  58723. }
  58724. }
  58725. }
  58726. private:
  58727. ColourSelector* const owner;
  58728. const int index;
  58729. SwatchComponent (const SwatchComponent&);
  58730. SwatchComponent& operator= (const SwatchComponent&);
  58731. };
  58732. ColourSelector::ColourSelector (const int flags_,
  58733. const int edgeGap_,
  58734. const int gapAroundColourSpaceComponent)
  58735. : colour (Colours::white),
  58736. flags (flags_),
  58737. topSpace (0),
  58738. edgeGap (edgeGap_)
  58739. {
  58740. // not much point having a selector with no components in it!
  58741. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58742. updateHSV();
  58743. if ((flags & showSliders) != 0)
  58744. {
  58745. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58746. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58747. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58748. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58749. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58750. for (int i = 4; --i >= 0;)
  58751. sliders[i]->addListener (this);
  58752. }
  58753. else
  58754. {
  58755. zeromem (sliders, sizeof (sliders));
  58756. }
  58757. if ((flags & showColourspace) != 0)
  58758. {
  58759. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  58760. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  58761. }
  58762. else
  58763. {
  58764. colourSpace = 0;
  58765. hueSelector = 0;
  58766. }
  58767. update();
  58768. }
  58769. ColourSelector::~ColourSelector()
  58770. {
  58771. dispatchPendingMessages();
  58772. swatchComponents.clear();
  58773. deleteAllChildren();
  58774. }
  58775. const Colour ColourSelector::getCurrentColour() const
  58776. {
  58777. return ((flags & showAlphaChannel) != 0) ? colour
  58778. : colour.withAlpha ((uint8) 0xff);
  58779. }
  58780. void ColourSelector::setCurrentColour (const Colour& c)
  58781. {
  58782. if (c != colour)
  58783. {
  58784. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  58785. updateHSV();
  58786. update();
  58787. }
  58788. }
  58789. void ColourSelector::setHue (float newH)
  58790. {
  58791. newH = jlimit (0.0f, 1.0f, newH);
  58792. if (h != newH)
  58793. {
  58794. h = newH;
  58795. colour = Colour (h, s, v, colour.getFloatAlpha());
  58796. update();
  58797. }
  58798. }
  58799. void ColourSelector::setSV (float newS, float newV)
  58800. {
  58801. newS = jlimit (0.0f, 1.0f, newS);
  58802. newV = jlimit (0.0f, 1.0f, newV);
  58803. if (s != newS || v != newV)
  58804. {
  58805. s = newS;
  58806. v = newV;
  58807. colour = Colour (h, s, v, colour.getFloatAlpha());
  58808. update();
  58809. }
  58810. }
  58811. void ColourSelector::updateHSV()
  58812. {
  58813. colour.getHSB (h, s, v);
  58814. }
  58815. void ColourSelector::update()
  58816. {
  58817. if (sliders[0] != 0)
  58818. {
  58819. sliders[0]->setValue ((int) colour.getRed());
  58820. sliders[1]->setValue ((int) colour.getGreen());
  58821. sliders[2]->setValue ((int) colour.getBlue());
  58822. sliders[3]->setValue ((int) colour.getAlpha());
  58823. }
  58824. if (colourSpace != 0)
  58825. {
  58826. colourSpace->updateIfNeeded();
  58827. hueSelector->updateIfNeeded();
  58828. }
  58829. if ((flags & showColourAtTop) != 0)
  58830. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  58831. sendChangeMessage (this);
  58832. }
  58833. void ColourSelector::paint (Graphics& g)
  58834. {
  58835. g.fillAll (findColour (backgroundColourId));
  58836. if ((flags & showColourAtTop) != 0)
  58837. {
  58838. const Colour colour (getCurrentColour());
  58839. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  58840. 10, 10,
  58841. Colour (0xffdddddd).overlaidWith (colour),
  58842. Colour (0xffffffff).overlaidWith (colour));
  58843. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  58844. g.setFont (14.0f, true);
  58845. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  58846. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  58847. Justification::centred, false);
  58848. }
  58849. if ((flags & showSliders) != 0)
  58850. {
  58851. g.setColour (findColour (labelTextColourId));
  58852. g.setFont (11.0f);
  58853. for (int i = 4; --i >= 0;)
  58854. {
  58855. if (sliders[i]->isVisible())
  58856. g.drawText (sliders[i]->getName() + ":",
  58857. 0, sliders[i]->getY(),
  58858. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  58859. Justification::centredRight, false);
  58860. }
  58861. }
  58862. }
  58863. void ColourSelector::resized()
  58864. {
  58865. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  58866. const int numSwatches = getNumSwatches();
  58867. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  58868. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  58869. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  58870. int y = topSpace;
  58871. if ((flags & showColourspace) != 0)
  58872. {
  58873. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  58874. colourSpace->setBounds (edgeGap, y,
  58875. getWidth() - hueWidth - edgeGap - 4,
  58876. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  58877. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  58878. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  58879. colourSpace->getHeight());
  58880. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  58881. }
  58882. if ((flags & showSliders) != 0)
  58883. {
  58884. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  58885. for (int i = 0; i < numSliders; ++i)
  58886. {
  58887. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  58888. proportionOfWidth (0.72f), sliderHeight - 2);
  58889. y += sliderHeight;
  58890. }
  58891. }
  58892. if (numSwatches > 0)
  58893. {
  58894. const int startX = 8;
  58895. const int xGap = 4;
  58896. const int yGap = 4;
  58897. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  58898. y += edgeGap;
  58899. if (swatchComponents.size() != numSwatches)
  58900. {
  58901. swatchComponents.clear();
  58902. for (int i = 0; i < numSwatches; ++i)
  58903. {
  58904. SwatchComponent* const sc = new SwatchComponent (this, i);
  58905. swatchComponents.add (sc);
  58906. addAndMakeVisible (sc);
  58907. }
  58908. }
  58909. int x = startX;
  58910. for (int i = 0; i < swatchComponents.size(); ++i)
  58911. {
  58912. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  58913. sc->setBounds (x + xGap / 2,
  58914. y + yGap / 2,
  58915. swatchWidth - xGap,
  58916. swatchHeight - yGap);
  58917. if (((i + 1) % swatchesPerRow) == 0)
  58918. {
  58919. x = startX;
  58920. y += swatchHeight;
  58921. }
  58922. else
  58923. {
  58924. x += swatchWidth;
  58925. }
  58926. }
  58927. }
  58928. }
  58929. void ColourSelector::sliderValueChanged (Slider*)
  58930. {
  58931. if (sliders[0] != 0)
  58932. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  58933. (uint8) sliders[1]->getValue(),
  58934. (uint8) sliders[2]->getValue(),
  58935. (uint8) sliders[3]->getValue()));
  58936. }
  58937. int ColourSelector::getNumSwatches() const
  58938. {
  58939. return 0;
  58940. }
  58941. const Colour ColourSelector::getSwatchColour (const int) const
  58942. {
  58943. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  58944. return Colours::black;
  58945. }
  58946. void ColourSelector::setSwatchColour (const int, const Colour&) const
  58947. {
  58948. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  58949. }
  58950. END_JUCE_NAMESPACE
  58951. /*** End of inlined file: juce_ColourSelector.cpp ***/
  58952. /*** Start of inlined file: juce_DropShadower.cpp ***/
  58953. BEGIN_JUCE_NAMESPACE
  58954. class ShadowWindow : public Component
  58955. {
  58956. Component* owner;
  58957. Image** shadowImageSections;
  58958. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  58959. public:
  58960. ShadowWindow (Component* const owner_,
  58961. const int type_,
  58962. Image** const shadowImageSections_)
  58963. : owner (owner_),
  58964. shadowImageSections (shadowImageSections_),
  58965. type (type_)
  58966. {
  58967. setInterceptsMouseClicks (false, false);
  58968. if (owner_->isOnDesktop())
  58969. {
  58970. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  58971. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  58972. | ComponentPeer::windowIsTemporary
  58973. | ComponentPeer::windowIgnoresKeyPresses);
  58974. }
  58975. else if (owner_->getParentComponent() != 0)
  58976. {
  58977. owner_->getParentComponent()->addChildComponent (this);
  58978. }
  58979. }
  58980. ~ShadowWindow()
  58981. {
  58982. }
  58983. void paint (Graphics& g)
  58984. {
  58985. Image* const topLeft = shadowImageSections [type * 3];
  58986. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  58987. Image* const filler = shadowImageSections [type * 3 + 2];
  58988. g.setOpacity (1.0f);
  58989. if (type < 2)
  58990. {
  58991. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  58992. g.drawImage (topLeft,
  58993. 0, 0, topLeft->getWidth(), imH,
  58994. 0, 0, topLeft->getWidth(), imH);
  58995. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  58996. g.drawImage (bottomRight,
  58997. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  58998. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  58999. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59000. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59001. }
  59002. else
  59003. {
  59004. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59005. g.drawImage (topLeft,
  59006. 0, 0, imW, topLeft->getHeight(),
  59007. 0, 0, imW, topLeft->getHeight());
  59008. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59009. g.drawImage (bottomRight,
  59010. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59011. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59012. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59013. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59014. }
  59015. }
  59016. void resized()
  59017. {
  59018. repaint(); // (needed for correct repainting)
  59019. }
  59020. private:
  59021. ShadowWindow (const ShadowWindow&);
  59022. ShadowWindow& operator= (const ShadowWindow&);
  59023. };
  59024. DropShadower::DropShadower (const float alpha_,
  59025. const int xOffset_,
  59026. const int yOffset_,
  59027. const float blurRadius_)
  59028. : owner (0),
  59029. numShadows (0),
  59030. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59031. xOffset (xOffset_),
  59032. yOffset (yOffset_),
  59033. alpha (alpha_),
  59034. blurRadius (blurRadius_),
  59035. inDestructor (false),
  59036. reentrant (false)
  59037. {
  59038. }
  59039. DropShadower::~DropShadower()
  59040. {
  59041. if (owner != 0)
  59042. owner->removeComponentListener (this);
  59043. inDestructor = true;
  59044. deleteShadowWindows();
  59045. }
  59046. void DropShadower::deleteShadowWindows()
  59047. {
  59048. if (numShadows > 0)
  59049. {
  59050. int i;
  59051. for (i = numShadows; --i >= 0;)
  59052. delete shadowWindows[i];
  59053. for (i = 12; --i >= 0;)
  59054. delete shadowImageSections[i];
  59055. numShadows = 0;
  59056. }
  59057. }
  59058. void DropShadower::setOwner (Component* componentToFollow)
  59059. {
  59060. if (componentToFollow != owner)
  59061. {
  59062. if (owner != 0)
  59063. owner->removeComponentListener (this);
  59064. // (the component can't be null)
  59065. jassert (componentToFollow != 0);
  59066. owner = componentToFollow;
  59067. jassert (owner != 0);
  59068. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59069. owner->addComponentListener (this);
  59070. updateShadows();
  59071. }
  59072. }
  59073. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59074. {
  59075. updateShadows();
  59076. }
  59077. void DropShadower::componentBroughtToFront (Component&)
  59078. {
  59079. bringShadowWindowsToFront();
  59080. }
  59081. void DropShadower::componentChildrenChanged (Component&)
  59082. {
  59083. }
  59084. void DropShadower::componentParentHierarchyChanged (Component&)
  59085. {
  59086. deleteShadowWindows();
  59087. updateShadows();
  59088. }
  59089. void DropShadower::componentVisibilityChanged (Component&)
  59090. {
  59091. updateShadows();
  59092. }
  59093. void DropShadower::updateShadows()
  59094. {
  59095. if (reentrant || inDestructor || (owner == 0))
  59096. return;
  59097. reentrant = true;
  59098. ComponentPeer* const nw = owner->getPeer();
  59099. const bool isOwnerVisible = owner->isVisible()
  59100. && (nw == 0 || ! nw->isMinimised());
  59101. const bool createShadowWindows = numShadows == 0
  59102. && owner->getWidth() > 0
  59103. && owner->getHeight() > 0
  59104. && isOwnerVisible
  59105. && (Desktop::canUseSemiTransparentWindows()
  59106. || owner->getParentComponent() != 0);
  59107. if (createShadowWindows)
  59108. {
  59109. // keep a cached version of the image to save doing the gaussian too often
  59110. String imageId;
  59111. imageId << shadowEdge << ',' << xOffset << ',' << yOffset << ',' << alpha;
  59112. const int hash = imageId.hashCode();
  59113. Image* bigIm = ImageCache::getFromHashCode (hash);
  59114. if (bigIm == 0)
  59115. {
  59116. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59117. Graphics bigG (*bigIm);
  59118. bigG.setColour (Colours::black.withAlpha (alpha));
  59119. bigG.fillRect (shadowEdge + xOffset,
  59120. shadowEdge + yOffset,
  59121. bigIm->getWidth() - (shadowEdge * 2),
  59122. bigIm->getHeight() - (shadowEdge * 2));
  59123. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59124. blurKernel.createGaussianBlur (blurRadius);
  59125. blurKernel.applyToImage (*bigIm, 0,
  59126. Rectangle<int> (xOffset, yOffset,
  59127. bigIm->getWidth(), bigIm->getHeight()));
  59128. ImageCache::addImageToCache (bigIm, hash);
  59129. }
  59130. const int iw = bigIm->getWidth();
  59131. const int ih = bigIm->getHeight();
  59132. const int shadowEdge2 = shadowEdge * 2;
  59133. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59134. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59135. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59136. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59137. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59138. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59139. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59140. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59141. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59142. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59143. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59144. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59145. ImageCache::release (bigIm);
  59146. for (int i = 0; i < 4; ++i)
  59147. {
  59148. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59149. ++numShadows;
  59150. }
  59151. }
  59152. if (numShadows > 0)
  59153. {
  59154. for (int i = numShadows; --i >= 0;)
  59155. {
  59156. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59157. shadowWindows[i]->setVisible (isOwnerVisible);
  59158. }
  59159. const int x = owner->getX();
  59160. const int y = owner->getY() - shadowEdge;
  59161. const int w = owner->getWidth();
  59162. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59163. shadowWindows[0]->setBounds (x - shadowEdge,
  59164. y,
  59165. shadowEdge,
  59166. h);
  59167. shadowWindows[1]->setBounds (x + w,
  59168. y,
  59169. shadowEdge,
  59170. h);
  59171. shadowWindows[2]->setBounds (x,
  59172. y,
  59173. w,
  59174. shadowEdge);
  59175. shadowWindows[3]->setBounds (x,
  59176. owner->getBottom(),
  59177. w,
  59178. shadowEdge);
  59179. }
  59180. reentrant = false;
  59181. if (createShadowWindows)
  59182. bringShadowWindowsToFront();
  59183. }
  59184. void DropShadower::setShadowImage (Image* const src, const int num, const int w, const int h,
  59185. const int sx, const int sy)
  59186. {
  59187. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59188. Graphics g (*shadowImageSections[num]);
  59189. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59190. }
  59191. void DropShadower::bringShadowWindowsToFront()
  59192. {
  59193. if (! (inDestructor || reentrant))
  59194. {
  59195. updateShadows();
  59196. reentrant = true;
  59197. for (int i = numShadows; --i >= 0;)
  59198. shadowWindows[i]->toBehind (owner);
  59199. reentrant = false;
  59200. }
  59201. }
  59202. END_JUCE_NAMESPACE
  59203. /*** End of inlined file: juce_DropShadower.cpp ***/
  59204. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59205. BEGIN_JUCE_NAMESPACE
  59206. class MagnifyingPeer : public ComponentPeer
  59207. {
  59208. public:
  59209. MagnifyingPeer (Component* const component_,
  59210. MagnifierComponent* const magnifierComp_)
  59211. : ComponentPeer (component_, 0),
  59212. magnifierComp (magnifierComp_)
  59213. {
  59214. }
  59215. ~MagnifyingPeer()
  59216. {
  59217. }
  59218. void* getNativeHandle() const { return 0; }
  59219. void setVisible (bool) {}
  59220. void setTitle (const String&) {}
  59221. void setPosition (int, int) {}
  59222. void setSize (int, int) {}
  59223. void setBounds (int, int, int, int, bool) {}
  59224. void setMinimised (bool) {}
  59225. bool isMinimised() const { return false; }
  59226. void setFullScreen (bool) {}
  59227. bool isFullScreen() const { return false; }
  59228. const BorderSize getFrameSize() const { return BorderSize (0); }
  59229. bool setAlwaysOnTop (bool) { return true; }
  59230. void toFront (bool) {}
  59231. void toBehind (ComponentPeer*) {}
  59232. void setIcon (const Image&) {}
  59233. bool isFocused() const
  59234. {
  59235. return magnifierComp->hasKeyboardFocus (true);
  59236. }
  59237. void grabFocus()
  59238. {
  59239. ComponentPeer* peer = magnifierComp->getPeer();
  59240. if (peer != 0)
  59241. peer->grabFocus();
  59242. }
  59243. void textInputRequired (const Point<int>& position)
  59244. {
  59245. ComponentPeer* peer = magnifierComp->getPeer();
  59246. if (peer != 0)
  59247. peer->textInputRequired (position);
  59248. }
  59249. const Rectangle<int> getBounds() const
  59250. {
  59251. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59252. component->getWidth(), component->getHeight());
  59253. }
  59254. const Point<int> getScreenPosition() const
  59255. {
  59256. return magnifierComp->getScreenPosition();
  59257. }
  59258. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59259. {
  59260. const double zoom = magnifierComp->getScaleFactor();
  59261. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59262. roundToInt (relativePosition.getY() * zoom)));
  59263. }
  59264. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59265. {
  59266. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59267. const double zoom = magnifierComp->getScaleFactor();
  59268. return Point<int> (roundToInt (p.getX() / zoom),
  59269. roundToInt (p.getY() / zoom));
  59270. }
  59271. bool contains (const Point<int>& position, bool) const
  59272. {
  59273. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59274. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59275. }
  59276. void repaint (int x, int y, int w, int h)
  59277. {
  59278. const double zoom = magnifierComp->getScaleFactor();
  59279. magnifierComp->repaint ((int) (x * zoom),
  59280. (int) (y * zoom),
  59281. roundToInt (w * zoom) + 1,
  59282. roundToInt (h * zoom) + 1);
  59283. }
  59284. void performAnyPendingRepaintsNow()
  59285. {
  59286. }
  59287. juce_UseDebuggingNewOperator
  59288. private:
  59289. MagnifierComponent* const magnifierComp;
  59290. MagnifyingPeer (const MagnifyingPeer&);
  59291. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59292. };
  59293. class PeerHolderComp : public Component
  59294. {
  59295. public:
  59296. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59297. : magnifierComp (magnifierComp_)
  59298. {
  59299. setVisible (true);
  59300. }
  59301. ~PeerHolderComp()
  59302. {
  59303. }
  59304. ComponentPeer* createNewPeer (int, void*)
  59305. {
  59306. return new MagnifyingPeer (this, magnifierComp);
  59307. }
  59308. void childBoundsChanged (Component* c)
  59309. {
  59310. if (c != 0)
  59311. {
  59312. setSize (c->getWidth(), c->getHeight());
  59313. magnifierComp->childBoundsChanged (this);
  59314. }
  59315. }
  59316. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59317. {
  59318. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59319. Component* const p = magnifierComp->getParentComponent();
  59320. if (p != 0)
  59321. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59322. }
  59323. private:
  59324. MagnifierComponent* const magnifierComp;
  59325. PeerHolderComp (const PeerHolderComp&);
  59326. PeerHolderComp& operator= (const PeerHolderComp&);
  59327. };
  59328. MagnifierComponent::MagnifierComponent (Component* const content_,
  59329. const bool deleteContentCompWhenNoLongerNeeded)
  59330. : content (content_),
  59331. scaleFactor (0.0),
  59332. peer (0),
  59333. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59334. quality (Graphics::lowResamplingQuality),
  59335. mouseSource (0, true)
  59336. {
  59337. holderComp = new PeerHolderComp (this);
  59338. setScaleFactor (1.0);
  59339. }
  59340. MagnifierComponent::~MagnifierComponent()
  59341. {
  59342. delete holderComp;
  59343. if (deleteContent)
  59344. delete content;
  59345. }
  59346. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59347. {
  59348. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59349. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59350. if (scaleFactor != newScaleFactor)
  59351. {
  59352. scaleFactor = newScaleFactor;
  59353. if (scaleFactor == 1.0)
  59354. {
  59355. holderComp->removeFromDesktop();
  59356. peer = 0;
  59357. addChildComponent (content);
  59358. childBoundsChanged (content);
  59359. }
  59360. else
  59361. {
  59362. holderComp->addAndMakeVisible (content);
  59363. holderComp->childBoundsChanged (content);
  59364. childBoundsChanged (holderComp);
  59365. holderComp->addToDesktop (0);
  59366. peer = holderComp->getPeer();
  59367. }
  59368. repaint();
  59369. }
  59370. }
  59371. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59372. {
  59373. quality = newQuality;
  59374. }
  59375. void MagnifierComponent::paint (Graphics& g)
  59376. {
  59377. const int w = holderComp->getWidth();
  59378. const int h = holderComp->getHeight();
  59379. if (w == 0 || h == 0)
  59380. return;
  59381. const Rectangle<int> r (g.getClipBounds());
  59382. const int srcX = (int) (r.getX() / scaleFactor);
  59383. const int srcY = (int) (r.getY() / scaleFactor);
  59384. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59385. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59386. if (scaleFactor >= 1.0)
  59387. {
  59388. ++srcW;
  59389. ++srcH;
  59390. }
  59391. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59392. temp.clear (srcX, srcY, srcW, srcH);
  59393. {
  59394. Graphics g2 (temp);
  59395. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59396. holderComp->paintEntireComponent (g2);
  59397. }
  59398. g.setImageResamplingQuality (quality);
  59399. g.drawImageTransformed (&temp, temp.getBounds(),
  59400. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59401. false);
  59402. }
  59403. void MagnifierComponent::childBoundsChanged (Component* c)
  59404. {
  59405. if (c != 0)
  59406. setSize (roundToInt (c->getWidth() * scaleFactor),
  59407. roundToInt (c->getHeight() * scaleFactor));
  59408. }
  59409. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59410. {
  59411. if (peer != 0)
  59412. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59413. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59414. }
  59415. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59416. {
  59417. passOnMouseEventToPeer (e);
  59418. }
  59419. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59420. {
  59421. passOnMouseEventToPeer (e);
  59422. }
  59423. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59424. {
  59425. passOnMouseEventToPeer (e);
  59426. }
  59427. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59428. {
  59429. passOnMouseEventToPeer (e);
  59430. }
  59431. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59432. {
  59433. passOnMouseEventToPeer (e);
  59434. }
  59435. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59436. {
  59437. passOnMouseEventToPeer (e);
  59438. }
  59439. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59440. {
  59441. if (peer != 0)
  59442. peer->handleMouseWheel (e.source.getIndex(),
  59443. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59444. ix * 256.0f, iy * 256.0f);
  59445. else
  59446. Component::mouseWheelMove (e, ix, iy);
  59447. }
  59448. int MagnifierComponent::scaleInt (const int n) const
  59449. {
  59450. return roundToInt (n / scaleFactor);
  59451. }
  59452. END_JUCE_NAMESPACE
  59453. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59454. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59455. BEGIN_JUCE_NAMESPACE
  59456. class MidiKeyboardUpDownButton : public Button
  59457. {
  59458. public:
  59459. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59460. const int delta_)
  59461. : Button (String::empty),
  59462. owner (owner_),
  59463. delta (delta_)
  59464. {
  59465. setOpaque (true);
  59466. }
  59467. ~MidiKeyboardUpDownButton()
  59468. {
  59469. }
  59470. void clicked()
  59471. {
  59472. int note = owner->getLowestVisibleKey();
  59473. if (delta < 0)
  59474. note = (note - 1) / 12;
  59475. else
  59476. note = note / 12 + 1;
  59477. owner->setLowestVisibleKey (note * 12);
  59478. }
  59479. void paintButton (Graphics& g,
  59480. bool isMouseOverButton,
  59481. bool isButtonDown)
  59482. {
  59483. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59484. isMouseOverButton, isButtonDown,
  59485. delta > 0);
  59486. }
  59487. private:
  59488. MidiKeyboardComponent* const owner;
  59489. const int delta;
  59490. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59491. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59492. };
  59493. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59494. const Orientation orientation_)
  59495. : state (state_),
  59496. xOffset (0),
  59497. blackNoteLength (1),
  59498. keyWidth (16.0f),
  59499. orientation (orientation_),
  59500. midiChannel (1),
  59501. midiInChannelMask (0xffff),
  59502. velocity (1.0f),
  59503. noteUnderMouse (-1),
  59504. mouseDownNote (-1),
  59505. rangeStart (0),
  59506. rangeEnd (127),
  59507. firstKey (12 * 4),
  59508. canScroll (true),
  59509. mouseDragging (false),
  59510. useMousePositionForVelocity (true),
  59511. keyMappingOctave (6),
  59512. octaveNumForMiddleC (3)
  59513. {
  59514. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59515. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59516. // initialise with a default set of querty key-mappings..
  59517. const char* const keymap = "awsedftgyhujkolp;";
  59518. for (int i = String (keymap).length(); --i >= 0;)
  59519. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59520. setOpaque (true);
  59521. setWantsKeyboardFocus (true);
  59522. state.addListener (this);
  59523. }
  59524. MidiKeyboardComponent::~MidiKeyboardComponent()
  59525. {
  59526. state.removeListener (this);
  59527. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59528. deleteAllChildren();
  59529. }
  59530. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59531. {
  59532. keyWidth = widthInPixels;
  59533. resized();
  59534. }
  59535. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59536. {
  59537. if (orientation != newOrientation)
  59538. {
  59539. orientation = newOrientation;
  59540. resized();
  59541. }
  59542. }
  59543. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59544. const int highestNote)
  59545. {
  59546. jassert (lowestNote >= 0 && lowestNote <= 127);
  59547. jassert (highestNote >= 0 && highestNote <= 127);
  59548. jassert (lowestNote <= highestNote);
  59549. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59550. {
  59551. rangeStart = jlimit (0, 127, lowestNote);
  59552. rangeEnd = jlimit (0, 127, highestNote);
  59553. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59554. resized();
  59555. }
  59556. }
  59557. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59558. {
  59559. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59560. if (noteNumber != firstKey)
  59561. {
  59562. firstKey = noteNumber;
  59563. sendChangeMessage (this);
  59564. resized();
  59565. }
  59566. }
  59567. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59568. {
  59569. if (canScroll != canScroll_)
  59570. {
  59571. canScroll = canScroll_;
  59572. resized();
  59573. }
  59574. }
  59575. void MidiKeyboardComponent::colourChanged()
  59576. {
  59577. repaint();
  59578. }
  59579. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59580. {
  59581. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59582. if (midiChannel != midiChannelNumber)
  59583. {
  59584. resetAnyKeysInUse();
  59585. midiChannel = jlimit (1, 16, midiChannelNumber);
  59586. }
  59587. }
  59588. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59589. {
  59590. midiInChannelMask = midiChannelMask;
  59591. triggerAsyncUpdate();
  59592. }
  59593. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59594. {
  59595. velocity = jlimit (0.0f, 1.0f, velocity_);
  59596. useMousePositionForVelocity = useMousePositionForVelocity_;
  59597. }
  59598. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59599. {
  59600. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59601. static const float blackNoteWidth = 0.7f;
  59602. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59603. 1.0f, 2 - blackNoteWidth * 0.4f,
  59604. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59605. 4.0f, 5 - blackNoteWidth * 0.5f,
  59606. 5.0f, 6 - blackNoteWidth * 0.3f,
  59607. 6.0f };
  59608. static const float widths[] = { 1.0f, blackNoteWidth,
  59609. 1.0f, blackNoteWidth,
  59610. 1.0f, 1.0f, blackNoteWidth,
  59611. 1.0f, blackNoteWidth,
  59612. 1.0f, blackNoteWidth,
  59613. 1.0f };
  59614. const int octave = midiNoteNumber / 12;
  59615. const int note = midiNoteNumber % 12;
  59616. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59617. w = roundToInt (widths [note] * keyWidth);
  59618. }
  59619. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59620. {
  59621. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59622. int rx, rw;
  59623. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59624. x -= xOffset + rx;
  59625. }
  59626. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59627. {
  59628. int x, y;
  59629. getKeyPos (midiNoteNumber, x, y);
  59630. return x;
  59631. }
  59632. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59633. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59634. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59635. {
  59636. if (! reallyContains (pos.getX(), pos.getY(), false))
  59637. return -1;
  59638. Point<int> p (pos);
  59639. if (orientation != horizontalKeyboard)
  59640. {
  59641. p = Point<int> (p.getY(), p.getX());
  59642. if (orientation == verticalKeyboardFacingLeft)
  59643. p = Point<int> (p.getX(), getWidth() - p.getY());
  59644. else
  59645. p = Point<int> (getHeight() - p.getX(), p.getY());
  59646. }
  59647. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59648. }
  59649. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59650. {
  59651. if (pos.getY() < blackNoteLength)
  59652. {
  59653. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59654. {
  59655. for (int i = 0; i < 5; ++i)
  59656. {
  59657. const int note = octaveStart + blackNotes [i];
  59658. if (note >= rangeStart && note <= rangeEnd)
  59659. {
  59660. int kx, kw;
  59661. getKeyPos (note, kx, kw);
  59662. kx += xOffset;
  59663. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59664. {
  59665. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59666. return note;
  59667. }
  59668. }
  59669. }
  59670. }
  59671. }
  59672. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59673. {
  59674. for (int i = 0; i < 7; ++i)
  59675. {
  59676. const int note = octaveStart + whiteNotes [i];
  59677. if (note >= rangeStart && note <= rangeEnd)
  59678. {
  59679. int kx, kw;
  59680. getKeyPos (note, kx, kw);
  59681. kx += xOffset;
  59682. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59683. {
  59684. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59685. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59686. return note;
  59687. }
  59688. }
  59689. }
  59690. }
  59691. mousePositionVelocity = 0;
  59692. return -1;
  59693. }
  59694. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59695. {
  59696. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59697. {
  59698. int x, w;
  59699. getKeyPos (noteNum, x, w);
  59700. if (orientation == horizontalKeyboard)
  59701. repaint (x, 0, w, getHeight());
  59702. else if (orientation == verticalKeyboardFacingLeft)
  59703. repaint (0, x, getWidth(), w);
  59704. else if (orientation == verticalKeyboardFacingRight)
  59705. repaint (0, getHeight() - x - w, getWidth(), w);
  59706. }
  59707. }
  59708. void MidiKeyboardComponent::paint (Graphics& g)
  59709. {
  59710. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59711. const Colour lineColour (findColour (keySeparatorLineColourId));
  59712. const Colour textColour (findColour (textLabelColourId));
  59713. int x, w, octave;
  59714. for (octave = 0; octave < 128; octave += 12)
  59715. {
  59716. for (int white = 0; white < 7; ++white)
  59717. {
  59718. const int noteNum = octave + whiteNotes [white];
  59719. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59720. {
  59721. getKeyPos (noteNum, x, w);
  59722. if (orientation == horizontalKeyboard)
  59723. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59724. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59725. noteUnderMouse == noteNum,
  59726. lineColour, textColour);
  59727. else if (orientation == verticalKeyboardFacingLeft)
  59728. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59729. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59730. noteUnderMouse == noteNum,
  59731. lineColour, textColour);
  59732. else if (orientation == verticalKeyboardFacingRight)
  59733. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59734. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59735. noteUnderMouse == noteNum,
  59736. lineColour, textColour);
  59737. }
  59738. }
  59739. }
  59740. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59741. if (orientation == verticalKeyboardFacingLeft)
  59742. {
  59743. x1 = getWidth() - 1.0f;
  59744. x2 = getWidth() - 5.0f;
  59745. }
  59746. else if (orientation == verticalKeyboardFacingRight)
  59747. x2 = 5.0f;
  59748. else
  59749. y2 = 5.0f;
  59750. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  59751. Colours::transparentBlack, x2, y2, false));
  59752. getKeyPos (rangeEnd, x, w);
  59753. x += w;
  59754. if (orientation == verticalKeyboardFacingLeft)
  59755. g.fillRect (getWidth() - 5, 0, 5, x);
  59756. else if (orientation == verticalKeyboardFacingRight)
  59757. g.fillRect (0, 0, 5, x);
  59758. else
  59759. g.fillRect (0, 0, x, 5);
  59760. g.setColour (lineColour);
  59761. if (orientation == verticalKeyboardFacingLeft)
  59762. g.fillRect (0, 0, 1, x);
  59763. else if (orientation == verticalKeyboardFacingRight)
  59764. g.fillRect (getWidth() - 1, 0, 1, x);
  59765. else
  59766. g.fillRect (0, getHeight() - 1, x, 1);
  59767. const Colour blackNoteColour (findColour (blackNoteColourId));
  59768. for (octave = 0; octave < 128; octave += 12)
  59769. {
  59770. for (int black = 0; black < 5; ++black)
  59771. {
  59772. const int noteNum = octave + blackNotes [black];
  59773. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59774. {
  59775. getKeyPos (noteNum, x, w);
  59776. if (orientation == horizontalKeyboard)
  59777. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  59778. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59779. noteUnderMouse == noteNum,
  59780. blackNoteColour);
  59781. else if (orientation == verticalKeyboardFacingLeft)
  59782. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  59783. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59784. noteUnderMouse == noteNum,
  59785. blackNoteColour);
  59786. else if (orientation == verticalKeyboardFacingRight)
  59787. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  59788. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59789. noteUnderMouse == noteNum,
  59790. blackNoteColour);
  59791. }
  59792. }
  59793. }
  59794. }
  59795. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  59796. Graphics& g, int x, int y, int w, int h,
  59797. bool isDown, bool isOver,
  59798. const Colour& lineColour,
  59799. const Colour& textColour)
  59800. {
  59801. Colour c (Colours::transparentWhite);
  59802. if (isDown)
  59803. c = findColour (keyDownOverlayColourId);
  59804. if (isOver)
  59805. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59806. g.setColour (c);
  59807. g.fillRect (x, y, w, h);
  59808. const String text (getWhiteNoteText (midiNoteNumber));
  59809. if (! text.isEmpty())
  59810. {
  59811. g.setColour (textColour);
  59812. Font f (jmin (12.0f, keyWidth * 0.9f));
  59813. f.setHorizontalScale (0.8f);
  59814. g.setFont (f);
  59815. Justification justification (Justification::centredBottom);
  59816. if (orientation == verticalKeyboardFacingLeft)
  59817. justification = Justification::centredLeft;
  59818. else if (orientation == verticalKeyboardFacingRight)
  59819. justification = Justification::centredRight;
  59820. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  59821. }
  59822. g.setColour (lineColour);
  59823. if (orientation == horizontalKeyboard)
  59824. g.fillRect (x, y, 1, h);
  59825. else if (orientation == verticalKeyboardFacingLeft)
  59826. g.fillRect (x, y, w, 1);
  59827. else if (orientation == verticalKeyboardFacingRight)
  59828. g.fillRect (x, y + h - 1, w, 1);
  59829. if (midiNoteNumber == rangeEnd)
  59830. {
  59831. if (orientation == horizontalKeyboard)
  59832. g.fillRect (x + w, y, 1, h);
  59833. else if (orientation == verticalKeyboardFacingLeft)
  59834. g.fillRect (x, y + h, w, 1);
  59835. else if (orientation == verticalKeyboardFacingRight)
  59836. g.fillRect (x, y - 1, w, 1);
  59837. }
  59838. }
  59839. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  59840. Graphics& g, int x, int y, int w, int h,
  59841. bool isDown, bool isOver,
  59842. const Colour& noteFillColour)
  59843. {
  59844. Colour c (noteFillColour);
  59845. if (isDown)
  59846. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  59847. if (isOver)
  59848. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59849. g.setColour (c);
  59850. g.fillRect (x, y, w, h);
  59851. if (isDown)
  59852. {
  59853. g.setColour (noteFillColour);
  59854. g.drawRect (x, y, w, h);
  59855. }
  59856. else
  59857. {
  59858. const int xIndent = jmax (1, jmin (w, h) / 8);
  59859. g.setColour (c.brighter());
  59860. if (orientation == horizontalKeyboard)
  59861. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  59862. else if (orientation == verticalKeyboardFacingLeft)
  59863. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  59864. else if (orientation == verticalKeyboardFacingRight)
  59865. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  59866. }
  59867. }
  59868. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  59869. {
  59870. octaveNumForMiddleC = octaveNumForMiddleC_;
  59871. repaint();
  59872. }
  59873. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  59874. {
  59875. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  59876. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  59877. return String::empty;
  59878. }
  59879. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  59880. const bool isMouseOver,
  59881. const bool isButtonDown,
  59882. const bool movesOctavesUp)
  59883. {
  59884. g.fillAll (findColour (upDownButtonBackgroundColourId));
  59885. float angle;
  59886. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  59887. angle = movesOctavesUp ? 0.0f : 0.5f;
  59888. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  59889. angle = movesOctavesUp ? 0.25f : 0.75f;
  59890. else
  59891. angle = movesOctavesUp ? 0.75f : 0.25f;
  59892. Path path;
  59893. path.lineTo (0.0f, 1.0f);
  59894. path.lineTo (1.0f, 0.5f);
  59895. path.closeSubPath();
  59896. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  59897. g.setColour (findColour (upDownButtonArrowColourId)
  59898. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  59899. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  59900. w - 2.0f,
  59901. h - 2.0f,
  59902. true));
  59903. }
  59904. void MidiKeyboardComponent::resized()
  59905. {
  59906. int w = getWidth();
  59907. int h = getHeight();
  59908. if (w > 0 && h > 0)
  59909. {
  59910. if (orientation != horizontalKeyboard)
  59911. swapVariables (w, h);
  59912. blackNoteLength = roundToInt (h * 0.7f);
  59913. int kx2, kw2;
  59914. getKeyPos (rangeEnd, kx2, kw2);
  59915. kx2 += kw2;
  59916. if (firstKey != rangeStart)
  59917. {
  59918. int kx1, kw1;
  59919. getKeyPos (rangeStart, kx1, kw1);
  59920. if (kx2 - kx1 <= w)
  59921. {
  59922. firstKey = rangeStart;
  59923. sendChangeMessage (this);
  59924. repaint();
  59925. }
  59926. }
  59927. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  59928. scrollDown->setVisible (showScrollButtons);
  59929. scrollUp->setVisible (showScrollButtons);
  59930. xOffset = 0;
  59931. if (showScrollButtons)
  59932. {
  59933. const int scrollButtonW = jmin (12, w / 2);
  59934. if (orientation == horizontalKeyboard)
  59935. {
  59936. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  59937. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  59938. }
  59939. else if (orientation == verticalKeyboardFacingLeft)
  59940. {
  59941. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  59942. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  59943. }
  59944. else if (orientation == verticalKeyboardFacingRight)
  59945. {
  59946. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  59947. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  59948. }
  59949. int endOfLastKey, kw;
  59950. getKeyPos (rangeEnd, endOfLastKey, kw);
  59951. endOfLastKey += kw;
  59952. float mousePositionVelocity;
  59953. const int spaceAvailable = w - scrollButtonW * 2;
  59954. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  59955. if (lastStartKey >= 0 && firstKey > lastStartKey)
  59956. {
  59957. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  59958. sendChangeMessage (this);
  59959. }
  59960. int newOffset = 0;
  59961. getKeyPos (firstKey, newOffset, kw);
  59962. xOffset = newOffset - scrollButtonW;
  59963. }
  59964. else
  59965. {
  59966. firstKey = rangeStart;
  59967. }
  59968. timerCallback();
  59969. repaint();
  59970. }
  59971. }
  59972. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  59973. {
  59974. triggerAsyncUpdate();
  59975. }
  59976. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  59977. {
  59978. triggerAsyncUpdate();
  59979. }
  59980. void MidiKeyboardComponent::handleAsyncUpdate()
  59981. {
  59982. for (int i = rangeStart; i <= rangeEnd; ++i)
  59983. {
  59984. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  59985. {
  59986. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  59987. repaintNote (i);
  59988. }
  59989. }
  59990. }
  59991. void MidiKeyboardComponent::resetAnyKeysInUse()
  59992. {
  59993. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  59994. {
  59995. state.allNotesOff (midiChannel);
  59996. keysPressed.clear();
  59997. mouseDownNote = -1;
  59998. }
  59999. }
  60000. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60001. {
  60002. float mousePositionVelocity = 0.0f;
  60003. const int newNote = (mouseDragging || isMouseOver())
  60004. ? xyToNote (pos, mousePositionVelocity) : -1;
  60005. if (noteUnderMouse != newNote)
  60006. {
  60007. if (mouseDownNote >= 0)
  60008. {
  60009. state.noteOff (midiChannel, mouseDownNote);
  60010. mouseDownNote = -1;
  60011. }
  60012. if (mouseDragging && newNote >= 0)
  60013. {
  60014. if (! useMousePositionForVelocity)
  60015. mousePositionVelocity = 1.0f;
  60016. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60017. mouseDownNote = newNote;
  60018. }
  60019. repaintNote (noteUnderMouse);
  60020. noteUnderMouse = newNote;
  60021. repaintNote (noteUnderMouse);
  60022. }
  60023. else if (mouseDownNote >= 0 && ! mouseDragging)
  60024. {
  60025. state.noteOff (midiChannel, mouseDownNote);
  60026. mouseDownNote = -1;
  60027. }
  60028. }
  60029. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60030. {
  60031. updateNoteUnderMouse (e.getPosition());
  60032. stopTimer();
  60033. }
  60034. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60035. {
  60036. float mousePositionVelocity;
  60037. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60038. if (newNote >= 0)
  60039. mouseDraggedToKey (newNote, e);
  60040. updateNoteUnderMouse (e.getPosition());
  60041. }
  60042. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60043. {
  60044. return true;
  60045. }
  60046. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60047. {
  60048. }
  60049. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60050. {
  60051. float mousePositionVelocity;
  60052. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60053. mouseDragging = false;
  60054. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60055. {
  60056. repaintNote (noteUnderMouse);
  60057. noteUnderMouse = -1;
  60058. mouseDragging = true;
  60059. updateNoteUnderMouse (e.getPosition());
  60060. startTimer (500);
  60061. }
  60062. }
  60063. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60064. {
  60065. mouseDragging = false;
  60066. updateNoteUnderMouse (e.getPosition());
  60067. stopTimer();
  60068. }
  60069. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60070. {
  60071. updateNoteUnderMouse (e.getPosition());
  60072. }
  60073. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60074. {
  60075. updateNoteUnderMouse (e.getPosition());
  60076. }
  60077. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60078. {
  60079. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60080. }
  60081. void MidiKeyboardComponent::timerCallback()
  60082. {
  60083. updateNoteUnderMouse (getMouseXYRelative());
  60084. }
  60085. void MidiKeyboardComponent::clearKeyMappings()
  60086. {
  60087. resetAnyKeysInUse();
  60088. keyPressNotes.clear();
  60089. keyPresses.clear();
  60090. }
  60091. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60092. const int midiNoteOffsetFromC)
  60093. {
  60094. removeKeyPressForNote (midiNoteOffsetFromC);
  60095. keyPressNotes.add (midiNoteOffsetFromC);
  60096. keyPresses.add (key);
  60097. }
  60098. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60099. {
  60100. for (int i = keyPressNotes.size(); --i >= 0;)
  60101. {
  60102. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60103. {
  60104. keyPressNotes.remove (i);
  60105. keyPresses.remove (i);
  60106. }
  60107. }
  60108. }
  60109. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60110. {
  60111. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60112. keyMappingOctave = newOctaveNumber;
  60113. }
  60114. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60115. {
  60116. bool keyPressUsed = false;
  60117. for (int i = keyPresses.size(); --i >= 0;)
  60118. {
  60119. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60120. if (keyPresses.getReference(i).isCurrentlyDown())
  60121. {
  60122. if (! keysPressed [note])
  60123. {
  60124. keysPressed.setBit (note);
  60125. state.noteOn (midiChannel, note, velocity);
  60126. keyPressUsed = true;
  60127. }
  60128. }
  60129. else
  60130. {
  60131. if (keysPressed [note])
  60132. {
  60133. keysPressed.clearBit (note);
  60134. state.noteOff (midiChannel, note);
  60135. keyPressUsed = true;
  60136. }
  60137. }
  60138. }
  60139. return keyPressUsed;
  60140. }
  60141. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60142. {
  60143. resetAnyKeysInUse();
  60144. }
  60145. END_JUCE_NAMESPACE
  60146. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60147. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60148. #if JUCE_OPENGL
  60149. BEGIN_JUCE_NAMESPACE
  60150. extern void juce_glViewport (const int w, const int h);
  60151. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60152. const int alphaBits_,
  60153. const int depthBufferBits_,
  60154. const int stencilBufferBits_)
  60155. : redBits (bitsPerRGBComponent),
  60156. greenBits (bitsPerRGBComponent),
  60157. blueBits (bitsPerRGBComponent),
  60158. alphaBits (alphaBits_),
  60159. depthBufferBits (depthBufferBits_),
  60160. stencilBufferBits (stencilBufferBits_),
  60161. accumulationBufferRedBits (0),
  60162. accumulationBufferGreenBits (0),
  60163. accumulationBufferBlueBits (0),
  60164. accumulationBufferAlphaBits (0),
  60165. fullSceneAntiAliasingNumSamples (0)
  60166. {
  60167. }
  60168. OpenGLPixelFormat::OpenGLPixelFormat (const OpenGLPixelFormat& other)
  60169. : redBits (other.redBits),
  60170. greenBits (other.greenBits),
  60171. blueBits (other.blueBits),
  60172. alphaBits (other.alphaBits),
  60173. depthBufferBits (other.depthBufferBits),
  60174. stencilBufferBits (other.stencilBufferBits),
  60175. accumulationBufferRedBits (other.accumulationBufferRedBits),
  60176. accumulationBufferGreenBits (other.accumulationBufferGreenBits),
  60177. accumulationBufferBlueBits (other.accumulationBufferBlueBits),
  60178. accumulationBufferAlphaBits (other.accumulationBufferAlphaBits),
  60179. fullSceneAntiAliasingNumSamples (other.fullSceneAntiAliasingNumSamples)
  60180. {
  60181. }
  60182. OpenGLPixelFormat& OpenGLPixelFormat::operator= (const OpenGLPixelFormat& other)
  60183. {
  60184. redBits = other.redBits;
  60185. greenBits = other.greenBits;
  60186. blueBits = other.blueBits;
  60187. alphaBits = other.alphaBits;
  60188. depthBufferBits = other.depthBufferBits;
  60189. stencilBufferBits = other.stencilBufferBits;
  60190. accumulationBufferRedBits = other.accumulationBufferRedBits;
  60191. accumulationBufferGreenBits = other.accumulationBufferGreenBits;
  60192. accumulationBufferBlueBits = other.accumulationBufferBlueBits;
  60193. accumulationBufferAlphaBits = other.accumulationBufferAlphaBits;
  60194. fullSceneAntiAliasingNumSamples = other.fullSceneAntiAliasingNumSamples;
  60195. return *this;
  60196. }
  60197. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const
  60198. {
  60199. return redBits == other.redBits
  60200. && greenBits == other.greenBits
  60201. && blueBits == other.blueBits
  60202. && alphaBits == other.alphaBits
  60203. && depthBufferBits == other.depthBufferBits
  60204. && stencilBufferBits == other.stencilBufferBits
  60205. && accumulationBufferRedBits == other.accumulationBufferRedBits
  60206. && accumulationBufferGreenBits == other.accumulationBufferGreenBits
  60207. && accumulationBufferBlueBits == other.accumulationBufferBlueBits
  60208. && accumulationBufferAlphaBits == other.accumulationBufferAlphaBits
  60209. && fullSceneAntiAliasingNumSamples == other.fullSceneAntiAliasingNumSamples;
  60210. }
  60211. static VoidArray knownContexts;
  60212. OpenGLContext::OpenGLContext() throw()
  60213. {
  60214. knownContexts.add (this);
  60215. }
  60216. OpenGLContext::~OpenGLContext()
  60217. {
  60218. knownContexts.removeValue (this);
  60219. }
  60220. OpenGLContext* OpenGLContext::getCurrentContext()
  60221. {
  60222. for (int i = knownContexts.size(); --i >= 0;)
  60223. {
  60224. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60225. if (oglc->isActive())
  60226. return oglc;
  60227. }
  60228. return 0;
  60229. }
  60230. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60231. {
  60232. public:
  60233. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60234. : ComponentMovementWatcher (owner_),
  60235. owner (owner_),
  60236. wasShowing (false)
  60237. {
  60238. }
  60239. ~OpenGLComponentWatcher() {}
  60240. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60241. {
  60242. owner->updateContextPosition();
  60243. }
  60244. void componentPeerChanged()
  60245. {
  60246. const ScopedLock sl (owner->getContextLock());
  60247. owner->deleteContext();
  60248. }
  60249. void componentVisibilityChanged (Component&)
  60250. {
  60251. const bool isShowingNow = owner->isShowing();
  60252. if (wasShowing != isShowingNow)
  60253. {
  60254. wasShowing = isShowingNow;
  60255. owner->updateContextPosition();
  60256. }
  60257. }
  60258. juce_UseDebuggingNewOperator
  60259. private:
  60260. OpenGLComponent* const owner;
  60261. bool wasShowing;
  60262. };
  60263. OpenGLComponent::OpenGLComponent (const OpenGLType type_)
  60264. : type (type_),
  60265. contextToShareListsWith (0),
  60266. needToUpdateViewport (true)
  60267. {
  60268. setOpaque (true);
  60269. componentWatcher = new OpenGLComponentWatcher (this);
  60270. }
  60271. OpenGLComponent::~OpenGLComponent()
  60272. {
  60273. deleteContext();
  60274. componentWatcher = 0;
  60275. }
  60276. void OpenGLComponent::deleteContext()
  60277. {
  60278. const ScopedLock sl (contextLock);
  60279. context = 0;
  60280. }
  60281. void OpenGLComponent::updateContextPosition()
  60282. {
  60283. needToUpdateViewport = true;
  60284. if (getWidth() > 0 && getHeight() > 0)
  60285. {
  60286. Component* const topComp = getTopLevelComponent();
  60287. if (topComp->getPeer() != 0)
  60288. {
  60289. const ScopedLock sl (contextLock);
  60290. if (context != 0)
  60291. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60292. getScreenY() - topComp->getScreenY(),
  60293. getWidth(),
  60294. getHeight(),
  60295. topComp->getHeight());
  60296. }
  60297. }
  60298. }
  60299. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60300. {
  60301. OpenGLPixelFormat pf;
  60302. const ScopedLock sl (contextLock);
  60303. if (context != 0)
  60304. pf = context->getPixelFormat();
  60305. return pf;
  60306. }
  60307. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60308. {
  60309. if (! (preferredPixelFormat == formatToUse))
  60310. {
  60311. const ScopedLock sl (contextLock);
  60312. deleteContext();
  60313. preferredPixelFormat = formatToUse;
  60314. }
  60315. }
  60316. void OpenGLComponent::shareWith (OpenGLContext* c)
  60317. {
  60318. if (contextToShareListsWith != c)
  60319. {
  60320. const ScopedLock sl (contextLock);
  60321. deleteContext();
  60322. contextToShareListsWith = c;
  60323. }
  60324. }
  60325. bool OpenGLComponent::makeCurrentContextActive()
  60326. {
  60327. if (context == 0)
  60328. {
  60329. const ScopedLock sl (contextLock);
  60330. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60331. {
  60332. context = createContext();
  60333. if (context != 0)
  60334. {
  60335. updateContextPosition();
  60336. if (context->makeActive())
  60337. newOpenGLContextCreated();
  60338. }
  60339. }
  60340. }
  60341. return context != 0 && context->makeActive();
  60342. }
  60343. void OpenGLComponent::makeCurrentContextInactive()
  60344. {
  60345. if (context != 0)
  60346. context->makeInactive();
  60347. }
  60348. bool OpenGLComponent::isActiveContext() const throw()
  60349. {
  60350. return context != 0 && context->isActive();
  60351. }
  60352. void OpenGLComponent::swapBuffers()
  60353. {
  60354. if (context != 0)
  60355. context->swapBuffers();
  60356. }
  60357. void OpenGLComponent::paint (Graphics&)
  60358. {
  60359. if (renderAndSwapBuffers())
  60360. {
  60361. ComponentPeer* const peer = getPeer();
  60362. if (peer != 0)
  60363. {
  60364. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60365. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60366. }
  60367. }
  60368. }
  60369. bool OpenGLComponent::renderAndSwapBuffers()
  60370. {
  60371. const ScopedLock sl (contextLock);
  60372. if (! makeCurrentContextActive())
  60373. return false;
  60374. if (needToUpdateViewport)
  60375. {
  60376. needToUpdateViewport = false;
  60377. juce_glViewport (getWidth(), getHeight());
  60378. }
  60379. renderOpenGL();
  60380. swapBuffers();
  60381. return true;
  60382. }
  60383. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60384. {
  60385. Component::internalRepaint (x, y, w, h);
  60386. if (context != 0)
  60387. context->repaint();
  60388. }
  60389. END_JUCE_NAMESPACE
  60390. #endif
  60391. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60392. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60393. BEGIN_JUCE_NAMESPACE
  60394. PreferencesPanel::PreferencesPanel()
  60395. : buttonSize (70)
  60396. {
  60397. }
  60398. PreferencesPanel::~PreferencesPanel()
  60399. {
  60400. currentPage = 0;
  60401. deleteAllChildren();
  60402. }
  60403. void PreferencesPanel::addSettingsPage (const String& title,
  60404. const Drawable* icon,
  60405. const Drawable* overIcon,
  60406. const Drawable* downIcon)
  60407. {
  60408. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60409. button->setImages (icon, overIcon, downIcon);
  60410. button->setRadioGroupId (1);
  60411. button->addButtonListener (this);
  60412. button->setClickingTogglesState (true);
  60413. button->setWantsKeyboardFocus (false);
  60414. addAndMakeVisible (button);
  60415. resized();
  60416. if (currentPage == 0)
  60417. setCurrentPage (title);
  60418. }
  60419. void PreferencesPanel::addSettingsPage (const String& title,
  60420. const char* imageData,
  60421. const int imageDataSize)
  60422. {
  60423. DrawableImage icon, iconOver, iconDown;
  60424. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60425. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60426. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60427. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60428. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60429. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60430. }
  60431. class PrefsDialogWindow : public DialogWindow
  60432. {
  60433. public:
  60434. PrefsDialogWindow (const String& dialogtitle,
  60435. const Colour& backgroundColour)
  60436. : DialogWindow (dialogtitle, backgroundColour, true)
  60437. {
  60438. }
  60439. ~PrefsDialogWindow()
  60440. {
  60441. }
  60442. void closeButtonPressed()
  60443. {
  60444. exitModalState (0);
  60445. }
  60446. private:
  60447. PrefsDialogWindow (const PrefsDialogWindow&);
  60448. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60449. };
  60450. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60451. int dialogWidth,
  60452. int dialogHeight,
  60453. const Colour& backgroundColour)
  60454. {
  60455. setSize (dialogWidth, dialogHeight);
  60456. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60457. dw.setContentComponent (this, true, true);
  60458. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60459. dw.runModalLoop();
  60460. dw.setContentComponent (0, false, false);
  60461. }
  60462. void PreferencesPanel::resized()
  60463. {
  60464. int x = 0;
  60465. for (int i = 0; i < getNumChildComponents(); ++i)
  60466. {
  60467. Component* c = getChildComponent (i);
  60468. if (dynamic_cast <DrawableButton*> (c) == 0)
  60469. {
  60470. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60471. }
  60472. else
  60473. {
  60474. c->setBounds (x, 0, buttonSize, buttonSize);
  60475. x += buttonSize;
  60476. }
  60477. }
  60478. }
  60479. void PreferencesPanel::paint (Graphics& g)
  60480. {
  60481. g.setColour (Colours::grey);
  60482. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60483. }
  60484. void PreferencesPanel::setCurrentPage (const String& pageName)
  60485. {
  60486. if (currentPageName != pageName)
  60487. {
  60488. currentPageName = pageName;
  60489. currentPage = 0;
  60490. currentPage = createComponentForPage (pageName);
  60491. if (currentPage != 0)
  60492. {
  60493. addAndMakeVisible (currentPage);
  60494. currentPage->toBack();
  60495. resized();
  60496. }
  60497. for (int i = 0; i < getNumChildComponents(); ++i)
  60498. {
  60499. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60500. if (db != 0 && db->getName() == pageName)
  60501. {
  60502. db->setToggleState (true, false);
  60503. break;
  60504. }
  60505. }
  60506. }
  60507. }
  60508. void PreferencesPanel::buttonClicked (Button*)
  60509. {
  60510. for (int i = 0; i < getNumChildComponents(); ++i)
  60511. {
  60512. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60513. if (db != 0 && db->getToggleState())
  60514. {
  60515. setCurrentPage (db->getName());
  60516. break;
  60517. }
  60518. }
  60519. }
  60520. END_JUCE_NAMESPACE
  60521. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60522. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60523. #if JUCE_WINDOWS || JUCE_LINUX
  60524. BEGIN_JUCE_NAMESPACE
  60525. SystemTrayIconComponent::SystemTrayIconComponent()
  60526. {
  60527. addToDesktop (0);
  60528. }
  60529. SystemTrayIconComponent::~SystemTrayIconComponent()
  60530. {
  60531. }
  60532. END_JUCE_NAMESPACE
  60533. #endif
  60534. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60535. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60536. BEGIN_JUCE_NAMESPACE
  60537. class AlertWindowTextEditor : public TextEditor
  60538. {
  60539. public:
  60540. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60541. : TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0)
  60542. {
  60543. setSelectAllWhenFocused (true);
  60544. }
  60545. ~AlertWindowTextEditor()
  60546. {
  60547. }
  60548. void returnPressed()
  60549. {
  60550. // pass these up the component hierarchy to be trigger the buttons
  60551. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, '\n'));
  60552. }
  60553. void escapePressed()
  60554. {
  60555. // pass these up the component hierarchy to be trigger the buttons
  60556. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60557. }
  60558. private:
  60559. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60560. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60561. static juce_wchar getDefaultPasswordChar() throw()
  60562. {
  60563. #if JUCE_LINUX
  60564. return 0x2022;
  60565. #else
  60566. return 0x25cf;
  60567. #endif
  60568. }
  60569. };
  60570. AlertWindow::AlertWindow (const String& title,
  60571. const String& message,
  60572. AlertIconType iconType,
  60573. Component* associatedComponent_)
  60574. : TopLevelWindow (title, true),
  60575. alertIconType (iconType),
  60576. associatedComponent (associatedComponent_)
  60577. {
  60578. if (message.isEmpty())
  60579. text = " "; // to force an update if the message is empty
  60580. setMessage (message);
  60581. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60582. {
  60583. Component* const c = Desktop::getInstance().getComponent (i);
  60584. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60585. {
  60586. setAlwaysOnTop (true);
  60587. break;
  60588. }
  60589. }
  60590. if (JUCEApplication::getInstance() == 0)
  60591. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60592. lookAndFeelChanged();
  60593. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60594. }
  60595. AlertWindow::~AlertWindow()
  60596. {
  60597. for (int i = customComps.size(); --i >= 0;)
  60598. removeChildComponent ((Component*) customComps[i]);
  60599. deleteAllChildren();
  60600. }
  60601. void AlertWindow::userTriedToCloseWindow()
  60602. {
  60603. exitModalState (0);
  60604. }
  60605. void AlertWindow::setMessage (const String& message)
  60606. {
  60607. const String newMessage (message.substring (0, 2048));
  60608. if (text != newMessage)
  60609. {
  60610. text = newMessage;
  60611. font.setHeight (15.0f);
  60612. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60613. textLayout.setText (getName() + "\n\n", titleFont);
  60614. textLayout.appendText (text, font);
  60615. updateLayout (true);
  60616. repaint();
  60617. }
  60618. }
  60619. void AlertWindow::buttonClicked (Button* button)
  60620. {
  60621. for (int i = 0; i < buttons.size(); i++)
  60622. {
  60623. TextButton* const c = (TextButton*) buttons[i];
  60624. if (button->getName() == c->getName())
  60625. {
  60626. if (c->getParentComponent() != 0)
  60627. c->getParentComponent()->exitModalState (c->getCommandID());
  60628. break;
  60629. }
  60630. }
  60631. }
  60632. void AlertWindow::addButton (const String& name,
  60633. const int returnValue,
  60634. const KeyPress& shortcutKey1,
  60635. const KeyPress& shortcutKey2)
  60636. {
  60637. TextButton* const b = new TextButton (name, String::empty);
  60638. b->setWantsKeyboardFocus (true);
  60639. b->setMouseClickGrabsKeyboardFocus (false);
  60640. b->setCommandToTrigger (0, returnValue, false);
  60641. b->addShortcut (shortcutKey1);
  60642. b->addShortcut (shortcutKey2);
  60643. b->addButtonListener (this);
  60644. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60645. addAndMakeVisible (b, 0);
  60646. buttons.add (b);
  60647. updateLayout (false);
  60648. }
  60649. int AlertWindow::getNumButtons() const
  60650. {
  60651. return buttons.size();
  60652. }
  60653. void AlertWindow::addTextEditor (const String& name,
  60654. const String& initialContents,
  60655. const String& onScreenLabel,
  60656. const bool isPasswordBox)
  60657. {
  60658. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60659. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60660. tc->setFont (font);
  60661. tc->setText (initialContents);
  60662. tc->setCaretPosition (initialContents.length());
  60663. addAndMakeVisible (tc);
  60664. textBoxes.add (tc);
  60665. allComps.add (tc);
  60666. textboxNames.add (onScreenLabel);
  60667. updateLayout (false);
  60668. }
  60669. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60670. {
  60671. for (int i = textBoxes.size(); --i >= 0;)
  60672. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60673. return ((TextEditor*)textBoxes[i])->getText();
  60674. return String::empty;
  60675. }
  60676. void AlertWindow::addComboBox (const String& name,
  60677. const StringArray& items,
  60678. const String& onScreenLabel)
  60679. {
  60680. ComboBox* const cb = new ComboBox (name);
  60681. for (int i = 0; i < items.size(); ++i)
  60682. cb->addItem (items[i], i + 1);
  60683. addAndMakeVisible (cb);
  60684. cb->setSelectedItemIndex (0);
  60685. comboBoxes.add (cb);
  60686. allComps.add (cb);
  60687. comboBoxNames.add (onScreenLabel);
  60688. updateLayout (false);
  60689. }
  60690. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60691. {
  60692. for (int i = comboBoxes.size(); --i >= 0;)
  60693. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60694. return (ComboBox*) comboBoxes[i];
  60695. return 0;
  60696. }
  60697. class AlertTextComp : public TextEditor
  60698. {
  60699. public:
  60700. AlertTextComp (const String& message,
  60701. const Font& font)
  60702. {
  60703. setReadOnly (true);
  60704. setMultiLine (true, true);
  60705. setCaretVisible (false);
  60706. setScrollbarsShown (true);
  60707. lookAndFeelChanged();
  60708. setWantsKeyboardFocus (false);
  60709. setFont (font);
  60710. setText (message, false);
  60711. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60712. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60713. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60714. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60715. }
  60716. ~AlertTextComp()
  60717. {
  60718. }
  60719. int getPreferredWidth() const throw() { return bestWidth; }
  60720. void updateLayout (const int width)
  60721. {
  60722. TextLayout text;
  60723. text.appendText (getText(), getFont());
  60724. text.layout (width - 8, Justification::topLeft, true);
  60725. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60726. }
  60727. private:
  60728. int bestWidth;
  60729. AlertTextComp (const AlertTextComp&);
  60730. AlertTextComp& operator= (const AlertTextComp&);
  60731. };
  60732. void AlertWindow::addTextBlock (const String& text)
  60733. {
  60734. AlertTextComp* const c = new AlertTextComp (text, font);
  60735. textBlocks.add (c);
  60736. allComps.add (c);
  60737. addAndMakeVisible (c);
  60738. updateLayout (false);
  60739. }
  60740. void AlertWindow::addProgressBarComponent (double& progressValue)
  60741. {
  60742. ProgressBar* const pb = new ProgressBar (progressValue);
  60743. progressBars.add (pb);
  60744. allComps.add (pb);
  60745. addAndMakeVisible (pb);
  60746. updateLayout (false);
  60747. }
  60748. void AlertWindow::addCustomComponent (Component* const component)
  60749. {
  60750. customComps.add (component);
  60751. allComps.add (component);
  60752. addAndMakeVisible (component);
  60753. updateLayout (false);
  60754. }
  60755. int AlertWindow::getNumCustomComponents() const
  60756. {
  60757. return customComps.size();
  60758. }
  60759. Component* AlertWindow::getCustomComponent (const int index) const
  60760. {
  60761. return (Component*) customComps [index];
  60762. }
  60763. Component* AlertWindow::removeCustomComponent (const int index)
  60764. {
  60765. Component* const c = getCustomComponent (index);
  60766. if (c != 0)
  60767. {
  60768. customComps.removeValue (c);
  60769. allComps.removeValue (c);
  60770. removeChildComponent (c);
  60771. updateLayout (false);
  60772. }
  60773. return c;
  60774. }
  60775. void AlertWindow::paint (Graphics& g)
  60776. {
  60777. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60778. g.setColour (findColour (textColourId));
  60779. g.setFont (getLookAndFeel().getAlertWindowFont());
  60780. int i;
  60781. for (i = textBoxes.size(); --i >= 0;)
  60782. {
  60783. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60784. g.drawFittedText (textboxNames[i],
  60785. te->getX(), te->getY() - 14,
  60786. te->getWidth(), 14,
  60787. Justification::centredLeft, 1);
  60788. }
  60789. for (i = comboBoxNames.size(); --i >= 0;)
  60790. {
  60791. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  60792. g.drawFittedText (comboBoxNames[i],
  60793. cb->getX(), cb->getY() - 14,
  60794. cb->getWidth(), 14,
  60795. Justification::centredLeft, 1);
  60796. }
  60797. for (i = customComps.size(); --i >= 0;)
  60798. {
  60799. const Component* const c = (Component*) customComps[i];
  60800. g.drawFittedText (c->getName(),
  60801. c->getX(), c->getY() - 14,
  60802. c->getWidth(), 14,
  60803. Justification::centredLeft, 1);
  60804. }
  60805. }
  60806. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  60807. {
  60808. const int titleH = 24;
  60809. const int iconWidth = 80;
  60810. const int wid = jmax (font.getStringWidth (text),
  60811. font.getStringWidth (getName()));
  60812. const int sw = (int) sqrt (font.getHeight() * wid);
  60813. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  60814. const int edgeGap = 10;
  60815. const int labelHeight = 18;
  60816. int iconSpace;
  60817. if (alertIconType == NoIcon)
  60818. {
  60819. textLayout.layout (w, Justification::horizontallyCentred, true);
  60820. iconSpace = 0;
  60821. }
  60822. else
  60823. {
  60824. textLayout.layout (w, Justification::left, true);
  60825. iconSpace = iconWidth;
  60826. }
  60827. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  60828. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60829. const int textLayoutH = textLayout.getHeight();
  60830. const int textBottom = 16 + titleH + textLayoutH;
  60831. int h = textBottom;
  60832. int buttonW = 40;
  60833. int i;
  60834. for (i = 0; i < buttons.size(); ++i)
  60835. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  60836. w = jmax (buttonW, w);
  60837. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  60838. if (buttons.size() > 0)
  60839. h += 20 + ((TextButton*) buttons[0])->getHeight();
  60840. for (i = customComps.size(); --i >= 0;)
  60841. {
  60842. Component* c = (Component*) customComps[i];
  60843. w = jmax (w, (c->getWidth() * 100) / 80);
  60844. h += 10 + c->getHeight();
  60845. if (c->getName().isNotEmpty())
  60846. h += labelHeight;
  60847. }
  60848. for (i = textBlocks.size(); --i >= 0;)
  60849. {
  60850. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60851. w = jmax (w, ac->getPreferredWidth());
  60852. }
  60853. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60854. for (i = textBlocks.size(); --i >= 0;)
  60855. {
  60856. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60857. ac->updateLayout ((int) (w * 0.8f));
  60858. h += ac->getHeight() + 10;
  60859. }
  60860. h = jmin (getParentHeight() - 50, h);
  60861. if (onlyIncreaseSize)
  60862. {
  60863. w = jmax (w, getWidth());
  60864. h = jmax (h, getHeight());
  60865. }
  60866. if (! isVisible())
  60867. {
  60868. centreAroundComponent (associatedComponent, w, h);
  60869. }
  60870. else
  60871. {
  60872. const int cx = getX() + getWidth() / 2;
  60873. const int cy = getY() + getHeight() / 2;
  60874. setBounds (cx - w / 2,
  60875. cy - h / 2,
  60876. w, h);
  60877. }
  60878. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  60879. const int spacer = 16;
  60880. int totalWidth = -spacer;
  60881. for (i = buttons.size(); --i >= 0;)
  60882. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  60883. int x = (w - totalWidth) / 2;
  60884. int y = (int) (getHeight() * 0.95f);
  60885. for (i = 0; i < buttons.size(); ++i)
  60886. {
  60887. TextButton* const c = (TextButton*) buttons[i];
  60888. int ny = proportionOfHeight (0.95f) - c->getHeight();
  60889. c->setTopLeftPosition (x, ny);
  60890. if (ny < y)
  60891. y = ny;
  60892. x += c->getWidth() + spacer;
  60893. c->toFront (false);
  60894. }
  60895. y = textBottom;
  60896. for (i = 0; i < allComps.size(); ++i)
  60897. {
  60898. Component* const c = (Component*) allComps[i];
  60899. int h = 22;
  60900. const int comboIndex = comboBoxes.indexOf (c);
  60901. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  60902. y += labelHeight;
  60903. const int tbIndex = textBoxes.indexOf (c);
  60904. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  60905. y += labelHeight;
  60906. if (customComps.contains (c))
  60907. {
  60908. if (c->getName().isNotEmpty())
  60909. y += labelHeight;
  60910. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  60911. h = c->getHeight();
  60912. }
  60913. else if (textBlocks.contains (c))
  60914. {
  60915. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  60916. h = c->getHeight();
  60917. }
  60918. else
  60919. {
  60920. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  60921. }
  60922. y += h + 10;
  60923. }
  60924. setWantsKeyboardFocus (getNumChildComponents() == 0);
  60925. }
  60926. bool AlertWindow::containsAnyExtraComponents() const
  60927. {
  60928. return textBoxes.size()
  60929. + comboBoxes.size()
  60930. + progressBars.size()
  60931. + customComps.size() > 0;
  60932. }
  60933. void AlertWindow::mouseDown (const MouseEvent&)
  60934. {
  60935. dragger.startDraggingComponent (this, &constrainer);
  60936. }
  60937. void AlertWindow::mouseDrag (const MouseEvent& e)
  60938. {
  60939. dragger.dragComponent (this, e);
  60940. }
  60941. bool AlertWindow::keyPressed (const KeyPress& key)
  60942. {
  60943. for (int i = buttons.size(); --i >= 0;)
  60944. {
  60945. TextButton* const b = (TextButton*) buttons[i];
  60946. if (b->isRegisteredForShortcut (key))
  60947. {
  60948. b->triggerClick();
  60949. return true;
  60950. }
  60951. }
  60952. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  60953. {
  60954. exitModalState (0);
  60955. return true;
  60956. }
  60957. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  60958. {
  60959. ((TextButton*) buttons.getFirst())->triggerClick();
  60960. return true;
  60961. }
  60962. return false;
  60963. }
  60964. void AlertWindow::lookAndFeelChanged()
  60965. {
  60966. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  60967. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  60968. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  60969. }
  60970. int AlertWindow::getDesktopWindowStyleFlags() const
  60971. {
  60972. return getLookAndFeel().getAlertBoxWindowFlags();
  60973. }
  60974. struct AlertWindowInfo
  60975. {
  60976. String title, message, button1, button2, button3;
  60977. AlertWindow::AlertIconType iconType;
  60978. int numButtons;
  60979. Component::SafePointer<Component> associatedComponent;
  60980. int run() const
  60981. {
  60982. return (int) (pointer_sized_int)
  60983. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  60984. }
  60985. private:
  60986. int show() const
  60987. {
  60988. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  60989. : LookAndFeel::getDefaultLookAndFeel();
  60990. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  60991. iconType, numButtons, associatedComponent));
  60992. jassert (alertBox != 0); // you have to return one of these!
  60993. return alertBox->runModalLoop();
  60994. }
  60995. static void* showCallback (void* userData)
  60996. {
  60997. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  60998. }
  60999. };
  61000. void AlertWindow::showMessageBox (AlertIconType iconType,
  61001. const String& title,
  61002. const String& message,
  61003. const String& buttonText,
  61004. Component* associatedComponent)
  61005. {
  61006. AlertWindowInfo info;
  61007. info.title = title;
  61008. info.message = message;
  61009. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61010. info.iconType = iconType;
  61011. info.numButtons = 1;
  61012. info.associatedComponent = associatedComponent;
  61013. info.run();
  61014. }
  61015. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61016. const String& title,
  61017. const String& message,
  61018. const String& button1Text,
  61019. const String& button2Text,
  61020. Component* associatedComponent)
  61021. {
  61022. AlertWindowInfo info;
  61023. info.title = title;
  61024. info.message = message;
  61025. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61026. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61027. info.iconType = iconType;
  61028. info.numButtons = 2;
  61029. info.associatedComponent = associatedComponent;
  61030. return info.run() != 0;
  61031. }
  61032. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61033. const String& title,
  61034. const String& message,
  61035. const String& button1Text,
  61036. const String& button2Text,
  61037. const String& button3Text,
  61038. Component* associatedComponent)
  61039. {
  61040. AlertWindowInfo info;
  61041. info.title = title;
  61042. info.message = message;
  61043. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61044. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61045. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61046. info.iconType = iconType;
  61047. info.numButtons = 3;
  61048. info.associatedComponent = associatedComponent;
  61049. return info.run();
  61050. }
  61051. END_JUCE_NAMESPACE
  61052. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61053. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61054. BEGIN_JUCE_NAMESPACE
  61055. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61056. static VoidArray heavyweightPeers;
  61057. ComponentPeer::ComponentPeer (Component* const component_,
  61058. const int styleFlags_) throw()
  61059. : component (component_),
  61060. styleFlags (styleFlags_),
  61061. lastPaintTime (0),
  61062. constrainer (0),
  61063. lastDragAndDropCompUnderMouse (0),
  61064. fakeMouseMessageSent (false),
  61065. isWindowMinimised (false)
  61066. {
  61067. heavyweightPeers.add (this);
  61068. }
  61069. ComponentPeer::~ComponentPeer()
  61070. {
  61071. heavyweightPeers.removeValue (this);
  61072. Desktop::getInstance().triggerFocusCallback();
  61073. }
  61074. int ComponentPeer::getNumPeers() throw()
  61075. {
  61076. return heavyweightPeers.size();
  61077. }
  61078. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61079. {
  61080. return (ComponentPeer*) heavyweightPeers [index];
  61081. }
  61082. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61083. {
  61084. for (int i = heavyweightPeers.size(); --i >= 0;)
  61085. {
  61086. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61087. if (peer->getComponent() == component)
  61088. return peer;
  61089. }
  61090. return 0;
  61091. }
  61092. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61093. {
  61094. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61095. }
  61096. void ComponentPeer::updateCurrentModifiers() throw()
  61097. {
  61098. ModifierKeys::updateCurrentModifiers();
  61099. }
  61100. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61101. {
  61102. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61103. jassert (mouse != 0); // not enough sources!
  61104. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61105. }
  61106. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61107. {
  61108. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61109. jassert (mouse != 0); // not enough sources!
  61110. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61111. }
  61112. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61113. {
  61114. Graphics g (&contextToPaintTo);
  61115. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61116. g.saveState();
  61117. #endif
  61118. JUCE_TRY
  61119. {
  61120. component->paintEntireComponent (g);
  61121. }
  61122. JUCE_CATCH_EXCEPTION
  61123. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61124. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61125. // clearly when things are being repainted.
  61126. {
  61127. g.restoreState();
  61128. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61129. (uint8) Random::getSystemRandom().nextInt (255),
  61130. (uint8) Random::getSystemRandom().nextInt (255),
  61131. (uint8) 0x50));
  61132. }
  61133. #endif
  61134. }
  61135. bool ComponentPeer::handleKeyPress (const int keyCode,
  61136. const juce_wchar textCharacter)
  61137. {
  61138. updateCurrentModifiers();
  61139. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61140. ? Component::getCurrentlyFocusedComponent()
  61141. : component;
  61142. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61143. {
  61144. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61145. if (currentModalComp != 0)
  61146. target = currentModalComp;
  61147. }
  61148. const KeyPress keyInfo (keyCode,
  61149. ModifierKeys::getCurrentModifiers().getRawFlags()
  61150. & ModifierKeys::allKeyboardModifiers,
  61151. textCharacter);
  61152. bool keyWasUsed = false;
  61153. while (target != 0)
  61154. {
  61155. const Component::SafePointer<Component> deletionChecker (target);
  61156. if (target->keyListeners_ != 0)
  61157. {
  61158. for (int i = target->keyListeners_->size(); --i >= 0;)
  61159. {
  61160. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61161. if (keyWasUsed || deletionChecker == 0)
  61162. return keyWasUsed;
  61163. i = jmin (i, target->keyListeners_->size());
  61164. }
  61165. }
  61166. keyWasUsed = target->keyPressed (keyInfo);
  61167. if (keyWasUsed || deletionChecker == 0)
  61168. break;
  61169. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61170. {
  61171. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61172. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61173. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61174. break;
  61175. }
  61176. target = target->parentComponent_;
  61177. }
  61178. return keyWasUsed;
  61179. }
  61180. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61181. {
  61182. updateCurrentModifiers();
  61183. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61184. ? Component::getCurrentlyFocusedComponent()
  61185. : component;
  61186. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61187. {
  61188. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61189. if (currentModalComp != 0)
  61190. target = currentModalComp;
  61191. }
  61192. bool keyWasUsed = false;
  61193. while (target != 0)
  61194. {
  61195. const Component::SafePointer<Component> deletionChecker (target);
  61196. keyWasUsed = target->keyStateChanged (isKeyDown);
  61197. if (keyWasUsed || deletionChecker == 0)
  61198. break;
  61199. if (target->keyListeners_ != 0)
  61200. {
  61201. for (int i = target->keyListeners_->size(); --i >= 0;)
  61202. {
  61203. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61204. if (keyWasUsed || deletionChecker == 0)
  61205. return keyWasUsed;
  61206. i = jmin (i, target->keyListeners_->size());
  61207. }
  61208. }
  61209. target = target->parentComponent_;
  61210. }
  61211. return keyWasUsed;
  61212. }
  61213. void ComponentPeer::handleModifierKeysChange()
  61214. {
  61215. updateCurrentModifiers();
  61216. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61217. if (target == 0)
  61218. target = Component::getCurrentlyFocusedComponent();
  61219. if (target == 0)
  61220. target = component;
  61221. if (target != 0)
  61222. target->internalModifierKeysChanged();
  61223. }
  61224. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61225. {
  61226. Component* const c = Component::getCurrentlyFocusedComponent();
  61227. if (component->isParentOf (c))
  61228. return dynamic_cast <TextInputTarget*> (c);
  61229. return 0;
  61230. }
  61231. void ComponentPeer::handleBroughtToFront()
  61232. {
  61233. updateCurrentModifiers();
  61234. if (component != 0)
  61235. component->internalBroughtToFront();
  61236. }
  61237. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61238. {
  61239. constrainer = newConstrainer;
  61240. }
  61241. void ComponentPeer::handleMovedOrResized()
  61242. {
  61243. jassert (component->isValidComponent());
  61244. updateCurrentModifiers();
  61245. const bool nowMinimised = isMinimised();
  61246. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61247. {
  61248. const Component::SafePointer<Component> deletionChecker (component);
  61249. const Rectangle<int> newBounds (getBounds());
  61250. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61251. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61252. if (wasMoved || wasResized)
  61253. {
  61254. component->bounds_ = newBounds;
  61255. if (wasResized)
  61256. component->repaint();
  61257. component->sendMovedResizedMessages (wasMoved, wasResized);
  61258. if (deletionChecker == 0)
  61259. return;
  61260. }
  61261. }
  61262. if (isWindowMinimised != nowMinimised)
  61263. {
  61264. isWindowMinimised = nowMinimised;
  61265. component->minimisationStateChanged (nowMinimised);
  61266. component->sendVisibilityChangeMessage();
  61267. }
  61268. if (! isFullScreen())
  61269. lastNonFullscreenBounds = component->getBounds();
  61270. }
  61271. void ComponentPeer::handleFocusGain()
  61272. {
  61273. updateCurrentModifiers();
  61274. if (component->isParentOf (lastFocusedComponent))
  61275. {
  61276. Component::currentlyFocusedComponent = lastFocusedComponent;
  61277. Desktop::getInstance().triggerFocusCallback();
  61278. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61279. }
  61280. else
  61281. {
  61282. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61283. component->grabKeyboardFocus();
  61284. else
  61285. Component::bringModalComponentToFront();
  61286. }
  61287. }
  61288. void ComponentPeer::handleFocusLoss()
  61289. {
  61290. updateCurrentModifiers();
  61291. if (component->hasKeyboardFocus (true))
  61292. {
  61293. lastFocusedComponent = Component::currentlyFocusedComponent;
  61294. if (lastFocusedComponent != 0)
  61295. {
  61296. Component::currentlyFocusedComponent = 0;
  61297. Desktop::getInstance().triggerFocusCallback();
  61298. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61299. }
  61300. }
  61301. }
  61302. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61303. {
  61304. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61305. ? static_cast <Component*> (lastFocusedComponent)
  61306. : component;
  61307. }
  61308. void ComponentPeer::handleScreenSizeChange()
  61309. {
  61310. updateCurrentModifiers();
  61311. component->parentSizeChanged();
  61312. handleMovedOrResized();
  61313. }
  61314. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61315. {
  61316. lastNonFullscreenBounds = newBounds;
  61317. }
  61318. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61319. {
  61320. return lastNonFullscreenBounds;
  61321. }
  61322. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61323. const StringArray& files,
  61324. FileDragAndDropTarget* const lastOne)
  61325. {
  61326. while (c != 0)
  61327. {
  61328. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61329. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61330. return t;
  61331. c = c->getParentComponent();
  61332. }
  61333. return 0;
  61334. }
  61335. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61336. {
  61337. updateCurrentModifiers();
  61338. FileDragAndDropTarget* lastTarget
  61339. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61340. FileDragAndDropTarget* newTarget = 0;
  61341. Component* const compUnderMouse = component->getComponentAt (position);
  61342. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61343. {
  61344. lastDragAndDropCompUnderMouse = compUnderMouse;
  61345. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61346. if (newTarget != lastTarget)
  61347. {
  61348. if (lastTarget != 0)
  61349. lastTarget->fileDragExit (files);
  61350. dragAndDropTargetComponent = 0;
  61351. if (newTarget != 0)
  61352. {
  61353. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61354. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61355. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61356. }
  61357. }
  61358. }
  61359. else
  61360. {
  61361. newTarget = lastTarget;
  61362. }
  61363. if (newTarget != 0)
  61364. {
  61365. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61366. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61367. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61368. }
  61369. }
  61370. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61371. {
  61372. handleFileDragMove (files, Point<int> (-1, -1));
  61373. jassert (dragAndDropTargetComponent == 0);
  61374. lastDragAndDropCompUnderMouse = 0;
  61375. }
  61376. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61377. {
  61378. handleFileDragMove (files, position);
  61379. if (dragAndDropTargetComponent != 0)
  61380. {
  61381. FileDragAndDropTarget* const target
  61382. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61383. dragAndDropTargetComponent = 0;
  61384. lastDragAndDropCompUnderMouse = 0;
  61385. if (target != 0)
  61386. {
  61387. Component* const targetComp = dynamic_cast <Component*> (target);
  61388. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61389. {
  61390. targetComp->internalModalInputAttempt();
  61391. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61392. return;
  61393. }
  61394. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61395. target->filesDropped (files, pos.getX(), pos.getY());
  61396. }
  61397. }
  61398. }
  61399. void ComponentPeer::handleUserClosingWindow()
  61400. {
  61401. updateCurrentModifiers();
  61402. component->userTriedToCloseWindow();
  61403. }
  61404. void ComponentPeer::bringModalComponentToFront()
  61405. {
  61406. Component::bringModalComponentToFront();
  61407. }
  61408. void ComponentPeer::clearMaskedRegion() throw()
  61409. {
  61410. maskedRegion.clear();
  61411. }
  61412. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61413. {
  61414. maskedRegion.add (x, y, w, h);
  61415. }
  61416. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61417. {
  61418. StringArray s;
  61419. s.add ("Software Renderer");
  61420. return s;
  61421. }
  61422. int ComponentPeer::getCurrentRenderingEngine() throw()
  61423. {
  61424. return 0;
  61425. }
  61426. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61427. {
  61428. }
  61429. END_JUCE_NAMESPACE
  61430. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61431. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61432. BEGIN_JUCE_NAMESPACE
  61433. DialogWindow::DialogWindow (const String& name,
  61434. const Colour& backgroundColour_,
  61435. const bool escapeKeyTriggersCloseButton_,
  61436. const bool addToDesktop_)
  61437. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61438. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61439. {
  61440. }
  61441. DialogWindow::~DialogWindow()
  61442. {
  61443. }
  61444. void DialogWindow::resized()
  61445. {
  61446. DocumentWindow::resized();
  61447. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61448. if (escapeKeyTriggersCloseButton
  61449. && getCloseButton() != 0
  61450. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61451. {
  61452. getCloseButton()->addShortcut (esc);
  61453. }
  61454. }
  61455. class TempDialogWindow : public DialogWindow
  61456. {
  61457. public:
  61458. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61459. : DialogWindow (title, colour, escapeCloses, true)
  61460. {
  61461. }
  61462. ~TempDialogWindow()
  61463. {
  61464. }
  61465. void closeButtonPressed()
  61466. {
  61467. setVisible (false);
  61468. }
  61469. private:
  61470. TempDialogWindow (const TempDialogWindow&);
  61471. TempDialogWindow& operator= (const TempDialogWindow&);
  61472. };
  61473. int DialogWindow::showModalDialog (const String& dialogTitle,
  61474. Component* contentComponent,
  61475. Component* componentToCentreAround,
  61476. const Colour& colour,
  61477. const bool escapeKeyTriggersCloseButton,
  61478. const bool shouldBeResizable,
  61479. const bool useBottomRightCornerResizer)
  61480. {
  61481. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61482. dw.setContentComponent (contentComponent, true, true);
  61483. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61484. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61485. const int result = dw.runModalLoop();
  61486. dw.setContentComponent (0, false);
  61487. return result;
  61488. }
  61489. END_JUCE_NAMESPACE
  61490. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61491. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61492. BEGIN_JUCE_NAMESPACE
  61493. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61494. {
  61495. public:
  61496. ButtonListenerProxy (DocumentWindow& owner_)
  61497. : owner (owner_)
  61498. {
  61499. }
  61500. void buttonClicked (Button* button)
  61501. {
  61502. if (button == owner.getMinimiseButton())
  61503. owner.minimiseButtonPressed();
  61504. else if (button == owner.getMaximiseButton())
  61505. owner.maximiseButtonPressed();
  61506. else if (button == owner.getCloseButton())
  61507. owner.closeButtonPressed();
  61508. }
  61509. juce_UseDebuggingNewOperator
  61510. private:
  61511. DocumentWindow& owner;
  61512. ButtonListenerProxy (const ButtonListenerProxy&);
  61513. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61514. };
  61515. DocumentWindow::DocumentWindow (const String& title,
  61516. const Colour& backgroundColour,
  61517. const int requiredButtons_,
  61518. const bool addToDesktop_)
  61519. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61520. titleBarHeight (26),
  61521. menuBarHeight (24),
  61522. requiredButtons (requiredButtons_),
  61523. #if JUCE_MAC
  61524. positionTitleBarButtonsOnLeft (true),
  61525. #else
  61526. positionTitleBarButtonsOnLeft (false),
  61527. #endif
  61528. drawTitleTextCentred (true),
  61529. menuBarModel (0)
  61530. {
  61531. setResizeLimits (128, 128, 32768, 32768);
  61532. lookAndFeelChanged();
  61533. }
  61534. DocumentWindow::~DocumentWindow()
  61535. {
  61536. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61537. titleBarButtons[i] = 0;
  61538. menuBar = 0;
  61539. }
  61540. void DocumentWindow::repaintTitleBar()
  61541. {
  61542. const Rectangle<int> titleBarArea (getTitleBarArea());
  61543. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61544. titleBarArea.getWidth(), titleBarArea.getHeight());
  61545. }
  61546. void DocumentWindow::setName (const String& newName)
  61547. {
  61548. if (newName != getName())
  61549. {
  61550. Component::setName (newName);
  61551. repaintTitleBar();
  61552. }
  61553. }
  61554. void DocumentWindow::setIcon (const Image* imageToUse)
  61555. {
  61556. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61557. repaintTitleBar();
  61558. }
  61559. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61560. {
  61561. titleBarHeight = newHeight;
  61562. resized();
  61563. repaintTitleBar();
  61564. }
  61565. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61566. const bool positionTitleBarButtonsOnLeft_)
  61567. {
  61568. requiredButtons = requiredButtons_;
  61569. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61570. lookAndFeelChanged();
  61571. }
  61572. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61573. {
  61574. drawTitleTextCentred = textShouldBeCentred;
  61575. repaintTitleBar();
  61576. }
  61577. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61578. const int menuBarHeight_)
  61579. {
  61580. if (menuBarModel != menuBarModel_)
  61581. {
  61582. menuBar = 0;
  61583. menuBarModel = menuBarModel_;
  61584. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61585. : getLookAndFeel().getDefaultMenuBarHeight();
  61586. if (menuBarModel != 0)
  61587. {
  61588. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61589. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61590. menuBar->setEnabled (isActiveWindow());
  61591. }
  61592. resized();
  61593. }
  61594. }
  61595. void DocumentWindow::closeButtonPressed()
  61596. {
  61597. /* If you've got a close button, you have to override this method to get
  61598. rid of your window!
  61599. If the window is just a pop-up, you should override this method and make
  61600. it delete the window in whatever way is appropriate for your app. E.g. you
  61601. might just want to call "delete this".
  61602. If your app is centred around this window such that the whole app should quit when
  61603. the window is closed, then you will probably want to use this method as an opportunity
  61604. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61605. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61606. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61607. or closing it via the taskbar icon on Windows).
  61608. */
  61609. jassertfalse
  61610. }
  61611. void DocumentWindow::minimiseButtonPressed()
  61612. {
  61613. setMinimised (true);
  61614. }
  61615. void DocumentWindow::maximiseButtonPressed()
  61616. {
  61617. setFullScreen (! isFullScreen());
  61618. }
  61619. void DocumentWindow::paint (Graphics& g)
  61620. {
  61621. ResizableWindow::paint (g);
  61622. if (resizableBorder == 0)
  61623. {
  61624. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61625. const BorderSize border (getBorderThickness());
  61626. g.fillRect (0, 0, getWidth(), border.getTop());
  61627. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61628. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61629. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61630. }
  61631. const Rectangle<int> titleBarArea (getTitleBarArea());
  61632. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61633. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61634. int titleSpaceX1 = 6;
  61635. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61636. for (int i = 0; i < 3; ++i)
  61637. {
  61638. if (titleBarButtons[i] != 0)
  61639. {
  61640. if (positionTitleBarButtonsOnLeft)
  61641. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61642. else
  61643. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61644. }
  61645. }
  61646. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61647. titleBarArea.getWidth(),
  61648. titleBarArea.getHeight(),
  61649. titleSpaceX1,
  61650. jmax (1, titleSpaceX2 - titleSpaceX1),
  61651. titleBarIcon,
  61652. ! drawTitleTextCentred);
  61653. }
  61654. void DocumentWindow::resized()
  61655. {
  61656. ResizableWindow::resized();
  61657. if (titleBarButtons[1] != 0)
  61658. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61659. const Rectangle<int> titleBarArea (getTitleBarArea());
  61660. getLookAndFeel()
  61661. .positionDocumentWindowButtons (*this,
  61662. titleBarArea.getX(), titleBarArea.getY(),
  61663. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61664. titleBarButtons[0],
  61665. titleBarButtons[1],
  61666. titleBarButtons[2],
  61667. positionTitleBarButtonsOnLeft);
  61668. if (menuBar != 0)
  61669. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61670. titleBarArea.getWidth(), menuBarHeight);
  61671. }
  61672. const BorderSize DocumentWindow::getBorderThickness()
  61673. {
  61674. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61675. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61676. }
  61677. const BorderSize DocumentWindow::getContentComponentBorder()
  61678. {
  61679. BorderSize border (getBorderThickness());
  61680. border.setTop (border.getTop()
  61681. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61682. + (menuBar != 0 ? menuBarHeight : 0));
  61683. return border;
  61684. }
  61685. int DocumentWindow::getTitleBarHeight() const
  61686. {
  61687. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61688. }
  61689. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61690. {
  61691. const BorderSize border (getBorderThickness());
  61692. return Rectangle<int> (border.getLeft(), border.getTop(),
  61693. getWidth() - border.getLeftAndRight(),
  61694. getTitleBarHeight());
  61695. }
  61696. Button* DocumentWindow::getCloseButton() const throw()
  61697. {
  61698. return titleBarButtons[2];
  61699. }
  61700. Button* DocumentWindow::getMinimiseButton() const throw()
  61701. {
  61702. return titleBarButtons[0];
  61703. }
  61704. Button* DocumentWindow::getMaximiseButton() const throw()
  61705. {
  61706. return titleBarButtons[1];
  61707. }
  61708. int DocumentWindow::getDesktopWindowStyleFlags() const
  61709. {
  61710. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61711. if ((requiredButtons & minimiseButton) != 0)
  61712. flags |= ComponentPeer::windowHasMinimiseButton;
  61713. if ((requiredButtons & maximiseButton) != 0)
  61714. flags |= ComponentPeer::windowHasMaximiseButton;
  61715. if ((requiredButtons & closeButton) != 0)
  61716. flags |= ComponentPeer::windowHasCloseButton;
  61717. return flags;
  61718. }
  61719. void DocumentWindow::lookAndFeelChanged()
  61720. {
  61721. int i;
  61722. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61723. titleBarButtons[i] = 0;
  61724. if (! isUsingNativeTitleBar())
  61725. {
  61726. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61727. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61728. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61729. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61730. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61731. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61732. for (i = 0; i < 3; ++i)
  61733. {
  61734. if (titleBarButtons[i] != 0)
  61735. {
  61736. if (buttonListener == 0)
  61737. buttonListener = new ButtonListenerProxy (*this);
  61738. titleBarButtons[i]->addButtonListener (buttonListener);
  61739. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61740. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61741. Component::addAndMakeVisible (titleBarButtons[i]);
  61742. }
  61743. }
  61744. if (getCloseButton() != 0)
  61745. {
  61746. #if JUCE_MAC
  61747. getCloseButton()->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
  61748. #else
  61749. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61750. #endif
  61751. }
  61752. }
  61753. activeWindowStatusChanged();
  61754. ResizableWindow::lookAndFeelChanged();
  61755. }
  61756. void DocumentWindow::parentHierarchyChanged()
  61757. {
  61758. lookAndFeelChanged();
  61759. }
  61760. void DocumentWindow::activeWindowStatusChanged()
  61761. {
  61762. ResizableWindow::activeWindowStatusChanged();
  61763. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61764. if (titleBarButtons[i] != 0)
  61765. titleBarButtons[i]->setEnabled (isActiveWindow());
  61766. if (menuBar != 0)
  61767. menuBar->setEnabled (isActiveWindow());
  61768. }
  61769. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61770. {
  61771. if (getTitleBarArea().contains (e.x, e.y)
  61772. && getMaximiseButton() != 0)
  61773. {
  61774. getMaximiseButton()->triggerClick();
  61775. }
  61776. }
  61777. void DocumentWindow::userTriedToCloseWindow()
  61778. {
  61779. closeButtonPressed();
  61780. }
  61781. END_JUCE_NAMESPACE
  61782. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61783. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61784. BEGIN_JUCE_NAMESPACE
  61785. ResizableWindow::ResizableWindow (const String& name,
  61786. const bool addToDesktop_)
  61787. : TopLevelWindow (name, addToDesktop_),
  61788. resizeToFitContent (false),
  61789. fullscreen (false),
  61790. lastNonFullScreenPos (50, 50, 256, 256),
  61791. constrainer (0)
  61792. #ifdef JUCE_DEBUG
  61793. , hasBeenResized (false)
  61794. #endif
  61795. {
  61796. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61797. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  61798. if (addToDesktop_)
  61799. Component::addToDesktop (getDesktopWindowStyleFlags());
  61800. }
  61801. ResizableWindow::ResizableWindow (const String& name,
  61802. const Colour& backgroundColour_,
  61803. const bool addToDesktop_)
  61804. : TopLevelWindow (name, addToDesktop_),
  61805. resizeToFitContent (false),
  61806. fullscreen (false),
  61807. lastNonFullScreenPos (50, 50, 256, 256),
  61808. constrainer (0)
  61809. #ifdef JUCE_DEBUG
  61810. , hasBeenResized (false)
  61811. #endif
  61812. {
  61813. setBackgroundColour (backgroundColour_);
  61814. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61815. if (addToDesktop_)
  61816. Component::addToDesktop (getDesktopWindowStyleFlags());
  61817. }
  61818. ResizableWindow::~ResizableWindow()
  61819. {
  61820. resizableCorner = 0;
  61821. resizableBorder = 0;
  61822. contentComponent = 0;
  61823. // have you been adding your own components directly to this window..? tut tut tut.
  61824. // Read the instructions for using a ResizableWindow!
  61825. jassert (getNumChildComponents() == 0);
  61826. }
  61827. int ResizableWindow::getDesktopWindowStyleFlags() const
  61828. {
  61829. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  61830. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  61831. flags |= ComponentPeer::windowIsResizable;
  61832. return flags;
  61833. }
  61834. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  61835. const bool deleteOldOne,
  61836. const bool resizeToFit)
  61837. {
  61838. resizeToFitContent = resizeToFit;
  61839. if (newContentComponent != static_cast <Component*> (contentComponent))
  61840. {
  61841. if (! deleteOldOne)
  61842. removeChildComponent (contentComponent.release());
  61843. contentComponent = newContentComponent;
  61844. Component::addAndMakeVisible (contentComponent);
  61845. }
  61846. if (resizeToFit)
  61847. childBoundsChanged (contentComponent);
  61848. resized(); // must always be called to position the new content comp
  61849. }
  61850. void ResizableWindow::setContentComponentSize (int width, int height)
  61851. {
  61852. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  61853. const BorderSize border (getContentComponentBorder());
  61854. setSize (width + border.getLeftAndRight(),
  61855. height + border.getTopAndBottom());
  61856. }
  61857. const BorderSize ResizableWindow::getBorderThickness()
  61858. {
  61859. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  61860. }
  61861. const BorderSize ResizableWindow::getContentComponentBorder()
  61862. {
  61863. return getBorderThickness();
  61864. }
  61865. void ResizableWindow::moved()
  61866. {
  61867. updateLastPos();
  61868. }
  61869. void ResizableWindow::visibilityChanged()
  61870. {
  61871. TopLevelWindow::visibilityChanged();
  61872. updateLastPos();
  61873. }
  61874. void ResizableWindow::resized()
  61875. {
  61876. if (resizableBorder != 0)
  61877. {
  61878. resizableBorder->setVisible (! isFullScreen());
  61879. resizableBorder->setBorderThickness (getBorderThickness());
  61880. resizableBorder->setSize (getWidth(), getHeight());
  61881. resizableBorder->toBack();
  61882. }
  61883. if (resizableCorner != 0)
  61884. {
  61885. resizableCorner->setVisible (! isFullScreen());
  61886. const int resizerSize = 18;
  61887. resizableCorner->setBounds (getWidth() - resizerSize,
  61888. getHeight() - resizerSize,
  61889. resizerSize, resizerSize);
  61890. }
  61891. if (contentComponent != 0)
  61892. contentComponent->setBoundsInset (getContentComponentBorder());
  61893. updateLastPos();
  61894. #ifdef JUCE_DEBUG
  61895. hasBeenResized = true;
  61896. #endif
  61897. }
  61898. void ResizableWindow::childBoundsChanged (Component* child)
  61899. {
  61900. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  61901. {
  61902. // not going to look very good if this component has a zero size..
  61903. jassert (child->getWidth() > 0);
  61904. jassert (child->getHeight() > 0);
  61905. const BorderSize borders (getContentComponentBorder());
  61906. setSize (child->getWidth() + borders.getLeftAndRight(),
  61907. child->getHeight() + borders.getTopAndBottom());
  61908. }
  61909. }
  61910. void ResizableWindow::activeWindowStatusChanged()
  61911. {
  61912. const BorderSize borders (getContentComponentBorder());
  61913. repaint (0, 0, getWidth(), borders.getTop());
  61914. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  61915. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  61916. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  61917. }
  61918. void ResizableWindow::setResizable (const bool shouldBeResizable,
  61919. const bool useBottomRightCornerResizer)
  61920. {
  61921. if (shouldBeResizable)
  61922. {
  61923. if (useBottomRightCornerResizer)
  61924. {
  61925. resizableBorder = 0;
  61926. if (resizableCorner == 0)
  61927. {
  61928. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  61929. resizableCorner->setAlwaysOnTop (true);
  61930. }
  61931. }
  61932. else
  61933. {
  61934. resizableCorner = 0;
  61935. if (resizableBorder == 0)
  61936. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  61937. }
  61938. }
  61939. else
  61940. {
  61941. resizableCorner = 0;
  61942. resizableBorder = 0;
  61943. }
  61944. if (isUsingNativeTitleBar())
  61945. recreateDesktopWindow();
  61946. childBoundsChanged (contentComponent);
  61947. resized();
  61948. }
  61949. bool ResizableWindow::isResizable() const throw()
  61950. {
  61951. return resizableCorner != 0
  61952. || resizableBorder != 0;
  61953. }
  61954. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  61955. const int newMinimumHeight,
  61956. const int newMaximumWidth,
  61957. const int newMaximumHeight) throw()
  61958. {
  61959. // if you've set up a custom constrainer then these settings won't have any effect..
  61960. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  61961. if (constrainer == 0)
  61962. setConstrainer (&defaultConstrainer);
  61963. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  61964. newMaximumWidth, newMaximumHeight);
  61965. setBoundsConstrained (getBounds());
  61966. }
  61967. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  61968. {
  61969. if (constrainer != newConstrainer)
  61970. {
  61971. constrainer = newConstrainer;
  61972. const bool useBottomRightCornerResizer = resizableCorner != 0;
  61973. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  61974. resizableCorner = 0;
  61975. resizableBorder = 0;
  61976. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61977. ComponentPeer* const peer = getPeer();
  61978. if (peer != 0)
  61979. peer->setConstrainer (newConstrainer);
  61980. }
  61981. }
  61982. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  61983. {
  61984. if (constrainer != 0)
  61985. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  61986. else
  61987. setBounds (bounds);
  61988. }
  61989. void ResizableWindow::paint (Graphics& g)
  61990. {
  61991. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  61992. getBorderThickness(), *this);
  61993. if (! isFullScreen())
  61994. {
  61995. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  61996. getBorderThickness(), *this);
  61997. }
  61998. #ifdef JUCE_DEBUG
  61999. /* If this fails, then you've probably written a subclass with a resized()
  62000. callback but forgotten to make it call its parent class's resized() method.
  62001. It's important when you override methods like resized(), moved(),
  62002. etc., that you make sure the base class methods also get called.
  62003. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62004. because your content should all be inside the content component - and it's the
  62005. content component's resized() method that you should be using to do your
  62006. layout.
  62007. */
  62008. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62009. #endif
  62010. }
  62011. void ResizableWindow::lookAndFeelChanged()
  62012. {
  62013. resized();
  62014. if (isOnDesktop())
  62015. {
  62016. Component::addToDesktop (getDesktopWindowStyleFlags());
  62017. ComponentPeer* const peer = getPeer();
  62018. if (peer != 0)
  62019. peer->setConstrainer (constrainer);
  62020. }
  62021. }
  62022. const Colour ResizableWindow::getBackgroundColour() const throw()
  62023. {
  62024. return findColour (backgroundColourId, false);
  62025. }
  62026. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62027. {
  62028. Colour backgroundColour (newColour);
  62029. if (! Desktop::canUseSemiTransparentWindows())
  62030. backgroundColour = newColour.withAlpha (1.0f);
  62031. setColour (backgroundColourId, backgroundColour);
  62032. setOpaque (backgroundColour.isOpaque());
  62033. repaint();
  62034. }
  62035. bool ResizableWindow::isFullScreen() const
  62036. {
  62037. if (isOnDesktop())
  62038. {
  62039. ComponentPeer* const peer = getPeer();
  62040. return peer != 0 && peer->isFullScreen();
  62041. }
  62042. return fullscreen;
  62043. }
  62044. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62045. {
  62046. if (shouldBeFullScreen != isFullScreen())
  62047. {
  62048. updateLastPos();
  62049. fullscreen = shouldBeFullScreen;
  62050. if (isOnDesktop())
  62051. {
  62052. ComponentPeer* const peer = getPeer();
  62053. if (peer != 0)
  62054. {
  62055. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62056. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62057. peer->setFullScreen (shouldBeFullScreen);
  62058. if (! shouldBeFullScreen)
  62059. setBounds (lastPos);
  62060. }
  62061. else
  62062. {
  62063. jassertfalse
  62064. }
  62065. }
  62066. else
  62067. {
  62068. if (shouldBeFullScreen)
  62069. setBounds (0, 0, getParentWidth(), getParentHeight());
  62070. else
  62071. setBounds (lastNonFullScreenPos);
  62072. }
  62073. resized();
  62074. }
  62075. }
  62076. bool ResizableWindow::isMinimised() const
  62077. {
  62078. ComponentPeer* const peer = getPeer();
  62079. return (peer != 0) && peer->isMinimised();
  62080. }
  62081. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62082. {
  62083. if (shouldMinimise != isMinimised())
  62084. {
  62085. ComponentPeer* const peer = getPeer();
  62086. if (peer != 0)
  62087. {
  62088. updateLastPos();
  62089. peer->setMinimised (shouldMinimise);
  62090. }
  62091. else
  62092. {
  62093. jassertfalse
  62094. }
  62095. }
  62096. }
  62097. void ResizableWindow::updateLastPos()
  62098. {
  62099. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62100. {
  62101. lastNonFullScreenPos = getBounds();
  62102. }
  62103. }
  62104. void ResizableWindow::parentSizeChanged()
  62105. {
  62106. if (isFullScreen() && getParentComponent() != 0)
  62107. {
  62108. setBounds (0, 0, getParentWidth(), getParentHeight());
  62109. }
  62110. }
  62111. const String ResizableWindow::getWindowStateAsString()
  62112. {
  62113. updateLastPos();
  62114. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62115. }
  62116. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62117. {
  62118. StringArray tokens;
  62119. tokens.addTokens (s, false);
  62120. tokens.removeEmptyStrings();
  62121. tokens.trim();
  62122. const bool fs = tokens[0].startsWithIgnoreCase ("fs");
  62123. const int firstCoord = fs ? 1 : 0;
  62124. if (tokens.size() != firstCoord + 4)
  62125. return false;
  62126. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62127. tokens[firstCoord + 1].getIntValue(),
  62128. tokens[firstCoord + 2].getIntValue(),
  62129. tokens[firstCoord + 3].getIntValue());
  62130. if (newPos.isEmpty())
  62131. return false;
  62132. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62133. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62134. if (peer != 0)
  62135. peer->getFrameSize().addTo (newPos);
  62136. if (! screen.contains (newPos))
  62137. {
  62138. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62139. jmin (newPos.getHeight(), screen.getHeight()));
  62140. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62141. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62142. }
  62143. if (peer != 0)
  62144. {
  62145. peer->getFrameSize().subtractFrom (newPos);
  62146. peer->setNonFullScreenBounds (newPos);
  62147. }
  62148. lastNonFullScreenPos = newPos;
  62149. setFullScreen (fs);
  62150. if (! fs)
  62151. setBoundsConstrained (newPos);
  62152. return true;
  62153. }
  62154. void ResizableWindow::mouseDown (const MouseEvent&)
  62155. {
  62156. if (! isFullScreen())
  62157. dragger.startDraggingComponent (this, constrainer);
  62158. }
  62159. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62160. {
  62161. if (! isFullScreen())
  62162. dragger.dragComponent (this, e);
  62163. }
  62164. #ifdef JUCE_DEBUG
  62165. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62166. {
  62167. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62168. manages its child components automatically, and if you add your own it'll cause
  62169. trouble. Instead, use setContentComponent() to give it a component which
  62170. will be automatically resized and kept in the right place - then you can add
  62171. subcomponents to the content comp. See the notes for the ResizableWindow class
  62172. for more info.
  62173. If you really know what you're doing and want to avoid this assertion, just call
  62174. Component::addChildComponent directly.
  62175. */
  62176. jassertfalse
  62177. Component::addChildComponent (child, zOrder);
  62178. }
  62179. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62180. {
  62181. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62182. manages its child components automatically, and if you add your own it'll cause
  62183. trouble. Instead, use setContentComponent() to give it a component which
  62184. will be automatically resized and kept in the right place - then you can add
  62185. subcomponents to the content comp. See the notes for the ResizableWindow class
  62186. for more info.
  62187. If you really know what you're doing and want to avoid this assertion, just call
  62188. Component::addAndMakeVisible directly.
  62189. */
  62190. jassertfalse
  62191. Component::addAndMakeVisible (child, zOrder);
  62192. }
  62193. #endif
  62194. END_JUCE_NAMESPACE
  62195. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62196. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62197. BEGIN_JUCE_NAMESPACE
  62198. SplashScreen::SplashScreen()
  62199. : backgroundImage (0)
  62200. {
  62201. setOpaque (true);
  62202. }
  62203. SplashScreen::~SplashScreen()
  62204. {
  62205. ImageCache::releaseOrDelete (backgroundImage);
  62206. }
  62207. void SplashScreen::show (const String& title,
  62208. Image* const backgroundImage_,
  62209. const int minimumTimeToDisplayFor,
  62210. const bool useDropShadow,
  62211. const bool removeOnMouseClick)
  62212. {
  62213. backgroundImage = backgroundImage_;
  62214. jassert (backgroundImage_ != 0);
  62215. if (backgroundImage_ != 0)
  62216. {
  62217. setOpaque (! backgroundImage_->hasAlphaChannel());
  62218. show (title,
  62219. backgroundImage_->getWidth(),
  62220. backgroundImage_->getHeight(),
  62221. minimumTimeToDisplayFor,
  62222. useDropShadow,
  62223. removeOnMouseClick);
  62224. }
  62225. }
  62226. void SplashScreen::show (const String& title,
  62227. const int width,
  62228. const int height,
  62229. const int minimumTimeToDisplayFor,
  62230. const bool useDropShadow,
  62231. const bool removeOnMouseClick)
  62232. {
  62233. setName (title);
  62234. setAlwaysOnTop (true);
  62235. setVisible (true);
  62236. centreWithSize (width, height);
  62237. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62238. toFront (false);
  62239. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62240. repaint();
  62241. originalClickCounter = removeOnMouseClick
  62242. ? Desktop::getMouseButtonClickCounter()
  62243. : std::numeric_limits<int>::max();
  62244. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62245. startTimer (50);
  62246. }
  62247. void SplashScreen::paint (Graphics& g)
  62248. {
  62249. if (backgroundImage != 0)
  62250. {
  62251. g.setOpacity (1.0f);
  62252. g.drawImage (backgroundImage,
  62253. 0, 0, getWidth(), getHeight(),
  62254. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62255. }
  62256. }
  62257. void SplashScreen::timerCallback()
  62258. {
  62259. if (Time::getCurrentTime() > earliestTimeToDelete
  62260. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62261. {
  62262. delete this;
  62263. }
  62264. }
  62265. END_JUCE_NAMESPACE
  62266. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62267. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62268. BEGIN_JUCE_NAMESPACE
  62269. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62270. const bool hasProgressBar,
  62271. const bool hasCancelButton,
  62272. const int timeOutMsWhenCancelling_,
  62273. const String& cancelButtonText)
  62274. : Thread ("Juce Progress Window"),
  62275. progress (0.0),
  62276. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62277. {
  62278. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62279. .createAlertWindow (title, String::empty, cancelButtonText,
  62280. String::empty, String::empty,
  62281. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62282. if (hasProgressBar)
  62283. alertWindow->addProgressBarComponent (progress);
  62284. }
  62285. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62286. {
  62287. stopThread (timeOutMsWhenCancelling);
  62288. }
  62289. bool ThreadWithProgressWindow::runThread (const int priority)
  62290. {
  62291. startThread (priority);
  62292. startTimer (100);
  62293. {
  62294. const ScopedLock sl (messageLock);
  62295. alertWindow->setMessage (message);
  62296. }
  62297. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62298. stopThread (timeOutMsWhenCancelling);
  62299. alertWindow->setVisible (false);
  62300. return finishedNaturally;
  62301. }
  62302. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62303. {
  62304. progress = newProgress;
  62305. }
  62306. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62307. {
  62308. const ScopedLock sl (messageLock);
  62309. message = newStatusMessage;
  62310. }
  62311. void ThreadWithProgressWindow::timerCallback()
  62312. {
  62313. if (! isThreadRunning())
  62314. {
  62315. // thread has finished normally..
  62316. alertWindow->exitModalState (1);
  62317. alertWindow->setVisible (false);
  62318. }
  62319. else
  62320. {
  62321. const ScopedLock sl (messageLock);
  62322. alertWindow->setMessage (message);
  62323. }
  62324. }
  62325. END_JUCE_NAMESPACE
  62326. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62327. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62328. BEGIN_JUCE_NAMESPACE
  62329. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62330. const int millisecondsBeforeTipAppears_)
  62331. : Component ("tooltip"),
  62332. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62333. mouseClicks (0),
  62334. lastHideTime (0),
  62335. lastComponentUnderMouse (0),
  62336. changedCompsSinceShown (true)
  62337. {
  62338. if (Desktop::getInstance().getMainMouseSource().canHover())
  62339. startTimer (123);
  62340. setAlwaysOnTop (true);
  62341. setOpaque (true);
  62342. if (parentComponent != 0)
  62343. parentComponent->addChildComponent (this);
  62344. }
  62345. TooltipWindow::~TooltipWindow()
  62346. {
  62347. hide();
  62348. }
  62349. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62350. {
  62351. millisecondsBeforeTipAppears = newTimeMs;
  62352. }
  62353. void TooltipWindow::paint (Graphics& g)
  62354. {
  62355. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62356. }
  62357. void TooltipWindow::mouseEnter (const MouseEvent&)
  62358. {
  62359. hide();
  62360. }
  62361. void TooltipWindow::showFor (const String& tip)
  62362. {
  62363. jassert (tip.isNotEmpty());
  62364. tipShowing = tip;
  62365. Point<int> mousePos (Desktop::getMousePosition());
  62366. if (getParentComponent() != 0)
  62367. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62368. int x, y, w, h;
  62369. getLookAndFeel().getTooltipSize (tip, w, h);
  62370. if (mousePos.getX() > getParentWidth() / 2)
  62371. x = mousePos.getX() - (w + 12);
  62372. else
  62373. x = mousePos.getX() + 24;
  62374. if (mousePos.getY() > getParentHeight() / 2)
  62375. y = mousePos.getY() - (h + 6);
  62376. else
  62377. y = mousePos.getY() + 6;
  62378. setBounds (x, y, w, h);
  62379. setVisible (true);
  62380. if (getParentComponent() == 0)
  62381. {
  62382. addToDesktop (ComponentPeer::windowHasDropShadow
  62383. | ComponentPeer::windowIsTemporary
  62384. | ComponentPeer::windowIgnoresKeyPresses);
  62385. }
  62386. toFront (false);
  62387. }
  62388. const String TooltipWindow::getTipFor (Component* const c)
  62389. {
  62390. if (c != 0
  62391. && Process::isForegroundProcess()
  62392. && ! Component::isMouseButtonDownAnywhere())
  62393. {
  62394. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62395. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62396. return ttc->getTooltip();
  62397. }
  62398. return String::empty;
  62399. }
  62400. void TooltipWindow::hide()
  62401. {
  62402. tipShowing = String::empty;
  62403. removeFromDesktop();
  62404. setVisible (false);
  62405. }
  62406. void TooltipWindow::timerCallback()
  62407. {
  62408. const unsigned int now = Time::getApproximateMillisecondCounter();
  62409. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62410. const String newTip (getTipFor (newComp));
  62411. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62412. lastComponentUnderMouse = newComp;
  62413. lastTipUnderMouse = newTip;
  62414. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62415. const bool mouseWasClicked = clickCount > mouseClicks;
  62416. mouseClicks = clickCount;
  62417. const Point<int> mousePos (Desktop::getMousePosition());
  62418. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62419. lastMousePos = mousePos;
  62420. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62421. lastCompChangeTime = now;
  62422. if (isVisible() || now < lastHideTime + 500)
  62423. {
  62424. // if a tip is currently visible (or has just disappeared), update to a new one
  62425. // immediately if needed..
  62426. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62427. {
  62428. if (isVisible())
  62429. {
  62430. lastHideTime = now;
  62431. hide();
  62432. }
  62433. }
  62434. else if (tipChanged)
  62435. {
  62436. showFor (newTip);
  62437. }
  62438. }
  62439. else
  62440. {
  62441. // if there isn't currently a tip, but one is needed, only let it
  62442. // appear after a timeout..
  62443. if (newTip.isNotEmpty()
  62444. && newTip != tipShowing
  62445. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62446. {
  62447. showFor (newTip);
  62448. }
  62449. }
  62450. }
  62451. END_JUCE_NAMESPACE
  62452. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62453. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62454. BEGIN_JUCE_NAMESPACE
  62455. class TopLevelWindowManager : public Timer,
  62456. public DeletedAtShutdown
  62457. {
  62458. public:
  62459. TopLevelWindowManager()
  62460. : currentActive (0)
  62461. {
  62462. }
  62463. ~TopLevelWindowManager()
  62464. {
  62465. clearSingletonInstance();
  62466. }
  62467. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62468. void timerCallback()
  62469. {
  62470. startTimer (jmin (1731, getTimerInterval() * 2));
  62471. TopLevelWindow* active = 0;
  62472. if (Process::isForegroundProcess())
  62473. {
  62474. active = currentActive;
  62475. Component* const c = Component::getCurrentlyFocusedComponent();
  62476. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62477. if (tlw == 0 && c != 0)
  62478. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62479. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62480. if (tlw != 0)
  62481. active = tlw;
  62482. }
  62483. if (active != currentActive)
  62484. {
  62485. currentActive = active;
  62486. for (int i = windows.size(); --i >= 0;)
  62487. {
  62488. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62489. tlw->setWindowActive (isWindowActive (tlw));
  62490. i = jmin (i, windows.size() - 1);
  62491. }
  62492. Desktop::getInstance().triggerFocusCallback();
  62493. }
  62494. }
  62495. bool addWindow (TopLevelWindow* const w) throw()
  62496. {
  62497. windows.add (w);
  62498. startTimer (10);
  62499. return isWindowActive (w);
  62500. }
  62501. void removeWindow (TopLevelWindow* const w) throw()
  62502. {
  62503. startTimer (10);
  62504. if (currentActive == w)
  62505. currentActive = 0;
  62506. windows.removeValue (w);
  62507. if (windows.size() == 0)
  62508. deleteInstance();
  62509. }
  62510. VoidArray windows;
  62511. private:
  62512. TopLevelWindow* currentActive;
  62513. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62514. {
  62515. return (tlw == currentActive
  62516. || tlw->isParentOf (currentActive)
  62517. || tlw->hasKeyboardFocus (true))
  62518. && tlw->isShowing();
  62519. }
  62520. TopLevelWindowManager (const TopLevelWindowManager&);
  62521. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62522. };
  62523. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62524. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62525. {
  62526. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62527. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62528. }
  62529. TopLevelWindow::TopLevelWindow (const String& name,
  62530. const bool addToDesktop_)
  62531. : Component (name),
  62532. useDropShadow (true),
  62533. useNativeTitleBar (false),
  62534. windowIsActive_ (false)
  62535. {
  62536. setOpaque (true);
  62537. if (addToDesktop_)
  62538. Component::addToDesktop (getDesktopWindowStyleFlags());
  62539. else
  62540. setDropShadowEnabled (true);
  62541. setWantsKeyboardFocus (true);
  62542. setBroughtToFrontOnMouseClick (true);
  62543. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62544. }
  62545. TopLevelWindow::~TopLevelWindow()
  62546. {
  62547. shadower = 0;
  62548. TopLevelWindowManager::getInstance()->removeWindow (this);
  62549. }
  62550. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62551. {
  62552. if (hasKeyboardFocus (true))
  62553. TopLevelWindowManager::getInstance()->timerCallback();
  62554. else
  62555. TopLevelWindowManager::getInstance()->startTimer (10);
  62556. }
  62557. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62558. {
  62559. if (windowIsActive_ != isNowActive)
  62560. {
  62561. windowIsActive_ = isNowActive;
  62562. activeWindowStatusChanged();
  62563. }
  62564. }
  62565. void TopLevelWindow::activeWindowStatusChanged()
  62566. {
  62567. }
  62568. void TopLevelWindow::parentHierarchyChanged()
  62569. {
  62570. setDropShadowEnabled (useDropShadow);
  62571. }
  62572. void TopLevelWindow::visibilityChanged()
  62573. {
  62574. if (isShowing())
  62575. toFront (true);
  62576. }
  62577. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62578. {
  62579. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62580. if (useDropShadow)
  62581. flags |= ComponentPeer::windowHasDropShadow;
  62582. if (useNativeTitleBar)
  62583. flags |= ComponentPeer::windowHasTitleBar;
  62584. return flags;
  62585. }
  62586. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62587. {
  62588. useDropShadow = useShadow;
  62589. if (isOnDesktop())
  62590. {
  62591. shadower = 0;
  62592. Component::addToDesktop (getDesktopWindowStyleFlags());
  62593. }
  62594. else
  62595. {
  62596. if (useShadow && isOpaque())
  62597. {
  62598. if (shadower == 0)
  62599. {
  62600. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62601. if (shadower != 0)
  62602. shadower->setOwner (this);
  62603. }
  62604. }
  62605. else
  62606. {
  62607. shadower = 0;
  62608. }
  62609. }
  62610. }
  62611. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62612. {
  62613. if (useNativeTitleBar != useNativeTitleBar_)
  62614. {
  62615. useNativeTitleBar = useNativeTitleBar_;
  62616. recreateDesktopWindow();
  62617. sendLookAndFeelChange();
  62618. }
  62619. }
  62620. void TopLevelWindow::recreateDesktopWindow()
  62621. {
  62622. if (isOnDesktop())
  62623. {
  62624. Component::addToDesktop (getDesktopWindowStyleFlags());
  62625. toFront (true);
  62626. }
  62627. }
  62628. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62629. {
  62630. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62631. because this class needs to make sure its layout corresponds with settings like whether
  62632. it's got a native title bar or not.
  62633. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62634. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62635. method, then add or remove whatever flags are necessary from this value before returning it.
  62636. */
  62637. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62638. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62639. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62640. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62641. sendLookAndFeelChange();
  62642. }
  62643. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62644. {
  62645. if (c == 0)
  62646. c = TopLevelWindow::getActiveTopLevelWindow();
  62647. if (c == 0)
  62648. {
  62649. centreWithSize (width, height);
  62650. }
  62651. else
  62652. {
  62653. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62654. (c->getHeight() - height) / 2)));
  62655. Rectangle<int> parentArea (c->getParentMonitorArea());
  62656. if (getParentComponent() != 0)
  62657. {
  62658. p = getParentComponent()->globalPositionToRelative (p);
  62659. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62660. }
  62661. parentArea.reduce (12, 12);
  62662. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62663. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62664. width, height);
  62665. }
  62666. }
  62667. int TopLevelWindow::getNumTopLevelWindows() throw()
  62668. {
  62669. return TopLevelWindowManager::getInstance()->windows.size();
  62670. }
  62671. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62672. {
  62673. return static_cast <TopLevelWindow*> (TopLevelWindowManager::getInstance()->windows [index]);
  62674. }
  62675. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62676. {
  62677. TopLevelWindow* best = 0;
  62678. int bestNumTWLParents = -1;
  62679. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62680. {
  62681. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62682. if (tlw->isActiveWindow())
  62683. {
  62684. int numTWLParents = 0;
  62685. const Component* c = tlw->getParentComponent();
  62686. while (c != 0)
  62687. {
  62688. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62689. ++numTWLParents;
  62690. c = c->getParentComponent();
  62691. }
  62692. if (bestNumTWLParents < numTWLParents)
  62693. {
  62694. best = tlw;
  62695. bestNumTWLParents = numTWLParents;
  62696. }
  62697. }
  62698. }
  62699. return best;
  62700. }
  62701. END_JUCE_NAMESPACE
  62702. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62703. /*** Start of inlined file: juce_Colour.cpp ***/
  62704. BEGIN_JUCE_NAMESPACE
  62705. namespace ColourHelpers
  62706. {
  62707. static uint8 floatAlphaToInt (const float alpha) throw()
  62708. {
  62709. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62710. }
  62711. static void convertHSBtoRGB (float h, float s, float v,
  62712. uint8& r, uint8& g, uint8& b) throw()
  62713. {
  62714. v = jlimit (0.0f, 1.0f, v);
  62715. v *= 255.0f;
  62716. const uint8 intV = (uint8) roundToInt (v);
  62717. if (s <= 0)
  62718. {
  62719. r = intV;
  62720. g = intV;
  62721. b = intV;
  62722. }
  62723. else
  62724. {
  62725. s = jmin (1.0f, s);
  62726. h = jlimit (0.0f, 1.0f, h);
  62727. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62728. const float f = h - floorf (h);
  62729. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62730. const float y = v * (1.0f - s * f);
  62731. const float z = v * (1.0f - (s * (1.0f - f)));
  62732. if (h < 1.0f)
  62733. {
  62734. r = intV;
  62735. g = (uint8) roundToInt (z);
  62736. b = x;
  62737. }
  62738. else if (h < 2.0f)
  62739. {
  62740. r = (uint8) roundToInt (y);
  62741. g = intV;
  62742. b = x;
  62743. }
  62744. else if (h < 3.0f)
  62745. {
  62746. r = x;
  62747. g = intV;
  62748. b = (uint8) roundToInt (z);
  62749. }
  62750. else if (h < 4.0f)
  62751. {
  62752. r = x;
  62753. g = (uint8) roundToInt (y);
  62754. b = intV;
  62755. }
  62756. else if (h < 5.0f)
  62757. {
  62758. r = (uint8) roundToInt (z);
  62759. g = x;
  62760. b = intV;
  62761. }
  62762. else if (h < 6.0f)
  62763. {
  62764. r = intV;
  62765. g = x;
  62766. b = (uint8) roundToInt (y);
  62767. }
  62768. else
  62769. {
  62770. r = 0;
  62771. g = 0;
  62772. b = 0;
  62773. }
  62774. }
  62775. }
  62776. }
  62777. Colour::Colour() throw()
  62778. : argb (0)
  62779. {
  62780. }
  62781. Colour::Colour (const Colour& other) throw()
  62782. : argb (other.argb)
  62783. {
  62784. }
  62785. Colour& Colour::operator= (const Colour& other) throw()
  62786. {
  62787. argb = other.argb;
  62788. return *this;
  62789. }
  62790. bool Colour::operator== (const Colour& other) const throw()
  62791. {
  62792. return argb.getARGB() == other.argb.getARGB();
  62793. }
  62794. bool Colour::operator!= (const Colour& other) const throw()
  62795. {
  62796. return argb.getARGB() != other.argb.getARGB();
  62797. }
  62798. Colour::Colour (const uint32 argb_) throw()
  62799. : argb (argb_)
  62800. {
  62801. }
  62802. Colour::Colour (const uint8 red,
  62803. const uint8 green,
  62804. const uint8 blue) throw()
  62805. {
  62806. argb.setARGB (0xff, red, green, blue);
  62807. }
  62808. const Colour Colour::fromRGB (const uint8 red,
  62809. const uint8 green,
  62810. const uint8 blue) throw()
  62811. {
  62812. return Colour (red, green, blue);
  62813. }
  62814. Colour::Colour (const uint8 red,
  62815. const uint8 green,
  62816. const uint8 blue,
  62817. const uint8 alpha) throw()
  62818. {
  62819. argb.setARGB (alpha, red, green, blue);
  62820. }
  62821. const Colour Colour::fromRGBA (const uint8 red,
  62822. const uint8 green,
  62823. const uint8 blue,
  62824. const uint8 alpha) throw()
  62825. {
  62826. return Colour (red, green, blue, alpha);
  62827. }
  62828. Colour::Colour (const uint8 red,
  62829. const uint8 green,
  62830. const uint8 blue,
  62831. const float alpha) throw()
  62832. {
  62833. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  62834. }
  62835. const Colour Colour::fromRGBAFloat (const uint8 red,
  62836. const uint8 green,
  62837. const uint8 blue,
  62838. const float alpha) throw()
  62839. {
  62840. return Colour (red, green, blue, alpha);
  62841. }
  62842. Colour::Colour (const float hue,
  62843. const float saturation,
  62844. const float brightness,
  62845. const float alpha) throw()
  62846. {
  62847. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62848. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62849. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  62850. }
  62851. const Colour Colour::fromHSV (const float hue,
  62852. const float saturation,
  62853. const float brightness,
  62854. const float alpha) throw()
  62855. {
  62856. return Colour (hue, saturation, brightness, alpha);
  62857. }
  62858. Colour::Colour (const float hue,
  62859. const float saturation,
  62860. const float brightness,
  62861. const uint8 alpha) throw()
  62862. {
  62863. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62864. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62865. argb.setARGB (alpha, r, g, b);
  62866. }
  62867. Colour::~Colour() throw()
  62868. {
  62869. }
  62870. const PixelARGB Colour::getPixelARGB() const throw()
  62871. {
  62872. PixelARGB p (argb);
  62873. p.premultiply();
  62874. return p;
  62875. }
  62876. uint32 Colour::getARGB() const throw()
  62877. {
  62878. return argb.getARGB();
  62879. }
  62880. bool Colour::isTransparent() const throw()
  62881. {
  62882. return getAlpha() == 0;
  62883. }
  62884. bool Colour::isOpaque() const throw()
  62885. {
  62886. return getAlpha() == 0xff;
  62887. }
  62888. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  62889. {
  62890. PixelARGB newCol (argb);
  62891. newCol.setAlpha (newAlpha);
  62892. return Colour (newCol.getARGB());
  62893. }
  62894. const Colour Colour::withAlpha (const float newAlpha) const throw()
  62895. {
  62896. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  62897. PixelARGB newCol (argb);
  62898. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  62899. return Colour (newCol.getARGB());
  62900. }
  62901. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  62902. {
  62903. jassert (alphaMultiplier >= 0);
  62904. PixelARGB newCol (argb);
  62905. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  62906. return Colour (newCol.getARGB());
  62907. }
  62908. const Colour Colour::overlaidWith (const Colour& src) const throw()
  62909. {
  62910. const int destAlpha = getAlpha();
  62911. if (destAlpha > 0)
  62912. {
  62913. const int invA = 0xff - (int) src.getAlpha();
  62914. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  62915. if (resA > 0)
  62916. {
  62917. const int da = (invA * destAlpha) / resA;
  62918. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  62919. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  62920. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  62921. (uint8) resA);
  62922. }
  62923. return *this;
  62924. }
  62925. else
  62926. {
  62927. return src;
  62928. }
  62929. }
  62930. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  62931. {
  62932. if (proportionOfOther <= 0)
  62933. return *this;
  62934. if (proportionOfOther >= 1.0f)
  62935. return other;
  62936. PixelARGB c1 (getPixelARGB());
  62937. const PixelARGB c2 (other.getPixelARGB());
  62938. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  62939. c1.unpremultiply();
  62940. return Colour (c1.getARGB());
  62941. }
  62942. float Colour::getFloatRed() const throw()
  62943. {
  62944. return getRed() / 255.0f;
  62945. }
  62946. float Colour::getFloatGreen() const throw()
  62947. {
  62948. return getGreen() / 255.0f;
  62949. }
  62950. float Colour::getFloatBlue() const throw()
  62951. {
  62952. return getBlue() / 255.0f;
  62953. }
  62954. float Colour::getFloatAlpha() const throw()
  62955. {
  62956. return getAlpha() / 255.0f;
  62957. }
  62958. void Colour::getHSB (float& h, float& s, float& v) const throw()
  62959. {
  62960. const int r = getRed();
  62961. const int g = getGreen();
  62962. const int b = getBlue();
  62963. const int hi = jmax (r, g, b);
  62964. const int lo = jmin (r, g, b);
  62965. if (hi != 0)
  62966. {
  62967. s = (hi - lo) / (float) hi;
  62968. if (s != 0)
  62969. {
  62970. const float invDiff = 1.0f / (hi - lo);
  62971. const float red = (hi - r) * invDiff;
  62972. const float green = (hi - g) * invDiff;
  62973. const float blue = (hi - b) * invDiff;
  62974. if (r == hi)
  62975. h = blue - green;
  62976. else if (g == hi)
  62977. h = 2.0f + red - blue;
  62978. else
  62979. h = 4.0f + green - red;
  62980. h *= 1.0f / 6.0f;
  62981. if (h < 0)
  62982. ++h;
  62983. }
  62984. else
  62985. {
  62986. h = 0;
  62987. }
  62988. }
  62989. else
  62990. {
  62991. s = 0;
  62992. h = 0;
  62993. }
  62994. v = hi / 255.0f;
  62995. }
  62996. float Colour::getHue() const throw()
  62997. {
  62998. float h, s, b;
  62999. getHSB (h, s, b);
  63000. return h;
  63001. }
  63002. const Colour Colour::withHue (const float hue) const throw()
  63003. {
  63004. float h, s, b;
  63005. getHSB (h, s, b);
  63006. return Colour (hue, s, b, getAlpha());
  63007. }
  63008. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63009. {
  63010. float h, s, b;
  63011. getHSB (h, s, b);
  63012. h += amountToRotate;
  63013. h -= floorf (h);
  63014. return Colour (h, s, b, getAlpha());
  63015. }
  63016. float Colour::getSaturation() const throw()
  63017. {
  63018. float h, s, b;
  63019. getHSB (h, s, b);
  63020. return s;
  63021. }
  63022. const Colour Colour::withSaturation (const float saturation) const throw()
  63023. {
  63024. float h, s, b;
  63025. getHSB (h, s, b);
  63026. return Colour (h, saturation, b, getAlpha());
  63027. }
  63028. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63029. {
  63030. float h, s, b;
  63031. getHSB (h, s, b);
  63032. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63033. }
  63034. float Colour::getBrightness() const throw()
  63035. {
  63036. float h, s, b;
  63037. getHSB (h, s, b);
  63038. return b;
  63039. }
  63040. const Colour Colour::withBrightness (const float brightness) const throw()
  63041. {
  63042. float h, s, b;
  63043. getHSB (h, s, b);
  63044. return Colour (h, s, brightness, getAlpha());
  63045. }
  63046. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63047. {
  63048. float h, s, b;
  63049. getHSB (h, s, b);
  63050. b *= amount;
  63051. if (b > 1.0f)
  63052. b = 1.0f;
  63053. return Colour (h, s, b, getAlpha());
  63054. }
  63055. const Colour Colour::brighter (float amount) const throw()
  63056. {
  63057. amount = 1.0f / (1.0f + amount);
  63058. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63059. (uint8) (255 - (amount * (255 - getGreen()))),
  63060. (uint8) (255 - (amount * (255 - getBlue()))),
  63061. getAlpha());
  63062. }
  63063. const Colour Colour::darker (float amount) const throw()
  63064. {
  63065. amount = 1.0f / (1.0f + amount);
  63066. return Colour ((uint8) (amount * getRed()),
  63067. (uint8) (amount * getGreen()),
  63068. (uint8) (amount * getBlue()),
  63069. getAlpha());
  63070. }
  63071. const Colour Colour::greyLevel (const float brightness) throw()
  63072. {
  63073. const uint8 level
  63074. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63075. return Colour (level, level, level);
  63076. }
  63077. const Colour Colour::contrasting (const float amount) const throw()
  63078. {
  63079. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63080. ? Colours::black
  63081. : Colours::white).withAlpha (amount));
  63082. }
  63083. const Colour Colour::contrasting (const Colour& colour1,
  63084. const Colour& colour2) throw()
  63085. {
  63086. const float b1 = colour1.getBrightness();
  63087. const float b2 = colour2.getBrightness();
  63088. float best = 0.0f;
  63089. float bestDist = 0.0f;
  63090. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63091. {
  63092. const float d1 = fabsf (i - b1);
  63093. const float d2 = fabsf (i - b2);
  63094. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63095. if (dist > bestDist)
  63096. {
  63097. best = i;
  63098. bestDist = dist;
  63099. }
  63100. }
  63101. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63102. .withBrightness (best);
  63103. }
  63104. const String Colour::toString() const
  63105. {
  63106. return String::toHexString ((int) argb.getARGB());
  63107. }
  63108. const Colour Colour::fromString (const String& encodedColourString)
  63109. {
  63110. return Colour ((uint32) encodedColourString.getHexValue32());
  63111. }
  63112. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63113. {
  63114. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63115. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63116. .toUpperCase();
  63117. }
  63118. END_JUCE_NAMESPACE
  63119. /*** End of inlined file: juce_Colour.cpp ***/
  63120. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63121. BEGIN_JUCE_NAMESPACE
  63122. ColourGradient::ColourGradient() throw()
  63123. {
  63124. #ifdef JUCE_DEBUG
  63125. x1 = 987654.0f;
  63126. #endif
  63127. }
  63128. ColourGradient::ColourGradient (const Colour& colour1,
  63129. const float x1_,
  63130. const float y1_,
  63131. const Colour& colour2,
  63132. const float x2_,
  63133. const float y2_,
  63134. const bool isRadial_) throw()
  63135. : x1 (x1_),
  63136. y1 (y1_),
  63137. x2 (x2_),
  63138. y2 (y2_),
  63139. isRadial (isRadial_)
  63140. {
  63141. colours.add (0);
  63142. colours.add (colour1.getARGB());
  63143. colours.add (1 << 16);
  63144. colours.add (colour2.getARGB());
  63145. }
  63146. ColourGradient::~ColourGradient() throw()
  63147. {
  63148. }
  63149. void ColourGradient::clearColours() throw()
  63150. {
  63151. colours.clear();
  63152. }
  63153. void ColourGradient::addColour (const double proportionAlongGradient,
  63154. const Colour& colour) throw()
  63155. {
  63156. // must be within the two end-points
  63157. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63158. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63159. int i;
  63160. for (i = 0; i < colours.size(); i += 2)
  63161. if (colours.getUnchecked(i) > pos)
  63162. break;
  63163. colours.insert (i, pos);
  63164. colours.insert (i + 1, colour.getARGB());
  63165. }
  63166. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63167. {
  63168. for (int i = 1; i < colours.size(); i += 2)
  63169. {
  63170. const Colour c (colours.getUnchecked(i));
  63171. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63172. }
  63173. }
  63174. int ColourGradient::getNumColours() const throw()
  63175. {
  63176. return colours.size() >> 1;
  63177. }
  63178. double ColourGradient::getColourPosition (const int index) const throw()
  63179. {
  63180. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63181. }
  63182. const Colour ColourGradient::getColour (const int index) const throw()
  63183. {
  63184. return Colour (colours [(index << 1) + 1]);
  63185. }
  63186. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63187. {
  63188. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63189. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63190. if (integerPos <= 0 || colours.size() <= 2)
  63191. return getColour (0);
  63192. int i = colours.size() - 2;
  63193. while (integerPos < (int) colours.getUnchecked(i))
  63194. i -= 2;
  63195. if (i >= colours.size() - 2)
  63196. return Colour (colours.getUnchecked(i));
  63197. const int pos1 = colours.getUnchecked (i);
  63198. const Colour col1 (colours.getUnchecked (i + 1));
  63199. const int pos2 = colours.getUnchecked (i + 2);
  63200. const Colour col2 (colours.getUnchecked (i + 3));
  63201. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63202. }
  63203. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63204. {
  63205. #ifdef JUCE_DEBUG
  63206. // trying to use the object without setting its co-ordinates? Have a careful read of
  63207. // the comments for the constructors.
  63208. jassert (x1 != 987654.0f);
  63209. #endif
  63210. const int numColours = colours.size() >> 1;
  63211. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63212. transform.transformPoint (tx1, ty1);
  63213. transform.transformPoint (tx2, ty2);
  63214. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63215. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63216. lookupTable.malloc (numEntries);
  63217. if (numColours >= 2)
  63218. {
  63219. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63220. PixelARGB pix1 (colours.getUnchecked (1));
  63221. pix1.premultiply();
  63222. int index = 0;
  63223. for (int j = 2; j < colours.size(); j += 2)
  63224. {
  63225. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63226. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63227. pix2.premultiply();
  63228. for (int i = 0; i < numToDo; ++i)
  63229. {
  63230. jassert (index >= 0 && index < numEntries);
  63231. lookupTable[index] = pix1;
  63232. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63233. ++index;
  63234. }
  63235. pix1 = pix2;
  63236. }
  63237. while (index < numEntries)
  63238. lookupTable [index++] = pix1;
  63239. }
  63240. else
  63241. {
  63242. jassertfalse // no colours specified!
  63243. }
  63244. return numEntries;
  63245. }
  63246. bool ColourGradient::isOpaque() const throw()
  63247. {
  63248. for (int i = 1; i < colours.size(); i += 2)
  63249. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63250. return false;
  63251. return true;
  63252. }
  63253. bool ColourGradient::isInvisible() const throw()
  63254. {
  63255. for (int i = 1; i < colours.size(); i += 2)
  63256. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63257. return false;
  63258. return true;
  63259. }
  63260. END_JUCE_NAMESPACE
  63261. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63262. /*** Start of inlined file: juce_Colours.cpp ***/
  63263. BEGIN_JUCE_NAMESPACE
  63264. const Colour Colours::transparentBlack (0);
  63265. const Colour Colours::transparentWhite (0x00ffffff);
  63266. const Colour Colours::aliceblue (0xfff0f8ff);
  63267. const Colour Colours::antiquewhite (0xfffaebd7);
  63268. const Colour Colours::aqua (0xff00ffff);
  63269. const Colour Colours::aquamarine (0xff7fffd4);
  63270. const Colour Colours::azure (0xfff0ffff);
  63271. const Colour Colours::beige (0xfff5f5dc);
  63272. const Colour Colours::bisque (0xffffe4c4);
  63273. const Colour Colours::black (0xff000000);
  63274. const Colour Colours::blanchedalmond (0xffffebcd);
  63275. const Colour Colours::blue (0xff0000ff);
  63276. const Colour Colours::blueviolet (0xff8a2be2);
  63277. const Colour Colours::brown (0xffa52a2a);
  63278. const Colour Colours::burlywood (0xffdeb887);
  63279. const Colour Colours::cadetblue (0xff5f9ea0);
  63280. const Colour Colours::chartreuse (0xff7fff00);
  63281. const Colour Colours::chocolate (0xffd2691e);
  63282. const Colour Colours::coral (0xffff7f50);
  63283. const Colour Colours::cornflowerblue (0xff6495ed);
  63284. const Colour Colours::cornsilk (0xfffff8dc);
  63285. const Colour Colours::crimson (0xffdc143c);
  63286. const Colour Colours::cyan (0xff00ffff);
  63287. const Colour Colours::darkblue (0xff00008b);
  63288. const Colour Colours::darkcyan (0xff008b8b);
  63289. const Colour Colours::darkgoldenrod (0xffb8860b);
  63290. const Colour Colours::darkgrey (0xff555555);
  63291. const Colour Colours::darkgreen (0xff006400);
  63292. const Colour Colours::darkkhaki (0xffbdb76b);
  63293. const Colour Colours::darkmagenta (0xff8b008b);
  63294. const Colour Colours::darkolivegreen (0xff556b2f);
  63295. const Colour Colours::darkorange (0xffff8c00);
  63296. const Colour Colours::darkorchid (0xff9932cc);
  63297. const Colour Colours::darkred (0xff8b0000);
  63298. const Colour Colours::darksalmon (0xffe9967a);
  63299. const Colour Colours::darkseagreen (0xff8fbc8f);
  63300. const Colour Colours::darkslateblue (0xff483d8b);
  63301. const Colour Colours::darkslategrey (0xff2f4f4f);
  63302. const Colour Colours::darkturquoise (0xff00ced1);
  63303. const Colour Colours::darkviolet (0xff9400d3);
  63304. const Colour Colours::deeppink (0xffff1493);
  63305. const Colour Colours::deepskyblue (0xff00bfff);
  63306. const Colour Colours::dimgrey (0xff696969);
  63307. const Colour Colours::dodgerblue (0xff1e90ff);
  63308. const Colour Colours::firebrick (0xffb22222);
  63309. const Colour Colours::floralwhite (0xfffffaf0);
  63310. const Colour Colours::forestgreen (0xff228b22);
  63311. const Colour Colours::fuchsia (0xffff00ff);
  63312. const Colour Colours::gainsboro (0xffdcdcdc);
  63313. const Colour Colours::gold (0xffffd700);
  63314. const Colour Colours::goldenrod (0xffdaa520);
  63315. const Colour Colours::grey (0xff808080);
  63316. const Colour Colours::green (0xff008000);
  63317. const Colour Colours::greenyellow (0xffadff2f);
  63318. const Colour Colours::honeydew (0xfff0fff0);
  63319. const Colour Colours::hotpink (0xffff69b4);
  63320. const Colour Colours::indianred (0xffcd5c5c);
  63321. const Colour Colours::indigo (0xff4b0082);
  63322. const Colour Colours::ivory (0xfffffff0);
  63323. const Colour Colours::khaki (0xfff0e68c);
  63324. const Colour Colours::lavender (0xffe6e6fa);
  63325. const Colour Colours::lavenderblush (0xfffff0f5);
  63326. const Colour Colours::lemonchiffon (0xfffffacd);
  63327. const Colour Colours::lightblue (0xffadd8e6);
  63328. const Colour Colours::lightcoral (0xfff08080);
  63329. const Colour Colours::lightcyan (0xffe0ffff);
  63330. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63331. const Colour Colours::lightgreen (0xff90ee90);
  63332. const Colour Colours::lightgrey (0xffd3d3d3);
  63333. const Colour Colours::lightpink (0xffffb6c1);
  63334. const Colour Colours::lightsalmon (0xffffa07a);
  63335. const Colour Colours::lightseagreen (0xff20b2aa);
  63336. const Colour Colours::lightskyblue (0xff87cefa);
  63337. const Colour Colours::lightslategrey (0xff778899);
  63338. const Colour Colours::lightsteelblue (0xffb0c4de);
  63339. const Colour Colours::lightyellow (0xffffffe0);
  63340. const Colour Colours::lime (0xff00ff00);
  63341. const Colour Colours::limegreen (0xff32cd32);
  63342. const Colour Colours::linen (0xfffaf0e6);
  63343. const Colour Colours::magenta (0xffff00ff);
  63344. const Colour Colours::maroon (0xff800000);
  63345. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63346. const Colour Colours::mediumblue (0xff0000cd);
  63347. const Colour Colours::mediumorchid (0xffba55d3);
  63348. const Colour Colours::mediumpurple (0xff9370db);
  63349. const Colour Colours::mediumseagreen (0xff3cb371);
  63350. const Colour Colours::mediumslateblue (0xff7b68ee);
  63351. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63352. const Colour Colours::mediumturquoise (0xff48d1cc);
  63353. const Colour Colours::mediumvioletred (0xffc71585);
  63354. const Colour Colours::midnightblue (0xff191970);
  63355. const Colour Colours::mintcream (0xfff5fffa);
  63356. const Colour Colours::mistyrose (0xffffe4e1);
  63357. const Colour Colours::navajowhite (0xffffdead);
  63358. const Colour Colours::navy (0xff000080);
  63359. const Colour Colours::oldlace (0xfffdf5e6);
  63360. const Colour Colours::olive (0xff808000);
  63361. const Colour Colours::olivedrab (0xff6b8e23);
  63362. const Colour Colours::orange (0xffffa500);
  63363. const Colour Colours::orangered (0xffff4500);
  63364. const Colour Colours::orchid (0xffda70d6);
  63365. const Colour Colours::palegoldenrod (0xffeee8aa);
  63366. const Colour Colours::palegreen (0xff98fb98);
  63367. const Colour Colours::paleturquoise (0xffafeeee);
  63368. const Colour Colours::palevioletred (0xffdb7093);
  63369. const Colour Colours::papayawhip (0xffffefd5);
  63370. const Colour Colours::peachpuff (0xffffdab9);
  63371. const Colour Colours::peru (0xffcd853f);
  63372. const Colour Colours::pink (0xffffc0cb);
  63373. const Colour Colours::plum (0xffdda0dd);
  63374. const Colour Colours::powderblue (0xffb0e0e6);
  63375. const Colour Colours::purple (0xff800080);
  63376. const Colour Colours::red (0xffff0000);
  63377. const Colour Colours::rosybrown (0xffbc8f8f);
  63378. const Colour Colours::royalblue (0xff4169e1);
  63379. const Colour Colours::saddlebrown (0xff8b4513);
  63380. const Colour Colours::salmon (0xfffa8072);
  63381. const Colour Colours::sandybrown (0xfff4a460);
  63382. const Colour Colours::seagreen (0xff2e8b57);
  63383. const Colour Colours::seashell (0xfffff5ee);
  63384. const Colour Colours::sienna (0xffa0522d);
  63385. const Colour Colours::silver (0xffc0c0c0);
  63386. const Colour Colours::skyblue (0xff87ceeb);
  63387. const Colour Colours::slateblue (0xff6a5acd);
  63388. const Colour Colours::slategrey (0xff708090);
  63389. const Colour Colours::snow (0xfffffafa);
  63390. const Colour Colours::springgreen (0xff00ff7f);
  63391. const Colour Colours::steelblue (0xff4682b4);
  63392. const Colour Colours::tan (0xffd2b48c);
  63393. const Colour Colours::teal (0xff008080);
  63394. const Colour Colours::thistle (0xffd8bfd8);
  63395. const Colour Colours::tomato (0xffff6347);
  63396. const Colour Colours::turquoise (0xff40e0d0);
  63397. const Colour Colours::violet (0xffee82ee);
  63398. const Colour Colours::wheat (0xfff5deb3);
  63399. const Colour Colours::white (0xffffffff);
  63400. const Colour Colours::whitesmoke (0xfff5f5f5);
  63401. const Colour Colours::yellow (0xffffff00);
  63402. const Colour Colours::yellowgreen (0xff9acd32);
  63403. const Colour Colours::findColourForName (const String& colourName,
  63404. const Colour& defaultColour)
  63405. {
  63406. static const int presets[] =
  63407. {
  63408. // (first value is the string's hashcode, second is ARGB)
  63409. 0x05978fff, 0xff000000, /* black */
  63410. 0x06bdcc29, 0xffffffff, /* white */
  63411. 0x002e305a, 0xff0000ff, /* blue */
  63412. 0x00308adf, 0xff808080, /* grey */
  63413. 0x05e0cf03, 0xff008000, /* green */
  63414. 0x0001b891, 0xffff0000, /* red */
  63415. 0xd43c6474, 0xffffff00, /* yellow */
  63416. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63417. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63418. 0x002dcebc, 0xff00ffff, /* aqua */
  63419. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63420. 0x0590228f, 0xfff0ffff, /* azure */
  63421. 0x05947fe4, 0xfff5f5dc, /* beige */
  63422. 0xad388e35, 0xffffe4c4, /* bisque */
  63423. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63424. 0x39129959, 0xff8a2be2, /* blueviolet */
  63425. 0x059a8136, 0xffa52a2a, /* brown */
  63426. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63427. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63428. 0x6b748956, 0xff7fff00, /* chartreuse */
  63429. 0x2903623c, 0xffd2691e, /* chocolate */
  63430. 0x05a74431, 0xffff7f50, /* coral */
  63431. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63432. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63433. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63434. 0x002ed323, 0xff00ffff, /* cyan */
  63435. 0x67cc74d0, 0xff00008b, /* darkblue */
  63436. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63437. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63438. 0x67cecf55, 0xff555555, /* darkgrey */
  63439. 0x920b194d, 0xff006400, /* darkgreen */
  63440. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63441. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63442. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63443. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63444. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63445. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63446. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63447. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63448. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63449. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63450. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63451. 0xc8769375, 0xff9400d3, /* darkviolet */
  63452. 0x25832862, 0xffff1493, /* deeppink */
  63453. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63454. 0x634c8b67, 0xff696969, /* dimgrey */
  63455. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63456. 0xef19e3cb, 0xffb22222, /* firebrick */
  63457. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63458. 0xd086fd06, 0xff228b22, /* forestgreen */
  63459. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63460. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63461. 0x00308060, 0xffffd700, /* gold */
  63462. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63463. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63464. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63465. 0x41892743, 0xffff69b4, /* hotpink */
  63466. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63467. 0xb969fed2, 0xff4b0082, /* indigo */
  63468. 0x05fef6a9, 0xfffffff0, /* ivory */
  63469. 0x06149302, 0xfff0e68c, /* khaki */
  63470. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63471. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63472. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63473. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63474. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63475. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63476. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63477. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63478. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63479. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63480. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63481. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63482. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63483. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63484. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63485. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63486. 0x0032afd5, 0xff00ff00, /* lime */
  63487. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63488. 0x06234efa, 0xfffaf0e6, /* linen */
  63489. 0x316858a9, 0xffff00ff, /* magenta */
  63490. 0xbf8ca470, 0xff800000, /* maroon */
  63491. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63492. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63493. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63494. 0x07556b71, 0xff9370db, /* mediumpurple */
  63495. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63496. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63497. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63498. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63499. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63500. 0x168eb32a, 0xff191970, /* midnightblue */
  63501. 0x4306b960, 0xfff5fffa, /* mintcream */
  63502. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63503. 0xe97218a6, 0xffffdead, /* navajowhite */
  63504. 0x00337bb6, 0xff000080, /* navy */
  63505. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63506. 0x064ee1db, 0xff808000, /* olive */
  63507. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63508. 0xc3de262e, 0xffffa500, /* orange */
  63509. 0x58bebba3, 0xffff4500, /* orangered */
  63510. 0xc3def8a3, 0xffda70d6, /* orchid */
  63511. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63512. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63513. 0x74022737, 0xffafeeee, /* paleturquoise */
  63514. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63515. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63516. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63517. 0x003472f8, 0xffcd853f, /* peru */
  63518. 0x00348176, 0xffffc0cb, /* pink */
  63519. 0x00348d94, 0xffdda0dd, /* plum */
  63520. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63521. 0xc5c507bc, 0xff800080, /* purple */
  63522. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63523. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63524. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63525. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63526. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63527. 0x34636c14, 0xff2e8b57, /* seagreen */
  63528. 0x3507fb41, 0xfffff5ee, /* seashell */
  63529. 0xca348772, 0xffa0522d, /* sienna */
  63530. 0xca37d30d, 0xffc0c0c0, /* silver */
  63531. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63532. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63533. 0x44ab37f8, 0xff708090, /* slategrey */
  63534. 0x0035f183, 0xfffffafa, /* snow */
  63535. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63536. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63537. 0x0001bfa1, 0xffd2b48c, /* tan */
  63538. 0x0036425c, 0xff008080, /* teal */
  63539. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63540. 0xcc41600a, 0xffff6347, /* tomato */
  63541. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63542. 0xcf57947f, 0xffee82ee, /* violet */
  63543. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63544. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63545. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63546. };
  63547. const int hash = colourName.trim().toLowerCase().hashCode();
  63548. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63549. if (presets [i] == hash)
  63550. return Colour (presets [i + 1]);
  63551. return defaultColour;
  63552. }
  63553. END_JUCE_NAMESPACE
  63554. /*** End of inlined file: juce_Colours.cpp ***/
  63555. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63556. BEGIN_JUCE_NAMESPACE
  63557. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63558. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63559. const Path& path, const AffineTransform& transform)
  63560. : bounds (bounds_),
  63561. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63562. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63563. needToCheckEmptinesss (true)
  63564. {
  63565. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63566. int* t = table;
  63567. for (int i = bounds.getHeight(); --i >= 0;)
  63568. {
  63569. *t = 0;
  63570. t += lineStrideElements;
  63571. }
  63572. const int topLimit = bounds.getY() << 8;
  63573. const int heightLimit = bounds.getHeight() << 8;
  63574. const int leftLimit = bounds.getX() << 8;
  63575. const int rightLimit = bounds.getRight() << 8;
  63576. PathFlatteningIterator iter (path, transform);
  63577. while (iter.next())
  63578. {
  63579. int y1 = roundToInt (iter.y1 * 256.0f);
  63580. int y2 = roundToInt (iter.y2 * 256.0f);
  63581. if (y1 != y2)
  63582. {
  63583. y1 -= topLimit;
  63584. y2 -= topLimit;
  63585. const int startY = y1;
  63586. int direction = -1;
  63587. if (y1 > y2)
  63588. {
  63589. swapVariables (y1, y2);
  63590. direction = 1;
  63591. }
  63592. if (y1 < 0)
  63593. y1 = 0;
  63594. if (y2 > heightLimit)
  63595. y2 = heightLimit;
  63596. if (y1 < y2)
  63597. {
  63598. const double startX = 256.0f * iter.x1;
  63599. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63600. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63601. do
  63602. {
  63603. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63604. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63605. if (x < leftLimit)
  63606. x = leftLimit;
  63607. else if (x >= rightLimit)
  63608. x = rightLimit - 1;
  63609. addEdgePoint (x, y1 >> 8, direction * step);
  63610. y1 += step;
  63611. }
  63612. while (y1 < y2);
  63613. }
  63614. }
  63615. }
  63616. sanitiseLevels (path.isUsingNonZeroWinding());
  63617. }
  63618. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63619. : bounds (rectangleToAdd),
  63620. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63621. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63622. needToCheckEmptinesss (true)
  63623. {
  63624. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63625. table[0] = 0;
  63626. const int x1 = rectangleToAdd.getX() << 8;
  63627. const int x2 = rectangleToAdd.getRight() << 8;
  63628. int* t = table;
  63629. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63630. {
  63631. t[0] = 2;
  63632. t[1] = x1;
  63633. t[2] = 255;
  63634. t[3] = x2;
  63635. t[4] = 0;
  63636. t += lineStrideElements;
  63637. }
  63638. }
  63639. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63640. : bounds (rectanglesToAdd.getBounds()),
  63641. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63642. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63643. needToCheckEmptinesss (true)
  63644. {
  63645. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63646. int* t = table;
  63647. for (int i = bounds.getHeight(); --i >= 0;)
  63648. {
  63649. *t = 0;
  63650. t += lineStrideElements;
  63651. }
  63652. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63653. {
  63654. const Rectangle<int>* const r = iter.getRectangle();
  63655. const int x1 = r->getX() << 8;
  63656. const int x2 = r->getRight() << 8;
  63657. int y = r->getY() - bounds.getY();
  63658. for (int j = r->getHeight(); --j >= 0;)
  63659. {
  63660. addEdgePoint (x1, y, 255);
  63661. addEdgePoint (x2, y, -255);
  63662. ++y;
  63663. }
  63664. }
  63665. sanitiseLevels (true);
  63666. }
  63667. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63668. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63669. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63670. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63671. needToCheckEmptinesss (true)
  63672. {
  63673. jassert (w > 0 && h > 0);
  63674. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63675. table[0] = 0;
  63676. const int x1 = roundToInt (x * 256.0f);
  63677. const int x2 = roundToInt ((x + w) * 256.0f);
  63678. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63679. jassert (y1 < 256);
  63680. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63681. if (x2 <= x1 || y2 <= y1)
  63682. {
  63683. bounds.setHeight (0);
  63684. return;
  63685. }
  63686. int lineY = 0;
  63687. int* t = table;
  63688. if ((y1 >> 8) == (y2 >> 8))
  63689. {
  63690. t[0] = 2;
  63691. t[1] = x1;
  63692. t[2] = y2 - y1;
  63693. t[3] = x2;
  63694. t[4] = 0;
  63695. ++lineY;
  63696. t += lineStrideElements;
  63697. }
  63698. else
  63699. {
  63700. t[0] = 2;
  63701. t[1] = x1;
  63702. t[2] = 255 - (y1 & 255);
  63703. t[3] = x2;
  63704. t[4] = 0;
  63705. ++lineY;
  63706. t += lineStrideElements;
  63707. while (lineY < (y2 >> 8))
  63708. {
  63709. t[0] = 2;
  63710. t[1] = x1;
  63711. t[2] = 255;
  63712. t[3] = x2;
  63713. t[4] = 0;
  63714. ++lineY;
  63715. t += lineStrideElements;
  63716. }
  63717. jassert (lineY < bounds.getHeight());
  63718. t[0] = 2;
  63719. t[1] = x1;
  63720. t[2] = y2 & 255;
  63721. t[3] = x2;
  63722. t[4] = 0;
  63723. ++lineY;
  63724. t += lineStrideElements;
  63725. }
  63726. while (lineY < bounds.getHeight())
  63727. {
  63728. t[0] = 0;
  63729. t += lineStrideElements;
  63730. ++lineY;
  63731. }
  63732. }
  63733. EdgeTable::EdgeTable (const EdgeTable& other)
  63734. : table (0)
  63735. {
  63736. operator= (other);
  63737. }
  63738. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63739. {
  63740. bounds = other.bounds;
  63741. maxEdgesPerLine = other.maxEdgesPerLine;
  63742. lineStrideElements = other.lineStrideElements;
  63743. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63744. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63745. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63746. return *this;
  63747. }
  63748. EdgeTable::~EdgeTable()
  63749. {
  63750. }
  63751. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63752. {
  63753. while (--numLines >= 0)
  63754. {
  63755. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63756. src += srcLineStride;
  63757. dest += destLineStride;
  63758. }
  63759. }
  63760. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63761. {
  63762. // Convert the table from relative windings to absolute levels..
  63763. int* lineStart = table;
  63764. for (int i = bounds.getHeight(); --i >= 0;)
  63765. {
  63766. int* line = lineStart;
  63767. lineStart += lineStrideElements;
  63768. int num = *line;
  63769. if (num == 0)
  63770. continue;
  63771. int level = 0;
  63772. if (useNonZeroWinding)
  63773. {
  63774. while (--num > 0)
  63775. {
  63776. line += 2;
  63777. level += *line;
  63778. int corrected = abs (level);
  63779. if (corrected >> 8)
  63780. corrected = 255;
  63781. *line = corrected;
  63782. }
  63783. }
  63784. else
  63785. {
  63786. while (--num > 0)
  63787. {
  63788. line += 2;
  63789. level += *line;
  63790. int corrected = abs (level);
  63791. if (corrected >> 8)
  63792. {
  63793. corrected &= 511;
  63794. if (corrected >> 8)
  63795. corrected = 511 - corrected;
  63796. }
  63797. *line = corrected;
  63798. }
  63799. }
  63800. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  63801. }
  63802. }
  63803. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  63804. {
  63805. if (newNumEdgesPerLine != maxEdgesPerLine)
  63806. {
  63807. maxEdgesPerLine = newNumEdgesPerLine;
  63808. jassert (bounds.getHeight() > 0);
  63809. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  63810. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  63811. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  63812. table.swapWith (newTable);
  63813. lineStrideElements = newLineStrideElements;
  63814. }
  63815. }
  63816. void EdgeTable::optimiseTable() throw()
  63817. {
  63818. int maxLineElements = 0;
  63819. for (int i = bounds.getHeight(); --i >= 0;)
  63820. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  63821. remapTableForNumEdges (maxLineElements);
  63822. }
  63823. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  63824. {
  63825. jassert (y >= 0 && y < bounds.getHeight());
  63826. int* line = table + lineStrideElements * y;
  63827. const int numPoints = line[0];
  63828. int n = numPoints << 1;
  63829. if (n > 0)
  63830. {
  63831. while (n > 0)
  63832. {
  63833. const int cx = line [n - 1];
  63834. if (cx <= x)
  63835. {
  63836. if (cx == x)
  63837. {
  63838. line [n] += winding;
  63839. return;
  63840. }
  63841. break;
  63842. }
  63843. n -= 2;
  63844. }
  63845. if (numPoints >= maxEdgesPerLine)
  63846. {
  63847. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  63848. jassert (numPoints < maxEdgesPerLine);
  63849. line = table + lineStrideElements * y;
  63850. }
  63851. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  63852. }
  63853. line [n + 1] = x;
  63854. line [n + 2] = winding;
  63855. line[0]++;
  63856. }
  63857. void EdgeTable::translate (float dx, int dy) throw()
  63858. {
  63859. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  63860. int* lineStart = table;
  63861. const int intDx = (int) (dx * 256.0f);
  63862. for (int i = bounds.getHeight(); --i >= 0;)
  63863. {
  63864. int* line = lineStart;
  63865. lineStart += lineStrideElements;
  63866. int num = *line++;
  63867. while (--num >= 0)
  63868. {
  63869. *line += intDx;
  63870. line += 2;
  63871. }
  63872. }
  63873. }
  63874. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  63875. {
  63876. jassert (y >= 0 && y < bounds.getHeight());
  63877. int* dest = table + lineStrideElements * y;
  63878. if (dest[0] == 0)
  63879. return;
  63880. int otherNumPoints = *otherLine;
  63881. if (otherNumPoints == 0)
  63882. {
  63883. *dest = 0;
  63884. return;
  63885. }
  63886. const int right = bounds.getRight() << 8;
  63887. // optimise for the common case where our line lies entirely within a
  63888. // single pair of points, as happens when clipping to a simple rect.
  63889. if (otherNumPoints == 2 && otherLine[2] >= 255)
  63890. {
  63891. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  63892. return;
  63893. }
  63894. ++otherLine;
  63895. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  63896. int* temp = (int*) alloca (lineSizeBytes);
  63897. memcpy (temp, dest, lineSizeBytes);
  63898. const int* src1 = temp;
  63899. int srcNum1 = *src1++;
  63900. int x1 = *src1++;
  63901. const int* src2 = otherLine;
  63902. int srcNum2 = otherNumPoints;
  63903. int x2 = *src2++;
  63904. int destIndex = 0, destTotal = 0;
  63905. int level1 = 0, level2 = 0;
  63906. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  63907. while (srcNum1 > 0 && srcNum2 > 0)
  63908. {
  63909. int nextX;
  63910. if (x1 < x2)
  63911. {
  63912. nextX = x1;
  63913. level1 = *src1++;
  63914. x1 = *src1++;
  63915. --srcNum1;
  63916. }
  63917. else if (x1 == x2)
  63918. {
  63919. nextX = x1;
  63920. level1 = *src1++;
  63921. level2 = *src2++;
  63922. x1 = *src1++;
  63923. x2 = *src2++;
  63924. --srcNum1;
  63925. --srcNum2;
  63926. }
  63927. else
  63928. {
  63929. nextX = x2;
  63930. level2 = *src2++;
  63931. x2 = *src2++;
  63932. --srcNum2;
  63933. }
  63934. if (nextX > lastX)
  63935. {
  63936. if (nextX >= right)
  63937. break;
  63938. lastX = nextX;
  63939. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  63940. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  63941. if (nextLevel != lastLevel)
  63942. {
  63943. if (destTotal >= maxEdgesPerLine)
  63944. {
  63945. dest[0] = destTotal;
  63946. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  63947. dest = table + lineStrideElements * y;
  63948. }
  63949. ++destTotal;
  63950. lastLevel = nextLevel;
  63951. dest[++destIndex] = nextX;
  63952. dest[++destIndex] = nextLevel;
  63953. }
  63954. }
  63955. }
  63956. if (lastLevel > 0)
  63957. {
  63958. if (destTotal >= maxEdgesPerLine)
  63959. {
  63960. dest[0] = destTotal;
  63961. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  63962. dest = table + lineStrideElements * y;
  63963. }
  63964. ++destTotal;
  63965. dest[++destIndex] = right;
  63966. dest[++destIndex] = 0;
  63967. }
  63968. dest[0] = destTotal;
  63969. #if JUCE_DEBUG
  63970. int last = std::numeric_limits<int>::min();
  63971. for (int i = 0; i < dest[0]; ++i)
  63972. {
  63973. jassert (dest[i * 2 + 1] > last);
  63974. last = dest[i * 2 + 1];
  63975. }
  63976. jassert (dest [dest[0] * 2] == 0);
  63977. #endif
  63978. }
  63979. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  63980. {
  63981. int* lastItem = dest + (dest[0] * 2 - 1);
  63982. if (x2 < lastItem[0])
  63983. {
  63984. if (x2 <= dest[1])
  63985. {
  63986. dest[0] = 0;
  63987. return;
  63988. }
  63989. while (x2 < lastItem[-2])
  63990. {
  63991. --(dest[0]);
  63992. lastItem -= 2;
  63993. }
  63994. lastItem[0] = x2;
  63995. lastItem[1] = 0;
  63996. }
  63997. if (x1 > dest[1])
  63998. {
  63999. while (lastItem[0] > x1)
  64000. lastItem -= 2;
  64001. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64002. if (itemsRemoved > 0)
  64003. {
  64004. dest[0] -= itemsRemoved;
  64005. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64006. }
  64007. dest[1] = x1;
  64008. }
  64009. }
  64010. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64011. {
  64012. const Rectangle<int> clipped (r.getIntersection (bounds));
  64013. if (clipped.isEmpty())
  64014. {
  64015. needToCheckEmptinesss = false;
  64016. bounds.setHeight (0);
  64017. }
  64018. else
  64019. {
  64020. const int top = clipped.getY() - bounds.getY();
  64021. const int bottom = clipped.getBottom() - bounds.getY();
  64022. if (bottom < bounds.getHeight())
  64023. bounds.setHeight (bottom);
  64024. if (clipped.getRight() < bounds.getRight())
  64025. bounds.setRight (clipped.getRight());
  64026. for (int i = top; --i >= 0;)
  64027. table [lineStrideElements * i] = 0;
  64028. if (clipped.getX() > bounds.getX())
  64029. {
  64030. const int x1 = clipped.getX() << 8;
  64031. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64032. int* line = table + lineStrideElements * top;
  64033. for (int i = bottom - top; --i >= 0;)
  64034. {
  64035. if (line[0] != 0)
  64036. clipEdgeTableLineToRange (line, x1, x2);
  64037. line += lineStrideElements;
  64038. }
  64039. }
  64040. needToCheckEmptinesss = true;
  64041. }
  64042. }
  64043. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64044. {
  64045. const Rectangle<int> clipped (r.getIntersection (bounds));
  64046. if (! clipped.isEmpty())
  64047. {
  64048. const int top = clipped.getY() - bounds.getY();
  64049. const int bottom = clipped.getBottom() - bounds.getY();
  64050. //XXX optimise here by shortening the table if it fills top or bottom
  64051. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64052. clipped.getX() << 8, 0,
  64053. clipped.getRight() << 8, 255,
  64054. std::numeric_limits<int>::max(), 0 };
  64055. for (int i = top; i < bottom; ++i)
  64056. intersectWithEdgeTableLine (i, rectLine);
  64057. needToCheckEmptinesss = true;
  64058. }
  64059. }
  64060. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64061. {
  64062. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64063. if (clipped.isEmpty())
  64064. {
  64065. needToCheckEmptinesss = false;
  64066. bounds.setHeight (0);
  64067. }
  64068. else
  64069. {
  64070. const int top = clipped.getY() - bounds.getY();
  64071. const int bottom = clipped.getBottom() - bounds.getY();
  64072. if (bottom < bounds.getHeight())
  64073. bounds.setHeight (bottom);
  64074. if (clipped.getRight() < bounds.getRight())
  64075. bounds.setRight (clipped.getRight());
  64076. int i = 0;
  64077. for (i = top; --i >= 0;)
  64078. table [lineStrideElements * i] = 0;
  64079. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64080. for (i = top; i < bottom; ++i)
  64081. {
  64082. intersectWithEdgeTableLine (i, otherLine);
  64083. otherLine += other.lineStrideElements;
  64084. }
  64085. needToCheckEmptinesss = true;
  64086. }
  64087. }
  64088. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64089. {
  64090. y -= bounds.getY();
  64091. if (y < 0 || y >= bounds.getHeight())
  64092. return;
  64093. needToCheckEmptinesss = true;
  64094. if (numPixels <= 0)
  64095. {
  64096. table [lineStrideElements * y] = 0;
  64097. return;
  64098. }
  64099. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64100. int destIndex = 0, lastLevel = 0;
  64101. while (--numPixels >= 0)
  64102. {
  64103. const int alpha = *mask;
  64104. mask += maskStride;
  64105. if (alpha != lastLevel)
  64106. {
  64107. tempLine[++destIndex] = (x << 8);
  64108. tempLine[++destIndex] = alpha;
  64109. lastLevel = alpha;
  64110. }
  64111. ++x;
  64112. }
  64113. if (lastLevel > 0)
  64114. {
  64115. tempLine[++destIndex] = (x << 8);
  64116. tempLine[++destIndex] = 0;
  64117. }
  64118. tempLine[0] = destIndex >> 1;
  64119. intersectWithEdgeTableLine (y, tempLine);
  64120. }
  64121. bool EdgeTable::isEmpty() throw()
  64122. {
  64123. if (needToCheckEmptinesss)
  64124. {
  64125. needToCheckEmptinesss = false;
  64126. int* t = table;
  64127. for (int i = bounds.getHeight(); --i >= 0;)
  64128. {
  64129. if (t[0] > 1)
  64130. return false;
  64131. t += lineStrideElements;
  64132. }
  64133. bounds.setHeight (0);
  64134. }
  64135. return bounds.getHeight() == 0;
  64136. }
  64137. END_JUCE_NAMESPACE
  64138. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64139. /*** Start of inlined file: juce_FillType.cpp ***/
  64140. BEGIN_JUCE_NAMESPACE
  64141. FillType::FillType() throw()
  64142. : colour (0xff000000), image (0)
  64143. {
  64144. }
  64145. FillType::FillType (const Colour& colour_) throw()
  64146. : colour (colour_), image (0)
  64147. {
  64148. }
  64149. FillType::FillType (const ColourGradient& gradient_) throw()
  64150. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64151. {
  64152. }
  64153. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64154. : colour (0xff000000), image (&image_), transform (transform_)
  64155. {
  64156. }
  64157. FillType::FillType (const FillType& other) throw()
  64158. : colour (other.colour),
  64159. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64160. image (other.image), transform (other.transform)
  64161. {
  64162. }
  64163. FillType& FillType::operator= (const FillType& other) throw()
  64164. {
  64165. if (this != &other)
  64166. {
  64167. colour = other.colour;
  64168. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64169. image = other.image;
  64170. transform = other.transform;
  64171. }
  64172. return *this;
  64173. }
  64174. FillType::~FillType() throw()
  64175. {
  64176. }
  64177. void FillType::setColour (const Colour& newColour) throw()
  64178. {
  64179. gradient = 0;
  64180. image = 0;
  64181. colour = newColour;
  64182. }
  64183. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64184. {
  64185. if (gradient != 0)
  64186. {
  64187. *gradient = newGradient;
  64188. }
  64189. else
  64190. {
  64191. image = 0;
  64192. gradient = new ColourGradient (newGradient);
  64193. colour = Colours::black;
  64194. }
  64195. }
  64196. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64197. {
  64198. gradient = 0;
  64199. image = &image_;
  64200. transform = transform_;
  64201. colour = Colours::black;
  64202. }
  64203. void FillType::setOpacity (const float newOpacity) throw()
  64204. {
  64205. colour = colour.withAlpha (newOpacity);
  64206. }
  64207. END_JUCE_NAMESPACE
  64208. /*** End of inlined file: juce_FillType.cpp ***/
  64209. /*** Start of inlined file: juce_Graphics.cpp ***/
  64210. BEGIN_JUCE_NAMESPACE
  64211. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64212. template <typename Type>
  64213. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64214. {
  64215. const int maxVal = 0x3fffffff;
  64216. return (int) x >= -maxVal && (int) x <= maxVal
  64217. && (int) y >= -maxVal && (int) y <= maxVal
  64218. && (int) w >= -maxVal && (int) w <= maxVal
  64219. && (int) h >= -maxVal && (int) h <= maxVal;
  64220. }
  64221. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64222. {
  64223. }
  64224. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64225. {
  64226. }
  64227. Graphics::Graphics (Image& imageToDrawOnto)
  64228. : context (imageToDrawOnto.createLowLevelContext()),
  64229. contextToDelete (context),
  64230. saveStatePending (false)
  64231. {
  64232. }
  64233. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64234. : context (internalContext),
  64235. saveStatePending (false)
  64236. {
  64237. }
  64238. Graphics::~Graphics()
  64239. {
  64240. }
  64241. void Graphics::resetToDefaultState()
  64242. {
  64243. saveStateIfPending();
  64244. context->setFill (FillType());
  64245. context->setFont (Font());
  64246. context->setInterpolationQuality (defaultQuality);
  64247. }
  64248. bool Graphics::isVectorDevice() const
  64249. {
  64250. return context->isVectorDevice();
  64251. }
  64252. bool Graphics::reduceClipRegion (const int x, const int y, const int w, const int h)
  64253. {
  64254. saveStateIfPending();
  64255. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64256. }
  64257. bool Graphics::reduceClipRegion (const RectangleList& clipRegion)
  64258. {
  64259. saveStateIfPending();
  64260. return context->clipToRectangleList (clipRegion);
  64261. }
  64262. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform)
  64263. {
  64264. saveStateIfPending();
  64265. context->clipToPath (path, transform);
  64266. return ! context->isClipEmpty();
  64267. }
  64268. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform)
  64269. {
  64270. saveStateIfPending();
  64271. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64272. return ! context->isClipEmpty();
  64273. }
  64274. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude)
  64275. {
  64276. saveStateIfPending();
  64277. context->excludeClipRectangle (rectangleToExclude);
  64278. }
  64279. bool Graphics::isClipEmpty() const
  64280. {
  64281. return context->isClipEmpty();
  64282. }
  64283. const Rectangle<int> Graphics::getClipBounds() const
  64284. {
  64285. return context->getClipBounds();
  64286. }
  64287. void Graphics::saveState()
  64288. {
  64289. saveStateIfPending();
  64290. saveStatePending = true;
  64291. }
  64292. void Graphics::restoreState()
  64293. {
  64294. if (saveStatePending)
  64295. saveStatePending = false;
  64296. else
  64297. context->restoreState();
  64298. }
  64299. void Graphics::saveStateIfPending()
  64300. {
  64301. if (saveStatePending)
  64302. {
  64303. saveStatePending = false;
  64304. context->saveState();
  64305. }
  64306. }
  64307. void Graphics::setOrigin (const int newOriginX, const int newOriginY)
  64308. {
  64309. saveStateIfPending();
  64310. context->setOrigin (newOriginX, newOriginY);
  64311. }
  64312. bool Graphics::clipRegionIntersects (const int x, const int y, const int w, const int h) const
  64313. {
  64314. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64315. }
  64316. void Graphics::setColour (const Colour& newColour)
  64317. {
  64318. saveStateIfPending();
  64319. context->setFill (newColour);
  64320. }
  64321. void Graphics::setOpacity (const float newOpacity)
  64322. {
  64323. saveStateIfPending();
  64324. context->setOpacity (newOpacity);
  64325. }
  64326. void Graphics::setGradientFill (const ColourGradient& gradient)
  64327. {
  64328. setFillType (gradient);
  64329. }
  64330. void Graphics::setTiledImageFill (const Image& imageToUse, const int anchorX, const int anchorY, const float opacity)
  64331. {
  64332. saveStateIfPending();
  64333. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64334. context->setOpacity (opacity);
  64335. }
  64336. void Graphics::setFillType (const FillType& newFill)
  64337. {
  64338. saveStateIfPending();
  64339. context->setFill (newFill);
  64340. }
  64341. void Graphics::setFont (const Font& newFont)
  64342. {
  64343. saveStateIfPending();
  64344. context->setFont (newFont);
  64345. }
  64346. void Graphics::setFont (const float newFontHeight, const int newFontStyleFlags)
  64347. {
  64348. saveStateIfPending();
  64349. Font f (context->getFont());
  64350. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64351. context->setFont (f);
  64352. }
  64353. void Graphics::drawSingleLineText (const String& text, const int startX, const int baselineY) const
  64354. {
  64355. if (text.isNotEmpty()
  64356. && startX < context->getClipBounds().getRight())
  64357. {
  64358. GlyphArrangement arr;
  64359. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64360. arr.draw (*this);
  64361. }
  64362. }
  64363. void Graphics::drawTextAsPath (const String& text, const AffineTransform& transform) const
  64364. {
  64365. if (text.isNotEmpty())
  64366. {
  64367. GlyphArrangement arr;
  64368. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64369. arr.draw (*this, transform);
  64370. }
  64371. }
  64372. void Graphics::drawMultiLineText (const String& text, const int startX, const int baselineY, const int maximumLineWidth) const
  64373. {
  64374. if (text.isNotEmpty()
  64375. && startX < context->getClipBounds().getRight())
  64376. {
  64377. GlyphArrangement arr;
  64378. arr.addJustifiedText (context->getFont(), text,
  64379. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64380. Justification::left);
  64381. arr.draw (*this);
  64382. }
  64383. }
  64384. void Graphics::drawText (const String& text,
  64385. const int x, const int y, const int width, const int height,
  64386. const Justification& justificationType,
  64387. const bool useEllipsesIfTooBig) const
  64388. {
  64389. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64390. {
  64391. GlyphArrangement arr;
  64392. arr.addCurtailedLineOfText (context->getFont(), text,
  64393. 0.0f, 0.0f, (float) width,
  64394. useEllipsesIfTooBig);
  64395. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64396. (float) x, (float) y, (float) width, (float) height,
  64397. justificationType);
  64398. arr.draw (*this);
  64399. }
  64400. }
  64401. void Graphics::drawFittedText (const String& text,
  64402. const int x, const int y, const int width, const int height,
  64403. const Justification& justification,
  64404. const int maximumNumberOfLines,
  64405. const float minimumHorizontalScale) const
  64406. {
  64407. if (text.isNotEmpty()
  64408. && width > 0 && height > 0
  64409. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64410. {
  64411. GlyphArrangement arr;
  64412. arr.addFittedText (context->getFont(), text,
  64413. (float) x, (float) y, (float) width, (float) height,
  64414. justification,
  64415. maximumNumberOfLines,
  64416. minimumHorizontalScale);
  64417. arr.draw (*this);
  64418. }
  64419. }
  64420. void Graphics::fillRect (int x, int y, int width, int height) const
  64421. {
  64422. // passing in a silly number can cause maths problems in rendering!
  64423. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64424. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64425. }
  64426. void Graphics::fillRect (const Rectangle<int>& r) const
  64427. {
  64428. context->fillRect (r, false);
  64429. }
  64430. void Graphics::fillRect (const float x, const float y, const float width, const float height) const
  64431. {
  64432. // passing in a silly number can cause maths problems in rendering!
  64433. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64434. Path p;
  64435. p.addRectangle (x, y, width, height);
  64436. fillPath (p);
  64437. }
  64438. void Graphics::setPixel (int x, int y) const
  64439. {
  64440. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64441. }
  64442. void Graphics::fillAll() const
  64443. {
  64444. fillRect (context->getClipBounds());
  64445. }
  64446. void Graphics::fillAll (const Colour& colourToUse) const
  64447. {
  64448. if (! colourToUse.isTransparent())
  64449. {
  64450. const Rectangle<int> clip (context->getClipBounds());
  64451. context->saveState();
  64452. context->setFill (colourToUse);
  64453. context->fillRect (clip, false);
  64454. context->restoreState();
  64455. }
  64456. }
  64457. void Graphics::fillPath (const Path& path, const AffineTransform& transform) const
  64458. {
  64459. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64460. context->fillPath (path, transform);
  64461. }
  64462. void Graphics::strokePath (const Path& path,
  64463. const PathStrokeType& strokeType,
  64464. const AffineTransform& transform) const
  64465. {
  64466. Path stroke;
  64467. strokeType.createStrokedPath (stroke, path, transform);
  64468. fillPath (stroke);
  64469. }
  64470. void Graphics::drawRect (const int x, const int y, const int width, const int height,
  64471. const int lineThickness) const
  64472. {
  64473. // passing in a silly number can cause maths problems in rendering!
  64474. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64475. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64476. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64477. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64478. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64479. }
  64480. void Graphics::drawRect (const float x, const float y, const float width, const float height, const float lineThickness) const
  64481. {
  64482. // passing in a silly number can cause maths problems in rendering!
  64483. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64484. Path p;
  64485. p.addRectangle (x, y, width, lineThickness);
  64486. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64487. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64488. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64489. fillPath (p);
  64490. }
  64491. void Graphics::drawRect (const Rectangle<int>& r, const int lineThickness) const
  64492. {
  64493. drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight(), lineThickness);
  64494. }
  64495. void Graphics::drawBevel (const int x, const int y, const int width, const int height,
  64496. const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
  64497. const bool useGradient, const bool sharpEdgeOnOutside) const
  64498. {
  64499. // passing in a silly number can cause maths problems in rendering!
  64500. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64501. if (clipRegionIntersects (x, y, width, height))
  64502. {
  64503. context->saveState();
  64504. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64505. const float ramp = oldOpacity / bevelThickness;
  64506. for (int i = bevelThickness; --i >= 0;)
  64507. {
  64508. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64509. : oldOpacity;
  64510. context->setFill (topLeftColour.withMultipliedAlpha (op));
  64511. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64512. context->setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
  64513. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64514. context->setFill (bottomRightColour.withMultipliedAlpha (op));
  64515. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64516. context->setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
  64517. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64518. }
  64519. context->restoreState();
  64520. }
  64521. }
  64522. void Graphics::fillEllipse (const float x, const float y, const float width, const float height) const
  64523. {
  64524. // passing in a silly number can cause maths problems in rendering!
  64525. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64526. Path p;
  64527. p.addEllipse (x, y, width, height);
  64528. fillPath (p);
  64529. }
  64530. void Graphics::drawEllipse (const float x, const float y, const float width, const float height,
  64531. const float lineThickness) const
  64532. {
  64533. // passing in a silly number can cause maths problems in rendering!
  64534. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64535. Path p;
  64536. p.addEllipse (x, y, width, height);
  64537. strokePath (p, PathStrokeType (lineThickness));
  64538. }
  64539. void Graphics::fillRoundedRectangle (const float x, const float y, const float width, const float height, const float cornerSize) const
  64540. {
  64541. // passing in a silly number can cause maths problems in rendering!
  64542. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64543. Path p;
  64544. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64545. fillPath (p);
  64546. }
  64547. void Graphics::fillRoundedRectangle (const Rectangle<float>& r, const float cornerSize) const
  64548. {
  64549. fillRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize);
  64550. }
  64551. void Graphics::drawRoundedRectangle (const float x, const float y, const float width, const float height,
  64552. const float cornerSize, const float lineThickness) const
  64553. {
  64554. // passing in a silly number can cause maths problems in rendering!
  64555. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64556. Path p;
  64557. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64558. strokePath (p, PathStrokeType (lineThickness));
  64559. }
  64560. void Graphics::drawRoundedRectangle (const Rectangle<float>& r, const float cornerSize, const float lineThickness) const
  64561. {
  64562. drawRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize, lineThickness);
  64563. }
  64564. void Graphics::drawArrow (const float startX, const float startY, const float endX, const float endY,
  64565. const float lineThickness, const float arrowheadWidth, const float arrowheadLength) const
  64566. {
  64567. Path p;
  64568. p.addArrow (startX, startY, endX, endY,
  64569. lineThickness, arrowheadWidth, arrowheadLength);
  64570. fillPath (p);
  64571. }
  64572. void Graphics::fillCheckerBoard (int x, int y, int width, int height,
  64573. const int checkWidth, const int checkHeight,
  64574. const Colour& colour1, const Colour& colour2) const
  64575. {
  64576. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64577. if (checkWidth > 0 && checkHeight > 0)
  64578. {
  64579. context->saveState();
  64580. if (colour1 == colour2)
  64581. {
  64582. context->setFill (colour1);
  64583. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64584. }
  64585. else
  64586. {
  64587. const Rectangle<int> clip (context->getClipBounds());
  64588. const int right = jmin (x + width, clip.getRight());
  64589. const int bottom = jmin (y + height, clip.getBottom());
  64590. int cy = 0;
  64591. while (y < bottom)
  64592. {
  64593. int cx = cy;
  64594. for (int xx = x; xx < right; xx += checkWidth)
  64595. {
  64596. context->setFill (((cx++ & 1) == 0) ? colour1 : colour2);
  64597. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64598. false);
  64599. }
  64600. ++cy;
  64601. y += checkHeight;
  64602. }
  64603. }
  64604. context->restoreState();
  64605. }
  64606. }
  64607. void Graphics::drawVerticalLine (const int x, float top, float bottom) const
  64608. {
  64609. context->drawVerticalLine (x, top, bottom);
  64610. }
  64611. void Graphics::drawHorizontalLine (const int y, float left, float right) const
  64612. {
  64613. context->drawHorizontalLine (y, left, right);
  64614. }
  64615. void Graphics::drawLine (float x1, float y1, float x2, float y2) const
  64616. {
  64617. context->drawLine (x1, y1, x2, y2);
  64618. }
  64619. void Graphics::drawLine (const float startX, const float startY,
  64620. const float endX, const float endY,
  64621. const float lineThickness) const
  64622. {
  64623. Path p;
  64624. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64625. fillPath (p);
  64626. }
  64627. void Graphics::drawLine (const Line& line) const
  64628. {
  64629. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64630. }
  64631. void Graphics::drawLine (const Line& line, const float lineThickness) const
  64632. {
  64633. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64634. }
  64635. void Graphics::drawDashedLine (const float startX, const float startY,
  64636. const float endX, const float endY,
  64637. const float* const dashLengths,
  64638. const int numDashLengths,
  64639. const float lineThickness) const
  64640. {
  64641. const double dx = endX - startX;
  64642. const double dy = endY - startY;
  64643. const double totalLen = juce_hypot (dx, dy);
  64644. if (totalLen >= 0.5)
  64645. {
  64646. const double onePixAlpha = 1.0 / totalLen;
  64647. double alpha = 0.0;
  64648. float x = startX;
  64649. float y = startY;
  64650. int n = 0;
  64651. while (alpha < 1.0f)
  64652. {
  64653. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64654. n = n % numDashLengths;
  64655. const float oldX = x;
  64656. const float oldY = y;
  64657. x = (float) (startX + dx * alpha);
  64658. y = (float) (startY + dy * alpha);
  64659. if ((n & 1) != 0)
  64660. {
  64661. if (lineThickness != 1.0f)
  64662. drawLine (oldX, oldY, x, y, lineThickness);
  64663. else
  64664. drawLine (oldX, oldY, x, y);
  64665. }
  64666. }
  64667. }
  64668. }
  64669. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality)
  64670. {
  64671. saveStateIfPending();
  64672. context->setInterpolationQuality (newQuality);
  64673. }
  64674. void Graphics::drawImageAt (const Image* const imageToDraw,
  64675. const int topLeftX, const int topLeftY,
  64676. const bool fillAlphaChannelWithCurrentBrush) const
  64677. {
  64678. if (imageToDraw != 0)
  64679. {
  64680. const int imageW = imageToDraw->getWidth();
  64681. const int imageH = imageToDraw->getHeight();
  64682. drawImage (imageToDraw,
  64683. topLeftX, topLeftY, imageW, imageH,
  64684. 0, 0, imageW, imageH,
  64685. fillAlphaChannelWithCurrentBrush);
  64686. }
  64687. }
  64688. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64689. const int destX, const int destY,
  64690. const int destW, const int destH,
  64691. const RectanglePlacement& placementWithinTarget,
  64692. const bool fillAlphaChannelWithCurrentBrush) const
  64693. {
  64694. // passing in a silly number can cause maths problems in rendering!
  64695. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64696. if (imageToDraw != 0)
  64697. {
  64698. const int imageW = imageToDraw->getWidth();
  64699. const int imageH = imageToDraw->getHeight();
  64700. if (imageW > 0 && imageH > 0)
  64701. {
  64702. double newX = 0.0, newY = 0.0;
  64703. double newW = imageW;
  64704. double newH = imageH;
  64705. placementWithinTarget.applyTo (newX, newY, newW, newH,
  64706. destX, destY, destW, destH);
  64707. if (newW > 0 && newH > 0)
  64708. {
  64709. drawImage (imageToDraw,
  64710. roundToInt (newX), roundToInt (newY),
  64711. roundToInt (newW), roundToInt (newH),
  64712. 0, 0, imageW, imageH,
  64713. fillAlphaChannelWithCurrentBrush);
  64714. }
  64715. }
  64716. }
  64717. }
  64718. void Graphics::drawImage (const Image* const imageToDraw,
  64719. int dx, int dy, int dw, int dh,
  64720. int sx, int sy, int sw, int sh,
  64721. const bool fillAlphaChannelWithCurrentBrush) const
  64722. {
  64723. // passing in a silly number can cause maths problems in rendering!
  64724. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  64725. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  64726. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  64727. {
  64728. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  64729. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  64730. .translated ((float) dx, (float) dy),
  64731. fillAlphaChannelWithCurrentBrush);
  64732. }
  64733. }
  64734. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  64735. const Rectangle<int>& imageSubRegion,
  64736. const AffineTransform& transform,
  64737. const bool fillAlphaChannelWithCurrentBrush) const
  64738. {
  64739. if (imageToDraw != 0 && ! context->isClipEmpty())
  64740. {
  64741. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  64742. if (fillAlphaChannelWithCurrentBrush)
  64743. {
  64744. context->saveState();
  64745. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  64746. fillAll();
  64747. context->restoreState();
  64748. }
  64749. else
  64750. {
  64751. context->drawImage (*imageToDraw, srcClip, transform, false);
  64752. }
  64753. }
  64754. }
  64755. END_JUCE_NAMESPACE
  64756. /*** End of inlined file: juce_Graphics.cpp ***/
  64757. /*** Start of inlined file: juce_Justification.cpp ***/
  64758. BEGIN_JUCE_NAMESPACE
  64759. Justification::Justification (const Justification& other) throw()
  64760. : flags (other.flags)
  64761. {
  64762. }
  64763. Justification& Justification::operator= (const Justification& other) throw()
  64764. {
  64765. flags = other.flags;
  64766. return *this;
  64767. }
  64768. int Justification::getOnlyVerticalFlags() const throw()
  64769. {
  64770. return flags & (top | bottom | verticallyCentred);
  64771. }
  64772. int Justification::getOnlyHorizontalFlags() const throw()
  64773. {
  64774. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  64775. }
  64776. void Justification::applyToRectangle (int& x, int& y,
  64777. const int w, const int h,
  64778. const int spaceX, const int spaceY,
  64779. const int spaceW, const int spaceH) const throw()
  64780. {
  64781. if ((flags & horizontallyCentred) != 0)
  64782. {
  64783. x = spaceX + ((spaceW - w) >> 1);
  64784. }
  64785. else if ((flags & right) != 0)
  64786. {
  64787. x = spaceX + spaceW - w;
  64788. }
  64789. else
  64790. {
  64791. x = spaceX;
  64792. }
  64793. if ((flags & verticallyCentred) != 0)
  64794. {
  64795. y = spaceY + ((spaceH - h) >> 1);
  64796. }
  64797. else if ((flags & bottom) != 0)
  64798. {
  64799. y = spaceY + spaceH - h;
  64800. }
  64801. else
  64802. {
  64803. y = spaceY;
  64804. }
  64805. }
  64806. END_JUCE_NAMESPACE
  64807. /*** End of inlined file: juce_Justification.cpp ***/
  64808. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  64809. BEGIN_JUCE_NAMESPACE
  64810. // this will throw an assertion if you try to draw something that's not
  64811. // possible in postscript
  64812. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  64813. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  64814. #define notPossibleInPostscriptAssert jassertfalse
  64815. #else
  64816. #define notPossibleInPostscriptAssert
  64817. #endif
  64818. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  64819. const String& documentTitle,
  64820. const int totalWidth_,
  64821. const int totalHeight_)
  64822. : out (resultingPostScript),
  64823. totalWidth (totalWidth_),
  64824. totalHeight (totalHeight_),
  64825. needToClip (true)
  64826. {
  64827. stateStack.add (new SavedState());
  64828. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  64829. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  64830. out << "%!PS-Adobe-3.0 EPSF-3.0"
  64831. "\n%%BoundingBox: 0 0 600 824"
  64832. "\n%%Pages: 0"
  64833. "\n%%Creator: Raw Material Software JUCE"
  64834. "\n%%Title: " << documentTitle <<
  64835. "\n%%CreationDate: none"
  64836. "\n%%LanguageLevel: 2"
  64837. "\n%%EndComments"
  64838. "\n%%BeginProlog"
  64839. "\n%%BeginResource: JRes"
  64840. "\n/bd {bind def} bind def"
  64841. "\n/c {setrgbcolor} bd"
  64842. "\n/m {moveto} bd"
  64843. "\n/l {lineto} bd"
  64844. "\n/rl {rlineto} bd"
  64845. "\n/ct {curveto} bd"
  64846. "\n/cp {closepath} bd"
  64847. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  64848. "\n/doclip {initclip newpath} bd"
  64849. "\n/endclip {clip newpath} bd"
  64850. "\n%%EndResource"
  64851. "\n%%EndProlog"
  64852. "\n%%BeginSetup"
  64853. "\n%%EndSetup"
  64854. "\n%%Page: 1 1"
  64855. "\n%%BeginPageSetup"
  64856. "\n%%EndPageSetup\n\n"
  64857. << "40 800 translate\n"
  64858. << scale << ' ' << scale << " scale\n\n";
  64859. }
  64860. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  64861. {
  64862. }
  64863. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  64864. {
  64865. return true;
  64866. }
  64867. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  64868. {
  64869. if (x != 0 || y != 0)
  64870. {
  64871. stateStack.getLast()->xOffset += x;
  64872. stateStack.getLast()->yOffset += y;
  64873. needToClip = true;
  64874. }
  64875. }
  64876. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  64877. {
  64878. needToClip = true;
  64879. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  64880. }
  64881. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  64882. {
  64883. needToClip = true;
  64884. return stateStack.getLast()->clip.clipTo (clipRegion);
  64885. }
  64886. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  64887. {
  64888. needToClip = true;
  64889. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  64890. }
  64891. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  64892. {
  64893. writeClip();
  64894. Path p (path);
  64895. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  64896. writePath (p);
  64897. out << "clip\n";
  64898. }
  64899. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  64900. {
  64901. needToClip = true;
  64902. jassertfalse // xxx
  64903. }
  64904. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  64905. {
  64906. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  64907. }
  64908. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  64909. {
  64910. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  64911. -stateStack.getLast()->yOffset);
  64912. }
  64913. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  64914. {
  64915. return stateStack.getLast()->clip.isEmpty();
  64916. }
  64917. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  64918. : xOffset (0),
  64919. yOffset (0)
  64920. {
  64921. }
  64922. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  64923. {
  64924. }
  64925. void LowLevelGraphicsPostScriptRenderer::saveState()
  64926. {
  64927. stateStack.add (new SavedState (*stateStack.getLast()));
  64928. }
  64929. void LowLevelGraphicsPostScriptRenderer::restoreState()
  64930. {
  64931. jassert (stateStack.size() > 0);
  64932. if (stateStack.size() > 0)
  64933. stateStack.removeLast();
  64934. }
  64935. void LowLevelGraphicsPostScriptRenderer::writeClip()
  64936. {
  64937. if (needToClip)
  64938. {
  64939. needToClip = false;
  64940. out << "doclip ";
  64941. int itemsOnLine = 0;
  64942. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  64943. {
  64944. if (++itemsOnLine == 6)
  64945. {
  64946. itemsOnLine = 0;
  64947. out << '\n';
  64948. }
  64949. const Rectangle<int>& r = *i.getRectangle();
  64950. out << r.getX() << ' ' << -r.getY() << ' '
  64951. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  64952. }
  64953. out << "endclip\n";
  64954. }
  64955. }
  64956. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  64957. {
  64958. Colour c (Colours::white.overlaidWith (colour));
  64959. if (lastColour != c)
  64960. {
  64961. lastColour = c;
  64962. out << String (c.getFloatRed(), 3) << ' '
  64963. << String (c.getFloatGreen(), 3) << ' '
  64964. << String (c.getFloatBlue(), 3) << " c\n";
  64965. }
  64966. }
  64967. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  64968. {
  64969. out << String (x, 2) << ' '
  64970. << String (-y, 2) << ' ';
  64971. }
  64972. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  64973. {
  64974. out << "newpath ";
  64975. float lastX = 0.0f;
  64976. float lastY = 0.0f;
  64977. int itemsOnLine = 0;
  64978. Path::Iterator i (path);
  64979. while (i.next())
  64980. {
  64981. if (++itemsOnLine == 4)
  64982. {
  64983. itemsOnLine = 0;
  64984. out << '\n';
  64985. }
  64986. switch (i.elementType)
  64987. {
  64988. case Path::Iterator::startNewSubPath:
  64989. writeXY (i.x1, i.y1);
  64990. lastX = i.x1;
  64991. lastY = i.y1;
  64992. out << "m ";
  64993. break;
  64994. case Path::Iterator::lineTo:
  64995. writeXY (i.x1, i.y1);
  64996. lastX = i.x1;
  64997. lastY = i.y1;
  64998. out << "l ";
  64999. break;
  65000. case Path::Iterator::quadraticTo:
  65001. {
  65002. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65003. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65004. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65005. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65006. writeXY (cp1x, cp1y);
  65007. writeXY (cp2x, cp2y);
  65008. writeXY (i.x2, i.y2);
  65009. out << "ct ";
  65010. lastX = i.x2;
  65011. lastY = i.y2;
  65012. }
  65013. break;
  65014. case Path::Iterator::cubicTo:
  65015. writeXY (i.x1, i.y1);
  65016. writeXY (i.x2, i.y2);
  65017. writeXY (i.x3, i.y3);
  65018. out << "ct ";
  65019. lastX = i.x3;
  65020. lastY = i.y3;
  65021. break;
  65022. case Path::Iterator::closePath:
  65023. out << "cp ";
  65024. break;
  65025. default:
  65026. jassertfalse
  65027. break;
  65028. }
  65029. }
  65030. out << '\n';
  65031. }
  65032. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65033. {
  65034. out << "[ "
  65035. << trans.mat00 << ' '
  65036. << trans.mat10 << ' '
  65037. << trans.mat01 << ' '
  65038. << trans.mat11 << ' '
  65039. << trans.mat02 << ' '
  65040. << trans.mat12 << " ] concat ";
  65041. }
  65042. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65043. {
  65044. stateStack.getLast()->fillType = fillType;
  65045. }
  65046. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65047. {
  65048. }
  65049. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65050. {
  65051. }
  65052. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65053. {
  65054. if (stateStack.getLast()->fillType.isColour())
  65055. {
  65056. writeClip();
  65057. writeColour (stateStack.getLast()->fillType.colour);
  65058. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65059. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65060. }
  65061. else
  65062. {
  65063. Path p;
  65064. p.addRectangle (r);
  65065. fillPath (p, AffineTransform::identity);
  65066. }
  65067. }
  65068. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65069. {
  65070. if (stateStack.getLast()->fillType.isColour())
  65071. {
  65072. writeClip();
  65073. Path p (path);
  65074. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65075. (float) stateStack.getLast()->yOffset));
  65076. writePath (p);
  65077. writeColour (stateStack.getLast()->fillType.colour);
  65078. out << "fill\n";
  65079. }
  65080. else if (stateStack.getLast()->fillType.isGradient())
  65081. {
  65082. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65083. // postscript can't do semi-transparent ones.
  65084. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65085. writeClip();
  65086. out << "gsave ";
  65087. {
  65088. Path p (path);
  65089. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65090. writePath (p);
  65091. out << "clip\n";
  65092. }
  65093. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65094. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65095. // time-being, this just fills it with the average colour..
  65096. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65097. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65098. out << "grestore\n";
  65099. }
  65100. }
  65101. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65102. const int sx, const int sy,
  65103. const int maxW, const int maxH) const
  65104. {
  65105. out << "{<\n";
  65106. const int w = jmin (maxW, im.getWidth());
  65107. const int h = jmin (maxH, im.getHeight());
  65108. int charsOnLine = 0;
  65109. const Image::BitmapData srcData (im, 0, 0, w, h);
  65110. Colour pixel;
  65111. for (int y = h; --y >= 0;)
  65112. {
  65113. for (int x = 0; x < w; ++x)
  65114. {
  65115. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65116. if (x >= sx && y >= sy)
  65117. {
  65118. if (im.isARGB())
  65119. {
  65120. PixelARGB p (*(const PixelARGB*) pixelData);
  65121. p.unpremultiply();
  65122. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65123. }
  65124. else if (im.isRGB())
  65125. {
  65126. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65127. }
  65128. else
  65129. {
  65130. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65131. }
  65132. }
  65133. else
  65134. {
  65135. pixel = Colours::transparentWhite;
  65136. }
  65137. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65138. out << String::toHexString (pixelValues, 3, 0);
  65139. charsOnLine += 3;
  65140. if (charsOnLine > 100)
  65141. {
  65142. out << '\n';
  65143. charsOnLine = 0;
  65144. }
  65145. }
  65146. }
  65147. out << "\n>}\n";
  65148. }
  65149. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65150. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65151. {
  65152. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65153. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65154. writeClip();
  65155. out << "gsave ";
  65156. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65157. .scaled (1.0f, -1.0f));
  65158. RectangleList imageClip;
  65159. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65160. imageClip.clipTo (srcClip);
  65161. out << "newpath ";
  65162. int itemsOnLine = 0;
  65163. for (RectangleList::Iterator i (imageClip); i.next();)
  65164. {
  65165. if (++itemsOnLine == 6)
  65166. {
  65167. out << '\n';
  65168. itemsOnLine = 0;
  65169. }
  65170. const Rectangle<int>& r = *i.getRectangle();
  65171. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65172. }
  65173. out << " clip newpath\n";
  65174. out << w << ' ' << h << " scale\n";
  65175. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65176. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65177. out << "false 3 colorimage grestore\n";
  65178. needToClip = true;
  65179. }
  65180. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65181. {
  65182. Path p;
  65183. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65184. fillPath (p, AffineTransform::identity);
  65185. }
  65186. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65187. {
  65188. drawLine (x, top, x, bottom);
  65189. }
  65190. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65191. {
  65192. drawLine (left, y, right, y);
  65193. }
  65194. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65195. {
  65196. stateStack.getLast()->font = newFont;
  65197. }
  65198. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65199. {
  65200. return stateStack.getLast()->font;
  65201. }
  65202. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65203. {
  65204. Path p;
  65205. Font& font = stateStack.getLast()->font;
  65206. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65207. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65208. }
  65209. END_JUCE_NAMESPACE
  65210. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65211. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65212. BEGIN_JUCE_NAMESPACE
  65213. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65214. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65215. #endif
  65216. #if JUCE_MSVC
  65217. #if JUCE_DEBUG
  65218. #pragma optimize ("t", on) // optimise just this file, to avoid sluggish graphics when debugging
  65219. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65220. #endif
  65221. #pragma warning (push)
  65222. #pragma warning (disable: 4127) // "expression is constant" warning
  65223. #endif
  65224. template <class PixelType, bool replaceExisting = false>
  65225. class SolidColourEdgeTableRenderer
  65226. {
  65227. public:
  65228. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65229. : data (data_),
  65230. sourceColour (colour)
  65231. {
  65232. if (sizeof (PixelType) == 3)
  65233. {
  65234. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65235. && sourceColour.getGreen() == sourceColour.getBlue();
  65236. filler[0].set (sourceColour);
  65237. filler[1].set (sourceColour);
  65238. filler[2].set (sourceColour);
  65239. filler[3].set (sourceColour);
  65240. }
  65241. }
  65242. forcedinline void setEdgeTableYPos (const int y) throw()
  65243. {
  65244. linePixels = (PixelType*) data.getLinePointer (y);
  65245. }
  65246. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65247. {
  65248. if (replaceExisting)
  65249. linePixels[x].set (sourceColour);
  65250. else
  65251. linePixels[x].blend (sourceColour, alphaLevel);
  65252. }
  65253. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65254. {
  65255. PixelARGB p (sourceColour);
  65256. p.multiplyAlpha (alphaLevel);
  65257. PixelType* dest = linePixels + x;
  65258. if (replaceExisting || p.getAlpha() >= 0xff)
  65259. replaceLine (dest, p, width);
  65260. else
  65261. blendLine (dest, p, width);
  65262. }
  65263. private:
  65264. const Image::BitmapData& data;
  65265. PixelType* linePixels;
  65266. PixelARGB sourceColour;
  65267. PixelRGB filler [4];
  65268. bool areRGBComponentsEqual;
  65269. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65270. {
  65271. do
  65272. {
  65273. dest->blend (colour);
  65274. ++dest;
  65275. } while (--width > 0);
  65276. }
  65277. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65278. {
  65279. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65280. {
  65281. memset (dest, colour.getRed(), width * 3);
  65282. }
  65283. else
  65284. {
  65285. if (width >> 5)
  65286. {
  65287. const int* const intFiller = (const int*) filler;
  65288. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65289. {
  65290. dest->set (colour);
  65291. ++dest;
  65292. --width;
  65293. }
  65294. while (width > 4)
  65295. {
  65296. ((int*) dest) [0] = intFiller[0];
  65297. ((int*) dest) [1] = intFiller[1];
  65298. ((int*) dest) [2] = intFiller[2];
  65299. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65300. width -= 4;
  65301. }
  65302. }
  65303. while (--width >= 0)
  65304. {
  65305. dest->set (colour);
  65306. ++dest;
  65307. }
  65308. }
  65309. }
  65310. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65311. {
  65312. memset (dest, colour.getAlpha(), width);
  65313. }
  65314. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65315. {
  65316. do
  65317. {
  65318. dest->set (colour);
  65319. ++dest;
  65320. } while (--width > 0);
  65321. }
  65322. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65323. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65324. };
  65325. class LinearGradientPixelGenerator
  65326. {
  65327. public:
  65328. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65329. : lookupTable (lookupTable_), numEntries (numEntries_)
  65330. {
  65331. jassert (numEntries_ >= 0);
  65332. float x1 = gradient.x1;
  65333. float y1 = gradient.y1;
  65334. float x2 = gradient.x2;
  65335. float y2 = gradient.y2;
  65336. if (! transform.isIdentity())
  65337. {
  65338. const Line l (x2, y2, x1, y1);
  65339. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65340. float x3 = p3.getX();
  65341. float y3 = p3.getY();
  65342. transform.transformPoint (x1, y1);
  65343. transform.transformPoint (x2, y2);
  65344. transform.transformPoint (x3, y3);
  65345. const Line l2 (x2, y2, x3, y3);
  65346. const float prop = l2.findNearestPointTo (x1, y1);
  65347. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65348. x2 = newP2.getX();
  65349. y2 = newP2.getY();
  65350. }
  65351. vertical = fabs (x1 - x2) < 0.001f;
  65352. horizontal = fabs (y1 - y2) < 0.001f;
  65353. if (vertical)
  65354. {
  65355. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65356. start = roundToInt (y1 * scale);
  65357. }
  65358. else if (horizontal)
  65359. {
  65360. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65361. start = roundToInt (x1 * scale);
  65362. }
  65363. else
  65364. {
  65365. grad = (y2 - y1) / (double) (x1 - x2);
  65366. yTerm = y1 - x1 / grad;
  65367. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65368. grad *= scale;
  65369. }
  65370. }
  65371. forcedinline void setY (const int y) throw()
  65372. {
  65373. if (vertical)
  65374. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65375. else if (! horizontal)
  65376. start = roundToInt ((y - yTerm) * grad);
  65377. }
  65378. inline const PixelARGB getPixel (const int x) const throw()
  65379. {
  65380. return vertical ? linePix
  65381. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65382. }
  65383. private:
  65384. const PixelARGB* const lookupTable;
  65385. const int numEntries;
  65386. PixelARGB linePix;
  65387. int start, scale;
  65388. double grad, yTerm;
  65389. bool vertical, horizontal;
  65390. enum { numScaleBits = 12 };
  65391. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65392. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65393. };
  65394. class RadialGradientPixelGenerator
  65395. {
  65396. public:
  65397. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65398. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65399. : lookupTable (lookupTable_),
  65400. numEntries (numEntries_),
  65401. gx1 (gradient.x1),
  65402. gy1 (gradient.y1)
  65403. {
  65404. jassert (numEntries_ >= 0);
  65405. const float gdx = gradient.x1 - gradient.x2;
  65406. const float gdy = gradient.y1 - gradient.y2;
  65407. maxDist = gdx * gdx + gdy * gdy;
  65408. invScale = numEntries / sqrt (maxDist);
  65409. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65410. }
  65411. forcedinline void setY (const int y) throw()
  65412. {
  65413. dy = y - gy1;
  65414. dy *= dy;
  65415. }
  65416. inline const PixelARGB getPixel (const int px) const throw()
  65417. {
  65418. double x = px - gx1;
  65419. x *= x;
  65420. x += dy;
  65421. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65422. }
  65423. protected:
  65424. const PixelARGB* const lookupTable;
  65425. const int numEntries;
  65426. const double gx1, gy1;
  65427. double maxDist, invScale, dy;
  65428. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65429. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65430. };
  65431. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65432. {
  65433. public:
  65434. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65435. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65436. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65437. inverseTransform (transform.inverted())
  65438. {
  65439. tM10 = inverseTransform.mat10;
  65440. tM00 = inverseTransform.mat00;
  65441. }
  65442. forcedinline void setY (const int y) throw()
  65443. {
  65444. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65445. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65446. }
  65447. inline const PixelARGB getPixel (const int px) const throw()
  65448. {
  65449. double x = px;
  65450. const double y = tM10 * x + lineYM11;
  65451. x = tM00 * x + lineYM01;
  65452. x *= x;
  65453. x += y * y;
  65454. if (x >= maxDist)
  65455. return lookupTable [numEntries];
  65456. else
  65457. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65458. }
  65459. private:
  65460. double tM10, tM00, lineYM01, lineYM11;
  65461. const AffineTransform inverseTransform;
  65462. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65463. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65464. };
  65465. template <class PixelType, class GradientType>
  65466. class GradientEdgeTableRenderer : public GradientType
  65467. {
  65468. public:
  65469. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65470. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65471. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65472. destData (destData_)
  65473. {
  65474. }
  65475. forcedinline void setEdgeTableYPos (const int y) throw()
  65476. {
  65477. linePixels = (PixelType*) destData.getLinePointer (y);
  65478. GradientType::setY (y);
  65479. }
  65480. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65481. {
  65482. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65483. }
  65484. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65485. {
  65486. PixelType* dest = linePixels + x;
  65487. if (alphaLevel < 0xff)
  65488. {
  65489. do
  65490. {
  65491. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65492. } while (--width > 0);
  65493. }
  65494. else
  65495. {
  65496. do
  65497. {
  65498. (dest++)->blend (GradientType::getPixel (x++));
  65499. } while (--width > 0);
  65500. }
  65501. }
  65502. private:
  65503. const Image::BitmapData& destData;
  65504. PixelType* linePixels;
  65505. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65506. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65507. };
  65508. static forcedinline int safeModulo (int n, const int divisor) throw()
  65509. {
  65510. jassert (divisor > 0);
  65511. n %= divisor;
  65512. return (n < 0) ? (n + divisor) : n;
  65513. }
  65514. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65515. class ImageFillEdgeTableRenderer
  65516. {
  65517. public:
  65518. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65519. const Image::BitmapData& srcData_,
  65520. const int extraAlpha_,
  65521. const int x, const int y) throw()
  65522. : destData (destData_),
  65523. srcData (srcData_),
  65524. extraAlpha (extraAlpha_ + 1),
  65525. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65526. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65527. {
  65528. }
  65529. forcedinline void setEdgeTableYPos (int y) throw()
  65530. {
  65531. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65532. y -= yOffset;
  65533. if (repeatPattern)
  65534. {
  65535. jassert (y >= 0);
  65536. y %= srcData.height;
  65537. }
  65538. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65539. }
  65540. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65541. {
  65542. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65543. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65544. }
  65545. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65546. {
  65547. DestPixelType* dest = linePixels + x;
  65548. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65549. x -= xOffset;
  65550. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65551. if (alphaLevel < 0xfe)
  65552. {
  65553. do
  65554. {
  65555. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65556. } while (--width > 0);
  65557. }
  65558. else
  65559. {
  65560. if (repeatPattern)
  65561. {
  65562. do
  65563. {
  65564. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65565. } while (--width > 0);
  65566. }
  65567. else
  65568. {
  65569. copyRow (dest, sourceLineStart + x, width);
  65570. }
  65571. }
  65572. }
  65573. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65574. {
  65575. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65576. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65577. uint8* mask = (uint8*) (s + x - xOffset);
  65578. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65579. mask += PixelARGB::indexA;
  65580. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65581. }
  65582. private:
  65583. const Image::BitmapData& destData;
  65584. const Image::BitmapData& srcData;
  65585. const int extraAlpha, xOffset, yOffset;
  65586. DestPixelType* linePixels;
  65587. SrcPixelType* sourceLineStart;
  65588. template <class PixelType1, class PixelType2>
  65589. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65590. {
  65591. do
  65592. {
  65593. dest++ ->blend (*src++);
  65594. } while (--width > 0);
  65595. }
  65596. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65597. {
  65598. memcpy (dest, src, width * sizeof (PixelRGB));
  65599. }
  65600. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65601. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65602. };
  65603. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65604. class TransformedImageFillEdgeTableRenderer
  65605. {
  65606. public:
  65607. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65608. const Image::BitmapData& srcData_,
  65609. const AffineTransform& transform,
  65610. const int extraAlpha_,
  65611. const bool betterQuality_) throw()
  65612. : interpolator (transform),
  65613. destData (destData_),
  65614. srcData (srcData_),
  65615. extraAlpha (extraAlpha_ + 1),
  65616. betterQuality (betterQuality_),
  65617. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65618. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65619. maxX (srcData_.width - 1),
  65620. maxY (srcData_.height - 1),
  65621. scratchSize (2048)
  65622. {
  65623. scratchBuffer.malloc (scratchSize);
  65624. }
  65625. ~TransformedImageFillEdgeTableRenderer() throw()
  65626. {
  65627. }
  65628. forcedinline void setEdgeTableYPos (const int newY) throw()
  65629. {
  65630. y = newY;
  65631. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65632. }
  65633. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65634. {
  65635. alphaLevel *= extraAlpha;
  65636. alphaLevel >>= 8;
  65637. SrcPixelType p;
  65638. generate (&p, x, 1);
  65639. linePixels[x].blend (p, alphaLevel);
  65640. }
  65641. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65642. {
  65643. if (width > scratchSize)
  65644. {
  65645. scratchSize = width;
  65646. scratchBuffer.malloc (scratchSize);
  65647. }
  65648. SrcPixelType* span = scratchBuffer;
  65649. generate (span, x, width);
  65650. DestPixelType* dest = linePixels + x;
  65651. alphaLevel *= extraAlpha;
  65652. alphaLevel >>= 8;
  65653. if (alphaLevel < 0xfe)
  65654. {
  65655. do
  65656. {
  65657. dest++ ->blend (*span++, alphaLevel);
  65658. } while (--width > 0);
  65659. }
  65660. else
  65661. {
  65662. do
  65663. {
  65664. dest++ ->blend (*span++);
  65665. } while (--width > 0);
  65666. }
  65667. }
  65668. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65669. {
  65670. if (width > scratchSize)
  65671. {
  65672. scratchSize = width;
  65673. scratchBuffer.malloc (scratchSize);
  65674. }
  65675. y = y_;
  65676. generate (scratchBuffer, x, width);
  65677. et.clipLineToMask (x, y_,
  65678. reinterpret_cast<uint8*> (scratchBuffer.getData()) + SrcPixelType::indexA,
  65679. sizeof (SrcPixelType), width);
  65680. }
  65681. private:
  65682. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65683. {
  65684. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65685. do
  65686. {
  65687. int hiResX, hiResY;
  65688. this->interpolator.next (hiResX, hiResY);
  65689. hiResX += pixelOffsetInt;
  65690. hiResY += pixelOffsetInt;
  65691. int loResX = hiResX >> 8;
  65692. int loResY = hiResY >> 8;
  65693. if (repeatPattern)
  65694. {
  65695. loResX = safeModulo (loResX, srcData.width);
  65696. loResY = safeModulo (loResY, srcData.height);
  65697. }
  65698. if (betterQuality
  65699. && ((unsigned int) loResX) < (unsigned int) maxX
  65700. && ((unsigned int) loResY) < (unsigned int) maxY)
  65701. {
  65702. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65703. hiResX &= 255;
  65704. hiResY &= 255;
  65705. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65706. uint32 weight = (256 - hiResX) * (256 - hiResY);
  65707. c[0] += weight * src[0];
  65708. c[1] += weight * src[1];
  65709. c[2] += weight * src[2];
  65710. c[3] += weight * src[3];
  65711. weight = hiResX * (256 - hiResY);
  65712. c[0] += weight * src[4];
  65713. c[1] += weight * src[5];
  65714. c[2] += weight * src[6];
  65715. c[3] += weight * src[7];
  65716. src += this->srcData.lineStride;
  65717. weight = (256 - hiResX) * hiResY;
  65718. c[0] += weight * src[0];
  65719. c[1] += weight * src[1];
  65720. c[2] += weight * src[2];
  65721. c[3] += weight * src[3];
  65722. weight = hiResX * hiResY;
  65723. c[0] += weight * src[4];
  65724. c[1] += weight * src[5];
  65725. c[2] += weight * src[6];
  65726. c[3] += weight * src[7];
  65727. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  65728. (uint8) (c[PixelARGB::indexR] >> 16),
  65729. (uint8) (c[PixelARGB::indexG] >> 16),
  65730. (uint8) (c[PixelARGB::indexB] >> 16));
  65731. }
  65732. else
  65733. {
  65734. if (! repeatPattern)
  65735. {
  65736. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65737. if (loResX < 0) loResX = 0;
  65738. if (loResY < 0) loResY = 0;
  65739. if (loResX > maxX) loResX = maxX;
  65740. if (loResY > maxY) loResY = maxY;
  65741. }
  65742. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  65743. }
  65744. ++dest;
  65745. } while (--numPixels > 0);
  65746. }
  65747. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  65748. {
  65749. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65750. do
  65751. {
  65752. int hiResX, hiResY;
  65753. this->interpolator.next (hiResX, hiResY);
  65754. hiResX += pixelOffsetInt;
  65755. hiResY += pixelOffsetInt;
  65756. int loResX = hiResX >> 8;
  65757. int loResY = hiResY >> 8;
  65758. if (repeatPattern)
  65759. {
  65760. loResX = safeModulo (loResX, srcData.width);
  65761. loResY = safeModulo (loResY, srcData.height);
  65762. }
  65763. if (betterQuality
  65764. && ((unsigned int) loResX) < (unsigned int) maxX
  65765. && ((unsigned int) loResY) < (unsigned int) maxY)
  65766. {
  65767. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  65768. hiResX &= 255;
  65769. hiResY &= 255;
  65770. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65771. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  65772. c[0] += weight * src[0];
  65773. c[1] += weight * src[1];
  65774. c[2] += weight * src[2];
  65775. weight = hiResX * (256 - hiResY);
  65776. c[0] += weight * src[3];
  65777. c[1] += weight * src[4];
  65778. c[2] += weight * src[5];
  65779. src += this->srcData.lineStride;
  65780. weight = (256 - hiResX) * hiResY;
  65781. c[0] += weight * src[0];
  65782. c[1] += weight * src[1];
  65783. c[2] += weight * src[2];
  65784. weight = hiResX * hiResY;
  65785. c[0] += weight * src[3];
  65786. c[1] += weight * src[4];
  65787. c[2] += weight * src[5];
  65788. dest->setARGB ((uint8) 255,
  65789. (uint8) (c[PixelRGB::indexR] >> 16),
  65790. (uint8) (c[PixelRGB::indexG] >> 16),
  65791. (uint8) (c[PixelRGB::indexB] >> 16));
  65792. }
  65793. else
  65794. {
  65795. if (! repeatPattern)
  65796. {
  65797. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65798. if (loResX < 0) loResX = 0;
  65799. if (loResY < 0) loResY = 0;
  65800. if (loResX > maxX) loResX = maxX;
  65801. if (loResY > maxY) loResY = maxY;
  65802. }
  65803. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  65804. }
  65805. ++dest;
  65806. } while (--numPixels > 0);
  65807. }
  65808. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  65809. {
  65810. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65811. do
  65812. {
  65813. int hiResX, hiResY;
  65814. this->interpolator.next (hiResX, hiResY);
  65815. hiResX += pixelOffsetInt;
  65816. hiResY += pixelOffsetInt;
  65817. int loResX = hiResX >> 8;
  65818. int loResY = hiResY >> 8;
  65819. if (repeatPattern)
  65820. {
  65821. loResX = safeModulo (loResX, srcData.width);
  65822. loResY = safeModulo (loResY, srcData.height);
  65823. }
  65824. if (betterQuality
  65825. && ((unsigned int) loResX) < (unsigned int) maxX
  65826. && ((unsigned int) loResY) < (unsigned int) maxY)
  65827. {
  65828. hiResX &= 255;
  65829. hiResY &= 255;
  65830. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65831. uint32 c = 256 * 128;
  65832. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  65833. c += src[1] * (hiResX * (256 - hiResY));
  65834. src += this->srcData.lineStride;
  65835. c += src[0] * ((256 - hiResX) * hiResY);
  65836. c += src[1] * (hiResX * hiResY);
  65837. *((uint8*) dest) = (uint8) c;
  65838. }
  65839. else
  65840. {
  65841. if (! repeatPattern)
  65842. {
  65843. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65844. if (loResX < 0) loResX = 0;
  65845. if (loResY < 0) loResY = 0;
  65846. if (loResX > maxX) loResX = maxX;
  65847. if (loResY > maxY) loResY = maxY;
  65848. }
  65849. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  65850. }
  65851. ++dest;
  65852. } while (--numPixels > 0);
  65853. }
  65854. class TransformedImageSpanInterpolator
  65855. {
  65856. public:
  65857. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  65858. : inverseTransform (transform.inverted())
  65859. {}
  65860. void setStartOfLine (float x, float y, const int numPixels) throw()
  65861. {
  65862. float x1 = x, y1 = y;
  65863. inverseTransform.transformPoint (x1, y1);
  65864. x += numPixels;
  65865. inverseTransform.transformPoint (x, y);
  65866. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  65867. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  65868. }
  65869. void next (int& x, int& y) throw()
  65870. {
  65871. x = xBresenham.n;
  65872. xBresenham.stepToNext();
  65873. y = yBresenham.n;
  65874. yBresenham.stepToNext();
  65875. }
  65876. private:
  65877. class BresenhamInterpolator
  65878. {
  65879. public:
  65880. BresenhamInterpolator() throw() {}
  65881. void set (const int n1, const int n2, const int numSteps_) throw()
  65882. {
  65883. numSteps = jmax (1, numSteps_);
  65884. step = (n2 - n1) / numSteps;
  65885. remainder = modulo = (n2 - n1) % numSteps;
  65886. n = n1;
  65887. if (modulo <= 0)
  65888. {
  65889. modulo += numSteps;
  65890. remainder += numSteps;
  65891. --step;
  65892. }
  65893. modulo -= numSteps;
  65894. }
  65895. forcedinline void stepToNext() throw()
  65896. {
  65897. modulo += remainder;
  65898. n += step;
  65899. if (modulo > 0)
  65900. {
  65901. modulo -= numSteps;
  65902. ++n;
  65903. }
  65904. }
  65905. int n;
  65906. private:
  65907. int numSteps, step, modulo, remainder;
  65908. };
  65909. const AffineTransform inverseTransform;
  65910. BresenhamInterpolator xBresenham, yBresenham;
  65911. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  65912. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  65913. };
  65914. TransformedImageSpanInterpolator interpolator;
  65915. const Image::BitmapData& destData;
  65916. const Image::BitmapData& srcData;
  65917. const int extraAlpha;
  65918. const bool betterQuality;
  65919. const float pixelOffset;
  65920. const int pixelOffsetInt, maxX, maxY;
  65921. int y;
  65922. DestPixelType* linePixels;
  65923. HeapBlock <SrcPixelType> scratchBuffer;
  65924. int scratchSize;
  65925. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  65926. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  65927. };
  65928. class LLGCSavedState
  65929. {
  65930. public:
  65931. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  65932. const Font& font_, const FillType& fillType_,
  65933. const Graphics::ResamplingQuality interpolationQuality_) throw()
  65934. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  65935. xOffset (xOffset_), yOffset (yOffset_),
  65936. font (font_), fillType (fillType_),
  65937. interpolationQuality (interpolationQuality_)
  65938. {
  65939. }
  65940. LLGCSavedState (const LLGCSavedState& other) throw()
  65941. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  65942. yOffset (other.yOffset), font (other.font),
  65943. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  65944. {
  65945. }
  65946. ~LLGCSavedState() throw()
  65947. {
  65948. }
  65949. bool clipToRectangle (const Rectangle<int>& r) throw()
  65950. {
  65951. dupeEdgeTableIfMultiplyReferenced();
  65952. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  65953. return ! edgeTable->edgeTable.isEmpty();
  65954. }
  65955. bool clipToRectangleList (const RectangleList& r) throw()
  65956. {
  65957. dupeEdgeTableIfMultiplyReferenced();
  65958. RectangleList offsetList (r);
  65959. offsetList.offsetAll (xOffset, yOffset);
  65960. EdgeTable e2 (offsetList);
  65961. edgeTable->edgeTable.clipToEdgeTable (e2);
  65962. return ! edgeTable->edgeTable.isEmpty();
  65963. }
  65964. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  65965. {
  65966. dupeEdgeTableIfMultiplyReferenced();
  65967. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  65968. return ! edgeTable->edgeTable.isEmpty();
  65969. }
  65970. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  65971. {
  65972. dupeEdgeTableIfMultiplyReferenced();
  65973. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  65974. edgeTable->edgeTable.clipToEdgeTable (et);
  65975. }
  65976. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  65977. {
  65978. et.clipToEdgeTable (edgeTable->edgeTable);
  65979. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  65980. if (fillType.isGradient())
  65981. {
  65982. jassert (! replaceContents); // that option is just for solid colours
  65983. ColourGradient g2 (*(fillType.gradient));
  65984. g2.multiplyOpacity (fillType.getOpacity());
  65985. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  65986. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  65987. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  65988. const bool isIdentity = transform.isOnlyTranslation();
  65989. if (isIdentity)
  65990. {
  65991. // If our translation doesn't involve any distortion, we can speed it up..
  65992. transform.transformPoint (g2.x1, g2.y1);
  65993. transform.transformPoint (g2.x2, g2.y2);
  65994. transform = AffineTransform::identity;
  65995. }
  65996. HeapBlock <PixelARGB> lookupTable;
  65997. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  65998. jassert (numLookupEntries > 0);
  65999. switch (image.getFormat())
  66000. {
  66001. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66002. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66003. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66004. }
  66005. }
  66006. else if (fillType.isTiledImage())
  66007. {
  66008. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66009. }
  66010. else
  66011. {
  66012. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66013. switch (image.getFormat())
  66014. {
  66015. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66016. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66017. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66018. }
  66019. }
  66020. }
  66021. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66022. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66023. {
  66024. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66025. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66026. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66027. const int alpha = fillType.colour.getAlpha();
  66028. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66029. if (transform.isOnlyTranslation())
  66030. {
  66031. // If our translation doesn't involve any distortion, just use a simple blit..
  66032. int tx = (int) (transform.getTranslationX() * 256.0f);
  66033. int ty = (int) (transform.getTranslationY() * 256.0f);
  66034. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66035. {
  66036. tx = ((tx + 128) >> 8);
  66037. ty = ((ty + 128) >> 8);
  66038. if (tiledFillClipRegion != 0)
  66039. {
  66040. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66041. }
  66042. else
  66043. {
  66044. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66045. et.clipToEdgeTable (edgeTable->edgeTable);
  66046. if (! et.isEmpty())
  66047. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66048. }
  66049. return;
  66050. }
  66051. }
  66052. if (transform.isSingularity())
  66053. return;
  66054. if (tiledFillClipRegion != 0)
  66055. {
  66056. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66057. }
  66058. else
  66059. {
  66060. Path p;
  66061. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66062. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66063. et.clipToEdgeTable (edgeTable->edgeTable);
  66064. if (! et.isEmpty())
  66065. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66066. }
  66067. }
  66068. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66069. {
  66070. if (! image.hasAlphaChannel())
  66071. {
  66072. Path p;
  66073. p.addRectangle (srcClip);
  66074. clipToPath (p, t);
  66075. return;
  66076. }
  66077. dupeEdgeTableIfMultiplyReferenced();
  66078. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66079. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66080. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66081. EdgeTable& et = edgeTable->edgeTable;
  66082. if (transform.isOnlyTranslation())
  66083. {
  66084. // If our translation doesn't involve any distortion, just use a simple blit..
  66085. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66086. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66087. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66088. {
  66089. const int imageX = ((tx + 128) >> 8);
  66090. const int imageY = ((ty + 128) >> 8);
  66091. if (image.getFormat() == Image::ARGB)
  66092. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66093. else
  66094. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66095. return;
  66096. }
  66097. }
  66098. if (transform.isSingularity())
  66099. {
  66100. et.clipToRectangle (Rectangle<int>());
  66101. return;
  66102. }
  66103. {
  66104. Path p;
  66105. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66106. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66107. et.clipToEdgeTable (et2);
  66108. }
  66109. if (! et.isEmpty())
  66110. {
  66111. if (image.getFormat() == Image::ARGB)
  66112. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66113. else
  66114. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66115. }
  66116. }
  66117. template <class SrcPixelType>
  66118. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66119. {
  66120. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66121. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66122. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66123. et.getMaximumBounds().getWidth());
  66124. }
  66125. template <class SrcPixelType>
  66126. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66127. {
  66128. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66129. et.clipToRectangle (r);
  66130. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66131. for (int y = 0; y < r.getHeight(); ++y)
  66132. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66133. }
  66134. class EdgeTableHolder : public ReferenceCountedObject
  66135. {
  66136. public:
  66137. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66138. EdgeTable edgeTable;
  66139. };
  66140. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66141. int xOffset, yOffset;
  66142. Font font;
  66143. FillType fillType;
  66144. Graphics::ResamplingQuality interpolationQuality;
  66145. private:
  66146. LLGCSavedState& operator= (const LLGCSavedState&);
  66147. void dupeEdgeTableIfMultiplyReferenced() throw()
  66148. {
  66149. if (edgeTable->getReferenceCount() > 1)
  66150. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66151. }
  66152. template <class DestPixelType>
  66153. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66154. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66155. {
  66156. jassert (destData.pixelStride == sizeof (DestPixelType));
  66157. if (g.isRadial)
  66158. {
  66159. if (isIdentity)
  66160. {
  66161. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66162. et.iterate (renderer);
  66163. }
  66164. else
  66165. {
  66166. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66167. et.iterate (renderer);
  66168. }
  66169. }
  66170. else
  66171. {
  66172. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66173. et.iterate (renderer);
  66174. }
  66175. }
  66176. template <class DestPixelType>
  66177. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66178. {
  66179. jassert (destData.pixelStride == sizeof (DestPixelType));
  66180. if (replaceContents)
  66181. {
  66182. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66183. et.iterate (r);
  66184. }
  66185. else
  66186. {
  66187. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66188. et.iterate (r);
  66189. }
  66190. }
  66191. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66192. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66193. {
  66194. switch (destImage.getFormat())
  66195. {
  66196. case Image::ARGB:
  66197. switch (srcImage.getFormat())
  66198. {
  66199. case Image::ARGB:
  66200. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66201. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66202. break;
  66203. case Image::RGB:
  66204. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66205. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66206. break;
  66207. default:
  66208. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66209. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66210. break;
  66211. }
  66212. break;
  66213. case Image::RGB:
  66214. switch (srcImage.getFormat())
  66215. {
  66216. case Image::ARGB:
  66217. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66218. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66219. break;
  66220. case Image::RGB:
  66221. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66222. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66223. break;
  66224. default:
  66225. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66226. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66227. break;
  66228. }
  66229. break;
  66230. default:
  66231. switch (srcImage.getFormat())
  66232. {
  66233. case Image::ARGB:
  66234. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66235. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66236. break;
  66237. case Image::RGB:
  66238. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66239. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66240. break;
  66241. default:
  66242. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66243. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66244. break;
  66245. }
  66246. break;
  66247. }
  66248. }
  66249. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66250. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66251. {
  66252. switch (destImage.getFormat())
  66253. {
  66254. case Image::ARGB:
  66255. switch (srcImage.getFormat())
  66256. {
  66257. case Image::ARGB:
  66258. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66259. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66260. break;
  66261. case Image::RGB:
  66262. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66263. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66264. break;
  66265. default:
  66266. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66267. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66268. break;
  66269. }
  66270. break;
  66271. case Image::RGB:
  66272. switch (srcImage.getFormat())
  66273. {
  66274. case Image::ARGB:
  66275. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66276. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66277. break;
  66278. case Image::RGB:
  66279. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66280. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66281. break;
  66282. default:
  66283. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66284. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66285. break;
  66286. }
  66287. break;
  66288. default:
  66289. switch (srcImage.getFormat())
  66290. {
  66291. case Image::ARGB:
  66292. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66293. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66294. break;
  66295. case Image::RGB:
  66296. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66297. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66298. break;
  66299. default:
  66300. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66301. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66302. break;
  66303. }
  66304. break;
  66305. }
  66306. }
  66307. };
  66308. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66309. : image (image_)
  66310. {
  66311. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66312. FillType(), Graphics::mediumResamplingQuality);
  66313. }
  66314. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66315. {
  66316. }
  66317. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66318. {
  66319. return false;
  66320. }
  66321. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66322. {
  66323. currentState->xOffset += x;
  66324. currentState->yOffset += y;
  66325. }
  66326. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66327. {
  66328. return currentState->clipToRectangle (r);
  66329. }
  66330. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66331. {
  66332. return currentState->clipToRectangleList (clipRegion);
  66333. }
  66334. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66335. {
  66336. currentState->excludeClipRectangle (r);
  66337. }
  66338. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66339. {
  66340. currentState->clipToPath (path, transform);
  66341. }
  66342. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66343. {
  66344. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66345. }
  66346. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66347. {
  66348. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66349. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66350. }
  66351. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66352. {
  66353. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66354. }
  66355. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66356. {
  66357. return currentState->edgeTable->edgeTable.isEmpty();
  66358. }
  66359. void LowLevelGraphicsSoftwareRenderer::saveState()
  66360. {
  66361. stateStack.add (new LLGCSavedState (*currentState));
  66362. }
  66363. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66364. {
  66365. LLGCSavedState* const top = stateStack.getLast();
  66366. if (top != 0)
  66367. {
  66368. currentState = top;
  66369. stateStack.removeLast (1, false);
  66370. }
  66371. else
  66372. {
  66373. jassertfalse // trying to pop with an empty stack!
  66374. }
  66375. }
  66376. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66377. {
  66378. currentState->fillType = fillType;
  66379. }
  66380. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66381. {
  66382. currentState->fillType.setOpacity (newOpacity);
  66383. }
  66384. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66385. {
  66386. currentState->interpolationQuality = quality;
  66387. }
  66388. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66389. {
  66390. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66391. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66392. if (! clipped.isEmpty())
  66393. {
  66394. EdgeTable et (clipped);
  66395. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66396. }
  66397. }
  66398. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66399. {
  66400. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66401. path, transform.translated ((float) currentState->xOffset,
  66402. (float) currentState->yOffset));
  66403. currentState->fillEdgeTable (image, et);
  66404. }
  66405. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66406. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66407. {
  66408. jassert (sourceImage.getBounds().contains (srcClip));
  66409. currentState->renderImage (image, sourceImage, srcClip, transform,
  66410. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66411. }
  66412. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66413. {
  66414. Path p;
  66415. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66416. fillPath (p, AffineTransform::identity);
  66417. }
  66418. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66419. {
  66420. if (bottom > top)
  66421. {
  66422. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66423. currentState->fillEdgeTable (image, et);
  66424. }
  66425. }
  66426. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66427. {
  66428. if (right > left)
  66429. {
  66430. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66431. (float) (right - left), 1.0f);
  66432. currentState->fillEdgeTable (image, et);
  66433. }
  66434. }
  66435. class GlyphCache : private DeletedAtShutdown
  66436. {
  66437. public:
  66438. GlyphCache() throw()
  66439. : accessCounter (0), hits (0), misses (0)
  66440. {
  66441. for (int i = 120; --i >= 0;)
  66442. glyphs.add (new CachedGlyph());
  66443. }
  66444. ~GlyphCache() throw()
  66445. {
  66446. clearSingletonInstance();
  66447. }
  66448. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66449. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66450. {
  66451. ++accessCounter;
  66452. int oldestCounter = std::numeric_limits<int>::max();
  66453. CachedGlyph* oldest = 0;
  66454. for (int i = glyphs.size(); --i >= 0;)
  66455. {
  66456. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66457. if (glyph->glyph == glyphNumber && glyph->font == font)
  66458. {
  66459. ++hits;
  66460. glyph->lastAccessCount = accessCounter;
  66461. glyph->draw (state, image, x, y);
  66462. return;
  66463. }
  66464. if (glyph->lastAccessCount <= oldestCounter)
  66465. {
  66466. oldestCounter = glyph->lastAccessCount;
  66467. oldest = glyph;
  66468. }
  66469. }
  66470. if (hits + ++misses > (glyphs.size() << 4))
  66471. {
  66472. if (misses * 2 > hits)
  66473. {
  66474. for (int i = 32; --i >= 0;)
  66475. glyphs.add (new CachedGlyph());
  66476. }
  66477. hits = misses = 0;
  66478. oldest = glyphs.getLast();
  66479. }
  66480. jassert (oldest != 0);
  66481. oldest->lastAccessCount = accessCounter;
  66482. oldest->generate (font, glyphNumber);
  66483. oldest->draw (state, image, x, y);
  66484. }
  66485. class CachedGlyph
  66486. {
  66487. public:
  66488. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66489. ~CachedGlyph() {}
  66490. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66491. {
  66492. if (edgeTable != 0)
  66493. {
  66494. EdgeTable et (*edgeTable);
  66495. et.translate (x, roundToInt (y));
  66496. state.fillEdgeTable (image, et, false);
  66497. }
  66498. }
  66499. void generate (const Font& newFont, const int glyphNumber) throw()
  66500. {
  66501. font = newFont;
  66502. glyph = glyphNumber;
  66503. edgeTable = 0;
  66504. Path glyphPath;
  66505. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66506. if (! glyphPath.isEmpty())
  66507. {
  66508. const float fontHeight = font.getHeight();
  66509. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66510. .translated (0.0f, -0.5f));
  66511. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66512. glyphPath, transform);
  66513. }
  66514. }
  66515. int glyph, lastAccessCount;
  66516. Font font;
  66517. juce_UseDebuggingNewOperator
  66518. private:
  66519. ScopedPointer <EdgeTable> edgeTable;
  66520. CachedGlyph (const CachedGlyph&);
  66521. CachedGlyph& operator= (const CachedGlyph&);
  66522. };
  66523. juce_UseDebuggingNewOperator
  66524. private:
  66525. OwnedArray <CachedGlyph> glyphs;
  66526. int accessCounter, hits, misses;
  66527. GlyphCache (const GlyphCache&);
  66528. GlyphCache& operator= (const GlyphCache&);
  66529. };
  66530. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66531. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66532. {
  66533. currentState->font = newFont;
  66534. }
  66535. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66536. {
  66537. return currentState->font;
  66538. }
  66539. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66540. {
  66541. Font& f = currentState->font;
  66542. if (transform.isOnlyTranslation())
  66543. {
  66544. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66545. transform.getTranslationX() + (float) currentState->xOffset,
  66546. transform.getTranslationY() + (float) currentState->yOffset);
  66547. }
  66548. else
  66549. {
  66550. Path p;
  66551. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66552. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66553. }
  66554. }
  66555. #if JUCE_MSVC
  66556. #pragma warning (pop)
  66557. #if JUCE_DEBUG
  66558. #pragma optimize ("", on) // resets optimisations to the project defaults
  66559. #endif
  66560. #endif
  66561. END_JUCE_NAMESPACE
  66562. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66563. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66564. BEGIN_JUCE_NAMESPACE
  66565. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66566. : flags (other.flags)
  66567. {
  66568. }
  66569. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66570. {
  66571. flags = other.flags;
  66572. return *this;
  66573. }
  66574. void RectanglePlacement::applyTo (double& x, double& y,
  66575. double& w, double& h,
  66576. const double dx, const double dy,
  66577. const double dw, const double dh) const throw()
  66578. {
  66579. if (w == 0 || h == 0)
  66580. return;
  66581. if ((flags & stretchToFit) != 0)
  66582. {
  66583. x = dx;
  66584. y = dy;
  66585. w = dw;
  66586. h = dh;
  66587. }
  66588. else
  66589. {
  66590. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66591. : jmin (dw / w, dh / h);
  66592. if ((flags & onlyReduceInSize) != 0)
  66593. scale = jmin (scale, 1.0);
  66594. if ((flags & onlyIncreaseInSize) != 0)
  66595. scale = jmax (scale, 1.0);
  66596. w *= scale;
  66597. h *= scale;
  66598. if ((flags & xLeft) != 0)
  66599. x = dx;
  66600. else if ((flags & xRight) != 0)
  66601. x = dx + dw - w;
  66602. else
  66603. x = dx + (dw - w) * 0.5;
  66604. if ((flags & yTop) != 0)
  66605. y = dy;
  66606. else if ((flags & yBottom) != 0)
  66607. y = dy + dh - h;
  66608. else
  66609. y = dy + (dh - h) * 0.5;
  66610. }
  66611. }
  66612. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66613. float w, float h,
  66614. const float dx, const float dy,
  66615. const float dw, const float dh) const throw()
  66616. {
  66617. if (w == 0 || h == 0)
  66618. return AffineTransform::identity;
  66619. const float scaleX = dw / w;
  66620. const float scaleY = dh / h;
  66621. if ((flags & stretchToFit) != 0)
  66622. return AffineTransform::translation (-x, -y)
  66623. .scaled (scaleX, scaleY)
  66624. .translated (dx, dy);
  66625. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66626. : jmin (scaleX, scaleY);
  66627. if ((flags & onlyReduceInSize) != 0)
  66628. scale = jmin (scale, 1.0f);
  66629. if ((flags & onlyIncreaseInSize) != 0)
  66630. scale = jmax (scale, 1.0f);
  66631. w *= scale;
  66632. h *= scale;
  66633. float newX = dx;
  66634. if ((flags & xRight) != 0)
  66635. newX += dw - w; // right
  66636. else if ((flags & xLeft) == 0)
  66637. newX += (dw - w) / 2.0f; // centre
  66638. float newY = dy;
  66639. if ((flags & yBottom) != 0)
  66640. newY += dh - h; // bottom
  66641. else if ((flags & yTop) == 0)
  66642. newY += (dh - h) / 2.0f; // centre
  66643. return AffineTransform::translation (-x, -y)
  66644. .scaled (scale, scale)
  66645. .translated (newX, newY);
  66646. }
  66647. END_JUCE_NAMESPACE
  66648. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66649. /*** Start of inlined file: juce_Drawable.cpp ***/
  66650. BEGIN_JUCE_NAMESPACE
  66651. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66652. const AffineTransform& transform_,
  66653. const float opacity_) throw()
  66654. : g (g_),
  66655. transform (transform_),
  66656. opacity (opacity_)
  66657. {
  66658. }
  66659. Drawable::Drawable()
  66660. {
  66661. }
  66662. Drawable::~Drawable()
  66663. {
  66664. }
  66665. void Drawable::draw (Graphics& g, const float opacity,
  66666. const AffineTransform& transform) const
  66667. {
  66668. render (RenderingContext (g, transform, opacity));
  66669. }
  66670. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66671. {
  66672. draw (g, opacity, AffineTransform::translation (x, y));
  66673. }
  66674. void Drawable::drawWithin (Graphics& g,
  66675. const int destX,
  66676. const int destY,
  66677. const int destW,
  66678. const int destH,
  66679. const RectanglePlacement& placement,
  66680. const float opacity) const
  66681. {
  66682. if (destW > 0 && destH > 0)
  66683. {
  66684. Rectangle<float> bounds (getBounds());
  66685. draw (g, opacity,
  66686. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66687. (float) destX, (float) destY,
  66688. (float) destW, (float) destH));
  66689. }
  66690. }
  66691. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66692. {
  66693. Drawable* result = 0;
  66694. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66695. if (image != 0)
  66696. {
  66697. DrawableImage* const di = new DrawableImage();
  66698. di->setImage (image, true);
  66699. result = di;
  66700. }
  66701. else
  66702. {
  66703. const String asString (String::createStringFromData (data, (int) numBytes));
  66704. XmlDocument doc (asString);
  66705. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66706. if (outer != 0 && outer->hasTagName ("svg"))
  66707. {
  66708. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  66709. if (svg != 0)
  66710. result = Drawable::createFromSVG (*svg);
  66711. }
  66712. }
  66713. return result;
  66714. }
  66715. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  66716. {
  66717. MemoryBlock mb;
  66718. dataSource.readIntoMemoryBlock (mb);
  66719. return createFromImageData (mb.getData(), mb.getSize());
  66720. }
  66721. Drawable* Drawable::createFromImageFile (const File& file)
  66722. {
  66723. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  66724. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  66725. }
  66726. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  66727. {
  66728. Drawable* d = DrawablePath::createFromValueTree (tree);
  66729. if (d == 0)
  66730. {
  66731. d = DrawableComposite::createFromValueTree (tree);
  66732. if (d == 0)
  66733. {
  66734. d = DrawableImage::createFromValueTree (tree);
  66735. if (d == 0)
  66736. d = DrawableText::createFromValueTree (tree);
  66737. }
  66738. }
  66739. return d;
  66740. }
  66741. END_JUCE_NAMESPACE
  66742. /*** End of inlined file: juce_Drawable.cpp ***/
  66743. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  66744. BEGIN_JUCE_NAMESPACE
  66745. DrawableComposite::DrawableComposite()
  66746. {
  66747. }
  66748. DrawableComposite::~DrawableComposite()
  66749. {
  66750. }
  66751. void DrawableComposite::insertDrawable (Drawable* drawable,
  66752. const AffineTransform& transform,
  66753. const int index)
  66754. {
  66755. if (drawable != 0)
  66756. {
  66757. if (! drawables.contains (drawable))
  66758. {
  66759. drawables.insert (index, drawable);
  66760. if (transform.isIdentity())
  66761. transforms.insert (index, 0);
  66762. else
  66763. transforms.insert (index, new AffineTransform (transform));
  66764. }
  66765. else
  66766. {
  66767. jassertfalse // trying to add a drawable that's already in here!
  66768. }
  66769. }
  66770. }
  66771. void DrawableComposite::insertDrawable (const Drawable& drawable,
  66772. const AffineTransform& transform,
  66773. const int index)
  66774. {
  66775. insertDrawable (drawable.createCopy(), transform, index);
  66776. }
  66777. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  66778. {
  66779. drawables.remove (index, deleteDrawable);
  66780. transforms.remove (index);
  66781. }
  66782. void DrawableComposite::bringToFront (const int index)
  66783. {
  66784. if (index >= 0 && index < drawables.size() - 1)
  66785. {
  66786. drawables.move (index, -1);
  66787. transforms.move (index, -1);
  66788. }
  66789. }
  66790. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  66791. {
  66792. if (drawables.size() > 0 && context.opacity > 0)
  66793. {
  66794. if (context.opacity >= 1.0f || drawables.size() == 1)
  66795. {
  66796. Drawable::RenderingContext contextCopy (context);
  66797. for (int i = 0; i < drawables.size(); ++i)
  66798. {
  66799. const AffineTransform* const t = transforms.getUnchecked(i);
  66800. contextCopy.transform = (t == 0) ? context.transform
  66801. : t->followedBy (context.transform);
  66802. drawables.getUnchecked(i)->render (contextCopy);
  66803. }
  66804. }
  66805. else
  66806. {
  66807. // To correctly render a whole composite layer with an overall transparency,
  66808. // we need to render everything opaquely into a temp buffer, then blend that
  66809. // with the target opacity...
  66810. const Rectangle<int> clipBounds (context.g.getClipBounds());
  66811. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  66812. {
  66813. Graphics tempG (tempImage);
  66814. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  66815. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  66816. render (tempContext);
  66817. }
  66818. context.g.setOpacity (context.opacity);
  66819. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  66820. }
  66821. }
  66822. }
  66823. const Rectangle<float> DrawableComposite::getBounds() const
  66824. {
  66825. Rectangle<float> bounds;
  66826. for (int i = 0; i < drawables.size(); ++i)
  66827. {
  66828. const Drawable* const d = drawables.getUnchecked(i);
  66829. const AffineTransform* const t = transforms.getUnchecked(i);
  66830. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  66831. : d->getBounds().transformed (*t));
  66832. if (bounds.isEmpty())
  66833. bounds = childBounds;
  66834. else if (! childBounds.isEmpty())
  66835. bounds = bounds.getUnion (childBounds);
  66836. }
  66837. return bounds;
  66838. }
  66839. bool DrawableComposite::hitTest (float x, float y) const
  66840. {
  66841. for (int i = 0; i < drawables.size(); ++i)
  66842. {
  66843. float tx = x;
  66844. float ty = y;
  66845. const AffineTransform* const t = transforms.getUnchecked(i);
  66846. if (t != 0)
  66847. t->inverted().transformPoint (tx, ty);
  66848. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  66849. return true;
  66850. }
  66851. return false;
  66852. }
  66853. Drawable* DrawableComposite::createCopy() const
  66854. {
  66855. DrawableComposite* const dc = new DrawableComposite();
  66856. for (int i = 0; i < drawables.size(); ++i)
  66857. {
  66858. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  66859. const AffineTransform* const t = transforms.getUnchecked(i);
  66860. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  66861. }
  66862. return dc;
  66863. }
  66864. ValueTree DrawableComposite::createValueTree() const throw()
  66865. {
  66866. ValueTree v ("Group");
  66867. if (getName().isNotEmpty())
  66868. v.setProperty ("id", getName(), 0);
  66869. for (int i = 0; i < drawables.size(); ++i)
  66870. {
  66871. Drawable* const d = drawables.getUnchecked(i);
  66872. ValueTree child (d->createValueTree());
  66873. AffineTransform* transform = transforms.getUnchecked(i);
  66874. if (transform != 0)
  66875. {
  66876. String t;
  66877. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  66878. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  66879. child.setProperty ("transform", t, 0);
  66880. }
  66881. v.addChild (child, -1, 0);
  66882. }
  66883. return v;
  66884. }
  66885. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  66886. {
  66887. if (! tree.hasType ("Group"))
  66888. return 0;
  66889. DrawableComposite* dc = new DrawableComposite();
  66890. dc->setName (tree ["id"]);
  66891. for (int i = 0; i < tree.getNumChildren(); ++i)
  66892. {
  66893. ValueTree childTree (tree.getChild (i));
  66894. Drawable* d = Drawable::createFromValueTree (childTree);
  66895. if (d != 0)
  66896. {
  66897. AffineTransform transform;
  66898. const String transformAtt (childTree ["transform"].toString());
  66899. if (transformAtt.isNotEmpty())
  66900. {
  66901. StringArray tokens;
  66902. tokens.addTokens (transformAtt.trim(), false);
  66903. tokens.removeEmptyStrings (true);
  66904. if (tokens.size() == 6)
  66905. {
  66906. float f[6];
  66907. for (int j = 0; j < 6; ++j)
  66908. f[j] = (float) tokens[j].getDoubleValue();
  66909. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  66910. }
  66911. }
  66912. dc->insertDrawable (d, transform);
  66913. }
  66914. }
  66915. return dc;
  66916. }
  66917. END_JUCE_NAMESPACE
  66918. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  66919. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  66920. BEGIN_JUCE_NAMESPACE
  66921. DrawableImage::DrawableImage()
  66922. : image (0),
  66923. canDeleteImage (false),
  66924. opacity (1.0f),
  66925. overlayColour (0x00000000)
  66926. {
  66927. }
  66928. DrawableImage::~DrawableImage()
  66929. {
  66930. clearImage();
  66931. }
  66932. void DrawableImage::clearImage()
  66933. {
  66934. if (canDeleteImage && image != 0)
  66935. ImageCache::releaseOrDelete (image);
  66936. image = 0;
  66937. }
  66938. void DrawableImage::setImage (const Image& imageToCopy)
  66939. {
  66940. clearImage();
  66941. image = new Image (imageToCopy);
  66942. canDeleteImage = true;
  66943. }
  66944. void DrawableImage::setImage (Image* imageToUse,
  66945. const bool releaseWhenNotNeeded)
  66946. {
  66947. clearImage();
  66948. image = imageToUse;
  66949. canDeleteImage = releaseWhenNotNeeded;
  66950. }
  66951. void DrawableImage::setOpacity (const float newOpacity)
  66952. {
  66953. opacity = newOpacity;
  66954. }
  66955. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  66956. {
  66957. overlayColour = newOverlayColour;
  66958. }
  66959. void DrawableImage::render (const Drawable::RenderingContext& context) const
  66960. {
  66961. if (image != 0)
  66962. {
  66963. if (opacity > 0.0f && ! overlayColour.isOpaque())
  66964. {
  66965. context.g.setOpacity (context.opacity * opacity);
  66966. context.g.drawImageTransformed (image, image->getBounds(),
  66967. context.transform, false);
  66968. }
  66969. if (! overlayColour.isTransparent())
  66970. {
  66971. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  66972. context.g.drawImageTransformed (image, image->getBounds(),
  66973. context.transform, true);
  66974. }
  66975. }
  66976. }
  66977. const Rectangle<float> DrawableImage::getBounds() const
  66978. {
  66979. if (image == 0)
  66980. return Rectangle<float>();
  66981. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  66982. }
  66983. bool DrawableImage::hitTest (float x, float y) const
  66984. {
  66985. return image != 0
  66986. && x >= 0.0f
  66987. && y >= 0.0f
  66988. && x < image->getWidth()
  66989. && y < image->getHeight()
  66990. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  66991. }
  66992. Drawable* DrawableImage::createCopy() const
  66993. {
  66994. DrawableImage* const di = new DrawableImage();
  66995. di->opacity = opacity;
  66996. di->overlayColour = overlayColour;
  66997. if (image != 0)
  66998. {
  66999. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67000. {
  67001. di->setImage (*image);
  67002. }
  67003. else
  67004. {
  67005. ImageCache::incReferenceCount (image);
  67006. di->setImage (image, true);
  67007. }
  67008. }
  67009. return di;
  67010. }
  67011. ValueTree DrawableImage::createValueTree() const throw()
  67012. {
  67013. ValueTree v ("Image");
  67014. if (getName().isNotEmpty())
  67015. v.setProperty ("id", getName(), 0);
  67016. if (opacity < 1.0f)
  67017. v.setProperty ("opacity", (double) opacity, 0);
  67018. if (! overlayColour.isTransparent())
  67019. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67020. if (image != 0)
  67021. {
  67022. MemoryOutputStream imageData;
  67023. PNGImageFormat pngFormat;
  67024. if (pngFormat.writeImageToStream (*image, imageData))
  67025. {
  67026. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67027. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67028. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67029. v.setProperty ("data", base64, 0);
  67030. }
  67031. }
  67032. return v;
  67033. }
  67034. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67035. {
  67036. if (! tree.hasType ("Image"))
  67037. return 0;
  67038. DrawableImage* di = new DrawableImage();
  67039. di->setName (tree ["id"]);
  67040. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67041. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67042. MemoryBlock imageData;
  67043. if (imageData.fromBase64Encoding (tree ["data"]))
  67044. {
  67045. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67046. if (im == 0)
  67047. return false;
  67048. di->setImage (im, true);
  67049. }
  67050. return di;
  67051. }
  67052. END_JUCE_NAMESPACE
  67053. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67054. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67055. BEGIN_JUCE_NAMESPACE
  67056. DrawablePath::DrawablePath()
  67057. : mainFill (Colours::black),
  67058. strokeFill (Colours::transparentBlack),
  67059. strokeType (0.0f)
  67060. {
  67061. }
  67062. DrawablePath::~DrawablePath()
  67063. {
  67064. }
  67065. void DrawablePath::setPath (const Path& newPath) throw()
  67066. {
  67067. path = newPath;
  67068. updateOutline();
  67069. }
  67070. void DrawablePath::setFill (const FillType& newFill) throw()
  67071. {
  67072. mainFill = newFill;
  67073. }
  67074. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67075. {
  67076. strokeFill = newFill;
  67077. }
  67078. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67079. {
  67080. strokeType = newStrokeType;
  67081. updateOutline();
  67082. }
  67083. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67084. {
  67085. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67086. }
  67087. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67088. {
  67089. {
  67090. FillType f (mainFill);
  67091. if (f.isGradient())
  67092. f.gradient->multiplyOpacity (context.opacity);
  67093. f.transform = f.transform.followedBy (context.transform);
  67094. context.g.setFillType (f);
  67095. context.g.fillPath (path, context.transform);
  67096. }
  67097. if (strokeType.getStrokeThickness() > 0.0f)
  67098. {
  67099. FillType f (strokeFill);
  67100. if (f.isGradient())
  67101. f.gradient->multiplyOpacity (context.opacity);
  67102. f.transform = f.transform.followedBy (context.transform);
  67103. context.g.setFillType (f);
  67104. context.g.fillPath (stroke, context.transform);
  67105. }
  67106. }
  67107. void DrawablePath::updateOutline()
  67108. {
  67109. stroke.clear();
  67110. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67111. }
  67112. const Rectangle<float> DrawablePath::getBounds() const
  67113. {
  67114. if (strokeType.getStrokeThickness() > 0.0f)
  67115. return stroke.getBounds();
  67116. else
  67117. return path.getBounds();
  67118. }
  67119. bool DrawablePath::hitTest (float x, float y) const
  67120. {
  67121. return path.contains (x, y)
  67122. || stroke.contains (x, y);
  67123. }
  67124. Drawable* DrawablePath::createCopy() const
  67125. {
  67126. DrawablePath* const dp = new DrawablePath();
  67127. dp->path = path;
  67128. dp->stroke = stroke;
  67129. dp->mainFill = mainFill;
  67130. dp->strokeFill = strokeFill;
  67131. dp->strokeType = strokeType;
  67132. return dp;
  67133. }
  67134. static const FillType readFillTypeFromTree (const ValueTree& v)
  67135. {
  67136. const String type (v["type"].toString());
  67137. if (type.equalsIgnoreCase ("solid"))
  67138. {
  67139. const String colour (v ["colour"].toString());
  67140. return Colour (colour.isEmpty() ? (uint32) 0xff000000
  67141. : (uint32) colour.getHexValue32());
  67142. }
  67143. else if (type.equalsIgnoreCase ("gradient"))
  67144. {
  67145. ColourGradient g;
  67146. g.x1 = v["x1"];
  67147. g.y1 = v["y1"];
  67148. g.x2 = v["x2"];
  67149. g.y2 = v["y2"];
  67150. g.isRadial = v["radial"];
  67151. StringArray colours;
  67152. colours.addTokens (v["colours"].toString(), false);
  67153. for (int i = 0; i < colours.size() / 2; ++i)
  67154. g.addColour (colours[i * 2].getDoubleValue(),
  67155. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67156. return g;
  67157. }
  67158. jassertfalse
  67159. return FillType();
  67160. }
  67161. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67162. {
  67163. ValueTree v (tagName);
  67164. if (fillType.isColour())
  67165. {
  67166. v.setProperty ("type", "solid", 0);
  67167. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67168. }
  67169. else if (fillType.isGradient())
  67170. {
  67171. v.setProperty ("type", "gradient", 0);
  67172. v.setProperty ("x1", fillType.gradient->x1, 0);
  67173. v.setProperty ("y1", fillType.gradient->y1, 0);
  67174. v.setProperty ("x2", fillType.gradient->x2, 0);
  67175. v.setProperty ("y2", fillType.gradient->y2, 0);
  67176. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67177. String s;
  67178. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67179. s << " " << fillType.gradient->getColourPosition (i)
  67180. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67181. v.setProperty ("colours", s.trimStart(), 0);
  67182. }
  67183. else
  67184. {
  67185. jassertfalse //xxx
  67186. }
  67187. return v;
  67188. }
  67189. ValueTree DrawablePath::createValueTree() const throw()
  67190. {
  67191. ValueTree v ("Path");
  67192. v.addChild (createTreeForFillType ("fill", mainFill), -1, 0);
  67193. v.addChild (createTreeForFillType ("stroke", strokeFill), -1, 0);
  67194. if (getName().isNotEmpty())
  67195. v.setProperty ("id", getName(), 0);
  67196. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67197. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67198. ? "miter" : (strokeType.getJointStyle() == PathStrokeType::curved ? "curved" : "bevel"), 0);
  67199. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67200. ? "butt" : (strokeType.getEndStyle() == PathStrokeType::square ? "square" : "round"), 0);
  67201. v.setProperty ("path", path.toString(), 0);
  67202. return v;
  67203. }
  67204. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67205. {
  67206. if (! tree.hasType ("Path"))
  67207. return 0;
  67208. DrawablePath* p = new DrawablePath();
  67209. p->setName (tree ["id"]);
  67210. p->mainFill = readFillTypeFromTree (tree.getChildWithName ("fill"));
  67211. p->strokeFill = readFillTypeFromTree (tree.getChildWithName ("stroke"));
  67212. const String jointStyle (tree ["jointStyle"].toString());
  67213. const String endStyle (tree ["capStyle"].toString());
  67214. p->strokeType
  67215. = PathStrokeType (tree ["strokeWidth"],
  67216. jointStyle.equalsIgnoreCase ("curved") ? PathStrokeType::curved
  67217. : (jointStyle.equalsIgnoreCase ("bevel") ? PathStrokeType::beveled
  67218. : PathStrokeType::mitered),
  67219. endStyle.equalsIgnoreCase ("square") ? PathStrokeType::square
  67220. : (endStyle.equalsIgnoreCase ("round") ? PathStrokeType::rounded
  67221. : PathStrokeType::butt));
  67222. p->path.clear();
  67223. p->path.restoreFromString (tree ["path"]);
  67224. p->updateOutline();
  67225. return p;
  67226. }
  67227. END_JUCE_NAMESPACE
  67228. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67229. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67230. BEGIN_JUCE_NAMESPACE
  67231. DrawableText::DrawableText()
  67232. : colour (Colours::white)
  67233. {
  67234. }
  67235. DrawableText::~DrawableText()
  67236. {
  67237. }
  67238. void DrawableText::setText (const GlyphArrangement& newText)
  67239. {
  67240. text = newText;
  67241. }
  67242. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67243. {
  67244. text.clear();
  67245. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67246. }
  67247. void DrawableText::setColour (const Colour& newColour)
  67248. {
  67249. colour = newColour;
  67250. }
  67251. void DrawableText::render (const Drawable::RenderingContext& context) const
  67252. {
  67253. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67254. text.draw (context.g, context.transform);
  67255. }
  67256. const Rectangle<float> DrawableText::getBounds() const
  67257. {
  67258. return text.getBoundingBox (0, -1, false);
  67259. }
  67260. bool DrawableText::hitTest (float x, float y) const
  67261. {
  67262. return text.findGlyphIndexAt (x, y) >= 0;
  67263. }
  67264. Drawable* DrawableText::createCopy() const
  67265. {
  67266. DrawableText* const dt = new DrawableText();
  67267. dt->text = text;
  67268. dt->colour = colour;
  67269. return dt;
  67270. }
  67271. ValueTree DrawableText::createValueTree() const throw()
  67272. {
  67273. ValueTree v ("Text");
  67274. if (getName().isNotEmpty())
  67275. v.setProperty ("id", getName(), 0);
  67276. jassertfalse // xxx not finished!
  67277. return v;
  67278. }
  67279. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67280. {
  67281. if (! tree.hasType ("Text"))
  67282. return 0;
  67283. DrawableText* dt = new DrawableText();
  67284. dt->setName (tree ["id"]);
  67285. jassertfalse // xxx not finished!
  67286. return dt;
  67287. }
  67288. END_JUCE_NAMESPACE
  67289. /*** End of inlined file: juce_DrawableText.cpp ***/
  67290. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67291. BEGIN_JUCE_NAMESPACE
  67292. class SVGState
  67293. {
  67294. public:
  67295. SVGState (const XmlElement* const topLevel)
  67296. : topLevelXml (topLevel),
  67297. elementX (0), elementY (0),
  67298. width (512), height (512),
  67299. viewBoxW (0), viewBoxH (0)
  67300. {
  67301. }
  67302. ~SVGState()
  67303. {
  67304. }
  67305. Drawable* parseSVGElement (const XmlElement& xml)
  67306. {
  67307. if (! xml.hasTagName ("svg"))
  67308. return 0;
  67309. DrawableComposite* const drawable = new DrawableComposite();
  67310. drawable->setName (xml.getStringAttribute ("id"));
  67311. SVGState newState (*this);
  67312. if (xml.hasAttribute ("transform"))
  67313. newState.addTransform (xml);
  67314. newState.elementX = getCoordLength (xml.getStringAttribute ("x", String (newState.elementX)), viewBoxW);
  67315. newState.elementY = getCoordLength (xml.getStringAttribute ("y", String (newState.elementY)), viewBoxH);
  67316. newState.width = getCoordLength (xml.getStringAttribute ("width", String (newState.width)), viewBoxW);
  67317. newState.height = getCoordLength (xml.getStringAttribute ("height", String (newState.height)), viewBoxH);
  67318. if (xml.hasAttribute ("viewBox"))
  67319. {
  67320. const String viewParams (xml.getStringAttribute ("viewBox"));
  67321. int i = 0;
  67322. float vx, vy, vw, vh;
  67323. if (parseCoords (viewParams, vx, vy, i, true)
  67324. && parseCoords (viewParams, vw, vh, i, true)
  67325. && vw > 0
  67326. && vh > 0)
  67327. {
  67328. newState.viewBoxW = vw;
  67329. newState.viewBoxH = vh;
  67330. int placementFlags = 0;
  67331. const String aspect (xml.getStringAttribute ("preserveAspectRatio"));
  67332. if (aspect.containsIgnoreCase ("none"))
  67333. {
  67334. placementFlags = RectanglePlacement::stretchToFit;
  67335. }
  67336. else
  67337. {
  67338. if (aspect.containsIgnoreCase ("slice"))
  67339. placementFlags |= RectanglePlacement::fillDestination;
  67340. if (aspect.containsIgnoreCase ("xMin"))
  67341. placementFlags |= RectanglePlacement::xLeft;
  67342. else if (aspect.containsIgnoreCase ("xMax"))
  67343. placementFlags |= RectanglePlacement::xRight;
  67344. else
  67345. placementFlags |= RectanglePlacement::xMid;
  67346. if (aspect.containsIgnoreCase ("yMin"))
  67347. placementFlags |= RectanglePlacement::yTop;
  67348. else if (aspect.containsIgnoreCase ("yMax"))
  67349. placementFlags |= RectanglePlacement::yBottom;
  67350. else
  67351. placementFlags |= RectanglePlacement::yMid;
  67352. }
  67353. const RectanglePlacement placement (placementFlags);
  67354. newState.transform
  67355. = placement.getTransformToFit (vx, vy, vw, vh,
  67356. 0.0f, 0.0f, newState.width, newState.height)
  67357. .followedBy (newState.transform);
  67358. }
  67359. }
  67360. else
  67361. {
  67362. if (viewBoxW == 0)
  67363. newState.viewBoxW = newState.width;
  67364. if (viewBoxH == 0)
  67365. newState.viewBoxH = newState.height;
  67366. }
  67367. newState.parseSubElements (xml, drawable);
  67368. return drawable;
  67369. }
  67370. private:
  67371. const XmlElement* const topLevelXml;
  67372. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67373. AffineTransform transform;
  67374. String cssStyleText;
  67375. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67376. {
  67377. forEachXmlChildElement (xml, e)
  67378. {
  67379. Drawable* d = 0;
  67380. if (e->hasTagName ("g"))
  67381. d = parseGroupElement (*e);
  67382. else if (e->hasTagName ("svg"))
  67383. d = parseSVGElement (*e);
  67384. else if (e->hasTagName ("path"))
  67385. d = parsePath (*e);
  67386. else if (e->hasTagName ("rect"))
  67387. d = parseRect (*e);
  67388. else if (e->hasTagName ("circle"))
  67389. d = parseCircle (*e);
  67390. else if (e->hasTagName ("ellipse"))
  67391. d = parseEllipse (*e);
  67392. else if (e->hasTagName ("line"))
  67393. d = parseLine (*e);
  67394. else if (e->hasTagName ("polyline"))
  67395. d = parsePolygon (*e, true);
  67396. else if (e->hasTagName ("polygon"))
  67397. d = parsePolygon (*e, false);
  67398. else if (e->hasTagName ("text"))
  67399. d = parseText (*e);
  67400. else if (e->hasTagName ("switch"))
  67401. d = parseSwitch (*e);
  67402. else if (e->hasTagName ("style"))
  67403. parseCSSStyle (*e);
  67404. parentDrawable->insertDrawable (d);
  67405. }
  67406. }
  67407. DrawableComposite* parseSwitch (const XmlElement& xml)
  67408. {
  67409. const XmlElement* const group = xml.getChildByName ("g");
  67410. if (group != 0)
  67411. return parseGroupElement (*group);
  67412. return 0;
  67413. }
  67414. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67415. {
  67416. DrawableComposite* const drawable = new DrawableComposite();
  67417. drawable->setName (xml.getStringAttribute ("id"));
  67418. if (xml.hasAttribute ("transform"))
  67419. {
  67420. SVGState newState (*this);
  67421. newState.addTransform (xml);
  67422. newState.parseSubElements (xml, drawable);
  67423. }
  67424. else
  67425. {
  67426. parseSubElements (xml, drawable);
  67427. }
  67428. return drawable;
  67429. }
  67430. Drawable* parsePath (const XmlElement& xml) const
  67431. {
  67432. const String d (xml.getStringAttribute ("d").trimStart());
  67433. Path path;
  67434. if (getStyleAttribute (&xml, "fill-rule").trim().equalsIgnoreCase ("evenodd"))
  67435. path.setUsingNonZeroWinding (false);
  67436. int index = 0;
  67437. float lastX = 0, lastY = 0;
  67438. float lastX2 = 0, lastY2 = 0;
  67439. juce_wchar lastCommandChar = 0;
  67440. bool isRelative = true;
  67441. bool carryOn = true;
  67442. const String validCommandChars ("MmLlHhVvCcSsQqTtAaZz");
  67443. while (d[index] != 0)
  67444. {
  67445. float x, y, x2, y2, x3, y3;
  67446. if (validCommandChars.containsChar (d[index]))
  67447. {
  67448. lastCommandChar = d [index++];
  67449. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67450. }
  67451. switch (lastCommandChar)
  67452. {
  67453. case 'M':
  67454. case 'm':
  67455. case 'L':
  67456. case 'l':
  67457. if (parseCoords (d, x, y, index, false))
  67458. {
  67459. if (isRelative)
  67460. {
  67461. x += lastX;
  67462. y += lastY;
  67463. }
  67464. if (lastCommandChar == 'M' || lastCommandChar == 'm')
  67465. {
  67466. path.startNewSubPath (x, y);
  67467. lastCommandChar = 'l';
  67468. }
  67469. else
  67470. path.lineTo (x, y);
  67471. lastX2 = lastX;
  67472. lastY2 = lastY;
  67473. lastX = x;
  67474. lastY = y;
  67475. }
  67476. else
  67477. {
  67478. ++index;
  67479. }
  67480. break;
  67481. case 'H':
  67482. case 'h':
  67483. if (parseCoord (d, x, index, false, true))
  67484. {
  67485. if (isRelative)
  67486. x += lastX;
  67487. path.lineTo (x, lastY);
  67488. lastX2 = lastX;
  67489. lastX = x;
  67490. }
  67491. else
  67492. {
  67493. ++index;
  67494. }
  67495. break;
  67496. case 'V':
  67497. case 'v':
  67498. if (parseCoord (d, y, index, false, false))
  67499. {
  67500. if (isRelative)
  67501. y += lastY;
  67502. path.lineTo (lastX, y);
  67503. lastY2 = lastY;
  67504. lastY = y;
  67505. }
  67506. else
  67507. {
  67508. ++index;
  67509. }
  67510. break;
  67511. case 'C':
  67512. case 'c':
  67513. if (parseCoords (d, x, y, index, false)
  67514. && parseCoords (d, x2, y2, index, false)
  67515. && parseCoords (d, x3, y3, index, false))
  67516. {
  67517. if (isRelative)
  67518. {
  67519. x += lastX;
  67520. y += lastY;
  67521. x2 += lastX;
  67522. y2 += lastY;
  67523. x3 += lastX;
  67524. y3 += lastY;
  67525. }
  67526. path.cubicTo (x, y, x2, y2, x3, y3);
  67527. lastX2 = x2;
  67528. lastY2 = y2;
  67529. lastX = x3;
  67530. lastY = y3;
  67531. }
  67532. else
  67533. {
  67534. ++index;
  67535. }
  67536. break;
  67537. case 'S':
  67538. case 's':
  67539. if (parseCoords (d, x, y, index, false)
  67540. && parseCoords (d, x3, y3, index, false))
  67541. {
  67542. if (isRelative)
  67543. {
  67544. x += lastX;
  67545. y += lastY;
  67546. x3 += lastX;
  67547. y3 += lastY;
  67548. }
  67549. x2 = lastX + (lastX - lastX2);
  67550. y2 = lastY + (lastY - lastY2);
  67551. path.cubicTo (x2, y2, x, y, x3, y3);
  67552. lastX2 = x;
  67553. lastY2 = y;
  67554. lastX = x3;
  67555. lastY = y3;
  67556. }
  67557. else
  67558. {
  67559. ++index;
  67560. }
  67561. break;
  67562. case 'Q':
  67563. case 'q':
  67564. if (parseCoords (d, x, y, index, false)
  67565. && parseCoords (d, x2, y2, index, false))
  67566. {
  67567. if (isRelative)
  67568. {
  67569. x += lastX;
  67570. y += lastY;
  67571. x2 += lastX;
  67572. y2 += lastY;
  67573. }
  67574. path.quadraticTo (x, y, x2, y2);
  67575. lastX2 = x;
  67576. lastY2 = y;
  67577. lastX = x2;
  67578. lastY = y2;
  67579. }
  67580. else
  67581. {
  67582. ++index;
  67583. }
  67584. break;
  67585. case 'T':
  67586. case 't':
  67587. if (parseCoords (d, x, y, index, false))
  67588. {
  67589. if (isRelative)
  67590. {
  67591. x += lastX;
  67592. y += lastY;
  67593. }
  67594. x2 = lastX + (lastX - lastX2);
  67595. y2 = lastY + (lastY - lastY2);
  67596. path.quadraticTo (x2, y2, x, y);
  67597. lastX2 = x2;
  67598. lastY2 = y2;
  67599. lastX = x;
  67600. lastY = y;
  67601. }
  67602. else
  67603. {
  67604. ++index;
  67605. }
  67606. break;
  67607. case 'A':
  67608. case 'a':
  67609. if (parseCoords (d, x, y, index, false))
  67610. {
  67611. String num;
  67612. if (parseNextNumber (d, num, index, false))
  67613. {
  67614. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67615. if (parseNextNumber (d, num, index, false))
  67616. {
  67617. const bool largeArc = num.getIntValue() != 0;
  67618. if (parseNextNumber (d, num, index, false))
  67619. {
  67620. const bool sweep = num.getIntValue() != 0;
  67621. if (parseCoords (d, x2, y2, index, false))
  67622. {
  67623. if (isRelative)
  67624. {
  67625. x2 += lastX;
  67626. y2 += lastY;
  67627. }
  67628. if (lastX != x2 || lastY != y2)
  67629. {
  67630. double centreX, centreY, startAngle, deltaAngle;
  67631. double rx = x, ry = y;
  67632. endpointToCentreParameters (lastX, lastY, x2, y2,
  67633. angle, largeArc, sweep,
  67634. rx, ry, centreX, centreY,
  67635. startAngle, deltaAngle);
  67636. path.addCentredArc ((float) centreX, (float) centreY,
  67637. (float) rx, (float) ry,
  67638. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67639. false);
  67640. path.lineTo (x2, y2);
  67641. }
  67642. lastX2 = lastX;
  67643. lastY2 = lastY;
  67644. lastX = x2;
  67645. lastY = y2;
  67646. }
  67647. }
  67648. }
  67649. }
  67650. }
  67651. else
  67652. {
  67653. ++index;
  67654. }
  67655. break;
  67656. case 'Z':
  67657. case 'z':
  67658. path.closeSubPath();
  67659. while (CharacterFunctions::isWhitespace (d [index]))
  67660. ++index;
  67661. break;
  67662. default:
  67663. carryOn = false;
  67664. break;
  67665. }
  67666. if (! carryOn)
  67667. break;
  67668. }
  67669. return parseShape (xml, path);
  67670. }
  67671. Drawable* parseRect (const XmlElement& xml) const
  67672. {
  67673. Path rect;
  67674. const bool hasRX = xml.hasAttribute ("rx");
  67675. const bool hasRY = xml.hasAttribute ("ry");
  67676. if (hasRX || hasRY)
  67677. {
  67678. float rx = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67679. float ry = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67680. if (! hasRX)
  67681. rx = ry;
  67682. else if (! hasRY)
  67683. ry = rx;
  67684. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67685. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67686. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67687. getCoordLength (xml.getStringAttribute ("height"), viewBoxH),
  67688. rx, ry);
  67689. }
  67690. else
  67691. {
  67692. rect.addRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67693. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67694. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67695. getCoordLength (xml.getStringAttribute ("height"), viewBoxH));
  67696. }
  67697. return parseShape (xml, rect);
  67698. }
  67699. Drawable* parseCircle (const XmlElement& xml) const
  67700. {
  67701. Path circle;
  67702. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67703. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67704. const float radius = getCoordLength (xml.getStringAttribute ("r"), viewBoxW);
  67705. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67706. return parseShape (xml, circle);
  67707. }
  67708. Drawable* parseEllipse (const XmlElement& xml) const
  67709. {
  67710. Path ellipse;
  67711. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67712. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67713. const float radiusX = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67714. const float radiusY = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67715. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  67716. return parseShape (xml, ellipse);
  67717. }
  67718. Drawable* parseLine (const XmlElement& xml) const
  67719. {
  67720. Path line;
  67721. const float x1 = getCoordLength (xml.getStringAttribute ("x1"), viewBoxW);
  67722. const float y1 = getCoordLength (xml.getStringAttribute ("y1"), viewBoxH);
  67723. const float x2 = getCoordLength (xml.getStringAttribute ("x2"), viewBoxW);
  67724. const float y2 = getCoordLength (xml.getStringAttribute ("y2"), viewBoxH);
  67725. line.startNewSubPath (x1, y1);
  67726. line.lineTo (x2, y2);
  67727. return parseShape (xml, line);
  67728. }
  67729. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  67730. {
  67731. const String points (xml.getStringAttribute ("points"));
  67732. Path path;
  67733. int index = 0;
  67734. float x, y;
  67735. if (parseCoords (points, x, y, index, true))
  67736. {
  67737. float firstX = x;
  67738. float firstY = y;
  67739. float lastX = 0, lastY = 0;
  67740. path.startNewSubPath (x, y);
  67741. while (parseCoords (points, x, y, index, true))
  67742. {
  67743. lastX = x;
  67744. lastY = y;
  67745. path.lineTo (x, y);
  67746. }
  67747. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  67748. path.closeSubPath();
  67749. }
  67750. return parseShape (xml, path);
  67751. }
  67752. Drawable* parseShape (const XmlElement& xml, Path& path,
  67753. const bool shouldParseTransform = true) const
  67754. {
  67755. if (shouldParseTransform && xml.hasAttribute ("transform"))
  67756. {
  67757. SVGState newState (*this);
  67758. newState.addTransform (xml);
  67759. return newState.parseShape (xml, path, false);
  67760. }
  67761. DrawablePath* dp = new DrawablePath();
  67762. dp->setName (xml.getStringAttribute ("id"));
  67763. dp->setFill (Colours::transparentBlack);
  67764. path.applyTransform (transform);
  67765. dp->setPath (path);
  67766. Path::Iterator iter (path);
  67767. bool containsClosedSubPath = false;
  67768. while (iter.next())
  67769. {
  67770. if (iter.elementType == Path::Iterator::closePath)
  67771. {
  67772. containsClosedSubPath = true;
  67773. break;
  67774. }
  67775. }
  67776. dp->setFill (getPathFillType (path,
  67777. getStyleAttribute (&xml, "fill"),
  67778. getStyleAttribute (&xml, "fill-opacity"),
  67779. getStyleAttribute (&xml, "opacity"),
  67780. containsClosedSubPath ? Colours::black
  67781. : Colours::transparentBlack));
  67782. const String strokeType (getStyleAttribute (&xml, "stroke"));
  67783. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase ("none"))
  67784. {
  67785. dp->setStrokeFill (getPathFillType (path, strokeType,
  67786. getStyleAttribute (&xml, "stroke-opacity"),
  67787. getStyleAttribute (&xml, "opacity"),
  67788. Colours::transparentBlack));
  67789. dp->setStrokeType (getStrokeFor (&xml));
  67790. }
  67791. return dp;
  67792. }
  67793. const XmlElement* findLinkedElement (const XmlElement* e) const
  67794. {
  67795. const String id (e->getStringAttribute ("xlink:href"));
  67796. if (! id.startsWithChar ('#'))
  67797. return 0;
  67798. return findElementForId (topLevelXml, id.substring (1));
  67799. }
  67800. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  67801. {
  67802. if (fillXml == 0)
  67803. return;
  67804. forEachXmlChildElementWithTagName (*fillXml, e, "stop")
  67805. {
  67806. int index = 0;
  67807. Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black));
  67808. const String opacity (getStyleAttribute (e, "stop-opacity", "1"));
  67809. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  67810. double offset = e->getDoubleAttribute ("offset");
  67811. if (e->getStringAttribute ("offset").containsChar ('%'))
  67812. offset *= 0.01;
  67813. cg.addColour (jlimit (0.0, 1.0, offset), col);
  67814. }
  67815. }
  67816. const FillType getPathFillType (const Path& path,
  67817. const String& fill,
  67818. const String& fillOpacity,
  67819. const String& overallOpacity,
  67820. const Colour& defaultColour) const
  67821. {
  67822. float opacity = 1.0f;
  67823. if (overallOpacity.isNotEmpty())
  67824. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  67825. if (fillOpacity.isNotEmpty())
  67826. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  67827. if (fill.startsWithIgnoreCase ("url"))
  67828. {
  67829. const String id (fill.fromFirstOccurrenceOf ("#", false, false)
  67830. .upToLastOccurrenceOf (")", false, false).trim());
  67831. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  67832. if (fillXml != 0
  67833. && (fillXml->hasTagName ("linearGradient")
  67834. || fillXml->hasTagName ("radialGradient")))
  67835. {
  67836. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  67837. ColourGradient gradient;
  67838. addGradientStopsIn (gradient, inheritedFrom);
  67839. addGradientStopsIn (gradient, fillXml);
  67840. if (gradient.getNumColours() > 0)
  67841. {
  67842. gradient.addColour (0.0, gradient.getColour (0));
  67843. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  67844. }
  67845. else
  67846. {
  67847. gradient.addColour (0.0, Colours::black);
  67848. gradient.addColour (1.0, Colours::black);
  67849. }
  67850. if (overallOpacity.isNotEmpty())
  67851. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  67852. jassert (gradient.getNumColours() > 0);
  67853. gradient.isRadial = fillXml->hasTagName ("radialGradient");
  67854. float width = viewBoxW;
  67855. float height = viewBoxH;
  67856. float dx = 0.0f;
  67857. float dy = 0.0f;
  67858. const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse");
  67859. if (! userSpace)
  67860. {
  67861. const Rectangle<float> bounds (path.getBounds());
  67862. dx = bounds.getX();
  67863. dy = bounds.getY();
  67864. width = bounds.getWidth();
  67865. height = bounds.getHeight();
  67866. }
  67867. if (gradient.isRadial)
  67868. {
  67869. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), width);
  67870. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), height);
  67871. const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), width);
  67872. gradient.x2 = gradient.x1 + radius;
  67873. gradient.y2 = gradient.y1;
  67874. //xxx (the fx, fy focal point isn't handled properly here..)
  67875. }
  67876. else
  67877. {
  67878. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), width);
  67879. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), height);
  67880. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), width);
  67881. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), height);
  67882. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  67883. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  67884. }
  67885. FillType type (gradient);
  67886. type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform"))
  67887. .followedBy (transform);
  67888. return type;
  67889. }
  67890. }
  67891. if (fill.equalsIgnoreCase ("none"))
  67892. return Colours::transparentBlack;
  67893. int i = 0;
  67894. const Colour colour (parseColour (fill, i, defaultColour));
  67895. return colour.withMultipliedAlpha (opacity);
  67896. }
  67897. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  67898. {
  67899. const String width (getStyleAttribute (xml, "stroke-width"));
  67900. const String cap (getStyleAttribute (xml, "stroke-linecap"));
  67901. const String join (getStyleAttribute (xml, "stroke-linejoin"));
  67902. //const String mitreLimit (getStyleAttribute (xml, "stroke-miterlimit"));
  67903. //const String dashArray (getStyleAttribute (xml, "stroke-dasharray"));
  67904. //const String dashOffset (getStyleAttribute (xml, "stroke-dashoffset"));
  67905. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  67906. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  67907. if (join.equalsIgnoreCase ("round"))
  67908. joinStyle = PathStrokeType::curved;
  67909. else if (join.equalsIgnoreCase ("bevel"))
  67910. joinStyle = PathStrokeType::beveled;
  67911. if (cap.equalsIgnoreCase ("round"))
  67912. capStyle = PathStrokeType::rounded;
  67913. else if (cap.equalsIgnoreCase ("square"))
  67914. capStyle = PathStrokeType::square;
  67915. float ox = 0.0f, oy = 0.0f;
  67916. transform.transformPoint (ox, oy);
  67917. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  67918. transform.transformPoint (x, y);
  67919. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  67920. joinStyle, capStyle);
  67921. }
  67922. Drawable* parseText (const XmlElement& xml)
  67923. {
  67924. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  67925. getCoordList (xCoords, getInheritedAttribute (&xml, "x"), true, true);
  67926. getCoordList (yCoords, getInheritedAttribute (&xml, "y"), true, false);
  67927. getCoordList (dxCoords, getInheritedAttribute (&xml, "dx"), true, true);
  67928. getCoordList (dyCoords, getInheritedAttribute (&xml, "dy"), true, false);
  67929. //xxx not done text yet!
  67930. forEachXmlChildElement (xml, e)
  67931. {
  67932. if (e->isTextElement())
  67933. {
  67934. const String text (e->getText());
  67935. Path path;
  67936. Drawable* s = parseShape (*e, path);
  67937. delete s;
  67938. }
  67939. else if (e->hasTagName ("tspan"))
  67940. {
  67941. Drawable* s = parseText (*e);
  67942. delete s;
  67943. }
  67944. }
  67945. return 0;
  67946. }
  67947. void addTransform (const XmlElement& xml)
  67948. {
  67949. transform = parseTransform (xml.getStringAttribute ("transform"))
  67950. .followedBy (transform);
  67951. }
  67952. bool parseCoord (const String& s, float& value, int& index,
  67953. const bool allowUnits, const bool isX) const
  67954. {
  67955. String number;
  67956. if (! parseNextNumber (s, number, index, allowUnits))
  67957. {
  67958. value = 0;
  67959. return false;
  67960. }
  67961. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  67962. return true;
  67963. }
  67964. bool parseCoords (const String& s, float& x, float& y,
  67965. int& index, const bool allowUnits) const
  67966. {
  67967. return parseCoord (s, x, index, allowUnits, true)
  67968. && parseCoord (s, y, index, allowUnits, false);
  67969. }
  67970. float getCoordLength (const String& s, const float sizeForProportions) const
  67971. {
  67972. float n = s.getFloatValue();
  67973. const int len = s.length();
  67974. if (len > 2)
  67975. {
  67976. const float dpi = 96.0f;
  67977. const juce_wchar n1 = s [len - 2];
  67978. const juce_wchar n2 = s [len - 1];
  67979. if (n1 == 'i' && n2 == 'n')
  67980. n *= dpi;
  67981. else if (n1 == 'm' && n2 == 'm')
  67982. n *= dpi / 25.4f;
  67983. else if (n1 == 'c' && n2 == 'm')
  67984. n *= dpi / 2.54f;
  67985. else if (n1 == 'p' && n2 == 'c')
  67986. n *= 15.0f;
  67987. else if (n2 == '%')
  67988. n *= 0.01f * sizeForProportions;
  67989. }
  67990. return n;
  67991. }
  67992. void getCoordList (Array <float>& coords, const String& list,
  67993. const bool allowUnits, const bool isX) const
  67994. {
  67995. int index = 0;
  67996. float value;
  67997. while (parseCoord (list, value, index, allowUnits, isX))
  67998. coords.add (value);
  67999. }
  68000. void parseCSSStyle (const XmlElement& xml)
  68001. {
  68002. cssStyleText = xml.getAllSubText() + "\n" + cssStyleText;
  68003. }
  68004. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68005. const String& defaultValue = String::empty) const
  68006. {
  68007. if (xml->hasAttribute (attributeName))
  68008. return xml->getStringAttribute (attributeName, defaultValue);
  68009. const String styleAtt (xml->getStringAttribute ("style"));
  68010. if (styleAtt.isNotEmpty())
  68011. {
  68012. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68013. if (value.isNotEmpty())
  68014. return value;
  68015. }
  68016. else if (xml->hasAttribute ("class"))
  68017. {
  68018. const String className ("." + xml->getStringAttribute ("class"));
  68019. int index = cssStyleText.indexOfIgnoreCase (className + " ");
  68020. if (index < 0)
  68021. index = cssStyleText.indexOfIgnoreCase (className + "{");
  68022. if (index >= 0)
  68023. {
  68024. const int openBracket = cssStyleText.indexOfChar (index, '{');
  68025. if (openBracket > index)
  68026. {
  68027. const int closeBracket = cssStyleText.indexOfChar (openBracket, '}');
  68028. if (closeBracket > openBracket)
  68029. {
  68030. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68031. if (value.isNotEmpty())
  68032. return value;
  68033. }
  68034. }
  68035. }
  68036. }
  68037. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68038. if (xml != 0)
  68039. return getStyleAttribute (xml, attributeName, defaultValue);
  68040. return defaultValue;
  68041. }
  68042. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68043. {
  68044. if (xml->hasAttribute (attributeName))
  68045. return xml->getStringAttribute (attributeName);
  68046. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68047. if (xml != 0)
  68048. return getInheritedAttribute (xml, attributeName);
  68049. return String::empty;
  68050. }
  68051. static bool isIdentifierChar (const juce_wchar c)
  68052. {
  68053. return CharacterFunctions::isLetter (c) || c == '-';
  68054. }
  68055. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68056. {
  68057. int i = 0;
  68058. for (;;)
  68059. {
  68060. i = list.indexOf (i, attributeName);
  68061. if (i < 0)
  68062. break;
  68063. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68064. && ! isIdentifierChar (list [i + attributeName.length()]))
  68065. {
  68066. i = list.indexOfChar (i, ':');
  68067. if (i < 0)
  68068. break;
  68069. int end = list.indexOfChar (i, ';');
  68070. if (end < 0)
  68071. end = 0x7ffff;
  68072. return list.substring (i + 1, end).trim();
  68073. }
  68074. ++i;
  68075. }
  68076. return defaultValue;
  68077. }
  68078. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68079. {
  68080. const juce_wchar* const s = source;
  68081. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68082. ++index;
  68083. int start = index;
  68084. if (CharacterFunctions::isDigit (s[index]) || s[index] == '.' || s[index] == '-')
  68085. ++index;
  68086. while (CharacterFunctions::isDigit (s[index]) || s[index] == '.')
  68087. ++index;
  68088. if ((s[index] == 'e' || s[index] == 'E')
  68089. && (CharacterFunctions::isDigit (s[index + 1])
  68090. || s[index + 1] == '-'
  68091. || s[index + 1] == '+'))
  68092. {
  68093. index += 2;
  68094. while (CharacterFunctions::isDigit (s[index]))
  68095. ++index;
  68096. }
  68097. if (allowUnits)
  68098. {
  68099. while (CharacterFunctions::isLetter (s[index]))
  68100. ++index;
  68101. }
  68102. if (index == start)
  68103. return false;
  68104. value = String (s + start, index - start);
  68105. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68106. ++index;
  68107. return true;
  68108. }
  68109. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68110. {
  68111. if (s [index] == '#')
  68112. {
  68113. uint32 hex [6];
  68114. zeromem (hex, sizeof (hex));
  68115. int numChars = 0;
  68116. for (int i = 6; --i >= 0;)
  68117. {
  68118. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68119. if (hexValue >= 0)
  68120. hex [numChars++] = hexValue;
  68121. else
  68122. break;
  68123. }
  68124. if (numChars <= 3)
  68125. return Colour ((uint8) (hex [0] * 0x11),
  68126. (uint8) (hex [1] * 0x11),
  68127. (uint8) (hex [2] * 0x11));
  68128. else
  68129. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68130. (uint8) ((hex [2] << 4) + hex [3]),
  68131. (uint8) ((hex [4] << 4) + hex [5]));
  68132. }
  68133. else if (s [index] == 'r'
  68134. && s [index + 1] == 'g'
  68135. && s [index + 2] == 'b')
  68136. {
  68137. const int openBracket = s.indexOfChar (index, '(');
  68138. const int closeBracket = s.indexOfChar (openBracket, ')');
  68139. if (openBracket >= 3 && closeBracket > openBracket)
  68140. {
  68141. index = closeBracket;
  68142. StringArray tokens;
  68143. tokens.addTokens (s.substring (openBracket + 1, closeBracket), ",", "");
  68144. tokens.trim();
  68145. tokens.removeEmptyStrings();
  68146. if (tokens[0].containsChar ('%'))
  68147. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68148. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68149. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68150. else
  68151. return Colour ((uint8) tokens[0].getIntValue(),
  68152. (uint8) tokens[1].getIntValue(),
  68153. (uint8) tokens[2].getIntValue());
  68154. }
  68155. }
  68156. return Colours::findColourForName (s, defaultColour);
  68157. }
  68158. static const AffineTransform parseTransform (String t)
  68159. {
  68160. AffineTransform result;
  68161. while (t.isNotEmpty())
  68162. {
  68163. StringArray tokens;
  68164. tokens.addTokens (t.fromFirstOccurrenceOf ("(", false, false)
  68165. .upToFirstOccurrenceOf (")", false, false),
  68166. ", ", String::empty);
  68167. tokens.removeEmptyStrings (true);
  68168. float numbers [6];
  68169. for (int i = 0; i < 6; ++i)
  68170. numbers[i] = tokens[i].getFloatValue();
  68171. AffineTransform trans;
  68172. if (t.startsWithIgnoreCase ("matrix"))
  68173. {
  68174. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68175. numbers[1], numbers[3], numbers[5]);
  68176. }
  68177. else if (t.startsWithIgnoreCase ("translate"))
  68178. {
  68179. jassert (tokens.size() == 2);
  68180. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68181. }
  68182. else if (t.startsWithIgnoreCase ("scale"))
  68183. {
  68184. if (tokens.size() == 1)
  68185. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68186. else
  68187. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68188. }
  68189. else if (t.startsWithIgnoreCase ("rotate"))
  68190. {
  68191. if (tokens.size() != 3)
  68192. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68193. else
  68194. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68195. numbers[1], numbers[2]);
  68196. }
  68197. else if (t.startsWithIgnoreCase ("skewX"))
  68198. {
  68199. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68200. 0.0f, 1.0f, 0.0f);
  68201. }
  68202. else if (t.startsWithIgnoreCase ("skewY"))
  68203. {
  68204. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68205. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68206. }
  68207. result = trans.followedBy (result);
  68208. t = t.fromFirstOccurrenceOf (")", false, false).trimStart();
  68209. }
  68210. return result;
  68211. }
  68212. static void endpointToCentreParameters (const double x1, const double y1,
  68213. const double x2, const double y2,
  68214. const double angle,
  68215. const bool largeArc, const bool sweep,
  68216. double& rx, double& ry,
  68217. double& centreX, double& centreY,
  68218. double& startAngle, double& deltaAngle)
  68219. {
  68220. const double midX = (x1 - x2) * 0.5;
  68221. const double midY = (y1 - y2) * 0.5;
  68222. const double cosAngle = cos (angle);
  68223. const double sinAngle = sin (angle);
  68224. const double xp = cosAngle * midX + sinAngle * midY;
  68225. const double yp = cosAngle * midY - sinAngle * midX;
  68226. const double xp2 = xp * xp;
  68227. const double yp2 = yp * yp;
  68228. double rx2 = rx * rx;
  68229. double ry2 = ry * ry;
  68230. const double s = (xp2 / rx2) + (yp2 / ry2);
  68231. double c;
  68232. if (s <= 1.0)
  68233. {
  68234. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68235. / (( rx2 * yp2) + (ry2 * xp2))));
  68236. if (largeArc == sweep)
  68237. c = -c;
  68238. }
  68239. else
  68240. {
  68241. const double s2 = sqrt (s);
  68242. rx *= s2;
  68243. ry *= s2;
  68244. rx2 = rx * rx;
  68245. ry2 = ry * ry;
  68246. c = 0;
  68247. }
  68248. const double cpx = ((rx * yp) / ry) * c;
  68249. const double cpy = ((-ry * xp) / rx) * c;
  68250. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68251. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68252. const double ux = (xp - cpx) / rx;
  68253. const double uy = (yp - cpy) / ry;
  68254. const double vx = (-xp - cpx) / rx;
  68255. const double vy = (-yp - cpy) / ry;
  68256. const double length = juce_hypot (ux, uy);
  68257. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68258. if (uy < 0)
  68259. startAngle = -startAngle;
  68260. startAngle += double_Pi * 0.5;
  68261. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68262. / (length * juce_hypot (vx, vy))));
  68263. if ((ux * vy) - (uy * vx) < 0)
  68264. deltaAngle = -deltaAngle;
  68265. if (sweep)
  68266. {
  68267. if (deltaAngle < 0)
  68268. deltaAngle += double_Pi * 2.0;
  68269. }
  68270. else
  68271. {
  68272. if (deltaAngle > 0)
  68273. deltaAngle -= double_Pi * 2.0;
  68274. }
  68275. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68276. }
  68277. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68278. {
  68279. forEachXmlChildElement (*parent, e)
  68280. {
  68281. if (e->compareAttribute ("id", id))
  68282. return e;
  68283. const XmlElement* const found = findElementForId (e, id);
  68284. if (found != 0)
  68285. return found;
  68286. }
  68287. return 0;
  68288. }
  68289. SVGState& operator= (const SVGState&);
  68290. };
  68291. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68292. {
  68293. SVGState state (&svgDocument);
  68294. return state.parseSVGElement (svgDocument);
  68295. }
  68296. END_JUCE_NAMESPACE
  68297. /*** End of inlined file: juce_SVGParser.cpp ***/
  68298. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68299. BEGIN_JUCE_NAMESPACE
  68300. #if JUCE_MSVC
  68301. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68302. #endif
  68303. DropShadowEffect::DropShadowEffect()
  68304. : offsetX (0),
  68305. offsetY (0),
  68306. radius (4),
  68307. opacity (0.6f)
  68308. {
  68309. }
  68310. DropShadowEffect::~DropShadowEffect()
  68311. {
  68312. }
  68313. void DropShadowEffect::setShadowProperties (const float newRadius,
  68314. const float newOpacity,
  68315. const int newShadowOffsetX,
  68316. const int newShadowOffsetY)
  68317. {
  68318. radius = jmax (1.1f, newRadius);
  68319. offsetX = newShadowOffsetX;
  68320. offsetY = newShadowOffsetY;
  68321. opacity = newOpacity;
  68322. }
  68323. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68324. {
  68325. const int w = image.getWidth();
  68326. const int h = image.getHeight();
  68327. Image shadowImage (Image::SingleChannel, w, h, false);
  68328. const Image::BitmapData srcData (image, 0, 0, w, h);
  68329. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68330. const int filter = roundToInt (63.0f / radius);
  68331. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68332. for (int x = w; --x >= 0;)
  68333. {
  68334. int shadowAlpha = 0;
  68335. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68336. uint8* shadowPix = destData.data + x;
  68337. for (int y = h; --y >= 0;)
  68338. {
  68339. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68340. *shadowPix = (uint8) shadowAlpha;
  68341. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68342. shadowPix += destData.lineStride;
  68343. }
  68344. }
  68345. for (int y = h; --y >= 0;)
  68346. {
  68347. int shadowAlpha = 0;
  68348. uint8* shadowPix = destData.getLinePointer (y);
  68349. for (int x = w; --x >= 0;)
  68350. {
  68351. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68352. *shadowPix++ = (uint8) shadowAlpha;
  68353. }
  68354. }
  68355. g.setColour (Colours::black.withAlpha (opacity));
  68356. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68357. g.setOpacity (1.0f);
  68358. g.drawImageAt (&image, 0, 0);
  68359. }
  68360. END_JUCE_NAMESPACE
  68361. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68362. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68363. BEGIN_JUCE_NAMESPACE
  68364. GlowEffect::GlowEffect()
  68365. : radius (2.0f),
  68366. colour (Colours::white)
  68367. {
  68368. }
  68369. GlowEffect::~GlowEffect()
  68370. {
  68371. }
  68372. void GlowEffect::setGlowProperties (const float newRadius,
  68373. const Colour& newColour)
  68374. {
  68375. radius = newRadius;
  68376. colour = newColour;
  68377. }
  68378. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68379. {
  68380. Image temp (image.getFormat(), image.getWidth(), image.getHeight(), true);
  68381. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68382. blurKernel.createGaussianBlur (radius);
  68383. blurKernel.rescaleAllValues (radius);
  68384. blurKernel.applyToImage (temp, &image, image.getBounds());
  68385. g.setColour (colour);
  68386. g.drawImageAt (&temp, 0, 0, true);
  68387. g.setOpacity (1.0f);
  68388. g.drawImageAt (&image, 0, 0, false);
  68389. }
  68390. END_JUCE_NAMESPACE
  68391. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68392. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68393. BEGIN_JUCE_NAMESPACE
  68394. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68395. : opacity (opacity_)
  68396. {
  68397. }
  68398. ReduceOpacityEffect::~ReduceOpacityEffect()
  68399. {
  68400. }
  68401. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68402. {
  68403. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68404. }
  68405. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68406. {
  68407. g.setOpacity (opacity);
  68408. g.drawImageAt (&image, 0, 0);
  68409. }
  68410. END_JUCE_NAMESPACE
  68411. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68412. /*** Start of inlined file: juce_Font.cpp ***/
  68413. BEGIN_JUCE_NAMESPACE
  68414. namespace FontValues
  68415. {
  68416. static float limitFontHeight (const float height) throw()
  68417. {
  68418. return jlimit (0.1f, 10000.0f, height);
  68419. }
  68420. static const float defaultFontHeight = 14.0f;
  68421. }
  68422. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68423. const float kerning_, const float ascent_, const int styleFlags_,
  68424. Typeface* const typeface_) throw()
  68425. : typefaceName (typefaceName_),
  68426. height (height_),
  68427. horizontalScale (horizontalScale_),
  68428. kerning (kerning_),
  68429. ascent (ascent_),
  68430. styleFlags (styleFlags_),
  68431. typeface (typeface_)
  68432. {
  68433. }
  68434. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68435. : typefaceName (other.typefaceName),
  68436. height (other.height),
  68437. horizontalScale (other.horizontalScale),
  68438. kerning (other.kerning),
  68439. ascent (other.ascent),
  68440. styleFlags (other.styleFlags),
  68441. typeface (other.typeface)
  68442. {
  68443. }
  68444. Font::Font() throw()
  68445. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::defaultFontHeight,
  68446. 1.0f, 0, 0, Font::plain, 0))
  68447. {
  68448. }
  68449. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68450. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::limitFontHeight (fontHeight),
  68451. 1.0f, 0, 0, styleFlags_, 0))
  68452. {
  68453. }
  68454. Font::Font (const String& typefaceName_,
  68455. const float fontHeight,
  68456. const int styleFlags_) throw()
  68457. : font (new SharedFontInternal (typefaceName_, FontValues::limitFontHeight (fontHeight),
  68458. 1.0f, 0, 0, styleFlags_, 0))
  68459. {
  68460. }
  68461. Font::Font (const Font& other) throw()
  68462. : font (other.font)
  68463. {
  68464. }
  68465. Font& Font::operator= (const Font& other) throw()
  68466. {
  68467. font = other.font;
  68468. return *this;
  68469. }
  68470. Font::~Font() throw()
  68471. {
  68472. }
  68473. Font::Font (const Typeface::Ptr& typeface) throw()
  68474. : font (new SharedFontInternal (typeface->getName(), FontValues::defaultFontHeight,
  68475. 1.0f, 0, 0, Font::plain, typeface))
  68476. {
  68477. }
  68478. bool Font::operator== (const Font& other) const throw()
  68479. {
  68480. return font == other.font
  68481. || (font->height == other.font->height
  68482. && font->styleFlags == other.font->styleFlags
  68483. && font->horizontalScale == other.font->horizontalScale
  68484. && font->kerning == other.font->kerning
  68485. && font->typefaceName == other.font->typefaceName);
  68486. }
  68487. bool Font::operator!= (const Font& other) const throw()
  68488. {
  68489. return ! operator== (other);
  68490. }
  68491. void Font::dupeInternalIfShared() throw()
  68492. {
  68493. if (font->getReferenceCount() > 1)
  68494. font = new SharedFontInternal (*font);
  68495. }
  68496. const String Font::getDefaultSansSerifFontName() throw()
  68497. {
  68498. static const String name ("<Sans-Serif>");
  68499. return name;
  68500. }
  68501. const String Font::getDefaultSerifFontName() throw()
  68502. {
  68503. static const String name ("<Serif>");
  68504. return name;
  68505. }
  68506. const String Font::getDefaultMonospacedFontName() throw()
  68507. {
  68508. static const String name ("<Monospaced>");
  68509. return name;
  68510. }
  68511. void Font::setTypefaceName (const String& faceName) throw()
  68512. {
  68513. if (faceName != font->typefaceName)
  68514. {
  68515. dupeInternalIfShared();
  68516. font->typefaceName = faceName;
  68517. font->typeface = 0;
  68518. font->ascent = 0;
  68519. }
  68520. }
  68521. static String fallbackFont;
  68522. const String Font::getFallbackFontName() throw()
  68523. {
  68524. return fallbackFont;
  68525. }
  68526. void Font::setFallbackFontName (const String& name) throw()
  68527. {
  68528. fallbackFont = name;
  68529. }
  68530. void Font::setHeight (float newHeight) throw()
  68531. {
  68532. newHeight = FontValues::limitFontHeight (newHeight);
  68533. if (font->height != newHeight)
  68534. {
  68535. dupeInternalIfShared();
  68536. font->height = newHeight;
  68537. }
  68538. }
  68539. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68540. {
  68541. newHeight = FontValues::limitFontHeight (newHeight);
  68542. if (font->height != newHeight)
  68543. {
  68544. dupeInternalIfShared();
  68545. font->horizontalScale *= (font->height / newHeight);
  68546. font->height = newHeight;
  68547. }
  68548. }
  68549. void Font::setStyleFlags (const int newFlags) throw()
  68550. {
  68551. if (font->styleFlags != newFlags)
  68552. {
  68553. dupeInternalIfShared();
  68554. font->styleFlags = newFlags;
  68555. font->typeface = 0;
  68556. font->ascent = 0;
  68557. }
  68558. }
  68559. void Font::setSizeAndStyle (float newHeight,
  68560. const int newStyleFlags,
  68561. const float newHorizontalScale,
  68562. const float newKerningAmount) throw()
  68563. {
  68564. newHeight = FontValues::limitFontHeight (newHeight);
  68565. if (font->height != newHeight
  68566. || font->horizontalScale != newHorizontalScale
  68567. || font->kerning != newKerningAmount)
  68568. {
  68569. dupeInternalIfShared();
  68570. font->height = newHeight;
  68571. font->horizontalScale = newHorizontalScale;
  68572. font->kerning = newKerningAmount;
  68573. }
  68574. setStyleFlags (newStyleFlags);
  68575. }
  68576. void Font::setHorizontalScale (const float scaleFactor) throw()
  68577. {
  68578. dupeInternalIfShared();
  68579. font->horizontalScale = scaleFactor;
  68580. }
  68581. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68582. {
  68583. dupeInternalIfShared();
  68584. font->kerning = extraKerning;
  68585. }
  68586. void Font::setBold (const bool shouldBeBold) throw()
  68587. {
  68588. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68589. : (font->styleFlags & ~bold));
  68590. }
  68591. bool Font::isBold() const throw()
  68592. {
  68593. return (font->styleFlags & bold) != 0;
  68594. }
  68595. void Font::setItalic (const bool shouldBeItalic) throw()
  68596. {
  68597. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68598. : (font->styleFlags & ~italic));
  68599. }
  68600. bool Font::isItalic() const throw()
  68601. {
  68602. return (font->styleFlags & italic) != 0;
  68603. }
  68604. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68605. {
  68606. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68607. : (font->styleFlags & ~underlined));
  68608. }
  68609. bool Font::isUnderlined() const throw()
  68610. {
  68611. return (font->styleFlags & underlined) != 0;
  68612. }
  68613. float Font::getAscent() const throw()
  68614. {
  68615. if (font->ascent == 0)
  68616. font->ascent = getTypeface()->getAscent();
  68617. return font->height * font->ascent;
  68618. }
  68619. float Font::getDescent() const throw()
  68620. {
  68621. return font->height - getAscent();
  68622. }
  68623. int Font::getStringWidth (const String& text) const throw()
  68624. {
  68625. return roundToInt (getStringWidthFloat (text));
  68626. }
  68627. float Font::getStringWidthFloat (const String& text) const throw()
  68628. {
  68629. float w = getTypeface()->getStringWidth (text);
  68630. if (font->kerning != 0)
  68631. w += font->kerning * text.length();
  68632. return w * font->height * font->horizontalScale;
  68633. }
  68634. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68635. {
  68636. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68637. const float scale = font->height * font->horizontalScale;
  68638. const int num = xOffsets.size();
  68639. if (num > 0)
  68640. {
  68641. float* const x = &(xOffsets.getReference(0));
  68642. if (font->kerning != 0)
  68643. {
  68644. for (int i = 0; i < num; ++i)
  68645. x[i] = (x[i] + i * font->kerning) * scale;
  68646. }
  68647. else
  68648. {
  68649. for (int i = 0; i < num; ++i)
  68650. x[i] *= scale;
  68651. }
  68652. }
  68653. }
  68654. void Font::findFonts (Array<Font>& destArray) throw()
  68655. {
  68656. const StringArray names (findAllTypefaceNames());
  68657. for (int i = 0; i < names.size(); ++i)
  68658. destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain));
  68659. }
  68660. class TypefaceCache : public DeletedAtShutdown
  68661. {
  68662. public:
  68663. TypefaceCache (int numToCache = 10) throw()
  68664. : counter (1)
  68665. {
  68666. while (--numToCache >= 0)
  68667. faces.add (new CachedFace());
  68668. }
  68669. ~TypefaceCache()
  68670. {
  68671. clearSingletonInstance();
  68672. }
  68673. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68674. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68675. {
  68676. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68677. const String faceName (font.getTypefaceName());
  68678. int i;
  68679. for (i = faces.size(); --i >= 0;)
  68680. {
  68681. CachedFace* const face = faces.getUnchecked(i);
  68682. if (face->flags == flags
  68683. && face->typefaceName == faceName)
  68684. {
  68685. face->lastUsageCount = ++counter;
  68686. return face->typeFace;
  68687. }
  68688. }
  68689. int replaceIndex = 0;
  68690. int bestLastUsageCount = std::numeric_limits<int>::max();
  68691. for (i = faces.size(); --i >= 0;)
  68692. {
  68693. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68694. if (bestLastUsageCount > lu)
  68695. {
  68696. bestLastUsageCount = lu;
  68697. replaceIndex = i;
  68698. }
  68699. }
  68700. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68701. face->typefaceName = faceName;
  68702. face->flags = flags;
  68703. face->lastUsageCount = ++counter;
  68704. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68705. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68706. return face->typeFace;
  68707. }
  68708. juce_UseDebuggingNewOperator
  68709. private:
  68710. struct CachedFace
  68711. {
  68712. CachedFace() throw()
  68713. : lastUsageCount (0), flags (-1)
  68714. {
  68715. }
  68716. String typefaceName;
  68717. int lastUsageCount;
  68718. int flags;
  68719. Typeface::Ptr typeFace;
  68720. };
  68721. int counter;
  68722. OwnedArray <CachedFace> faces;
  68723. TypefaceCache (const TypefaceCache&);
  68724. TypefaceCache& operator= (const TypefaceCache&);
  68725. };
  68726. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  68727. Typeface* Font::getTypeface() const throw()
  68728. {
  68729. if (font->typeface == 0)
  68730. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  68731. return font->typeface;
  68732. }
  68733. END_JUCE_NAMESPACE
  68734. /*** End of inlined file: juce_Font.cpp ***/
  68735. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  68736. BEGIN_JUCE_NAMESPACE
  68737. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  68738. const juce_wchar character_, const int glyph_)
  68739. : x (x_),
  68740. y (y_),
  68741. w (w_),
  68742. font (font_),
  68743. character (character_),
  68744. glyph (glyph_)
  68745. {
  68746. }
  68747. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  68748. : x (other.x),
  68749. y (other.y),
  68750. w (other.w),
  68751. font (other.font),
  68752. character (other.character),
  68753. glyph (other.glyph)
  68754. {
  68755. }
  68756. void PositionedGlyph::draw (const Graphics& g) const
  68757. {
  68758. if (! isWhitespace())
  68759. {
  68760. g.getInternalContext()->setFont (font);
  68761. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  68762. }
  68763. }
  68764. void PositionedGlyph::draw (const Graphics& g,
  68765. const AffineTransform& transform) const
  68766. {
  68767. if (! isWhitespace())
  68768. {
  68769. g.getInternalContext()->setFont (font);
  68770. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  68771. .followedBy (transform));
  68772. }
  68773. }
  68774. void PositionedGlyph::createPath (Path& path) const
  68775. {
  68776. if (! isWhitespace())
  68777. {
  68778. Typeface* const t = font.getTypeface();
  68779. if (t != 0)
  68780. {
  68781. Path p;
  68782. t->getOutlineForGlyph (glyph, p);
  68783. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  68784. .translated (x, y));
  68785. }
  68786. }
  68787. }
  68788. bool PositionedGlyph::hitTest (float px, float py) const
  68789. {
  68790. if (getBounds().contains (px, py) && ! isWhitespace())
  68791. {
  68792. Typeface* const t = font.getTypeface();
  68793. if (t != 0)
  68794. {
  68795. Path p;
  68796. t->getOutlineForGlyph (glyph, p);
  68797. AffineTransform::translation (-x, -y)
  68798. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  68799. .transformPoint (px, py);
  68800. return p.contains (px, py);
  68801. }
  68802. }
  68803. return false;
  68804. }
  68805. void PositionedGlyph::moveBy (const float deltaX,
  68806. const float deltaY)
  68807. {
  68808. x += deltaX;
  68809. y += deltaY;
  68810. }
  68811. GlyphArrangement::GlyphArrangement()
  68812. {
  68813. glyphs.ensureStorageAllocated (128);
  68814. }
  68815. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  68816. {
  68817. addGlyphArrangement (other);
  68818. }
  68819. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  68820. {
  68821. if (this != &other)
  68822. {
  68823. clear();
  68824. addGlyphArrangement (other);
  68825. }
  68826. return *this;
  68827. }
  68828. GlyphArrangement::~GlyphArrangement()
  68829. {
  68830. }
  68831. void GlyphArrangement::clear()
  68832. {
  68833. glyphs.clear();
  68834. }
  68835. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  68836. {
  68837. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  68838. return *glyphs [index];
  68839. }
  68840. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  68841. {
  68842. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  68843. for (int i = 0; i < other.glyphs.size(); ++i)
  68844. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  68845. }
  68846. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  68847. {
  68848. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  68849. }
  68850. void GlyphArrangement::addLineOfText (const Font& font,
  68851. const String& text,
  68852. const float xOffset,
  68853. const float yOffset)
  68854. {
  68855. addCurtailedLineOfText (font, text,
  68856. xOffset, yOffset,
  68857. 1.0e10f, false);
  68858. }
  68859. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  68860. const String& text,
  68861. float xOffset,
  68862. const float yOffset,
  68863. const float maxWidthPixels,
  68864. const bool useEllipsis)
  68865. {
  68866. if (text.isNotEmpty())
  68867. {
  68868. Array <int> newGlyphs;
  68869. Array <float> xOffsets;
  68870. font.getGlyphPositions (text, newGlyphs, xOffsets);
  68871. const int textLen = newGlyphs.size();
  68872. const juce_wchar* const unicodeText = text;
  68873. for (int i = 0; i < textLen; ++i)
  68874. {
  68875. const float thisX = xOffsets.getUnchecked (i);
  68876. const float nextX = xOffsets.getUnchecked (i + 1);
  68877. if (nextX > maxWidthPixels + 1.0f)
  68878. {
  68879. // curtail the string if it's too wide..
  68880. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  68881. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  68882. break;
  68883. }
  68884. else
  68885. {
  68886. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  68887. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  68888. }
  68889. }
  68890. }
  68891. }
  68892. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  68893. const int startIndex, int endIndex)
  68894. {
  68895. int numDeleted = 0;
  68896. if (glyphs.size() > 0)
  68897. {
  68898. Array<int> dotGlyphs;
  68899. Array<float> dotXs;
  68900. font.getGlyphPositions ("..", dotGlyphs, dotXs);
  68901. const float dx = dotXs[1];
  68902. float xOffset = 0.0f, yOffset = 0.0f;
  68903. while (endIndex > startIndex)
  68904. {
  68905. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  68906. xOffset = pg->x;
  68907. yOffset = pg->y;
  68908. glyphs.remove (endIndex);
  68909. ++numDeleted;
  68910. if (xOffset + dx * 3 <= maxXPos)
  68911. break;
  68912. }
  68913. for (int i = 3; --i >= 0;)
  68914. {
  68915. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  68916. font, '.', dotGlyphs.getFirst()));
  68917. --numDeleted;
  68918. xOffset += dx;
  68919. if (xOffset > maxXPos)
  68920. break;
  68921. }
  68922. }
  68923. return numDeleted;
  68924. }
  68925. void GlyphArrangement::addJustifiedText (const Font& font,
  68926. const String& text,
  68927. float x, float y,
  68928. const float maxLineWidth,
  68929. const Justification& horizontalLayout)
  68930. {
  68931. int lineStartIndex = glyphs.size();
  68932. addLineOfText (font, text, x, y);
  68933. const float originalY = y;
  68934. while (lineStartIndex < glyphs.size())
  68935. {
  68936. int i = lineStartIndex;
  68937. if (glyphs.getUnchecked(i)->getCharacter() != '\n'
  68938. && glyphs.getUnchecked(i)->getCharacter() != '\r')
  68939. ++i;
  68940. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  68941. int lastWordBreakIndex = -1;
  68942. while (i < glyphs.size())
  68943. {
  68944. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  68945. const juce_wchar c = pg->getCharacter();
  68946. if (c == '\r' || c == '\n')
  68947. {
  68948. ++i;
  68949. if (c == '\r' && i < glyphs.size()
  68950. && glyphs.getUnchecked(i)->getCharacter() == '\n')
  68951. ++i;
  68952. break;
  68953. }
  68954. else if (pg->isWhitespace())
  68955. {
  68956. lastWordBreakIndex = i + 1;
  68957. }
  68958. else if (pg->getRight() - 0.0001f >= lineMaxX)
  68959. {
  68960. if (lastWordBreakIndex >= 0)
  68961. i = lastWordBreakIndex;
  68962. break;
  68963. }
  68964. ++i;
  68965. }
  68966. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  68967. float currentLineEndX = currentLineStartX;
  68968. for (int j = i; --j >= lineStartIndex;)
  68969. {
  68970. if (! glyphs.getUnchecked (j)->isWhitespace())
  68971. {
  68972. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  68973. break;
  68974. }
  68975. }
  68976. float deltaX = 0.0f;
  68977. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  68978. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  68979. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  68980. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  68981. else if (horizontalLayout.testFlags (Justification::right))
  68982. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  68983. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  68984. x + deltaX - currentLineStartX, y - originalY);
  68985. lineStartIndex = i;
  68986. y += font.getHeight();
  68987. }
  68988. }
  68989. void GlyphArrangement::addFittedText (const Font& f,
  68990. const String& text,
  68991. const float x, const float y,
  68992. const float width, const float height,
  68993. const Justification& layout,
  68994. int maximumLines,
  68995. const float minimumHorizontalScale)
  68996. {
  68997. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  68998. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  68999. if (text.containsAnyOf ("\r\n"))
  69000. {
  69001. GlyphArrangement ga;
  69002. ga.addJustifiedText (f, text, x, y, width, layout);
  69003. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  69004. float dy = y - bb.getY();
  69005. if (layout.testFlags (Justification::verticallyCentred))
  69006. dy += (height - bb.getHeight()) * 0.5f;
  69007. else if (layout.testFlags (Justification::bottom))
  69008. dy += height - bb.getHeight();
  69009. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69010. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69011. for (int i = 0; i < ga.glyphs.size(); ++i)
  69012. glyphs.add (ga.glyphs.getUnchecked (i));
  69013. ga.glyphs.clear (false);
  69014. return;
  69015. }
  69016. int startIndex = glyphs.size();
  69017. addLineOfText (f, text.trim(), x, y);
  69018. if (glyphs.size() > startIndex)
  69019. {
  69020. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69021. - glyphs.getUnchecked (startIndex)->getLeft();
  69022. if (lineWidth <= 0)
  69023. return;
  69024. if (lineWidth * minimumHorizontalScale < width)
  69025. {
  69026. if (lineWidth > width)
  69027. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69028. width / lineWidth);
  69029. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69030. x, y, width, height, layout);
  69031. }
  69032. else if (maximumLines <= 1)
  69033. {
  69034. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69035. x, y, width, height, f, layout, minimumHorizontalScale);
  69036. }
  69037. else
  69038. {
  69039. Font font (f);
  69040. String txt (text.trim());
  69041. const int length = txt.length();
  69042. const int originalStartIndex = startIndex;
  69043. int numLines = 1;
  69044. if (length <= 12 && ! txt.containsAnyOf (" -\t\r\n"))
  69045. maximumLines = 1;
  69046. maximumLines = jmin (maximumLines, length);
  69047. while (numLines < maximumLines)
  69048. {
  69049. ++numLines;
  69050. const float newFontHeight = height / (float) numLines;
  69051. if (newFontHeight < font.getHeight())
  69052. {
  69053. font.setHeight (jmax (8.0f, newFontHeight));
  69054. removeRangeOfGlyphs (startIndex, -1);
  69055. addLineOfText (font, txt, x, y);
  69056. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69057. - glyphs.getUnchecked (startIndex)->getLeft();
  69058. }
  69059. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69060. break;
  69061. }
  69062. if (numLines < 1)
  69063. numLines = 1;
  69064. float lineY = y;
  69065. float widthPerLine = lineWidth / numLines;
  69066. int lastLineStartIndex = 0;
  69067. for (int line = 0; line < numLines; ++line)
  69068. {
  69069. int i = startIndex;
  69070. lastLineStartIndex = i;
  69071. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69072. if (line == numLines - 1)
  69073. {
  69074. widthPerLine = width;
  69075. i = glyphs.size();
  69076. }
  69077. else
  69078. {
  69079. while (i < glyphs.size())
  69080. {
  69081. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69082. if (lineWidth > widthPerLine)
  69083. {
  69084. // got to a point where the line's too long, so skip forward to find a
  69085. // good place to break it..
  69086. const int searchStartIndex = i;
  69087. while (i < glyphs.size())
  69088. {
  69089. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69090. {
  69091. if (glyphs.getUnchecked (i)->isWhitespace()
  69092. || glyphs.getUnchecked (i)->getCharacter() == '-')
  69093. {
  69094. ++i;
  69095. break;
  69096. }
  69097. }
  69098. else
  69099. {
  69100. // can't find a suitable break, so try looking backwards..
  69101. i = searchStartIndex;
  69102. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69103. {
  69104. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69105. || glyphs.getUnchecked (i - back)->getCharacter() == '-')
  69106. {
  69107. i -= back - 1;
  69108. break;
  69109. }
  69110. }
  69111. break;
  69112. }
  69113. ++i;
  69114. }
  69115. break;
  69116. }
  69117. ++i;
  69118. }
  69119. int wsStart = i;
  69120. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69121. --wsStart;
  69122. int wsEnd = i;
  69123. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69124. ++wsEnd;
  69125. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69126. i = jmax (wsStart, startIndex + 1);
  69127. }
  69128. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69129. x, lineY, width, font.getHeight(), font,
  69130. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69131. minimumHorizontalScale);
  69132. startIndex = i;
  69133. lineY += font.getHeight();
  69134. if (startIndex >= glyphs.size())
  69135. break;
  69136. }
  69137. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69138. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69139. }
  69140. }
  69141. }
  69142. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69143. const float dx, const float dy)
  69144. {
  69145. jassert (startIndex >= 0);
  69146. if (dx != 0.0f || dy != 0.0f)
  69147. {
  69148. if (num < 0 || startIndex + num > glyphs.size())
  69149. num = glyphs.size() - startIndex;
  69150. while (--num >= 0)
  69151. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69152. }
  69153. }
  69154. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69155. const Justification& justification, float minimumHorizontalScale)
  69156. {
  69157. int numDeleted = 0;
  69158. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69159. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69160. if (lineWidth > w)
  69161. {
  69162. if (minimumHorizontalScale < 1.0f)
  69163. {
  69164. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69165. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69166. }
  69167. if (lineWidth > w)
  69168. {
  69169. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69170. numGlyphs -= numDeleted;
  69171. }
  69172. }
  69173. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69174. return numDeleted;
  69175. }
  69176. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69177. const float horizontalScaleFactor)
  69178. {
  69179. jassert (startIndex >= 0);
  69180. if (num < 0 || startIndex + num > glyphs.size())
  69181. num = glyphs.size() - startIndex;
  69182. if (num > 0)
  69183. {
  69184. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69185. while (--num >= 0)
  69186. {
  69187. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69188. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69189. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69190. pg->w *= horizontalScaleFactor;
  69191. }
  69192. }
  69193. }
  69194. const Rectangle<float> GlyphArrangement::getBoundingBox (int startIndex, int num, const bool includeWhitespace) const
  69195. {
  69196. jassert (startIndex >= 0);
  69197. if (num < 0 || startIndex + num > glyphs.size())
  69198. num = glyphs.size() - startIndex;
  69199. Rectangle<float> result;
  69200. bool isFirst = true;
  69201. while (--num >= 0)
  69202. {
  69203. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69204. if (includeWhitespace || ! pg->isWhitespace())
  69205. {
  69206. if (isFirst)
  69207. {
  69208. isFirst = false;
  69209. result = pg->getBounds();
  69210. }
  69211. else
  69212. {
  69213. result = result.getUnion (pg->getBounds());
  69214. }
  69215. }
  69216. }
  69217. return result;
  69218. }
  69219. void GlyphArrangement::justifyGlyphs (const int startIndex, const int num,
  69220. const float x, const float y, const float width, const float height,
  69221. const Justification& justification)
  69222. {
  69223. jassert (num >= 0 && startIndex >= 0);
  69224. if (glyphs.size() > 0 && num > 0)
  69225. {
  69226. const Rectangle<float> bb (getBoundingBox (startIndex, num, ! justification.testFlags (Justification::horizontallyJustified
  69227. | Justification::horizontallyCentred)));
  69228. float deltaX = 0.0f;
  69229. if (justification.testFlags (Justification::horizontallyJustified))
  69230. deltaX = x - bb.getX();
  69231. else if (justification.testFlags (Justification::horizontallyCentred))
  69232. deltaX = x + (width - bb.getWidth()) * 0.5f - bb.getX();
  69233. else if (justification.testFlags (Justification::right))
  69234. deltaX = (x + width) - bb.getRight();
  69235. else
  69236. deltaX = x - bb.getX();
  69237. float deltaY = 0.0f;
  69238. if (justification.testFlags (Justification::top))
  69239. deltaY = y - bb.getY();
  69240. else if (justification.testFlags (Justification::bottom))
  69241. deltaY = (y + height) - bb.getBottom();
  69242. else
  69243. deltaY = y + (height - bb.getHeight()) * 0.5f - bb.getY();
  69244. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69245. if (justification.testFlags (Justification::horizontallyJustified))
  69246. {
  69247. int lineStart = 0;
  69248. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69249. int i;
  69250. for (i = 0; i < num; ++i)
  69251. {
  69252. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69253. if (glyphY != baseY)
  69254. {
  69255. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69256. lineStart = i;
  69257. baseY = glyphY;
  69258. }
  69259. }
  69260. if (i > lineStart)
  69261. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69262. }
  69263. }
  69264. }
  69265. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69266. {
  69267. if (start + num < glyphs.size()
  69268. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\r'
  69269. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\n')
  69270. {
  69271. int numSpaces = 0;
  69272. int spacesAtEnd = 0;
  69273. for (int i = 0; i < num; ++i)
  69274. {
  69275. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69276. {
  69277. ++spacesAtEnd;
  69278. ++numSpaces;
  69279. }
  69280. else
  69281. {
  69282. spacesAtEnd = 0;
  69283. }
  69284. }
  69285. numSpaces -= spacesAtEnd;
  69286. if (numSpaces > 0)
  69287. {
  69288. const float startX = glyphs.getUnchecked (start)->getLeft();
  69289. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69290. const float extraPaddingBetweenWords
  69291. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69292. float deltaX = 0.0f;
  69293. for (int i = 0; i < num; ++i)
  69294. {
  69295. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69296. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69297. deltaX += extraPaddingBetweenWords;
  69298. }
  69299. }
  69300. }
  69301. }
  69302. void GlyphArrangement::draw (const Graphics& g) const
  69303. {
  69304. for (int i = 0; i < glyphs.size(); ++i)
  69305. {
  69306. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69307. if (pg->font.isUnderlined())
  69308. {
  69309. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69310. float nextX = pg->x + pg->w;
  69311. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69312. nextX = glyphs.getUnchecked (i + 1)->x;
  69313. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69314. nextX - pg->x, lineThickness);
  69315. }
  69316. pg->draw (g);
  69317. }
  69318. }
  69319. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69320. {
  69321. for (int i = 0; i < glyphs.size(); ++i)
  69322. {
  69323. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69324. if (pg->font.isUnderlined())
  69325. {
  69326. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69327. float nextX = pg->x + pg->w;
  69328. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69329. nextX = glyphs.getUnchecked (i + 1)->x;
  69330. Path p;
  69331. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69332. nextX, pg->y + lineThickness * 2.0f,
  69333. lineThickness);
  69334. g.fillPath (p, transform);
  69335. }
  69336. pg->draw (g, transform);
  69337. }
  69338. }
  69339. void GlyphArrangement::createPath (Path& path) const
  69340. {
  69341. for (int i = 0; i < glyphs.size(); ++i)
  69342. glyphs.getUnchecked (i)->createPath (path);
  69343. }
  69344. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69345. {
  69346. for (int i = 0; i < glyphs.size(); ++i)
  69347. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69348. return i;
  69349. return -1;
  69350. }
  69351. END_JUCE_NAMESPACE
  69352. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69353. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69354. BEGIN_JUCE_NAMESPACE
  69355. class TextLayout::Token
  69356. {
  69357. public:
  69358. String text;
  69359. Font font;
  69360. int x, y, w, h;
  69361. int line, lineHeight;
  69362. bool isWhitespace, isNewLine;
  69363. Token (const String& t,
  69364. const Font& f,
  69365. const bool isWhitespace_)
  69366. : text (t),
  69367. font (f),
  69368. x(0),
  69369. y(0),
  69370. isWhitespace (isWhitespace_)
  69371. {
  69372. w = font.getStringWidth (t);
  69373. h = roundToInt (f.getHeight());
  69374. isNewLine = t.containsChar ('\n') || t.containsChar ('\r');
  69375. }
  69376. Token (const Token& other)
  69377. : text (other.text),
  69378. font (other.font),
  69379. x (other.x),
  69380. y (other.y),
  69381. w (other.w),
  69382. h (other.h),
  69383. line (other.line),
  69384. lineHeight (other.lineHeight),
  69385. isWhitespace (other.isWhitespace),
  69386. isNewLine (other.isNewLine)
  69387. {
  69388. }
  69389. ~Token()
  69390. {
  69391. }
  69392. void draw (Graphics& g,
  69393. const int xOffset,
  69394. const int yOffset)
  69395. {
  69396. if (! isWhitespace)
  69397. {
  69398. g.setFont (font);
  69399. g.drawSingleLineText (text.trimEnd(),
  69400. xOffset + x,
  69401. yOffset + y + (lineHeight - h)
  69402. + roundToInt (font.getAscent()));
  69403. }
  69404. }
  69405. juce_UseDebuggingNewOperator
  69406. };
  69407. TextLayout::TextLayout()
  69408. : totalLines (0)
  69409. {
  69410. tokens.ensureStorageAllocated (64);
  69411. }
  69412. TextLayout::TextLayout (const String& text, const Font& font)
  69413. : totalLines (0)
  69414. {
  69415. tokens.ensureStorageAllocated (64);
  69416. appendText (text, font);
  69417. }
  69418. TextLayout::TextLayout (const TextLayout& other)
  69419. : totalLines (0)
  69420. {
  69421. *this = other;
  69422. }
  69423. TextLayout& TextLayout::operator= (const TextLayout& other)
  69424. {
  69425. if (this != &other)
  69426. {
  69427. clear();
  69428. totalLines = other.totalLines;
  69429. for (int i = 0; i < other.tokens.size(); ++i)
  69430. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69431. }
  69432. return *this;
  69433. }
  69434. TextLayout::~TextLayout()
  69435. {
  69436. clear();
  69437. }
  69438. void TextLayout::clear()
  69439. {
  69440. tokens.clear();
  69441. totalLines = 0;
  69442. }
  69443. void TextLayout::appendText (const String& text, const Font& font)
  69444. {
  69445. const juce_wchar* t = text;
  69446. String currentString;
  69447. int lastCharType = 0;
  69448. for (;;)
  69449. {
  69450. const juce_wchar c = *t++;
  69451. if (c == 0)
  69452. break;
  69453. int charType;
  69454. if (c == '\r' || c == '\n')
  69455. {
  69456. charType = 0;
  69457. }
  69458. else if (CharacterFunctions::isWhitespace (c))
  69459. {
  69460. charType = 2;
  69461. }
  69462. else
  69463. {
  69464. charType = 1;
  69465. }
  69466. if (charType == 0 || charType != lastCharType)
  69467. {
  69468. if (currentString.isNotEmpty())
  69469. {
  69470. tokens.add (new Token (currentString, font,
  69471. lastCharType == 2 || lastCharType == 0));
  69472. }
  69473. currentString = String::charToString (c);
  69474. if (c == '\r' && *t == '\n')
  69475. currentString += *t++;
  69476. }
  69477. else
  69478. {
  69479. currentString += c;
  69480. }
  69481. lastCharType = charType;
  69482. }
  69483. if (currentString.isNotEmpty())
  69484. tokens.add (new Token (currentString, font, lastCharType == 2));
  69485. }
  69486. void TextLayout::setText (const String& text, const Font& font)
  69487. {
  69488. clear();
  69489. appendText (text, font);
  69490. }
  69491. void TextLayout::layout (int maxWidth,
  69492. const Justification& justification,
  69493. const bool attemptToBalanceLineLengths)
  69494. {
  69495. if (attemptToBalanceLineLengths)
  69496. {
  69497. const int originalW = maxWidth;
  69498. int bestWidth = maxWidth;
  69499. float bestLineProportion = 0.0f;
  69500. while (maxWidth > originalW / 2)
  69501. {
  69502. layout (maxWidth, justification, false);
  69503. if (getNumLines() <= 1)
  69504. return;
  69505. const int lastLineW = getLineWidth (getNumLines() - 1);
  69506. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69507. const float prop = lastLineW / (float) lastButOneLineW;
  69508. if (prop > 0.9f)
  69509. return;
  69510. if (prop > bestLineProportion)
  69511. {
  69512. bestLineProportion = prop;
  69513. bestWidth = maxWidth;
  69514. }
  69515. maxWidth -= 10;
  69516. }
  69517. layout (bestWidth, justification, false);
  69518. }
  69519. else
  69520. {
  69521. int x = 0;
  69522. int y = 0;
  69523. int h = 0;
  69524. totalLines = 0;
  69525. int i;
  69526. for (i = 0; i < tokens.size(); ++i)
  69527. {
  69528. Token* const t = tokens.getUnchecked(i);
  69529. t->x = x;
  69530. t->y = y;
  69531. t->line = totalLines;
  69532. x += t->w;
  69533. h = jmax (h, t->h);
  69534. const Token* nextTok = tokens [i + 1];
  69535. if (nextTok == 0)
  69536. break;
  69537. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69538. {
  69539. // finished a line, so go back and update the heights of the things on it
  69540. for (int j = i; j >= 0; --j)
  69541. {
  69542. Token* const tok = tokens.getUnchecked(j);
  69543. if (tok->line == totalLines)
  69544. tok->lineHeight = h;
  69545. else
  69546. break;
  69547. }
  69548. x = 0;
  69549. y += h;
  69550. h = 0;
  69551. ++totalLines;
  69552. }
  69553. }
  69554. // finished a line, so go back and update the heights of the things on it
  69555. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69556. {
  69557. Token* const t = tokens.getUnchecked(j);
  69558. if (t->line == totalLines)
  69559. t->lineHeight = h;
  69560. else
  69561. break;
  69562. }
  69563. ++totalLines;
  69564. if (! justification.testFlags (Justification::left))
  69565. {
  69566. int totalW = getWidth();
  69567. for (i = totalLines; --i >= 0;)
  69568. {
  69569. const int lineW = getLineWidth (i);
  69570. int dx = 0;
  69571. if (justification.testFlags (Justification::horizontallyCentred))
  69572. dx = (totalW - lineW) / 2;
  69573. else if (justification.testFlags (Justification::right))
  69574. dx = totalW - lineW;
  69575. for (int j = tokens.size(); --j >= 0;)
  69576. {
  69577. Token* const t = tokens.getUnchecked(j);
  69578. if (t->line == i)
  69579. t->x += dx;
  69580. }
  69581. }
  69582. }
  69583. }
  69584. }
  69585. int TextLayout::getLineWidth (const int lineNumber) const
  69586. {
  69587. int maxW = 0;
  69588. for (int i = tokens.size(); --i >= 0;)
  69589. {
  69590. const Token* const t = tokens.getUnchecked(i);
  69591. if (t->line == lineNumber && ! t->isWhitespace)
  69592. maxW = jmax (maxW, t->x + t->w);
  69593. }
  69594. return maxW;
  69595. }
  69596. int TextLayout::getWidth() const
  69597. {
  69598. int maxW = 0;
  69599. for (int i = tokens.size(); --i >= 0;)
  69600. {
  69601. const Token* const t = tokens.getUnchecked(i);
  69602. if (! t->isWhitespace)
  69603. maxW = jmax (maxW, t->x + t->w);
  69604. }
  69605. return maxW;
  69606. }
  69607. int TextLayout::getHeight() const
  69608. {
  69609. int maxH = 0;
  69610. for (int i = tokens.size(); --i >= 0;)
  69611. {
  69612. const Token* const t = tokens.getUnchecked(i);
  69613. if (! t->isWhitespace)
  69614. maxH = jmax (maxH, t->y + t->h);
  69615. }
  69616. return maxH;
  69617. }
  69618. void TextLayout::draw (Graphics& g,
  69619. const int xOffset,
  69620. const int yOffset) const
  69621. {
  69622. for (int i = tokens.size(); --i >= 0;)
  69623. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69624. }
  69625. void TextLayout::drawWithin (Graphics& g,
  69626. int x, int y, int w, int h,
  69627. const Justification& justification) const
  69628. {
  69629. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69630. x, y, w, h);
  69631. draw (g, x, y);
  69632. }
  69633. END_JUCE_NAMESPACE
  69634. /*** End of inlined file: juce_TextLayout.cpp ***/
  69635. /*** Start of inlined file: juce_Typeface.cpp ***/
  69636. BEGIN_JUCE_NAMESPACE
  69637. Typeface::Typeface (const String& name_) throw()
  69638. : name (name_)
  69639. {
  69640. }
  69641. Typeface::~Typeface()
  69642. {
  69643. }
  69644. class CustomTypeface::GlyphInfo
  69645. {
  69646. public:
  69647. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69648. : character (character_), path (path_), width (width_)
  69649. {
  69650. }
  69651. ~GlyphInfo() throw()
  69652. {
  69653. }
  69654. struct KerningPair
  69655. {
  69656. juce_wchar character2;
  69657. float kerningAmount;
  69658. };
  69659. void addKerningPair (const juce_wchar subsequentCharacter,
  69660. const float extraKerningAmount) throw()
  69661. {
  69662. KerningPair kp;
  69663. kp.character2 = subsequentCharacter;
  69664. kp.kerningAmount = extraKerningAmount;
  69665. kerningPairs.add (kp);
  69666. }
  69667. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69668. {
  69669. if (subsequentCharacter != 0)
  69670. {
  69671. for (int i = kerningPairs.size(); --i >= 0;)
  69672. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69673. return width + kerningPairs.getReference(i).kerningAmount;
  69674. }
  69675. return width;
  69676. }
  69677. const juce_wchar character;
  69678. const Path path;
  69679. float width;
  69680. Array <KerningPair> kerningPairs;
  69681. juce_UseDebuggingNewOperator
  69682. private:
  69683. GlyphInfo (const GlyphInfo&);
  69684. GlyphInfo& operator= (const GlyphInfo&);
  69685. };
  69686. CustomTypeface::CustomTypeface()
  69687. : Typeface (String::empty)
  69688. {
  69689. clear();
  69690. }
  69691. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  69692. : Typeface (String::empty)
  69693. {
  69694. clear();
  69695. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  69696. BufferedInputStream in (&gzin, 32768, false);
  69697. name = in.readString();
  69698. isBold = in.readBool();
  69699. isItalic = in.readBool();
  69700. ascent = in.readFloat();
  69701. defaultCharacter = (juce_wchar) in.readShort();
  69702. int i, numChars = in.readInt();
  69703. for (i = 0; i < numChars; ++i)
  69704. {
  69705. const juce_wchar c = (juce_wchar) in.readShort();
  69706. const float width = in.readFloat();
  69707. Path p;
  69708. p.loadPathFromStream (in);
  69709. addGlyph (c, p, width);
  69710. }
  69711. const int numKerningPairs = in.readInt();
  69712. for (i = 0; i < numKerningPairs; ++i)
  69713. {
  69714. const juce_wchar char1 = (juce_wchar) in.readShort();
  69715. const juce_wchar char2 = (juce_wchar) in.readShort();
  69716. addKerningPair (char1, char2, in.readFloat());
  69717. }
  69718. }
  69719. CustomTypeface::~CustomTypeface()
  69720. {
  69721. }
  69722. void CustomTypeface::clear()
  69723. {
  69724. defaultCharacter = 0;
  69725. ascent = 1.0f;
  69726. isBold = isItalic = false;
  69727. zeromem (lookupTable, sizeof (lookupTable));
  69728. glyphs.clear();
  69729. }
  69730. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  69731. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  69732. {
  69733. name = name_;
  69734. defaultCharacter = defaultCharacter_;
  69735. ascent = ascent_;
  69736. isBold = isBold_;
  69737. isItalic = isItalic_;
  69738. }
  69739. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  69740. {
  69741. // Check that you're not trying to add the same character twice..
  69742. jassert (findGlyph (character, false) == 0);
  69743. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  69744. lookupTable [character] = (short) glyphs.size();
  69745. glyphs.add (new GlyphInfo (character, path, width));
  69746. }
  69747. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  69748. {
  69749. if (extraAmount != 0)
  69750. {
  69751. GlyphInfo* const g = findGlyph (char1, true);
  69752. jassert (g != 0); // can only add kerning pairs for characters that exist!
  69753. if (g != 0)
  69754. g->addKerningPair (char2, extraAmount);
  69755. }
  69756. }
  69757. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  69758. {
  69759. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  69760. return glyphs [(int) lookupTable [(int) character]];
  69761. for (int i = 0; i < glyphs.size(); ++i)
  69762. {
  69763. GlyphInfo* const g = glyphs.getUnchecked(i);
  69764. if (g->character == character)
  69765. return g;
  69766. }
  69767. if (loadIfNeeded && loadGlyphIfPossible (character))
  69768. return findGlyph (character, false);
  69769. return 0;
  69770. }
  69771. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  69772. {
  69773. GlyphInfo* glyph = findGlyph (character, true);
  69774. if (glyph == 0)
  69775. {
  69776. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  69777. glyph = findGlyph (L' ', true);
  69778. if (glyph == 0)
  69779. {
  69780. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  69781. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  69782. if (fallbackTypeface != 0 && fallbackTypeface != this)
  69783. {
  69784. //xxx
  69785. }
  69786. if (glyph == 0)
  69787. glyph = findGlyph (defaultCharacter, true);
  69788. }
  69789. }
  69790. return glyph;
  69791. }
  69792. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  69793. {
  69794. return false;
  69795. }
  69796. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  69797. {
  69798. setCharacteristics (name, typefaceToCopy.getAscent(), isBold, isItalic, defaultCharacter);
  69799. for (int i = 0; i < numCharacters; ++i)
  69800. {
  69801. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  69802. Array <int> glyphIndexes;
  69803. Array <float> offsets;
  69804. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  69805. const int glyphIndex = glyphIndexes.getFirst();
  69806. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  69807. {
  69808. const float glyphWidth = offsets[1];
  69809. Path p;
  69810. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  69811. addGlyph (c, p, glyphWidth);
  69812. for (int j = glyphs.size() - 1; --j >= 0;)
  69813. {
  69814. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  69815. glyphIndexes.clearQuick();
  69816. offsets.clearQuick();
  69817. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  69818. if (offsets.size() > 1)
  69819. addKerningPair (c, char2, offsets[1] - glyphWidth);
  69820. }
  69821. }
  69822. }
  69823. }
  69824. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  69825. {
  69826. GZIPCompressorOutputStream out (&outputStream);
  69827. out.writeString (name);
  69828. out.writeBool (isBold);
  69829. out.writeBool (isItalic);
  69830. out.writeFloat (ascent);
  69831. out.writeShort ((short) (unsigned short) defaultCharacter);
  69832. out.writeInt (glyphs.size());
  69833. int i, numKerningPairs = 0;
  69834. for (i = 0; i < glyphs.size(); ++i)
  69835. {
  69836. const GlyphInfo* const g = glyphs.getUnchecked (i);
  69837. out.writeShort ((short) (unsigned short) g->character);
  69838. out.writeFloat (g->width);
  69839. g->path.writePathToStream (out);
  69840. numKerningPairs += g->kerningPairs.size();
  69841. }
  69842. out.writeInt (numKerningPairs);
  69843. for (i = 0; i < glyphs.size(); ++i)
  69844. {
  69845. const GlyphInfo* const g = glyphs.getUnchecked (i);
  69846. for (int j = 0; j < g->kerningPairs.size(); ++j)
  69847. {
  69848. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  69849. out.writeShort ((short) (unsigned short) g->character);
  69850. out.writeShort ((short) (unsigned short) p.character2);
  69851. out.writeFloat (p.kerningAmount);
  69852. }
  69853. }
  69854. return true;
  69855. }
  69856. float CustomTypeface::getAscent() const
  69857. {
  69858. return ascent;
  69859. }
  69860. float CustomTypeface::getDescent() const
  69861. {
  69862. return 1.0f - ascent;
  69863. }
  69864. float CustomTypeface::getStringWidth (const String& text)
  69865. {
  69866. float x = 0;
  69867. const juce_wchar* t = text;
  69868. while (*t != 0)
  69869. {
  69870. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  69871. if (glyph != 0)
  69872. x += glyph->getHorizontalSpacing (*t);
  69873. }
  69874. return x;
  69875. }
  69876. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  69877. {
  69878. xOffsets.add (0);
  69879. float x = 0;
  69880. const juce_wchar* t = text;
  69881. while (*t != 0)
  69882. {
  69883. const juce_wchar c = *t++;
  69884. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  69885. if (glyph != 0)
  69886. {
  69887. x += glyph->getHorizontalSpacing (*t);
  69888. resultGlyphs.add ((int) glyph->character);
  69889. xOffsets.add (x);
  69890. }
  69891. }
  69892. }
  69893. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  69894. {
  69895. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  69896. if (glyph != 0)
  69897. {
  69898. path = glyph->path;
  69899. return true;
  69900. }
  69901. return false;
  69902. }
  69903. END_JUCE_NAMESPACE
  69904. /*** End of inlined file: juce_Typeface.cpp ***/
  69905. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  69906. BEGIN_JUCE_NAMESPACE
  69907. AffineTransform::AffineTransform() throw()
  69908. : mat00 (1.0f),
  69909. mat01 (0),
  69910. mat02 (0),
  69911. mat10 (0),
  69912. mat11 (1.0f),
  69913. mat12 (0)
  69914. {
  69915. }
  69916. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  69917. : mat00 (other.mat00),
  69918. mat01 (other.mat01),
  69919. mat02 (other.mat02),
  69920. mat10 (other.mat10),
  69921. mat11 (other.mat11),
  69922. mat12 (other.mat12)
  69923. {
  69924. }
  69925. AffineTransform::AffineTransform (const float mat00_,
  69926. const float mat01_,
  69927. const float mat02_,
  69928. const float mat10_,
  69929. const float mat11_,
  69930. const float mat12_) throw()
  69931. : mat00 (mat00_),
  69932. mat01 (mat01_),
  69933. mat02 (mat02_),
  69934. mat10 (mat10_),
  69935. mat11 (mat11_),
  69936. mat12 (mat12_)
  69937. {
  69938. }
  69939. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  69940. {
  69941. mat00 = other.mat00;
  69942. mat01 = other.mat01;
  69943. mat02 = other.mat02;
  69944. mat10 = other.mat10;
  69945. mat11 = other.mat11;
  69946. mat12 = other.mat12;
  69947. return *this;
  69948. }
  69949. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  69950. {
  69951. return mat00 == other.mat00
  69952. && mat01 == other.mat01
  69953. && mat02 == other.mat02
  69954. && mat10 == other.mat10
  69955. && mat11 == other.mat11
  69956. && mat12 == other.mat12;
  69957. }
  69958. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  69959. {
  69960. return ! operator== (other);
  69961. }
  69962. bool AffineTransform::isIdentity() const throw()
  69963. {
  69964. return (mat01 == 0)
  69965. && (mat02 == 0)
  69966. && (mat10 == 0)
  69967. && (mat12 == 0)
  69968. && (mat00 == 1.0f)
  69969. && (mat11 == 1.0f);
  69970. }
  69971. const AffineTransform AffineTransform::identity;
  69972. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  69973. {
  69974. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  69975. other.mat00 * mat01 + other.mat01 * mat11,
  69976. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  69977. other.mat10 * mat00 + other.mat11 * mat10,
  69978. other.mat10 * mat01 + other.mat11 * mat11,
  69979. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  69980. }
  69981. const AffineTransform AffineTransform::followedBy (const float omat00,
  69982. const float omat01,
  69983. const float omat02,
  69984. const float omat10,
  69985. const float omat11,
  69986. const float omat12) const throw()
  69987. {
  69988. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  69989. omat00 * mat01 + omat01 * mat11,
  69990. omat00 * mat02 + omat01 * mat12 + omat02,
  69991. omat10 * mat00 + omat11 * mat10,
  69992. omat10 * mat01 + omat11 * mat11,
  69993. omat10 * mat02 + omat11 * mat12 + omat12);
  69994. }
  69995. const AffineTransform AffineTransform::translated (const float dx,
  69996. const float dy) const throw()
  69997. {
  69998. return AffineTransform (mat00, mat01, mat02 + dx,
  69999. mat10, mat11, mat12 + dy);
  70000. }
  70001. const AffineTransform AffineTransform::translation (const float dx,
  70002. const float dy) throw()
  70003. {
  70004. return AffineTransform (1.0f, 0, dx,
  70005. 0, 1.0f, dy);
  70006. }
  70007. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70008. {
  70009. const float cosRad = cosf (rad);
  70010. const float sinRad = sinf (rad);
  70011. return followedBy (cosRad, -sinRad, 0,
  70012. sinRad, cosRad, 0);
  70013. }
  70014. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70015. {
  70016. const float cosRad = cosf (rad);
  70017. const float sinRad = sinf (rad);
  70018. return AffineTransform (cosRad, -sinRad, 0,
  70019. sinRad, cosRad, 0);
  70020. }
  70021. const AffineTransform AffineTransform::rotated (const float angle,
  70022. const float pivotX,
  70023. const float pivotY) const throw()
  70024. {
  70025. return translated (-pivotX, -pivotY)
  70026. .rotated (angle)
  70027. .translated (pivotX, pivotY);
  70028. }
  70029. const AffineTransform AffineTransform::rotation (const float angle,
  70030. const float pivotX,
  70031. const float pivotY) throw()
  70032. {
  70033. return translation (-pivotX, -pivotY)
  70034. .rotated (angle)
  70035. .translated (pivotX, pivotY);
  70036. }
  70037. const AffineTransform AffineTransform::scaled (const float factorX,
  70038. const float factorY) const throw()
  70039. {
  70040. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70041. factorY * mat10, factorY * mat11, factorY * mat12);
  70042. }
  70043. const AffineTransform AffineTransform::scale (const float factorX,
  70044. const float factorY) throw()
  70045. {
  70046. return AffineTransform (factorX, 0, 0,
  70047. 0, factorY, 0);
  70048. }
  70049. const AffineTransform AffineTransform::sheared (const float shearX,
  70050. const float shearY) const throw()
  70051. {
  70052. return followedBy (1.0f, shearX, 0,
  70053. shearY, 1.0f, 0);
  70054. }
  70055. const AffineTransform AffineTransform::inverted() const throw()
  70056. {
  70057. double determinant = (mat00 * mat11 - mat10 * mat01);
  70058. if (determinant != 0.0)
  70059. {
  70060. determinant = 1.0 / determinant;
  70061. const float dst00 = (float) (mat11 * determinant);
  70062. const float dst10 = (float) (-mat10 * determinant);
  70063. const float dst01 = (float) (-mat01 * determinant);
  70064. const float dst11 = (float) (mat00 * determinant);
  70065. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70066. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70067. }
  70068. else
  70069. {
  70070. // singularity..
  70071. return *this;
  70072. }
  70073. }
  70074. bool AffineTransform::isSingularity() const throw()
  70075. {
  70076. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70077. }
  70078. bool AffineTransform::isOnlyTranslation() const throw()
  70079. {
  70080. return (mat01 == 0)
  70081. && (mat10 == 0)
  70082. && (mat00 == 1.0f)
  70083. && (mat11 == 1.0f);
  70084. }
  70085. void AffineTransform::transformPoint (float& x,
  70086. float& y) const throw()
  70087. {
  70088. const float oldX = x;
  70089. x = mat00 * oldX + mat01 * y + mat02;
  70090. y = mat10 * oldX + mat11 * y + mat12;
  70091. }
  70092. void AffineTransform::transformPoint (double& x,
  70093. double& y) const throw()
  70094. {
  70095. const double oldX = x;
  70096. x = mat00 * oldX + mat01 * y + mat02;
  70097. y = mat10 * oldX + mat11 * y + mat12;
  70098. }
  70099. END_JUCE_NAMESPACE
  70100. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70101. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70102. BEGIN_JUCE_NAMESPACE
  70103. BorderSize::BorderSize() throw()
  70104. : top (0),
  70105. left (0),
  70106. bottom (0),
  70107. right (0)
  70108. {
  70109. }
  70110. BorderSize::BorderSize (const BorderSize& other) throw()
  70111. : top (other.top),
  70112. left (other.left),
  70113. bottom (other.bottom),
  70114. right (other.right)
  70115. {
  70116. }
  70117. BorderSize::BorderSize (const int topGap,
  70118. const int leftGap,
  70119. const int bottomGap,
  70120. const int rightGap) throw()
  70121. : top (topGap),
  70122. left (leftGap),
  70123. bottom (bottomGap),
  70124. right (rightGap)
  70125. {
  70126. }
  70127. BorderSize::BorderSize (const int allGaps) throw()
  70128. : top (allGaps),
  70129. left (allGaps),
  70130. bottom (allGaps),
  70131. right (allGaps)
  70132. {
  70133. }
  70134. BorderSize::~BorderSize() throw()
  70135. {
  70136. }
  70137. void BorderSize::setTop (const int newTopGap) throw()
  70138. {
  70139. top = newTopGap;
  70140. }
  70141. void BorderSize::setLeft (const int newLeftGap) throw()
  70142. {
  70143. left = newLeftGap;
  70144. }
  70145. void BorderSize::setBottom (const int newBottomGap) throw()
  70146. {
  70147. bottom = newBottomGap;
  70148. }
  70149. void BorderSize::setRight (const int newRightGap) throw()
  70150. {
  70151. right = newRightGap;
  70152. }
  70153. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70154. {
  70155. return Rectangle<int> (r.getX() + left,
  70156. r.getY() + top,
  70157. r.getWidth() - (left + right),
  70158. r.getHeight() - (top + bottom));
  70159. }
  70160. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70161. {
  70162. r.setBounds (r.getX() + left,
  70163. r.getY() + top,
  70164. r.getWidth() - (left + right),
  70165. r.getHeight() - (top + bottom));
  70166. }
  70167. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70168. {
  70169. return Rectangle<int> (r.getX() - left,
  70170. r.getY() - top,
  70171. r.getWidth() + (left + right),
  70172. r.getHeight() + (top + bottom));
  70173. }
  70174. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70175. {
  70176. r.setBounds (r.getX() - left,
  70177. r.getY() - top,
  70178. r.getWidth() + (left + right),
  70179. r.getHeight() + (top + bottom));
  70180. }
  70181. bool BorderSize::operator== (const BorderSize& other) const throw()
  70182. {
  70183. return top == other.top
  70184. && left == other.left
  70185. && bottom == other.bottom
  70186. && right == other.right;
  70187. }
  70188. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70189. {
  70190. return ! operator== (other);
  70191. }
  70192. END_JUCE_NAMESPACE
  70193. /*** End of inlined file: juce_BorderSize.cpp ***/
  70194. /*** Start of inlined file: juce_Line.cpp ***/
  70195. BEGIN_JUCE_NAMESPACE
  70196. static bool juce_lineIntersection (const float x1, const float y1,
  70197. const float x2, const float y2,
  70198. const float x3, const float y3,
  70199. const float x4, const float y4,
  70200. float& intersectionX,
  70201. float& intersectionY) throw()
  70202. {
  70203. if (x2 != x3 || y2 != y3)
  70204. {
  70205. const float dx1 = x2 - x1;
  70206. const float dy1 = y2 - y1;
  70207. const float dx2 = x4 - x3;
  70208. const float dy2 = y4 - y3;
  70209. const float divisor = dx1 * dy2 - dx2 * dy1;
  70210. if (divisor == 0)
  70211. {
  70212. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70213. {
  70214. if (dy1 == 0 && dy2 != 0)
  70215. {
  70216. const float along = (y1 - y3) / dy2;
  70217. intersectionX = x3 + along * dx2;
  70218. intersectionY = y1;
  70219. return along >= 0 && along <= 1.0f;
  70220. }
  70221. else if (dy2 == 0 && dy1 != 0)
  70222. {
  70223. const float along = (y3 - y1) / dy1;
  70224. intersectionX = x1 + along * dx1;
  70225. intersectionY = y3;
  70226. return along >= 0 && along <= 1.0f;
  70227. }
  70228. else if (dx1 == 0 && dx2 != 0)
  70229. {
  70230. const float along = (x1 - x3) / dx2;
  70231. intersectionX = x1;
  70232. intersectionY = y3 + along * dy2;
  70233. return along >= 0 && along <= 1.0f;
  70234. }
  70235. else if (dx2 == 0 && dx1 != 0)
  70236. {
  70237. const float along = (x3 - x1) / dx1;
  70238. intersectionX = x3;
  70239. intersectionY = y1 + along * dy1;
  70240. return along >= 0 && along <= 1.0f;
  70241. }
  70242. }
  70243. intersectionX = 0.5f * (x2 + x3);
  70244. intersectionY = 0.5f * (y2 + y3);
  70245. return false;
  70246. }
  70247. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70248. intersectionX = x1 + along1 * dx1;
  70249. intersectionY = y1 + along1 * dy1;
  70250. if (along1 < 0 || along1 > 1.0f)
  70251. return false;
  70252. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70253. return along2 >= 0 && along2 <= 1.0f;
  70254. }
  70255. intersectionX = x2;
  70256. intersectionY = y2;
  70257. return true;
  70258. }
  70259. Line::Line() throw()
  70260. : startX (0.0f),
  70261. startY (0.0f),
  70262. endX (0.0f),
  70263. endY (0.0f)
  70264. {
  70265. }
  70266. Line::Line (const Line& other) throw()
  70267. : startX (other.startX),
  70268. startY (other.startY),
  70269. endX (other.endX),
  70270. endY (other.endY)
  70271. {
  70272. }
  70273. Line::Line (const float startX_, const float startY_,
  70274. const float endX_, const float endY_) throw()
  70275. : startX (startX_),
  70276. startY (startY_),
  70277. endX (endX_),
  70278. endY (endY_)
  70279. {
  70280. }
  70281. Line::Line (const Point<float>& start,
  70282. const Point<float>& end) throw()
  70283. : startX (start.getX()),
  70284. startY (start.getY()),
  70285. endX (end.getX()),
  70286. endY (end.getY())
  70287. {
  70288. }
  70289. Line& Line::operator= (const Line& other) throw()
  70290. {
  70291. startX = other.startX;
  70292. startY = other.startY;
  70293. endX = other.endX;
  70294. endY = other.endY;
  70295. return *this;
  70296. }
  70297. Line::~Line() throw()
  70298. {
  70299. }
  70300. const Point<float> Line::getStart() const throw()
  70301. {
  70302. return Point<float> (startX, startY);
  70303. }
  70304. const Point<float> Line::getEnd() const throw()
  70305. {
  70306. return Point<float> (endX, endY);
  70307. }
  70308. void Line::setStart (const float newStartX,
  70309. const float newStartY) throw()
  70310. {
  70311. startX = newStartX;
  70312. startY = newStartY;
  70313. }
  70314. void Line::setStart (const Point<float>& newStart) throw()
  70315. {
  70316. startX = newStart.getX();
  70317. startY = newStart.getY();
  70318. }
  70319. void Line::setEnd (const float newEndX,
  70320. const float newEndY) throw()
  70321. {
  70322. endX = newEndX;
  70323. endY = newEndY;
  70324. }
  70325. void Line::setEnd (const Point<float>& newEnd) throw()
  70326. {
  70327. endX = newEnd.getX();
  70328. endY = newEnd.getY();
  70329. }
  70330. bool Line::operator== (const Line& other) const throw()
  70331. {
  70332. return startX == other.startX
  70333. && startY == other.startY
  70334. && endX == other.endX
  70335. && endY == other.endY;
  70336. }
  70337. bool Line::operator!= (const Line& other) const throw()
  70338. {
  70339. return startX != other.startX
  70340. || startY != other.startY
  70341. || endX != other.endX
  70342. || endY != other.endY;
  70343. }
  70344. void Line::applyTransform (const AffineTransform& transform) throw()
  70345. {
  70346. transform.transformPoint (startX, startY);
  70347. transform.transformPoint (endX, endY);
  70348. }
  70349. float Line::getLength() const throw()
  70350. {
  70351. return (float) juce_hypot (startX - endX,
  70352. startY - endY);
  70353. }
  70354. float Line::getAngle() const throw()
  70355. {
  70356. return atan2f (endX - startX,
  70357. endY - startY);
  70358. }
  70359. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70360. {
  70361. const float alpha = distanceFromStart / getLength();
  70362. return Point<float> (startX + (endX - startX) * alpha,
  70363. startY + (endY - startY) * alpha);
  70364. }
  70365. const Point<float> Line::getPointAlongLine (const float offsetX,
  70366. const float offsetY) const throw()
  70367. {
  70368. const float dx = endX - startX;
  70369. const float dy = endY - startY;
  70370. const double length = juce_hypot (dx, dy);
  70371. if (length == 0)
  70372. return Point<float> (startX, startY);
  70373. else
  70374. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70375. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70376. }
  70377. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70378. {
  70379. return Point<float> (startX + (endX - startX) * alpha,
  70380. startY + (endY - startY) * alpha);
  70381. }
  70382. float Line::getDistanceFromLine (const float x,
  70383. const float y) const throw()
  70384. {
  70385. const double dx = endX - startX;
  70386. const double dy = endY - startY;
  70387. const double length = dx * dx + dy * dy;
  70388. if (length > 0)
  70389. {
  70390. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70391. if (prop >= 0.0f && prop < 1.0f)
  70392. {
  70393. return (float) juce_hypot (x - (startX + prop * dx),
  70394. y - (startY + prop * dy));
  70395. }
  70396. }
  70397. return (float) jmin (juce_hypot (x - startX, y - startY),
  70398. juce_hypot (x - endX, y - endY));
  70399. }
  70400. float Line::findNearestPointTo (const float x,
  70401. const float y) const throw()
  70402. {
  70403. const double dx = endX - startX;
  70404. const double dy = endY - startY;
  70405. const double length = dx * dx + dy * dy;
  70406. if (length <= 0.0)
  70407. return 0.0f;
  70408. return jlimit (0.0f, 1.0f,
  70409. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70410. }
  70411. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70412. {
  70413. const float length = getLength();
  70414. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70415. getEnd());
  70416. }
  70417. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70418. {
  70419. const float length = getLength();
  70420. return Line (getStart(),
  70421. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70422. }
  70423. bool Line::clipToPath (const Path& path,
  70424. const bool keepSectionOutsidePath) throw()
  70425. {
  70426. const bool startInside = path.contains (startX, startY);
  70427. const bool endInside = path.contains (endX, endY);
  70428. if (startInside == endInside)
  70429. {
  70430. if (keepSectionOutsidePath != startInside)
  70431. {
  70432. // entirely outside the path
  70433. return false;
  70434. }
  70435. else
  70436. {
  70437. // entirely inside the path
  70438. startX = 0.0f;
  70439. startY = 0.0f;
  70440. endX = 0.0f;
  70441. endY = 0.0f;
  70442. return true;
  70443. }
  70444. }
  70445. else
  70446. {
  70447. bool changed = false;
  70448. PathFlatteningIterator iter (path, AffineTransform::identity);
  70449. while (iter.next())
  70450. {
  70451. float ix, iy;
  70452. if (intersects (Line (iter.x1, iter.y1,
  70453. iter.x2, iter.y2),
  70454. ix, iy))
  70455. {
  70456. if ((startInside && keepSectionOutsidePath)
  70457. || (endInside && ! keepSectionOutsidePath))
  70458. {
  70459. setStart (ix, iy);
  70460. }
  70461. else
  70462. {
  70463. setEnd (ix, iy);
  70464. }
  70465. changed = true;
  70466. }
  70467. }
  70468. return changed;
  70469. }
  70470. }
  70471. bool Line::intersects (const Line& line,
  70472. float& intersectionX,
  70473. float& intersectionY) const throw()
  70474. {
  70475. return juce_lineIntersection (startX, startY,
  70476. endX, endY,
  70477. line.startX, line.startY,
  70478. line.endX, line.endY,
  70479. intersectionX,
  70480. intersectionY);
  70481. }
  70482. bool Line::isVertical() const throw()
  70483. {
  70484. return startX == endX;
  70485. }
  70486. bool Line::isHorizontal() const throw()
  70487. {
  70488. return startY == endY;
  70489. }
  70490. bool Line::isPointAbove (const float x, const float y) const throw()
  70491. {
  70492. return startX != endX
  70493. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70494. }
  70495. END_JUCE_NAMESPACE
  70496. /*** End of inlined file: juce_Line.cpp ***/
  70497. /*** Start of inlined file: juce_Path.cpp ***/
  70498. BEGIN_JUCE_NAMESPACE
  70499. // tests that some co-ords aren't NaNs
  70500. #define CHECK_COORDS_ARE_VALID(x, y) \
  70501. jassert (x == x && y == y);
  70502. namespace PathHelpers
  70503. {
  70504. static const float ellipseAngularIncrement = 0.05f;
  70505. static void perpendicularOffset (const float x1, const float y1,
  70506. const float x2, const float y2,
  70507. const float offsetX, const float offsetY,
  70508. float& resultX, float& resultY) throw()
  70509. {
  70510. const float dx = x2 - x1;
  70511. const float dy = y2 - y1;
  70512. const float len = juce_hypotf (dx, dy);
  70513. if (len == 0)
  70514. {
  70515. resultX = x1;
  70516. resultY = y1;
  70517. }
  70518. else
  70519. {
  70520. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  70521. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  70522. }
  70523. }
  70524. static const String nextToken (const juce_wchar*& t)
  70525. {
  70526. while (CharacterFunctions::isWhitespace (*t))
  70527. ++t;
  70528. const juce_wchar* const start = t;
  70529. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  70530. ++t;
  70531. const int length = (int) (t - start);
  70532. while (CharacterFunctions::isWhitespace (*t))
  70533. ++t;
  70534. return String (start, length);
  70535. }
  70536. }
  70537. const float Path::lineMarker = 100001.0f;
  70538. const float Path::moveMarker = 100002.0f;
  70539. const float Path::quadMarker = 100003.0f;
  70540. const float Path::cubicMarker = 100004.0f;
  70541. const float Path::closeSubPathMarker = 100005.0f;
  70542. Path::Path()
  70543. : numElements (0),
  70544. pathXMin (0),
  70545. pathXMax (0),
  70546. pathYMin (0),
  70547. pathYMax (0),
  70548. useNonZeroWinding (true)
  70549. {
  70550. }
  70551. Path::~Path()
  70552. {
  70553. }
  70554. Path::Path (const Path& other)
  70555. : numElements (other.numElements),
  70556. pathXMin (other.pathXMin),
  70557. pathXMax (other.pathXMax),
  70558. pathYMin (other.pathYMin),
  70559. pathYMax (other.pathYMax),
  70560. useNonZeroWinding (other.useNonZeroWinding)
  70561. {
  70562. if (numElements > 0)
  70563. {
  70564. data.setAllocatedSize ((int) numElements);
  70565. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70566. }
  70567. }
  70568. Path& Path::operator= (const Path& other)
  70569. {
  70570. if (this != &other)
  70571. {
  70572. data.ensureAllocatedSize ((int) other.numElements);
  70573. numElements = other.numElements;
  70574. pathXMin = other.pathXMin;
  70575. pathXMax = other.pathXMax;
  70576. pathYMin = other.pathYMin;
  70577. pathYMax = other.pathYMax;
  70578. useNonZeroWinding = other.useNonZeroWinding;
  70579. if (numElements > 0)
  70580. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70581. }
  70582. return *this;
  70583. }
  70584. void Path::clear() throw()
  70585. {
  70586. numElements = 0;
  70587. pathXMin = 0;
  70588. pathYMin = 0;
  70589. pathYMax = 0;
  70590. pathXMax = 0;
  70591. }
  70592. void Path::swapWithPath (Path& other)
  70593. {
  70594. data.swapWith (other.data);
  70595. swapVariables <size_t> (numElements, other.numElements);
  70596. swapVariables <float> (pathXMin, other.pathXMin);
  70597. swapVariables <float> (pathXMax, other.pathXMax);
  70598. swapVariables <float> (pathYMin, other.pathYMin);
  70599. swapVariables <float> (pathYMax, other.pathYMax);
  70600. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70601. }
  70602. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70603. {
  70604. useNonZeroWinding = isNonZero;
  70605. }
  70606. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70607. const bool preserveProportions) throw()
  70608. {
  70609. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70610. }
  70611. bool Path::isEmpty() const throw()
  70612. {
  70613. size_t i = 0;
  70614. while (i < numElements)
  70615. {
  70616. const float type = data.elements [i++];
  70617. if (type == moveMarker)
  70618. {
  70619. i += 2;
  70620. }
  70621. else if (type == lineMarker
  70622. || type == quadMarker
  70623. || type == cubicMarker)
  70624. {
  70625. return false;
  70626. }
  70627. }
  70628. return true;
  70629. }
  70630. const Rectangle<float> Path::getBounds() const throw()
  70631. {
  70632. return Rectangle<float> (pathXMin, pathYMin,
  70633. pathXMax - pathXMin,
  70634. pathYMax - pathYMin);
  70635. }
  70636. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70637. {
  70638. return getBounds().transformed (transform);
  70639. }
  70640. void Path::startNewSubPath (const float x, const float y)
  70641. {
  70642. CHECK_COORDS_ARE_VALID (x, y);
  70643. if (numElements == 0)
  70644. {
  70645. pathXMin = pathXMax = x;
  70646. pathYMin = pathYMax = y;
  70647. }
  70648. else
  70649. {
  70650. pathXMin = jmin (pathXMin, x);
  70651. pathXMax = jmax (pathXMax, x);
  70652. pathYMin = jmin (pathYMin, y);
  70653. pathYMax = jmax (pathYMax, y);
  70654. }
  70655. data.ensureAllocatedSize ((int) numElements + 3);
  70656. data.elements [numElements++] = moveMarker;
  70657. data.elements [numElements++] = x;
  70658. data.elements [numElements++] = y;
  70659. }
  70660. void Path::lineTo (const float x, const float y)
  70661. {
  70662. CHECK_COORDS_ARE_VALID (x, y);
  70663. if (numElements == 0)
  70664. startNewSubPath (0, 0);
  70665. data.ensureAllocatedSize ((int) numElements + 3);
  70666. data.elements [numElements++] = lineMarker;
  70667. data.elements [numElements++] = x;
  70668. data.elements [numElements++] = y;
  70669. pathXMin = jmin (pathXMin, x);
  70670. pathXMax = jmax (pathXMax, x);
  70671. pathYMin = jmin (pathYMin, y);
  70672. pathYMax = jmax (pathYMax, y);
  70673. }
  70674. void Path::quadraticTo (const float x1, const float y1,
  70675. const float x2, const float y2)
  70676. {
  70677. CHECK_COORDS_ARE_VALID (x1, y1);
  70678. CHECK_COORDS_ARE_VALID (x2, y2);
  70679. if (numElements == 0)
  70680. startNewSubPath (0, 0);
  70681. data.ensureAllocatedSize ((int) numElements + 5);
  70682. data.elements [numElements++] = quadMarker;
  70683. data.elements [numElements++] = x1;
  70684. data.elements [numElements++] = y1;
  70685. data.elements [numElements++] = x2;
  70686. data.elements [numElements++] = y2;
  70687. pathXMin = jmin (pathXMin, x1, x2);
  70688. pathXMax = jmax (pathXMax, x1, x2);
  70689. pathYMin = jmin (pathYMin, y1, y2);
  70690. pathYMax = jmax (pathYMax, y1, y2);
  70691. }
  70692. void Path::cubicTo (const float x1, const float y1,
  70693. const float x2, const float y2,
  70694. const float x3, const float y3)
  70695. {
  70696. CHECK_COORDS_ARE_VALID (x1, y1);
  70697. CHECK_COORDS_ARE_VALID (x2, y2);
  70698. CHECK_COORDS_ARE_VALID (x3, y3);
  70699. if (numElements == 0)
  70700. startNewSubPath (0, 0);
  70701. data.ensureAllocatedSize ((int) numElements + 7);
  70702. data.elements [numElements++] = cubicMarker;
  70703. data.elements [numElements++] = x1;
  70704. data.elements [numElements++] = y1;
  70705. data.elements [numElements++] = x2;
  70706. data.elements [numElements++] = y2;
  70707. data.elements [numElements++] = x3;
  70708. data.elements [numElements++] = y3;
  70709. pathXMin = jmin (pathXMin, x1, x2, x3);
  70710. pathXMax = jmax (pathXMax, x1, x2, x3);
  70711. pathYMin = jmin (pathYMin, y1, y2, y3);
  70712. pathYMax = jmax (pathYMax, y1, y2, y3);
  70713. }
  70714. void Path::closeSubPath()
  70715. {
  70716. if (numElements > 0
  70717. && data.elements [numElements - 1] != closeSubPathMarker)
  70718. {
  70719. data.ensureAllocatedSize ((int) numElements + 1);
  70720. data.elements [numElements++] = closeSubPathMarker;
  70721. }
  70722. }
  70723. const Point<float> Path::getCurrentPosition() const
  70724. {
  70725. size_t i = numElements - 1;
  70726. if (i > 0 && data.elements[i] == closeSubPathMarker)
  70727. {
  70728. while (i >= 0)
  70729. {
  70730. if (data.elements[i] == moveMarker)
  70731. {
  70732. i += 2;
  70733. break;
  70734. }
  70735. --i;
  70736. }
  70737. }
  70738. if (i > 0)
  70739. return Point<float> (data.elements [i - 1], data.elements [i]);
  70740. return Point<float>();
  70741. }
  70742. void Path::addRectangle (const float x, const float y,
  70743. const float w, const float h)
  70744. {
  70745. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  70746. if (w < 0)
  70747. swapVariables (x1, x2);
  70748. if (h < 0)
  70749. swapVariables (y1, y2);
  70750. data.ensureAllocatedSize ((int) numElements + 13);
  70751. if (numElements == 0)
  70752. {
  70753. pathXMin = x1;
  70754. pathXMax = x2;
  70755. pathYMin = y1;
  70756. pathYMax = y2;
  70757. }
  70758. else
  70759. {
  70760. pathXMin = jmin (pathXMin, x1);
  70761. pathXMax = jmax (pathXMax, x2);
  70762. pathYMin = jmin (pathYMin, y1);
  70763. pathYMax = jmax (pathYMax, y2);
  70764. }
  70765. data.elements [numElements++] = moveMarker;
  70766. data.elements [numElements++] = x1;
  70767. data.elements [numElements++] = y2;
  70768. data.elements [numElements++] = lineMarker;
  70769. data.elements [numElements++] = x1;
  70770. data.elements [numElements++] = y1;
  70771. data.elements [numElements++] = lineMarker;
  70772. data.elements [numElements++] = x2;
  70773. data.elements [numElements++] = y1;
  70774. data.elements [numElements++] = lineMarker;
  70775. data.elements [numElements++] = x2;
  70776. data.elements [numElements++] = y2;
  70777. data.elements [numElements++] = closeSubPathMarker;
  70778. }
  70779. void Path::addRectangle (const Rectangle<int>& rectangle)
  70780. {
  70781. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  70782. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  70783. }
  70784. void Path::addRoundedRectangle (const float x, const float y,
  70785. const float w, const float h,
  70786. float csx,
  70787. float csy)
  70788. {
  70789. csx = jmin (csx, w * 0.5f);
  70790. csy = jmin (csy, h * 0.5f);
  70791. const float cs45x = csx * 0.45f;
  70792. const float cs45y = csy * 0.45f;
  70793. const float x2 = x + w;
  70794. const float y2 = y + h;
  70795. startNewSubPath (x + csx, y);
  70796. lineTo (x2 - csx, y);
  70797. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  70798. lineTo (x2, y2 - csy);
  70799. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  70800. lineTo (x + csx, y2);
  70801. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  70802. lineTo (x, y + csy);
  70803. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  70804. closeSubPath();
  70805. }
  70806. void Path::addRoundedRectangle (const float x, const float y,
  70807. const float w, const float h,
  70808. float cs)
  70809. {
  70810. addRoundedRectangle (x, y, w, h, cs, cs);
  70811. }
  70812. void Path::addTriangle (const float x1, const float y1,
  70813. const float x2, const float y2,
  70814. const float x3, const float y3)
  70815. {
  70816. startNewSubPath (x1, y1);
  70817. lineTo (x2, y2);
  70818. lineTo (x3, y3);
  70819. closeSubPath();
  70820. }
  70821. void Path::addQuadrilateral (const float x1, const float y1,
  70822. const float x2, const float y2,
  70823. const float x3, const float y3,
  70824. const float x4, const float y4)
  70825. {
  70826. startNewSubPath (x1, y1);
  70827. lineTo (x2, y2);
  70828. lineTo (x3, y3);
  70829. lineTo (x4, y4);
  70830. closeSubPath();
  70831. }
  70832. void Path::addEllipse (const float x, const float y,
  70833. const float w, const float h)
  70834. {
  70835. const float hw = w * 0.5f;
  70836. const float hw55 = hw * 0.55f;
  70837. const float hh = h * 0.5f;
  70838. const float hh45 = hh * 0.55f;
  70839. const float cx = x + hw;
  70840. const float cy = y + hh;
  70841. startNewSubPath (cx, cy - hh);
  70842. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  70843. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  70844. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  70845. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  70846. closeSubPath();
  70847. }
  70848. void Path::addArc (const float x, const float y,
  70849. const float w, const float h,
  70850. const float fromRadians,
  70851. const float toRadians,
  70852. const bool startAsNewSubPath)
  70853. {
  70854. const float radiusX = w / 2.0f;
  70855. const float radiusY = h / 2.0f;
  70856. addCentredArc (x + radiusX,
  70857. y + radiusY,
  70858. radiusX, radiusY,
  70859. 0.0f,
  70860. fromRadians, toRadians,
  70861. startAsNewSubPath);
  70862. }
  70863. void Path::addCentredArc (const float centreX, const float centreY,
  70864. const float radiusX, const float radiusY,
  70865. const float rotationOfEllipse,
  70866. const float fromRadians,
  70867. const float toRadians,
  70868. const bool startAsNewSubPath)
  70869. {
  70870. if (radiusX > 0.0f && radiusY > 0.0f)
  70871. {
  70872. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  70873. float angle = fromRadians;
  70874. if (startAsNewSubPath)
  70875. {
  70876. float x = centreX + radiusX * sinf (angle);
  70877. float y = centreY - radiusY * cosf (angle);
  70878. if (rotationOfEllipse != 0)
  70879. rotation.transformPoint (x, y);
  70880. startNewSubPath (x, y);
  70881. }
  70882. if (fromRadians < toRadians)
  70883. {
  70884. if (startAsNewSubPath)
  70885. angle += PathHelpers::ellipseAngularIncrement;
  70886. while (angle < toRadians)
  70887. {
  70888. float x = centreX + radiusX * sinf (angle);
  70889. float y = centreY - radiusY * cosf (angle);
  70890. if (rotationOfEllipse != 0)
  70891. rotation.transformPoint (x, y);
  70892. lineTo (x, y);
  70893. angle += PathHelpers::ellipseAngularIncrement;
  70894. }
  70895. }
  70896. else
  70897. {
  70898. if (startAsNewSubPath)
  70899. angle -= PathHelpers::ellipseAngularIncrement;
  70900. while (angle > toRadians)
  70901. {
  70902. float x = centreX + radiusX * sinf (angle);
  70903. float y = centreY - radiusY * cosf (angle);
  70904. if (rotationOfEllipse != 0)
  70905. rotation.transformPoint (x, y);
  70906. lineTo (x, y);
  70907. angle -= PathHelpers::ellipseAngularIncrement;
  70908. }
  70909. }
  70910. float x = centreX + radiusX * sinf (toRadians);
  70911. float y = centreY - radiusY * cosf (toRadians);
  70912. if (rotationOfEllipse != 0)
  70913. rotation.transformPoint (x, y);
  70914. lineTo (x, y);
  70915. }
  70916. }
  70917. void Path::addPieSegment (const float x, const float y,
  70918. const float width, const float height,
  70919. const float fromRadians,
  70920. const float toRadians,
  70921. const float innerCircleProportionalSize)
  70922. {
  70923. float hw = width * 0.5f;
  70924. float hh = height * 0.5f;
  70925. const float centreX = x + hw;
  70926. const float centreY = y + hh;
  70927. startNewSubPath (centreX + hw * sinf (fromRadians),
  70928. centreY - hh * cosf (fromRadians));
  70929. addArc (x, y, width, height, fromRadians, toRadians);
  70930. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  70931. {
  70932. closeSubPath();
  70933. if (innerCircleProportionalSize > 0)
  70934. {
  70935. hw *= innerCircleProportionalSize;
  70936. hh *= innerCircleProportionalSize;
  70937. startNewSubPath (centreX + hw * sinf (toRadians),
  70938. centreY - hh * cosf (toRadians));
  70939. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  70940. toRadians, fromRadians);
  70941. }
  70942. }
  70943. else
  70944. {
  70945. if (innerCircleProportionalSize > 0)
  70946. {
  70947. hw *= innerCircleProportionalSize;
  70948. hh *= innerCircleProportionalSize;
  70949. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  70950. toRadians, fromRadians);
  70951. }
  70952. else
  70953. {
  70954. lineTo (centreX, centreY);
  70955. }
  70956. }
  70957. closeSubPath();
  70958. }
  70959. void Path::addLineSegment (const float startX, const float startY,
  70960. const float endX, const float endY,
  70961. float lineThickness)
  70962. {
  70963. lineThickness *= 0.5f;
  70964. float x, y;
  70965. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  70966. 0, lineThickness, x, y);
  70967. startNewSubPath (x, y);
  70968. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  70969. 0, -lineThickness, x, y);
  70970. lineTo (x, y);
  70971. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  70972. 0, lineThickness, x, y);
  70973. lineTo (x, y);
  70974. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  70975. 0, -lineThickness, x, y);
  70976. lineTo (x, y);
  70977. closeSubPath();
  70978. }
  70979. void Path::addArrow (const float startX, const float startY,
  70980. const float endX, const float endY,
  70981. float lineThickness,
  70982. float arrowheadWidth,
  70983. float arrowheadLength)
  70984. {
  70985. lineThickness *= 0.5f;
  70986. arrowheadWidth *= 0.5f;
  70987. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  70988. startY - endY));
  70989. float x, y;
  70990. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  70991. 0, lineThickness, x, y);
  70992. startNewSubPath (x, y);
  70993. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  70994. 0, -lineThickness, x, y);
  70995. lineTo (x, y);
  70996. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  70997. arrowheadLength, lineThickness, x, y);
  70998. lineTo (x, y);
  70999. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71000. arrowheadLength, arrowheadWidth, x, y);
  71001. lineTo (x, y);
  71002. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71003. 0, 0, x, y);
  71004. lineTo (x, y);
  71005. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71006. arrowheadLength, -arrowheadWidth, x, y);
  71007. lineTo (x, y);
  71008. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71009. arrowheadLength, -lineThickness, x, y);
  71010. lineTo (x, y);
  71011. closeSubPath();
  71012. }
  71013. void Path::addStar (const float centreX,
  71014. const float centreY,
  71015. const int numberOfPoints,
  71016. const float innerRadius,
  71017. const float outerRadius,
  71018. const float startAngle)
  71019. {
  71020. jassert (numberOfPoints > 1); // this would be silly.
  71021. if (numberOfPoints > 1)
  71022. {
  71023. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71024. for (int i = 0; i < numberOfPoints; ++i)
  71025. {
  71026. float angle = startAngle + i * angleBetweenPoints;
  71027. const float x = centreX + outerRadius * sinf (angle);
  71028. const float y = centreY - outerRadius * cosf (angle);
  71029. if (i == 0)
  71030. startNewSubPath (x, y);
  71031. else
  71032. lineTo (x, y);
  71033. angle += angleBetweenPoints * 0.5f;
  71034. lineTo (centreX + innerRadius * sinf (angle),
  71035. centreY - innerRadius * cosf (angle));
  71036. }
  71037. closeSubPath();
  71038. }
  71039. }
  71040. void Path::addBubble (float x, float y,
  71041. float w, float h,
  71042. float cs,
  71043. float tipX,
  71044. float tipY,
  71045. int whichSide,
  71046. float arrowPos,
  71047. float arrowWidth)
  71048. {
  71049. if (w > 1.0f && h > 1.0f)
  71050. {
  71051. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71052. const float cs2 = 2.0f * cs;
  71053. startNewSubPath (x + cs, y);
  71054. if (whichSide == 0)
  71055. {
  71056. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71057. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71058. lineTo (arrowX1, y);
  71059. lineTo (tipX, tipY);
  71060. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71061. }
  71062. lineTo (x + w - cs, y);
  71063. if (cs > 0.0f)
  71064. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71065. if (whichSide == 3)
  71066. {
  71067. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71068. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71069. lineTo (x + w, arrowY1);
  71070. lineTo (tipX, tipY);
  71071. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71072. }
  71073. lineTo (x + w, y + h - cs);
  71074. if (cs > 0.0f)
  71075. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71076. if (whichSide == 2)
  71077. {
  71078. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71079. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71080. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71081. lineTo (tipX, tipY);
  71082. lineTo (arrowX1, y + h);
  71083. }
  71084. lineTo (x + cs, y + h);
  71085. if (cs > 0.0f)
  71086. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71087. if (whichSide == 1)
  71088. {
  71089. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71090. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71091. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71092. lineTo (tipX, tipY);
  71093. lineTo (x, arrowY1);
  71094. }
  71095. lineTo (x, y + cs);
  71096. if (cs > 0.0f)
  71097. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement);
  71098. closeSubPath();
  71099. }
  71100. }
  71101. void Path::addPath (const Path& other)
  71102. {
  71103. size_t i = 0;
  71104. while (i < other.numElements)
  71105. {
  71106. const float type = other.data.elements [i++];
  71107. if (type == moveMarker)
  71108. {
  71109. startNewSubPath (other.data.elements [i],
  71110. other.data.elements [i + 1]);
  71111. i += 2;
  71112. }
  71113. else if (type == lineMarker)
  71114. {
  71115. lineTo (other.data.elements [i],
  71116. other.data.elements [i + 1]);
  71117. i += 2;
  71118. }
  71119. else if (type == quadMarker)
  71120. {
  71121. quadraticTo (other.data.elements [i],
  71122. other.data.elements [i + 1],
  71123. other.data.elements [i + 2],
  71124. other.data.elements [i + 3]);
  71125. i += 4;
  71126. }
  71127. else if (type == cubicMarker)
  71128. {
  71129. cubicTo (other.data.elements [i],
  71130. other.data.elements [i + 1],
  71131. other.data.elements [i + 2],
  71132. other.data.elements [i + 3],
  71133. other.data.elements [i + 4],
  71134. other.data.elements [i + 5]);
  71135. i += 6;
  71136. }
  71137. else if (type == closeSubPathMarker)
  71138. {
  71139. closeSubPath();
  71140. }
  71141. else
  71142. {
  71143. // something's gone wrong with the element list!
  71144. jassertfalse
  71145. }
  71146. }
  71147. }
  71148. void Path::addPath (const Path& other,
  71149. const AffineTransform& transformToApply)
  71150. {
  71151. size_t i = 0;
  71152. while (i < other.numElements)
  71153. {
  71154. const float type = other.data.elements [i++];
  71155. if (type == closeSubPathMarker)
  71156. {
  71157. closeSubPath();
  71158. }
  71159. else
  71160. {
  71161. float x = other.data.elements [i++];
  71162. float y = other.data.elements [i++];
  71163. transformToApply.transformPoint (x, y);
  71164. if (type == moveMarker)
  71165. {
  71166. startNewSubPath (x, y);
  71167. }
  71168. else if (type == lineMarker)
  71169. {
  71170. lineTo (x, y);
  71171. }
  71172. else if (type == quadMarker)
  71173. {
  71174. float x2 = other.data.elements [i++];
  71175. float y2 = other.data.elements [i++];
  71176. transformToApply.transformPoint (x2, y2);
  71177. quadraticTo (x, y, x2, y2);
  71178. }
  71179. else if (type == cubicMarker)
  71180. {
  71181. float x2 = other.data.elements [i++];
  71182. float y2 = other.data.elements [i++];
  71183. float x3 = other.data.elements [i++];
  71184. float y3 = other.data.elements [i++];
  71185. transformToApply.transformPoint (x2, y2);
  71186. transformToApply.transformPoint (x3, y3);
  71187. cubicTo (x, y, x2, y2, x3, y3);
  71188. }
  71189. else
  71190. {
  71191. // something's gone wrong with the element list!
  71192. jassertfalse
  71193. }
  71194. }
  71195. }
  71196. }
  71197. void Path::applyTransform (const AffineTransform& transform) throw()
  71198. {
  71199. size_t i = 0;
  71200. pathYMin = pathXMin = 0;
  71201. pathYMax = pathXMax = 0;
  71202. bool setMaxMin = false;
  71203. while (i < numElements)
  71204. {
  71205. const float type = data.elements [i++];
  71206. if (type == moveMarker)
  71207. {
  71208. transform.transformPoint (data.elements [i],
  71209. data.elements [i + 1]);
  71210. if (setMaxMin)
  71211. {
  71212. pathXMin = jmin (pathXMin, data.elements [i]);
  71213. pathXMax = jmax (pathXMax, data.elements [i]);
  71214. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71215. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71216. }
  71217. else
  71218. {
  71219. pathXMin = pathXMax = data.elements [i];
  71220. pathYMin = pathYMax = data.elements [i + 1];
  71221. setMaxMin = true;
  71222. }
  71223. i += 2;
  71224. }
  71225. else if (type == lineMarker)
  71226. {
  71227. transform.transformPoint (data.elements [i],
  71228. data.elements [i + 1]);
  71229. pathXMin = jmin (pathXMin, data.elements [i]);
  71230. pathXMax = jmax (pathXMax, data.elements [i]);
  71231. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71232. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71233. i += 2;
  71234. }
  71235. else if (type == quadMarker)
  71236. {
  71237. transform.transformPoint (data.elements [i],
  71238. data.elements [i + 1]);
  71239. transform.transformPoint (data.elements [i + 2],
  71240. data.elements [i + 3]);
  71241. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71242. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71243. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71244. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71245. i += 4;
  71246. }
  71247. else if (type == cubicMarker)
  71248. {
  71249. transform.transformPoint (data.elements [i],
  71250. data.elements [i + 1]);
  71251. transform.transformPoint (data.elements [i + 2],
  71252. data.elements [i + 3]);
  71253. transform.transformPoint (data.elements [i + 4],
  71254. data.elements [i + 5]);
  71255. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71256. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71257. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71258. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71259. i += 6;
  71260. }
  71261. }
  71262. }
  71263. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71264. const float w, const float h,
  71265. const bool preserveProportions,
  71266. const Justification& justification) const
  71267. {
  71268. Rectangle<float> bounds (getBounds());
  71269. if (preserveProportions)
  71270. {
  71271. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71272. return AffineTransform::identity;
  71273. float newW, newH;
  71274. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71275. if (srcRatio > h / w)
  71276. {
  71277. newW = h / srcRatio;
  71278. newH = h;
  71279. }
  71280. else
  71281. {
  71282. newW = w;
  71283. newH = w * srcRatio;
  71284. }
  71285. float newXCentre = x;
  71286. float newYCentre = y;
  71287. if (justification.testFlags (Justification::left))
  71288. newXCentre += newW * 0.5f;
  71289. else if (justification.testFlags (Justification::right))
  71290. newXCentre += w - newW * 0.5f;
  71291. else
  71292. newXCentre += w * 0.5f;
  71293. if (justification.testFlags (Justification::top))
  71294. newYCentre += newH * 0.5f;
  71295. else if (justification.testFlags (Justification::bottom))
  71296. newYCentre += h - newH * 0.5f;
  71297. else
  71298. newYCentre += h * 0.5f;
  71299. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71300. bounds.getHeight() * -0.5f - bounds.getY())
  71301. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71302. .translated (newXCentre, newYCentre);
  71303. }
  71304. else
  71305. {
  71306. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71307. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71308. .translated (x, y);
  71309. }
  71310. }
  71311. bool Path::contains (const float x, const float y, const float tolerence) const
  71312. {
  71313. if (x <= pathXMin || x >= pathXMax
  71314. || y <= pathYMin || y >= pathYMax)
  71315. return false;
  71316. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71317. int positiveCrossings = 0;
  71318. int negativeCrossings = 0;
  71319. while (i.next())
  71320. {
  71321. if ((i.y1 <= y && i.y2 > y)
  71322. || (i.y2 <= y && i.y1 > y))
  71323. {
  71324. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71325. if (intersectX <= x)
  71326. {
  71327. if (i.y1 < i.y2)
  71328. ++positiveCrossings;
  71329. else
  71330. ++negativeCrossings;
  71331. }
  71332. }
  71333. }
  71334. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71335. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71336. }
  71337. bool Path::intersectsLine (const float x1, const float y1,
  71338. const float x2, const float y2,
  71339. const float tolerence)
  71340. {
  71341. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71342. const Line line1 (x1, y1, x2, y2);
  71343. while (i.next())
  71344. {
  71345. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71346. float ix, iy;
  71347. if (line1.intersects (line2, ix, iy))
  71348. return true;
  71349. }
  71350. return false;
  71351. }
  71352. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  71353. {
  71354. if (cornerRadius <= 0.01f)
  71355. return *this;
  71356. size_t indexOfPathStart = 0, indexOfPathStartThis = 0;
  71357. size_t n = 0;
  71358. bool lastWasLine = false, firstWasLine = false;
  71359. Path p;
  71360. while (n < numElements)
  71361. {
  71362. const float type = data.elements [n++];
  71363. if (type == moveMarker)
  71364. {
  71365. indexOfPathStart = p.numElements;
  71366. indexOfPathStartThis = n - 1;
  71367. const float x = data.elements [n++];
  71368. const float y = data.elements [n++];
  71369. p.startNewSubPath (x, y);
  71370. lastWasLine = false;
  71371. firstWasLine = (data.elements [n] == lineMarker);
  71372. }
  71373. else if (type == lineMarker || type == closeSubPathMarker)
  71374. {
  71375. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71376. if (type == lineMarker)
  71377. {
  71378. endX = data.elements [n++];
  71379. endY = data.elements [n++];
  71380. if (n > 8)
  71381. {
  71382. startX = data.elements [n - 8];
  71383. startY = data.elements [n - 7];
  71384. joinX = data.elements [n - 5];
  71385. joinY = data.elements [n - 4];
  71386. }
  71387. }
  71388. else
  71389. {
  71390. endX = data.elements [indexOfPathStartThis + 1];
  71391. endY = data.elements [indexOfPathStartThis + 2];
  71392. if (n > 6)
  71393. {
  71394. startX = data.elements [n - 6];
  71395. startY = data.elements [n - 5];
  71396. joinX = data.elements [n - 3];
  71397. joinY = data.elements [n - 2];
  71398. }
  71399. }
  71400. if (lastWasLine)
  71401. {
  71402. const double len1 = juce_hypot (startX - joinX,
  71403. startY - joinY);
  71404. if (len1 > 0)
  71405. {
  71406. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71407. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71408. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71409. }
  71410. const double len2 = juce_hypot (endX - joinX,
  71411. endY - joinY);
  71412. if (len2 > 0)
  71413. {
  71414. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71415. p.quadraticTo (joinX, joinY,
  71416. (float) (joinX + (endX - joinX) * propNeeded),
  71417. (float) (joinY + (endY - joinY) * propNeeded));
  71418. }
  71419. p.lineTo (endX, endY);
  71420. }
  71421. else if (type == lineMarker)
  71422. {
  71423. p.lineTo (endX, endY);
  71424. lastWasLine = true;
  71425. }
  71426. if (type == closeSubPathMarker)
  71427. {
  71428. if (firstWasLine)
  71429. {
  71430. startX = data.elements [n - 3];
  71431. startY = data.elements [n - 2];
  71432. joinX = endX;
  71433. joinY = endY;
  71434. endX = data.elements [indexOfPathStartThis + 4];
  71435. endY = data.elements [indexOfPathStartThis + 5];
  71436. const double len1 = juce_hypot (startX - joinX,
  71437. startY - joinY);
  71438. if (len1 > 0)
  71439. {
  71440. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71441. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71442. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71443. }
  71444. const double len2 = juce_hypot (endX - joinX,
  71445. endY - joinY);
  71446. if (len2 > 0)
  71447. {
  71448. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71449. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71450. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71451. p.quadraticTo (joinX, joinY, endX, endY);
  71452. p.data.elements [indexOfPathStart + 1] = endX;
  71453. p.data.elements [indexOfPathStart + 2] = endY;
  71454. }
  71455. }
  71456. p.closeSubPath();
  71457. }
  71458. }
  71459. else if (type == quadMarker)
  71460. {
  71461. lastWasLine = false;
  71462. const float x1 = data.elements [n++];
  71463. const float y1 = data.elements [n++];
  71464. const float x2 = data.elements [n++];
  71465. const float y2 = data.elements [n++];
  71466. p.quadraticTo (x1, y1, x2, y2);
  71467. }
  71468. else if (type == cubicMarker)
  71469. {
  71470. lastWasLine = false;
  71471. const float x1 = data.elements [n++];
  71472. const float y1 = data.elements [n++];
  71473. const float x2 = data.elements [n++];
  71474. const float y2 = data.elements [n++];
  71475. const float x3 = data.elements [n++];
  71476. const float y3 = data.elements [n++];
  71477. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71478. }
  71479. }
  71480. return p;
  71481. }
  71482. void Path::loadPathFromStream (InputStream& source)
  71483. {
  71484. while (! source.isExhausted())
  71485. {
  71486. switch (source.readByte())
  71487. {
  71488. case 'm':
  71489. {
  71490. const float x = source.readFloat();
  71491. const float y = source.readFloat();
  71492. startNewSubPath (x, y);
  71493. break;
  71494. }
  71495. case 'l':
  71496. {
  71497. const float x = source.readFloat();
  71498. const float y = source.readFloat();
  71499. lineTo (x, y);
  71500. break;
  71501. }
  71502. case 'q':
  71503. {
  71504. const float x1 = source.readFloat();
  71505. const float y1 = source.readFloat();
  71506. const float x2 = source.readFloat();
  71507. const float y2 = source.readFloat();
  71508. quadraticTo (x1, y1, x2, y2);
  71509. break;
  71510. }
  71511. case 'b':
  71512. {
  71513. const float x1 = source.readFloat();
  71514. const float y1 = source.readFloat();
  71515. const float x2 = source.readFloat();
  71516. const float y2 = source.readFloat();
  71517. const float x3 = source.readFloat();
  71518. const float y3 = source.readFloat();
  71519. cubicTo (x1, y1, x2, y2, x3, y3);
  71520. break;
  71521. }
  71522. case 'c':
  71523. closeSubPath();
  71524. break;
  71525. case 'n':
  71526. useNonZeroWinding = true;
  71527. break;
  71528. case 'z':
  71529. useNonZeroWinding = false;
  71530. break;
  71531. case 'e':
  71532. return; // end of path marker
  71533. default:
  71534. jassertfalse // illegal char in the stream
  71535. break;
  71536. }
  71537. }
  71538. }
  71539. void Path::loadPathFromData (const void* const data, const int numberOfBytes)
  71540. {
  71541. MemoryInputStream in (data, numberOfBytes, false);
  71542. loadPathFromStream (in);
  71543. }
  71544. void Path::writePathToStream (OutputStream& dest) const
  71545. {
  71546. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  71547. size_t i = 0;
  71548. while (i < numElements)
  71549. {
  71550. const float type = data.elements [i++];
  71551. if (type == moveMarker)
  71552. {
  71553. dest.writeByte ('m');
  71554. dest.writeFloat (data.elements [i++]);
  71555. dest.writeFloat (data.elements [i++]);
  71556. }
  71557. else if (type == lineMarker)
  71558. {
  71559. dest.writeByte ('l');
  71560. dest.writeFloat (data.elements [i++]);
  71561. dest.writeFloat (data.elements [i++]);
  71562. }
  71563. else if (type == quadMarker)
  71564. {
  71565. dest.writeByte ('q');
  71566. dest.writeFloat (data.elements [i++]);
  71567. dest.writeFloat (data.elements [i++]);
  71568. dest.writeFloat (data.elements [i++]);
  71569. dest.writeFloat (data.elements [i++]);
  71570. }
  71571. else if (type == cubicMarker)
  71572. {
  71573. dest.writeByte ('b');
  71574. dest.writeFloat (data.elements [i++]);
  71575. dest.writeFloat (data.elements [i++]);
  71576. dest.writeFloat (data.elements [i++]);
  71577. dest.writeFloat (data.elements [i++]);
  71578. dest.writeFloat (data.elements [i++]);
  71579. dest.writeFloat (data.elements [i++]);
  71580. }
  71581. else if (type == closeSubPathMarker)
  71582. {
  71583. dest.writeByte ('c');
  71584. }
  71585. }
  71586. dest.writeByte ('e'); // marks the end-of-path
  71587. }
  71588. const String Path::toString() const
  71589. {
  71590. MemoryOutputStream s (2048, 2048);
  71591. if (! useNonZeroWinding)
  71592. s << 'a';
  71593. size_t i = 0;
  71594. float lastMarker = 0.0f;
  71595. while (i < numElements)
  71596. {
  71597. const float marker = data.elements [i++];
  71598. char markerChar = 0;
  71599. int numCoords = 0;
  71600. if (marker == moveMarker)
  71601. {
  71602. markerChar = 'm';
  71603. numCoords = 2;
  71604. }
  71605. else if (marker == lineMarker)
  71606. {
  71607. markerChar = 'l';
  71608. numCoords = 2;
  71609. }
  71610. else if (marker == quadMarker)
  71611. {
  71612. markerChar = 'q';
  71613. numCoords = 4;
  71614. }
  71615. else if (marker == cubicMarker)
  71616. {
  71617. markerChar = 'c';
  71618. numCoords = 6;
  71619. }
  71620. else
  71621. {
  71622. jassert (marker == closeSubPathMarker);
  71623. markerChar = 'z';
  71624. }
  71625. if (marker != lastMarker)
  71626. {
  71627. if (s.getDataSize() != 0)
  71628. s << ' ';
  71629. s << markerChar;
  71630. lastMarker = marker;
  71631. }
  71632. while (--numCoords >= 0 && i < numElements)
  71633. {
  71634. String coord (data.elements [i++], 3);
  71635. while (coord.endsWithChar ('0') && coord != "0")
  71636. coord = coord.dropLastCharacters (1);
  71637. if (coord.endsWithChar ('.'))
  71638. coord = coord.dropLastCharacters (1);
  71639. if (s.getDataSize() != 0)
  71640. s << ' ';
  71641. s << coord;
  71642. }
  71643. }
  71644. return s.toUTF8();
  71645. }
  71646. void Path::restoreFromString (const String& stringVersion)
  71647. {
  71648. clear();
  71649. setUsingNonZeroWinding (true);
  71650. const juce_wchar* t = stringVersion;
  71651. juce_wchar marker = 'm';
  71652. int numValues = 2;
  71653. float values [6];
  71654. while (*t != 0)
  71655. {
  71656. const String token (PathHelpers::nextToken (t));
  71657. const juce_wchar firstChar = token[0];
  71658. int startNum = 0;
  71659. if (firstChar == 'm' || firstChar == 'l')
  71660. {
  71661. marker = firstChar;
  71662. numValues = 2;
  71663. }
  71664. else if (firstChar == 'q')
  71665. {
  71666. marker = firstChar;
  71667. numValues = 4;
  71668. }
  71669. else if (firstChar == 'c')
  71670. {
  71671. marker = firstChar;
  71672. numValues = 6;
  71673. }
  71674. else if (firstChar == 'z')
  71675. {
  71676. marker = firstChar;
  71677. numValues = 0;
  71678. }
  71679. else if (firstChar == 'a')
  71680. {
  71681. setUsingNonZeroWinding (false);
  71682. continue;
  71683. }
  71684. else
  71685. {
  71686. ++startNum;
  71687. values [0] = token.getFloatValue();
  71688. }
  71689. for (int i = startNum; i < numValues; ++i)
  71690. values [i] = PathHelpers::nextToken (t).getFloatValue();
  71691. switch (marker)
  71692. {
  71693. case 'm':
  71694. startNewSubPath (values[0], values[1]);
  71695. break;
  71696. case 'l':
  71697. lineTo (values[0], values[1]);
  71698. break;
  71699. case 'q':
  71700. quadraticTo (values[0], values[1],
  71701. values[2], values[3]);
  71702. break;
  71703. case 'c':
  71704. cubicTo (values[0], values[1],
  71705. values[2], values[3],
  71706. values[4], values[5]);
  71707. break;
  71708. case 'z':
  71709. closeSubPath();
  71710. break;
  71711. default:
  71712. jassertfalse // illegal string format?
  71713. break;
  71714. }
  71715. }
  71716. }
  71717. Path::Iterator::Iterator (const Path& path_)
  71718. : path (path_),
  71719. index (0)
  71720. {
  71721. }
  71722. Path::Iterator::~Iterator()
  71723. {
  71724. }
  71725. bool Path::Iterator::next()
  71726. {
  71727. const float* const elements = path.data.elements;
  71728. if (index < path.numElements)
  71729. {
  71730. const float type = elements [index++];
  71731. if (type == moveMarker)
  71732. {
  71733. elementType = startNewSubPath;
  71734. x1 = elements [index++];
  71735. y1 = elements [index++];
  71736. }
  71737. else if (type == lineMarker)
  71738. {
  71739. elementType = lineTo;
  71740. x1 = elements [index++];
  71741. y1 = elements [index++];
  71742. }
  71743. else if (type == quadMarker)
  71744. {
  71745. elementType = quadraticTo;
  71746. x1 = elements [index++];
  71747. y1 = elements [index++];
  71748. x2 = elements [index++];
  71749. y2 = elements [index++];
  71750. }
  71751. else if (type == cubicMarker)
  71752. {
  71753. elementType = cubicTo;
  71754. x1 = elements [index++];
  71755. y1 = elements [index++];
  71756. x2 = elements [index++];
  71757. y2 = elements [index++];
  71758. x3 = elements [index++];
  71759. y3 = elements [index++];
  71760. }
  71761. else if (type == closeSubPathMarker)
  71762. {
  71763. elementType = closePath;
  71764. }
  71765. return true;
  71766. }
  71767. return false;
  71768. }
  71769. END_JUCE_NAMESPACE
  71770. /*** End of inlined file: juce_Path.cpp ***/
  71771. /*** Start of inlined file: juce_PathIterator.cpp ***/
  71772. BEGIN_JUCE_NAMESPACE
  71773. #if JUCE_MSVC
  71774. #pragma optimize ("t", on)
  71775. #endif
  71776. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  71777. const AffineTransform& transform_,
  71778. float tolerence_)
  71779. : x2 (0),
  71780. y2 (0),
  71781. closesSubPath (false),
  71782. subPathIndex (-1),
  71783. path (path_),
  71784. transform (transform_),
  71785. points (path_.data.elements),
  71786. tolerence (tolerence_ * tolerence_),
  71787. subPathCloseX (0),
  71788. subPathCloseY (0),
  71789. isIdentityTransform (transform_.isIdentity()),
  71790. stackBase (32),
  71791. index (0),
  71792. stackSize (32)
  71793. {
  71794. stackPos = stackBase;
  71795. }
  71796. PathFlatteningIterator::~PathFlatteningIterator()
  71797. {
  71798. }
  71799. bool PathFlatteningIterator::next()
  71800. {
  71801. x1 = x2;
  71802. y1 = y2;
  71803. float x3 = 0;
  71804. float y3 = 0;
  71805. float x4 = 0;
  71806. float y4 = 0;
  71807. float type;
  71808. for (;;)
  71809. {
  71810. if (stackPos == stackBase)
  71811. {
  71812. if (index >= path.numElements)
  71813. {
  71814. return false;
  71815. }
  71816. else
  71817. {
  71818. type = points [index++];
  71819. if (type != Path::closeSubPathMarker)
  71820. {
  71821. x2 = points [index++];
  71822. y2 = points [index++];
  71823. if (! isIdentityTransform)
  71824. transform.transformPoint (x2, y2);
  71825. if (type == Path::quadMarker)
  71826. {
  71827. x3 = points [index++];
  71828. y3 = points [index++];
  71829. if (! isIdentityTransform)
  71830. transform.transformPoint (x3, y3);
  71831. }
  71832. else if (type == Path::cubicMarker)
  71833. {
  71834. x3 = points [index++];
  71835. y3 = points [index++];
  71836. x4 = points [index++];
  71837. y4 = points [index++];
  71838. if (! isIdentityTransform)
  71839. {
  71840. transform.transformPoint (x3, y3);
  71841. transform.transformPoint (x4, y4);
  71842. }
  71843. }
  71844. }
  71845. }
  71846. }
  71847. else
  71848. {
  71849. type = *--stackPos;
  71850. if (type != Path::closeSubPathMarker)
  71851. {
  71852. x2 = *--stackPos;
  71853. y2 = *--stackPos;
  71854. if (type == Path::quadMarker)
  71855. {
  71856. x3 = *--stackPos;
  71857. y3 = *--stackPos;
  71858. }
  71859. else if (type == Path::cubicMarker)
  71860. {
  71861. x3 = *--stackPos;
  71862. y3 = *--stackPos;
  71863. x4 = *--stackPos;
  71864. y4 = *--stackPos;
  71865. }
  71866. }
  71867. }
  71868. if (type == Path::lineMarker)
  71869. {
  71870. ++subPathIndex;
  71871. closesSubPath = (stackPos == stackBase)
  71872. && (index < path.numElements)
  71873. && (points [index] == Path::closeSubPathMarker)
  71874. && x2 == subPathCloseX
  71875. && y2 == subPathCloseY;
  71876. return true;
  71877. }
  71878. else if (type == Path::quadMarker)
  71879. {
  71880. const size_t offset = (size_t) (stackPos - stackBase);
  71881. if (offset >= stackSize - 10)
  71882. {
  71883. stackSize <<= 1;
  71884. stackBase.realloc (stackSize);
  71885. stackPos = stackBase + offset;
  71886. }
  71887. const float dx1 = x1 - x2;
  71888. const float dy1 = y1 - y2;
  71889. const float dx2 = x2 - x3;
  71890. const float dy2 = y2 - y3;
  71891. const float m1x = (x1 + x2) * 0.5f;
  71892. const float m1y = (y1 + y2) * 0.5f;
  71893. const float m2x = (x2 + x3) * 0.5f;
  71894. const float m2y = (y2 + y3) * 0.5f;
  71895. const float m3x = (m1x + m2x) * 0.5f;
  71896. const float m3y = (m1y + m2y) * 0.5f;
  71897. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  71898. {
  71899. *stackPos++ = y3;
  71900. *stackPos++ = x3;
  71901. *stackPos++ = m2y;
  71902. *stackPos++ = m2x;
  71903. *stackPos++ = Path::quadMarker;
  71904. *stackPos++ = m3y;
  71905. *stackPos++ = m3x;
  71906. *stackPos++ = m1y;
  71907. *stackPos++ = m1x;
  71908. *stackPos++ = Path::quadMarker;
  71909. }
  71910. else
  71911. {
  71912. *stackPos++ = y3;
  71913. *stackPos++ = x3;
  71914. *stackPos++ = Path::lineMarker;
  71915. *stackPos++ = m3y;
  71916. *stackPos++ = m3x;
  71917. *stackPos++ = Path::lineMarker;
  71918. }
  71919. jassert (stackPos < stackBase + stackSize);
  71920. }
  71921. else if (type == Path::cubicMarker)
  71922. {
  71923. const size_t offset = (size_t) (stackPos - stackBase);
  71924. if (offset >= stackSize - 16)
  71925. {
  71926. stackSize <<= 1;
  71927. stackBase.realloc (stackSize);
  71928. stackPos = stackBase + offset;
  71929. }
  71930. const float dx1 = x1 - x2;
  71931. const float dy1 = y1 - y2;
  71932. const float dx2 = x2 - x3;
  71933. const float dy2 = y2 - y3;
  71934. const float dx3 = x3 - x4;
  71935. const float dy3 = y3 - y4;
  71936. const float m1x = (x1 + x2) * 0.5f;
  71937. const float m1y = (y1 + y2) * 0.5f;
  71938. const float m2x = (x3 + x2) * 0.5f;
  71939. const float m2y = (y3 + y2) * 0.5f;
  71940. const float m3x = (x3 + x4) * 0.5f;
  71941. const float m3y = (y3 + y4) * 0.5f;
  71942. const float m4x = (m1x + m2x) * 0.5f;
  71943. const float m4y = (m1y + m2y) * 0.5f;
  71944. const float m5x = (m3x + m2x) * 0.5f;
  71945. const float m5y = (m3y + m2y) * 0.5f;
  71946. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  71947. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  71948. {
  71949. *stackPos++ = y4;
  71950. *stackPos++ = x4;
  71951. *stackPos++ = m3y;
  71952. *stackPos++ = m3x;
  71953. *stackPos++ = m5y;
  71954. *stackPos++ = m5x;
  71955. *stackPos++ = Path::cubicMarker;
  71956. *stackPos++ = (m4y + m5y) * 0.5f;
  71957. *stackPos++ = (m4x + m5x) * 0.5f;
  71958. *stackPos++ = m4y;
  71959. *stackPos++ = m4x;
  71960. *stackPos++ = m1y;
  71961. *stackPos++ = m1x;
  71962. *stackPos++ = Path::cubicMarker;
  71963. }
  71964. else
  71965. {
  71966. *stackPos++ = y4;
  71967. *stackPos++ = x4;
  71968. *stackPos++ = Path::lineMarker;
  71969. *stackPos++ = m5y;
  71970. *stackPos++ = m5x;
  71971. *stackPos++ = Path::lineMarker;
  71972. *stackPos++ = m4y;
  71973. *stackPos++ = m4x;
  71974. *stackPos++ = Path::lineMarker;
  71975. }
  71976. }
  71977. else if (type == Path::closeSubPathMarker)
  71978. {
  71979. if (x2 != subPathCloseX || y2 != subPathCloseY)
  71980. {
  71981. x1 = x2;
  71982. y1 = y2;
  71983. x2 = subPathCloseX;
  71984. y2 = subPathCloseY;
  71985. closesSubPath = true;
  71986. return true;
  71987. }
  71988. }
  71989. else
  71990. {
  71991. jassert (type == Path::moveMarker);
  71992. subPathIndex = -1;
  71993. subPathCloseX = x1 = x2;
  71994. subPathCloseY = y1 = y2;
  71995. }
  71996. }
  71997. }
  71998. END_JUCE_NAMESPACE
  71999. /*** End of inlined file: juce_PathIterator.cpp ***/
  72000. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72001. BEGIN_JUCE_NAMESPACE
  72002. PathStrokeType::PathStrokeType (const float strokeThickness,
  72003. const JointStyle jointStyle_,
  72004. const EndCapStyle endStyle_) throw()
  72005. : thickness (strokeThickness),
  72006. jointStyle (jointStyle_),
  72007. endStyle (endStyle_)
  72008. {
  72009. }
  72010. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72011. : thickness (other.thickness),
  72012. jointStyle (other.jointStyle),
  72013. endStyle (other.endStyle)
  72014. {
  72015. }
  72016. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72017. {
  72018. thickness = other.thickness;
  72019. jointStyle = other.jointStyle;
  72020. endStyle = other.endStyle;
  72021. return *this;
  72022. }
  72023. PathStrokeType::~PathStrokeType() throw()
  72024. {
  72025. }
  72026. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72027. {
  72028. return thickness == other.thickness
  72029. && jointStyle == other.jointStyle
  72030. && endStyle == other.endStyle;
  72031. }
  72032. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72033. {
  72034. return ! operator== (other);
  72035. }
  72036. static bool lineIntersection (const float x1, const float y1,
  72037. const float x2, const float y2,
  72038. const float x3, const float y3,
  72039. const float x4, const float y4,
  72040. float& intersectionX,
  72041. float& intersectionY,
  72042. float& distanceBeyondLine1EndSquared) throw()
  72043. {
  72044. if (x2 != x3 || y2 != y3)
  72045. {
  72046. const float dx1 = x2 - x1;
  72047. const float dy1 = y2 - y1;
  72048. const float dx2 = x4 - x3;
  72049. const float dy2 = y4 - y3;
  72050. const float divisor = dx1 * dy2 - dx2 * dy1;
  72051. if (divisor == 0)
  72052. {
  72053. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72054. {
  72055. if (dy1 == 0 && dy2 != 0)
  72056. {
  72057. const float along = (y1 - y3) / dy2;
  72058. intersectionX = x3 + along * dx2;
  72059. intersectionY = y1;
  72060. distanceBeyondLine1EndSquared = intersectionX - x2;
  72061. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72062. if ((x2 > x1) == (intersectionX < x2))
  72063. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72064. return along >= 0 && along <= 1.0f;
  72065. }
  72066. else if (dy2 == 0 && dy1 != 0)
  72067. {
  72068. const float along = (y3 - y1) / dy1;
  72069. intersectionX = x1 + along * dx1;
  72070. intersectionY = y3;
  72071. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72072. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72073. if (along < 1.0f)
  72074. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72075. return along >= 0 && along <= 1.0f;
  72076. }
  72077. else if (dx1 == 0 && dx2 != 0)
  72078. {
  72079. const float along = (x1 - x3) / dx2;
  72080. intersectionX = x1;
  72081. intersectionY = y3 + along * dy2;
  72082. distanceBeyondLine1EndSquared = intersectionY - y2;
  72083. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72084. if ((y2 > y1) == (intersectionY < y2))
  72085. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72086. return along >= 0 && along <= 1.0f;
  72087. }
  72088. else if (dx2 == 0 && dx1 != 0)
  72089. {
  72090. const float along = (x3 - x1) / dx1;
  72091. intersectionX = x3;
  72092. intersectionY = y1 + along * dy1;
  72093. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72094. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72095. if (along < 1.0f)
  72096. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72097. return along >= 0 && along <= 1.0f;
  72098. }
  72099. }
  72100. intersectionX = 0.5f * (x2 + x3);
  72101. intersectionY = 0.5f * (y2 + y3);
  72102. distanceBeyondLine1EndSquared = 0.0f;
  72103. return false;
  72104. }
  72105. else
  72106. {
  72107. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72108. intersectionX = x1 + along1 * dx1;
  72109. intersectionY = y1 + along1 * dy1;
  72110. if (along1 >= 0 && along1 <= 1.0f)
  72111. {
  72112. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72113. if (along2 >= 0 && along2 <= divisor)
  72114. {
  72115. distanceBeyondLine1EndSquared = 0.0f;
  72116. return true;
  72117. }
  72118. }
  72119. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72120. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72121. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72122. if (along1 < 1.0f)
  72123. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72124. return false;
  72125. }
  72126. }
  72127. intersectionX = x2;
  72128. intersectionY = y2;
  72129. distanceBeyondLine1EndSquared = 0.0f;
  72130. return true;
  72131. }
  72132. namespace PathFunctions
  72133. {
  72134. // part of stroke drawing stuff
  72135. static void addEdgeAndJoint (Path& destPath,
  72136. const PathStrokeType::JointStyle style,
  72137. const float maxMiterExtensionSquared, const float width,
  72138. const float x1, const float y1,
  72139. const float x2, const float y2,
  72140. const float x3, const float y3,
  72141. const float x4, const float y4,
  72142. const float midX, const float midY)
  72143. {
  72144. if (style == PathStrokeType::beveled
  72145. || (x3 == x4 && y3 == y4)
  72146. || (x1 == x2 && y1 == y2))
  72147. {
  72148. destPath.lineTo (x2, y2);
  72149. destPath.lineTo (x3, y3);
  72150. }
  72151. else
  72152. {
  72153. float jx, jy, distanceBeyondLine1EndSquared;
  72154. // if they intersect, use this point..
  72155. if (lineIntersection (x1, y1, x2, y2,
  72156. x3, y3, x4, y4,
  72157. jx, jy, distanceBeyondLine1EndSquared))
  72158. {
  72159. destPath.lineTo (jx, jy);
  72160. }
  72161. else
  72162. {
  72163. if (style == PathStrokeType::mitered)
  72164. {
  72165. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72166. && distanceBeyondLine1EndSquared > 0.0f)
  72167. {
  72168. destPath.lineTo (jx, jy);
  72169. }
  72170. else
  72171. {
  72172. // the end sticks out too far, so just use a blunt joint
  72173. destPath.lineTo (x2, y2);
  72174. destPath.lineTo (x3, y3);
  72175. }
  72176. }
  72177. else
  72178. {
  72179. // curved joints
  72180. float angle1 = atan2f (x2 - midX, y2 - midY);
  72181. float angle2 = atan2f (x3 - midX, y3 - midY);
  72182. const float angleIncrement = 0.1f;
  72183. destPath.lineTo (x2, y2);
  72184. if (fabs (angle1 - angle2) > angleIncrement)
  72185. {
  72186. if (angle2 > angle1 + float_Pi
  72187. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72188. {
  72189. if (angle2 > angle1)
  72190. angle2 -= float_Pi * 2.0f;
  72191. jassert (angle1 <= angle2 + float_Pi);
  72192. angle1 -= angleIncrement;
  72193. while (angle1 > angle2)
  72194. {
  72195. destPath.lineTo (midX + width * sinf (angle1),
  72196. midY + width * cosf (angle1));
  72197. angle1 -= angleIncrement;
  72198. }
  72199. }
  72200. else
  72201. {
  72202. if (angle1 > angle2)
  72203. angle1 -= float_Pi * 2.0f;
  72204. jassert (angle1 >= angle2 - float_Pi);
  72205. angle1 += angleIncrement;
  72206. while (angle1 < angle2)
  72207. {
  72208. destPath.lineTo (midX + width * sinf (angle1),
  72209. midY + width * cosf (angle1));
  72210. angle1 += angleIncrement;
  72211. }
  72212. }
  72213. }
  72214. destPath.lineTo (x3, y3);
  72215. }
  72216. }
  72217. }
  72218. }
  72219. static void addLineEnd (Path& destPath,
  72220. const PathStrokeType::EndCapStyle style,
  72221. const float x1, const float y1,
  72222. const float x2, const float y2,
  72223. const float width)
  72224. {
  72225. if (style == PathStrokeType::butt)
  72226. {
  72227. destPath.lineTo (x2, y2);
  72228. }
  72229. else
  72230. {
  72231. float offx1, offy1, offx2, offy2;
  72232. float dx = x2 - x1;
  72233. float dy = y2 - y1;
  72234. const float len = juce_hypotf (dx, dy);
  72235. if (len == 0)
  72236. {
  72237. offx1 = offx2 = x1;
  72238. offy1 = offy2 = y1;
  72239. }
  72240. else
  72241. {
  72242. const float offset = width / len;
  72243. dx *= offset;
  72244. dy *= offset;
  72245. offx1 = x1 + dy;
  72246. offy1 = y1 - dx;
  72247. offx2 = x2 + dy;
  72248. offy2 = y2 - dx;
  72249. }
  72250. if (style == PathStrokeType::square)
  72251. {
  72252. // sqaure ends
  72253. destPath.lineTo (offx1, offy1);
  72254. destPath.lineTo (offx2, offy2);
  72255. destPath.lineTo (x2, y2);
  72256. }
  72257. else
  72258. {
  72259. // rounded ends
  72260. const float midx = (offx1 + offx2) * 0.5f;
  72261. const float midy = (offy1 + offy2) * 0.5f;
  72262. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72263. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72264. midx, midy);
  72265. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72266. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72267. x2, y2);
  72268. }
  72269. }
  72270. }
  72271. struct LineSection
  72272. {
  72273. LineSection() {}
  72274. LineSection (int) {}
  72275. float x1, y1, x2, y2; // original line
  72276. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72277. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72278. };
  72279. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72280. const bool isClosed,
  72281. const float width, const float maxMiterExtensionSquared,
  72282. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72283. {
  72284. jassert (subPath.size() > 0);
  72285. const LineSection& firstLine = subPath.getReference (0);
  72286. float lastX1 = firstLine.lx1;
  72287. float lastY1 = firstLine.ly1;
  72288. float lastX2 = firstLine.lx2;
  72289. float lastY2 = firstLine.ly2;
  72290. if (isClosed)
  72291. {
  72292. destPath.startNewSubPath (lastX1, lastY1);
  72293. }
  72294. else
  72295. {
  72296. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72297. addLineEnd (destPath, endStyle,
  72298. firstLine.rx2, firstLine.ry2,
  72299. lastX1, lastY1,
  72300. width);
  72301. }
  72302. int i;
  72303. for (i = 1; i < subPath.size(); ++i)
  72304. {
  72305. const LineSection& l = subPath.getReference (i);
  72306. addEdgeAndJoint (destPath, jointStyle,
  72307. maxMiterExtensionSquared, width,
  72308. lastX1, lastY1, lastX2, lastY2,
  72309. l.lx1, l.ly1, l.lx2, l.ly2,
  72310. l.x1, l.y1);
  72311. lastX1 = l.lx1;
  72312. lastY1 = l.ly1;
  72313. lastX2 = l.lx2;
  72314. lastY2 = l.ly2;
  72315. }
  72316. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72317. if (isClosed)
  72318. {
  72319. const LineSection& l = subPath.getReference (0);
  72320. addEdgeAndJoint (destPath, jointStyle,
  72321. maxMiterExtensionSquared, width,
  72322. lastX1, lastY1, lastX2, lastY2,
  72323. l.lx1, l.ly1, l.lx2, l.ly2,
  72324. l.x1, l.y1);
  72325. destPath.closeSubPath();
  72326. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72327. }
  72328. else
  72329. {
  72330. destPath.lineTo (lastX2, lastY2);
  72331. addLineEnd (destPath, endStyle,
  72332. lastX2, lastY2,
  72333. lastLine.rx1, lastLine.ry1,
  72334. width);
  72335. }
  72336. lastX1 = lastLine.rx1;
  72337. lastY1 = lastLine.ry1;
  72338. lastX2 = lastLine.rx2;
  72339. lastY2 = lastLine.ry2;
  72340. for (i = subPath.size() - 1; --i >= 0;)
  72341. {
  72342. const LineSection& l = subPath.getReference (i);
  72343. addEdgeAndJoint (destPath, jointStyle,
  72344. maxMiterExtensionSquared, width,
  72345. lastX1, lastY1, lastX2, lastY2,
  72346. l.rx1, l.ry1, l.rx2, l.ry2,
  72347. l.x2, l.y2);
  72348. lastX1 = l.rx1;
  72349. lastY1 = l.ry1;
  72350. lastX2 = l.rx2;
  72351. lastY2 = l.ry2;
  72352. }
  72353. if (isClosed)
  72354. {
  72355. addEdgeAndJoint (destPath, jointStyle,
  72356. maxMiterExtensionSquared, width,
  72357. lastX1, lastY1, lastX2, lastY2,
  72358. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72359. lastLine.x2, lastLine.y2);
  72360. }
  72361. else
  72362. {
  72363. // do the last line
  72364. destPath.lineTo (lastX2, lastY2);
  72365. }
  72366. destPath.closeSubPath();
  72367. }
  72368. }
  72369. void PathStrokeType::createStrokedPath (Path& destPath,
  72370. const Path& source,
  72371. const AffineTransform& transform,
  72372. const float extraAccuracy) const
  72373. {
  72374. if (thickness <= 0)
  72375. {
  72376. destPath.clear();
  72377. return;
  72378. }
  72379. const Path* sourcePath = &source;
  72380. Path temp;
  72381. if (sourcePath == &destPath)
  72382. {
  72383. destPath.swapWithPath (temp);
  72384. sourcePath = &temp;
  72385. }
  72386. else
  72387. {
  72388. destPath.clear();
  72389. }
  72390. destPath.setUsingNonZeroWinding (true);
  72391. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72392. const float width = 0.5f * thickness;
  72393. // Iterate the path, creating a list of the
  72394. // left/right-hand lines along either side of it...
  72395. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72396. using namespace PathFunctions;
  72397. Array <LineSection> subPath;
  72398. LineSection l;
  72399. l.x1 = 0;
  72400. l.y1 = 0;
  72401. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72402. while (it.next())
  72403. {
  72404. if (it.subPathIndex == 0)
  72405. {
  72406. if (subPath.size() > 0)
  72407. {
  72408. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72409. subPath.clearQuick();
  72410. }
  72411. l.x1 = it.x1;
  72412. l.y1 = it.y1;
  72413. }
  72414. l.x2 = it.x2;
  72415. l.y2 = it.y2;
  72416. float dx = l.x2 - l.x1;
  72417. float dy = l.y2 - l.y1;
  72418. const float hypotSquared = dx*dx + dy*dy;
  72419. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72420. {
  72421. const float len = sqrtf (hypotSquared);
  72422. if (len == 0)
  72423. {
  72424. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72425. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72426. }
  72427. else
  72428. {
  72429. const float offset = width / len;
  72430. dx *= offset;
  72431. dy *= offset;
  72432. l.rx2 = l.x1 - dy;
  72433. l.ry2 = l.y1 + dx;
  72434. l.lx1 = l.x1 + dy;
  72435. l.ly1 = l.y1 - dx;
  72436. l.lx2 = l.x2 + dy;
  72437. l.ly2 = l.y2 - dx;
  72438. l.rx1 = l.x2 - dy;
  72439. l.ry1 = l.y2 + dx;
  72440. }
  72441. subPath.add (l);
  72442. if (it.closesSubPath)
  72443. {
  72444. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72445. subPath.clearQuick();
  72446. }
  72447. else
  72448. {
  72449. l.x1 = it.x2;
  72450. l.y1 = it.y2;
  72451. }
  72452. }
  72453. }
  72454. if (subPath.size() > 0)
  72455. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72456. }
  72457. void PathStrokeType::createDashedStroke (Path& destPath,
  72458. const Path& sourcePath,
  72459. const float* dashLengths,
  72460. int numDashLengths,
  72461. const AffineTransform& transform,
  72462. const float extraAccuracy) const
  72463. {
  72464. if (thickness <= 0)
  72465. return;
  72466. // this should really be an even number..
  72467. jassert ((numDashLengths & 1) == 0);
  72468. Path newDestPath;
  72469. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72470. bool first = true;
  72471. int dashNum = 0;
  72472. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72473. float dx = 0.0f, dy = 0.0f;
  72474. for (;;)
  72475. {
  72476. const bool isSolid = ((dashNum & 1) == 0);
  72477. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72478. jassert (dashLen > 0); // must be a positive increment!
  72479. if (dashLen <= 0)
  72480. break;
  72481. pos += dashLen;
  72482. while (pos > lineEndPos)
  72483. {
  72484. if (! it.next())
  72485. {
  72486. if (isSolid && ! first)
  72487. newDestPath.lineTo (it.x2, it.y2);
  72488. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72489. return;
  72490. }
  72491. if (isSolid && ! first)
  72492. newDestPath.lineTo (it.x1, it.y1);
  72493. else
  72494. newDestPath.startNewSubPath (it.x1, it.y1);
  72495. dx = it.x2 - it.x1;
  72496. dy = it.y2 - it.y1;
  72497. lineLen = juce_hypotf (dx, dy);
  72498. lineEndPos += lineLen;
  72499. first = it.closesSubPath;
  72500. }
  72501. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72502. if (isSolid)
  72503. newDestPath.lineTo (it.x1 + dx * alpha,
  72504. it.y1 + dy * alpha);
  72505. else
  72506. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72507. it.y1 + dy * alpha);
  72508. }
  72509. }
  72510. END_JUCE_NAMESPACE
  72511. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72512. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72513. BEGIN_JUCE_NAMESPACE
  72514. PositionedRectangle::PositionedRectangle() throw()
  72515. : x (0.0),
  72516. y (0.0),
  72517. w (0.0),
  72518. h (0.0),
  72519. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72520. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72521. wMode (absoluteSize),
  72522. hMode (absoluteSize)
  72523. {
  72524. }
  72525. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72526. : x (other.x),
  72527. y (other.y),
  72528. w (other.w),
  72529. h (other.h),
  72530. xMode (other.xMode),
  72531. yMode (other.yMode),
  72532. wMode (other.wMode),
  72533. hMode (other.hMode)
  72534. {
  72535. }
  72536. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72537. {
  72538. x = other.x;
  72539. y = other.y;
  72540. w = other.w;
  72541. h = other.h;
  72542. xMode = other.xMode;
  72543. yMode = other.yMode;
  72544. wMode = other.wMode;
  72545. hMode = other.hMode;
  72546. return *this;
  72547. }
  72548. PositionedRectangle::~PositionedRectangle() throw()
  72549. {
  72550. }
  72551. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72552. {
  72553. return x == other.x
  72554. && y == other.y
  72555. && w == other.w
  72556. && h == other.h
  72557. && xMode == other.xMode
  72558. && yMode == other.yMode
  72559. && wMode == other.wMode
  72560. && hMode == other.hMode;
  72561. }
  72562. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72563. {
  72564. return ! operator== (other);
  72565. }
  72566. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72567. {
  72568. StringArray tokens;
  72569. tokens.addTokens (stringVersion, false);
  72570. decodePosString (tokens [0], xMode, x);
  72571. decodePosString (tokens [1], yMode, y);
  72572. decodeSizeString (tokens [2], wMode, w);
  72573. decodeSizeString (tokens [3], hMode, h);
  72574. }
  72575. const String PositionedRectangle::toString() const throw()
  72576. {
  72577. String s;
  72578. s.preallocateStorage (12);
  72579. addPosDescription (s, xMode, x);
  72580. s << ' ';
  72581. addPosDescription (s, yMode, y);
  72582. s << ' ';
  72583. addSizeDescription (s, wMode, w);
  72584. s << ' ';
  72585. addSizeDescription (s, hMode, h);
  72586. return s;
  72587. }
  72588. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72589. {
  72590. jassert (! target.isEmpty());
  72591. double x_, y_, w_, h_;
  72592. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72593. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72594. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72595. roundToInt (w_), roundToInt (h_));
  72596. }
  72597. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72598. double& x_, double& y_,
  72599. double& w_, double& h_) const throw()
  72600. {
  72601. jassert (! target.isEmpty());
  72602. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72603. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72604. }
  72605. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72606. {
  72607. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72608. }
  72609. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72610. const Rectangle<int>& target) throw()
  72611. {
  72612. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72613. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72614. }
  72615. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72616. const double newW, const double newH,
  72617. const Rectangle<int>& target) throw()
  72618. {
  72619. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72620. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72621. }
  72622. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72623. {
  72624. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72625. updateFrom (comp.getBounds(), Rectangle<int>());
  72626. else
  72627. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72628. }
  72629. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72630. {
  72631. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72632. }
  72633. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72634. {
  72635. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72636. | absoluteFromParentBottomRight
  72637. | absoluteFromParentCentre
  72638. | proportionOfParentSize));
  72639. }
  72640. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72641. {
  72642. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72643. }
  72644. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72645. {
  72646. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72647. | absoluteFromParentBottomRight
  72648. | absoluteFromParentCentre
  72649. | proportionOfParentSize));
  72650. }
  72651. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72652. {
  72653. return (SizeMode) wMode;
  72654. }
  72655. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72656. {
  72657. return (SizeMode) hMode;
  72658. }
  72659. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72660. const PositionMode xMode_,
  72661. const AnchorPoint yAnchor,
  72662. const PositionMode yMode_,
  72663. const SizeMode widthMode,
  72664. const SizeMode heightMode,
  72665. const Rectangle<int>& target) throw()
  72666. {
  72667. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72668. {
  72669. double tx, tw;
  72670. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72671. xMode = (uint8) (xAnchor | xMode_);
  72672. wMode = (uint8) widthMode;
  72673. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72674. }
  72675. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72676. {
  72677. double ty, th;
  72678. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72679. yMode = (uint8) (yAnchor | yMode_);
  72680. hMode = (uint8) heightMode;
  72681. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  72682. }
  72683. }
  72684. bool PositionedRectangle::isPositionAbsolute() const throw()
  72685. {
  72686. return xMode == absoluteFromParentTopLeft
  72687. && yMode == absoluteFromParentTopLeft
  72688. && wMode == absoluteSize
  72689. && hMode == absoluteSize;
  72690. }
  72691. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  72692. {
  72693. if ((mode & proportionOfParentSize) != 0)
  72694. {
  72695. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72696. }
  72697. else
  72698. {
  72699. s << (roundToInt (value * 100.0) / 100.0);
  72700. if ((mode & absoluteFromParentBottomRight) != 0)
  72701. s << 'R';
  72702. else if ((mode & absoluteFromParentCentre) != 0)
  72703. s << 'C';
  72704. }
  72705. if ((mode & anchorAtRightOrBottom) != 0)
  72706. s << 'r';
  72707. else if ((mode & anchorAtCentre) != 0)
  72708. s << 'c';
  72709. }
  72710. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  72711. {
  72712. if (mode == proportionalSize)
  72713. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72714. else if (mode == parentSizeMinusAbsolute)
  72715. s << (roundToInt (value * 100.0) / 100.0) << 'M';
  72716. else
  72717. s << (roundToInt (value * 100.0) / 100.0);
  72718. }
  72719. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  72720. {
  72721. if (s.containsChar ('r'))
  72722. mode = anchorAtRightOrBottom;
  72723. else if (s.containsChar ('c'))
  72724. mode = anchorAtCentre;
  72725. else
  72726. mode = anchorAtLeftOrTop;
  72727. if (s.containsChar ('%'))
  72728. {
  72729. mode |= proportionOfParentSize;
  72730. value = s.removeCharacters ("%rcRC").getDoubleValue() / 100.0;
  72731. }
  72732. else
  72733. {
  72734. if (s.containsChar ('R'))
  72735. mode |= absoluteFromParentBottomRight;
  72736. else if (s.containsChar ('C'))
  72737. mode |= absoluteFromParentCentre;
  72738. else
  72739. mode |= absoluteFromParentTopLeft;
  72740. value = s.removeCharacters ("rcRC").getDoubleValue();
  72741. }
  72742. }
  72743. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  72744. {
  72745. if (s.containsChar ('%'))
  72746. {
  72747. mode = proportionalSize;
  72748. value = s.upToFirstOccurrenceOf ("%", false, false).getDoubleValue() / 100.0;
  72749. }
  72750. else if (s.containsChar ('M'))
  72751. {
  72752. mode = parentSizeMinusAbsolute;
  72753. value = s.getDoubleValue();
  72754. }
  72755. else
  72756. {
  72757. mode = absoluteSize;
  72758. value = s.getDoubleValue();
  72759. }
  72760. }
  72761. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  72762. const double x_, const double w_,
  72763. const uint8 xMode_, const uint8 wMode_,
  72764. const int parentPos,
  72765. const int parentSize) const throw()
  72766. {
  72767. if (wMode_ == proportionalSize)
  72768. wOut = roundToInt (w_ * parentSize);
  72769. else if (wMode_ == parentSizeMinusAbsolute)
  72770. wOut = jmax (0, parentSize - roundToInt (w_));
  72771. else
  72772. wOut = roundToInt (w_);
  72773. if ((xMode_ & proportionOfParentSize) != 0)
  72774. xOut = parentPos + x_ * parentSize;
  72775. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72776. xOut = (parentPos + parentSize) - x_;
  72777. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72778. xOut = x_ + (parentPos + parentSize / 2);
  72779. else
  72780. xOut = x_ + parentPos;
  72781. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72782. xOut -= wOut;
  72783. else if ((xMode_ & anchorAtCentre) != 0)
  72784. xOut -= wOut / 2;
  72785. }
  72786. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  72787. double x_, const double w_,
  72788. const uint8 xMode_, const uint8 wMode_,
  72789. const int parentPos,
  72790. const int parentSize) const throw()
  72791. {
  72792. if (wMode_ == proportionalSize)
  72793. {
  72794. if (parentSize > 0)
  72795. wOut = w_ / parentSize;
  72796. }
  72797. else if (wMode_ == parentSizeMinusAbsolute)
  72798. wOut = parentSize - w_;
  72799. else
  72800. wOut = w_;
  72801. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72802. x_ += w_;
  72803. else if ((xMode_ & anchorAtCentre) != 0)
  72804. x_ += w_ / 2;
  72805. if ((xMode_ & proportionOfParentSize) != 0)
  72806. {
  72807. if (parentSize > 0)
  72808. xOut = (x_ - parentPos) / parentSize;
  72809. }
  72810. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72811. xOut = (parentPos + parentSize) - x_;
  72812. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72813. xOut = x_ - (parentPos + parentSize / 2);
  72814. else
  72815. xOut = x_ - parentPos;
  72816. }
  72817. END_JUCE_NAMESPACE
  72818. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  72819. /*** Start of inlined file: juce_RectangleList.cpp ***/
  72820. BEGIN_JUCE_NAMESPACE
  72821. RectangleList::RectangleList() throw()
  72822. {
  72823. }
  72824. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  72825. {
  72826. if (! rect.isEmpty())
  72827. rects.add (rect);
  72828. }
  72829. RectangleList::RectangleList (const RectangleList& other) throw()
  72830. : rects (other.rects)
  72831. {
  72832. }
  72833. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  72834. {
  72835. rects = other.rects;
  72836. return *this;
  72837. }
  72838. RectangleList::~RectangleList() throw()
  72839. {
  72840. }
  72841. void RectangleList::clear() throw()
  72842. {
  72843. rects.clearQuick();
  72844. }
  72845. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  72846. {
  72847. if (((unsigned int) index) < (unsigned int) rects.size())
  72848. return rects.getReference (index);
  72849. return Rectangle<int>();
  72850. }
  72851. bool RectangleList::isEmpty() const throw()
  72852. {
  72853. return rects.size() == 0;
  72854. }
  72855. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  72856. : current (0),
  72857. owner (list),
  72858. index (list.rects.size())
  72859. {
  72860. }
  72861. RectangleList::Iterator::~Iterator() throw()
  72862. {
  72863. }
  72864. bool RectangleList::Iterator::next() throw()
  72865. {
  72866. if (--index >= 0)
  72867. {
  72868. current = & (owner.rects.getReference (index));
  72869. return true;
  72870. }
  72871. return false;
  72872. }
  72873. void RectangleList::add (const Rectangle<int>& rect) throw()
  72874. {
  72875. if (! rect.isEmpty())
  72876. {
  72877. if (rects.size() == 0)
  72878. {
  72879. rects.add (rect);
  72880. }
  72881. else
  72882. {
  72883. bool anyOverlaps = false;
  72884. int i;
  72885. for (i = rects.size(); --i >= 0;)
  72886. {
  72887. Rectangle<int>& ourRect = rects.getReference (i);
  72888. if (rect.intersects (ourRect))
  72889. {
  72890. if (rect.contains (ourRect))
  72891. rects.remove (i);
  72892. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  72893. anyOverlaps = true;
  72894. }
  72895. }
  72896. if (anyOverlaps && rects.size() > 0)
  72897. {
  72898. RectangleList r (rect);
  72899. for (i = rects.size(); --i >= 0;)
  72900. {
  72901. const Rectangle<int>& ourRect = rects.getReference (i);
  72902. if (rect.intersects (ourRect))
  72903. {
  72904. r.subtract (ourRect);
  72905. if (r.rects.size() == 0)
  72906. return;
  72907. }
  72908. }
  72909. for (i = r.getNumRectangles(); --i >= 0;)
  72910. rects.add (r.rects.getReference (i));
  72911. }
  72912. else
  72913. {
  72914. rects.add (rect);
  72915. }
  72916. }
  72917. }
  72918. }
  72919. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  72920. {
  72921. rects.add (rect);
  72922. }
  72923. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  72924. {
  72925. if (rects.size() == 0)
  72926. {
  72927. if (w > 0 && h > 0)
  72928. rects.add (Rectangle<int> (x, y, w, h));
  72929. }
  72930. else
  72931. {
  72932. add (Rectangle<int> (x, y, w, h));
  72933. }
  72934. }
  72935. void RectangleList::add (const RectangleList& other) throw()
  72936. {
  72937. for (int i = 0; i < other.rects.size(); ++i)
  72938. add (other.rects.getReference (i));
  72939. }
  72940. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  72941. {
  72942. const int originalNumRects = rects.size();
  72943. if (originalNumRects > 0)
  72944. {
  72945. const int x1 = rect.x;
  72946. const int y1 = rect.y;
  72947. const int x2 = x1 + rect.w;
  72948. const int y2 = y1 + rect.h;
  72949. for (int i = getNumRectangles(); --i >= 0;)
  72950. {
  72951. Rectangle<int>& r = rects.getReference (i);
  72952. const int rx1 = r.x;
  72953. const int ry1 = r.y;
  72954. const int rx2 = rx1 + r.w;
  72955. const int ry2 = ry1 + r.h;
  72956. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  72957. {
  72958. if (x1 > rx1 && x1 < rx2)
  72959. {
  72960. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  72961. {
  72962. r.w = x1 - rx1;
  72963. }
  72964. else
  72965. {
  72966. r.x = x1;
  72967. r.w = rx2 - x1;
  72968. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  72969. i += 2;
  72970. }
  72971. }
  72972. else if (x2 > rx1 && x2 < rx2)
  72973. {
  72974. r.x = x2;
  72975. r.w = rx2 - x2;
  72976. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  72977. {
  72978. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  72979. i += 2;
  72980. }
  72981. }
  72982. else if (y1 > ry1 && y1 < ry2)
  72983. {
  72984. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  72985. {
  72986. r.h = y1 - ry1;
  72987. }
  72988. else
  72989. {
  72990. r.y = y1;
  72991. r.h = ry2 - y1;
  72992. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  72993. i += 2;
  72994. }
  72995. }
  72996. else if (y2 > ry1 && y2 < ry2)
  72997. {
  72998. r.y = y2;
  72999. r.h = ry2 - y2;
  73000. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73001. {
  73002. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73003. i += 2;
  73004. }
  73005. }
  73006. else
  73007. {
  73008. rects.remove (i);
  73009. }
  73010. }
  73011. }
  73012. if (rects.size() > originalNumRects + 10)
  73013. consolidate();
  73014. }
  73015. }
  73016. void RectangleList::subtract (const RectangleList& otherList) throw()
  73017. {
  73018. for (int i = otherList.rects.size(); --i >= 0;)
  73019. subtract (otherList.rects.getReference (i));
  73020. }
  73021. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73022. {
  73023. bool notEmpty = false;
  73024. if (rect.isEmpty())
  73025. {
  73026. clear();
  73027. }
  73028. else
  73029. {
  73030. for (int i = rects.size(); --i >= 0;)
  73031. {
  73032. Rectangle<int>& r = rects.getReference (i);
  73033. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73034. rects.remove (i);
  73035. else
  73036. notEmpty = true;
  73037. }
  73038. }
  73039. return notEmpty;
  73040. }
  73041. bool RectangleList::clipTo (const RectangleList& other) throw()
  73042. {
  73043. if (rects.size() == 0)
  73044. return false;
  73045. RectangleList result;
  73046. for (int j = 0; j < rects.size(); ++j)
  73047. {
  73048. const Rectangle<int>& rect = rects.getReference (j);
  73049. for (int i = other.rects.size(); --i >= 0;)
  73050. {
  73051. Rectangle<int> r (other.rects.getReference (i));
  73052. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73053. result.rects.add (r);
  73054. }
  73055. }
  73056. swapWith (result);
  73057. return ! isEmpty();
  73058. }
  73059. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73060. {
  73061. destRegion.clear();
  73062. if (! rect.isEmpty())
  73063. {
  73064. for (int i = rects.size(); --i >= 0;)
  73065. {
  73066. Rectangle<int> r (rects.getReference (i));
  73067. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73068. destRegion.rects.add (r);
  73069. }
  73070. }
  73071. return destRegion.rects.size() > 0;
  73072. }
  73073. void RectangleList::swapWith (RectangleList& otherList) throw()
  73074. {
  73075. rects.swapWithArray (otherList.rects);
  73076. }
  73077. void RectangleList::consolidate() throw()
  73078. {
  73079. int i;
  73080. for (i = 0; i < getNumRectangles() - 1; ++i)
  73081. {
  73082. Rectangle<int>& r = rects.getReference (i);
  73083. const int rx1 = r.x;
  73084. const int ry1 = r.y;
  73085. const int rx2 = rx1 + r.w;
  73086. const int ry2 = ry1 + r.h;
  73087. for (int j = rects.size(); --j > i;)
  73088. {
  73089. Rectangle<int>& r2 = rects.getReference (j);
  73090. const int jrx1 = r2.x;
  73091. const int jry1 = r2.y;
  73092. const int jrx2 = jrx1 + r2.w;
  73093. const int jry2 = jry1 + r2.h;
  73094. // if the vertical edges of any blocks are touching and their horizontals don't
  73095. // line up, split them horizontally..
  73096. if (jrx1 == rx2 || jrx2 == rx1)
  73097. {
  73098. if (jry1 > ry1 && jry1 < ry2)
  73099. {
  73100. r.h = jry1 - ry1;
  73101. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73102. i = -1;
  73103. break;
  73104. }
  73105. if (jry2 > ry1 && jry2 < ry2)
  73106. {
  73107. r.h = jry2 - ry1;
  73108. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73109. i = -1;
  73110. break;
  73111. }
  73112. else if (ry1 > jry1 && ry1 < jry2)
  73113. {
  73114. r2.h = ry1 - jry1;
  73115. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73116. i = -1;
  73117. break;
  73118. }
  73119. else if (ry2 > jry1 && ry2 < jry2)
  73120. {
  73121. r2.h = ry2 - jry1;
  73122. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73123. i = -1;
  73124. break;
  73125. }
  73126. }
  73127. }
  73128. }
  73129. for (i = 0; i < rects.size() - 1; ++i)
  73130. {
  73131. Rectangle<int>& r = rects.getReference (i);
  73132. for (int j = rects.size(); --j > i;)
  73133. {
  73134. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73135. {
  73136. rects.remove (j);
  73137. i = -1;
  73138. break;
  73139. }
  73140. }
  73141. }
  73142. }
  73143. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73144. {
  73145. for (int i = getNumRectangles(); --i >= 0;)
  73146. if (rects.getReference (i).contains (x, y))
  73147. return true;
  73148. return false;
  73149. }
  73150. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73151. {
  73152. if (rects.size() > 1)
  73153. {
  73154. RectangleList r (rectangleToCheck);
  73155. for (int i = rects.size(); --i >= 0;)
  73156. {
  73157. r.subtract (rects.getReference (i));
  73158. if (r.rects.size() == 0)
  73159. return true;
  73160. }
  73161. }
  73162. else if (rects.size() > 0)
  73163. {
  73164. return rects.getReference (0).contains (rectangleToCheck);
  73165. }
  73166. return false;
  73167. }
  73168. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73169. {
  73170. for (int i = rects.size(); --i >= 0;)
  73171. if (rects.getReference (i).intersects (rectangleToCheck))
  73172. return true;
  73173. return false;
  73174. }
  73175. bool RectangleList::intersects (const RectangleList& other) const throw()
  73176. {
  73177. for (int i = rects.size(); --i >= 0;)
  73178. if (other.intersectsRectangle (rects.getReference (i)))
  73179. return true;
  73180. return false;
  73181. }
  73182. const Rectangle<int> RectangleList::getBounds() const throw()
  73183. {
  73184. if (rects.size() <= 1)
  73185. {
  73186. if (rects.size() == 0)
  73187. return Rectangle<int>();
  73188. else
  73189. return rects.getReference (0);
  73190. }
  73191. else
  73192. {
  73193. const Rectangle<int>& r = rects.getReference (0);
  73194. int minX = r.x;
  73195. int minY = r.y;
  73196. int maxX = minX + r.w;
  73197. int maxY = minY + r.h;
  73198. for (int i = rects.size(); --i > 0;)
  73199. {
  73200. const Rectangle<int>& r2 = rects.getReference (i);
  73201. minX = jmin (minX, r2.x);
  73202. minY = jmin (minY, r2.y);
  73203. maxX = jmax (maxX, r2.getRight());
  73204. maxY = jmax (maxY, r2.getBottom());
  73205. }
  73206. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73207. }
  73208. }
  73209. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73210. {
  73211. for (int i = rects.size(); --i >= 0;)
  73212. {
  73213. Rectangle<int>& r = rects.getReference (i);
  73214. r.x += dx;
  73215. r.y += dy;
  73216. }
  73217. }
  73218. const Path RectangleList::toPath() const throw()
  73219. {
  73220. Path p;
  73221. for (int i = rects.size(); --i >= 0;)
  73222. {
  73223. const Rectangle<int>& r = rects.getReference (i);
  73224. p.addRectangle ((float) r.x,
  73225. (float) r.y,
  73226. (float) r.w,
  73227. (float) r.h);
  73228. }
  73229. return p;
  73230. }
  73231. END_JUCE_NAMESPACE
  73232. /*** End of inlined file: juce_RectangleList.cpp ***/
  73233. /*** Start of inlined file: juce_Image.cpp ***/
  73234. BEGIN_JUCE_NAMESPACE
  73235. static const int fullAlphaThreshold = 253;
  73236. Image::Image (const PixelFormat format_,
  73237. const int imageWidth_,
  73238. const int imageHeight_)
  73239. : format (format_),
  73240. imageWidth (imageWidth_),
  73241. imageHeight (imageHeight_),
  73242. imageData (0)
  73243. {
  73244. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73245. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73246. // actual image will be at least 1x1.
  73247. }
  73248. Image::Image (const PixelFormat format_,
  73249. const int imageWidth_,
  73250. const int imageHeight_,
  73251. const bool clearImage)
  73252. : format (format_),
  73253. imageWidth (imageWidth_),
  73254. imageHeight (imageHeight_)
  73255. {
  73256. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73257. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73258. // actual image will be at least 1x1.
  73259. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73260. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73261. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73262. imageData = imageDataAllocated;
  73263. }
  73264. Image::Image (const Image& other)
  73265. : format (other.format),
  73266. imageWidth (other.imageWidth),
  73267. imageHeight (other.imageHeight)
  73268. {
  73269. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73270. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73271. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73272. imageData = imageDataAllocated;
  73273. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73274. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73275. }
  73276. Image::~Image()
  73277. {
  73278. }
  73279. LowLevelGraphicsContext* Image::createLowLevelContext()
  73280. {
  73281. return new LowLevelGraphicsSoftwareRenderer (*this);
  73282. }
  73283. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73284. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73285. lineStride (image.lineStride),
  73286. pixelStride (image.pixelStride),
  73287. width (w),
  73288. height (h)
  73289. {
  73290. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73291. }
  73292. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73293. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73294. lineStride (image.lineStride),
  73295. pixelStride (image.pixelStride),
  73296. width (w),
  73297. height (h)
  73298. {
  73299. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73300. }
  73301. Image::BitmapData::~BitmapData()
  73302. {
  73303. }
  73304. void Image::setPixelData (int x, int y, int w, int h,
  73305. const uint8* sourcePixelData, int sourceLineStride)
  73306. {
  73307. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73308. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73309. {
  73310. const BitmapData dest (*this, x, y, w, h, true);
  73311. for (int i = 0; i < h; ++i)
  73312. {
  73313. memcpy (dest.getLinePointer(i),
  73314. sourcePixelData + sourceLineStride * i,
  73315. w * dest.pixelStride);
  73316. }
  73317. }
  73318. }
  73319. void Image::clear (int dx, int dy, int dw, int dh, const Colour& colourToClearTo)
  73320. {
  73321. if (Rectangle<int>::intersectRectangles (dx, dy, dw, dh, 0, 0, imageWidth, imageHeight))
  73322. {
  73323. const PixelARGB col (colourToClearTo.getPixelARGB());
  73324. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73325. uint8* dest = destData.data;
  73326. while (--dh >= 0)
  73327. {
  73328. uint8* line = dest;
  73329. dest += destData.lineStride;
  73330. if (isARGB())
  73331. {
  73332. for (int x = dw; --x >= 0;)
  73333. {
  73334. ((PixelARGB*) line)->set (col);
  73335. line += destData.pixelStride;
  73336. }
  73337. }
  73338. else if (isRGB())
  73339. {
  73340. for (int x = dw; --x >= 0;)
  73341. {
  73342. ((PixelRGB*) line)->set (col);
  73343. line += destData.pixelStride;
  73344. }
  73345. }
  73346. else
  73347. {
  73348. for (int x = dw; --x >= 0;)
  73349. {
  73350. *line = col.getAlpha();
  73351. line += destData.pixelStride;
  73352. }
  73353. }
  73354. }
  73355. }
  73356. }
  73357. Image* Image::createCopy (int newWidth, int newHeight,
  73358. const Graphics::ResamplingQuality quality) const
  73359. {
  73360. if (newWidth < 0)
  73361. newWidth = imageWidth;
  73362. if (newHeight < 0)
  73363. newHeight = imageHeight;
  73364. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73365. Graphics g (*newImage);
  73366. g.setImageResamplingQuality (quality);
  73367. g.drawImage (this,
  73368. 0, 0, newWidth, newHeight,
  73369. 0, 0, imageWidth, imageHeight,
  73370. false);
  73371. return newImage;
  73372. }
  73373. Image* Image::createCopyOfAlphaChannel() const
  73374. {
  73375. jassert (format != SingleChannel);
  73376. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73377. if (! hasAlphaChannel())
  73378. {
  73379. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73380. }
  73381. else
  73382. {
  73383. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73384. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73385. for (int y = 0; y < imageHeight; ++y)
  73386. {
  73387. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73388. uint8* dst = destData.getLinePointer (y);
  73389. for (int x = imageWidth; --x >= 0;)
  73390. {
  73391. *dst++ = src->getAlpha();
  73392. ++src;
  73393. }
  73394. }
  73395. }
  73396. return newImage;
  73397. }
  73398. const Colour Image::getPixelAt (const int x, const int y) const
  73399. {
  73400. Colour c;
  73401. if (((unsigned int) x) < (unsigned int) imageWidth
  73402. && ((unsigned int) y) < (unsigned int) imageHeight)
  73403. {
  73404. const BitmapData srcData (*this, x, y, 1, 1);
  73405. if (isARGB())
  73406. {
  73407. PixelARGB p (*(const PixelARGB*) srcData.data);
  73408. p.unpremultiply();
  73409. c = Colour (p.getARGB());
  73410. }
  73411. else if (isRGB())
  73412. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73413. else
  73414. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73415. }
  73416. return c;
  73417. }
  73418. void Image::setPixelAt (const int x, const int y,
  73419. const Colour& colour)
  73420. {
  73421. if (((unsigned int) x) < (unsigned int) imageWidth
  73422. && ((unsigned int) y) < (unsigned int) imageHeight)
  73423. {
  73424. const BitmapData destData (*this, x, y, 1, 1, true);
  73425. const PixelARGB col (colour.getPixelARGB());
  73426. if (isARGB())
  73427. ((PixelARGB*) destData.data)->set (col);
  73428. else if (isRGB())
  73429. ((PixelRGB*) destData.data)->set (col);
  73430. else
  73431. *(destData.data) = col.getAlpha();
  73432. }
  73433. }
  73434. void Image::multiplyAlphaAt (const int x, const int y,
  73435. const float multiplier)
  73436. {
  73437. if (((unsigned int) x) < (unsigned int) imageWidth
  73438. && ((unsigned int) y) < (unsigned int) imageHeight
  73439. && hasAlphaChannel())
  73440. {
  73441. const BitmapData destData (*this, x, y, 1, 1, true);
  73442. if (isARGB())
  73443. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73444. else
  73445. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73446. }
  73447. }
  73448. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73449. {
  73450. if (hasAlphaChannel())
  73451. {
  73452. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73453. if (isARGB())
  73454. {
  73455. for (int y = 0; y < imageHeight; ++y)
  73456. {
  73457. uint8* p = destData.getLinePointer (y);
  73458. for (int x = 0; x < imageWidth; ++x)
  73459. {
  73460. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73461. p += destData.pixelStride;
  73462. }
  73463. }
  73464. }
  73465. else
  73466. {
  73467. for (int y = 0; y < imageHeight; ++y)
  73468. {
  73469. uint8* p = destData.getLinePointer (y);
  73470. for (int x = 0; x < imageWidth; ++x)
  73471. {
  73472. *p = (uint8) (*p * amountToMultiplyBy);
  73473. p += destData.pixelStride;
  73474. }
  73475. }
  73476. }
  73477. }
  73478. else
  73479. {
  73480. jassertfalse // can't do this without an alpha-channel!
  73481. }
  73482. }
  73483. void Image::desaturate()
  73484. {
  73485. if (isARGB() || isRGB())
  73486. {
  73487. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73488. if (isARGB())
  73489. {
  73490. for (int y = 0; y < imageHeight; ++y)
  73491. {
  73492. uint8* p = destData.getLinePointer (y);
  73493. for (int x = 0; x < imageWidth; ++x)
  73494. {
  73495. ((PixelARGB*) p)->desaturate();
  73496. p += destData.pixelStride;
  73497. }
  73498. }
  73499. }
  73500. else
  73501. {
  73502. for (int y = 0; y < imageHeight; ++y)
  73503. {
  73504. uint8* p = destData.getLinePointer (y);
  73505. for (int x = 0; x < imageWidth; ++x)
  73506. {
  73507. ((PixelRGB*) p)->desaturate();
  73508. p += destData.pixelStride;
  73509. }
  73510. }
  73511. }
  73512. }
  73513. }
  73514. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73515. {
  73516. if (hasAlphaChannel())
  73517. {
  73518. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73519. SparseSet<int> pixelsOnRow;
  73520. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73521. for (int y = 0; y < imageHeight; ++y)
  73522. {
  73523. pixelsOnRow.clear();
  73524. const uint8* lineData = srcData.getLinePointer (y);
  73525. if (isARGB())
  73526. {
  73527. for (int x = 0; x < imageWidth; ++x)
  73528. {
  73529. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73530. pixelsOnRow.addRange (Range<int> (x, x + 1));
  73531. lineData += srcData.pixelStride;
  73532. }
  73533. }
  73534. else
  73535. {
  73536. for (int x = 0; x < imageWidth; ++x)
  73537. {
  73538. if (*lineData >= threshold)
  73539. pixelsOnRow.addRange (Range<int> (x, x + 1));
  73540. lineData += srcData.pixelStride;
  73541. }
  73542. }
  73543. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73544. {
  73545. const Range<int> range (pixelsOnRow.getRange (i));
  73546. result.add (Rectangle<int> (range.getStart(), y, range.getLength(), 1));
  73547. }
  73548. result.consolidate();
  73549. }
  73550. }
  73551. else
  73552. {
  73553. result.add (0, 0, imageWidth, imageHeight);
  73554. }
  73555. }
  73556. void Image::moveImageSection (int dx, int dy,
  73557. int sx, int sy,
  73558. int w, int h)
  73559. {
  73560. if (dx < 0)
  73561. {
  73562. w += dx;
  73563. sx -= dx;
  73564. dx = 0;
  73565. }
  73566. if (dy < 0)
  73567. {
  73568. h += dy;
  73569. sy -= dy;
  73570. dy = 0;
  73571. }
  73572. if (sx < 0)
  73573. {
  73574. w += sx;
  73575. dx -= sx;
  73576. sx = 0;
  73577. }
  73578. if (sy < 0)
  73579. {
  73580. h += sy;
  73581. dy -= sy;
  73582. sy = 0;
  73583. }
  73584. const int minX = jmin (dx, sx);
  73585. const int minY = jmin (dy, sy);
  73586. w = jmin (w, getWidth() - jmax (sx, dx));
  73587. h = jmin (h, getHeight() - jmax (sy, dy));
  73588. if (w > 0 && h > 0)
  73589. {
  73590. const int maxX = jmax (dx, sx) + w;
  73591. const int maxY = jmax (dy, sy) + h;
  73592. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73593. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73594. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73595. const int lineSize = destData.pixelStride * w;
  73596. if (dy > sy)
  73597. {
  73598. while (--h >= 0)
  73599. {
  73600. const int offset = h * destData.lineStride;
  73601. memmove (dst + offset, src + offset, lineSize);
  73602. }
  73603. }
  73604. else if (dst != src)
  73605. {
  73606. while (--h >= 0)
  73607. {
  73608. memmove (dst, src, lineSize);
  73609. dst += destData.lineStride;
  73610. src += destData.lineStride;
  73611. }
  73612. }
  73613. }
  73614. }
  73615. END_JUCE_NAMESPACE
  73616. /*** End of inlined file: juce_Image.cpp ***/
  73617. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73618. BEGIN_JUCE_NAMESPACE
  73619. struct ImageCache::Item
  73620. {
  73621. ScopedPointer <Image> image;
  73622. int64 hashCode;
  73623. int refCount;
  73624. uint32 releaseTime;
  73625. juce_UseDebuggingNewOperator
  73626. };
  73627. ImageCache* ImageCache::instance = 0;
  73628. int ImageCache::cacheTimeout = 5000;
  73629. ImageCache::ImageCache()
  73630. {
  73631. }
  73632. ImageCache::~ImageCache()
  73633. {
  73634. jassert (instance == this);
  73635. instance = 0;
  73636. }
  73637. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73638. {
  73639. if (instance != 0)
  73640. {
  73641. const ScopedLock sl (instance->lock);
  73642. for (int i = instance->images.size(); --i >= 0;)
  73643. {
  73644. Item* const ci = instance->images.getUnchecked(i);
  73645. if (ci->hashCode == hashCode)
  73646. {
  73647. ci->refCount++;
  73648. return ci->image;
  73649. }
  73650. }
  73651. }
  73652. return 0;
  73653. }
  73654. void ImageCache::addImageToCache (Image* const image, const int64 hashCode)
  73655. {
  73656. if (image != 0)
  73657. {
  73658. if (instance == 0)
  73659. instance = new ImageCache();
  73660. Item* const newC = new Item();
  73661. newC->hashCode = hashCode;
  73662. newC->image = image;
  73663. newC->refCount = 1;
  73664. newC->releaseTime = 0;
  73665. const ScopedLock sl (instance->lock);
  73666. instance->images.add (newC);
  73667. }
  73668. }
  73669. void ImageCache::release (Image* const imageToRelease)
  73670. {
  73671. if (imageToRelease != 0 && instance != 0)
  73672. {
  73673. const ScopedLock sl (instance->lock);
  73674. for (int i = instance->images.size(); --i >= 0;)
  73675. {
  73676. Item* const ci = instance->images.getUnchecked(i);
  73677. if (static_cast <Image*> (ci->image) == imageToRelease)
  73678. {
  73679. if (--(ci->refCount) == 0)
  73680. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73681. if (! instance->isTimerRunning())
  73682. instance->startTimer (999);
  73683. break;
  73684. }
  73685. }
  73686. }
  73687. }
  73688. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  73689. {
  73690. if (isImageInCache (imageToRelease))
  73691. release (imageToRelease);
  73692. else
  73693. delete imageToRelease;
  73694. }
  73695. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  73696. {
  73697. if (instance != 0)
  73698. {
  73699. const ScopedLock sl (instance->lock);
  73700. for (int i = instance->images.size(); --i >= 0;)
  73701. if (static_cast <Image*> (instance->images.getUnchecked(i)->image) == imageToLookFor)
  73702. return true;
  73703. }
  73704. return false;
  73705. }
  73706. void ImageCache::incReferenceCount (Image* const image)
  73707. {
  73708. if (instance != 0)
  73709. {
  73710. const ScopedLock sl (instance->lock);
  73711. for (int i = instance->images.size(); --i >= 0;)
  73712. {
  73713. Item* const ci = instance->images.getUnchecked(i);
  73714. if (static_cast <Image*> (ci->image) == image)
  73715. {
  73716. ci->refCount++;
  73717. return;
  73718. }
  73719. }
  73720. }
  73721. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  73722. }
  73723. void ImageCache::timerCallback()
  73724. {
  73725. int numberStillNeedingReleasing = 0;
  73726. const uint32 now = Time::getApproximateMillisecondCounter();
  73727. const ScopedLock sl (lock);
  73728. for (int i = images.size(); --i >= 0;)
  73729. {
  73730. Item* const ci = images.getUnchecked(i);
  73731. if (ci->refCount <= 0)
  73732. {
  73733. if (now > ci->releaseTime + cacheTimeout
  73734. || now < ci->releaseTime - 1000)
  73735. {
  73736. images.remove (i);
  73737. }
  73738. else
  73739. {
  73740. ++numberStillNeedingReleasing;
  73741. }
  73742. }
  73743. }
  73744. if (numberStillNeedingReleasing == 0)
  73745. stopTimer();
  73746. }
  73747. Image* ImageCache::getFromFile (const File& file)
  73748. {
  73749. const int64 hashCode = file.hashCode64();
  73750. Image* image = getFromHashCode (hashCode);
  73751. if (image == 0)
  73752. {
  73753. image = ImageFileFormat::loadFrom (file);
  73754. addImageToCache (image, hashCode);
  73755. }
  73756. return image;
  73757. }
  73758. Image* ImageCache::getFromMemory (const void* imageData, const int dataSize)
  73759. {
  73760. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  73761. Image* image = getFromHashCode (hashCode);
  73762. if (image == 0)
  73763. {
  73764. image = ImageFileFormat::loadFrom (imageData, dataSize);
  73765. addImageToCache (image, hashCode);
  73766. }
  73767. return image;
  73768. }
  73769. void ImageCache::setCacheTimeout (const int millisecs)
  73770. {
  73771. cacheTimeout = millisecs;
  73772. }
  73773. END_JUCE_NAMESPACE
  73774. /*** End of inlined file: juce_ImageCache.cpp ***/
  73775. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  73776. BEGIN_JUCE_NAMESPACE
  73777. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  73778. : values (size_ * size_),
  73779. size (size_)
  73780. {
  73781. clear();
  73782. }
  73783. ImageConvolutionKernel::~ImageConvolutionKernel()
  73784. {
  73785. }
  73786. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  73787. {
  73788. if (((unsigned int) x) < (unsigned int) size
  73789. && ((unsigned int) y) < (unsigned int) size)
  73790. {
  73791. return values [x + y * size];
  73792. }
  73793. else
  73794. {
  73795. jassertfalse;
  73796. return 0;
  73797. }
  73798. }
  73799. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  73800. {
  73801. if (((unsigned int) x) < (unsigned int) size
  73802. && ((unsigned int) y) < (unsigned int) size)
  73803. {
  73804. values [x + y * size] = value;
  73805. }
  73806. else
  73807. {
  73808. jassertfalse;
  73809. }
  73810. }
  73811. void ImageConvolutionKernel::clear()
  73812. {
  73813. for (int i = size * size; --i >= 0;)
  73814. values[i] = 0;
  73815. }
  73816. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  73817. {
  73818. double currentTotal = 0.0;
  73819. for (int i = size * size; --i >= 0;)
  73820. currentTotal += values[i];
  73821. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  73822. }
  73823. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  73824. {
  73825. for (int i = size * size; --i >= 0;)
  73826. values[i] *= multiplier;
  73827. }
  73828. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  73829. {
  73830. const double radiusFactor = -1.0 / (radius * radius * 2);
  73831. const int centre = size >> 1;
  73832. for (int y = size; --y >= 0;)
  73833. {
  73834. for (int x = size; --x >= 0;)
  73835. {
  73836. const int cx = x - centre;
  73837. const int cy = y - centre;
  73838. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  73839. }
  73840. }
  73841. setOverallSum (1.0f);
  73842. }
  73843. void ImageConvolutionKernel::applyToImage (Image& destImage,
  73844. const Image* sourceImage,
  73845. const Rectangle<int>& destinationArea) const
  73846. {
  73847. ScopedPointer <Image> imageCreated;
  73848. if (sourceImage == 0)
  73849. {
  73850. sourceImage = imageCreated = destImage.createCopy();
  73851. }
  73852. else
  73853. {
  73854. jassert (sourceImage->getWidth() == destImage.getWidth()
  73855. && sourceImage->getHeight() == destImage.getHeight()
  73856. && sourceImage->getFormat() == destImage.getFormat());
  73857. if (sourceImage->getWidth() != destImage.getWidth()
  73858. || sourceImage->getHeight() != destImage.getHeight()
  73859. || sourceImage->getFormat() != destImage.getFormat())
  73860. return;
  73861. }
  73862. const Rectangle<int> area (destinationArea.getIntersection (destImage.getBounds()));
  73863. if (area.isEmpty())
  73864. return;
  73865. const int right = area.getRight();
  73866. const int bottom = area.getBottom();
  73867. const Image::BitmapData destData (destImage, area.getX(), area.getY(), area.getWidth(), area.getHeight(), true);
  73868. uint8* line = destData.data;
  73869. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  73870. if (destData.pixelStride == 4)
  73871. {
  73872. for (int y = area.getY(); y < bottom; ++y)
  73873. {
  73874. uint8* dest = line;
  73875. line += destData.lineStride;
  73876. for (int x = area.getX(); x < right; ++x)
  73877. {
  73878. float c1 = 0;
  73879. float c2 = 0;
  73880. float c3 = 0;
  73881. float c4 = 0;
  73882. for (int yy = 0; yy < size; ++yy)
  73883. {
  73884. const int sy = y + yy - (size >> 1);
  73885. if (sy >= srcData.height)
  73886. break;
  73887. if (sy >= 0)
  73888. {
  73889. int sx = x - (size >> 1);
  73890. const uint8* src = srcData.getPixelPointer (sx, sy);
  73891. for (int xx = 0; xx < size; ++xx)
  73892. {
  73893. if (sx >= srcData.width)
  73894. break;
  73895. if (sx >= 0)
  73896. {
  73897. const float kernelMult = values [xx + yy * size];
  73898. c1 += kernelMult * *src++;
  73899. c2 += kernelMult * *src++;
  73900. c3 += kernelMult * *src++;
  73901. c4 += kernelMult * *src++;
  73902. }
  73903. else
  73904. {
  73905. src += 4;
  73906. }
  73907. ++sx;
  73908. }
  73909. }
  73910. }
  73911. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  73912. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  73913. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  73914. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  73915. }
  73916. }
  73917. }
  73918. else if (destData.pixelStride == 3)
  73919. {
  73920. for (int y = area.getY(); y < bottom; ++y)
  73921. {
  73922. uint8* dest = line;
  73923. line += destData.lineStride;
  73924. for (int x = area.getX(); x < right; ++x)
  73925. {
  73926. float c1 = 0;
  73927. float c2 = 0;
  73928. float c3 = 0;
  73929. for (int yy = 0; yy < size; ++yy)
  73930. {
  73931. const int sy = y + yy - (size >> 1);
  73932. if (sy >= srcData.height)
  73933. break;
  73934. if (sy >= 0)
  73935. {
  73936. int sx = x - (size >> 1);
  73937. const uint8* src = srcData.getPixelPointer (sx, sy);
  73938. for (int xx = 0; xx < size; ++xx)
  73939. {
  73940. if (sx >= srcData.width)
  73941. break;
  73942. if (sx >= 0)
  73943. {
  73944. const float kernelMult = values [xx + yy * size];
  73945. c1 += kernelMult * *src++;
  73946. c2 += kernelMult * *src++;
  73947. c3 += kernelMult * *src++;
  73948. }
  73949. else
  73950. {
  73951. src += 3;
  73952. }
  73953. ++sx;
  73954. }
  73955. }
  73956. }
  73957. *dest++ = (uint8) roundToInt (c1);
  73958. *dest++ = (uint8) roundToInt (c2);
  73959. *dest++ = (uint8) roundToInt (c3);
  73960. }
  73961. }
  73962. }
  73963. }
  73964. END_JUCE_NAMESPACE
  73965. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  73966. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  73967. BEGIN_JUCE_NAMESPACE
  73968. /*** Start of inlined file: juce_GIFLoader.h ***/
  73969. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  73970. #define __JUCE_GIFLOADER_JUCEHEADER__
  73971. #ifndef DOXYGEN
  73972. class GIFLoader
  73973. {
  73974. public:
  73975. GIFLoader (InputStream& in);
  73976. ~GIFLoader();
  73977. Image* getImage() const { return image; }
  73978. private:
  73979. Image* image;
  73980. InputStream& input;
  73981. uint8 buffer [300];
  73982. uint8 palette [256][4];
  73983. bool dataBlockIsZero, fresh, finished;
  73984. int currentBit, lastBit, lastByteIndex;
  73985. int codeSize, setCodeSize;
  73986. int maxCode, maxCodeSize;
  73987. int firstcode, oldcode;
  73988. int clearCode, end_code;
  73989. enum { maxGifCode = 1 << 12 };
  73990. int table [2] [maxGifCode];
  73991. int stack [2 * maxGifCode];
  73992. int *sp;
  73993. bool getSizeFromHeader (int& width, int& height);
  73994. bool readPalette (const int numCols);
  73995. int readDataBlock (unsigned char* dest);
  73996. int processExtension (int type, int& transparent);
  73997. int readLZWByte (bool initialise, int input_code_size);
  73998. int getCode (int code_size, bool initialise);
  73999. bool readImage (int width, int height, int interlace, int transparent);
  74000. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74001. GIFLoader (const GIFLoader&);
  74002. GIFLoader& operator= (const GIFLoader&);
  74003. };
  74004. #endif // DOXYGEN
  74005. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74006. /*** End of inlined file: juce_GIFLoader.h ***/
  74007. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74008. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74009. PNGImageFormat::PNGImageFormat() {}
  74010. PNGImageFormat::~PNGImageFormat() {}
  74011. const String PNGImageFormat::getFormatName()
  74012. {
  74013. return "PNG";
  74014. }
  74015. bool PNGImageFormat::canUnderstand (InputStream& in)
  74016. {
  74017. const int bytesNeeded = 4;
  74018. char header [bytesNeeded];
  74019. return in.read (header, bytesNeeded) == bytesNeeded
  74020. && header[1] == 'P'
  74021. && header[2] == 'N'
  74022. && header[3] == 'G';
  74023. }
  74024. Image* PNGImageFormat::decodeImage (InputStream& in)
  74025. {
  74026. return juce_loadPNGImageFromStream (in);
  74027. }
  74028. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74029. OutputStream& destStream)
  74030. {
  74031. return juce_writePNGImageToStream (sourceImage, destStream);
  74032. }
  74033. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74034. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74035. JPEGImageFormat::JPEGImageFormat()
  74036. : quality (-1.0f)
  74037. {
  74038. }
  74039. JPEGImageFormat::~JPEGImageFormat() {}
  74040. void JPEGImageFormat::setQuality (const float newQuality)
  74041. {
  74042. quality = newQuality;
  74043. }
  74044. const String JPEGImageFormat::getFormatName()
  74045. {
  74046. return "JPEG";
  74047. }
  74048. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74049. {
  74050. const int bytesNeeded = 10;
  74051. uint8 header [bytesNeeded];
  74052. if (in.read (header, bytesNeeded) == bytesNeeded)
  74053. {
  74054. return header[0] == 0xff
  74055. && header[1] == 0xd8
  74056. && header[2] == 0xff
  74057. && (header[3] == 0xe0 || header[3] == 0xe1);
  74058. }
  74059. return false;
  74060. }
  74061. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74062. {
  74063. return juce_loadJPEGImageFromStream (in);
  74064. }
  74065. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74066. OutputStream& destStream)
  74067. {
  74068. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74069. }
  74070. class GIFImageFormat : public ImageFileFormat
  74071. {
  74072. public:
  74073. GIFImageFormat() {}
  74074. ~GIFImageFormat() {}
  74075. const String getFormatName()
  74076. {
  74077. return "GIF";
  74078. }
  74079. bool canUnderstand (InputStream& in)
  74080. {
  74081. const int bytesNeeded = 4;
  74082. char header [bytesNeeded];
  74083. return (in.read (header, bytesNeeded) == bytesNeeded)
  74084. && header[0] == 'G'
  74085. && header[1] == 'I'
  74086. && header[2] == 'F';
  74087. }
  74088. Image* decodeImage (InputStream& in)
  74089. {
  74090. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74091. return loader->getImage();
  74092. }
  74093. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74094. {
  74095. return false;
  74096. }
  74097. };
  74098. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74099. {
  74100. static PNGImageFormat png;
  74101. static JPEGImageFormat jpg;
  74102. static GIFImageFormat gif;
  74103. ImageFileFormat* formats[4];
  74104. int numFormats = 0;
  74105. formats [numFormats++] = &png;
  74106. formats [numFormats++] = &jpg;
  74107. formats [numFormats++] = &gif;
  74108. const int64 streamPos = input.getPosition();
  74109. for (int i = 0; i < numFormats; ++i)
  74110. {
  74111. const bool found = formats[i]->canUnderstand (input);
  74112. input.setPosition (streamPos);
  74113. if (found)
  74114. return formats[i];
  74115. }
  74116. return 0;
  74117. }
  74118. Image* ImageFileFormat::loadFrom (InputStream& input)
  74119. {
  74120. ImageFileFormat* const format = findImageFormatForStream (input);
  74121. if (format != 0)
  74122. return format->decodeImage (input);
  74123. return 0;
  74124. }
  74125. Image* ImageFileFormat::loadFrom (const File& file)
  74126. {
  74127. InputStream* const in = file.createInputStream();
  74128. if (in != 0)
  74129. {
  74130. BufferedInputStream b (in, 8192, true);
  74131. return loadFrom (b);
  74132. }
  74133. return 0;
  74134. }
  74135. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74136. {
  74137. if (rawData != 0 && numBytes > 4)
  74138. {
  74139. MemoryInputStream stream (rawData, numBytes, false);
  74140. return loadFrom (stream);
  74141. }
  74142. return 0;
  74143. }
  74144. END_JUCE_NAMESPACE
  74145. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74146. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74147. BEGIN_JUCE_NAMESPACE
  74148. GIFLoader::GIFLoader (InputStream& in)
  74149. : image (0),
  74150. input (in),
  74151. dataBlockIsZero (false),
  74152. fresh (false),
  74153. finished (false)
  74154. {
  74155. currentBit = lastBit = lastByteIndex = 0;
  74156. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74157. firstcode = oldcode = 0;
  74158. clearCode = end_code = 0;
  74159. int imageWidth, imageHeight;
  74160. int transparent = -1;
  74161. if (! getSizeFromHeader (imageWidth, imageHeight))
  74162. return;
  74163. if ((imageWidth <= 0) || (imageHeight <= 0))
  74164. return;
  74165. unsigned char buf [16];
  74166. if (in.read (buf, 3) != 3)
  74167. return;
  74168. int numColours = 2 << (buf[0] & 7);
  74169. if ((buf[0] & 0x80) != 0)
  74170. readPalette (numColours);
  74171. for (;;)
  74172. {
  74173. if (input.read (buf, 1) != 1)
  74174. break;
  74175. if (buf[0] == ';')
  74176. break;
  74177. if (buf[0] == '!')
  74178. {
  74179. if (input.read (buf, 1) != 1)
  74180. break;
  74181. if (processExtension (buf[0], transparent) < 0)
  74182. break;
  74183. continue;
  74184. }
  74185. if (buf[0] != ',')
  74186. continue;
  74187. if (input.read (buf, 9) != 9)
  74188. break;
  74189. imageWidth = makeWord (buf[4], buf[5]);
  74190. imageHeight = makeWord (buf[6], buf[7]);
  74191. numColours = 2 << (buf[8] & 7);
  74192. if ((buf[8] & 0x80) != 0)
  74193. if (! readPalette (numColours))
  74194. break;
  74195. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74196. imageWidth, imageHeight, (transparent >= 0));
  74197. readImage (imageWidth, imageHeight,
  74198. (buf[8] & 0x40) != 0,
  74199. transparent);
  74200. break;
  74201. }
  74202. }
  74203. GIFLoader::~GIFLoader()
  74204. {
  74205. }
  74206. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74207. {
  74208. char b[8];
  74209. if (input.read (b, 6) == 6)
  74210. {
  74211. if ((strncmp ("GIF87a", b, 6) == 0)
  74212. || (strncmp ("GIF89a", b, 6) == 0))
  74213. {
  74214. if (input.read (b, 4) == 4)
  74215. {
  74216. w = makeWord (b[0], b[1]);
  74217. h = makeWord (b[2], b[3]);
  74218. return true;
  74219. }
  74220. }
  74221. }
  74222. return false;
  74223. }
  74224. bool GIFLoader::readPalette (const int numCols)
  74225. {
  74226. unsigned char rgb[4];
  74227. for (int i = 0; i < numCols; ++i)
  74228. {
  74229. input.read (rgb, 3);
  74230. palette [i][0] = rgb[0];
  74231. palette [i][1] = rgb[1];
  74232. palette [i][2] = rgb[2];
  74233. palette [i][3] = 0xff;
  74234. }
  74235. return true;
  74236. }
  74237. int GIFLoader::readDataBlock (unsigned char* const dest)
  74238. {
  74239. unsigned char n;
  74240. if (input.read (&n, 1) == 1)
  74241. {
  74242. dataBlockIsZero = (n == 0);
  74243. if (dataBlockIsZero || (input.read (dest, n) == n))
  74244. return n;
  74245. }
  74246. return -1;
  74247. }
  74248. int GIFLoader::processExtension (const int type, int& transparent)
  74249. {
  74250. unsigned char b [300];
  74251. int n = 0;
  74252. if (type == 0xf9)
  74253. {
  74254. n = readDataBlock (b);
  74255. if (n < 0)
  74256. return 1;
  74257. if ((b[0] & 0x1) != 0)
  74258. transparent = b[3];
  74259. }
  74260. do
  74261. {
  74262. n = readDataBlock (b);
  74263. }
  74264. while (n > 0);
  74265. return n;
  74266. }
  74267. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74268. {
  74269. if (initialise)
  74270. {
  74271. currentBit = 0;
  74272. lastBit = 0;
  74273. finished = false;
  74274. return 0;
  74275. }
  74276. if ((currentBit + codeSize_) >= lastBit)
  74277. {
  74278. if (finished)
  74279. return -1;
  74280. buffer[0] = buffer [lastByteIndex - 2];
  74281. buffer[1] = buffer [lastByteIndex - 1];
  74282. const int n = readDataBlock (&buffer[2]);
  74283. if (n == 0)
  74284. finished = true;
  74285. lastByteIndex = 2 + n;
  74286. currentBit = (currentBit - lastBit) + 16;
  74287. lastBit = (2 + n) * 8 ;
  74288. }
  74289. int result = 0;
  74290. int i = currentBit;
  74291. for (int j = 0; j < codeSize_; ++j)
  74292. {
  74293. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74294. ++i;
  74295. }
  74296. currentBit += codeSize_;
  74297. return result;
  74298. }
  74299. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74300. {
  74301. int code, incode, i;
  74302. if (initialise)
  74303. {
  74304. setCodeSize = inputCodeSize;
  74305. codeSize = setCodeSize + 1;
  74306. clearCode = 1 << setCodeSize;
  74307. end_code = clearCode + 1;
  74308. maxCodeSize = 2 * clearCode;
  74309. maxCode = clearCode + 2;
  74310. getCode (0, true);
  74311. fresh = true;
  74312. for (i = 0; i < clearCode; ++i)
  74313. {
  74314. table[0][i] = 0;
  74315. table[1][i] = i;
  74316. }
  74317. for (; i < maxGifCode; ++i)
  74318. {
  74319. table[0][i] = 0;
  74320. table[1][i] = 0;
  74321. }
  74322. sp = stack;
  74323. return 0;
  74324. }
  74325. else if (fresh)
  74326. {
  74327. fresh = false;
  74328. do
  74329. {
  74330. firstcode = oldcode
  74331. = getCode (codeSize, false);
  74332. }
  74333. while (firstcode == clearCode);
  74334. return firstcode;
  74335. }
  74336. if (sp > stack)
  74337. return *--sp;
  74338. while ((code = getCode (codeSize, false)) >= 0)
  74339. {
  74340. if (code == clearCode)
  74341. {
  74342. for (i = 0; i < clearCode; ++i)
  74343. {
  74344. table[0][i] = 0;
  74345. table[1][i] = i;
  74346. }
  74347. for (; i < maxGifCode; ++i)
  74348. {
  74349. table[0][i] = 0;
  74350. table[1][i] = 0;
  74351. }
  74352. codeSize = setCodeSize + 1;
  74353. maxCodeSize = 2 * clearCode;
  74354. maxCode = clearCode + 2;
  74355. sp = stack;
  74356. firstcode = oldcode = getCode (codeSize, false);
  74357. return firstcode;
  74358. }
  74359. else if (code == end_code)
  74360. {
  74361. if (dataBlockIsZero)
  74362. return -2;
  74363. unsigned char buf [260];
  74364. int n;
  74365. while ((n = readDataBlock (buf)) > 0)
  74366. {}
  74367. if (n != 0)
  74368. return -2;
  74369. }
  74370. incode = code;
  74371. if (code >= maxCode)
  74372. {
  74373. *sp++ = firstcode;
  74374. code = oldcode;
  74375. }
  74376. while (code >= clearCode)
  74377. {
  74378. *sp++ = table[1][code];
  74379. if (code == table[0][code])
  74380. return -2;
  74381. code = table[0][code];
  74382. }
  74383. *sp++ = firstcode = table[1][code];
  74384. if ((code = maxCode) < maxGifCode)
  74385. {
  74386. table[0][code] = oldcode;
  74387. table[1][code] = firstcode;
  74388. ++maxCode;
  74389. if ((maxCode >= maxCodeSize)
  74390. && (maxCodeSize < maxGifCode))
  74391. {
  74392. maxCodeSize <<= 1;
  74393. ++codeSize;
  74394. }
  74395. }
  74396. oldcode = incode;
  74397. if (sp > stack)
  74398. return *--sp;
  74399. }
  74400. return code;
  74401. }
  74402. bool GIFLoader::readImage (const int width, const int height,
  74403. const int interlace, const int transparent)
  74404. {
  74405. unsigned char c;
  74406. if (input.read (&c, 1) != 1
  74407. || readLZWByte (true, c) < 0)
  74408. return false;
  74409. if (transparent >= 0)
  74410. {
  74411. palette [transparent][0] = 0;
  74412. palette [transparent][1] = 0;
  74413. palette [transparent][2] = 0;
  74414. palette [transparent][3] = 0;
  74415. }
  74416. int index;
  74417. int xpos = 0, ypos = 0, pass = 0;
  74418. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74419. uint8* p = destData.data;
  74420. const bool hasAlpha = image->hasAlphaChannel();
  74421. while ((index = readLZWByte (false, c)) >= 0)
  74422. {
  74423. const uint8* const paletteEntry = palette [index];
  74424. if (hasAlpha)
  74425. {
  74426. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74427. paletteEntry[0],
  74428. paletteEntry[1],
  74429. paletteEntry[2]);
  74430. ((PixelARGB*) p)->premultiply();
  74431. }
  74432. else
  74433. {
  74434. ((PixelRGB*) p)->setARGB (0,
  74435. paletteEntry[0],
  74436. paletteEntry[1],
  74437. paletteEntry[2]);
  74438. }
  74439. p += destData.pixelStride;
  74440. ++xpos;
  74441. if (xpos == width)
  74442. {
  74443. xpos = 0;
  74444. if (interlace)
  74445. {
  74446. switch (pass)
  74447. {
  74448. case 0:
  74449. case 1:
  74450. ypos += 8;
  74451. break;
  74452. case 2:
  74453. ypos += 4;
  74454. break;
  74455. case 3:
  74456. ypos += 2;
  74457. break;
  74458. }
  74459. while (ypos >= height)
  74460. {
  74461. ++pass;
  74462. switch (pass)
  74463. {
  74464. case 1:
  74465. ypos = 4;
  74466. break;
  74467. case 2:
  74468. ypos = 2;
  74469. break;
  74470. case 3:
  74471. ypos = 1;
  74472. break;
  74473. default:
  74474. return true;
  74475. }
  74476. }
  74477. }
  74478. else
  74479. {
  74480. ++ypos;
  74481. }
  74482. p = destData.getPixelPointer (xpos, ypos);
  74483. }
  74484. if (ypos >= height)
  74485. break;
  74486. }
  74487. return true;
  74488. }
  74489. END_JUCE_NAMESPACE
  74490. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74491. #endif
  74492. //==============================================================================
  74493. // some files include lots of library code, so leave them to the end to avoid cluttering
  74494. // up the build for the clean files.
  74495. #if JUCE_BUILD_CORE
  74496. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74497. namespace zlibNamespace
  74498. {
  74499. #if JUCE_INCLUDE_ZLIB_CODE
  74500. #undef OS_CODE
  74501. #undef fdopen
  74502. /*** Start of inlined file: zlib.h ***/
  74503. #ifndef ZLIB_H
  74504. #define ZLIB_H
  74505. /*** Start of inlined file: zconf.h ***/
  74506. #ifndef ZCONF_H
  74507. #define ZCONF_H
  74508. // *** Just a few hacks here to make it compile nicely with Juce..
  74509. #define Z_PREFIX 1
  74510. #undef __MACTYPES__
  74511. #ifdef _MSC_VER
  74512. #pragma warning (disable : 4131 4127 4244 4267)
  74513. #endif
  74514. #ifdef Z_PREFIX
  74515. # define deflateInit_ z_deflateInit_
  74516. # define deflate z_deflate
  74517. # define deflateEnd z_deflateEnd
  74518. # define inflateInit_ z_inflateInit_
  74519. # define inflate z_inflate
  74520. # define inflateEnd z_inflateEnd
  74521. # define inflatePrime z_inflatePrime
  74522. # define inflateGetHeader z_inflateGetHeader
  74523. # define adler32_combine z_adler32_combine
  74524. # define crc32_combine z_crc32_combine
  74525. # define deflateInit2_ z_deflateInit2_
  74526. # define deflateSetDictionary z_deflateSetDictionary
  74527. # define deflateCopy z_deflateCopy
  74528. # define deflateReset z_deflateReset
  74529. # define deflateParams z_deflateParams
  74530. # define deflateBound z_deflateBound
  74531. # define deflatePrime z_deflatePrime
  74532. # define inflateInit2_ z_inflateInit2_
  74533. # define inflateSetDictionary z_inflateSetDictionary
  74534. # define inflateSync z_inflateSync
  74535. # define inflateSyncPoint z_inflateSyncPoint
  74536. # define inflateCopy z_inflateCopy
  74537. # define inflateReset z_inflateReset
  74538. # define inflateBack z_inflateBack
  74539. # define inflateBackEnd z_inflateBackEnd
  74540. # define compress z_compress
  74541. # define compress2 z_compress2
  74542. # define compressBound z_compressBound
  74543. # define uncompress z_uncompress
  74544. # define adler32 z_adler32
  74545. # define crc32 z_crc32
  74546. # define get_crc_table z_get_crc_table
  74547. # define zError z_zError
  74548. # define alloc_func z_alloc_func
  74549. # define free_func z_free_func
  74550. # define in_func z_in_func
  74551. # define out_func z_out_func
  74552. # define Byte z_Byte
  74553. # define uInt z_uInt
  74554. # define uLong z_uLong
  74555. # define Bytef z_Bytef
  74556. # define charf z_charf
  74557. # define intf z_intf
  74558. # define uIntf z_uIntf
  74559. # define uLongf z_uLongf
  74560. # define voidpf z_voidpf
  74561. # define voidp z_voidp
  74562. #endif
  74563. #if defined(__MSDOS__) && !defined(MSDOS)
  74564. # define MSDOS
  74565. #endif
  74566. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74567. # define OS2
  74568. #endif
  74569. #if defined(_WINDOWS) && !defined(WINDOWS)
  74570. # define WINDOWS
  74571. #endif
  74572. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74573. # ifndef WIN32
  74574. # define WIN32
  74575. # endif
  74576. #endif
  74577. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74578. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74579. # ifndef SYS16BIT
  74580. # define SYS16BIT
  74581. # endif
  74582. # endif
  74583. #endif
  74584. #ifdef SYS16BIT
  74585. # define MAXSEG_64K
  74586. #endif
  74587. #ifdef MSDOS
  74588. # define UNALIGNED_OK
  74589. #endif
  74590. #ifdef __STDC_VERSION__
  74591. # ifndef STDC
  74592. # define STDC
  74593. # endif
  74594. # if __STDC_VERSION__ >= 199901L
  74595. # ifndef STDC99
  74596. # define STDC99
  74597. # endif
  74598. # endif
  74599. #endif
  74600. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74601. # define STDC
  74602. #endif
  74603. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74604. # define STDC
  74605. #endif
  74606. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74607. # define STDC
  74608. #endif
  74609. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74610. # define STDC
  74611. #endif
  74612. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74613. # define STDC
  74614. #endif
  74615. #ifndef STDC
  74616. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74617. # define const /* note: need a more gentle solution here */
  74618. # endif
  74619. #endif
  74620. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74621. # define NO_DUMMY_DECL
  74622. #endif
  74623. #ifndef MAX_MEM_LEVEL
  74624. # ifdef MAXSEG_64K
  74625. # define MAX_MEM_LEVEL 8
  74626. # else
  74627. # define MAX_MEM_LEVEL 9
  74628. # endif
  74629. #endif
  74630. #ifndef MAX_WBITS
  74631. # define MAX_WBITS 15 /* 32K LZ77 window */
  74632. #endif
  74633. #ifndef OF /* function prototypes */
  74634. # ifdef STDC
  74635. # define OF(args) args
  74636. # else
  74637. # define OF(args) ()
  74638. # endif
  74639. #endif
  74640. #ifdef SYS16BIT
  74641. # if defined(M_I86SM) || defined(M_I86MM)
  74642. # define SMALL_MEDIUM
  74643. # ifdef _MSC_VER
  74644. # define FAR _far
  74645. # else
  74646. # define FAR far
  74647. # endif
  74648. # endif
  74649. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74650. # define SMALL_MEDIUM
  74651. # ifdef __BORLANDC__
  74652. # define FAR _far
  74653. # else
  74654. # define FAR far
  74655. # endif
  74656. # endif
  74657. #endif
  74658. #if defined(WINDOWS) || defined(WIN32)
  74659. # ifdef ZLIB_DLL
  74660. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74661. # ifdef ZLIB_INTERNAL
  74662. # define ZEXTERN extern __declspec(dllexport)
  74663. # else
  74664. # define ZEXTERN extern __declspec(dllimport)
  74665. # endif
  74666. # endif
  74667. # endif /* ZLIB_DLL */
  74668. # ifdef ZLIB_WINAPI
  74669. # ifdef FAR
  74670. # undef FAR
  74671. # endif
  74672. # include <windows.h>
  74673. # define ZEXPORT WINAPI
  74674. # ifdef WIN32
  74675. # define ZEXPORTVA WINAPIV
  74676. # else
  74677. # define ZEXPORTVA FAR CDECL
  74678. # endif
  74679. # endif
  74680. #endif
  74681. #if defined (__BEOS__)
  74682. # ifdef ZLIB_DLL
  74683. # ifdef ZLIB_INTERNAL
  74684. # define ZEXPORT __declspec(dllexport)
  74685. # define ZEXPORTVA __declspec(dllexport)
  74686. # else
  74687. # define ZEXPORT __declspec(dllimport)
  74688. # define ZEXPORTVA __declspec(dllimport)
  74689. # endif
  74690. # endif
  74691. #endif
  74692. #ifndef ZEXTERN
  74693. # define ZEXTERN extern
  74694. #endif
  74695. #ifndef ZEXPORT
  74696. # define ZEXPORT
  74697. #endif
  74698. #ifndef ZEXPORTVA
  74699. # define ZEXPORTVA
  74700. #endif
  74701. #ifndef FAR
  74702. # define FAR
  74703. #endif
  74704. #if !defined(__MACTYPES__)
  74705. typedef unsigned char Byte; /* 8 bits */
  74706. #endif
  74707. typedef unsigned int uInt; /* 16 bits or more */
  74708. typedef unsigned long uLong; /* 32 bits or more */
  74709. #ifdef SMALL_MEDIUM
  74710. # define Bytef Byte FAR
  74711. #else
  74712. typedef Byte FAR Bytef;
  74713. #endif
  74714. typedef char FAR charf;
  74715. typedef int FAR intf;
  74716. typedef uInt FAR uIntf;
  74717. typedef uLong FAR uLongf;
  74718. #ifdef STDC
  74719. typedef void const *voidpc;
  74720. typedef void FAR *voidpf;
  74721. typedef void *voidp;
  74722. #else
  74723. typedef Byte const *voidpc;
  74724. typedef Byte FAR *voidpf;
  74725. typedef Byte *voidp;
  74726. #endif
  74727. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  74728. # include <sys/types.h> /* for off_t */
  74729. # include <unistd.h> /* for SEEK_* and off_t */
  74730. # ifdef VMS
  74731. # include <unixio.h> /* for off_t */
  74732. # endif
  74733. # define z_off_t off_t
  74734. #endif
  74735. #ifndef SEEK_SET
  74736. # define SEEK_SET 0 /* Seek from beginning of file. */
  74737. # define SEEK_CUR 1 /* Seek from current position. */
  74738. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  74739. #endif
  74740. #ifndef z_off_t
  74741. # define z_off_t long
  74742. #endif
  74743. #if defined(__OS400__)
  74744. # define NO_vsnprintf
  74745. #endif
  74746. #if defined(__MVS__)
  74747. # define NO_vsnprintf
  74748. # ifdef FAR
  74749. # undef FAR
  74750. # endif
  74751. #endif
  74752. #if defined(__MVS__)
  74753. # pragma map(deflateInit_,"DEIN")
  74754. # pragma map(deflateInit2_,"DEIN2")
  74755. # pragma map(deflateEnd,"DEEND")
  74756. # pragma map(deflateBound,"DEBND")
  74757. # pragma map(inflateInit_,"ININ")
  74758. # pragma map(inflateInit2_,"ININ2")
  74759. # pragma map(inflateEnd,"INEND")
  74760. # pragma map(inflateSync,"INSY")
  74761. # pragma map(inflateSetDictionary,"INSEDI")
  74762. # pragma map(compressBound,"CMBND")
  74763. # pragma map(inflate_table,"INTABL")
  74764. # pragma map(inflate_fast,"INFA")
  74765. # pragma map(inflate_copyright,"INCOPY")
  74766. #endif
  74767. #endif /* ZCONF_H */
  74768. /*** End of inlined file: zconf.h ***/
  74769. #ifdef __cplusplus
  74770. extern "C" {
  74771. #endif
  74772. #define ZLIB_VERSION "1.2.3"
  74773. #define ZLIB_VERNUM 0x1230
  74774. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  74775. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  74776. struct internal_state;
  74777. typedef struct z_stream_s {
  74778. Bytef *next_in; /* next input byte */
  74779. uInt avail_in; /* number of bytes available at next_in */
  74780. uLong total_in; /* total nb of input bytes read so far */
  74781. Bytef *next_out; /* next output byte should be put there */
  74782. uInt avail_out; /* remaining free space at next_out */
  74783. uLong total_out; /* total nb of bytes output so far */
  74784. char *msg; /* last error message, NULL if no error */
  74785. struct internal_state FAR *state; /* not visible by applications */
  74786. alloc_func zalloc; /* used to allocate the internal state */
  74787. free_func zfree; /* used to free the internal state */
  74788. voidpf opaque; /* private data object passed to zalloc and zfree */
  74789. int data_type; /* best guess about the data type: binary or text */
  74790. uLong adler; /* adler32 value of the uncompressed data */
  74791. uLong reserved; /* reserved for future use */
  74792. } z_stream;
  74793. typedef z_stream FAR *z_streamp;
  74794. typedef struct gz_header_s {
  74795. int text; /* true if compressed data believed to be text */
  74796. uLong time; /* modification time */
  74797. int xflags; /* extra flags (not used when writing a gzip file) */
  74798. int os; /* operating system */
  74799. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  74800. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  74801. uInt extra_max; /* space at extra (only when reading header) */
  74802. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  74803. uInt name_max; /* space at name (only when reading header) */
  74804. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  74805. uInt comm_max; /* space at comment (only when reading header) */
  74806. int hcrc; /* true if there was or will be a header crc */
  74807. int done; /* true when done reading gzip header (not used
  74808. when writing a gzip file) */
  74809. } gz_header;
  74810. typedef gz_header FAR *gz_headerp;
  74811. #define Z_NO_FLUSH 0
  74812. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  74813. #define Z_SYNC_FLUSH 2
  74814. #define Z_FULL_FLUSH 3
  74815. #define Z_FINISH 4
  74816. #define Z_BLOCK 5
  74817. #define Z_OK 0
  74818. #define Z_STREAM_END 1
  74819. #define Z_NEED_DICT 2
  74820. #define Z_ERRNO (-1)
  74821. #define Z_STREAM_ERROR (-2)
  74822. #define Z_DATA_ERROR (-3)
  74823. #define Z_MEM_ERROR (-4)
  74824. #define Z_BUF_ERROR (-5)
  74825. #define Z_VERSION_ERROR (-6)
  74826. #define Z_NO_COMPRESSION 0
  74827. #define Z_BEST_SPEED 1
  74828. #define Z_BEST_COMPRESSION 9
  74829. #define Z_DEFAULT_COMPRESSION (-1)
  74830. #define Z_FILTERED 1
  74831. #define Z_HUFFMAN_ONLY 2
  74832. #define Z_RLE 3
  74833. #define Z_FIXED 4
  74834. #define Z_DEFAULT_STRATEGY 0
  74835. #define Z_BINARY 0
  74836. #define Z_TEXT 1
  74837. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  74838. #define Z_UNKNOWN 2
  74839. #define Z_DEFLATED 8
  74840. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  74841. #define zlib_version zlibVersion()
  74842. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  74843. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  74844. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  74845. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  74846. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  74847. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  74848. const Bytef *dictionary,
  74849. uInt dictLength));
  74850. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  74851. z_streamp source));
  74852. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  74853. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  74854. int level,
  74855. int strategy));
  74856. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  74857. int good_length,
  74858. int max_lazy,
  74859. int nice_length,
  74860. int max_chain));
  74861. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  74862. uLong sourceLen));
  74863. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  74864. int bits,
  74865. int value));
  74866. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  74867. gz_headerp head));
  74868. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  74869. const Bytef *dictionary,
  74870. uInt dictLength));
  74871. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  74872. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  74873. z_streamp source));
  74874. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  74875. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  74876. int bits,
  74877. int value));
  74878. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  74879. gz_headerp head));
  74880. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  74881. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  74882. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  74883. in_func in, void FAR *in_desc,
  74884. out_func out, void FAR *out_desc));
  74885. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  74886. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  74887. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  74888. const Bytef *source, uLong sourceLen));
  74889. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  74890. const Bytef *source, uLong sourceLen,
  74891. int level));
  74892. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  74893. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  74894. const Bytef *source, uLong sourceLen));
  74895. typedef voidp gzFile;
  74896. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  74897. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  74898. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  74899. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  74900. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  74901. voidpc buf, unsigned len));
  74902. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  74903. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  74904. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  74905. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  74906. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  74907. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  74908. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  74909. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  74910. z_off_t offset, int whence));
  74911. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  74912. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  74913. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  74914. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  74915. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  74916. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  74917. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  74918. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  74919. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  74920. z_off_t len2));
  74921. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  74922. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  74923. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  74924. const char *version, int stream_size));
  74925. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  74926. const char *version, int stream_size));
  74927. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  74928. int windowBits, int memLevel,
  74929. int strategy, const char *version,
  74930. int stream_size));
  74931. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  74932. const char *version, int stream_size));
  74933. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  74934. unsigned char FAR *window,
  74935. const char *version,
  74936. int stream_size));
  74937. #define deflateInit(strm, level) \
  74938. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  74939. #define inflateInit(strm) \
  74940. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  74941. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  74942. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  74943. (strategy), ZLIB_VERSION, sizeof(z_stream))
  74944. #define inflateInit2(strm, windowBits) \
  74945. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  74946. #define inflateBackInit(strm, windowBits, window) \
  74947. inflateBackInit_((strm), (windowBits), (window), \
  74948. ZLIB_VERSION, sizeof(z_stream))
  74949. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  74950. struct internal_state {int dummy;}; /* hack for buggy compilers */
  74951. #endif
  74952. ZEXTERN const char * ZEXPORT zError OF((int));
  74953. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  74954. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  74955. #ifdef __cplusplus
  74956. }
  74957. #endif
  74958. #endif /* ZLIB_H */
  74959. /*** End of inlined file: zlib.h ***/
  74960. #undef OS_CODE
  74961. #else
  74962. #include <zlib.h>
  74963. #endif
  74964. }
  74965. BEGIN_JUCE_NAMESPACE
  74966. // internal helper object that holds the zlib structures so they don't have to be
  74967. // included publicly.
  74968. class GZIPCompressorHelper
  74969. {
  74970. public:
  74971. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  74972. : data (0),
  74973. dataSize (0),
  74974. compLevel (compressionLevel),
  74975. strategy (0),
  74976. setParams (true),
  74977. streamIsValid (false),
  74978. finished (false),
  74979. shouldFinish (false)
  74980. {
  74981. using namespace zlibNamespace;
  74982. zerostruct (stream);
  74983. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  74984. nowrap ? -MAX_WBITS : MAX_WBITS,
  74985. 8, strategy) == Z_OK);
  74986. }
  74987. ~GZIPCompressorHelper()
  74988. {
  74989. using namespace zlibNamespace;
  74990. if (streamIsValid)
  74991. deflateEnd (&stream);
  74992. }
  74993. bool needsInput() const throw()
  74994. {
  74995. return dataSize <= 0;
  74996. }
  74997. void setInput (const uint8* const newData, const int size) throw()
  74998. {
  74999. data = newData;
  75000. dataSize = size;
  75001. }
  75002. int doNextBlock (uint8* const dest, const int destSize) throw()
  75003. {
  75004. using namespace zlibNamespace;
  75005. if (streamIsValid)
  75006. {
  75007. stream.next_in = const_cast <uint8*> (data);
  75008. stream.next_out = dest;
  75009. stream.avail_in = dataSize;
  75010. stream.avail_out = destSize;
  75011. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75012. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75013. setParams = false;
  75014. switch (result)
  75015. {
  75016. case Z_STREAM_END:
  75017. finished = true;
  75018. // Deliberate fall-through..
  75019. case Z_OK:
  75020. data += dataSize - stream.avail_in;
  75021. dataSize = stream.avail_in;
  75022. return destSize - stream.avail_out;
  75023. default:
  75024. break;
  75025. }
  75026. }
  75027. return 0;
  75028. }
  75029. private:
  75030. zlibNamespace::z_stream stream;
  75031. const uint8* data;
  75032. int dataSize, compLevel, strategy;
  75033. bool setParams, streamIsValid;
  75034. public:
  75035. bool finished, shouldFinish;
  75036. };
  75037. const int gzipCompBufferSize = 32768;
  75038. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75039. int compressionLevel,
  75040. const bool deleteDestStream,
  75041. const bool noWrap)
  75042. : destStream (destStream_),
  75043. streamToDelete (deleteDestStream ? destStream_ : 0),
  75044. buffer (gzipCompBufferSize)
  75045. {
  75046. if (compressionLevel < 1 || compressionLevel > 9)
  75047. compressionLevel = -1;
  75048. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75049. }
  75050. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75051. {
  75052. flush();
  75053. }
  75054. void GZIPCompressorOutputStream::flush()
  75055. {
  75056. if (! helper->finished)
  75057. {
  75058. helper->shouldFinish = true;
  75059. while (! helper->finished)
  75060. doNextBlock();
  75061. }
  75062. destStream->flush();
  75063. }
  75064. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75065. {
  75066. if (! helper->finished)
  75067. {
  75068. helper->setInput (static_cast <const uint8*> (destBuffer), howMany);
  75069. while (! helper->needsInput())
  75070. {
  75071. if (! doNextBlock())
  75072. return false;
  75073. }
  75074. }
  75075. return true;
  75076. }
  75077. bool GZIPCompressorOutputStream::doNextBlock()
  75078. {
  75079. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75080. if (len > 0)
  75081. return destStream->write (buffer, len);
  75082. else
  75083. return true;
  75084. }
  75085. int64 GZIPCompressorOutputStream::getPosition()
  75086. {
  75087. return destStream->getPosition();
  75088. }
  75089. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75090. {
  75091. jassertfalse // can't do it!
  75092. return false;
  75093. }
  75094. END_JUCE_NAMESPACE
  75095. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75096. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75097. #if JUCE_MSVC
  75098. #pragma warning (push)
  75099. #pragma warning (disable: 4309 4305)
  75100. #endif
  75101. namespace zlibNamespace
  75102. {
  75103. #if JUCE_INCLUDE_ZLIB_CODE
  75104. extern "C"
  75105. {
  75106. #undef OS_CODE
  75107. #undef fdopen
  75108. #define ZLIB_INTERNAL
  75109. #define NO_DUMMY_DECL
  75110. /*** Start of inlined file: adler32.c ***/
  75111. #define ZLIB_INTERNAL
  75112. #define BASE 65521UL /* largest prime smaller than 65536 */
  75113. #define NMAX 5552
  75114. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75115. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75116. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75117. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75118. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75119. #ifdef NO_DIVIDE
  75120. # define MOD(a) \
  75121. do { \
  75122. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75123. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75124. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75125. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75126. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75127. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75128. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75129. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75130. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75131. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75132. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75133. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75134. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75135. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75136. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75137. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75138. if (a >= BASE) a -= BASE; \
  75139. } while (0)
  75140. # define MOD4(a) \
  75141. do { \
  75142. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75143. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75144. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75145. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75146. if (a >= BASE) a -= BASE; \
  75147. } while (0)
  75148. #else
  75149. # define MOD(a) a %= BASE
  75150. # define MOD4(a) a %= BASE
  75151. #endif
  75152. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75153. {
  75154. unsigned long sum2;
  75155. unsigned n;
  75156. sum2 = (adler >> 16) & 0xffff;
  75157. adler &= 0xffff;
  75158. if (len == 1) {
  75159. adler += buf[0];
  75160. if (adler >= BASE)
  75161. adler -= BASE;
  75162. sum2 += adler;
  75163. if (sum2 >= BASE)
  75164. sum2 -= BASE;
  75165. return adler | (sum2 << 16);
  75166. }
  75167. if (buf == Z_NULL)
  75168. return 1L;
  75169. if (len < 16) {
  75170. while (len--) {
  75171. adler += *buf++;
  75172. sum2 += adler;
  75173. }
  75174. if (adler >= BASE)
  75175. adler -= BASE;
  75176. MOD4(sum2); /* only added so many BASE's */
  75177. return adler | (sum2 << 16);
  75178. }
  75179. while (len >= NMAX) {
  75180. len -= NMAX;
  75181. n = NMAX / 16; /* NMAX is divisible by 16 */
  75182. do {
  75183. DO16(buf); /* 16 sums unrolled */
  75184. buf += 16;
  75185. } while (--n);
  75186. MOD(adler);
  75187. MOD(sum2);
  75188. }
  75189. if (len) { /* avoid modulos if none remaining */
  75190. while (len >= 16) {
  75191. len -= 16;
  75192. DO16(buf);
  75193. buf += 16;
  75194. }
  75195. while (len--) {
  75196. adler += *buf++;
  75197. sum2 += adler;
  75198. }
  75199. MOD(adler);
  75200. MOD(sum2);
  75201. }
  75202. return adler | (sum2 << 16);
  75203. }
  75204. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75205. {
  75206. unsigned long sum1;
  75207. unsigned long sum2;
  75208. unsigned rem;
  75209. rem = (unsigned)(len2 % BASE);
  75210. sum1 = adler1 & 0xffff;
  75211. sum2 = rem * sum1;
  75212. MOD(sum2);
  75213. sum1 += (adler2 & 0xffff) + BASE - 1;
  75214. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75215. if (sum1 > BASE) sum1 -= BASE;
  75216. if (sum1 > BASE) sum1 -= BASE;
  75217. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75218. if (sum2 > BASE) sum2 -= BASE;
  75219. return sum1 | (sum2 << 16);
  75220. }
  75221. /*** End of inlined file: adler32.c ***/
  75222. /*** Start of inlined file: compress.c ***/
  75223. #define ZLIB_INTERNAL
  75224. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75225. uLong sourceLen, int level)
  75226. {
  75227. z_stream stream;
  75228. int err;
  75229. stream.next_in = (Bytef*)source;
  75230. stream.avail_in = (uInt)sourceLen;
  75231. #ifdef MAXSEG_64K
  75232. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75233. #endif
  75234. stream.next_out = dest;
  75235. stream.avail_out = (uInt)*destLen;
  75236. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75237. stream.zalloc = (alloc_func)0;
  75238. stream.zfree = (free_func)0;
  75239. stream.opaque = (voidpf)0;
  75240. err = deflateInit(&stream, level);
  75241. if (err != Z_OK) return err;
  75242. err = deflate(&stream, Z_FINISH);
  75243. if (err != Z_STREAM_END) {
  75244. deflateEnd(&stream);
  75245. return err == Z_OK ? Z_BUF_ERROR : err;
  75246. }
  75247. *destLen = stream.total_out;
  75248. err = deflateEnd(&stream);
  75249. return err;
  75250. }
  75251. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75252. {
  75253. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75254. }
  75255. uLong ZEXPORT compressBound (uLong sourceLen)
  75256. {
  75257. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75258. }
  75259. /*** End of inlined file: compress.c ***/
  75260. #undef DO1
  75261. #undef DO8
  75262. /*** Start of inlined file: crc32.c ***/
  75263. #ifdef MAKECRCH
  75264. # include <stdio.h>
  75265. # ifndef DYNAMIC_CRC_TABLE
  75266. # define DYNAMIC_CRC_TABLE
  75267. # endif /* !DYNAMIC_CRC_TABLE */
  75268. #endif /* MAKECRCH */
  75269. /*** Start of inlined file: zutil.h ***/
  75270. #ifndef ZUTIL_H
  75271. #define ZUTIL_H
  75272. #define ZLIB_INTERNAL
  75273. #ifdef STDC
  75274. # ifndef _WIN32_WCE
  75275. # include <stddef.h>
  75276. # endif
  75277. # include <string.h>
  75278. # include <stdlib.h>
  75279. #endif
  75280. #ifdef NO_ERRNO_H
  75281. # ifdef _WIN32_WCE
  75282. # define errno z_errno
  75283. # endif
  75284. extern int errno;
  75285. #else
  75286. # ifndef _WIN32_WCE
  75287. # include <errno.h>
  75288. # endif
  75289. #endif
  75290. #ifndef local
  75291. # define local static
  75292. #endif
  75293. typedef unsigned char uch;
  75294. typedef uch FAR uchf;
  75295. typedef unsigned short ush;
  75296. typedef ush FAR ushf;
  75297. typedef unsigned long ulg;
  75298. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75299. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75300. #define ERR_RETURN(strm,err) \
  75301. return (strm->msg = (char*)ERR_MSG(err), (err))
  75302. #ifndef DEF_WBITS
  75303. # define DEF_WBITS MAX_WBITS
  75304. #endif
  75305. #if MAX_MEM_LEVEL >= 8
  75306. # define DEF_MEM_LEVEL 8
  75307. #else
  75308. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75309. #endif
  75310. #define STORED_BLOCK 0
  75311. #define STATIC_TREES 1
  75312. #define DYN_TREES 2
  75313. #define MIN_MATCH 3
  75314. #define MAX_MATCH 258
  75315. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75316. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75317. # define OS_CODE 0x00
  75318. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75319. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75320. void _Cdecl farfree( void *block );
  75321. void *_Cdecl farmalloc( unsigned long nbytes );
  75322. # else
  75323. # include <alloc.h>
  75324. # endif
  75325. # else /* MSC or DJGPP */
  75326. # include <malloc.h>
  75327. # endif
  75328. #endif
  75329. #ifdef AMIGA
  75330. # define OS_CODE 0x01
  75331. #endif
  75332. #if defined(VAXC) || defined(VMS)
  75333. # define OS_CODE 0x02
  75334. # define F_OPEN(name, mode) \
  75335. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75336. #endif
  75337. #if defined(ATARI) || defined(atarist)
  75338. # define OS_CODE 0x05
  75339. #endif
  75340. #ifdef OS2
  75341. # define OS_CODE 0x06
  75342. # ifdef M_I86
  75343. #include <malloc.h>
  75344. # endif
  75345. #endif
  75346. #if defined(MACOS) || TARGET_OS_MAC
  75347. # define OS_CODE 0x07
  75348. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75349. # include <unix.h> /* for fdopen */
  75350. # else
  75351. # ifndef fdopen
  75352. # define fdopen(fd,mode) NULL /* No fdopen() */
  75353. # endif
  75354. # endif
  75355. #endif
  75356. #ifdef TOPS20
  75357. # define OS_CODE 0x0a
  75358. #endif
  75359. #ifdef WIN32
  75360. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75361. # define OS_CODE 0x0b
  75362. # endif
  75363. #endif
  75364. #ifdef __50SERIES /* Prime/PRIMOS */
  75365. # define OS_CODE 0x0f
  75366. #endif
  75367. #if defined(_BEOS_) || defined(RISCOS)
  75368. # define fdopen(fd,mode) NULL /* No fdopen() */
  75369. #endif
  75370. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75371. # if defined(_WIN32_WCE)
  75372. # define fdopen(fd,mode) NULL /* No fdopen() */
  75373. # ifndef _PTRDIFF_T_DEFINED
  75374. typedef int ptrdiff_t;
  75375. # define _PTRDIFF_T_DEFINED
  75376. # endif
  75377. # else
  75378. # define fdopen(fd,type) _fdopen(fd,type)
  75379. # endif
  75380. #endif
  75381. #ifndef OS_CODE
  75382. # define OS_CODE 0x03 /* assume Unix */
  75383. #endif
  75384. #ifndef F_OPEN
  75385. # define F_OPEN(name, mode) fopen((name), (mode))
  75386. #endif
  75387. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75388. # ifndef HAVE_VSNPRINTF
  75389. # define HAVE_VSNPRINTF
  75390. # endif
  75391. #endif
  75392. #if defined(__CYGWIN__)
  75393. # ifndef HAVE_VSNPRINTF
  75394. # define HAVE_VSNPRINTF
  75395. # endif
  75396. #endif
  75397. #ifndef HAVE_VSNPRINTF
  75398. # ifdef MSDOS
  75399. # define NO_vsnprintf
  75400. # endif
  75401. # ifdef __TURBOC__
  75402. # define NO_vsnprintf
  75403. # endif
  75404. # ifdef WIN32
  75405. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75406. # define vsnprintf _vsnprintf
  75407. # endif
  75408. # endif
  75409. # ifdef __SASC
  75410. # define NO_vsnprintf
  75411. # endif
  75412. #endif
  75413. #ifdef VMS
  75414. # define NO_vsnprintf
  75415. #endif
  75416. #if defined(pyr)
  75417. # define NO_MEMCPY
  75418. #endif
  75419. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75420. # define NO_MEMCPY
  75421. #endif
  75422. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75423. # define HAVE_MEMCPY
  75424. #endif
  75425. #ifdef HAVE_MEMCPY
  75426. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75427. # define zmemcpy _fmemcpy
  75428. # define zmemcmp _fmemcmp
  75429. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75430. # else
  75431. # define zmemcpy memcpy
  75432. # define zmemcmp memcmp
  75433. # define zmemzero(dest, len) memset(dest, 0, len)
  75434. # endif
  75435. #else
  75436. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75437. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75438. extern void zmemzero OF((Bytef* dest, uInt len));
  75439. #endif
  75440. #ifdef DEBUG
  75441. # include <stdio.h>
  75442. extern int z_verbose;
  75443. extern void z_error OF((const char *m));
  75444. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75445. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75446. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75447. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75448. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75449. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75450. #else
  75451. # define Assert(cond,msg)
  75452. # define Trace(x)
  75453. # define Tracev(x)
  75454. # define Tracevv(x)
  75455. # define Tracec(c,x)
  75456. # define Tracecv(c,x)
  75457. #endif
  75458. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75459. void zcfree OF((voidpf opaque, voidpf ptr));
  75460. #define ZALLOC(strm, items, size) \
  75461. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75462. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75463. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75464. #endif /* ZUTIL_H */
  75465. /*** End of inlined file: zutil.h ***/
  75466. /* for STDC and FAR definitions */
  75467. #define local static
  75468. #ifndef NOBYFOUR
  75469. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75470. # include <limits.h>
  75471. # define BYFOUR
  75472. # if (UINT_MAX == 0xffffffffUL)
  75473. typedef unsigned int u4;
  75474. # else
  75475. # if (ULONG_MAX == 0xffffffffUL)
  75476. typedef unsigned long u4;
  75477. # else
  75478. # if (USHRT_MAX == 0xffffffffUL)
  75479. typedef unsigned short u4;
  75480. # else
  75481. # undef BYFOUR /* can't find a four-byte integer type! */
  75482. # endif
  75483. # endif
  75484. # endif
  75485. # endif /* STDC */
  75486. #endif /* !NOBYFOUR */
  75487. #ifdef BYFOUR
  75488. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75489. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75490. local unsigned long crc32_little OF((unsigned long,
  75491. const unsigned char FAR *, unsigned));
  75492. local unsigned long crc32_big OF((unsigned long,
  75493. const unsigned char FAR *, unsigned));
  75494. # define TBLS 8
  75495. #else
  75496. # define TBLS 1
  75497. #endif /* BYFOUR */
  75498. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75499. unsigned long vec));
  75500. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75501. #ifdef DYNAMIC_CRC_TABLE
  75502. local volatile int crc_table_empty = 1;
  75503. local unsigned long FAR crc_table[TBLS][256];
  75504. local void make_crc_table OF((void));
  75505. #ifdef MAKECRCH
  75506. local void write_table OF((FILE *, const unsigned long FAR *));
  75507. #endif /* MAKECRCH */
  75508. local void make_crc_table()
  75509. {
  75510. unsigned long c;
  75511. int n, k;
  75512. unsigned long poly; /* polynomial exclusive-or pattern */
  75513. static volatile int first = 1; /* flag to limit concurrent making */
  75514. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75515. if (first) {
  75516. first = 0;
  75517. poly = 0UL;
  75518. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75519. poly |= 1UL << (31 - p[n]);
  75520. for (n = 0; n < 256; n++) {
  75521. c = (unsigned long)n;
  75522. for (k = 0; k < 8; k++)
  75523. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75524. crc_table[0][n] = c;
  75525. }
  75526. #ifdef BYFOUR
  75527. for (n = 0; n < 256; n++) {
  75528. c = crc_table[0][n];
  75529. crc_table[4][n] = REV(c);
  75530. for (k = 1; k < 4; k++) {
  75531. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75532. crc_table[k][n] = c;
  75533. crc_table[k + 4][n] = REV(c);
  75534. }
  75535. }
  75536. #endif /* BYFOUR */
  75537. crc_table_empty = 0;
  75538. }
  75539. else { /* not first */
  75540. while (crc_table_empty)
  75541. ;
  75542. }
  75543. #ifdef MAKECRCH
  75544. {
  75545. FILE *out;
  75546. out = fopen("crc32.h", "w");
  75547. if (out == NULL) return;
  75548. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75549. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75550. fprintf(out, "local const unsigned long FAR ");
  75551. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75552. write_table(out, crc_table[0]);
  75553. # ifdef BYFOUR
  75554. fprintf(out, "#ifdef BYFOUR\n");
  75555. for (k = 1; k < 8; k++) {
  75556. fprintf(out, " },\n {\n");
  75557. write_table(out, crc_table[k]);
  75558. }
  75559. fprintf(out, "#endif\n");
  75560. # endif /* BYFOUR */
  75561. fprintf(out, " }\n};\n");
  75562. fclose(out);
  75563. }
  75564. #endif /* MAKECRCH */
  75565. }
  75566. #ifdef MAKECRCH
  75567. local void write_table(out, table)
  75568. FILE *out;
  75569. const unsigned long FAR *table;
  75570. {
  75571. int n;
  75572. for (n = 0; n < 256; n++)
  75573. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75574. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75575. }
  75576. #endif /* MAKECRCH */
  75577. #else /* !DYNAMIC_CRC_TABLE */
  75578. /*** Start of inlined file: crc32.h ***/
  75579. local const unsigned long FAR crc_table[TBLS][256] =
  75580. {
  75581. {
  75582. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75583. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75584. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75585. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75586. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75587. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75588. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75589. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75590. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75591. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75592. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75593. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75594. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75595. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75596. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75597. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75598. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75599. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75600. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75601. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75602. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75603. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75604. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75605. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75606. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75607. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75608. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75609. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75610. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75611. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75612. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75613. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75614. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75615. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75616. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75617. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75618. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75619. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75620. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75621. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75622. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75623. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75624. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75625. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75626. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75627. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75628. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75629. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75630. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75631. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75632. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75633. 0x2d02ef8dUL
  75634. #ifdef BYFOUR
  75635. },
  75636. {
  75637. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75638. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75639. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75640. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75641. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75642. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75643. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75644. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75645. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75646. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75647. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75648. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75649. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75650. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75651. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75652. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75653. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75654. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75655. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75656. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75657. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75658. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75659. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75660. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75661. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75662. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75663. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75664. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75665. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75666. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75667. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75668. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75669. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75670. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75671. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75672. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75673. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75674. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75675. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75676. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75677. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75678. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  75679. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  75680. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  75681. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  75682. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  75683. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  75684. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  75685. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  75686. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  75687. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  75688. 0x9324fd72UL
  75689. },
  75690. {
  75691. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  75692. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  75693. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  75694. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  75695. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  75696. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  75697. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  75698. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  75699. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  75700. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  75701. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  75702. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  75703. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  75704. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  75705. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  75706. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  75707. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  75708. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  75709. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  75710. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  75711. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  75712. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  75713. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  75714. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  75715. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  75716. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  75717. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  75718. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  75719. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  75720. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  75721. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  75722. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  75723. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  75724. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  75725. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  75726. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  75727. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  75728. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  75729. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  75730. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  75731. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  75732. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  75733. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  75734. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  75735. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  75736. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  75737. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  75738. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  75739. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  75740. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  75741. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  75742. 0xbe9834edUL
  75743. },
  75744. {
  75745. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  75746. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  75747. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  75748. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  75749. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  75750. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  75751. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  75752. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  75753. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  75754. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  75755. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  75756. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  75757. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  75758. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  75759. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  75760. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  75761. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  75762. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  75763. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  75764. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  75765. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  75766. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  75767. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  75768. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  75769. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  75770. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  75771. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  75772. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  75773. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  75774. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  75775. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  75776. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  75777. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  75778. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  75779. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  75780. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  75781. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  75782. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  75783. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  75784. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  75785. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  75786. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  75787. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  75788. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  75789. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  75790. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  75791. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  75792. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  75793. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  75794. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  75795. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  75796. 0xde0506f1UL
  75797. },
  75798. {
  75799. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  75800. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  75801. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  75802. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  75803. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  75804. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  75805. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  75806. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  75807. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  75808. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  75809. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  75810. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  75811. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  75812. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  75813. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  75814. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  75815. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  75816. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  75817. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  75818. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  75819. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  75820. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  75821. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  75822. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  75823. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  75824. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  75825. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  75826. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  75827. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  75828. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  75829. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  75830. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  75831. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  75832. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  75833. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  75834. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  75835. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  75836. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  75837. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  75838. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  75839. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  75840. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  75841. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  75842. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  75843. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  75844. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  75845. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  75846. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  75847. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  75848. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  75849. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  75850. 0x8def022dUL
  75851. },
  75852. {
  75853. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  75854. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  75855. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  75856. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  75857. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  75858. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  75859. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  75860. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  75861. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  75862. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  75863. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  75864. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  75865. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  75866. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  75867. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  75868. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  75869. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  75870. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  75871. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  75872. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  75873. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  75874. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  75875. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  75876. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  75877. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  75878. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  75879. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  75880. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  75881. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  75882. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  75883. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  75884. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  75885. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  75886. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  75887. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  75888. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  75889. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  75890. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  75891. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  75892. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  75893. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  75894. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  75895. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  75896. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  75897. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  75898. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  75899. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  75900. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  75901. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  75902. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  75903. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  75904. 0x72fd2493UL
  75905. },
  75906. {
  75907. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  75908. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  75909. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  75910. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  75911. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  75912. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  75913. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  75914. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  75915. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  75916. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  75917. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  75918. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  75919. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  75920. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  75921. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  75922. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  75923. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  75924. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  75925. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  75926. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  75927. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  75928. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  75929. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  75930. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  75931. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  75932. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  75933. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  75934. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  75935. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  75936. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  75937. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  75938. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  75939. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  75940. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  75941. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  75942. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  75943. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  75944. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  75945. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  75946. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  75947. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  75948. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  75949. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  75950. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  75951. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  75952. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  75953. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  75954. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  75955. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  75956. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  75957. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  75958. 0xed3498beUL
  75959. },
  75960. {
  75961. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  75962. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  75963. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  75964. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  75965. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  75966. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  75967. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  75968. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  75969. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  75970. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  75971. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  75972. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  75973. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  75974. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  75975. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  75976. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  75977. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  75978. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  75979. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  75980. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  75981. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  75982. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  75983. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  75984. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  75985. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  75986. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  75987. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  75988. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  75989. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  75990. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  75991. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  75992. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  75993. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  75994. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  75995. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  75996. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  75997. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  75998. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  75999. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76000. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76001. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76002. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76003. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76004. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76005. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76006. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76007. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76008. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76009. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76010. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76011. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76012. 0xf10605deUL
  76013. #endif
  76014. }
  76015. };
  76016. /*** End of inlined file: crc32.h ***/
  76017. #endif /* DYNAMIC_CRC_TABLE */
  76018. const unsigned long FAR * ZEXPORT get_crc_table()
  76019. {
  76020. #ifdef DYNAMIC_CRC_TABLE
  76021. if (crc_table_empty)
  76022. make_crc_table();
  76023. #endif /* DYNAMIC_CRC_TABLE */
  76024. return (const unsigned long FAR *)crc_table;
  76025. }
  76026. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76027. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76028. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76029. {
  76030. if (buf == Z_NULL) return 0UL;
  76031. #ifdef DYNAMIC_CRC_TABLE
  76032. if (crc_table_empty)
  76033. make_crc_table();
  76034. #endif /* DYNAMIC_CRC_TABLE */
  76035. #ifdef BYFOUR
  76036. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76037. u4 endian;
  76038. endian = 1;
  76039. if (*((unsigned char *)(&endian)))
  76040. return crc32_little(crc, buf, len);
  76041. else
  76042. return crc32_big(crc, buf, len);
  76043. }
  76044. #endif /* BYFOUR */
  76045. crc = crc ^ 0xffffffffUL;
  76046. while (len >= 8) {
  76047. DO8;
  76048. len -= 8;
  76049. }
  76050. if (len) do {
  76051. DO1;
  76052. } while (--len);
  76053. return crc ^ 0xffffffffUL;
  76054. }
  76055. #ifdef BYFOUR
  76056. #define DOLIT4 c ^= *buf4++; \
  76057. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76058. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76059. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76060. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76061. {
  76062. register u4 c;
  76063. register const u4 FAR *buf4;
  76064. c = (u4)crc;
  76065. c = ~c;
  76066. while (len && ((ptrdiff_t)buf & 3)) {
  76067. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76068. len--;
  76069. }
  76070. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76071. while (len >= 32) {
  76072. DOLIT32;
  76073. len -= 32;
  76074. }
  76075. while (len >= 4) {
  76076. DOLIT4;
  76077. len -= 4;
  76078. }
  76079. buf = (const unsigned char FAR *)buf4;
  76080. if (len) do {
  76081. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76082. } while (--len);
  76083. c = ~c;
  76084. return (unsigned long)c;
  76085. }
  76086. #define DOBIG4 c ^= *++buf4; \
  76087. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76088. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76089. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76090. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76091. {
  76092. register u4 c;
  76093. register const u4 FAR *buf4;
  76094. c = REV((u4)crc);
  76095. c = ~c;
  76096. while (len && ((ptrdiff_t)buf & 3)) {
  76097. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76098. len--;
  76099. }
  76100. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76101. buf4--;
  76102. while (len >= 32) {
  76103. DOBIG32;
  76104. len -= 32;
  76105. }
  76106. while (len >= 4) {
  76107. DOBIG4;
  76108. len -= 4;
  76109. }
  76110. buf4++;
  76111. buf = (const unsigned char FAR *)buf4;
  76112. if (len) do {
  76113. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76114. } while (--len);
  76115. c = ~c;
  76116. return (unsigned long)(REV(c));
  76117. }
  76118. #endif /* BYFOUR */
  76119. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76120. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76121. {
  76122. unsigned long sum;
  76123. sum = 0;
  76124. while (vec) {
  76125. if (vec & 1)
  76126. sum ^= *mat;
  76127. vec >>= 1;
  76128. mat++;
  76129. }
  76130. return sum;
  76131. }
  76132. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76133. {
  76134. int n;
  76135. for (n = 0; n < GF2_DIM; n++)
  76136. square[n] = gf2_matrix_times(mat, mat[n]);
  76137. }
  76138. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76139. {
  76140. int n;
  76141. unsigned long row;
  76142. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76143. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76144. if (len2 == 0)
  76145. return crc1;
  76146. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76147. row = 1;
  76148. for (n = 1; n < GF2_DIM; n++) {
  76149. odd[n] = row;
  76150. row <<= 1;
  76151. }
  76152. gf2_matrix_square(even, odd);
  76153. gf2_matrix_square(odd, even);
  76154. do {
  76155. gf2_matrix_square(even, odd);
  76156. if (len2 & 1)
  76157. crc1 = gf2_matrix_times(even, crc1);
  76158. len2 >>= 1;
  76159. if (len2 == 0)
  76160. break;
  76161. gf2_matrix_square(odd, even);
  76162. if (len2 & 1)
  76163. crc1 = gf2_matrix_times(odd, crc1);
  76164. len2 >>= 1;
  76165. } while (len2 != 0);
  76166. crc1 ^= crc2;
  76167. return crc1;
  76168. }
  76169. /*** End of inlined file: crc32.c ***/
  76170. /*** Start of inlined file: deflate.c ***/
  76171. /*** Start of inlined file: deflate.h ***/
  76172. #ifndef DEFLATE_H
  76173. #define DEFLATE_H
  76174. #ifndef NO_GZIP
  76175. # define GZIP
  76176. #endif
  76177. #define NO_DUMMY_DECL
  76178. #define LENGTH_CODES 29
  76179. #define LITERALS 256
  76180. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76181. #define D_CODES 30
  76182. #define BL_CODES 19
  76183. #define HEAP_SIZE (2*L_CODES+1)
  76184. #define MAX_BITS 15
  76185. #define INIT_STATE 42
  76186. #define EXTRA_STATE 69
  76187. #define NAME_STATE 73
  76188. #define COMMENT_STATE 91
  76189. #define HCRC_STATE 103
  76190. #define BUSY_STATE 113
  76191. #define FINISH_STATE 666
  76192. typedef struct ct_data_s {
  76193. union {
  76194. ush freq; /* frequency count */
  76195. ush code; /* bit string */
  76196. } fc;
  76197. union {
  76198. ush dad; /* father node in Huffman tree */
  76199. ush len; /* length of bit string */
  76200. } dl;
  76201. } FAR ct_data;
  76202. #define Freq fc.freq
  76203. #define Code fc.code
  76204. #define Dad dl.dad
  76205. #define Len dl.len
  76206. typedef struct static_tree_desc_s static_tree_desc;
  76207. typedef struct tree_desc_s {
  76208. ct_data *dyn_tree; /* the dynamic tree */
  76209. int max_code; /* largest code with non zero frequency */
  76210. static_tree_desc *stat_desc; /* the corresponding static tree */
  76211. } FAR tree_desc;
  76212. typedef ush Pos;
  76213. typedef Pos FAR Posf;
  76214. typedef unsigned IPos;
  76215. typedef struct internal_state {
  76216. z_streamp strm; /* pointer back to this zlib stream */
  76217. int status; /* as the name implies */
  76218. Bytef *pending_buf; /* output still pending */
  76219. ulg pending_buf_size; /* size of pending_buf */
  76220. Bytef *pending_out; /* next pending byte to output to the stream */
  76221. uInt pending; /* nb of bytes in the pending buffer */
  76222. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76223. gz_headerp gzhead; /* gzip header information to write */
  76224. uInt gzindex; /* where in extra, name, or comment */
  76225. Byte method; /* STORED (for zip only) or DEFLATED */
  76226. int last_flush; /* value of flush param for previous deflate call */
  76227. uInt w_size; /* LZ77 window size (32K by default) */
  76228. uInt w_bits; /* log2(w_size) (8..16) */
  76229. uInt w_mask; /* w_size - 1 */
  76230. Bytef *window;
  76231. ulg window_size;
  76232. Posf *prev;
  76233. Posf *head; /* Heads of the hash chains or NIL. */
  76234. uInt ins_h; /* hash index of string to be inserted */
  76235. uInt hash_size; /* number of elements in hash table */
  76236. uInt hash_bits; /* log2(hash_size) */
  76237. uInt hash_mask; /* hash_size-1 */
  76238. uInt hash_shift;
  76239. long block_start;
  76240. uInt match_length; /* length of best match */
  76241. IPos prev_match; /* previous match */
  76242. int match_available; /* set if previous match exists */
  76243. uInt strstart; /* start of string to insert */
  76244. uInt match_start; /* start of matching string */
  76245. uInt lookahead; /* number of valid bytes ahead in window */
  76246. uInt prev_length;
  76247. uInt max_chain_length;
  76248. uInt max_lazy_match;
  76249. # define max_insert_length max_lazy_match
  76250. int level; /* compression level (1..9) */
  76251. int strategy; /* favor or force Huffman coding*/
  76252. uInt good_match;
  76253. int nice_match; /* Stop searching when current match exceeds this */
  76254. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76255. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76256. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76257. struct tree_desc_s l_desc; /* desc. for literal tree */
  76258. struct tree_desc_s d_desc; /* desc. for distance tree */
  76259. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76260. ush bl_count[MAX_BITS+1];
  76261. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76262. int heap_len; /* number of elements in the heap */
  76263. int heap_max; /* element of largest frequency */
  76264. uch depth[2*L_CODES+1];
  76265. uchf *l_buf; /* buffer for literals or lengths */
  76266. uInt lit_bufsize;
  76267. uInt last_lit; /* running index in l_buf */
  76268. ushf *d_buf;
  76269. ulg opt_len; /* bit length of current block with optimal trees */
  76270. ulg static_len; /* bit length of current block with static trees */
  76271. uInt matches; /* number of string matches in current block */
  76272. int last_eob_len; /* bit length of EOB code for last block */
  76273. #ifdef DEBUG
  76274. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76275. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76276. #endif
  76277. ush bi_buf;
  76278. int bi_valid;
  76279. } FAR deflate_state;
  76280. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76281. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76282. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76283. void _tr_init OF((deflate_state *s));
  76284. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76285. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76286. int eof));
  76287. void _tr_align OF((deflate_state *s));
  76288. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76289. int eof));
  76290. #define d_code(dist) \
  76291. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76292. #ifndef DEBUG
  76293. #if defined(GEN_TREES_H) || !defined(STDC)
  76294. extern uch _length_code[];
  76295. extern uch _dist_code[];
  76296. #else
  76297. extern const uch _length_code[];
  76298. extern const uch _dist_code[];
  76299. #endif
  76300. # define _tr_tally_lit(s, c, flush) \
  76301. { uch cc = (c); \
  76302. s->d_buf[s->last_lit] = 0; \
  76303. s->l_buf[s->last_lit++] = cc; \
  76304. s->dyn_ltree[cc].Freq++; \
  76305. flush = (s->last_lit == s->lit_bufsize-1); \
  76306. }
  76307. # define _tr_tally_dist(s, distance, length, flush) \
  76308. { uch len = (length); \
  76309. ush dist = (distance); \
  76310. s->d_buf[s->last_lit] = dist; \
  76311. s->l_buf[s->last_lit++] = len; \
  76312. dist--; \
  76313. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76314. s->dyn_dtree[d_code(dist)].Freq++; \
  76315. flush = (s->last_lit == s->lit_bufsize-1); \
  76316. }
  76317. #else
  76318. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76319. # define _tr_tally_dist(s, distance, length, flush) \
  76320. flush = _tr_tally(s, distance, length)
  76321. #endif
  76322. #endif /* DEFLATE_H */
  76323. /*** End of inlined file: deflate.h ***/
  76324. const char deflate_copyright[] =
  76325. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76326. typedef enum {
  76327. need_more, /* block not completed, need more input or more output */
  76328. block_done, /* block flush performed */
  76329. finish_started, /* finish started, need only more output at next deflate */
  76330. finish_done /* finish done, accept no more input or output */
  76331. } block_state;
  76332. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76333. local void fill_window OF((deflate_state *s));
  76334. local block_state deflate_stored OF((deflate_state *s, int flush));
  76335. local block_state deflate_fast OF((deflate_state *s, int flush));
  76336. #ifndef FASTEST
  76337. local block_state deflate_slow OF((deflate_state *s, int flush));
  76338. #endif
  76339. local void lm_init OF((deflate_state *s));
  76340. local void putShortMSB OF((deflate_state *s, uInt b));
  76341. local void flush_pending OF((z_streamp strm));
  76342. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76343. #ifndef FASTEST
  76344. #ifdef ASMV
  76345. void match_init OF((void)); /* asm code initialization */
  76346. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76347. #else
  76348. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76349. #endif
  76350. #endif
  76351. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76352. #ifdef DEBUG
  76353. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76354. int length));
  76355. #endif
  76356. #define NIL 0
  76357. #ifndef TOO_FAR
  76358. # define TOO_FAR 4096
  76359. #endif
  76360. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76361. typedef struct config_s {
  76362. ush good_length; /* reduce lazy search above this match length */
  76363. ush max_lazy; /* do not perform lazy search above this match length */
  76364. ush nice_length; /* quit search above this match length */
  76365. ush max_chain;
  76366. compress_func func;
  76367. } config;
  76368. #ifdef FASTEST
  76369. local const config configuration_table[2] = {
  76370. {0, 0, 0, 0, deflate_stored}, /* store only */
  76371. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76372. #else
  76373. local const config configuration_table[10] = {
  76374. {0, 0, 0, 0, deflate_stored}, /* store only */
  76375. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76376. {4, 5, 16, 8, deflate_fast},
  76377. {4, 6, 32, 32, deflate_fast},
  76378. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76379. {8, 16, 32, 32, deflate_slow},
  76380. {8, 16, 128, 128, deflate_slow},
  76381. {8, 32, 128, 256, deflate_slow},
  76382. {32, 128, 258, 1024, deflate_slow},
  76383. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76384. #endif
  76385. #define EQUAL 0
  76386. #ifndef NO_DUMMY_DECL
  76387. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76388. #endif
  76389. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76390. #ifdef FASTEST
  76391. #define INSERT_STRING(s, str, match_head) \
  76392. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76393. match_head = s->head[s->ins_h], \
  76394. s->head[s->ins_h] = (Pos)(str))
  76395. #else
  76396. #define INSERT_STRING(s, str, match_head) \
  76397. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76398. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76399. s->head[s->ins_h] = (Pos)(str))
  76400. #endif
  76401. #define CLEAR_HASH(s) \
  76402. s->head[s->hash_size-1] = NIL; \
  76403. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76404. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76405. {
  76406. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76407. Z_DEFAULT_STRATEGY, version, stream_size);
  76408. }
  76409. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76410. {
  76411. deflate_state *s;
  76412. int wrap = 1;
  76413. static const char my_version[] = ZLIB_VERSION;
  76414. ushf *overlay;
  76415. if (version == Z_NULL || version[0] != my_version[0] ||
  76416. stream_size != sizeof(z_stream)) {
  76417. return Z_VERSION_ERROR;
  76418. }
  76419. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76420. strm->msg = Z_NULL;
  76421. if (strm->zalloc == (alloc_func)0) {
  76422. strm->zalloc = zcalloc;
  76423. strm->opaque = (voidpf)0;
  76424. }
  76425. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76426. #ifdef FASTEST
  76427. if (level != 0) level = 1;
  76428. #else
  76429. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76430. #endif
  76431. if (windowBits < 0) { /* suppress zlib wrapper */
  76432. wrap = 0;
  76433. windowBits = -windowBits;
  76434. }
  76435. #ifdef GZIP
  76436. else if (windowBits > 15) {
  76437. wrap = 2; /* write gzip wrapper instead */
  76438. windowBits -= 16;
  76439. }
  76440. #endif
  76441. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76442. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76443. strategy < 0 || strategy > Z_FIXED) {
  76444. return Z_STREAM_ERROR;
  76445. }
  76446. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76447. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76448. if (s == Z_NULL) return Z_MEM_ERROR;
  76449. strm->state = (struct internal_state FAR *)s;
  76450. s->strm = strm;
  76451. s->wrap = wrap;
  76452. s->gzhead = Z_NULL;
  76453. s->w_bits = windowBits;
  76454. s->w_size = 1 << s->w_bits;
  76455. s->w_mask = s->w_size - 1;
  76456. s->hash_bits = memLevel + 7;
  76457. s->hash_size = 1 << s->hash_bits;
  76458. s->hash_mask = s->hash_size - 1;
  76459. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76460. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76461. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76462. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76463. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76464. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76465. s->pending_buf = (uchf *) overlay;
  76466. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76467. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76468. s->pending_buf == Z_NULL) {
  76469. s->status = FINISH_STATE;
  76470. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76471. deflateEnd (strm);
  76472. return Z_MEM_ERROR;
  76473. }
  76474. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76475. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76476. s->level = level;
  76477. s->strategy = strategy;
  76478. s->method = (Byte)method;
  76479. return deflateReset(strm);
  76480. }
  76481. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76482. {
  76483. deflate_state *s;
  76484. uInt length = dictLength;
  76485. uInt n;
  76486. IPos hash_head = 0;
  76487. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76488. strm->state->wrap == 2 ||
  76489. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76490. return Z_STREAM_ERROR;
  76491. s = strm->state;
  76492. if (s->wrap)
  76493. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76494. if (length < MIN_MATCH) return Z_OK;
  76495. if (length > MAX_DIST(s)) {
  76496. length = MAX_DIST(s);
  76497. dictionary += dictLength - length; /* use the tail of the dictionary */
  76498. }
  76499. zmemcpy(s->window, dictionary, length);
  76500. s->strstart = length;
  76501. s->block_start = (long)length;
  76502. s->ins_h = s->window[0];
  76503. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76504. for (n = 0; n <= length - MIN_MATCH; n++) {
  76505. INSERT_STRING(s, n, hash_head);
  76506. }
  76507. if (hash_head) hash_head = 0; /* to make compiler happy */
  76508. return Z_OK;
  76509. }
  76510. int ZEXPORT deflateReset (z_streamp strm)
  76511. {
  76512. deflate_state *s;
  76513. if (strm == Z_NULL || strm->state == Z_NULL ||
  76514. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76515. return Z_STREAM_ERROR;
  76516. }
  76517. strm->total_in = strm->total_out = 0;
  76518. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76519. strm->data_type = Z_UNKNOWN;
  76520. s = (deflate_state *)strm->state;
  76521. s->pending = 0;
  76522. s->pending_out = s->pending_buf;
  76523. if (s->wrap < 0) {
  76524. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76525. }
  76526. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76527. strm->adler =
  76528. #ifdef GZIP
  76529. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76530. #endif
  76531. adler32(0L, Z_NULL, 0);
  76532. s->last_flush = Z_NO_FLUSH;
  76533. _tr_init(s);
  76534. lm_init(s);
  76535. return Z_OK;
  76536. }
  76537. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76538. {
  76539. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76540. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76541. strm->state->gzhead = head;
  76542. return Z_OK;
  76543. }
  76544. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76545. {
  76546. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76547. strm->state->bi_valid = bits;
  76548. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76549. return Z_OK;
  76550. }
  76551. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76552. {
  76553. deflate_state *s;
  76554. compress_func func;
  76555. int err = Z_OK;
  76556. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76557. s = strm->state;
  76558. #ifdef FASTEST
  76559. if (level != 0) level = 1;
  76560. #else
  76561. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76562. #endif
  76563. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76564. return Z_STREAM_ERROR;
  76565. }
  76566. func = configuration_table[s->level].func;
  76567. if (func != configuration_table[level].func && strm->total_in != 0) {
  76568. err = deflate(strm, Z_PARTIAL_FLUSH);
  76569. }
  76570. if (s->level != level) {
  76571. s->level = level;
  76572. s->max_lazy_match = configuration_table[level].max_lazy;
  76573. s->good_match = configuration_table[level].good_length;
  76574. s->nice_match = configuration_table[level].nice_length;
  76575. s->max_chain_length = configuration_table[level].max_chain;
  76576. }
  76577. s->strategy = strategy;
  76578. return err;
  76579. }
  76580. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76581. {
  76582. deflate_state *s;
  76583. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76584. s = strm->state;
  76585. s->good_match = good_length;
  76586. s->max_lazy_match = max_lazy;
  76587. s->nice_match = nice_length;
  76588. s->max_chain_length = max_chain;
  76589. return Z_OK;
  76590. }
  76591. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76592. {
  76593. deflate_state *s;
  76594. uLong destLen;
  76595. destLen = sourceLen +
  76596. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76597. if (strm == Z_NULL || strm->state == Z_NULL)
  76598. return destLen;
  76599. s = strm->state;
  76600. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76601. return destLen;
  76602. return compressBound(sourceLen);
  76603. }
  76604. local void putShortMSB (deflate_state *s, uInt b)
  76605. {
  76606. put_byte(s, (Byte)(b >> 8));
  76607. put_byte(s, (Byte)(b & 0xff));
  76608. }
  76609. local void flush_pending (z_streamp strm)
  76610. {
  76611. unsigned len = strm->state->pending;
  76612. if (len > strm->avail_out) len = strm->avail_out;
  76613. if (len == 0) return;
  76614. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76615. strm->next_out += len;
  76616. strm->state->pending_out += len;
  76617. strm->total_out += len;
  76618. strm->avail_out -= len;
  76619. strm->state->pending -= len;
  76620. if (strm->state->pending == 0) {
  76621. strm->state->pending_out = strm->state->pending_buf;
  76622. }
  76623. }
  76624. int ZEXPORT deflate (z_streamp strm, int flush)
  76625. {
  76626. int old_flush; /* value of flush param for previous deflate call */
  76627. deflate_state *s;
  76628. if (strm == Z_NULL || strm->state == Z_NULL ||
  76629. flush > Z_FINISH || flush < 0) {
  76630. return Z_STREAM_ERROR;
  76631. }
  76632. s = strm->state;
  76633. if (strm->next_out == Z_NULL ||
  76634. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76635. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76636. ERR_RETURN(strm, Z_STREAM_ERROR);
  76637. }
  76638. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76639. s->strm = strm; /* just in case */
  76640. old_flush = s->last_flush;
  76641. s->last_flush = flush;
  76642. if (s->status == INIT_STATE) {
  76643. #ifdef GZIP
  76644. if (s->wrap == 2) {
  76645. strm->adler = crc32(0L, Z_NULL, 0);
  76646. put_byte(s, 31);
  76647. put_byte(s, 139);
  76648. put_byte(s, 8);
  76649. if (s->gzhead == NULL) {
  76650. put_byte(s, 0);
  76651. put_byte(s, 0);
  76652. put_byte(s, 0);
  76653. put_byte(s, 0);
  76654. put_byte(s, 0);
  76655. put_byte(s, s->level == 9 ? 2 :
  76656. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76657. 4 : 0));
  76658. put_byte(s, OS_CODE);
  76659. s->status = BUSY_STATE;
  76660. }
  76661. else {
  76662. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76663. (s->gzhead->hcrc ? 2 : 0) +
  76664. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76665. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76666. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76667. );
  76668. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76669. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76670. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76671. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76672. put_byte(s, s->level == 9 ? 2 :
  76673. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76674. 4 : 0));
  76675. put_byte(s, s->gzhead->os & 0xff);
  76676. if (s->gzhead->extra != NULL) {
  76677. put_byte(s, s->gzhead->extra_len & 0xff);
  76678. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  76679. }
  76680. if (s->gzhead->hcrc)
  76681. strm->adler = crc32(strm->adler, s->pending_buf,
  76682. s->pending);
  76683. s->gzindex = 0;
  76684. s->status = EXTRA_STATE;
  76685. }
  76686. }
  76687. else
  76688. #endif
  76689. {
  76690. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  76691. uInt level_flags;
  76692. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  76693. level_flags = 0;
  76694. else if (s->level < 6)
  76695. level_flags = 1;
  76696. else if (s->level == 6)
  76697. level_flags = 2;
  76698. else
  76699. level_flags = 3;
  76700. header |= (level_flags << 6);
  76701. if (s->strstart != 0) header |= PRESET_DICT;
  76702. header += 31 - (header % 31);
  76703. s->status = BUSY_STATE;
  76704. putShortMSB(s, header);
  76705. if (s->strstart != 0) {
  76706. putShortMSB(s, (uInt)(strm->adler >> 16));
  76707. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76708. }
  76709. strm->adler = adler32(0L, Z_NULL, 0);
  76710. }
  76711. }
  76712. #ifdef GZIP
  76713. if (s->status == EXTRA_STATE) {
  76714. if (s->gzhead->extra != NULL) {
  76715. uInt beg = s->pending; /* start of bytes to update crc */
  76716. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  76717. if (s->pending == s->pending_buf_size) {
  76718. if (s->gzhead->hcrc && s->pending > beg)
  76719. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76720. s->pending - beg);
  76721. flush_pending(strm);
  76722. beg = s->pending;
  76723. if (s->pending == s->pending_buf_size)
  76724. break;
  76725. }
  76726. put_byte(s, s->gzhead->extra[s->gzindex]);
  76727. s->gzindex++;
  76728. }
  76729. if (s->gzhead->hcrc && s->pending > beg)
  76730. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76731. s->pending - beg);
  76732. if (s->gzindex == s->gzhead->extra_len) {
  76733. s->gzindex = 0;
  76734. s->status = NAME_STATE;
  76735. }
  76736. }
  76737. else
  76738. s->status = NAME_STATE;
  76739. }
  76740. if (s->status == NAME_STATE) {
  76741. if (s->gzhead->name != NULL) {
  76742. uInt beg = s->pending; /* start of bytes to update crc */
  76743. int val;
  76744. do {
  76745. if (s->pending == s->pending_buf_size) {
  76746. if (s->gzhead->hcrc && s->pending > beg)
  76747. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76748. s->pending - beg);
  76749. flush_pending(strm);
  76750. beg = s->pending;
  76751. if (s->pending == s->pending_buf_size) {
  76752. val = 1;
  76753. break;
  76754. }
  76755. }
  76756. val = s->gzhead->name[s->gzindex++];
  76757. put_byte(s, val);
  76758. } while (val != 0);
  76759. if (s->gzhead->hcrc && s->pending > beg)
  76760. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76761. s->pending - beg);
  76762. if (val == 0) {
  76763. s->gzindex = 0;
  76764. s->status = COMMENT_STATE;
  76765. }
  76766. }
  76767. else
  76768. s->status = COMMENT_STATE;
  76769. }
  76770. if (s->status == COMMENT_STATE) {
  76771. if (s->gzhead->comment != NULL) {
  76772. uInt beg = s->pending; /* start of bytes to update crc */
  76773. int val;
  76774. do {
  76775. if (s->pending == s->pending_buf_size) {
  76776. if (s->gzhead->hcrc && s->pending > beg)
  76777. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76778. s->pending - beg);
  76779. flush_pending(strm);
  76780. beg = s->pending;
  76781. if (s->pending == s->pending_buf_size) {
  76782. val = 1;
  76783. break;
  76784. }
  76785. }
  76786. val = s->gzhead->comment[s->gzindex++];
  76787. put_byte(s, val);
  76788. } while (val != 0);
  76789. if (s->gzhead->hcrc && s->pending > beg)
  76790. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76791. s->pending - beg);
  76792. if (val == 0)
  76793. s->status = HCRC_STATE;
  76794. }
  76795. else
  76796. s->status = HCRC_STATE;
  76797. }
  76798. if (s->status == HCRC_STATE) {
  76799. if (s->gzhead->hcrc) {
  76800. if (s->pending + 2 > s->pending_buf_size)
  76801. flush_pending(strm);
  76802. if (s->pending + 2 <= s->pending_buf_size) {
  76803. put_byte(s, (Byte)(strm->adler & 0xff));
  76804. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  76805. strm->adler = crc32(0L, Z_NULL, 0);
  76806. s->status = BUSY_STATE;
  76807. }
  76808. }
  76809. else
  76810. s->status = BUSY_STATE;
  76811. }
  76812. #endif
  76813. if (s->pending != 0) {
  76814. flush_pending(strm);
  76815. if (strm->avail_out == 0) {
  76816. s->last_flush = -1;
  76817. return Z_OK;
  76818. }
  76819. } else if (strm->avail_in == 0 && flush <= old_flush &&
  76820. flush != Z_FINISH) {
  76821. ERR_RETURN(strm, Z_BUF_ERROR);
  76822. }
  76823. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  76824. ERR_RETURN(strm, Z_BUF_ERROR);
  76825. }
  76826. if (strm->avail_in != 0 || s->lookahead != 0 ||
  76827. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  76828. block_state bstate;
  76829. bstate = (*(configuration_table[s->level].func))(s, flush);
  76830. if (bstate == finish_started || bstate == finish_done) {
  76831. s->status = FINISH_STATE;
  76832. }
  76833. if (bstate == need_more || bstate == finish_started) {
  76834. if (strm->avail_out == 0) {
  76835. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  76836. }
  76837. return Z_OK;
  76838. }
  76839. if (bstate == block_done) {
  76840. if (flush == Z_PARTIAL_FLUSH) {
  76841. _tr_align(s);
  76842. } else { /* FULL_FLUSH or SYNC_FLUSH */
  76843. _tr_stored_block(s, (char*)0, 0L, 0);
  76844. if (flush == Z_FULL_FLUSH) {
  76845. CLEAR_HASH(s); /* forget history */
  76846. }
  76847. }
  76848. flush_pending(strm);
  76849. if (strm->avail_out == 0) {
  76850. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  76851. return Z_OK;
  76852. }
  76853. }
  76854. }
  76855. Assert(strm->avail_out > 0, "bug2");
  76856. if (flush != Z_FINISH) return Z_OK;
  76857. if (s->wrap <= 0) return Z_STREAM_END;
  76858. #ifdef GZIP
  76859. if (s->wrap == 2) {
  76860. put_byte(s, (Byte)(strm->adler & 0xff));
  76861. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  76862. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  76863. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  76864. put_byte(s, (Byte)(strm->total_in & 0xff));
  76865. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  76866. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  76867. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  76868. }
  76869. else
  76870. #endif
  76871. {
  76872. putShortMSB(s, (uInt)(strm->adler >> 16));
  76873. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76874. }
  76875. flush_pending(strm);
  76876. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  76877. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  76878. }
  76879. int ZEXPORT deflateEnd (z_streamp strm)
  76880. {
  76881. int status;
  76882. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76883. status = strm->state->status;
  76884. if (status != INIT_STATE &&
  76885. status != EXTRA_STATE &&
  76886. status != NAME_STATE &&
  76887. status != COMMENT_STATE &&
  76888. status != HCRC_STATE &&
  76889. status != BUSY_STATE &&
  76890. status != FINISH_STATE) {
  76891. return Z_STREAM_ERROR;
  76892. }
  76893. TRY_FREE(strm, strm->state->pending_buf);
  76894. TRY_FREE(strm, strm->state->head);
  76895. TRY_FREE(strm, strm->state->prev);
  76896. TRY_FREE(strm, strm->state->window);
  76897. ZFREE(strm, strm->state);
  76898. strm->state = Z_NULL;
  76899. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  76900. }
  76901. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  76902. {
  76903. #ifdef MAXSEG_64K
  76904. return Z_STREAM_ERROR;
  76905. #else
  76906. deflate_state *ds;
  76907. deflate_state *ss;
  76908. ushf *overlay;
  76909. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  76910. return Z_STREAM_ERROR;
  76911. }
  76912. ss = source->state;
  76913. zmemcpy(dest, source, sizeof(z_stream));
  76914. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  76915. if (ds == Z_NULL) return Z_MEM_ERROR;
  76916. dest->state = (struct internal_state FAR *) ds;
  76917. zmemcpy(ds, ss, sizeof(deflate_state));
  76918. ds->strm = dest;
  76919. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  76920. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  76921. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  76922. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  76923. ds->pending_buf = (uchf *) overlay;
  76924. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  76925. ds->pending_buf == Z_NULL) {
  76926. deflateEnd (dest);
  76927. return Z_MEM_ERROR;
  76928. }
  76929. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  76930. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  76931. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  76932. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  76933. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  76934. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  76935. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  76936. ds->l_desc.dyn_tree = ds->dyn_ltree;
  76937. ds->d_desc.dyn_tree = ds->dyn_dtree;
  76938. ds->bl_desc.dyn_tree = ds->bl_tree;
  76939. return Z_OK;
  76940. #endif /* MAXSEG_64K */
  76941. }
  76942. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  76943. {
  76944. unsigned len = strm->avail_in;
  76945. if (len > size) len = size;
  76946. if (len == 0) return 0;
  76947. strm->avail_in -= len;
  76948. if (strm->state->wrap == 1) {
  76949. strm->adler = adler32(strm->adler, strm->next_in, len);
  76950. }
  76951. #ifdef GZIP
  76952. else if (strm->state->wrap == 2) {
  76953. strm->adler = crc32(strm->adler, strm->next_in, len);
  76954. }
  76955. #endif
  76956. zmemcpy(buf, strm->next_in, len);
  76957. strm->next_in += len;
  76958. strm->total_in += len;
  76959. return (int)len;
  76960. }
  76961. local void lm_init (deflate_state *s)
  76962. {
  76963. s->window_size = (ulg)2L*s->w_size;
  76964. CLEAR_HASH(s);
  76965. s->max_lazy_match = configuration_table[s->level].max_lazy;
  76966. s->good_match = configuration_table[s->level].good_length;
  76967. s->nice_match = configuration_table[s->level].nice_length;
  76968. s->max_chain_length = configuration_table[s->level].max_chain;
  76969. s->strstart = 0;
  76970. s->block_start = 0L;
  76971. s->lookahead = 0;
  76972. s->match_length = s->prev_length = MIN_MATCH-1;
  76973. s->match_available = 0;
  76974. s->ins_h = 0;
  76975. #ifndef FASTEST
  76976. #ifdef ASMV
  76977. match_init(); /* initialize the asm code */
  76978. #endif
  76979. #endif
  76980. }
  76981. #ifndef FASTEST
  76982. #ifndef ASMV
  76983. local uInt longest_match(deflate_state *s, IPos cur_match)
  76984. {
  76985. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  76986. register Bytef *scan = s->window + s->strstart; /* current string */
  76987. register Bytef *match; /* matched string */
  76988. register int len; /* length of current match */
  76989. int best_len = s->prev_length; /* best match length so far */
  76990. int nice_match = s->nice_match; /* stop if match long enough */
  76991. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  76992. s->strstart - (IPos)MAX_DIST(s) : NIL;
  76993. Posf *prev = s->prev;
  76994. uInt wmask = s->w_mask;
  76995. #ifdef UNALIGNED_OK
  76996. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  76997. register ush scan_start = *(ushf*)scan;
  76998. register ush scan_end = *(ushf*)(scan+best_len-1);
  76999. #else
  77000. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77001. register Byte scan_end1 = scan[best_len-1];
  77002. register Byte scan_end = scan[best_len];
  77003. #endif
  77004. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77005. if (s->prev_length >= s->good_match) {
  77006. chain_length >>= 2;
  77007. }
  77008. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77009. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77010. do {
  77011. Assert(cur_match < s->strstart, "no future");
  77012. match = s->window + cur_match;
  77013. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77014. if (*(ushf*)(match+best_len-1) != scan_end ||
  77015. *(ushf*)match != scan_start) continue;
  77016. Assert(scan[2] == match[2], "scan[2]?");
  77017. scan++, match++;
  77018. do {
  77019. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77020. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77021. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77022. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77023. scan < strend);
  77024. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77025. if (*scan == *match) scan++;
  77026. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77027. scan = strend - (MAX_MATCH-1);
  77028. #else /* UNALIGNED_OK */
  77029. if (match[best_len] != scan_end ||
  77030. match[best_len-1] != scan_end1 ||
  77031. *match != *scan ||
  77032. *++match != scan[1]) continue;
  77033. scan += 2, match++;
  77034. Assert(*scan == *match, "match[2]?");
  77035. do {
  77036. } while (*++scan == *++match && *++scan == *++match &&
  77037. *++scan == *++match && *++scan == *++match &&
  77038. *++scan == *++match && *++scan == *++match &&
  77039. *++scan == *++match && *++scan == *++match &&
  77040. scan < strend);
  77041. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77042. len = MAX_MATCH - (int)(strend - scan);
  77043. scan = strend - MAX_MATCH;
  77044. #endif /* UNALIGNED_OK */
  77045. if (len > best_len) {
  77046. s->match_start = cur_match;
  77047. best_len = len;
  77048. if (len >= nice_match) break;
  77049. #ifdef UNALIGNED_OK
  77050. scan_end = *(ushf*)(scan+best_len-1);
  77051. #else
  77052. scan_end1 = scan[best_len-1];
  77053. scan_end = scan[best_len];
  77054. #endif
  77055. }
  77056. } while ((cur_match = prev[cur_match & wmask]) > limit
  77057. && --chain_length != 0);
  77058. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77059. return s->lookahead;
  77060. }
  77061. #endif /* ASMV */
  77062. #endif /* FASTEST */
  77063. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77064. {
  77065. register Bytef *scan = s->window + s->strstart; /* current string */
  77066. register Bytef *match; /* matched string */
  77067. register int len; /* length of current match */
  77068. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77069. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77070. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77071. Assert(cur_match < s->strstart, "no future");
  77072. match = s->window + cur_match;
  77073. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77074. scan += 2, match += 2;
  77075. Assert(*scan == *match, "match[2]?");
  77076. do {
  77077. } while (*++scan == *++match && *++scan == *++match &&
  77078. *++scan == *++match && *++scan == *++match &&
  77079. *++scan == *++match && *++scan == *++match &&
  77080. *++scan == *++match && *++scan == *++match &&
  77081. scan < strend);
  77082. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77083. len = MAX_MATCH - (int)(strend - scan);
  77084. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77085. s->match_start = cur_match;
  77086. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77087. }
  77088. #ifdef DEBUG
  77089. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77090. {
  77091. if (zmemcmp(s->window + match,
  77092. s->window + start, length) != EQUAL) {
  77093. fprintf(stderr, " start %u, match %u, length %d\n",
  77094. start, match, length);
  77095. do {
  77096. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77097. } while (--length != 0);
  77098. z_error("invalid match");
  77099. }
  77100. if (z_verbose > 1) {
  77101. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77102. do { putc(s->window[start++], stderr); } while (--length != 0);
  77103. }
  77104. }
  77105. #else
  77106. # define check_match(s, start, match, length)
  77107. #endif /* DEBUG */
  77108. local void fill_window (deflate_state *s)
  77109. {
  77110. register unsigned n, m;
  77111. register Posf *p;
  77112. unsigned more; /* Amount of free space at the end of the window. */
  77113. uInt wsize = s->w_size;
  77114. do {
  77115. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77116. if (sizeof(int) <= 2) {
  77117. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77118. more = wsize;
  77119. } else if (more == (unsigned)(-1)) {
  77120. more--;
  77121. }
  77122. }
  77123. if (s->strstart >= wsize+MAX_DIST(s)) {
  77124. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77125. s->match_start -= wsize;
  77126. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77127. s->block_start -= (long) wsize;
  77128. n = s->hash_size;
  77129. p = &s->head[n];
  77130. do {
  77131. m = *--p;
  77132. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77133. } while (--n);
  77134. n = wsize;
  77135. #ifndef FASTEST
  77136. p = &s->prev[n];
  77137. do {
  77138. m = *--p;
  77139. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77140. } while (--n);
  77141. #endif
  77142. more += wsize;
  77143. }
  77144. if (s->strm->avail_in == 0) return;
  77145. Assert(more >= 2, "more < 2");
  77146. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77147. s->lookahead += n;
  77148. if (s->lookahead >= MIN_MATCH) {
  77149. s->ins_h = s->window[s->strstart];
  77150. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77151. #if MIN_MATCH != 3
  77152. Call UPDATE_HASH() MIN_MATCH-3 more times
  77153. #endif
  77154. }
  77155. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77156. }
  77157. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77158. _tr_flush_block(s, (s->block_start >= 0L ? \
  77159. (charf *)&s->window[(unsigned)s->block_start] : \
  77160. (charf *)Z_NULL), \
  77161. (ulg)((long)s->strstart - s->block_start), \
  77162. (eof)); \
  77163. s->block_start = s->strstart; \
  77164. flush_pending(s->strm); \
  77165. Tracev((stderr,"[FLUSH]")); \
  77166. }
  77167. #define FLUSH_BLOCK(s, eof) { \
  77168. FLUSH_BLOCK_ONLY(s, eof); \
  77169. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77170. }
  77171. local block_state deflate_stored(deflate_state *s, int flush)
  77172. {
  77173. ulg max_block_size = 0xffff;
  77174. ulg max_start;
  77175. if (max_block_size > s->pending_buf_size - 5) {
  77176. max_block_size = s->pending_buf_size - 5;
  77177. }
  77178. for (;;) {
  77179. if (s->lookahead <= 1) {
  77180. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77181. s->block_start >= (long)s->w_size, "slide too late");
  77182. fill_window(s);
  77183. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77184. if (s->lookahead == 0) break; /* flush the current block */
  77185. }
  77186. Assert(s->block_start >= 0L, "block gone");
  77187. s->strstart += s->lookahead;
  77188. s->lookahead = 0;
  77189. max_start = s->block_start + max_block_size;
  77190. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77191. s->lookahead = (uInt)(s->strstart - max_start);
  77192. s->strstart = (uInt)max_start;
  77193. FLUSH_BLOCK(s, 0);
  77194. }
  77195. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77196. FLUSH_BLOCK(s, 0);
  77197. }
  77198. }
  77199. FLUSH_BLOCK(s, flush == Z_FINISH);
  77200. return flush == Z_FINISH ? finish_done : block_done;
  77201. }
  77202. local block_state deflate_fast(deflate_state *s, int flush)
  77203. {
  77204. IPos hash_head = NIL; /* head of the hash chain */
  77205. int bflush; /* set if current block must be flushed */
  77206. for (;;) {
  77207. if (s->lookahead < MIN_LOOKAHEAD) {
  77208. fill_window(s);
  77209. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77210. return need_more;
  77211. }
  77212. if (s->lookahead == 0) break; /* flush the current block */
  77213. }
  77214. if (s->lookahead >= MIN_MATCH) {
  77215. INSERT_STRING(s, s->strstart, hash_head);
  77216. }
  77217. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77218. #ifdef FASTEST
  77219. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77220. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77221. s->match_length = longest_match_fast (s, hash_head);
  77222. }
  77223. #else
  77224. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77225. s->match_length = longest_match (s, hash_head);
  77226. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77227. s->match_length = longest_match_fast (s, hash_head);
  77228. }
  77229. #endif
  77230. }
  77231. if (s->match_length >= MIN_MATCH) {
  77232. check_match(s, s->strstart, s->match_start, s->match_length);
  77233. _tr_tally_dist(s, s->strstart - s->match_start,
  77234. s->match_length - MIN_MATCH, bflush);
  77235. s->lookahead -= s->match_length;
  77236. #ifndef FASTEST
  77237. if (s->match_length <= s->max_insert_length &&
  77238. s->lookahead >= MIN_MATCH) {
  77239. s->match_length--; /* string at strstart already in table */
  77240. do {
  77241. s->strstart++;
  77242. INSERT_STRING(s, s->strstart, hash_head);
  77243. } while (--s->match_length != 0);
  77244. s->strstart++;
  77245. } else
  77246. #endif
  77247. {
  77248. s->strstart += s->match_length;
  77249. s->match_length = 0;
  77250. s->ins_h = s->window[s->strstart];
  77251. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77252. #if MIN_MATCH != 3
  77253. Call UPDATE_HASH() MIN_MATCH-3 more times
  77254. #endif
  77255. }
  77256. } else {
  77257. Tracevv((stderr,"%c", s->window[s->strstart]));
  77258. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77259. s->lookahead--;
  77260. s->strstart++;
  77261. }
  77262. if (bflush) FLUSH_BLOCK(s, 0);
  77263. }
  77264. FLUSH_BLOCK(s, flush == Z_FINISH);
  77265. return flush == Z_FINISH ? finish_done : block_done;
  77266. }
  77267. #ifndef FASTEST
  77268. local block_state deflate_slow(deflate_state *s, int flush)
  77269. {
  77270. IPos hash_head = NIL; /* head of hash chain */
  77271. int bflush; /* set if current block must be flushed */
  77272. for (;;) {
  77273. if (s->lookahead < MIN_LOOKAHEAD) {
  77274. fill_window(s);
  77275. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77276. return need_more;
  77277. }
  77278. if (s->lookahead == 0) break; /* flush the current block */
  77279. }
  77280. if (s->lookahead >= MIN_MATCH) {
  77281. INSERT_STRING(s, s->strstart, hash_head);
  77282. }
  77283. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77284. s->match_length = MIN_MATCH-1;
  77285. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77286. s->strstart - hash_head <= MAX_DIST(s)) {
  77287. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77288. s->match_length = longest_match (s, hash_head);
  77289. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77290. s->match_length = longest_match_fast (s, hash_head);
  77291. }
  77292. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77293. #if TOO_FAR <= 32767
  77294. || (s->match_length == MIN_MATCH &&
  77295. s->strstart - s->match_start > TOO_FAR)
  77296. #endif
  77297. )) {
  77298. s->match_length = MIN_MATCH-1;
  77299. }
  77300. }
  77301. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77302. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77303. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77304. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77305. s->prev_length - MIN_MATCH, bflush);
  77306. s->lookahead -= s->prev_length-1;
  77307. s->prev_length -= 2;
  77308. do {
  77309. if (++s->strstart <= max_insert) {
  77310. INSERT_STRING(s, s->strstart, hash_head);
  77311. }
  77312. } while (--s->prev_length != 0);
  77313. s->match_available = 0;
  77314. s->match_length = MIN_MATCH-1;
  77315. s->strstart++;
  77316. if (bflush) FLUSH_BLOCK(s, 0);
  77317. } else if (s->match_available) {
  77318. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77319. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77320. if (bflush) {
  77321. FLUSH_BLOCK_ONLY(s, 0);
  77322. }
  77323. s->strstart++;
  77324. s->lookahead--;
  77325. if (s->strm->avail_out == 0) return need_more;
  77326. } else {
  77327. s->match_available = 1;
  77328. s->strstart++;
  77329. s->lookahead--;
  77330. }
  77331. }
  77332. Assert (flush != Z_NO_FLUSH, "no flush?");
  77333. if (s->match_available) {
  77334. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77335. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77336. s->match_available = 0;
  77337. }
  77338. FLUSH_BLOCK(s, flush == Z_FINISH);
  77339. return flush == Z_FINISH ? finish_done : block_done;
  77340. }
  77341. #endif /* FASTEST */
  77342. #if 0
  77343. local block_state deflate_rle(s, flush)
  77344. deflate_state *s;
  77345. int flush;
  77346. {
  77347. int bflush; /* set if current block must be flushed */
  77348. uInt run; /* length of run */
  77349. uInt max; /* maximum length of run */
  77350. uInt prev; /* byte at distance one to match */
  77351. Bytef *scan; /* scan for end of run */
  77352. for (;;) {
  77353. if (s->lookahead < MAX_MATCH) {
  77354. fill_window(s);
  77355. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77356. return need_more;
  77357. }
  77358. if (s->lookahead == 0) break; /* flush the current block */
  77359. }
  77360. run = 0;
  77361. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77362. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77363. scan = s->window + s->strstart - 1;
  77364. prev = *scan++;
  77365. do {
  77366. if (*scan++ != prev)
  77367. break;
  77368. } while (++run < max);
  77369. }
  77370. if (run >= MIN_MATCH) {
  77371. check_match(s, s->strstart, s->strstart - 1, run);
  77372. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77373. s->lookahead -= run;
  77374. s->strstart += run;
  77375. } else {
  77376. Tracevv((stderr,"%c", s->window[s->strstart]));
  77377. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77378. s->lookahead--;
  77379. s->strstart++;
  77380. }
  77381. if (bflush) FLUSH_BLOCK(s, 0);
  77382. }
  77383. FLUSH_BLOCK(s, flush == Z_FINISH);
  77384. return flush == Z_FINISH ? finish_done : block_done;
  77385. }
  77386. #endif
  77387. /*** End of inlined file: deflate.c ***/
  77388. /*** Start of inlined file: inffast.c ***/
  77389. /*** Start of inlined file: inftrees.h ***/
  77390. #ifndef _INFTREES_H_
  77391. #define _INFTREES_H_
  77392. typedef struct {
  77393. unsigned char op; /* operation, extra bits, table bits */
  77394. unsigned char bits; /* bits in this part of the code */
  77395. unsigned short val; /* offset in table or code value */
  77396. } code;
  77397. #define ENOUGH 2048
  77398. #define MAXD 592
  77399. typedef enum {
  77400. CODES,
  77401. LENS,
  77402. DISTS
  77403. } codetype;
  77404. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77405. unsigned codes, code FAR * FAR *table,
  77406. unsigned FAR *bits, unsigned short FAR *work));
  77407. #endif
  77408. /*** End of inlined file: inftrees.h ***/
  77409. /*** Start of inlined file: inflate.h ***/
  77410. #ifndef _INFLATE_H_
  77411. #define _INFLATE_H_
  77412. #ifndef NO_GZIP
  77413. # define GUNZIP
  77414. #endif
  77415. typedef enum {
  77416. HEAD, /* i: waiting for magic header */
  77417. FLAGS, /* i: waiting for method and flags (gzip) */
  77418. TIME, /* i: waiting for modification time (gzip) */
  77419. OS, /* i: waiting for extra flags and operating system (gzip) */
  77420. EXLEN, /* i: waiting for extra length (gzip) */
  77421. EXTRA, /* i: waiting for extra bytes (gzip) */
  77422. NAME, /* i: waiting for end of file name (gzip) */
  77423. COMMENT, /* i: waiting for end of comment (gzip) */
  77424. HCRC, /* i: waiting for header crc (gzip) */
  77425. DICTID, /* i: waiting for dictionary check value */
  77426. DICT, /* waiting for inflateSetDictionary() call */
  77427. TYPE, /* i: waiting for type bits, including last-flag bit */
  77428. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77429. STORED, /* i: waiting for stored size (length and complement) */
  77430. COPY, /* i/o: waiting for input or output to copy stored block */
  77431. TABLE, /* i: waiting for dynamic block table lengths */
  77432. LENLENS, /* i: waiting for code length code lengths */
  77433. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77434. LEN, /* i: waiting for length/lit code */
  77435. LENEXT, /* i: waiting for length extra bits */
  77436. DIST, /* i: waiting for distance code */
  77437. DISTEXT, /* i: waiting for distance extra bits */
  77438. MATCH, /* o: waiting for output space to copy string */
  77439. LIT, /* o: waiting for output space to write literal */
  77440. CHECK, /* i: waiting for 32-bit check value */
  77441. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77442. DONE, /* finished check, done -- remain here until reset */
  77443. BAD, /* got a data error -- remain here until reset */
  77444. MEM, /* got an inflate() memory error -- remain here until reset */
  77445. SYNC /* looking for synchronization bytes to restart inflate() */
  77446. } inflate_mode;
  77447. struct inflate_state {
  77448. inflate_mode mode; /* current inflate mode */
  77449. int last; /* true if processing last block */
  77450. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77451. int havedict; /* true if dictionary provided */
  77452. int flags; /* gzip header method and flags (0 if zlib) */
  77453. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77454. unsigned long check; /* protected copy of check value */
  77455. unsigned long total; /* protected copy of output count */
  77456. gz_headerp head; /* where to save gzip header information */
  77457. unsigned wbits; /* log base 2 of requested window size */
  77458. unsigned wsize; /* window size or zero if not using window */
  77459. unsigned whave; /* valid bytes in the window */
  77460. unsigned write; /* window write index */
  77461. unsigned char FAR *window; /* allocated sliding window, if needed */
  77462. unsigned long hold; /* input bit accumulator */
  77463. unsigned bits; /* number of bits in "in" */
  77464. unsigned length; /* literal or length of data to copy */
  77465. unsigned offset; /* distance back to copy string from */
  77466. unsigned extra; /* extra bits needed */
  77467. code const FAR *lencode; /* starting table for length/literal codes */
  77468. code const FAR *distcode; /* starting table for distance codes */
  77469. unsigned lenbits; /* index bits for lencode */
  77470. unsigned distbits; /* index bits for distcode */
  77471. unsigned ncode; /* number of code length code lengths */
  77472. unsigned nlen; /* number of length code lengths */
  77473. unsigned ndist; /* number of distance code lengths */
  77474. unsigned have; /* number of code lengths in lens[] */
  77475. code FAR *next; /* next available space in codes[] */
  77476. unsigned short lens[320]; /* temporary storage for code lengths */
  77477. unsigned short work[288]; /* work area for code table building */
  77478. code codes[ENOUGH]; /* space for code tables */
  77479. };
  77480. #endif
  77481. /*** End of inlined file: inflate.h ***/
  77482. /*** Start of inlined file: inffast.h ***/
  77483. void inflate_fast OF((z_streamp strm, unsigned start));
  77484. /*** End of inlined file: inffast.h ***/
  77485. #ifndef ASMINF
  77486. #ifdef POSTINC
  77487. # define OFF 0
  77488. # define PUP(a) *(a)++
  77489. #else
  77490. # define OFF 1
  77491. # define PUP(a) *++(a)
  77492. #endif
  77493. void inflate_fast (z_streamp strm, unsigned start)
  77494. {
  77495. struct inflate_state FAR *state;
  77496. unsigned char FAR *in; /* local strm->next_in */
  77497. unsigned char FAR *last; /* while in < last, enough input available */
  77498. unsigned char FAR *out; /* local strm->next_out */
  77499. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77500. unsigned char FAR *end; /* while out < end, enough space available */
  77501. #ifdef INFLATE_STRICT
  77502. unsigned dmax; /* maximum distance from zlib header */
  77503. #endif
  77504. unsigned wsize; /* window size or zero if not using window */
  77505. unsigned whave; /* valid bytes in the window */
  77506. unsigned write; /* window write index */
  77507. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77508. unsigned long hold; /* local strm->hold */
  77509. unsigned bits; /* local strm->bits */
  77510. code const FAR *lcode; /* local strm->lencode */
  77511. code const FAR *dcode; /* local strm->distcode */
  77512. unsigned lmask; /* mask for first level of length codes */
  77513. unsigned dmask; /* mask for first level of distance codes */
  77514. code thisx; /* retrieved table entry */
  77515. unsigned op; /* code bits, operation, extra bits, or */
  77516. unsigned len; /* match length, unused bytes */
  77517. unsigned dist; /* match distance */
  77518. unsigned char FAR *from; /* where to copy match from */
  77519. state = (struct inflate_state FAR *)strm->state;
  77520. in = strm->next_in - OFF;
  77521. last = in + (strm->avail_in - 5);
  77522. out = strm->next_out - OFF;
  77523. beg = out - (start - strm->avail_out);
  77524. end = out + (strm->avail_out - 257);
  77525. #ifdef INFLATE_STRICT
  77526. dmax = state->dmax;
  77527. #endif
  77528. wsize = state->wsize;
  77529. whave = state->whave;
  77530. write = state->write;
  77531. window = state->window;
  77532. hold = state->hold;
  77533. bits = state->bits;
  77534. lcode = state->lencode;
  77535. dcode = state->distcode;
  77536. lmask = (1U << state->lenbits) - 1;
  77537. dmask = (1U << state->distbits) - 1;
  77538. do {
  77539. if (bits < 15) {
  77540. hold += (unsigned long)(PUP(in)) << bits;
  77541. bits += 8;
  77542. hold += (unsigned long)(PUP(in)) << bits;
  77543. bits += 8;
  77544. }
  77545. thisx = lcode[hold & lmask];
  77546. dolen:
  77547. op = (unsigned)(thisx.bits);
  77548. hold >>= op;
  77549. bits -= op;
  77550. op = (unsigned)(thisx.op);
  77551. if (op == 0) { /* literal */
  77552. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77553. "inflate: literal '%c'\n" :
  77554. "inflate: literal 0x%02x\n", thisx.val));
  77555. PUP(out) = (unsigned char)(thisx.val);
  77556. }
  77557. else if (op & 16) { /* length base */
  77558. len = (unsigned)(thisx.val);
  77559. op &= 15; /* number of extra bits */
  77560. if (op) {
  77561. if (bits < op) {
  77562. hold += (unsigned long)(PUP(in)) << bits;
  77563. bits += 8;
  77564. }
  77565. len += (unsigned)hold & ((1U << op) - 1);
  77566. hold >>= op;
  77567. bits -= op;
  77568. }
  77569. Tracevv((stderr, "inflate: length %u\n", len));
  77570. if (bits < 15) {
  77571. hold += (unsigned long)(PUP(in)) << bits;
  77572. bits += 8;
  77573. hold += (unsigned long)(PUP(in)) << bits;
  77574. bits += 8;
  77575. }
  77576. thisx = dcode[hold & dmask];
  77577. dodist:
  77578. op = (unsigned)(thisx.bits);
  77579. hold >>= op;
  77580. bits -= op;
  77581. op = (unsigned)(thisx.op);
  77582. if (op & 16) { /* distance base */
  77583. dist = (unsigned)(thisx.val);
  77584. op &= 15; /* number of extra bits */
  77585. if (bits < op) {
  77586. hold += (unsigned long)(PUP(in)) << bits;
  77587. bits += 8;
  77588. if (bits < op) {
  77589. hold += (unsigned long)(PUP(in)) << bits;
  77590. bits += 8;
  77591. }
  77592. }
  77593. dist += (unsigned)hold & ((1U << op) - 1);
  77594. #ifdef INFLATE_STRICT
  77595. if (dist > dmax) {
  77596. strm->msg = (char *)"invalid distance too far back";
  77597. state->mode = BAD;
  77598. break;
  77599. }
  77600. #endif
  77601. hold >>= op;
  77602. bits -= op;
  77603. Tracevv((stderr, "inflate: distance %u\n", dist));
  77604. op = (unsigned)(out - beg); /* max distance in output */
  77605. if (dist > op) { /* see if copy from window */
  77606. op = dist - op; /* distance back in window */
  77607. if (op > whave) {
  77608. strm->msg = (char *)"invalid distance too far back";
  77609. state->mode = BAD;
  77610. break;
  77611. }
  77612. from = window - OFF;
  77613. if (write == 0) { /* very common case */
  77614. from += wsize - op;
  77615. if (op < len) { /* some from window */
  77616. len -= op;
  77617. do {
  77618. PUP(out) = PUP(from);
  77619. } while (--op);
  77620. from = out - dist; /* rest from output */
  77621. }
  77622. }
  77623. else if (write < op) { /* wrap around window */
  77624. from += wsize + write - op;
  77625. op -= write;
  77626. if (op < len) { /* some from end of window */
  77627. len -= op;
  77628. do {
  77629. PUP(out) = PUP(from);
  77630. } while (--op);
  77631. from = window - OFF;
  77632. if (write < len) { /* some from start of window */
  77633. op = write;
  77634. len -= op;
  77635. do {
  77636. PUP(out) = PUP(from);
  77637. } while (--op);
  77638. from = out - dist; /* rest from output */
  77639. }
  77640. }
  77641. }
  77642. else { /* contiguous in window */
  77643. from += write - op;
  77644. if (op < len) { /* some from window */
  77645. len -= op;
  77646. do {
  77647. PUP(out) = PUP(from);
  77648. } while (--op);
  77649. from = out - dist; /* rest from output */
  77650. }
  77651. }
  77652. while (len > 2) {
  77653. PUP(out) = PUP(from);
  77654. PUP(out) = PUP(from);
  77655. PUP(out) = PUP(from);
  77656. len -= 3;
  77657. }
  77658. if (len) {
  77659. PUP(out) = PUP(from);
  77660. if (len > 1)
  77661. PUP(out) = PUP(from);
  77662. }
  77663. }
  77664. else {
  77665. from = out - dist; /* copy direct from output */
  77666. do { /* minimum length is three */
  77667. PUP(out) = PUP(from);
  77668. PUP(out) = PUP(from);
  77669. PUP(out) = PUP(from);
  77670. len -= 3;
  77671. } while (len > 2);
  77672. if (len) {
  77673. PUP(out) = PUP(from);
  77674. if (len > 1)
  77675. PUP(out) = PUP(from);
  77676. }
  77677. }
  77678. }
  77679. else if ((op & 64) == 0) { /* 2nd level distance code */
  77680. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  77681. goto dodist;
  77682. }
  77683. else {
  77684. strm->msg = (char *)"invalid distance code";
  77685. state->mode = BAD;
  77686. break;
  77687. }
  77688. }
  77689. else if ((op & 64) == 0) { /* 2nd level length code */
  77690. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  77691. goto dolen;
  77692. }
  77693. else if (op & 32) { /* end-of-block */
  77694. Tracevv((stderr, "inflate: end of block\n"));
  77695. state->mode = TYPE;
  77696. break;
  77697. }
  77698. else {
  77699. strm->msg = (char *)"invalid literal/length code";
  77700. state->mode = BAD;
  77701. break;
  77702. }
  77703. } while (in < last && out < end);
  77704. len = bits >> 3;
  77705. in -= len;
  77706. bits -= len << 3;
  77707. hold &= (1U << bits) - 1;
  77708. strm->next_in = in + OFF;
  77709. strm->next_out = out + OFF;
  77710. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  77711. strm->avail_out = (unsigned)(out < end ?
  77712. 257 + (end - out) : 257 - (out - end));
  77713. state->hold = hold;
  77714. state->bits = bits;
  77715. return;
  77716. }
  77717. #endif /* !ASMINF */
  77718. /*** End of inlined file: inffast.c ***/
  77719. #undef PULLBYTE
  77720. #undef LOAD
  77721. #undef RESTORE
  77722. #undef INITBITS
  77723. #undef NEEDBITS
  77724. #undef DROPBITS
  77725. #undef BYTEBITS
  77726. /*** Start of inlined file: inflate.c ***/
  77727. /*** Start of inlined file: inffast.h ***/
  77728. void inflate_fast OF((z_streamp strm, unsigned start));
  77729. /*** End of inlined file: inffast.h ***/
  77730. #ifdef MAKEFIXED
  77731. # ifndef BUILDFIXED
  77732. # define BUILDFIXED
  77733. # endif
  77734. #endif
  77735. local void fixedtables OF((struct inflate_state FAR *state));
  77736. local int updatewindow OF((z_streamp strm, unsigned out));
  77737. #ifdef BUILDFIXED
  77738. void makefixed OF((void));
  77739. #endif
  77740. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  77741. unsigned len));
  77742. int ZEXPORT inflateReset (z_streamp strm)
  77743. {
  77744. struct inflate_state FAR *state;
  77745. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77746. state = (struct inflate_state FAR *)strm->state;
  77747. strm->total_in = strm->total_out = state->total = 0;
  77748. strm->msg = Z_NULL;
  77749. strm->adler = 1; /* to support ill-conceived Java test suite */
  77750. state->mode = HEAD;
  77751. state->last = 0;
  77752. state->havedict = 0;
  77753. state->dmax = 32768U;
  77754. state->head = Z_NULL;
  77755. state->wsize = 0;
  77756. state->whave = 0;
  77757. state->write = 0;
  77758. state->hold = 0;
  77759. state->bits = 0;
  77760. state->lencode = state->distcode = state->next = state->codes;
  77761. Tracev((stderr, "inflate: reset\n"));
  77762. return Z_OK;
  77763. }
  77764. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  77765. {
  77766. struct inflate_state FAR *state;
  77767. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77768. state = (struct inflate_state FAR *)strm->state;
  77769. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  77770. value &= (1L << bits) - 1;
  77771. state->hold += value << state->bits;
  77772. state->bits += bits;
  77773. return Z_OK;
  77774. }
  77775. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  77776. {
  77777. struct inflate_state FAR *state;
  77778. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  77779. stream_size != (int)(sizeof(z_stream)))
  77780. return Z_VERSION_ERROR;
  77781. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77782. strm->msg = Z_NULL; /* in case we return an error */
  77783. if (strm->zalloc == (alloc_func)0) {
  77784. strm->zalloc = zcalloc;
  77785. strm->opaque = (voidpf)0;
  77786. }
  77787. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77788. state = (struct inflate_state FAR *)
  77789. ZALLOC(strm, 1, sizeof(struct inflate_state));
  77790. if (state == Z_NULL) return Z_MEM_ERROR;
  77791. Tracev((stderr, "inflate: allocated\n"));
  77792. strm->state = (struct internal_state FAR *)state;
  77793. if (windowBits < 0) {
  77794. state->wrap = 0;
  77795. windowBits = -windowBits;
  77796. }
  77797. else {
  77798. state->wrap = (windowBits >> 4) + 1;
  77799. #ifdef GUNZIP
  77800. if (windowBits < 48) windowBits &= 15;
  77801. #endif
  77802. }
  77803. if (windowBits < 8 || windowBits > 15) {
  77804. ZFREE(strm, state);
  77805. strm->state = Z_NULL;
  77806. return Z_STREAM_ERROR;
  77807. }
  77808. state->wbits = (unsigned)windowBits;
  77809. state->window = Z_NULL;
  77810. return inflateReset(strm);
  77811. }
  77812. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  77813. {
  77814. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  77815. }
  77816. local void fixedtables (struct inflate_state FAR *state)
  77817. {
  77818. #ifdef BUILDFIXED
  77819. static int virgin = 1;
  77820. static code *lenfix, *distfix;
  77821. static code fixed[544];
  77822. if (virgin) {
  77823. unsigned sym, bits;
  77824. static code *next;
  77825. sym = 0;
  77826. while (sym < 144) state->lens[sym++] = 8;
  77827. while (sym < 256) state->lens[sym++] = 9;
  77828. while (sym < 280) state->lens[sym++] = 7;
  77829. while (sym < 288) state->lens[sym++] = 8;
  77830. next = fixed;
  77831. lenfix = next;
  77832. bits = 9;
  77833. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  77834. sym = 0;
  77835. while (sym < 32) state->lens[sym++] = 5;
  77836. distfix = next;
  77837. bits = 5;
  77838. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  77839. virgin = 0;
  77840. }
  77841. #else /* !BUILDFIXED */
  77842. /*** Start of inlined file: inffixed.h ***/
  77843. static const code lenfix[512] = {
  77844. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  77845. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  77846. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  77847. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  77848. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  77849. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  77850. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  77851. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  77852. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  77853. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  77854. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  77855. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  77856. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  77857. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  77858. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  77859. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  77860. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  77861. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  77862. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  77863. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  77864. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  77865. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  77866. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  77867. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  77868. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  77869. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  77870. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  77871. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  77872. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  77873. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  77874. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  77875. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  77876. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  77877. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  77878. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  77879. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  77880. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  77881. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  77882. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  77883. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  77884. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  77885. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  77886. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  77887. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  77888. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  77889. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  77890. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  77891. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  77892. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  77893. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  77894. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  77895. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  77896. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  77897. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  77898. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  77899. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  77900. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  77901. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  77902. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  77903. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  77904. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  77905. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  77906. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  77907. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  77908. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  77909. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  77910. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  77911. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  77912. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  77913. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  77914. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  77915. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  77916. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  77917. {0,9,255}
  77918. };
  77919. static const code distfix[32] = {
  77920. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  77921. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  77922. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  77923. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  77924. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  77925. {22,5,193},{64,5,0}
  77926. };
  77927. /*** End of inlined file: inffixed.h ***/
  77928. #endif /* BUILDFIXED */
  77929. state->lencode = lenfix;
  77930. state->lenbits = 9;
  77931. state->distcode = distfix;
  77932. state->distbits = 5;
  77933. }
  77934. #ifdef MAKEFIXED
  77935. #include <stdio.h>
  77936. void makefixed()
  77937. {
  77938. unsigned low, size;
  77939. struct inflate_state state;
  77940. fixedtables(&state);
  77941. puts(" /* inffixed.h -- table for decoding fixed codes");
  77942. puts(" * Generated automatically by makefixed().");
  77943. puts(" */");
  77944. puts("");
  77945. puts(" /* WARNING: this file should *not* be used by applications.");
  77946. puts(" It is part of the implementation of this library and is");
  77947. puts(" subject to change. Applications should only use zlib.h.");
  77948. puts(" */");
  77949. puts("");
  77950. size = 1U << 9;
  77951. printf(" static const code lenfix[%u] = {", size);
  77952. low = 0;
  77953. for (;;) {
  77954. if ((low % 7) == 0) printf("\n ");
  77955. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  77956. state.lencode[low].val);
  77957. if (++low == size) break;
  77958. putchar(',');
  77959. }
  77960. puts("\n };");
  77961. size = 1U << 5;
  77962. printf("\n static const code distfix[%u] = {", size);
  77963. low = 0;
  77964. for (;;) {
  77965. if ((low % 6) == 0) printf("\n ");
  77966. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  77967. state.distcode[low].val);
  77968. if (++low == size) break;
  77969. putchar(',');
  77970. }
  77971. puts("\n };");
  77972. }
  77973. #endif /* MAKEFIXED */
  77974. local int updatewindow (z_streamp strm, unsigned out)
  77975. {
  77976. struct inflate_state FAR *state;
  77977. unsigned copy, dist;
  77978. state = (struct inflate_state FAR *)strm->state;
  77979. if (state->window == Z_NULL) {
  77980. state->window = (unsigned char FAR *)
  77981. ZALLOC(strm, 1U << state->wbits,
  77982. sizeof(unsigned char));
  77983. if (state->window == Z_NULL) return 1;
  77984. }
  77985. if (state->wsize == 0) {
  77986. state->wsize = 1U << state->wbits;
  77987. state->write = 0;
  77988. state->whave = 0;
  77989. }
  77990. copy = out - strm->avail_out;
  77991. if (copy >= state->wsize) {
  77992. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  77993. state->write = 0;
  77994. state->whave = state->wsize;
  77995. }
  77996. else {
  77997. dist = state->wsize - state->write;
  77998. if (dist > copy) dist = copy;
  77999. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78000. copy -= dist;
  78001. if (copy) {
  78002. zmemcpy(state->window, strm->next_out - copy, copy);
  78003. state->write = copy;
  78004. state->whave = state->wsize;
  78005. }
  78006. else {
  78007. state->write += dist;
  78008. if (state->write == state->wsize) state->write = 0;
  78009. if (state->whave < state->wsize) state->whave += dist;
  78010. }
  78011. }
  78012. return 0;
  78013. }
  78014. #ifdef GUNZIP
  78015. # define UPDATE(check, buf, len) \
  78016. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78017. #else
  78018. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78019. #endif
  78020. #ifdef GUNZIP
  78021. # define CRC2(check, word) \
  78022. do { \
  78023. hbuf[0] = (unsigned char)(word); \
  78024. hbuf[1] = (unsigned char)((word) >> 8); \
  78025. check = crc32(check, hbuf, 2); \
  78026. } while (0)
  78027. # define CRC4(check, word) \
  78028. do { \
  78029. hbuf[0] = (unsigned char)(word); \
  78030. hbuf[1] = (unsigned char)((word) >> 8); \
  78031. hbuf[2] = (unsigned char)((word) >> 16); \
  78032. hbuf[3] = (unsigned char)((word) >> 24); \
  78033. check = crc32(check, hbuf, 4); \
  78034. } while (0)
  78035. #endif
  78036. #define LOAD() \
  78037. do { \
  78038. put = strm->next_out; \
  78039. left = strm->avail_out; \
  78040. next = strm->next_in; \
  78041. have = strm->avail_in; \
  78042. hold = state->hold; \
  78043. bits = state->bits; \
  78044. } while (0)
  78045. #define RESTORE() \
  78046. do { \
  78047. strm->next_out = put; \
  78048. strm->avail_out = left; \
  78049. strm->next_in = next; \
  78050. strm->avail_in = have; \
  78051. state->hold = hold; \
  78052. state->bits = bits; \
  78053. } while (0)
  78054. #define INITBITS() \
  78055. do { \
  78056. hold = 0; \
  78057. bits = 0; \
  78058. } while (0)
  78059. #define PULLBYTE() \
  78060. do { \
  78061. if (have == 0) goto inf_leave; \
  78062. have--; \
  78063. hold += (unsigned long)(*next++) << bits; \
  78064. bits += 8; \
  78065. } while (0)
  78066. #define NEEDBITS(n) \
  78067. do { \
  78068. while (bits < (unsigned)(n)) \
  78069. PULLBYTE(); \
  78070. } while (0)
  78071. #define BITS(n) \
  78072. ((unsigned)hold & ((1U << (n)) - 1))
  78073. #define DROPBITS(n) \
  78074. do { \
  78075. hold >>= (n); \
  78076. bits -= (unsigned)(n); \
  78077. } while (0)
  78078. #define BYTEBITS() \
  78079. do { \
  78080. hold >>= bits & 7; \
  78081. bits -= bits & 7; \
  78082. } while (0)
  78083. #define REVERSE(q) \
  78084. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78085. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78086. int ZEXPORT inflate (z_streamp strm, int flush)
  78087. {
  78088. struct inflate_state FAR *state;
  78089. unsigned char FAR *next; /* next input */
  78090. unsigned char FAR *put; /* next output */
  78091. unsigned have, left; /* available input and output */
  78092. unsigned long hold; /* bit buffer */
  78093. unsigned bits; /* bits in bit buffer */
  78094. unsigned in, out; /* save starting available input and output */
  78095. unsigned copy; /* number of stored or match bytes to copy */
  78096. unsigned char FAR *from; /* where to copy match bytes from */
  78097. code thisx; /* current decoding table entry */
  78098. code last; /* parent table entry */
  78099. unsigned len; /* length to copy for repeats, bits to drop */
  78100. int ret; /* return code */
  78101. #ifdef GUNZIP
  78102. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78103. #endif
  78104. static const unsigned short order[19] = /* permutation of code lengths */
  78105. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78106. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78107. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78108. return Z_STREAM_ERROR;
  78109. state = (struct inflate_state FAR *)strm->state;
  78110. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78111. LOAD();
  78112. in = have;
  78113. out = left;
  78114. ret = Z_OK;
  78115. for (;;)
  78116. switch (state->mode) {
  78117. case HEAD:
  78118. if (state->wrap == 0) {
  78119. state->mode = TYPEDO;
  78120. break;
  78121. }
  78122. NEEDBITS(16);
  78123. #ifdef GUNZIP
  78124. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78125. state->check = crc32(0L, Z_NULL, 0);
  78126. CRC2(state->check, hold);
  78127. INITBITS();
  78128. state->mode = FLAGS;
  78129. break;
  78130. }
  78131. state->flags = 0; /* expect zlib header */
  78132. if (state->head != Z_NULL)
  78133. state->head->done = -1;
  78134. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78135. #else
  78136. if (
  78137. #endif
  78138. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78139. strm->msg = (char *)"incorrect header check";
  78140. state->mode = BAD;
  78141. break;
  78142. }
  78143. if (BITS(4) != Z_DEFLATED) {
  78144. strm->msg = (char *)"unknown compression method";
  78145. state->mode = BAD;
  78146. break;
  78147. }
  78148. DROPBITS(4);
  78149. len = BITS(4) + 8;
  78150. if (len > state->wbits) {
  78151. strm->msg = (char *)"invalid window size";
  78152. state->mode = BAD;
  78153. break;
  78154. }
  78155. state->dmax = 1U << len;
  78156. Tracev((stderr, "inflate: zlib header ok\n"));
  78157. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78158. state->mode = hold & 0x200 ? DICTID : TYPE;
  78159. INITBITS();
  78160. break;
  78161. #ifdef GUNZIP
  78162. case FLAGS:
  78163. NEEDBITS(16);
  78164. state->flags = (int)(hold);
  78165. if ((state->flags & 0xff) != Z_DEFLATED) {
  78166. strm->msg = (char *)"unknown compression method";
  78167. state->mode = BAD;
  78168. break;
  78169. }
  78170. if (state->flags & 0xe000) {
  78171. strm->msg = (char *)"unknown header flags set";
  78172. state->mode = BAD;
  78173. break;
  78174. }
  78175. if (state->head != Z_NULL)
  78176. state->head->text = (int)((hold >> 8) & 1);
  78177. if (state->flags & 0x0200) CRC2(state->check, hold);
  78178. INITBITS();
  78179. state->mode = TIME;
  78180. case TIME:
  78181. NEEDBITS(32);
  78182. if (state->head != Z_NULL)
  78183. state->head->time = hold;
  78184. if (state->flags & 0x0200) CRC4(state->check, hold);
  78185. INITBITS();
  78186. state->mode = OS;
  78187. case OS:
  78188. NEEDBITS(16);
  78189. if (state->head != Z_NULL) {
  78190. state->head->xflags = (int)(hold & 0xff);
  78191. state->head->os = (int)(hold >> 8);
  78192. }
  78193. if (state->flags & 0x0200) CRC2(state->check, hold);
  78194. INITBITS();
  78195. state->mode = EXLEN;
  78196. case EXLEN:
  78197. if (state->flags & 0x0400) {
  78198. NEEDBITS(16);
  78199. state->length = (unsigned)(hold);
  78200. if (state->head != Z_NULL)
  78201. state->head->extra_len = (unsigned)hold;
  78202. if (state->flags & 0x0200) CRC2(state->check, hold);
  78203. INITBITS();
  78204. }
  78205. else if (state->head != Z_NULL)
  78206. state->head->extra = Z_NULL;
  78207. state->mode = EXTRA;
  78208. case EXTRA:
  78209. if (state->flags & 0x0400) {
  78210. copy = state->length;
  78211. if (copy > have) copy = have;
  78212. if (copy) {
  78213. if (state->head != Z_NULL &&
  78214. state->head->extra != Z_NULL) {
  78215. len = state->head->extra_len - state->length;
  78216. zmemcpy(state->head->extra + len, next,
  78217. len + copy > state->head->extra_max ?
  78218. state->head->extra_max - len : copy);
  78219. }
  78220. if (state->flags & 0x0200)
  78221. state->check = crc32(state->check, next, copy);
  78222. have -= copy;
  78223. next += copy;
  78224. state->length -= copy;
  78225. }
  78226. if (state->length) goto inf_leave;
  78227. }
  78228. state->length = 0;
  78229. state->mode = NAME;
  78230. case NAME:
  78231. if (state->flags & 0x0800) {
  78232. if (have == 0) goto inf_leave;
  78233. copy = 0;
  78234. do {
  78235. len = (unsigned)(next[copy++]);
  78236. if (state->head != Z_NULL &&
  78237. state->head->name != Z_NULL &&
  78238. state->length < state->head->name_max)
  78239. state->head->name[state->length++] = len;
  78240. } while (len && copy < have);
  78241. if (state->flags & 0x0200)
  78242. state->check = crc32(state->check, next, copy);
  78243. have -= copy;
  78244. next += copy;
  78245. if (len) goto inf_leave;
  78246. }
  78247. else if (state->head != Z_NULL)
  78248. state->head->name = Z_NULL;
  78249. state->length = 0;
  78250. state->mode = COMMENT;
  78251. case COMMENT:
  78252. if (state->flags & 0x1000) {
  78253. if (have == 0) goto inf_leave;
  78254. copy = 0;
  78255. do {
  78256. len = (unsigned)(next[copy++]);
  78257. if (state->head != Z_NULL &&
  78258. state->head->comment != Z_NULL &&
  78259. state->length < state->head->comm_max)
  78260. state->head->comment[state->length++] = len;
  78261. } while (len && copy < have);
  78262. if (state->flags & 0x0200)
  78263. state->check = crc32(state->check, next, copy);
  78264. have -= copy;
  78265. next += copy;
  78266. if (len) goto inf_leave;
  78267. }
  78268. else if (state->head != Z_NULL)
  78269. state->head->comment = Z_NULL;
  78270. state->mode = HCRC;
  78271. case HCRC:
  78272. if (state->flags & 0x0200) {
  78273. NEEDBITS(16);
  78274. if (hold != (state->check & 0xffff)) {
  78275. strm->msg = (char *)"header crc mismatch";
  78276. state->mode = BAD;
  78277. break;
  78278. }
  78279. INITBITS();
  78280. }
  78281. if (state->head != Z_NULL) {
  78282. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78283. state->head->done = 1;
  78284. }
  78285. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78286. state->mode = TYPE;
  78287. break;
  78288. #endif
  78289. case DICTID:
  78290. NEEDBITS(32);
  78291. strm->adler = state->check = REVERSE(hold);
  78292. INITBITS();
  78293. state->mode = DICT;
  78294. case DICT:
  78295. if (state->havedict == 0) {
  78296. RESTORE();
  78297. return Z_NEED_DICT;
  78298. }
  78299. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78300. state->mode = TYPE;
  78301. case TYPE:
  78302. if (flush == Z_BLOCK) goto inf_leave;
  78303. case TYPEDO:
  78304. if (state->last) {
  78305. BYTEBITS();
  78306. state->mode = CHECK;
  78307. break;
  78308. }
  78309. NEEDBITS(3);
  78310. state->last = BITS(1);
  78311. DROPBITS(1);
  78312. switch (BITS(2)) {
  78313. case 0: /* stored block */
  78314. Tracev((stderr, "inflate: stored block%s\n",
  78315. state->last ? " (last)" : ""));
  78316. state->mode = STORED;
  78317. break;
  78318. case 1: /* fixed block */
  78319. fixedtables(state);
  78320. Tracev((stderr, "inflate: fixed codes block%s\n",
  78321. state->last ? " (last)" : ""));
  78322. state->mode = LEN; /* decode codes */
  78323. break;
  78324. case 2: /* dynamic block */
  78325. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78326. state->last ? " (last)" : ""));
  78327. state->mode = TABLE;
  78328. break;
  78329. case 3:
  78330. strm->msg = (char *)"invalid block type";
  78331. state->mode = BAD;
  78332. }
  78333. DROPBITS(2);
  78334. break;
  78335. case STORED:
  78336. BYTEBITS(); /* go to byte boundary */
  78337. NEEDBITS(32);
  78338. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78339. strm->msg = (char *)"invalid stored block lengths";
  78340. state->mode = BAD;
  78341. break;
  78342. }
  78343. state->length = (unsigned)hold & 0xffff;
  78344. Tracev((stderr, "inflate: stored length %u\n",
  78345. state->length));
  78346. INITBITS();
  78347. state->mode = COPY;
  78348. case COPY:
  78349. copy = state->length;
  78350. if (copy) {
  78351. if (copy > have) copy = have;
  78352. if (copy > left) copy = left;
  78353. if (copy == 0) goto inf_leave;
  78354. zmemcpy(put, next, copy);
  78355. have -= copy;
  78356. next += copy;
  78357. left -= copy;
  78358. put += copy;
  78359. state->length -= copy;
  78360. break;
  78361. }
  78362. Tracev((stderr, "inflate: stored end\n"));
  78363. state->mode = TYPE;
  78364. break;
  78365. case TABLE:
  78366. NEEDBITS(14);
  78367. state->nlen = BITS(5) + 257;
  78368. DROPBITS(5);
  78369. state->ndist = BITS(5) + 1;
  78370. DROPBITS(5);
  78371. state->ncode = BITS(4) + 4;
  78372. DROPBITS(4);
  78373. #ifndef PKZIP_BUG_WORKAROUND
  78374. if (state->nlen > 286 || state->ndist > 30) {
  78375. strm->msg = (char *)"too many length or distance symbols";
  78376. state->mode = BAD;
  78377. break;
  78378. }
  78379. #endif
  78380. Tracev((stderr, "inflate: table sizes ok\n"));
  78381. state->have = 0;
  78382. state->mode = LENLENS;
  78383. case LENLENS:
  78384. while (state->have < state->ncode) {
  78385. NEEDBITS(3);
  78386. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78387. DROPBITS(3);
  78388. }
  78389. while (state->have < 19)
  78390. state->lens[order[state->have++]] = 0;
  78391. state->next = state->codes;
  78392. state->lencode = (code const FAR *)(state->next);
  78393. state->lenbits = 7;
  78394. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78395. &(state->lenbits), state->work);
  78396. if (ret) {
  78397. strm->msg = (char *)"invalid code lengths set";
  78398. state->mode = BAD;
  78399. break;
  78400. }
  78401. Tracev((stderr, "inflate: code lengths ok\n"));
  78402. state->have = 0;
  78403. state->mode = CODELENS;
  78404. case CODELENS:
  78405. while (state->have < state->nlen + state->ndist) {
  78406. for (;;) {
  78407. thisx = state->lencode[BITS(state->lenbits)];
  78408. if ((unsigned)(thisx.bits) <= bits) break;
  78409. PULLBYTE();
  78410. }
  78411. if (thisx.val < 16) {
  78412. NEEDBITS(thisx.bits);
  78413. DROPBITS(thisx.bits);
  78414. state->lens[state->have++] = thisx.val;
  78415. }
  78416. else {
  78417. if (thisx.val == 16) {
  78418. NEEDBITS(thisx.bits + 2);
  78419. DROPBITS(thisx.bits);
  78420. if (state->have == 0) {
  78421. strm->msg = (char *)"invalid bit length repeat";
  78422. state->mode = BAD;
  78423. break;
  78424. }
  78425. len = state->lens[state->have - 1];
  78426. copy = 3 + BITS(2);
  78427. DROPBITS(2);
  78428. }
  78429. else if (thisx.val == 17) {
  78430. NEEDBITS(thisx.bits + 3);
  78431. DROPBITS(thisx.bits);
  78432. len = 0;
  78433. copy = 3 + BITS(3);
  78434. DROPBITS(3);
  78435. }
  78436. else {
  78437. NEEDBITS(thisx.bits + 7);
  78438. DROPBITS(thisx.bits);
  78439. len = 0;
  78440. copy = 11 + BITS(7);
  78441. DROPBITS(7);
  78442. }
  78443. if (state->have + copy > state->nlen + state->ndist) {
  78444. strm->msg = (char *)"invalid bit length repeat";
  78445. state->mode = BAD;
  78446. break;
  78447. }
  78448. while (copy--)
  78449. state->lens[state->have++] = (unsigned short)len;
  78450. }
  78451. }
  78452. if (state->mode == BAD) break;
  78453. state->next = state->codes;
  78454. state->lencode = (code const FAR *)(state->next);
  78455. state->lenbits = 9;
  78456. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78457. &(state->lenbits), state->work);
  78458. if (ret) {
  78459. strm->msg = (char *)"invalid literal/lengths set";
  78460. state->mode = BAD;
  78461. break;
  78462. }
  78463. state->distcode = (code const FAR *)(state->next);
  78464. state->distbits = 6;
  78465. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78466. &(state->next), &(state->distbits), state->work);
  78467. if (ret) {
  78468. strm->msg = (char *)"invalid distances set";
  78469. state->mode = BAD;
  78470. break;
  78471. }
  78472. Tracev((stderr, "inflate: codes ok\n"));
  78473. state->mode = LEN;
  78474. case LEN:
  78475. if (have >= 6 && left >= 258) {
  78476. RESTORE();
  78477. inflate_fast(strm, out);
  78478. LOAD();
  78479. break;
  78480. }
  78481. for (;;) {
  78482. thisx = state->lencode[BITS(state->lenbits)];
  78483. if ((unsigned)(thisx.bits) <= bits) break;
  78484. PULLBYTE();
  78485. }
  78486. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78487. last = thisx;
  78488. for (;;) {
  78489. thisx = state->lencode[last.val +
  78490. (BITS(last.bits + last.op) >> last.bits)];
  78491. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78492. PULLBYTE();
  78493. }
  78494. DROPBITS(last.bits);
  78495. }
  78496. DROPBITS(thisx.bits);
  78497. state->length = (unsigned)thisx.val;
  78498. if ((int)(thisx.op) == 0) {
  78499. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78500. "inflate: literal '%c'\n" :
  78501. "inflate: literal 0x%02x\n", thisx.val));
  78502. state->mode = LIT;
  78503. break;
  78504. }
  78505. if (thisx.op & 32) {
  78506. Tracevv((stderr, "inflate: end of block\n"));
  78507. state->mode = TYPE;
  78508. break;
  78509. }
  78510. if (thisx.op & 64) {
  78511. strm->msg = (char *)"invalid literal/length code";
  78512. state->mode = BAD;
  78513. break;
  78514. }
  78515. state->extra = (unsigned)(thisx.op) & 15;
  78516. state->mode = LENEXT;
  78517. case LENEXT:
  78518. if (state->extra) {
  78519. NEEDBITS(state->extra);
  78520. state->length += BITS(state->extra);
  78521. DROPBITS(state->extra);
  78522. }
  78523. Tracevv((stderr, "inflate: length %u\n", state->length));
  78524. state->mode = DIST;
  78525. case DIST:
  78526. for (;;) {
  78527. thisx = state->distcode[BITS(state->distbits)];
  78528. if ((unsigned)(thisx.bits) <= bits) break;
  78529. PULLBYTE();
  78530. }
  78531. if ((thisx.op & 0xf0) == 0) {
  78532. last = thisx;
  78533. for (;;) {
  78534. thisx = state->distcode[last.val +
  78535. (BITS(last.bits + last.op) >> last.bits)];
  78536. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78537. PULLBYTE();
  78538. }
  78539. DROPBITS(last.bits);
  78540. }
  78541. DROPBITS(thisx.bits);
  78542. if (thisx.op & 64) {
  78543. strm->msg = (char *)"invalid distance code";
  78544. state->mode = BAD;
  78545. break;
  78546. }
  78547. state->offset = (unsigned)thisx.val;
  78548. state->extra = (unsigned)(thisx.op) & 15;
  78549. state->mode = DISTEXT;
  78550. case DISTEXT:
  78551. if (state->extra) {
  78552. NEEDBITS(state->extra);
  78553. state->offset += BITS(state->extra);
  78554. DROPBITS(state->extra);
  78555. }
  78556. #ifdef INFLATE_STRICT
  78557. if (state->offset > state->dmax) {
  78558. strm->msg = (char *)"invalid distance too far back";
  78559. state->mode = BAD;
  78560. break;
  78561. }
  78562. #endif
  78563. if (state->offset > state->whave + out - left) {
  78564. strm->msg = (char *)"invalid distance too far back";
  78565. state->mode = BAD;
  78566. break;
  78567. }
  78568. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78569. state->mode = MATCH;
  78570. case MATCH:
  78571. if (left == 0) goto inf_leave;
  78572. copy = out - left;
  78573. if (state->offset > copy) { /* copy from window */
  78574. copy = state->offset - copy;
  78575. if (copy > state->write) {
  78576. copy -= state->write;
  78577. from = state->window + (state->wsize - copy);
  78578. }
  78579. else
  78580. from = state->window + (state->write - copy);
  78581. if (copy > state->length) copy = state->length;
  78582. }
  78583. else { /* copy from output */
  78584. from = put - state->offset;
  78585. copy = state->length;
  78586. }
  78587. if (copy > left) copy = left;
  78588. left -= copy;
  78589. state->length -= copy;
  78590. do {
  78591. *put++ = *from++;
  78592. } while (--copy);
  78593. if (state->length == 0) state->mode = LEN;
  78594. break;
  78595. case LIT:
  78596. if (left == 0) goto inf_leave;
  78597. *put++ = (unsigned char)(state->length);
  78598. left--;
  78599. state->mode = LEN;
  78600. break;
  78601. case CHECK:
  78602. if (state->wrap) {
  78603. NEEDBITS(32);
  78604. out -= left;
  78605. strm->total_out += out;
  78606. state->total += out;
  78607. if (out)
  78608. strm->adler = state->check =
  78609. UPDATE(state->check, put - out, out);
  78610. out = left;
  78611. if ((
  78612. #ifdef GUNZIP
  78613. state->flags ? hold :
  78614. #endif
  78615. REVERSE(hold)) != state->check) {
  78616. strm->msg = (char *)"incorrect data check";
  78617. state->mode = BAD;
  78618. break;
  78619. }
  78620. INITBITS();
  78621. Tracev((stderr, "inflate: check matches trailer\n"));
  78622. }
  78623. #ifdef GUNZIP
  78624. state->mode = LENGTH;
  78625. case LENGTH:
  78626. if (state->wrap && state->flags) {
  78627. NEEDBITS(32);
  78628. if (hold != (state->total & 0xffffffffUL)) {
  78629. strm->msg = (char *)"incorrect length check";
  78630. state->mode = BAD;
  78631. break;
  78632. }
  78633. INITBITS();
  78634. Tracev((stderr, "inflate: length matches trailer\n"));
  78635. }
  78636. #endif
  78637. state->mode = DONE;
  78638. case DONE:
  78639. ret = Z_STREAM_END;
  78640. goto inf_leave;
  78641. case BAD:
  78642. ret = Z_DATA_ERROR;
  78643. goto inf_leave;
  78644. case MEM:
  78645. return Z_MEM_ERROR;
  78646. case SYNC:
  78647. default:
  78648. return Z_STREAM_ERROR;
  78649. }
  78650. inf_leave:
  78651. RESTORE();
  78652. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78653. if (updatewindow(strm, out)) {
  78654. state->mode = MEM;
  78655. return Z_MEM_ERROR;
  78656. }
  78657. in -= strm->avail_in;
  78658. out -= strm->avail_out;
  78659. strm->total_in += in;
  78660. strm->total_out += out;
  78661. state->total += out;
  78662. if (state->wrap && out)
  78663. strm->adler = state->check =
  78664. UPDATE(state->check, strm->next_out - out, out);
  78665. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78666. (state->mode == TYPE ? 128 : 0);
  78667. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78668. ret = Z_BUF_ERROR;
  78669. return ret;
  78670. }
  78671. int ZEXPORT inflateEnd (z_streamp strm)
  78672. {
  78673. struct inflate_state FAR *state;
  78674. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78675. return Z_STREAM_ERROR;
  78676. state = (struct inflate_state FAR *)strm->state;
  78677. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78678. ZFREE(strm, strm->state);
  78679. strm->state = Z_NULL;
  78680. Tracev((stderr, "inflate: end\n"));
  78681. return Z_OK;
  78682. }
  78683. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  78684. {
  78685. struct inflate_state FAR *state;
  78686. unsigned long id_;
  78687. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78688. state = (struct inflate_state FAR *)strm->state;
  78689. if (state->wrap != 0 && state->mode != DICT)
  78690. return Z_STREAM_ERROR;
  78691. if (state->mode == DICT) {
  78692. id_ = adler32(0L, Z_NULL, 0);
  78693. id_ = adler32(id_, dictionary, dictLength);
  78694. if (id_ != state->check)
  78695. return Z_DATA_ERROR;
  78696. }
  78697. if (updatewindow(strm, strm->avail_out)) {
  78698. state->mode = MEM;
  78699. return Z_MEM_ERROR;
  78700. }
  78701. if (dictLength > state->wsize) {
  78702. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  78703. state->wsize);
  78704. state->whave = state->wsize;
  78705. }
  78706. else {
  78707. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  78708. dictLength);
  78709. state->whave = dictLength;
  78710. }
  78711. state->havedict = 1;
  78712. Tracev((stderr, "inflate: dictionary set\n"));
  78713. return Z_OK;
  78714. }
  78715. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  78716. {
  78717. struct inflate_state FAR *state;
  78718. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78719. state = (struct inflate_state FAR *)strm->state;
  78720. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  78721. state->head = head;
  78722. head->done = 0;
  78723. return Z_OK;
  78724. }
  78725. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  78726. {
  78727. unsigned got;
  78728. unsigned next;
  78729. got = *have;
  78730. next = 0;
  78731. while (next < len && got < 4) {
  78732. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  78733. got++;
  78734. else if (buf[next])
  78735. got = 0;
  78736. else
  78737. got = 4 - got;
  78738. next++;
  78739. }
  78740. *have = got;
  78741. return next;
  78742. }
  78743. int ZEXPORT inflateSync (z_streamp strm)
  78744. {
  78745. unsigned len; /* number of bytes to look at or looked at */
  78746. unsigned long in, out; /* temporary to save total_in and total_out */
  78747. unsigned char buf[4]; /* to restore bit buffer to byte string */
  78748. struct inflate_state FAR *state;
  78749. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78750. state = (struct inflate_state FAR *)strm->state;
  78751. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  78752. if (state->mode != SYNC) {
  78753. state->mode = SYNC;
  78754. state->hold <<= state->bits & 7;
  78755. state->bits -= state->bits & 7;
  78756. len = 0;
  78757. while (state->bits >= 8) {
  78758. buf[len++] = (unsigned char)(state->hold);
  78759. state->hold >>= 8;
  78760. state->bits -= 8;
  78761. }
  78762. state->have = 0;
  78763. syncsearch(&(state->have), buf, len);
  78764. }
  78765. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  78766. strm->avail_in -= len;
  78767. strm->next_in += len;
  78768. strm->total_in += len;
  78769. if (state->have != 4) return Z_DATA_ERROR;
  78770. in = strm->total_in; out = strm->total_out;
  78771. inflateReset(strm);
  78772. strm->total_in = in; strm->total_out = out;
  78773. state->mode = TYPE;
  78774. return Z_OK;
  78775. }
  78776. int ZEXPORT inflateSyncPoint (z_streamp strm)
  78777. {
  78778. struct inflate_state FAR *state;
  78779. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78780. state = (struct inflate_state FAR *)strm->state;
  78781. return state->mode == STORED && state->bits == 0;
  78782. }
  78783. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  78784. {
  78785. struct inflate_state FAR *state;
  78786. struct inflate_state FAR *copy;
  78787. unsigned char FAR *window;
  78788. unsigned wsize;
  78789. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  78790. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  78791. return Z_STREAM_ERROR;
  78792. state = (struct inflate_state FAR *)source->state;
  78793. copy = (struct inflate_state FAR *)
  78794. ZALLOC(source, 1, sizeof(struct inflate_state));
  78795. if (copy == Z_NULL) return Z_MEM_ERROR;
  78796. window = Z_NULL;
  78797. if (state->window != Z_NULL) {
  78798. window = (unsigned char FAR *)
  78799. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  78800. if (window == Z_NULL) {
  78801. ZFREE(source, copy);
  78802. return Z_MEM_ERROR;
  78803. }
  78804. }
  78805. zmemcpy(dest, source, sizeof(z_stream));
  78806. zmemcpy(copy, state, sizeof(struct inflate_state));
  78807. if (state->lencode >= state->codes &&
  78808. state->lencode <= state->codes + ENOUGH - 1) {
  78809. copy->lencode = copy->codes + (state->lencode - state->codes);
  78810. copy->distcode = copy->codes + (state->distcode - state->codes);
  78811. }
  78812. copy->next = copy->codes + (state->next - state->codes);
  78813. if (window != Z_NULL) {
  78814. wsize = 1U << state->wbits;
  78815. zmemcpy(window, state->window, wsize);
  78816. }
  78817. copy->window = window;
  78818. dest->state = (struct internal_state FAR *)copy;
  78819. return Z_OK;
  78820. }
  78821. /*** End of inlined file: inflate.c ***/
  78822. /*** Start of inlined file: inftrees.c ***/
  78823. #define MAXBITS 15
  78824. const char inflate_copyright[] =
  78825. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  78826. int inflate_table (codetype type,
  78827. unsigned short FAR *lens,
  78828. unsigned codes,
  78829. code FAR * FAR *table,
  78830. unsigned FAR *bits,
  78831. unsigned short FAR *work)
  78832. {
  78833. unsigned len; /* a code's length in bits */
  78834. unsigned sym; /* index of code symbols */
  78835. unsigned min, max; /* minimum and maximum code lengths */
  78836. unsigned root; /* number of index bits for root table */
  78837. unsigned curr; /* number of index bits for current table */
  78838. unsigned drop; /* code bits to drop for sub-table */
  78839. int left; /* number of prefix codes available */
  78840. unsigned used; /* code entries in table used */
  78841. unsigned huff; /* Huffman code */
  78842. unsigned incr; /* for incrementing code, index */
  78843. unsigned fill; /* index for replicating entries */
  78844. unsigned low; /* low bits for current root entry */
  78845. unsigned mask; /* mask for low root bits */
  78846. code thisx; /* table entry for duplication */
  78847. code FAR *next; /* next available space in table */
  78848. const unsigned short FAR *base; /* base value table to use */
  78849. const unsigned short FAR *extra; /* extra bits table to use */
  78850. int end; /* use base and extra for symbol > end */
  78851. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  78852. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  78853. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  78854. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  78855. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  78856. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  78857. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  78858. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  78859. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  78860. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  78861. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  78862. 8193, 12289, 16385, 24577, 0, 0};
  78863. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  78864. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  78865. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  78866. 28, 28, 29, 29, 64, 64};
  78867. for (len = 0; len <= MAXBITS; len++)
  78868. count[len] = 0;
  78869. for (sym = 0; sym < codes; sym++)
  78870. count[lens[sym]]++;
  78871. root = *bits;
  78872. for (max = MAXBITS; max >= 1; max--)
  78873. if (count[max] != 0) break;
  78874. if (root > max) root = max;
  78875. if (max == 0) { /* no symbols to code at all */
  78876. thisx.op = (unsigned char)64; /* invalid code marker */
  78877. thisx.bits = (unsigned char)1;
  78878. thisx.val = (unsigned short)0;
  78879. *(*table)++ = thisx; /* make a table to force an error */
  78880. *(*table)++ = thisx;
  78881. *bits = 1;
  78882. return 0; /* no symbols, but wait for decoding to report error */
  78883. }
  78884. for (min = 1; min <= MAXBITS; min++)
  78885. if (count[min] != 0) break;
  78886. if (root < min) root = min;
  78887. left = 1;
  78888. for (len = 1; len <= MAXBITS; len++) {
  78889. left <<= 1;
  78890. left -= count[len];
  78891. if (left < 0) return -1; /* over-subscribed */
  78892. }
  78893. if (left > 0 && (type == CODES || max != 1))
  78894. return -1; /* incomplete set */
  78895. offs[1] = 0;
  78896. for (len = 1; len < MAXBITS; len++)
  78897. offs[len + 1] = offs[len] + count[len];
  78898. for (sym = 0; sym < codes; sym++)
  78899. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  78900. switch (type) {
  78901. case CODES:
  78902. base = extra = work; /* dummy value--not used */
  78903. end = 19;
  78904. break;
  78905. case LENS:
  78906. base = lbase;
  78907. base -= 257;
  78908. extra = lext;
  78909. extra -= 257;
  78910. end = 256;
  78911. break;
  78912. default: /* DISTS */
  78913. base = dbase;
  78914. extra = dext;
  78915. end = -1;
  78916. }
  78917. huff = 0; /* starting code */
  78918. sym = 0; /* starting code symbol */
  78919. len = min; /* starting code length */
  78920. next = *table; /* current table to fill in */
  78921. curr = root; /* current table index bits */
  78922. drop = 0; /* current bits to drop from code for index */
  78923. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  78924. used = 1U << root; /* use root table entries */
  78925. mask = used - 1; /* mask for comparing low */
  78926. if (type == LENS && used >= ENOUGH - MAXD)
  78927. return 1;
  78928. for (;;) {
  78929. thisx.bits = (unsigned char)(len - drop);
  78930. if ((int)(work[sym]) < end) {
  78931. thisx.op = (unsigned char)0;
  78932. thisx.val = work[sym];
  78933. }
  78934. else if ((int)(work[sym]) > end) {
  78935. thisx.op = (unsigned char)(extra[work[sym]]);
  78936. thisx.val = base[work[sym]];
  78937. }
  78938. else {
  78939. thisx.op = (unsigned char)(32 + 64); /* end of block */
  78940. thisx.val = 0;
  78941. }
  78942. incr = 1U << (len - drop);
  78943. fill = 1U << curr;
  78944. min = fill; /* save offset to next table */
  78945. do {
  78946. fill -= incr;
  78947. next[(huff >> drop) + fill] = thisx;
  78948. } while (fill != 0);
  78949. incr = 1U << (len - 1);
  78950. while (huff & incr)
  78951. incr >>= 1;
  78952. if (incr != 0) {
  78953. huff &= incr - 1;
  78954. huff += incr;
  78955. }
  78956. else
  78957. huff = 0;
  78958. sym++;
  78959. if (--(count[len]) == 0) {
  78960. if (len == max) break;
  78961. len = lens[work[sym]];
  78962. }
  78963. if (len > root && (huff & mask) != low) {
  78964. if (drop == 0)
  78965. drop = root;
  78966. next += min; /* here min is 1 << curr */
  78967. curr = len - drop;
  78968. left = (int)(1 << curr);
  78969. while (curr + drop < max) {
  78970. left -= count[curr + drop];
  78971. if (left <= 0) break;
  78972. curr++;
  78973. left <<= 1;
  78974. }
  78975. used += 1U << curr;
  78976. if (type == LENS && used >= ENOUGH - MAXD)
  78977. return 1;
  78978. low = huff & mask;
  78979. (*table)[low].op = (unsigned char)curr;
  78980. (*table)[low].bits = (unsigned char)root;
  78981. (*table)[low].val = (unsigned short)(next - *table);
  78982. }
  78983. }
  78984. thisx.op = (unsigned char)64; /* invalid code marker */
  78985. thisx.bits = (unsigned char)(len - drop);
  78986. thisx.val = (unsigned short)0;
  78987. while (huff != 0) {
  78988. if (drop != 0 && (huff & mask) != low) {
  78989. drop = 0;
  78990. len = root;
  78991. next = *table;
  78992. thisx.bits = (unsigned char)len;
  78993. }
  78994. next[huff >> drop] = thisx;
  78995. incr = 1U << (len - 1);
  78996. while (huff & incr)
  78997. incr >>= 1;
  78998. if (incr != 0) {
  78999. huff &= incr - 1;
  79000. huff += incr;
  79001. }
  79002. else
  79003. huff = 0;
  79004. }
  79005. *table += used;
  79006. *bits = root;
  79007. return 0;
  79008. }
  79009. /*** End of inlined file: inftrees.c ***/
  79010. /*** Start of inlined file: trees.c ***/
  79011. #ifdef DEBUG
  79012. # include <ctype.h>
  79013. #endif
  79014. #define MAX_BL_BITS 7
  79015. #define END_BLOCK 256
  79016. #define REP_3_6 16
  79017. #define REPZ_3_10 17
  79018. #define REPZ_11_138 18
  79019. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79020. = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
  79021. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79022. = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
  79023. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79024. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79025. local const uch bl_order[BL_CODES]
  79026. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79027. #define Buf_size (8 * 2*sizeof(char))
  79028. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79029. #if defined(GEN_TREES_H) || !defined(STDC)
  79030. local ct_data static_ltree[L_CODES+2];
  79031. local ct_data static_dtree[D_CODES];
  79032. uch _dist_code[DIST_CODE_LEN];
  79033. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79034. local int base_length[LENGTH_CODES];
  79035. local int base_dist[D_CODES];
  79036. #else
  79037. /*** Start of inlined file: trees.h ***/
  79038. local const ct_data static_ltree[L_CODES+2] = {
  79039. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79040. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79041. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79042. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79043. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79044. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79045. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79046. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79047. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79048. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79049. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79050. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79051. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79052. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79053. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79054. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79055. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79056. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79057. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79058. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79059. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79060. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79061. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79062. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79063. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79064. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79065. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79066. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79067. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79068. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79069. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79070. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79071. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79072. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79073. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79074. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79075. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79076. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79077. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79078. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79079. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79080. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79081. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79082. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79083. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79084. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79085. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79086. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79087. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79088. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79089. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79090. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79091. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79092. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79093. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79094. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79095. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79096. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79097. };
  79098. local const ct_data static_dtree[D_CODES] = {
  79099. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79100. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79101. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79102. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79103. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79104. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79105. };
  79106. const uch _dist_code[DIST_CODE_LEN] = {
  79107. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79108. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79109. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79110. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79111. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79112. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79113. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79114. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79115. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79116. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79117. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79118. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79119. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79120. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79121. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79122. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79123. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79124. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79125. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79126. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79127. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79128. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79129. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79130. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79131. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79132. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79133. };
  79134. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79135. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79136. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79137. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79138. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79139. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79140. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79141. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79142. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79143. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79144. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79145. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79146. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79147. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79148. };
  79149. local const int base_length[LENGTH_CODES] = {
  79150. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79151. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79152. };
  79153. local const int base_dist[D_CODES] = {
  79154. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79155. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79156. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79157. };
  79158. /*** End of inlined file: trees.h ***/
  79159. #endif /* GEN_TREES_H */
  79160. struct static_tree_desc_s {
  79161. const ct_data *static_tree; /* static tree or NULL */
  79162. const intf *extra_bits; /* extra bits for each code or NULL */
  79163. int extra_base; /* base index for extra_bits */
  79164. int elems; /* max number of elements in the tree */
  79165. int max_length; /* max bit length for the codes */
  79166. };
  79167. local static_tree_desc static_l_desc =
  79168. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79169. local static_tree_desc static_d_desc =
  79170. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79171. local static_tree_desc static_bl_desc =
  79172. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79173. local void tr_static_init OF((void));
  79174. local void init_block OF((deflate_state *s));
  79175. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79176. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79177. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79178. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79179. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79180. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79181. local int build_bl_tree OF((deflate_state *s));
  79182. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79183. int blcodes));
  79184. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79185. ct_data *dtree));
  79186. local void set_data_type OF((deflate_state *s));
  79187. local unsigned bi_reverse OF((unsigned value, int length));
  79188. local void bi_windup OF((deflate_state *s));
  79189. local void bi_flush OF((deflate_state *s));
  79190. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79191. int header));
  79192. #ifdef GEN_TREES_H
  79193. local void gen_trees_header OF((void));
  79194. #endif
  79195. #ifndef DEBUG
  79196. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79197. #else /* DEBUG */
  79198. # define send_code(s, c, tree) \
  79199. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79200. send_bits(s, tree[c].Code, tree[c].Len); }
  79201. #endif
  79202. #define put_short(s, w) { \
  79203. put_byte(s, (uch)((w) & 0xff)); \
  79204. put_byte(s, (uch)((ush)(w) >> 8)); \
  79205. }
  79206. #ifdef DEBUG
  79207. local void send_bits OF((deflate_state *s, int value, int length));
  79208. local void send_bits (deflate_state *s, int value, int length)
  79209. {
  79210. Tracevv((stderr," l %2d v %4x ", length, value));
  79211. Assert(length > 0 && length <= 15, "invalid length");
  79212. s->bits_sent += (ulg)length;
  79213. if (s->bi_valid > (int)Buf_size - length) {
  79214. s->bi_buf |= (value << s->bi_valid);
  79215. put_short(s, s->bi_buf);
  79216. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79217. s->bi_valid += length - Buf_size;
  79218. } else {
  79219. s->bi_buf |= value << s->bi_valid;
  79220. s->bi_valid += length;
  79221. }
  79222. }
  79223. #else /* !DEBUG */
  79224. #define send_bits(s, value, length) \
  79225. { int len = length;\
  79226. if (s->bi_valid > (int)Buf_size - len) {\
  79227. int val = value;\
  79228. s->bi_buf |= (val << s->bi_valid);\
  79229. put_short(s, s->bi_buf);\
  79230. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79231. s->bi_valid += len - Buf_size;\
  79232. } else {\
  79233. s->bi_buf |= (value) << s->bi_valid;\
  79234. s->bi_valid += len;\
  79235. }\
  79236. }
  79237. #endif /* DEBUG */
  79238. local void tr_static_init()
  79239. {
  79240. #if defined(GEN_TREES_H) || !defined(STDC)
  79241. static int static_init_done = 0;
  79242. int n; /* iterates over tree elements */
  79243. int bits; /* bit counter */
  79244. int length; /* length value */
  79245. int code; /* code value */
  79246. int dist; /* distance index */
  79247. ush bl_count[MAX_BITS+1];
  79248. if (static_init_done) return;
  79249. static_l_desc.static_tree = static_ltree;
  79250. static_l_desc.extra_bits = extra_lbits;
  79251. static_d_desc.static_tree = static_dtree;
  79252. static_d_desc.extra_bits = extra_dbits;
  79253. static_bl_desc.extra_bits = extra_blbits;
  79254. length = 0;
  79255. for (code = 0; code < LENGTH_CODES-1; code++) {
  79256. base_length[code] = length;
  79257. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79258. _length_code[length++] = (uch)code;
  79259. }
  79260. }
  79261. Assert (length == 256, "tr_static_init: length != 256");
  79262. _length_code[length-1] = (uch)code;
  79263. dist = 0;
  79264. for (code = 0 ; code < 16; code++) {
  79265. base_dist[code] = dist;
  79266. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79267. _dist_code[dist++] = (uch)code;
  79268. }
  79269. }
  79270. Assert (dist == 256, "tr_static_init: dist != 256");
  79271. dist >>= 7; /* from now on, all distances are divided by 128 */
  79272. for ( ; code < D_CODES; code++) {
  79273. base_dist[code] = dist << 7;
  79274. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79275. _dist_code[256 + dist++] = (uch)code;
  79276. }
  79277. }
  79278. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79279. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79280. n = 0;
  79281. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79282. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79283. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79284. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79285. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79286. for (n = 0; n < D_CODES; n++) {
  79287. static_dtree[n].Len = 5;
  79288. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79289. }
  79290. static_init_done = 1;
  79291. # ifdef GEN_TREES_H
  79292. gen_trees_header();
  79293. # endif
  79294. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79295. }
  79296. #ifdef GEN_TREES_H
  79297. # ifndef DEBUG
  79298. # include <stdio.h>
  79299. # endif
  79300. # define SEPARATOR(i, last, width) \
  79301. ((i) == (last)? "\n};\n\n" : \
  79302. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79303. void gen_trees_header()
  79304. {
  79305. FILE *header = fopen("trees.h", "w");
  79306. int i;
  79307. Assert (header != NULL, "Can't open trees.h");
  79308. fprintf(header,
  79309. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79310. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79311. for (i = 0; i < L_CODES+2; i++) {
  79312. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79313. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79314. }
  79315. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79316. for (i = 0; i < D_CODES; i++) {
  79317. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79318. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79319. }
  79320. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79321. for (i = 0; i < DIST_CODE_LEN; i++) {
  79322. fprintf(header, "%2u%s", _dist_code[i],
  79323. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79324. }
  79325. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79326. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79327. fprintf(header, "%2u%s", _length_code[i],
  79328. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79329. }
  79330. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79331. for (i = 0; i < LENGTH_CODES; i++) {
  79332. fprintf(header, "%1u%s", base_length[i],
  79333. SEPARATOR(i, LENGTH_CODES-1, 20));
  79334. }
  79335. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79336. for (i = 0; i < D_CODES; i++) {
  79337. fprintf(header, "%5u%s", base_dist[i],
  79338. SEPARATOR(i, D_CODES-1, 10));
  79339. }
  79340. fclose(header);
  79341. }
  79342. #endif /* GEN_TREES_H */
  79343. void _tr_init(deflate_state *s)
  79344. {
  79345. tr_static_init();
  79346. s->l_desc.dyn_tree = s->dyn_ltree;
  79347. s->l_desc.stat_desc = &static_l_desc;
  79348. s->d_desc.dyn_tree = s->dyn_dtree;
  79349. s->d_desc.stat_desc = &static_d_desc;
  79350. s->bl_desc.dyn_tree = s->bl_tree;
  79351. s->bl_desc.stat_desc = &static_bl_desc;
  79352. s->bi_buf = 0;
  79353. s->bi_valid = 0;
  79354. s->last_eob_len = 8; /* enough lookahead for inflate */
  79355. #ifdef DEBUG
  79356. s->compressed_len = 0L;
  79357. s->bits_sent = 0L;
  79358. #endif
  79359. init_block(s);
  79360. }
  79361. local void init_block (deflate_state *s)
  79362. {
  79363. int n; /* iterates over tree elements */
  79364. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79365. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79366. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79367. s->dyn_ltree[END_BLOCK].Freq = 1;
  79368. s->opt_len = s->static_len = 0L;
  79369. s->last_lit = s->matches = 0;
  79370. }
  79371. #define SMALLEST 1
  79372. #define pqremove(s, tree, top) \
  79373. {\
  79374. top = s->heap[SMALLEST]; \
  79375. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79376. pqdownheap(s, tree, SMALLEST); \
  79377. }
  79378. #define smaller(tree, n, m, depth) \
  79379. (tree[n].Freq < tree[m].Freq || \
  79380. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79381. local void pqdownheap (deflate_state *s,
  79382. ct_data *tree, /* the tree to restore */
  79383. int k) /* node to move down */
  79384. {
  79385. int v = s->heap[k];
  79386. int j = k << 1; /* left son of k */
  79387. while (j <= s->heap_len) {
  79388. if (j < s->heap_len &&
  79389. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79390. j++;
  79391. }
  79392. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79393. s->heap[k] = s->heap[j]; k = j;
  79394. j <<= 1;
  79395. }
  79396. s->heap[k] = v;
  79397. }
  79398. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79399. {
  79400. ct_data *tree = desc->dyn_tree;
  79401. int max_code = desc->max_code;
  79402. const ct_data *stree = desc->stat_desc->static_tree;
  79403. const intf *extra = desc->stat_desc->extra_bits;
  79404. int base = desc->stat_desc->extra_base;
  79405. int max_length = desc->stat_desc->max_length;
  79406. int h; /* heap index */
  79407. int n, m; /* iterate over the tree elements */
  79408. int bits; /* bit length */
  79409. int xbits; /* extra bits */
  79410. ush f; /* frequency */
  79411. int overflow = 0; /* number of elements with bit length too large */
  79412. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79413. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79414. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79415. n = s->heap[h];
  79416. bits = tree[tree[n].Dad].Len + 1;
  79417. if (bits > max_length) bits = max_length, overflow++;
  79418. tree[n].Len = (ush)bits;
  79419. if (n > max_code) continue; /* not a leaf node */
  79420. s->bl_count[bits]++;
  79421. xbits = 0;
  79422. if (n >= base) xbits = extra[n-base];
  79423. f = tree[n].Freq;
  79424. s->opt_len += (ulg)f * (bits + xbits);
  79425. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79426. }
  79427. if (overflow == 0) return;
  79428. Trace((stderr,"\nbit length overflow\n"));
  79429. do {
  79430. bits = max_length-1;
  79431. while (s->bl_count[bits] == 0) bits--;
  79432. s->bl_count[bits]--; /* move one leaf down the tree */
  79433. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79434. s->bl_count[max_length]--;
  79435. overflow -= 2;
  79436. } while (overflow > 0);
  79437. for (bits = max_length; bits != 0; bits--) {
  79438. n = s->bl_count[bits];
  79439. while (n != 0) {
  79440. m = s->heap[--h];
  79441. if (m > max_code) continue;
  79442. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79443. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79444. s->opt_len += ((long)bits - (long)tree[m].Len)
  79445. *(long)tree[m].Freq;
  79446. tree[m].Len = (ush)bits;
  79447. }
  79448. n--;
  79449. }
  79450. }
  79451. }
  79452. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79453. int max_code, /* largest code with non zero frequency */
  79454. ushf *bl_count) /* number of codes at each bit length */
  79455. {
  79456. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79457. ush code = 0; /* running code value */
  79458. int bits; /* bit index */
  79459. int n; /* code index */
  79460. for (bits = 1; bits <= MAX_BITS; bits++) {
  79461. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79462. }
  79463. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79464. "inconsistent bit counts");
  79465. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79466. for (n = 0; n <= max_code; n++) {
  79467. int len = tree[n].Len;
  79468. if (len == 0) continue;
  79469. tree[n].Code = bi_reverse(next_code[len]++, len);
  79470. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79471. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79472. }
  79473. }
  79474. local void build_tree (deflate_state *s,
  79475. tree_desc *desc) /* the tree descriptor */
  79476. {
  79477. ct_data *tree = desc->dyn_tree;
  79478. const ct_data *stree = desc->stat_desc->static_tree;
  79479. int elems = desc->stat_desc->elems;
  79480. int n, m; /* iterate over heap elements */
  79481. int max_code = -1; /* largest code with non zero frequency */
  79482. int node; /* new node being created */
  79483. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79484. for (n = 0; n < elems; n++) {
  79485. if (tree[n].Freq != 0) {
  79486. s->heap[++(s->heap_len)] = max_code = n;
  79487. s->depth[n] = 0;
  79488. } else {
  79489. tree[n].Len = 0;
  79490. }
  79491. }
  79492. while (s->heap_len < 2) {
  79493. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79494. tree[node].Freq = 1;
  79495. s->depth[node] = 0;
  79496. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79497. }
  79498. desc->max_code = max_code;
  79499. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79500. node = elems; /* next internal node of the tree */
  79501. do {
  79502. pqremove(s, tree, n); /* n = node of least frequency */
  79503. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79504. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79505. s->heap[--(s->heap_max)] = m;
  79506. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79507. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79508. s->depth[n] : s->depth[m]) + 1);
  79509. tree[n].Dad = tree[m].Dad = (ush)node;
  79510. #ifdef DUMP_BL_TREE
  79511. if (tree == s->bl_tree) {
  79512. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79513. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79514. }
  79515. #endif
  79516. s->heap[SMALLEST] = node++;
  79517. pqdownheap(s, tree, SMALLEST);
  79518. } while (s->heap_len >= 2);
  79519. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79520. gen_bitlen(s, (tree_desc *)desc);
  79521. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79522. }
  79523. local void scan_tree (deflate_state *s,
  79524. ct_data *tree, /* the tree to be scanned */
  79525. int max_code) /* and its largest code of non zero frequency */
  79526. {
  79527. int n; /* iterates over all tree elements */
  79528. int prevlen = -1; /* last emitted length */
  79529. int curlen; /* length of current code */
  79530. int nextlen = tree[0].Len; /* length of next code */
  79531. int count = 0; /* repeat count of the current code */
  79532. int max_count = 7; /* max repeat count */
  79533. int min_count = 4; /* min repeat count */
  79534. if (nextlen == 0) max_count = 138, min_count = 3;
  79535. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79536. for (n = 0; n <= max_code; n++) {
  79537. curlen = nextlen; nextlen = tree[n+1].Len;
  79538. if (++count < max_count && curlen == nextlen) {
  79539. continue;
  79540. } else if (count < min_count) {
  79541. s->bl_tree[curlen].Freq += count;
  79542. } else if (curlen != 0) {
  79543. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79544. s->bl_tree[REP_3_6].Freq++;
  79545. } else if (count <= 10) {
  79546. s->bl_tree[REPZ_3_10].Freq++;
  79547. } else {
  79548. s->bl_tree[REPZ_11_138].Freq++;
  79549. }
  79550. count = 0; prevlen = curlen;
  79551. if (nextlen == 0) {
  79552. max_count = 138, min_count = 3;
  79553. } else if (curlen == nextlen) {
  79554. max_count = 6, min_count = 3;
  79555. } else {
  79556. max_count = 7, min_count = 4;
  79557. }
  79558. }
  79559. }
  79560. local void send_tree (deflate_state *s,
  79561. ct_data *tree, /* the tree to be scanned */
  79562. int max_code) /* and its largest code of non zero frequency */
  79563. {
  79564. int n; /* iterates over all tree elements */
  79565. int prevlen = -1; /* last emitted length */
  79566. int curlen; /* length of current code */
  79567. int nextlen = tree[0].Len; /* length of next code */
  79568. int count = 0; /* repeat count of the current code */
  79569. int max_count = 7; /* max repeat count */
  79570. int min_count = 4; /* min repeat count */
  79571. /* guard already set */
  79572. if (nextlen == 0) max_count = 138, min_count = 3;
  79573. for (n = 0; n <= max_code; n++) {
  79574. curlen = nextlen; nextlen = tree[n+1].Len;
  79575. if (++count < max_count && curlen == nextlen) {
  79576. continue;
  79577. } else if (count < min_count) {
  79578. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79579. } else if (curlen != 0) {
  79580. if (curlen != prevlen) {
  79581. send_code(s, curlen, s->bl_tree); count--;
  79582. }
  79583. Assert(count >= 3 && count <= 6, " 3_6?");
  79584. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79585. } else if (count <= 10) {
  79586. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79587. } else {
  79588. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79589. }
  79590. count = 0; prevlen = curlen;
  79591. if (nextlen == 0) {
  79592. max_count = 138, min_count = 3;
  79593. } else if (curlen == nextlen) {
  79594. max_count = 6, min_count = 3;
  79595. } else {
  79596. max_count = 7, min_count = 4;
  79597. }
  79598. }
  79599. }
  79600. local int build_bl_tree (deflate_state *s)
  79601. {
  79602. int max_blindex; /* index of last bit length code of non zero freq */
  79603. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79604. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79605. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79606. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79607. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79608. }
  79609. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79610. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79611. s->opt_len, s->static_len));
  79612. return max_blindex;
  79613. }
  79614. local void send_all_trees (deflate_state *s,
  79615. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79616. {
  79617. int rank; /* index in bl_order */
  79618. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79619. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79620. "too many codes");
  79621. Tracev((stderr, "\nbl counts: "));
  79622. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79623. send_bits(s, dcodes-1, 5);
  79624. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79625. for (rank = 0; rank < blcodes; rank++) {
  79626. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79627. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79628. }
  79629. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79630. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79631. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79632. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79633. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79634. }
  79635. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79636. {
  79637. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79638. #ifdef DEBUG
  79639. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79640. s->compressed_len += (stored_len + 4) << 3;
  79641. #endif
  79642. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79643. }
  79644. void _tr_align (deflate_state *s)
  79645. {
  79646. send_bits(s, STATIC_TREES<<1, 3);
  79647. send_code(s, END_BLOCK, static_ltree);
  79648. #ifdef DEBUG
  79649. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79650. #endif
  79651. bi_flush(s);
  79652. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79653. send_bits(s, STATIC_TREES<<1, 3);
  79654. send_code(s, END_BLOCK, static_ltree);
  79655. #ifdef DEBUG
  79656. s->compressed_len += 10L;
  79657. #endif
  79658. bi_flush(s);
  79659. }
  79660. s->last_eob_len = 7;
  79661. }
  79662. void _tr_flush_block (deflate_state *s,
  79663. charf *buf, /* input block, or NULL if too old */
  79664. ulg stored_len, /* length of input block */
  79665. int eof) /* true if this is the last block for a file */
  79666. {
  79667. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79668. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79669. if (s->level > 0) {
  79670. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79671. set_data_type(s);
  79672. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79673. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79674. s->static_len));
  79675. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79676. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79677. s->static_len));
  79678. max_blindex = build_bl_tree(s);
  79679. opt_lenb = (s->opt_len+3+7)>>3;
  79680. static_lenb = (s->static_len+3+7)>>3;
  79681. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  79682. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  79683. s->last_lit));
  79684. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  79685. } else {
  79686. Assert(buf != (char*)0, "lost buf");
  79687. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  79688. }
  79689. #ifdef FORCE_STORED
  79690. if (buf != (char*)0) { /* force stored block */
  79691. #else
  79692. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  79693. #endif
  79694. _tr_stored_block(s, buf, stored_len, eof);
  79695. #ifdef FORCE_STATIC
  79696. } else if (static_lenb >= 0) { /* force static trees */
  79697. #else
  79698. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  79699. #endif
  79700. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  79701. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  79702. #ifdef DEBUG
  79703. s->compressed_len += 3 + s->static_len;
  79704. #endif
  79705. } else {
  79706. send_bits(s, (DYN_TREES<<1)+eof, 3);
  79707. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  79708. max_blindex+1);
  79709. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  79710. #ifdef DEBUG
  79711. s->compressed_len += 3 + s->opt_len;
  79712. #endif
  79713. }
  79714. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  79715. init_block(s);
  79716. if (eof) {
  79717. bi_windup(s);
  79718. #ifdef DEBUG
  79719. s->compressed_len += 7; /* align on byte boundary */
  79720. #endif
  79721. }
  79722. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  79723. s->compressed_len-7*eof));
  79724. }
  79725. int _tr_tally (deflate_state *s,
  79726. unsigned dist, /* distance of matched string */
  79727. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  79728. {
  79729. s->d_buf[s->last_lit] = (ush)dist;
  79730. s->l_buf[s->last_lit++] = (uch)lc;
  79731. if (dist == 0) {
  79732. s->dyn_ltree[lc].Freq++;
  79733. } else {
  79734. s->matches++;
  79735. dist--; /* dist = match distance - 1 */
  79736. Assert((ush)dist < (ush)MAX_DIST(s) &&
  79737. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  79738. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  79739. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  79740. s->dyn_dtree[d_code(dist)].Freq++;
  79741. }
  79742. #ifdef TRUNCATE_BLOCK
  79743. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  79744. ulg out_length = (ulg)s->last_lit*8L;
  79745. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  79746. int dcode;
  79747. for (dcode = 0; dcode < D_CODES; dcode++) {
  79748. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  79749. (5L+extra_dbits[dcode]);
  79750. }
  79751. out_length >>= 3;
  79752. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  79753. s->last_lit, in_length, out_length,
  79754. 100L - out_length*100L/in_length));
  79755. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  79756. }
  79757. #endif
  79758. return (s->last_lit == s->lit_bufsize-1);
  79759. }
  79760. local void compress_block (deflate_state *s,
  79761. ct_data *ltree, /* literal tree */
  79762. ct_data *dtree) /* distance tree */
  79763. {
  79764. unsigned dist; /* distance of matched string */
  79765. int lc; /* match length or unmatched char (if dist == 0) */
  79766. unsigned lx = 0; /* running index in l_buf */
  79767. unsigned code; /* the code to send */
  79768. int extra; /* number of extra bits to send */
  79769. if (s->last_lit != 0) do {
  79770. dist = s->d_buf[lx];
  79771. lc = s->l_buf[lx++];
  79772. if (dist == 0) {
  79773. send_code(s, lc, ltree); /* send a literal byte */
  79774. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  79775. } else {
  79776. code = _length_code[lc];
  79777. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  79778. extra = extra_lbits[code];
  79779. if (extra != 0) {
  79780. lc -= base_length[code];
  79781. send_bits(s, lc, extra); /* send the extra length bits */
  79782. }
  79783. dist--; /* dist is now the match distance - 1 */
  79784. code = d_code(dist);
  79785. Assert (code < D_CODES, "bad d_code");
  79786. send_code(s, code, dtree); /* send the distance code */
  79787. extra = extra_dbits[code];
  79788. if (extra != 0) {
  79789. dist -= base_dist[code];
  79790. send_bits(s, dist, extra); /* send the extra distance bits */
  79791. }
  79792. } /* literal or match pair ? */
  79793. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  79794. "pendingBuf overflow");
  79795. } while (lx < s->last_lit);
  79796. send_code(s, END_BLOCK, ltree);
  79797. s->last_eob_len = ltree[END_BLOCK].Len;
  79798. }
  79799. local void set_data_type (deflate_state *s)
  79800. {
  79801. int n;
  79802. for (n = 0; n < 9; n++)
  79803. if (s->dyn_ltree[n].Freq != 0)
  79804. break;
  79805. if (n == 9)
  79806. for (n = 14; n < 32; n++)
  79807. if (s->dyn_ltree[n].Freq != 0)
  79808. break;
  79809. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  79810. }
  79811. local unsigned bi_reverse (unsigned code, int len)
  79812. {
  79813. register unsigned res = 0;
  79814. do {
  79815. res |= code & 1;
  79816. code >>= 1, res <<= 1;
  79817. } while (--len > 0);
  79818. return res >> 1;
  79819. }
  79820. local void bi_flush (deflate_state *s)
  79821. {
  79822. if (s->bi_valid == 16) {
  79823. put_short(s, s->bi_buf);
  79824. s->bi_buf = 0;
  79825. s->bi_valid = 0;
  79826. } else if (s->bi_valid >= 8) {
  79827. put_byte(s, (Byte)s->bi_buf);
  79828. s->bi_buf >>= 8;
  79829. s->bi_valid -= 8;
  79830. }
  79831. }
  79832. local void bi_windup (deflate_state *s)
  79833. {
  79834. if (s->bi_valid > 8) {
  79835. put_short(s, s->bi_buf);
  79836. } else if (s->bi_valid > 0) {
  79837. put_byte(s, (Byte)s->bi_buf);
  79838. }
  79839. s->bi_buf = 0;
  79840. s->bi_valid = 0;
  79841. #ifdef DEBUG
  79842. s->bits_sent = (s->bits_sent+7) & ~7;
  79843. #endif
  79844. }
  79845. local void copy_block(deflate_state *s,
  79846. charf *buf, /* the input data */
  79847. unsigned len, /* its length */
  79848. int header) /* true if block header must be written */
  79849. {
  79850. bi_windup(s); /* align on byte boundary */
  79851. s->last_eob_len = 8; /* enough lookahead for inflate */
  79852. if (header) {
  79853. put_short(s, (ush)len);
  79854. put_short(s, (ush)~len);
  79855. #ifdef DEBUG
  79856. s->bits_sent += 2*16;
  79857. #endif
  79858. }
  79859. #ifdef DEBUG
  79860. s->bits_sent += (ulg)len<<3;
  79861. #endif
  79862. while (len--) {
  79863. put_byte(s, *buf++);
  79864. }
  79865. }
  79866. /*** End of inlined file: trees.c ***/
  79867. /*** Start of inlined file: zutil.c ***/
  79868. #ifndef NO_DUMMY_DECL
  79869. struct internal_state {int dummy;}; /* for buggy compilers */
  79870. #endif
  79871. const char * const z_errmsg[10] = {
  79872. "need dictionary", /* Z_NEED_DICT 2 */
  79873. "stream end", /* Z_STREAM_END 1 */
  79874. "", /* Z_OK 0 */
  79875. "file error", /* Z_ERRNO (-1) */
  79876. "stream error", /* Z_STREAM_ERROR (-2) */
  79877. "data error", /* Z_DATA_ERROR (-3) */
  79878. "insufficient memory", /* Z_MEM_ERROR (-4) */
  79879. "buffer error", /* Z_BUF_ERROR (-5) */
  79880. "incompatible version",/* Z_VERSION_ERROR (-6) */
  79881. ""};
  79882. #ifdef DEBUG
  79883. # ifndef verbose
  79884. # define verbose 0
  79885. # endif
  79886. int z_verbose = verbose;
  79887. void z_error (const char *m)
  79888. {
  79889. fprintf(stderr, "%s\n", m);
  79890. exit(1);
  79891. }
  79892. #endif
  79893. const char * ZEXPORT zError(int err)
  79894. {
  79895. return ERR_MSG(err);
  79896. }
  79897. #if defined(_WIN32_WCE)
  79898. int errno = 0;
  79899. #endif
  79900. #ifndef HAVE_MEMCPY
  79901. void zmemcpy(dest, source, len)
  79902. Bytef* dest;
  79903. const Bytef* source;
  79904. uInt len;
  79905. {
  79906. if (len == 0) return;
  79907. do {
  79908. *dest++ = *source++; /* ??? to be unrolled */
  79909. } while (--len != 0);
  79910. }
  79911. int zmemcmp(s1, s2, len)
  79912. const Bytef* s1;
  79913. const Bytef* s2;
  79914. uInt len;
  79915. {
  79916. uInt j;
  79917. for (j = 0; j < len; j++) {
  79918. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  79919. }
  79920. return 0;
  79921. }
  79922. void zmemzero(dest, len)
  79923. Bytef* dest;
  79924. uInt len;
  79925. {
  79926. if (len == 0) return;
  79927. do {
  79928. *dest++ = 0; /* ??? to be unrolled */
  79929. } while (--len != 0);
  79930. }
  79931. #endif
  79932. #ifdef SYS16BIT
  79933. #ifdef __TURBOC__
  79934. # define MY_ZCALLOC
  79935. #define MAX_PTR 10
  79936. local int next_ptr = 0;
  79937. typedef struct ptr_table_s {
  79938. voidpf org_ptr;
  79939. voidpf new_ptr;
  79940. } ptr_table;
  79941. local ptr_table table[MAX_PTR];
  79942. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  79943. {
  79944. voidpf buf = opaque; /* just to make some compilers happy */
  79945. ulg bsize = (ulg)items*size;
  79946. if (bsize < 65520L) {
  79947. buf = farmalloc(bsize);
  79948. if (*(ush*)&buf != 0) return buf;
  79949. } else {
  79950. buf = farmalloc(bsize + 16L);
  79951. }
  79952. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  79953. table[next_ptr].org_ptr = buf;
  79954. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  79955. *(ush*)&buf = 0;
  79956. table[next_ptr++].new_ptr = buf;
  79957. return buf;
  79958. }
  79959. void zcfree (voidpf opaque, voidpf ptr)
  79960. {
  79961. int n;
  79962. if (*(ush*)&ptr != 0) { /* object < 64K */
  79963. farfree(ptr);
  79964. return;
  79965. }
  79966. for (n = 0; n < next_ptr; n++) {
  79967. if (ptr != table[n].new_ptr) continue;
  79968. farfree(table[n].org_ptr);
  79969. while (++n < next_ptr) {
  79970. table[n-1] = table[n];
  79971. }
  79972. next_ptr--;
  79973. return;
  79974. }
  79975. ptr = opaque; /* just to make some compilers happy */
  79976. Assert(0, "zcfree: ptr not found");
  79977. }
  79978. #endif /* __TURBOC__ */
  79979. #ifdef M_I86
  79980. # define MY_ZCALLOC
  79981. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  79982. # define _halloc halloc
  79983. # define _hfree hfree
  79984. #endif
  79985. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  79986. {
  79987. if (opaque) opaque = 0; /* to make compiler happy */
  79988. return _halloc((long)items, size);
  79989. }
  79990. void zcfree (voidpf opaque, voidpf ptr)
  79991. {
  79992. if (opaque) opaque = 0; /* to make compiler happy */
  79993. _hfree(ptr);
  79994. }
  79995. #endif /* M_I86 */
  79996. #endif /* SYS16BIT */
  79997. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  79998. #ifndef STDC
  79999. extern voidp malloc OF((uInt size));
  80000. extern voidp calloc OF((uInt items, uInt size));
  80001. extern void free OF((voidpf ptr));
  80002. #endif
  80003. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80004. {
  80005. if (opaque) items += size - size; /* make compiler happy */
  80006. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80007. (voidpf)calloc(items, size);
  80008. }
  80009. void zcfree (voidpf opaque, voidpf ptr)
  80010. {
  80011. free(ptr);
  80012. if (opaque) return; /* make compiler happy */
  80013. }
  80014. #endif /* MY_ZCALLOC */
  80015. /*** End of inlined file: zutil.c ***/
  80016. #undef Byte
  80017. }
  80018. #else
  80019. #include <zlib.h>
  80020. #endif
  80021. }
  80022. #if JUCE_MSVC
  80023. #pragma warning (pop)
  80024. #endif
  80025. BEGIN_JUCE_NAMESPACE
  80026. // internal helper object that holds the zlib structures so they don't have to be
  80027. // included publicly.
  80028. class GZIPDecompressHelper
  80029. {
  80030. public:
  80031. GZIPDecompressHelper (const bool noWrap)
  80032. : finished (true),
  80033. needsDictionary (false),
  80034. error (true),
  80035. streamIsValid (false),
  80036. data (0),
  80037. dataSize (0)
  80038. {
  80039. using namespace zlibNamespace;
  80040. zerostruct (stream);
  80041. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80042. finished = error = ! streamIsValid;
  80043. }
  80044. ~GZIPDecompressHelper()
  80045. {
  80046. using namespace zlibNamespace;
  80047. if (streamIsValid)
  80048. inflateEnd (&stream);
  80049. }
  80050. bool needsInput() const throw() { return dataSize <= 0; }
  80051. void setInput (uint8* const data_, const int size) throw()
  80052. {
  80053. data = data_;
  80054. dataSize = size;
  80055. }
  80056. int doNextBlock (uint8* const dest, const int destSize)
  80057. {
  80058. using namespace zlibNamespace;
  80059. if (streamIsValid && data != 0 && ! finished)
  80060. {
  80061. stream.next_in = data;
  80062. stream.next_out = dest;
  80063. stream.avail_in = dataSize;
  80064. stream.avail_out = destSize;
  80065. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80066. {
  80067. case Z_STREAM_END:
  80068. finished = true;
  80069. // deliberate fall-through
  80070. case Z_OK:
  80071. data += dataSize - stream.avail_in;
  80072. dataSize = stream.avail_in;
  80073. return destSize - stream.avail_out;
  80074. case Z_NEED_DICT:
  80075. needsDictionary = true;
  80076. data += dataSize - stream.avail_in;
  80077. dataSize = stream.avail_in;
  80078. break;
  80079. case Z_DATA_ERROR:
  80080. case Z_MEM_ERROR:
  80081. error = true;
  80082. default:
  80083. break;
  80084. }
  80085. }
  80086. return 0;
  80087. }
  80088. bool finished, needsDictionary, error, streamIsValid;
  80089. private:
  80090. zlibNamespace::z_stream stream;
  80091. uint8* data;
  80092. int dataSize;
  80093. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80094. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80095. };
  80096. const int gzipDecompBufferSize = 32768;
  80097. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80098. const bool deleteSourceWhenDestroyed,
  80099. const bool noWrap_,
  80100. const int64 uncompressedStreamLength_)
  80101. : sourceStream (sourceStream_),
  80102. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80103. uncompressedStreamLength (uncompressedStreamLength_),
  80104. noWrap (noWrap_),
  80105. isEof (false),
  80106. activeBufferSize (0),
  80107. originalSourcePos (sourceStream_->getPosition()),
  80108. currentPos (0),
  80109. buffer (gzipDecompBufferSize),
  80110. helper (new GZIPDecompressHelper (noWrap_))
  80111. {
  80112. }
  80113. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80114. {
  80115. }
  80116. int64 GZIPDecompressorInputStream::getTotalLength()
  80117. {
  80118. return uncompressedStreamLength;
  80119. }
  80120. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80121. {
  80122. if ((howMany > 0) && ! isEof)
  80123. {
  80124. jassert (destBuffer != 0);
  80125. if (destBuffer != 0)
  80126. {
  80127. int numRead = 0;
  80128. uint8* d = static_cast <uint8*> (destBuffer);
  80129. while (! helper->error)
  80130. {
  80131. const int n = helper->doNextBlock (d, howMany);
  80132. currentPos += n;
  80133. if (n == 0)
  80134. {
  80135. if (helper->finished || helper->needsDictionary)
  80136. {
  80137. isEof = true;
  80138. return numRead;
  80139. }
  80140. if (helper->needsInput())
  80141. {
  80142. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80143. if (activeBufferSize > 0)
  80144. {
  80145. helper->setInput (buffer, activeBufferSize);
  80146. }
  80147. else
  80148. {
  80149. isEof = true;
  80150. return numRead;
  80151. }
  80152. }
  80153. }
  80154. else
  80155. {
  80156. numRead += n;
  80157. howMany -= n;
  80158. d += n;
  80159. if (howMany <= 0)
  80160. return numRead;
  80161. }
  80162. }
  80163. }
  80164. }
  80165. return 0;
  80166. }
  80167. bool GZIPDecompressorInputStream::isExhausted()
  80168. {
  80169. return helper->error || isEof;
  80170. }
  80171. int64 GZIPDecompressorInputStream::getPosition()
  80172. {
  80173. return currentPos;
  80174. }
  80175. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80176. {
  80177. if (newPos < currentPos)
  80178. {
  80179. // to go backwards, reset the stream and start again..
  80180. isEof = false;
  80181. activeBufferSize = 0;
  80182. currentPos = 0;
  80183. helper = new GZIPDecompressHelper (noWrap);
  80184. sourceStream->setPosition (originalSourcePos);
  80185. }
  80186. skipNextBytes (newPos - currentPos);
  80187. return true;
  80188. }
  80189. END_JUCE_NAMESPACE
  80190. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80191. #endif
  80192. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80193. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80194. #if JUCE_USE_FLAC
  80195. #if JUCE_WINDOWS
  80196. #include <windows.h>
  80197. #endif
  80198. #ifdef _MSC_VER
  80199. #pragma warning (disable : 4505)
  80200. #pragma warning (push)
  80201. #endif
  80202. namespace FlacNamespace
  80203. {
  80204. #if JUCE_INCLUDE_FLAC_CODE
  80205. #define FLAC__NO_DLL 1
  80206. #if ! defined (SIZE_MAX)
  80207. #define SIZE_MAX 0xffffffff
  80208. #endif
  80209. #define __STDC_LIMIT_MACROS 1
  80210. /*** Start of inlined file: all.h ***/
  80211. #ifndef FLAC__ALL_H
  80212. #define FLAC__ALL_H
  80213. /*** Start of inlined file: export.h ***/
  80214. #ifndef FLAC__EXPORT_H
  80215. #define FLAC__EXPORT_H
  80216. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80217. #define FLAC_API
  80218. #else
  80219. #ifdef FLAC_API_EXPORTS
  80220. #define FLAC_API _declspec(dllexport)
  80221. #else
  80222. #define FLAC_API _declspec(dllimport)
  80223. #endif
  80224. #endif
  80225. #define FLAC_API_VERSION_CURRENT 10
  80226. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80227. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80228. #ifdef __cplusplus
  80229. extern "C" {
  80230. #endif
  80231. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80232. #ifdef __cplusplus
  80233. }
  80234. #endif
  80235. #endif
  80236. /*** End of inlined file: export.h ***/
  80237. /*** Start of inlined file: assert.h ***/
  80238. #ifndef FLAC__ASSERT_H
  80239. #define FLAC__ASSERT_H
  80240. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80241. #ifdef DEBUG
  80242. #include <assert.h>
  80243. #define FLAC__ASSERT(x) assert(x)
  80244. #define FLAC__ASSERT_DECLARATION(x) x
  80245. #else
  80246. #define FLAC__ASSERT(x)
  80247. #define FLAC__ASSERT_DECLARATION(x)
  80248. #endif
  80249. #endif
  80250. /*** End of inlined file: assert.h ***/
  80251. /*** Start of inlined file: callback.h ***/
  80252. #ifndef FLAC__CALLBACK_H
  80253. #define FLAC__CALLBACK_H
  80254. /*** Start of inlined file: ordinals.h ***/
  80255. #ifndef FLAC__ORDINALS_H
  80256. #define FLAC__ORDINALS_H
  80257. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80258. #include <inttypes.h>
  80259. #endif
  80260. typedef signed char FLAC__int8;
  80261. typedef unsigned char FLAC__uint8;
  80262. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80263. typedef __int16 FLAC__int16;
  80264. typedef __int32 FLAC__int32;
  80265. typedef __int64 FLAC__int64;
  80266. typedef unsigned __int16 FLAC__uint16;
  80267. typedef unsigned __int32 FLAC__uint32;
  80268. typedef unsigned __int64 FLAC__uint64;
  80269. #elif defined(__EMX__)
  80270. typedef short FLAC__int16;
  80271. typedef long FLAC__int32;
  80272. typedef long long FLAC__int64;
  80273. typedef unsigned short FLAC__uint16;
  80274. typedef unsigned long FLAC__uint32;
  80275. typedef unsigned long long FLAC__uint64;
  80276. #else
  80277. typedef int16_t FLAC__int16;
  80278. typedef int32_t FLAC__int32;
  80279. typedef int64_t FLAC__int64;
  80280. typedef uint16_t FLAC__uint16;
  80281. typedef uint32_t FLAC__uint32;
  80282. typedef uint64_t FLAC__uint64;
  80283. #endif
  80284. typedef int FLAC__bool;
  80285. typedef FLAC__uint8 FLAC__byte;
  80286. #ifdef true
  80287. #undef true
  80288. #endif
  80289. #ifdef false
  80290. #undef false
  80291. #endif
  80292. #ifndef __cplusplus
  80293. #define true 1
  80294. #define false 0
  80295. #endif
  80296. #endif
  80297. /*** End of inlined file: ordinals.h ***/
  80298. #include <stdlib.h> /* for size_t */
  80299. #ifdef __cplusplus
  80300. extern "C" {
  80301. #endif
  80302. typedef void* FLAC__IOHandle;
  80303. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80304. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80305. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80306. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80307. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80308. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80309. typedef struct {
  80310. FLAC__IOCallback_Read read;
  80311. FLAC__IOCallback_Write write;
  80312. FLAC__IOCallback_Seek seek;
  80313. FLAC__IOCallback_Tell tell;
  80314. FLAC__IOCallback_Eof eof;
  80315. FLAC__IOCallback_Close close;
  80316. } FLAC__IOCallbacks;
  80317. #ifdef __cplusplus
  80318. }
  80319. #endif
  80320. #endif
  80321. /*** End of inlined file: callback.h ***/
  80322. /*** Start of inlined file: format.h ***/
  80323. #ifndef FLAC__FORMAT_H
  80324. #define FLAC__FORMAT_H
  80325. #ifdef __cplusplus
  80326. extern "C" {
  80327. #endif
  80328. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80329. #define FLAC__MIN_BLOCK_SIZE (16u)
  80330. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80331. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80332. #define FLAC__MAX_CHANNELS (8u)
  80333. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80334. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80335. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80336. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80337. #define FLAC__MAX_LPC_ORDER (32u)
  80338. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80339. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80340. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80341. #define FLAC__MAX_FIXED_ORDER (4u)
  80342. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80343. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80344. extern FLAC_API const char *FLAC__VERSION_STRING;
  80345. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80346. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80347. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80348. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80349. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80350. typedef enum {
  80351. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80352. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80353. } FLAC__EntropyCodingMethodType;
  80354. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80355. typedef struct {
  80356. unsigned *parameters;
  80357. unsigned *raw_bits;
  80358. unsigned capacity_by_order;
  80359. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80360. typedef struct {
  80361. unsigned order;
  80362. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80363. } FLAC__EntropyCodingMethod_PartitionedRice;
  80364. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80365. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80366. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80367. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80368. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80369. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80370. typedef struct {
  80371. FLAC__EntropyCodingMethodType type;
  80372. union {
  80373. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80374. } data;
  80375. } FLAC__EntropyCodingMethod;
  80376. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80377. typedef enum {
  80378. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80379. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80380. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80381. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80382. } FLAC__SubframeType;
  80383. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80384. typedef struct {
  80385. FLAC__int32 value; /**< The constant signal value. */
  80386. } FLAC__Subframe_Constant;
  80387. typedef struct {
  80388. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80389. } FLAC__Subframe_Verbatim;
  80390. typedef struct {
  80391. FLAC__EntropyCodingMethod entropy_coding_method;
  80392. unsigned order;
  80393. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80394. const FLAC__int32 *residual;
  80395. } FLAC__Subframe_Fixed;
  80396. typedef struct {
  80397. FLAC__EntropyCodingMethod entropy_coding_method;
  80398. unsigned order;
  80399. unsigned qlp_coeff_precision;
  80400. int quantization_level;
  80401. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80402. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80403. const FLAC__int32 *residual;
  80404. } FLAC__Subframe_LPC;
  80405. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80406. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80407. typedef struct {
  80408. FLAC__SubframeType type;
  80409. union {
  80410. FLAC__Subframe_Constant constant;
  80411. FLAC__Subframe_Fixed fixed;
  80412. FLAC__Subframe_LPC lpc;
  80413. FLAC__Subframe_Verbatim verbatim;
  80414. } data;
  80415. unsigned wasted_bits;
  80416. } FLAC__Subframe;
  80417. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80418. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80419. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80420. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80421. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80422. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80423. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80424. typedef enum {
  80425. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80426. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80427. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80428. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80429. } FLAC__ChannelAssignment;
  80430. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80431. typedef enum {
  80432. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80433. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80434. } FLAC__FrameNumberType;
  80435. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80436. typedef struct {
  80437. unsigned blocksize;
  80438. unsigned sample_rate;
  80439. unsigned channels;
  80440. FLAC__ChannelAssignment channel_assignment;
  80441. unsigned bits_per_sample;
  80442. FLAC__FrameNumberType number_type;
  80443. union {
  80444. FLAC__uint32 frame_number;
  80445. FLAC__uint64 sample_number;
  80446. } number;
  80447. FLAC__uint8 crc;
  80448. } FLAC__FrameHeader;
  80449. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80450. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80451. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80452. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80453. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80454. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80455. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80456. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80457. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80458. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80459. typedef struct {
  80460. FLAC__uint16 crc;
  80461. } FLAC__FrameFooter;
  80462. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80463. typedef struct {
  80464. FLAC__FrameHeader header;
  80465. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80466. FLAC__FrameFooter footer;
  80467. } FLAC__Frame;
  80468. typedef enum {
  80469. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80470. FLAC__METADATA_TYPE_PADDING = 1,
  80471. FLAC__METADATA_TYPE_APPLICATION = 2,
  80472. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80473. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80474. FLAC__METADATA_TYPE_CUESHEET = 5,
  80475. FLAC__METADATA_TYPE_PICTURE = 6,
  80476. FLAC__METADATA_TYPE_UNDEFINED = 7
  80477. } FLAC__MetadataType;
  80478. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80479. typedef struct {
  80480. unsigned min_blocksize, max_blocksize;
  80481. unsigned min_framesize, max_framesize;
  80482. unsigned sample_rate;
  80483. unsigned channels;
  80484. unsigned bits_per_sample;
  80485. FLAC__uint64 total_samples;
  80486. FLAC__byte md5sum[16];
  80487. } FLAC__StreamMetadata_StreamInfo;
  80488. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80489. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80490. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80491. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80492. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80493. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80494. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80495. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80496. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80497. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80498. typedef struct {
  80499. int dummy;
  80500. } FLAC__StreamMetadata_Padding;
  80501. typedef struct {
  80502. FLAC__byte id[4];
  80503. FLAC__byte *data;
  80504. } FLAC__StreamMetadata_Application;
  80505. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80506. typedef struct {
  80507. FLAC__uint64 sample_number;
  80508. FLAC__uint64 stream_offset;
  80509. unsigned frame_samples;
  80510. } FLAC__StreamMetadata_SeekPoint;
  80511. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80512. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80513. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80514. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80515. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80516. typedef struct {
  80517. unsigned num_points;
  80518. FLAC__StreamMetadata_SeekPoint *points;
  80519. } FLAC__StreamMetadata_SeekTable;
  80520. typedef struct {
  80521. FLAC__uint32 length;
  80522. FLAC__byte *entry;
  80523. } FLAC__StreamMetadata_VorbisComment_Entry;
  80524. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80525. typedef struct {
  80526. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80527. FLAC__uint32 num_comments;
  80528. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80529. } FLAC__StreamMetadata_VorbisComment;
  80530. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80531. typedef struct {
  80532. FLAC__uint64 offset;
  80533. FLAC__byte number;
  80534. } FLAC__StreamMetadata_CueSheet_Index;
  80535. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80536. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80537. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80538. typedef struct {
  80539. FLAC__uint64 offset;
  80540. FLAC__byte number;
  80541. char isrc[13];
  80542. unsigned type:1;
  80543. unsigned pre_emphasis:1;
  80544. FLAC__byte num_indices;
  80545. FLAC__StreamMetadata_CueSheet_Index *indices;
  80546. } FLAC__StreamMetadata_CueSheet_Track;
  80547. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80548. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80549. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80550. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80551. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80552. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80553. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80554. typedef struct {
  80555. char media_catalog_number[129];
  80556. FLAC__uint64 lead_in;
  80557. FLAC__bool is_cd;
  80558. unsigned num_tracks;
  80559. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80560. } FLAC__StreamMetadata_CueSheet;
  80561. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80562. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80563. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80564. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80565. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80566. typedef enum {
  80567. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80568. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80569. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80570. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80571. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80572. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80573. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80574. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80575. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80576. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80577. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80578. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80579. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80580. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80581. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80582. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80583. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80584. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80585. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80586. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80587. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80588. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80589. } FLAC__StreamMetadata_Picture_Type;
  80590. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80591. typedef struct {
  80592. FLAC__StreamMetadata_Picture_Type type;
  80593. char *mime_type;
  80594. FLAC__byte *description;
  80595. FLAC__uint32 width;
  80596. FLAC__uint32 height;
  80597. FLAC__uint32 depth;
  80598. FLAC__uint32 colors;
  80599. FLAC__uint32 data_length;
  80600. FLAC__byte *data;
  80601. } FLAC__StreamMetadata_Picture;
  80602. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80603. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80604. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80605. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80606. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80607. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80608. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80609. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80610. typedef struct {
  80611. FLAC__byte *data;
  80612. } FLAC__StreamMetadata_Unknown;
  80613. typedef struct {
  80614. FLAC__MetadataType type;
  80615. FLAC__bool is_last;
  80616. unsigned length;
  80617. union {
  80618. FLAC__StreamMetadata_StreamInfo stream_info;
  80619. FLAC__StreamMetadata_Padding padding;
  80620. FLAC__StreamMetadata_Application application;
  80621. FLAC__StreamMetadata_SeekTable seek_table;
  80622. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80623. FLAC__StreamMetadata_CueSheet cue_sheet;
  80624. FLAC__StreamMetadata_Picture picture;
  80625. FLAC__StreamMetadata_Unknown unknown;
  80626. } data;
  80627. } FLAC__StreamMetadata;
  80628. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80629. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80630. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80631. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80632. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80633. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80634. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80635. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80636. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80637. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80638. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80639. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80640. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80641. #ifdef __cplusplus
  80642. }
  80643. #endif
  80644. #endif
  80645. /*** End of inlined file: format.h ***/
  80646. /*** Start of inlined file: metadata.h ***/
  80647. #ifndef FLAC__METADATA_H
  80648. #define FLAC__METADATA_H
  80649. #include <sys/types.h> /* for off_t */
  80650. #ifdef __cplusplus
  80651. extern "C" {
  80652. #endif
  80653. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80654. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80655. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80656. FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors);
  80657. struct FLAC__Metadata_SimpleIterator;
  80658. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80659. typedef enum {
  80660. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80661. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80662. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80663. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80664. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80665. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80666. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80667. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80668. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80669. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80670. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80671. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80672. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80673. } FLAC__Metadata_SimpleIteratorStatus;
  80674. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80675. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80676. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80677. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80678. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool read_only, FLAC__bool preserve_file_stats);
  80679. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80680. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80681. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  80682. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  80683. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  80684. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  80685. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  80686. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  80687. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  80688. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80689. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80690. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  80691. struct FLAC__Metadata_Chain;
  80692. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  80693. struct FLAC__Metadata_Iterator;
  80694. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  80695. typedef enum {
  80696. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  80697. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  80698. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  80699. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  80700. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  80701. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  80702. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  80703. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  80704. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  80705. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  80706. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  80707. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  80708. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  80709. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  80710. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  80711. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  80712. } FLAC__Metadata_ChainStatus;
  80713. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  80714. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  80715. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  80716. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  80717. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  80718. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  80719. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80720. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80721. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  80722. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  80723. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80724. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__IOHandle temp_handle, FLAC__IOCallbacks temp_callbacks);
  80725. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  80726. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  80727. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  80728. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  80729. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  80730. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  80731. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  80732. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  80733. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  80734. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80735. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  80736. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80737. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80738. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  80739. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  80740. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  80741. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  80742. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  80743. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  80744. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80745. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80746. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  80747. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  80748. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  80749. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  80750. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  80751. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  80752. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  80753. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  80754. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80755. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  80756. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80757. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80758. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80759. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  80760. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  80761. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, const char *field_value);
  80762. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(const FLAC__StreamMetadata_VorbisComment_Entry entry, char **field_name, char **field_value);
  80763. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  80764. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  80765. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  80766. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  80767. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  80768. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  80769. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  80770. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  80771. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num, FLAC__StreamMetadata_CueSheet_Index index);
  80772. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80773. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80774. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  80775. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80776. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80777. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  80778. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  80779. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  80780. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  80781. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  80782. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  80783. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  80784. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  80785. #ifdef __cplusplus
  80786. }
  80787. #endif
  80788. #endif
  80789. /*** End of inlined file: metadata.h ***/
  80790. /*** Start of inlined file: stream_decoder.h ***/
  80791. #ifndef FLAC__STREAM_DECODER_H
  80792. #define FLAC__STREAM_DECODER_H
  80793. #include <stdio.h> /* for FILE */
  80794. #ifdef __cplusplus
  80795. extern "C" {
  80796. #endif
  80797. typedef enum {
  80798. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  80799. FLAC__STREAM_DECODER_READ_METADATA,
  80800. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  80801. FLAC__STREAM_DECODER_READ_FRAME,
  80802. FLAC__STREAM_DECODER_END_OF_STREAM,
  80803. FLAC__STREAM_DECODER_OGG_ERROR,
  80804. FLAC__STREAM_DECODER_SEEK_ERROR,
  80805. FLAC__STREAM_DECODER_ABORTED,
  80806. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  80807. FLAC__STREAM_DECODER_UNINITIALIZED
  80808. } FLAC__StreamDecoderState;
  80809. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  80810. typedef enum {
  80811. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  80812. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  80813. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  80814. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  80815. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  80816. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  80817. } FLAC__StreamDecoderInitStatus;
  80818. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  80819. typedef enum {
  80820. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  80821. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  80822. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  80823. } FLAC__StreamDecoderReadStatus;
  80824. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  80825. typedef enum {
  80826. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  80827. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  80828. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  80829. } FLAC__StreamDecoderSeekStatus;
  80830. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  80831. typedef enum {
  80832. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  80833. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  80834. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  80835. } FLAC__StreamDecoderTellStatus;
  80836. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  80837. typedef enum {
  80838. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  80839. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  80840. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  80841. } FLAC__StreamDecoderLengthStatus;
  80842. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  80843. typedef enum {
  80844. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  80845. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  80846. } FLAC__StreamDecoderWriteStatus;
  80847. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  80848. typedef enum {
  80849. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  80850. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  80851. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  80852. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  80853. } FLAC__StreamDecoderErrorStatus;
  80854. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  80855. struct FLAC__StreamDecoderProtected;
  80856. struct FLAC__StreamDecoderPrivate;
  80857. typedef struct {
  80858. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  80859. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  80860. } FLAC__StreamDecoder;
  80861. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  80862. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  80863. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  80864. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  80865. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  80866. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  80867. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  80868. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  80869. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  80870. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  80871. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  80872. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  80873. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  80874. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  80875. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  80876. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  80877. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  80878. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  80879. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  80880. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  80881. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  80882. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  80883. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  80884. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  80885. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  80886. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  80887. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  80888. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  80889. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  80890. FLAC__StreamDecoder *decoder,
  80891. FLAC__StreamDecoderReadCallback read_callback,
  80892. FLAC__StreamDecoderSeekCallback seek_callback,
  80893. FLAC__StreamDecoderTellCallback tell_callback,
  80894. FLAC__StreamDecoderLengthCallback length_callback,
  80895. FLAC__StreamDecoderEofCallback eof_callback,
  80896. FLAC__StreamDecoderWriteCallback write_callback,
  80897. FLAC__StreamDecoderMetadataCallback metadata_callback,
  80898. FLAC__StreamDecoderErrorCallback error_callback,
  80899. void *client_data
  80900. );
  80901. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  80902. FLAC__StreamDecoder *decoder,
  80903. FLAC__StreamDecoderReadCallback read_callback,
  80904. FLAC__StreamDecoderSeekCallback seek_callback,
  80905. FLAC__StreamDecoderTellCallback tell_callback,
  80906. FLAC__StreamDecoderLengthCallback length_callback,
  80907. FLAC__StreamDecoderEofCallback eof_callback,
  80908. FLAC__StreamDecoderWriteCallback write_callback,
  80909. FLAC__StreamDecoderMetadataCallback metadata_callback,
  80910. FLAC__StreamDecoderErrorCallback error_callback,
  80911. void *client_data
  80912. );
  80913. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  80914. FLAC__StreamDecoder *decoder,
  80915. FILE *file,
  80916. FLAC__StreamDecoderWriteCallback write_callback,
  80917. FLAC__StreamDecoderMetadataCallback metadata_callback,
  80918. FLAC__StreamDecoderErrorCallback error_callback,
  80919. void *client_data
  80920. );
  80921. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  80922. FLAC__StreamDecoder *decoder,
  80923. FILE *file,
  80924. FLAC__StreamDecoderWriteCallback write_callback,
  80925. FLAC__StreamDecoderMetadataCallback metadata_callback,
  80926. FLAC__StreamDecoderErrorCallback error_callback,
  80927. void *client_data
  80928. );
  80929. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  80930. FLAC__StreamDecoder *decoder,
  80931. const char *filename,
  80932. FLAC__StreamDecoderWriteCallback write_callback,
  80933. FLAC__StreamDecoderMetadataCallback metadata_callback,
  80934. FLAC__StreamDecoderErrorCallback error_callback,
  80935. void *client_data
  80936. );
  80937. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  80938. FLAC__StreamDecoder *decoder,
  80939. const char *filename,
  80940. FLAC__StreamDecoderWriteCallback write_callback,
  80941. FLAC__StreamDecoderMetadataCallback metadata_callback,
  80942. FLAC__StreamDecoderErrorCallback error_callback,
  80943. void *client_data
  80944. );
  80945. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  80946. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  80947. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  80948. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  80949. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  80950. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  80951. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  80952. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  80953. #ifdef __cplusplus
  80954. }
  80955. #endif
  80956. #endif
  80957. /*** End of inlined file: stream_decoder.h ***/
  80958. /*** Start of inlined file: stream_encoder.h ***/
  80959. #ifndef FLAC__STREAM_ENCODER_H
  80960. #define FLAC__STREAM_ENCODER_H
  80961. #include <stdio.h> /* for FILE */
  80962. #ifdef __cplusplus
  80963. extern "C" {
  80964. #endif
  80965. typedef enum {
  80966. FLAC__STREAM_ENCODER_OK = 0,
  80967. FLAC__STREAM_ENCODER_UNINITIALIZED,
  80968. FLAC__STREAM_ENCODER_OGG_ERROR,
  80969. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  80970. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  80971. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  80972. FLAC__STREAM_ENCODER_IO_ERROR,
  80973. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  80974. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  80975. } FLAC__StreamEncoderState;
  80976. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  80977. typedef enum {
  80978. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  80979. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  80980. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  80981. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  80982. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  80983. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  80984. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  80985. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  80986. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  80987. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  80988. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  80989. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  80990. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  80991. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  80992. } FLAC__StreamEncoderInitStatus;
  80993. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  80994. typedef enum {
  80995. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  80996. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  80997. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  80998. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  80999. } FLAC__StreamEncoderReadStatus;
  81000. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81001. typedef enum {
  81002. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81003. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81004. } FLAC__StreamEncoderWriteStatus;
  81005. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81006. typedef enum {
  81007. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81008. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81009. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81010. } FLAC__StreamEncoderSeekStatus;
  81011. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81012. typedef enum {
  81013. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81014. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81015. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81016. } FLAC__StreamEncoderTellStatus;
  81017. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81018. struct FLAC__StreamEncoderProtected;
  81019. struct FLAC__StreamEncoderPrivate;
  81020. typedef struct {
  81021. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81022. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81023. } FLAC__StreamEncoder;
  81024. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81025. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81026. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81027. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81028. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81029. typedef void (*FLAC__StreamEncoderProgressCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
  81030. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81031. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81032. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81033. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81034. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81035. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81036. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81037. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81038. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81039. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81040. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81041. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81042. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81043. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81044. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81045. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81046. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81047. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81048. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81049. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81050. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81051. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81052. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81053. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81054. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81055. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81056. FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
  81057. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81058. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81059. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81060. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81061. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81062. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81063. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81064. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81065. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81066. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81067. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81068. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81069. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81070. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81071. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81072. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81073. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81074. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
  81075. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
  81076. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81077. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81078. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81079. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81080. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81081. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81082. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81083. #ifdef __cplusplus
  81084. }
  81085. #endif
  81086. #endif
  81087. /*** End of inlined file: stream_encoder.h ***/
  81088. #ifdef _MSC_VER
  81089. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81090. {
  81091. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81092. return (x>>16) | (x<<16);
  81093. }
  81094. #endif
  81095. #if defined(_MSC_VER) && defined(_X86_)
  81096. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81097. {
  81098. __asm {
  81099. mov edx, start
  81100. mov ecx, len
  81101. test ecx, ecx
  81102. loop1:
  81103. jz done1
  81104. mov eax, [edx]
  81105. bswap eax
  81106. mov [edx], eax
  81107. add edx, 4
  81108. dec ecx
  81109. jmp short loop1
  81110. done1:
  81111. }
  81112. }
  81113. #endif
  81114. #endif
  81115. /*** End of inlined file: all.h ***/
  81116. /*** Start of inlined file: bitmath.c ***/
  81117. /*** Start of inlined file: juce_FlacHeader.h ***/
  81118. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81119. // tasks..
  81120. #define VERSION "1.2.1"
  81121. #define FLAC__NO_DLL 1
  81122. #if JUCE_MSVC
  81123. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81124. #endif
  81125. #if JUCE_MAC
  81126. #define FLAC__SYS_DARWIN 1
  81127. #endif
  81128. /*** End of inlined file: juce_FlacHeader.h ***/
  81129. #if JUCE_USE_FLAC
  81130. #if HAVE_CONFIG_H
  81131. # include <config.h>
  81132. #endif
  81133. /*** Start of inlined file: bitmath.h ***/
  81134. #ifndef FLAC__PRIVATE__BITMATH_H
  81135. #define FLAC__PRIVATE__BITMATH_H
  81136. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81137. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81138. unsigned FLAC__bitmath_silog2(int v);
  81139. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81140. #endif
  81141. /*** End of inlined file: bitmath.h ***/
  81142. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81143. {
  81144. unsigned l = 0;
  81145. FLAC__ASSERT(v > 0);
  81146. while(v >>= 1)
  81147. l++;
  81148. return l;
  81149. }
  81150. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81151. {
  81152. unsigned l = 0;
  81153. FLAC__ASSERT(v > 0);
  81154. while(v >>= 1)
  81155. l++;
  81156. return l;
  81157. }
  81158. unsigned FLAC__bitmath_silog2(int v)
  81159. {
  81160. while(1) {
  81161. if(v == 0) {
  81162. return 0;
  81163. }
  81164. else if(v > 0) {
  81165. unsigned l = 0;
  81166. while(v) {
  81167. l++;
  81168. v >>= 1;
  81169. }
  81170. return l+1;
  81171. }
  81172. else if(v == -1) {
  81173. return 2;
  81174. }
  81175. else {
  81176. v++;
  81177. v = -v;
  81178. }
  81179. }
  81180. }
  81181. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81182. {
  81183. while(1) {
  81184. if(v == 0) {
  81185. return 0;
  81186. }
  81187. else if(v > 0) {
  81188. unsigned l = 0;
  81189. while(v) {
  81190. l++;
  81191. v >>= 1;
  81192. }
  81193. return l+1;
  81194. }
  81195. else if(v == -1) {
  81196. return 2;
  81197. }
  81198. else {
  81199. v++;
  81200. v = -v;
  81201. }
  81202. }
  81203. }
  81204. #endif
  81205. /*** End of inlined file: bitmath.c ***/
  81206. /*** Start of inlined file: bitreader.c ***/
  81207. /*** Start of inlined file: juce_FlacHeader.h ***/
  81208. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81209. // tasks..
  81210. #define VERSION "1.2.1"
  81211. #define FLAC__NO_DLL 1
  81212. #if JUCE_MSVC
  81213. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81214. #endif
  81215. #if JUCE_MAC
  81216. #define FLAC__SYS_DARWIN 1
  81217. #endif
  81218. /*** End of inlined file: juce_FlacHeader.h ***/
  81219. #if JUCE_USE_FLAC
  81220. #if HAVE_CONFIG_H
  81221. # include <config.h>
  81222. #endif
  81223. #include <stdlib.h> /* for malloc() */
  81224. #include <string.h> /* for memcpy(), memset() */
  81225. #ifdef _MSC_VER
  81226. #include <winsock.h> /* for ntohl() */
  81227. #elif defined FLAC__SYS_DARWIN
  81228. #include <machine/endian.h> /* for ntohl() */
  81229. #elif defined __MINGW32__
  81230. #include <winsock.h> /* for ntohl() */
  81231. #else
  81232. #include <netinet/in.h> /* for ntohl() */
  81233. #endif
  81234. /*** Start of inlined file: bitreader.h ***/
  81235. #ifndef FLAC__PRIVATE__BITREADER_H
  81236. #define FLAC__PRIVATE__BITREADER_H
  81237. #include <stdio.h> /* for FILE */
  81238. /*** Start of inlined file: cpu.h ***/
  81239. #ifndef FLAC__PRIVATE__CPU_H
  81240. #define FLAC__PRIVATE__CPU_H
  81241. #ifdef HAVE_CONFIG_H
  81242. #include <config.h>
  81243. #endif
  81244. typedef enum {
  81245. FLAC__CPUINFO_TYPE_IA32,
  81246. FLAC__CPUINFO_TYPE_PPC,
  81247. FLAC__CPUINFO_TYPE_UNKNOWN
  81248. } FLAC__CPUInfo_Type;
  81249. typedef struct {
  81250. FLAC__bool cpuid;
  81251. FLAC__bool bswap;
  81252. FLAC__bool cmov;
  81253. FLAC__bool mmx;
  81254. FLAC__bool fxsr;
  81255. FLAC__bool sse;
  81256. FLAC__bool sse2;
  81257. FLAC__bool sse3;
  81258. FLAC__bool ssse3;
  81259. FLAC__bool _3dnow;
  81260. FLAC__bool ext3dnow;
  81261. FLAC__bool extmmx;
  81262. } FLAC__CPUInfo_IA32;
  81263. typedef struct {
  81264. FLAC__bool altivec;
  81265. FLAC__bool ppc64;
  81266. } FLAC__CPUInfo_PPC;
  81267. typedef struct {
  81268. FLAC__bool use_asm;
  81269. FLAC__CPUInfo_Type type;
  81270. union {
  81271. FLAC__CPUInfo_IA32 ia32;
  81272. FLAC__CPUInfo_PPC ppc;
  81273. } data;
  81274. } FLAC__CPUInfo;
  81275. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81276. #ifndef FLAC__NO_ASM
  81277. #ifdef FLAC__CPU_IA32
  81278. #ifdef FLAC__HAS_NASM
  81279. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81280. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81281. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81282. #endif
  81283. #endif
  81284. #endif
  81285. #endif
  81286. /*** End of inlined file: cpu.h ***/
  81287. struct FLAC__BitReader;
  81288. typedef struct FLAC__BitReader FLAC__BitReader;
  81289. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81290. FLAC__BitReader *FLAC__bitreader_new(void);
  81291. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81292. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81293. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81294. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81295. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81296. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81297. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81298. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81299. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81300. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81301. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81302. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81303. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81304. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81305. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81306. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81307. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81308. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81309. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81310. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81311. #ifndef FLAC__NO_ASM
  81312. # ifdef FLAC__CPU_IA32
  81313. # ifdef FLAC__HAS_NASM
  81314. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81315. # endif
  81316. # endif
  81317. #endif
  81318. #if 0 /* UNUSED */
  81319. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81320. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81321. #endif
  81322. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81323. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81324. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81325. #endif
  81326. /*** End of inlined file: bitreader.h ***/
  81327. /*** Start of inlined file: crc.h ***/
  81328. #ifndef FLAC__PRIVATE__CRC_H
  81329. #define FLAC__PRIVATE__CRC_H
  81330. extern FLAC__byte const FLAC__crc8_table[256];
  81331. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81332. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81333. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81334. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81335. extern unsigned FLAC__crc16_table[256];
  81336. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81337. #if 0
  81338. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81339. #endif
  81340. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81341. #endif
  81342. /*** End of inlined file: crc.h ***/
  81343. typedef FLAC__uint32 brword;
  81344. #define FLAC__BYTES_PER_WORD 4
  81345. #define FLAC__BITS_PER_WORD 32
  81346. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81347. #if WORDS_BIGENDIAN
  81348. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81349. #else
  81350. #if defined (_MSC_VER) && defined (_X86_)
  81351. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81352. #else
  81353. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81354. #endif
  81355. #endif
  81356. #define COUNT_ZERO_MSBS(word) ( \
  81357. (word) <= 0xffff ? \
  81358. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81359. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81360. )
  81361. #define COUNT_ZERO_MSBS2(word) ( (word) <= 0xff ? byte_to_unary_table[word] + 24 : ((word) <= 0xffff ? byte_to_unary_table[(word) >> 8] + 16 : ((word) <= 0xffffff ? byte_to_unary_table[(word) >> 16] + 8 : byte_to_unary_table[(word) >> 24])) )
  81362. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81363. static const unsigned char byte_to_unary_table[] = {
  81364. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81365. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81366. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81367. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81368. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81369. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81370. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81371. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81380. };
  81381. #ifdef min
  81382. #undef min
  81383. #endif
  81384. #define min(x,y) ((x)<(y)?(x):(y))
  81385. #ifdef max
  81386. #undef max
  81387. #endif
  81388. #define max(x,y) ((x)>(y)?(x):(y))
  81389. #ifdef _MSC_VER
  81390. #define FLAC__U64L(x) x
  81391. #else
  81392. #define FLAC__U64L(x) x##LLU
  81393. #endif
  81394. #ifndef FLaC__INLINE
  81395. #define FLaC__INLINE
  81396. #endif
  81397. struct FLAC__BitReader {
  81398. brword *buffer;
  81399. unsigned capacity; /* in words */
  81400. unsigned words; /* # of completed words in buffer */
  81401. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81402. unsigned consumed_words; /* #words ... */
  81403. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81404. unsigned read_crc16; /* the running frame CRC */
  81405. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81406. FLAC__BitReaderReadCallback read_callback;
  81407. void *client_data;
  81408. FLAC__CPUInfo cpu_info;
  81409. };
  81410. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81411. {
  81412. register unsigned crc = br->read_crc16;
  81413. #if FLAC__BYTES_PER_WORD == 4
  81414. switch(br->crc16_align) {
  81415. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81416. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81417. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81418. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81419. }
  81420. #elif FLAC__BYTES_PER_WORD == 8
  81421. switch(br->crc16_align) {
  81422. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81423. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81424. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81425. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81426. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81427. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81428. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81429. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81430. }
  81431. #else
  81432. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81433. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81434. br->read_crc16 = crc;
  81435. #endif
  81436. br->crc16_align = 0;
  81437. }
  81438. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81439. {
  81440. unsigned start, end;
  81441. size_t bytes;
  81442. FLAC__byte *target;
  81443. if(br->consumed_words > 0) {
  81444. start = br->consumed_words;
  81445. end = br->words + (br->bytes? 1:0);
  81446. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81447. br->words -= start;
  81448. br->consumed_words = 0;
  81449. }
  81450. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81451. if(bytes == 0)
  81452. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81453. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81454. #if WORDS_BIGENDIAN
  81455. #else
  81456. if(br->bytes)
  81457. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81458. #endif
  81459. if(!br->read_callback(target, &bytes, br->client_data))
  81460. return false;
  81461. #if WORDS_BIGENDIAN
  81462. #else
  81463. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81464. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81465. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81466. start = br->words;
  81467. local_swap32_block_(br->buffer + start, end - start);
  81468. }
  81469. else
  81470. # endif
  81471. for(start = br->words; start < end; start++)
  81472. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81473. #endif
  81474. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81475. br->words = end / FLAC__BYTES_PER_WORD;
  81476. br->bytes = end % FLAC__BYTES_PER_WORD;
  81477. return true;
  81478. }
  81479. FLAC__BitReader *FLAC__bitreader_new(void)
  81480. {
  81481. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81482. return br;
  81483. }
  81484. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81485. {
  81486. FLAC__ASSERT(0 != br);
  81487. FLAC__bitreader_free(br);
  81488. free(br);
  81489. }
  81490. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81491. {
  81492. FLAC__ASSERT(0 != br);
  81493. br->words = br->bytes = 0;
  81494. br->consumed_words = br->consumed_bits = 0;
  81495. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81496. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81497. if(br->buffer == 0)
  81498. return false;
  81499. br->read_callback = rcb;
  81500. br->client_data = cd;
  81501. br->cpu_info = cpu;
  81502. return true;
  81503. }
  81504. void FLAC__bitreader_free(FLAC__BitReader *br)
  81505. {
  81506. FLAC__ASSERT(0 != br);
  81507. if(0 != br->buffer)
  81508. free(br->buffer);
  81509. br->buffer = 0;
  81510. br->capacity = 0;
  81511. br->words = br->bytes = 0;
  81512. br->consumed_words = br->consumed_bits = 0;
  81513. br->read_callback = 0;
  81514. br->client_data = 0;
  81515. }
  81516. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81517. {
  81518. br->words = br->bytes = 0;
  81519. br->consumed_words = br->consumed_bits = 0;
  81520. return true;
  81521. }
  81522. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81523. {
  81524. unsigned i, j;
  81525. if(br == 0) {
  81526. fprintf(out, "bitreader is NULL\n");
  81527. }
  81528. else {
  81529. fprintf(out, "bitreader: capacity=%u words=%u bytes=%u consumed: words=%u, bits=%u\n", br->capacity, br->words, br->bytes, br->consumed_words, br->consumed_bits);
  81530. for(i = 0; i < br->words; i++) {
  81531. fprintf(out, "%08X: ", i);
  81532. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81533. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81534. fprintf(out, ".");
  81535. else
  81536. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81537. fprintf(out, "\n");
  81538. }
  81539. if(br->bytes > 0) {
  81540. fprintf(out, "%08X: ", i);
  81541. for(j = 0; j < br->bytes*8; j++)
  81542. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81543. fprintf(out, ".");
  81544. else
  81545. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81546. fprintf(out, "\n");
  81547. }
  81548. }
  81549. }
  81550. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81551. {
  81552. FLAC__ASSERT(0 != br);
  81553. FLAC__ASSERT(0 != br->buffer);
  81554. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81555. br->read_crc16 = (unsigned)seed;
  81556. br->crc16_align = br->consumed_bits;
  81557. }
  81558. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81559. {
  81560. FLAC__ASSERT(0 != br);
  81561. FLAC__ASSERT(0 != br->buffer);
  81562. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81563. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81564. if(br->consumed_bits) {
  81565. const brword tail = br->buffer[br->consumed_words];
  81566. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81567. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81568. }
  81569. return br->read_crc16;
  81570. }
  81571. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81572. {
  81573. return ((br->consumed_bits & 7) == 0);
  81574. }
  81575. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81576. {
  81577. return 8 - (br->consumed_bits & 7);
  81578. }
  81579. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81580. {
  81581. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81582. }
  81583. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81584. {
  81585. FLAC__ASSERT(0 != br);
  81586. FLAC__ASSERT(0 != br->buffer);
  81587. FLAC__ASSERT(bits <= 32);
  81588. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81589. FLAC__ASSERT(br->consumed_words <= br->words);
  81590. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81591. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81592. *val = 0;
  81593. return true;
  81594. }
  81595. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81596. if(!bitreader_read_from_client_(br))
  81597. return false;
  81598. }
  81599. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81600. if(br->consumed_bits) {
  81601. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81602. const brword word = br->buffer[br->consumed_words];
  81603. if(bits < n) {
  81604. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81605. br->consumed_bits += bits;
  81606. return true;
  81607. }
  81608. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81609. bits -= n;
  81610. crc16_update_word_(br, word);
  81611. br->consumed_words++;
  81612. br->consumed_bits = 0;
  81613. if(bits) { /* if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
  81614. *val <<= bits;
  81615. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81616. br->consumed_bits = bits;
  81617. }
  81618. return true;
  81619. }
  81620. else {
  81621. const brword word = br->buffer[br->consumed_words];
  81622. if(bits < FLAC__BITS_PER_WORD) {
  81623. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81624. br->consumed_bits = bits;
  81625. return true;
  81626. }
  81627. *val = word;
  81628. crc16_update_word_(br, word);
  81629. br->consumed_words++;
  81630. return true;
  81631. }
  81632. }
  81633. else {
  81634. if(br->consumed_bits) {
  81635. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81636. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81637. br->consumed_bits += bits;
  81638. return true;
  81639. }
  81640. else {
  81641. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81642. br->consumed_bits += bits;
  81643. return true;
  81644. }
  81645. }
  81646. }
  81647. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81648. {
  81649. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81650. return false;
  81651. *val <<= (32-bits);
  81652. *val >>= (32-bits);
  81653. return true;
  81654. }
  81655. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81656. {
  81657. FLAC__uint32 hi, lo;
  81658. if(bits > 32) {
  81659. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81660. return false;
  81661. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81662. return false;
  81663. *val = hi;
  81664. *val <<= 32;
  81665. *val |= lo;
  81666. }
  81667. else {
  81668. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81669. return false;
  81670. *val = lo;
  81671. }
  81672. return true;
  81673. }
  81674. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81675. {
  81676. FLAC__uint32 x8, x32 = 0;
  81677. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81678. return false;
  81679. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81680. return false;
  81681. x32 |= (x8 << 8);
  81682. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81683. return false;
  81684. x32 |= (x8 << 16);
  81685. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81686. return false;
  81687. x32 |= (x8 << 24);
  81688. *val = x32;
  81689. return true;
  81690. }
  81691. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  81692. {
  81693. FLAC__ASSERT(0 != br);
  81694. FLAC__ASSERT(0 != br->buffer);
  81695. if(bits > 0) {
  81696. const unsigned n = br->consumed_bits & 7;
  81697. unsigned m;
  81698. FLAC__uint32 x;
  81699. if(n != 0) {
  81700. m = min(8-n, bits);
  81701. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  81702. return false;
  81703. bits -= m;
  81704. }
  81705. m = bits / 8;
  81706. if(m > 0) {
  81707. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  81708. return false;
  81709. bits %= 8;
  81710. }
  81711. if(bits > 0) {
  81712. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  81713. return false;
  81714. }
  81715. }
  81716. return true;
  81717. }
  81718. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  81719. {
  81720. FLAC__uint32 x;
  81721. FLAC__ASSERT(0 != br);
  81722. FLAC__ASSERT(0 != br->buffer);
  81723. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81724. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81725. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81726. return false;
  81727. nvals--;
  81728. }
  81729. if(0 == nvals)
  81730. return true;
  81731. while(nvals >= FLAC__BYTES_PER_WORD) {
  81732. if(br->consumed_words < br->words) {
  81733. br->consumed_words++;
  81734. nvals -= FLAC__BYTES_PER_WORD;
  81735. }
  81736. else if(!bitreader_read_from_client_(br))
  81737. return false;
  81738. }
  81739. while(nvals) {
  81740. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81741. return false;
  81742. nvals--;
  81743. }
  81744. return true;
  81745. }
  81746. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  81747. {
  81748. FLAC__uint32 x;
  81749. FLAC__ASSERT(0 != br);
  81750. FLAC__ASSERT(0 != br->buffer);
  81751. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81752. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81753. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81754. return false;
  81755. *val++ = (FLAC__byte)x;
  81756. nvals--;
  81757. }
  81758. if(0 == nvals)
  81759. return true;
  81760. while(nvals >= FLAC__BYTES_PER_WORD) {
  81761. if(br->consumed_words < br->words) {
  81762. const brword word = br->buffer[br->consumed_words++];
  81763. #if FLAC__BYTES_PER_WORD == 4
  81764. val[0] = (FLAC__byte)(word >> 24);
  81765. val[1] = (FLAC__byte)(word >> 16);
  81766. val[2] = (FLAC__byte)(word >> 8);
  81767. val[3] = (FLAC__byte)word;
  81768. #elif FLAC__BYTES_PER_WORD == 8
  81769. val[0] = (FLAC__byte)(word >> 56);
  81770. val[1] = (FLAC__byte)(word >> 48);
  81771. val[2] = (FLAC__byte)(word >> 40);
  81772. val[3] = (FLAC__byte)(word >> 32);
  81773. val[4] = (FLAC__byte)(word >> 24);
  81774. val[5] = (FLAC__byte)(word >> 16);
  81775. val[6] = (FLAC__byte)(word >> 8);
  81776. val[7] = (FLAC__byte)word;
  81777. #else
  81778. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  81779. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  81780. #endif
  81781. val += FLAC__BYTES_PER_WORD;
  81782. nvals -= FLAC__BYTES_PER_WORD;
  81783. }
  81784. else if(!bitreader_read_from_client_(br))
  81785. return false;
  81786. }
  81787. while(nvals) {
  81788. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81789. return false;
  81790. *val++ = (FLAC__byte)x;
  81791. nvals--;
  81792. }
  81793. return true;
  81794. }
  81795. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  81796. #if 0 /* slow but readable version */
  81797. {
  81798. unsigned bit;
  81799. FLAC__ASSERT(0 != br);
  81800. FLAC__ASSERT(0 != br->buffer);
  81801. *val = 0;
  81802. while(1) {
  81803. if(!FLAC__bitreader_read_bit(br, &bit))
  81804. return false;
  81805. if(bit)
  81806. break;
  81807. else
  81808. *val++;
  81809. }
  81810. return true;
  81811. }
  81812. #else
  81813. {
  81814. unsigned i;
  81815. FLAC__ASSERT(0 != br);
  81816. FLAC__ASSERT(0 != br->buffer);
  81817. *val = 0;
  81818. while(1) {
  81819. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81820. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  81821. if(b) {
  81822. i = COUNT_ZERO_MSBS(b);
  81823. *val += i;
  81824. i++;
  81825. br->consumed_bits += i;
  81826. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  81827. crc16_update_word_(br, br->buffer[br->consumed_words]);
  81828. br->consumed_words++;
  81829. br->consumed_bits = 0;
  81830. }
  81831. return true;
  81832. }
  81833. else {
  81834. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  81835. crc16_update_word_(br, br->buffer[br->consumed_words]);
  81836. br->consumed_words++;
  81837. br->consumed_bits = 0;
  81838. }
  81839. }
  81840. if(br->bytes) {
  81841. const unsigned end = br->bytes * 8;
  81842. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  81843. if(b) {
  81844. i = COUNT_ZERO_MSBS(b);
  81845. *val += i;
  81846. i++;
  81847. br->consumed_bits += i;
  81848. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  81849. return true;
  81850. }
  81851. else {
  81852. *val += end - br->consumed_bits;
  81853. br->consumed_bits += end;
  81854. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  81855. }
  81856. }
  81857. if(!bitreader_read_from_client_(br))
  81858. return false;
  81859. }
  81860. }
  81861. #endif
  81862. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  81863. {
  81864. FLAC__uint32 lsbs = 0, msbs = 0;
  81865. unsigned uval;
  81866. FLAC__ASSERT(0 != br);
  81867. FLAC__ASSERT(0 != br->buffer);
  81868. FLAC__ASSERT(parameter <= 31);
  81869. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  81870. return false;
  81871. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  81872. return false;
  81873. uval = (msbs << parameter) | lsbs;
  81874. if(uval & 1)
  81875. *val = -((int)(uval >> 1)) - 1;
  81876. else
  81877. *val = (int)(uval >> 1);
  81878. return true;
  81879. }
  81880. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  81881. #ifdef _MSC_VER
  81882. {
  81883. unsigned i;
  81884. unsigned uval = 0;
  81885. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  81886. register unsigned cwords;
  81887. register unsigned cbits;
  81888. FLAC__ASSERT(0 != br);
  81889. FLAC__ASSERT(0 != br->buffer);
  81890. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81891. FLAC__ASSERT(parameter < 32);
  81892. if(nvals == 0)
  81893. return true;
  81894. cbits = br->consumed_bits;
  81895. cwords = br->consumed_words;
  81896. while(1) {
  81897. while(1) {
  81898. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  81899. brword b = br->buffer[cwords] << cbits;
  81900. if(b) {
  81901. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  81902. __asm {
  81903. bsr eax, b
  81904. not eax
  81905. and eax, 31
  81906. mov i, eax
  81907. }
  81908. #else
  81909. i = COUNT_ZERO_MSBS(b);
  81910. #endif
  81911. uval += i;
  81912. bits = parameter;
  81913. i++;
  81914. cbits += i;
  81915. if(cbits == FLAC__BITS_PER_WORD) {
  81916. crc16_update_word_(br, br->buffer[cwords]);
  81917. cwords++;
  81918. cbits = 0;
  81919. }
  81920. goto break1;
  81921. }
  81922. else {
  81923. uval += FLAC__BITS_PER_WORD - cbits;
  81924. crc16_update_word_(br, br->buffer[cwords]);
  81925. cwords++;
  81926. cbits = 0;
  81927. }
  81928. }
  81929. if(br->bytes) {
  81930. const unsigned end = br->bytes * 8;
  81931. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  81932. if(b) {
  81933. i = COUNT_ZERO_MSBS(b);
  81934. uval += i;
  81935. bits = parameter;
  81936. i++;
  81937. cbits += i;
  81938. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  81939. goto break1;
  81940. }
  81941. else {
  81942. uval += end - cbits;
  81943. cbits += end;
  81944. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  81945. }
  81946. }
  81947. br->consumed_bits = cbits;
  81948. br->consumed_words = cwords;
  81949. if(!bitreader_read_from_client_(br))
  81950. return false;
  81951. cwords = br->consumed_words;
  81952. }
  81953. break1:
  81954. FLAC__ASSERT(cwords <= br->words);
  81955. if(bits) {
  81956. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  81957. br->consumed_bits = cbits;
  81958. br->consumed_words = cwords;
  81959. if(!bitreader_read_from_client_(br))
  81960. return false;
  81961. cwords = br->consumed_words;
  81962. }
  81963. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  81964. if(cbits) {
  81965. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  81966. const brword word = br->buffer[cwords];
  81967. if(bits < n) {
  81968. uval <<= bits;
  81969. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  81970. cbits += bits;
  81971. goto break2;
  81972. }
  81973. uval <<= n;
  81974. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  81975. bits -= n;
  81976. crc16_update_word_(br, word);
  81977. cwords++;
  81978. cbits = 0;
  81979. if(bits) { /* if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
  81980. uval <<= bits;
  81981. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  81982. cbits = bits;
  81983. }
  81984. goto break2;
  81985. }
  81986. else {
  81987. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  81988. uval <<= bits;
  81989. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  81990. cbits = bits;
  81991. goto break2;
  81992. }
  81993. }
  81994. else {
  81995. uval <<= bits;
  81996. if(cbits) {
  81997. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  81998. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  81999. cbits += bits;
  82000. goto break2;
  82001. }
  82002. else {
  82003. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82004. cbits += bits;
  82005. goto break2;
  82006. }
  82007. }
  82008. }
  82009. break2:
  82010. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82011. --nvals;
  82012. if(nvals == 0) {
  82013. br->consumed_bits = cbits;
  82014. br->consumed_words = cwords;
  82015. return true;
  82016. }
  82017. uval = 0;
  82018. ++vals;
  82019. }
  82020. }
  82021. #else
  82022. {
  82023. unsigned i;
  82024. unsigned uval = 0;
  82025. register unsigned cwords;
  82026. register unsigned cbits;
  82027. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82028. FLAC__ASSERT(0 != br);
  82029. FLAC__ASSERT(0 != br->buffer);
  82030. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82031. FLAC__ASSERT(parameter < 32);
  82032. if(nvals == 0)
  82033. return true;
  82034. cbits = br->consumed_bits;
  82035. cwords = br->consumed_words;
  82036. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82037. while(1) {
  82038. while(1) {
  82039. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82040. brword b = br->buffer[cwords] << cbits;
  82041. if(b) {
  82042. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82043. asm volatile (
  82044. "bsrl %1, %0;"
  82045. "notl %0;"
  82046. "andl $31, %0;"
  82047. : "=r"(i)
  82048. : "r"(b)
  82049. );
  82050. #else
  82051. i = COUNT_ZERO_MSBS(b);
  82052. #endif
  82053. uval += i;
  82054. cbits += i;
  82055. cbits++; /* skip over stop bit */
  82056. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82057. crc16_update_word_(br, br->buffer[cwords]);
  82058. cwords++;
  82059. cbits = 0;
  82060. }
  82061. goto break1;
  82062. }
  82063. else {
  82064. uval += FLAC__BITS_PER_WORD - cbits;
  82065. crc16_update_word_(br, br->buffer[cwords]);
  82066. cwords++;
  82067. cbits = 0;
  82068. }
  82069. }
  82070. if(br->bytes) {
  82071. const unsigned end = br->bytes * 8;
  82072. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82073. if(b) {
  82074. i = COUNT_ZERO_MSBS(b);
  82075. uval += i;
  82076. cbits += i;
  82077. cbits++; /* skip over stop bit */
  82078. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82079. goto break1;
  82080. }
  82081. else {
  82082. uval += end - cbits;
  82083. cbits += end;
  82084. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82085. }
  82086. }
  82087. br->consumed_bits = cbits;
  82088. br->consumed_words = cwords;
  82089. if(!bitreader_read_from_client_(br))
  82090. return false;
  82091. cwords = br->consumed_words;
  82092. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82093. }
  82094. break1:
  82095. ucbits -= uval;
  82096. ucbits--; /* account for stop bit */
  82097. FLAC__ASSERT(cwords <= br->words);
  82098. if(parameter) {
  82099. while(ucbits < parameter) {
  82100. br->consumed_bits = cbits;
  82101. br->consumed_words = cwords;
  82102. if(!bitreader_read_from_client_(br))
  82103. return false;
  82104. cwords = br->consumed_words;
  82105. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82106. }
  82107. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82108. if(cbits) {
  82109. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82110. const brword word = br->buffer[cwords];
  82111. if(parameter < n) {
  82112. uval <<= parameter;
  82113. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82114. cbits += parameter;
  82115. }
  82116. else {
  82117. uval <<= n;
  82118. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82119. crc16_update_word_(br, word);
  82120. cwords++;
  82121. cbits = parameter - n;
  82122. if(cbits) { /* parameter > n, i.e. if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
  82123. uval <<= cbits;
  82124. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82125. }
  82126. }
  82127. }
  82128. else {
  82129. cbits = parameter;
  82130. uval <<= parameter;
  82131. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82132. }
  82133. }
  82134. else {
  82135. uval <<= parameter;
  82136. if(cbits) {
  82137. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82138. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82139. cbits += parameter;
  82140. }
  82141. else {
  82142. cbits = parameter;
  82143. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82144. }
  82145. }
  82146. }
  82147. ucbits -= parameter;
  82148. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82149. --nvals;
  82150. if(nvals == 0) {
  82151. br->consumed_bits = cbits;
  82152. br->consumed_words = cwords;
  82153. return true;
  82154. }
  82155. uval = 0;
  82156. ++vals;
  82157. }
  82158. }
  82159. #endif
  82160. #if 0 /* UNUSED */
  82161. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82162. {
  82163. FLAC__uint32 lsbs = 0, msbs = 0;
  82164. unsigned bit, uval, k;
  82165. FLAC__ASSERT(0 != br);
  82166. FLAC__ASSERT(0 != br->buffer);
  82167. k = FLAC__bitmath_ilog2(parameter);
  82168. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82169. return false;
  82170. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82171. return false;
  82172. if(parameter == 1u<<k) {
  82173. uval = (msbs << k) | lsbs;
  82174. }
  82175. else {
  82176. unsigned d = (1 << (k+1)) - parameter;
  82177. if(lsbs >= d) {
  82178. if(!FLAC__bitreader_read_bit(br, &bit))
  82179. return false;
  82180. lsbs <<= 1;
  82181. lsbs |= bit;
  82182. lsbs -= d;
  82183. }
  82184. uval = msbs * parameter + lsbs;
  82185. }
  82186. if(uval & 1)
  82187. *val = -((int)(uval >> 1)) - 1;
  82188. else
  82189. *val = (int)(uval >> 1);
  82190. return true;
  82191. }
  82192. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82193. {
  82194. FLAC__uint32 lsbs, msbs = 0;
  82195. unsigned bit, k;
  82196. FLAC__ASSERT(0 != br);
  82197. FLAC__ASSERT(0 != br->buffer);
  82198. k = FLAC__bitmath_ilog2(parameter);
  82199. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82200. return false;
  82201. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82202. return false;
  82203. if(parameter == 1u<<k) {
  82204. *val = (msbs << k) | lsbs;
  82205. }
  82206. else {
  82207. unsigned d = (1 << (k+1)) - parameter;
  82208. if(lsbs >= d) {
  82209. if(!FLAC__bitreader_read_bit(br, &bit))
  82210. return false;
  82211. lsbs <<= 1;
  82212. lsbs |= bit;
  82213. lsbs -= d;
  82214. }
  82215. *val = msbs * parameter + lsbs;
  82216. }
  82217. return true;
  82218. }
  82219. #endif /* UNUSED */
  82220. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82221. {
  82222. FLAC__uint32 v = 0;
  82223. FLAC__uint32 x;
  82224. unsigned i;
  82225. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82226. return false;
  82227. if(raw)
  82228. raw[(*rawlen)++] = (FLAC__byte)x;
  82229. if(!(x & 0x80)) { /* 0xxxxxxx */
  82230. v = x;
  82231. i = 0;
  82232. }
  82233. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82234. v = x & 0x1F;
  82235. i = 1;
  82236. }
  82237. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82238. v = x & 0x0F;
  82239. i = 2;
  82240. }
  82241. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82242. v = x & 0x07;
  82243. i = 3;
  82244. }
  82245. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82246. v = x & 0x03;
  82247. i = 4;
  82248. }
  82249. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82250. v = x & 0x01;
  82251. i = 5;
  82252. }
  82253. else {
  82254. *val = 0xffffffff;
  82255. return true;
  82256. }
  82257. for( ; i; i--) {
  82258. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82259. return false;
  82260. if(raw)
  82261. raw[(*rawlen)++] = (FLAC__byte)x;
  82262. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82263. *val = 0xffffffff;
  82264. return true;
  82265. }
  82266. v <<= 6;
  82267. v |= (x & 0x3F);
  82268. }
  82269. *val = v;
  82270. return true;
  82271. }
  82272. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82273. {
  82274. FLAC__uint64 v = 0;
  82275. FLAC__uint32 x;
  82276. unsigned i;
  82277. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82278. return false;
  82279. if(raw)
  82280. raw[(*rawlen)++] = (FLAC__byte)x;
  82281. if(!(x & 0x80)) { /* 0xxxxxxx */
  82282. v = x;
  82283. i = 0;
  82284. }
  82285. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82286. v = x & 0x1F;
  82287. i = 1;
  82288. }
  82289. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82290. v = x & 0x0F;
  82291. i = 2;
  82292. }
  82293. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82294. v = x & 0x07;
  82295. i = 3;
  82296. }
  82297. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82298. v = x & 0x03;
  82299. i = 4;
  82300. }
  82301. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82302. v = x & 0x01;
  82303. i = 5;
  82304. }
  82305. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82306. v = 0;
  82307. i = 6;
  82308. }
  82309. else {
  82310. *val = FLAC__U64L(0xffffffffffffffff);
  82311. return true;
  82312. }
  82313. for( ; i; i--) {
  82314. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82315. return false;
  82316. if(raw)
  82317. raw[(*rawlen)++] = (FLAC__byte)x;
  82318. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82319. *val = FLAC__U64L(0xffffffffffffffff);
  82320. return true;
  82321. }
  82322. v <<= 6;
  82323. v |= (x & 0x3F);
  82324. }
  82325. *val = v;
  82326. return true;
  82327. }
  82328. #endif
  82329. /*** End of inlined file: bitreader.c ***/
  82330. /*** Start of inlined file: bitwriter.c ***/
  82331. /*** Start of inlined file: juce_FlacHeader.h ***/
  82332. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82333. // tasks..
  82334. #define VERSION "1.2.1"
  82335. #define FLAC__NO_DLL 1
  82336. #if JUCE_MSVC
  82337. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82338. #endif
  82339. #if JUCE_MAC
  82340. #define FLAC__SYS_DARWIN 1
  82341. #endif
  82342. /*** End of inlined file: juce_FlacHeader.h ***/
  82343. #if JUCE_USE_FLAC
  82344. #if HAVE_CONFIG_H
  82345. # include <config.h>
  82346. #endif
  82347. #include <stdlib.h> /* for malloc() */
  82348. #include <string.h> /* for memcpy(), memset() */
  82349. #ifdef _MSC_VER
  82350. #include <winsock.h> /* for ntohl() */
  82351. #elif defined FLAC__SYS_DARWIN
  82352. #include <machine/endian.h> /* for ntohl() */
  82353. #elif defined __MINGW32__
  82354. #include <winsock.h> /* for ntohl() */
  82355. #else
  82356. #include <netinet/in.h> /* for ntohl() */
  82357. #endif
  82358. #if 0 /* UNUSED */
  82359. #endif
  82360. /*** Start of inlined file: bitwriter.h ***/
  82361. #ifndef FLAC__PRIVATE__BITWRITER_H
  82362. #define FLAC__PRIVATE__BITWRITER_H
  82363. #include <stdio.h> /* for FILE */
  82364. struct FLAC__BitWriter;
  82365. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82366. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82367. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82368. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82369. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82370. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82371. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82372. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82373. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82374. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82375. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82376. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82377. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82378. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82379. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82380. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82381. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82382. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82383. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82384. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82385. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82386. #if 0 /* UNUSED */
  82387. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82388. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82389. #endif
  82390. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82391. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82392. #if 0 /* UNUSED */
  82393. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82394. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82395. #endif
  82396. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82397. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82398. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82399. #endif
  82400. /*** End of inlined file: bitwriter.h ***/
  82401. /*** Start of inlined file: alloc.h ***/
  82402. #ifndef FLAC__SHARE__ALLOC_H
  82403. #define FLAC__SHARE__ALLOC_H
  82404. #if HAVE_CONFIG_H
  82405. # include <config.h>
  82406. #endif
  82407. #include <limits.h> /* for SIZE_MAX */
  82408. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82409. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82410. #endif
  82411. #include <stdlib.h> /* for size_t, malloc(), etc */
  82412. #ifndef SIZE_MAX
  82413. # ifndef SIZE_T_MAX
  82414. # ifdef _MSC_VER
  82415. # define SIZE_T_MAX UINT_MAX
  82416. # else
  82417. # error
  82418. # endif
  82419. # endif
  82420. # define SIZE_MAX SIZE_T_MAX
  82421. #endif
  82422. #ifndef FLaC__INLINE
  82423. #define FLaC__INLINE
  82424. #endif
  82425. static FLaC__INLINE void *safe_malloc_(size_t size)
  82426. {
  82427. if(!size)
  82428. size++;
  82429. return malloc(size);
  82430. }
  82431. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82432. {
  82433. if(!nmemb || !size)
  82434. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82435. return calloc(nmemb, size);
  82436. }
  82437. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82438. {
  82439. size2 += size1;
  82440. if(size2 < size1)
  82441. return 0;
  82442. return safe_malloc_(size2);
  82443. }
  82444. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82445. {
  82446. size2 += size1;
  82447. if(size2 < size1)
  82448. return 0;
  82449. size3 += size2;
  82450. if(size3 < size2)
  82451. return 0;
  82452. return safe_malloc_(size3);
  82453. }
  82454. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82455. {
  82456. size2 += size1;
  82457. if(size2 < size1)
  82458. return 0;
  82459. size3 += size2;
  82460. if(size3 < size2)
  82461. return 0;
  82462. size4 += size3;
  82463. if(size4 < size3)
  82464. return 0;
  82465. return safe_malloc_(size4);
  82466. }
  82467. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82468. #if 0
  82469. needs support for cases where sizeof(size_t) != 4
  82470. {
  82471. if(sizeof(size_t) == 4) {
  82472. if ((double)size1 * (double)size2 < 4294967296.0)
  82473. return malloc(size1*size2);
  82474. }
  82475. return 0;
  82476. }
  82477. #else
  82478. {
  82479. if(!size1 || !size2)
  82480. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82481. if(size1 > SIZE_MAX / size2)
  82482. return 0;
  82483. return malloc(size1*size2);
  82484. }
  82485. #endif
  82486. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82487. {
  82488. if(!size1 || !size2 || !size3)
  82489. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82490. if(size1 > SIZE_MAX / size2)
  82491. return 0;
  82492. size1 *= size2;
  82493. if(size1 > SIZE_MAX / size3)
  82494. return 0;
  82495. return malloc(size1*size3);
  82496. }
  82497. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82498. {
  82499. if(!size1 || !size2)
  82500. return safe_malloc_(size3);
  82501. if(size1 > SIZE_MAX / size2)
  82502. return 0;
  82503. return safe_malloc_add_2op_(size1*size2, size3);
  82504. }
  82505. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82506. {
  82507. if(!size1 || (!size2 && !size3))
  82508. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82509. size2 += size3;
  82510. if(size2 < size3)
  82511. return 0;
  82512. return safe_malloc_mul_2op_(size1, size2);
  82513. }
  82514. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82515. {
  82516. size2 += size1;
  82517. if(size2 < size1)
  82518. return 0;
  82519. return realloc(ptr, size2);
  82520. }
  82521. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82522. {
  82523. size2 += size1;
  82524. if(size2 < size1)
  82525. return 0;
  82526. size3 += size2;
  82527. if(size3 < size2)
  82528. return 0;
  82529. return realloc(ptr, size3);
  82530. }
  82531. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82532. {
  82533. size2 += size1;
  82534. if(size2 < size1)
  82535. return 0;
  82536. size3 += size2;
  82537. if(size3 < size2)
  82538. return 0;
  82539. size4 += size3;
  82540. if(size4 < size3)
  82541. return 0;
  82542. return realloc(ptr, size4);
  82543. }
  82544. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82545. {
  82546. if(!size1 || !size2)
  82547. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82548. if(size1 > SIZE_MAX / size2)
  82549. return 0;
  82550. return realloc(ptr, size1*size2);
  82551. }
  82552. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82553. {
  82554. if(!size1 || (!size2 && !size3))
  82555. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82556. size2 += size3;
  82557. if(size2 < size3)
  82558. return 0;
  82559. return safe_realloc_mul_2op_(ptr, size1, size2);
  82560. }
  82561. #endif
  82562. /*** End of inlined file: alloc.h ***/
  82563. typedef FLAC__uint32 bwword;
  82564. #define FLAC__BYTES_PER_WORD 4
  82565. #define FLAC__BITS_PER_WORD 32
  82566. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82567. #if WORDS_BIGENDIAN
  82568. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82569. #else
  82570. #ifdef _MSC_VER
  82571. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82572. #else
  82573. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82574. #endif
  82575. #endif
  82576. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82577. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82578. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82579. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82580. #ifdef min
  82581. #undef min
  82582. #endif
  82583. #define min(x,y) ((x)<(y)?(x):(y))
  82584. #ifdef _MSC_VER
  82585. #define FLAC__U64L(x) x
  82586. #else
  82587. #define FLAC__U64L(x) x##LLU
  82588. #endif
  82589. #ifndef FLaC__INLINE
  82590. #define FLaC__INLINE
  82591. #endif
  82592. struct FLAC__BitWriter {
  82593. bwword *buffer;
  82594. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82595. unsigned capacity; /* capacity of buffer in words */
  82596. unsigned words; /* # of complete words in buffer */
  82597. unsigned bits; /* # of used bits in accum */
  82598. };
  82599. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82600. {
  82601. unsigned new_capacity;
  82602. bwword *new_buffer;
  82603. FLAC__ASSERT(0 != bw);
  82604. FLAC__ASSERT(0 != bw->buffer);
  82605. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82606. if(bw->capacity >= new_capacity)
  82607. return true;
  82608. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82609. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82610. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82611. FLAC__ASSERT(new_capacity > bw->capacity);
  82612. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82613. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82614. if(new_buffer == 0)
  82615. return false;
  82616. bw->buffer = new_buffer;
  82617. bw->capacity = new_capacity;
  82618. return true;
  82619. }
  82620. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82621. {
  82622. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82623. return bw;
  82624. }
  82625. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82626. {
  82627. FLAC__ASSERT(0 != bw);
  82628. FLAC__bitwriter_free(bw);
  82629. free(bw);
  82630. }
  82631. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82632. {
  82633. FLAC__ASSERT(0 != bw);
  82634. bw->words = bw->bits = 0;
  82635. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82636. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82637. if(bw->buffer == 0)
  82638. return false;
  82639. return true;
  82640. }
  82641. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82642. {
  82643. FLAC__ASSERT(0 != bw);
  82644. if(0 != bw->buffer)
  82645. free(bw->buffer);
  82646. bw->buffer = 0;
  82647. bw->capacity = 0;
  82648. bw->words = bw->bits = 0;
  82649. }
  82650. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82651. {
  82652. bw->words = bw->bits = 0;
  82653. }
  82654. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82655. {
  82656. unsigned i, j;
  82657. if(bw == 0) {
  82658. fprintf(out, "bitwriter is NULL\n");
  82659. }
  82660. else {
  82661. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82662. for(i = 0; i < bw->words; i++) {
  82663. fprintf(out, "%08X: ", i);
  82664. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82665. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82666. fprintf(out, "\n");
  82667. }
  82668. if(bw->bits > 0) {
  82669. fprintf(out, "%08X: ", i);
  82670. for(j = 0; j < bw->bits; j++)
  82671. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82672. fprintf(out, "\n");
  82673. }
  82674. }
  82675. }
  82676. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82677. {
  82678. const FLAC__byte *buffer;
  82679. size_t bytes;
  82680. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82681. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82682. return false;
  82683. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  82684. FLAC__bitwriter_release_buffer(bw);
  82685. return true;
  82686. }
  82687. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  82688. {
  82689. const FLAC__byte *buffer;
  82690. size_t bytes;
  82691. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82692. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82693. return false;
  82694. *crc = FLAC__crc8(buffer, bytes);
  82695. FLAC__bitwriter_release_buffer(bw);
  82696. return true;
  82697. }
  82698. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  82699. {
  82700. return ((bw->bits & 7) == 0);
  82701. }
  82702. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  82703. {
  82704. return FLAC__TOTAL_BITS(bw);
  82705. }
  82706. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  82707. {
  82708. FLAC__ASSERT((bw->bits & 7) == 0);
  82709. if(bw->bits & 7)
  82710. return false;
  82711. if(bw->bits) {
  82712. FLAC__ASSERT(bw->words <= bw->capacity);
  82713. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  82714. return false;
  82715. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  82716. }
  82717. *buffer = (FLAC__byte*)bw->buffer;
  82718. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  82719. return true;
  82720. }
  82721. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  82722. {
  82723. (void)bw;
  82724. }
  82725. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  82726. {
  82727. unsigned n;
  82728. FLAC__ASSERT(0 != bw);
  82729. FLAC__ASSERT(0 != bw->buffer);
  82730. if(bits == 0)
  82731. return true;
  82732. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82733. return false;
  82734. if(bw->bits) {
  82735. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  82736. bw->accum <<= n;
  82737. bits -= n;
  82738. bw->bits += n;
  82739. if(bw->bits == FLAC__BITS_PER_WORD) {
  82740. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82741. bw->bits = 0;
  82742. }
  82743. else
  82744. return true;
  82745. }
  82746. while(bits >= FLAC__BITS_PER_WORD) {
  82747. bw->buffer[bw->words++] = 0;
  82748. bits -= FLAC__BITS_PER_WORD;
  82749. }
  82750. if(bits > 0) {
  82751. bw->accum = 0;
  82752. bw->bits = bits;
  82753. }
  82754. return true;
  82755. }
  82756. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  82757. {
  82758. register unsigned left;
  82759. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82760. FLAC__ASSERT(0 != bw);
  82761. FLAC__ASSERT(0 != bw->buffer);
  82762. FLAC__ASSERT(bits <= 32);
  82763. if(bits == 0)
  82764. return true;
  82765. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82766. return false;
  82767. left = FLAC__BITS_PER_WORD - bw->bits;
  82768. if(bits < left) {
  82769. bw->accum <<= bits;
  82770. bw->accum |= val;
  82771. bw->bits += bits;
  82772. }
  82773. else if(bw->bits) { /* WATCHOUT: if bw->bits == 0, left==FLAC__BITS_PER_WORD and bw->accum<<=left is a NOP instead of setting to 0 */
  82774. bw->accum <<= left;
  82775. bw->accum |= val >> (bw->bits = bits - left);
  82776. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82777. bw->accum = val;
  82778. }
  82779. else {
  82780. bw->accum = val;
  82781. bw->bits = 0;
  82782. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  82783. }
  82784. return true;
  82785. }
  82786. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  82787. {
  82788. if(bits < 32)
  82789. val &= (~(0xffffffff << bits));
  82790. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82791. }
  82792. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  82793. {
  82794. if(bits > 32) {
  82795. return
  82796. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  82797. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  82798. }
  82799. else
  82800. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82801. }
  82802. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  82803. {
  82804. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  82805. return false;
  82806. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  82807. return false;
  82808. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  82809. return false;
  82810. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  82811. return false;
  82812. return true;
  82813. }
  82814. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  82815. {
  82816. unsigned i;
  82817. for(i = 0; i < nvals; i++) {
  82818. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  82819. return false;
  82820. }
  82821. return true;
  82822. }
  82823. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  82824. {
  82825. if(val < 32)
  82826. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  82827. else
  82828. return
  82829. FLAC__bitwriter_write_zeroes(bw, val) &&
  82830. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  82831. }
  82832. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  82833. {
  82834. FLAC__uint32 uval;
  82835. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  82836. uval = (val<<1) ^ (val>>31);
  82837. return 1 + parameter + (uval >> parameter);
  82838. }
  82839. #if 0 /* UNUSED */
  82840. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  82841. {
  82842. unsigned bits, msbs, uval;
  82843. unsigned k;
  82844. FLAC__ASSERT(parameter > 0);
  82845. if(val < 0)
  82846. uval = (unsigned)(((-(++val)) << 1) + 1);
  82847. else
  82848. uval = (unsigned)(val << 1);
  82849. k = FLAC__bitmath_ilog2(parameter);
  82850. if(parameter == 1u<<k) {
  82851. FLAC__ASSERT(k <= 30);
  82852. msbs = uval >> k;
  82853. bits = 1 + k + msbs;
  82854. }
  82855. else {
  82856. unsigned q, r, d;
  82857. d = (1 << (k+1)) - parameter;
  82858. q = uval / parameter;
  82859. r = uval - (q * parameter);
  82860. bits = 1 + q + k;
  82861. if(r >= d)
  82862. bits++;
  82863. }
  82864. return bits;
  82865. }
  82866. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  82867. {
  82868. unsigned bits, msbs;
  82869. unsigned k;
  82870. FLAC__ASSERT(parameter > 0);
  82871. k = FLAC__bitmath_ilog2(parameter);
  82872. if(parameter == 1u<<k) {
  82873. FLAC__ASSERT(k <= 30);
  82874. msbs = uval >> k;
  82875. bits = 1 + k + msbs;
  82876. }
  82877. else {
  82878. unsigned q, r, d;
  82879. d = (1 << (k+1)) - parameter;
  82880. q = uval / parameter;
  82881. r = uval - (q * parameter);
  82882. bits = 1 + q + k;
  82883. if(r >= d)
  82884. bits++;
  82885. }
  82886. return bits;
  82887. }
  82888. #endif /* UNUSED */
  82889. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  82890. {
  82891. unsigned total_bits, interesting_bits, msbs;
  82892. FLAC__uint32 uval, pattern;
  82893. FLAC__ASSERT(0 != bw);
  82894. FLAC__ASSERT(0 != bw->buffer);
  82895. FLAC__ASSERT(parameter < 8*sizeof(uval));
  82896. uval = (val<<1) ^ (val>>31);
  82897. msbs = uval >> parameter;
  82898. interesting_bits = 1 + parameter;
  82899. total_bits = interesting_bits + msbs;
  82900. pattern = 1 << parameter; /* the unary end bit */
  82901. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  82902. if(total_bits <= 32)
  82903. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  82904. else
  82905. return
  82906. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  82907. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  82908. }
  82909. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  82910. {
  82911. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  82912. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  82913. FLAC__uint32 uval;
  82914. unsigned left;
  82915. const unsigned lsbits = 1 + parameter;
  82916. unsigned msbits;
  82917. FLAC__ASSERT(0 != bw);
  82918. FLAC__ASSERT(0 != bw->buffer);
  82919. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  82920. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82921. while(nvals) {
  82922. uval = (*vals<<1) ^ (*vals>>31);
  82923. msbits = uval >> parameter;
  82924. #if 0 /* OPT: can remove this special case if it doesn't make up for the extra compare (doesn't make a statistically significant difference with msvc or gcc/x86) */
  82925. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  82926. bw->bits = bw->bits + msbits + lsbits;
  82927. uval |= mask1; /* set stop bit */
  82928. uval &= mask2; /* mask off unused top bits */
  82929. bw->accum <<= msbits;
  82930. bw->accum <<= lsbits;
  82931. bw->accum |= uval;
  82932. if(bw->bits == FLAC__BITS_PER_WORD) {
  82933. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82934. bw->bits = 0;
  82935. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  82936. FLAC__ASSERT(bw->capacity == bw->words);
  82937. return false;
  82938. }
  82939. }
  82940. }
  82941. else {
  82942. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  82943. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  82944. bw->bits = bw->bits + msbits + lsbits;
  82945. uval |= mask1; /* set stop bit */
  82946. uval &= mask2; /* mask off unused top bits */
  82947. bw->accum <<= msbits + lsbits;
  82948. bw->accum |= uval;
  82949. }
  82950. else {
  82951. #endif
  82952. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  82953. return false;
  82954. if(msbits) {
  82955. if(bw->bits) {
  82956. left = FLAC__BITS_PER_WORD - bw->bits;
  82957. if(msbits < left) {
  82958. bw->accum <<= msbits;
  82959. bw->bits += msbits;
  82960. goto break1;
  82961. }
  82962. else {
  82963. bw->accum <<= left;
  82964. msbits -= left;
  82965. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82966. bw->bits = 0;
  82967. }
  82968. }
  82969. while(msbits >= FLAC__BITS_PER_WORD) {
  82970. bw->buffer[bw->words++] = 0;
  82971. msbits -= FLAC__BITS_PER_WORD;
  82972. }
  82973. if(msbits > 0) {
  82974. bw->accum = 0;
  82975. bw->bits = msbits;
  82976. }
  82977. }
  82978. break1:
  82979. uval |= mask1; /* set stop bit */
  82980. uval &= mask2; /* mask off unused top bits */
  82981. left = FLAC__BITS_PER_WORD - bw->bits;
  82982. if(lsbits < left) {
  82983. bw->accum <<= lsbits;
  82984. bw->accum |= uval;
  82985. bw->bits += lsbits;
  82986. }
  82987. else {
  82988. FLAC__ASSERT(bw->bits);
  82989. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  82990. bw->accum <<= left;
  82991. bw->accum |= uval >> (bw->bits = lsbits - left);
  82992. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82993. bw->accum = uval;
  82994. }
  82995. #if 1
  82996. }
  82997. #endif
  82998. vals++;
  82999. nvals--;
  83000. }
  83001. return true;
  83002. }
  83003. #if 0 /* UNUSED */
  83004. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83005. {
  83006. unsigned total_bits, msbs, uval;
  83007. unsigned k;
  83008. FLAC__ASSERT(0 != bw);
  83009. FLAC__ASSERT(0 != bw->buffer);
  83010. FLAC__ASSERT(parameter > 0);
  83011. if(val < 0)
  83012. uval = (unsigned)(((-(++val)) << 1) + 1);
  83013. else
  83014. uval = (unsigned)(val << 1);
  83015. k = FLAC__bitmath_ilog2(parameter);
  83016. if(parameter == 1u<<k) {
  83017. unsigned pattern;
  83018. FLAC__ASSERT(k <= 30);
  83019. msbs = uval >> k;
  83020. total_bits = 1 + k + msbs;
  83021. pattern = 1 << k; /* the unary end bit */
  83022. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83023. if(total_bits <= 32) {
  83024. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83025. return false;
  83026. }
  83027. else {
  83028. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83029. return false;
  83030. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83031. return false;
  83032. }
  83033. }
  83034. else {
  83035. unsigned q, r, d;
  83036. d = (1 << (k+1)) - parameter;
  83037. q = uval / parameter;
  83038. r = uval - (q * parameter);
  83039. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83040. return false;
  83041. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83042. return false;
  83043. if(r >= d) {
  83044. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83045. return false;
  83046. }
  83047. else {
  83048. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83049. return false;
  83050. }
  83051. }
  83052. return true;
  83053. }
  83054. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83055. {
  83056. unsigned total_bits, msbs;
  83057. unsigned k;
  83058. FLAC__ASSERT(0 != bw);
  83059. FLAC__ASSERT(0 != bw->buffer);
  83060. FLAC__ASSERT(parameter > 0);
  83061. k = FLAC__bitmath_ilog2(parameter);
  83062. if(parameter == 1u<<k) {
  83063. unsigned pattern;
  83064. FLAC__ASSERT(k <= 30);
  83065. msbs = uval >> k;
  83066. total_bits = 1 + k + msbs;
  83067. pattern = 1 << k; /* the unary end bit */
  83068. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83069. if(total_bits <= 32) {
  83070. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83071. return false;
  83072. }
  83073. else {
  83074. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83075. return false;
  83076. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83077. return false;
  83078. }
  83079. }
  83080. else {
  83081. unsigned q, r, d;
  83082. d = (1 << (k+1)) - parameter;
  83083. q = uval / parameter;
  83084. r = uval - (q * parameter);
  83085. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83086. return false;
  83087. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83088. return false;
  83089. if(r >= d) {
  83090. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83091. return false;
  83092. }
  83093. else {
  83094. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83095. return false;
  83096. }
  83097. }
  83098. return true;
  83099. }
  83100. #endif /* UNUSED */
  83101. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83102. {
  83103. FLAC__bool ok = 1;
  83104. FLAC__ASSERT(0 != bw);
  83105. FLAC__ASSERT(0 != bw->buffer);
  83106. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83107. if(val < 0x80) {
  83108. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83109. }
  83110. else if(val < 0x800) {
  83111. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83112. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83113. }
  83114. else if(val < 0x10000) {
  83115. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83116. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83117. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83118. }
  83119. else if(val < 0x200000) {
  83120. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83121. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83122. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83123. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83124. }
  83125. else if(val < 0x4000000) {
  83126. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83127. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83128. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83129. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83130. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83131. }
  83132. else {
  83133. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83134. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83135. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83136. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83137. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83138. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83139. }
  83140. return ok;
  83141. }
  83142. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83143. {
  83144. FLAC__bool ok = 1;
  83145. FLAC__ASSERT(0 != bw);
  83146. FLAC__ASSERT(0 != bw->buffer);
  83147. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83148. if(val < 0x80) {
  83149. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83150. }
  83151. else if(val < 0x800) {
  83152. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83153. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83154. }
  83155. else if(val < 0x10000) {
  83156. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83157. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83158. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83159. }
  83160. else if(val < 0x200000) {
  83161. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83162. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83163. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83164. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83165. }
  83166. else if(val < 0x4000000) {
  83167. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83168. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83169. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83170. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83171. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83172. }
  83173. else if(val < 0x80000000) {
  83174. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83175. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83176. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83177. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83178. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83179. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83180. }
  83181. else {
  83182. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83183. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83184. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83185. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83186. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83187. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83188. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83189. }
  83190. return ok;
  83191. }
  83192. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83193. {
  83194. if(bw->bits & 7u)
  83195. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83196. else
  83197. return true;
  83198. }
  83199. #endif
  83200. /*** End of inlined file: bitwriter.c ***/
  83201. /*** Start of inlined file: cpu.c ***/
  83202. /*** Start of inlined file: juce_FlacHeader.h ***/
  83203. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83204. // tasks..
  83205. #define VERSION "1.2.1"
  83206. #define FLAC__NO_DLL 1
  83207. #if JUCE_MSVC
  83208. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83209. #endif
  83210. #if JUCE_MAC
  83211. #define FLAC__SYS_DARWIN 1
  83212. #endif
  83213. /*** End of inlined file: juce_FlacHeader.h ***/
  83214. #if JUCE_USE_FLAC
  83215. #if HAVE_CONFIG_H
  83216. # include <config.h>
  83217. #endif
  83218. #include <stdlib.h>
  83219. #include <stdio.h>
  83220. #if defined FLAC__CPU_IA32
  83221. # include <signal.h>
  83222. #elif defined FLAC__CPU_PPC
  83223. # if !defined FLAC__NO_ASM
  83224. # if defined FLAC__SYS_DARWIN
  83225. # include <sys/sysctl.h>
  83226. # include <mach/mach.h>
  83227. # include <mach/mach_host.h>
  83228. # include <mach/host_info.h>
  83229. # include <mach/machine.h>
  83230. # ifndef CPU_SUBTYPE_POWERPC_970
  83231. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83232. # endif
  83233. # else /* FLAC__SYS_DARWIN */
  83234. # include <signal.h>
  83235. # include <setjmp.h>
  83236. static sigjmp_buf jmpbuf;
  83237. static volatile sig_atomic_t canjump = 0;
  83238. static void sigill_handler (int sig)
  83239. {
  83240. if (!canjump) {
  83241. signal (sig, SIG_DFL);
  83242. raise (sig);
  83243. }
  83244. canjump = 0;
  83245. siglongjmp (jmpbuf, 1);
  83246. }
  83247. # endif /* FLAC__SYS_DARWIN */
  83248. # endif /* FLAC__NO_ASM */
  83249. #endif /* FLAC__CPU_PPC */
  83250. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83251. #include <sys/param.h>
  83252. #include <sys/sysctl.h>
  83253. #include <machine/cpu.h>
  83254. #endif
  83255. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83256. #include <sys/types.h>
  83257. #include <sys/sysctl.h>
  83258. #endif
  83259. #if defined(__APPLE__)
  83260. #endif
  83261. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83262. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83263. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83264. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83265. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83266. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83267. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83268. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83269. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83270. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83271. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83272. # if defined(__linux__)
  83273. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83274. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83275. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83276. {
  83277. (void)signal;
  83278. sc.eip += 3 + 3 + 6;
  83279. }
  83280. # else
  83281. # include <sys/ucontext.h>
  83282. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83283. {
  83284. (void)signal, (void)si;
  83285. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83286. }
  83287. # endif
  83288. # elif defined(_MSC_VER)
  83289. # include <windows.h>
  83290. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83291. # ifdef USE_TRY_CATCH_FLAVOR
  83292. # else
  83293. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83294. {
  83295. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83296. ep->ContextRecord->Eip += 3 + 3 + 6;
  83297. return EXCEPTION_CONTINUE_EXECUTION;
  83298. }
  83299. return EXCEPTION_CONTINUE_SEARCH;
  83300. }
  83301. # endif
  83302. # endif
  83303. #endif
  83304. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83305. {
  83306. #ifdef FLAC__CPU_IA32
  83307. info->type = FLAC__CPUINFO_TYPE_IA32;
  83308. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83309. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83310. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83311. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83312. info->data.ia32.cmov = false;
  83313. info->data.ia32.mmx = false;
  83314. info->data.ia32.fxsr = false;
  83315. info->data.ia32.sse = false;
  83316. info->data.ia32.sse2 = false;
  83317. info->data.ia32.sse3 = false;
  83318. info->data.ia32.ssse3 = false;
  83319. info->data.ia32._3dnow = false;
  83320. info->data.ia32.ext3dnow = false;
  83321. info->data.ia32.extmmx = false;
  83322. if(info->data.ia32.cpuid) {
  83323. FLAC__uint32 flags_edx, flags_ecx;
  83324. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83325. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83326. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83327. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83328. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83329. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83330. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83331. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83332. #ifdef FLAC__USE_3DNOW
  83333. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83334. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83335. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83336. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83337. #else
  83338. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83339. #endif
  83340. #ifdef DEBUG
  83341. fprintf(stderr, "CPU info (IA-32):\n");
  83342. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83343. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83344. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83345. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83346. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83347. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83348. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83349. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83350. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83351. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83352. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83353. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83354. #endif
  83355. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83356. #if defined FLAC__NO_SSE_OS
  83357. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83358. #elif defined FLAC__SSE_OS
  83359. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83360. int sse = 0;
  83361. size_t len;
  83362. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83363. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83364. if(!sse)
  83365. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83366. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83367. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83368. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83369. size_t len = sizeof(val);
  83370. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83371. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83372. else { /* double-check SSE2 */
  83373. mib[1] = CPU_SSE2;
  83374. len = sizeof(val);
  83375. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83376. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83377. }
  83378. # else
  83379. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83380. # endif
  83381. #elif defined(__linux__)
  83382. int sse = 0;
  83383. struct sigaction sigill_save;
  83384. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83385. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83386. #else
  83387. struct sigaction sigill_sse;
  83388. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83389. __sigemptyset(&sigill_sse.sa_mask);
  83390. sigill_sse.sa_flags = SA_SIGINFO | SA_RESETHAND; /* SA_RESETHAND just in case our SIGILL return jump breaks, so we don't get stuck in a loop */
  83391. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83392. #endif
  83393. {
  83394. asm volatile (
  83395. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83396. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83397. "incl %0\n\t" /* SIGILL handler will jump over this */
  83398. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83399. "nop\n\t"
  83400. "nop\n\t"
  83401. "nop\n\t"
  83402. "nop\n\t"
  83403. "nop\n\t"
  83404. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83405. "nop\n\t"
  83406. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83407. : "=r"(sse)
  83408. : "r"(sse)
  83409. );
  83410. sigaction(SIGILL, &sigill_save, NULL);
  83411. }
  83412. if(!sse)
  83413. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83414. #elif defined(_MSC_VER)
  83415. # ifdef USE_TRY_CATCH_FLAVOR
  83416. _try {
  83417. __asm {
  83418. # if _MSC_VER <= 1200
  83419. _emit 0x0F
  83420. _emit 0x57
  83421. _emit 0xC0
  83422. # else
  83423. xorps xmm0,xmm0
  83424. # endif
  83425. }
  83426. }
  83427. _except(EXCEPTION_EXECUTE_HANDLER) {
  83428. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83429. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83430. }
  83431. # else
  83432. int sse = 0;
  83433. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83434. __asm {
  83435. # if _MSC_VER <= 1200
  83436. _emit 0x0F
  83437. _emit 0x57
  83438. _emit 0xC0
  83439. # else
  83440. xorps xmm0,xmm0
  83441. # endif
  83442. inc sse
  83443. nop
  83444. nop
  83445. nop
  83446. nop
  83447. nop
  83448. nop
  83449. nop
  83450. nop
  83451. nop
  83452. }
  83453. SetUnhandledExceptionFilter(save);
  83454. if(!sse)
  83455. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83456. # endif
  83457. #else
  83458. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83459. #endif
  83460. #ifdef DEBUG
  83461. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83462. #endif
  83463. }
  83464. }
  83465. #else
  83466. info->use_asm = false;
  83467. #endif
  83468. #elif defined FLAC__CPU_PPC
  83469. info->type = FLAC__CPUINFO_TYPE_PPC;
  83470. # if !defined FLAC__NO_ASM
  83471. info->use_asm = true;
  83472. # ifdef FLAC__USE_ALTIVEC
  83473. # if defined FLAC__SYS_DARWIN
  83474. {
  83475. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83476. size_t len = sizeof(val);
  83477. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83478. }
  83479. {
  83480. host_basic_info_data_t hostInfo;
  83481. mach_msg_type_number_t infoCount;
  83482. infoCount = HOST_BASIC_INFO_COUNT;
  83483. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83484. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83485. }
  83486. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83487. {
  83488. info->data.ppc.altivec = 0;
  83489. info->data.ppc.ppc64 = 0;
  83490. signal (SIGILL, sigill_handler);
  83491. canjump = 0;
  83492. if (!sigsetjmp (jmpbuf, 1)) {
  83493. canjump = 1;
  83494. asm volatile (
  83495. "mtspr 256, %0\n\t"
  83496. "vand %%v0, %%v0, %%v0"
  83497. :
  83498. : "r" (-1)
  83499. );
  83500. info->data.ppc.altivec = 1;
  83501. }
  83502. canjump = 0;
  83503. if (!sigsetjmp (jmpbuf, 1)) {
  83504. int x = 0;
  83505. canjump = 1;
  83506. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83507. info->data.ppc.ppc64 = 1;
  83508. }
  83509. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83510. }
  83511. # endif
  83512. # else /* !FLAC__USE_ALTIVEC */
  83513. info->data.ppc.altivec = 0;
  83514. info->data.ppc.ppc64 = 0;
  83515. # endif
  83516. # else
  83517. info->use_asm = false;
  83518. # endif
  83519. #else
  83520. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83521. info->use_asm = false;
  83522. #endif
  83523. }
  83524. #endif
  83525. /*** End of inlined file: cpu.c ***/
  83526. /*** Start of inlined file: crc.c ***/
  83527. /*** Start of inlined file: juce_FlacHeader.h ***/
  83528. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83529. // tasks..
  83530. #define VERSION "1.2.1"
  83531. #define FLAC__NO_DLL 1
  83532. #if JUCE_MSVC
  83533. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83534. #endif
  83535. #if JUCE_MAC
  83536. #define FLAC__SYS_DARWIN 1
  83537. #endif
  83538. /*** End of inlined file: juce_FlacHeader.h ***/
  83539. #if JUCE_USE_FLAC
  83540. #if HAVE_CONFIG_H
  83541. # include <config.h>
  83542. #endif
  83543. FLAC__byte const FLAC__crc8_table[256] = {
  83544. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83545. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83546. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83547. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83548. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83549. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83550. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83551. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83552. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83553. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83554. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83555. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83556. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83557. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83558. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83559. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83560. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83561. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83562. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83563. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83564. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83565. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83566. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83567. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83568. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83569. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83570. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83571. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83572. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83573. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83574. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83575. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83576. };
  83577. unsigned FLAC__crc16_table[256] = {
  83578. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83579. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83580. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83581. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83582. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83583. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83584. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83585. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83586. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83587. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83588. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83589. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83590. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83591. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83592. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83593. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83594. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83595. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83596. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83597. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83598. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83599. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83600. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83601. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83602. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83603. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83604. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83605. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83606. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83607. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83608. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83609. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83610. };
  83611. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83612. {
  83613. *crc = FLAC__crc8_table[*crc ^ data];
  83614. }
  83615. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83616. {
  83617. while(len--)
  83618. *crc = FLAC__crc8_table[*crc ^ *data++];
  83619. }
  83620. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83621. {
  83622. FLAC__uint8 crc = 0;
  83623. while(len--)
  83624. crc = FLAC__crc8_table[crc ^ *data++];
  83625. return crc;
  83626. }
  83627. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83628. {
  83629. unsigned crc = 0;
  83630. while(len--)
  83631. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83632. return crc;
  83633. }
  83634. #endif
  83635. /*** End of inlined file: crc.c ***/
  83636. /*** Start of inlined file: fixed.c ***/
  83637. /*** Start of inlined file: juce_FlacHeader.h ***/
  83638. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83639. // tasks..
  83640. #define VERSION "1.2.1"
  83641. #define FLAC__NO_DLL 1
  83642. #if JUCE_MSVC
  83643. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83644. #endif
  83645. #if JUCE_MAC
  83646. #define FLAC__SYS_DARWIN 1
  83647. #endif
  83648. /*** End of inlined file: juce_FlacHeader.h ***/
  83649. #if JUCE_USE_FLAC
  83650. #if HAVE_CONFIG_H
  83651. # include <config.h>
  83652. #endif
  83653. #include <math.h>
  83654. #include <string.h>
  83655. /*** Start of inlined file: fixed.h ***/
  83656. #ifndef FLAC__PRIVATE__FIXED_H
  83657. #define FLAC__PRIVATE__FIXED_H
  83658. #ifdef HAVE_CONFIG_H
  83659. #include <config.h>
  83660. #endif
  83661. /*** Start of inlined file: float.h ***/
  83662. #ifndef FLAC__PRIVATE__FLOAT_H
  83663. #define FLAC__PRIVATE__FLOAT_H
  83664. #ifdef HAVE_CONFIG_H
  83665. #include <config.h>
  83666. #endif
  83667. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83668. typedef double FLAC__double;
  83669. typedef float FLAC__float;
  83670. typedef float FLAC__real;
  83671. #else
  83672. typedef FLAC__int32 FLAC__fixedpoint;
  83673. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83674. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83675. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83676. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83677. extern const FLAC__fixedpoint FLAC__FP_E;
  83678. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83679. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83680. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83681. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  83682. #endif
  83683. #endif
  83684. /*** End of inlined file: float.h ***/
  83685. /*** Start of inlined file: format.h ***/
  83686. #ifndef FLAC__PRIVATE__FORMAT_H
  83687. #define FLAC__PRIVATE__FORMAT_H
  83688. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  83689. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  83690. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  83691. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83692. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83693. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  83694. #endif
  83695. /*** End of inlined file: format.h ***/
  83696. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83697. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83698. # ifndef FLAC__NO_ASM
  83699. # ifdef FLAC__CPU_IA32
  83700. # ifdef FLAC__HAS_NASM
  83701. unsigned FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83702. # endif
  83703. # endif
  83704. # endif
  83705. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83706. #else
  83707. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83708. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83709. #endif
  83710. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  83711. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  83712. #endif
  83713. /*** End of inlined file: fixed.h ***/
  83714. #ifndef M_LN2
  83715. #define M_LN2 0.69314718055994530942
  83716. #endif
  83717. #ifdef min
  83718. #undef min
  83719. #endif
  83720. #define min(x,y) ((x) < (y)? (x) : (y))
  83721. #ifdef local_abs
  83722. #undef local_abs
  83723. #endif
  83724. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  83725. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  83726. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  83727. {
  83728. FLAC__uint32 rbps;
  83729. unsigned bits; /* the number of bits required to represent a number */
  83730. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83731. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83732. FLAC__ASSERT(err > 0);
  83733. FLAC__ASSERT(n > 0);
  83734. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83735. if(err <= n)
  83736. return 0;
  83737. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  83738. err <<= fracbits;
  83739. err /= n;
  83740. FLAC__ASSERT(err > 0);
  83741. bits = FLAC__bitmath_ilog2(err)+1;
  83742. if(bits > 16) {
  83743. err >>= (bits-16);
  83744. fracbits -= (bits-16);
  83745. }
  83746. rbps = (FLAC__uint32)err;
  83747. rbps *= FLAC__FP_LN2;
  83748. fracbits += 16;
  83749. FLAC__ASSERT(fracbits >= 0);
  83750. {
  83751. const int f = fracbits & 3;
  83752. if(f) {
  83753. rbps >>= f;
  83754. fracbits -= f;
  83755. }
  83756. }
  83757. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83758. if(rbps == 0)
  83759. return 0;
  83760. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83761. FLAC__ASSERT(fracbits >= -3);
  83762. if(fracbits < 16)
  83763. return rbps << (16-fracbits);
  83764. else if(fracbits > 16)
  83765. return rbps >> (fracbits-16);
  83766. else
  83767. return rbps;
  83768. }
  83769. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  83770. {
  83771. FLAC__uint32 rbps;
  83772. unsigned bits; /* the number of bits required to represent a number */
  83773. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83774. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83775. FLAC__ASSERT(err > 0);
  83776. FLAC__ASSERT(n > 0);
  83777. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83778. if(err <= n)
  83779. return 0;
  83780. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  83781. err <<= fracbits;
  83782. err /= n;
  83783. FLAC__ASSERT(err > 0);
  83784. bits = FLAC__bitmath_ilog2_wide(err)+1;
  83785. if(bits > 16) {
  83786. err >>= (bits-16);
  83787. fracbits -= (bits-16);
  83788. }
  83789. rbps = (FLAC__uint32)err;
  83790. rbps *= FLAC__FP_LN2;
  83791. fracbits += 16;
  83792. FLAC__ASSERT(fracbits >= 0);
  83793. {
  83794. const int f = fracbits & 3;
  83795. if(f) {
  83796. rbps >>= f;
  83797. fracbits -= f;
  83798. }
  83799. }
  83800. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83801. if(rbps == 0)
  83802. return 0;
  83803. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83804. FLAC__ASSERT(fracbits >= -3);
  83805. if(fracbits < 16)
  83806. return rbps << (16-fracbits);
  83807. else if(fracbits > 16)
  83808. return rbps >> (fracbits-16);
  83809. else
  83810. return rbps;
  83811. }
  83812. #endif
  83813. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83814. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83815. #else
  83816. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83817. #endif
  83818. {
  83819. FLAC__int32 last_error_0 = data[-1];
  83820. FLAC__int32 last_error_1 = data[-1] - data[-2];
  83821. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  83822. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  83823. FLAC__int32 error, save;
  83824. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  83825. unsigned i, order;
  83826. for(i = 0; i < data_len; i++) {
  83827. error = data[i] ; total_error_0 += local_abs(error); save = error;
  83828. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  83829. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  83830. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  83831. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  83832. }
  83833. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  83834. order = 0;
  83835. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  83836. order = 1;
  83837. else if(total_error_2 < min(total_error_3, total_error_4))
  83838. order = 2;
  83839. else if(total_error_3 < total_error_4)
  83840. order = 3;
  83841. else
  83842. order = 4;
  83843. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  83844. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  83845. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  83846. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  83847. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  83848. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83849. residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83850. residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83851. residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83852. residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83853. residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83854. #else
  83855. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  83856. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  83857. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  83858. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  83859. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  83860. #endif
  83861. return order;
  83862. }
  83863. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83864. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83865. #else
  83866. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83867. #endif
  83868. {
  83869. FLAC__int32 last_error_0 = data[-1];
  83870. FLAC__int32 last_error_1 = data[-1] - data[-2];
  83871. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  83872. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  83873. FLAC__int32 error, save;
  83874. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  83875. unsigned i, order;
  83876. for(i = 0; i < data_len; i++) {
  83877. error = data[i] ; total_error_0 += local_abs(error); save = error;
  83878. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  83879. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  83880. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  83881. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  83882. }
  83883. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  83884. order = 0;
  83885. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  83886. order = 1;
  83887. else if(total_error_2 < min(total_error_3, total_error_4))
  83888. order = 2;
  83889. else if(total_error_3 < total_error_4)
  83890. order = 3;
  83891. else
  83892. order = 4;
  83893. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  83894. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  83895. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  83896. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  83897. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  83898. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83899. #if defined _MSC_VER || defined __MINGW32__
  83900. residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83901. residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83902. residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83903. residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83904. residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83905. #else
  83906. residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83907. residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83908. residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83909. residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83910. residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83911. #endif
  83912. #else
  83913. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  83914. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  83915. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  83916. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  83917. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  83918. #endif
  83919. return order;
  83920. }
  83921. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  83922. {
  83923. const int idata_len = (int)data_len;
  83924. int i;
  83925. switch(order) {
  83926. case 0:
  83927. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  83928. memcpy(residual, data, sizeof(residual[0])*data_len);
  83929. break;
  83930. case 1:
  83931. for(i = 0; i < idata_len; i++)
  83932. residual[i] = data[i] - data[i-1];
  83933. break;
  83934. case 2:
  83935. for(i = 0; i < idata_len; i++)
  83936. #if 1 /* OPT: may be faster with some compilers on some systems */
  83937. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  83938. #else
  83939. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  83940. #endif
  83941. break;
  83942. case 3:
  83943. for(i = 0; i < idata_len; i++)
  83944. #if 1 /* OPT: may be faster with some compilers on some systems */
  83945. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  83946. #else
  83947. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  83948. #endif
  83949. break;
  83950. case 4:
  83951. for(i = 0; i < idata_len; i++)
  83952. #if 1 /* OPT: may be faster with some compilers on some systems */
  83953. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  83954. #else
  83955. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  83956. #endif
  83957. break;
  83958. default:
  83959. FLAC__ASSERT(0);
  83960. }
  83961. }
  83962. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  83963. {
  83964. int i, idata_len = (int)data_len;
  83965. switch(order) {
  83966. case 0:
  83967. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  83968. memcpy(data, residual, sizeof(residual[0])*data_len);
  83969. break;
  83970. case 1:
  83971. for(i = 0; i < idata_len; i++)
  83972. data[i] = residual[i] + data[i-1];
  83973. break;
  83974. case 2:
  83975. for(i = 0; i < idata_len; i++)
  83976. #if 1 /* OPT: may be faster with some compilers on some systems */
  83977. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  83978. #else
  83979. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  83980. #endif
  83981. break;
  83982. case 3:
  83983. for(i = 0; i < idata_len; i++)
  83984. #if 1 /* OPT: may be faster with some compilers on some systems */
  83985. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  83986. #else
  83987. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  83988. #endif
  83989. break;
  83990. case 4:
  83991. for(i = 0; i < idata_len; i++)
  83992. #if 1 /* OPT: may be faster with some compilers on some systems */
  83993. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  83994. #else
  83995. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  83996. #endif
  83997. break;
  83998. default:
  83999. FLAC__ASSERT(0);
  84000. }
  84001. }
  84002. #endif
  84003. /*** End of inlined file: fixed.c ***/
  84004. /*** Start of inlined file: float.c ***/
  84005. /*** Start of inlined file: juce_FlacHeader.h ***/
  84006. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84007. // tasks..
  84008. #define VERSION "1.2.1"
  84009. #define FLAC__NO_DLL 1
  84010. #if JUCE_MSVC
  84011. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84012. #endif
  84013. #if JUCE_MAC
  84014. #define FLAC__SYS_DARWIN 1
  84015. #endif
  84016. /*** End of inlined file: juce_FlacHeader.h ***/
  84017. #if JUCE_USE_FLAC
  84018. #if HAVE_CONFIG_H
  84019. # include <config.h>
  84020. #endif
  84021. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84022. #ifdef _MSC_VER
  84023. #define FLAC__U64L(x) x
  84024. #else
  84025. #define FLAC__U64L(x) x##LLU
  84026. #endif
  84027. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84028. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84029. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84030. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84031. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84032. #define LOG2_LOOKUP_PRECISION 16
  84033. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84034. {
  84035. 0x00000000,
  84036. 0x00000001,
  84037. 0x00000000,
  84038. 0x00000000,
  84039. 0x00000000,
  84040. 0x00000000,
  84041. 0x00000000,
  84042. 0x00000000,
  84043. 0x00000000,
  84044. 0x00000000,
  84045. 0x00000000,
  84046. 0x00000000,
  84047. 0x00000000,
  84048. 0x00000000,
  84049. 0x00000000,
  84050. 0x00000000
  84051. },
  84052. {
  84053. 0x00000000,
  84054. 0x00000010,
  84055. 0x00000007,
  84056. 0x00000003,
  84057. 0x00000001,
  84058. 0x00000001,
  84059. 0x00000000,
  84060. 0x00000000,
  84061. 0x00000000,
  84062. 0x00000000,
  84063. 0x00000000,
  84064. 0x00000000,
  84065. 0x00000000,
  84066. 0x00000000,
  84067. 0x00000000,
  84068. 0x00000000
  84069. },
  84070. {
  84071. 0x00000000,
  84072. 0x00000100,
  84073. 0x0000006a,
  84074. 0x00000031,
  84075. 0x00000018,
  84076. 0x0000000c,
  84077. 0x00000006,
  84078. 0x00000003,
  84079. 0x00000001,
  84080. 0x00000001,
  84081. 0x00000000,
  84082. 0x00000000,
  84083. 0x00000000,
  84084. 0x00000000,
  84085. 0x00000000,
  84086. 0x00000000
  84087. },
  84088. {
  84089. 0x00000000,
  84090. 0x00001000,
  84091. 0x000006a4,
  84092. 0x00000315,
  84093. 0x0000017d,
  84094. 0x000000bc,
  84095. 0x0000005d,
  84096. 0x0000002e,
  84097. 0x00000017,
  84098. 0x0000000c,
  84099. 0x00000006,
  84100. 0x00000003,
  84101. 0x00000001,
  84102. 0x00000001,
  84103. 0x00000000,
  84104. 0x00000000
  84105. },
  84106. {
  84107. 0x00000000,
  84108. 0x00010000,
  84109. 0x00006a40,
  84110. 0x00003151,
  84111. 0x000017d6,
  84112. 0x00000bba,
  84113. 0x000005d1,
  84114. 0x000002e6,
  84115. 0x00000172,
  84116. 0x000000b9,
  84117. 0x0000005c,
  84118. 0x0000002e,
  84119. 0x00000017,
  84120. 0x0000000c,
  84121. 0x00000006,
  84122. 0x00000003
  84123. },
  84124. {
  84125. 0x00000000,
  84126. 0x00100000,
  84127. 0x0006a3fe,
  84128. 0x00031513,
  84129. 0x00017d60,
  84130. 0x0000bb9d,
  84131. 0x00005d10,
  84132. 0x00002e59,
  84133. 0x00001721,
  84134. 0x00000b8e,
  84135. 0x000005c6,
  84136. 0x000002e3,
  84137. 0x00000171,
  84138. 0x000000b9,
  84139. 0x0000005c,
  84140. 0x0000002e
  84141. },
  84142. {
  84143. 0x00000000,
  84144. 0x01000000,
  84145. 0x006a3fe6,
  84146. 0x00315130,
  84147. 0x0017d605,
  84148. 0x000bb9ca,
  84149. 0x0005d0fc,
  84150. 0x0002e58f,
  84151. 0x0001720e,
  84152. 0x0000b8d8,
  84153. 0x00005c61,
  84154. 0x00002e2d,
  84155. 0x00001716,
  84156. 0x00000b8b,
  84157. 0x000005c5,
  84158. 0x000002e3
  84159. },
  84160. {
  84161. 0x00000000,
  84162. 0x10000000,
  84163. 0x06a3fe5c,
  84164. 0x03151301,
  84165. 0x017d6049,
  84166. 0x00bb9ca6,
  84167. 0x005d0fba,
  84168. 0x002e58f7,
  84169. 0x001720da,
  84170. 0x000b8d87,
  84171. 0x0005c60b,
  84172. 0x0002e2d7,
  84173. 0x00017160,
  84174. 0x0000b8ad,
  84175. 0x00005c56,
  84176. 0x00002e2b
  84177. }
  84178. };
  84179. #if 0
  84180. static const FLAC__uint64 log2_lookup_wide[] = {
  84181. {
  84182. 0x00000000,
  84183. FLAC__U64L(0x100000000),
  84184. FLAC__U64L(0x6a3fe5c6),
  84185. FLAC__U64L(0x31513015),
  84186. FLAC__U64L(0x17d60497),
  84187. FLAC__U64L(0x0bb9ca65),
  84188. FLAC__U64L(0x05d0fba2),
  84189. FLAC__U64L(0x02e58f74),
  84190. FLAC__U64L(0x01720d9c),
  84191. FLAC__U64L(0x00b8d875),
  84192. FLAC__U64L(0x005c60aa),
  84193. FLAC__U64L(0x002e2d72),
  84194. FLAC__U64L(0x00171600),
  84195. FLAC__U64L(0x000b8ad2),
  84196. FLAC__U64L(0x0005c55d),
  84197. FLAC__U64L(0x0002e2ac)
  84198. },
  84199. {
  84200. 0x00000000,
  84201. FLAC__U64L(0x1000000000000),
  84202. FLAC__U64L(0x6a3fe5c60429),
  84203. FLAC__U64L(0x315130157f7a),
  84204. FLAC__U64L(0x17d60496cfbb),
  84205. FLAC__U64L(0xbb9ca64ecac),
  84206. FLAC__U64L(0x5d0fba187cd),
  84207. FLAC__U64L(0x2e58f7441ee),
  84208. FLAC__U64L(0x1720d9c06a8),
  84209. FLAC__U64L(0xb8d8752173),
  84210. FLAC__U64L(0x5c60aa252e),
  84211. FLAC__U64L(0x2e2d71b0d8),
  84212. FLAC__U64L(0x1716001719),
  84213. FLAC__U64L(0xb8ad1de1b),
  84214. FLAC__U64L(0x5c55d640d),
  84215. FLAC__U64L(0x2e2abcf52)
  84216. }
  84217. };
  84218. #endif
  84219. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84220. {
  84221. const FLAC__uint32 ONE = (1u << fracbits);
  84222. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84223. FLAC__ASSERT(fracbits < 32);
  84224. FLAC__ASSERT((fracbits & 0x3) == 0);
  84225. if(x < ONE)
  84226. return 0;
  84227. if(precision > LOG2_LOOKUP_PRECISION)
  84228. precision = LOG2_LOOKUP_PRECISION;
  84229. {
  84230. FLAC__uint32 y = 0;
  84231. FLAC__uint32 z = x >> 1, k = 1;
  84232. while (x > ONE && k < precision) {
  84233. if (x - z >= ONE) {
  84234. x -= z;
  84235. z = x >> k;
  84236. y += table[k];
  84237. }
  84238. else {
  84239. z >>= 1;
  84240. k++;
  84241. }
  84242. }
  84243. return y;
  84244. }
  84245. }
  84246. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84247. #endif
  84248. /*** End of inlined file: float.c ***/
  84249. /*** Start of inlined file: format.c ***/
  84250. /*** Start of inlined file: juce_FlacHeader.h ***/
  84251. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84252. // tasks..
  84253. #define VERSION "1.2.1"
  84254. #define FLAC__NO_DLL 1
  84255. #if JUCE_MSVC
  84256. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84257. #endif
  84258. #if JUCE_MAC
  84259. #define FLAC__SYS_DARWIN 1
  84260. #endif
  84261. /*** End of inlined file: juce_FlacHeader.h ***/
  84262. #if JUCE_USE_FLAC
  84263. #if HAVE_CONFIG_H
  84264. # include <config.h>
  84265. #endif
  84266. #include <stdio.h>
  84267. #include <stdlib.h> /* for qsort() */
  84268. #include <string.h> /* for memset() */
  84269. #ifndef FLaC__INLINE
  84270. #define FLaC__INLINE
  84271. #endif
  84272. #ifdef min
  84273. #undef min
  84274. #endif
  84275. #define min(a,b) ((a)<(b)?(a):(b))
  84276. #ifdef _MSC_VER
  84277. #define FLAC__U64L(x) x
  84278. #else
  84279. #define FLAC__U64L(x) x##LLU
  84280. #endif
  84281. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84282. ;
  84283. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84284. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84285. #else
  84286. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84287. #endif
  84288. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84289. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84290. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84291. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84292. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84293. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84294. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84295. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84296. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84297. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84298. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84299. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84300. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84301. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84302. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84303. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84304. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84305. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84306. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84307. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84308. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84309. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84310. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84311. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84312. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84313. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84314. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84315. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84316. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84317. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84318. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84319. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84320. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84321. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84322. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84323. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84324. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84325. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84326. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84327. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84328. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84329. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84330. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84331. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84332. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84333. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84334. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84335. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84336. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84337. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84338. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84339. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84340. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84341. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84342. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84343. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84344. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84345. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84346. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84347. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84348. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84349. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84350. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84351. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84352. "PARTITIONED_RICE",
  84353. "PARTITIONED_RICE2"
  84354. };
  84355. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84356. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84357. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84358. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84359. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84360. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84361. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84362. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84363. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84364. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84365. "CONSTANT",
  84366. "VERBATIM",
  84367. "FIXED",
  84368. "LPC"
  84369. };
  84370. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84371. "INDEPENDENT",
  84372. "LEFT_SIDE",
  84373. "RIGHT_SIDE",
  84374. "MID_SIDE"
  84375. };
  84376. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84377. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84378. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84379. };
  84380. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84381. "STREAMINFO",
  84382. "PADDING",
  84383. "APPLICATION",
  84384. "SEEKTABLE",
  84385. "VORBIS_COMMENT",
  84386. "CUESHEET",
  84387. "PICTURE"
  84388. };
  84389. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84390. "Other",
  84391. "32x32 pixels 'file icon' (PNG only)",
  84392. "Other file icon",
  84393. "Cover (front)",
  84394. "Cover (back)",
  84395. "Leaflet page",
  84396. "Media (e.g. label side of CD)",
  84397. "Lead artist/lead performer/soloist",
  84398. "Artist/performer",
  84399. "Conductor",
  84400. "Band/Orchestra",
  84401. "Composer",
  84402. "Lyricist/text writer",
  84403. "Recording Location",
  84404. "During recording",
  84405. "During performance",
  84406. "Movie/video screen capture",
  84407. "A bright coloured fish",
  84408. "Illustration",
  84409. "Band/artist logotype",
  84410. "Publisher/Studio logotype"
  84411. };
  84412. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84413. {
  84414. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84415. return false;
  84416. }
  84417. else
  84418. return true;
  84419. }
  84420. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84421. {
  84422. if(
  84423. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84424. (
  84425. sample_rate >= (1u << 16) &&
  84426. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84427. )
  84428. ) {
  84429. return false;
  84430. }
  84431. else
  84432. return true;
  84433. }
  84434. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84435. {
  84436. unsigned i;
  84437. FLAC__uint64 prev_sample_number = 0;
  84438. FLAC__bool got_prev = false;
  84439. FLAC__ASSERT(0 != seek_table);
  84440. for(i = 0; i < seek_table->num_points; i++) {
  84441. if(got_prev) {
  84442. if(
  84443. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84444. seek_table->points[i].sample_number <= prev_sample_number
  84445. )
  84446. return false;
  84447. }
  84448. prev_sample_number = seek_table->points[i].sample_number;
  84449. got_prev = true;
  84450. }
  84451. return true;
  84452. }
  84453. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84454. {
  84455. if(l->sample_number == r->sample_number)
  84456. return 0;
  84457. else if(l->sample_number < r->sample_number)
  84458. return -1;
  84459. else
  84460. return 1;
  84461. }
  84462. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84463. {
  84464. unsigned i, j;
  84465. FLAC__bool first;
  84466. FLAC__ASSERT(0 != seek_table);
  84467. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84468. first = true;
  84469. for(i = j = 0; i < seek_table->num_points; i++) {
  84470. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84471. if(!first) {
  84472. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84473. continue;
  84474. }
  84475. }
  84476. first = false;
  84477. seek_table->points[j++] = seek_table->points[i];
  84478. }
  84479. for(i = j; i < seek_table->num_points; i++) {
  84480. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84481. seek_table->points[i].stream_offset = 0;
  84482. seek_table->points[i].frame_samples = 0;
  84483. }
  84484. return j;
  84485. }
  84486. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84487. {
  84488. FLAC__ASSERT(0 != utf8);
  84489. if ((utf8[0] & 0x80) == 0) {
  84490. return 1;
  84491. }
  84492. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84493. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84494. return 0;
  84495. return 2;
  84496. }
  84497. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84498. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84499. return 0;
  84500. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84501. return 0;
  84502. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84503. return 0;
  84504. return 3;
  84505. }
  84506. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84507. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84508. return 0;
  84509. return 4;
  84510. }
  84511. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84512. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84513. return 0;
  84514. return 5;
  84515. }
  84516. else if ((utf8[0] & 0xFE) == 0xFC && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80 && (utf8[5] & 0xC0) == 0x80) {
  84517. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84518. return 0;
  84519. return 6;
  84520. }
  84521. else {
  84522. return 0;
  84523. }
  84524. }
  84525. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84526. {
  84527. char c;
  84528. for(c = *name; c; c = *(++name))
  84529. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84530. return false;
  84531. return true;
  84532. }
  84533. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84534. {
  84535. if(length == (unsigned)(-1)) {
  84536. while(*value) {
  84537. unsigned n = utf8len_(value);
  84538. if(n == 0)
  84539. return false;
  84540. value += n;
  84541. }
  84542. }
  84543. else {
  84544. const FLAC__byte *end = value + length;
  84545. while(value < end) {
  84546. unsigned n = utf8len_(value);
  84547. if(n == 0)
  84548. return false;
  84549. value += n;
  84550. }
  84551. if(value != end)
  84552. return false;
  84553. }
  84554. return true;
  84555. }
  84556. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84557. {
  84558. const FLAC__byte *s, *end;
  84559. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84560. if(*s < 0x20 || *s > 0x7D)
  84561. return false;
  84562. }
  84563. if(s == end)
  84564. return false;
  84565. s++; /* skip '=' */
  84566. while(s < end) {
  84567. unsigned n = utf8len_(s);
  84568. if(n == 0)
  84569. return false;
  84570. s += n;
  84571. }
  84572. if(s != end)
  84573. return false;
  84574. return true;
  84575. }
  84576. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84577. {
  84578. unsigned i, j;
  84579. if(check_cd_da_subset) {
  84580. if(cue_sheet->lead_in < 2 * 44100) {
  84581. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84582. return false;
  84583. }
  84584. if(cue_sheet->lead_in % 588 != 0) {
  84585. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84586. return false;
  84587. }
  84588. }
  84589. if(cue_sheet->num_tracks == 0) {
  84590. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84591. return false;
  84592. }
  84593. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84594. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84595. return false;
  84596. }
  84597. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84598. if(cue_sheet->tracks[i].number == 0) {
  84599. if(violation) *violation = "cue sheet may not have a track number 0";
  84600. return false;
  84601. }
  84602. if(check_cd_da_subset) {
  84603. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84604. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84605. return false;
  84606. }
  84607. }
  84608. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84609. if(violation) {
  84610. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84611. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84612. else
  84613. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84614. }
  84615. return false;
  84616. }
  84617. if(i < cue_sheet->num_tracks - 1) {
  84618. if(cue_sheet->tracks[i].num_indices == 0) {
  84619. if(violation) *violation = "cue sheet track must have at least one index point";
  84620. return false;
  84621. }
  84622. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84623. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84624. return false;
  84625. }
  84626. }
  84627. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84628. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84629. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84630. return false;
  84631. }
  84632. if(j > 0) {
  84633. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84634. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84635. return false;
  84636. }
  84637. }
  84638. }
  84639. }
  84640. return true;
  84641. }
  84642. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84643. {
  84644. char *p;
  84645. FLAC__byte *b;
  84646. for(p = picture->mime_type; *p; p++) {
  84647. if(*p < 0x20 || *p > 0x7e) {
  84648. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84649. return false;
  84650. }
  84651. }
  84652. for(b = picture->description; *b; ) {
  84653. unsigned n = utf8len_(b);
  84654. if(n == 0) {
  84655. if(violation) *violation = "description string must be valid UTF-8";
  84656. return false;
  84657. }
  84658. b += n;
  84659. }
  84660. return true;
  84661. }
  84662. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84663. {
  84664. return
  84665. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84666. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84667. blocksize,
  84668. predictor_order
  84669. );
  84670. }
  84671. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84672. {
  84673. unsigned max_rice_partition_order = 0;
  84674. while(!(blocksize & 1)) {
  84675. max_rice_partition_order++;
  84676. blocksize >>= 1;
  84677. }
  84678. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84679. }
  84680. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84681. {
  84682. unsigned max_rice_partition_order = limit;
  84683. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  84684. max_rice_partition_order--;
  84685. FLAC__ASSERT(
  84686. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  84687. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  84688. );
  84689. return max_rice_partition_order;
  84690. }
  84691. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84692. {
  84693. FLAC__ASSERT(0 != object);
  84694. object->parameters = 0;
  84695. object->raw_bits = 0;
  84696. object->capacity_by_order = 0;
  84697. }
  84698. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84699. {
  84700. FLAC__ASSERT(0 != object);
  84701. if(0 != object->parameters)
  84702. free(object->parameters);
  84703. if(0 != object->raw_bits)
  84704. free(object->raw_bits);
  84705. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  84706. }
  84707. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  84708. {
  84709. FLAC__ASSERT(0 != object);
  84710. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  84711. if(object->capacity_by_order < max_partition_order) {
  84712. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  84713. return false;
  84714. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  84715. return false;
  84716. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  84717. object->capacity_by_order = max_partition_order;
  84718. }
  84719. return true;
  84720. }
  84721. #endif
  84722. /*** End of inlined file: format.c ***/
  84723. /*** Start of inlined file: lpc_flac.c ***/
  84724. /*** Start of inlined file: juce_FlacHeader.h ***/
  84725. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84726. // tasks..
  84727. #define VERSION "1.2.1"
  84728. #define FLAC__NO_DLL 1
  84729. #if JUCE_MSVC
  84730. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84731. #endif
  84732. #if JUCE_MAC
  84733. #define FLAC__SYS_DARWIN 1
  84734. #endif
  84735. /*** End of inlined file: juce_FlacHeader.h ***/
  84736. #if JUCE_USE_FLAC
  84737. #if HAVE_CONFIG_H
  84738. # include <config.h>
  84739. #endif
  84740. #include <math.h>
  84741. /*** Start of inlined file: lpc.h ***/
  84742. #ifndef FLAC__PRIVATE__LPC_H
  84743. #define FLAC__PRIVATE__LPC_H
  84744. #ifdef HAVE_CONFIG_H
  84745. #include <config.h>
  84746. #endif
  84747. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84748. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  84749. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84750. #ifndef FLAC__NO_ASM
  84751. # ifdef FLAC__CPU_IA32
  84752. # ifdef FLAC__HAS_NASM
  84753. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84754. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84755. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84756. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84757. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84758. # endif
  84759. # endif
  84760. #endif
  84761. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  84762. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  84763. void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  84764. void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  84765. #ifndef FLAC__NO_ASM
  84766. # ifdef FLAC__CPU_IA32
  84767. # ifdef FLAC__HAS_NASM
  84768. void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  84769. void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  84770. # endif
  84771. # endif
  84772. #endif
  84773. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84774. void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84775. void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84776. #ifndef FLAC__NO_ASM
  84777. # ifdef FLAC__CPU_IA32
  84778. # ifdef FLAC__HAS_NASM
  84779. void FLAC__lpc_restore_signal_asm_ia32(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84780. void FLAC__lpc_restore_signal_asm_ia32_mmx(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84781. # endif /* FLAC__HAS_NASM */
  84782. # elif defined FLAC__CPU_PPC
  84783. void FLAC__lpc_restore_signal_asm_ppc_altivec_16(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84784. void FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84785. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  84786. #endif /* FLAC__NO_ASM */
  84787. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84788. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  84789. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  84790. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  84791. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84792. #endif
  84793. /*** End of inlined file: lpc.h ***/
  84794. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  84795. #include <stdio.h>
  84796. #endif
  84797. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84798. #ifndef M_LN2
  84799. #define M_LN2 0.69314718055994530942
  84800. #endif
  84801. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  84802. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  84803. {
  84804. unsigned i;
  84805. for(i = 0; i < data_len; i++)
  84806. out[i] = in[i] * window[i];
  84807. }
  84808. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  84809. {
  84810. #if 0
  84811. FLAC__real d;
  84812. unsigned i;
  84813. FLAC__ASSERT(lag > 0);
  84814. FLAC__ASSERT(lag <= data_len);
  84815. while(lag--) {
  84816. for(i = lag, d = 0.0; i < data_len; i++)
  84817. d += data[i] * data[i - lag];
  84818. autoc[lag] = d;
  84819. }
  84820. #endif
  84821. FLAC__real d;
  84822. unsigned sample, coeff;
  84823. const unsigned limit = data_len - lag;
  84824. FLAC__ASSERT(lag > 0);
  84825. FLAC__ASSERT(lag <= data_len);
  84826. for(coeff = 0; coeff < lag; coeff++)
  84827. autoc[coeff] = 0.0;
  84828. for(sample = 0; sample <= limit; sample++) {
  84829. d = data[sample];
  84830. for(coeff = 0; coeff < lag; coeff++)
  84831. autoc[coeff] += d * data[sample+coeff];
  84832. }
  84833. for(; sample < data_len; sample++) {
  84834. d = data[sample];
  84835. for(coeff = 0; coeff < data_len - sample; coeff++)
  84836. autoc[coeff] += d * data[sample+coeff];
  84837. }
  84838. }
  84839. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  84840. {
  84841. unsigned i, j;
  84842. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  84843. FLAC__ASSERT(0 != max_order);
  84844. FLAC__ASSERT(0 < *max_order);
  84845. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  84846. FLAC__ASSERT(autoc[0] != 0.0);
  84847. err = autoc[0];
  84848. for(i = 0; i < *max_order; i++) {
  84849. r = -autoc[i+1];
  84850. for(j = 0; j < i; j++)
  84851. r -= lpc[j] * autoc[i-j];
  84852. ref[i] = (r/=err);
  84853. lpc[i]=r;
  84854. for(j = 0; j < (i>>1); j++) {
  84855. FLAC__double tmp = lpc[j];
  84856. lpc[j] += r * lpc[i-1-j];
  84857. lpc[i-1-j] += r * tmp;
  84858. }
  84859. if(i & 1)
  84860. lpc[j] += lpc[j] * r;
  84861. err *= (1.0 - r * r);
  84862. for(j = 0; j <= i; j++)
  84863. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  84864. error[i] = err;
  84865. if(err == 0.0) {
  84866. *max_order = i+1;
  84867. return;
  84868. }
  84869. }
  84870. }
  84871. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  84872. {
  84873. unsigned i;
  84874. FLAC__double cmax;
  84875. FLAC__int32 qmax, qmin;
  84876. FLAC__ASSERT(precision > 0);
  84877. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  84878. precision--;
  84879. qmax = 1 << precision;
  84880. qmin = -qmax;
  84881. qmax--;
  84882. cmax = 0.0;
  84883. for(i = 0; i < order; i++) {
  84884. const FLAC__double d = fabs(lp_coeff[i]);
  84885. if(d > cmax)
  84886. cmax = d;
  84887. }
  84888. if(cmax <= 0.0) {
  84889. return 2;
  84890. }
  84891. else {
  84892. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  84893. const int min_shiftlimit = -max_shiftlimit - 1;
  84894. int log2cmax;
  84895. (void)frexp(cmax, &log2cmax);
  84896. log2cmax--;
  84897. *shift = (int)precision - log2cmax - 1;
  84898. if(*shift > max_shiftlimit)
  84899. *shift = max_shiftlimit;
  84900. else if(*shift < min_shiftlimit)
  84901. return 1;
  84902. }
  84903. if(*shift >= 0) {
  84904. FLAC__double error = 0.0;
  84905. FLAC__int32 q;
  84906. for(i = 0; i < order; i++) {
  84907. error += lp_coeff[i] * (1 << *shift);
  84908. #if 1 /* unfortunately lround() is C99 */
  84909. if(error >= 0.0)
  84910. q = (FLAC__int32)(error + 0.5);
  84911. else
  84912. q = (FLAC__int32)(error - 0.5);
  84913. #else
  84914. q = lround(error);
  84915. #endif
  84916. #ifdef FLAC__OVERFLOW_DETECT
  84917. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  84918. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
  84919. else if(q < qmin)
  84920. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);
  84921. #endif
  84922. if(q > qmax)
  84923. q = qmax;
  84924. else if(q < qmin)
  84925. q = qmin;
  84926. error -= q;
  84927. qlp_coeff[i] = q;
  84928. }
  84929. }
  84930. else {
  84931. const int nshift = -(*shift);
  84932. FLAC__double error = 0.0;
  84933. FLAC__int32 q;
  84934. #ifdef DEBUG
  84935. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  84936. #endif
  84937. for(i = 0; i < order; i++) {
  84938. error += lp_coeff[i] / (1 << nshift);
  84939. #if 1 /* unfortunately lround() is C99 */
  84940. if(error >= 0.0)
  84941. q = (FLAC__int32)(error + 0.5);
  84942. else
  84943. q = (FLAC__int32)(error - 0.5);
  84944. #else
  84945. q = lround(error);
  84946. #endif
  84947. #ifdef FLAC__OVERFLOW_DETECT
  84948. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  84949. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
  84950. else if(q < qmin)
  84951. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);
  84952. #endif
  84953. if(q > qmax)
  84954. q = qmax;
  84955. else if(q < qmin)
  84956. q = qmin;
  84957. error -= q;
  84958. qlp_coeff[i] = q;
  84959. }
  84960. *shift = 0;
  84961. }
  84962. return 0;
  84963. }
  84964. void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
  84965. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  84966. {
  84967. FLAC__int64 sumo;
  84968. unsigned i, j;
  84969. FLAC__int32 sum;
  84970. const FLAC__int32 *history;
  84971. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  84972. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  84973. for(i=0;i<order;i++)
  84974. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  84975. fprintf(stderr,"\n");
  84976. #endif
  84977. FLAC__ASSERT(order > 0);
  84978. for(i = 0; i < data_len; i++) {
  84979. sumo = 0;
  84980. sum = 0;
  84981. history = data;
  84982. for(j = 0; j < order; j++) {
  84983. sum += qlp_coeff[j] * (*(--history));
  84984. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  84985. #if defined _MSC_VER
  84986. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  84987. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%I64d\n",i,j,qlp_coeff[j],*history,sumo);
  84988. #else
  84989. if(sumo > 2147483647ll || sumo < -2147483648ll)
  84990. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%lld\n",i,j,qlp_coeff[j],*history,(long long)sumo);
  84991. #endif
  84992. }
  84993. *(residual++) = *(data++) - (sum >> lp_quantization);
  84994. }
  84995. }
  84996. #else /* fully unrolled version for normal use */
  84997. {
  84998. int i;
  84999. FLAC__int32 sum;
  85000. FLAC__ASSERT(order > 0);
  85001. FLAC__ASSERT(order <= 32);
  85002. if(order <= 12) {
  85003. if(order > 8) {
  85004. if(order > 10) {
  85005. if(order == 12) {
  85006. for(i = 0; i < (int)data_len; i++) {
  85007. sum = 0;
  85008. sum += qlp_coeff[11] * data[i-12];
  85009. sum += qlp_coeff[10] * data[i-11];
  85010. sum += qlp_coeff[9] * data[i-10];
  85011. sum += qlp_coeff[8] * data[i-9];
  85012. sum += qlp_coeff[7] * data[i-8];
  85013. sum += qlp_coeff[6] * data[i-7];
  85014. sum += qlp_coeff[5] * data[i-6];
  85015. sum += qlp_coeff[4] * data[i-5];
  85016. sum += qlp_coeff[3] * data[i-4];
  85017. sum += qlp_coeff[2] * data[i-3];
  85018. sum += qlp_coeff[1] * data[i-2];
  85019. sum += qlp_coeff[0] * data[i-1];
  85020. residual[i] = data[i] - (sum >> lp_quantization);
  85021. }
  85022. }
  85023. else { /* order == 11 */
  85024. for(i = 0; i < (int)data_len; i++) {
  85025. sum = 0;
  85026. sum += qlp_coeff[10] * data[i-11];
  85027. sum += qlp_coeff[9] * data[i-10];
  85028. sum += qlp_coeff[8] * data[i-9];
  85029. sum += qlp_coeff[7] * data[i-8];
  85030. sum += qlp_coeff[6] * data[i-7];
  85031. sum += qlp_coeff[5] * data[i-6];
  85032. sum += qlp_coeff[4] * data[i-5];
  85033. sum += qlp_coeff[3] * data[i-4];
  85034. sum += qlp_coeff[2] * data[i-3];
  85035. sum += qlp_coeff[1] * data[i-2];
  85036. sum += qlp_coeff[0] * data[i-1];
  85037. residual[i] = data[i] - (sum >> lp_quantization);
  85038. }
  85039. }
  85040. }
  85041. else {
  85042. if(order == 10) {
  85043. for(i = 0; i < (int)data_len; i++) {
  85044. sum = 0;
  85045. sum += qlp_coeff[9] * data[i-10];
  85046. sum += qlp_coeff[8] * data[i-9];
  85047. sum += qlp_coeff[7] * data[i-8];
  85048. sum += qlp_coeff[6] * data[i-7];
  85049. sum += qlp_coeff[5] * data[i-6];
  85050. sum += qlp_coeff[4] * data[i-5];
  85051. sum += qlp_coeff[3] * data[i-4];
  85052. sum += qlp_coeff[2] * data[i-3];
  85053. sum += qlp_coeff[1] * data[i-2];
  85054. sum += qlp_coeff[0] * data[i-1];
  85055. residual[i] = data[i] - (sum >> lp_quantization);
  85056. }
  85057. }
  85058. else { /* order == 9 */
  85059. for(i = 0; i < (int)data_len; i++) {
  85060. sum = 0;
  85061. sum += qlp_coeff[8] * data[i-9];
  85062. sum += qlp_coeff[7] * data[i-8];
  85063. sum += qlp_coeff[6] * data[i-7];
  85064. sum += qlp_coeff[5] * data[i-6];
  85065. sum += qlp_coeff[4] * data[i-5];
  85066. sum += qlp_coeff[3] * data[i-4];
  85067. sum += qlp_coeff[2] * data[i-3];
  85068. sum += qlp_coeff[1] * data[i-2];
  85069. sum += qlp_coeff[0] * data[i-1];
  85070. residual[i] = data[i] - (sum >> lp_quantization);
  85071. }
  85072. }
  85073. }
  85074. }
  85075. else if(order > 4) {
  85076. if(order > 6) {
  85077. if(order == 8) {
  85078. for(i = 0; i < (int)data_len; i++) {
  85079. sum = 0;
  85080. sum += qlp_coeff[7] * data[i-8];
  85081. sum += qlp_coeff[6] * data[i-7];
  85082. sum += qlp_coeff[5] * data[i-6];
  85083. sum += qlp_coeff[4] * data[i-5];
  85084. sum += qlp_coeff[3] * data[i-4];
  85085. sum += qlp_coeff[2] * data[i-3];
  85086. sum += qlp_coeff[1] * data[i-2];
  85087. sum += qlp_coeff[0] * data[i-1];
  85088. residual[i] = data[i] - (sum >> lp_quantization);
  85089. }
  85090. }
  85091. else { /* order == 7 */
  85092. for(i = 0; i < (int)data_len; i++) {
  85093. sum = 0;
  85094. sum += qlp_coeff[6] * data[i-7];
  85095. sum += qlp_coeff[5] * data[i-6];
  85096. sum += qlp_coeff[4] * data[i-5];
  85097. sum += qlp_coeff[3] * data[i-4];
  85098. sum += qlp_coeff[2] * data[i-3];
  85099. sum += qlp_coeff[1] * data[i-2];
  85100. sum += qlp_coeff[0] * data[i-1];
  85101. residual[i] = data[i] - (sum >> lp_quantization);
  85102. }
  85103. }
  85104. }
  85105. else {
  85106. if(order == 6) {
  85107. for(i = 0; i < (int)data_len; i++) {
  85108. sum = 0;
  85109. sum += qlp_coeff[5] * data[i-6];
  85110. sum += qlp_coeff[4] * data[i-5];
  85111. sum += qlp_coeff[3] * data[i-4];
  85112. sum += qlp_coeff[2] * data[i-3];
  85113. sum += qlp_coeff[1] * data[i-2];
  85114. sum += qlp_coeff[0] * data[i-1];
  85115. residual[i] = data[i] - (sum >> lp_quantization);
  85116. }
  85117. }
  85118. else { /* order == 5 */
  85119. for(i = 0; i < (int)data_len; i++) {
  85120. sum = 0;
  85121. sum += qlp_coeff[4] * data[i-5];
  85122. sum += qlp_coeff[3] * data[i-4];
  85123. sum += qlp_coeff[2] * data[i-3];
  85124. sum += qlp_coeff[1] * data[i-2];
  85125. sum += qlp_coeff[0] * data[i-1];
  85126. residual[i] = data[i] - (sum >> lp_quantization);
  85127. }
  85128. }
  85129. }
  85130. }
  85131. else {
  85132. if(order > 2) {
  85133. if(order == 4) {
  85134. for(i = 0; i < (int)data_len; i++) {
  85135. sum = 0;
  85136. sum += qlp_coeff[3] * data[i-4];
  85137. sum += qlp_coeff[2] * data[i-3];
  85138. sum += qlp_coeff[1] * data[i-2];
  85139. sum += qlp_coeff[0] * data[i-1];
  85140. residual[i] = data[i] - (sum >> lp_quantization);
  85141. }
  85142. }
  85143. else { /* order == 3 */
  85144. for(i = 0; i < (int)data_len; i++) {
  85145. sum = 0;
  85146. sum += qlp_coeff[2] * data[i-3];
  85147. sum += qlp_coeff[1] * data[i-2];
  85148. sum += qlp_coeff[0] * data[i-1];
  85149. residual[i] = data[i] - (sum >> lp_quantization);
  85150. }
  85151. }
  85152. }
  85153. else {
  85154. if(order == 2) {
  85155. for(i = 0; i < (int)data_len; i++) {
  85156. sum = 0;
  85157. sum += qlp_coeff[1] * data[i-2];
  85158. sum += qlp_coeff[0] * data[i-1];
  85159. residual[i] = data[i] - (sum >> lp_quantization);
  85160. }
  85161. }
  85162. else { /* order == 1 */
  85163. for(i = 0; i < (int)data_len; i++)
  85164. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85165. }
  85166. }
  85167. }
  85168. }
  85169. else { /* order > 12 */
  85170. for(i = 0; i < (int)data_len; i++) {
  85171. sum = 0;
  85172. switch(order) {
  85173. case 32: sum += qlp_coeff[31] * data[i-32];
  85174. case 31: sum += qlp_coeff[30] * data[i-31];
  85175. case 30: sum += qlp_coeff[29] * data[i-30];
  85176. case 29: sum += qlp_coeff[28] * data[i-29];
  85177. case 28: sum += qlp_coeff[27] * data[i-28];
  85178. case 27: sum += qlp_coeff[26] * data[i-27];
  85179. case 26: sum += qlp_coeff[25] * data[i-26];
  85180. case 25: sum += qlp_coeff[24] * data[i-25];
  85181. case 24: sum += qlp_coeff[23] * data[i-24];
  85182. case 23: sum += qlp_coeff[22] * data[i-23];
  85183. case 22: sum += qlp_coeff[21] * data[i-22];
  85184. case 21: sum += qlp_coeff[20] * data[i-21];
  85185. case 20: sum += qlp_coeff[19] * data[i-20];
  85186. case 19: sum += qlp_coeff[18] * data[i-19];
  85187. case 18: sum += qlp_coeff[17] * data[i-18];
  85188. case 17: sum += qlp_coeff[16] * data[i-17];
  85189. case 16: sum += qlp_coeff[15] * data[i-16];
  85190. case 15: sum += qlp_coeff[14] * data[i-15];
  85191. case 14: sum += qlp_coeff[13] * data[i-14];
  85192. case 13: sum += qlp_coeff[12] * data[i-13];
  85193. sum += qlp_coeff[11] * data[i-12];
  85194. sum += qlp_coeff[10] * data[i-11];
  85195. sum += qlp_coeff[ 9] * data[i-10];
  85196. sum += qlp_coeff[ 8] * data[i- 9];
  85197. sum += qlp_coeff[ 7] * data[i- 8];
  85198. sum += qlp_coeff[ 6] * data[i- 7];
  85199. sum += qlp_coeff[ 5] * data[i- 6];
  85200. sum += qlp_coeff[ 4] * data[i- 5];
  85201. sum += qlp_coeff[ 3] * data[i- 4];
  85202. sum += qlp_coeff[ 2] * data[i- 3];
  85203. sum += qlp_coeff[ 1] * data[i- 2];
  85204. sum += qlp_coeff[ 0] * data[i- 1];
  85205. }
  85206. residual[i] = data[i] - (sum >> lp_quantization);
  85207. }
  85208. }
  85209. }
  85210. #endif
  85211. void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
  85212. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85213. {
  85214. unsigned i, j;
  85215. FLAC__int64 sum;
  85216. const FLAC__int32 *history;
  85217. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85218. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85219. for(i=0;i<order;i++)
  85220. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85221. fprintf(stderr,"\n");
  85222. #endif
  85223. FLAC__ASSERT(order > 0);
  85224. for(i = 0; i < data_len; i++) {
  85225. sum = 0;
  85226. history = data;
  85227. for(j = 0; j < order; j++)
  85228. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85229. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85230. #if defined _MSC_VER
  85231. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85232. #else
  85233. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85234. #endif
  85235. break;
  85236. }
  85237. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85238. #if defined _MSC_VER
  85239. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%I64d, residual=%I64d\n", i, *data, sum >> lp_quantization, (FLAC__int64)(*data) - (sum >> lp_quantization));
  85240. #else
  85241. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%lld, residual=%lld\n", i, *data, (long long)(sum >> lp_quantization), (long long)((FLAC__int64)(*data) - (sum >> lp_quantization)));
  85242. #endif
  85243. break;
  85244. }
  85245. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85246. }
  85247. }
  85248. #else /* fully unrolled version for normal use */
  85249. {
  85250. int i;
  85251. FLAC__int64 sum;
  85252. FLAC__ASSERT(order > 0);
  85253. FLAC__ASSERT(order <= 32);
  85254. if(order <= 12) {
  85255. if(order > 8) {
  85256. if(order > 10) {
  85257. if(order == 12) {
  85258. for(i = 0; i < (int)data_len; i++) {
  85259. sum = 0;
  85260. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85261. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85262. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85263. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85264. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85265. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85266. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85267. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85268. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85269. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85270. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85271. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85272. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85273. }
  85274. }
  85275. else { /* order == 11 */
  85276. for(i = 0; i < (int)data_len; i++) {
  85277. sum = 0;
  85278. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85279. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85280. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85281. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85282. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85283. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85284. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85285. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85286. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85287. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85288. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85289. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85290. }
  85291. }
  85292. }
  85293. else {
  85294. if(order == 10) {
  85295. for(i = 0; i < (int)data_len; i++) {
  85296. sum = 0;
  85297. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85298. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85299. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85300. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85301. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85302. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85303. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85304. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85305. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85306. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85307. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85308. }
  85309. }
  85310. else { /* order == 9 */
  85311. for(i = 0; i < (int)data_len; i++) {
  85312. sum = 0;
  85313. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85314. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85315. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85316. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85317. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85318. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85319. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85320. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85321. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85322. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85323. }
  85324. }
  85325. }
  85326. }
  85327. else if(order > 4) {
  85328. if(order > 6) {
  85329. if(order == 8) {
  85330. for(i = 0; i < (int)data_len; i++) {
  85331. sum = 0;
  85332. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85333. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85334. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85335. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85336. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85337. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85338. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85339. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85340. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85341. }
  85342. }
  85343. else { /* order == 7 */
  85344. for(i = 0; i < (int)data_len; i++) {
  85345. sum = 0;
  85346. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85347. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85348. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85349. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85350. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85351. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85352. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85353. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85354. }
  85355. }
  85356. }
  85357. else {
  85358. if(order == 6) {
  85359. for(i = 0; i < (int)data_len; i++) {
  85360. sum = 0;
  85361. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85362. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85363. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85364. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85365. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85366. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85367. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85368. }
  85369. }
  85370. else { /* order == 5 */
  85371. for(i = 0; i < (int)data_len; i++) {
  85372. sum = 0;
  85373. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85374. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85375. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85376. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85377. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85378. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85379. }
  85380. }
  85381. }
  85382. }
  85383. else {
  85384. if(order > 2) {
  85385. if(order == 4) {
  85386. for(i = 0; i < (int)data_len; i++) {
  85387. sum = 0;
  85388. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85389. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85390. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85391. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85392. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85393. }
  85394. }
  85395. else { /* order == 3 */
  85396. for(i = 0; i < (int)data_len; i++) {
  85397. sum = 0;
  85398. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85399. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85400. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85401. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85402. }
  85403. }
  85404. }
  85405. else {
  85406. if(order == 2) {
  85407. for(i = 0; i < (int)data_len; i++) {
  85408. sum = 0;
  85409. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85410. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85411. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85412. }
  85413. }
  85414. else { /* order == 1 */
  85415. for(i = 0; i < (int)data_len; i++)
  85416. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85417. }
  85418. }
  85419. }
  85420. }
  85421. else { /* order > 12 */
  85422. for(i = 0; i < (int)data_len; i++) {
  85423. sum = 0;
  85424. switch(order) {
  85425. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85426. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85427. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85428. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85429. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85430. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85431. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85432. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85433. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85434. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85435. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85436. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85437. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85438. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85439. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85440. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85441. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85442. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85443. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85444. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85445. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85446. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85447. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85448. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85449. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85450. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85451. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85452. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85453. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85454. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85455. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85456. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85457. }
  85458. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85459. }
  85460. }
  85461. }
  85462. #endif
  85463. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85464. void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
  85465. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85466. {
  85467. FLAC__int64 sumo;
  85468. unsigned i, j;
  85469. FLAC__int32 sum;
  85470. const FLAC__int32 *r = residual, *history;
  85471. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85472. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85473. for(i=0;i<order;i++)
  85474. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85475. fprintf(stderr,"\n");
  85476. #endif
  85477. FLAC__ASSERT(order > 0);
  85478. for(i = 0; i < data_len; i++) {
  85479. sumo = 0;
  85480. sum = 0;
  85481. history = data;
  85482. for(j = 0; j < order; j++) {
  85483. sum += qlp_coeff[j] * (*(--history));
  85484. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85485. #if defined _MSC_VER
  85486. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85487. fprintf(stderr,"FLAC__lpc_restore_signal: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%I64d\n",i,j,qlp_coeff[j],*history,sumo);
  85488. #else
  85489. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85490. fprintf(stderr,"FLAC__lpc_restore_signal: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%lld\n",i,j,qlp_coeff[j],*history,(long long)sumo);
  85491. #endif
  85492. }
  85493. *(data++) = *(r++) + (sum >> lp_quantization);
  85494. }
  85495. }
  85496. #else /* fully unrolled version for normal use */
  85497. {
  85498. int i;
  85499. FLAC__int32 sum;
  85500. FLAC__ASSERT(order > 0);
  85501. FLAC__ASSERT(order <= 32);
  85502. if(order <= 12) {
  85503. if(order > 8) {
  85504. if(order > 10) {
  85505. if(order == 12) {
  85506. for(i = 0; i < (int)data_len; i++) {
  85507. sum = 0;
  85508. sum += qlp_coeff[11] * data[i-12];
  85509. sum += qlp_coeff[10] * data[i-11];
  85510. sum += qlp_coeff[9] * data[i-10];
  85511. sum += qlp_coeff[8] * data[i-9];
  85512. sum += qlp_coeff[7] * data[i-8];
  85513. sum += qlp_coeff[6] * data[i-7];
  85514. sum += qlp_coeff[5] * data[i-6];
  85515. sum += qlp_coeff[4] * data[i-5];
  85516. sum += qlp_coeff[3] * data[i-4];
  85517. sum += qlp_coeff[2] * data[i-3];
  85518. sum += qlp_coeff[1] * data[i-2];
  85519. sum += qlp_coeff[0] * data[i-1];
  85520. data[i] = residual[i] + (sum >> lp_quantization);
  85521. }
  85522. }
  85523. else { /* order == 11 */
  85524. for(i = 0; i < (int)data_len; i++) {
  85525. sum = 0;
  85526. sum += qlp_coeff[10] * data[i-11];
  85527. sum += qlp_coeff[9] * data[i-10];
  85528. sum += qlp_coeff[8] * data[i-9];
  85529. sum += qlp_coeff[7] * data[i-8];
  85530. sum += qlp_coeff[6] * data[i-7];
  85531. sum += qlp_coeff[5] * data[i-6];
  85532. sum += qlp_coeff[4] * data[i-5];
  85533. sum += qlp_coeff[3] * data[i-4];
  85534. sum += qlp_coeff[2] * data[i-3];
  85535. sum += qlp_coeff[1] * data[i-2];
  85536. sum += qlp_coeff[0] * data[i-1];
  85537. data[i] = residual[i] + (sum >> lp_quantization);
  85538. }
  85539. }
  85540. }
  85541. else {
  85542. if(order == 10) {
  85543. for(i = 0; i < (int)data_len; i++) {
  85544. sum = 0;
  85545. sum += qlp_coeff[9] * data[i-10];
  85546. sum += qlp_coeff[8] * data[i-9];
  85547. sum += qlp_coeff[7] * data[i-8];
  85548. sum += qlp_coeff[6] * data[i-7];
  85549. sum += qlp_coeff[5] * data[i-6];
  85550. sum += qlp_coeff[4] * data[i-5];
  85551. sum += qlp_coeff[3] * data[i-4];
  85552. sum += qlp_coeff[2] * data[i-3];
  85553. sum += qlp_coeff[1] * data[i-2];
  85554. sum += qlp_coeff[0] * data[i-1];
  85555. data[i] = residual[i] + (sum >> lp_quantization);
  85556. }
  85557. }
  85558. else { /* order == 9 */
  85559. for(i = 0; i < (int)data_len; i++) {
  85560. sum = 0;
  85561. sum += qlp_coeff[8] * data[i-9];
  85562. sum += qlp_coeff[7] * data[i-8];
  85563. sum += qlp_coeff[6] * data[i-7];
  85564. sum += qlp_coeff[5] * data[i-6];
  85565. sum += qlp_coeff[4] * data[i-5];
  85566. sum += qlp_coeff[3] * data[i-4];
  85567. sum += qlp_coeff[2] * data[i-3];
  85568. sum += qlp_coeff[1] * data[i-2];
  85569. sum += qlp_coeff[0] * data[i-1];
  85570. data[i] = residual[i] + (sum >> lp_quantization);
  85571. }
  85572. }
  85573. }
  85574. }
  85575. else if(order > 4) {
  85576. if(order > 6) {
  85577. if(order == 8) {
  85578. for(i = 0; i < (int)data_len; i++) {
  85579. sum = 0;
  85580. sum += qlp_coeff[7] * data[i-8];
  85581. sum += qlp_coeff[6] * data[i-7];
  85582. sum += qlp_coeff[5] * data[i-6];
  85583. sum += qlp_coeff[4] * data[i-5];
  85584. sum += qlp_coeff[3] * data[i-4];
  85585. sum += qlp_coeff[2] * data[i-3];
  85586. sum += qlp_coeff[1] * data[i-2];
  85587. sum += qlp_coeff[0] * data[i-1];
  85588. data[i] = residual[i] + (sum >> lp_quantization);
  85589. }
  85590. }
  85591. else { /* order == 7 */
  85592. for(i = 0; i < (int)data_len; i++) {
  85593. sum = 0;
  85594. sum += qlp_coeff[6] * data[i-7];
  85595. sum += qlp_coeff[5] * data[i-6];
  85596. sum += qlp_coeff[4] * data[i-5];
  85597. sum += qlp_coeff[3] * data[i-4];
  85598. sum += qlp_coeff[2] * data[i-3];
  85599. sum += qlp_coeff[1] * data[i-2];
  85600. sum += qlp_coeff[0] * data[i-1];
  85601. data[i] = residual[i] + (sum >> lp_quantization);
  85602. }
  85603. }
  85604. }
  85605. else {
  85606. if(order == 6) {
  85607. for(i = 0; i < (int)data_len; i++) {
  85608. sum = 0;
  85609. sum += qlp_coeff[5] * data[i-6];
  85610. sum += qlp_coeff[4] * data[i-5];
  85611. sum += qlp_coeff[3] * data[i-4];
  85612. sum += qlp_coeff[2] * data[i-3];
  85613. sum += qlp_coeff[1] * data[i-2];
  85614. sum += qlp_coeff[0] * data[i-1];
  85615. data[i] = residual[i] + (sum >> lp_quantization);
  85616. }
  85617. }
  85618. else { /* order == 5 */
  85619. for(i = 0; i < (int)data_len; i++) {
  85620. sum = 0;
  85621. sum += qlp_coeff[4] * data[i-5];
  85622. sum += qlp_coeff[3] * data[i-4];
  85623. sum += qlp_coeff[2] * data[i-3];
  85624. sum += qlp_coeff[1] * data[i-2];
  85625. sum += qlp_coeff[0] * data[i-1];
  85626. data[i] = residual[i] + (sum >> lp_quantization);
  85627. }
  85628. }
  85629. }
  85630. }
  85631. else {
  85632. if(order > 2) {
  85633. if(order == 4) {
  85634. for(i = 0; i < (int)data_len; i++) {
  85635. sum = 0;
  85636. sum += qlp_coeff[3] * data[i-4];
  85637. sum += qlp_coeff[2] * data[i-3];
  85638. sum += qlp_coeff[1] * data[i-2];
  85639. sum += qlp_coeff[0] * data[i-1];
  85640. data[i] = residual[i] + (sum >> lp_quantization);
  85641. }
  85642. }
  85643. else { /* order == 3 */
  85644. for(i = 0; i < (int)data_len; i++) {
  85645. sum = 0;
  85646. sum += qlp_coeff[2] * data[i-3];
  85647. sum += qlp_coeff[1] * data[i-2];
  85648. sum += qlp_coeff[0] * data[i-1];
  85649. data[i] = residual[i] + (sum >> lp_quantization);
  85650. }
  85651. }
  85652. }
  85653. else {
  85654. if(order == 2) {
  85655. for(i = 0; i < (int)data_len; i++) {
  85656. sum = 0;
  85657. sum += qlp_coeff[1] * data[i-2];
  85658. sum += qlp_coeff[0] * data[i-1];
  85659. data[i] = residual[i] + (sum >> lp_quantization);
  85660. }
  85661. }
  85662. else { /* order == 1 */
  85663. for(i = 0; i < (int)data_len; i++)
  85664. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85665. }
  85666. }
  85667. }
  85668. }
  85669. else { /* order > 12 */
  85670. for(i = 0; i < (int)data_len; i++) {
  85671. sum = 0;
  85672. switch(order) {
  85673. case 32: sum += qlp_coeff[31] * data[i-32];
  85674. case 31: sum += qlp_coeff[30] * data[i-31];
  85675. case 30: sum += qlp_coeff[29] * data[i-30];
  85676. case 29: sum += qlp_coeff[28] * data[i-29];
  85677. case 28: sum += qlp_coeff[27] * data[i-28];
  85678. case 27: sum += qlp_coeff[26] * data[i-27];
  85679. case 26: sum += qlp_coeff[25] * data[i-26];
  85680. case 25: sum += qlp_coeff[24] * data[i-25];
  85681. case 24: sum += qlp_coeff[23] * data[i-24];
  85682. case 23: sum += qlp_coeff[22] * data[i-23];
  85683. case 22: sum += qlp_coeff[21] * data[i-22];
  85684. case 21: sum += qlp_coeff[20] * data[i-21];
  85685. case 20: sum += qlp_coeff[19] * data[i-20];
  85686. case 19: sum += qlp_coeff[18] * data[i-19];
  85687. case 18: sum += qlp_coeff[17] * data[i-18];
  85688. case 17: sum += qlp_coeff[16] * data[i-17];
  85689. case 16: sum += qlp_coeff[15] * data[i-16];
  85690. case 15: sum += qlp_coeff[14] * data[i-15];
  85691. case 14: sum += qlp_coeff[13] * data[i-14];
  85692. case 13: sum += qlp_coeff[12] * data[i-13];
  85693. sum += qlp_coeff[11] * data[i-12];
  85694. sum += qlp_coeff[10] * data[i-11];
  85695. sum += qlp_coeff[ 9] * data[i-10];
  85696. sum += qlp_coeff[ 8] * data[i- 9];
  85697. sum += qlp_coeff[ 7] * data[i- 8];
  85698. sum += qlp_coeff[ 6] * data[i- 7];
  85699. sum += qlp_coeff[ 5] * data[i- 6];
  85700. sum += qlp_coeff[ 4] * data[i- 5];
  85701. sum += qlp_coeff[ 3] * data[i- 4];
  85702. sum += qlp_coeff[ 2] * data[i- 3];
  85703. sum += qlp_coeff[ 1] * data[i- 2];
  85704. sum += qlp_coeff[ 0] * data[i- 1];
  85705. }
  85706. data[i] = residual[i] + (sum >> lp_quantization);
  85707. }
  85708. }
  85709. }
  85710. #endif
  85711. void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
  85712. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85713. {
  85714. unsigned i, j;
  85715. FLAC__int64 sum;
  85716. const FLAC__int32 *r = residual, *history;
  85717. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85718. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85719. for(i=0;i<order;i++)
  85720. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85721. fprintf(stderr,"\n");
  85722. #endif
  85723. FLAC__ASSERT(order > 0);
  85724. for(i = 0; i < data_len; i++) {
  85725. sum = 0;
  85726. history = data;
  85727. for(j = 0; j < order; j++)
  85728. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85729. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85730. #ifdef _MSC_VER
  85731. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85732. #else
  85733. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85734. #endif
  85735. break;
  85736. }
  85737. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  85738. #ifdef _MSC_VER
  85739. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%I64d, data=%I64d\n", i, *r, sum >> lp_quantization, (FLAC__int64)(*r) + (sum >> lp_quantization));
  85740. #else
  85741. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%lld, data=%lld\n", i, *r, (long long)(sum >> lp_quantization), (long long)((FLAC__int64)(*r) + (sum >> lp_quantization)));
  85742. #endif
  85743. break;
  85744. }
  85745. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  85746. }
  85747. }
  85748. #else /* fully unrolled version for normal use */
  85749. {
  85750. int i;
  85751. FLAC__int64 sum;
  85752. FLAC__ASSERT(order > 0);
  85753. FLAC__ASSERT(order <= 32);
  85754. if(order <= 12) {
  85755. if(order > 8) {
  85756. if(order > 10) {
  85757. if(order == 12) {
  85758. for(i = 0; i < (int)data_len; i++) {
  85759. sum = 0;
  85760. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85761. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85762. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85763. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85764. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85765. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85766. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85767. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85768. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85769. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85770. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85771. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85772. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85773. }
  85774. }
  85775. else { /* order == 11 */
  85776. for(i = 0; i < (int)data_len; i++) {
  85777. sum = 0;
  85778. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85779. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85780. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85781. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85782. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85783. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85784. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85785. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85786. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85787. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85788. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85789. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85790. }
  85791. }
  85792. }
  85793. else {
  85794. if(order == 10) {
  85795. for(i = 0; i < (int)data_len; i++) {
  85796. sum = 0;
  85797. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85798. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85799. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85800. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85801. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85802. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85803. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85804. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85805. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85806. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85807. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85808. }
  85809. }
  85810. else { /* order == 9 */
  85811. for(i = 0; i < (int)data_len; i++) {
  85812. sum = 0;
  85813. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85814. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85815. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85816. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85817. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85818. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85819. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85820. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85821. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85822. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85823. }
  85824. }
  85825. }
  85826. }
  85827. else if(order > 4) {
  85828. if(order > 6) {
  85829. if(order == 8) {
  85830. for(i = 0; i < (int)data_len; i++) {
  85831. sum = 0;
  85832. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85833. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85834. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85835. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85836. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85837. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85838. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85839. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85840. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85841. }
  85842. }
  85843. else { /* order == 7 */
  85844. for(i = 0; i < (int)data_len; i++) {
  85845. sum = 0;
  85846. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85847. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85848. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85849. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85850. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85851. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85852. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85853. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85854. }
  85855. }
  85856. }
  85857. else {
  85858. if(order == 6) {
  85859. for(i = 0; i < (int)data_len; i++) {
  85860. sum = 0;
  85861. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85862. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85863. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85864. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85865. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85866. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85867. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85868. }
  85869. }
  85870. else { /* order == 5 */
  85871. for(i = 0; i < (int)data_len; i++) {
  85872. sum = 0;
  85873. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85874. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85875. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85876. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85877. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85878. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85879. }
  85880. }
  85881. }
  85882. }
  85883. else {
  85884. if(order > 2) {
  85885. if(order == 4) {
  85886. for(i = 0; i < (int)data_len; i++) {
  85887. sum = 0;
  85888. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85889. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85890. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85891. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85892. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85893. }
  85894. }
  85895. else { /* order == 3 */
  85896. for(i = 0; i < (int)data_len; i++) {
  85897. sum = 0;
  85898. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85899. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85900. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85901. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85902. }
  85903. }
  85904. }
  85905. else {
  85906. if(order == 2) {
  85907. for(i = 0; i < (int)data_len; i++) {
  85908. sum = 0;
  85909. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85910. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85911. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85912. }
  85913. }
  85914. else { /* order == 1 */
  85915. for(i = 0; i < (int)data_len; i++)
  85916. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85917. }
  85918. }
  85919. }
  85920. }
  85921. else { /* order > 12 */
  85922. for(i = 0; i < (int)data_len; i++) {
  85923. sum = 0;
  85924. switch(order) {
  85925. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85926. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85927. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85928. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85929. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85930. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85931. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85932. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85933. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85934. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85935. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85936. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85937. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85938. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85939. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85940. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85941. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85942. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85943. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85944. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85945. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85946. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85947. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85948. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85949. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85950. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85951. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85952. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85953. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85954. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85955. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85956. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85957. }
  85958. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85959. }
  85960. }
  85961. }
  85962. #endif
  85963. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85964. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  85965. {
  85966. FLAC__double error_scale;
  85967. FLAC__ASSERT(total_samples > 0);
  85968. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  85969. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  85970. }
  85971. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  85972. {
  85973. if(lpc_error > 0.0) {
  85974. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  85975. if(bps >= 0.0)
  85976. return bps;
  85977. else
  85978. return 0.0;
  85979. }
  85980. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  85981. return 1e32;
  85982. }
  85983. else {
  85984. return 0.0;
  85985. }
  85986. }
  85987. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  85988. {
  85989. unsigned order, index, best_index; /* 'index' the index into lpc_error; index==order-1 since lpc_error[0] is for order==1, lpc_error[1] is for order==2, etc */
  85990. FLAC__double bits, best_bits, error_scale;
  85991. FLAC__ASSERT(max_order > 0);
  85992. FLAC__ASSERT(total_samples > 0);
  85993. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  85994. best_index = 0;
  85995. best_bits = (unsigned)(-1);
  85996. for(index = 0, order = 1; index < max_order; index++, order++) {
  85997. bits = FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error[index], error_scale) * (FLAC__double)(total_samples - order) + (FLAC__double)(order * overhead_bits_per_order);
  85998. if(bits < best_bits) {
  85999. best_index = index;
  86000. best_bits = bits;
  86001. }
  86002. }
  86003. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86004. }
  86005. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86006. #endif
  86007. /*** End of inlined file: lpc_flac.c ***/
  86008. /*** Start of inlined file: md5.c ***/
  86009. /*** Start of inlined file: juce_FlacHeader.h ***/
  86010. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86011. // tasks..
  86012. #define VERSION "1.2.1"
  86013. #define FLAC__NO_DLL 1
  86014. #if JUCE_MSVC
  86015. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86016. #endif
  86017. #if JUCE_MAC
  86018. #define FLAC__SYS_DARWIN 1
  86019. #endif
  86020. /*** End of inlined file: juce_FlacHeader.h ***/
  86021. #if JUCE_USE_FLAC
  86022. #if HAVE_CONFIG_H
  86023. # include <config.h>
  86024. #endif
  86025. #include <stdlib.h> /* for malloc() */
  86026. #include <string.h> /* for memcpy() */
  86027. /*** Start of inlined file: md5.h ***/
  86028. #ifndef FLAC__PRIVATE__MD5_H
  86029. #define FLAC__PRIVATE__MD5_H
  86030. typedef struct {
  86031. FLAC__uint32 in[16];
  86032. FLAC__uint32 buf[4];
  86033. FLAC__uint32 bytes[2];
  86034. FLAC__byte *internal_buf;
  86035. size_t capacity;
  86036. } FLAC__MD5Context;
  86037. void FLAC__MD5Init(FLAC__MD5Context *context);
  86038. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86039. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86040. #endif
  86041. /*** End of inlined file: md5.h ***/
  86042. #ifndef FLaC__INLINE
  86043. #define FLaC__INLINE
  86044. #endif
  86045. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86046. #define F2(x, y, z) F1(z, x, y)
  86047. #define F3(x, y, z) (x ^ y ^ z)
  86048. #define F4(x, y, z) (y ^ (x | ~z))
  86049. #define MD5STEP(f,w,x,y,z,in,s) \
  86050. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86051. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86052. {
  86053. register FLAC__uint32 a, b, c, d;
  86054. a = buf[0];
  86055. b = buf[1];
  86056. c = buf[2];
  86057. d = buf[3];
  86058. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86059. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86060. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86061. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86062. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86063. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86064. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86065. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86066. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86067. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86068. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86069. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86070. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86071. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86072. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86073. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86074. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86075. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86076. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86077. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86078. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86079. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86080. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86081. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86082. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86083. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86084. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86085. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86086. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86087. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86088. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86089. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86090. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86091. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86092. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86093. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86094. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86095. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86096. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86097. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86098. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86099. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86100. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86101. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86102. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86103. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86104. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86105. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86106. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86107. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86108. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86109. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86110. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86111. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86112. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86113. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86114. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86115. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86116. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86117. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86118. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86119. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86120. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86121. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86122. buf[0] += a;
  86123. buf[1] += b;
  86124. buf[2] += c;
  86125. buf[3] += d;
  86126. }
  86127. #if WORDS_BIGENDIAN
  86128. //@@@@@@ OPT: use bswap/intrinsics
  86129. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86130. {
  86131. register FLAC__uint32 x;
  86132. do {
  86133. x = *buf;
  86134. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86135. *buf++ = (x >> 16) | (x << 16);
  86136. } while (--words);
  86137. }
  86138. static void byteSwapX16(FLAC__uint32 *buf)
  86139. {
  86140. register FLAC__uint32 x;
  86141. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86142. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86143. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86144. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86145. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86146. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86147. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86148. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86149. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86150. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86151. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86152. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86153. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86154. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86155. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86156. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86157. }
  86158. #else
  86159. #define byteSwap(buf, words)
  86160. #define byteSwapX16(buf)
  86161. #endif
  86162. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86163. {
  86164. FLAC__uint32 t;
  86165. t = ctx->bytes[0];
  86166. if ((ctx->bytes[0] = t + len) < t)
  86167. ctx->bytes[1]++; /* Carry from low to high */
  86168. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86169. if (t > len) {
  86170. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86171. return;
  86172. }
  86173. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86174. byteSwapX16(ctx->in);
  86175. FLAC__MD5Transform(ctx->buf, ctx->in);
  86176. buf += t;
  86177. len -= t;
  86178. while (len >= 64) {
  86179. memcpy(ctx->in, buf, 64);
  86180. byteSwapX16(ctx->in);
  86181. FLAC__MD5Transform(ctx->buf, ctx->in);
  86182. buf += 64;
  86183. len -= 64;
  86184. }
  86185. memcpy(ctx->in, buf, len);
  86186. }
  86187. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86188. {
  86189. ctx->buf[0] = 0x67452301;
  86190. ctx->buf[1] = 0xefcdab89;
  86191. ctx->buf[2] = 0x98badcfe;
  86192. ctx->buf[3] = 0x10325476;
  86193. ctx->bytes[0] = 0;
  86194. ctx->bytes[1] = 0;
  86195. ctx->internal_buf = 0;
  86196. ctx->capacity = 0;
  86197. }
  86198. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86199. {
  86200. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86201. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86202. *p++ = 0x80;
  86203. count = 56 - 1 - count;
  86204. if (count < 0) { /* Padding forces an extra block */
  86205. memset(p, 0, count + 8);
  86206. byteSwapX16(ctx->in);
  86207. FLAC__MD5Transform(ctx->buf, ctx->in);
  86208. p = (FLAC__byte *)ctx->in;
  86209. count = 56;
  86210. }
  86211. memset(p, 0, count);
  86212. byteSwap(ctx->in, 14);
  86213. ctx->in[14] = ctx->bytes[0] << 3;
  86214. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86215. FLAC__MD5Transform(ctx->buf, ctx->in);
  86216. byteSwap(ctx->buf, 4);
  86217. memcpy(digest, ctx->buf, 16);
  86218. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86219. if(0 != ctx->internal_buf) {
  86220. free(ctx->internal_buf);
  86221. ctx->internal_buf = 0;
  86222. ctx->capacity = 0;
  86223. }
  86224. }
  86225. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86226. {
  86227. unsigned channel, sample;
  86228. register FLAC__int32 a_word;
  86229. register FLAC__byte *buf_ = buf;
  86230. #if WORDS_BIGENDIAN
  86231. #else
  86232. if(channels == 2 && bytes_per_sample == 2) {
  86233. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86234. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86235. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86236. *buf1_ = (FLAC__int16)signal[1][sample];
  86237. }
  86238. else if(channels == 1 && bytes_per_sample == 2) {
  86239. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86240. for(sample = 0; sample < samples; sample++)
  86241. *buf1_++ = (FLAC__int16)signal[0][sample];
  86242. }
  86243. else
  86244. #endif
  86245. if(bytes_per_sample == 2) {
  86246. if(channels == 2) {
  86247. for(sample = 0; sample < samples; sample++) {
  86248. a_word = signal[0][sample];
  86249. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86250. *buf_++ = (FLAC__byte)a_word;
  86251. a_word = signal[1][sample];
  86252. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86253. *buf_++ = (FLAC__byte)a_word;
  86254. }
  86255. }
  86256. else if(channels == 1) {
  86257. for(sample = 0; sample < samples; sample++) {
  86258. a_word = signal[0][sample];
  86259. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86260. *buf_++ = (FLAC__byte)a_word;
  86261. }
  86262. }
  86263. else {
  86264. for(sample = 0; sample < samples; sample++) {
  86265. for(channel = 0; channel < channels; channel++) {
  86266. a_word = signal[channel][sample];
  86267. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86268. *buf_++ = (FLAC__byte)a_word;
  86269. }
  86270. }
  86271. }
  86272. }
  86273. else if(bytes_per_sample == 3) {
  86274. if(channels == 2) {
  86275. for(sample = 0; sample < samples; sample++) {
  86276. a_word = signal[0][sample];
  86277. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86278. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86279. *buf_++ = (FLAC__byte)a_word;
  86280. a_word = signal[1][sample];
  86281. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86282. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86283. *buf_++ = (FLAC__byte)a_word;
  86284. }
  86285. }
  86286. else if(channels == 1) {
  86287. for(sample = 0; sample < samples; sample++) {
  86288. a_word = signal[0][sample];
  86289. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86290. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86291. *buf_++ = (FLAC__byte)a_word;
  86292. }
  86293. }
  86294. else {
  86295. for(sample = 0; sample < samples; sample++) {
  86296. for(channel = 0; channel < channels; channel++) {
  86297. a_word = signal[channel][sample];
  86298. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86299. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86300. *buf_++ = (FLAC__byte)a_word;
  86301. }
  86302. }
  86303. }
  86304. }
  86305. else if(bytes_per_sample == 1) {
  86306. if(channels == 2) {
  86307. for(sample = 0; sample < samples; sample++) {
  86308. a_word = signal[0][sample];
  86309. *buf_++ = (FLAC__byte)a_word;
  86310. a_word = signal[1][sample];
  86311. *buf_++ = (FLAC__byte)a_word;
  86312. }
  86313. }
  86314. else if(channels == 1) {
  86315. for(sample = 0; sample < samples; sample++) {
  86316. a_word = signal[0][sample];
  86317. *buf_++ = (FLAC__byte)a_word;
  86318. }
  86319. }
  86320. else {
  86321. for(sample = 0; sample < samples; sample++) {
  86322. for(channel = 0; channel < channels; channel++) {
  86323. a_word = signal[channel][sample];
  86324. *buf_++ = (FLAC__byte)a_word;
  86325. }
  86326. }
  86327. }
  86328. }
  86329. else { /* bytes_per_sample == 4, maybe optimize more later */
  86330. for(sample = 0; sample < samples; sample++) {
  86331. for(channel = 0; channel < channels; channel++) {
  86332. a_word = signal[channel][sample];
  86333. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86334. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86335. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86336. *buf_++ = (FLAC__byte)a_word;
  86337. }
  86338. }
  86339. }
  86340. }
  86341. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86342. {
  86343. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86344. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86345. return false;
  86346. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86347. return false;
  86348. if(ctx->capacity < bytes_needed) {
  86349. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86350. if(0 == tmp) {
  86351. free(ctx->internal_buf);
  86352. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86353. return false;
  86354. }
  86355. ctx->internal_buf = tmp;
  86356. ctx->capacity = bytes_needed;
  86357. }
  86358. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86359. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86360. return true;
  86361. }
  86362. #endif
  86363. /*** End of inlined file: md5.c ***/
  86364. /*** Start of inlined file: memory.c ***/
  86365. /*** Start of inlined file: juce_FlacHeader.h ***/
  86366. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86367. // tasks..
  86368. #define VERSION "1.2.1"
  86369. #define FLAC__NO_DLL 1
  86370. #if JUCE_MSVC
  86371. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86372. #endif
  86373. #if JUCE_MAC
  86374. #define FLAC__SYS_DARWIN 1
  86375. #endif
  86376. /*** End of inlined file: juce_FlacHeader.h ***/
  86377. #if JUCE_USE_FLAC
  86378. #if HAVE_CONFIG_H
  86379. # include <config.h>
  86380. #endif
  86381. /*** Start of inlined file: memory.h ***/
  86382. #ifndef FLAC__PRIVATE__MEMORY_H
  86383. #define FLAC__PRIVATE__MEMORY_H
  86384. #ifdef HAVE_CONFIG_H
  86385. #include <config.h>
  86386. #endif
  86387. #include <stdlib.h> /* for size_t */
  86388. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86389. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86390. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86391. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86392. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86393. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86394. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86395. #endif
  86396. #endif
  86397. /*** End of inlined file: memory.h ***/
  86398. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86399. {
  86400. void *x;
  86401. FLAC__ASSERT(0 != aligned_address);
  86402. #ifdef FLAC__ALIGN_MALLOC_DATA
  86403. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86404. #ifdef SIZEOF_VOIDP
  86405. #if SIZEOF_VOIDP == 4
  86406. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86407. #elif SIZEOF_VOIDP == 8
  86408. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86409. #else
  86410. # error Unsupported sizeof(void*)
  86411. #endif
  86412. #else
  86413. if(sizeof(void*) == sizeof(unsigned))
  86414. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86415. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86416. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86417. else
  86418. return 0;
  86419. #endif
  86420. #else
  86421. x = safe_malloc_(bytes);
  86422. *aligned_address = x;
  86423. #endif
  86424. return x;
  86425. }
  86426. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86427. {
  86428. FLAC__int32 *pu; /* unaligned pointer */
  86429. union { /* union needed to comply with C99 pointer aliasing rules */
  86430. FLAC__int32 *pa; /* aligned pointer */
  86431. void *pv; /* aligned pointer alias */
  86432. } u;
  86433. FLAC__ASSERT(elements > 0);
  86434. FLAC__ASSERT(0 != unaligned_pointer);
  86435. FLAC__ASSERT(0 != aligned_pointer);
  86436. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86437. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86438. if(0 == pu) {
  86439. return false;
  86440. }
  86441. else {
  86442. if(*unaligned_pointer != 0)
  86443. free(*unaligned_pointer);
  86444. *unaligned_pointer = pu;
  86445. *aligned_pointer = u.pa;
  86446. return true;
  86447. }
  86448. }
  86449. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86450. {
  86451. FLAC__uint32 *pu; /* unaligned pointer */
  86452. union { /* union needed to comply with C99 pointer aliasing rules */
  86453. FLAC__uint32 *pa; /* aligned pointer */
  86454. void *pv; /* aligned pointer alias */
  86455. } u;
  86456. FLAC__ASSERT(elements > 0);
  86457. FLAC__ASSERT(0 != unaligned_pointer);
  86458. FLAC__ASSERT(0 != aligned_pointer);
  86459. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86460. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86461. if(0 == pu) {
  86462. return false;
  86463. }
  86464. else {
  86465. if(*unaligned_pointer != 0)
  86466. free(*unaligned_pointer);
  86467. *unaligned_pointer = pu;
  86468. *aligned_pointer = u.pa;
  86469. return true;
  86470. }
  86471. }
  86472. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86473. {
  86474. FLAC__uint64 *pu; /* unaligned pointer */
  86475. union { /* union needed to comply with C99 pointer aliasing rules */
  86476. FLAC__uint64 *pa; /* aligned pointer */
  86477. void *pv; /* aligned pointer alias */
  86478. } u;
  86479. FLAC__ASSERT(elements > 0);
  86480. FLAC__ASSERT(0 != unaligned_pointer);
  86481. FLAC__ASSERT(0 != aligned_pointer);
  86482. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86483. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86484. if(0 == pu) {
  86485. return false;
  86486. }
  86487. else {
  86488. if(*unaligned_pointer != 0)
  86489. free(*unaligned_pointer);
  86490. *unaligned_pointer = pu;
  86491. *aligned_pointer = u.pa;
  86492. return true;
  86493. }
  86494. }
  86495. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86496. {
  86497. unsigned *pu; /* unaligned pointer */
  86498. union { /* union needed to comply with C99 pointer aliasing rules */
  86499. unsigned *pa; /* aligned pointer */
  86500. void *pv; /* aligned pointer alias */
  86501. } u;
  86502. FLAC__ASSERT(elements > 0);
  86503. FLAC__ASSERT(0 != unaligned_pointer);
  86504. FLAC__ASSERT(0 != aligned_pointer);
  86505. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86506. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86507. if(0 == pu) {
  86508. return false;
  86509. }
  86510. else {
  86511. if(*unaligned_pointer != 0)
  86512. free(*unaligned_pointer);
  86513. *unaligned_pointer = pu;
  86514. *aligned_pointer = u.pa;
  86515. return true;
  86516. }
  86517. }
  86518. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86519. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86520. {
  86521. FLAC__real *pu; /* unaligned pointer */
  86522. union { /* union needed to comply with C99 pointer aliasing rules */
  86523. FLAC__real *pa; /* aligned pointer */
  86524. void *pv; /* aligned pointer alias */
  86525. } u;
  86526. FLAC__ASSERT(elements > 0);
  86527. FLAC__ASSERT(0 != unaligned_pointer);
  86528. FLAC__ASSERT(0 != aligned_pointer);
  86529. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86530. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86531. if(0 == pu) {
  86532. return false;
  86533. }
  86534. else {
  86535. if(*unaligned_pointer != 0)
  86536. free(*unaligned_pointer);
  86537. *unaligned_pointer = pu;
  86538. *aligned_pointer = u.pa;
  86539. return true;
  86540. }
  86541. }
  86542. #endif
  86543. #endif
  86544. /*** End of inlined file: memory.c ***/
  86545. /*** Start of inlined file: stream_decoder.c ***/
  86546. /*** Start of inlined file: juce_FlacHeader.h ***/
  86547. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86548. // tasks..
  86549. #define VERSION "1.2.1"
  86550. #define FLAC__NO_DLL 1
  86551. #if JUCE_MSVC
  86552. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86553. #endif
  86554. #if JUCE_MAC
  86555. #define FLAC__SYS_DARWIN 1
  86556. #endif
  86557. /*** End of inlined file: juce_FlacHeader.h ***/
  86558. #if JUCE_USE_FLAC
  86559. #if HAVE_CONFIG_H
  86560. # include <config.h>
  86561. #endif
  86562. #if defined _MSC_VER || defined __MINGW32__
  86563. #include <io.h> /* for _setmode() */
  86564. #include <fcntl.h> /* for _O_BINARY */
  86565. #endif
  86566. #if defined __CYGWIN__ || defined __EMX__
  86567. #include <io.h> /* for setmode(), O_BINARY */
  86568. #include <fcntl.h> /* for _O_BINARY */
  86569. #endif
  86570. #include <stdio.h>
  86571. #include <stdlib.h> /* for malloc() */
  86572. #include <string.h> /* for memset/memcpy() */
  86573. #include <sys/stat.h> /* for stat() */
  86574. #include <sys/types.h> /* for off_t */
  86575. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86576. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86577. #define fseeko fseek
  86578. #define ftello ftell
  86579. #endif
  86580. #endif
  86581. /*** Start of inlined file: stream_decoder.h ***/
  86582. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86583. #define FLAC__PROTECTED__STREAM_DECODER_H
  86584. #if FLAC__HAS_OGG
  86585. #include "include/private/ogg_decoder_aspect.h"
  86586. #endif
  86587. typedef struct FLAC__StreamDecoderProtected {
  86588. FLAC__StreamDecoderState state;
  86589. unsigned channels;
  86590. FLAC__ChannelAssignment channel_assignment;
  86591. unsigned bits_per_sample;
  86592. unsigned sample_rate; /* in Hz */
  86593. unsigned blocksize; /* in samples (per channel) */
  86594. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86595. #if FLAC__HAS_OGG
  86596. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86597. #endif
  86598. } FLAC__StreamDecoderProtected;
  86599. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86600. #endif
  86601. /*** End of inlined file: stream_decoder.h ***/
  86602. #ifdef max
  86603. #undef max
  86604. #endif
  86605. #define max(a,b) ((a)>(b)?(a):(b))
  86606. #ifdef _MSC_VER
  86607. #define FLAC__U64L(x) x
  86608. #else
  86609. #define FLAC__U64L(x) x##LLU
  86610. #endif
  86611. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86612. #if FLAC__HAS_OGG
  86613. 1
  86614. #else
  86615. 0
  86616. #endif
  86617. ;
  86618. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86619. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86620. static FILE *get_binary_stdin_(void);
  86621. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86622. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86623. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86624. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86625. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86626. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86627. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86628. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86629. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86630. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86631. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86632. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86633. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86634. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86635. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86636. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86637. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86638. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86639. static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended);
  86640. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86641. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86642. #if FLAC__HAS_OGG
  86643. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86644. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86645. #endif
  86646. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86647. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86648. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86649. #if FLAC__HAS_OGG
  86650. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86651. #endif
  86652. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86653. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86654. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86655. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86656. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86657. typedef struct FLAC__StreamDecoderPrivate {
  86658. #if FLAC__HAS_OGG
  86659. FLAC__bool is_ogg;
  86660. #endif
  86661. FLAC__StreamDecoderReadCallback read_callback;
  86662. FLAC__StreamDecoderSeekCallback seek_callback;
  86663. FLAC__StreamDecoderTellCallback tell_callback;
  86664. FLAC__StreamDecoderLengthCallback length_callback;
  86665. FLAC__StreamDecoderEofCallback eof_callback;
  86666. FLAC__StreamDecoderWriteCallback write_callback;
  86667. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86668. FLAC__StreamDecoderErrorCallback error_callback;
  86669. void (*local_lpc_restore_signal)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  86670. void (*local_lpc_restore_signal_64bit)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  86671. void (*local_lpc_restore_signal_16bit)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  86672. void (*local_lpc_restore_signal_16bit_order8)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  86673. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86674. void *client_data;
  86675. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86676. FLAC__BitReader *input;
  86677. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86678. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86679. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86680. unsigned output_capacity, output_channels;
  86681. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  86682. FLAC__uint64 samples_decoded;
  86683. FLAC__bool has_stream_info, has_seek_table;
  86684. FLAC__StreamMetadata stream_info;
  86685. FLAC__StreamMetadata seek_table;
  86686. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  86687. FLAC__byte *metadata_filter_ids;
  86688. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  86689. FLAC__Frame frame;
  86690. FLAC__bool cached; /* true if there is a byte in lookahead */
  86691. FLAC__CPUInfo cpuinfo;
  86692. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  86693. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  86694. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  86695. FLAC__bool do_md5_checking; /* initially gets protected_->md5_checking but is turned off after a seek or if the metadata has a zero MD5 */
  86696. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  86697. FLAC__bool is_seeking;
  86698. FLAC__MD5Context md5context;
  86699. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  86700. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  86701. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  86702. FLAC__uint64 target_sample;
  86703. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  86704. #if FLAC__HAS_OGG
  86705. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  86706. #endif
  86707. } FLAC__StreamDecoderPrivate;
  86708. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  86709. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  86710. "FLAC__STREAM_DECODER_READ_METADATA",
  86711. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  86712. "FLAC__STREAM_DECODER_READ_FRAME",
  86713. "FLAC__STREAM_DECODER_END_OF_STREAM",
  86714. "FLAC__STREAM_DECODER_OGG_ERROR",
  86715. "FLAC__STREAM_DECODER_SEEK_ERROR",
  86716. "FLAC__STREAM_DECODER_ABORTED",
  86717. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  86718. "FLAC__STREAM_DECODER_UNINITIALIZED"
  86719. };
  86720. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  86721. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  86722. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  86723. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  86724. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  86725. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  86726. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  86727. };
  86728. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  86729. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  86730. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  86731. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  86732. };
  86733. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  86734. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  86735. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  86736. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  86737. };
  86738. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  86739. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  86740. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  86741. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  86742. };
  86743. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  86744. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  86745. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  86746. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  86747. };
  86748. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  86749. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  86750. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  86751. };
  86752. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  86753. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  86754. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  86755. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  86756. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  86757. };
  86758. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  86759. {
  86760. FLAC__StreamDecoder *decoder;
  86761. unsigned i;
  86762. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  86763. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  86764. if(decoder == 0) {
  86765. return 0;
  86766. }
  86767. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  86768. if(decoder->protected_ == 0) {
  86769. free(decoder);
  86770. return 0;
  86771. }
  86772. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  86773. if(decoder->private_ == 0) {
  86774. free(decoder->protected_);
  86775. free(decoder);
  86776. return 0;
  86777. }
  86778. decoder->private_->input = FLAC__bitreader_new();
  86779. if(decoder->private_->input == 0) {
  86780. free(decoder->private_);
  86781. free(decoder->protected_);
  86782. free(decoder);
  86783. return 0;
  86784. }
  86785. decoder->private_->metadata_filter_ids_capacity = 16;
  86786. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  86787. FLAC__bitreader_delete(decoder->private_->input);
  86788. free(decoder->private_);
  86789. free(decoder->protected_);
  86790. free(decoder);
  86791. return 0;
  86792. }
  86793. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  86794. decoder->private_->output[i] = 0;
  86795. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  86796. }
  86797. decoder->private_->output_capacity = 0;
  86798. decoder->private_->output_channels = 0;
  86799. decoder->private_->has_seek_table = false;
  86800. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  86801. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  86802. decoder->private_->file = 0;
  86803. set_defaults_dec(decoder);
  86804. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  86805. return decoder;
  86806. }
  86807. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  86808. {
  86809. unsigned i;
  86810. FLAC__ASSERT(0 != decoder);
  86811. FLAC__ASSERT(0 != decoder->protected_);
  86812. FLAC__ASSERT(0 != decoder->private_);
  86813. FLAC__ASSERT(0 != decoder->private_->input);
  86814. (void)FLAC__stream_decoder_finish(decoder);
  86815. if(0 != decoder->private_->metadata_filter_ids)
  86816. free(decoder->private_->metadata_filter_ids);
  86817. FLAC__bitreader_delete(decoder->private_->input);
  86818. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  86819. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  86820. free(decoder->private_);
  86821. free(decoder->protected_);
  86822. free(decoder);
  86823. }
  86824. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  86825. FLAC__StreamDecoder *decoder,
  86826. FLAC__StreamDecoderReadCallback read_callback,
  86827. FLAC__StreamDecoderSeekCallback seek_callback,
  86828. FLAC__StreamDecoderTellCallback tell_callback,
  86829. FLAC__StreamDecoderLengthCallback length_callback,
  86830. FLAC__StreamDecoderEofCallback eof_callback,
  86831. FLAC__StreamDecoderWriteCallback write_callback,
  86832. FLAC__StreamDecoderMetadataCallback metadata_callback,
  86833. FLAC__StreamDecoderErrorCallback error_callback,
  86834. void *client_data,
  86835. FLAC__bool is_ogg
  86836. )
  86837. {
  86838. FLAC__ASSERT(0 != decoder);
  86839. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  86840. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  86841. #if !FLAC__HAS_OGG
  86842. if(is_ogg)
  86843. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  86844. #endif
  86845. if(
  86846. 0 == read_callback ||
  86847. 0 == write_callback ||
  86848. 0 == error_callback ||
  86849. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  86850. )
  86851. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  86852. #if FLAC__HAS_OGG
  86853. decoder->private_->is_ogg = is_ogg;
  86854. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  86855. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  86856. #endif
  86857. FLAC__cpu_info(&decoder->private_->cpuinfo);
  86858. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  86859. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  86860. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  86861. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  86862. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  86863. #ifndef FLAC__NO_ASM
  86864. if(decoder->private_->cpuinfo.use_asm) {
  86865. #ifdef FLAC__CPU_IA32
  86866. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  86867. #ifdef FLAC__HAS_NASM
  86868. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  86869. if(decoder->private_->cpuinfo.data.ia32.bswap)
  86870. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  86871. #endif
  86872. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  86873. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  86874. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  86875. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  86876. }
  86877. else {
  86878. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  86879. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  86880. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  86881. }
  86882. #endif
  86883. #elif defined FLAC__CPU_PPC
  86884. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  86885. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  86886. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  86887. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  86888. }
  86889. #endif
  86890. }
  86891. #endif
  86892. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  86893. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  86894. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  86895. }
  86896. decoder->private_->read_callback = read_callback;
  86897. decoder->private_->seek_callback = seek_callback;
  86898. decoder->private_->tell_callback = tell_callback;
  86899. decoder->private_->length_callback = length_callback;
  86900. decoder->private_->eof_callback = eof_callback;
  86901. decoder->private_->write_callback = write_callback;
  86902. decoder->private_->metadata_callback = metadata_callback;
  86903. decoder->private_->error_callback = error_callback;
  86904. decoder->private_->client_data = client_data;
  86905. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  86906. decoder->private_->samples_decoded = 0;
  86907. decoder->private_->has_stream_info = false;
  86908. decoder->private_->cached = false;
  86909. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  86910. decoder->private_->is_seeking = false;
  86911. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  86912. if(!FLAC__stream_decoder_reset(decoder)) {
  86913. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  86914. }
  86915. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  86916. }
  86917. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  86918. FLAC__StreamDecoder *decoder,
  86919. FLAC__StreamDecoderReadCallback read_callback,
  86920. FLAC__StreamDecoderSeekCallback seek_callback,
  86921. FLAC__StreamDecoderTellCallback tell_callback,
  86922. FLAC__StreamDecoderLengthCallback length_callback,
  86923. FLAC__StreamDecoderEofCallback eof_callback,
  86924. FLAC__StreamDecoderWriteCallback write_callback,
  86925. FLAC__StreamDecoderMetadataCallback metadata_callback,
  86926. FLAC__StreamDecoderErrorCallback error_callback,
  86927. void *client_data
  86928. )
  86929. {
  86930. return init_stream_internal_dec(
  86931. decoder,
  86932. read_callback,
  86933. seek_callback,
  86934. tell_callback,
  86935. length_callback,
  86936. eof_callback,
  86937. write_callback,
  86938. metadata_callback,
  86939. error_callback,
  86940. client_data,
  86941. false
  86942. );
  86943. }
  86944. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  86945. FLAC__StreamDecoder *decoder,
  86946. FLAC__StreamDecoderReadCallback read_callback,
  86947. FLAC__StreamDecoderSeekCallback seek_callback,
  86948. FLAC__StreamDecoderTellCallback tell_callback,
  86949. FLAC__StreamDecoderLengthCallback length_callback,
  86950. FLAC__StreamDecoderEofCallback eof_callback,
  86951. FLAC__StreamDecoderWriteCallback write_callback,
  86952. FLAC__StreamDecoderMetadataCallback metadata_callback,
  86953. FLAC__StreamDecoderErrorCallback error_callback,
  86954. void *client_data
  86955. )
  86956. {
  86957. return init_stream_internal_dec(
  86958. decoder,
  86959. read_callback,
  86960. seek_callback,
  86961. tell_callback,
  86962. length_callback,
  86963. eof_callback,
  86964. write_callback,
  86965. metadata_callback,
  86966. error_callback,
  86967. client_data,
  86968. true
  86969. );
  86970. }
  86971. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  86972. FLAC__StreamDecoder *decoder,
  86973. FILE *file,
  86974. FLAC__StreamDecoderWriteCallback write_callback,
  86975. FLAC__StreamDecoderMetadataCallback metadata_callback,
  86976. FLAC__StreamDecoderErrorCallback error_callback,
  86977. void *client_data,
  86978. FLAC__bool is_ogg
  86979. )
  86980. {
  86981. FLAC__ASSERT(0 != decoder);
  86982. FLAC__ASSERT(0 != file);
  86983. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  86984. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  86985. if(0 == write_callback || 0 == error_callback)
  86986. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  86987. if(file == stdin)
  86988. file = get_binary_stdin_(); /* just to be safe */
  86989. decoder->private_->file = file;
  86990. return init_stream_internal_dec(
  86991. decoder,
  86992. file_read_callback_dec,
  86993. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  86994. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  86995. decoder->private_->file == stdin? 0: file_length_callback_,
  86996. file_eof_callback_,
  86997. write_callback,
  86998. metadata_callback,
  86999. error_callback,
  87000. client_data,
  87001. is_ogg
  87002. );
  87003. }
  87004. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87005. FLAC__StreamDecoder *decoder,
  87006. FILE *file,
  87007. FLAC__StreamDecoderWriteCallback write_callback,
  87008. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87009. FLAC__StreamDecoderErrorCallback error_callback,
  87010. void *client_data
  87011. )
  87012. {
  87013. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87014. }
  87015. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87016. FLAC__StreamDecoder *decoder,
  87017. FILE *file,
  87018. FLAC__StreamDecoderWriteCallback write_callback,
  87019. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87020. FLAC__StreamDecoderErrorCallback error_callback,
  87021. void *client_data
  87022. )
  87023. {
  87024. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87025. }
  87026. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87027. FLAC__StreamDecoder *decoder,
  87028. const char *filename,
  87029. FLAC__StreamDecoderWriteCallback write_callback,
  87030. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87031. FLAC__StreamDecoderErrorCallback error_callback,
  87032. void *client_data,
  87033. FLAC__bool is_ogg
  87034. )
  87035. {
  87036. FILE *file;
  87037. FLAC__ASSERT(0 != decoder);
  87038. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87039. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87040. if(0 == write_callback || 0 == error_callback)
  87041. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87042. file = filename? fopen(filename, "rb") : stdin;
  87043. if(0 == file)
  87044. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87045. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87046. }
  87047. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87048. FLAC__StreamDecoder *decoder,
  87049. const char *filename,
  87050. FLAC__StreamDecoderWriteCallback write_callback,
  87051. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87052. FLAC__StreamDecoderErrorCallback error_callback,
  87053. void *client_data
  87054. )
  87055. {
  87056. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87057. }
  87058. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87059. FLAC__StreamDecoder *decoder,
  87060. const char *filename,
  87061. FLAC__StreamDecoderWriteCallback write_callback,
  87062. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87063. FLAC__StreamDecoderErrorCallback error_callback,
  87064. void *client_data
  87065. )
  87066. {
  87067. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87068. }
  87069. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87070. {
  87071. FLAC__bool md5_failed = false;
  87072. unsigned i;
  87073. FLAC__ASSERT(0 != decoder);
  87074. FLAC__ASSERT(0 != decoder->private_);
  87075. FLAC__ASSERT(0 != decoder->protected_);
  87076. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87077. return true;
  87078. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87079. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87080. free(decoder->private_->seek_table.data.seek_table.points);
  87081. decoder->private_->seek_table.data.seek_table.points = 0;
  87082. decoder->private_->has_seek_table = false;
  87083. }
  87084. FLAC__bitreader_free(decoder->private_->input);
  87085. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87086. if(0 != decoder->private_->output[i]) {
  87087. free(decoder->private_->output[i]-4);
  87088. decoder->private_->output[i] = 0;
  87089. }
  87090. if(0 != decoder->private_->residual_unaligned[i]) {
  87091. free(decoder->private_->residual_unaligned[i]);
  87092. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87093. }
  87094. }
  87095. decoder->private_->output_capacity = 0;
  87096. decoder->private_->output_channels = 0;
  87097. #if FLAC__HAS_OGG
  87098. if(decoder->private_->is_ogg)
  87099. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87100. #endif
  87101. if(0 != decoder->private_->file) {
  87102. if(decoder->private_->file != stdin)
  87103. fclose(decoder->private_->file);
  87104. decoder->private_->file = 0;
  87105. }
  87106. if(decoder->private_->do_md5_checking) {
  87107. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87108. md5_failed = true;
  87109. }
  87110. decoder->private_->is_seeking = false;
  87111. set_defaults_dec(decoder);
  87112. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87113. return !md5_failed;
  87114. }
  87115. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87116. {
  87117. FLAC__ASSERT(0 != decoder);
  87118. FLAC__ASSERT(0 != decoder->private_);
  87119. FLAC__ASSERT(0 != decoder->protected_);
  87120. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87121. return false;
  87122. #if FLAC__HAS_OGG
  87123. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87124. return true;
  87125. #else
  87126. (void)value;
  87127. return false;
  87128. #endif
  87129. }
  87130. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87131. {
  87132. FLAC__ASSERT(0 != decoder);
  87133. FLAC__ASSERT(0 != decoder->protected_);
  87134. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87135. return false;
  87136. decoder->protected_->md5_checking = value;
  87137. return true;
  87138. }
  87139. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87140. {
  87141. FLAC__ASSERT(0 != decoder);
  87142. FLAC__ASSERT(0 != decoder->private_);
  87143. FLAC__ASSERT(0 != decoder->protected_);
  87144. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87145. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87146. return false;
  87147. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87148. return false;
  87149. decoder->private_->metadata_filter[type] = true;
  87150. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87151. decoder->private_->metadata_filter_ids_count = 0;
  87152. return true;
  87153. }
  87154. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87155. {
  87156. FLAC__ASSERT(0 != decoder);
  87157. FLAC__ASSERT(0 != decoder->private_);
  87158. FLAC__ASSERT(0 != decoder->protected_);
  87159. FLAC__ASSERT(0 != id);
  87160. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87161. return false;
  87162. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87163. return true;
  87164. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87165. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87166. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) {
  87167. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87168. return false;
  87169. }
  87170. decoder->private_->metadata_filter_ids_capacity *= 2;
  87171. }
  87172. memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metadata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8));
  87173. decoder->private_->metadata_filter_ids_count++;
  87174. return true;
  87175. }
  87176. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87177. {
  87178. unsigned i;
  87179. FLAC__ASSERT(0 != decoder);
  87180. FLAC__ASSERT(0 != decoder->private_);
  87181. FLAC__ASSERT(0 != decoder->protected_);
  87182. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87183. return false;
  87184. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87185. decoder->private_->metadata_filter[i] = true;
  87186. decoder->private_->metadata_filter_ids_count = 0;
  87187. return true;
  87188. }
  87189. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87190. {
  87191. FLAC__ASSERT(0 != decoder);
  87192. FLAC__ASSERT(0 != decoder->private_);
  87193. FLAC__ASSERT(0 != decoder->protected_);
  87194. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87195. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87196. return false;
  87197. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87198. return false;
  87199. decoder->private_->metadata_filter[type] = false;
  87200. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87201. decoder->private_->metadata_filter_ids_count = 0;
  87202. return true;
  87203. }
  87204. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87205. {
  87206. FLAC__ASSERT(0 != decoder);
  87207. FLAC__ASSERT(0 != decoder->private_);
  87208. FLAC__ASSERT(0 != decoder->protected_);
  87209. FLAC__ASSERT(0 != id);
  87210. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87211. return false;
  87212. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87213. return true;
  87214. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87215. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87216. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) {
  87217. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87218. return false;
  87219. }
  87220. decoder->private_->metadata_filter_ids_capacity *= 2;
  87221. }
  87222. memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metadata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8));
  87223. decoder->private_->metadata_filter_ids_count++;
  87224. return true;
  87225. }
  87226. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87227. {
  87228. FLAC__ASSERT(0 != decoder);
  87229. FLAC__ASSERT(0 != decoder->private_);
  87230. FLAC__ASSERT(0 != decoder->protected_);
  87231. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87232. return false;
  87233. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87234. decoder->private_->metadata_filter_ids_count = 0;
  87235. return true;
  87236. }
  87237. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87238. {
  87239. FLAC__ASSERT(0 != decoder);
  87240. FLAC__ASSERT(0 != decoder->protected_);
  87241. return decoder->protected_->state;
  87242. }
  87243. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87244. {
  87245. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87246. }
  87247. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87248. {
  87249. FLAC__ASSERT(0 != decoder);
  87250. FLAC__ASSERT(0 != decoder->protected_);
  87251. return decoder->protected_->md5_checking;
  87252. }
  87253. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87254. {
  87255. FLAC__ASSERT(0 != decoder);
  87256. FLAC__ASSERT(0 != decoder->protected_);
  87257. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87258. }
  87259. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87260. {
  87261. FLAC__ASSERT(0 != decoder);
  87262. FLAC__ASSERT(0 != decoder->protected_);
  87263. return decoder->protected_->channels;
  87264. }
  87265. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87266. {
  87267. FLAC__ASSERT(0 != decoder);
  87268. FLAC__ASSERT(0 != decoder->protected_);
  87269. return decoder->protected_->channel_assignment;
  87270. }
  87271. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87272. {
  87273. FLAC__ASSERT(0 != decoder);
  87274. FLAC__ASSERT(0 != decoder->protected_);
  87275. return decoder->protected_->bits_per_sample;
  87276. }
  87277. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87278. {
  87279. FLAC__ASSERT(0 != decoder);
  87280. FLAC__ASSERT(0 != decoder->protected_);
  87281. return decoder->protected_->sample_rate;
  87282. }
  87283. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87284. {
  87285. FLAC__ASSERT(0 != decoder);
  87286. FLAC__ASSERT(0 != decoder->protected_);
  87287. return decoder->protected_->blocksize;
  87288. }
  87289. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87290. {
  87291. FLAC__ASSERT(0 != decoder);
  87292. FLAC__ASSERT(0 != decoder->private_);
  87293. FLAC__ASSERT(0 != position);
  87294. #if FLAC__HAS_OGG
  87295. if(decoder->private_->is_ogg)
  87296. return false;
  87297. #endif
  87298. if(0 == decoder->private_->tell_callback)
  87299. return false;
  87300. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87301. return false;
  87302. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87303. return false;
  87304. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87305. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87306. return true;
  87307. }
  87308. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87309. {
  87310. FLAC__ASSERT(0 != decoder);
  87311. FLAC__ASSERT(0 != decoder->private_);
  87312. FLAC__ASSERT(0 != decoder->protected_);
  87313. decoder->private_->samples_decoded = 0;
  87314. decoder->private_->do_md5_checking = false;
  87315. #if FLAC__HAS_OGG
  87316. if(decoder->private_->is_ogg)
  87317. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87318. #endif
  87319. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87320. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87321. return false;
  87322. }
  87323. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87324. return true;
  87325. }
  87326. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87327. {
  87328. FLAC__ASSERT(0 != decoder);
  87329. FLAC__ASSERT(0 != decoder->private_);
  87330. FLAC__ASSERT(0 != decoder->protected_);
  87331. if(!FLAC__stream_decoder_flush(decoder)) {
  87332. return false;
  87333. }
  87334. #if FLAC__HAS_OGG
  87335. if(decoder->private_->is_ogg)
  87336. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87337. #endif
  87338. if(!decoder->private_->internal_reset_hack) {
  87339. if(decoder->private_->file == stdin)
  87340. return false; /* can't rewind stdin, reset fails */
  87341. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87342. return false; /* seekable and seek fails, reset fails */
  87343. }
  87344. else
  87345. decoder->private_->internal_reset_hack = false;
  87346. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87347. decoder->private_->has_stream_info = false;
  87348. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87349. free(decoder->private_->seek_table.data.seek_table.points);
  87350. decoder->private_->seek_table.data.seek_table.points = 0;
  87351. decoder->private_->has_seek_table = false;
  87352. }
  87353. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87354. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87355. FLAC__MD5Init(&decoder->private_->md5context);
  87356. decoder->private_->first_frame_offset = 0;
  87357. decoder->private_->unparseable_frame_count = 0;
  87358. return true;
  87359. }
  87360. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87361. {
  87362. FLAC__bool got_a_frame;
  87363. FLAC__ASSERT(0 != decoder);
  87364. FLAC__ASSERT(0 != decoder->protected_);
  87365. while(1) {
  87366. switch(decoder->protected_->state) {
  87367. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87368. if(!find_metadata_(decoder))
  87369. return false; /* above function sets the status for us */
  87370. break;
  87371. case FLAC__STREAM_DECODER_READ_METADATA:
  87372. if(!read_metadata_(decoder))
  87373. return false; /* above function sets the status for us */
  87374. else
  87375. return true;
  87376. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87377. if(!frame_sync_(decoder))
  87378. return true; /* above function sets the status for us */
  87379. break;
  87380. case FLAC__STREAM_DECODER_READ_FRAME:
  87381. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87382. return false; /* above function sets the status for us */
  87383. if(got_a_frame)
  87384. return true; /* above function sets the status for us */
  87385. break;
  87386. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87387. case FLAC__STREAM_DECODER_ABORTED:
  87388. return true;
  87389. default:
  87390. FLAC__ASSERT(0);
  87391. return false;
  87392. }
  87393. }
  87394. }
  87395. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87396. {
  87397. FLAC__ASSERT(0 != decoder);
  87398. FLAC__ASSERT(0 != decoder->protected_);
  87399. while(1) {
  87400. switch(decoder->protected_->state) {
  87401. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87402. if(!find_metadata_(decoder))
  87403. return false; /* above function sets the status for us */
  87404. break;
  87405. case FLAC__STREAM_DECODER_READ_METADATA:
  87406. if(!read_metadata_(decoder))
  87407. return false; /* above function sets the status for us */
  87408. break;
  87409. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87410. case FLAC__STREAM_DECODER_READ_FRAME:
  87411. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87412. case FLAC__STREAM_DECODER_ABORTED:
  87413. return true;
  87414. default:
  87415. FLAC__ASSERT(0);
  87416. return false;
  87417. }
  87418. }
  87419. }
  87420. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87421. {
  87422. FLAC__bool dummy;
  87423. FLAC__ASSERT(0 != decoder);
  87424. FLAC__ASSERT(0 != decoder->protected_);
  87425. while(1) {
  87426. switch(decoder->protected_->state) {
  87427. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87428. if(!find_metadata_(decoder))
  87429. return false; /* above function sets the status for us */
  87430. break;
  87431. case FLAC__STREAM_DECODER_READ_METADATA:
  87432. if(!read_metadata_(decoder))
  87433. return false; /* above function sets the status for us */
  87434. break;
  87435. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87436. if(!frame_sync_(decoder))
  87437. return true; /* above function sets the status for us */
  87438. break;
  87439. case FLAC__STREAM_DECODER_READ_FRAME:
  87440. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87441. return false; /* above function sets the status for us */
  87442. break;
  87443. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87444. case FLAC__STREAM_DECODER_ABORTED:
  87445. return true;
  87446. default:
  87447. FLAC__ASSERT(0);
  87448. return false;
  87449. }
  87450. }
  87451. }
  87452. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87453. {
  87454. FLAC__bool got_a_frame;
  87455. FLAC__ASSERT(0 != decoder);
  87456. FLAC__ASSERT(0 != decoder->protected_);
  87457. while(1) {
  87458. switch(decoder->protected_->state) {
  87459. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87460. case FLAC__STREAM_DECODER_READ_METADATA:
  87461. return false; /* above function sets the status for us */
  87462. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87463. if(!frame_sync_(decoder))
  87464. return true; /* above function sets the status for us */
  87465. break;
  87466. case FLAC__STREAM_DECODER_READ_FRAME:
  87467. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87468. return false; /* above function sets the status for us */
  87469. if(got_a_frame)
  87470. return true; /* above function sets the status for us */
  87471. break;
  87472. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87473. case FLAC__STREAM_DECODER_ABORTED:
  87474. return true;
  87475. default:
  87476. FLAC__ASSERT(0);
  87477. return false;
  87478. }
  87479. }
  87480. }
  87481. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87482. {
  87483. FLAC__uint64 length;
  87484. FLAC__ASSERT(0 != decoder);
  87485. if(
  87486. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87487. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87488. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87489. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87490. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87491. )
  87492. return false;
  87493. if(0 == decoder->private_->seek_callback)
  87494. return false;
  87495. FLAC__ASSERT(decoder->private_->seek_callback);
  87496. FLAC__ASSERT(decoder->private_->tell_callback);
  87497. FLAC__ASSERT(decoder->private_->length_callback);
  87498. FLAC__ASSERT(decoder->private_->eof_callback);
  87499. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87500. return false;
  87501. decoder->private_->is_seeking = true;
  87502. decoder->private_->do_md5_checking = false;
  87503. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87504. decoder->private_->is_seeking = false;
  87505. return false;
  87506. }
  87507. if(
  87508. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87509. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87510. ) {
  87511. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87512. decoder->private_->is_seeking = false;
  87513. return false;
  87514. }
  87515. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87516. decoder->private_->is_seeking = false;
  87517. return false;
  87518. }
  87519. }
  87520. {
  87521. const FLAC__bool ok =
  87522. #if FLAC__HAS_OGG
  87523. decoder->private_->is_ogg?
  87524. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87525. #endif
  87526. seek_to_absolute_sample_(decoder, length, sample)
  87527. ;
  87528. decoder->private_->is_seeking = false;
  87529. return ok;
  87530. }
  87531. }
  87532. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87533. {
  87534. FLAC__ASSERT(0 != decoder);
  87535. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87536. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87537. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87538. }
  87539. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87540. {
  87541. #if FLAC__HAS_OGG
  87542. decoder->private_->is_ogg = false;
  87543. #endif
  87544. decoder->private_->read_callback = 0;
  87545. decoder->private_->seek_callback = 0;
  87546. decoder->private_->tell_callback = 0;
  87547. decoder->private_->length_callback = 0;
  87548. decoder->private_->eof_callback = 0;
  87549. decoder->private_->write_callback = 0;
  87550. decoder->private_->metadata_callback = 0;
  87551. decoder->private_->error_callback = 0;
  87552. decoder->private_->client_data = 0;
  87553. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87554. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87555. decoder->private_->metadata_filter_ids_count = 0;
  87556. decoder->protected_->md5_checking = false;
  87557. #if FLAC__HAS_OGG
  87558. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87559. #endif
  87560. }
  87561. FILE *get_binary_stdin_(void)
  87562. {
  87563. #if defined _MSC_VER || defined __MINGW32__
  87564. _setmode(_fileno(stdin), _O_BINARY);
  87565. #elif defined __CYGWIN__
  87566. setmode(_fileno(stdin), _O_BINARY);
  87567. #elif defined __EMX__
  87568. setmode(fileno(stdin), O_BINARY);
  87569. #endif
  87570. return stdin;
  87571. }
  87572. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87573. {
  87574. unsigned i;
  87575. FLAC__int32 *tmp;
  87576. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87577. return true;
  87578. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87579. if(0 != decoder->private_->output[i]) {
  87580. free(decoder->private_->output[i]-4);
  87581. decoder->private_->output[i] = 0;
  87582. }
  87583. if(0 != decoder->private_->residual_unaligned[i]) {
  87584. free(decoder->private_->residual_unaligned[i]);
  87585. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87586. }
  87587. }
  87588. for(i = 0; i < channels; i++) {
  87589. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87590. if(tmp == 0) {
  87591. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87592. return false;
  87593. }
  87594. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87595. decoder->private_->output[i] = tmp + 4;
  87596. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87597. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87598. return false;
  87599. }
  87600. }
  87601. decoder->private_->output_capacity = size;
  87602. decoder->private_->output_channels = channels;
  87603. return true;
  87604. }
  87605. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87606. {
  87607. size_t i;
  87608. FLAC__ASSERT(0 != decoder);
  87609. FLAC__ASSERT(0 != decoder->private_);
  87610. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87611. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87612. return true;
  87613. return false;
  87614. }
  87615. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87616. {
  87617. FLAC__uint32 x;
  87618. unsigned i, id_;
  87619. FLAC__bool first = true;
  87620. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87621. for(i = id_ = 0; i < 4; ) {
  87622. if(decoder->private_->cached) {
  87623. x = (FLAC__uint32)decoder->private_->lookahead;
  87624. decoder->private_->cached = false;
  87625. }
  87626. else {
  87627. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87628. return false; /* read_callback_ sets the state for us */
  87629. }
  87630. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87631. first = true;
  87632. i++;
  87633. id_ = 0;
  87634. continue;
  87635. }
  87636. if(x == ID3V2_TAG_[id_]) {
  87637. id_++;
  87638. i = 0;
  87639. if(id_ == 3) {
  87640. if(!skip_id3v2_tag_(decoder))
  87641. return false; /* skip_id3v2_tag_ sets the state for us */
  87642. }
  87643. continue;
  87644. }
  87645. id_ = 0;
  87646. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87647. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87648. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87649. return false; /* read_callback_ sets the state for us */
  87650. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87651. decoder->private_->lookahead = (FLAC__byte)x;
  87652. decoder->private_->cached = true;
  87653. }
  87654. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87655. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87656. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87657. return true;
  87658. }
  87659. }
  87660. i = 0;
  87661. if(first) {
  87662. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87663. first = false;
  87664. }
  87665. }
  87666. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87667. return true;
  87668. }
  87669. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87670. {
  87671. FLAC__bool is_last;
  87672. FLAC__uint32 i, x, type, length;
  87673. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87674. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87675. return false; /* read_callback_ sets the state for us */
  87676. is_last = x? true : false;
  87677. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87678. return false; /* read_callback_ sets the state for us */
  87679. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87680. return false; /* read_callback_ sets the state for us */
  87681. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  87682. if(!read_metadata_streaminfo_(decoder, is_last, length))
  87683. return false;
  87684. decoder->private_->has_stream_info = true;
  87685. if(0 == memcmp(decoder->private_->stream_info.data.stream_info.md5sum, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16))
  87686. decoder->private_->do_md5_checking = false;
  87687. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  87688. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  87689. }
  87690. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  87691. if(!read_metadata_seektable_(decoder, is_last, length))
  87692. return false;
  87693. decoder->private_->has_seek_table = true;
  87694. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  87695. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  87696. }
  87697. else {
  87698. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  87699. unsigned real_length = length;
  87700. FLAC__StreamMetadata block;
  87701. block.is_last = is_last;
  87702. block.type = (FLAC__MetadataType)type;
  87703. block.length = length;
  87704. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  87705. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  87706. return false; /* read_callback_ sets the state for us */
  87707. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  87708. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  87709. return false;
  87710. }
  87711. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  87712. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  87713. skip_it = !skip_it;
  87714. }
  87715. if(skip_it) {
  87716. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87717. return false; /* read_callback_ sets the state for us */
  87718. }
  87719. else {
  87720. switch(type) {
  87721. case FLAC__METADATA_TYPE_PADDING:
  87722. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87723. return false; /* read_callback_ sets the state for us */
  87724. break;
  87725. case FLAC__METADATA_TYPE_APPLICATION:
  87726. if(real_length > 0) {
  87727. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  87728. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87729. return false;
  87730. }
  87731. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  87732. return false; /* read_callback_ sets the state for us */
  87733. }
  87734. else
  87735. block.data.application.data = 0;
  87736. break;
  87737. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87738. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  87739. return false;
  87740. break;
  87741. case FLAC__METADATA_TYPE_CUESHEET:
  87742. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  87743. return false;
  87744. break;
  87745. case FLAC__METADATA_TYPE_PICTURE:
  87746. if(!read_metadata_picture_(decoder, &block.data.picture))
  87747. return false;
  87748. break;
  87749. case FLAC__METADATA_TYPE_STREAMINFO:
  87750. case FLAC__METADATA_TYPE_SEEKTABLE:
  87751. FLAC__ASSERT(0);
  87752. break;
  87753. default:
  87754. if(real_length > 0) {
  87755. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  87756. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87757. return false;
  87758. }
  87759. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  87760. return false; /* read_callback_ sets the state for us */
  87761. }
  87762. else
  87763. block.data.unknown.data = 0;
  87764. break;
  87765. }
  87766. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  87767. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  87768. switch(type) {
  87769. case FLAC__METADATA_TYPE_PADDING:
  87770. break;
  87771. case FLAC__METADATA_TYPE_APPLICATION:
  87772. if(0 != block.data.application.data)
  87773. free(block.data.application.data);
  87774. break;
  87775. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87776. if(0 != block.data.vorbis_comment.vendor_string.entry)
  87777. free(block.data.vorbis_comment.vendor_string.entry);
  87778. if(block.data.vorbis_comment.num_comments > 0)
  87779. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  87780. if(0 != block.data.vorbis_comment.comments[i].entry)
  87781. free(block.data.vorbis_comment.comments[i].entry);
  87782. if(0 != block.data.vorbis_comment.comments)
  87783. free(block.data.vorbis_comment.comments);
  87784. break;
  87785. case FLAC__METADATA_TYPE_CUESHEET:
  87786. if(block.data.cue_sheet.num_tracks > 0)
  87787. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  87788. if(0 != block.data.cue_sheet.tracks[i].indices)
  87789. free(block.data.cue_sheet.tracks[i].indices);
  87790. if(0 != block.data.cue_sheet.tracks)
  87791. free(block.data.cue_sheet.tracks);
  87792. break;
  87793. case FLAC__METADATA_TYPE_PICTURE:
  87794. if(0 != block.data.picture.mime_type)
  87795. free(block.data.picture.mime_type);
  87796. if(0 != block.data.picture.description)
  87797. free(block.data.picture.description);
  87798. if(0 != block.data.picture.data)
  87799. free(block.data.picture.data);
  87800. break;
  87801. case FLAC__METADATA_TYPE_STREAMINFO:
  87802. case FLAC__METADATA_TYPE_SEEKTABLE:
  87803. FLAC__ASSERT(0);
  87804. default:
  87805. if(0 != block.data.unknown.data)
  87806. free(block.data.unknown.data);
  87807. break;
  87808. }
  87809. }
  87810. }
  87811. if(is_last) {
  87812. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  87813. decoder->private_->first_frame_offset = 0;
  87814. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87815. }
  87816. return true;
  87817. }
  87818. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  87819. {
  87820. FLAC__uint32 x;
  87821. unsigned bits, used_bits = 0;
  87822. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87823. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  87824. decoder->private_->stream_info.is_last = is_last;
  87825. decoder->private_->stream_info.length = length;
  87826. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  87827. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  87828. return false; /* read_callback_ sets the state for us */
  87829. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  87830. used_bits += bits;
  87831. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  87832. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  87833. return false; /* read_callback_ sets the state for us */
  87834. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  87835. used_bits += bits;
  87836. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  87837. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  87838. return false; /* read_callback_ sets the state for us */
  87839. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  87840. used_bits += bits;
  87841. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  87842. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  87843. return false; /* read_callback_ sets the state for us */
  87844. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  87845. used_bits += bits;
  87846. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  87847. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  87848. return false; /* read_callback_ sets the state for us */
  87849. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  87850. used_bits += bits;
  87851. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  87852. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  87853. return false; /* read_callback_ sets the state for us */
  87854. decoder->private_->stream_info.data.stream_info.channels = x+1;
  87855. used_bits += bits;
  87856. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  87857. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  87858. return false; /* read_callback_ sets the state for us */
  87859. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  87860. used_bits += bits;
  87861. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  87862. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &decoder->private_->stream_info.data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  87863. return false; /* read_callback_ sets the state for us */
  87864. used_bits += bits;
  87865. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  87866. return false; /* read_callback_ sets the state for us */
  87867. used_bits += 16*8;
  87868. FLAC__ASSERT(used_bits % 8 == 0);
  87869. length -= (used_bits / 8);
  87870. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  87871. return false; /* read_callback_ sets the state for us */
  87872. return true;
  87873. }
  87874. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  87875. {
  87876. FLAC__uint32 i, x;
  87877. FLAC__uint64 xx;
  87878. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87879. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  87880. decoder->private_->seek_table.is_last = is_last;
  87881. decoder->private_->seek_table.length = length;
  87882. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  87883. if(0 == (decoder->private_->seek_table.data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*)safe_realloc_mul_2op_(decoder->private_->seek_table.data.seek_table.points, decoder->private_->seek_table.data.seek_table.num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)))) {
  87884. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87885. return false;
  87886. }
  87887. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  87888. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  87889. return false; /* read_callback_ sets the state for us */
  87890. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  87891. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  87892. return false; /* read_callback_ sets the state for us */
  87893. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  87894. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  87895. return false; /* read_callback_ sets the state for us */
  87896. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  87897. }
  87898. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  87899. if(length > 0) {
  87900. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  87901. return false; /* read_callback_ sets the state for us */
  87902. }
  87903. return true;
  87904. }
  87905. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  87906. {
  87907. FLAC__uint32 i;
  87908. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87909. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  87910. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  87911. return false; /* read_callback_ sets the state for us */
  87912. if(obj->vendor_string.length > 0) {
  87913. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  87914. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87915. return false;
  87916. }
  87917. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  87918. return false; /* read_callback_ sets the state for us */
  87919. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  87920. }
  87921. else
  87922. obj->vendor_string.entry = 0;
  87923. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  87924. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  87925. return false; /* read_callback_ sets the state for us */
  87926. if(obj->num_comments > 0) {
  87927. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  87928. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87929. return false;
  87930. }
  87931. for(i = 0; i < obj->num_comments; i++) {
  87932. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  87933. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  87934. return false; /* read_callback_ sets the state for us */
  87935. if(obj->comments[i].length > 0) {
  87936. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  87937. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87938. return false;
  87939. }
  87940. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  87941. return false; /* read_callback_ sets the state for us */
  87942. obj->comments[i].entry[obj->comments[i].length] = '\0';
  87943. }
  87944. else
  87945. obj->comments[i].entry = 0;
  87946. }
  87947. }
  87948. else {
  87949. obj->comments = 0;
  87950. }
  87951. return true;
  87952. }
  87953. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  87954. {
  87955. FLAC__uint32 i, j, x;
  87956. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87957. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  87958. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  87959. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8))
  87960. return false; /* read_callback_ sets the state for us */
  87961. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  87962. return false; /* read_callback_ sets the state for us */
  87963. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  87964. return false; /* read_callback_ sets the state for us */
  87965. obj->is_cd = x? true : false;
  87966. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  87967. return false; /* read_callback_ sets the state for us */
  87968. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  87969. return false; /* read_callback_ sets the state for us */
  87970. obj->num_tracks = x;
  87971. if(obj->num_tracks > 0) {
  87972. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  87973. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87974. return false;
  87975. }
  87976. for(i = 0; i < obj->num_tracks; i++) {
  87977. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  87978. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  87979. return false; /* read_callback_ sets the state for us */
  87980. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  87981. return false; /* read_callback_ sets the state for us */
  87982. track->number = (FLAC__byte)x;
  87983. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  87984. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  87985. return false; /* read_callback_ sets the state for us */
  87986. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  87987. return false; /* read_callback_ sets the state for us */
  87988. track->type = x;
  87989. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  87990. return false; /* read_callback_ sets the state for us */
  87991. track->pre_emphasis = x;
  87992. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  87993. return false; /* read_callback_ sets the state for us */
  87994. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  87995. return false; /* read_callback_ sets the state for us */
  87996. track->num_indices = (FLAC__byte)x;
  87997. if(track->num_indices > 0) {
  87998. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  87999. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88000. return false;
  88001. }
  88002. for(j = 0; j < track->num_indices; j++) {
  88003. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88004. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88005. return false; /* read_callback_ sets the state for us */
  88006. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88007. return false; /* read_callback_ sets the state for us */
  88008. index->number = (FLAC__byte)x;
  88009. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88010. return false; /* read_callback_ sets the state for us */
  88011. }
  88012. }
  88013. }
  88014. }
  88015. return true;
  88016. }
  88017. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88018. {
  88019. FLAC__uint32 x;
  88020. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88021. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88022. return false; /* read_callback_ sets the state for us */
  88023. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88024. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88025. return false; /* read_callback_ sets the state for us */
  88026. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88027. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88028. return false;
  88029. }
  88030. if(x > 0) {
  88031. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88032. return false; /* read_callback_ sets the state for us */
  88033. }
  88034. obj->mime_type[x] = '\0';
  88035. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88036. return false; /* read_callback_ sets the state for us */
  88037. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88038. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88039. return false;
  88040. }
  88041. if(x > 0) {
  88042. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88043. return false; /* read_callback_ sets the state for us */
  88044. }
  88045. obj->description[x] = '\0';
  88046. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88047. return false; /* read_callback_ sets the state for us */
  88048. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88049. return false; /* read_callback_ sets the state for us */
  88050. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88051. return false; /* read_callback_ sets the state for us */
  88052. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88053. return false; /* read_callback_ sets the state for us */
  88054. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88055. return false; /* read_callback_ sets the state for us */
  88056. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88057. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88058. return false;
  88059. }
  88060. if(obj->data_length > 0) {
  88061. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88062. return false; /* read_callback_ sets the state for us */
  88063. }
  88064. return true;
  88065. }
  88066. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88067. {
  88068. FLAC__uint32 x;
  88069. unsigned i, skip;
  88070. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88071. return false; /* read_callback_ sets the state for us */
  88072. skip = 0;
  88073. for(i = 0; i < 4; i++) {
  88074. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88075. return false; /* read_callback_ sets the state for us */
  88076. skip <<= 7;
  88077. skip |= (x & 0x7f);
  88078. }
  88079. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88080. return false; /* read_callback_ sets the state for us */
  88081. return true;
  88082. }
  88083. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88084. {
  88085. FLAC__uint32 x;
  88086. FLAC__bool first = true;
  88087. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88088. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88089. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88090. return true;
  88091. }
  88092. }
  88093. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88094. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88095. return false; /* read_callback_ sets the state for us */
  88096. }
  88097. while(1) {
  88098. if(decoder->private_->cached) {
  88099. x = (FLAC__uint32)decoder->private_->lookahead;
  88100. decoder->private_->cached = false;
  88101. }
  88102. else {
  88103. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88104. return false; /* read_callback_ sets the state for us */
  88105. }
  88106. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88107. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88108. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88109. return false; /* read_callback_ sets the state for us */
  88110. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88111. decoder->private_->lookahead = (FLAC__byte)x;
  88112. decoder->private_->cached = true;
  88113. }
  88114. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88115. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88116. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88117. return true;
  88118. }
  88119. }
  88120. if(first) {
  88121. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88122. first = false;
  88123. }
  88124. }
  88125. return true;
  88126. }
  88127. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88128. {
  88129. unsigned channel;
  88130. unsigned i;
  88131. FLAC__int32 mid, side;
  88132. unsigned frame_crc; /* the one we calculate from the input stream */
  88133. FLAC__uint32 x;
  88134. *got_a_frame = false;
  88135. frame_crc = 0;
  88136. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88137. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88138. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88139. if(!read_frame_header_(decoder))
  88140. return false;
  88141. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88142. return true;
  88143. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88144. return false;
  88145. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88146. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88147. switch(decoder->private_->frame.header.channel_assignment) {
  88148. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88149. break;
  88150. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88151. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88152. if(channel == 1)
  88153. bps++;
  88154. break;
  88155. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88156. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88157. if(channel == 0)
  88158. bps++;
  88159. break;
  88160. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88161. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88162. if(channel == 1)
  88163. bps++;
  88164. break;
  88165. default:
  88166. FLAC__ASSERT(0);
  88167. }
  88168. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88169. return false;
  88170. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88171. return true;
  88172. }
  88173. if(!read_zero_padding_(decoder))
  88174. return false;
  88175. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption (i.e. "zero bits" were not all zeroes) */
  88176. return true;
  88177. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88178. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88179. return false; /* read_callback_ sets the state for us */
  88180. if(frame_crc == x) {
  88181. if(do_full_decode) {
  88182. switch(decoder->private_->frame.header.channel_assignment) {
  88183. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88184. break;
  88185. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88186. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88187. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88188. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88189. break;
  88190. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88191. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88192. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88193. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88194. break;
  88195. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88196. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88197. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88198. #if 1
  88199. mid = decoder->private_->output[0][i];
  88200. side = decoder->private_->output[1][i];
  88201. mid <<= 1;
  88202. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88203. decoder->private_->output[0][i] = (mid + side) >> 1;
  88204. decoder->private_->output[1][i] = (mid - side) >> 1;
  88205. #else
  88206. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88207. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88208. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88209. #endif
  88210. }
  88211. break;
  88212. default:
  88213. FLAC__ASSERT(0);
  88214. break;
  88215. }
  88216. }
  88217. }
  88218. else {
  88219. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88220. if(do_full_decode) {
  88221. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88222. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88223. }
  88224. }
  88225. }
  88226. *got_a_frame = true;
  88227. if(decoder->private_->next_fixed_block_size)
  88228. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88229. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88230. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88231. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88232. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88233. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88234. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88235. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88236. if(do_full_decode) {
  88237. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88238. return false;
  88239. }
  88240. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88241. return true;
  88242. }
  88243. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88244. {
  88245. FLAC__uint32 x;
  88246. FLAC__uint64 xx;
  88247. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88248. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88249. unsigned raw_header_len;
  88250. FLAC__bool is_unparseable = false;
  88251. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88252. raw_header[0] = decoder->private_->header_warmup[0];
  88253. raw_header[1] = decoder->private_->header_warmup[1];
  88254. raw_header_len = 2;
  88255. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88256. is_unparseable = true;
  88257. for(i = 0; i < 2; i++) {
  88258. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88259. return false; /* read_callback_ sets the state for us */
  88260. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88261. decoder->private_->lookahead = (FLAC__byte)x;
  88262. decoder->private_->cached = true;
  88263. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88264. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88265. return true;
  88266. }
  88267. raw_header[raw_header_len++] = (FLAC__byte)x;
  88268. }
  88269. switch(x = raw_header[2] >> 4) {
  88270. case 0:
  88271. is_unparseable = true;
  88272. break;
  88273. case 1:
  88274. decoder->private_->frame.header.blocksize = 192;
  88275. break;
  88276. case 2:
  88277. case 3:
  88278. case 4:
  88279. case 5:
  88280. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88281. break;
  88282. case 6:
  88283. case 7:
  88284. blocksize_hint = x;
  88285. break;
  88286. case 8:
  88287. case 9:
  88288. case 10:
  88289. case 11:
  88290. case 12:
  88291. case 13:
  88292. case 14:
  88293. case 15:
  88294. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88295. break;
  88296. default:
  88297. FLAC__ASSERT(0);
  88298. break;
  88299. }
  88300. switch(x = raw_header[2] & 0x0f) {
  88301. case 0:
  88302. if(decoder->private_->has_stream_info)
  88303. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88304. else
  88305. is_unparseable = true;
  88306. break;
  88307. case 1:
  88308. decoder->private_->frame.header.sample_rate = 88200;
  88309. break;
  88310. case 2:
  88311. decoder->private_->frame.header.sample_rate = 176400;
  88312. break;
  88313. case 3:
  88314. decoder->private_->frame.header.sample_rate = 192000;
  88315. break;
  88316. case 4:
  88317. decoder->private_->frame.header.sample_rate = 8000;
  88318. break;
  88319. case 5:
  88320. decoder->private_->frame.header.sample_rate = 16000;
  88321. break;
  88322. case 6:
  88323. decoder->private_->frame.header.sample_rate = 22050;
  88324. break;
  88325. case 7:
  88326. decoder->private_->frame.header.sample_rate = 24000;
  88327. break;
  88328. case 8:
  88329. decoder->private_->frame.header.sample_rate = 32000;
  88330. break;
  88331. case 9:
  88332. decoder->private_->frame.header.sample_rate = 44100;
  88333. break;
  88334. case 10:
  88335. decoder->private_->frame.header.sample_rate = 48000;
  88336. break;
  88337. case 11:
  88338. decoder->private_->frame.header.sample_rate = 96000;
  88339. break;
  88340. case 12:
  88341. case 13:
  88342. case 14:
  88343. sample_rate_hint = x;
  88344. break;
  88345. case 15:
  88346. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88347. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88348. return true;
  88349. default:
  88350. FLAC__ASSERT(0);
  88351. }
  88352. x = (unsigned)(raw_header[3] >> 4);
  88353. if(x & 8) {
  88354. decoder->private_->frame.header.channels = 2;
  88355. switch(x & 7) {
  88356. case 0:
  88357. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88358. break;
  88359. case 1:
  88360. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88361. break;
  88362. case 2:
  88363. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88364. break;
  88365. default:
  88366. is_unparseable = true;
  88367. break;
  88368. }
  88369. }
  88370. else {
  88371. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88372. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88373. }
  88374. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88375. case 0:
  88376. if(decoder->private_->has_stream_info)
  88377. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88378. else
  88379. is_unparseable = true;
  88380. break;
  88381. case 1:
  88382. decoder->private_->frame.header.bits_per_sample = 8;
  88383. break;
  88384. case 2:
  88385. decoder->private_->frame.header.bits_per_sample = 12;
  88386. break;
  88387. case 4:
  88388. decoder->private_->frame.header.bits_per_sample = 16;
  88389. break;
  88390. case 5:
  88391. decoder->private_->frame.header.bits_per_sample = 20;
  88392. break;
  88393. case 6:
  88394. decoder->private_->frame.header.bits_per_sample = 24;
  88395. break;
  88396. case 3:
  88397. case 7:
  88398. is_unparseable = true;
  88399. break;
  88400. default:
  88401. FLAC__ASSERT(0);
  88402. break;
  88403. }
  88404. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88405. is_unparseable = true;
  88406. if(
  88407. raw_header[1] & 0x01 ||
  88408. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88409. ) { /* variable blocksize */
  88410. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88411. return false; /* read_callback_ sets the state for us */
  88412. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88413. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88414. decoder->private_->cached = true;
  88415. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88416. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88417. return true;
  88418. }
  88419. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88420. decoder->private_->frame.header.number.sample_number = xx;
  88421. }
  88422. else { /* fixed blocksize */
  88423. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88424. return false; /* read_callback_ sets the state for us */
  88425. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88426. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88427. decoder->private_->cached = true;
  88428. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88429. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88430. return true;
  88431. }
  88432. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88433. decoder->private_->frame.header.number.frame_number = x;
  88434. }
  88435. if(blocksize_hint) {
  88436. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88437. return false; /* read_callback_ sets the state for us */
  88438. raw_header[raw_header_len++] = (FLAC__byte)x;
  88439. if(blocksize_hint == 7) {
  88440. FLAC__uint32 _x;
  88441. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88442. return false; /* read_callback_ sets the state for us */
  88443. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88444. x = (x << 8) | _x;
  88445. }
  88446. decoder->private_->frame.header.blocksize = x+1;
  88447. }
  88448. if(sample_rate_hint) {
  88449. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88450. return false; /* read_callback_ sets the state for us */
  88451. raw_header[raw_header_len++] = (FLAC__byte)x;
  88452. if(sample_rate_hint != 12) {
  88453. FLAC__uint32 _x;
  88454. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88455. return false; /* read_callback_ sets the state for us */
  88456. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88457. x = (x << 8) | _x;
  88458. }
  88459. if(sample_rate_hint == 12)
  88460. decoder->private_->frame.header.sample_rate = x*1000;
  88461. else if(sample_rate_hint == 13)
  88462. decoder->private_->frame.header.sample_rate = x;
  88463. else
  88464. decoder->private_->frame.header.sample_rate = x*10;
  88465. }
  88466. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88467. return false; /* read_callback_ sets the state for us */
  88468. crc8 = (FLAC__byte)x;
  88469. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88470. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88471. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88472. return true;
  88473. }
  88474. decoder->private_->next_fixed_block_size = 0;
  88475. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88476. x = decoder->private_->frame.header.number.frame_number;
  88477. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88478. if(decoder->private_->fixed_block_size)
  88479. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88480. else if(decoder->private_->has_stream_info) {
  88481. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88482. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88483. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88484. }
  88485. else
  88486. is_unparseable = true;
  88487. }
  88488. else if(x == 0) {
  88489. decoder->private_->frame.header.number.sample_number = 0;
  88490. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88491. }
  88492. else {
  88493. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88494. }
  88495. }
  88496. if(is_unparseable) {
  88497. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88498. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88499. return true;
  88500. }
  88501. return true;
  88502. }
  88503. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88504. {
  88505. FLAC__uint32 x;
  88506. FLAC__bool wasted_bits;
  88507. unsigned i;
  88508. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88509. return false; /* read_callback_ sets the state for us */
  88510. wasted_bits = (x & 1);
  88511. x &= 0xfe;
  88512. if(wasted_bits) {
  88513. unsigned u;
  88514. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88515. return false; /* read_callback_ sets the state for us */
  88516. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88517. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88518. }
  88519. else
  88520. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88521. if(x & 0x80) {
  88522. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88523. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88524. return true;
  88525. }
  88526. else if(x == 0) {
  88527. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88528. return false;
  88529. }
  88530. else if(x == 2) {
  88531. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88532. return false;
  88533. }
  88534. else if(x < 16) {
  88535. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88536. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88537. return true;
  88538. }
  88539. else if(x <= 24) {
  88540. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88541. return false;
  88542. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88543. return true;
  88544. }
  88545. else if(x < 64) {
  88546. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88547. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88548. return true;
  88549. }
  88550. else {
  88551. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88552. return false;
  88553. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88554. return true;
  88555. }
  88556. if(wasted_bits && do_full_decode) {
  88557. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88558. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88559. decoder->private_->output[channel][i] <<= x;
  88560. }
  88561. return true;
  88562. }
  88563. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88564. {
  88565. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88566. FLAC__int32 x;
  88567. unsigned i;
  88568. FLAC__int32 *output = decoder->private_->output[channel];
  88569. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88570. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88571. return false; /* read_callback_ sets the state for us */
  88572. subframe->value = x;
  88573. if(do_full_decode) {
  88574. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88575. output[i] = x;
  88576. }
  88577. return true;
  88578. }
  88579. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88580. {
  88581. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88582. FLAC__int32 i32;
  88583. FLAC__uint32 u32;
  88584. unsigned u;
  88585. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88586. subframe->residual = decoder->private_->residual[channel];
  88587. subframe->order = order;
  88588. for(u = 0; u < order; u++) {
  88589. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88590. return false; /* read_callback_ sets the state for us */
  88591. subframe->warmup[u] = i32;
  88592. }
  88593. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88594. return false; /* read_callback_ sets the state for us */
  88595. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88596. switch(subframe->entropy_coding_method.type) {
  88597. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88598. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88599. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88600. return false; /* read_callback_ sets the state for us */
  88601. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88602. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88603. break;
  88604. default:
  88605. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88606. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88607. return true;
  88608. }
  88609. switch(subframe->entropy_coding_method.type) {
  88610. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88611. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88612. if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2))
  88613. return false;
  88614. break;
  88615. default:
  88616. FLAC__ASSERT(0);
  88617. }
  88618. if(do_full_decode) {
  88619. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88620. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88621. }
  88622. return true;
  88623. }
  88624. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88625. {
  88626. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88627. FLAC__int32 i32;
  88628. FLAC__uint32 u32;
  88629. unsigned u;
  88630. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88631. subframe->residual = decoder->private_->residual[channel];
  88632. subframe->order = order;
  88633. for(u = 0; u < order; u++) {
  88634. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88635. return false; /* read_callback_ sets the state for us */
  88636. subframe->warmup[u] = i32;
  88637. }
  88638. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88639. return false; /* read_callback_ sets the state for us */
  88640. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88641. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88642. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88643. return true;
  88644. }
  88645. subframe->qlp_coeff_precision = u32+1;
  88646. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88647. return false; /* read_callback_ sets the state for us */
  88648. subframe->quantization_level = i32;
  88649. for(u = 0; u < order; u++) {
  88650. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88651. return false; /* read_callback_ sets the state for us */
  88652. subframe->qlp_coeff[u] = i32;
  88653. }
  88654. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88655. return false; /* read_callback_ sets the state for us */
  88656. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88657. switch(subframe->entropy_coding_method.type) {
  88658. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88659. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88660. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88661. return false; /* read_callback_ sets the state for us */
  88662. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88663. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88664. break;
  88665. default:
  88666. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88667. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88668. return true;
  88669. }
  88670. switch(subframe->entropy_coding_method.type) {
  88671. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88672. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88673. if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2))
  88674. return false;
  88675. break;
  88676. default:
  88677. FLAC__ASSERT(0);
  88678. }
  88679. if(do_full_decode) {
  88680. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88681. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  88682. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  88683. if(order <= 8)
  88684. decoder->private_->local_lpc_restore_signal_16bit_order8(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  88685. else
  88686. decoder->private_->local_lpc_restore_signal_16bit(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  88687. }
  88688. else
  88689. decoder->private_->local_lpc_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  88690. else
  88691. decoder->private_->local_lpc_restore_signal_64bit(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  88692. }
  88693. return true;
  88694. }
  88695. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88696. {
  88697. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  88698. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  88699. unsigned i;
  88700. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  88701. subframe->data = residual;
  88702. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88703. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88704. return false; /* read_callback_ sets the state for us */
  88705. residual[i] = x;
  88706. }
  88707. if(do_full_decode)
  88708. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88709. return true;
  88710. }
  88711. FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended)
  88712. {
  88713. FLAC__uint32 rice_parameter;
  88714. int i;
  88715. unsigned partition, sample, u;
  88716. const unsigned partitions = 1u << partition_order;
  88717. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  88718. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  88719. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  88720. if(partition_order == 0) {
  88721. if(decoder->private_->frame.header.blocksize < predictor_order) {
  88722. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88723. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88724. return true;
  88725. }
  88726. }
  88727. else {
  88728. if(partition_samples < predictor_order) {
  88729. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88730. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88731. return true;
  88732. }
  88733. }
  88734. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  88735. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88736. return false;
  88737. }
  88738. sample = 0;
  88739. for(partition = 0; partition < partitions; partition++) {
  88740. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  88741. return false; /* read_callback_ sets the state for us */
  88742. partitioned_rice_contents->parameters[partition] = rice_parameter;
  88743. if(rice_parameter < pesc) {
  88744. partitioned_rice_contents->raw_bits[partition] = 0;
  88745. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  88746. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  88747. return false; /* read_callback_ sets the state for us */
  88748. sample += u;
  88749. }
  88750. else {
  88751. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  88752. return false; /* read_callback_ sets the state for us */
  88753. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  88754. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  88755. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  88756. return false; /* read_callback_ sets the state for us */
  88757. residual[sample] = i;
  88758. }
  88759. }
  88760. }
  88761. return true;
  88762. }
  88763. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  88764. {
  88765. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88766. FLAC__uint32 zero = 0;
  88767. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88768. return false; /* read_callback_ sets the state for us */
  88769. if(zero != 0) {
  88770. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88771. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88772. }
  88773. }
  88774. return true;
  88775. }
  88776. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  88777. {
  88778. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  88779. if(
  88780. #if FLAC__HAS_OGG
  88781. !decoder->private_->is_ogg &&
  88782. #endif
  88783. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88784. ) {
  88785. *bytes = 0;
  88786. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88787. return false;
  88788. }
  88789. else if(*bytes > 0) {
  88790. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  88791. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88792. return false;
  88793. }
  88794. else {
  88795. const FLAC__StreamDecoderReadStatus status =
  88796. #if FLAC__HAS_OGG
  88797. decoder->private_->is_ogg?
  88798. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  88799. #endif
  88800. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  88801. ;
  88802. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  88803. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88804. return false;
  88805. }
  88806. else if(*bytes == 0) {
  88807. if(
  88808. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  88809. (
  88810. #if FLAC__HAS_OGG
  88811. !decoder->private_->is_ogg &&
  88812. #endif
  88813. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88814. )
  88815. ) {
  88816. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88817. return false;
  88818. }
  88819. else
  88820. return true;
  88821. }
  88822. else
  88823. return true;
  88824. }
  88825. }
  88826. else {
  88827. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88828. return false;
  88829. }
  88830. }
  88831. #if FLAC__HAS_OGG
  88832. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  88833. {
  88834. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  88835. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  88836. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  88837. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  88838. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  88839. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  88840. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  88841. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  88842. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  88843. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  88844. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  88845. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  88846. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  88847. default:
  88848. FLAC__ASSERT(0);
  88849. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  88850. }
  88851. }
  88852. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  88853. {
  88854. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  88855. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  88856. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  88857. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  88858. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  88859. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  88860. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  88861. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  88862. default:
  88863. FLAC__ASSERT(0);
  88864. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  88865. }
  88866. }
  88867. #endif
  88868. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  88869. {
  88870. if(decoder->private_->is_seeking) {
  88871. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  88872. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  88873. FLAC__uint64 target_sample = decoder->private_->target_sample;
  88874. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88875. #if FLAC__HAS_OGG
  88876. decoder->private_->got_a_frame = true;
  88877. #endif
  88878. decoder->private_->last_frame = *frame; /* save the frame */
  88879. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  88880. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  88881. decoder->private_->is_seeking = false;
  88882. if(delta > 0) {
  88883. unsigned channel;
  88884. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  88885. for(channel = 0; channel < frame->header.channels; channel++)
  88886. newbuffer[channel] = buffer[channel] + delta;
  88887. decoder->private_->last_frame.header.blocksize -= delta;
  88888. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  88889. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  88890. }
  88891. else {
  88892. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  88893. }
  88894. }
  88895. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  88896. }
  88897. if(!decoder->private_->has_stream_info)
  88898. decoder->private_->do_md5_checking = false;
  88899. if(decoder->private_->do_md5_checking) {
  88900. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  88901. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  88902. }
  88903. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  88904. }
  88905. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  88906. {
  88907. if(!decoder->private_->is_seeking)
  88908. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  88909. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  88910. decoder->private_->unparseable_frame_count++;
  88911. }
  88912. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  88913. {
  88914. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  88915. FLAC__int64 pos = -1;
  88916. int i;
  88917. unsigned approx_bytes_per_frame;
  88918. FLAC__bool first_seek = true;
  88919. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  88920. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  88921. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88922. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  88923. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  88924. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  88925. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  88926. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  88927. if(channels == 0)
  88928. channels = decoder->private_->stream_info.data.stream_info.channels;
  88929. if(bps == 0)
  88930. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88931. if(max_framesize > 0)
  88932. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  88933. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  88934. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  88935. }
  88936. else
  88937. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  88938. lower_bound = first_frame_offset;
  88939. lower_bound_sample = 0;
  88940. upper_bound = stream_length;
  88941. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  88942. if(seek_table) {
  88943. FLAC__uint64 new_lower_bound = lower_bound;
  88944. FLAC__uint64 new_upper_bound = upper_bound;
  88945. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  88946. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  88947. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  88948. if(
  88949. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  88950. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  88951. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  88952. seek_table->points[i].sample_number <= target_sample
  88953. )
  88954. break;
  88955. }
  88956. if(i >= 0) { /* i.e. we found a suitable seek point... */
  88957. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  88958. new_lower_bound_sample = seek_table->points[i].sample_number;
  88959. }
  88960. for(i = 0; i < (int)seek_table->num_points; i++) {
  88961. if(
  88962. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  88963. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  88964. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  88965. seek_table->points[i].sample_number > target_sample
  88966. )
  88967. break;
  88968. }
  88969. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  88970. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  88971. new_upper_bound_sample = seek_table->points[i].sample_number;
  88972. }
  88973. if(new_upper_bound >= new_lower_bound) {
  88974. lower_bound = new_lower_bound;
  88975. upper_bound = new_upper_bound;
  88976. lower_bound_sample = new_lower_bound_sample;
  88977. upper_bound_sample = new_upper_bound_sample;
  88978. }
  88979. }
  88980. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  88981. if(upper_bound_sample == lower_bound_sample)
  88982. upper_bound_sample++;
  88983. decoder->private_->target_sample = target_sample;
  88984. while(1) {
  88985. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  88986. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  88987. return false;
  88988. }
  88989. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  88990. #if defined _MSC_VER || defined __MINGW32__
  88991. pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(FLAC__int64)(target_sample - lower_bound_sample) / (FLAC__double)(FLAC__int64)(upper_bound_sample - lower_bound_sample) * (FLAC__double)(FLAC__int64)(upper_bound - lower_bound)) - approx_bytes_per_frame;
  88992. #else
  88993. pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(target_sample - lower_bound_sample) / (FLAC__double)(upper_bound_sample - lower_bound_sample) * (FLAC__double)(upper_bound - lower_bound)) - approx_bytes_per_frame;
  88994. #endif
  88995. #else
  88996. if(upper_bound - lower_bound < 0xffffffff)
  88997. pos = (FLAC__int64)lower_bound + (FLAC__int64)(((target_sample - lower_bound_sample) * (upper_bound - lower_bound)) / (upper_bound_sample - lower_bound_sample)) - approx_bytes_per_frame;
  88998. else /* @@@ WATCHOUT, ~2TB limit */
  88999. pos = (FLAC__int64)lower_bound + (FLAC__int64)((((target_sample - lower_bound_sample)>>8) * ((upper_bound - lower_bound)>>8)) / ((upper_bound_sample - lower_bound_sample)>>16)) - approx_bytes_per_frame;
  89000. #endif
  89001. if(pos >= (FLAC__int64)upper_bound)
  89002. pos = (FLAC__int64)upper_bound - 1;
  89003. if(pos < (FLAC__int64)lower_bound)
  89004. pos = (FLAC__int64)lower_bound;
  89005. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89006. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89007. return false;
  89008. }
  89009. if(!FLAC__stream_decoder_flush(decoder)) {
  89010. return false;
  89011. }
  89012. decoder->private_->unparseable_frame_count = 0;
  89013. if(!FLAC__stream_decoder_process_single(decoder)) {
  89014. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89015. return false;
  89016. }
  89017. #if 0
  89018. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89019. break;
  89020. #endif
  89021. if(!decoder->private_->is_seeking)
  89022. break;
  89023. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89024. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89025. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89026. if (pos == (FLAC__int64)lower_bound) {
  89027. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89028. return false;
  89029. }
  89030. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89031. continue;
  89032. }
  89033. first_seek = false;
  89034. if (this_frame_sample < lower_bound_sample) {
  89035. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89036. return false;
  89037. }
  89038. if(target_sample < this_frame_sample) {
  89039. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89040. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89041. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89042. return false;
  89043. }
  89044. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89045. }
  89046. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89047. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89048. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89049. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89050. return false;
  89051. }
  89052. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89053. }
  89054. }
  89055. return true;
  89056. }
  89057. #if FLAC__HAS_OGG
  89058. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89059. {
  89060. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89061. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89062. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89063. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89064. FLAC__bool did_a_seek;
  89065. unsigned iteration = 0;
  89066. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89067. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89068. if(right_sample == 0) {
  89069. right_sample = (FLAC__uint64)(-1);
  89070. BINARY_SEARCH_AFTER_ITERATION = 0;
  89071. }
  89072. decoder->private_->target_sample = target_sample;
  89073. for( ; ; iteration++) {
  89074. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89075. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89076. pos = (right_pos + left_pos) / 2;
  89077. }
  89078. else {
  89079. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89080. #if defined _MSC_VER || defined __MINGW32__
  89081. pos = (FLAC__uint64)((FLAC__double)(FLAC__int64)(target_sample - left_sample) / (FLAC__double)(FLAC__int64)(right_sample - left_sample) * (FLAC__double)(FLAC__int64)(right_pos - left_pos));
  89082. #else
  89083. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89084. #endif
  89085. #else
  89086. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89087. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89088. else /* @@@ WATCHOUT, ~2TB limit */
  89089. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89090. #endif
  89091. }
  89092. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89093. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89094. return false;
  89095. }
  89096. if(!FLAC__stream_decoder_flush(decoder)) {
  89097. return false;
  89098. }
  89099. did_a_seek = true;
  89100. }
  89101. else
  89102. did_a_seek = false;
  89103. decoder->private_->got_a_frame = false;
  89104. if(!FLAC__stream_decoder_process_single(decoder)) {
  89105. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89106. return false;
  89107. }
  89108. if(!decoder->private_->got_a_frame) {
  89109. if(did_a_seek) {
  89110. right_pos = pos;
  89111. BINARY_SEARCH_AFTER_ITERATION = 0;
  89112. }
  89113. else {
  89114. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89115. return false;
  89116. }
  89117. }
  89118. else if(!decoder->private_->is_seeking) {
  89119. break;
  89120. }
  89121. else {
  89122. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89123. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89124. if (did_a_seek) {
  89125. if (this_frame_sample <= target_sample) {
  89126. FLAC__ASSERT(this_frame_sample != target_sample);
  89127. left_sample = this_frame_sample;
  89128. if (left_pos == pos) {
  89129. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89130. return false;
  89131. }
  89132. left_pos = pos;
  89133. }
  89134. else if(this_frame_sample > target_sample) {
  89135. right_sample = this_frame_sample;
  89136. if (right_pos == pos) {
  89137. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89138. return false;
  89139. }
  89140. right_pos = pos;
  89141. }
  89142. }
  89143. }
  89144. }
  89145. return true;
  89146. }
  89147. #endif
  89148. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89149. {
  89150. (void)client_data;
  89151. if(*bytes > 0) {
  89152. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89153. if(ferror(decoder->private_->file))
  89154. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89155. else if(*bytes == 0)
  89156. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89157. else
  89158. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89159. }
  89160. else
  89161. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89162. }
  89163. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89164. {
  89165. (void)client_data;
  89166. if(decoder->private_->file == stdin)
  89167. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89168. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89169. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89170. else
  89171. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89172. }
  89173. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89174. {
  89175. off_t pos;
  89176. (void)client_data;
  89177. if(decoder->private_->file == stdin)
  89178. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89179. else if((pos = ftello(decoder->private_->file)) < 0)
  89180. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89181. else {
  89182. *absolute_byte_offset = (FLAC__uint64)pos;
  89183. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89184. }
  89185. }
  89186. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89187. {
  89188. struct stat filestats;
  89189. (void)client_data;
  89190. if(decoder->private_->file == stdin)
  89191. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89192. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89193. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89194. else {
  89195. *stream_length = (FLAC__uint64)filestats.st_size;
  89196. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89197. }
  89198. }
  89199. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89200. {
  89201. (void)client_data;
  89202. return feof(decoder->private_->file)? true : false;
  89203. }
  89204. #endif
  89205. /*** End of inlined file: stream_decoder.c ***/
  89206. /*** Start of inlined file: stream_encoder.c ***/
  89207. /*** Start of inlined file: juce_FlacHeader.h ***/
  89208. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89209. // tasks..
  89210. #define VERSION "1.2.1"
  89211. #define FLAC__NO_DLL 1
  89212. #if JUCE_MSVC
  89213. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89214. #endif
  89215. #if JUCE_MAC
  89216. #define FLAC__SYS_DARWIN 1
  89217. #endif
  89218. /*** End of inlined file: juce_FlacHeader.h ***/
  89219. #if JUCE_USE_FLAC
  89220. #if HAVE_CONFIG_H
  89221. # include <config.h>
  89222. #endif
  89223. #if defined _MSC_VER || defined __MINGW32__
  89224. #include <io.h> /* for _setmode() */
  89225. #include <fcntl.h> /* for _O_BINARY */
  89226. #endif
  89227. #if defined __CYGWIN__ || defined __EMX__
  89228. #include <io.h> /* for setmode(), O_BINARY */
  89229. #include <fcntl.h> /* for _O_BINARY */
  89230. #endif
  89231. #include <limits.h>
  89232. #include <stdio.h>
  89233. #include <stdlib.h> /* for malloc() */
  89234. #include <string.h> /* for memcpy() */
  89235. #include <sys/types.h> /* for off_t */
  89236. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89237. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89238. #define fseeko fseek
  89239. #define ftello ftell
  89240. #endif
  89241. #endif
  89242. /*** Start of inlined file: stream_encoder.h ***/
  89243. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89244. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89245. #if FLAC__HAS_OGG
  89246. #include "private/ogg_encoder_aspect.h"
  89247. #endif
  89248. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89249. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89250. typedef enum {
  89251. FLAC__APODIZATION_BARTLETT,
  89252. FLAC__APODIZATION_BARTLETT_HANN,
  89253. FLAC__APODIZATION_BLACKMAN,
  89254. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89255. FLAC__APODIZATION_CONNES,
  89256. FLAC__APODIZATION_FLATTOP,
  89257. FLAC__APODIZATION_GAUSS,
  89258. FLAC__APODIZATION_HAMMING,
  89259. FLAC__APODIZATION_HANN,
  89260. FLAC__APODIZATION_KAISER_BESSEL,
  89261. FLAC__APODIZATION_NUTTALL,
  89262. FLAC__APODIZATION_RECTANGLE,
  89263. FLAC__APODIZATION_TRIANGLE,
  89264. FLAC__APODIZATION_TUKEY,
  89265. FLAC__APODIZATION_WELCH
  89266. } FLAC__ApodizationFunction;
  89267. typedef struct {
  89268. FLAC__ApodizationFunction type;
  89269. union {
  89270. struct {
  89271. FLAC__real stddev;
  89272. } gauss;
  89273. struct {
  89274. FLAC__real p;
  89275. } tukey;
  89276. } parameters;
  89277. } FLAC__ApodizationSpecification;
  89278. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89279. typedef struct FLAC__StreamEncoderProtected {
  89280. FLAC__StreamEncoderState state;
  89281. FLAC__bool verify;
  89282. FLAC__bool streamable_subset;
  89283. FLAC__bool do_md5;
  89284. FLAC__bool do_mid_side_stereo;
  89285. FLAC__bool loose_mid_side_stereo;
  89286. unsigned channels;
  89287. unsigned bits_per_sample;
  89288. unsigned sample_rate;
  89289. unsigned blocksize;
  89290. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89291. unsigned num_apodizations;
  89292. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89293. #endif
  89294. unsigned max_lpc_order;
  89295. unsigned qlp_coeff_precision;
  89296. FLAC__bool do_qlp_coeff_prec_search;
  89297. FLAC__bool do_exhaustive_model_search;
  89298. FLAC__bool do_escape_coding;
  89299. unsigned min_residual_partition_order;
  89300. unsigned max_residual_partition_order;
  89301. unsigned rice_parameter_search_dist;
  89302. FLAC__uint64 total_samples_estimate;
  89303. FLAC__StreamMetadata **metadata;
  89304. unsigned num_metadata_blocks;
  89305. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89306. #if FLAC__HAS_OGG
  89307. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89308. #endif
  89309. } FLAC__StreamEncoderProtected;
  89310. #endif
  89311. /*** End of inlined file: stream_encoder.h ***/
  89312. #if FLAC__HAS_OGG
  89313. #include "include/private/ogg_helper.h"
  89314. #include "include/private/ogg_mapping.h"
  89315. #endif
  89316. /*** Start of inlined file: stream_encoder_framing.h ***/
  89317. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89318. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89319. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89320. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89321. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89322. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89323. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89324. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89325. #endif
  89326. /*** End of inlined file: stream_encoder_framing.h ***/
  89327. /*** Start of inlined file: window.h ***/
  89328. #ifndef FLAC__PRIVATE__WINDOW_H
  89329. #define FLAC__PRIVATE__WINDOW_H
  89330. #ifdef HAVE_CONFIG_H
  89331. #include <config.h>
  89332. #endif
  89333. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89334. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89335. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89336. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89337. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89338. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89339. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89340. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89341. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89342. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89343. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89344. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89345. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89346. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89347. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89348. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89349. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89350. #endif
  89351. /*** End of inlined file: window.h ***/
  89352. #ifndef FLaC__INLINE
  89353. #define FLaC__INLINE
  89354. #endif
  89355. #ifdef min
  89356. #undef min
  89357. #endif
  89358. #define min(x,y) ((x)<(y)?(x):(y))
  89359. #ifdef max
  89360. #undef max
  89361. #endif
  89362. #define max(x,y) ((x)>(y)?(x):(y))
  89363. #undef EXACT_RICE_BITS_CALCULATION
  89364. #undef ENABLE_RICE_PARAMETER_SEARCH
  89365. typedef struct {
  89366. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89367. unsigned size; /* of each data[] in samples */
  89368. unsigned tail;
  89369. } verify_input_fifo;
  89370. typedef struct {
  89371. const FLAC__byte *data;
  89372. unsigned capacity;
  89373. unsigned bytes;
  89374. } verify_output;
  89375. typedef enum {
  89376. ENCODER_IN_MAGIC = 0,
  89377. ENCODER_IN_METADATA = 1,
  89378. ENCODER_IN_AUDIO = 2
  89379. } EncoderStateHint;
  89380. static struct CompressionLevels {
  89381. FLAC__bool do_mid_side_stereo;
  89382. FLAC__bool loose_mid_side_stereo;
  89383. unsigned max_lpc_order;
  89384. unsigned qlp_coeff_precision;
  89385. FLAC__bool do_qlp_coeff_prec_search;
  89386. FLAC__bool do_escape_coding;
  89387. FLAC__bool do_exhaustive_model_search;
  89388. unsigned min_residual_partition_order;
  89389. unsigned max_residual_partition_order;
  89390. unsigned rice_parameter_search_dist;
  89391. } compression_levels_[] = {
  89392. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89393. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89394. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89395. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89396. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89397. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89398. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89399. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89400. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89401. };
  89402. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89403. static void free_(FLAC__StreamEncoder *encoder);
  89404. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89405. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89406. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89407. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89408. #if FLAC__HAS_OGG
  89409. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89410. #endif
  89411. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89412. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89413. static FLAC__bool process_subframe_(
  89414. FLAC__StreamEncoder *encoder,
  89415. unsigned min_partition_order,
  89416. unsigned max_partition_order,
  89417. const FLAC__FrameHeader *frame_header,
  89418. unsigned subframe_bps,
  89419. const FLAC__int32 integer_signal[],
  89420. FLAC__Subframe *subframe[2],
  89421. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89422. FLAC__int32 *residual[2],
  89423. unsigned *best_subframe,
  89424. unsigned *best_bits
  89425. );
  89426. static FLAC__bool add_subframe_(
  89427. FLAC__StreamEncoder *encoder,
  89428. unsigned blocksize,
  89429. unsigned subframe_bps,
  89430. const FLAC__Subframe *subframe,
  89431. FLAC__BitWriter *frame
  89432. );
  89433. static unsigned evaluate_constant_subframe_(
  89434. FLAC__StreamEncoder *encoder,
  89435. const FLAC__int32 signal,
  89436. unsigned blocksize,
  89437. unsigned subframe_bps,
  89438. FLAC__Subframe *subframe
  89439. );
  89440. static unsigned evaluate_fixed_subframe_(
  89441. FLAC__StreamEncoder *encoder,
  89442. const FLAC__int32 signal[],
  89443. FLAC__int32 residual[],
  89444. FLAC__uint64 abs_residual_partition_sums[],
  89445. unsigned raw_bits_per_partition[],
  89446. unsigned blocksize,
  89447. unsigned subframe_bps,
  89448. unsigned order,
  89449. unsigned rice_parameter,
  89450. unsigned rice_parameter_limit,
  89451. unsigned min_partition_order,
  89452. unsigned max_partition_order,
  89453. FLAC__bool do_escape_coding,
  89454. unsigned rice_parameter_search_dist,
  89455. FLAC__Subframe *subframe,
  89456. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89457. );
  89458. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89459. static unsigned evaluate_lpc_subframe_(
  89460. FLAC__StreamEncoder *encoder,
  89461. const FLAC__int32 signal[],
  89462. FLAC__int32 residual[],
  89463. FLAC__uint64 abs_residual_partition_sums[],
  89464. unsigned raw_bits_per_partition[],
  89465. const FLAC__real lp_coeff[],
  89466. unsigned blocksize,
  89467. unsigned subframe_bps,
  89468. unsigned order,
  89469. unsigned qlp_coeff_precision,
  89470. unsigned rice_parameter,
  89471. unsigned rice_parameter_limit,
  89472. unsigned min_partition_order,
  89473. unsigned max_partition_order,
  89474. FLAC__bool do_escape_coding,
  89475. unsigned rice_parameter_search_dist,
  89476. FLAC__Subframe *subframe,
  89477. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89478. );
  89479. #endif
  89480. static unsigned evaluate_verbatim_subframe_(
  89481. FLAC__StreamEncoder *encoder,
  89482. const FLAC__int32 signal[],
  89483. unsigned blocksize,
  89484. unsigned subframe_bps,
  89485. FLAC__Subframe *subframe
  89486. );
  89487. static unsigned find_best_partition_order_(
  89488. struct FLAC__StreamEncoderPrivate *private_,
  89489. const FLAC__int32 residual[],
  89490. FLAC__uint64 abs_residual_partition_sums[],
  89491. unsigned raw_bits_per_partition[],
  89492. unsigned residual_samples,
  89493. unsigned predictor_order,
  89494. unsigned rice_parameter,
  89495. unsigned rice_parameter_limit,
  89496. unsigned min_partition_order,
  89497. unsigned max_partition_order,
  89498. unsigned bps,
  89499. FLAC__bool do_escape_coding,
  89500. unsigned rice_parameter_search_dist,
  89501. FLAC__EntropyCodingMethod *best_ecm
  89502. );
  89503. static void precompute_partition_info_sums_(
  89504. const FLAC__int32 residual[],
  89505. FLAC__uint64 abs_residual_partition_sums[],
  89506. unsigned residual_samples,
  89507. unsigned predictor_order,
  89508. unsigned min_partition_order,
  89509. unsigned max_partition_order,
  89510. unsigned bps
  89511. );
  89512. static void precompute_partition_info_escapes_(
  89513. const FLAC__int32 residual[],
  89514. unsigned raw_bits_per_partition[],
  89515. unsigned residual_samples,
  89516. unsigned predictor_order,
  89517. unsigned min_partition_order,
  89518. unsigned max_partition_order
  89519. );
  89520. static FLAC__bool set_partitioned_rice_(
  89521. #ifdef EXACT_RICE_BITS_CALCULATION
  89522. const FLAC__int32 residual[],
  89523. #endif
  89524. const FLAC__uint64 abs_residual_partition_sums[],
  89525. const unsigned raw_bits_per_partition[],
  89526. const unsigned residual_samples,
  89527. const unsigned predictor_order,
  89528. const unsigned suggested_rice_parameter,
  89529. const unsigned rice_parameter_limit,
  89530. const unsigned rice_parameter_search_dist,
  89531. const unsigned partition_order,
  89532. const FLAC__bool search_for_escapes,
  89533. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89534. unsigned *bits
  89535. );
  89536. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89537. static void append_to_verify_fifo_(
  89538. verify_input_fifo *fifo,
  89539. const FLAC__int32 * const input[],
  89540. unsigned input_offset,
  89541. unsigned channels,
  89542. unsigned wide_samples
  89543. );
  89544. static void append_to_verify_fifo_interleaved_(
  89545. verify_input_fifo *fifo,
  89546. const FLAC__int32 input[],
  89547. unsigned input_offset,
  89548. unsigned channels,
  89549. unsigned wide_samples
  89550. );
  89551. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89552. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89553. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89554. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89555. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89556. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89557. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89558. static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  89559. static FILE *get_binary_stdout_(void);
  89560. typedef struct FLAC__StreamEncoderPrivate {
  89561. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89562. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89563. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89564. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89565. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89566. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89567. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89568. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89569. #endif
  89570. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89571. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89572. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89573. FLAC__int32 *residual_workspace_mid_side[2][2];
  89574. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89575. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89576. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89577. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89578. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89579. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89580. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89581. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89582. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89583. unsigned best_subframe_mid_side[2];
  89584. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89585. unsigned best_subframe_bits_mid_side[2];
  89586. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89587. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89588. FLAC__BitWriter *frame; /* the current frame being worked on */
  89589. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89590. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89591. FLAC__ChannelAssignment last_channel_assignment;
  89592. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89593. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89594. unsigned current_sample_number;
  89595. unsigned current_frame_number;
  89596. FLAC__MD5Context md5context;
  89597. FLAC__CPUInfo cpuinfo;
  89598. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89599. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89600. #else
  89601. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89602. #endif
  89603. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89604. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89605. void (*local_lpc_compute_residual_from_qlp_coefficients)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  89606. void (*local_lpc_compute_residual_from_qlp_coefficients_64bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  89607. void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  89608. #endif
  89609. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89610. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89611. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89612. FLAC__bool disable_constant_subframes;
  89613. FLAC__bool disable_fixed_subframes;
  89614. FLAC__bool disable_verbatim_subframes;
  89615. #if FLAC__HAS_OGG
  89616. FLAC__bool is_ogg;
  89617. #endif
  89618. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89619. FLAC__StreamEncoderSeekCallback seek_callback;
  89620. FLAC__StreamEncoderTellCallback tell_callback;
  89621. FLAC__StreamEncoderWriteCallback write_callback;
  89622. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89623. FLAC__StreamEncoderProgressCallback progress_callback;
  89624. void *client_data;
  89625. unsigned first_seekpoint_to_check;
  89626. FILE *file; /* only used when encoding to a file */
  89627. FLAC__uint64 bytes_written;
  89628. FLAC__uint64 samples_written;
  89629. unsigned frames_written;
  89630. unsigned total_frames_estimate;
  89631. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89632. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89633. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89634. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89635. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89636. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89637. FLAC__real *windowed_signal_unaligned;
  89638. #endif
  89639. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89640. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89641. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89642. unsigned *raw_bits_per_partition_unaligned;
  89643. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89644. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89645. #endif
  89646. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89647. struct {
  89648. FLAC__StreamDecoder *decoder;
  89649. EncoderStateHint state_hint;
  89650. FLAC__bool needs_magic_hack;
  89651. verify_input_fifo input_fifo;
  89652. verify_output output;
  89653. struct {
  89654. FLAC__uint64 absolute_sample;
  89655. unsigned frame_number;
  89656. unsigned channel;
  89657. unsigned sample;
  89658. FLAC__int32 expected;
  89659. FLAC__int32 got;
  89660. } error_stats;
  89661. } verify;
  89662. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89663. } FLAC__StreamEncoderPrivate;
  89664. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89665. "FLAC__STREAM_ENCODER_OK",
  89666. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89667. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89668. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89669. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89670. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89671. "FLAC__STREAM_ENCODER_IO_ERROR",
  89672. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89673. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89674. };
  89675. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89676. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89677. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89678. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89679. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89680. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89681. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  89682. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  89683. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  89684. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  89685. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  89686. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  89687. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  89688. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  89689. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  89690. };
  89691. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  89692. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  89693. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  89694. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  89695. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  89696. };
  89697. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  89698. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  89699. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  89700. };
  89701. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  89702. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  89703. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  89704. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  89705. };
  89706. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  89707. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  89708. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  89709. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  89710. };
  89711. static const unsigned OVERREAD_ = 1;
  89712. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  89713. {
  89714. FLAC__StreamEncoder *encoder;
  89715. unsigned i;
  89716. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  89717. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  89718. if(encoder == 0) {
  89719. return 0;
  89720. }
  89721. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  89722. if(encoder->protected_ == 0) {
  89723. free(encoder);
  89724. return 0;
  89725. }
  89726. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  89727. if(encoder->private_ == 0) {
  89728. free(encoder->protected_);
  89729. free(encoder);
  89730. return 0;
  89731. }
  89732. encoder->private_->frame = FLAC__bitwriter_new();
  89733. if(encoder->private_->frame == 0) {
  89734. free(encoder->private_);
  89735. free(encoder->protected_);
  89736. free(encoder);
  89737. return 0;
  89738. }
  89739. encoder->private_->file = 0;
  89740. set_defaults_enc(encoder);
  89741. encoder->private_->is_being_deleted = false;
  89742. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89743. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  89744. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  89745. }
  89746. for(i = 0; i < 2; i++) {
  89747. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  89748. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  89749. }
  89750. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89751. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  89752. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  89753. }
  89754. for(i = 0; i < 2; i++) {
  89755. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  89756. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  89757. }
  89758. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89759. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89760. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89761. }
  89762. for(i = 0; i < 2; i++) {
  89763. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89764. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89765. }
  89766. for(i = 0; i < 2; i++)
  89767. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  89768. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  89769. return encoder;
  89770. }
  89771. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  89772. {
  89773. unsigned i;
  89774. FLAC__ASSERT(0 != encoder);
  89775. FLAC__ASSERT(0 != encoder->protected_);
  89776. FLAC__ASSERT(0 != encoder->private_);
  89777. FLAC__ASSERT(0 != encoder->private_->frame);
  89778. encoder->private_->is_being_deleted = true;
  89779. (void)FLAC__stream_encoder_finish(encoder);
  89780. if(0 != encoder->private_->verify.decoder)
  89781. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  89782. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89783. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89784. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89785. }
  89786. for(i = 0; i < 2; i++) {
  89787. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89788. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89789. }
  89790. for(i = 0; i < 2; i++)
  89791. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  89792. FLAC__bitwriter_delete(encoder->private_->frame);
  89793. free(encoder->private_);
  89794. free(encoder->protected_);
  89795. free(encoder);
  89796. }
  89797. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  89798. FLAC__StreamEncoder *encoder,
  89799. FLAC__StreamEncoderReadCallback read_callback,
  89800. FLAC__StreamEncoderWriteCallback write_callback,
  89801. FLAC__StreamEncoderSeekCallback seek_callback,
  89802. FLAC__StreamEncoderTellCallback tell_callback,
  89803. FLAC__StreamEncoderMetadataCallback metadata_callback,
  89804. void *client_data,
  89805. FLAC__bool is_ogg
  89806. )
  89807. {
  89808. unsigned i;
  89809. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  89810. FLAC__ASSERT(0 != encoder);
  89811. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  89812. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  89813. #if !FLAC__HAS_OGG
  89814. if(is_ogg)
  89815. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  89816. #endif
  89817. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  89818. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  89819. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  89820. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  89821. if(encoder->protected_->channels != 2) {
  89822. encoder->protected_->do_mid_side_stereo = false;
  89823. encoder->protected_->loose_mid_side_stereo = false;
  89824. }
  89825. else if(!encoder->protected_->do_mid_side_stereo)
  89826. encoder->protected_->loose_mid_side_stereo = false;
  89827. if(encoder->protected_->bits_per_sample >= 32)
  89828. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  89829. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  89830. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  89831. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  89832. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  89833. if(encoder->protected_->blocksize == 0) {
  89834. if(encoder->protected_->max_lpc_order == 0)
  89835. encoder->protected_->blocksize = 1152;
  89836. else
  89837. encoder->protected_->blocksize = 4096;
  89838. }
  89839. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  89840. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  89841. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  89842. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  89843. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  89844. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  89845. if(encoder->protected_->qlp_coeff_precision == 0) {
  89846. if(encoder->protected_->bits_per_sample < 16) {
  89847. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  89848. }
  89849. else if(encoder->protected_->bits_per_sample == 16) {
  89850. if(encoder->protected_->blocksize <= 192)
  89851. encoder->protected_->qlp_coeff_precision = 7;
  89852. else if(encoder->protected_->blocksize <= 384)
  89853. encoder->protected_->qlp_coeff_precision = 8;
  89854. else if(encoder->protected_->blocksize <= 576)
  89855. encoder->protected_->qlp_coeff_precision = 9;
  89856. else if(encoder->protected_->blocksize <= 1152)
  89857. encoder->protected_->qlp_coeff_precision = 10;
  89858. else if(encoder->protected_->blocksize <= 2304)
  89859. encoder->protected_->qlp_coeff_precision = 11;
  89860. else if(encoder->protected_->blocksize <= 4608)
  89861. encoder->protected_->qlp_coeff_precision = 12;
  89862. else
  89863. encoder->protected_->qlp_coeff_precision = 13;
  89864. }
  89865. else {
  89866. if(encoder->protected_->blocksize <= 384)
  89867. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  89868. else if(encoder->protected_->blocksize <= 1152)
  89869. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  89870. else
  89871. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  89872. }
  89873. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  89874. }
  89875. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  89876. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  89877. if(encoder->protected_->streamable_subset) {
  89878. if(
  89879. encoder->protected_->blocksize != 192 &&
  89880. encoder->protected_->blocksize != 576 &&
  89881. encoder->protected_->blocksize != 1152 &&
  89882. encoder->protected_->blocksize != 2304 &&
  89883. encoder->protected_->blocksize != 4608 &&
  89884. encoder->protected_->blocksize != 256 &&
  89885. encoder->protected_->blocksize != 512 &&
  89886. encoder->protected_->blocksize != 1024 &&
  89887. encoder->protected_->blocksize != 2048 &&
  89888. encoder->protected_->blocksize != 4096 &&
  89889. encoder->protected_->blocksize != 8192 &&
  89890. encoder->protected_->blocksize != 16384
  89891. )
  89892. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89893. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  89894. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89895. if(
  89896. encoder->protected_->bits_per_sample != 8 &&
  89897. encoder->protected_->bits_per_sample != 12 &&
  89898. encoder->protected_->bits_per_sample != 16 &&
  89899. encoder->protected_->bits_per_sample != 20 &&
  89900. encoder->protected_->bits_per_sample != 24
  89901. )
  89902. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89903. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  89904. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89905. if(
  89906. encoder->protected_->sample_rate <= 48000 &&
  89907. (
  89908. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  89909. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  89910. )
  89911. ) {
  89912. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89913. }
  89914. }
  89915. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89916. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  89917. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  89918. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  89919. #if FLAC__HAS_OGG
  89920. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  89921. unsigned i;
  89922. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  89923. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  89924. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  89925. for( ; i > 0; i--)
  89926. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  89927. encoder->protected_->metadata[0] = vc;
  89928. break;
  89929. }
  89930. }
  89931. }
  89932. #endif
  89933. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  89934. unsigned i;
  89935. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  89936. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  89937. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  89938. break; /* take only the first one */
  89939. }
  89940. }
  89941. }
  89942. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  89943. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89944. metadata_has_seektable = false;
  89945. metadata_has_vorbis_comment = false;
  89946. metadata_picture_has_type1 = false;
  89947. metadata_picture_has_type2 = false;
  89948. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  89949. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  89950. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  89951. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89952. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  89953. if(metadata_has_seektable) /* only one is allowed */
  89954. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89955. metadata_has_seektable = true;
  89956. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  89957. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89958. }
  89959. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  89960. if(metadata_has_vorbis_comment) /* only one is allowed */
  89961. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89962. metadata_has_vorbis_comment = true;
  89963. }
  89964. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  89965. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  89966. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89967. }
  89968. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  89969. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  89970. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89971. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  89972. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  89973. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89974. metadata_picture_has_type1 = true;
  89975. if(
  89976. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  89977. (
  89978. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  89979. m->data.picture.width != 32 ||
  89980. m->data.picture.height != 32
  89981. )
  89982. )
  89983. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89984. }
  89985. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  89986. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  89987. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  89988. metadata_picture_has_type2 = true;
  89989. }
  89990. }
  89991. }
  89992. encoder->private_->input_capacity = 0;
  89993. for(i = 0; i < encoder->protected_->channels; i++) {
  89994. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  89995. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89996. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  89997. #endif
  89998. }
  89999. for(i = 0; i < 2; i++) {
  90000. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90001. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90002. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90003. #endif
  90004. }
  90005. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90006. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90007. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90008. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90009. #endif
  90010. for(i = 0; i < encoder->protected_->channels; i++) {
  90011. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90012. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90013. encoder->private_->best_subframe[i] = 0;
  90014. }
  90015. for(i = 0; i < 2; i++) {
  90016. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90017. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90018. encoder->private_->best_subframe_mid_side[i] = 0;
  90019. }
  90020. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90021. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90022. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90023. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90024. #else
  90025. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90026. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90027. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90028. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90029. encoder->private_->loose_mid_side_stereo_frames = (unsigned)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF);
  90030. #endif
  90031. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90032. encoder->private_->loose_mid_side_stereo_frames = 1;
  90033. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90034. encoder->private_->current_sample_number = 0;
  90035. encoder->private_->current_frame_number = 0;
  90036. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90037. encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(max(encoder->protected_->max_lpc_order, FLAC__MAX_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */
  90038. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90039. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90040. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90041. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90042. #endif
  90043. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90044. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90045. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90046. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90047. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90048. #endif
  90049. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90050. # ifndef FLAC__NO_ASM
  90051. if(encoder->private_->cpuinfo.use_asm) {
  90052. # ifdef FLAC__CPU_IA32
  90053. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90054. # ifdef FLAC__HAS_NASM
  90055. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90056. if(encoder->protected_->max_lpc_order < 4)
  90057. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90058. else if(encoder->protected_->max_lpc_order < 8)
  90059. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90060. else if(encoder->protected_->max_lpc_order < 12)
  90061. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90062. else
  90063. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90064. }
  90065. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90066. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90067. else
  90068. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90069. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90070. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90071. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90072. }
  90073. else {
  90074. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90075. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90076. }
  90077. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90078. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90079. # endif /* FLAC__HAS_NASM */
  90080. # endif /* FLAC__CPU_IA32 */
  90081. }
  90082. # endif /* !FLAC__NO_ASM */
  90083. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90084. if(encoder->private_->use_wide_by_block) {
  90085. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90086. }
  90087. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90088. #if FLAC__HAS_OGG
  90089. encoder->private_->is_ogg = is_ogg;
  90090. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90091. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90092. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90093. }
  90094. #endif
  90095. encoder->private_->read_callback = read_callback;
  90096. encoder->private_->write_callback = write_callback;
  90097. encoder->private_->seek_callback = seek_callback;
  90098. encoder->private_->tell_callback = tell_callback;
  90099. encoder->private_->metadata_callback = metadata_callback;
  90100. encoder->private_->client_data = client_data;
  90101. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90102. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90103. }
  90104. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90105. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90106. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90107. }
  90108. if(encoder->protected_->verify) {
  90109. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90110. for(i = 0; i < encoder->protected_->channels; i++) {
  90111. if(0 == (encoder->private_->verify.input_fifo.data[i] = (FLAC__int32*)safe_malloc_mul_2op_(sizeof(FLAC__int32), /*times*/encoder->private_->verify.input_fifo.size))) {
  90112. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90113. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90114. }
  90115. }
  90116. encoder->private_->verify.input_fifo.tail = 0;
  90117. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90118. if(0 == encoder->private_->verify.decoder) {
  90119. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90120. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90121. }
  90122. if(FLAC__stream_decoder_init_stream(encoder->private_->verify.decoder, verify_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, verify_write_callback_, verify_metadata_callback_, verify_error_callback_, /*client_data=*/encoder) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
  90123. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90124. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90125. }
  90126. }
  90127. encoder->private_->verify.error_stats.absolute_sample = 0;
  90128. encoder->private_->verify.error_stats.frame_number = 0;
  90129. encoder->private_->verify.error_stats.channel = 0;
  90130. encoder->private_->verify.error_stats.sample = 0;
  90131. encoder->private_->verify.error_stats.expected = 0;
  90132. encoder->private_->verify.error_stats.got = 0;
  90133. encoder->private_->first_seekpoint_to_check = 0;
  90134. encoder->private_->samples_written = 0;
  90135. encoder->protected_->streaminfo_offset = 0;
  90136. encoder->protected_->seektable_offset = 0;
  90137. encoder->protected_->audio_offset = 0;
  90138. if(encoder->protected_->verify)
  90139. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90140. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90141. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90142. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90143. }
  90144. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90145. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90146. }
  90147. if(encoder->protected_->verify)
  90148. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90149. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90150. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90151. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90152. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90153. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90154. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90155. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90156. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90157. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90158. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90159. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90160. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90161. if(encoder->protected_->do_md5)
  90162. FLAC__MD5Init(&encoder->private_->md5context);
  90163. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90164. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90165. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90166. }
  90167. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90168. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90169. }
  90170. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90171. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90172. if(!metadata_has_vorbis_comment) {
  90173. FLAC__StreamMetadata vorbis_comment;
  90174. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90175. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90176. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90177. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90178. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90179. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90180. vorbis_comment.data.vorbis_comment.comments = 0;
  90181. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90182. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90183. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90184. }
  90185. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90186. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90187. }
  90188. }
  90189. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90190. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90191. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90192. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90193. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90194. }
  90195. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90196. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90197. }
  90198. }
  90199. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &encoder->protected_->audio_offset, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) { /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get the offset; no error */
  90200. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90201. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90202. }
  90203. if(encoder->protected_->verify)
  90204. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90205. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90206. }
  90207. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90208. FLAC__StreamEncoder *encoder,
  90209. FLAC__StreamEncoderWriteCallback write_callback,
  90210. FLAC__StreamEncoderSeekCallback seek_callback,
  90211. FLAC__StreamEncoderTellCallback tell_callback,
  90212. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90213. void *client_data
  90214. )
  90215. {
  90216. return init_stream_internal_enc(
  90217. encoder,
  90218. 0,
  90219. write_callback,
  90220. seek_callback,
  90221. tell_callback,
  90222. metadata_callback,
  90223. client_data,
  90224. false
  90225. );
  90226. }
  90227. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90228. FLAC__StreamEncoder *encoder,
  90229. FLAC__StreamEncoderReadCallback read_callback,
  90230. FLAC__StreamEncoderWriteCallback write_callback,
  90231. FLAC__StreamEncoderSeekCallback seek_callback,
  90232. FLAC__StreamEncoderTellCallback tell_callback,
  90233. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90234. void *client_data
  90235. )
  90236. {
  90237. return init_stream_internal_enc(
  90238. encoder,
  90239. read_callback,
  90240. write_callback,
  90241. seek_callback,
  90242. tell_callback,
  90243. metadata_callback,
  90244. client_data,
  90245. true
  90246. );
  90247. }
  90248. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90249. FLAC__StreamEncoder *encoder,
  90250. FILE *file,
  90251. FLAC__StreamEncoderProgressCallback progress_callback,
  90252. void *client_data,
  90253. FLAC__bool is_ogg
  90254. )
  90255. {
  90256. FLAC__StreamEncoderInitStatus init_status;
  90257. FLAC__ASSERT(0 != encoder);
  90258. FLAC__ASSERT(0 != file);
  90259. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90260. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90261. if(file == 0) {
  90262. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90263. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90264. }
  90265. if(file == stdout)
  90266. file = get_binary_stdout_(); /* just to be safe */
  90267. encoder->private_->file = file;
  90268. encoder->private_->progress_callback = progress_callback;
  90269. encoder->private_->bytes_written = 0;
  90270. encoder->private_->samples_written = 0;
  90271. encoder->private_->frames_written = 0;
  90272. init_status = init_stream_internal_enc(
  90273. encoder,
  90274. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90275. file_write_callback_,
  90276. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90277. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90278. 0,
  90279. client_data,
  90280. is_ogg
  90281. );
  90282. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90283. return init_status;
  90284. }
  90285. {
  90286. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90287. FLAC__ASSERT(blocksize != 0);
  90288. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90289. }
  90290. return init_status;
  90291. }
  90292. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90293. FLAC__StreamEncoder *encoder,
  90294. FILE *file,
  90295. FLAC__StreamEncoderProgressCallback progress_callback,
  90296. void *client_data
  90297. )
  90298. {
  90299. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90300. }
  90301. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90302. FLAC__StreamEncoder *encoder,
  90303. FILE *file,
  90304. FLAC__StreamEncoderProgressCallback progress_callback,
  90305. void *client_data
  90306. )
  90307. {
  90308. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90309. }
  90310. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90311. FLAC__StreamEncoder *encoder,
  90312. const char *filename,
  90313. FLAC__StreamEncoderProgressCallback progress_callback,
  90314. void *client_data,
  90315. FLAC__bool is_ogg
  90316. )
  90317. {
  90318. FILE *file;
  90319. FLAC__ASSERT(0 != encoder);
  90320. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90321. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90322. file = filename? fopen(filename, "w+b") : stdout;
  90323. if(file == 0) {
  90324. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90325. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90326. }
  90327. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90328. }
  90329. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90330. FLAC__StreamEncoder *encoder,
  90331. const char *filename,
  90332. FLAC__StreamEncoderProgressCallback progress_callback,
  90333. void *client_data
  90334. )
  90335. {
  90336. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90337. }
  90338. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90339. FLAC__StreamEncoder *encoder,
  90340. const char *filename,
  90341. FLAC__StreamEncoderProgressCallback progress_callback,
  90342. void *client_data
  90343. )
  90344. {
  90345. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90346. }
  90347. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90348. {
  90349. FLAC__bool error = false;
  90350. FLAC__ASSERT(0 != encoder);
  90351. FLAC__ASSERT(0 != encoder->private_);
  90352. FLAC__ASSERT(0 != encoder->protected_);
  90353. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90354. return true;
  90355. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90356. if(encoder->private_->current_sample_number != 0) {
  90357. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90358. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90359. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90360. error = true;
  90361. }
  90362. }
  90363. if(encoder->protected_->do_md5)
  90364. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90365. if(!encoder->private_->is_being_deleted) {
  90366. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90367. if(encoder->private_->seek_callback) {
  90368. #if FLAC__HAS_OGG
  90369. if(encoder->private_->is_ogg)
  90370. update_ogg_metadata_(encoder);
  90371. else
  90372. #endif
  90373. update_metadata_(encoder);
  90374. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90375. error = true;
  90376. }
  90377. if(encoder->private_->metadata_callback)
  90378. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90379. }
  90380. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90381. if(!error)
  90382. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90383. error = true;
  90384. }
  90385. }
  90386. if(0 != encoder->private_->file) {
  90387. if(encoder->private_->file != stdout)
  90388. fclose(encoder->private_->file);
  90389. encoder->private_->file = 0;
  90390. }
  90391. #if FLAC__HAS_OGG
  90392. if(encoder->private_->is_ogg)
  90393. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90394. #endif
  90395. free_(encoder);
  90396. set_defaults_enc(encoder);
  90397. if(!error)
  90398. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90399. return !error;
  90400. }
  90401. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90402. {
  90403. FLAC__ASSERT(0 != encoder);
  90404. FLAC__ASSERT(0 != encoder->private_);
  90405. FLAC__ASSERT(0 != encoder->protected_);
  90406. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90407. return false;
  90408. #if FLAC__HAS_OGG
  90409. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90410. return true;
  90411. #else
  90412. (void)value;
  90413. return false;
  90414. #endif
  90415. }
  90416. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90417. {
  90418. FLAC__ASSERT(0 != encoder);
  90419. FLAC__ASSERT(0 != encoder->private_);
  90420. FLAC__ASSERT(0 != encoder->protected_);
  90421. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90422. return false;
  90423. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90424. encoder->protected_->verify = value;
  90425. #endif
  90426. return true;
  90427. }
  90428. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90429. {
  90430. FLAC__ASSERT(0 != encoder);
  90431. FLAC__ASSERT(0 != encoder->private_);
  90432. FLAC__ASSERT(0 != encoder->protected_);
  90433. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90434. return false;
  90435. encoder->protected_->streamable_subset = value;
  90436. return true;
  90437. }
  90438. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90439. {
  90440. FLAC__ASSERT(0 != encoder);
  90441. FLAC__ASSERT(0 != encoder->private_);
  90442. FLAC__ASSERT(0 != encoder->protected_);
  90443. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90444. return false;
  90445. encoder->protected_->do_md5 = value;
  90446. return true;
  90447. }
  90448. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90449. {
  90450. FLAC__ASSERT(0 != encoder);
  90451. FLAC__ASSERT(0 != encoder->private_);
  90452. FLAC__ASSERT(0 != encoder->protected_);
  90453. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90454. return false;
  90455. encoder->protected_->channels = value;
  90456. return true;
  90457. }
  90458. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90459. {
  90460. FLAC__ASSERT(0 != encoder);
  90461. FLAC__ASSERT(0 != encoder->private_);
  90462. FLAC__ASSERT(0 != encoder->protected_);
  90463. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90464. return false;
  90465. encoder->protected_->bits_per_sample = value;
  90466. return true;
  90467. }
  90468. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90469. {
  90470. FLAC__ASSERT(0 != encoder);
  90471. FLAC__ASSERT(0 != encoder->private_);
  90472. FLAC__ASSERT(0 != encoder->protected_);
  90473. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90474. return false;
  90475. encoder->protected_->sample_rate = value;
  90476. return true;
  90477. }
  90478. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90479. {
  90480. FLAC__bool ok = true;
  90481. FLAC__ASSERT(0 != encoder);
  90482. FLAC__ASSERT(0 != encoder->private_);
  90483. FLAC__ASSERT(0 != encoder->protected_);
  90484. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90485. return false;
  90486. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90487. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90488. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90489. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90490. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90491. #if 0
  90492. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90493. #else
  90494. encoder->protected_->num_apodizations = 1;
  90495. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90496. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90497. #endif
  90498. #endif
  90499. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90500. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90501. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90502. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90503. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90504. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90505. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90506. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90507. return ok;
  90508. }
  90509. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90510. {
  90511. FLAC__ASSERT(0 != encoder);
  90512. FLAC__ASSERT(0 != encoder->private_);
  90513. FLAC__ASSERT(0 != encoder->protected_);
  90514. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90515. return false;
  90516. encoder->protected_->blocksize = value;
  90517. return true;
  90518. }
  90519. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90520. {
  90521. FLAC__ASSERT(0 != encoder);
  90522. FLAC__ASSERT(0 != encoder->private_);
  90523. FLAC__ASSERT(0 != encoder->protected_);
  90524. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90525. return false;
  90526. encoder->protected_->do_mid_side_stereo = value;
  90527. return true;
  90528. }
  90529. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90530. {
  90531. FLAC__ASSERT(0 != encoder);
  90532. FLAC__ASSERT(0 != encoder->private_);
  90533. FLAC__ASSERT(0 != encoder->protected_);
  90534. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90535. return false;
  90536. encoder->protected_->loose_mid_side_stereo = value;
  90537. return true;
  90538. }
  90539. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90540. {
  90541. FLAC__ASSERT(0 != encoder);
  90542. FLAC__ASSERT(0 != encoder->private_);
  90543. FLAC__ASSERT(0 != encoder->protected_);
  90544. FLAC__ASSERT(0 != specification);
  90545. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90546. return false;
  90547. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90548. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90549. #else
  90550. encoder->protected_->num_apodizations = 0;
  90551. while(1) {
  90552. const char *s = strchr(specification, ';');
  90553. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90554. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90555. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90556. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90557. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90558. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90559. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90560. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90561. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90562. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90563. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90564. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90565. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90566. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90567. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90568. if (stddev > 0.0 && stddev <= 0.5) {
  90569. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90570. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90571. }
  90572. }
  90573. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90574. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90575. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90576. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90577. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90578. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90579. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90580. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90581. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90582. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90583. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90584. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90585. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90586. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90587. if (p >= 0.0 && p <= 1.0) {
  90588. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90589. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90590. }
  90591. }
  90592. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90593. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90594. if (encoder->protected_->num_apodizations == 32)
  90595. break;
  90596. if (s)
  90597. specification = s+1;
  90598. else
  90599. break;
  90600. }
  90601. if(encoder->protected_->num_apodizations == 0) {
  90602. encoder->protected_->num_apodizations = 1;
  90603. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90604. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90605. }
  90606. #endif
  90607. return true;
  90608. }
  90609. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90610. {
  90611. FLAC__ASSERT(0 != encoder);
  90612. FLAC__ASSERT(0 != encoder->private_);
  90613. FLAC__ASSERT(0 != encoder->protected_);
  90614. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90615. return false;
  90616. encoder->protected_->max_lpc_order = value;
  90617. return true;
  90618. }
  90619. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90620. {
  90621. FLAC__ASSERT(0 != encoder);
  90622. FLAC__ASSERT(0 != encoder->private_);
  90623. FLAC__ASSERT(0 != encoder->protected_);
  90624. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90625. return false;
  90626. encoder->protected_->qlp_coeff_precision = value;
  90627. return true;
  90628. }
  90629. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90630. {
  90631. FLAC__ASSERT(0 != encoder);
  90632. FLAC__ASSERT(0 != encoder->private_);
  90633. FLAC__ASSERT(0 != encoder->protected_);
  90634. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90635. return false;
  90636. encoder->protected_->do_qlp_coeff_prec_search = value;
  90637. return true;
  90638. }
  90639. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90640. {
  90641. FLAC__ASSERT(0 != encoder);
  90642. FLAC__ASSERT(0 != encoder->private_);
  90643. FLAC__ASSERT(0 != encoder->protected_);
  90644. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90645. return false;
  90646. #if 0
  90647. encoder->protected_->do_escape_coding = value;
  90648. #else
  90649. (void)value;
  90650. #endif
  90651. return true;
  90652. }
  90653. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90654. {
  90655. FLAC__ASSERT(0 != encoder);
  90656. FLAC__ASSERT(0 != encoder->private_);
  90657. FLAC__ASSERT(0 != encoder->protected_);
  90658. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90659. return false;
  90660. encoder->protected_->do_exhaustive_model_search = value;
  90661. return true;
  90662. }
  90663. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90664. {
  90665. FLAC__ASSERT(0 != encoder);
  90666. FLAC__ASSERT(0 != encoder->private_);
  90667. FLAC__ASSERT(0 != encoder->protected_);
  90668. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90669. return false;
  90670. encoder->protected_->min_residual_partition_order = value;
  90671. return true;
  90672. }
  90673. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90674. {
  90675. FLAC__ASSERT(0 != encoder);
  90676. FLAC__ASSERT(0 != encoder->private_);
  90677. FLAC__ASSERT(0 != encoder->protected_);
  90678. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90679. return false;
  90680. encoder->protected_->max_residual_partition_order = value;
  90681. return true;
  90682. }
  90683. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  90684. {
  90685. FLAC__ASSERT(0 != encoder);
  90686. FLAC__ASSERT(0 != encoder->private_);
  90687. FLAC__ASSERT(0 != encoder->protected_);
  90688. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90689. return false;
  90690. #if 0
  90691. encoder->protected_->rice_parameter_search_dist = value;
  90692. #else
  90693. (void)value;
  90694. #endif
  90695. return true;
  90696. }
  90697. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  90698. {
  90699. FLAC__ASSERT(0 != encoder);
  90700. FLAC__ASSERT(0 != encoder->private_);
  90701. FLAC__ASSERT(0 != encoder->protected_);
  90702. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90703. return false;
  90704. encoder->protected_->total_samples_estimate = value;
  90705. return true;
  90706. }
  90707. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  90708. {
  90709. FLAC__ASSERT(0 != encoder);
  90710. FLAC__ASSERT(0 != encoder->private_);
  90711. FLAC__ASSERT(0 != encoder->protected_);
  90712. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90713. return false;
  90714. if(0 == metadata)
  90715. num_blocks = 0;
  90716. if(0 == num_blocks)
  90717. metadata = 0;
  90718. if(encoder->protected_->metadata) {
  90719. free(encoder->protected_->metadata);
  90720. encoder->protected_->metadata = 0;
  90721. encoder->protected_->num_metadata_blocks = 0;
  90722. }
  90723. if(num_blocks) {
  90724. FLAC__StreamMetadata **m;
  90725. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  90726. return false;
  90727. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  90728. encoder->protected_->metadata = m;
  90729. encoder->protected_->num_metadata_blocks = num_blocks;
  90730. }
  90731. #if FLAC__HAS_OGG
  90732. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  90733. return false;
  90734. #endif
  90735. return true;
  90736. }
  90737. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90738. {
  90739. FLAC__ASSERT(0 != encoder);
  90740. FLAC__ASSERT(0 != encoder->private_);
  90741. FLAC__ASSERT(0 != encoder->protected_);
  90742. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90743. return false;
  90744. encoder->private_->disable_constant_subframes = value;
  90745. return true;
  90746. }
  90747. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90748. {
  90749. FLAC__ASSERT(0 != encoder);
  90750. FLAC__ASSERT(0 != encoder->private_);
  90751. FLAC__ASSERT(0 != encoder->protected_);
  90752. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90753. return false;
  90754. encoder->private_->disable_fixed_subframes = value;
  90755. return true;
  90756. }
  90757. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90758. {
  90759. FLAC__ASSERT(0 != encoder);
  90760. FLAC__ASSERT(0 != encoder->private_);
  90761. FLAC__ASSERT(0 != encoder->protected_);
  90762. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90763. return false;
  90764. encoder->private_->disable_verbatim_subframes = value;
  90765. return true;
  90766. }
  90767. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  90768. {
  90769. FLAC__ASSERT(0 != encoder);
  90770. FLAC__ASSERT(0 != encoder->private_);
  90771. FLAC__ASSERT(0 != encoder->protected_);
  90772. return encoder->protected_->state;
  90773. }
  90774. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  90775. {
  90776. FLAC__ASSERT(0 != encoder);
  90777. FLAC__ASSERT(0 != encoder->private_);
  90778. FLAC__ASSERT(0 != encoder->protected_);
  90779. if(encoder->protected_->verify)
  90780. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  90781. else
  90782. return FLAC__STREAM_DECODER_UNINITIALIZED;
  90783. }
  90784. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  90785. {
  90786. FLAC__ASSERT(0 != encoder);
  90787. FLAC__ASSERT(0 != encoder->private_);
  90788. FLAC__ASSERT(0 != encoder->protected_);
  90789. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  90790. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  90791. else
  90792. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  90793. }
  90794. FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
  90795. {
  90796. FLAC__ASSERT(0 != encoder);
  90797. FLAC__ASSERT(0 != encoder->private_);
  90798. FLAC__ASSERT(0 != encoder->protected_);
  90799. if(0 != absolute_sample)
  90800. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  90801. if(0 != frame_number)
  90802. *frame_number = encoder->private_->verify.error_stats.frame_number;
  90803. if(0 != channel)
  90804. *channel = encoder->private_->verify.error_stats.channel;
  90805. if(0 != sample)
  90806. *sample = encoder->private_->verify.error_stats.sample;
  90807. if(0 != expected)
  90808. *expected = encoder->private_->verify.error_stats.expected;
  90809. if(0 != got)
  90810. *got = encoder->private_->verify.error_stats.got;
  90811. }
  90812. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  90813. {
  90814. FLAC__ASSERT(0 != encoder);
  90815. FLAC__ASSERT(0 != encoder->private_);
  90816. FLAC__ASSERT(0 != encoder->protected_);
  90817. return encoder->protected_->verify;
  90818. }
  90819. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  90820. {
  90821. FLAC__ASSERT(0 != encoder);
  90822. FLAC__ASSERT(0 != encoder->private_);
  90823. FLAC__ASSERT(0 != encoder->protected_);
  90824. return encoder->protected_->streamable_subset;
  90825. }
  90826. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  90827. {
  90828. FLAC__ASSERT(0 != encoder);
  90829. FLAC__ASSERT(0 != encoder->private_);
  90830. FLAC__ASSERT(0 != encoder->protected_);
  90831. return encoder->protected_->do_md5;
  90832. }
  90833. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  90834. {
  90835. FLAC__ASSERT(0 != encoder);
  90836. FLAC__ASSERT(0 != encoder->private_);
  90837. FLAC__ASSERT(0 != encoder->protected_);
  90838. return encoder->protected_->channels;
  90839. }
  90840. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  90841. {
  90842. FLAC__ASSERT(0 != encoder);
  90843. FLAC__ASSERT(0 != encoder->private_);
  90844. FLAC__ASSERT(0 != encoder->protected_);
  90845. return encoder->protected_->bits_per_sample;
  90846. }
  90847. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  90848. {
  90849. FLAC__ASSERT(0 != encoder);
  90850. FLAC__ASSERT(0 != encoder->private_);
  90851. FLAC__ASSERT(0 != encoder->protected_);
  90852. return encoder->protected_->sample_rate;
  90853. }
  90854. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  90855. {
  90856. FLAC__ASSERT(0 != encoder);
  90857. FLAC__ASSERT(0 != encoder->private_);
  90858. FLAC__ASSERT(0 != encoder->protected_);
  90859. return encoder->protected_->blocksize;
  90860. }
  90861. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  90862. {
  90863. FLAC__ASSERT(0 != encoder);
  90864. FLAC__ASSERT(0 != encoder->private_);
  90865. FLAC__ASSERT(0 != encoder->protected_);
  90866. return encoder->protected_->do_mid_side_stereo;
  90867. }
  90868. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  90869. {
  90870. FLAC__ASSERT(0 != encoder);
  90871. FLAC__ASSERT(0 != encoder->private_);
  90872. FLAC__ASSERT(0 != encoder->protected_);
  90873. return encoder->protected_->loose_mid_side_stereo;
  90874. }
  90875. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  90876. {
  90877. FLAC__ASSERT(0 != encoder);
  90878. FLAC__ASSERT(0 != encoder->private_);
  90879. FLAC__ASSERT(0 != encoder->protected_);
  90880. return encoder->protected_->max_lpc_order;
  90881. }
  90882. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  90883. {
  90884. FLAC__ASSERT(0 != encoder);
  90885. FLAC__ASSERT(0 != encoder->private_);
  90886. FLAC__ASSERT(0 != encoder->protected_);
  90887. return encoder->protected_->qlp_coeff_precision;
  90888. }
  90889. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  90890. {
  90891. FLAC__ASSERT(0 != encoder);
  90892. FLAC__ASSERT(0 != encoder->private_);
  90893. FLAC__ASSERT(0 != encoder->protected_);
  90894. return encoder->protected_->do_qlp_coeff_prec_search;
  90895. }
  90896. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  90897. {
  90898. FLAC__ASSERT(0 != encoder);
  90899. FLAC__ASSERT(0 != encoder->private_);
  90900. FLAC__ASSERT(0 != encoder->protected_);
  90901. return encoder->protected_->do_escape_coding;
  90902. }
  90903. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  90904. {
  90905. FLAC__ASSERT(0 != encoder);
  90906. FLAC__ASSERT(0 != encoder->private_);
  90907. FLAC__ASSERT(0 != encoder->protected_);
  90908. return encoder->protected_->do_exhaustive_model_search;
  90909. }
  90910. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  90911. {
  90912. FLAC__ASSERT(0 != encoder);
  90913. FLAC__ASSERT(0 != encoder->private_);
  90914. FLAC__ASSERT(0 != encoder->protected_);
  90915. return encoder->protected_->min_residual_partition_order;
  90916. }
  90917. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  90918. {
  90919. FLAC__ASSERT(0 != encoder);
  90920. FLAC__ASSERT(0 != encoder->private_);
  90921. FLAC__ASSERT(0 != encoder->protected_);
  90922. return encoder->protected_->max_residual_partition_order;
  90923. }
  90924. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  90925. {
  90926. FLAC__ASSERT(0 != encoder);
  90927. FLAC__ASSERT(0 != encoder->private_);
  90928. FLAC__ASSERT(0 != encoder->protected_);
  90929. return encoder->protected_->rice_parameter_search_dist;
  90930. }
  90931. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  90932. {
  90933. FLAC__ASSERT(0 != encoder);
  90934. FLAC__ASSERT(0 != encoder->private_);
  90935. FLAC__ASSERT(0 != encoder->protected_);
  90936. return encoder->protected_->total_samples_estimate;
  90937. }
  90938. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  90939. {
  90940. unsigned i, j = 0, channel;
  90941. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  90942. FLAC__ASSERT(0 != encoder);
  90943. FLAC__ASSERT(0 != encoder->private_);
  90944. FLAC__ASSERT(0 != encoder->protected_);
  90945. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  90946. do {
  90947. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  90948. if(encoder->protected_->verify)
  90949. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  90950. for(channel = 0; channel < channels; channel++)
  90951. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  90952. if(encoder->protected_->do_mid_side_stereo) {
  90953. FLAC__ASSERT(channels == 2);
  90954. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  90955. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  90956. encoder->private_->integer_signal_mid_side[0][i] = (buffer[0][j] + buffer[1][j]) >> 1; /* NOTE: not the same as 'mid = (buffer[0][j] + buffer[1][j]) / 2' ! */
  90957. }
  90958. }
  90959. else
  90960. j += n;
  90961. encoder->private_->current_sample_number += n;
  90962. if(encoder->private_->current_sample_number > blocksize) {
  90963. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  90964. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  90965. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  90966. return false;
  90967. for(channel = 0; channel < channels; channel++)
  90968. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  90969. if(encoder->protected_->do_mid_side_stereo) {
  90970. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  90971. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  90972. }
  90973. encoder->private_->current_sample_number = 1;
  90974. }
  90975. } while(j < samples);
  90976. return true;
  90977. }
  90978. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  90979. {
  90980. unsigned i, j, k, channel;
  90981. FLAC__int32 x, mid, side;
  90982. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  90983. FLAC__ASSERT(0 != encoder);
  90984. FLAC__ASSERT(0 != encoder->private_);
  90985. FLAC__ASSERT(0 != encoder->protected_);
  90986. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  90987. j = k = 0;
  90988. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  90989. do {
  90990. if(encoder->protected_->verify)
  90991. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  90992. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  90993. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  90994. x = buffer[k++];
  90995. encoder->private_->integer_signal[1][i] = x;
  90996. mid += x;
  90997. side -= x;
  90998. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  90999. encoder->private_->integer_signal_mid_side[1][i] = side;
  91000. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91001. }
  91002. encoder->private_->current_sample_number = i;
  91003. if(i > blocksize) {
  91004. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91005. return false;
  91006. /* move unprocessed overread samples to beginnings of arrays */
  91007. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91008. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91009. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91010. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91011. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91012. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91013. encoder->private_->current_sample_number = 1;
  91014. }
  91015. } while(j < samples);
  91016. }
  91017. else {
  91018. do {
  91019. if(encoder->protected_->verify)
  91020. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91021. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91022. for(channel = 0; channel < channels; channel++)
  91023. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91024. }
  91025. encoder->private_->current_sample_number = i;
  91026. if(i > blocksize) {
  91027. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91028. return false;
  91029. /* move unprocessed overread samples to beginnings of arrays */
  91030. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91031. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91032. for(channel = 0; channel < channels; channel++)
  91033. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91034. encoder->private_->current_sample_number = 1;
  91035. }
  91036. } while(j < samples);
  91037. }
  91038. return true;
  91039. }
  91040. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91041. {
  91042. FLAC__ASSERT(0 != encoder);
  91043. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91044. encoder->protected_->verify = true;
  91045. #else
  91046. encoder->protected_->verify = false;
  91047. #endif
  91048. encoder->protected_->streamable_subset = true;
  91049. encoder->protected_->do_md5 = true;
  91050. encoder->protected_->do_mid_side_stereo = false;
  91051. encoder->protected_->loose_mid_side_stereo = false;
  91052. encoder->protected_->channels = 2;
  91053. encoder->protected_->bits_per_sample = 16;
  91054. encoder->protected_->sample_rate = 44100;
  91055. encoder->protected_->blocksize = 0;
  91056. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91057. encoder->protected_->num_apodizations = 1;
  91058. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91059. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91060. #endif
  91061. encoder->protected_->max_lpc_order = 0;
  91062. encoder->protected_->qlp_coeff_precision = 0;
  91063. encoder->protected_->do_qlp_coeff_prec_search = false;
  91064. encoder->protected_->do_exhaustive_model_search = false;
  91065. encoder->protected_->do_escape_coding = false;
  91066. encoder->protected_->min_residual_partition_order = 0;
  91067. encoder->protected_->max_residual_partition_order = 0;
  91068. encoder->protected_->rice_parameter_search_dist = 0;
  91069. encoder->protected_->total_samples_estimate = 0;
  91070. encoder->protected_->metadata = 0;
  91071. encoder->protected_->num_metadata_blocks = 0;
  91072. encoder->private_->seek_table = 0;
  91073. encoder->private_->disable_constant_subframes = false;
  91074. encoder->private_->disable_fixed_subframes = false;
  91075. encoder->private_->disable_verbatim_subframes = false;
  91076. #if FLAC__HAS_OGG
  91077. encoder->private_->is_ogg = false;
  91078. #endif
  91079. encoder->private_->read_callback = 0;
  91080. encoder->private_->write_callback = 0;
  91081. encoder->private_->seek_callback = 0;
  91082. encoder->private_->tell_callback = 0;
  91083. encoder->private_->metadata_callback = 0;
  91084. encoder->private_->progress_callback = 0;
  91085. encoder->private_->client_data = 0;
  91086. #if FLAC__HAS_OGG
  91087. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91088. #endif
  91089. }
  91090. void free_(FLAC__StreamEncoder *encoder)
  91091. {
  91092. unsigned i, channel;
  91093. FLAC__ASSERT(0 != encoder);
  91094. if(encoder->protected_->metadata) {
  91095. free(encoder->protected_->metadata);
  91096. encoder->protected_->metadata = 0;
  91097. encoder->protected_->num_metadata_blocks = 0;
  91098. }
  91099. for(i = 0; i < encoder->protected_->channels; i++) {
  91100. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91101. free(encoder->private_->integer_signal_unaligned[i]);
  91102. encoder->private_->integer_signal_unaligned[i] = 0;
  91103. }
  91104. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91105. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91106. free(encoder->private_->real_signal_unaligned[i]);
  91107. encoder->private_->real_signal_unaligned[i] = 0;
  91108. }
  91109. #endif
  91110. }
  91111. for(i = 0; i < 2; i++) {
  91112. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91113. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91114. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91115. }
  91116. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91117. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91118. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91119. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91120. }
  91121. #endif
  91122. }
  91123. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91124. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91125. if(0 != encoder->private_->window_unaligned[i]) {
  91126. free(encoder->private_->window_unaligned[i]);
  91127. encoder->private_->window_unaligned[i] = 0;
  91128. }
  91129. }
  91130. if(0 != encoder->private_->windowed_signal_unaligned) {
  91131. free(encoder->private_->windowed_signal_unaligned);
  91132. encoder->private_->windowed_signal_unaligned = 0;
  91133. }
  91134. #endif
  91135. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91136. for(i = 0; i < 2; i++) {
  91137. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91138. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91139. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91140. }
  91141. }
  91142. }
  91143. for(channel = 0; channel < 2; channel++) {
  91144. for(i = 0; i < 2; i++) {
  91145. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91146. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91147. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91148. }
  91149. }
  91150. }
  91151. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91152. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91153. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91154. }
  91155. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91156. free(encoder->private_->raw_bits_per_partition_unaligned);
  91157. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91158. }
  91159. if(encoder->protected_->verify) {
  91160. for(i = 0; i < encoder->protected_->channels; i++) {
  91161. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91162. free(encoder->private_->verify.input_fifo.data[i]);
  91163. encoder->private_->verify.input_fifo.data[i] = 0;
  91164. }
  91165. }
  91166. }
  91167. FLAC__bitwriter_free(encoder->private_->frame);
  91168. }
  91169. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91170. {
  91171. FLAC__bool ok;
  91172. unsigned i, channel;
  91173. FLAC__ASSERT(new_blocksize > 0);
  91174. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91175. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91176. if(new_blocksize <= encoder->private_->input_capacity)
  91177. return true;
  91178. ok = true;
  91179. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91180. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91181. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91182. encoder->private_->integer_signal[i] += 4;
  91183. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91184. #if 0 /* @@@ currently unused */
  91185. if(encoder->protected_->max_lpc_order > 0)
  91186. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91187. #endif
  91188. #endif
  91189. }
  91190. for(i = 0; ok && i < 2; i++) {
  91191. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_mid_side_unaligned[i], &encoder->private_->integer_signal_mid_side[i]);
  91192. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91193. encoder->private_->integer_signal_mid_side[i] += 4;
  91194. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91195. #if 0 /* @@@ currently unused */
  91196. if(encoder->protected_->max_lpc_order > 0)
  91197. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_mid_side_unaligned[i], &encoder->private_->real_signal_mid_side[i]);
  91198. #endif
  91199. #endif
  91200. }
  91201. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91202. if(ok && encoder->protected_->max_lpc_order > 0) {
  91203. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91204. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91205. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91206. }
  91207. #endif
  91208. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91209. for(i = 0; ok && i < 2; i++) {
  91210. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91211. }
  91212. }
  91213. for(channel = 0; ok && channel < 2; channel++) {
  91214. for(i = 0; ok && i < 2; i++) {
  91215. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_mid_side_unaligned[channel][i], &encoder->private_->residual_workspace_mid_side[channel][i]);
  91216. }
  91217. }
  91218. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91219. if(encoder->protected_->do_escape_coding)
  91220. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91221. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91222. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91223. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91224. switch(encoder->protected_->apodizations[i].type) {
  91225. case FLAC__APODIZATION_BARTLETT:
  91226. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91227. break;
  91228. case FLAC__APODIZATION_BARTLETT_HANN:
  91229. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91230. break;
  91231. case FLAC__APODIZATION_BLACKMAN:
  91232. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91233. break;
  91234. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91235. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91236. break;
  91237. case FLAC__APODIZATION_CONNES:
  91238. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91239. break;
  91240. case FLAC__APODIZATION_FLATTOP:
  91241. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91242. break;
  91243. case FLAC__APODIZATION_GAUSS:
  91244. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91245. break;
  91246. case FLAC__APODIZATION_HAMMING:
  91247. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91248. break;
  91249. case FLAC__APODIZATION_HANN:
  91250. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91251. break;
  91252. case FLAC__APODIZATION_KAISER_BESSEL:
  91253. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91254. break;
  91255. case FLAC__APODIZATION_NUTTALL:
  91256. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91257. break;
  91258. case FLAC__APODIZATION_RECTANGLE:
  91259. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91260. break;
  91261. case FLAC__APODIZATION_TRIANGLE:
  91262. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91263. break;
  91264. case FLAC__APODIZATION_TUKEY:
  91265. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91266. break;
  91267. case FLAC__APODIZATION_WELCH:
  91268. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91269. break;
  91270. default:
  91271. FLAC__ASSERT(0);
  91272. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91273. break;
  91274. }
  91275. }
  91276. }
  91277. #endif
  91278. if(ok)
  91279. encoder->private_->input_capacity = new_blocksize;
  91280. else
  91281. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91282. return ok;
  91283. }
  91284. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91285. {
  91286. const FLAC__byte *buffer;
  91287. size_t bytes;
  91288. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91289. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91290. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91291. return false;
  91292. }
  91293. if(encoder->protected_->verify) {
  91294. encoder->private_->verify.output.data = buffer;
  91295. encoder->private_->verify.output.bytes = bytes;
  91296. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91297. encoder->private_->verify.needs_magic_hack = true;
  91298. }
  91299. else {
  91300. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91301. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91302. FLAC__bitwriter_clear(encoder->private_->frame);
  91303. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91304. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91305. return false;
  91306. }
  91307. }
  91308. }
  91309. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91310. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91311. FLAC__bitwriter_clear(encoder->private_->frame);
  91312. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91313. return false;
  91314. }
  91315. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91316. FLAC__bitwriter_clear(encoder->private_->frame);
  91317. if(samples > 0) {
  91318. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91319. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91320. }
  91321. return true;
  91322. }
  91323. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91324. {
  91325. FLAC__StreamEncoderWriteStatus status;
  91326. FLAC__uint64 output_position = 0;
  91327. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91328. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91329. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91330. }
  91331. if(samples == 0) {
  91332. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91333. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91334. encoder->protected_->streaminfo_offset = output_position;
  91335. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91336. encoder->protected_->seektable_offset = output_position;
  91337. }
  91338. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91339. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91340. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91341. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91342. FLAC__uint64 test_sample;
  91343. unsigned i;
  91344. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91345. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91346. if(test_sample > frame_last_sample) {
  91347. break;
  91348. }
  91349. else if(test_sample >= frame_first_sample) {
  91350. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91351. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91352. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91353. encoder->private_->first_seekpoint_to_check++;
  91354. }
  91355. else {
  91356. encoder->private_->first_seekpoint_to_check++;
  91357. }
  91358. }
  91359. }
  91360. #if FLAC__HAS_OGG
  91361. if(encoder->private_->is_ogg) {
  91362. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91363. &encoder->protected_->ogg_encoder_aspect,
  91364. buffer,
  91365. bytes,
  91366. samples,
  91367. encoder->private_->current_frame_number,
  91368. is_last_block,
  91369. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91370. encoder,
  91371. encoder->private_->client_data
  91372. );
  91373. }
  91374. else
  91375. #endif
  91376. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91377. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91378. encoder->private_->bytes_written += bytes;
  91379. encoder->private_->samples_written += samples;
  91380. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91381. }
  91382. else
  91383. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91384. return status;
  91385. }
  91386. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91387. {
  91388. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91389. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91390. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91391. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91392. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91393. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91394. FLAC__StreamEncoderSeekStatus seek_status;
  91395. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91396. {
  91397. const unsigned md5_offset =
  91398. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91399. (
  91400. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91401. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91402. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91403. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91404. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91405. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91406. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91407. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91408. ) / 8;
  91409. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91410. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91411. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91412. return;
  91413. }
  91414. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91415. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91416. return;
  91417. }
  91418. }
  91419. {
  91420. const unsigned total_samples_byte_offset =
  91421. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91422. (
  91423. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91424. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91425. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91426. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91427. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91428. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91429. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91430. - 4
  91431. ) / 8;
  91432. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91433. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91434. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91435. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91436. b[4] = (FLAC__byte)(samples & 0xFF);
  91437. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + total_samples_byte_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91438. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91439. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91440. return;
  91441. }
  91442. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91443. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91444. return;
  91445. }
  91446. }
  91447. {
  91448. const unsigned min_framesize_offset =
  91449. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91450. (
  91451. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91452. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91453. ) / 8;
  91454. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91455. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91456. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91457. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91458. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91459. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91460. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + min_framesize_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91461. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91462. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91463. return;
  91464. }
  91465. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91466. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91467. return;
  91468. }
  91469. }
  91470. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91471. unsigned i;
  91472. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91473. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91474. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->seektable_offset + FLAC__STREAM_METADATA_HEADER_LENGTH, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91475. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91476. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91477. return;
  91478. }
  91479. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91480. FLAC__uint64 xx;
  91481. unsigned x;
  91482. xx = encoder->private_->seek_table->points[i].sample_number;
  91483. b[7] = (FLAC__byte)xx; xx >>= 8;
  91484. b[6] = (FLAC__byte)xx; xx >>= 8;
  91485. b[5] = (FLAC__byte)xx; xx >>= 8;
  91486. b[4] = (FLAC__byte)xx; xx >>= 8;
  91487. b[3] = (FLAC__byte)xx; xx >>= 8;
  91488. b[2] = (FLAC__byte)xx; xx >>= 8;
  91489. b[1] = (FLAC__byte)xx; xx >>= 8;
  91490. b[0] = (FLAC__byte)xx; xx >>= 8;
  91491. xx = encoder->private_->seek_table->points[i].stream_offset;
  91492. b[15] = (FLAC__byte)xx; xx >>= 8;
  91493. b[14] = (FLAC__byte)xx; xx >>= 8;
  91494. b[13] = (FLAC__byte)xx; xx >>= 8;
  91495. b[12] = (FLAC__byte)xx; xx >>= 8;
  91496. b[11] = (FLAC__byte)xx; xx >>= 8;
  91497. b[10] = (FLAC__byte)xx; xx >>= 8;
  91498. b[9] = (FLAC__byte)xx; xx >>= 8;
  91499. b[8] = (FLAC__byte)xx; xx >>= 8;
  91500. x = encoder->private_->seek_table->points[i].frame_samples;
  91501. b[17] = (FLAC__byte)x; x >>= 8;
  91502. b[16] = (FLAC__byte)x; x >>= 8;
  91503. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91504. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91505. return;
  91506. }
  91507. }
  91508. }
  91509. }
  91510. #if FLAC__HAS_OGG
  91511. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91512. {
  91513. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91514. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91515. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91516. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91517. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91518. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91519. FLAC__STREAM_SYNC_LENGTH
  91520. ;
  91521. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91522. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91523. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91524. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91525. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91526. ogg_page page;
  91527. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91528. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91529. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91530. return;
  91531. simple_ogg_page__init(&page);
  91532. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91533. simple_ogg_page__clear(&page);
  91534. return; /* state already set */
  91535. }
  91536. {
  91537. const unsigned md5_offset =
  91538. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91539. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91540. (
  91541. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91542. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91543. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91544. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91545. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91546. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91547. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91548. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91549. ) / 8;
  91550. if(md5_offset + 16 > (unsigned)page.body_len) {
  91551. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91552. simple_ogg_page__clear(&page);
  91553. return;
  91554. }
  91555. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91556. }
  91557. {
  91558. const unsigned total_samples_byte_offset =
  91559. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91560. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91561. (
  91562. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91563. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91564. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91565. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91566. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91567. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91568. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91569. - 4
  91570. ) / 8;
  91571. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91572. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91573. simple_ogg_page__clear(&page);
  91574. return;
  91575. }
  91576. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91577. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91578. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91579. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91580. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91581. b[4] = (FLAC__byte)(samples & 0xFF);
  91582. memcpy(page.body + total_samples_byte_offset, b, 5);
  91583. }
  91584. {
  91585. const unsigned min_framesize_offset =
  91586. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91587. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91588. (
  91589. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91590. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91591. ) / 8;
  91592. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91593. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91594. simple_ogg_page__clear(&page);
  91595. return;
  91596. }
  91597. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91598. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91599. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91600. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91601. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91602. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91603. memcpy(page.body + min_framesize_offset, b, 6);
  91604. }
  91605. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91606. simple_ogg_page__clear(&page);
  91607. return; /* state already set */
  91608. }
  91609. simple_ogg_page__clear(&page);
  91610. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91611. unsigned i;
  91612. FLAC__byte *p;
  91613. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91614. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91615. simple_ogg_page__init(&page);
  91616. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91617. simple_ogg_page__clear(&page);
  91618. return; /* state already set */
  91619. }
  91620. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91621. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91622. simple_ogg_page__clear(&page);
  91623. return;
  91624. }
  91625. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91626. FLAC__uint64 xx;
  91627. unsigned x;
  91628. xx = encoder->private_->seek_table->points[i].sample_number;
  91629. b[7] = (FLAC__byte)xx; xx >>= 8;
  91630. b[6] = (FLAC__byte)xx; xx >>= 8;
  91631. b[5] = (FLAC__byte)xx; xx >>= 8;
  91632. b[4] = (FLAC__byte)xx; xx >>= 8;
  91633. b[3] = (FLAC__byte)xx; xx >>= 8;
  91634. b[2] = (FLAC__byte)xx; xx >>= 8;
  91635. b[1] = (FLAC__byte)xx; xx >>= 8;
  91636. b[0] = (FLAC__byte)xx; xx >>= 8;
  91637. xx = encoder->private_->seek_table->points[i].stream_offset;
  91638. b[15] = (FLAC__byte)xx; xx >>= 8;
  91639. b[14] = (FLAC__byte)xx; xx >>= 8;
  91640. b[13] = (FLAC__byte)xx; xx >>= 8;
  91641. b[12] = (FLAC__byte)xx; xx >>= 8;
  91642. b[11] = (FLAC__byte)xx; xx >>= 8;
  91643. b[10] = (FLAC__byte)xx; xx >>= 8;
  91644. b[9] = (FLAC__byte)xx; xx >>= 8;
  91645. b[8] = (FLAC__byte)xx; xx >>= 8;
  91646. x = encoder->private_->seek_table->points[i].frame_samples;
  91647. b[17] = (FLAC__byte)x; x >>= 8;
  91648. b[16] = (FLAC__byte)x; x >>= 8;
  91649. memcpy(p, b, 18);
  91650. }
  91651. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91652. simple_ogg_page__clear(&page);
  91653. return; /* state already set */
  91654. }
  91655. simple_ogg_page__clear(&page);
  91656. }
  91657. }
  91658. #endif
  91659. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91660. {
  91661. FLAC__uint16 crc;
  91662. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91663. if(encoder->protected_->do_md5 && !FLAC__MD5Accumulate(&encoder->private_->md5context, (const FLAC__int32 * const *)encoder->private_->integer_signal, encoder->protected_->channels, encoder->protected_->blocksize, (encoder->protected_->bits_per_sample+7) / 8)) {
  91664. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91665. return false;
  91666. }
  91667. if(!process_subframes_(encoder, is_fractional_block)) {
  91668. return false;
  91669. }
  91670. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91671. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91672. return false;
  91673. }
  91674. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91675. if(
  91676. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91677. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91678. ) {
  91679. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91680. return false;
  91681. }
  91682. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  91683. return false;
  91684. }
  91685. encoder->private_->current_sample_number = 0;
  91686. encoder->private_->current_frame_number++;
  91687. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  91688. return true;
  91689. }
  91690. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  91691. {
  91692. FLAC__FrameHeader frame_header;
  91693. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  91694. FLAC__bool do_independent, do_mid_side;
  91695. if(is_fractional_block) {
  91696. max_partition_order = 0;
  91697. }
  91698. else {
  91699. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  91700. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  91701. }
  91702. min_partition_order = min(min_partition_order, max_partition_order);
  91703. frame_header.blocksize = encoder->protected_->blocksize;
  91704. frame_header.sample_rate = encoder->protected_->sample_rate;
  91705. frame_header.channels = encoder->protected_->channels;
  91706. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  91707. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  91708. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  91709. frame_header.number.frame_number = encoder->private_->current_frame_number;
  91710. if(encoder->protected_->do_mid_side_stereo) {
  91711. if(encoder->protected_->loose_mid_side_stereo) {
  91712. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  91713. do_independent = true;
  91714. do_mid_side = true;
  91715. }
  91716. else {
  91717. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  91718. do_mid_side = !do_independent;
  91719. }
  91720. }
  91721. else {
  91722. do_independent = true;
  91723. do_mid_side = true;
  91724. }
  91725. }
  91726. else {
  91727. do_independent = true;
  91728. do_mid_side = false;
  91729. }
  91730. FLAC__ASSERT(do_independent || do_mid_side);
  91731. if(do_independent) {
  91732. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91733. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  91734. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  91735. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  91736. }
  91737. }
  91738. if(do_mid_side) {
  91739. FLAC__ASSERT(encoder->protected_->channels == 2);
  91740. for(channel = 0; channel < 2; channel++) {
  91741. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  91742. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  91743. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  91744. }
  91745. }
  91746. if(do_independent) {
  91747. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91748. if(!
  91749. process_subframe_(
  91750. encoder,
  91751. min_partition_order,
  91752. max_partition_order,
  91753. &frame_header,
  91754. encoder->private_->subframe_bps[channel],
  91755. encoder->private_->integer_signal[channel],
  91756. encoder->private_->subframe_workspace_ptr[channel],
  91757. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  91758. encoder->private_->residual_workspace[channel],
  91759. encoder->private_->best_subframe+channel,
  91760. encoder->private_->best_subframe_bits+channel
  91761. )
  91762. )
  91763. return false;
  91764. }
  91765. }
  91766. if(do_mid_side) {
  91767. FLAC__ASSERT(encoder->protected_->channels == 2);
  91768. for(channel = 0; channel < 2; channel++) {
  91769. if(!
  91770. process_subframe_(
  91771. encoder,
  91772. min_partition_order,
  91773. max_partition_order,
  91774. &frame_header,
  91775. encoder->private_->subframe_bps_mid_side[channel],
  91776. encoder->private_->integer_signal_mid_side[channel],
  91777. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  91778. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  91779. encoder->private_->residual_workspace_mid_side[channel],
  91780. encoder->private_->best_subframe_mid_side+channel,
  91781. encoder->private_->best_subframe_bits_mid_side+channel
  91782. )
  91783. )
  91784. return false;
  91785. }
  91786. }
  91787. if(do_mid_side) {
  91788. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  91789. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  91790. FLAC__ChannelAssignment channel_assignment;
  91791. FLAC__ASSERT(encoder->protected_->channels == 2);
  91792. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  91793. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  91794. }
  91795. else {
  91796. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  91797. unsigned min_bits;
  91798. int ca;
  91799. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  91800. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  91801. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  91802. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  91803. FLAC__ASSERT(do_independent && do_mid_side);
  91804. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  91805. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  91806. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  91807. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  91808. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  91809. min_bits = bits[channel_assignment];
  91810. for(ca = 1; ca <= 3; ca++) {
  91811. if(bits[ca] < min_bits) {
  91812. min_bits = bits[ca];
  91813. channel_assignment = (FLAC__ChannelAssignment)ca;
  91814. }
  91815. }
  91816. }
  91817. frame_header.channel_assignment = channel_assignment;
  91818. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  91819. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91820. return false;
  91821. }
  91822. switch(channel_assignment) {
  91823. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  91824. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  91825. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  91826. break;
  91827. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  91828. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  91829. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91830. break;
  91831. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  91832. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91833. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  91834. break;
  91835. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  91836. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  91837. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91838. break;
  91839. default:
  91840. FLAC__ASSERT(0);
  91841. }
  91842. switch(channel_assignment) {
  91843. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  91844. left_bps = encoder->private_->subframe_bps [0];
  91845. right_bps = encoder->private_->subframe_bps [1];
  91846. break;
  91847. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  91848. left_bps = encoder->private_->subframe_bps [0];
  91849. right_bps = encoder->private_->subframe_bps_mid_side[1];
  91850. break;
  91851. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  91852. left_bps = encoder->private_->subframe_bps_mid_side[1];
  91853. right_bps = encoder->private_->subframe_bps [1];
  91854. break;
  91855. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  91856. left_bps = encoder->private_->subframe_bps_mid_side[0];
  91857. right_bps = encoder->private_->subframe_bps_mid_side[1];
  91858. break;
  91859. default:
  91860. FLAC__ASSERT(0);
  91861. }
  91862. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  91863. return false;
  91864. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  91865. return false;
  91866. }
  91867. else {
  91868. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  91869. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91870. return false;
  91871. }
  91872. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91873. if(!add_subframe_(encoder, frame_header.blocksize, encoder->private_->subframe_bps[channel], &encoder->private_->subframe_workspace[channel][encoder->private_->best_subframe[channel]], encoder->private_->frame)) {
  91874. return false;
  91875. }
  91876. }
  91877. }
  91878. if(encoder->protected_->loose_mid_side_stereo) {
  91879. encoder->private_->loose_mid_side_stereo_frame_count++;
  91880. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  91881. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  91882. }
  91883. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  91884. return true;
  91885. }
  91886. FLAC__bool process_subframe_(
  91887. FLAC__StreamEncoder *encoder,
  91888. unsigned min_partition_order,
  91889. unsigned max_partition_order,
  91890. const FLAC__FrameHeader *frame_header,
  91891. unsigned subframe_bps,
  91892. const FLAC__int32 integer_signal[],
  91893. FLAC__Subframe *subframe[2],
  91894. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  91895. FLAC__int32 *residual[2],
  91896. unsigned *best_subframe,
  91897. unsigned *best_bits
  91898. )
  91899. {
  91900. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91901. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  91902. #else
  91903. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  91904. #endif
  91905. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91906. FLAC__double lpc_residual_bits_per_sample;
  91907. FLAC__real autoc[FLAC__MAX_LPC_ORDER+1]; /* WATCHOUT: the size is important even though encoder->protected_->max_lpc_order might be less; some asm routines need all the space */
  91908. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  91909. unsigned min_lpc_order, max_lpc_order, lpc_order;
  91910. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  91911. #endif
  91912. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  91913. unsigned rice_parameter;
  91914. unsigned _candidate_bits, _best_bits;
  91915. unsigned _best_subframe;
  91916. const unsigned rice_parameter_limit = FLAC__stream_encoder_get_bits_per_sample(encoder) > 16? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  91917. FLAC__ASSERT(frame_header->blocksize > 0);
  91918. _best_subframe = 0;
  91919. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  91920. _best_bits = UINT_MAX;
  91921. else
  91922. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  91923. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  91924. unsigned signal_is_constant = false;
  91925. guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample);
  91926. if(
  91927. !encoder->private_->disable_constant_subframes &&
  91928. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91929. fixed_residual_bits_per_sample[1] == 0.0
  91930. #else
  91931. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  91932. #endif
  91933. ) {
  91934. unsigned i;
  91935. signal_is_constant = true;
  91936. for(i = 1; i < frame_header->blocksize; i++) {
  91937. if(integer_signal[0] != integer_signal[i]) {
  91938. signal_is_constant = false;
  91939. break;
  91940. }
  91941. }
  91942. }
  91943. if(signal_is_constant) {
  91944. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  91945. if(_candidate_bits < _best_bits) {
  91946. _best_subframe = !_best_subframe;
  91947. _best_bits = _candidate_bits;
  91948. }
  91949. }
  91950. else {
  91951. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  91952. if(encoder->protected_->do_exhaustive_model_search) {
  91953. min_fixed_order = 0;
  91954. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  91955. }
  91956. else {
  91957. min_fixed_order = max_fixed_order = guess_fixed_order;
  91958. }
  91959. if(max_fixed_order >= frame_header->blocksize)
  91960. max_fixed_order = frame_header->blocksize - 1;
  91961. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  91962. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91963. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  91964. continue; /* don't even try */
  91965. rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > 0.0)? (unsigned)(fixed_residual_bits_per_sample[fixed_order]+0.5) : 0; /* 0.5 is for rounding */
  91966. #else
  91967. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  91968. continue; /* don't even try */
  91969. rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > FLAC__FP_ZERO)? (unsigned)FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]+FLAC__FP_ONE_HALF) : 0; /* 0.5 is for rounding */
  91970. #endif
  91971. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  91972. if(rice_parameter >= rice_parameter_limit) {
  91973. #ifdef DEBUG_VERBOSE
  91974. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  91975. #endif
  91976. rice_parameter = rice_parameter_limit - 1;
  91977. }
  91978. _candidate_bits =
  91979. evaluate_fixed_subframe_(
  91980. encoder,
  91981. integer_signal,
  91982. residual[!_best_subframe],
  91983. encoder->private_->abs_residual_partition_sums,
  91984. encoder->private_->raw_bits_per_partition,
  91985. frame_header->blocksize,
  91986. subframe_bps,
  91987. fixed_order,
  91988. rice_parameter,
  91989. rice_parameter_limit,
  91990. min_partition_order,
  91991. max_partition_order,
  91992. encoder->protected_->do_escape_coding,
  91993. encoder->protected_->rice_parameter_search_dist,
  91994. subframe[!_best_subframe],
  91995. partitioned_rice_contents[!_best_subframe]
  91996. );
  91997. if(_candidate_bits < _best_bits) {
  91998. _best_subframe = !_best_subframe;
  91999. _best_bits = _candidate_bits;
  92000. }
  92001. }
  92002. }
  92003. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92004. if(encoder->protected_->max_lpc_order > 0) {
  92005. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92006. max_lpc_order = frame_header->blocksize-1;
  92007. else
  92008. max_lpc_order = encoder->protected_->max_lpc_order;
  92009. if(max_lpc_order > 0) {
  92010. unsigned a;
  92011. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92012. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92013. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92014. if(autoc[0] != 0.0) {
  92015. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92016. if(encoder->protected_->do_exhaustive_model_search) {
  92017. min_lpc_order = 1;
  92018. }
  92019. else {
  92020. const unsigned guess_lpc_order =
  92021. FLAC__lpc_compute_best_order(
  92022. lpc_error,
  92023. max_lpc_order,
  92024. frame_header->blocksize,
  92025. subframe_bps + (
  92026. encoder->protected_->do_qlp_coeff_prec_search?
  92027. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92028. encoder->protected_->qlp_coeff_precision
  92029. )
  92030. );
  92031. min_lpc_order = max_lpc_order = guess_lpc_order;
  92032. }
  92033. if(max_lpc_order >= frame_header->blocksize)
  92034. max_lpc_order = frame_header->blocksize - 1;
  92035. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92036. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92037. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92038. continue; /* don't even try */
  92039. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92040. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92041. if(rice_parameter >= rice_parameter_limit) {
  92042. #ifdef DEBUG_VERBOSE
  92043. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92044. #endif
  92045. rice_parameter = rice_parameter_limit - 1;
  92046. }
  92047. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92048. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92049. if(subframe_bps <= 17) {
  92050. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92051. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92052. }
  92053. else
  92054. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92055. }
  92056. else {
  92057. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92058. }
  92059. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92060. _candidate_bits =
  92061. evaluate_lpc_subframe_(
  92062. encoder,
  92063. integer_signal,
  92064. residual[!_best_subframe],
  92065. encoder->private_->abs_residual_partition_sums,
  92066. encoder->private_->raw_bits_per_partition,
  92067. encoder->private_->lp_coeff[lpc_order-1],
  92068. frame_header->blocksize,
  92069. subframe_bps,
  92070. lpc_order,
  92071. qlp_coeff_precision,
  92072. rice_parameter,
  92073. rice_parameter_limit,
  92074. min_partition_order,
  92075. max_partition_order,
  92076. encoder->protected_->do_escape_coding,
  92077. encoder->protected_->rice_parameter_search_dist,
  92078. subframe[!_best_subframe],
  92079. partitioned_rice_contents[!_best_subframe]
  92080. );
  92081. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92082. if(_candidate_bits < _best_bits) {
  92083. _best_subframe = !_best_subframe;
  92084. _best_bits = _candidate_bits;
  92085. }
  92086. }
  92087. }
  92088. }
  92089. }
  92090. }
  92091. }
  92092. }
  92093. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92094. }
  92095. }
  92096. if(_best_bits == UINT_MAX) {
  92097. FLAC__ASSERT(_best_subframe == 0);
  92098. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92099. }
  92100. *best_subframe = _best_subframe;
  92101. *best_bits = _best_bits;
  92102. return true;
  92103. }
  92104. FLAC__bool add_subframe_(
  92105. FLAC__StreamEncoder *encoder,
  92106. unsigned blocksize,
  92107. unsigned subframe_bps,
  92108. const FLAC__Subframe *subframe,
  92109. FLAC__BitWriter *frame
  92110. )
  92111. {
  92112. switch(subframe->type) {
  92113. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92114. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92115. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92116. return false;
  92117. }
  92118. break;
  92119. case FLAC__SUBFRAME_TYPE_FIXED:
  92120. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92121. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92122. return false;
  92123. }
  92124. break;
  92125. case FLAC__SUBFRAME_TYPE_LPC:
  92126. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92127. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92128. return false;
  92129. }
  92130. break;
  92131. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92132. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92133. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92134. return false;
  92135. }
  92136. break;
  92137. default:
  92138. FLAC__ASSERT(0);
  92139. }
  92140. return true;
  92141. }
  92142. #define SPOTCHECK_ESTIMATE 0
  92143. #if SPOTCHECK_ESTIMATE
  92144. static void spotcheck_subframe_estimate_(
  92145. FLAC__StreamEncoder *encoder,
  92146. unsigned blocksize,
  92147. unsigned subframe_bps,
  92148. const FLAC__Subframe *subframe,
  92149. unsigned estimate
  92150. )
  92151. {
  92152. FLAC__bool ret;
  92153. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92154. if(frame == 0) {
  92155. fprintf(stderr, "EST: can't allocate frame\n");
  92156. return;
  92157. }
  92158. if(!FLAC__bitwriter_init(frame)) {
  92159. fprintf(stderr, "EST: can't init frame\n");
  92160. return;
  92161. }
  92162. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92163. FLAC__ASSERT(ret);
  92164. {
  92165. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92166. if(estimate != actual)
  92167. fprintf(stderr, "EST: bad, frame#%u sub#%%d type=%8s est=%u, actual=%u, delta=%d\n", encoder->private_->current_frame_number, FLAC__SubframeTypeString[subframe->type], estimate, actual, (int)actual-(int)estimate);
  92168. }
  92169. FLAC__bitwriter_delete(frame);
  92170. }
  92171. #endif
  92172. unsigned evaluate_constant_subframe_(
  92173. FLAC__StreamEncoder *encoder,
  92174. const FLAC__int32 signal,
  92175. unsigned blocksize,
  92176. unsigned subframe_bps,
  92177. FLAC__Subframe *subframe
  92178. )
  92179. {
  92180. unsigned estimate;
  92181. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92182. subframe->data.constant.value = signal;
  92183. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92184. #if SPOTCHECK_ESTIMATE
  92185. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92186. #else
  92187. (void)encoder, (void)blocksize;
  92188. #endif
  92189. return estimate;
  92190. }
  92191. unsigned evaluate_fixed_subframe_(
  92192. FLAC__StreamEncoder *encoder,
  92193. const FLAC__int32 signal[],
  92194. FLAC__int32 residual[],
  92195. FLAC__uint64 abs_residual_partition_sums[],
  92196. unsigned raw_bits_per_partition[],
  92197. unsigned blocksize,
  92198. unsigned subframe_bps,
  92199. unsigned order,
  92200. unsigned rice_parameter,
  92201. unsigned rice_parameter_limit,
  92202. unsigned min_partition_order,
  92203. unsigned max_partition_order,
  92204. FLAC__bool do_escape_coding,
  92205. unsigned rice_parameter_search_dist,
  92206. FLAC__Subframe *subframe,
  92207. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92208. )
  92209. {
  92210. unsigned i, residual_bits, estimate;
  92211. const unsigned residual_samples = blocksize - order;
  92212. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92213. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92214. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92215. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92216. subframe->data.fixed.residual = residual;
  92217. residual_bits =
  92218. find_best_partition_order_(
  92219. encoder->private_,
  92220. residual,
  92221. abs_residual_partition_sums,
  92222. raw_bits_per_partition,
  92223. residual_samples,
  92224. order,
  92225. rice_parameter,
  92226. rice_parameter_limit,
  92227. min_partition_order,
  92228. max_partition_order,
  92229. subframe_bps,
  92230. do_escape_coding,
  92231. rice_parameter_search_dist,
  92232. &subframe->data.fixed.entropy_coding_method
  92233. );
  92234. subframe->data.fixed.order = order;
  92235. for(i = 0; i < order; i++)
  92236. subframe->data.fixed.warmup[i] = signal[i];
  92237. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92238. #if SPOTCHECK_ESTIMATE
  92239. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92240. #endif
  92241. return estimate;
  92242. }
  92243. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92244. unsigned evaluate_lpc_subframe_(
  92245. FLAC__StreamEncoder *encoder,
  92246. const FLAC__int32 signal[],
  92247. FLAC__int32 residual[],
  92248. FLAC__uint64 abs_residual_partition_sums[],
  92249. unsigned raw_bits_per_partition[],
  92250. const FLAC__real lp_coeff[],
  92251. unsigned blocksize,
  92252. unsigned subframe_bps,
  92253. unsigned order,
  92254. unsigned qlp_coeff_precision,
  92255. unsigned rice_parameter,
  92256. unsigned rice_parameter_limit,
  92257. unsigned min_partition_order,
  92258. unsigned max_partition_order,
  92259. FLAC__bool do_escape_coding,
  92260. unsigned rice_parameter_search_dist,
  92261. FLAC__Subframe *subframe,
  92262. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92263. )
  92264. {
  92265. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92266. unsigned i, residual_bits, estimate;
  92267. int quantization, ret;
  92268. const unsigned residual_samples = blocksize - order;
  92269. if(subframe_bps <= 16) {
  92270. FLAC__ASSERT(order > 0);
  92271. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92272. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92273. }
  92274. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92275. if(ret != 0)
  92276. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92277. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92278. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92279. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92280. else
  92281. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92282. else
  92283. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92284. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92285. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92286. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92287. subframe->data.lpc.residual = residual;
  92288. residual_bits =
  92289. find_best_partition_order_(
  92290. encoder->private_,
  92291. residual,
  92292. abs_residual_partition_sums,
  92293. raw_bits_per_partition,
  92294. residual_samples,
  92295. order,
  92296. rice_parameter,
  92297. rice_parameter_limit,
  92298. min_partition_order,
  92299. max_partition_order,
  92300. subframe_bps,
  92301. do_escape_coding,
  92302. rice_parameter_search_dist,
  92303. &subframe->data.lpc.entropy_coding_method
  92304. );
  92305. subframe->data.lpc.order = order;
  92306. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92307. subframe->data.lpc.quantization_level = quantization;
  92308. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92309. for(i = 0; i < order; i++)
  92310. subframe->data.lpc.warmup[i] = signal[i];
  92311. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN + FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN + (order * (qlp_coeff_precision + subframe_bps)) + residual_bits;
  92312. #if SPOTCHECK_ESTIMATE
  92313. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92314. #endif
  92315. return estimate;
  92316. }
  92317. #endif
  92318. unsigned evaluate_verbatim_subframe_(
  92319. FLAC__StreamEncoder *encoder,
  92320. const FLAC__int32 signal[],
  92321. unsigned blocksize,
  92322. unsigned subframe_bps,
  92323. FLAC__Subframe *subframe
  92324. )
  92325. {
  92326. unsigned estimate;
  92327. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92328. subframe->data.verbatim.data = signal;
  92329. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92330. #if SPOTCHECK_ESTIMATE
  92331. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92332. #else
  92333. (void)encoder;
  92334. #endif
  92335. return estimate;
  92336. }
  92337. unsigned find_best_partition_order_(
  92338. FLAC__StreamEncoderPrivate *private_,
  92339. const FLAC__int32 residual[],
  92340. FLAC__uint64 abs_residual_partition_sums[],
  92341. unsigned raw_bits_per_partition[],
  92342. unsigned residual_samples,
  92343. unsigned predictor_order,
  92344. unsigned rice_parameter,
  92345. unsigned rice_parameter_limit,
  92346. unsigned min_partition_order,
  92347. unsigned max_partition_order,
  92348. unsigned bps,
  92349. FLAC__bool do_escape_coding,
  92350. unsigned rice_parameter_search_dist,
  92351. FLAC__EntropyCodingMethod *best_ecm
  92352. )
  92353. {
  92354. unsigned residual_bits, best_residual_bits = 0;
  92355. unsigned best_parameters_index = 0;
  92356. unsigned best_partition_order = 0;
  92357. const unsigned blocksize = residual_samples + predictor_order;
  92358. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92359. min_partition_order = min(min_partition_order, max_partition_order);
  92360. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92361. if(do_escape_coding)
  92362. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92363. {
  92364. int partition_order;
  92365. unsigned sum;
  92366. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92367. if(!
  92368. set_partitioned_rice_(
  92369. #ifdef EXACT_RICE_BITS_CALCULATION
  92370. residual,
  92371. #endif
  92372. abs_residual_partition_sums+sum,
  92373. raw_bits_per_partition+sum,
  92374. residual_samples,
  92375. predictor_order,
  92376. rice_parameter,
  92377. rice_parameter_limit,
  92378. rice_parameter_search_dist,
  92379. (unsigned)partition_order,
  92380. do_escape_coding,
  92381. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92382. &residual_bits
  92383. )
  92384. )
  92385. {
  92386. FLAC__ASSERT(best_residual_bits != 0);
  92387. break;
  92388. }
  92389. sum += 1u << partition_order;
  92390. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92391. best_residual_bits = residual_bits;
  92392. best_parameters_index = !best_parameters_index;
  92393. best_partition_order = partition_order;
  92394. }
  92395. }
  92396. }
  92397. best_ecm->data.partitioned_rice.order = best_partition_order;
  92398. {
  92399. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92400. unsigned partition;
  92401. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92402. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92403. if(do_escape_coding)
  92404. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92405. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92406. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92407. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92408. break;
  92409. }
  92410. }
  92411. }
  92412. return best_residual_bits;
  92413. }
  92414. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92415. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92416. const FLAC__int32 residual[],
  92417. FLAC__uint64 abs_residual_partition_sums[],
  92418. unsigned blocksize,
  92419. unsigned predictor_order,
  92420. unsigned min_partition_order,
  92421. unsigned max_partition_order
  92422. );
  92423. #endif
  92424. void precompute_partition_info_sums_(
  92425. const FLAC__int32 residual[],
  92426. FLAC__uint64 abs_residual_partition_sums[],
  92427. unsigned residual_samples,
  92428. unsigned predictor_order,
  92429. unsigned min_partition_order,
  92430. unsigned max_partition_order,
  92431. unsigned bps
  92432. )
  92433. {
  92434. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92435. unsigned partitions = 1u << max_partition_order;
  92436. FLAC__ASSERT(default_partition_samples > predictor_order);
  92437. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92438. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92439. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92440. return;
  92441. }
  92442. #endif
  92443. {
  92444. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92445. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92446. FLAC__uint32 abs_residual_partition_sum;
  92447. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92448. end += default_partition_samples;
  92449. abs_residual_partition_sum = 0;
  92450. for( ; residual_sample < end; residual_sample++)
  92451. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92452. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92453. }
  92454. }
  92455. else { /* have to pessimistically use 64 bits for accumulator */
  92456. FLAC__uint64 abs_residual_partition_sum;
  92457. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92458. end += default_partition_samples;
  92459. abs_residual_partition_sum = 0;
  92460. for( ; residual_sample < end; residual_sample++)
  92461. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92462. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92463. }
  92464. }
  92465. }
  92466. {
  92467. unsigned from_partition = 0, to_partition = partitions;
  92468. int partition_order;
  92469. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92470. unsigned i;
  92471. partitions >>= 1;
  92472. for(i = 0; i < partitions; i++) {
  92473. abs_residual_partition_sums[to_partition++] =
  92474. abs_residual_partition_sums[from_partition ] +
  92475. abs_residual_partition_sums[from_partition+1];
  92476. from_partition += 2;
  92477. }
  92478. }
  92479. }
  92480. }
  92481. void precompute_partition_info_escapes_(
  92482. const FLAC__int32 residual[],
  92483. unsigned raw_bits_per_partition[],
  92484. unsigned residual_samples,
  92485. unsigned predictor_order,
  92486. unsigned min_partition_order,
  92487. unsigned max_partition_order
  92488. )
  92489. {
  92490. int partition_order;
  92491. unsigned from_partition, to_partition = 0;
  92492. const unsigned blocksize = residual_samples + predictor_order;
  92493. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92494. FLAC__int32 r;
  92495. FLAC__uint32 rmax;
  92496. unsigned partition, partition_sample, partition_samples, residual_sample;
  92497. const unsigned partitions = 1u << partition_order;
  92498. const unsigned default_partition_samples = blocksize >> partition_order;
  92499. FLAC__ASSERT(default_partition_samples > predictor_order);
  92500. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92501. partition_samples = default_partition_samples;
  92502. if(partition == 0)
  92503. partition_samples -= predictor_order;
  92504. rmax = 0;
  92505. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92506. r = residual[residual_sample++];
  92507. if(r < 0)
  92508. rmax |= ~r;
  92509. else
  92510. rmax |= r;
  92511. }
  92512. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92513. }
  92514. to_partition = partitions;
  92515. break; /*@@@ yuck, should remove the 'for' loop instead */
  92516. }
  92517. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92518. unsigned m;
  92519. unsigned i;
  92520. const unsigned partitions = 1u << partition_order;
  92521. for(i = 0; i < partitions; i++) {
  92522. m = raw_bits_per_partition[from_partition];
  92523. from_partition++;
  92524. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92525. from_partition++;
  92526. to_partition++;
  92527. }
  92528. }
  92529. }
  92530. #ifdef EXACT_RICE_BITS_CALCULATION
  92531. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92532. const unsigned rice_parameter,
  92533. const unsigned partition_samples,
  92534. const FLAC__int32 *residual
  92535. )
  92536. {
  92537. unsigned i, partition_bits =
  92538. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */
  92539. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92540. ;
  92541. for(i = 0; i < partition_samples; i++)
  92542. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92543. return partition_bits;
  92544. }
  92545. #else
  92546. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92547. const unsigned rice_parameter,
  92548. const unsigned partition_samples,
  92549. const FLAC__uint64 abs_residual_partition_sum
  92550. )
  92551. {
  92552. return
  92553. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */
  92554. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92555. (
  92556. rice_parameter?
  92557. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92558. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92559. )
  92560. - (partition_samples >> 1)
  92561. ;
  92562. }
  92563. #endif
  92564. FLAC__bool set_partitioned_rice_(
  92565. #ifdef EXACT_RICE_BITS_CALCULATION
  92566. const FLAC__int32 residual[],
  92567. #endif
  92568. const FLAC__uint64 abs_residual_partition_sums[],
  92569. const unsigned raw_bits_per_partition[],
  92570. const unsigned residual_samples,
  92571. const unsigned predictor_order,
  92572. const unsigned suggested_rice_parameter,
  92573. const unsigned rice_parameter_limit,
  92574. const unsigned rice_parameter_search_dist,
  92575. const unsigned partition_order,
  92576. const FLAC__bool search_for_escapes,
  92577. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92578. unsigned *bits
  92579. )
  92580. {
  92581. unsigned rice_parameter, partition_bits;
  92582. unsigned best_partition_bits, best_rice_parameter = 0;
  92583. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92584. unsigned *parameters, *raw_bits;
  92585. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92586. unsigned min_rice_parameter, max_rice_parameter;
  92587. #else
  92588. (void)rice_parameter_search_dist;
  92589. #endif
  92590. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92591. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92592. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92593. parameters = partitioned_rice_contents->parameters;
  92594. raw_bits = partitioned_rice_contents->raw_bits;
  92595. if(partition_order == 0) {
  92596. best_partition_bits = (unsigned)(-1);
  92597. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92598. if(rice_parameter_search_dist) {
  92599. if(suggested_rice_parameter < rice_parameter_search_dist)
  92600. min_rice_parameter = 0;
  92601. else
  92602. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92603. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92604. if(max_rice_parameter >= rice_parameter_limit) {
  92605. #ifdef DEBUG_VERBOSE
  92606. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92607. #endif
  92608. max_rice_parameter = rice_parameter_limit - 1;
  92609. }
  92610. }
  92611. else
  92612. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92613. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92614. #else
  92615. rice_parameter = suggested_rice_parameter;
  92616. #endif
  92617. #ifdef EXACT_RICE_BITS_CALCULATION
  92618. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92619. #else
  92620. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92621. #endif
  92622. if(partition_bits < best_partition_bits) {
  92623. best_rice_parameter = rice_parameter;
  92624. best_partition_bits = partition_bits;
  92625. }
  92626. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92627. }
  92628. #endif
  92629. if(search_for_escapes) {
  92630. partition_bits = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN + raw_bits_per_partition[0] * residual_samples;
  92631. if(partition_bits <= best_partition_bits) {
  92632. raw_bits[0] = raw_bits_per_partition[0];
  92633. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92634. best_partition_bits = partition_bits;
  92635. }
  92636. else
  92637. raw_bits[0] = 0;
  92638. }
  92639. parameters[0] = best_rice_parameter;
  92640. bits_ += best_partition_bits;
  92641. }
  92642. else {
  92643. unsigned partition, residual_sample;
  92644. unsigned partition_samples;
  92645. FLAC__uint64 mean, k;
  92646. const unsigned partitions = 1u << partition_order;
  92647. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92648. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92649. if(partition == 0) {
  92650. if(partition_samples <= predictor_order)
  92651. return false;
  92652. else
  92653. partition_samples -= predictor_order;
  92654. }
  92655. mean = abs_residual_partition_sums[partition];
  92656. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92657. ;
  92658. if(rice_parameter >= rice_parameter_limit) {
  92659. #ifdef DEBUG_VERBOSE
  92660. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92661. #endif
  92662. rice_parameter = rice_parameter_limit - 1;
  92663. }
  92664. best_partition_bits = (unsigned)(-1);
  92665. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92666. if(rice_parameter_search_dist) {
  92667. if(rice_parameter < rice_parameter_search_dist)
  92668. min_rice_parameter = 0;
  92669. else
  92670. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92671. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  92672. if(max_rice_parameter >= rice_parameter_limit) {
  92673. #ifdef DEBUG_VERBOSE
  92674. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  92675. #endif
  92676. max_rice_parameter = rice_parameter_limit - 1;
  92677. }
  92678. }
  92679. else
  92680. min_rice_parameter = max_rice_parameter = rice_parameter;
  92681. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92682. #endif
  92683. #ifdef EXACT_RICE_BITS_CALCULATION
  92684. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  92685. #else
  92686. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  92687. #endif
  92688. if(partition_bits < best_partition_bits) {
  92689. best_rice_parameter = rice_parameter;
  92690. best_partition_bits = partition_bits;
  92691. }
  92692. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92693. }
  92694. #endif
  92695. if(search_for_escapes) {
  92696. partition_bits = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN + raw_bits_per_partition[partition] * partition_samples;
  92697. if(partition_bits <= best_partition_bits) {
  92698. raw_bits[partition] = raw_bits_per_partition[partition];
  92699. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92700. best_partition_bits = partition_bits;
  92701. }
  92702. else
  92703. raw_bits[partition] = 0;
  92704. }
  92705. parameters[partition] = best_rice_parameter;
  92706. bits_ += best_partition_bits;
  92707. residual_sample += partition_samples;
  92708. }
  92709. }
  92710. *bits = bits_;
  92711. return true;
  92712. }
  92713. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  92714. {
  92715. unsigned i, shift;
  92716. FLAC__int32 x = 0;
  92717. for(i = 0; i < samples && !(x&1); i++)
  92718. x |= signal[i];
  92719. if(x == 0) {
  92720. shift = 0;
  92721. }
  92722. else {
  92723. for(shift = 0; !(x&1); shift++)
  92724. x >>= 1;
  92725. }
  92726. if(shift > 0) {
  92727. for(i = 0; i < samples; i++)
  92728. signal[i] >>= shift;
  92729. }
  92730. return shift;
  92731. }
  92732. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92733. {
  92734. unsigned channel;
  92735. for(channel = 0; channel < channels; channel++)
  92736. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  92737. fifo->tail += wide_samples;
  92738. FLAC__ASSERT(fifo->tail <= fifo->size);
  92739. }
  92740. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92741. {
  92742. unsigned channel;
  92743. unsigned sample, wide_sample;
  92744. unsigned tail = fifo->tail;
  92745. sample = input_offset * channels;
  92746. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  92747. for(channel = 0; channel < channels; channel++)
  92748. fifo->data[channel][tail] = input[sample++];
  92749. tail++;
  92750. }
  92751. fifo->tail = tail;
  92752. FLAC__ASSERT(fifo->tail <= fifo->size);
  92753. }
  92754. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92755. {
  92756. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92757. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  92758. (void)decoder;
  92759. if(encoder->private_->verify.needs_magic_hack) {
  92760. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  92761. *bytes = FLAC__STREAM_SYNC_LENGTH;
  92762. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  92763. encoder->private_->verify.needs_magic_hack = false;
  92764. }
  92765. else {
  92766. if(encoded_bytes == 0) {
  92767. FLAC__ASSERT(0);
  92768. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  92769. }
  92770. else if(encoded_bytes < *bytes)
  92771. *bytes = encoded_bytes;
  92772. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  92773. encoder->private_->verify.output.data += *bytes;
  92774. encoder->private_->verify.output.bytes -= *bytes;
  92775. }
  92776. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  92777. }
  92778. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  92779. {
  92780. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  92781. unsigned channel;
  92782. const unsigned channels = frame->header.channels;
  92783. const unsigned blocksize = frame->header.blocksize;
  92784. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  92785. (void)decoder;
  92786. for(channel = 0; channel < channels; channel++) {
  92787. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  92788. unsigned i, sample = 0;
  92789. FLAC__int32 expect = 0, got = 0;
  92790. for(i = 0; i < blocksize; i++) {
  92791. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  92792. sample = i;
  92793. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  92794. got = (FLAC__int32)buffer[channel][i];
  92795. break;
  92796. }
  92797. }
  92798. FLAC__ASSERT(i < blocksize);
  92799. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  92800. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  92801. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  92802. encoder->private_->verify.error_stats.channel = channel;
  92803. encoder->private_->verify.error_stats.sample = sample;
  92804. encoder->private_->verify.error_stats.expected = expect;
  92805. encoder->private_->verify.error_stats.got = got;
  92806. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  92807. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  92808. }
  92809. }
  92810. encoder->private_->verify.input_fifo.tail -= blocksize;
  92811. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  92812. for(channel = 0; channel < channels; channel++)
  92813. memmove(&encoder->private_->verify.input_fifo.data[channel][0], &encoder->private_->verify.input_fifo.data[channel][blocksize], encoder->private_->verify.input_fifo.tail * sizeof(encoder->private_->verify.input_fifo.data[0][0]));
  92814. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  92815. }
  92816. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  92817. {
  92818. (void)decoder, (void)metadata, (void)client_data;
  92819. }
  92820. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  92821. {
  92822. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92823. (void)decoder, (void)status;
  92824. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92825. }
  92826. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92827. {
  92828. (void)client_data;
  92829. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  92830. if (*bytes == 0) {
  92831. if (feof(encoder->private_->file))
  92832. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  92833. else if (ferror(encoder->private_->file))
  92834. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  92835. }
  92836. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  92837. }
  92838. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  92839. {
  92840. (void)client_data;
  92841. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  92842. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  92843. else
  92844. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  92845. }
  92846. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  92847. {
  92848. off_t offset;
  92849. (void)client_data;
  92850. offset = ftello(encoder->private_->file);
  92851. if(offset < 0) {
  92852. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  92853. }
  92854. else {
  92855. *absolute_byte_offset = (FLAC__uint64)offset;
  92856. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  92857. }
  92858. }
  92859. #ifdef FLAC__VALGRIND_TESTING
  92860. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  92861. {
  92862. size_t ret = fwrite(ptr, size, nmemb, stream);
  92863. if(!ferror(stream))
  92864. fflush(stream);
  92865. return ret;
  92866. }
  92867. #else
  92868. #define local__fwrite fwrite
  92869. #endif
  92870. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  92871. {
  92872. (void)client_data, (void)current_frame;
  92873. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  92874. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  92875. #if FLAC__HAS_OGG
  92876. encoder->private_->is_ogg? true :
  92877. #endif
  92878. samples > 0
  92879. );
  92880. if(call_it) {
  92881. encoder->private_->progress_callback(encoder, encoder->private_->bytes_written+bytes, encoder->private_->samples_written+samples, encoder->private_->frames_written+(samples?1:0), encoder->private_->total_frames_estimate, encoder->private_->client_data);
  92882. }
  92883. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  92884. }
  92885. else
  92886. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  92887. }
  92888. FILE *get_binary_stdout_(void)
  92889. {
  92890. #if defined _MSC_VER || defined __MINGW32__
  92891. _setmode(_fileno(stdout), _O_BINARY);
  92892. #elif defined __CYGWIN__
  92893. setmode(_fileno(stdout), _O_BINARY);
  92894. #elif defined __EMX__
  92895. setmode(fileno(stdout), O_BINARY);
  92896. #endif
  92897. return stdout;
  92898. }
  92899. #endif
  92900. /*** End of inlined file: stream_encoder.c ***/
  92901. /*** Start of inlined file: stream_encoder_framing.c ***/
  92902. /*** Start of inlined file: juce_FlacHeader.h ***/
  92903. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  92904. // tasks..
  92905. #define VERSION "1.2.1"
  92906. #define FLAC__NO_DLL 1
  92907. #if JUCE_MSVC
  92908. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  92909. #endif
  92910. #if JUCE_MAC
  92911. #define FLAC__SYS_DARWIN 1
  92912. #endif
  92913. /*** End of inlined file: juce_FlacHeader.h ***/
  92914. #if JUCE_USE_FLAC
  92915. #if HAVE_CONFIG_H
  92916. # include <config.h>
  92917. #endif
  92918. #include <stdio.h>
  92919. #include <string.h> /* for strlen() */
  92920. #ifdef max
  92921. #undef max
  92922. #endif
  92923. #define max(x,y) ((x)>(y)?(x):(y))
  92924. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  92925. static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended);
  92926. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  92927. {
  92928. unsigned i, j;
  92929. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  92930. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  92931. return false;
  92932. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  92933. return false;
  92934. i = metadata->length;
  92935. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  92936. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  92937. i -= metadata->data.vorbis_comment.vendor_string.length;
  92938. i += vendor_string_length;
  92939. }
  92940. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  92941. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  92942. return false;
  92943. switch(metadata->type) {
  92944. case FLAC__METADATA_TYPE_STREAMINFO:
  92945. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  92946. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  92947. return false;
  92948. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  92949. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  92950. return false;
  92951. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  92952. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  92953. return false;
  92954. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  92955. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  92956. return false;
  92957. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  92958. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  92959. return false;
  92960. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  92961. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  92962. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  92963. return false;
  92964. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  92965. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  92966. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  92967. return false;
  92968. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  92969. return false;
  92970. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  92971. return false;
  92972. break;
  92973. case FLAC__METADATA_TYPE_PADDING:
  92974. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  92975. return false;
  92976. break;
  92977. case FLAC__METADATA_TYPE_APPLICATION:
  92978. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  92979. return false;
  92980. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  92981. return false;
  92982. break;
  92983. case FLAC__METADATA_TYPE_SEEKTABLE:
  92984. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  92985. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  92986. return false;
  92987. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  92988. return false;
  92989. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  92990. return false;
  92991. }
  92992. break;
  92993. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  92994. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  92995. return false;
  92996. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  92997. return false;
  92998. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  92999. return false;
  93000. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93001. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93002. return false;
  93003. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93004. return false;
  93005. }
  93006. break;
  93007. case FLAC__METADATA_TYPE_CUESHEET:
  93008. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93009. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.cue_sheet.media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8))
  93010. return false;
  93011. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93012. return false;
  93013. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93014. return false;
  93015. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93016. return false;
  93017. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93018. return false;
  93019. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93020. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93021. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93022. return false;
  93023. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93024. return false;
  93025. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93026. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93027. return false;
  93028. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93029. return false;
  93030. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93031. return false;
  93032. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93033. return false;
  93034. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93035. return false;
  93036. for(j = 0; j < track->num_indices; j++) {
  93037. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93038. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93039. return false;
  93040. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93041. return false;
  93042. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93043. return false;
  93044. }
  93045. }
  93046. break;
  93047. case FLAC__METADATA_TYPE_PICTURE:
  93048. {
  93049. size_t len;
  93050. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93051. return false;
  93052. len = strlen(metadata->data.picture.mime_type);
  93053. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93054. return false;
  93055. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93056. return false;
  93057. len = strlen((const char *)metadata->data.picture.description);
  93058. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93059. return false;
  93060. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93061. return false;
  93062. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93063. return false;
  93064. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93065. return false;
  93066. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93067. return false;
  93068. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93069. return false;
  93070. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93071. return false;
  93072. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93073. return false;
  93074. }
  93075. break;
  93076. default:
  93077. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93078. return false;
  93079. break;
  93080. }
  93081. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93082. return true;
  93083. }
  93084. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93085. {
  93086. unsigned u, blocksize_hint, sample_rate_hint;
  93087. FLAC__byte crc;
  93088. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93089. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93090. return false;
  93091. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93092. return false;
  93093. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93094. return false;
  93095. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93096. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93097. blocksize_hint = 0;
  93098. switch(header->blocksize) {
  93099. case 192: u = 1; break;
  93100. case 576: u = 2; break;
  93101. case 1152: u = 3; break;
  93102. case 2304: u = 4; break;
  93103. case 4608: u = 5; break;
  93104. case 256: u = 8; break;
  93105. case 512: u = 9; break;
  93106. case 1024: u = 10; break;
  93107. case 2048: u = 11; break;
  93108. case 4096: u = 12; break;
  93109. case 8192: u = 13; break;
  93110. case 16384: u = 14; break;
  93111. case 32768: u = 15; break;
  93112. default:
  93113. if(header->blocksize <= 0x100)
  93114. blocksize_hint = u = 6;
  93115. else
  93116. blocksize_hint = u = 7;
  93117. break;
  93118. }
  93119. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93120. return false;
  93121. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93122. sample_rate_hint = 0;
  93123. switch(header->sample_rate) {
  93124. case 88200: u = 1; break;
  93125. case 176400: u = 2; break;
  93126. case 192000: u = 3; break;
  93127. case 8000: u = 4; break;
  93128. case 16000: u = 5; break;
  93129. case 22050: u = 6; break;
  93130. case 24000: u = 7; break;
  93131. case 32000: u = 8; break;
  93132. case 44100: u = 9; break;
  93133. case 48000: u = 10; break;
  93134. case 96000: u = 11; break;
  93135. default:
  93136. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93137. sample_rate_hint = u = 12;
  93138. else if(header->sample_rate % 10 == 0)
  93139. sample_rate_hint = u = 14;
  93140. else if(header->sample_rate <= 0xffff)
  93141. sample_rate_hint = u = 13;
  93142. else
  93143. u = 0;
  93144. break;
  93145. }
  93146. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93147. return false;
  93148. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93149. switch(header->channel_assignment) {
  93150. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93151. u = header->channels - 1;
  93152. break;
  93153. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93154. FLAC__ASSERT(header->channels == 2);
  93155. u = 8;
  93156. break;
  93157. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93158. FLAC__ASSERT(header->channels == 2);
  93159. u = 9;
  93160. break;
  93161. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93162. FLAC__ASSERT(header->channels == 2);
  93163. u = 10;
  93164. break;
  93165. default:
  93166. FLAC__ASSERT(0);
  93167. }
  93168. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93169. return false;
  93170. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93171. switch(header->bits_per_sample) {
  93172. case 8 : u = 1; break;
  93173. case 12: u = 2; break;
  93174. case 16: u = 4; break;
  93175. case 20: u = 5; break;
  93176. case 24: u = 6; break;
  93177. default: u = 0; break;
  93178. }
  93179. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93180. return false;
  93181. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93182. return false;
  93183. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93184. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93185. return false;
  93186. }
  93187. else {
  93188. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93189. return false;
  93190. }
  93191. if(blocksize_hint)
  93192. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93193. return false;
  93194. switch(sample_rate_hint) {
  93195. case 12:
  93196. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93197. return false;
  93198. break;
  93199. case 13:
  93200. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93201. return false;
  93202. break;
  93203. case 14:
  93204. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93205. return false;
  93206. break;
  93207. }
  93208. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93209. return false;
  93210. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93211. return false;
  93212. return true;
  93213. }
  93214. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93215. {
  93216. FLAC__bool ok;
  93217. ok =
  93218. FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN) &&
  93219. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93220. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93221. ;
  93222. return ok;
  93223. }
  93224. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93225. {
  93226. unsigned i;
  93227. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK | (subframe->order<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
  93228. return false;
  93229. if(wasted_bits)
  93230. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93231. return false;
  93232. for(i = 0; i < subframe->order; i++)
  93233. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93234. return false;
  93235. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93236. return false;
  93237. switch(subframe->entropy_coding_method.type) {
  93238. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93239. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93240. if(!add_residual_partitioned_rice_(
  93241. bw,
  93242. subframe->residual,
  93243. residual_samples,
  93244. subframe->order,
  93245. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93246. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93247. subframe->entropy_coding_method.data.partitioned_rice.order,
  93248. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93249. ))
  93250. return false;
  93251. break;
  93252. default:
  93253. FLAC__ASSERT(0);
  93254. }
  93255. return true;
  93256. }
  93257. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93258. {
  93259. unsigned i;
  93260. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK | ((subframe->order-1)<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
  93261. return false;
  93262. if(wasted_bits)
  93263. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93264. return false;
  93265. for(i = 0; i < subframe->order; i++)
  93266. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93267. return false;
  93268. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93269. return false;
  93270. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93271. return false;
  93272. for(i = 0; i < subframe->order; i++)
  93273. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93274. return false;
  93275. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93276. return false;
  93277. switch(subframe->entropy_coding_method.type) {
  93278. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93279. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93280. if(!add_residual_partitioned_rice_(
  93281. bw,
  93282. subframe->residual,
  93283. residual_samples,
  93284. subframe->order,
  93285. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93286. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93287. subframe->entropy_coding_method.data.partitioned_rice.order,
  93288. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93289. ))
  93290. return false;
  93291. break;
  93292. default:
  93293. FLAC__ASSERT(0);
  93294. }
  93295. return true;
  93296. }
  93297. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93298. {
  93299. unsigned i;
  93300. const FLAC__int32 *signal = subframe->data;
  93301. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
  93302. return false;
  93303. if(wasted_bits)
  93304. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93305. return false;
  93306. for(i = 0; i < samples; i++)
  93307. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93308. return false;
  93309. return true;
  93310. }
  93311. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93312. {
  93313. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93314. return false;
  93315. switch(method->type) {
  93316. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93317. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93318. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93319. return false;
  93320. break;
  93321. default:
  93322. FLAC__ASSERT(0);
  93323. }
  93324. return true;
  93325. }
  93326. FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended)
  93327. {
  93328. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93329. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93330. if(partition_order == 0) {
  93331. unsigned i;
  93332. if(raw_bits[0] == 0) {
  93333. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93334. return false;
  93335. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93336. return false;
  93337. }
  93338. else {
  93339. FLAC__ASSERT(rice_parameters[0] == 0);
  93340. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93341. return false;
  93342. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93343. return false;
  93344. for(i = 0; i < residual_samples; i++) {
  93345. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93346. return false;
  93347. }
  93348. }
  93349. return true;
  93350. }
  93351. else {
  93352. unsigned i, j, k = 0, k_last = 0;
  93353. unsigned partition_samples;
  93354. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93355. for(i = 0; i < (1u<<partition_order); i++) {
  93356. partition_samples = default_partition_samples;
  93357. if(i == 0)
  93358. partition_samples -= predictor_order;
  93359. k += partition_samples;
  93360. if(raw_bits[i] == 0) {
  93361. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93362. return false;
  93363. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93364. return false;
  93365. }
  93366. else {
  93367. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93368. return false;
  93369. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93370. return false;
  93371. for(j = k_last; j < k; j++) {
  93372. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93373. return false;
  93374. }
  93375. }
  93376. k_last = k;
  93377. }
  93378. return true;
  93379. }
  93380. }
  93381. #endif
  93382. /*** End of inlined file: stream_encoder_framing.c ***/
  93383. /*** Start of inlined file: window_flac.c ***/
  93384. /*** Start of inlined file: juce_FlacHeader.h ***/
  93385. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93386. // tasks..
  93387. #define VERSION "1.2.1"
  93388. #define FLAC__NO_DLL 1
  93389. #if JUCE_MSVC
  93390. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93391. #endif
  93392. #if JUCE_MAC
  93393. #define FLAC__SYS_DARWIN 1
  93394. #endif
  93395. /*** End of inlined file: juce_FlacHeader.h ***/
  93396. #if JUCE_USE_FLAC
  93397. #if HAVE_CONFIG_H
  93398. # include <config.h>
  93399. #endif
  93400. #include <math.h>
  93401. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93402. #ifndef M_PI
  93403. #define M_PI 3.14159265358979323846
  93404. #endif
  93405. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93406. {
  93407. const FLAC__int32 N = L - 1;
  93408. FLAC__int32 n;
  93409. if (L & 1) {
  93410. for (n = 0; n <= N/2; n++)
  93411. window[n] = 2.0f * n / (float)N;
  93412. for (; n <= N; n++)
  93413. window[n] = 2.0f - 2.0f * n / (float)N;
  93414. }
  93415. else {
  93416. for (n = 0; n <= L/2-1; n++)
  93417. window[n] = 2.0f * n / (float)N;
  93418. for (; n <= N; n++)
  93419. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93420. }
  93421. }
  93422. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93423. {
  93424. const FLAC__int32 N = L - 1;
  93425. FLAC__int32 n;
  93426. for (n = 0; n < L; n++)
  93427. window[n] = (FLAC__real)(0.62f - 0.48f * fabs((float)n/(float)N+0.5f) + 0.38f * cos(2.0f * M_PI * ((float)n/(float)N+0.5f)));
  93428. }
  93429. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93430. {
  93431. const FLAC__int32 N = L - 1;
  93432. FLAC__int32 n;
  93433. for (n = 0; n < L; n++)
  93434. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93435. }
  93436. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93437. {
  93438. const FLAC__int32 N = L - 1;
  93439. FLAC__int32 n;
  93440. for (n = 0; n <= N; n++)
  93441. window[n] = (FLAC__real)(0.35875f - 0.48829f * cos(2.0f * M_PI * n / N) + 0.14128f * cos(4.0f * M_PI * n / N) - 0.01168f * cos(6.0f * M_PI * n / N));
  93442. }
  93443. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93444. {
  93445. const FLAC__int32 N = L - 1;
  93446. const double N2 = (double)N / 2.;
  93447. FLAC__int32 n;
  93448. for (n = 0; n <= N; n++) {
  93449. double k = ((double)n - N2) / N2;
  93450. k = 1.0f - k * k;
  93451. window[n] = (FLAC__real)(k * k);
  93452. }
  93453. }
  93454. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93455. {
  93456. const FLAC__int32 N = L - 1;
  93457. FLAC__int32 n;
  93458. for (n = 0; n < L; n++)
  93459. window[n] = (FLAC__real)(1.0f - 1.93f * cos(2.0f * M_PI * n / N) + 1.29f * cos(4.0f * M_PI * n / N) - 0.388f * cos(6.0f * M_PI * n / N) + 0.0322f * cos(8.0f * M_PI * n / N));
  93460. }
  93461. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93462. {
  93463. const FLAC__int32 N = L - 1;
  93464. const double N2 = (double)N / 2.;
  93465. FLAC__int32 n;
  93466. for (n = 0; n <= N; n++) {
  93467. const double k = ((double)n - N2) / (stddev * N2);
  93468. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93469. }
  93470. }
  93471. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93472. {
  93473. const FLAC__int32 N = L - 1;
  93474. FLAC__int32 n;
  93475. for (n = 0; n < L; n++)
  93476. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93477. }
  93478. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93479. {
  93480. const FLAC__int32 N = L - 1;
  93481. FLAC__int32 n;
  93482. for (n = 0; n < L; n++)
  93483. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93484. }
  93485. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93486. {
  93487. const FLAC__int32 N = L - 1;
  93488. FLAC__int32 n;
  93489. for (n = 0; n < L; n++)
  93490. window[n] = (FLAC__real)(0.402f - 0.498f * cos(2.0f * M_PI * n / N) + 0.098f * cos(4.0f * M_PI * n / N) - 0.001f * cos(6.0f * M_PI * n / N));
  93491. }
  93492. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93493. {
  93494. const FLAC__int32 N = L - 1;
  93495. FLAC__int32 n;
  93496. for (n = 0; n < L; n++)
  93497. window[n] = (FLAC__real)(0.3635819f - 0.4891775f*cos(2.0f*M_PI*n/N) + 0.1365995f*cos(4.0f*M_PI*n/N) - 0.0106411f*cos(6.0f*M_PI*n/N));
  93498. }
  93499. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93500. {
  93501. FLAC__int32 n;
  93502. for (n = 0; n < L; n++)
  93503. window[n] = 1.0f;
  93504. }
  93505. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93506. {
  93507. FLAC__int32 n;
  93508. if (L & 1) {
  93509. for (n = 1; n <= L+1/2; n++)
  93510. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93511. for (; n <= L; n++)
  93512. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93513. }
  93514. else {
  93515. for (n = 1; n <= L/2; n++)
  93516. window[n-1] = 2.0f * n / (float)L;
  93517. for (; n <= L; n++)
  93518. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93519. }
  93520. }
  93521. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93522. {
  93523. if (p <= 0.0)
  93524. FLAC__window_rectangle(window, L);
  93525. else if (p >= 1.0)
  93526. FLAC__window_hann(window, L);
  93527. else {
  93528. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93529. FLAC__int32 n;
  93530. FLAC__window_rectangle(window, L);
  93531. if (Np > 0) {
  93532. for (n = 0; n <= Np; n++) {
  93533. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93534. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93535. }
  93536. }
  93537. }
  93538. }
  93539. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93540. {
  93541. const FLAC__int32 N = L - 1;
  93542. const double N2 = (double)N / 2.;
  93543. FLAC__int32 n;
  93544. for (n = 0; n <= N; n++) {
  93545. const double k = ((double)n - N2) / N2;
  93546. window[n] = (FLAC__real)(1.0f - k * k);
  93547. }
  93548. }
  93549. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93550. #endif
  93551. /*** End of inlined file: window_flac.c ***/
  93552. #else
  93553. #include <FLAC/all.h>
  93554. #endif
  93555. }
  93556. #undef max
  93557. #undef min
  93558. #ifdef _MSC_VER
  93559. #pragma warning (pop)
  93560. #endif
  93561. BEGIN_JUCE_NAMESPACE
  93562. static const char* const flacFormatName = "FLAC file";
  93563. static const juce_wchar* const flacExtensions[] = { T(".flac"), 0 };
  93564. class FlacReader : public AudioFormatReader
  93565. {
  93566. public:
  93567. FlacReader (InputStream* const in)
  93568. : AudioFormatReader (in, TRANS (flacFormatName)),
  93569. reservoir (2, 0),
  93570. reservoirStart (0),
  93571. samplesInReservoir (0),
  93572. scanningForLength (false)
  93573. {
  93574. using namespace FlacNamespace;
  93575. lengthInSamples = 0;
  93576. decoder = FLAC__stream_decoder_new();
  93577. ok = FLAC__stream_decoder_init_stream (decoder,
  93578. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93579. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93580. this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93581. if (ok)
  93582. {
  93583. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93584. if (lengthInSamples == 0 && sampleRate > 0)
  93585. {
  93586. // the length hasn't been stored in the metadata, so we'll need to
  93587. // work it out the length the hard way, by scanning the whole file..
  93588. scanningForLength = true;
  93589. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93590. scanningForLength = false;
  93591. const int64 tempLength = lengthInSamples;
  93592. FLAC__stream_decoder_reset (decoder);
  93593. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93594. lengthInSamples = tempLength;
  93595. }
  93596. }
  93597. }
  93598. ~FlacReader()
  93599. {
  93600. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93601. }
  93602. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93603. {
  93604. sampleRate = info.sample_rate;
  93605. bitsPerSample = info.bits_per_sample;
  93606. lengthInSamples = (unsigned int) info.total_samples;
  93607. numChannels = info.channels;
  93608. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93609. }
  93610. // returns the number of samples read
  93611. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93612. int64 startSampleInFile, int numSamples)
  93613. {
  93614. using namespace FlacNamespace;
  93615. if (! ok)
  93616. return false;
  93617. while (numSamples > 0)
  93618. {
  93619. if (startSampleInFile >= reservoirStart
  93620. && startSampleInFile < reservoirStart + samplesInReservoir)
  93621. {
  93622. const int num = (int) jmin ((int64) numSamples,
  93623. reservoirStart + samplesInReservoir - startSampleInFile);
  93624. jassert (num > 0);
  93625. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93626. if (destSamples[i] != 0)
  93627. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93628. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93629. sizeof (int) * num);
  93630. startOffsetInDestBuffer += num;
  93631. startSampleInFile += num;
  93632. numSamples -= num;
  93633. }
  93634. else
  93635. {
  93636. if (startSampleInFile >= (int) lengthInSamples)
  93637. {
  93638. samplesInReservoir = 0;
  93639. }
  93640. else if (startSampleInFile < reservoirStart
  93641. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93642. {
  93643. // had some problems with flac crashing if the read pos is aligned more
  93644. // accurately than this. Probably fixed in newer versions of the library, though.
  93645. reservoirStart = (int) (startSampleInFile & ~511);
  93646. samplesInReservoir = 0;
  93647. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93648. }
  93649. else
  93650. {
  93651. reservoirStart += samplesInReservoir;
  93652. samplesInReservoir = 0;
  93653. FLAC__stream_decoder_process_single (decoder);
  93654. }
  93655. if (samplesInReservoir == 0)
  93656. break;
  93657. }
  93658. }
  93659. if (numSamples > 0)
  93660. {
  93661. for (int i = numDestChannels; --i >= 0;)
  93662. if (destSamples[i] != 0)
  93663. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93664. sizeof (int) * numSamples);
  93665. }
  93666. return true;
  93667. }
  93668. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93669. {
  93670. if (scanningForLength)
  93671. {
  93672. lengthInSamples += numSamples;
  93673. }
  93674. else
  93675. {
  93676. if (numSamples > reservoir.getNumSamples())
  93677. reservoir.setSize (numChannels, numSamples, false, false, true);
  93678. const int bitsToShift = 32 - bitsPerSample;
  93679. for (int i = 0; i < (int) numChannels; ++i)
  93680. {
  93681. const FlacNamespace::FLAC__int32* src = buffer[i];
  93682. int n = i;
  93683. while (src == 0 && n > 0)
  93684. src = buffer [--n];
  93685. if (src != 0)
  93686. {
  93687. int* dest = (int*) reservoir.getSampleData(i);
  93688. for (int j = 0; j < numSamples; ++j)
  93689. dest[j] = src[j] << bitsToShift;
  93690. }
  93691. }
  93692. samplesInReservoir = numSamples;
  93693. }
  93694. }
  93695. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  93696. {
  93697. using namespace FlacNamespace;
  93698. *bytes = (size_t) static_cast <const FlacReader*> (client_data)->input->read (buffer, (int) *bytes);
  93699. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93700. }
  93701. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  93702. {
  93703. using namespace FlacNamespace;
  93704. static_cast <const FlacReader*> (client_data)->input->setPosition ((int) absolute_byte_offset);
  93705. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  93706. }
  93707. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93708. {
  93709. using namespace FlacNamespace;
  93710. *absolute_byte_offset = static_cast <const FlacReader*> (client_data)->input->getPosition();
  93711. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  93712. }
  93713. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  93714. {
  93715. using namespace FlacNamespace;
  93716. *stream_length = static_cast <const FlacReader*> (client_data)->input->getTotalLength();
  93717. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  93718. }
  93719. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  93720. {
  93721. return static_cast <const FlacReader*> (client_data)->input->isExhausted();
  93722. }
  93723. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93724. const FlacNamespace::FLAC__Frame* frame,
  93725. const FlacNamespace::FLAC__int32* const buffer[],
  93726. void* client_data)
  93727. {
  93728. using namespace FlacNamespace;
  93729. static_cast <FlacReader*> (client_data)->useSamples (buffer, frame->header.blocksize);
  93730. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93731. }
  93732. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93733. const FlacNamespace::FLAC__StreamMetadata* metadata,
  93734. void* client_data)
  93735. {
  93736. static_cast <FlacReader*> (client_data)->useMetadata (metadata->data.stream_info);
  93737. }
  93738. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  93739. {
  93740. }
  93741. juce_UseDebuggingNewOperator
  93742. private:
  93743. FlacNamespace::FLAC__StreamDecoder* decoder;
  93744. AudioSampleBuffer reservoir;
  93745. int reservoirStart, samplesInReservoir;
  93746. bool ok, scanningForLength;
  93747. FlacReader (const FlacReader&);
  93748. FlacReader& operator= (const FlacReader&);
  93749. };
  93750. class FlacWriter : public AudioFormatWriter
  93751. {
  93752. public:
  93753. FlacWriter (OutputStream* const out,
  93754. const double sampleRate_,
  93755. const int numChannels_,
  93756. const int bitsPerSample_)
  93757. : AudioFormatWriter (out, TRANS (flacFormatName),
  93758. sampleRate_,
  93759. numChannels_,
  93760. bitsPerSample_)
  93761. {
  93762. using namespace FlacNamespace;
  93763. encoder = FLAC__stream_encoder_new();
  93764. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  93765. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  93766. FLAC__stream_encoder_set_channels (encoder, numChannels);
  93767. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  93768. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  93769. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  93770. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  93771. ok = FLAC__stream_encoder_init_stream (encoder,
  93772. encodeWriteCallback, encodeSeekCallback,
  93773. encodeTellCallback, encodeMetadataCallback,
  93774. this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  93775. }
  93776. ~FlacWriter()
  93777. {
  93778. if (ok)
  93779. {
  93780. FlacNamespace::FLAC__stream_encoder_finish (encoder);
  93781. output->flush();
  93782. }
  93783. else
  93784. {
  93785. output = 0; // to stop the base class deleting this, as it needs to be returned
  93786. // to the caller of createWriter()
  93787. }
  93788. FlacNamespace::FLAC__stream_encoder_delete (encoder);
  93789. }
  93790. bool write (const int** samplesToWrite, int numSamples)
  93791. {
  93792. using namespace FlacNamespace;
  93793. if (! ok)
  93794. return false;
  93795. int* buf[3];
  93796. const int bitsToShift = 32 - bitsPerSample;
  93797. if (bitsToShift > 0)
  93798. {
  93799. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  93800. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  93801. buf[0] = (int*) temp.getData();
  93802. buf[1] = buf[0] + numSamples;
  93803. buf[2] = 0;
  93804. for (int i = numChannelsToWrite; --i >= 0;)
  93805. {
  93806. if (samplesToWrite[i] != 0)
  93807. {
  93808. for (int j = 0; j < numSamples; ++j)
  93809. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  93810. }
  93811. }
  93812. samplesToWrite = (const int**) buf;
  93813. }
  93814. return FLAC__stream_encoder_process (encoder,
  93815. (const FLAC__int32**) samplesToWrite,
  93816. numSamples) != 0;
  93817. }
  93818. bool writeData (const void* const data, const int size) const
  93819. {
  93820. return output->write (data, size);
  93821. }
  93822. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  93823. {
  93824. using namespace FlacNamespace;
  93825. b += bytes;
  93826. for (int i = 0; i < bytes; ++i)
  93827. {
  93828. *(--b) = (FLAC__byte) (val & 0xff);
  93829. val >>= 8;
  93830. }
  93831. }
  93832. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  93833. {
  93834. using namespace FlacNamespace;
  93835. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  93836. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  93837. const unsigned int channelsMinus1 = info.channels - 1;
  93838. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  93839. packUint32 (info.min_blocksize, buffer, 2);
  93840. packUint32 (info.max_blocksize, buffer + 2, 2);
  93841. packUint32 (info.min_framesize, buffer + 4, 3);
  93842. packUint32 (info.max_framesize, buffer + 7, 3);
  93843. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  93844. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  93845. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  93846. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  93847. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  93848. memcpy (buffer + 18, info.md5sum, 16);
  93849. const bool seekOk = output->setPosition (4);
  93850. (void) seekOk;
  93851. // if this fails, you've given it an output stream that can't seek! It needs
  93852. // to be able to seek back to write the header
  93853. jassert (seekOk);
  93854. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  93855. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  93856. }
  93857. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  93858. const FlacNamespace::FLAC__byte buffer[],
  93859. size_t bytes,
  93860. unsigned int /*samples*/,
  93861. unsigned int /*current_frame*/,
  93862. void* client_data)
  93863. {
  93864. using namespace FlacNamespace;
  93865. return static_cast <FlacWriter*> (client_data)->writeData (buffer, (int) bytes)
  93866. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  93867. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93868. }
  93869. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  93870. {
  93871. using namespace FlacNamespace;
  93872. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  93873. }
  93874. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93875. {
  93876. using namespace FlacNamespace;
  93877. if (client_data == 0)
  93878. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  93879. *absolute_byte_offset = (FLAC__uint64) static_cast <FlacWriter*> (client_data)->output->getPosition();
  93880. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93881. }
  93882. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*, const FlacNamespace::FLAC__StreamMetadata* metadata, void* client_data)
  93883. {
  93884. static_cast <FlacWriter*> (client_data)->writeMetaData (metadata);
  93885. }
  93886. juce_UseDebuggingNewOperator
  93887. bool ok;
  93888. private:
  93889. FlacNamespace::FLAC__StreamEncoder* encoder;
  93890. MemoryBlock temp;
  93891. FlacWriter (const FlacWriter&);
  93892. FlacWriter& operator= (const FlacWriter&);
  93893. };
  93894. FlacAudioFormat::FlacAudioFormat()
  93895. : AudioFormat (TRANS (flacFormatName), (const juce_wchar**) flacExtensions)
  93896. {
  93897. }
  93898. FlacAudioFormat::~FlacAudioFormat()
  93899. {
  93900. }
  93901. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  93902. {
  93903. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  93904. return Array <int> (rates);
  93905. }
  93906. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  93907. {
  93908. const int depths[] = { 16, 24, 0 };
  93909. return Array <int> (depths);
  93910. }
  93911. bool FlacAudioFormat::canDoStereo()
  93912. {
  93913. return true;
  93914. }
  93915. bool FlacAudioFormat::canDoMono()
  93916. {
  93917. return true;
  93918. }
  93919. bool FlacAudioFormat::isCompressed()
  93920. {
  93921. return true;
  93922. }
  93923. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  93924. const bool deleteStreamIfOpeningFails)
  93925. {
  93926. ScopedPointer<FlacReader> r (new FlacReader (in));
  93927. if (r->sampleRate != 0)
  93928. return r.release();
  93929. if (! deleteStreamIfOpeningFails)
  93930. r->input = 0;
  93931. return 0;
  93932. }
  93933. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  93934. double sampleRate,
  93935. unsigned int numberOfChannels,
  93936. int bitsPerSample,
  93937. const StringPairArray& /*metadataValues*/,
  93938. int /*qualityOptionIndex*/)
  93939. {
  93940. if (getPossibleBitDepths().contains (bitsPerSample))
  93941. {
  93942. ScopedPointer<FlacWriter> w (new FlacWriter (out, sampleRate, numberOfChannels, bitsPerSample));
  93943. if (w->ok)
  93944. return w.release();
  93945. }
  93946. return 0;
  93947. }
  93948. END_JUCE_NAMESPACE
  93949. #endif
  93950. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  93951. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  93952. #if JUCE_USE_OGGVORBIS
  93953. #if JUCE_MAC
  93954. #define __MACOSX__ 1
  93955. #endif
  93956. namespace OggVorbisNamespace
  93957. {
  93958. #if JUCE_INCLUDE_OGGVORBIS_CODE
  93959. /*** Start of inlined file: vorbisenc.h ***/
  93960. #ifndef _OV_ENC_H_
  93961. #define _OV_ENC_H_
  93962. #ifdef __cplusplus
  93963. extern "C"
  93964. {
  93965. #endif /* __cplusplus */
  93966. /*** Start of inlined file: codec.h ***/
  93967. #ifndef _vorbis_codec_h_
  93968. #define _vorbis_codec_h_
  93969. #ifdef __cplusplus
  93970. extern "C"
  93971. {
  93972. #endif /* __cplusplus */
  93973. /*** Start of inlined file: ogg.h ***/
  93974. #ifndef _OGG_H
  93975. #define _OGG_H
  93976. #ifdef __cplusplus
  93977. extern "C" {
  93978. #endif
  93979. /*** Start of inlined file: os_types.h ***/
  93980. #ifndef _OS_TYPES_H
  93981. #define _OS_TYPES_H
  93982. #define _ogg_malloc malloc
  93983. #define _ogg_calloc calloc
  93984. #define _ogg_realloc realloc
  93985. #define _ogg_free free
  93986. #if defined(_WIN32)
  93987. # if defined(__CYGWIN__)
  93988. # include <_G_config.h>
  93989. typedef _G_int64_t ogg_int64_t;
  93990. typedef _G_int32_t ogg_int32_t;
  93991. typedef _G_uint32_t ogg_uint32_t;
  93992. typedef _G_int16_t ogg_int16_t;
  93993. typedef _G_uint16_t ogg_uint16_t;
  93994. # elif defined(__MINGW32__)
  93995. typedef short ogg_int16_t;
  93996. typedef unsigned short ogg_uint16_t;
  93997. typedef int ogg_int32_t;
  93998. typedef unsigned int ogg_uint32_t;
  93999. typedef long long ogg_int64_t;
  94000. typedef unsigned long long ogg_uint64_t;
  94001. # elif defined(__MWERKS__)
  94002. typedef long long ogg_int64_t;
  94003. typedef int ogg_int32_t;
  94004. typedef unsigned int ogg_uint32_t;
  94005. typedef short ogg_int16_t;
  94006. typedef unsigned short ogg_uint16_t;
  94007. # else
  94008. typedef __int64 ogg_int64_t;
  94009. typedef __int32 ogg_int32_t;
  94010. typedef unsigned __int32 ogg_uint32_t;
  94011. typedef __int16 ogg_int16_t;
  94012. typedef unsigned __int16 ogg_uint16_t;
  94013. # endif
  94014. #elif defined(__MACOS__)
  94015. # include <sys/types.h>
  94016. typedef SInt16 ogg_int16_t;
  94017. typedef UInt16 ogg_uint16_t;
  94018. typedef SInt32 ogg_int32_t;
  94019. typedef UInt32 ogg_uint32_t;
  94020. typedef SInt64 ogg_int64_t;
  94021. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94022. # include <sys/types.h>
  94023. typedef int16_t ogg_int16_t;
  94024. typedef u_int16_t ogg_uint16_t;
  94025. typedef int32_t ogg_int32_t;
  94026. typedef u_int32_t ogg_uint32_t;
  94027. typedef int64_t ogg_int64_t;
  94028. #elif defined(__BEOS__)
  94029. # include <inttypes.h>
  94030. typedef int16_t ogg_int16_t;
  94031. typedef u_int16_t ogg_uint16_t;
  94032. typedef int32_t ogg_int32_t;
  94033. typedef u_int32_t ogg_uint32_t;
  94034. typedef int64_t ogg_int64_t;
  94035. #elif defined (__EMX__)
  94036. typedef short ogg_int16_t;
  94037. typedef unsigned short ogg_uint16_t;
  94038. typedef int ogg_int32_t;
  94039. typedef unsigned int ogg_uint32_t;
  94040. typedef long long ogg_int64_t;
  94041. #elif defined (DJGPP)
  94042. typedef short ogg_int16_t;
  94043. typedef int ogg_int32_t;
  94044. typedef unsigned int ogg_uint32_t;
  94045. typedef long long ogg_int64_t;
  94046. #elif defined(R5900)
  94047. typedef long ogg_int64_t;
  94048. typedef int ogg_int32_t;
  94049. typedef unsigned ogg_uint32_t;
  94050. typedef short ogg_int16_t;
  94051. #elif defined(__SYMBIAN32__)
  94052. typedef signed short ogg_int16_t;
  94053. typedef unsigned short ogg_uint16_t;
  94054. typedef signed int ogg_int32_t;
  94055. typedef unsigned int ogg_uint32_t;
  94056. typedef long long int ogg_int64_t;
  94057. #else
  94058. # include <sys/types.h>
  94059. /*** Start of inlined file: config_types.h ***/
  94060. #ifndef __CONFIG_TYPES_H__
  94061. #define __CONFIG_TYPES_H__
  94062. typedef int16_t ogg_int16_t;
  94063. typedef unsigned short ogg_uint16_t;
  94064. typedef int32_t ogg_int32_t;
  94065. typedef unsigned int ogg_uint32_t;
  94066. typedef int64_t ogg_int64_t;
  94067. #endif
  94068. /*** End of inlined file: config_types.h ***/
  94069. #endif
  94070. #endif /* _OS_TYPES_H */
  94071. /*** End of inlined file: os_types.h ***/
  94072. typedef struct {
  94073. long endbyte;
  94074. int endbit;
  94075. unsigned char *buffer;
  94076. unsigned char *ptr;
  94077. long storage;
  94078. } oggpack_buffer;
  94079. typedef struct {
  94080. unsigned char *header;
  94081. long header_len;
  94082. unsigned char *body;
  94083. long body_len;
  94084. } ogg_page;
  94085. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94086. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94087. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94088. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94089. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94090. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94091. }
  94092. typedef struct {
  94093. unsigned char *body_data; /* bytes from packet bodies */
  94094. long body_storage; /* storage elements allocated */
  94095. long body_fill; /* elements stored; fill mark */
  94096. long body_returned; /* elements of fill returned */
  94097. int *lacing_vals; /* The values that will go to the segment table */
  94098. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94099. this way, but it is simple coupled to the
  94100. lacing fifo */
  94101. long lacing_storage;
  94102. long lacing_fill;
  94103. long lacing_packet;
  94104. long lacing_returned;
  94105. unsigned char header[282]; /* working space for header encode */
  94106. int header_fill;
  94107. int e_o_s; /* set when we have buffered the last packet in the
  94108. logical bitstream */
  94109. int b_o_s; /* set after we've written the initial page
  94110. of a logical bitstream */
  94111. long serialno;
  94112. long pageno;
  94113. ogg_int64_t packetno; /* sequence number for decode; the framing
  94114. knows where there's a hole in the data,
  94115. but we need coupling so that the codec
  94116. (which is in a seperate abstraction
  94117. layer) also knows about the gap */
  94118. ogg_int64_t granulepos;
  94119. } ogg_stream_state;
  94120. typedef struct {
  94121. unsigned char *packet;
  94122. long bytes;
  94123. long b_o_s;
  94124. long e_o_s;
  94125. ogg_int64_t granulepos;
  94126. ogg_int64_t packetno; /* sequence number for decode; the framing
  94127. knows where there's a hole in the data,
  94128. but we need coupling so that the codec
  94129. (which is in a seperate abstraction
  94130. layer) also knows about the gap */
  94131. } ogg_packet;
  94132. typedef struct {
  94133. unsigned char *data;
  94134. int storage;
  94135. int fill;
  94136. int returned;
  94137. int unsynced;
  94138. int headerbytes;
  94139. int bodybytes;
  94140. } ogg_sync_state;
  94141. extern void oggpack_writeinit(oggpack_buffer *b);
  94142. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94143. extern void oggpack_writealign(oggpack_buffer *b);
  94144. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94145. extern void oggpack_reset(oggpack_buffer *b);
  94146. extern void oggpack_writeclear(oggpack_buffer *b);
  94147. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94148. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94149. extern long oggpack_look(oggpack_buffer *b,int bits);
  94150. extern long oggpack_look1(oggpack_buffer *b);
  94151. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94152. extern void oggpack_adv1(oggpack_buffer *b);
  94153. extern long oggpack_read(oggpack_buffer *b,int bits);
  94154. extern long oggpack_read1(oggpack_buffer *b);
  94155. extern long oggpack_bytes(oggpack_buffer *b);
  94156. extern long oggpack_bits(oggpack_buffer *b);
  94157. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94158. extern void oggpackB_writeinit(oggpack_buffer *b);
  94159. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94160. extern void oggpackB_writealign(oggpack_buffer *b);
  94161. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94162. extern void oggpackB_reset(oggpack_buffer *b);
  94163. extern void oggpackB_writeclear(oggpack_buffer *b);
  94164. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94165. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94166. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94167. extern long oggpackB_look1(oggpack_buffer *b);
  94168. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94169. extern void oggpackB_adv1(oggpack_buffer *b);
  94170. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94171. extern long oggpackB_read1(oggpack_buffer *b);
  94172. extern long oggpackB_bytes(oggpack_buffer *b);
  94173. extern long oggpackB_bits(oggpack_buffer *b);
  94174. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94175. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94176. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94177. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94178. extern int ogg_sync_init(ogg_sync_state *oy);
  94179. extern int ogg_sync_clear(ogg_sync_state *oy);
  94180. extern int ogg_sync_reset(ogg_sync_state *oy);
  94181. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94182. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94183. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94184. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94185. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94186. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94187. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94188. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94189. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94190. extern int ogg_stream_clear(ogg_stream_state *os);
  94191. extern int ogg_stream_reset(ogg_stream_state *os);
  94192. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94193. extern int ogg_stream_destroy(ogg_stream_state *os);
  94194. extern int ogg_stream_eos(ogg_stream_state *os);
  94195. extern void ogg_page_checksum_set(ogg_page *og);
  94196. extern int ogg_page_version(ogg_page *og);
  94197. extern int ogg_page_continued(ogg_page *og);
  94198. extern int ogg_page_bos(ogg_page *og);
  94199. extern int ogg_page_eos(ogg_page *og);
  94200. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94201. extern int ogg_page_serialno(ogg_page *og);
  94202. extern long ogg_page_pageno(ogg_page *og);
  94203. extern int ogg_page_packets(ogg_page *og);
  94204. extern void ogg_packet_clear(ogg_packet *op);
  94205. #ifdef __cplusplus
  94206. }
  94207. #endif
  94208. #endif /* _OGG_H */
  94209. /*** End of inlined file: ogg.h ***/
  94210. typedef struct vorbis_info{
  94211. int version;
  94212. int channels;
  94213. long rate;
  94214. long bitrate_upper;
  94215. long bitrate_nominal;
  94216. long bitrate_lower;
  94217. long bitrate_window;
  94218. void *codec_setup;
  94219. } vorbis_info;
  94220. typedef struct vorbis_dsp_state{
  94221. int analysisp;
  94222. vorbis_info *vi;
  94223. float **pcm;
  94224. float **pcmret;
  94225. int pcm_storage;
  94226. int pcm_current;
  94227. int pcm_returned;
  94228. int preextrapolate;
  94229. int eofflag;
  94230. long lW;
  94231. long W;
  94232. long nW;
  94233. long centerW;
  94234. ogg_int64_t granulepos;
  94235. ogg_int64_t sequence;
  94236. ogg_int64_t glue_bits;
  94237. ogg_int64_t time_bits;
  94238. ogg_int64_t floor_bits;
  94239. ogg_int64_t res_bits;
  94240. void *backend_state;
  94241. } vorbis_dsp_state;
  94242. typedef struct vorbis_block{
  94243. float **pcm; /* this is a pointer into local storage */
  94244. oggpack_buffer opb;
  94245. long lW;
  94246. long W;
  94247. long nW;
  94248. int pcmend;
  94249. int mode;
  94250. int eofflag;
  94251. ogg_int64_t granulepos;
  94252. ogg_int64_t sequence;
  94253. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94254. void *localstore;
  94255. long localtop;
  94256. long localalloc;
  94257. long totaluse;
  94258. struct alloc_chain *reap;
  94259. long glue_bits;
  94260. long time_bits;
  94261. long floor_bits;
  94262. long res_bits;
  94263. void *internal;
  94264. } vorbis_block;
  94265. struct alloc_chain{
  94266. void *ptr;
  94267. struct alloc_chain *next;
  94268. };
  94269. typedef struct vorbis_comment{
  94270. char **user_comments;
  94271. int *comment_lengths;
  94272. int comments;
  94273. char *vendor;
  94274. } vorbis_comment;
  94275. extern void vorbis_info_init(vorbis_info *vi);
  94276. extern void vorbis_info_clear(vorbis_info *vi);
  94277. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94278. extern void vorbis_comment_init(vorbis_comment *vc);
  94279. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94280. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94281. const char *tag, char *contents);
  94282. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94283. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94284. extern void vorbis_comment_clear(vorbis_comment *vc);
  94285. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94286. extern int vorbis_block_clear(vorbis_block *vb);
  94287. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94288. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94289. ogg_int64_t granulepos);
  94290. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94291. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94292. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94293. vorbis_comment *vc,
  94294. ogg_packet *op,
  94295. ogg_packet *op_comm,
  94296. ogg_packet *op_code);
  94297. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94298. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94299. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94300. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94301. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94302. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94303. ogg_packet *op);
  94304. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94305. ogg_packet *op);
  94306. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94307. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94308. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94309. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94310. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94311. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94312. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94313. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94314. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94315. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94316. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94317. #define OV_FALSE -1
  94318. #define OV_EOF -2
  94319. #define OV_HOLE -3
  94320. #define OV_EREAD -128
  94321. #define OV_EFAULT -129
  94322. #define OV_EIMPL -130
  94323. #define OV_EINVAL -131
  94324. #define OV_ENOTVORBIS -132
  94325. #define OV_EBADHEADER -133
  94326. #define OV_EVERSION -134
  94327. #define OV_ENOTAUDIO -135
  94328. #define OV_EBADPACKET -136
  94329. #define OV_EBADLINK -137
  94330. #define OV_ENOSEEK -138
  94331. #ifdef __cplusplus
  94332. }
  94333. #endif /* __cplusplus */
  94334. #endif
  94335. /*** End of inlined file: codec.h ***/
  94336. extern int vorbis_encode_init(vorbis_info *vi,
  94337. long channels,
  94338. long rate,
  94339. long max_bitrate,
  94340. long nominal_bitrate,
  94341. long min_bitrate);
  94342. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94343. long channels,
  94344. long rate,
  94345. long max_bitrate,
  94346. long nominal_bitrate,
  94347. long min_bitrate);
  94348. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94349. long channels,
  94350. long rate,
  94351. float quality /* quality level from 0. (lo) to 1. (hi) */
  94352. );
  94353. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94354. long channels,
  94355. long rate,
  94356. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94357. );
  94358. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94359. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94360. #define OV_ECTL_RATEMANAGE_GET 0x10
  94361. #define OV_ECTL_RATEMANAGE_SET 0x11
  94362. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94363. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94364. struct ovectl_ratemanage_arg {
  94365. int management_active;
  94366. long bitrate_hard_min;
  94367. long bitrate_hard_max;
  94368. double bitrate_hard_window;
  94369. long bitrate_av_lo;
  94370. long bitrate_av_hi;
  94371. double bitrate_av_window;
  94372. double bitrate_av_window_center;
  94373. };
  94374. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94375. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94376. struct ovectl_ratemanage2_arg {
  94377. int management_active;
  94378. long bitrate_limit_min_kbps;
  94379. long bitrate_limit_max_kbps;
  94380. long bitrate_limit_reservoir_bits;
  94381. double bitrate_limit_reservoir_bias;
  94382. long bitrate_average_kbps;
  94383. double bitrate_average_damping;
  94384. };
  94385. #define OV_ECTL_LOWPASS_GET 0x20
  94386. #define OV_ECTL_LOWPASS_SET 0x21
  94387. #define OV_ECTL_IBLOCK_GET 0x30
  94388. #define OV_ECTL_IBLOCK_SET 0x31
  94389. #ifdef __cplusplus
  94390. }
  94391. #endif /* __cplusplus */
  94392. #endif
  94393. /*** End of inlined file: vorbisenc.h ***/
  94394. /*** Start of inlined file: vorbisfile.h ***/
  94395. #ifndef _OV_FILE_H_
  94396. #define _OV_FILE_H_
  94397. #ifdef __cplusplus
  94398. extern "C"
  94399. {
  94400. #endif /* __cplusplus */
  94401. #include <stdio.h>
  94402. typedef struct {
  94403. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94404. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94405. int (*close_func) (void *datasource);
  94406. long (*tell_func) (void *datasource);
  94407. } ov_callbacks;
  94408. #define NOTOPEN 0
  94409. #define PARTOPEN 1
  94410. #define OPENED 2
  94411. #define STREAMSET 3
  94412. #define INITSET 4
  94413. typedef struct OggVorbis_File {
  94414. void *datasource; /* Pointer to a FILE *, etc. */
  94415. int seekable;
  94416. ogg_int64_t offset;
  94417. ogg_int64_t end;
  94418. ogg_sync_state oy;
  94419. int links;
  94420. ogg_int64_t *offsets;
  94421. ogg_int64_t *dataoffsets;
  94422. long *serialnos;
  94423. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94424. compatability; x2 size, stores both
  94425. beginning and end values */
  94426. vorbis_info *vi;
  94427. vorbis_comment *vc;
  94428. ogg_int64_t pcm_offset;
  94429. int ready_state;
  94430. long current_serialno;
  94431. int current_link;
  94432. double bittrack;
  94433. double samptrack;
  94434. ogg_stream_state os; /* take physical pages, weld into a logical
  94435. stream of packets */
  94436. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94437. vorbis_block vb; /* local working space for packet->PCM decode */
  94438. ov_callbacks callbacks;
  94439. } OggVorbis_File;
  94440. extern int ov_clear(OggVorbis_File *vf);
  94441. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94442. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94443. char *initial, long ibytes, ov_callbacks callbacks);
  94444. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94445. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94446. char *initial, long ibytes, ov_callbacks callbacks);
  94447. extern int ov_test_open(OggVorbis_File *vf);
  94448. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94449. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94450. extern long ov_streams(OggVorbis_File *vf);
  94451. extern long ov_seekable(OggVorbis_File *vf);
  94452. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94453. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94454. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94455. extern double ov_time_total(OggVorbis_File *vf,int i);
  94456. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94457. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94458. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94459. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94460. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94461. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94462. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94463. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94464. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94465. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94466. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94467. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94468. extern double ov_time_tell(OggVorbis_File *vf);
  94469. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94470. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94471. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94472. int *bitstream);
  94473. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94474. int bigendianp,int word,int sgned,int *bitstream);
  94475. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94476. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94477. extern int ov_halfrate_p(OggVorbis_File *vf);
  94478. #ifdef __cplusplus
  94479. }
  94480. #endif /* __cplusplus */
  94481. #endif
  94482. /*** End of inlined file: vorbisfile.h ***/
  94483. /*** Start of inlined file: bitwise.c ***/
  94484. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94485. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94486. // tasks..
  94487. #if JUCE_MSVC
  94488. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94489. #endif
  94490. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94491. #if JUCE_USE_OGGVORBIS
  94492. #include <string.h>
  94493. #include <stdlib.h>
  94494. #define BUFFER_INCREMENT 256
  94495. static const unsigned long mask[]=
  94496. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94497. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94498. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94499. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94500. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94501. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94502. 0x3fffffff,0x7fffffff,0xffffffff };
  94503. static const unsigned int mask8B[]=
  94504. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94505. void oggpack_writeinit(oggpack_buffer *b){
  94506. memset(b,0,sizeof(*b));
  94507. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94508. b->buffer[0]='\0';
  94509. b->storage=BUFFER_INCREMENT;
  94510. }
  94511. void oggpackB_writeinit(oggpack_buffer *b){
  94512. oggpack_writeinit(b);
  94513. }
  94514. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94515. long bytes=bits>>3;
  94516. bits-=bytes*8;
  94517. b->ptr=b->buffer+bytes;
  94518. b->endbit=bits;
  94519. b->endbyte=bytes;
  94520. *b->ptr&=mask[bits];
  94521. }
  94522. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94523. long bytes=bits>>3;
  94524. bits-=bytes*8;
  94525. b->ptr=b->buffer+bytes;
  94526. b->endbit=bits;
  94527. b->endbyte=bytes;
  94528. *b->ptr&=mask8B[bits];
  94529. }
  94530. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94531. if(b->endbyte+4>=b->storage){
  94532. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94533. b->storage+=BUFFER_INCREMENT;
  94534. b->ptr=b->buffer+b->endbyte;
  94535. }
  94536. value&=mask[bits];
  94537. bits+=b->endbit;
  94538. b->ptr[0]|=value<<b->endbit;
  94539. if(bits>=8){
  94540. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94541. if(bits>=16){
  94542. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94543. if(bits>=24){
  94544. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94545. if(bits>=32){
  94546. if(b->endbit)
  94547. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94548. else
  94549. b->ptr[4]=0;
  94550. }
  94551. }
  94552. }
  94553. }
  94554. b->endbyte+=bits/8;
  94555. b->ptr+=bits/8;
  94556. b->endbit=bits&7;
  94557. }
  94558. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94559. if(b->endbyte+4>=b->storage){
  94560. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94561. b->storage+=BUFFER_INCREMENT;
  94562. b->ptr=b->buffer+b->endbyte;
  94563. }
  94564. value=(value&mask[bits])<<(32-bits);
  94565. bits+=b->endbit;
  94566. b->ptr[0]|=value>>(24+b->endbit);
  94567. if(bits>=8){
  94568. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94569. if(bits>=16){
  94570. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94571. if(bits>=24){
  94572. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94573. if(bits>=32){
  94574. if(b->endbit)
  94575. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94576. else
  94577. b->ptr[4]=0;
  94578. }
  94579. }
  94580. }
  94581. }
  94582. b->endbyte+=bits/8;
  94583. b->ptr+=bits/8;
  94584. b->endbit=bits&7;
  94585. }
  94586. void oggpack_writealign(oggpack_buffer *b){
  94587. int bits=8-b->endbit;
  94588. if(bits<8)
  94589. oggpack_write(b,0,bits);
  94590. }
  94591. void oggpackB_writealign(oggpack_buffer *b){
  94592. int bits=8-b->endbit;
  94593. if(bits<8)
  94594. oggpackB_write(b,0,bits);
  94595. }
  94596. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94597. void *source,
  94598. long bits,
  94599. void (*w)(oggpack_buffer *,
  94600. unsigned long,
  94601. int),
  94602. int msb){
  94603. unsigned char *ptr=(unsigned char *)source;
  94604. long bytes=bits/8;
  94605. bits-=bytes*8;
  94606. if(b->endbit){
  94607. int i;
  94608. for(i=0;i<bytes;i++)
  94609. w(b,(unsigned long)(ptr[i]),8);
  94610. }else{
  94611. if(b->endbyte+bytes+1>=b->storage){
  94612. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94613. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94614. b->ptr=b->buffer+b->endbyte;
  94615. }
  94616. memmove(b->ptr,source,bytes);
  94617. b->ptr+=bytes;
  94618. b->endbyte+=bytes;
  94619. *b->ptr=0;
  94620. }
  94621. if(bits){
  94622. if(msb)
  94623. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94624. else
  94625. w(b,(unsigned long)(ptr[bytes]),bits);
  94626. }
  94627. }
  94628. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94629. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94630. }
  94631. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94632. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94633. }
  94634. void oggpack_reset(oggpack_buffer *b){
  94635. b->ptr=b->buffer;
  94636. b->buffer[0]=0;
  94637. b->endbit=b->endbyte=0;
  94638. }
  94639. void oggpackB_reset(oggpack_buffer *b){
  94640. oggpack_reset(b);
  94641. }
  94642. void oggpack_writeclear(oggpack_buffer *b){
  94643. _ogg_free(b->buffer);
  94644. memset(b,0,sizeof(*b));
  94645. }
  94646. void oggpackB_writeclear(oggpack_buffer *b){
  94647. oggpack_writeclear(b);
  94648. }
  94649. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94650. memset(b,0,sizeof(*b));
  94651. b->buffer=b->ptr=buf;
  94652. b->storage=bytes;
  94653. }
  94654. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94655. oggpack_readinit(b,buf,bytes);
  94656. }
  94657. long oggpack_look(oggpack_buffer *b,int bits){
  94658. unsigned long ret;
  94659. unsigned long m=mask[bits];
  94660. bits+=b->endbit;
  94661. if(b->endbyte+4>=b->storage){
  94662. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94663. }
  94664. ret=b->ptr[0]>>b->endbit;
  94665. if(bits>8){
  94666. ret|=b->ptr[1]<<(8-b->endbit);
  94667. if(bits>16){
  94668. ret|=b->ptr[2]<<(16-b->endbit);
  94669. if(bits>24){
  94670. ret|=b->ptr[3]<<(24-b->endbit);
  94671. if(bits>32 && b->endbit)
  94672. ret|=b->ptr[4]<<(32-b->endbit);
  94673. }
  94674. }
  94675. }
  94676. return(m&ret);
  94677. }
  94678. long oggpackB_look(oggpack_buffer *b,int bits){
  94679. unsigned long ret;
  94680. int m=32-bits;
  94681. bits+=b->endbit;
  94682. if(b->endbyte+4>=b->storage){
  94683. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94684. }
  94685. ret=b->ptr[0]<<(24+b->endbit);
  94686. if(bits>8){
  94687. ret|=b->ptr[1]<<(16+b->endbit);
  94688. if(bits>16){
  94689. ret|=b->ptr[2]<<(8+b->endbit);
  94690. if(bits>24){
  94691. ret|=b->ptr[3]<<(b->endbit);
  94692. if(bits>32 && b->endbit)
  94693. ret|=b->ptr[4]>>(8-b->endbit);
  94694. }
  94695. }
  94696. }
  94697. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  94698. }
  94699. long oggpack_look1(oggpack_buffer *b){
  94700. if(b->endbyte>=b->storage)return(-1);
  94701. return((b->ptr[0]>>b->endbit)&1);
  94702. }
  94703. long oggpackB_look1(oggpack_buffer *b){
  94704. if(b->endbyte>=b->storage)return(-1);
  94705. return((b->ptr[0]>>(7-b->endbit))&1);
  94706. }
  94707. void oggpack_adv(oggpack_buffer *b,int bits){
  94708. bits+=b->endbit;
  94709. b->ptr+=bits/8;
  94710. b->endbyte+=bits/8;
  94711. b->endbit=bits&7;
  94712. }
  94713. void oggpackB_adv(oggpack_buffer *b,int bits){
  94714. oggpack_adv(b,bits);
  94715. }
  94716. void oggpack_adv1(oggpack_buffer *b){
  94717. if(++(b->endbit)>7){
  94718. b->endbit=0;
  94719. b->ptr++;
  94720. b->endbyte++;
  94721. }
  94722. }
  94723. void oggpackB_adv1(oggpack_buffer *b){
  94724. oggpack_adv1(b);
  94725. }
  94726. long oggpack_read(oggpack_buffer *b,int bits){
  94727. long ret;
  94728. unsigned long m=mask[bits];
  94729. bits+=b->endbit;
  94730. if(b->endbyte+4>=b->storage){
  94731. ret=-1L;
  94732. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94733. }
  94734. ret=b->ptr[0]>>b->endbit;
  94735. if(bits>8){
  94736. ret|=b->ptr[1]<<(8-b->endbit);
  94737. if(bits>16){
  94738. ret|=b->ptr[2]<<(16-b->endbit);
  94739. if(bits>24){
  94740. ret|=b->ptr[3]<<(24-b->endbit);
  94741. if(bits>32 && b->endbit){
  94742. ret|=b->ptr[4]<<(32-b->endbit);
  94743. }
  94744. }
  94745. }
  94746. }
  94747. ret&=m;
  94748. overflow:
  94749. b->ptr+=bits/8;
  94750. b->endbyte+=bits/8;
  94751. b->endbit=bits&7;
  94752. return(ret);
  94753. }
  94754. long oggpackB_read(oggpack_buffer *b,int bits){
  94755. long ret;
  94756. long m=32-bits;
  94757. bits+=b->endbit;
  94758. if(b->endbyte+4>=b->storage){
  94759. ret=-1L;
  94760. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94761. }
  94762. ret=b->ptr[0]<<(24+b->endbit);
  94763. if(bits>8){
  94764. ret|=b->ptr[1]<<(16+b->endbit);
  94765. if(bits>16){
  94766. ret|=b->ptr[2]<<(8+b->endbit);
  94767. if(bits>24){
  94768. ret|=b->ptr[3]<<(b->endbit);
  94769. if(bits>32 && b->endbit)
  94770. ret|=b->ptr[4]>>(8-b->endbit);
  94771. }
  94772. }
  94773. }
  94774. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  94775. overflow:
  94776. b->ptr+=bits/8;
  94777. b->endbyte+=bits/8;
  94778. b->endbit=bits&7;
  94779. return(ret);
  94780. }
  94781. long oggpack_read1(oggpack_buffer *b){
  94782. long ret;
  94783. if(b->endbyte>=b->storage){
  94784. ret=-1L;
  94785. goto overflow;
  94786. }
  94787. ret=(b->ptr[0]>>b->endbit)&1;
  94788. overflow:
  94789. b->endbit++;
  94790. if(b->endbit>7){
  94791. b->endbit=0;
  94792. b->ptr++;
  94793. b->endbyte++;
  94794. }
  94795. return(ret);
  94796. }
  94797. long oggpackB_read1(oggpack_buffer *b){
  94798. long ret;
  94799. if(b->endbyte>=b->storage){
  94800. ret=-1L;
  94801. goto overflow;
  94802. }
  94803. ret=(b->ptr[0]>>(7-b->endbit))&1;
  94804. overflow:
  94805. b->endbit++;
  94806. if(b->endbit>7){
  94807. b->endbit=0;
  94808. b->ptr++;
  94809. b->endbyte++;
  94810. }
  94811. return(ret);
  94812. }
  94813. long oggpack_bytes(oggpack_buffer *b){
  94814. return(b->endbyte+(b->endbit+7)/8);
  94815. }
  94816. long oggpack_bits(oggpack_buffer *b){
  94817. return(b->endbyte*8+b->endbit);
  94818. }
  94819. long oggpackB_bytes(oggpack_buffer *b){
  94820. return oggpack_bytes(b);
  94821. }
  94822. long oggpackB_bits(oggpack_buffer *b){
  94823. return oggpack_bits(b);
  94824. }
  94825. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  94826. return(b->buffer);
  94827. }
  94828. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  94829. return oggpack_get_buffer(b);
  94830. }
  94831. #ifdef _V_SELFTEST
  94832. #include <stdio.h>
  94833. static int ilog(unsigned int v){
  94834. int ret=0;
  94835. while(v){
  94836. ret++;
  94837. v>>=1;
  94838. }
  94839. return(ret);
  94840. }
  94841. oggpack_buffer o;
  94842. oggpack_buffer r;
  94843. void report(char *in){
  94844. fprintf(stderr,"%s",in);
  94845. exit(1);
  94846. }
  94847. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  94848. long bytes,i;
  94849. unsigned char *buffer;
  94850. oggpack_reset(&o);
  94851. for(i=0;i<vals;i++)
  94852. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  94853. buffer=oggpack_get_buffer(&o);
  94854. bytes=oggpack_bytes(&o);
  94855. if(bytes!=compsize)report("wrong number of bytes!\n");
  94856. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  94857. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  94858. report("wrote incorrect value!\n");
  94859. }
  94860. oggpack_readinit(&r,buffer,bytes);
  94861. for(i=0;i<vals;i++){
  94862. int tbit=bits?bits:ilog(b[i]);
  94863. if(oggpack_look(&r,tbit)==-1)
  94864. report("out of data!\n");
  94865. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  94866. report("looked at incorrect value!\n");
  94867. if(tbit==1)
  94868. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  94869. report("looked at single bit incorrect value!\n");
  94870. if(tbit==1){
  94871. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  94872. report("read incorrect single bit value!\n");
  94873. }else{
  94874. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  94875. report("read incorrect value!\n");
  94876. }
  94877. }
  94878. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  94879. }
  94880. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  94881. long bytes,i;
  94882. unsigned char *buffer;
  94883. oggpackB_reset(&o);
  94884. for(i=0;i<vals;i++)
  94885. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  94886. buffer=oggpackB_get_buffer(&o);
  94887. bytes=oggpackB_bytes(&o);
  94888. if(bytes!=compsize)report("wrong number of bytes!\n");
  94889. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  94890. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  94891. report("wrote incorrect value!\n");
  94892. }
  94893. oggpackB_readinit(&r,buffer,bytes);
  94894. for(i=0;i<vals;i++){
  94895. int tbit=bits?bits:ilog(b[i]);
  94896. if(oggpackB_look(&r,tbit)==-1)
  94897. report("out of data!\n");
  94898. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  94899. report("looked at incorrect value!\n");
  94900. if(tbit==1)
  94901. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  94902. report("looked at single bit incorrect value!\n");
  94903. if(tbit==1){
  94904. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  94905. report("read incorrect single bit value!\n");
  94906. }else{
  94907. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  94908. report("read incorrect value!\n");
  94909. }
  94910. }
  94911. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  94912. }
  94913. int main(void){
  94914. unsigned char *buffer;
  94915. long bytes,i;
  94916. static unsigned long testbuffer1[]=
  94917. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  94918. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  94919. int test1size=43;
  94920. static unsigned long testbuffer2[]=
  94921. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  94922. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  94923. 85525151,0,12321,1,349528352};
  94924. int test2size=21;
  94925. static unsigned long testbuffer3[]=
  94926. {1,0,14,0,1,0,12,0,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,1,1,1,0,0,1,
  94927. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  94928. int test3size=56;
  94929. static unsigned long large[]=
  94930. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  94931. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  94932. 85525151,0,12321,1,2146528352};
  94933. int onesize=33;
  94934. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  94935. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  94936. 223,4};
  94937. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  94938. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  94939. 245,251,128};
  94940. int twosize=6;
  94941. static int two[6]={61,255,255,251,231,29};
  94942. static int twoB[6]={247,63,255,253,249,120};
  94943. int threesize=54;
  94944. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  94945. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  94946. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  94947. 100,52,4,14,18,86,77,1};
  94948. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  94949. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  94950. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  94951. 200,20,254,4,58,106,176,144,0};
  94952. int foursize=38;
  94953. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  94954. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  94955. 28,2,133,0,1};
  94956. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  94957. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  94958. 129,10,4,32};
  94959. int fivesize=45;
  94960. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  94961. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  94962. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  94963. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  94964. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  94965. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  94966. int sixsize=7;
  94967. static int six[7]={17,177,170,242,169,19,148};
  94968. static int sixB[7]={136,141,85,79,149,200,41};
  94969. oggpack_writeinit(&o);
  94970. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  94971. cliptest(testbuffer1,test1size,0,one,onesize);
  94972. fprintf(stderr,"ok.");
  94973. fprintf(stderr,"\nNull bit call (LSb): ");
  94974. cliptest(testbuffer3,test3size,0,two,twosize);
  94975. fprintf(stderr,"ok.");
  94976. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  94977. cliptest(testbuffer2,test2size,0,three,threesize);
  94978. fprintf(stderr,"ok.");
  94979. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  94980. oggpack_reset(&o);
  94981. for(i=0;i<test2size;i++)
  94982. oggpack_write(&o,large[i],32);
  94983. buffer=oggpack_get_buffer(&o);
  94984. bytes=oggpack_bytes(&o);
  94985. oggpack_readinit(&r,buffer,bytes);
  94986. for(i=0;i<test2size;i++){
  94987. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  94988. if(oggpack_look(&r,32)!=large[i]){
  94989. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  94990. oggpack_look(&r,32),large[i]);
  94991. report("read incorrect value!\n");
  94992. }
  94993. oggpack_adv(&r,32);
  94994. }
  94995. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  94996. fprintf(stderr,"ok.");
  94997. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  94998. cliptest(testbuffer1,test1size,7,four,foursize);
  94999. fprintf(stderr,"ok.");
  95000. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95001. cliptest(testbuffer2,test2size,17,five,fivesize);
  95002. fprintf(stderr,"ok.");
  95003. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95004. cliptest(testbuffer3,test3size,1,six,sixsize);
  95005. fprintf(stderr,"ok.");
  95006. fprintf(stderr,"\nTesting read past end (LSb): ");
  95007. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95008. for(i=0;i<64;i++){
  95009. if(oggpack_read(&r,1)!=0){
  95010. fprintf(stderr,"failed; got -1 prematurely.\n");
  95011. exit(1);
  95012. }
  95013. }
  95014. if(oggpack_look(&r,1)!=-1 ||
  95015. oggpack_read(&r,1)!=-1){
  95016. fprintf(stderr,"failed; read past end without -1.\n");
  95017. exit(1);
  95018. }
  95019. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95020. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95021. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95022. exit(1);
  95023. }
  95024. if(oggpack_look(&r,18)!=0 ||
  95025. oggpack_look(&r,18)!=0){
  95026. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95027. exit(1);
  95028. }
  95029. if(oggpack_look(&r,19)!=-1 ||
  95030. oggpack_look(&r,19)!=-1){
  95031. fprintf(stderr,"failed; read past end without -1.\n");
  95032. exit(1);
  95033. }
  95034. if(oggpack_look(&r,32)!=-1 ||
  95035. oggpack_look(&r,32)!=-1){
  95036. fprintf(stderr,"failed; read past end without -1.\n");
  95037. exit(1);
  95038. }
  95039. oggpack_writeclear(&o);
  95040. fprintf(stderr,"ok.\n");
  95041. oggpackB_writeinit(&o);
  95042. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95043. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95044. fprintf(stderr,"ok.");
  95045. fprintf(stderr,"\nNull bit call (MSb): ");
  95046. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95047. fprintf(stderr,"ok.");
  95048. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95049. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95050. fprintf(stderr,"ok.");
  95051. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95052. oggpackB_reset(&o);
  95053. for(i=0;i<test2size;i++)
  95054. oggpackB_write(&o,large[i],32);
  95055. buffer=oggpackB_get_buffer(&o);
  95056. bytes=oggpackB_bytes(&o);
  95057. oggpackB_readinit(&r,buffer,bytes);
  95058. for(i=0;i<test2size;i++){
  95059. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95060. if(oggpackB_look(&r,32)!=large[i]){
  95061. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95062. oggpackB_look(&r,32),large[i]);
  95063. report("read incorrect value!\n");
  95064. }
  95065. oggpackB_adv(&r,32);
  95066. }
  95067. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95068. fprintf(stderr,"ok.");
  95069. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95070. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95071. fprintf(stderr,"ok.");
  95072. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95073. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95074. fprintf(stderr,"ok.");
  95075. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95076. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95077. fprintf(stderr,"ok.");
  95078. fprintf(stderr,"\nTesting read past end (MSb): ");
  95079. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95080. for(i=0;i<64;i++){
  95081. if(oggpackB_read(&r,1)!=0){
  95082. fprintf(stderr,"failed; got -1 prematurely.\n");
  95083. exit(1);
  95084. }
  95085. }
  95086. if(oggpackB_look(&r,1)!=-1 ||
  95087. oggpackB_read(&r,1)!=-1){
  95088. fprintf(stderr,"failed; read past end without -1.\n");
  95089. exit(1);
  95090. }
  95091. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95092. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95093. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95094. exit(1);
  95095. }
  95096. if(oggpackB_look(&r,18)!=0 ||
  95097. oggpackB_look(&r,18)!=0){
  95098. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95099. exit(1);
  95100. }
  95101. if(oggpackB_look(&r,19)!=-1 ||
  95102. oggpackB_look(&r,19)!=-1){
  95103. fprintf(stderr,"failed; read past end without -1.\n");
  95104. exit(1);
  95105. }
  95106. if(oggpackB_look(&r,32)!=-1 ||
  95107. oggpackB_look(&r,32)!=-1){
  95108. fprintf(stderr,"failed; read past end without -1.\n");
  95109. exit(1);
  95110. }
  95111. oggpackB_writeclear(&o);
  95112. fprintf(stderr,"ok.\n\n");
  95113. return(0);
  95114. }
  95115. #endif /* _V_SELFTEST */
  95116. #undef BUFFER_INCREMENT
  95117. #endif
  95118. /*** End of inlined file: bitwise.c ***/
  95119. /*** Start of inlined file: framing.c ***/
  95120. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95121. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95122. // tasks..
  95123. #if JUCE_MSVC
  95124. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95125. #endif
  95126. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95127. #if JUCE_USE_OGGVORBIS
  95128. #include <stdlib.h>
  95129. #include <string.h>
  95130. int ogg_page_version(ogg_page *og){
  95131. return((int)(og->header[4]));
  95132. }
  95133. int ogg_page_continued(ogg_page *og){
  95134. return((int)(og->header[5]&0x01));
  95135. }
  95136. int ogg_page_bos(ogg_page *og){
  95137. return((int)(og->header[5]&0x02));
  95138. }
  95139. int ogg_page_eos(ogg_page *og){
  95140. return((int)(og->header[5]&0x04));
  95141. }
  95142. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95143. unsigned char *page=og->header;
  95144. ogg_int64_t granulepos=page[13]&(0xff);
  95145. granulepos= (granulepos<<8)|(page[12]&0xff);
  95146. granulepos= (granulepos<<8)|(page[11]&0xff);
  95147. granulepos= (granulepos<<8)|(page[10]&0xff);
  95148. granulepos= (granulepos<<8)|(page[9]&0xff);
  95149. granulepos= (granulepos<<8)|(page[8]&0xff);
  95150. granulepos= (granulepos<<8)|(page[7]&0xff);
  95151. granulepos= (granulepos<<8)|(page[6]&0xff);
  95152. return(granulepos);
  95153. }
  95154. int ogg_page_serialno(ogg_page *og){
  95155. return(og->header[14] |
  95156. (og->header[15]<<8) |
  95157. (og->header[16]<<16) |
  95158. (og->header[17]<<24));
  95159. }
  95160. long ogg_page_pageno(ogg_page *og){
  95161. return(og->header[18] |
  95162. (og->header[19]<<8) |
  95163. (og->header[20]<<16) |
  95164. (og->header[21]<<24));
  95165. }
  95166. int ogg_page_packets(ogg_page *og){
  95167. int i,n=og->header[26],count=0;
  95168. for(i=0;i<n;i++)
  95169. if(og->header[27+i]<255)count++;
  95170. return(count);
  95171. }
  95172. #if 0
  95173. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95174. int i;
  95175. unsigned long r;
  95176. r = index << 24;
  95177. for (i=0; i<8; i++)
  95178. if (r & 0x80000000UL)
  95179. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95180. polynomial, although we use an
  95181. unreflected alg and an init/final
  95182. of 0, not 0xffffffff */
  95183. else
  95184. r<<=1;
  95185. return (r & 0xffffffffUL);
  95186. }
  95187. #endif
  95188. static const ogg_uint32_t crc_lookup[256]={
  95189. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95190. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95191. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95192. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95193. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95194. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95195. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95196. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95197. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95198. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95199. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95200. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95201. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95202. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95203. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95204. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95205. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95206. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95207. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95208. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95209. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95210. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95211. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95212. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95213. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95214. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95215. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95216. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95217. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95218. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95219. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95220. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95221. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95222. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95223. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95224. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95225. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95226. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95227. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95228. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95229. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95230. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95231. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95232. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95233. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95234. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95235. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95236. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95237. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95238. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95239. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95240. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95241. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95242. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95243. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95244. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95245. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95246. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95247. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95248. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95249. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95250. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95251. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95252. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95253. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95254. if(os){
  95255. memset(os,0,sizeof(*os));
  95256. os->body_storage=16*1024;
  95257. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95258. os->lacing_storage=1024;
  95259. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95260. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95261. os->serialno=serialno;
  95262. return(0);
  95263. }
  95264. return(-1);
  95265. }
  95266. int ogg_stream_clear(ogg_stream_state *os){
  95267. if(os){
  95268. if(os->body_data)_ogg_free(os->body_data);
  95269. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95270. if(os->granule_vals)_ogg_free(os->granule_vals);
  95271. memset(os,0,sizeof(*os));
  95272. }
  95273. return(0);
  95274. }
  95275. int ogg_stream_destroy(ogg_stream_state *os){
  95276. if(os){
  95277. ogg_stream_clear(os);
  95278. _ogg_free(os);
  95279. }
  95280. return(0);
  95281. }
  95282. static void _os_body_expand(ogg_stream_state *os,int needed){
  95283. if(os->body_storage<=os->body_fill+needed){
  95284. os->body_storage+=(needed+1024);
  95285. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95286. }
  95287. }
  95288. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95289. if(os->lacing_storage<=os->lacing_fill+needed){
  95290. os->lacing_storage+=(needed+32);
  95291. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95292. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95293. }
  95294. }
  95295. void ogg_page_checksum_set(ogg_page *og){
  95296. if(og){
  95297. ogg_uint32_t crc_reg=0;
  95298. int i;
  95299. og->header[22]=0;
  95300. og->header[23]=0;
  95301. og->header[24]=0;
  95302. og->header[25]=0;
  95303. for(i=0;i<og->header_len;i++)
  95304. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95305. for(i=0;i<og->body_len;i++)
  95306. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95307. og->header[22]=(unsigned char)(crc_reg&0xff);
  95308. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95309. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95310. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95311. }
  95312. }
  95313. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95314. int lacing_vals=op->bytes/255+1,i;
  95315. if(os->body_returned){
  95316. os->body_fill-=os->body_returned;
  95317. if(os->body_fill)
  95318. memmove(os->body_data,os->body_data+os->body_returned,
  95319. os->body_fill);
  95320. os->body_returned=0;
  95321. }
  95322. _os_body_expand(os,op->bytes);
  95323. _os_lacing_expand(os,lacing_vals);
  95324. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95325. os->body_fill+=op->bytes;
  95326. for(i=0;i<lacing_vals-1;i++){
  95327. os->lacing_vals[os->lacing_fill+i]=255;
  95328. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95329. }
  95330. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95331. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95332. os->lacing_vals[os->lacing_fill]|= 0x100;
  95333. os->lacing_fill+=lacing_vals;
  95334. os->packetno++;
  95335. if(op->e_o_s)os->e_o_s=1;
  95336. return(0);
  95337. }
  95338. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95339. int i;
  95340. int vals=0;
  95341. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95342. int bytes=0;
  95343. long acc=0;
  95344. ogg_int64_t granule_pos=-1;
  95345. if(maxvals==0)return(0);
  95346. if(os->b_o_s==0){ /* 'initial header page' case */
  95347. granule_pos=0;
  95348. for(vals=0;vals<maxvals;vals++){
  95349. if((os->lacing_vals[vals]&0x0ff)<255){
  95350. vals++;
  95351. break;
  95352. }
  95353. }
  95354. }else{
  95355. for(vals=0;vals<maxvals;vals++){
  95356. if(acc>4096)break;
  95357. acc+=os->lacing_vals[vals]&0x0ff;
  95358. if((os->lacing_vals[vals]&0xff)<255)
  95359. granule_pos=os->granule_vals[vals];
  95360. }
  95361. }
  95362. memcpy(os->header,"OggS",4);
  95363. os->header[4]=0x00;
  95364. os->header[5]=0x00;
  95365. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95366. if(os->b_o_s==0)os->header[5]|=0x02;
  95367. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95368. os->b_o_s=1;
  95369. for(i=6;i<14;i++){
  95370. os->header[i]=(unsigned char)(granule_pos&0xff);
  95371. granule_pos>>=8;
  95372. }
  95373. {
  95374. long serialno=os->serialno;
  95375. for(i=14;i<18;i++){
  95376. os->header[i]=(unsigned char)(serialno&0xff);
  95377. serialno>>=8;
  95378. }
  95379. }
  95380. if(os->pageno==-1)os->pageno=0; /* because someone called
  95381. stream_reset; this would be a
  95382. strange thing to do in an
  95383. encode stream, but it has
  95384. plausible uses */
  95385. {
  95386. long pageno=os->pageno++;
  95387. for(i=18;i<22;i++){
  95388. os->header[i]=(unsigned char)(pageno&0xff);
  95389. pageno>>=8;
  95390. }
  95391. }
  95392. os->header[22]=0;
  95393. os->header[23]=0;
  95394. os->header[24]=0;
  95395. os->header[25]=0;
  95396. os->header[26]=(unsigned char)(vals&0xff);
  95397. for(i=0;i<vals;i++)
  95398. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95399. og->header=os->header;
  95400. og->header_len=os->header_fill=vals+27;
  95401. og->body=os->body_data+os->body_returned;
  95402. og->body_len=bytes;
  95403. os->lacing_fill-=vals;
  95404. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95405. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95406. os->body_returned+=bytes;
  95407. ogg_page_checksum_set(og);
  95408. return(1);
  95409. }
  95410. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95411. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95412. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95413. os->lacing_fill>=255 || /* 'segment table full' case */
  95414. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95415. return(ogg_stream_flush(os,og));
  95416. }
  95417. return(0);
  95418. }
  95419. int ogg_stream_eos(ogg_stream_state *os){
  95420. return os->e_o_s;
  95421. }
  95422. int ogg_sync_init(ogg_sync_state *oy){
  95423. if(oy){
  95424. memset(oy,0,sizeof(*oy));
  95425. }
  95426. return(0);
  95427. }
  95428. int ogg_sync_clear(ogg_sync_state *oy){
  95429. if(oy){
  95430. if(oy->data)_ogg_free(oy->data);
  95431. ogg_sync_init(oy);
  95432. }
  95433. return(0);
  95434. }
  95435. int ogg_sync_destroy(ogg_sync_state *oy){
  95436. if(oy){
  95437. ogg_sync_clear(oy);
  95438. _ogg_free(oy);
  95439. }
  95440. return(0);
  95441. }
  95442. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95443. if(oy->returned){
  95444. oy->fill-=oy->returned;
  95445. if(oy->fill>0)
  95446. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95447. oy->returned=0;
  95448. }
  95449. if(size>oy->storage-oy->fill){
  95450. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95451. if(oy->data)
  95452. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95453. else
  95454. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95455. oy->storage=newsize;
  95456. }
  95457. return((char *)oy->data+oy->fill);
  95458. }
  95459. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95460. if(oy->fill+bytes>oy->storage)return(-1);
  95461. oy->fill+=bytes;
  95462. return(0);
  95463. }
  95464. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95465. unsigned char *page=oy->data+oy->returned;
  95466. unsigned char *next;
  95467. long bytes=oy->fill-oy->returned;
  95468. if(oy->headerbytes==0){
  95469. int headerbytes,i;
  95470. if(bytes<27)return(0); /* not enough for a header */
  95471. if(memcmp(page,"OggS",4))goto sync_fail;
  95472. headerbytes=page[26]+27;
  95473. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95474. for(i=0;i<page[26];i++)
  95475. oy->bodybytes+=page[27+i];
  95476. oy->headerbytes=headerbytes;
  95477. }
  95478. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95479. {
  95480. char chksum[4];
  95481. ogg_page log;
  95482. memcpy(chksum,page+22,4);
  95483. memset(page+22,0,4);
  95484. log.header=page;
  95485. log.header_len=oy->headerbytes;
  95486. log.body=page+oy->headerbytes;
  95487. log.body_len=oy->bodybytes;
  95488. ogg_page_checksum_set(&log);
  95489. if(memcmp(chksum,page+22,4)){
  95490. memcpy(page+22,chksum,4);
  95491. goto sync_fail;
  95492. }
  95493. }
  95494. {
  95495. unsigned char *page=oy->data+oy->returned;
  95496. long bytes;
  95497. if(og){
  95498. og->header=page;
  95499. og->header_len=oy->headerbytes;
  95500. og->body=page+oy->headerbytes;
  95501. og->body_len=oy->bodybytes;
  95502. }
  95503. oy->unsynced=0;
  95504. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95505. oy->headerbytes=0;
  95506. oy->bodybytes=0;
  95507. return(bytes);
  95508. }
  95509. sync_fail:
  95510. oy->headerbytes=0;
  95511. oy->bodybytes=0;
  95512. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95513. if(!next)
  95514. next=oy->data+oy->fill;
  95515. oy->returned=next-oy->data;
  95516. return(-(next-page));
  95517. }
  95518. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95519. for(;;){
  95520. long ret=ogg_sync_pageseek(oy,og);
  95521. if(ret>0){
  95522. return(1);
  95523. }
  95524. if(ret==0){
  95525. return(0);
  95526. }
  95527. if(!oy->unsynced){
  95528. oy->unsynced=1;
  95529. return(-1);
  95530. }
  95531. }
  95532. }
  95533. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95534. unsigned char *header=og->header;
  95535. unsigned char *body=og->body;
  95536. long bodysize=og->body_len;
  95537. int segptr=0;
  95538. int version=ogg_page_version(og);
  95539. int continued=ogg_page_continued(og);
  95540. int bos=ogg_page_bos(og);
  95541. int eos=ogg_page_eos(og);
  95542. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95543. int serialno=ogg_page_serialno(og);
  95544. long pageno=ogg_page_pageno(og);
  95545. int segments=header[26];
  95546. {
  95547. long lr=os->lacing_returned;
  95548. long br=os->body_returned;
  95549. if(br){
  95550. os->body_fill-=br;
  95551. if(os->body_fill)
  95552. memmove(os->body_data,os->body_data+br,os->body_fill);
  95553. os->body_returned=0;
  95554. }
  95555. if(lr){
  95556. if(os->lacing_fill-lr){
  95557. memmove(os->lacing_vals,os->lacing_vals+lr,
  95558. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95559. memmove(os->granule_vals,os->granule_vals+lr,
  95560. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95561. }
  95562. os->lacing_fill-=lr;
  95563. os->lacing_packet-=lr;
  95564. os->lacing_returned=0;
  95565. }
  95566. }
  95567. if(serialno!=os->serialno)return(-1);
  95568. if(version>0)return(-1);
  95569. _os_lacing_expand(os,segments+1);
  95570. if(pageno!=os->pageno){
  95571. int i;
  95572. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95573. os->body_fill-=os->lacing_vals[i]&0xff;
  95574. os->lacing_fill=os->lacing_packet;
  95575. if(os->pageno!=-1){
  95576. os->lacing_vals[os->lacing_fill++]=0x400;
  95577. os->lacing_packet++;
  95578. }
  95579. }
  95580. if(continued){
  95581. if(os->lacing_fill<1 ||
  95582. os->lacing_vals[os->lacing_fill-1]==0x400){
  95583. bos=0;
  95584. for(;segptr<segments;segptr++){
  95585. int val=header[27+segptr];
  95586. body+=val;
  95587. bodysize-=val;
  95588. if(val<255){
  95589. segptr++;
  95590. break;
  95591. }
  95592. }
  95593. }
  95594. }
  95595. if(bodysize){
  95596. _os_body_expand(os,bodysize);
  95597. memcpy(os->body_data+os->body_fill,body,bodysize);
  95598. os->body_fill+=bodysize;
  95599. }
  95600. {
  95601. int saved=-1;
  95602. while(segptr<segments){
  95603. int val=header[27+segptr];
  95604. os->lacing_vals[os->lacing_fill]=val;
  95605. os->granule_vals[os->lacing_fill]=-1;
  95606. if(bos){
  95607. os->lacing_vals[os->lacing_fill]|=0x100;
  95608. bos=0;
  95609. }
  95610. if(val<255)saved=os->lacing_fill;
  95611. os->lacing_fill++;
  95612. segptr++;
  95613. if(val<255)os->lacing_packet=os->lacing_fill;
  95614. }
  95615. if(saved!=-1){
  95616. os->granule_vals[saved]=granulepos;
  95617. }
  95618. }
  95619. if(eos){
  95620. os->e_o_s=1;
  95621. if(os->lacing_fill>0)
  95622. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95623. }
  95624. os->pageno=pageno+1;
  95625. return(0);
  95626. }
  95627. int ogg_sync_reset(ogg_sync_state *oy){
  95628. oy->fill=0;
  95629. oy->returned=0;
  95630. oy->unsynced=0;
  95631. oy->headerbytes=0;
  95632. oy->bodybytes=0;
  95633. return(0);
  95634. }
  95635. int ogg_stream_reset(ogg_stream_state *os){
  95636. os->body_fill=0;
  95637. os->body_returned=0;
  95638. os->lacing_fill=0;
  95639. os->lacing_packet=0;
  95640. os->lacing_returned=0;
  95641. os->header_fill=0;
  95642. os->e_o_s=0;
  95643. os->b_o_s=0;
  95644. os->pageno=-1;
  95645. os->packetno=0;
  95646. os->granulepos=0;
  95647. return(0);
  95648. }
  95649. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95650. ogg_stream_reset(os);
  95651. os->serialno=serialno;
  95652. return(0);
  95653. }
  95654. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95655. int ptr=os->lacing_returned;
  95656. if(os->lacing_packet<=ptr)return(0);
  95657. if(os->lacing_vals[ptr]&0x400){
  95658. os->lacing_returned++;
  95659. os->packetno++;
  95660. return(-1);
  95661. }
  95662. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95663. to ask if there's a whole packet
  95664. waiting */
  95665. {
  95666. int size=os->lacing_vals[ptr]&0xff;
  95667. int bytes=size;
  95668. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95669. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95670. while(size==255){
  95671. int val=os->lacing_vals[++ptr];
  95672. size=val&0xff;
  95673. if(val&0x200)eos=0x200;
  95674. bytes+=size;
  95675. }
  95676. if(op){
  95677. op->e_o_s=eos;
  95678. op->b_o_s=bos;
  95679. op->packet=os->body_data+os->body_returned;
  95680. op->packetno=os->packetno;
  95681. op->granulepos=os->granule_vals[ptr];
  95682. op->bytes=bytes;
  95683. }
  95684. if(adv){
  95685. os->body_returned+=bytes;
  95686. os->lacing_returned=ptr+1;
  95687. os->packetno++;
  95688. }
  95689. }
  95690. return(1);
  95691. }
  95692. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  95693. return _packetout(os,op,1);
  95694. }
  95695. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  95696. return _packetout(os,op,0);
  95697. }
  95698. void ogg_packet_clear(ogg_packet *op) {
  95699. _ogg_free(op->packet);
  95700. memset(op, 0, sizeof(*op));
  95701. }
  95702. #ifdef _V_SELFTEST
  95703. #include <stdio.h>
  95704. ogg_stream_state os_en, os_de;
  95705. ogg_sync_state oy;
  95706. void checkpacket(ogg_packet *op,int len, int no, int pos){
  95707. long j;
  95708. static int sequence=0;
  95709. static int lastno=0;
  95710. if(op->bytes!=len){
  95711. fprintf(stderr,"incorrect packet length!\n");
  95712. exit(1);
  95713. }
  95714. if(op->granulepos!=pos){
  95715. fprintf(stderr,"incorrect packet position!\n");
  95716. exit(1);
  95717. }
  95718. if(no==0){
  95719. sequence=0;
  95720. }else{
  95721. sequence++;
  95722. if(no>lastno+1)
  95723. sequence++;
  95724. }
  95725. lastno=no;
  95726. if(op->packetno!=sequence){
  95727. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  95728. (long)(op->packetno),sequence);
  95729. exit(1);
  95730. }
  95731. for(j=0;j<op->bytes;j++)
  95732. if(op->packet[j]!=((j+no)&0xff)){
  95733. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  95734. j,op->packet[j],(j+no)&0xff);
  95735. exit(1);
  95736. }
  95737. }
  95738. void check_page(unsigned char *data,const int *header,ogg_page *og){
  95739. long j;
  95740. for(j=0;j<og->body_len;j++)
  95741. if(og->body[j]!=data[j]){
  95742. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  95743. j,data[j],og->body[j]);
  95744. exit(1);
  95745. }
  95746. for(j=0;j<og->header_len;j++){
  95747. if(og->header[j]!=header[j]){
  95748. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  95749. for(j=0;j<header[26]+27;j++)
  95750. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  95751. fprintf(stderr,"\n");
  95752. exit(1);
  95753. }
  95754. }
  95755. if(og->header_len!=header[26]+27){
  95756. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  95757. og->header_len,header[26]+27);
  95758. exit(1);
  95759. }
  95760. }
  95761. void print_header(ogg_page *og){
  95762. int j;
  95763. fprintf(stderr,"\nHEADER:\n");
  95764. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  95765. og->header[0],og->header[1],og->header[2],og->header[3],
  95766. (int)og->header[4],(int)og->header[5]);
  95767. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  95768. (og->header[9]<<24)|(og->header[8]<<16)|
  95769. (og->header[7]<<8)|og->header[6],
  95770. (og->header[17]<<24)|(og->header[16]<<16)|
  95771. (og->header[15]<<8)|og->header[14],
  95772. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  95773. (og->header[19]<<8)|og->header[18]);
  95774. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  95775. (int)og->header[22],(int)og->header[23],
  95776. (int)og->header[24],(int)og->header[25],
  95777. (int)og->header[26]);
  95778. for(j=27;j<og->header_len;j++)
  95779. fprintf(stderr,"%d ",(int)og->header[j]);
  95780. fprintf(stderr,")\n\n");
  95781. }
  95782. void copy_page(ogg_page *og){
  95783. unsigned char *temp=_ogg_malloc(og->header_len);
  95784. memcpy(temp,og->header,og->header_len);
  95785. og->header=temp;
  95786. temp=_ogg_malloc(og->body_len);
  95787. memcpy(temp,og->body,og->body_len);
  95788. og->body=temp;
  95789. }
  95790. void free_page(ogg_page *og){
  95791. _ogg_free (og->header);
  95792. _ogg_free (og->body);
  95793. }
  95794. void error(void){
  95795. fprintf(stderr,"error!\n");
  95796. exit(1);
  95797. }
  95798. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  95799. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95800. 0x01,0x02,0x03,0x04,0,0,0,0,
  95801. 0x15,0xed,0xec,0x91,
  95802. 1,
  95803. 17};
  95804. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95805. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95806. 0x01,0x02,0x03,0x04,0,0,0,0,
  95807. 0x59,0x10,0x6c,0x2c,
  95808. 1,
  95809. 17};
  95810. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95811. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  95812. 0x01,0x02,0x03,0x04,1,0,0,0,
  95813. 0x89,0x33,0x85,0xce,
  95814. 13,
  95815. 254,255,0,255,1,255,245,255,255,0,
  95816. 255,255,90};
  95817. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95818. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95819. 0x01,0x02,0x03,0x04,0,0,0,0,
  95820. 0xff,0x7b,0x23,0x17,
  95821. 1,
  95822. 0};
  95823. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95824. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  95825. 0x01,0x02,0x03,0x04,1,0,0,0,
  95826. 0x5c,0x3f,0x66,0xcb,
  95827. 17,
  95828. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  95829. 255,255,90,0};
  95830. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95831. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95832. 0x01,0x02,0x03,0x04,0,0,0,0,
  95833. 0x01,0x27,0x31,0xaa,
  95834. 18,
  95835. 255,255,255,255,255,255,255,255,
  95836. 255,255,255,255,255,255,255,255,255,10};
  95837. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95838. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  95839. 0x01,0x02,0x03,0x04,1,0,0,0,
  95840. 0x7f,0x4e,0x8a,0xd2,
  95841. 4,
  95842. 255,4,255,0};
  95843. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95844. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95845. 0x01,0x02,0x03,0x04,0,0,0,0,
  95846. 0xff,0x7b,0x23,0x17,
  95847. 1,
  95848. 0};
  95849. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95850. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  95851. 0x01,0x02,0x03,0x04,1,0,0,0,
  95852. 0x54,0x05,0x51,0xc8,
  95853. 17,
  95854. 255,255,255,255,255,255,255,255,
  95855. 255,255,255,255,255,255,255,255,255};
  95856. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  95857. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  95858. 0x01,0x02,0x03,0x04,2,0,0,0,
  95859. 0xc8,0xc3,0xcb,0xed,
  95860. 5,
  95861. 10,255,4,255,0};
  95862. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95863. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95864. 0x01,0x02,0x03,0x04,0,0,0,0,
  95865. 0xff,0x7b,0x23,0x17,
  95866. 1,
  95867. 0};
  95868. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95869. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  95870. 0x01,0x02,0x03,0x04,1,0,0,0,
  95871. 0xed,0x2a,0x2e,0xa7,
  95872. 255,
  95873. 10,10,10,10,10,10,10,10,
  95874. 10,10,10,10,10,10,10,10,
  95875. 10,10,10,10,10,10,10,10,
  95876. 10,10,10,10,10,10,10,10,
  95877. 10,10,10,10,10,10,10,10,
  95878. 10,10,10,10,10,10,10,10,
  95879. 10,10,10,10,10,10,10,10,
  95880. 10,10,10,10,10,10,10,10,
  95881. 10,10,10,10,10,10,10,10,
  95882. 10,10,10,10,10,10,10,10,
  95883. 10,10,10,10,10,10,10,10,
  95884. 10,10,10,10,10,10,10,10,
  95885. 10,10,10,10,10,10,10,10,
  95886. 10,10,10,10,10,10,10,10,
  95887. 10,10,10,10,10,10,10,10,
  95888. 10,10,10,10,10,10,10,10,
  95889. 10,10,10,10,10,10,10,10,
  95890. 10,10,10,10,10,10,10,10,
  95891. 10,10,10,10,10,10,10,10,
  95892. 10,10,10,10,10,10,10,10,
  95893. 10,10,10,10,10,10,10,10,
  95894. 10,10,10,10,10,10,10,10,
  95895. 10,10,10,10,10,10,10,10,
  95896. 10,10,10,10,10,10,10,10,
  95897. 10,10,10,10,10,10,10,10,
  95898. 10,10,10,10,10,10,10,10,
  95899. 10,10,10,10,10,10,10,10,
  95900. 10,10,10,10,10,10,10,10,
  95901. 10,10,10,10,10,10,10,10,
  95902. 10,10,10,10,10,10,10,10,
  95903. 10,10,10,10,10,10,10,10,
  95904. 10,10,10,10,10,10,10};
  95905. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95906. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  95907. 0x01,0x02,0x03,0x04,2,0,0,0,
  95908. 0x6c,0x3b,0x82,0x3d,
  95909. 1,
  95910. 50};
  95911. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95912. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95913. 0x01,0x02,0x03,0x04,0,0,0,0,
  95914. 0xff,0x7b,0x23,0x17,
  95915. 1,
  95916. 0};
  95917. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95918. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  95919. 0x01,0x02,0x03,0x04,1,0,0,0,
  95920. 0x3c,0xd9,0x4d,0x3f,
  95921. 17,
  95922. 100,255,255,255,255,255,255,255,255,
  95923. 255,255,255,255,255,255,255,255};
  95924. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  95925. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  95926. 0x01,0x02,0x03,0x04,2,0,0,0,
  95927. 0x01,0xd2,0xe5,0xe5,
  95928. 17,
  95929. 255,255,255,255,255,255,255,255,
  95930. 255,255,255,255,255,255,255,255,255};
  95931. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  95932. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  95933. 0x01,0x02,0x03,0x04,3,0,0,0,
  95934. 0xef,0xdd,0x88,0xde,
  95935. 7,
  95936. 255,255,75,255,4,255,0};
  95937. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95938. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95939. 0x01,0x02,0x03,0x04,0,0,0,0,
  95940. 0xff,0x7b,0x23,0x17,
  95941. 1,
  95942. 0};
  95943. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95944. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  95945. 0x01,0x02,0x03,0x04,1,0,0,0,
  95946. 0x3c,0xd9,0x4d,0x3f,
  95947. 17,
  95948. 100,255,255,255,255,255,255,255,255,
  95949. 255,255,255,255,255,255,255,255};
  95950. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  95951. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  95952. 0x01,0x02,0x03,0x04,2,0,0,0,
  95953. 0xd4,0xe0,0x60,0xe5,
  95954. 1,0};
  95955. void test_pack(const int *pl, const int **headers, int byteskip,
  95956. int pageskip, int packetskip){
  95957. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  95958. long inptr=0;
  95959. long outptr=0;
  95960. long deptr=0;
  95961. long depacket=0;
  95962. long granule_pos=7,pageno=0;
  95963. int i,j,packets,pageout=pageskip;
  95964. int eosflag=0;
  95965. int bosflag=0;
  95966. int byteskipcount=0;
  95967. ogg_stream_reset(&os_en);
  95968. ogg_stream_reset(&os_de);
  95969. ogg_sync_reset(&oy);
  95970. for(packets=0;packets<packetskip;packets++)
  95971. depacket+=pl[packets];
  95972. for(packets=0;;packets++)if(pl[packets]==-1)break;
  95973. for(i=0;i<packets;i++){
  95974. ogg_packet op;
  95975. int len=pl[i];
  95976. op.packet=data+inptr;
  95977. op.bytes=len;
  95978. op.e_o_s=(pl[i+1]<0?1:0);
  95979. op.granulepos=granule_pos;
  95980. granule_pos+=1024;
  95981. for(j=0;j<len;j++)data[inptr++]=i+j;
  95982. ogg_stream_packetin(&os_en,&op);
  95983. {
  95984. ogg_page og;
  95985. while(ogg_stream_pageout(&os_en,&og)){
  95986. fprintf(stderr,"%ld, ",pageno);
  95987. if(headers[pageno]==NULL){
  95988. fprintf(stderr,"coded too many pages!\n");
  95989. exit(1);
  95990. }
  95991. check_page(data+outptr,headers[pageno],&og);
  95992. outptr+=og.body_len;
  95993. pageno++;
  95994. if(pageskip){
  95995. bosflag=1;
  95996. pageskip--;
  95997. deptr+=og.body_len;
  95998. }
  95999. {
  96000. ogg_page og_de;
  96001. ogg_packet op_de,op_de2;
  96002. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96003. char *next=buf;
  96004. byteskipcount+=og.header_len;
  96005. if(byteskipcount>byteskip){
  96006. memcpy(next,og.header,byteskipcount-byteskip);
  96007. next+=byteskipcount-byteskip;
  96008. byteskipcount=byteskip;
  96009. }
  96010. byteskipcount+=og.body_len;
  96011. if(byteskipcount>byteskip){
  96012. memcpy(next,og.body,byteskipcount-byteskip);
  96013. next+=byteskipcount-byteskip;
  96014. byteskipcount=byteskip;
  96015. }
  96016. ogg_sync_wrote(&oy,next-buf);
  96017. while(1){
  96018. int ret=ogg_sync_pageout(&oy,&og_de);
  96019. if(ret==0)break;
  96020. if(ret<0)continue;
  96021. fprintf(stderr,"(%ld), ",pageout);
  96022. check_page(data+deptr,headers[pageout],&og_de);
  96023. deptr+=og_de.body_len;
  96024. pageout++;
  96025. ogg_stream_pagein(&os_de,&og_de);
  96026. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96027. ogg_stream_packetpeek(&os_de,NULL);
  96028. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96029. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96030. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96031. depacket);
  96032. exit(1);
  96033. }
  96034. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96035. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96036. depacket);
  96037. exit(1);
  96038. }
  96039. if(bosflag==0 && op_de.b_o_s==0){
  96040. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96041. exit(1);
  96042. }
  96043. if(bosflag && op_de.b_o_s){
  96044. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96045. exit(1);
  96046. }
  96047. bosflag=1;
  96048. depacket+=op_de.bytes;
  96049. if(eosflag){
  96050. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96051. exit(1);
  96052. }
  96053. if(op_de.e_o_s)eosflag=1;
  96054. if(op_de.granulepos!=-1){
  96055. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96056. }
  96057. }
  96058. }
  96059. }
  96060. }
  96061. }
  96062. }
  96063. _ogg_free(data);
  96064. if(headers[pageno]!=NULL){
  96065. fprintf(stderr,"did not write last page!\n");
  96066. exit(1);
  96067. }
  96068. if(headers[pageout]!=NULL){
  96069. fprintf(stderr,"did not decode last page!\n");
  96070. exit(1);
  96071. }
  96072. if(inptr!=outptr){
  96073. fprintf(stderr,"encoded page data incomplete!\n");
  96074. exit(1);
  96075. }
  96076. if(inptr!=deptr){
  96077. fprintf(stderr,"decoded page data incomplete!\n");
  96078. exit(1);
  96079. }
  96080. if(inptr!=depacket){
  96081. fprintf(stderr,"decoded packet data incomplete!\n");
  96082. exit(1);
  96083. }
  96084. if(!eosflag){
  96085. fprintf(stderr,"Never got a packet with EOS set!\n");
  96086. exit(1);
  96087. }
  96088. fprintf(stderr,"ok.\n");
  96089. }
  96090. int main(void){
  96091. ogg_stream_init(&os_en,0x04030201);
  96092. ogg_stream_init(&os_de,0x04030201);
  96093. ogg_sync_init(&oy);
  96094. {
  96095. const int packets[]={17, -1};
  96096. const int *headret[]={head1_0,NULL};
  96097. fprintf(stderr,"testing single page encoding... ");
  96098. test_pack(packets,headret,0,0,0);
  96099. }
  96100. {
  96101. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96102. const int *headret[]={head1_1,head2_1,NULL};
  96103. fprintf(stderr,"testing basic page encoding... ");
  96104. test_pack(packets,headret,0,0,0);
  96105. }
  96106. {
  96107. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96108. const int *headret[]={head1_2,head2_2,NULL};
  96109. fprintf(stderr,"testing basic nil packets... ");
  96110. test_pack(packets,headret,0,0,0);
  96111. }
  96112. {
  96113. const int packets[]={4345,259,255,-1};
  96114. const int *headret[]={head1_3,head2_3,NULL};
  96115. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96116. test_pack(packets,headret,0,0,0);
  96117. }
  96118. {
  96119. const int packets[]={0,4345,259,255,-1};
  96120. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96121. fprintf(stderr,"testing single packet page span... ");
  96122. test_pack(packets,headret,0,0,0);
  96123. }
  96124. {
  96125. const int packets[]={0,10,10,10,10,10,10,10,10,
  96126. 10,10,10,10,10,10,10,10,
  96127. 10,10,10,10,10,10,10,10,
  96128. 10,10,10,10,10,10,10,10,
  96129. 10,10,10,10,10,10,10,10,
  96130. 10,10,10,10,10,10,10,10,
  96131. 10,10,10,10,10,10,10,10,
  96132. 10,10,10,10,10,10,10,10,
  96133. 10,10,10,10,10,10,10,10,
  96134. 10,10,10,10,10,10,10,10,
  96135. 10,10,10,10,10,10,10,10,
  96136. 10,10,10,10,10,10,10,10,
  96137. 10,10,10,10,10,10,10,10,
  96138. 10,10,10,10,10,10,10,10,
  96139. 10,10,10,10,10,10,10,10,
  96140. 10,10,10,10,10,10,10,10,
  96141. 10,10,10,10,10,10,10,10,
  96142. 10,10,10,10,10,10,10,10,
  96143. 10,10,10,10,10,10,10,10,
  96144. 10,10,10,10,10,10,10,10,
  96145. 10,10,10,10,10,10,10,10,
  96146. 10,10,10,10,10,10,10,10,
  96147. 10,10,10,10,10,10,10,10,
  96148. 10,10,10,10,10,10,10,10,
  96149. 10,10,10,10,10,10,10,10,
  96150. 10,10,10,10,10,10,10,10,
  96151. 10,10,10,10,10,10,10,10,
  96152. 10,10,10,10,10,10,10,10,
  96153. 10,10,10,10,10,10,10,10,
  96154. 10,10,10,10,10,10,10,10,
  96155. 10,10,10,10,10,10,10,10,
  96156. 10,10,10,10,10,10,10,50,-1};
  96157. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96158. fprintf(stderr,"testing max packet segments... ");
  96159. test_pack(packets,headret,0,0,0);
  96160. }
  96161. {
  96162. const int packets[]={0,100,9000,259,255,-1};
  96163. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96164. fprintf(stderr,"testing very large packets... ");
  96165. test_pack(packets,headret,0,0,0);
  96166. }
  96167. {
  96168. const int packets[]={0,100,9000,259,255,-1};
  96169. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96170. fprintf(stderr,"testing continuation resync in very large packets... ");
  96171. test_pack(packets,headret,100,2,3);
  96172. }
  96173. {
  96174. const int packets[]={0,100,4080,-1};
  96175. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96176. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96177. test_pack(packets,headret,0,0,0);
  96178. }
  96179. {
  96180. unsigned char *data=_ogg_malloc(1024*1024);
  96181. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96182. int inptr=0,i,j;
  96183. ogg_page og[5];
  96184. ogg_stream_reset(&os_en);
  96185. for(i=0;pl[i]!=-1;i++){
  96186. ogg_packet op;
  96187. int len=pl[i];
  96188. op.packet=data+inptr;
  96189. op.bytes=len;
  96190. op.e_o_s=(pl[i+1]<0?1:0);
  96191. op.granulepos=(i+1)*1000;
  96192. for(j=0;j<len;j++)data[inptr++]=i+j;
  96193. ogg_stream_packetin(&os_en,&op);
  96194. }
  96195. _ogg_free(data);
  96196. for(i=0;i<5;i++){
  96197. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96198. fprintf(stderr,"Too few pages output building sync tests!\n");
  96199. exit(1);
  96200. }
  96201. copy_page(&og[i]);
  96202. }
  96203. {
  96204. ogg_page temp;
  96205. ogg_packet test;
  96206. fprintf(stderr,"Testing loss of pages... ");
  96207. ogg_sync_reset(&oy);
  96208. ogg_stream_reset(&os_de);
  96209. for(i=0;i<5;i++){
  96210. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96211. og[i].header_len);
  96212. ogg_sync_wrote(&oy,og[i].header_len);
  96213. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96214. ogg_sync_wrote(&oy,og[i].body_len);
  96215. }
  96216. ogg_sync_pageout(&oy,&temp);
  96217. ogg_stream_pagein(&os_de,&temp);
  96218. ogg_sync_pageout(&oy,&temp);
  96219. ogg_stream_pagein(&os_de,&temp);
  96220. ogg_sync_pageout(&oy,&temp);
  96221. ogg_sync_pageout(&oy,&temp);
  96222. ogg_stream_pagein(&os_de,&temp);
  96223. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96224. checkpacket(&test,0,0,0);
  96225. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96226. checkpacket(&test,100,1,-1);
  96227. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96228. checkpacket(&test,4079,2,3000);
  96229. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96230. fprintf(stderr,"Error: loss of page did not return error\n");
  96231. exit(1);
  96232. }
  96233. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96234. checkpacket(&test,76,5,-1);
  96235. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96236. checkpacket(&test,34,6,-1);
  96237. fprintf(stderr,"ok.\n");
  96238. }
  96239. {
  96240. ogg_page temp;
  96241. ogg_packet test;
  96242. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96243. ogg_sync_reset(&oy);
  96244. ogg_stream_reset(&os_de);
  96245. for(i=0;i<5;i++){
  96246. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96247. og[i].header_len);
  96248. ogg_sync_wrote(&oy,og[i].header_len);
  96249. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96250. ogg_sync_wrote(&oy,og[i].body_len);
  96251. }
  96252. ogg_sync_pageout(&oy,&temp);
  96253. ogg_stream_pagein(&os_de,&temp);
  96254. ogg_sync_pageout(&oy,&temp);
  96255. ogg_stream_pagein(&os_de,&temp);
  96256. ogg_sync_pageout(&oy,&temp);
  96257. ogg_stream_pagein(&os_de,&temp);
  96258. ogg_sync_pageout(&oy,&temp);
  96259. ogg_sync_pageout(&oy,&temp);
  96260. ogg_stream_pagein(&os_de,&temp);
  96261. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96262. checkpacket(&test,0,0,0);
  96263. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96264. checkpacket(&test,100,1,-1);
  96265. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96266. checkpacket(&test,4079,2,3000);
  96267. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96268. checkpacket(&test,2956,3,4000);
  96269. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96270. fprintf(stderr,"Error: loss of page did not return error\n");
  96271. exit(1);
  96272. }
  96273. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96274. checkpacket(&test,300,13,14000);
  96275. fprintf(stderr,"ok.\n");
  96276. }
  96277. {
  96278. ogg_page og_de;
  96279. fprintf(stderr,"Testing sync on partial inputs... ");
  96280. ogg_sync_reset(&oy);
  96281. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96282. 3);
  96283. ogg_sync_wrote(&oy,3);
  96284. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96285. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96286. 20);
  96287. ogg_sync_wrote(&oy,20);
  96288. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96289. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96290. 5);
  96291. ogg_sync_wrote(&oy,5);
  96292. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96293. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96294. og[1].header_len-28);
  96295. ogg_sync_wrote(&oy,og[1].header_len-28);
  96296. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96297. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96298. ogg_sync_wrote(&oy,1000);
  96299. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96300. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96301. og[1].body_len-1000);
  96302. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96303. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96304. fprintf(stderr,"ok.\n");
  96305. }
  96306. {
  96307. ogg_page og_de;
  96308. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96309. ogg_sync_reset(&oy);
  96310. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96311. og[1].header_len);
  96312. ogg_sync_wrote(&oy,og[1].header_len);
  96313. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96314. og[1].body_len);
  96315. ogg_sync_wrote(&oy,og[1].body_len);
  96316. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96317. 20);
  96318. ogg_sync_wrote(&oy,20);
  96319. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96320. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96321. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96322. og[1].header_len-20);
  96323. ogg_sync_wrote(&oy,og[1].header_len-20);
  96324. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96325. og[1].body_len);
  96326. ogg_sync_wrote(&oy,og[1].body_len);
  96327. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96328. fprintf(stderr,"ok.\n");
  96329. }
  96330. {
  96331. ogg_page og_de;
  96332. fprintf(stderr,"Testing search for capture... ");
  96333. ogg_sync_reset(&oy);
  96334. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96335. og[1].body_len);
  96336. ogg_sync_wrote(&oy,og[1].body_len);
  96337. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96338. og[1].header_len);
  96339. ogg_sync_wrote(&oy,og[1].header_len);
  96340. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96341. og[1].body_len);
  96342. ogg_sync_wrote(&oy,og[1].body_len);
  96343. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96344. 20);
  96345. ogg_sync_wrote(&oy,20);
  96346. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96347. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96348. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96349. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96350. og[2].header_len-20);
  96351. ogg_sync_wrote(&oy,og[2].header_len-20);
  96352. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96353. og[2].body_len);
  96354. ogg_sync_wrote(&oy,og[2].body_len);
  96355. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96356. fprintf(stderr,"ok.\n");
  96357. }
  96358. {
  96359. ogg_page og_de;
  96360. fprintf(stderr,"Testing recapture... ");
  96361. ogg_sync_reset(&oy);
  96362. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96363. og[1].header_len);
  96364. ogg_sync_wrote(&oy,og[1].header_len);
  96365. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96366. og[1].body_len);
  96367. ogg_sync_wrote(&oy,og[1].body_len);
  96368. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96369. og[2].header_len);
  96370. ogg_sync_wrote(&oy,og[2].header_len);
  96371. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96372. og[2].header_len);
  96373. ogg_sync_wrote(&oy,og[2].header_len);
  96374. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96375. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96376. og[2].body_len-5);
  96377. ogg_sync_wrote(&oy,og[2].body_len-5);
  96378. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96379. og[3].header_len);
  96380. ogg_sync_wrote(&oy,og[3].header_len);
  96381. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96382. og[3].body_len);
  96383. ogg_sync_wrote(&oy,og[3].body_len);
  96384. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96385. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96386. fprintf(stderr,"ok.\n");
  96387. }
  96388. {
  96389. for(i=0;i<5;i++){
  96390. free_page(&og[i]);
  96391. }
  96392. }
  96393. }
  96394. return(0);
  96395. }
  96396. #endif
  96397. #endif
  96398. /*** End of inlined file: framing.c ***/
  96399. /*** Start of inlined file: analysis.c ***/
  96400. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96401. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96402. // tasks..
  96403. #if JUCE_MSVC
  96404. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96405. #endif
  96406. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96407. #if JUCE_USE_OGGVORBIS
  96408. #include <stdio.h>
  96409. #include <string.h>
  96410. #include <math.h>
  96411. /*** Start of inlined file: codec_internal.h ***/
  96412. #ifndef _V_CODECI_H_
  96413. #define _V_CODECI_H_
  96414. /*** Start of inlined file: envelope.h ***/
  96415. #ifndef _V_ENVELOPE_
  96416. #define _V_ENVELOPE_
  96417. /*** Start of inlined file: mdct.h ***/
  96418. #ifndef _OGG_mdct_H_
  96419. #define _OGG_mdct_H_
  96420. #ifdef MDCT_INTEGERIZED
  96421. #define DATA_TYPE int
  96422. #define REG_TYPE register int
  96423. #define TRIGBITS 14
  96424. #define cPI3_8 6270
  96425. #define cPI2_8 11585
  96426. #define cPI1_8 15137
  96427. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96428. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96429. #define HALVE(x) ((x)>>1)
  96430. #else
  96431. #define DATA_TYPE float
  96432. #define REG_TYPE float
  96433. #define cPI3_8 .38268343236508977175F
  96434. #define cPI2_8 .70710678118654752441F
  96435. #define cPI1_8 .92387953251128675613F
  96436. #define FLOAT_CONV(x) (x)
  96437. #define MULT_NORM(x) (x)
  96438. #define HALVE(x) ((x)*.5f)
  96439. #endif
  96440. typedef struct {
  96441. int n;
  96442. int log2n;
  96443. DATA_TYPE *trig;
  96444. int *bitrev;
  96445. DATA_TYPE scale;
  96446. } mdct_lookup;
  96447. extern void mdct_init(mdct_lookup *lookup,int n);
  96448. extern void mdct_clear(mdct_lookup *l);
  96449. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96450. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96451. #endif
  96452. /*** End of inlined file: mdct.h ***/
  96453. #define VE_PRE 16
  96454. #define VE_WIN 4
  96455. #define VE_POST 2
  96456. #define VE_AMP (VE_PRE+VE_POST-1)
  96457. #define VE_BANDS 7
  96458. #define VE_NEARDC 15
  96459. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96460. #define VE_MAXSTRETCH 12 /* one-third full block */
  96461. typedef struct {
  96462. float ampbuf[VE_AMP];
  96463. int ampptr;
  96464. float nearDC[VE_NEARDC];
  96465. float nearDC_acc;
  96466. float nearDC_partialacc;
  96467. int nearptr;
  96468. } envelope_filter_state;
  96469. typedef struct {
  96470. int begin;
  96471. int end;
  96472. float *window;
  96473. float total;
  96474. } envelope_band;
  96475. typedef struct {
  96476. int ch;
  96477. int winlength;
  96478. int searchstep;
  96479. float minenergy;
  96480. mdct_lookup mdct;
  96481. float *mdct_win;
  96482. envelope_band band[VE_BANDS];
  96483. envelope_filter_state *filter;
  96484. int stretch;
  96485. int *mark;
  96486. long storage;
  96487. long current;
  96488. long curmark;
  96489. long cursor;
  96490. } envelope_lookup;
  96491. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96492. extern void _ve_envelope_clear(envelope_lookup *e);
  96493. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96494. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96495. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96496. #endif
  96497. /*** End of inlined file: envelope.h ***/
  96498. /*** Start of inlined file: codebook.h ***/
  96499. #ifndef _V_CODEBOOK_H_
  96500. #define _V_CODEBOOK_H_
  96501. typedef struct static_codebook{
  96502. long dim; /* codebook dimensions (elements per vector) */
  96503. long entries; /* codebook entries */
  96504. long *lengthlist; /* codeword lengths in bits */
  96505. int maptype; /* 0=none
  96506. 1=implicitly populated values from map column
  96507. 2=listed arbitrary values */
  96508. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96509. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96510. int q_quant; /* bits: 0 < quant <= 16 */
  96511. int q_sequencep; /* bitflag */
  96512. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96513. map == 2: list of dim*entries quantized entry vals
  96514. */
  96515. struct encode_aux_nearestmatch *nearest_tree;
  96516. struct encode_aux_threshmatch *thresh_tree;
  96517. struct encode_aux_pigeonhole *pigeon_tree;
  96518. int allocedp;
  96519. } static_codebook;
  96520. typedef struct encode_aux_nearestmatch{
  96521. long *ptr0;
  96522. long *ptr1;
  96523. long *p; /* decision points (each is an entry) */
  96524. long *q; /* decision points (each is an entry) */
  96525. long aux; /* number of tree entries */
  96526. long alloc;
  96527. } encode_aux_nearestmatch;
  96528. typedef struct encode_aux_threshmatch{
  96529. float *quantthresh;
  96530. long *quantmap;
  96531. int quantvals;
  96532. int threshvals;
  96533. } encode_aux_threshmatch;
  96534. typedef struct encode_aux_pigeonhole{
  96535. float min;
  96536. float del;
  96537. int mapentries;
  96538. int quantvals;
  96539. long *pigeonmap;
  96540. long fittotal;
  96541. long *fitlist;
  96542. long *fitmap;
  96543. long *fitlength;
  96544. } encode_aux_pigeonhole;
  96545. typedef struct codebook{
  96546. long dim; /* codebook dimensions (elements per vector) */
  96547. long entries; /* codebook entries */
  96548. long used_entries; /* populated codebook entries */
  96549. const static_codebook *c;
  96550. float *valuelist; /* list of dim*entries actual entry values */
  96551. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96552. int *dec_index; /* only used if sparseness collapsed */
  96553. char *dec_codelengths;
  96554. ogg_uint32_t *dec_firsttable;
  96555. int dec_firsttablen;
  96556. int dec_maxlength;
  96557. } codebook;
  96558. extern void vorbis_staticbook_clear(static_codebook *b);
  96559. extern void vorbis_staticbook_destroy(static_codebook *b);
  96560. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96561. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96562. extern void vorbis_book_clear(codebook *b);
  96563. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96564. extern float *_book_logdist(const static_codebook *b,float *vals);
  96565. extern float _float32_unpack(long val);
  96566. extern long _float32_pack(float val);
  96567. extern int _best(codebook *book, float *a, int step);
  96568. extern int _ilog(unsigned int v);
  96569. extern long _book_maptype1_quantvals(const static_codebook *b);
  96570. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96571. extern long vorbis_book_codeword(codebook *book,int entry);
  96572. extern long vorbis_book_codelen(codebook *book,int entry);
  96573. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96574. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96575. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96576. extern int vorbis_book_errorv(codebook *book, float *a);
  96577. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96578. oggpack_buffer *b);
  96579. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96580. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96581. oggpack_buffer *b,int n);
  96582. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96583. oggpack_buffer *b,int n);
  96584. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96585. oggpack_buffer *b,int n);
  96586. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96587. long off,int ch,
  96588. oggpack_buffer *b,int n);
  96589. #endif
  96590. /*** End of inlined file: codebook.h ***/
  96591. #define BLOCKTYPE_IMPULSE 0
  96592. #define BLOCKTYPE_PADDING 1
  96593. #define BLOCKTYPE_TRANSITION 0
  96594. #define BLOCKTYPE_LONG 1
  96595. #define PACKETBLOBS 15
  96596. typedef struct vorbis_block_internal{
  96597. float **pcmdelay; /* this is a pointer into local storage */
  96598. float ampmax;
  96599. int blocktype;
  96600. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96601. blob [PACKETBLOBS/2] points to
  96602. the oggpack_buffer in the
  96603. main vorbis_block */
  96604. } vorbis_block_internal;
  96605. typedef void vorbis_look_floor;
  96606. typedef void vorbis_look_residue;
  96607. typedef void vorbis_look_transform;
  96608. typedef struct {
  96609. int blockflag;
  96610. int windowtype;
  96611. int transformtype;
  96612. int mapping;
  96613. } vorbis_info_mode;
  96614. typedef void vorbis_info_floor;
  96615. typedef void vorbis_info_residue;
  96616. typedef void vorbis_info_mapping;
  96617. /*** Start of inlined file: psy.h ***/
  96618. #ifndef _V_PSY_H_
  96619. #define _V_PSY_H_
  96620. /*** Start of inlined file: smallft.h ***/
  96621. #ifndef _V_SMFT_H_
  96622. #define _V_SMFT_H_
  96623. typedef struct {
  96624. int n;
  96625. float *trigcache;
  96626. int *splitcache;
  96627. } drft_lookup;
  96628. extern void drft_forward(drft_lookup *l,float *data);
  96629. extern void drft_backward(drft_lookup *l,float *data);
  96630. extern void drft_init(drft_lookup *l,int n);
  96631. extern void drft_clear(drft_lookup *l);
  96632. #endif
  96633. /*** End of inlined file: smallft.h ***/
  96634. /*** Start of inlined file: backends.h ***/
  96635. #ifndef _vorbis_backend_h_
  96636. #define _vorbis_backend_h_
  96637. typedef struct{
  96638. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96639. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96640. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96641. void (*free_info) (vorbis_info_floor *);
  96642. void (*free_look) (vorbis_look_floor *);
  96643. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96644. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96645. void *buffer,float *);
  96646. } vorbis_func_floor;
  96647. typedef struct{
  96648. int order;
  96649. long rate;
  96650. long barkmap;
  96651. int ampbits;
  96652. int ampdB;
  96653. int numbooks; /* <= 16 */
  96654. int books[16];
  96655. float lessthan; /* encode-only config setting hacks for libvorbis */
  96656. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96657. } vorbis_info_floor0;
  96658. #define VIF_POSIT 63
  96659. #define VIF_CLASS 16
  96660. #define VIF_PARTS 31
  96661. typedef struct{
  96662. int partitions; /* 0 to 31 */
  96663. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96664. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96665. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96666. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96667. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96668. int mult; /* 1 2 3 or 4 */
  96669. int postlist[VIF_POSIT+2]; /* first two implicit */
  96670. float maxover;
  96671. float maxunder;
  96672. float maxerr;
  96673. float twofitweight;
  96674. float twofitatten;
  96675. int n;
  96676. } vorbis_info_floor1;
  96677. typedef struct{
  96678. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96679. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96680. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96681. vorbis_info_residue *);
  96682. void (*free_info) (vorbis_info_residue *);
  96683. void (*free_look) (vorbis_look_residue *);
  96684. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96685. float **,int *,int);
  96686. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96687. vorbis_look_residue *,
  96688. float **,float **,int *,int,long **);
  96689. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96690. float **,int *,int);
  96691. } vorbis_func_residue;
  96692. typedef struct vorbis_info_residue0{
  96693. long begin;
  96694. long end;
  96695. int grouping; /* group n vectors per partition */
  96696. int partitions; /* possible codebooks for a partition */
  96697. int groupbook; /* huffbook for partitioning */
  96698. int secondstages[64]; /* expanded out to pointers in lookup */
  96699. int booklist[256]; /* list of second stage books */
  96700. float classmetric1[64];
  96701. float classmetric2[64];
  96702. } vorbis_info_residue0;
  96703. typedef struct{
  96704. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  96705. oggpack_buffer *);
  96706. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  96707. void (*free_info) (vorbis_info_mapping *);
  96708. int (*forward) (struct vorbis_block *vb);
  96709. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  96710. } vorbis_func_mapping;
  96711. typedef struct vorbis_info_mapping0{
  96712. int submaps; /* <= 16 */
  96713. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  96714. int floorsubmap[16]; /* [mux] submap to floors */
  96715. int residuesubmap[16]; /* [mux] submap to residue */
  96716. int coupling_steps;
  96717. int coupling_mag[256];
  96718. int coupling_ang[256];
  96719. } vorbis_info_mapping0;
  96720. #endif
  96721. /*** End of inlined file: backends.h ***/
  96722. #ifndef EHMER_MAX
  96723. #define EHMER_MAX 56
  96724. #endif
  96725. #define P_BANDS 17 /* 62Hz to 16kHz */
  96726. #define P_LEVELS 8 /* 30dB to 100dB */
  96727. #define P_LEVEL_0 30. /* 30 dB */
  96728. #define P_NOISECURVES 3
  96729. #define NOISE_COMPAND_LEVELS 40
  96730. typedef struct vorbis_info_psy{
  96731. int blockflag;
  96732. float ath_adjatt;
  96733. float ath_maxatt;
  96734. float tone_masteratt[P_NOISECURVES];
  96735. float tone_centerboost;
  96736. float tone_decay;
  96737. float tone_abs_limit;
  96738. float toneatt[P_BANDS];
  96739. int noisemaskp;
  96740. float noisemaxsupp;
  96741. float noisewindowlo;
  96742. float noisewindowhi;
  96743. int noisewindowlomin;
  96744. int noisewindowhimin;
  96745. int noisewindowfixed;
  96746. float noiseoff[P_NOISECURVES][P_BANDS];
  96747. float noisecompand[NOISE_COMPAND_LEVELS];
  96748. float max_curve_dB;
  96749. int normal_channel_p;
  96750. int normal_point_p;
  96751. int normal_start;
  96752. int normal_partition;
  96753. double normal_thresh;
  96754. } vorbis_info_psy;
  96755. typedef struct{
  96756. int eighth_octave_lines;
  96757. float preecho_thresh[VE_BANDS];
  96758. float postecho_thresh[VE_BANDS];
  96759. float stretch_penalty;
  96760. float preecho_minenergy;
  96761. float ampmax_att_per_sec;
  96762. int coupling_pkHz[PACKETBLOBS];
  96763. int coupling_pointlimit[2][PACKETBLOBS];
  96764. int coupling_prepointamp[PACKETBLOBS];
  96765. int coupling_postpointamp[PACKETBLOBS];
  96766. int sliding_lowpass[2][PACKETBLOBS];
  96767. } vorbis_info_psy_global;
  96768. typedef struct {
  96769. float ampmax;
  96770. int channels;
  96771. vorbis_info_psy_global *gi;
  96772. int coupling_pointlimit[2][P_NOISECURVES];
  96773. } vorbis_look_psy_global;
  96774. typedef struct {
  96775. int n;
  96776. struct vorbis_info_psy *vi;
  96777. float ***tonecurves;
  96778. float **noiseoffset;
  96779. float *ath;
  96780. long *octave; /* in n.ocshift format */
  96781. long *bark;
  96782. long firstoc;
  96783. long shiftoc;
  96784. int eighth_octave_lines; /* power of two, please */
  96785. int total_octave_lines;
  96786. long rate; /* cache it */
  96787. float m_val; /* Masking compensation value */
  96788. } vorbis_look_psy;
  96789. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  96790. vorbis_info_psy_global *gi,int n,long rate);
  96791. extern void _vp_psy_clear(vorbis_look_psy *p);
  96792. extern void *_vi_psy_dup(void *source);
  96793. extern void _vi_psy_free(vorbis_info_psy *i);
  96794. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  96795. extern void _vp_remove_floor(vorbis_look_psy *p,
  96796. float *mdct,
  96797. int *icodedflr,
  96798. float *residue,
  96799. int sliding_lowpass);
  96800. extern void _vp_noisemask(vorbis_look_psy *p,
  96801. float *logmdct,
  96802. float *logmask);
  96803. extern void _vp_tonemask(vorbis_look_psy *p,
  96804. float *logfft,
  96805. float *logmask,
  96806. float global_specmax,
  96807. float local_specmax);
  96808. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  96809. float *noise,
  96810. float *tone,
  96811. int offset_select,
  96812. float *logmask,
  96813. float *mdct,
  96814. float *logmdct);
  96815. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  96816. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  96817. vorbis_info_psy_global *g,
  96818. vorbis_look_psy *p,
  96819. vorbis_info_mapping0 *vi,
  96820. float **mdct);
  96821. extern void _vp_couple(int blobno,
  96822. vorbis_info_psy_global *g,
  96823. vorbis_look_psy *p,
  96824. vorbis_info_mapping0 *vi,
  96825. float **res,
  96826. float **mag_memo,
  96827. int **mag_sort,
  96828. int **ifloor,
  96829. int *nonzero,
  96830. int sliding_lowpass);
  96831. extern void _vp_noise_normalize(vorbis_look_psy *p,
  96832. float *in,float *out,int *sortedindex);
  96833. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  96834. float *magnitudes,int *sortedindex);
  96835. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  96836. vorbis_look_psy *p,
  96837. vorbis_info_mapping0 *vi,
  96838. float **mags);
  96839. extern void hf_reduction(vorbis_info_psy_global *g,
  96840. vorbis_look_psy *p,
  96841. vorbis_info_mapping0 *vi,
  96842. float **mdct);
  96843. #endif
  96844. /*** End of inlined file: psy.h ***/
  96845. /*** Start of inlined file: bitrate.h ***/
  96846. #ifndef _V_BITRATE_H_
  96847. #define _V_BITRATE_H_
  96848. /*** Start of inlined file: os.h ***/
  96849. #ifndef _OS_H
  96850. #define _OS_H
  96851. #ifdef HAVE_CONFIG_H
  96852. #include "config.h"
  96853. #endif
  96854. #include <math.h>
  96855. /*** Start of inlined file: misc.h ***/
  96856. #ifndef _V_RANDOM_H_
  96857. #define _V_RANDOM_H_
  96858. extern int analysis_noisy;
  96859. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  96860. extern void _vorbis_block_ripcord(vorbis_block *vb);
  96861. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  96862. ogg_int64_t off);
  96863. #ifdef DEBUG_MALLOC
  96864. #define _VDBG_GRAPHFILE "malloc.m"
  96865. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  96866. extern void _VDBG_free(void *ptr,char *file,long line);
  96867. #ifndef MISC_C
  96868. #undef _ogg_malloc
  96869. #undef _ogg_calloc
  96870. #undef _ogg_realloc
  96871. #undef _ogg_free
  96872. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  96873. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  96874. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  96875. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  96876. #endif
  96877. #endif
  96878. #endif
  96879. /*** End of inlined file: misc.h ***/
  96880. #ifndef _V_IFDEFJAIL_H_
  96881. # define _V_IFDEFJAIL_H_
  96882. # ifdef __GNUC__
  96883. # define STIN static __inline__
  96884. # elif _WIN32
  96885. # define STIN static __inline
  96886. # else
  96887. # define STIN static
  96888. # endif
  96889. #ifdef DJGPP
  96890. # define rint(x) (floor((x)+0.5f))
  96891. #endif
  96892. #ifndef M_PI
  96893. # define M_PI (3.1415926536f)
  96894. #endif
  96895. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  96896. # include <malloc.h>
  96897. # define rint(x) (floor((x)+0.5f))
  96898. # define NO_FLOAT_MATH_LIB
  96899. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  96900. #endif
  96901. #if defined(__SYMBIAN32__) && defined(__WINS__)
  96902. void *_alloca(size_t size);
  96903. # define alloca _alloca
  96904. #endif
  96905. #ifndef FAST_HYPOT
  96906. # define FAST_HYPOT hypot
  96907. #endif
  96908. #endif
  96909. #ifdef HAVE_ALLOCA_H
  96910. # include <alloca.h>
  96911. #endif
  96912. #ifdef USE_MEMORY_H
  96913. # include <memory.h>
  96914. #endif
  96915. #ifndef min
  96916. # define min(x,y) ((x)>(y)?(y):(x))
  96917. #endif
  96918. #ifndef max
  96919. # define max(x,y) ((x)<(y)?(y):(x))
  96920. #endif
  96921. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  96922. # define VORBIS_FPU_CONTROL
  96923. typedef ogg_int16_t vorbis_fpu_control;
  96924. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  96925. ogg_int16_t ret;
  96926. ogg_int16_t temp;
  96927. __asm__ __volatile__("fnstcw %0\n\t"
  96928. "movw %0,%%dx\n\t"
  96929. "orw $62463,%%dx\n\t"
  96930. "movw %%dx,%1\n\t"
  96931. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  96932. *fpu=ret;
  96933. }
  96934. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  96935. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  96936. }
  96937. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  96938. we get extra fst/fld to
  96939. truncate precision */
  96940. int i;
  96941. __asm__("fistl %0": "=m"(i) : "t"(f));
  96942. return(i);
  96943. }
  96944. #endif
  96945. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  96946. # define VORBIS_FPU_CONTROL
  96947. typedef ogg_int16_t vorbis_fpu_control;
  96948. static __inline int vorbis_ftoi(double f){
  96949. int i;
  96950. __asm{
  96951. fld f
  96952. fistp i
  96953. }
  96954. return i;
  96955. }
  96956. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  96957. }
  96958. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  96959. }
  96960. #endif
  96961. #ifndef VORBIS_FPU_CONTROL
  96962. typedef int vorbis_fpu_control;
  96963. static int vorbis_ftoi(double f){
  96964. return (int)(f+.5);
  96965. }
  96966. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  96967. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  96968. #endif
  96969. #endif /* _OS_H */
  96970. /*** End of inlined file: os.h ***/
  96971. typedef struct bitrate_manager_state {
  96972. int managed;
  96973. long avg_reservoir;
  96974. long minmax_reservoir;
  96975. long avg_bitsper;
  96976. long min_bitsper;
  96977. long max_bitsper;
  96978. long short_per_long;
  96979. double avgfloat;
  96980. vorbis_block *vb;
  96981. int choice;
  96982. } bitrate_manager_state;
  96983. typedef struct bitrate_manager_info{
  96984. long avg_rate;
  96985. long min_rate;
  96986. long max_rate;
  96987. long reservoir_bits;
  96988. double reservoir_bias;
  96989. double slew_damp;
  96990. } bitrate_manager_info;
  96991. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  96992. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  96993. extern int vorbis_bitrate_managed(vorbis_block *vb);
  96994. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  96995. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  96996. #endif
  96997. /*** End of inlined file: bitrate.h ***/
  96998. static int ilog(unsigned int v){
  96999. int ret=0;
  97000. while(v){
  97001. ret++;
  97002. v>>=1;
  97003. }
  97004. return(ret);
  97005. }
  97006. static int ilog2(unsigned int v){
  97007. int ret=0;
  97008. if(v)--v;
  97009. while(v){
  97010. ret++;
  97011. v>>=1;
  97012. }
  97013. return(ret);
  97014. }
  97015. typedef struct private_state {
  97016. envelope_lookup *ve; /* envelope lookup */
  97017. int window[2];
  97018. vorbis_look_transform **transform[2]; /* block, type */
  97019. drft_lookup fft_look[2];
  97020. int modebits;
  97021. vorbis_look_floor **flr;
  97022. vorbis_look_residue **residue;
  97023. vorbis_look_psy *psy;
  97024. vorbis_look_psy_global *psy_g_look;
  97025. unsigned char *header;
  97026. unsigned char *header1;
  97027. unsigned char *header2;
  97028. bitrate_manager_state bms;
  97029. ogg_int64_t sample_count;
  97030. } private_state;
  97031. /*** Start of inlined file: highlevel.h ***/
  97032. typedef struct highlevel_byblocktype {
  97033. double tone_mask_setting;
  97034. double tone_peaklimit_setting;
  97035. double noise_bias_setting;
  97036. double noise_compand_setting;
  97037. } highlevel_byblocktype;
  97038. typedef struct highlevel_encode_setup {
  97039. void *setup;
  97040. int set_in_stone;
  97041. double base_setting;
  97042. double long_setting;
  97043. double short_setting;
  97044. double impulse_noisetune;
  97045. int managed;
  97046. long bitrate_min;
  97047. long bitrate_av;
  97048. double bitrate_av_damp;
  97049. long bitrate_max;
  97050. long bitrate_reservoir;
  97051. double bitrate_reservoir_bias;
  97052. int impulse_block_p;
  97053. int noise_normalize_p;
  97054. double stereo_point_setting;
  97055. double lowpass_kHz;
  97056. double ath_floating_dB;
  97057. double ath_absolute_dB;
  97058. double amplitude_track_dBpersec;
  97059. double trigger_setting;
  97060. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97061. } highlevel_encode_setup;
  97062. /*** End of inlined file: highlevel.h ***/
  97063. typedef struct codec_setup_info {
  97064. long blocksizes[2];
  97065. int modes;
  97066. int maps;
  97067. int floors;
  97068. int residues;
  97069. int books;
  97070. int psys; /* encode only */
  97071. vorbis_info_mode *mode_param[64];
  97072. int map_type[64];
  97073. vorbis_info_mapping *map_param[64];
  97074. int floor_type[64];
  97075. vorbis_info_floor *floor_param[64];
  97076. int residue_type[64];
  97077. vorbis_info_residue *residue_param[64];
  97078. static_codebook *book_param[256];
  97079. codebook *fullbooks;
  97080. vorbis_info_psy *psy_param[4]; /* encode only */
  97081. vorbis_info_psy_global psy_g_param;
  97082. bitrate_manager_info bi;
  97083. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97084. highly redundant structure, but
  97085. improves clarity of program flow. */
  97086. int halfrate_flag; /* painless downsample for decode */
  97087. } codec_setup_info;
  97088. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97089. extern void _vp_global_free(vorbis_look_psy_global *look);
  97090. #endif
  97091. /*** End of inlined file: codec_internal.h ***/
  97092. /*** Start of inlined file: registry.h ***/
  97093. #ifndef _V_REG_H_
  97094. #define _V_REG_H_
  97095. #define VI_TRANSFORMB 1
  97096. #define VI_WINDOWB 1
  97097. #define VI_TIMEB 1
  97098. #define VI_FLOORB 2
  97099. #define VI_RESB 3
  97100. #define VI_MAPB 1
  97101. extern vorbis_func_floor *_floor_P[];
  97102. extern vorbis_func_residue *_residue_P[];
  97103. extern vorbis_func_mapping *_mapping_P[];
  97104. #endif
  97105. /*** End of inlined file: registry.h ***/
  97106. /*** Start of inlined file: scales.h ***/
  97107. #ifndef _V_SCALES_H_
  97108. #define _V_SCALES_H_
  97109. #include <math.h>
  97110. #define VORBIS_IEEE_FLOAT32 1
  97111. #ifdef VORBIS_IEEE_FLOAT32
  97112. static float unitnorm(float x){
  97113. union {
  97114. ogg_uint32_t i;
  97115. float f;
  97116. } ix;
  97117. ix.f = x;
  97118. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97119. return ix.f;
  97120. }
  97121. static float todB(const float *x){
  97122. union {
  97123. ogg_uint32_t i;
  97124. float f;
  97125. } ix;
  97126. ix.f = *x;
  97127. ix.i = ix.i&0x7fffffff;
  97128. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97129. }
  97130. #define todB_nn(x) todB(x)
  97131. #else
  97132. static float unitnorm(float x){
  97133. if(x<0)return(-1.f);
  97134. return(1.f);
  97135. }
  97136. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97137. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97138. #endif
  97139. #define fromdB(x) (exp((x)*.11512925f))
  97140. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97141. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97142. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97143. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97144. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97145. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97146. #endif
  97147. /*** End of inlined file: scales.h ***/
  97148. int analysis_noisy=1;
  97149. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97150. int ret,i;
  97151. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97152. vb->glue_bits=0;
  97153. vb->time_bits=0;
  97154. vb->floor_bits=0;
  97155. vb->res_bits=0;
  97156. for(i=0;i<PACKETBLOBS;i++)
  97157. oggpack_reset(vbi->packetblob[i]);
  97158. if((ret=_mapping_P[0]->forward(vb)))
  97159. return(ret);
  97160. if(op){
  97161. if(vorbis_bitrate_managed(vb))
  97162. return(OV_EINVAL);
  97163. op->packet=oggpack_get_buffer(&vb->opb);
  97164. op->bytes=oggpack_bytes(&vb->opb);
  97165. op->b_o_s=0;
  97166. op->e_o_s=vb->eofflag;
  97167. op->granulepos=vb->granulepos;
  97168. op->packetno=vb->sequence; /* for sake of completeness */
  97169. }
  97170. return(0);
  97171. }
  97172. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97173. int j;
  97174. FILE *of;
  97175. char buffer[80];
  97176. sprintf(buffer,"%s_%d.m",base,i);
  97177. of=fopen(buffer,"w");
  97178. if(!of)perror("failed to open data dump file");
  97179. for(j=0;j<n;j++){
  97180. if(bark){
  97181. float b=toBARK((4000.f*j/n)+.25);
  97182. fprintf(of,"%f ",b);
  97183. }else
  97184. if(off!=0)
  97185. fprintf(of,"%f ",(double)(j+off)/8000.);
  97186. else
  97187. fprintf(of,"%f ",(double)j);
  97188. if(dB){
  97189. float val;
  97190. if(v[j]==0.)
  97191. val=-140.;
  97192. else
  97193. val=todB(v+j);
  97194. fprintf(of,"%f\n",val);
  97195. }else{
  97196. fprintf(of,"%f\n",v[j]);
  97197. }
  97198. }
  97199. fclose(of);
  97200. }
  97201. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97202. ogg_int64_t off){
  97203. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97204. }
  97205. #endif
  97206. /*** End of inlined file: analysis.c ***/
  97207. /*** Start of inlined file: bitrate.c ***/
  97208. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97209. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97210. // tasks..
  97211. #if JUCE_MSVC
  97212. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97213. #endif
  97214. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97215. #if JUCE_USE_OGGVORBIS
  97216. #include <stdlib.h>
  97217. #include <string.h>
  97218. #include <math.h>
  97219. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97220. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97221. bitrate_manager_info *bi=&ci->bi;
  97222. memset(bm,0,sizeof(*bm));
  97223. if(bi && (bi->reservoir_bits>0)){
  97224. long ratesamples=vi->rate;
  97225. int halfsamples=ci->blocksizes[0]>>1;
  97226. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97227. bm->managed=1;
  97228. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97229. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97230. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97231. bm->avgfloat=PACKETBLOBS/2;
  97232. {
  97233. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97234. bm->minmax_reservoir=desired_fill;
  97235. bm->avg_reservoir=desired_fill;
  97236. }
  97237. }
  97238. }
  97239. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97240. memset(bm,0,sizeof(*bm));
  97241. return;
  97242. }
  97243. int vorbis_bitrate_managed(vorbis_block *vb){
  97244. vorbis_dsp_state *vd=vb->vd;
  97245. private_state *b=(private_state*)vd->backend_state;
  97246. bitrate_manager_state *bm=&b->bms;
  97247. if(bm && bm->managed)return(1);
  97248. return(0);
  97249. }
  97250. int vorbis_bitrate_addblock(vorbis_block *vb){
  97251. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97252. vorbis_dsp_state *vd=vb->vd;
  97253. private_state *b=(private_state*)vd->backend_state;
  97254. bitrate_manager_state *bm=&b->bms;
  97255. vorbis_info *vi=vd->vi;
  97256. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97257. bitrate_manager_info *bi=&ci->bi;
  97258. int choice=rint(bm->avgfloat);
  97259. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97260. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97261. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97262. int samples=ci->blocksizes[vb->W]>>1;
  97263. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97264. if(!bm->managed){
  97265. if(bm->vb)return(-1); /* one has been submitted without
  97266. being claimed */
  97267. bm->vb=vb;
  97268. return(0);
  97269. }
  97270. bm->vb=vb;
  97271. if(bm->avg_bitsper>0){
  97272. double slew=0.;
  97273. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97274. double slewlimit= 15./bi->slew_damp;
  97275. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97276. while(choice>0 && this_bits>avg_target_bits &&
  97277. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97278. choice--;
  97279. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97280. }
  97281. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97282. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97283. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97284. choice++;
  97285. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97286. }
  97287. }
  97288. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97289. if(slew<-slewlimit)slew=-slewlimit;
  97290. if(slew>slewlimit)slew=slewlimit;
  97291. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97292. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97293. }
  97294. if(bm->min_bitsper>0){
  97295. if(this_bits<min_target_bits){
  97296. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97297. choice++;
  97298. if(choice>=PACKETBLOBS)break;
  97299. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97300. }
  97301. }
  97302. }
  97303. if(bm->max_bitsper>0){
  97304. if(this_bits>max_target_bits){
  97305. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97306. choice--;
  97307. if(choice<0)break;
  97308. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97309. }
  97310. }
  97311. }
  97312. if(choice<0){
  97313. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97314. bm->choice=choice=0;
  97315. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97316. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97317. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97318. }
  97319. }else{
  97320. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97321. if(choice>=PACKETBLOBS)
  97322. choice=PACKETBLOBS-1;
  97323. bm->choice=choice;
  97324. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97325. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97326. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97327. }
  97328. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97329. if(max_target_bits>0 && this_bits>max_target_bits){
  97330. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97331. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97332. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97333. }else{
  97334. if(bm->minmax_reservoir>desired_fill){
  97335. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97336. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97337. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97338. }else{
  97339. bm->minmax_reservoir=desired_fill;
  97340. }
  97341. }else{
  97342. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97343. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97344. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97345. }else{
  97346. bm->minmax_reservoir=desired_fill;
  97347. }
  97348. }
  97349. }
  97350. }
  97351. if(bm->avg_bitsper>0){
  97352. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97353. bm->avg_reservoir+=this_bits-avg_target_bits;
  97354. }
  97355. return(0);
  97356. }
  97357. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97358. private_state *b=(private_state*)vd->backend_state;
  97359. bitrate_manager_state *bm=&b->bms;
  97360. vorbis_block *vb=bm->vb;
  97361. int choice=PACKETBLOBS/2;
  97362. if(!vb)return 0;
  97363. if(op){
  97364. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97365. if(vorbis_bitrate_managed(vb))
  97366. choice=bm->choice;
  97367. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97368. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97369. op->b_o_s=0;
  97370. op->e_o_s=vb->eofflag;
  97371. op->granulepos=vb->granulepos;
  97372. op->packetno=vb->sequence; /* for sake of completeness */
  97373. }
  97374. bm->vb=0;
  97375. return(1);
  97376. }
  97377. #endif
  97378. /*** End of inlined file: bitrate.c ***/
  97379. /*** Start of inlined file: block.c ***/
  97380. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97381. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97382. // tasks..
  97383. #if JUCE_MSVC
  97384. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97385. #endif
  97386. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97387. #if JUCE_USE_OGGVORBIS
  97388. #include <stdio.h>
  97389. #include <stdlib.h>
  97390. #include <string.h>
  97391. /*** Start of inlined file: window.h ***/
  97392. #ifndef _V_WINDOW_
  97393. #define _V_WINDOW_
  97394. extern float *_vorbis_window_get(int n);
  97395. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97396. int lW,int W,int nW);
  97397. #endif
  97398. /*** End of inlined file: window.h ***/
  97399. /*** Start of inlined file: lpc.h ***/
  97400. #ifndef _V_LPC_H_
  97401. #define _V_LPC_H_
  97402. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97403. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97404. float *data,long n);
  97405. #endif
  97406. /*** End of inlined file: lpc.h ***/
  97407. #ifndef WORD_ALIGN
  97408. #define WORD_ALIGN 8
  97409. #endif
  97410. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97411. int i;
  97412. memset(vb,0,sizeof(*vb));
  97413. vb->vd=v;
  97414. vb->localalloc=0;
  97415. vb->localstore=NULL;
  97416. if(v->analysisp){
  97417. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97418. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97419. vbi->ampmax=-9999;
  97420. for(i=0;i<PACKETBLOBS;i++){
  97421. if(i==PACKETBLOBS/2){
  97422. vbi->packetblob[i]=&vb->opb;
  97423. }else{
  97424. vbi->packetblob[i]=
  97425. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97426. }
  97427. oggpack_writeinit(vbi->packetblob[i]);
  97428. }
  97429. }
  97430. return(0);
  97431. }
  97432. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97433. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97434. if(bytes+vb->localtop>vb->localalloc){
  97435. if(vb->localstore){
  97436. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97437. vb->totaluse+=vb->localtop;
  97438. link->next=vb->reap;
  97439. link->ptr=vb->localstore;
  97440. vb->reap=link;
  97441. }
  97442. vb->localalloc=bytes;
  97443. vb->localstore=_ogg_malloc(vb->localalloc);
  97444. vb->localtop=0;
  97445. }
  97446. {
  97447. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97448. vb->localtop+=bytes;
  97449. return ret;
  97450. }
  97451. }
  97452. void _vorbis_block_ripcord(vorbis_block *vb){
  97453. struct alloc_chain *reap=vb->reap;
  97454. while(reap){
  97455. struct alloc_chain *next=reap->next;
  97456. _ogg_free(reap->ptr);
  97457. memset(reap,0,sizeof(*reap));
  97458. _ogg_free(reap);
  97459. reap=next;
  97460. }
  97461. if(vb->totaluse){
  97462. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97463. vb->localalloc+=vb->totaluse;
  97464. vb->totaluse=0;
  97465. }
  97466. vb->localtop=0;
  97467. vb->reap=NULL;
  97468. }
  97469. int vorbis_block_clear(vorbis_block *vb){
  97470. int i;
  97471. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97472. _vorbis_block_ripcord(vb);
  97473. if(vb->localstore)_ogg_free(vb->localstore);
  97474. if(vbi){
  97475. for(i=0;i<PACKETBLOBS;i++){
  97476. oggpack_writeclear(vbi->packetblob[i]);
  97477. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97478. }
  97479. _ogg_free(vbi);
  97480. }
  97481. memset(vb,0,sizeof(*vb));
  97482. return(0);
  97483. }
  97484. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97485. int i;
  97486. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97487. private_state *b=NULL;
  97488. int hs;
  97489. if(ci==NULL) return 1;
  97490. hs=ci->halfrate_flag;
  97491. memset(v,0,sizeof(*v));
  97492. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97493. v->vi=vi;
  97494. b->modebits=ilog2(ci->modes);
  97495. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97496. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97497. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97498. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97499. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97500. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97501. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97502. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97503. if(encp){ /* encode/decode differ here */
  97504. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97505. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97506. if(!ci->fullbooks){
  97507. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97508. for(i=0;i<ci->books;i++)
  97509. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97510. }
  97511. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97512. for(i=0;i<ci->psys;i++){
  97513. _vp_psy_init(b->psy+i,
  97514. ci->psy_param[i],
  97515. &ci->psy_g_param,
  97516. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97517. vi->rate);
  97518. }
  97519. v->analysisp=1;
  97520. }else{
  97521. if(!ci->fullbooks){
  97522. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97523. for(i=0;i<ci->books;i++){
  97524. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97525. vorbis_staticbook_destroy(ci->book_param[i]);
  97526. ci->book_param[i]=NULL;
  97527. }
  97528. }
  97529. }
  97530. v->pcm_storage=ci->blocksizes[1];
  97531. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97532. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97533. {
  97534. int i;
  97535. for(i=0;i<vi->channels;i++)
  97536. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97537. }
  97538. v->lW=0; /* previous window size */
  97539. v->W=0; /* current window size */
  97540. v->centerW=ci->blocksizes[1]/2;
  97541. v->pcm_current=v->centerW;
  97542. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97543. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97544. for(i=0;i<ci->floors;i++)
  97545. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97546. look(v,ci->floor_param[i]);
  97547. for(i=0;i<ci->residues;i++)
  97548. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97549. look(v,ci->residue_param[i]);
  97550. return 0;
  97551. }
  97552. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97553. private_state *b=NULL;
  97554. if(_vds_shared_init(v,vi,1))return 1;
  97555. b=(private_state*)v->backend_state;
  97556. b->psy_g_look=_vp_global_look(vi);
  97557. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97558. _ve_envelope_init(b->ve,vi);
  97559. vorbis_bitrate_init(vi,&b->bms);
  97560. v->sequence=3;
  97561. return(0);
  97562. }
  97563. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97564. int i;
  97565. if(v){
  97566. vorbis_info *vi=v->vi;
  97567. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97568. private_state *b=(private_state*)v->backend_state;
  97569. if(b){
  97570. if(b->ve){
  97571. _ve_envelope_clear(b->ve);
  97572. _ogg_free(b->ve);
  97573. }
  97574. if(b->transform[0]){
  97575. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97576. _ogg_free(b->transform[0][0]);
  97577. _ogg_free(b->transform[0]);
  97578. }
  97579. if(b->transform[1]){
  97580. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97581. _ogg_free(b->transform[1][0]);
  97582. _ogg_free(b->transform[1]);
  97583. }
  97584. if(b->flr){
  97585. for(i=0;i<ci->floors;i++)
  97586. _floor_P[ci->floor_type[i]]->
  97587. free_look(b->flr[i]);
  97588. _ogg_free(b->flr);
  97589. }
  97590. if(b->residue){
  97591. for(i=0;i<ci->residues;i++)
  97592. _residue_P[ci->residue_type[i]]->
  97593. free_look(b->residue[i]);
  97594. _ogg_free(b->residue);
  97595. }
  97596. if(b->psy){
  97597. for(i=0;i<ci->psys;i++)
  97598. _vp_psy_clear(b->psy+i);
  97599. _ogg_free(b->psy);
  97600. }
  97601. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97602. vorbis_bitrate_clear(&b->bms);
  97603. drft_clear(&b->fft_look[0]);
  97604. drft_clear(&b->fft_look[1]);
  97605. }
  97606. if(v->pcm){
  97607. for(i=0;i<vi->channels;i++)
  97608. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97609. _ogg_free(v->pcm);
  97610. if(v->pcmret)_ogg_free(v->pcmret);
  97611. }
  97612. if(b){
  97613. if(b->header)_ogg_free(b->header);
  97614. if(b->header1)_ogg_free(b->header1);
  97615. if(b->header2)_ogg_free(b->header2);
  97616. _ogg_free(b);
  97617. }
  97618. memset(v,0,sizeof(*v));
  97619. }
  97620. }
  97621. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97622. int i;
  97623. vorbis_info *vi=v->vi;
  97624. private_state *b=(private_state*)v->backend_state;
  97625. if(b->header)_ogg_free(b->header);b->header=NULL;
  97626. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97627. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97628. if(v->pcm_current+vals>=v->pcm_storage){
  97629. v->pcm_storage=v->pcm_current+vals*2;
  97630. for(i=0;i<vi->channels;i++){
  97631. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97632. }
  97633. }
  97634. for(i=0;i<vi->channels;i++)
  97635. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97636. return(v->pcmret);
  97637. }
  97638. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97639. int i;
  97640. int order=32;
  97641. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97642. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97643. long j;
  97644. v->preextrapolate=1;
  97645. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97646. for(i=0;i<v->vi->channels;i++){
  97647. for(j=0;j<v->pcm_current;j++)
  97648. work[j]=v->pcm[i][v->pcm_current-j-1];
  97649. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97650. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97651. order,
  97652. work+v->pcm_current-v->centerW,
  97653. v->centerW);
  97654. for(j=0;j<v->pcm_current;j++)
  97655. v->pcm[i][v->pcm_current-j-1]=work[j];
  97656. }
  97657. }
  97658. }
  97659. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97660. vorbis_info *vi=v->vi;
  97661. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97662. if(vals<=0){
  97663. int order=32;
  97664. int i;
  97665. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97666. if(!v->preextrapolate)
  97667. _preextrapolate_helper(v);
  97668. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97669. v->eofflag=v->pcm_current;
  97670. v->pcm_current+=ci->blocksizes[1]*3;
  97671. for(i=0;i<vi->channels;i++){
  97672. if(v->eofflag>order*2){
  97673. long n;
  97674. n=v->eofflag;
  97675. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97676. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97677. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97678. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97679. }else{
  97680. memset(v->pcm[i]+v->eofflag,0,
  97681. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97682. }
  97683. }
  97684. }else{
  97685. if(v->pcm_current+vals>v->pcm_storage)
  97686. return(OV_EINVAL);
  97687. v->pcm_current+=vals;
  97688. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97689. _preextrapolate_helper(v);
  97690. }
  97691. return(0);
  97692. }
  97693. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  97694. int i;
  97695. vorbis_info *vi=v->vi;
  97696. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97697. private_state *b=(private_state*)v->backend_state;
  97698. vorbis_look_psy_global *g=b->psy_g_look;
  97699. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  97700. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97701. if(!v->preextrapolate)return(0);
  97702. if(v->eofflag==-1)return(0);
  97703. {
  97704. long bp=_ve_envelope_search(v);
  97705. if(bp==-1){
  97706. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  97707. full long block */
  97708. v->nW=0;
  97709. }else{
  97710. if(ci->blocksizes[0]==ci->blocksizes[1])
  97711. v->nW=0;
  97712. else
  97713. v->nW=bp;
  97714. }
  97715. }
  97716. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  97717. {
  97718. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  97719. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  97720. although this check is
  97721. less strict that the
  97722. _ve_envelope_search,
  97723. the search is not run
  97724. if we only use one
  97725. block size */
  97726. }
  97727. _vorbis_block_ripcord(vb);
  97728. vb->lW=v->lW;
  97729. vb->W=v->W;
  97730. vb->nW=v->nW;
  97731. if(v->W){
  97732. if(!v->lW || !v->nW){
  97733. vbi->blocktype=BLOCKTYPE_TRANSITION;
  97734. }else{
  97735. vbi->blocktype=BLOCKTYPE_LONG;
  97736. }
  97737. }else{
  97738. if(_ve_envelope_mark(v)){
  97739. vbi->blocktype=BLOCKTYPE_IMPULSE;
  97740. }else{
  97741. vbi->blocktype=BLOCKTYPE_PADDING;
  97742. }
  97743. }
  97744. vb->vd=v;
  97745. vb->sequence=v->sequence++;
  97746. vb->granulepos=v->granulepos;
  97747. vb->pcmend=ci->blocksizes[v->W];
  97748. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  97749. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  97750. vbi->ampmax=g->ampmax;
  97751. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  97752. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  97753. for(i=0;i<vi->channels;i++){
  97754. vbi->pcmdelay[i]=
  97755. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97756. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97757. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  97758. }
  97759. if(v->eofflag){
  97760. if(v->centerW>=v->eofflag){
  97761. v->eofflag=-1;
  97762. vb->eofflag=1;
  97763. return(1);
  97764. }
  97765. }
  97766. {
  97767. int new_centerNext=ci->blocksizes[1]/2;
  97768. int movementW=centerNext-new_centerNext;
  97769. if(movementW>0){
  97770. _ve_envelope_shift(b->ve,movementW);
  97771. v->pcm_current-=movementW;
  97772. for(i=0;i<vi->channels;i++)
  97773. memmove(v->pcm[i],v->pcm[i]+movementW,
  97774. v->pcm_current*sizeof(*v->pcm[i]));
  97775. v->lW=v->W;
  97776. v->W=v->nW;
  97777. v->centerW=new_centerNext;
  97778. if(v->eofflag){
  97779. v->eofflag-=movementW;
  97780. if(v->eofflag<=0)v->eofflag=-1;
  97781. if(v->centerW>=v->eofflag){
  97782. v->granulepos+=movementW-(v->centerW-v->eofflag);
  97783. }else{
  97784. v->granulepos+=movementW;
  97785. }
  97786. }else{
  97787. v->granulepos+=movementW;
  97788. }
  97789. }
  97790. }
  97791. return(1);
  97792. }
  97793. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  97794. vorbis_info *vi=v->vi;
  97795. codec_setup_info *ci;
  97796. int hs;
  97797. if(!v->backend_state)return -1;
  97798. if(!vi)return -1;
  97799. ci=(codec_setup_info*) vi->codec_setup;
  97800. if(!ci)return -1;
  97801. hs=ci->halfrate_flag;
  97802. v->centerW=ci->blocksizes[1]>>(hs+1);
  97803. v->pcm_current=v->centerW>>hs;
  97804. v->pcm_returned=-1;
  97805. v->granulepos=-1;
  97806. v->sequence=-1;
  97807. v->eofflag=0;
  97808. ((private_state *)(v->backend_state))->sample_count=-1;
  97809. return(0);
  97810. }
  97811. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97812. if(_vds_shared_init(v,vi,0)) return 1;
  97813. vorbis_synthesis_restart(v);
  97814. return 0;
  97815. }
  97816. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  97817. vorbis_info *vi=v->vi;
  97818. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97819. private_state *b=(private_state*)v->backend_state;
  97820. int hs=ci->halfrate_flag;
  97821. int i,j;
  97822. if(!vb)return(OV_EINVAL);
  97823. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  97824. v->lW=v->W;
  97825. v->W=vb->W;
  97826. v->nW=-1;
  97827. if((v->sequence==-1)||
  97828. (v->sequence+1 != vb->sequence)){
  97829. v->granulepos=-1; /* out of sequence; lose count */
  97830. b->sample_count=-1;
  97831. }
  97832. v->sequence=vb->sequence;
  97833. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  97834. was called on block */
  97835. int n=ci->blocksizes[v->W]>>(hs+1);
  97836. int n0=ci->blocksizes[0]>>(hs+1);
  97837. int n1=ci->blocksizes[1]>>(hs+1);
  97838. int thisCenter;
  97839. int prevCenter;
  97840. v->glue_bits+=vb->glue_bits;
  97841. v->time_bits+=vb->time_bits;
  97842. v->floor_bits+=vb->floor_bits;
  97843. v->res_bits+=vb->res_bits;
  97844. if(v->centerW){
  97845. thisCenter=n1;
  97846. prevCenter=0;
  97847. }else{
  97848. thisCenter=0;
  97849. prevCenter=n1;
  97850. }
  97851. for(j=0;j<vi->channels;j++){
  97852. if(v->lW){
  97853. if(v->W){
  97854. float *w=_vorbis_window_get(b->window[1]-hs);
  97855. float *pcm=v->pcm[j]+prevCenter;
  97856. float *p=vb->pcm[j];
  97857. for(i=0;i<n1;i++)
  97858. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  97859. }else{
  97860. float *w=_vorbis_window_get(b->window[0]-hs);
  97861. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  97862. float *p=vb->pcm[j];
  97863. for(i=0;i<n0;i++)
  97864. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97865. }
  97866. }else{
  97867. if(v->W){
  97868. float *w=_vorbis_window_get(b->window[0]-hs);
  97869. float *pcm=v->pcm[j]+prevCenter;
  97870. float *p=vb->pcm[j]+n1/2-n0/2;
  97871. for(i=0;i<n0;i++)
  97872. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97873. for(;i<n1/2+n0/2;i++)
  97874. pcm[i]=p[i];
  97875. }else{
  97876. float *w=_vorbis_window_get(b->window[0]-hs);
  97877. float *pcm=v->pcm[j]+prevCenter;
  97878. float *p=vb->pcm[j];
  97879. for(i=0;i<n0;i++)
  97880. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97881. }
  97882. }
  97883. {
  97884. float *pcm=v->pcm[j]+thisCenter;
  97885. float *p=vb->pcm[j]+n;
  97886. for(i=0;i<n;i++)
  97887. pcm[i]=p[i];
  97888. }
  97889. }
  97890. if(v->centerW)
  97891. v->centerW=0;
  97892. else
  97893. v->centerW=n1;
  97894. if(v->pcm_returned==-1){
  97895. v->pcm_returned=thisCenter;
  97896. v->pcm_current=thisCenter;
  97897. }else{
  97898. v->pcm_returned=prevCenter;
  97899. v->pcm_current=prevCenter+
  97900. ((ci->blocksizes[v->lW]/4+
  97901. ci->blocksizes[v->W]/4)>>hs);
  97902. }
  97903. }
  97904. if(b->sample_count==-1){
  97905. b->sample_count=0;
  97906. }else{
  97907. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  97908. }
  97909. if(v->granulepos==-1){
  97910. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  97911. v->granulepos=vb->granulepos;
  97912. if(b->sample_count>v->granulepos){
  97913. if(vb->eofflag){
  97914. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  97915. }else{
  97916. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  97917. if(v->pcm_returned>v->pcm_current)
  97918. v->pcm_returned=v->pcm_current;
  97919. }
  97920. }
  97921. }
  97922. }else{
  97923. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  97924. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  97925. if(v->granulepos>vb->granulepos){
  97926. long extra=v->granulepos-vb->granulepos;
  97927. if(extra)
  97928. if(vb->eofflag){
  97929. v->pcm_current-=extra>>hs;
  97930. } /* else {Shouldn't happen *unless* the bitstream is out of
  97931. spec. Either way, believe the bitstream } */
  97932. } /* else {Shouldn't happen *unless* the bitstream is out of
  97933. spec. Either way, believe the bitstream } */
  97934. v->granulepos=vb->granulepos;
  97935. }
  97936. }
  97937. if(vb->eofflag)v->eofflag=1;
  97938. return(0);
  97939. }
  97940. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  97941. vorbis_info *vi=v->vi;
  97942. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  97943. if(pcm){
  97944. int i;
  97945. for(i=0;i<vi->channels;i++)
  97946. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  97947. *pcm=v->pcmret;
  97948. }
  97949. return(v->pcm_current-v->pcm_returned);
  97950. }
  97951. return(0);
  97952. }
  97953. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  97954. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  97955. v->pcm_returned+=n;
  97956. return(0);
  97957. }
  97958. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  97959. vorbis_info *vi=v->vi;
  97960. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97961. int hs=ci->halfrate_flag;
  97962. int n=ci->blocksizes[v->W]>>(hs+1);
  97963. int n0=ci->blocksizes[0]>>(hs+1);
  97964. int n1=ci->blocksizes[1]>>(hs+1);
  97965. int i,j;
  97966. if(v->pcm_returned<0)return 0;
  97967. if(v->centerW==n1){
  97968. for(j=0;j<vi->channels;j++){
  97969. float *p=v->pcm[j];
  97970. for(i=0;i<n1;i++){
  97971. float temp=p[i];
  97972. p[i]=p[i+n1];
  97973. p[i+n1]=temp;
  97974. }
  97975. }
  97976. v->pcm_current-=n1;
  97977. v->pcm_returned-=n1;
  97978. v->centerW=0;
  97979. }
  97980. if((v->lW^v->W)==1){
  97981. for(j=0;j<vi->channels;j++){
  97982. float *s=v->pcm[j];
  97983. float *d=v->pcm[j]+(n1-n0)/2;
  97984. for(i=(n1+n0)/2-1;i>=0;--i)
  97985. d[i]=s[i];
  97986. }
  97987. v->pcm_returned+=(n1-n0)/2;
  97988. v->pcm_current+=(n1-n0)/2;
  97989. }else{
  97990. if(v->lW==0){
  97991. for(j=0;j<vi->channels;j++){
  97992. float *s=v->pcm[j];
  97993. float *d=v->pcm[j]+n1-n0;
  97994. for(i=n0-1;i>=0;--i)
  97995. d[i]=s[i];
  97996. }
  97997. v->pcm_returned+=n1-n0;
  97998. v->pcm_current+=n1-n0;
  97999. }
  98000. }
  98001. if(pcm){
  98002. int i;
  98003. for(i=0;i<vi->channels;i++)
  98004. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98005. *pcm=v->pcmret;
  98006. }
  98007. return(n1+n-v->pcm_returned);
  98008. }
  98009. float *vorbis_window(vorbis_dsp_state *v,int W){
  98010. vorbis_info *vi=v->vi;
  98011. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98012. int hs=ci->halfrate_flag;
  98013. private_state *b=(private_state*)v->backend_state;
  98014. if(b->window[W]-1<0)return NULL;
  98015. return _vorbis_window_get(b->window[W]-hs);
  98016. }
  98017. #endif
  98018. /*** End of inlined file: block.c ***/
  98019. /*** Start of inlined file: codebook.c ***/
  98020. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98021. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98022. // tasks..
  98023. #if JUCE_MSVC
  98024. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98025. #endif
  98026. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98027. #if JUCE_USE_OGGVORBIS
  98028. #include <stdlib.h>
  98029. #include <string.h>
  98030. #include <math.h>
  98031. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98032. long i,j;
  98033. int ordered=0;
  98034. oggpack_write(opb,0x564342,24);
  98035. oggpack_write(opb,c->dim,16);
  98036. oggpack_write(opb,c->entries,24);
  98037. for(i=1;i<c->entries;i++)
  98038. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98039. if(i==c->entries)ordered=1;
  98040. if(ordered){
  98041. long count=0;
  98042. oggpack_write(opb,1,1); /* ordered */
  98043. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98044. for(i=1;i<c->entries;i++){
  98045. long thisx=c->lengthlist[i];
  98046. long last=c->lengthlist[i-1];
  98047. if(thisx>last){
  98048. for(j=last;j<thisx;j++){
  98049. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98050. count=i;
  98051. }
  98052. }
  98053. }
  98054. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98055. }else{
  98056. oggpack_write(opb,0,1); /* unordered */
  98057. for(i=0;i<c->entries;i++)
  98058. if(c->lengthlist[i]==0)break;
  98059. if(i==c->entries){
  98060. oggpack_write(opb,0,1); /* no unused entries */
  98061. for(i=0;i<c->entries;i++)
  98062. oggpack_write(opb,c->lengthlist[i]-1,5);
  98063. }else{
  98064. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98065. for(i=0;i<c->entries;i++){
  98066. if(c->lengthlist[i]==0){
  98067. oggpack_write(opb,0,1);
  98068. }else{
  98069. oggpack_write(opb,1,1);
  98070. oggpack_write(opb,c->lengthlist[i]-1,5);
  98071. }
  98072. }
  98073. }
  98074. }
  98075. oggpack_write(opb,c->maptype,4);
  98076. switch(c->maptype){
  98077. case 0:
  98078. break;
  98079. case 1:case 2:
  98080. if(!c->quantlist){
  98081. return(-1);
  98082. }
  98083. oggpack_write(opb,c->q_min,32);
  98084. oggpack_write(opb,c->q_delta,32);
  98085. oggpack_write(opb,c->q_quant-1,4);
  98086. oggpack_write(opb,c->q_sequencep,1);
  98087. {
  98088. int quantvals;
  98089. switch(c->maptype){
  98090. case 1:
  98091. quantvals=_book_maptype1_quantvals(c);
  98092. break;
  98093. case 2:
  98094. quantvals=c->entries*c->dim;
  98095. break;
  98096. default: /* NOT_REACHABLE */
  98097. quantvals=-1;
  98098. }
  98099. for(i=0;i<quantvals;i++)
  98100. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98101. }
  98102. break;
  98103. default:
  98104. return(-1);
  98105. }
  98106. return(0);
  98107. }
  98108. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98109. long i,j;
  98110. memset(s,0,sizeof(*s));
  98111. s->allocedp=1;
  98112. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98113. s->dim=oggpack_read(opb,16);
  98114. s->entries=oggpack_read(opb,24);
  98115. if(s->entries==-1)goto _eofout;
  98116. switch((int)oggpack_read(opb,1)){
  98117. case 0:
  98118. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98119. if(oggpack_read(opb,1)){
  98120. for(i=0;i<s->entries;i++){
  98121. if(oggpack_read(opb,1)){
  98122. long num=oggpack_read(opb,5);
  98123. if(num==-1)goto _eofout;
  98124. s->lengthlist[i]=num+1;
  98125. }else
  98126. s->lengthlist[i]=0;
  98127. }
  98128. }else{
  98129. for(i=0;i<s->entries;i++){
  98130. long num=oggpack_read(opb,5);
  98131. if(num==-1)goto _eofout;
  98132. s->lengthlist[i]=num+1;
  98133. }
  98134. }
  98135. break;
  98136. case 1:
  98137. {
  98138. long length=oggpack_read(opb,5)+1;
  98139. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98140. for(i=0;i<s->entries;){
  98141. long num=oggpack_read(opb,_ilog(s->entries-i));
  98142. if(num==-1)goto _eofout;
  98143. for(j=0;j<num && i<s->entries;j++,i++)
  98144. s->lengthlist[i]=length;
  98145. length++;
  98146. }
  98147. }
  98148. break;
  98149. default:
  98150. return(-1);
  98151. }
  98152. switch((s->maptype=oggpack_read(opb,4))){
  98153. case 0:
  98154. break;
  98155. case 1: case 2:
  98156. s->q_min=oggpack_read(opb,32);
  98157. s->q_delta=oggpack_read(opb,32);
  98158. s->q_quant=oggpack_read(opb,4)+1;
  98159. s->q_sequencep=oggpack_read(opb,1);
  98160. {
  98161. int quantvals=0;
  98162. switch(s->maptype){
  98163. case 1:
  98164. quantvals=_book_maptype1_quantvals(s);
  98165. break;
  98166. case 2:
  98167. quantvals=s->entries*s->dim;
  98168. break;
  98169. }
  98170. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98171. for(i=0;i<quantvals;i++)
  98172. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98173. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98174. }
  98175. break;
  98176. default:
  98177. goto _errout;
  98178. }
  98179. return(0);
  98180. _errout:
  98181. _eofout:
  98182. vorbis_staticbook_clear(s);
  98183. return(-1);
  98184. }
  98185. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98186. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98187. return(book->c->lengthlist[a]);
  98188. }
  98189. int vorbis_book_errorv(codebook *book,float *a){
  98190. int dim=book->dim,k;
  98191. int best=_best(book,a,1);
  98192. for(k=0;k<dim;k++)
  98193. a[k]=(book->valuelist+best*dim)[k];
  98194. return(best);
  98195. }
  98196. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98197. int k,dim=book->dim;
  98198. for(k=0;k<dim;k++)
  98199. a[k]=(book->valuelist+best*dim)[k];
  98200. return(vorbis_book_encode(book,best,b));
  98201. }
  98202. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98203. int read=book->dec_maxlength;
  98204. long lo,hi;
  98205. long lok = oggpack_look(b,book->dec_firsttablen);
  98206. if (lok >= 0) {
  98207. long entry = book->dec_firsttable[lok];
  98208. if(entry&0x80000000UL){
  98209. lo=(entry>>15)&0x7fff;
  98210. hi=book->used_entries-(entry&0x7fff);
  98211. }else{
  98212. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98213. return(entry-1);
  98214. }
  98215. }else{
  98216. lo=0;
  98217. hi=book->used_entries;
  98218. }
  98219. lok = oggpack_look(b, read);
  98220. while(lok<0 && read>1)
  98221. lok = oggpack_look(b, --read);
  98222. if(lok<0)return -1;
  98223. {
  98224. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98225. while(hi-lo>1){
  98226. long p=(hi-lo)>>1;
  98227. long test=book->codelist[lo+p]>testword;
  98228. lo+=p&(test-1);
  98229. hi-=p&(-test);
  98230. }
  98231. if(book->dec_codelengths[lo]<=read){
  98232. oggpack_adv(b, book->dec_codelengths[lo]);
  98233. return(lo);
  98234. }
  98235. }
  98236. oggpack_adv(b, read);
  98237. return(-1);
  98238. }
  98239. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98240. long packed_entry=decode_packed_entry_number(book,b);
  98241. if(packed_entry>=0)
  98242. return(book->dec_index[packed_entry]);
  98243. return(packed_entry);
  98244. }
  98245. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98246. int step=n/book->dim;
  98247. long *entry = (long*)alloca(sizeof(*entry)*step);
  98248. float **t = (float**)alloca(sizeof(*t)*step);
  98249. int i,j,o;
  98250. for (i = 0; i < step; i++) {
  98251. entry[i]=decode_packed_entry_number(book,b);
  98252. if(entry[i]==-1)return(-1);
  98253. t[i] = book->valuelist+entry[i]*book->dim;
  98254. }
  98255. for(i=0,o=0;i<book->dim;i++,o+=step)
  98256. for (j=0;j<step;j++)
  98257. a[o+j]+=t[j][i];
  98258. return(0);
  98259. }
  98260. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98261. int i,j,entry;
  98262. float *t;
  98263. if(book->dim>8){
  98264. for(i=0;i<n;){
  98265. entry = decode_packed_entry_number(book,b);
  98266. if(entry==-1)return(-1);
  98267. t = book->valuelist+entry*book->dim;
  98268. for (j=0;j<book->dim;)
  98269. a[i++]+=t[j++];
  98270. }
  98271. }else{
  98272. for(i=0;i<n;){
  98273. entry = decode_packed_entry_number(book,b);
  98274. if(entry==-1)return(-1);
  98275. t = book->valuelist+entry*book->dim;
  98276. j=0;
  98277. switch((int)book->dim){
  98278. case 8:
  98279. a[i++]+=t[j++];
  98280. case 7:
  98281. a[i++]+=t[j++];
  98282. case 6:
  98283. a[i++]+=t[j++];
  98284. case 5:
  98285. a[i++]+=t[j++];
  98286. case 4:
  98287. a[i++]+=t[j++];
  98288. case 3:
  98289. a[i++]+=t[j++];
  98290. case 2:
  98291. a[i++]+=t[j++];
  98292. case 1:
  98293. a[i++]+=t[j++];
  98294. case 0:
  98295. break;
  98296. }
  98297. }
  98298. }
  98299. return(0);
  98300. }
  98301. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98302. int i,j,entry;
  98303. float *t;
  98304. for(i=0;i<n;){
  98305. entry = decode_packed_entry_number(book,b);
  98306. if(entry==-1)return(-1);
  98307. t = book->valuelist+entry*book->dim;
  98308. for (j=0;j<book->dim;)
  98309. a[i++]=t[j++];
  98310. }
  98311. return(0);
  98312. }
  98313. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98314. oggpack_buffer *b,int n){
  98315. long i,j,entry;
  98316. int chptr=0;
  98317. for(i=offset/ch;i<(offset+n)/ch;){
  98318. entry = decode_packed_entry_number(book,b);
  98319. if(entry==-1)return(-1);
  98320. {
  98321. const float *t = book->valuelist+entry*book->dim;
  98322. for (j=0;j<book->dim;j++){
  98323. a[chptr++][i]+=t[j];
  98324. if(chptr==ch){
  98325. chptr=0;
  98326. i++;
  98327. }
  98328. }
  98329. }
  98330. }
  98331. return(0);
  98332. }
  98333. #ifdef _V_SELFTEST
  98334. #include <stdio.h>
  98335. #include "vorbis/book/lsp20_0.vqh"
  98336. #include "vorbis/book/res0a_13.vqh"
  98337. #define TESTSIZE 40
  98338. float test1[TESTSIZE]={
  98339. 0.105939f,
  98340. 0.215373f,
  98341. 0.429117f,
  98342. 0.587974f,
  98343. 0.181173f,
  98344. 0.296583f,
  98345. 0.515707f,
  98346. 0.715261f,
  98347. 0.162327f,
  98348. 0.263834f,
  98349. 0.342876f,
  98350. 0.406025f,
  98351. 0.103571f,
  98352. 0.223561f,
  98353. 0.368513f,
  98354. 0.540313f,
  98355. 0.136672f,
  98356. 0.395882f,
  98357. 0.587183f,
  98358. 0.652476f,
  98359. 0.114338f,
  98360. 0.417300f,
  98361. 0.525486f,
  98362. 0.698679f,
  98363. 0.147492f,
  98364. 0.324481f,
  98365. 0.643089f,
  98366. 0.757582f,
  98367. 0.139556f,
  98368. 0.215795f,
  98369. 0.324559f,
  98370. 0.399387f,
  98371. 0.120236f,
  98372. 0.267420f,
  98373. 0.446940f,
  98374. 0.608760f,
  98375. 0.115587f,
  98376. 0.287234f,
  98377. 0.571081f,
  98378. 0.708603f,
  98379. };
  98380. float test3[TESTSIZE]={
  98381. 0,1,-2,3,4,-5,6,7,8,9,
  98382. 8,-2,7,-1,4,6,8,3,1,-9,
  98383. 10,11,12,13,14,15,26,17,18,19,
  98384. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98385. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98386. &_vq_book_res0a_13,NULL};
  98387. float *testvec[]={test1,test3};
  98388. int main(){
  98389. oggpack_buffer write;
  98390. oggpack_buffer read;
  98391. long ptr=0,i;
  98392. oggpack_writeinit(&write);
  98393. fprintf(stderr,"Testing codebook abstraction...:\n");
  98394. while(testlist[ptr]){
  98395. codebook c;
  98396. static_codebook s;
  98397. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98398. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98399. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98400. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98401. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98402. oggpack_reset(&write);
  98403. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98404. we can write */
  98405. vorbis_staticbook_pack(testlist[ptr],&write);
  98406. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98407. for(i=0;i<TESTSIZE;i+=c.dim){
  98408. int best=_best(&c,qv+i,1);
  98409. vorbis_book_encodev(&c,best,qv+i,&write);
  98410. }
  98411. vorbis_book_clear(&c);
  98412. fprintf(stderr,"OK.\n");
  98413. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98414. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98415. if(vorbis_staticbook_unpack(&read,&s)){
  98416. fprintf(stderr,"Error unpacking codebook.\n");
  98417. exit(1);
  98418. }
  98419. if(vorbis_book_init_decode(&c,&s)){
  98420. fprintf(stderr,"Error initializing codebook.\n");
  98421. exit(1);
  98422. }
  98423. for(i=0;i<TESTSIZE;i+=c.dim)
  98424. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98425. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98426. exit(1);
  98427. }
  98428. for(i=0;i<TESTSIZE;i++)
  98429. if(fabs(qv[i]-iv[i])>.000001){
  98430. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98431. iv[i],qv[i],i);
  98432. exit(1);
  98433. }
  98434. fprintf(stderr,"OK\n");
  98435. ptr++;
  98436. }
  98437. exit(0);
  98438. }
  98439. #endif
  98440. #endif
  98441. /*** End of inlined file: codebook.c ***/
  98442. /*** Start of inlined file: envelope.c ***/
  98443. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98444. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98445. // tasks..
  98446. #if JUCE_MSVC
  98447. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98448. #endif
  98449. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98450. #if JUCE_USE_OGGVORBIS
  98451. #include <stdlib.h>
  98452. #include <string.h>
  98453. #include <stdio.h>
  98454. #include <math.h>
  98455. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98456. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98457. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98458. int ch=vi->channels;
  98459. int i,j;
  98460. int n=e->winlength=128;
  98461. e->searchstep=64; /* not random */
  98462. e->minenergy=gi->preecho_minenergy;
  98463. e->ch=ch;
  98464. e->storage=128;
  98465. e->cursor=ci->blocksizes[1]/2;
  98466. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98467. mdct_init(&e->mdct,n);
  98468. for(i=0;i<n;i++){
  98469. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98470. e->mdct_win[i]*=e->mdct_win[i];
  98471. }
  98472. e->band[0].begin=2; e->band[0].end=4;
  98473. e->band[1].begin=4; e->band[1].end=5;
  98474. e->band[2].begin=6; e->band[2].end=6;
  98475. e->band[3].begin=9; e->band[3].end=8;
  98476. e->band[4].begin=13; e->band[4].end=8;
  98477. e->band[5].begin=17; e->band[5].end=8;
  98478. e->band[6].begin=22; e->band[6].end=8;
  98479. for(j=0;j<VE_BANDS;j++){
  98480. n=e->band[j].end;
  98481. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98482. for(i=0;i<n;i++){
  98483. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98484. e->band[j].total+=e->band[j].window[i];
  98485. }
  98486. e->band[j].total=1./e->band[j].total;
  98487. }
  98488. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98489. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98490. }
  98491. void _ve_envelope_clear(envelope_lookup *e){
  98492. int i;
  98493. mdct_clear(&e->mdct);
  98494. for(i=0;i<VE_BANDS;i++)
  98495. _ogg_free(e->band[i].window);
  98496. _ogg_free(e->mdct_win);
  98497. _ogg_free(e->filter);
  98498. _ogg_free(e->mark);
  98499. memset(e,0,sizeof(*e));
  98500. }
  98501. static int _ve_amp(envelope_lookup *ve,
  98502. vorbis_info_psy_global *gi,
  98503. float *data,
  98504. envelope_band *bands,
  98505. envelope_filter_state *filters,
  98506. long pos){
  98507. long n=ve->winlength;
  98508. int ret=0;
  98509. long i,j;
  98510. float decay;
  98511. float minV=ve->minenergy;
  98512. float *vec=(float*) alloca(n*sizeof(*vec));
  98513. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98514. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98515. if(penalty<0.f)penalty=0.f;
  98516. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98517. for(i=0;i<n;i++)
  98518. vec[i]=data[i]*ve->mdct_win[i];
  98519. mdct_forward(&ve->mdct,vec,vec);
  98520. {
  98521. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98522. int ptr=filters->nearptr;
  98523. if(ptr==0){
  98524. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98525. filters->nearDC_partialacc=temp;
  98526. }else{
  98527. decay=filters->nearDC_acc+=temp;
  98528. filters->nearDC_partialacc+=temp;
  98529. }
  98530. filters->nearDC_acc-=filters->nearDC[ptr];
  98531. filters->nearDC[ptr]=temp;
  98532. decay*=(1./(VE_NEARDC+1));
  98533. filters->nearptr++;
  98534. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98535. decay=todB(&decay)*.5-15.f;
  98536. }
  98537. for(i=0;i<n/2;i+=2){
  98538. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98539. val=todB(&val)*.5f;
  98540. if(val<decay)val=decay;
  98541. if(val<minV)val=minV;
  98542. vec[i>>1]=val;
  98543. decay-=8.;
  98544. }
  98545. for(j=0;j<VE_BANDS;j++){
  98546. float acc=0.;
  98547. float valmax,valmin;
  98548. for(i=0;i<bands[j].end;i++)
  98549. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98550. acc*=bands[j].total;
  98551. {
  98552. int p,thisx=filters[j].ampptr;
  98553. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98554. p=thisx;
  98555. p--;
  98556. if(p<0)p+=VE_AMP;
  98557. postmax=max(acc,filters[j].ampbuf[p]);
  98558. postmin=min(acc,filters[j].ampbuf[p]);
  98559. for(i=0;i<stretch;i++){
  98560. p--;
  98561. if(p<0)p+=VE_AMP;
  98562. premax=max(premax,filters[j].ampbuf[p]);
  98563. premin=min(premin,filters[j].ampbuf[p]);
  98564. }
  98565. valmin=postmin-premin;
  98566. valmax=postmax-premax;
  98567. filters[j].ampbuf[thisx]=acc;
  98568. filters[j].ampptr++;
  98569. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98570. }
  98571. if(valmax>gi->preecho_thresh[j]+penalty){
  98572. ret|=1;
  98573. ret|=4;
  98574. }
  98575. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98576. }
  98577. return(ret);
  98578. }
  98579. #if 0
  98580. static int seq=0;
  98581. static ogg_int64_t totalshift=-1024;
  98582. #endif
  98583. long _ve_envelope_search(vorbis_dsp_state *v){
  98584. vorbis_info *vi=v->vi;
  98585. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98586. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98587. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98588. long i,j;
  98589. int first=ve->current/ve->searchstep;
  98590. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98591. if(first<0)first=0;
  98592. if(last+VE_WIN+VE_POST>ve->storage){
  98593. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98594. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98595. }
  98596. for(j=first;j<last;j++){
  98597. int ret=0;
  98598. ve->stretch++;
  98599. if(ve->stretch>VE_MAXSTRETCH*2)
  98600. ve->stretch=VE_MAXSTRETCH*2;
  98601. for(i=0;i<ve->ch;i++){
  98602. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98603. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98604. }
  98605. ve->mark[j+VE_POST]=0;
  98606. if(ret&1){
  98607. ve->mark[j]=1;
  98608. ve->mark[j+1]=1;
  98609. }
  98610. if(ret&2){
  98611. ve->mark[j]=1;
  98612. if(j>0)ve->mark[j-1]=1;
  98613. }
  98614. if(ret&4)ve->stretch=-1;
  98615. }
  98616. ve->current=last*ve->searchstep;
  98617. {
  98618. long centerW=v->centerW;
  98619. long testW=
  98620. centerW+
  98621. ci->blocksizes[v->W]/4+
  98622. ci->blocksizes[1]/2+
  98623. ci->blocksizes[0]/4;
  98624. j=ve->cursor;
  98625. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98626. working back one window */
  98627. if(j>=testW)return(1);
  98628. ve->cursor=j;
  98629. if(ve->mark[j/ve->searchstep]){
  98630. if(j>centerW){
  98631. #if 0
  98632. if(j>ve->curmark){
  98633. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98634. int l,m;
  98635. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98636. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98637. seq,
  98638. (totalshift+ve->cursor)/44100.,
  98639. (totalshift+j)/44100.);
  98640. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98641. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98642. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98643. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98644. for(m=0;m<VE_BANDS;m++){
  98645. char buf[80];
  98646. sprintf(buf,"delL%d",m);
  98647. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98648. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98649. }
  98650. for(m=0;m<VE_BANDS;m++){
  98651. char buf[80];
  98652. sprintf(buf,"delR%d",m);
  98653. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98654. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98655. }
  98656. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98657. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98658. seq++;
  98659. }
  98660. #endif
  98661. ve->curmark=j;
  98662. if(j>=testW)return(1);
  98663. return(0);
  98664. }
  98665. }
  98666. j+=ve->searchstep;
  98667. }
  98668. }
  98669. return(-1);
  98670. }
  98671. int _ve_envelope_mark(vorbis_dsp_state *v){
  98672. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98673. vorbis_info *vi=v->vi;
  98674. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98675. long centerW=v->centerW;
  98676. long beginW=centerW-ci->blocksizes[v->W]/4;
  98677. long endW=centerW+ci->blocksizes[v->W]/4;
  98678. if(v->W){
  98679. beginW-=ci->blocksizes[v->lW]/4;
  98680. endW+=ci->blocksizes[v->nW]/4;
  98681. }else{
  98682. beginW-=ci->blocksizes[0]/4;
  98683. endW+=ci->blocksizes[0]/4;
  98684. }
  98685. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98686. {
  98687. long first=beginW/ve->searchstep;
  98688. long last=endW/ve->searchstep;
  98689. long i;
  98690. for(i=first;i<last;i++)
  98691. if(ve->mark[i])return(1);
  98692. }
  98693. return(0);
  98694. }
  98695. void _ve_envelope_shift(envelope_lookup *e,long shift){
  98696. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  98697. ahead of ve->current */
  98698. int smallshift=shift/e->searchstep;
  98699. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  98700. #if 0
  98701. for(i=0;i<VE_BANDS*e->ch;i++)
  98702. memmove(e->filter[i].markers,
  98703. e->filter[i].markers+smallshift,
  98704. (1024-smallshift)*sizeof(*(*e->filter).markers));
  98705. totalshift+=shift;
  98706. #endif
  98707. e->current-=shift;
  98708. if(e->curmark>=0)
  98709. e->curmark-=shift;
  98710. e->cursor-=shift;
  98711. }
  98712. #endif
  98713. /*** End of inlined file: envelope.c ***/
  98714. /*** Start of inlined file: floor0.c ***/
  98715. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98716. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98717. // tasks..
  98718. #if JUCE_MSVC
  98719. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98720. #endif
  98721. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98722. #if JUCE_USE_OGGVORBIS
  98723. #include <stdlib.h>
  98724. #include <string.h>
  98725. #include <math.h>
  98726. /*** Start of inlined file: lsp.h ***/
  98727. #ifndef _V_LSP_H_
  98728. #define _V_LSP_H_
  98729. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  98730. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  98731. float *lsp,int m,
  98732. float amp,float ampoffset);
  98733. #endif
  98734. /*** End of inlined file: lsp.h ***/
  98735. #include <stdio.h>
  98736. typedef struct {
  98737. int ln;
  98738. int m;
  98739. int **linearmap;
  98740. int n[2];
  98741. vorbis_info_floor0 *vi;
  98742. long bits;
  98743. long frames;
  98744. } vorbis_look_floor0;
  98745. static void floor0_free_info(vorbis_info_floor *i){
  98746. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  98747. if(info){
  98748. memset(info,0,sizeof(*info));
  98749. _ogg_free(info);
  98750. }
  98751. }
  98752. static void floor0_free_look(vorbis_look_floor *i){
  98753. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98754. if(look){
  98755. if(look->linearmap){
  98756. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  98757. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  98758. _ogg_free(look->linearmap);
  98759. }
  98760. memset(look,0,sizeof(*look));
  98761. _ogg_free(look);
  98762. }
  98763. }
  98764. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  98765. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98766. int j;
  98767. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  98768. info->order=oggpack_read(opb,8);
  98769. info->rate=oggpack_read(opb,16);
  98770. info->barkmap=oggpack_read(opb,16);
  98771. info->ampbits=oggpack_read(opb,6);
  98772. info->ampdB=oggpack_read(opb,8);
  98773. info->numbooks=oggpack_read(opb,4)+1;
  98774. if(info->order<1)goto err_out;
  98775. if(info->rate<1)goto err_out;
  98776. if(info->barkmap<1)goto err_out;
  98777. if(info->numbooks<1)goto err_out;
  98778. for(j=0;j<info->numbooks;j++){
  98779. info->books[j]=oggpack_read(opb,8);
  98780. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  98781. }
  98782. return(info);
  98783. err_out:
  98784. floor0_free_info(info);
  98785. return(NULL);
  98786. }
  98787. static void floor0_map_lazy_init(vorbis_block *vb,
  98788. vorbis_info_floor *infoX,
  98789. vorbis_look_floor0 *look){
  98790. if(!look->linearmap[vb->W]){
  98791. vorbis_dsp_state *vd=vb->vd;
  98792. vorbis_info *vi=vd->vi;
  98793. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98794. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  98795. int W=vb->W;
  98796. int n=ci->blocksizes[W]/2,j;
  98797. float scale=look->ln/toBARK(info->rate/2.f);
  98798. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  98799. for(j=0;j<n;j++){
  98800. int val=floor( toBARK((info->rate/2.f)/n*j)
  98801. *scale); /* bark numbers represent band edges */
  98802. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  98803. look->linearmap[W][j]=val;
  98804. }
  98805. look->linearmap[W][j]=-1;
  98806. look->n[W]=n;
  98807. }
  98808. }
  98809. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  98810. vorbis_info_floor *i){
  98811. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  98812. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  98813. look->m=info->order;
  98814. look->ln=info->barkmap;
  98815. look->vi=info;
  98816. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  98817. return look;
  98818. }
  98819. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  98820. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98821. vorbis_info_floor0 *info=look->vi;
  98822. int j,k;
  98823. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  98824. if(ampraw>0){ /* also handles the -1 out of data case */
  98825. long maxval=(1<<info->ampbits)-1;
  98826. float amp=(float)ampraw/maxval*info->ampdB;
  98827. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  98828. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  98829. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  98830. codebook *b=ci->fullbooks+info->books[booknum];
  98831. float last=0.f;
  98832. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  98833. for(j=0;j<look->m;j+=b->dim)
  98834. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  98835. for(j=0;j<look->m;){
  98836. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  98837. last=lsp[j-1];
  98838. }
  98839. lsp[look->m]=amp;
  98840. return(lsp);
  98841. }
  98842. }
  98843. eop:
  98844. return(NULL);
  98845. }
  98846. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  98847. void *memo,float *out){
  98848. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98849. vorbis_info_floor0 *info=look->vi;
  98850. floor0_map_lazy_init(vb,info,look);
  98851. if(memo){
  98852. float *lsp=(float *)memo;
  98853. float amp=lsp[look->m];
  98854. vorbis_lsp_to_curve(out,
  98855. look->linearmap[vb->W],
  98856. look->n[vb->W],
  98857. look->ln,
  98858. lsp,look->m,amp,(float)info->ampdB);
  98859. return(1);
  98860. }
  98861. memset(out,0,sizeof(*out)*look->n[vb->W]);
  98862. return(0);
  98863. }
  98864. vorbis_func_floor floor0_exportbundle={
  98865. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  98866. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  98867. };
  98868. #endif
  98869. /*** End of inlined file: floor0.c ***/
  98870. /*** Start of inlined file: floor1.c ***/
  98871. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98872. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98873. // tasks..
  98874. #if JUCE_MSVC
  98875. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98876. #endif
  98877. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98878. #if JUCE_USE_OGGVORBIS
  98879. #include <stdlib.h>
  98880. #include <string.h>
  98881. #include <math.h>
  98882. #include <stdio.h>
  98883. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  98884. typedef struct {
  98885. int sorted_index[VIF_POSIT+2];
  98886. int forward_index[VIF_POSIT+2];
  98887. int reverse_index[VIF_POSIT+2];
  98888. int hineighbor[VIF_POSIT];
  98889. int loneighbor[VIF_POSIT];
  98890. int posts;
  98891. int n;
  98892. int quant_q;
  98893. vorbis_info_floor1 *vi;
  98894. long phrasebits;
  98895. long postbits;
  98896. long frames;
  98897. } vorbis_look_floor1;
  98898. typedef struct lsfit_acc{
  98899. long x0;
  98900. long x1;
  98901. long xa;
  98902. long ya;
  98903. long x2a;
  98904. long y2a;
  98905. long xya;
  98906. long an;
  98907. } lsfit_acc;
  98908. static void floor1_free_info(vorbis_info_floor *i){
  98909. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  98910. if(info){
  98911. memset(info,0,sizeof(*info));
  98912. _ogg_free(info);
  98913. }
  98914. }
  98915. static void floor1_free_look(vorbis_look_floor *i){
  98916. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  98917. if(look){
  98918. memset(look,0,sizeof(*look));
  98919. _ogg_free(look);
  98920. }
  98921. }
  98922. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  98923. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  98924. int j,k;
  98925. int count=0;
  98926. int rangebits;
  98927. int maxposit=info->postlist[1];
  98928. int maxclass=-1;
  98929. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  98930. for(j=0;j<info->partitions;j++){
  98931. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  98932. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  98933. }
  98934. for(j=0;j<maxclass+1;j++){
  98935. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  98936. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  98937. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  98938. for(k=0;k<(1<<info->class_subs[j]);k++)
  98939. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  98940. }
  98941. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  98942. oggpack_write(opb,ilog2(maxposit),4);
  98943. rangebits=ilog2(maxposit);
  98944. for(j=0,k=0;j<info->partitions;j++){
  98945. count+=info->class_dim[info->partitionclass[j]];
  98946. for(;k<count;k++)
  98947. oggpack_write(opb,info->postlist[k+2],rangebits);
  98948. }
  98949. }
  98950. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  98951. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98952. int j,k,count=0,maxclass=-1,rangebits;
  98953. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  98954. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  98955. for(j=0;j<info->partitions;j++){
  98956. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  98957. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  98958. }
  98959. for(j=0;j<maxclass+1;j++){
  98960. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  98961. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  98962. if(info->class_subs[j]<0)
  98963. goto err_out;
  98964. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  98965. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  98966. goto err_out;
  98967. for(k=0;k<(1<<info->class_subs[j]);k++){
  98968. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  98969. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  98970. goto err_out;
  98971. }
  98972. }
  98973. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  98974. rangebits=oggpack_read(opb,4);
  98975. for(j=0,k=0;j<info->partitions;j++){
  98976. count+=info->class_dim[info->partitionclass[j]];
  98977. for(;k<count;k++){
  98978. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  98979. if(t<0 || t>=(1<<rangebits))
  98980. goto err_out;
  98981. }
  98982. }
  98983. info->postlist[0]=0;
  98984. info->postlist[1]=1<<rangebits;
  98985. return(info);
  98986. err_out:
  98987. floor1_free_info(info);
  98988. return(NULL);
  98989. }
  98990. static int icomp(const void *a,const void *b){
  98991. return(**(int **)a-**(int **)b);
  98992. }
  98993. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  98994. vorbis_info_floor *in){
  98995. int *sortpointer[VIF_POSIT+2];
  98996. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  98997. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  98998. int i,j,n=0;
  98999. look->vi=info;
  99000. look->n=info->postlist[1];
  99001. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99002. n+=2;
  99003. look->posts=n;
  99004. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99005. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99006. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99007. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99008. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99009. switch(info->mult){
  99010. case 1: /* 1024 -> 256 */
  99011. look->quant_q=256;
  99012. break;
  99013. case 2: /* 1024 -> 128 */
  99014. look->quant_q=128;
  99015. break;
  99016. case 3: /* 1024 -> 86 */
  99017. look->quant_q=86;
  99018. break;
  99019. case 4: /* 1024 -> 64 */
  99020. look->quant_q=64;
  99021. break;
  99022. }
  99023. for(i=0;i<n-2;i++){
  99024. int lo=0;
  99025. int hi=1;
  99026. int lx=0;
  99027. int hx=look->n;
  99028. int currentx=info->postlist[i+2];
  99029. for(j=0;j<i+2;j++){
  99030. int x=info->postlist[j];
  99031. if(x>lx && x<currentx){
  99032. lo=j;
  99033. lx=x;
  99034. }
  99035. if(x<hx && x>currentx){
  99036. hi=j;
  99037. hx=x;
  99038. }
  99039. }
  99040. look->loneighbor[i]=lo;
  99041. look->hineighbor[i]=hi;
  99042. }
  99043. return(look);
  99044. }
  99045. static int render_point(int x0,int x1,int y0,int y1,int x){
  99046. y0&=0x7fff; /* mask off flag */
  99047. y1&=0x7fff;
  99048. {
  99049. int dy=y1-y0;
  99050. int adx=x1-x0;
  99051. int ady=abs(dy);
  99052. int err=ady*(x-x0);
  99053. int off=err/adx;
  99054. if(dy<0)return(y0-off);
  99055. return(y0+off);
  99056. }
  99057. }
  99058. static int vorbis_dBquant(const float *x){
  99059. int i= *x*7.3142857f+1023.5f;
  99060. if(i>1023)return(1023);
  99061. if(i<0)return(0);
  99062. return i;
  99063. }
  99064. static float FLOOR1_fromdB_LOOKUP[256]={
  99065. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99066. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99067. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99068. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99069. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99070. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99071. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99072. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99073. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99074. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99075. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99076. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99077. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99078. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99079. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99080. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99081. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99082. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99083. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99084. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99085. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99086. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99087. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99088. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99089. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99090. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99091. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99092. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99093. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99094. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99095. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99096. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99097. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99098. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99099. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99100. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99101. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99102. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99103. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99104. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99105. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99106. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99107. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99108. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99109. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99110. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99111. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99112. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99113. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99114. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99115. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99116. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99117. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99118. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99119. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99120. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99121. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99122. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99123. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99124. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99125. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99126. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99127. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99128. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99129. };
  99130. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99131. int dy=y1-y0;
  99132. int adx=x1-x0;
  99133. int ady=abs(dy);
  99134. int base=dy/adx;
  99135. int sy=(dy<0?base-1:base+1);
  99136. int x=x0;
  99137. int y=y0;
  99138. int err=0;
  99139. ady-=abs(base*adx);
  99140. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99141. while(++x<x1){
  99142. err=err+ady;
  99143. if(err>=adx){
  99144. err-=adx;
  99145. y+=sy;
  99146. }else{
  99147. y+=base;
  99148. }
  99149. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99150. }
  99151. }
  99152. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99153. int dy=y1-y0;
  99154. int adx=x1-x0;
  99155. int ady=abs(dy);
  99156. int base=dy/adx;
  99157. int sy=(dy<0?base-1:base+1);
  99158. int x=x0;
  99159. int y=y0;
  99160. int err=0;
  99161. ady-=abs(base*adx);
  99162. d[x]=y;
  99163. while(++x<x1){
  99164. err=err+ady;
  99165. if(err>=adx){
  99166. err-=adx;
  99167. y+=sy;
  99168. }else{
  99169. y+=base;
  99170. }
  99171. d[x]=y;
  99172. }
  99173. }
  99174. static int accumulate_fit(const float *flr,const float *mdct,
  99175. int x0, int x1,lsfit_acc *a,
  99176. int n,vorbis_info_floor1 *info){
  99177. long i;
  99178. long xa=0,ya=0,x2a=0,y2a=0,xya=0,na=0, xb=0,yb=0,x2b=0,y2b=0,xyb=0,nb=0;
  99179. memset(a,0,sizeof(*a));
  99180. a->x0=x0;
  99181. a->x1=x1;
  99182. if(x1>=n)x1=n-1;
  99183. for(i=x0;i<=x1;i++){
  99184. int quantized=vorbis_dBquant(flr+i);
  99185. if(quantized){
  99186. if(mdct[i]+info->twofitatten>=flr[i]){
  99187. xa += i;
  99188. ya += quantized;
  99189. x2a += i*i;
  99190. y2a += quantized*quantized;
  99191. xya += i*quantized;
  99192. na++;
  99193. }else{
  99194. xb += i;
  99195. yb += quantized;
  99196. x2b += i*i;
  99197. y2b += quantized*quantized;
  99198. xyb += i*quantized;
  99199. nb++;
  99200. }
  99201. }
  99202. }
  99203. xb+=xa;
  99204. yb+=ya;
  99205. x2b+=x2a;
  99206. y2b+=y2a;
  99207. xyb+=xya;
  99208. nb+=na;
  99209. {
  99210. int weight=nb*info->twofitweight/(na+1);
  99211. a->xa=xa*weight+xb;
  99212. a->ya=ya*weight+yb;
  99213. a->x2a=x2a*weight+x2b;
  99214. a->y2a=y2a*weight+y2b;
  99215. a->xya=xya*weight+xyb;
  99216. a->an=na*weight+nb;
  99217. }
  99218. return(na);
  99219. }
  99220. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99221. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99222. long x0=a[0].x0;
  99223. long x1=a[fits-1].x1;
  99224. for(i=0;i<fits;i++){
  99225. x+=a[i].xa;
  99226. y+=a[i].ya;
  99227. x2+=a[i].x2a;
  99228. y2+=a[i].y2a;
  99229. xy+=a[i].xya;
  99230. an+=a[i].an;
  99231. }
  99232. if(*y0>=0){
  99233. x+= x0;
  99234. y+= *y0;
  99235. x2+= x0 * x0;
  99236. y2+= *y0 * *y0;
  99237. xy+= *y0 * x0;
  99238. an++;
  99239. }
  99240. if(*y1>=0){
  99241. x+= x1;
  99242. y+= *y1;
  99243. x2+= x1 * x1;
  99244. y2+= *y1 * *y1;
  99245. xy+= *y1 * x1;
  99246. an++;
  99247. }
  99248. if(an){
  99249. double fx=x;
  99250. double fy=y;
  99251. double fx2=x2;
  99252. double fxy=xy;
  99253. double denom=1./(an*fx2-fx*fx);
  99254. double a=(fy*fx2-fxy*fx)*denom;
  99255. double b=(an*fxy-fx*fy)*denom;
  99256. *y0=rint(a+b*x0);
  99257. *y1=rint(a+b*x1);
  99258. if(*y0>1023)*y0=1023;
  99259. if(*y1>1023)*y1=1023;
  99260. if(*y0<0)*y0=0;
  99261. if(*y1<0)*y1=0;
  99262. }else{
  99263. *y0=0;
  99264. *y1=0;
  99265. }
  99266. }
  99267. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99268. const float *mdct,
  99269. vorbis_info_floor1 *info){
  99270. int dy=y1-y0;
  99271. int adx=x1-x0;
  99272. int ady=abs(dy);
  99273. int base=dy/adx;
  99274. int sy=(dy<0?base-1:base+1);
  99275. int x=x0;
  99276. int y=y0;
  99277. int err=0;
  99278. int val=vorbis_dBquant(mask+x);
  99279. int mse=0;
  99280. int n=0;
  99281. ady-=abs(base*adx);
  99282. mse=(y-val);
  99283. mse*=mse;
  99284. n++;
  99285. if(mdct[x]+info->twofitatten>=mask[x]){
  99286. if(y+info->maxover<val)return(1);
  99287. if(y-info->maxunder>val)return(1);
  99288. }
  99289. while(++x<x1){
  99290. err=err+ady;
  99291. if(err>=adx){
  99292. err-=adx;
  99293. y+=sy;
  99294. }else{
  99295. y+=base;
  99296. }
  99297. val=vorbis_dBquant(mask+x);
  99298. mse+=((y-val)*(y-val));
  99299. n++;
  99300. if(mdct[x]+info->twofitatten>=mask[x]){
  99301. if(val){
  99302. if(y+info->maxover<val)return(1);
  99303. if(y-info->maxunder>val)return(1);
  99304. }
  99305. }
  99306. }
  99307. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99308. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99309. if(mse/n>info->maxerr)return(1);
  99310. return(0);
  99311. }
  99312. static int post_Y(int *A,int *B,int pos){
  99313. if(A[pos]<0)
  99314. return B[pos];
  99315. if(B[pos]<0)
  99316. return A[pos];
  99317. return (A[pos]+B[pos])>>1;
  99318. }
  99319. int *floor1_fit(vorbis_block *vb,void *look_,
  99320. const float *logmdct, /* in */
  99321. const float *logmask){
  99322. long i,j;
  99323. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99324. vorbis_info_floor1 *info=look->vi;
  99325. long n=look->n;
  99326. long posts=look->posts;
  99327. long nonzero=0;
  99328. lsfit_acc fits[VIF_POSIT+1];
  99329. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99330. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99331. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99332. int hineighbor[VIF_POSIT+2];
  99333. int *output=NULL;
  99334. int memo[VIF_POSIT+2];
  99335. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99336. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99337. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99338. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99339. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99340. if(posts==0){
  99341. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99342. }else{
  99343. for(i=0;i<posts-1;i++)
  99344. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99345. look->sorted_index[i+1],fits+i,
  99346. n,info);
  99347. }
  99348. if(nonzero){
  99349. int y0=-200;
  99350. int y1=-200;
  99351. fit_line(fits,posts-1,&y0,&y1);
  99352. fit_valueA[0]=y0;
  99353. fit_valueB[0]=y0;
  99354. fit_valueB[1]=y1;
  99355. fit_valueA[1]=y1;
  99356. for(i=2;i<posts;i++){
  99357. int sortpos=look->reverse_index[i];
  99358. int ln=loneighbor[sortpos];
  99359. int hn=hineighbor[sortpos];
  99360. if(memo[ln]!=hn){
  99361. int lsortpos=look->reverse_index[ln];
  99362. int hsortpos=look->reverse_index[hn];
  99363. memo[ln]=hn;
  99364. {
  99365. int lx=info->postlist[ln];
  99366. int hx=info->postlist[hn];
  99367. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99368. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99369. if(ly==-1 || hy==-1){
  99370. exit(1);
  99371. }
  99372. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99373. int ly0=-200;
  99374. int ly1=-200;
  99375. int hy0=-200;
  99376. int hy1=-200;
  99377. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99378. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99379. fit_valueB[ln]=ly0;
  99380. if(ln==0)fit_valueA[ln]=ly0;
  99381. fit_valueA[i]=ly1;
  99382. fit_valueB[i]=hy0;
  99383. fit_valueA[hn]=hy1;
  99384. if(hn==1)fit_valueB[hn]=hy1;
  99385. if(ly1>=0 || hy0>=0){
  99386. for(j=sortpos-1;j>=0;j--)
  99387. if(hineighbor[j]==hn)
  99388. hineighbor[j]=i;
  99389. else
  99390. break;
  99391. for(j=sortpos+1;j<posts;j++)
  99392. if(loneighbor[j]==ln)
  99393. loneighbor[j]=i;
  99394. else
  99395. break;
  99396. }
  99397. }else{
  99398. fit_valueA[i]=-200;
  99399. fit_valueB[i]=-200;
  99400. }
  99401. }
  99402. }
  99403. }
  99404. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99405. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99406. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99407. for(i=2;i<posts;i++){
  99408. int ln=look->loneighbor[i-2];
  99409. int hn=look->hineighbor[i-2];
  99410. int x0=info->postlist[ln];
  99411. int x1=info->postlist[hn];
  99412. int y0=output[ln];
  99413. int y1=output[hn];
  99414. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99415. int vx=post_Y(fit_valueA,fit_valueB,i);
  99416. if(vx>=0 && predicted!=vx){
  99417. output[i]=vx;
  99418. }else{
  99419. output[i]= predicted|0x8000;
  99420. }
  99421. }
  99422. }
  99423. return(output);
  99424. }
  99425. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99426. int *A,int *B,
  99427. int del){
  99428. long i;
  99429. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99430. long posts=look->posts;
  99431. int *output=NULL;
  99432. if(A && B){
  99433. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99434. for(i=0;i<posts;i++){
  99435. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99436. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99437. }
  99438. }
  99439. return(output);
  99440. }
  99441. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99442. void*look_,
  99443. int *post,int *ilogmask){
  99444. long i,j;
  99445. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99446. vorbis_info_floor1 *info=look->vi;
  99447. long posts=look->posts;
  99448. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99449. int out[VIF_POSIT+2];
  99450. static_codebook **sbooks=ci->book_param;
  99451. codebook *books=ci->fullbooks;
  99452. static long seq=0;
  99453. if(post){
  99454. for(i=0;i<posts;i++){
  99455. int val=post[i]&0x7fff;
  99456. switch(info->mult){
  99457. case 1: /* 1024 -> 256 */
  99458. val>>=2;
  99459. break;
  99460. case 2: /* 1024 -> 128 */
  99461. val>>=3;
  99462. break;
  99463. case 3: /* 1024 -> 86 */
  99464. val/=12;
  99465. break;
  99466. case 4: /* 1024 -> 64 */
  99467. val>>=4;
  99468. break;
  99469. }
  99470. post[i]=val | (post[i]&0x8000);
  99471. }
  99472. out[0]=post[0];
  99473. out[1]=post[1];
  99474. for(i=2;i<posts;i++){
  99475. int ln=look->loneighbor[i-2];
  99476. int hn=look->hineighbor[i-2];
  99477. int x0=info->postlist[ln];
  99478. int x1=info->postlist[hn];
  99479. int y0=post[ln];
  99480. int y1=post[hn];
  99481. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99482. if((post[i]&0x8000) || (predicted==post[i])){
  99483. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99484. in interpolation */
  99485. out[i]=0;
  99486. }else{
  99487. int headroom=(look->quant_q-predicted<predicted?
  99488. look->quant_q-predicted:predicted);
  99489. int val=post[i]-predicted;
  99490. if(val<0)
  99491. if(val<-headroom)
  99492. val=headroom-val-1;
  99493. else
  99494. val=-1-(val<<1);
  99495. else
  99496. if(val>=headroom)
  99497. val= val+headroom;
  99498. else
  99499. val<<=1;
  99500. out[i]=val;
  99501. post[ln]&=0x7fff;
  99502. post[hn]&=0x7fff;
  99503. }
  99504. }
  99505. oggpack_write(opb,1,1);
  99506. look->frames++;
  99507. look->postbits+=ilog(look->quant_q-1)*2;
  99508. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99509. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99510. for(i=0,j=2;i<info->partitions;i++){
  99511. int classx=info->partitionclass[i];
  99512. int cdim=info->class_dim[classx];
  99513. int csubbits=info->class_subs[classx];
  99514. int csub=1<<csubbits;
  99515. int bookas[8]={0,0,0,0,0,0,0,0};
  99516. int cval=0;
  99517. int cshift=0;
  99518. int k,l;
  99519. if(csubbits){
  99520. int maxval[8];
  99521. for(k=0;k<csub;k++){
  99522. int booknum=info->class_subbook[classx][k];
  99523. if(booknum<0){
  99524. maxval[k]=1;
  99525. }else{
  99526. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99527. }
  99528. }
  99529. for(k=0;k<cdim;k++){
  99530. for(l=0;l<csub;l++){
  99531. int val=out[j+k];
  99532. if(val<maxval[l]){
  99533. bookas[k]=l;
  99534. break;
  99535. }
  99536. }
  99537. cval|= bookas[k]<<cshift;
  99538. cshift+=csubbits;
  99539. }
  99540. look->phrasebits+=
  99541. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99542. #ifdef TRAIN_FLOOR1
  99543. {
  99544. FILE *of;
  99545. char buffer[80];
  99546. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99547. vb->pcmend/2,posts-2,class);
  99548. of=fopen(buffer,"a");
  99549. fprintf(of,"%d\n",cval);
  99550. fclose(of);
  99551. }
  99552. #endif
  99553. }
  99554. for(k=0;k<cdim;k++){
  99555. int book=info->class_subbook[classx][bookas[k]];
  99556. if(book>=0){
  99557. if(out[j+k]<(books+book)->entries)
  99558. look->postbits+=vorbis_book_encode(books+book,
  99559. out[j+k],opb);
  99560. #ifdef TRAIN_FLOOR1
  99561. {
  99562. FILE *of;
  99563. char buffer[80];
  99564. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99565. vb->pcmend/2,posts-2,class,bookas[k]);
  99566. of=fopen(buffer,"a");
  99567. fprintf(of,"%d\n",out[j+k]);
  99568. fclose(of);
  99569. }
  99570. #endif
  99571. }
  99572. }
  99573. j+=cdim;
  99574. }
  99575. {
  99576. int hx=0;
  99577. int lx=0;
  99578. int ly=post[0]*info->mult;
  99579. for(j=1;j<look->posts;j++){
  99580. int current=look->forward_index[j];
  99581. int hy=post[current]&0x7fff;
  99582. if(hy==post[current]){
  99583. hy*=info->mult;
  99584. hx=info->postlist[current];
  99585. render_line0(lx,hx,ly,hy,ilogmask);
  99586. lx=hx;
  99587. ly=hy;
  99588. }
  99589. }
  99590. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99591. seq++;
  99592. return(1);
  99593. }
  99594. }else{
  99595. oggpack_write(opb,0,1);
  99596. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99597. seq++;
  99598. return(0);
  99599. }
  99600. }
  99601. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99602. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99603. vorbis_info_floor1 *info=look->vi;
  99604. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99605. int i,j,k;
  99606. codebook *books=ci->fullbooks;
  99607. if(oggpack_read(&vb->opb,1)==1){
  99608. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99609. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99610. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99611. for(i=0,j=2;i<info->partitions;i++){
  99612. int classx=info->partitionclass[i];
  99613. int cdim=info->class_dim[classx];
  99614. int csubbits=info->class_subs[classx];
  99615. int csub=1<<csubbits;
  99616. int cval=0;
  99617. if(csubbits){
  99618. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99619. if(cval==-1)goto eop;
  99620. }
  99621. for(k=0;k<cdim;k++){
  99622. int book=info->class_subbook[classx][cval&(csub-1)];
  99623. cval>>=csubbits;
  99624. if(book>=0){
  99625. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99626. goto eop;
  99627. }else{
  99628. fit_value[j+k]=0;
  99629. }
  99630. }
  99631. j+=cdim;
  99632. }
  99633. for(i=2;i<look->posts;i++){
  99634. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99635. info->postlist[look->hineighbor[i-2]],
  99636. fit_value[look->loneighbor[i-2]],
  99637. fit_value[look->hineighbor[i-2]],
  99638. info->postlist[i]);
  99639. int hiroom=look->quant_q-predicted;
  99640. int loroom=predicted;
  99641. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99642. int val=fit_value[i];
  99643. if(val){
  99644. if(val>=room){
  99645. if(hiroom>loroom){
  99646. val = val-loroom;
  99647. }else{
  99648. val = -1-(val-hiroom);
  99649. }
  99650. }else{
  99651. if(val&1){
  99652. val= -((val+1)>>1);
  99653. }else{
  99654. val>>=1;
  99655. }
  99656. }
  99657. fit_value[i]=val+predicted;
  99658. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99659. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99660. }else{
  99661. fit_value[i]=predicted|0x8000;
  99662. }
  99663. }
  99664. return(fit_value);
  99665. }
  99666. eop:
  99667. return(NULL);
  99668. }
  99669. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99670. float *out){
  99671. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99672. vorbis_info_floor1 *info=look->vi;
  99673. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99674. int n=ci->blocksizes[vb->W]/2;
  99675. int j;
  99676. if(memo){
  99677. int *fit_value=(int *)memo;
  99678. int hx=0;
  99679. int lx=0;
  99680. int ly=fit_value[0]*info->mult;
  99681. for(j=1;j<look->posts;j++){
  99682. int current=look->forward_index[j];
  99683. int hy=fit_value[current]&0x7fff;
  99684. if(hy==fit_value[current]){
  99685. hy*=info->mult;
  99686. hx=info->postlist[current];
  99687. render_line(lx,hx,ly,hy,out);
  99688. lx=hx;
  99689. ly=hy;
  99690. }
  99691. }
  99692. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  99693. return(1);
  99694. }
  99695. memset(out,0,sizeof(*out)*n);
  99696. return(0);
  99697. }
  99698. vorbis_func_floor floor1_exportbundle={
  99699. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  99700. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  99701. };
  99702. #endif
  99703. /*** End of inlined file: floor1.c ***/
  99704. /*** Start of inlined file: info.c ***/
  99705. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99706. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99707. // tasks..
  99708. #if JUCE_MSVC
  99709. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99710. #endif
  99711. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99712. #if JUCE_USE_OGGVORBIS
  99713. #include <stdlib.h>
  99714. #include <string.h>
  99715. #include <ctype.h>
  99716. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  99717. while(bytes--){
  99718. oggpack_write(o,*s++,8);
  99719. }
  99720. }
  99721. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  99722. while(bytes--){
  99723. *buf++=oggpack_read(o,8);
  99724. }
  99725. }
  99726. void vorbis_comment_init(vorbis_comment *vc){
  99727. memset(vc,0,sizeof(*vc));
  99728. }
  99729. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  99730. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  99731. (vc->comments+2)*sizeof(*vc->user_comments));
  99732. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  99733. (vc->comments+2)*sizeof(*vc->comment_lengths));
  99734. vc->comment_lengths[vc->comments]=strlen(comment);
  99735. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  99736. strcpy(vc->user_comments[vc->comments], comment);
  99737. vc->comments++;
  99738. vc->user_comments[vc->comments]=NULL;
  99739. }
  99740. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  99741. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  99742. strcpy(comment, tag);
  99743. strcat(comment, "=");
  99744. strcat(comment, contents);
  99745. vorbis_comment_add(vc, comment);
  99746. }
  99747. static int tagcompare(const char *s1, const char *s2, int n){
  99748. int c=0;
  99749. while(c < n){
  99750. if(toupper(s1[c]) != toupper(s2[c]))
  99751. return !0;
  99752. c++;
  99753. }
  99754. return 0;
  99755. }
  99756. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  99757. long i;
  99758. int found = 0;
  99759. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99760. char *fulltag = (char*)alloca(taglen+ 1);
  99761. strcpy(fulltag, tag);
  99762. strcat(fulltag, "=");
  99763. for(i=0;i<vc->comments;i++){
  99764. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  99765. if(count == found)
  99766. return vc->user_comments[i] + taglen;
  99767. else
  99768. found++;
  99769. }
  99770. }
  99771. return NULL; /* didn't find anything */
  99772. }
  99773. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  99774. int i,count=0;
  99775. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99776. char *fulltag = (char*)alloca(taglen+1);
  99777. strcpy(fulltag,tag);
  99778. strcat(fulltag, "=");
  99779. for(i=0;i<vc->comments;i++){
  99780. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  99781. count++;
  99782. }
  99783. return count;
  99784. }
  99785. void vorbis_comment_clear(vorbis_comment *vc){
  99786. if(vc){
  99787. long i;
  99788. for(i=0;i<vc->comments;i++)
  99789. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  99790. if(vc->user_comments)_ogg_free(vc->user_comments);
  99791. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  99792. if(vc->vendor)_ogg_free(vc->vendor);
  99793. }
  99794. memset(vc,0,sizeof(*vc));
  99795. }
  99796. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  99797. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  99798. return ci ? ci->blocksizes[zo] : -1;
  99799. }
  99800. void vorbis_info_init(vorbis_info *vi){
  99801. memset(vi,0,sizeof(*vi));
  99802. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  99803. }
  99804. void vorbis_info_clear(vorbis_info *vi){
  99805. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99806. int i;
  99807. if(ci){
  99808. for(i=0;i<ci->modes;i++)
  99809. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  99810. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  99811. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  99812. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  99813. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  99814. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  99815. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  99816. for(i=0;i<ci->books;i++){
  99817. if(ci->book_param[i]){
  99818. vorbis_staticbook_destroy(ci->book_param[i]);
  99819. }
  99820. if(ci->fullbooks)
  99821. vorbis_book_clear(ci->fullbooks+i);
  99822. }
  99823. if(ci->fullbooks)
  99824. _ogg_free(ci->fullbooks);
  99825. for(i=0;i<ci->psys;i++)
  99826. _vi_psy_free(ci->psy_param[i]);
  99827. _ogg_free(ci);
  99828. }
  99829. memset(vi,0,sizeof(*vi));
  99830. }
  99831. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  99832. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99833. if(!ci)return(OV_EFAULT);
  99834. vi->version=oggpack_read(opb,32);
  99835. if(vi->version!=0)return(OV_EVERSION);
  99836. vi->channels=oggpack_read(opb,8);
  99837. vi->rate=oggpack_read(opb,32);
  99838. vi->bitrate_upper=oggpack_read(opb,32);
  99839. vi->bitrate_nominal=oggpack_read(opb,32);
  99840. vi->bitrate_lower=oggpack_read(opb,32);
  99841. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  99842. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  99843. if(vi->rate<1)goto err_out;
  99844. if(vi->channels<1)goto err_out;
  99845. if(ci->blocksizes[0]<8)goto err_out;
  99846. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  99847. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  99848. return(0);
  99849. err_out:
  99850. vorbis_info_clear(vi);
  99851. return(OV_EBADHEADER);
  99852. }
  99853. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  99854. int i;
  99855. int vendorlen=oggpack_read(opb,32);
  99856. if(vendorlen<0)goto err_out;
  99857. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  99858. _v_readstring(opb,vc->vendor,vendorlen);
  99859. vc->comments=oggpack_read(opb,32);
  99860. if(vc->comments<0)goto err_out;
  99861. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  99862. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  99863. for(i=0;i<vc->comments;i++){
  99864. int len=oggpack_read(opb,32);
  99865. if(len<0)goto err_out;
  99866. vc->comment_lengths[i]=len;
  99867. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  99868. _v_readstring(opb,vc->user_comments[i],len);
  99869. }
  99870. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  99871. return(0);
  99872. err_out:
  99873. vorbis_comment_clear(vc);
  99874. return(OV_EBADHEADER);
  99875. }
  99876. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  99877. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99878. int i;
  99879. if(!ci)return(OV_EFAULT);
  99880. ci->books=oggpack_read(opb,8)+1;
  99881. for(i=0;i<ci->books;i++){
  99882. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  99883. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  99884. }
  99885. {
  99886. int times=oggpack_read(opb,6)+1;
  99887. for(i=0;i<times;i++){
  99888. int test=oggpack_read(opb,16);
  99889. if(test<0 || test>=VI_TIMEB)goto err_out;
  99890. }
  99891. }
  99892. ci->floors=oggpack_read(opb,6)+1;
  99893. for(i=0;i<ci->floors;i++){
  99894. ci->floor_type[i]=oggpack_read(opb,16);
  99895. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  99896. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  99897. if(!ci->floor_param[i])goto err_out;
  99898. }
  99899. ci->residues=oggpack_read(opb,6)+1;
  99900. for(i=0;i<ci->residues;i++){
  99901. ci->residue_type[i]=oggpack_read(opb,16);
  99902. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  99903. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  99904. if(!ci->residue_param[i])goto err_out;
  99905. }
  99906. ci->maps=oggpack_read(opb,6)+1;
  99907. for(i=0;i<ci->maps;i++){
  99908. ci->map_type[i]=oggpack_read(opb,16);
  99909. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  99910. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  99911. if(!ci->map_param[i])goto err_out;
  99912. }
  99913. ci->modes=oggpack_read(opb,6)+1;
  99914. for(i=0;i<ci->modes;i++){
  99915. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  99916. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  99917. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  99918. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  99919. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  99920. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  99921. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  99922. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  99923. }
  99924. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  99925. return(0);
  99926. err_out:
  99927. vorbis_info_clear(vi);
  99928. return(OV_EBADHEADER);
  99929. }
  99930. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  99931. oggpack_buffer opb;
  99932. if(op){
  99933. oggpack_readinit(&opb,op->packet,op->bytes);
  99934. {
  99935. char buffer[6];
  99936. int packtype=oggpack_read(&opb,8);
  99937. memset(buffer,0,6);
  99938. _v_readstring(&opb,buffer,6);
  99939. if(memcmp(buffer,"vorbis",6)){
  99940. return(OV_ENOTVORBIS);
  99941. }
  99942. switch(packtype){
  99943. case 0x01: /* least significant *bit* is read first */
  99944. if(!op->b_o_s){
  99945. return(OV_EBADHEADER);
  99946. }
  99947. if(vi->rate!=0){
  99948. return(OV_EBADHEADER);
  99949. }
  99950. return(_vorbis_unpack_info(vi,&opb));
  99951. case 0x03: /* least significant *bit* is read first */
  99952. if(vi->rate==0){
  99953. return(OV_EBADHEADER);
  99954. }
  99955. return(_vorbis_unpack_comment(vc,&opb));
  99956. case 0x05: /* least significant *bit* is read first */
  99957. if(vi->rate==0 || vc->vendor==NULL){
  99958. return(OV_EBADHEADER);
  99959. }
  99960. return(_vorbis_unpack_books(vi,&opb));
  99961. default:
  99962. return(OV_EBADHEADER);
  99963. break;
  99964. }
  99965. }
  99966. }
  99967. return(OV_EBADHEADER);
  99968. }
  99969. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  99970. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99971. if(!ci)return(OV_EFAULT);
  99972. oggpack_write(opb,0x01,8);
  99973. _v_writestring(opb,"vorbis", 6);
  99974. oggpack_write(opb,0x00,32);
  99975. oggpack_write(opb,vi->channels,8);
  99976. oggpack_write(opb,vi->rate,32);
  99977. oggpack_write(opb,vi->bitrate_upper,32);
  99978. oggpack_write(opb,vi->bitrate_nominal,32);
  99979. oggpack_write(opb,vi->bitrate_lower,32);
  99980. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  99981. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  99982. oggpack_write(opb,1,1);
  99983. return(0);
  99984. }
  99985. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  99986. char temp[]="Xiph.Org libVorbis I 20050304";
  99987. int bytes = strlen(temp);
  99988. oggpack_write(opb,0x03,8);
  99989. _v_writestring(opb,"vorbis", 6);
  99990. oggpack_write(opb,bytes,32);
  99991. _v_writestring(opb,temp, bytes);
  99992. oggpack_write(opb,vc->comments,32);
  99993. if(vc->comments){
  99994. int i;
  99995. for(i=0;i<vc->comments;i++){
  99996. if(vc->user_comments[i]){
  99997. oggpack_write(opb,vc->comment_lengths[i],32);
  99998. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  99999. }else{
  100000. oggpack_write(opb,0,32);
  100001. }
  100002. }
  100003. }
  100004. oggpack_write(opb,1,1);
  100005. return(0);
  100006. }
  100007. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100008. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100009. int i;
  100010. if(!ci)return(OV_EFAULT);
  100011. oggpack_write(opb,0x05,8);
  100012. _v_writestring(opb,"vorbis", 6);
  100013. oggpack_write(opb,ci->books-1,8);
  100014. for(i=0;i<ci->books;i++)
  100015. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100016. oggpack_write(opb,0,6);
  100017. oggpack_write(opb,0,16);
  100018. oggpack_write(opb,ci->floors-1,6);
  100019. for(i=0;i<ci->floors;i++){
  100020. oggpack_write(opb,ci->floor_type[i],16);
  100021. if(_floor_P[ci->floor_type[i]]->pack)
  100022. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100023. else
  100024. goto err_out;
  100025. }
  100026. oggpack_write(opb,ci->residues-1,6);
  100027. for(i=0;i<ci->residues;i++){
  100028. oggpack_write(opb,ci->residue_type[i],16);
  100029. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100030. }
  100031. oggpack_write(opb,ci->maps-1,6);
  100032. for(i=0;i<ci->maps;i++){
  100033. oggpack_write(opb,ci->map_type[i],16);
  100034. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100035. }
  100036. oggpack_write(opb,ci->modes-1,6);
  100037. for(i=0;i<ci->modes;i++){
  100038. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100039. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100040. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100041. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100042. }
  100043. oggpack_write(opb,1,1);
  100044. return(0);
  100045. err_out:
  100046. return(-1);
  100047. }
  100048. int vorbis_commentheader_out(vorbis_comment *vc,
  100049. ogg_packet *op){
  100050. oggpack_buffer opb;
  100051. oggpack_writeinit(&opb);
  100052. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100053. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100054. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100055. op->bytes=oggpack_bytes(&opb);
  100056. op->b_o_s=0;
  100057. op->e_o_s=0;
  100058. op->granulepos=0;
  100059. op->packetno=1;
  100060. return 0;
  100061. }
  100062. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100063. vorbis_comment *vc,
  100064. ogg_packet *op,
  100065. ogg_packet *op_comm,
  100066. ogg_packet *op_code){
  100067. int ret=OV_EIMPL;
  100068. vorbis_info *vi=v->vi;
  100069. oggpack_buffer opb;
  100070. private_state *b=(private_state*)v->backend_state;
  100071. if(!b){
  100072. ret=OV_EFAULT;
  100073. goto err_out;
  100074. }
  100075. oggpack_writeinit(&opb);
  100076. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100077. if(b->header)_ogg_free(b->header);
  100078. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100079. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100080. op->packet=b->header;
  100081. op->bytes=oggpack_bytes(&opb);
  100082. op->b_o_s=1;
  100083. op->e_o_s=0;
  100084. op->granulepos=0;
  100085. op->packetno=0;
  100086. oggpack_reset(&opb);
  100087. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100088. if(b->header1)_ogg_free(b->header1);
  100089. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100090. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100091. op_comm->packet=b->header1;
  100092. op_comm->bytes=oggpack_bytes(&opb);
  100093. op_comm->b_o_s=0;
  100094. op_comm->e_o_s=0;
  100095. op_comm->granulepos=0;
  100096. op_comm->packetno=1;
  100097. oggpack_reset(&opb);
  100098. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100099. if(b->header2)_ogg_free(b->header2);
  100100. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100101. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100102. op_code->packet=b->header2;
  100103. op_code->bytes=oggpack_bytes(&opb);
  100104. op_code->b_o_s=0;
  100105. op_code->e_o_s=0;
  100106. op_code->granulepos=0;
  100107. op_code->packetno=2;
  100108. oggpack_writeclear(&opb);
  100109. return(0);
  100110. err_out:
  100111. oggpack_writeclear(&opb);
  100112. memset(op,0,sizeof(*op));
  100113. memset(op_comm,0,sizeof(*op_comm));
  100114. memset(op_code,0,sizeof(*op_code));
  100115. if(b->header)_ogg_free(b->header);
  100116. if(b->header1)_ogg_free(b->header1);
  100117. if(b->header2)_ogg_free(b->header2);
  100118. b->header=NULL;
  100119. b->header1=NULL;
  100120. b->header2=NULL;
  100121. return(ret);
  100122. }
  100123. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100124. if(granulepos>=0)
  100125. return((double)granulepos/v->vi->rate);
  100126. return(-1);
  100127. }
  100128. #endif
  100129. /*** End of inlined file: info.c ***/
  100130. /*** Start of inlined file: lpc.c ***/
  100131. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100132. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100133. // tasks..
  100134. #if JUCE_MSVC
  100135. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100136. #endif
  100137. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100138. #if JUCE_USE_OGGVORBIS
  100139. #include <stdlib.h>
  100140. #include <string.h>
  100141. #include <math.h>
  100142. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100143. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100144. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100145. double error;
  100146. int i,j;
  100147. j=m+1;
  100148. while(j--){
  100149. double d=0; /* double needed for accumulator depth */
  100150. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100151. aut[j]=d;
  100152. }
  100153. error=aut[0];
  100154. for(i=0;i<m;i++){
  100155. double r= -aut[i+1];
  100156. if(error==0){
  100157. memset(lpci,0,m*sizeof(*lpci));
  100158. return 0;
  100159. }
  100160. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100161. r/=error;
  100162. lpc[i]=r;
  100163. for(j=0;j<i/2;j++){
  100164. double tmp=lpc[j];
  100165. lpc[j]+=r*lpc[i-1-j];
  100166. lpc[i-1-j]+=r*tmp;
  100167. }
  100168. if(i%2)lpc[j]+=lpc[j]*r;
  100169. error*=1.f-r*r;
  100170. }
  100171. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100172. return error;
  100173. }
  100174. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100175. float *data,long n){
  100176. long i,j,o,p;
  100177. float y;
  100178. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100179. if(!prime)
  100180. for(i=0;i<m;i++)
  100181. work[i]=0.f;
  100182. else
  100183. for(i=0;i<m;i++)
  100184. work[i]=prime[i];
  100185. for(i=0;i<n;i++){
  100186. y=0;
  100187. o=i;
  100188. p=m;
  100189. for(j=0;j<m;j++)
  100190. y-=work[o++]*coeff[--p];
  100191. data[i]=work[o]=y;
  100192. }
  100193. }
  100194. #endif
  100195. /*** End of inlined file: lpc.c ***/
  100196. /*** Start of inlined file: lsp.c ***/
  100197. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100198. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100199. // tasks..
  100200. #if JUCE_MSVC
  100201. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100202. #endif
  100203. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100204. #if JUCE_USE_OGGVORBIS
  100205. #include <math.h>
  100206. #include <string.h>
  100207. #include <stdlib.h>
  100208. /*** Start of inlined file: lookup.h ***/
  100209. #ifndef _V_LOOKUP_H_
  100210. #ifdef FLOAT_LOOKUP
  100211. extern float vorbis_coslook(float a);
  100212. extern float vorbis_invsqlook(float a);
  100213. extern float vorbis_invsq2explook(int a);
  100214. extern float vorbis_fromdBlook(float a);
  100215. #endif
  100216. #ifdef INT_LOOKUP
  100217. extern long vorbis_invsqlook_i(long a,long e);
  100218. extern long vorbis_coslook_i(long a);
  100219. extern float vorbis_fromdBlook_i(long a);
  100220. #endif
  100221. #endif
  100222. /*** End of inlined file: lookup.h ***/
  100223. #define FLOAT_LOOKUP
  100224. #undef INT_LOOKUP
  100225. #ifdef FLOAT_LOOKUP
  100226. /*** Start of inlined file: lookup.c ***/
  100227. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100228. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100229. // tasks..
  100230. #if JUCE_MSVC
  100231. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100232. #endif
  100233. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100234. #if JUCE_USE_OGGVORBIS
  100235. #include <math.h>
  100236. /*** Start of inlined file: lookup.h ***/
  100237. #ifndef _V_LOOKUP_H_
  100238. #ifdef FLOAT_LOOKUP
  100239. extern float vorbis_coslook(float a);
  100240. extern float vorbis_invsqlook(float a);
  100241. extern float vorbis_invsq2explook(int a);
  100242. extern float vorbis_fromdBlook(float a);
  100243. #endif
  100244. #ifdef INT_LOOKUP
  100245. extern long vorbis_invsqlook_i(long a,long e);
  100246. extern long vorbis_coslook_i(long a);
  100247. extern float vorbis_fromdBlook_i(long a);
  100248. #endif
  100249. #endif
  100250. /*** End of inlined file: lookup.h ***/
  100251. /*** Start of inlined file: lookup_data.h ***/
  100252. #ifndef _V_LOOKUP_DATA_H_
  100253. #ifdef FLOAT_LOOKUP
  100254. #define COS_LOOKUP_SZ 128
  100255. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100256. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100257. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100258. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100259. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100260. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100261. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100262. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100263. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100264. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100265. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100266. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100267. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100268. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100269. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100270. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100271. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100272. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100273. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100274. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100275. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100276. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100277. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100278. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100279. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100280. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100281. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100282. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100283. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100284. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100285. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100286. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100287. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100288. -1.0000000000000f,
  100289. };
  100290. #define INVSQ_LOOKUP_SZ 32
  100291. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100292. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100293. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100294. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100295. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100296. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100297. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100298. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100299. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100300. 1.000000000000f,
  100301. };
  100302. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100303. #define INVSQ2EXP_LOOKUP_MAX 32
  100304. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100305. INVSQ2EXP_LOOKUP_MIN+1]={
  100306. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100307. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100308. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100309. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100310. 256.f, 181.019336f, 128.f, 90.50966799f,
  100311. 64.f, 45.254834f, 32.f, 22.627417f,
  100312. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100313. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100314. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100315. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100316. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100317. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100318. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100319. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100320. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100321. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100322. 1.525878906e-05f,
  100323. };
  100324. #endif
  100325. #define FROMdB_LOOKUP_SZ 35
  100326. #define FROMdB2_LOOKUP_SZ 32
  100327. #define FROMdB_SHIFT 5
  100328. #define FROMdB2_SHIFT 3
  100329. #define FROMdB2_MASK 31
  100330. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100331. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100332. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100333. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100334. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100335. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100336. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100337. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100338. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100339. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100340. };
  100341. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100342. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100343. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100344. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100345. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100346. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100347. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100348. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100349. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100350. };
  100351. #ifdef INT_LOOKUP
  100352. #define INVSQ_LOOKUP_I_SHIFT 10
  100353. #define INVSQ_LOOKUP_I_MASK 1023
  100354. static long INVSQ_LOOKUP_I[64+1]={
  100355. 92682l, 91966l, 91267l, 90583l,
  100356. 89915l, 89261l, 88621l, 87995l,
  100357. 87381l, 86781l, 86192l, 85616l,
  100358. 85051l, 84497l, 83953l, 83420l,
  100359. 82897l, 82384l, 81880l, 81385l,
  100360. 80899l, 80422l, 79953l, 79492l,
  100361. 79039l, 78594l, 78156l, 77726l,
  100362. 77302l, 76885l, 76475l, 76072l,
  100363. 75674l, 75283l, 74898l, 74519l,
  100364. 74146l, 73778l, 73415l, 73058l,
  100365. 72706l, 72359l, 72016l, 71679l,
  100366. 71347l, 71019l, 70695l, 70376l,
  100367. 70061l, 69750l, 69444l, 69141l,
  100368. 68842l, 68548l, 68256l, 67969l,
  100369. 67685l, 67405l, 67128l, 66855l,
  100370. 66585l, 66318l, 66054l, 65794l,
  100371. 65536l,
  100372. };
  100373. #define COS_LOOKUP_I_SHIFT 9
  100374. #define COS_LOOKUP_I_MASK 511
  100375. #define COS_LOOKUP_I_SZ 128
  100376. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100377. 16384l, 16379l, 16364l, 16340l,
  100378. 16305l, 16261l, 16207l, 16143l,
  100379. 16069l, 15986l, 15893l, 15791l,
  100380. 15679l, 15557l, 15426l, 15286l,
  100381. 15137l, 14978l, 14811l, 14635l,
  100382. 14449l, 14256l, 14053l, 13842l,
  100383. 13623l, 13395l, 13160l, 12916l,
  100384. 12665l, 12406l, 12140l, 11866l,
  100385. 11585l, 11297l, 11003l, 10702l,
  100386. 10394l, 10080l, 9760l, 9434l,
  100387. 9102l, 8765l, 8423l, 8076l,
  100388. 7723l, 7366l, 7005l, 6639l,
  100389. 6270l, 5897l, 5520l, 5139l,
  100390. 4756l, 4370l, 3981l, 3590l,
  100391. 3196l, 2801l, 2404l, 2006l,
  100392. 1606l, 1205l, 804l, 402l,
  100393. 0l, -401l, -803l, -1204l,
  100394. -1605l, -2005l, -2403l, -2800l,
  100395. -3195l, -3589l, -3980l, -4369l,
  100396. -4755l, -5138l, -5519l, -5896l,
  100397. -6269l, -6638l, -7004l, -7365l,
  100398. -7722l, -8075l, -8422l, -8764l,
  100399. -9101l, -9433l, -9759l, -10079l,
  100400. -10393l, -10701l, -11002l, -11296l,
  100401. -11584l, -11865l, -12139l, -12405l,
  100402. -12664l, -12915l, -13159l, -13394l,
  100403. -13622l, -13841l, -14052l, -14255l,
  100404. -14448l, -14634l, -14810l, -14977l,
  100405. -15136l, -15285l, -15425l, -15556l,
  100406. -15678l, -15790l, -15892l, -15985l,
  100407. -16068l, -16142l, -16206l, -16260l,
  100408. -16304l, -16339l, -16363l, -16378l,
  100409. -16383l,
  100410. };
  100411. #endif
  100412. #endif
  100413. /*** End of inlined file: lookup_data.h ***/
  100414. #ifdef FLOAT_LOOKUP
  100415. float vorbis_coslook(float a){
  100416. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100417. int i=vorbis_ftoi(d-.5);
  100418. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100419. }
  100420. float vorbis_invsqlook(float a){
  100421. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100422. int i=vorbis_ftoi(d-.5f);
  100423. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100424. }
  100425. float vorbis_invsq2explook(int a){
  100426. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100427. }
  100428. #include <stdio.h>
  100429. float vorbis_fromdBlook(float a){
  100430. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100431. return (i<0)?1.f:
  100432. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100433. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100434. }
  100435. #endif
  100436. #ifdef INT_LOOKUP
  100437. long vorbis_invsqlook_i(long a,long e){
  100438. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100439. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100440. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100441. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100442. d)>>16); /* result 1.16 */
  100443. e+=32;
  100444. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100445. e=(e>>1)-8;
  100446. return(val>>e);
  100447. }
  100448. float vorbis_fromdBlook_i(long a){
  100449. int i=(-a)>>(12-FROMdB2_SHIFT);
  100450. return (i<0)?1.f:
  100451. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100452. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100453. }
  100454. long vorbis_coslook_i(long a){
  100455. int i=a>>COS_LOOKUP_I_SHIFT;
  100456. int d=a&COS_LOOKUP_I_MASK;
  100457. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100458. COS_LOOKUP_I_SHIFT);
  100459. }
  100460. #endif
  100461. #endif
  100462. /*** End of inlined file: lookup.c ***/
  100463. /* catch this in the build system; we #include for
  100464. compilers (like gcc) that can't inline across
  100465. modules */
  100466. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100467. float amp,float ampoffset){
  100468. int i;
  100469. float wdel=M_PI/ln;
  100470. vorbis_fpu_control fpu;
  100471. (void) fpu; // to avoid an unused variable warning
  100472. vorbis_fpu_setround(&fpu);
  100473. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100474. i=0;
  100475. while(i<n){
  100476. int k=map[i];
  100477. int qexp;
  100478. float p=.7071067812f;
  100479. float q=.7071067812f;
  100480. float w=vorbis_coslook(wdel*k);
  100481. float *ftmp=lsp;
  100482. int c=m>>1;
  100483. do{
  100484. q*=ftmp[0]-w;
  100485. p*=ftmp[1]-w;
  100486. ftmp+=2;
  100487. }while(--c);
  100488. if(m&1){
  100489. q*=ftmp[0]-w;
  100490. q*=q;
  100491. p*=p*(1.f-w*w);
  100492. }else{
  100493. q*=q*(1.f+w);
  100494. p*=p*(1.f-w);
  100495. }
  100496. q=frexp(p+q,&qexp);
  100497. q=vorbis_fromdBlook(amp*
  100498. vorbis_invsqlook(q)*
  100499. vorbis_invsq2explook(qexp+m)-
  100500. ampoffset);
  100501. do{
  100502. curve[i++]*=q;
  100503. }while(map[i]==k);
  100504. }
  100505. vorbis_fpu_restore(fpu);
  100506. }
  100507. #else
  100508. #ifdef INT_LOOKUP
  100509. /*** Start of inlined file: lookup.c ***/
  100510. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100511. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100512. // tasks..
  100513. #if JUCE_MSVC
  100514. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100515. #endif
  100516. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100517. #if JUCE_USE_OGGVORBIS
  100518. #include <math.h>
  100519. /*** Start of inlined file: lookup.h ***/
  100520. #ifndef _V_LOOKUP_H_
  100521. #ifdef FLOAT_LOOKUP
  100522. extern float vorbis_coslook(float a);
  100523. extern float vorbis_invsqlook(float a);
  100524. extern float vorbis_invsq2explook(int a);
  100525. extern float vorbis_fromdBlook(float a);
  100526. #endif
  100527. #ifdef INT_LOOKUP
  100528. extern long vorbis_invsqlook_i(long a,long e);
  100529. extern long vorbis_coslook_i(long a);
  100530. extern float vorbis_fromdBlook_i(long a);
  100531. #endif
  100532. #endif
  100533. /*** End of inlined file: lookup.h ***/
  100534. /*** Start of inlined file: lookup_data.h ***/
  100535. #ifndef _V_LOOKUP_DATA_H_
  100536. #ifdef FLOAT_LOOKUP
  100537. #define COS_LOOKUP_SZ 128
  100538. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100539. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100540. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100541. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100542. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100543. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100544. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100545. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100546. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100547. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100548. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100549. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100550. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100551. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100552. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100553. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100554. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100555. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100556. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100557. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100558. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100559. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100560. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100561. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100562. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100563. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100564. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100565. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100566. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100567. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100568. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100569. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100570. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100571. -1.0000000000000f,
  100572. };
  100573. #define INVSQ_LOOKUP_SZ 32
  100574. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100575. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100576. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100577. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100578. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100579. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100580. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100581. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100582. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100583. 1.000000000000f,
  100584. };
  100585. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100586. #define INVSQ2EXP_LOOKUP_MAX 32
  100587. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100588. INVSQ2EXP_LOOKUP_MIN+1]={
  100589. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100590. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100591. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100592. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100593. 256.f, 181.019336f, 128.f, 90.50966799f,
  100594. 64.f, 45.254834f, 32.f, 22.627417f,
  100595. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100596. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100597. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100598. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100599. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100600. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100601. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100602. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100603. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100604. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100605. 1.525878906e-05f,
  100606. };
  100607. #endif
  100608. #define FROMdB_LOOKUP_SZ 35
  100609. #define FROMdB2_LOOKUP_SZ 32
  100610. #define FROMdB_SHIFT 5
  100611. #define FROMdB2_SHIFT 3
  100612. #define FROMdB2_MASK 31
  100613. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100614. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100615. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100616. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100617. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100618. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100619. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100620. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100621. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100622. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100623. };
  100624. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100625. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100626. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100627. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100628. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100629. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100630. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100631. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100632. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100633. };
  100634. #ifdef INT_LOOKUP
  100635. #define INVSQ_LOOKUP_I_SHIFT 10
  100636. #define INVSQ_LOOKUP_I_MASK 1023
  100637. static long INVSQ_LOOKUP_I[64+1]={
  100638. 92682l, 91966l, 91267l, 90583l,
  100639. 89915l, 89261l, 88621l, 87995l,
  100640. 87381l, 86781l, 86192l, 85616l,
  100641. 85051l, 84497l, 83953l, 83420l,
  100642. 82897l, 82384l, 81880l, 81385l,
  100643. 80899l, 80422l, 79953l, 79492l,
  100644. 79039l, 78594l, 78156l, 77726l,
  100645. 77302l, 76885l, 76475l, 76072l,
  100646. 75674l, 75283l, 74898l, 74519l,
  100647. 74146l, 73778l, 73415l, 73058l,
  100648. 72706l, 72359l, 72016l, 71679l,
  100649. 71347l, 71019l, 70695l, 70376l,
  100650. 70061l, 69750l, 69444l, 69141l,
  100651. 68842l, 68548l, 68256l, 67969l,
  100652. 67685l, 67405l, 67128l, 66855l,
  100653. 66585l, 66318l, 66054l, 65794l,
  100654. 65536l,
  100655. };
  100656. #define COS_LOOKUP_I_SHIFT 9
  100657. #define COS_LOOKUP_I_MASK 511
  100658. #define COS_LOOKUP_I_SZ 128
  100659. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100660. 16384l, 16379l, 16364l, 16340l,
  100661. 16305l, 16261l, 16207l, 16143l,
  100662. 16069l, 15986l, 15893l, 15791l,
  100663. 15679l, 15557l, 15426l, 15286l,
  100664. 15137l, 14978l, 14811l, 14635l,
  100665. 14449l, 14256l, 14053l, 13842l,
  100666. 13623l, 13395l, 13160l, 12916l,
  100667. 12665l, 12406l, 12140l, 11866l,
  100668. 11585l, 11297l, 11003l, 10702l,
  100669. 10394l, 10080l, 9760l, 9434l,
  100670. 9102l, 8765l, 8423l, 8076l,
  100671. 7723l, 7366l, 7005l, 6639l,
  100672. 6270l, 5897l, 5520l, 5139l,
  100673. 4756l, 4370l, 3981l, 3590l,
  100674. 3196l, 2801l, 2404l, 2006l,
  100675. 1606l, 1205l, 804l, 402l,
  100676. 0l, -401l, -803l, -1204l,
  100677. -1605l, -2005l, -2403l, -2800l,
  100678. -3195l, -3589l, -3980l, -4369l,
  100679. -4755l, -5138l, -5519l, -5896l,
  100680. -6269l, -6638l, -7004l, -7365l,
  100681. -7722l, -8075l, -8422l, -8764l,
  100682. -9101l, -9433l, -9759l, -10079l,
  100683. -10393l, -10701l, -11002l, -11296l,
  100684. -11584l, -11865l, -12139l, -12405l,
  100685. -12664l, -12915l, -13159l, -13394l,
  100686. -13622l, -13841l, -14052l, -14255l,
  100687. -14448l, -14634l, -14810l, -14977l,
  100688. -15136l, -15285l, -15425l, -15556l,
  100689. -15678l, -15790l, -15892l, -15985l,
  100690. -16068l, -16142l, -16206l, -16260l,
  100691. -16304l, -16339l, -16363l, -16378l,
  100692. -16383l,
  100693. };
  100694. #endif
  100695. #endif
  100696. /*** End of inlined file: lookup_data.h ***/
  100697. #ifdef FLOAT_LOOKUP
  100698. float vorbis_coslook(float a){
  100699. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100700. int i=vorbis_ftoi(d-.5);
  100701. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100702. }
  100703. float vorbis_invsqlook(float a){
  100704. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100705. int i=vorbis_ftoi(d-.5f);
  100706. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100707. }
  100708. float vorbis_invsq2explook(int a){
  100709. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100710. }
  100711. #include <stdio.h>
  100712. float vorbis_fromdBlook(float a){
  100713. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100714. return (i<0)?1.f:
  100715. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100716. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100717. }
  100718. #endif
  100719. #ifdef INT_LOOKUP
  100720. long vorbis_invsqlook_i(long a,long e){
  100721. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100722. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100723. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100724. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100725. d)>>16); /* result 1.16 */
  100726. e+=32;
  100727. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100728. e=(e>>1)-8;
  100729. return(val>>e);
  100730. }
  100731. float vorbis_fromdBlook_i(long a){
  100732. int i=(-a)>>(12-FROMdB2_SHIFT);
  100733. return (i<0)?1.f:
  100734. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100735. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100736. }
  100737. long vorbis_coslook_i(long a){
  100738. int i=a>>COS_LOOKUP_I_SHIFT;
  100739. int d=a&COS_LOOKUP_I_MASK;
  100740. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100741. COS_LOOKUP_I_SHIFT);
  100742. }
  100743. #endif
  100744. #endif
  100745. /*** End of inlined file: lookup.c ***/
  100746. /* catch this in the build system; we #include for
  100747. compilers (like gcc) that can't inline across
  100748. modules */
  100749. static int MLOOP_1[64]={
  100750. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  100751. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  100752. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100753. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100754. };
  100755. static int MLOOP_2[64]={
  100756. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  100757. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  100758. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100759. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100760. };
  100761. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  100762. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100763. float amp,float ampoffset){
  100764. int i;
  100765. int ampoffseti=rint(ampoffset*4096.f);
  100766. int ampi=rint(amp*16.f);
  100767. long *ilsp=alloca(m*sizeof(*ilsp));
  100768. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  100769. i=0;
  100770. while(i<n){
  100771. int j,k=map[i];
  100772. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  100773. unsigned long qi=46341;
  100774. int qexp=0,shift;
  100775. long wi=vorbis_coslook_i(k*65536/ln);
  100776. qi*=labs(ilsp[0]-wi);
  100777. pi*=labs(ilsp[1]-wi);
  100778. for(j=3;j<m;j+=2){
  100779. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100780. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100781. shift=MLOOP_3[(pi|qi)>>16];
  100782. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100783. pi=(pi>>shift)*labs(ilsp[j]-wi);
  100784. qexp+=shift;
  100785. }
  100786. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100787. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100788. shift=MLOOP_3[(pi|qi)>>16];
  100789. if(m&1){
  100790. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100791. pi=(pi>>shift)<<14;
  100792. qexp+=shift;
  100793. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100794. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100795. shift=MLOOP_3[(pi|qi)>>16];
  100796. pi>>=shift;
  100797. qi>>=shift;
  100798. qexp+=shift-14*((m+1)>>1);
  100799. pi=((pi*pi)>>16);
  100800. qi=((qi*qi)>>16);
  100801. qexp=qexp*2+m;
  100802. pi*=(1<<14)-((wi*wi)>>14);
  100803. qi+=pi>>14;
  100804. }else{
  100805. pi>>=shift;
  100806. qi>>=shift;
  100807. qexp+=shift-7*m;
  100808. pi=((pi*pi)>>16);
  100809. qi=((qi*qi)>>16);
  100810. qexp=qexp*2+m;
  100811. pi*=(1<<14)-wi;
  100812. qi*=(1<<14)+wi;
  100813. qi=(qi+pi)>>14;
  100814. }
  100815. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  100816. qi>>=1; qexp++;
  100817. }else
  100818. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  100819. qi<<=1; qexp--;
  100820. }
  100821. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  100822. vorbis_invsqlook_i(qi,qexp)-
  100823. ampoffseti); /* 8.12[0] */
  100824. curve[i]*=amp;
  100825. while(map[++i]==k)curve[i]*=amp;
  100826. }
  100827. }
  100828. #else
  100829. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100830. float amp,float ampoffset){
  100831. int i;
  100832. float wdel=M_PI/ln;
  100833. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  100834. i=0;
  100835. while(i<n){
  100836. int j,k=map[i];
  100837. float p=.5f;
  100838. float q=.5f;
  100839. float w=2.f*cos(wdel*k);
  100840. for(j=1;j<m;j+=2){
  100841. q *= w-lsp[j-1];
  100842. p *= w-lsp[j];
  100843. }
  100844. if(j==m){
  100845. q*=w-lsp[j-1];
  100846. p*=p*(4.f-w*w);
  100847. q*=q;
  100848. }else{
  100849. p*=p*(2.f-w);
  100850. q*=q*(2.f+w);
  100851. }
  100852. q=fromdB(amp/sqrt(p+q)-ampoffset);
  100853. curve[i]*=q;
  100854. while(map[++i]==k)curve[i]*=q;
  100855. }
  100856. }
  100857. #endif
  100858. #endif
  100859. static void cheby(float *g, int ord) {
  100860. int i, j;
  100861. g[0] *= .5f;
  100862. for(i=2; i<= ord; i++) {
  100863. for(j=ord; j >= i; j--) {
  100864. g[j-2] -= g[j];
  100865. g[j] += g[j];
  100866. }
  100867. }
  100868. }
  100869. static int comp(const void *a,const void *b){
  100870. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  100871. }
  100872. #define EPSILON 10e-7
  100873. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  100874. int i,m;
  100875. double lastdelta=0.f;
  100876. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  100877. for(i=0;i<=ord;i++)defl[i]=a[i];
  100878. for(m=ord;m>0;m--){
  100879. double newx=0.f,delta;
  100880. while(1){
  100881. double p=defl[m],pp=0.f,ppp=0.f,denom;
  100882. for(i=m;i>0;i--){
  100883. ppp = newx*ppp + pp;
  100884. pp = newx*pp + p;
  100885. p = newx*p + defl[i-1];
  100886. }
  100887. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  100888. if(denom<0)
  100889. return(-1); /* complex root! The LPC generator handed us a bad filter */
  100890. if(pp>0){
  100891. denom = pp + sqrt(denom);
  100892. if(denom<EPSILON)denom=EPSILON;
  100893. }else{
  100894. denom = pp - sqrt(denom);
  100895. if(denom>-(EPSILON))denom=-(EPSILON);
  100896. }
  100897. delta = m*p/denom;
  100898. newx -= delta;
  100899. if(delta<0.f)delta*=-1;
  100900. if(fabs(delta/newx)<10e-12)break;
  100901. lastdelta=delta;
  100902. }
  100903. r[m-1]=newx;
  100904. for(i=m;i>0;i--)
  100905. defl[i-1]+=newx*defl[i];
  100906. defl++;
  100907. }
  100908. return(0);
  100909. }
  100910. static int Newton_Raphson(float *a,int ord,float *r){
  100911. int i, k, count=0;
  100912. double error=1.f;
  100913. double *root=(double*)alloca(ord*sizeof(*root));
  100914. for(i=0; i<ord;i++) root[i] = r[i];
  100915. while(error>1e-20){
  100916. error=0;
  100917. for(i=0; i<ord; i++) { /* Update each point. */
  100918. double pp=0.,delta;
  100919. double rooti=root[i];
  100920. double p=a[ord];
  100921. for(k=ord-1; k>= 0; k--) {
  100922. pp= pp* rooti + p;
  100923. p = p * rooti + a[k];
  100924. }
  100925. delta = p/pp;
  100926. root[i] -= delta;
  100927. error+= delta*delta;
  100928. }
  100929. if(count>40)return(-1);
  100930. count++;
  100931. }
  100932. for(i=0; i<ord;i++) r[i] = root[i];
  100933. return(0);
  100934. }
  100935. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  100936. int order2=(m+1)>>1;
  100937. int g1_order,g2_order;
  100938. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  100939. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  100940. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  100941. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  100942. int i;
  100943. g1_order=(m+1)>>1;
  100944. g2_order=(m) >>1;
  100945. g1[g1_order] = 1.f;
  100946. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  100947. g2[g2_order] = 1.f;
  100948. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  100949. if(g1_order>g2_order){
  100950. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  100951. }else{
  100952. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  100953. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  100954. }
  100955. cheby(g1,g1_order);
  100956. cheby(g2,g2_order);
  100957. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  100958. Laguerre_With_Deflation(g2,g2_order,g2r))
  100959. return(-1);
  100960. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  100961. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  100962. qsort(g1r,g1_order,sizeof(*g1r),comp);
  100963. qsort(g2r,g2_order,sizeof(*g2r),comp);
  100964. for(i=0;i<g1_order;i++)
  100965. lsp[i*2] = acos(g1r[i]);
  100966. for(i=0;i<g2_order;i++)
  100967. lsp[i*2+1] = acos(g2r[i]);
  100968. return(0);
  100969. }
  100970. #endif
  100971. /*** End of inlined file: lsp.c ***/
  100972. /*** Start of inlined file: mapping0.c ***/
  100973. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100974. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100975. // tasks..
  100976. #if JUCE_MSVC
  100977. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100978. #endif
  100979. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100980. #if JUCE_USE_OGGVORBIS
  100981. #include <stdlib.h>
  100982. #include <stdio.h>
  100983. #include <string.h>
  100984. #include <math.h>
  100985. static void mapping0_free_info(vorbis_info_mapping *i){
  100986. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  100987. if(info){
  100988. memset(info,0,sizeof(*info));
  100989. _ogg_free(info);
  100990. }
  100991. }
  100992. static int ilog3(unsigned int v){
  100993. int ret=0;
  100994. if(v)--v;
  100995. while(v){
  100996. ret++;
  100997. v>>=1;
  100998. }
  100999. return(ret);
  101000. }
  101001. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101002. oggpack_buffer *opb){
  101003. int i;
  101004. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101005. if(info->submaps>1){
  101006. oggpack_write(opb,1,1);
  101007. oggpack_write(opb,info->submaps-1,4);
  101008. }else
  101009. oggpack_write(opb,0,1);
  101010. if(info->coupling_steps>0){
  101011. oggpack_write(opb,1,1);
  101012. oggpack_write(opb,info->coupling_steps-1,8);
  101013. for(i=0;i<info->coupling_steps;i++){
  101014. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101015. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101016. }
  101017. }else
  101018. oggpack_write(opb,0,1);
  101019. oggpack_write(opb,0,2); /* 2,3:reserved */
  101020. if(info->submaps>1){
  101021. for(i=0;i<vi->channels;i++)
  101022. oggpack_write(opb,info->chmuxlist[i],4);
  101023. }
  101024. for(i=0;i<info->submaps;i++){
  101025. oggpack_write(opb,0,8); /* time submap unused */
  101026. oggpack_write(opb,info->floorsubmap[i],8);
  101027. oggpack_write(opb,info->residuesubmap[i],8);
  101028. }
  101029. }
  101030. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101031. int i;
  101032. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101033. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101034. memset(info,0,sizeof(*info));
  101035. if(oggpack_read(opb,1))
  101036. info->submaps=oggpack_read(opb,4)+1;
  101037. else
  101038. info->submaps=1;
  101039. if(oggpack_read(opb,1)){
  101040. info->coupling_steps=oggpack_read(opb,8)+1;
  101041. for(i=0;i<info->coupling_steps;i++){
  101042. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101043. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101044. if(testM<0 ||
  101045. testA<0 ||
  101046. testM==testA ||
  101047. testM>=vi->channels ||
  101048. testA>=vi->channels) goto err_out;
  101049. }
  101050. }
  101051. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101052. if(info->submaps>1){
  101053. for(i=0;i<vi->channels;i++){
  101054. info->chmuxlist[i]=oggpack_read(opb,4);
  101055. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101056. }
  101057. }
  101058. for(i=0;i<info->submaps;i++){
  101059. oggpack_read(opb,8); /* time submap unused */
  101060. info->floorsubmap[i]=oggpack_read(opb,8);
  101061. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101062. info->residuesubmap[i]=oggpack_read(opb,8);
  101063. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101064. }
  101065. return info;
  101066. err_out:
  101067. mapping0_free_info(info);
  101068. return(NULL);
  101069. }
  101070. #if 0
  101071. static long seq=0;
  101072. static ogg_int64_t total=0;
  101073. static float FLOOR1_fromdB_LOOKUP[256]={
  101074. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101075. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101076. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101077. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101078. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101079. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101080. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101081. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101082. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101083. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101084. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101085. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101086. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101087. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101088. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101089. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101090. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101091. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101092. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101093. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101094. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101095. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101096. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101097. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101098. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101099. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101100. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101101. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101102. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101103. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101104. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101105. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101106. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101107. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101108. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101109. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101110. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101111. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101112. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101113. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101114. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101115. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101116. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101117. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101118. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101119. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101120. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101121. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101122. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101123. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101124. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101125. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101126. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101127. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101128. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101129. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101130. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101131. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101132. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101133. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101134. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101135. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101136. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101137. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101138. };
  101139. #endif
  101140. extern int *floor1_fit(vorbis_block *vb,void *look,
  101141. const float *logmdct, /* in */
  101142. const float *logmask);
  101143. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101144. int *A,int *B,
  101145. int del);
  101146. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101147. void*look,
  101148. int *post,int *ilogmask);
  101149. static int mapping0_forward(vorbis_block *vb){
  101150. vorbis_dsp_state *vd=vb->vd;
  101151. vorbis_info *vi=vd->vi;
  101152. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101153. private_state *b=(private_state*)vb->vd->backend_state;
  101154. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101155. int n=vb->pcmend;
  101156. int i,j,k;
  101157. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101158. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101159. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101160. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101161. float global_ampmax=vbi->ampmax;
  101162. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101163. int blocktype=vbi->blocktype;
  101164. int modenumber=vb->W;
  101165. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101166. vorbis_look_psy *psy_look=
  101167. b->psy+blocktype+(vb->W?2:0);
  101168. vb->mode=modenumber;
  101169. for(i=0;i<vi->channels;i++){
  101170. float scale=4.f/n;
  101171. float scale_dB;
  101172. float *pcm =vb->pcm[i];
  101173. float *logfft =pcm;
  101174. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101175. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101176. todB estimation used on IEEE 754
  101177. compliant machines had a bug that
  101178. returned dB values about a third
  101179. of a decibel too high. The bug
  101180. was harmless because tunings
  101181. implicitly took that into
  101182. account. However, fixing the bug
  101183. in the estimator requires
  101184. changing all the tunings as well.
  101185. For now, it's easier to sync
  101186. things back up here, and
  101187. recalibrate the tunings in the
  101188. next major model upgrade. */
  101189. #if 0
  101190. if(vi->channels==2)
  101191. if(i==0)
  101192. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101193. else
  101194. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101195. #endif
  101196. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101197. #if 0
  101198. if(vi->channels==2)
  101199. if(i==0)
  101200. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101201. else
  101202. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101203. #endif
  101204. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101205. drft_forward(&b->fft_look[vb->W],pcm);
  101206. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101207. original todB estimation used on
  101208. IEEE 754 compliant machines had a
  101209. bug that returned dB values about
  101210. a third of a decibel too high.
  101211. The bug was harmless because
  101212. tunings implicitly took that into
  101213. account. However, fixing the bug
  101214. in the estimator requires
  101215. changing all the tunings as well.
  101216. For now, it's easier to sync
  101217. things back up here, and
  101218. recalibrate the tunings in the
  101219. next major model upgrade. */
  101220. local_ampmax[i]=logfft[0];
  101221. for(j=1;j<n-1;j+=2){
  101222. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101223. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101224. .345 is a hack; the original todB
  101225. estimation used on IEEE 754
  101226. compliant machines had a bug that
  101227. returned dB values about a third
  101228. of a decibel too high. The bug
  101229. was harmless because tunings
  101230. implicitly took that into
  101231. account. However, fixing the bug
  101232. in the estimator requires
  101233. changing all the tunings as well.
  101234. For now, it's easier to sync
  101235. things back up here, and
  101236. recalibrate the tunings in the
  101237. next major model upgrade. */
  101238. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101239. }
  101240. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101241. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101242. #if 0
  101243. if(vi->channels==2){
  101244. if(i==0){
  101245. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101246. }else{
  101247. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101248. }
  101249. }
  101250. #endif
  101251. }
  101252. {
  101253. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101254. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101255. for(i=0;i<vi->channels;i++){
  101256. int submap=info->chmuxlist[i];
  101257. float *mdct =gmdct[i];
  101258. float *logfft =vb->pcm[i];
  101259. float *logmdct =logfft+n/2;
  101260. float *logmask =logfft;
  101261. vb->mode=modenumber;
  101262. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101263. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101264. for(j=0;j<n/2;j++)
  101265. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101266. todB estimation used on IEEE 754
  101267. compliant machines had a bug that
  101268. returned dB values about a third
  101269. of a decibel too high. The bug
  101270. was harmless because tunings
  101271. implicitly took that into
  101272. account. However, fixing the bug
  101273. in the estimator requires
  101274. changing all the tunings as well.
  101275. For now, it's easier to sync
  101276. things back up here, and
  101277. recalibrate the tunings in the
  101278. next major model upgrade. */
  101279. #if 0
  101280. if(vi->channels==2){
  101281. if(i==0)
  101282. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101283. else
  101284. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101285. }else{
  101286. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101287. }
  101288. #endif
  101289. _vp_noisemask(psy_look,
  101290. logmdct,
  101291. noise); /* noise does not have by-frequency offset
  101292. bias applied yet */
  101293. #if 0
  101294. if(vi->channels==2){
  101295. if(i==0)
  101296. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101297. else
  101298. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101299. }
  101300. #endif
  101301. _vp_tonemask(psy_look,
  101302. logfft,
  101303. tone,
  101304. global_ampmax,
  101305. local_ampmax[i]);
  101306. #if 0
  101307. if(vi->channels==2){
  101308. if(i==0)
  101309. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101310. else
  101311. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101312. }
  101313. #endif
  101314. #if 0
  101315. {
  101316. float aotuv[psy_look->n];
  101317. #endif
  101318. _vp_offset_and_mix(psy_look,
  101319. noise,
  101320. tone,
  101321. 1,
  101322. logmask,
  101323. mdct,
  101324. logmdct);
  101325. #if 0
  101326. if(vi->channels==2){
  101327. if(i==0)
  101328. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101329. else
  101330. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101331. }
  101332. }
  101333. #endif
  101334. #if 0
  101335. if(vi->channels==2){
  101336. if(i==0)
  101337. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101338. else
  101339. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101340. }
  101341. #endif
  101342. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101343. floor_posts[i][PACKETBLOBS/2]=
  101344. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101345. logmdct,
  101346. logmask);
  101347. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101348. _vp_offset_and_mix(psy_look,
  101349. noise,
  101350. tone,
  101351. 2,
  101352. logmask,
  101353. mdct,
  101354. logmdct);
  101355. #if 0
  101356. if(vi->channels==2){
  101357. if(i==0)
  101358. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101359. else
  101360. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101361. }
  101362. #endif
  101363. floor_posts[i][PACKETBLOBS-1]=
  101364. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101365. logmdct,
  101366. logmask);
  101367. _vp_offset_and_mix(psy_look,
  101368. noise,
  101369. tone,
  101370. 0,
  101371. logmask,
  101372. mdct,
  101373. logmdct);
  101374. #if 0
  101375. if(vi->channels==2)
  101376. if(i==0)
  101377. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101378. else
  101379. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101380. #endif
  101381. floor_posts[i][0]=
  101382. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101383. logmdct,
  101384. logmask);
  101385. for(k=1;k<PACKETBLOBS/2;k++)
  101386. floor_posts[i][k]=
  101387. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101388. floor_posts[i][0],
  101389. floor_posts[i][PACKETBLOBS/2],
  101390. k*65536/(PACKETBLOBS/2));
  101391. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101392. floor_posts[i][k]=
  101393. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101394. floor_posts[i][PACKETBLOBS/2],
  101395. floor_posts[i][PACKETBLOBS-1],
  101396. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101397. }
  101398. }
  101399. }
  101400. vbi->ampmax=global_ampmax;
  101401. {
  101402. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101403. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101404. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101405. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101406. float **mag_memo;
  101407. int **mag_sort;
  101408. if(info->coupling_steps){
  101409. mag_memo=_vp_quantize_couple_memo(vb,
  101410. &ci->psy_g_param,
  101411. psy_look,
  101412. info,
  101413. gmdct);
  101414. mag_sort=_vp_quantize_couple_sort(vb,
  101415. psy_look,
  101416. info,
  101417. mag_memo);
  101418. hf_reduction(&ci->psy_g_param,
  101419. psy_look,
  101420. info,
  101421. mag_memo);
  101422. }
  101423. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101424. if(psy_look->vi->normal_channel_p){
  101425. for(i=0;i<vi->channels;i++){
  101426. float *mdct =gmdct[i];
  101427. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101428. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101429. }
  101430. }
  101431. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101432. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101433. k++){
  101434. oggpack_buffer *opb=vbi->packetblob[k];
  101435. oggpack_write(opb,0,1);
  101436. oggpack_write(opb,modenumber,b->modebits);
  101437. if(vb->W){
  101438. oggpack_write(opb,vb->lW,1);
  101439. oggpack_write(opb,vb->nW,1);
  101440. }
  101441. for(i=0;i<vi->channels;i++){
  101442. int submap=info->chmuxlist[i];
  101443. float *mdct =gmdct[i];
  101444. float *res =vb->pcm[i];
  101445. int *ilogmask=ilogmaskch[i]=
  101446. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101447. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101448. floor_posts[i][k],
  101449. ilogmask);
  101450. #if 0
  101451. {
  101452. char buf[80];
  101453. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101454. float work[n/2];
  101455. for(j=0;j<n/2;j++)
  101456. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101457. _analysis_output(buf,seq,work,n/2,1,1,0);
  101458. }
  101459. #endif
  101460. _vp_remove_floor(psy_look,
  101461. mdct,
  101462. ilogmask,
  101463. res,
  101464. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101465. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101466. #if 0
  101467. {
  101468. char buf[80];
  101469. float work[n/2];
  101470. for(j=0;j<n/2;j++)
  101471. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101472. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101473. _analysis_output(buf,seq,work,n/2,1,1,0);
  101474. }
  101475. #endif
  101476. }
  101477. if(info->coupling_steps){
  101478. _vp_couple(k,
  101479. &ci->psy_g_param,
  101480. psy_look,
  101481. info,
  101482. vb->pcm,
  101483. mag_memo,
  101484. mag_sort,
  101485. ilogmaskch,
  101486. nonzero,
  101487. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101488. }
  101489. for(i=0;i<info->submaps;i++){
  101490. int ch_in_bundle=0;
  101491. long **classifications;
  101492. int resnum=info->residuesubmap[i];
  101493. for(j=0;j<vi->channels;j++){
  101494. if(info->chmuxlist[j]==i){
  101495. zerobundle[ch_in_bundle]=0;
  101496. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101497. res_bundle[ch_in_bundle]=vb->pcm[j];
  101498. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101499. }
  101500. }
  101501. classifications=_residue_P[ci->residue_type[resnum]]->
  101502. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101503. _residue_P[ci->residue_type[resnum]]->
  101504. forward(opb,vb,b->residue[resnum],
  101505. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101506. }
  101507. }
  101508. }
  101509. #if 0
  101510. seq++;
  101511. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101512. #endif
  101513. return(0);
  101514. }
  101515. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101516. vorbis_dsp_state *vd=vb->vd;
  101517. vorbis_info *vi=vd->vi;
  101518. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101519. private_state *b=(private_state*)vd->backend_state;
  101520. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101521. int i,j;
  101522. long n=vb->pcmend=ci->blocksizes[vb->W];
  101523. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101524. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101525. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101526. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101527. for(i=0;i<vi->channels;i++){
  101528. int submap=info->chmuxlist[i];
  101529. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101530. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101531. if(floormemo[i])
  101532. nonzero[i]=1;
  101533. else
  101534. nonzero[i]=0;
  101535. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101536. }
  101537. for(i=0;i<info->coupling_steps;i++){
  101538. if(nonzero[info->coupling_mag[i]] ||
  101539. nonzero[info->coupling_ang[i]]){
  101540. nonzero[info->coupling_mag[i]]=1;
  101541. nonzero[info->coupling_ang[i]]=1;
  101542. }
  101543. }
  101544. for(i=0;i<info->submaps;i++){
  101545. int ch_in_bundle=0;
  101546. for(j=0;j<vi->channels;j++){
  101547. if(info->chmuxlist[j]==i){
  101548. if(nonzero[j])
  101549. zerobundle[ch_in_bundle]=1;
  101550. else
  101551. zerobundle[ch_in_bundle]=0;
  101552. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101553. }
  101554. }
  101555. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101556. inverse(vb,b->residue[info->residuesubmap[i]],
  101557. pcmbundle,zerobundle,ch_in_bundle);
  101558. }
  101559. for(i=info->coupling_steps-1;i>=0;i--){
  101560. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101561. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101562. for(j=0;j<n/2;j++){
  101563. float mag=pcmM[j];
  101564. float ang=pcmA[j];
  101565. if(mag>0)
  101566. if(ang>0){
  101567. pcmM[j]=mag;
  101568. pcmA[j]=mag-ang;
  101569. }else{
  101570. pcmA[j]=mag;
  101571. pcmM[j]=mag+ang;
  101572. }
  101573. else
  101574. if(ang>0){
  101575. pcmM[j]=mag;
  101576. pcmA[j]=mag+ang;
  101577. }else{
  101578. pcmA[j]=mag;
  101579. pcmM[j]=mag-ang;
  101580. }
  101581. }
  101582. }
  101583. for(i=0;i<vi->channels;i++){
  101584. float *pcm=vb->pcm[i];
  101585. int submap=info->chmuxlist[i];
  101586. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101587. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101588. floormemo[i],pcm);
  101589. }
  101590. for(i=0;i<vi->channels;i++){
  101591. float *pcm=vb->pcm[i];
  101592. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101593. }
  101594. return(0);
  101595. }
  101596. vorbis_func_mapping mapping0_exportbundle={
  101597. &mapping0_pack,
  101598. &mapping0_unpack,
  101599. &mapping0_free_info,
  101600. &mapping0_forward,
  101601. &mapping0_inverse
  101602. };
  101603. #endif
  101604. /*** End of inlined file: mapping0.c ***/
  101605. /*** Start of inlined file: mdct.c ***/
  101606. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101607. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101608. // tasks..
  101609. #if JUCE_MSVC
  101610. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101611. #endif
  101612. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101613. #if JUCE_USE_OGGVORBIS
  101614. #include <stdio.h>
  101615. #include <stdlib.h>
  101616. #include <string.h>
  101617. #include <math.h>
  101618. void mdct_init(mdct_lookup *lookup,int n){
  101619. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101620. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101621. int i;
  101622. int n2=n>>1;
  101623. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101624. lookup->n=n;
  101625. lookup->trig=T;
  101626. lookup->bitrev=bitrev;
  101627. for(i=0;i<n/4;i++){
  101628. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101629. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101630. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101631. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101632. }
  101633. for(i=0;i<n/8;i++){
  101634. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101635. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101636. }
  101637. {
  101638. int mask=(1<<(log2n-1))-1,i,j;
  101639. int msb=1<<(log2n-2);
  101640. for(i=0;i<n/8;i++){
  101641. int acc=0;
  101642. for(j=0;msb>>j;j++)
  101643. if((msb>>j)&i)acc|=1<<j;
  101644. bitrev[i*2]=((~acc)&mask)-1;
  101645. bitrev[i*2+1]=acc;
  101646. }
  101647. }
  101648. lookup->scale=FLOAT_CONV(4.f/n);
  101649. }
  101650. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101651. REG_TYPE r0 = x[6] + x[2];
  101652. REG_TYPE r1 = x[6] - x[2];
  101653. REG_TYPE r2 = x[4] + x[0];
  101654. REG_TYPE r3 = x[4] - x[0];
  101655. x[6] = r0 + r2;
  101656. x[4] = r0 - r2;
  101657. r0 = x[5] - x[1];
  101658. r2 = x[7] - x[3];
  101659. x[0] = r1 + r0;
  101660. x[2] = r1 - r0;
  101661. r0 = x[5] + x[1];
  101662. r1 = x[7] + x[3];
  101663. x[3] = r2 + r3;
  101664. x[1] = r2 - r3;
  101665. x[7] = r1 + r0;
  101666. x[5] = r1 - r0;
  101667. }
  101668. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101669. REG_TYPE r0 = x[1] - x[9];
  101670. REG_TYPE r1 = x[0] - x[8];
  101671. x[8] += x[0];
  101672. x[9] += x[1];
  101673. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101674. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101675. r0 = x[3] - x[11];
  101676. r1 = x[10] - x[2];
  101677. x[10] += x[2];
  101678. x[11] += x[3];
  101679. x[2] = r0;
  101680. x[3] = r1;
  101681. r0 = x[12] - x[4];
  101682. r1 = x[13] - x[5];
  101683. x[12] += x[4];
  101684. x[13] += x[5];
  101685. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101686. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101687. r0 = x[14] - x[6];
  101688. r1 = x[15] - x[7];
  101689. x[14] += x[6];
  101690. x[15] += x[7];
  101691. x[6] = r0;
  101692. x[7] = r1;
  101693. mdct_butterfly_8(x);
  101694. mdct_butterfly_8(x+8);
  101695. }
  101696. STIN void mdct_butterfly_32(DATA_TYPE *x){
  101697. REG_TYPE r0 = x[30] - x[14];
  101698. REG_TYPE r1 = x[31] - x[15];
  101699. x[30] += x[14];
  101700. x[31] += x[15];
  101701. x[14] = r0;
  101702. x[15] = r1;
  101703. r0 = x[28] - x[12];
  101704. r1 = x[29] - x[13];
  101705. x[28] += x[12];
  101706. x[29] += x[13];
  101707. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  101708. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  101709. r0 = x[26] - x[10];
  101710. r1 = x[27] - x[11];
  101711. x[26] += x[10];
  101712. x[27] += x[11];
  101713. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  101714. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  101715. r0 = x[24] - x[8];
  101716. r1 = x[25] - x[9];
  101717. x[24] += x[8];
  101718. x[25] += x[9];
  101719. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  101720. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101721. r0 = x[22] - x[6];
  101722. r1 = x[7] - x[23];
  101723. x[22] += x[6];
  101724. x[23] += x[7];
  101725. x[6] = r1;
  101726. x[7] = r0;
  101727. r0 = x[4] - x[20];
  101728. r1 = x[5] - x[21];
  101729. x[20] += x[4];
  101730. x[21] += x[5];
  101731. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  101732. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  101733. r0 = x[2] - x[18];
  101734. r1 = x[3] - x[19];
  101735. x[18] += x[2];
  101736. x[19] += x[3];
  101737. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  101738. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  101739. r0 = x[0] - x[16];
  101740. r1 = x[1] - x[17];
  101741. x[16] += x[0];
  101742. x[17] += x[1];
  101743. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101744. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  101745. mdct_butterfly_16(x);
  101746. mdct_butterfly_16(x+16);
  101747. }
  101748. STIN void mdct_butterfly_first(DATA_TYPE *T,
  101749. DATA_TYPE *x,
  101750. int points){
  101751. DATA_TYPE *x1 = x + points - 8;
  101752. DATA_TYPE *x2 = x + (points>>1) - 8;
  101753. REG_TYPE r0;
  101754. REG_TYPE r1;
  101755. do{
  101756. r0 = x1[6] - x2[6];
  101757. r1 = x1[7] - x2[7];
  101758. x1[6] += x2[6];
  101759. x1[7] += x2[7];
  101760. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101761. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101762. r0 = x1[4] - x2[4];
  101763. r1 = x1[5] - x2[5];
  101764. x1[4] += x2[4];
  101765. x1[5] += x2[5];
  101766. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  101767. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  101768. r0 = x1[2] - x2[2];
  101769. r1 = x1[3] - x2[3];
  101770. x1[2] += x2[2];
  101771. x1[3] += x2[3];
  101772. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  101773. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  101774. r0 = x1[0] - x2[0];
  101775. r1 = x1[1] - x2[1];
  101776. x1[0] += x2[0];
  101777. x1[1] += x2[1];
  101778. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  101779. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  101780. x1-=8;
  101781. x2-=8;
  101782. T+=16;
  101783. }while(x2>=x);
  101784. }
  101785. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  101786. DATA_TYPE *x,
  101787. int points,
  101788. int trigint){
  101789. DATA_TYPE *x1 = x + points - 8;
  101790. DATA_TYPE *x2 = x + (points>>1) - 8;
  101791. REG_TYPE r0;
  101792. REG_TYPE r1;
  101793. do{
  101794. r0 = x1[6] - x2[6];
  101795. r1 = x1[7] - x2[7];
  101796. x1[6] += x2[6];
  101797. x1[7] += x2[7];
  101798. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101799. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101800. T+=trigint;
  101801. r0 = x1[4] - x2[4];
  101802. r1 = x1[5] - x2[5];
  101803. x1[4] += x2[4];
  101804. x1[5] += x2[5];
  101805. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101806. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101807. T+=trigint;
  101808. r0 = x1[2] - x2[2];
  101809. r1 = x1[3] - x2[3];
  101810. x1[2] += x2[2];
  101811. x1[3] += x2[3];
  101812. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101813. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101814. T+=trigint;
  101815. r0 = x1[0] - x2[0];
  101816. r1 = x1[1] - x2[1];
  101817. x1[0] += x2[0];
  101818. x1[1] += x2[1];
  101819. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101820. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101821. T+=trigint;
  101822. x1-=8;
  101823. x2-=8;
  101824. }while(x2>=x);
  101825. }
  101826. STIN void mdct_butterflies(mdct_lookup *init,
  101827. DATA_TYPE *x,
  101828. int points){
  101829. DATA_TYPE *T=init->trig;
  101830. int stages=init->log2n-5;
  101831. int i,j;
  101832. if(--stages>0){
  101833. mdct_butterfly_first(T,x,points);
  101834. }
  101835. for(i=1;--stages>0;i++){
  101836. for(j=0;j<(1<<i);j++)
  101837. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  101838. }
  101839. for(j=0;j<points;j+=32)
  101840. mdct_butterfly_32(x+j);
  101841. }
  101842. void mdct_clear(mdct_lookup *l){
  101843. if(l){
  101844. if(l->trig)_ogg_free(l->trig);
  101845. if(l->bitrev)_ogg_free(l->bitrev);
  101846. memset(l,0,sizeof(*l));
  101847. }
  101848. }
  101849. STIN void mdct_bitreverse(mdct_lookup *init,
  101850. DATA_TYPE *x){
  101851. int n = init->n;
  101852. int *bit = init->bitrev;
  101853. DATA_TYPE *w0 = x;
  101854. DATA_TYPE *w1 = x = w0+(n>>1);
  101855. DATA_TYPE *T = init->trig+n;
  101856. do{
  101857. DATA_TYPE *x0 = x+bit[0];
  101858. DATA_TYPE *x1 = x+bit[1];
  101859. REG_TYPE r0 = x0[1] - x1[1];
  101860. REG_TYPE r1 = x0[0] + x1[0];
  101861. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  101862. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  101863. w1 -= 4;
  101864. r0 = HALVE(x0[1] + x1[1]);
  101865. r1 = HALVE(x0[0] - x1[0]);
  101866. w0[0] = r0 + r2;
  101867. w1[2] = r0 - r2;
  101868. w0[1] = r1 + r3;
  101869. w1[3] = r3 - r1;
  101870. x0 = x+bit[2];
  101871. x1 = x+bit[3];
  101872. r0 = x0[1] - x1[1];
  101873. r1 = x0[0] + x1[0];
  101874. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  101875. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  101876. r0 = HALVE(x0[1] + x1[1]);
  101877. r1 = HALVE(x0[0] - x1[0]);
  101878. w0[2] = r0 + r2;
  101879. w1[0] = r0 - r2;
  101880. w0[3] = r1 + r3;
  101881. w1[1] = r3 - r1;
  101882. T += 4;
  101883. bit += 4;
  101884. w0 += 4;
  101885. }while(w0<w1);
  101886. }
  101887. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  101888. int n=init->n;
  101889. int n2=n>>1;
  101890. int n4=n>>2;
  101891. DATA_TYPE *iX = in+n2-7;
  101892. DATA_TYPE *oX = out+n2+n4;
  101893. DATA_TYPE *T = init->trig+n4;
  101894. do{
  101895. oX -= 4;
  101896. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  101897. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  101898. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  101899. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  101900. iX -= 8;
  101901. T += 4;
  101902. }while(iX>=in);
  101903. iX = in+n2-8;
  101904. oX = out+n2+n4;
  101905. T = init->trig+n4;
  101906. do{
  101907. T -= 4;
  101908. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  101909. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  101910. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  101911. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  101912. iX -= 8;
  101913. oX += 4;
  101914. }while(iX>=in);
  101915. mdct_butterflies(init,out+n2,n2);
  101916. mdct_bitreverse(init,out);
  101917. {
  101918. DATA_TYPE *oX1=out+n2+n4;
  101919. DATA_TYPE *oX2=out+n2+n4;
  101920. DATA_TYPE *iX =out;
  101921. T =init->trig+n2;
  101922. do{
  101923. oX1-=4;
  101924. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  101925. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  101926. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  101927. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  101928. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  101929. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  101930. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  101931. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  101932. oX2+=4;
  101933. iX += 8;
  101934. T += 8;
  101935. }while(iX<oX1);
  101936. iX=out+n2+n4;
  101937. oX1=out+n4;
  101938. oX2=oX1;
  101939. do{
  101940. oX1-=4;
  101941. iX-=4;
  101942. oX2[0] = -(oX1[3] = iX[3]);
  101943. oX2[1] = -(oX1[2] = iX[2]);
  101944. oX2[2] = -(oX1[1] = iX[1]);
  101945. oX2[3] = -(oX1[0] = iX[0]);
  101946. oX2+=4;
  101947. }while(oX2<iX);
  101948. iX=out+n2+n4;
  101949. oX1=out+n2+n4;
  101950. oX2=out+n2;
  101951. do{
  101952. oX1-=4;
  101953. oX1[0]= iX[3];
  101954. oX1[1]= iX[2];
  101955. oX1[2]= iX[1];
  101956. oX1[3]= iX[0];
  101957. iX+=4;
  101958. }while(oX1>oX2);
  101959. }
  101960. }
  101961. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  101962. int n=init->n;
  101963. int n2=n>>1;
  101964. int n4=n>>2;
  101965. int n8=n>>3;
  101966. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  101967. DATA_TYPE *w2=w+n2;
  101968. REG_TYPE r0;
  101969. REG_TYPE r1;
  101970. DATA_TYPE *x0=in+n2+n4;
  101971. DATA_TYPE *x1=x0+1;
  101972. DATA_TYPE *T=init->trig+n2;
  101973. int i=0;
  101974. for(i=0;i<n8;i+=2){
  101975. x0 -=4;
  101976. T-=2;
  101977. r0= x0[2] + x1[0];
  101978. r1= x0[0] + x1[2];
  101979. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  101980. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  101981. x1 +=4;
  101982. }
  101983. x1=in+1;
  101984. for(;i<n2-n8;i+=2){
  101985. T-=2;
  101986. x0 -=4;
  101987. r0= x0[2] - x1[0];
  101988. r1= x0[0] - x1[2];
  101989. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  101990. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  101991. x1 +=4;
  101992. }
  101993. x0=in+n;
  101994. for(;i<n2;i+=2){
  101995. T-=2;
  101996. x0 -=4;
  101997. r0= -x0[2] - x1[0];
  101998. r1= -x0[0] - x1[2];
  101999. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102000. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102001. x1 +=4;
  102002. }
  102003. mdct_butterflies(init,w+n2,n2);
  102004. mdct_bitreverse(init,w);
  102005. T=init->trig+n2;
  102006. x0=out+n2;
  102007. for(i=0;i<n4;i++){
  102008. x0--;
  102009. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102010. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102011. w+=2;
  102012. T+=2;
  102013. }
  102014. }
  102015. #endif
  102016. /*** End of inlined file: mdct.c ***/
  102017. /*** Start of inlined file: psy.c ***/
  102018. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102019. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102020. // tasks..
  102021. #if JUCE_MSVC
  102022. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102023. #endif
  102024. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102025. #if JUCE_USE_OGGVORBIS
  102026. #include <stdlib.h>
  102027. #include <math.h>
  102028. #include <string.h>
  102029. /*** Start of inlined file: masking.h ***/
  102030. #ifndef _V_MASKING_H_
  102031. #define _V_MASKING_H_
  102032. #define MAX_ATH 88
  102033. static float ATH[]={
  102034. -51, -52, -53, -54, -55, -56, -57, -58,
  102035. -59, -60, -61, -62, -63, -64, -65, -66,
  102036. -67, -68, -69, -70, -71, -72, -73, -74,
  102037. -75, -76, -77, -78, -80, -81, -82, -83,
  102038. -84, -85, -86, -87, -88, -88, -89, -89,
  102039. -90, -91, -91, -92, -93, -94, -95, -96,
  102040. -96, -97, -98, -98, -99, -99,-100,-100,
  102041. -101,-102,-103,-104,-106,-107,-107,-107,
  102042. -107,-105,-103,-102,-101, -99, -98, -96,
  102043. -95, -95, -96, -97, -96, -95, -93, -90,
  102044. -80, -70, -50, -40, -30, -30, -30, -30
  102045. };
  102046. #define EHMER_OFFSET 16
  102047. #define EHMER_MAX 56
  102048. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102049. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102050. -60, -60, -60, -60, -62, -62, -65, -73,
  102051. -69, -68, -68, -67, -70, -70, -72, -74,
  102052. -75, -79, -79, -80, -83, -88, -93, -100,
  102053. -110, -999, -999, -999, -999, -999, -999, -999,
  102054. -999, -999, -999, -999, -999, -999, -999, -999,
  102055. -999, -999, -999, -999, -999, -999, -999, -999},
  102056. { -48, -48, -48, -48, -48, -48, -48, -48,
  102057. -48, -48, -48, -48, -48, -53, -61, -66,
  102058. -66, -68, -67, -70, -76, -76, -72, -73,
  102059. -75, -76, -78, -79, -83, -88, -93, -100,
  102060. -110, -999, -999, -999, -999, -999, -999, -999,
  102061. -999, -999, -999, -999, -999, -999, -999, -999,
  102062. -999, -999, -999, -999, -999, -999, -999, -999},
  102063. { -37, -37, -37, -37, -37, -37, -37, -37,
  102064. -38, -40, -42, -46, -48, -53, -55, -62,
  102065. -65, -58, -56, -56, -61, -60, -65, -67,
  102066. -69, -71, -77, -77, -78, -80, -82, -84,
  102067. -88, -93, -98, -106, -112, -999, -999, -999,
  102068. -999, -999, -999, -999, -999, -999, -999, -999,
  102069. -999, -999, -999, -999, -999, -999, -999, -999},
  102070. { -25, -25, -25, -25, -25, -25, -25, -25,
  102071. -25, -26, -27, -29, -32, -38, -48, -52,
  102072. -52, -50, -48, -48, -51, -52, -54, -60,
  102073. -67, -67, -66, -68, -69, -73, -73, -76,
  102074. -80, -81, -81, -85, -85, -86, -88, -93,
  102075. -100, -110, -999, -999, -999, -999, -999, -999,
  102076. -999, -999, -999, -999, -999, -999, -999, -999},
  102077. { -16, -16, -16, -16, -16, -16, -16, -16,
  102078. -17, -19, -20, -22, -26, -28, -31, -40,
  102079. -47, -39, -39, -40, -42, -43, -47, -51,
  102080. -57, -52, -55, -55, -60, -58, -62, -63,
  102081. -70, -67, -69, -72, -73, -77, -80, -82,
  102082. -83, -87, -90, -94, -98, -104, -115, -999,
  102083. -999, -999, -999, -999, -999, -999, -999, -999},
  102084. { -8, -8, -8, -8, -8, -8, -8, -8,
  102085. -8, -8, -10, -11, -15, -19, -25, -30,
  102086. -34, -31, -30, -31, -29, -32, -35, -42,
  102087. -48, -42, -44, -46, -50, -50, -51, -52,
  102088. -59, -54, -55, -55, -58, -62, -63, -66,
  102089. -72, -73, -76, -75, -78, -80, -80, -81,
  102090. -84, -88, -90, -94, -98, -101, -106, -110}},
  102091. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102092. -66, -66, -66, -66, -66, -67, -67, -67,
  102093. -76, -72, -71, -74, -76, -76, -75, -78,
  102094. -79, -79, -81, -83, -86, -89, -93, -97,
  102095. -100, -105, -110, -999, -999, -999, -999, -999,
  102096. -999, -999, -999, -999, -999, -999, -999, -999,
  102097. -999, -999, -999, -999, -999, -999, -999, -999},
  102098. { -47, -47, -47, -47, -47, -47, -47, -47,
  102099. -47, -47, -47, -48, -51, -55, -59, -66,
  102100. -66, -66, -67, -66, -68, -69, -70, -74,
  102101. -79, -77, -77, -78, -80, -81, -82, -84,
  102102. -86, -88, -91, -95, -100, -108, -116, -999,
  102103. -999, -999, -999, -999, -999, -999, -999, -999,
  102104. -999, -999, -999, -999, -999, -999, -999, -999},
  102105. { -36, -36, -36, -36, -36, -36, -36, -36,
  102106. -36, -37, -37, -41, -44, -48, -51, -58,
  102107. -62, -60, -57, -59, -59, -60, -63, -65,
  102108. -72, -71, -70, -72, -74, -77, -76, -78,
  102109. -81, -81, -80, -83, -86, -91, -96, -100,
  102110. -105, -110, -999, -999, -999, -999, -999, -999,
  102111. -999, -999, -999, -999, -999, -999, -999, -999},
  102112. { -28, -28, -28, -28, -28, -28, -28, -28,
  102113. -28, -30, -32, -32, -33, -35, -41, -49,
  102114. -50, -49, -47, -48, -48, -52, -51, -57,
  102115. -65, -61, -59, -61, -64, -69, -70, -74,
  102116. -77, -77, -78, -81, -84, -85, -87, -90,
  102117. -92, -96, -100, -107, -112, -999, -999, -999,
  102118. -999, -999, -999, -999, -999, -999, -999, -999},
  102119. { -19, -19, -19, -19, -19, -19, -19, -19,
  102120. -20, -21, -23, -27, -30, -35, -36, -41,
  102121. -46, -44, -42, -40, -41, -41, -43, -48,
  102122. -55, -53, -52, -53, -56, -59, -58, -60,
  102123. -67, -66, -69, -71, -72, -75, -79, -81,
  102124. -84, -87, -90, -93, -97, -101, -107, -114,
  102125. -999, -999, -999, -999, -999, -999, -999, -999},
  102126. { -9, -9, -9, -9, -9, -9, -9, -9,
  102127. -11, -12, -12, -15, -16, -20, -23, -30,
  102128. -37, -34, -33, -34, -31, -32, -32, -38,
  102129. -47, -44, -41, -40, -47, -49, -46, -46,
  102130. -58, -50, -50, -54, -58, -62, -64, -67,
  102131. -67, -70, -72, -76, -79, -83, -87, -91,
  102132. -96, -100, -104, -110, -999, -999, -999, -999}},
  102133. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102134. -62, -62, -63, -64, -66, -67, -66, -68,
  102135. -75, -72, -76, -75, -76, -78, -79, -82,
  102136. -84, -85, -90, -94, -101, -110, -999, -999,
  102137. -999, -999, -999, -999, -999, -999, -999, -999,
  102138. -999, -999, -999, -999, -999, -999, -999, -999,
  102139. -999, -999, -999, -999, -999, -999, -999, -999},
  102140. { -59, -59, -59, -59, -59, -59, -59, -59,
  102141. -59, -59, -59, -60, -60, -61, -63, -66,
  102142. -71, -68, -70, -70, -71, -72, -72, -75,
  102143. -81, -78, -79, -82, -83, -86, -90, -97,
  102144. -103, -113, -999, -999, -999, -999, -999, -999,
  102145. -999, -999, -999, -999, -999, -999, -999, -999,
  102146. -999, -999, -999, -999, -999, -999, -999, -999},
  102147. { -53, -53, -53, -53, -53, -53, -53, -53,
  102148. -53, -54, -55, -57, -56, -57, -55, -61,
  102149. -65, -60, -60, -62, -63, -63, -66, -68,
  102150. -74, -73, -75, -75, -78, -80, -80, -82,
  102151. -85, -90, -96, -101, -108, -999, -999, -999,
  102152. -999, -999, -999, -999, -999, -999, -999, -999,
  102153. -999, -999, -999, -999, -999, -999, -999, -999},
  102154. { -46, -46, -46, -46, -46, -46, -46, -46,
  102155. -46, -46, -47, -47, -47, -47, -48, -51,
  102156. -57, -51, -49, -50, -51, -53, -54, -59,
  102157. -66, -60, -62, -67, -67, -70, -72, -75,
  102158. -76, -78, -81, -85, -88, -94, -97, -104,
  102159. -112, -999, -999, -999, -999, -999, -999, -999,
  102160. -999, -999, -999, -999, -999, -999, -999, -999},
  102161. { -36, -36, -36, -36, -36, -36, -36, -36,
  102162. -39, -41, -42, -42, -39, -38, -41, -43,
  102163. -52, -44, -40, -39, -37, -37, -40, -47,
  102164. -54, -50, -48, -50, -55, -61, -59, -62,
  102165. -66, -66, -66, -69, -69, -73, -74, -74,
  102166. -75, -77, -79, -82, -87, -91, -95, -100,
  102167. -108, -115, -999, -999, -999, -999, -999, -999},
  102168. { -28, -26, -24, -22, -20, -20, -23, -29,
  102169. -30, -31, -28, -27, -28, -28, -28, -35,
  102170. -40, -33, -32, -29, -30, -30, -30, -37,
  102171. -45, -41, -37, -38, -45, -47, -47, -48,
  102172. -53, -49, -48, -50, -49, -49, -51, -52,
  102173. -58, -56, -57, -56, -60, -61, -62, -70,
  102174. -72, -74, -78, -83, -88, -93, -100, -106}},
  102175. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102176. -999, -110, -105, -100, -95, -91, -87, -83,
  102177. -80, -78, -76, -78, -78, -81, -83, -85,
  102178. -86, -85, -86, -87, -90, -97, -107, -999,
  102179. -999, -999, -999, -999, -999, -999, -999, -999,
  102180. -999, -999, -999, -999, -999, -999, -999, -999,
  102181. -999, -999, -999, -999, -999, -999, -999, -999},
  102182. {-999, -999, -999, -110, -105, -100, -95, -90,
  102183. -85, -81, -77, -73, -70, -67, -67, -68,
  102184. -75, -73, -70, -69, -70, -72, -75, -79,
  102185. -84, -83, -84, -86, -88, -89, -89, -93,
  102186. -98, -105, -112, -999, -999, -999, -999, -999,
  102187. -999, -999, -999, -999, -999, -999, -999, -999,
  102188. -999, -999, -999, -999, -999, -999, -999, -999},
  102189. {-105, -100, -95, -90, -85, -80, -76, -71,
  102190. -68, -68, -65, -63, -63, -62, -62, -64,
  102191. -65, -64, -61, -62, -63, -64, -66, -68,
  102192. -73, -73, -74, -75, -76, -81, -83, -85,
  102193. -88, -89, -92, -95, -100, -108, -999, -999,
  102194. -999, -999, -999, -999, -999, -999, -999, -999,
  102195. -999, -999, -999, -999, -999, -999, -999, -999},
  102196. { -80, -75, -71, -68, -65, -63, -62, -61,
  102197. -61, -61, -61, -59, -56, -57, -53, -50,
  102198. -58, -52, -50, -50, -52, -53, -54, -58,
  102199. -67, -63, -67, -68, -72, -75, -78, -80,
  102200. -81, -81, -82, -85, -89, -90, -93, -97,
  102201. -101, -107, -114, -999, -999, -999, -999, -999,
  102202. -999, -999, -999, -999, -999, -999, -999, -999},
  102203. { -65, -61, -59, -57, -56, -55, -55, -56,
  102204. -56, -57, -55, -53, -52, -47, -44, -44,
  102205. -50, -44, -41, -39, -39, -42, -40, -46,
  102206. -51, -49, -50, -53, -54, -63, -60, -61,
  102207. -62, -66, -66, -66, -70, -73, -74, -75,
  102208. -76, -75, -79, -85, -89, -91, -96, -102,
  102209. -110, -999, -999, -999, -999, -999, -999, -999},
  102210. { -52, -50, -49, -49, -48, -48, -48, -49,
  102211. -50, -50, -49, -46, -43, -39, -35, -33,
  102212. -38, -36, -32, -29, -32, -32, -32, -35,
  102213. -44, -39, -38, -38, -46, -50, -45, -46,
  102214. -53, -50, -50, -50, -54, -54, -53, -53,
  102215. -56, -57, -59, -66, -70, -72, -74, -79,
  102216. -83, -85, -90, -97, -114, -999, -999, -999}},
  102217. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102218. -100, -95, -90, -86, -80, -75, -75, -79,
  102219. -80, -79, -80, -81, -82, -88, -95, -103,
  102220. -110, -999, -999, -999, -999, -999, -999, -999,
  102221. -999, -999, -999, -999, -999, -999, -999, -999,
  102222. -999, -999, -999, -999, -999, -999, -999, -999,
  102223. -999, -999, -999, -999, -999, -999, -999, -999},
  102224. {-999, -999, -999, -999, -108, -103, -98, -93,
  102225. -88, -83, -79, -78, -75, -71, -67, -68,
  102226. -73, -73, -72, -73, -75, -77, -80, -82,
  102227. -88, -93, -100, -107, -114, -999, -999, -999,
  102228. -999, -999, -999, -999, -999, -999, -999, -999,
  102229. -999, -999, -999, -999, -999, -999, -999, -999,
  102230. -999, -999, -999, -999, -999, -999, -999, -999},
  102231. {-999, -999, -999, -110, -105, -101, -96, -90,
  102232. -86, -81, -77, -73, -69, -66, -61, -62,
  102233. -66, -64, -62, -65, -66, -70, -72, -76,
  102234. -81, -80, -84, -90, -95, -102, -110, -999,
  102235. -999, -999, -999, -999, -999, -999, -999, -999,
  102236. -999, -999, -999, -999, -999, -999, -999, -999,
  102237. -999, -999, -999, -999, -999, -999, -999, -999},
  102238. {-999, -999, -999, -107, -103, -97, -92, -88,
  102239. -83, -79, -74, -70, -66, -59, -53, -58,
  102240. -62, -55, -54, -54, -54, -58, -61, -62,
  102241. -72, -70, -72, -75, -78, -80, -81, -80,
  102242. -83, -83, -88, -93, -100, -107, -115, -999,
  102243. -999, -999, -999, -999, -999, -999, -999, -999,
  102244. -999, -999, -999, -999, -999, -999, -999, -999},
  102245. {-999, -999, -999, -105, -100, -95, -90, -85,
  102246. -80, -75, -70, -66, -62, -56, -48, -44,
  102247. -48, -46, -46, -43, -46, -48, -48, -51,
  102248. -58, -58, -59, -60, -62, -62, -61, -61,
  102249. -65, -64, -65, -68, -70, -74, -75, -78,
  102250. -81, -86, -95, -110, -999, -999, -999, -999,
  102251. -999, -999, -999, -999, -999, -999, -999, -999},
  102252. {-999, -999, -105, -100, -95, -90, -85, -80,
  102253. -75, -70, -65, -61, -55, -49, -39, -33,
  102254. -40, -35, -32, -38, -40, -33, -35, -37,
  102255. -46, -41, -45, -44, -46, -42, -45, -46,
  102256. -52, -50, -50, -50, -54, -54, -55, -57,
  102257. -62, -64, -66, -68, -70, -76, -81, -90,
  102258. -100, -110, -999, -999, -999, -999, -999, -999}},
  102259. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102260. -105, -98, -90, -85, -82, -83, -80, -78,
  102261. -84, -79, -80, -83, -87, -89, -91, -93,
  102262. -99, -106, -117, -999, -999, -999, -999, -999,
  102263. -999, -999, -999, -999, -999, -999, -999, -999,
  102264. -999, -999, -999, -999, -999, -999, -999, -999,
  102265. -999, -999, -999, -999, -999, -999, -999, -999},
  102266. {-999, -999, -999, -999, -999, -999, -999, -999,
  102267. -105, -98, -90, -85, -80, -75, -70, -68,
  102268. -74, -72, -74, -77, -80, -82, -85, -87,
  102269. -92, -89, -91, -95, -100, -106, -112, -999,
  102270. -999, -999, -999, -999, -999, -999, -999, -999,
  102271. -999, -999, -999, -999, -999, -999, -999, -999,
  102272. -999, -999, -999, -999, -999, -999, -999, -999},
  102273. {-999, -999, -999, -999, -999, -999, -999, -999,
  102274. -105, -98, -90, -83, -75, -71, -63, -64,
  102275. -67, -62, -64, -67, -70, -73, -77, -81,
  102276. -84, -83, -85, -89, -90, -93, -98, -104,
  102277. -109, -114, -999, -999, -999, -999, -999, -999,
  102278. -999, -999, -999, -999, -999, -999, -999, -999,
  102279. -999, -999, -999, -999, -999, -999, -999, -999},
  102280. {-999, -999, -999, -999, -999, -999, -999, -999,
  102281. -103, -96, -88, -81, -75, -68, -58, -54,
  102282. -56, -54, -56, -56, -58, -60, -63, -66,
  102283. -74, -69, -72, -72, -75, -74, -77, -81,
  102284. -81, -82, -84, -87, -93, -96, -99, -104,
  102285. -110, -999, -999, -999, -999, -999, -999, -999,
  102286. -999, -999, -999, -999, -999, -999, -999, -999},
  102287. {-999, -999, -999, -999, -999, -108, -102, -96,
  102288. -91, -85, -80, -74, -68, -60, -51, -46,
  102289. -48, -46, -43, -45, -47, -47, -49, -48,
  102290. -56, -53, -55, -58, -57, -63, -58, -60,
  102291. -66, -64, -67, -70, -70, -74, -77, -84,
  102292. -86, -89, -91, -93, -94, -101, -109, -118,
  102293. -999, -999, -999, -999, -999, -999, -999, -999},
  102294. {-999, -999, -999, -108, -103, -98, -93, -88,
  102295. -83, -78, -73, -68, -60, -53, -44, -35,
  102296. -38, -38, -34, -34, -36, -40, -41, -44,
  102297. -51, -45, -46, -47, -46, -54, -50, -49,
  102298. -50, -50, -50, -51, -54, -57, -58, -60,
  102299. -66, -66, -66, -64, -65, -68, -77, -82,
  102300. -87, -95, -110, -999, -999, -999, -999, -999}},
  102301. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102302. -107, -102, -97, -92, -87, -83, -78, -75,
  102303. -82, -79, -83, -85, -89, -92, -95, -98,
  102304. -101, -105, -109, -113, -999, -999, -999, -999,
  102305. -999, -999, -999, -999, -999, -999, -999, -999,
  102306. -999, -999, -999, -999, -999, -999, -999, -999,
  102307. -999, -999, -999, -999, -999, -999, -999, -999},
  102308. {-999, -999, -999, -999, -999, -999, -999, -106,
  102309. -100, -95, -90, -86, -81, -78, -74, -69,
  102310. -74, -74, -76, -79, -83, -84, -86, -89,
  102311. -92, -97, -93, -100, -103, -107, -110, -999,
  102312. -999, -999, -999, -999, -999, -999, -999, -999,
  102313. -999, -999, -999, -999, -999, -999, -999, -999,
  102314. -999, -999, -999, -999, -999, -999, -999, -999},
  102315. {-999, -999, -999, -999, -999, -999, -106, -100,
  102316. -95, -90, -87, -83, -80, -75, -69, -60,
  102317. -66, -66, -68, -70, -74, -78, -79, -81,
  102318. -81, -83, -84, -87, -93, -96, -99, -103,
  102319. -107, -110, -999, -999, -999, -999, -999, -999,
  102320. -999, -999, -999, -999, -999, -999, -999, -999,
  102321. -999, -999, -999, -999, -999, -999, -999, -999},
  102322. {-999, -999, -999, -999, -999, -108, -103, -98,
  102323. -93, -89, -85, -82, -78, -71, -62, -55,
  102324. -58, -58, -54, -54, -55, -59, -61, -62,
  102325. -70, -66, -66, -67, -70, -72, -75, -78,
  102326. -84, -84, -84, -88, -91, -90, -95, -98,
  102327. -102, -103, -106, -110, -999, -999, -999, -999,
  102328. -999, -999, -999, -999, -999, -999, -999, -999},
  102329. {-999, -999, -999, -999, -108, -103, -98, -94,
  102330. -90, -87, -82, -79, -73, -67, -58, -47,
  102331. -50, -45, -41, -45, -48, -44, -44, -49,
  102332. -54, -51, -48, -47, -49, -50, -51, -57,
  102333. -58, -60, -63, -69, -70, -69, -71, -74,
  102334. -78, -82, -90, -95, -101, -105, -110, -999,
  102335. -999, -999, -999, -999, -999, -999, -999, -999},
  102336. {-999, -999, -999, -105, -101, -97, -93, -90,
  102337. -85, -80, -77, -72, -65, -56, -48, -37,
  102338. -40, -36, -34, -40, -50, -47, -38, -41,
  102339. -47, -38, -35, -39, -38, -43, -40, -45,
  102340. -50, -45, -44, -47, -50, -55, -48, -48,
  102341. -52, -66, -70, -76, -82, -90, -97, -105,
  102342. -110, -999, -999, -999, -999, -999, -999, -999}},
  102343. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102344. -999, -108, -103, -98, -93, -86, -79, -76,
  102345. -83, -81, -85, -87, -89, -93, -98, -102,
  102346. -107, -112, -999, -999, -999, -999, -999, -999,
  102347. -999, -999, -999, -999, -999, -999, -999, -999,
  102348. -999, -999, -999, -999, -999, -999, -999, -999,
  102349. -999, -999, -999, -999, -999, -999, -999, -999},
  102350. {-999, -999, -999, -999, -999, -999, -999, -999,
  102351. -999, -108, -103, -98, -93, -86, -79, -71,
  102352. -77, -74, -77, -79, -81, -84, -85, -90,
  102353. -92, -93, -92, -98, -101, -108, -112, -999,
  102354. -999, -999, -999, -999, -999, -999, -999, -999,
  102355. -999, -999, -999, -999, -999, -999, -999, -999,
  102356. -999, -999, -999, -999, -999, -999, -999, -999},
  102357. {-999, -999, -999, -999, -999, -999, -999, -999,
  102358. -108, -103, -98, -93, -87, -78, -68, -65,
  102359. -66, -62, -65, -67, -70, -73, -75, -78,
  102360. -82, -82, -83, -84, -91, -93, -98, -102,
  102361. -106, -110, -999, -999, -999, -999, -999, -999,
  102362. -999, -999, -999, -999, -999, -999, -999, -999,
  102363. -999, -999, -999, -999, -999, -999, -999, -999},
  102364. {-999, -999, -999, -999, -999, -999, -999, -999,
  102365. -105, -100, -95, -90, -82, -74, -62, -57,
  102366. -58, -56, -51, -52, -52, -54, -54, -58,
  102367. -66, -59, -60, -63, -66, -69, -73, -79,
  102368. -83, -84, -80, -81, -81, -82, -88, -92,
  102369. -98, -105, -113, -999, -999, -999, -999, -999,
  102370. -999, -999, -999, -999, -999, -999, -999, -999},
  102371. {-999, -999, -999, -999, -999, -999, -999, -107,
  102372. -102, -97, -92, -84, -79, -69, -57, -47,
  102373. -52, -47, -44, -45, -50, -52, -42, -42,
  102374. -53, -43, -43, -48, -51, -56, -55, -52,
  102375. -57, -59, -61, -62, -67, -71, -78, -83,
  102376. -86, -94, -98, -103, -110, -999, -999, -999,
  102377. -999, -999, -999, -999, -999, -999, -999, -999},
  102378. {-999, -999, -999, -999, -999, -999, -105, -100,
  102379. -95, -90, -84, -78, -70, -61, -51, -41,
  102380. -40, -38, -40, -46, -52, -51, -41, -40,
  102381. -46, -40, -38, -38, -41, -46, -41, -46,
  102382. -47, -43, -43, -45, -41, -45, -56, -67,
  102383. -68, -83, -87, -90, -95, -102, -107, -113,
  102384. -999, -999, -999, -999, -999, -999, -999, -999}},
  102385. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102386. -999, -109, -105, -101, -96, -91, -84, -77,
  102387. -82, -82, -85, -89, -94, -100, -106, -110,
  102388. -999, -999, -999, -999, -999, -999, -999, -999,
  102389. -999, -999, -999, -999, -999, -999, -999, -999,
  102390. -999, -999, -999, -999, -999, -999, -999, -999,
  102391. -999, -999, -999, -999, -999, -999, -999, -999},
  102392. {-999, -999, -999, -999, -999, -999, -999, -999,
  102393. -999, -106, -103, -98, -92, -85, -80, -71,
  102394. -75, -72, -76, -80, -84, -86, -89, -93,
  102395. -100, -107, -113, -999, -999, -999, -999, -999,
  102396. -999, -999, -999, -999, -999, -999, -999, -999,
  102397. -999, -999, -999, -999, -999, -999, -999, -999,
  102398. -999, -999, -999, -999, -999, -999, -999, -999},
  102399. {-999, -999, -999, -999, -999, -999, -999, -107,
  102400. -104, -101, -97, -92, -88, -84, -80, -64,
  102401. -66, -63, -64, -66, -69, -73, -77, -83,
  102402. -83, -86, -91, -98, -104, -111, -999, -999,
  102403. -999, -999, -999, -999, -999, -999, -999, -999,
  102404. -999, -999, -999, -999, -999, -999, -999, -999,
  102405. -999, -999, -999, -999, -999, -999, -999, -999},
  102406. {-999, -999, -999, -999, -999, -999, -999, -107,
  102407. -104, -101, -97, -92, -90, -84, -74, -57,
  102408. -58, -52, -55, -54, -50, -52, -50, -52,
  102409. -63, -62, -69, -76, -77, -78, -78, -79,
  102410. -82, -88, -94, -100, -106, -111, -999, -999,
  102411. -999, -999, -999, -999, -999, -999, -999, -999,
  102412. -999, -999, -999, -999, -999, -999, -999, -999},
  102413. {-999, -999, -999, -999, -999, -999, -106, -102,
  102414. -98, -95, -90, -85, -83, -78, -70, -50,
  102415. -50, -41, -44, -49, -47, -50, -50, -44,
  102416. -55, -46, -47, -48, -48, -54, -49, -49,
  102417. -58, -62, -71, -81, -87, -92, -97, -102,
  102418. -108, -114, -999, -999, -999, -999, -999, -999,
  102419. -999, -999, -999, -999, -999, -999, -999, -999},
  102420. {-999, -999, -999, -999, -999, -999, -106, -102,
  102421. -98, -95, -90, -85, -83, -78, -70, -45,
  102422. -43, -41, -47, -50, -51, -50, -49, -45,
  102423. -47, -41, -44, -41, -39, -43, -38, -37,
  102424. -40, -41, -44, -50, -58, -65, -73, -79,
  102425. -85, -92, -97, -101, -105, -109, -113, -999,
  102426. -999, -999, -999, -999, -999, -999, -999, -999}},
  102427. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102428. -999, -999, -999, -107, -100, -95, -87, -81,
  102429. -85, -83, -88, -93, -100, -107, -114, -999,
  102430. -999, -999, -999, -999, -999, -999, -999, -999,
  102431. -999, -999, -999, -999, -999, -999, -999, -999,
  102432. -999, -999, -999, -999, -999, -999, -999, -999,
  102433. -999, -999, -999, -999, -999, -999, -999, -999},
  102434. {-999, -999, -999, -999, -999, -999, -999, -999,
  102435. -999, -999, -107, -101, -95, -88, -83, -76,
  102436. -73, -72, -79, -84, -90, -95, -100, -105,
  102437. -110, -115, -999, -999, -999, -999, -999, -999,
  102438. -999, -999, -999, -999, -999, -999, -999, -999,
  102439. -999, -999, -999, -999, -999, -999, -999, -999,
  102440. -999, -999, -999, -999, -999, -999, -999, -999},
  102441. {-999, -999, -999, -999, -999, -999, -999, -999,
  102442. -999, -999, -104, -98, -92, -87, -81, -70,
  102443. -65, -62, -67, -71, -74, -80, -85, -91,
  102444. -95, -99, -103, -108, -111, -114, -999, -999,
  102445. -999, -999, -999, -999, -999, -999, -999, -999,
  102446. -999, -999, -999, -999, -999, -999, -999, -999,
  102447. -999, -999, -999, -999, -999, -999, -999, -999},
  102448. {-999, -999, -999, -999, -999, -999, -999, -999,
  102449. -999, -999, -103, -97, -90, -85, -76, -60,
  102450. -56, -54, -60, -62, -61, -56, -63, -65,
  102451. -73, -74, -77, -75, -78, -81, -86, -87,
  102452. -88, -91, -94, -98, -103, -110, -999, -999,
  102453. -999, -999, -999, -999, -999, -999, -999, -999,
  102454. -999, -999, -999, -999, -999, -999, -999, -999},
  102455. {-999, -999, -999, -999, -999, -999, -999, -105,
  102456. -100, -97, -92, -86, -81, -79, -70, -57,
  102457. -51, -47, -51, -58, -60, -56, -53, -50,
  102458. -58, -52, -50, -50, -53, -55, -64, -69,
  102459. -71, -85, -82, -78, -81, -85, -95, -102,
  102460. -112, -999, -999, -999, -999, -999, -999, -999,
  102461. -999, -999, -999, -999, -999, -999, -999, -999},
  102462. {-999, -999, -999, -999, -999, -999, -999, -105,
  102463. -100, -97, -92, -85, -83, -79, -72, -49,
  102464. -40, -43, -43, -54, -56, -51, -50, -40,
  102465. -43, -38, -36, -35, -37, -38, -37, -44,
  102466. -54, -60, -57, -60, -70, -75, -84, -92,
  102467. -103, -112, -999, -999, -999, -999, -999, -999,
  102468. -999, -999, -999, -999, -999, -999, -999, -999}},
  102469. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102470. -999, -999, -999, -110, -102, -95, -89, -82,
  102471. -83, -84, -90, -92, -99, -107, -113, -999,
  102472. -999, -999, -999, -999, -999, -999, -999, -999,
  102473. -999, -999, -999, -999, -999, -999, -999, -999,
  102474. -999, -999, -999, -999, -999, -999, -999, -999,
  102475. -999, -999, -999, -999, -999, -999, -999, -999},
  102476. {-999, -999, -999, -999, -999, -999, -999, -999,
  102477. -999, -999, -107, -101, -95, -89, -83, -72,
  102478. -74, -78, -85, -88, -88, -90, -92, -98,
  102479. -105, -111, -999, -999, -999, -999, -999, -999,
  102480. -999, -999, -999, -999, -999, -999, -999, -999,
  102481. -999, -999, -999, -999, -999, -999, -999, -999,
  102482. -999, -999, -999, -999, -999, -999, -999, -999},
  102483. {-999, -999, -999, -999, -999, -999, -999, -999,
  102484. -999, -109, -103, -97, -93, -87, -81, -70,
  102485. -70, -67, -75, -73, -76, -79, -81, -83,
  102486. -88, -89, -97, -103, -110, -999, -999, -999,
  102487. -999, -999, -999, -999, -999, -999, -999, -999,
  102488. -999, -999, -999, -999, -999, -999, -999, -999,
  102489. -999, -999, -999, -999, -999, -999, -999, -999},
  102490. {-999, -999, -999, -999, -999, -999, -999, -999,
  102491. -999, -107, -100, -94, -88, -83, -75, -63,
  102492. -59, -59, -63, -66, -60, -62, -67, -67,
  102493. -77, -76, -81, -88, -86, -92, -96, -102,
  102494. -109, -116, -999, -999, -999, -999, -999, -999,
  102495. -999, -999, -999, -999, -999, -999, -999, -999,
  102496. -999, -999, -999, -999, -999, -999, -999, -999},
  102497. {-999, -999, -999, -999, -999, -999, -999, -999,
  102498. -999, -105, -98, -92, -86, -81, -73, -56,
  102499. -52, -47, -55, -60, -58, -52, -51, -45,
  102500. -49, -50, -53, -54, -61, -71, -70, -69,
  102501. -78, -79, -87, -90, -96, -104, -112, -999,
  102502. -999, -999, -999, -999, -999, -999, -999, -999,
  102503. -999, -999, -999, -999, -999, -999, -999, -999},
  102504. {-999, -999, -999, -999, -999, -999, -999, -999,
  102505. -999, -103, -96, -90, -86, -78, -70, -51,
  102506. -42, -47, -48, -55, -54, -54, -53, -42,
  102507. -35, -28, -33, -38, -37, -44, -47, -49,
  102508. -54, -63, -68, -78, -82, -89, -94, -99,
  102509. -104, -109, -114, -999, -999, -999, -999, -999,
  102510. -999, -999, -999, -999, -999, -999, -999, -999}},
  102511. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102512. -999, -999, -999, -999, -110, -100, -90, -79,
  102513. -85, -81, -82, -82, -89, -94, -99, -103,
  102514. -109, -115, -999, -999, -999, -999, -999, -999,
  102515. -999, -999, -999, -999, -999, -999, -999, -999,
  102516. -999, -999, -999, -999, -999, -999, -999, -999,
  102517. -999, -999, -999, -999, -999, -999, -999, -999},
  102518. {-999, -999, -999, -999, -999, -999, -999, -999,
  102519. -999, -999, -999, -999, -105, -97, -85, -72,
  102520. -74, -70, -70, -70, -76, -85, -91, -93,
  102521. -97, -103, -109, -115, -999, -999, -999, -999,
  102522. -999, -999, -999, -999, -999, -999, -999, -999,
  102523. -999, -999, -999, -999, -999, -999, -999, -999,
  102524. -999, -999, -999, -999, -999, -999, -999, -999},
  102525. {-999, -999, -999, -999, -999, -999, -999, -999,
  102526. -999, -999, -999, -999, -112, -93, -81, -68,
  102527. -62, -60, -60, -57, -63, -70, -77, -82,
  102528. -90, -93, -98, -104, -109, -113, -999, -999,
  102529. -999, -999, -999, -999, -999, -999, -999, -999,
  102530. -999, -999, -999, -999, -999, -999, -999, -999,
  102531. -999, -999, -999, -999, -999, -999, -999, -999},
  102532. {-999, -999, -999, -999, -999, -999, -999, -999,
  102533. -999, -999, -999, -113, -100, -93, -84, -63,
  102534. -58, -48, -53, -54, -52, -52, -57, -64,
  102535. -66, -76, -83, -81, -85, -85, -90, -95,
  102536. -98, -101, -103, -106, -108, -111, -999, -999,
  102537. -999, -999, -999, -999, -999, -999, -999, -999,
  102538. -999, -999, -999, -999, -999, -999, -999, -999},
  102539. {-999, -999, -999, -999, -999, -999, -999, -999,
  102540. -999, -999, -999, -105, -95, -86, -74, -53,
  102541. -50, -38, -43, -49, -43, -42, -39, -39,
  102542. -46, -52, -57, -56, -72, -69, -74, -81,
  102543. -87, -92, -94, -97, -99, -102, -105, -108,
  102544. -999, -999, -999, -999, -999, -999, -999, -999,
  102545. -999, -999, -999, -999, -999, -999, -999, -999},
  102546. {-999, -999, -999, -999, -999, -999, -999, -999,
  102547. -999, -999, -108, -99, -90, -76, -66, -45,
  102548. -43, -41, -44, -47, -43, -47, -40, -30,
  102549. -31, -31, -39, -33, -40, -41, -43, -53,
  102550. -59, -70, -73, -77, -79, -82, -84, -87,
  102551. -999, -999, -999, -999, -999, -999, -999, -999,
  102552. -999, -999, -999, -999, -999, -999, -999, -999}},
  102553. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102554. -999, -999, -999, -999, -999, -110, -91, -76,
  102555. -75, -85, -93, -98, -104, -110, -999, -999,
  102556. -999, -999, -999, -999, -999, -999, -999, -999,
  102557. -999, -999, -999, -999, -999, -999, -999, -999,
  102558. -999, -999, -999, -999, -999, -999, -999, -999,
  102559. -999, -999, -999, -999, -999, -999, -999, -999},
  102560. {-999, -999, -999, -999, -999, -999, -999, -999,
  102561. -999, -999, -999, -999, -999, -110, -91, -70,
  102562. -70, -75, -86, -89, -94, -98, -101, -106,
  102563. -110, -999, -999, -999, -999, -999, -999, -999,
  102564. -999, -999, -999, -999, -999, -999, -999, -999,
  102565. -999, -999, -999, -999, -999, -999, -999, -999,
  102566. -999, -999, -999, -999, -999, -999, -999, -999},
  102567. {-999, -999, -999, -999, -999, -999, -999, -999,
  102568. -999, -999, -999, -999, -110, -95, -80, -60,
  102569. -65, -64, -74, -83, -88, -91, -95, -99,
  102570. -103, -107, -110, -999, -999, -999, -999, -999,
  102571. -999, -999, -999, -999, -999, -999, -999, -999,
  102572. -999, -999, -999, -999, -999, -999, -999, -999,
  102573. -999, -999, -999, -999, -999, -999, -999, -999},
  102574. {-999, -999, -999, -999, -999, -999, -999, -999,
  102575. -999, -999, -999, -999, -110, -95, -80, -58,
  102576. -55, -49, -66, -68, -71, -78, -78, -80,
  102577. -88, -85, -89, -97, -100, -105, -110, -999,
  102578. -999, -999, -999, -999, -999, -999, -999, -999,
  102579. -999, -999, -999, -999, -999, -999, -999, -999,
  102580. -999, -999, -999, -999, -999, -999, -999, -999},
  102581. {-999, -999, -999, -999, -999, -999, -999, -999,
  102582. -999, -999, -999, -999, -110, -95, -80, -53,
  102583. -52, -41, -59, -59, -49, -58, -56, -63,
  102584. -86, -79, -90, -93, -98, -103, -107, -112,
  102585. -999, -999, -999, -999, -999, -999, -999, -999,
  102586. -999, -999, -999, -999, -999, -999, -999, -999,
  102587. -999, -999, -999, -999, -999, -999, -999, -999},
  102588. {-999, -999, -999, -999, -999, -999, -999, -999,
  102589. -999, -999, -999, -110, -97, -91, -73, -45,
  102590. -40, -33, -53, -61, -49, -54, -50, -50,
  102591. -60, -52, -67, -74, -81, -92, -96, -100,
  102592. -105, -110, -999, -999, -999, -999, -999, -999,
  102593. -999, -999, -999, -999, -999, -999, -999, -999,
  102594. -999, -999, -999, -999, -999, -999, -999, -999}},
  102595. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102596. -999, -999, -999, -113, -106, -99, -92, -77,
  102597. -80, -88, -97, -106, -115, -999, -999, -999,
  102598. -999, -999, -999, -999, -999, -999, -999, -999,
  102599. -999, -999, -999, -999, -999, -999, -999, -999,
  102600. -999, -999, -999, -999, -999, -999, -999, -999,
  102601. -999, -999, -999, -999, -999, -999, -999, -999},
  102602. {-999, -999, -999, -999, -999, -999, -999, -999,
  102603. -999, -999, -116, -109, -102, -95, -89, -74,
  102604. -72, -88, -87, -95, -102, -109, -116, -999,
  102605. -999, -999, -999, -999, -999, -999, -999, -999,
  102606. -999, -999, -999, -999, -999, -999, -999, -999,
  102607. -999, -999, -999, -999, -999, -999, -999, -999,
  102608. -999, -999, -999, -999, -999, -999, -999, -999},
  102609. {-999, -999, -999, -999, -999, -999, -999, -999,
  102610. -999, -999, -116, -109, -102, -95, -89, -75,
  102611. -66, -74, -77, -78, -86, -87, -90, -96,
  102612. -105, -115, -999, -999, -999, -999, -999, -999,
  102613. -999, -999, -999, -999, -999, -999, -999, -999,
  102614. -999, -999, -999, -999, -999, -999, -999, -999,
  102615. -999, -999, -999, -999, -999, -999, -999, -999},
  102616. {-999, -999, -999, -999, -999, -999, -999, -999,
  102617. -999, -999, -115, -108, -101, -94, -88, -66,
  102618. -56, -61, -70, -65, -78, -72, -83, -84,
  102619. -93, -98, -105, -110, -999, -999, -999, -999,
  102620. -999, -999, -999, -999, -999, -999, -999, -999,
  102621. -999, -999, -999, -999, -999, -999, -999, -999,
  102622. -999, -999, -999, -999, -999, -999, -999, -999},
  102623. {-999, -999, -999, -999, -999, -999, -999, -999,
  102624. -999, -999, -110, -105, -95, -89, -82, -57,
  102625. -52, -52, -59, -56, -59, -58, -69, -67,
  102626. -88, -82, -82, -89, -94, -100, -108, -999,
  102627. -999, -999, -999, -999, -999, -999, -999, -999,
  102628. -999, -999, -999, -999, -999, -999, -999, -999,
  102629. -999, -999, -999, -999, -999, -999, -999, -999},
  102630. {-999, -999, -999, -999, -999, -999, -999, -999,
  102631. -999, -110, -101, -96, -90, -83, -77, -54,
  102632. -43, -38, -50, -48, -52, -48, -42, -42,
  102633. -51, -52, -53, -59, -65, -71, -78, -85,
  102634. -95, -999, -999, -999, -999, -999, -999, -999,
  102635. -999, -999, -999, -999, -999, -999, -999, -999,
  102636. -999, -999, -999, -999, -999, -999, -999, -999}},
  102637. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102638. -999, -999, -999, -999, -120, -105, -86, -68,
  102639. -78, -79, -90, -100, -110, -999, -999, -999,
  102640. -999, -999, -999, -999, -999, -999, -999, -999,
  102641. -999, -999, -999, -999, -999, -999, -999, -999,
  102642. -999, -999, -999, -999, -999, -999, -999, -999,
  102643. -999, -999, -999, -999, -999, -999, -999, -999},
  102644. {-999, -999, -999, -999, -999, -999, -999, -999,
  102645. -999, -999, -999, -999, -120, -105, -86, -66,
  102646. -73, -77, -88, -96, -105, -115, -999, -999,
  102647. -999, -999, -999, -999, -999, -999, -999, -999,
  102648. -999, -999, -999, -999, -999, -999, -999, -999,
  102649. -999, -999, -999, -999, -999, -999, -999, -999,
  102650. -999, -999, -999, -999, -999, -999, -999, -999},
  102651. {-999, -999, -999, -999, -999, -999, -999, -999,
  102652. -999, -999, -999, -120, -105, -92, -80, -61,
  102653. -64, -68, -80, -87, -92, -100, -110, -999,
  102654. -999, -999, -999, -999, -999, -999, -999, -999,
  102655. -999, -999, -999, -999, -999, -999, -999, -999,
  102656. -999, -999, -999, -999, -999, -999, -999, -999,
  102657. -999, -999, -999, -999, -999, -999, -999, -999},
  102658. {-999, -999, -999, -999, -999, -999, -999, -999,
  102659. -999, -999, -999, -120, -104, -91, -79, -52,
  102660. -60, -54, -64, -69, -77, -80, -82, -84,
  102661. -85, -87, -88, -90, -999, -999, -999, -999,
  102662. -999, -999, -999, -999, -999, -999, -999, -999,
  102663. -999, -999, -999, -999, -999, -999, -999, -999,
  102664. -999, -999, -999, -999, -999, -999, -999, -999},
  102665. {-999, -999, -999, -999, -999, -999, -999, -999,
  102666. -999, -999, -999, -118, -100, -87, -77, -49,
  102667. -50, -44, -58, -61, -61, -67, -65, -62,
  102668. -62, -62, -65, -68, -999, -999, -999, -999,
  102669. -999, -999, -999, -999, -999, -999, -999, -999,
  102670. -999, -999, -999, -999, -999, -999, -999, -999,
  102671. -999, -999, -999, -999, -999, -999, -999, -999},
  102672. {-999, -999, -999, -999, -999, -999, -999, -999,
  102673. -999, -999, -999, -115, -98, -84, -62, -49,
  102674. -44, -38, -46, -49, -49, -46, -39, -37,
  102675. -39, -40, -42, -43, -999, -999, -999, -999,
  102676. -999, -999, -999, -999, -999, -999, -999, -999,
  102677. -999, -999, -999, -999, -999, -999, -999, -999,
  102678. -999, -999, -999, -999, -999, -999, -999, -999}},
  102679. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102680. -999, -999, -999, -999, -999, -110, -88, -74,
  102681. -77, -82, -82, -85, -90, -94, -99, -104,
  102682. -999, -999, -999, -999, -999, -999, -999, -999,
  102683. -999, -999, -999, -999, -999, -999, -999, -999,
  102684. -999, -999, -999, -999, -999, -999, -999, -999,
  102685. -999, -999, -999, -999, -999, -999, -999, -999},
  102686. {-999, -999, -999, -999, -999, -999, -999, -999,
  102687. -999, -999, -999, -999, -999, -110, -88, -66,
  102688. -70, -81, -80, -81, -84, -88, -91, -93,
  102689. -999, -999, -999, -999, -999, -999, -999, -999,
  102690. -999, -999, -999, -999, -999, -999, -999, -999,
  102691. -999, -999, -999, -999, -999, -999, -999, -999,
  102692. -999, -999, -999, -999, -999, -999, -999, -999},
  102693. {-999, -999, -999, -999, -999, -999, -999, -999,
  102694. -999, -999, -999, -999, -999, -110, -88, -61,
  102695. -63, -70, -71, -74, -77, -80, -83, -85,
  102696. -999, -999, -999, -999, -999, -999, -999, -999,
  102697. -999, -999, -999, -999, -999, -999, -999, -999,
  102698. -999, -999, -999, -999, -999, -999, -999, -999,
  102699. -999, -999, -999, -999, -999, -999, -999, -999},
  102700. {-999, -999, -999, -999, -999, -999, -999, -999,
  102701. -999, -999, -999, -999, -999, -110, -86, -62,
  102702. -63, -62, -62, -58, -52, -50, -50, -52,
  102703. -54, -999, -999, -999, -999, -999, -999, -999,
  102704. -999, -999, -999, -999, -999, -999, -999, -999,
  102705. -999, -999, -999, -999, -999, -999, -999, -999,
  102706. -999, -999, -999, -999, -999, -999, -999, -999},
  102707. {-999, -999, -999, -999, -999, -999, -999, -999,
  102708. -999, -999, -999, -999, -118, -108, -84, -53,
  102709. -50, -50, -50, -55, -47, -45, -40, -40,
  102710. -40, -999, -999, -999, -999, -999, -999, -999,
  102711. -999, -999, -999, -999, -999, -999, -999, -999,
  102712. -999, -999, -999, -999, -999, -999, -999, -999,
  102713. -999, -999, -999, -999, -999, -999, -999, -999},
  102714. {-999, -999, -999, -999, -999, -999, -999, -999,
  102715. -999, -999, -999, -999, -118, -100, -73, -43,
  102716. -37, -42, -43, -53, -38, -37, -35, -35,
  102717. -38, -999, -999, -999, -999, -999, -999, -999,
  102718. -999, -999, -999, -999, -999, -999, -999, -999,
  102719. -999, -999, -999, -999, -999, -999, -999, -999,
  102720. -999, -999, -999, -999, -999, -999, -999, -999}},
  102721. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102722. -999, -999, -999, -110, -100, -91, -84, -74,
  102723. -80, -80, -80, -80, -80, -999, -999, -999,
  102724. -999, -999, -999, -999, -999, -999, -999, -999,
  102725. -999, -999, -999, -999, -999, -999, -999, -999,
  102726. -999, -999, -999, -999, -999, -999, -999, -999,
  102727. -999, -999, -999, -999, -999, -999, -999, -999},
  102728. {-999, -999, -999, -999, -999, -999, -999, -999,
  102729. -999, -999, -999, -110, -100, -91, -84, -74,
  102730. -68, -68, -68, -68, -68, -999, -999, -999,
  102731. -999, -999, -999, -999, -999, -999, -999, -999,
  102732. -999, -999, -999, -999, -999, -999, -999, -999,
  102733. -999, -999, -999, -999, -999, -999, -999, -999,
  102734. -999, -999, -999, -999, -999, -999, -999, -999},
  102735. {-999, -999, -999, -999, -999, -999, -999, -999,
  102736. -999, -999, -999, -110, -100, -86, -78, -70,
  102737. -60, -45, -30, -21, -999, -999, -999, -999,
  102738. -999, -999, -999, -999, -999, -999, -999, -999,
  102739. -999, -999, -999, -999, -999, -999, -999, -999,
  102740. -999, -999, -999, -999, -999, -999, -999, -999,
  102741. -999, -999, -999, -999, -999, -999, -999, -999},
  102742. {-999, -999, -999, -999, -999, -999, -999, -999,
  102743. -999, -999, -999, -110, -100, -87, -78, -67,
  102744. -48, -38, -29, -21, -999, -999, -999, -999,
  102745. -999, -999, -999, -999, -999, -999, -999, -999,
  102746. -999, -999, -999, -999, -999, -999, -999, -999,
  102747. -999, -999, -999, -999, -999, -999, -999, -999,
  102748. -999, -999, -999, -999, -999, -999, -999, -999},
  102749. {-999, -999, -999, -999, -999, -999, -999, -999,
  102750. -999, -999, -999, -110, -100, -86, -69, -56,
  102751. -45, -35, -33, -29, -999, -999, -999, -999,
  102752. -999, -999, -999, -999, -999, -999, -999, -999,
  102753. -999, -999, -999, -999, -999, -999, -999, -999,
  102754. -999, -999, -999, -999, -999, -999, -999, -999,
  102755. -999, -999, -999, -999, -999, -999, -999, -999},
  102756. {-999, -999, -999, -999, -999, -999, -999, -999,
  102757. -999, -999, -999, -110, -100, -83, -71, -48,
  102758. -27, -38, -37, -34, -999, -999, -999, -999,
  102759. -999, -999, -999, -999, -999, -999, -999, -999,
  102760. -999, -999, -999, -999, -999, -999, -999, -999,
  102761. -999, -999, -999, -999, -999, -999, -999, -999,
  102762. -999, -999, -999, -999, -999, -999, -999, -999}}
  102763. };
  102764. #endif
  102765. /*** End of inlined file: masking.h ***/
  102766. #define NEGINF -9999.f
  102767. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  102768. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  102769. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  102770. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102771. vorbis_info_psy_global *gi=&ci->psy_g_param;
  102772. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  102773. look->channels=vi->channels;
  102774. look->ampmax=-9999.;
  102775. look->gi=gi;
  102776. return(look);
  102777. }
  102778. void _vp_global_free(vorbis_look_psy_global *look){
  102779. if(look){
  102780. memset(look,0,sizeof(*look));
  102781. _ogg_free(look);
  102782. }
  102783. }
  102784. void _vi_gpsy_free(vorbis_info_psy_global *i){
  102785. if(i){
  102786. memset(i,0,sizeof(*i));
  102787. _ogg_free(i);
  102788. }
  102789. }
  102790. void _vi_psy_free(vorbis_info_psy *i){
  102791. if(i){
  102792. memset(i,0,sizeof(*i));
  102793. _ogg_free(i);
  102794. }
  102795. }
  102796. static void min_curve(float *c,
  102797. float *c2){
  102798. int i;
  102799. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  102800. }
  102801. static void max_curve(float *c,
  102802. float *c2){
  102803. int i;
  102804. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  102805. }
  102806. static void attenuate_curve(float *c,float att){
  102807. int i;
  102808. for(i=0;i<EHMER_MAX;i++)
  102809. c[i]+=att;
  102810. }
  102811. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  102812. float center_boost, float center_decay_rate){
  102813. int i,j,k,m;
  102814. float ath[EHMER_MAX];
  102815. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  102816. float athc[P_LEVELS][EHMER_MAX];
  102817. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  102818. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  102819. memset(workc,0,sizeof(workc));
  102820. for(i=0;i<P_BANDS;i++){
  102821. int ath_offset=i*4;
  102822. for(j=0;j<EHMER_MAX;j++){
  102823. float min=999.;
  102824. for(k=0;k<4;k++)
  102825. if(j+k+ath_offset<MAX_ATH){
  102826. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  102827. }else{
  102828. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  102829. }
  102830. ath[j]=min;
  102831. }
  102832. for(j=0;j<6;j++)
  102833. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  102834. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  102835. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  102836. for(j=0;j<P_LEVELS;j++){
  102837. for(k=0;k<EHMER_MAX;k++){
  102838. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  102839. if(adj<0. && center_boost>0)adj=0.;
  102840. if(adj>0. && center_boost<0)adj=0.;
  102841. workc[i][j][k]+=adj;
  102842. }
  102843. }
  102844. for(j=0;j<P_LEVELS;j++){
  102845. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  102846. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  102847. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  102848. max_curve(athc[j],workc[i][j]);
  102849. }
  102850. for(j=1;j<P_LEVELS;j++){
  102851. min_curve(athc[j],athc[j-1]);
  102852. min_curve(workc[i][j],athc[j]);
  102853. }
  102854. }
  102855. for(i=0;i<P_BANDS;i++){
  102856. int hi_curve,lo_curve,bin;
  102857. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  102858. bin=floor(fromOC(i*.5)/binHz);
  102859. lo_curve= ceil(toOC(bin*binHz+1)*2);
  102860. hi_curve= floor(toOC((bin+1)*binHz)*2);
  102861. if(lo_curve>i)lo_curve=i;
  102862. if(lo_curve<0)lo_curve=0;
  102863. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  102864. for(m=0;m<P_LEVELS;m++){
  102865. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  102866. for(j=0;j<n;j++)brute_buffer[j]=999.;
  102867. for(k=lo_curve;k<=hi_curve;k++){
  102868. int l=0;
  102869. for(j=0;j<EHMER_MAX;j++){
  102870. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  102871. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  102872. if(lo_bin<0)lo_bin=0;
  102873. if(lo_bin>n)lo_bin=n;
  102874. if(lo_bin<l)l=lo_bin;
  102875. if(hi_bin<0)hi_bin=0;
  102876. if(hi_bin>n)hi_bin=n;
  102877. for(;l<hi_bin && l<n;l++)
  102878. if(brute_buffer[l]>workc[k][m][j])
  102879. brute_buffer[l]=workc[k][m][j];
  102880. }
  102881. for(;l<n;l++)
  102882. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  102883. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  102884. }
  102885. if(i+1<P_BANDS){
  102886. int l=0;
  102887. k=i+1;
  102888. for(j=0;j<EHMER_MAX;j++){
  102889. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  102890. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  102891. if(lo_bin<0)lo_bin=0;
  102892. if(lo_bin>n)lo_bin=n;
  102893. if(lo_bin<l)l=lo_bin;
  102894. if(hi_bin<0)hi_bin=0;
  102895. if(hi_bin>n)hi_bin=n;
  102896. for(;l<hi_bin && l<n;l++)
  102897. if(brute_buffer[l]>workc[k][m][j])
  102898. brute_buffer[l]=workc[k][m][j];
  102899. }
  102900. for(;l<n;l++)
  102901. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  102902. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  102903. }
  102904. for(j=0;j<EHMER_MAX;j++){
  102905. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  102906. if(bin<0){
  102907. ret[i][m][j+2]=-999.;
  102908. }else{
  102909. if(bin>=n){
  102910. ret[i][m][j+2]=-999.;
  102911. }else{
  102912. ret[i][m][j+2]=brute_buffer[bin];
  102913. }
  102914. }
  102915. }
  102916. for(j=0;j<EHMER_OFFSET;j++)
  102917. if(ret[i][m][j+2]>-200.f)break;
  102918. ret[i][m][0]=j;
  102919. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  102920. if(ret[i][m][j+2]>-200.f)
  102921. break;
  102922. ret[i][m][1]=j;
  102923. }
  102924. }
  102925. return(ret);
  102926. }
  102927. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  102928. vorbis_info_psy_global *gi,int n,long rate){
  102929. long i,j,lo=-99,hi=1;
  102930. long maxoc;
  102931. memset(p,0,sizeof(*p));
  102932. p->eighth_octave_lines=gi->eighth_octave_lines;
  102933. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  102934. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  102935. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  102936. p->total_octave_lines=maxoc-p->firstoc+1;
  102937. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  102938. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  102939. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  102940. p->vi=vi;
  102941. p->n=n;
  102942. p->rate=rate;
  102943. p->m_val = 1.;
  102944. if(rate < 26000) p->m_val = 0;
  102945. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  102946. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  102947. for(i=0,j=0;i<MAX_ATH-1;i++){
  102948. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  102949. float base=ATH[i];
  102950. if(j<endpos){
  102951. float delta=(ATH[i+1]-base)/(endpos-j);
  102952. for(;j<endpos && j<n;j++){
  102953. p->ath[j]=base+100.;
  102954. base+=delta;
  102955. }
  102956. }
  102957. }
  102958. for(i=0;i<n;i++){
  102959. float bark=toBARK(rate/(2*n)*i);
  102960. for(;lo+vi->noisewindowlomin<i &&
  102961. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  102962. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  102963. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  102964. p->bark[i]=((lo-1)<<16)+(hi-1);
  102965. }
  102966. for(i=0;i<n;i++)
  102967. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  102968. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  102969. vi->tone_centerboost,vi->tone_decay);
  102970. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  102971. for(i=0;i<P_NOISECURVES;i++)
  102972. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  102973. for(i=0;i<n;i++){
  102974. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  102975. int inthalfoc;
  102976. float del;
  102977. if(halfoc<0)halfoc=0;
  102978. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  102979. inthalfoc=(int)halfoc;
  102980. del=halfoc-inthalfoc;
  102981. for(j=0;j<P_NOISECURVES;j++)
  102982. p->noiseoffset[j][i]=
  102983. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  102984. p->vi->noiseoff[j][inthalfoc+1]*del;
  102985. }
  102986. #if 0
  102987. {
  102988. static int ls=0;
  102989. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  102990. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  102991. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  102992. }
  102993. #endif
  102994. }
  102995. void _vp_psy_clear(vorbis_look_psy *p){
  102996. int i,j;
  102997. if(p){
  102998. if(p->ath)_ogg_free(p->ath);
  102999. if(p->octave)_ogg_free(p->octave);
  103000. if(p->bark)_ogg_free(p->bark);
  103001. if(p->tonecurves){
  103002. for(i=0;i<P_BANDS;i++){
  103003. for(j=0;j<P_LEVELS;j++){
  103004. _ogg_free(p->tonecurves[i][j]);
  103005. }
  103006. _ogg_free(p->tonecurves[i]);
  103007. }
  103008. _ogg_free(p->tonecurves);
  103009. }
  103010. if(p->noiseoffset){
  103011. for(i=0;i<P_NOISECURVES;i++){
  103012. _ogg_free(p->noiseoffset[i]);
  103013. }
  103014. _ogg_free(p->noiseoffset);
  103015. }
  103016. memset(p,0,sizeof(*p));
  103017. }
  103018. }
  103019. static void seed_curve(float *seed,
  103020. const float **curves,
  103021. float amp,
  103022. int oc, int n,
  103023. int linesper,float dBoffset){
  103024. int i,post1;
  103025. int seedptr;
  103026. const float *posts,*curve;
  103027. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103028. choice=max(choice,0);
  103029. choice=min(choice,P_LEVELS-1);
  103030. posts=curves[choice];
  103031. curve=posts+2;
  103032. post1=(int)posts[1];
  103033. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103034. for(i=posts[0];i<post1;i++){
  103035. if(seedptr>0){
  103036. float lin=amp+curve[i];
  103037. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103038. }
  103039. seedptr+=linesper;
  103040. if(seedptr>=n)break;
  103041. }
  103042. }
  103043. static void seed_loop(vorbis_look_psy *p,
  103044. const float ***curves,
  103045. const float *f,
  103046. const float *flr,
  103047. float *seed,
  103048. float specmax){
  103049. vorbis_info_psy *vi=p->vi;
  103050. long n=p->n,i;
  103051. float dBoffset=vi->max_curve_dB-specmax;
  103052. for(i=0;i<n;i++){
  103053. float max=f[i];
  103054. long oc=p->octave[i];
  103055. while(i+1<n && p->octave[i+1]==oc){
  103056. i++;
  103057. if(f[i]>max)max=f[i];
  103058. }
  103059. if(max+6.f>flr[i]){
  103060. oc=oc>>p->shiftoc;
  103061. if(oc>=P_BANDS)oc=P_BANDS-1;
  103062. if(oc<0)oc=0;
  103063. seed_curve(seed,
  103064. curves[oc],
  103065. max,
  103066. p->octave[i]-p->firstoc,
  103067. p->total_octave_lines,
  103068. p->eighth_octave_lines,
  103069. dBoffset);
  103070. }
  103071. }
  103072. }
  103073. static void seed_chase(float *seeds, int linesper, long n){
  103074. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103075. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103076. long stack=0;
  103077. long pos=0;
  103078. long i;
  103079. for(i=0;i<n;i++){
  103080. if(stack<2){
  103081. posstack[stack]=i;
  103082. ampstack[stack++]=seeds[i];
  103083. }else{
  103084. while(1){
  103085. if(seeds[i]<ampstack[stack-1]){
  103086. posstack[stack]=i;
  103087. ampstack[stack++]=seeds[i];
  103088. break;
  103089. }else{
  103090. if(i<posstack[stack-1]+linesper){
  103091. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103092. i<posstack[stack-2]+linesper){
  103093. stack--;
  103094. continue;
  103095. }
  103096. }
  103097. posstack[stack]=i;
  103098. ampstack[stack++]=seeds[i];
  103099. break;
  103100. }
  103101. }
  103102. }
  103103. }
  103104. for(i=0;i<stack;i++){
  103105. long endpos;
  103106. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103107. endpos=posstack[i+1];
  103108. }else{
  103109. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103110. discarded in short frames */
  103111. }
  103112. if(endpos>n)endpos=n;
  103113. for(;pos<endpos;pos++)
  103114. seeds[pos]=ampstack[i];
  103115. }
  103116. }
  103117. #include<stdio.h>
  103118. static void max_seeds(vorbis_look_psy *p,
  103119. float *seed,
  103120. float *flr){
  103121. long n=p->total_octave_lines;
  103122. int linesper=p->eighth_octave_lines;
  103123. long linpos=0;
  103124. long pos;
  103125. seed_chase(seed,linesper,n); /* for masking */
  103126. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103127. while(linpos+1<p->n){
  103128. float minV=seed[pos];
  103129. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103130. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103131. while(pos+1<=end){
  103132. pos++;
  103133. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103134. minV=seed[pos];
  103135. }
  103136. end=pos+p->firstoc;
  103137. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103138. if(flr[linpos]<minV)flr[linpos]=minV;
  103139. }
  103140. {
  103141. float minV=seed[p->total_octave_lines-1];
  103142. for(;linpos<p->n;linpos++)
  103143. if(flr[linpos]<minV)flr[linpos]=minV;
  103144. }
  103145. }
  103146. static void bark_noise_hybridmp(int n,const long *b,
  103147. const float *f,
  103148. float *noise,
  103149. const float offset,
  103150. const int fixed){
  103151. float *N=(float*) alloca(n*sizeof(*N));
  103152. float *X=(float*) alloca(n*sizeof(*N));
  103153. float *XX=(float*) alloca(n*sizeof(*N));
  103154. float *Y=(float*) alloca(n*sizeof(*N));
  103155. float *XY=(float*) alloca(n*sizeof(*N));
  103156. float tN, tX, tXX, tY, tXY;
  103157. int i;
  103158. int lo, hi;
  103159. float R, A, B, D;
  103160. float w, x, y;
  103161. tN = tX = tXX = tY = tXY = 0.f;
  103162. y = f[0] + offset;
  103163. if (y < 1.f) y = 1.f;
  103164. w = y * y * .5;
  103165. tN += w;
  103166. tX += w;
  103167. tY += w * y;
  103168. N[0] = tN;
  103169. X[0] = tX;
  103170. XX[0] = tXX;
  103171. Y[0] = tY;
  103172. XY[0] = tXY;
  103173. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103174. y = f[i] + offset;
  103175. if (y < 1.f) y = 1.f;
  103176. w = y * y;
  103177. tN += w;
  103178. tX += w * x;
  103179. tXX += w * x * x;
  103180. tY += w * y;
  103181. tXY += w * x * y;
  103182. N[i] = tN;
  103183. X[i] = tX;
  103184. XX[i] = tXX;
  103185. Y[i] = tY;
  103186. XY[i] = tXY;
  103187. }
  103188. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103189. lo = b[i] >> 16;
  103190. if( lo>=0 ) break;
  103191. hi = b[i] & 0xffff;
  103192. tN = N[hi] + N[-lo];
  103193. tX = X[hi] - X[-lo];
  103194. tXX = XX[hi] + XX[-lo];
  103195. tY = Y[hi] + Y[-lo];
  103196. tXY = XY[hi] - XY[-lo];
  103197. A = tY * tXX - tX * tXY;
  103198. B = tN * tXY - tX * tY;
  103199. D = tN * tXX - tX * tX;
  103200. R = (A + x * B) / D;
  103201. if (R < 0.f)
  103202. R = 0.f;
  103203. noise[i] = R - offset;
  103204. }
  103205. for ( ;; i++, x += 1.f) {
  103206. lo = b[i] >> 16;
  103207. hi = b[i] & 0xffff;
  103208. if(hi>=n)break;
  103209. tN = N[hi] - N[lo];
  103210. tX = X[hi] - X[lo];
  103211. tXX = XX[hi] - XX[lo];
  103212. tY = Y[hi] - Y[lo];
  103213. tXY = XY[hi] - XY[lo];
  103214. A = tY * tXX - tX * tXY;
  103215. B = tN * tXY - tX * tY;
  103216. D = tN * tXX - tX * tX;
  103217. R = (A + x * B) / D;
  103218. if (R < 0.f) R = 0.f;
  103219. noise[i] = R - offset;
  103220. }
  103221. for ( ; i < n; i++, x += 1.f) {
  103222. R = (A + x * B) / D;
  103223. if (R < 0.f) R = 0.f;
  103224. noise[i] = R - offset;
  103225. }
  103226. if (fixed <= 0) return;
  103227. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103228. hi = i + fixed / 2;
  103229. lo = hi - fixed;
  103230. if(lo>=0)break;
  103231. tN = N[hi] + N[-lo];
  103232. tX = X[hi] - X[-lo];
  103233. tXX = XX[hi] + XX[-lo];
  103234. tY = Y[hi] + Y[-lo];
  103235. tXY = XY[hi] - XY[-lo];
  103236. A = tY * tXX - tX * tXY;
  103237. B = tN * tXY - tX * tY;
  103238. D = tN * tXX - tX * tX;
  103239. R = (A + x * B) / D;
  103240. if (R - offset < noise[i]) noise[i] = R - offset;
  103241. }
  103242. for ( ;; i++, x += 1.f) {
  103243. hi = i + fixed / 2;
  103244. lo = hi - fixed;
  103245. if(hi>=n)break;
  103246. tN = N[hi] - N[lo];
  103247. tX = X[hi] - X[lo];
  103248. tXX = XX[hi] - XX[lo];
  103249. tY = Y[hi] - Y[lo];
  103250. tXY = XY[hi] - XY[lo];
  103251. A = tY * tXX - tX * tXY;
  103252. B = tN * tXY - tX * tY;
  103253. D = tN * tXX - tX * tX;
  103254. R = (A + x * B) / D;
  103255. if (R - offset < noise[i]) noise[i] = R - offset;
  103256. }
  103257. for ( ; i < n; i++, x += 1.f) {
  103258. R = (A + x * B) / D;
  103259. if (R - offset < noise[i]) noise[i] = R - offset;
  103260. }
  103261. }
  103262. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103263. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103264. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103265. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103266. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103267. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103268. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103269. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103270. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103271. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103272. 973377.F, 913981.F, 858210.F, 805842.F,
  103273. 756669.F, 710497.F, 667142.F, 626433.F,
  103274. 588208.F, 552316.F, 518613.F, 486967.F,
  103275. 457252.F, 429351.F, 403152.F, 378551.F,
  103276. 355452.F, 333762.F, 313396.F, 294273.F,
  103277. 276316.F, 259455.F, 243623.F, 228757.F,
  103278. 214798.F, 201691.F, 189384.F, 177828.F,
  103279. 166977.F, 156788.F, 147221.F, 138237.F,
  103280. 129802.F, 121881.F, 114444.F, 107461.F,
  103281. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103282. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103283. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103284. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103285. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103286. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103287. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103288. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103289. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103290. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103291. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103292. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103293. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103294. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103295. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103296. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103297. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103298. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103299. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103300. 842.910F, 791.475F, 743.179F, 697.830F,
  103301. 655.249F, 615.265F, 577.722F, 542.469F,
  103302. 509.367F, 478.286F, 449.101F, 421.696F,
  103303. 395.964F, 371.803F, 349.115F, 327.812F,
  103304. 307.809F, 289.026F, 271.390F, 254.830F,
  103305. 239.280F, 224.679F, 210.969F, 198.096F,
  103306. 186.008F, 174.658F, 164.000F, 153.993F,
  103307. 144.596F, 135.773F, 127.488F, 119.708F,
  103308. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103309. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103310. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103311. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103312. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103313. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103314. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103315. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103316. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103317. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103318. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103319. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103320. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103321. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103322. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103323. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103324. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103325. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103326. 1.20790F, 1.13419F, 1.06499F, 1.F
  103327. };
  103328. void _vp_remove_floor(vorbis_look_psy *p,
  103329. float *mdct,
  103330. int *codedflr,
  103331. float *residue,
  103332. int sliding_lowpass){
  103333. int i,n=p->n;
  103334. if(sliding_lowpass>n)sliding_lowpass=n;
  103335. for(i=0;i<sliding_lowpass;i++){
  103336. residue[i]=
  103337. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103338. }
  103339. for(;i<n;i++)
  103340. residue[i]=0.;
  103341. }
  103342. void _vp_noisemask(vorbis_look_psy *p,
  103343. float *logmdct,
  103344. float *logmask){
  103345. int i,n=p->n;
  103346. float *work=(float*) alloca(n*sizeof(*work));
  103347. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103348. 140.,-1);
  103349. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103350. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103351. p->vi->noisewindowfixed);
  103352. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103353. #if 0
  103354. {
  103355. static int seq=0;
  103356. float work2[n];
  103357. for(i=0;i<n;i++){
  103358. work2[i]=logmask[i]+work[i];
  103359. }
  103360. if(seq&1)
  103361. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103362. else
  103363. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103364. if(seq&1)
  103365. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103366. else
  103367. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103368. seq++;
  103369. }
  103370. #endif
  103371. for(i=0;i<n;i++){
  103372. int dB=logmask[i]+.5;
  103373. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103374. if(dB<0)dB=0;
  103375. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103376. }
  103377. }
  103378. void _vp_tonemask(vorbis_look_psy *p,
  103379. float *logfft,
  103380. float *logmask,
  103381. float global_specmax,
  103382. float local_specmax){
  103383. int i,n=p->n;
  103384. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103385. float att=local_specmax+p->vi->ath_adjatt;
  103386. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103387. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103388. for(i=0;i<n;i++)
  103389. logmask[i]=p->ath[i]+att;
  103390. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103391. max_seeds(p,seed,logmask);
  103392. }
  103393. void _vp_offset_and_mix(vorbis_look_psy *p,
  103394. float *noise,
  103395. float *tone,
  103396. int offset_select,
  103397. float *logmask,
  103398. float *mdct,
  103399. float *logmdct){
  103400. int i,n=p->n;
  103401. float de, coeffi, cx;/* AoTuV */
  103402. float toneatt=p->vi->tone_masteratt[offset_select];
  103403. cx = p->m_val;
  103404. for(i=0;i<n;i++){
  103405. float val= noise[i]+p->noiseoffset[offset_select][i];
  103406. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103407. logmask[i]=max(val,tone[i]+toneatt);
  103408. if(offset_select == 1) {
  103409. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103410. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103411. if(val > coeffi){
  103412. de = 1.0-((val-coeffi)*0.005*cx);
  103413. if(de < 0) de = 0.0001;
  103414. }else
  103415. de = 1.0-((val-coeffi)*0.0003*cx);
  103416. mdct[i] *= de;
  103417. }
  103418. }
  103419. }
  103420. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103421. vorbis_info *vi=vd->vi;
  103422. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103423. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103424. int n=ci->blocksizes[vd->W]/2;
  103425. float secs=(float)n/vi->rate;
  103426. amp+=secs*gi->ampmax_att_per_sec;
  103427. if(amp<-9999)amp=-9999;
  103428. return(amp);
  103429. }
  103430. static void couple_lossless(float A, float B,
  103431. float *qA, float *qB){
  103432. int test1=fabs(*qA)>fabs(*qB);
  103433. test1-= fabs(*qA)<fabs(*qB);
  103434. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103435. if(test1==1){
  103436. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103437. }else{
  103438. float temp=*qB;
  103439. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103440. *qA=temp;
  103441. }
  103442. if(*qB>fabs(*qA)*1.9999f){
  103443. *qB= -fabs(*qA)*2.f;
  103444. *qA= -*qA;
  103445. }
  103446. }
  103447. static float hypot_lookup[32]={
  103448. -0.009935, -0.011245, -0.012726, -0.014397,
  103449. -0.016282, -0.018407, -0.020800, -0.023494,
  103450. -0.026522, -0.029923, -0.033737, -0.038010,
  103451. -0.042787, -0.048121, -0.054064, -0.060671,
  103452. -0.068000, -0.076109, -0.085054, -0.094892,
  103453. -0.105675, -0.117451, -0.130260, -0.144134,
  103454. -0.159093, -0.175146, -0.192286, -0.210490,
  103455. -0.229718, -0.249913, -0.271001, -0.292893};
  103456. static void precomputed_couple_point(float premag,
  103457. int floorA,int floorB,
  103458. float *mag, float *ang){
  103459. int test=(floorA>floorB)-1;
  103460. int offset=31-abs(floorA-floorB);
  103461. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103462. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103463. *mag=premag*floormag;
  103464. *ang=0.f;
  103465. }
  103466. static float dipole_hypot(float a, float b){
  103467. if(a>0.){
  103468. if(b>0.)return sqrt(a*a+b*b);
  103469. if(a>-b)return sqrt(a*a-b*b);
  103470. return -sqrt(b*b-a*a);
  103471. }
  103472. if(b<0.)return -sqrt(a*a+b*b);
  103473. if(-a>b)return -sqrt(a*a-b*b);
  103474. return sqrt(b*b-a*a);
  103475. }
  103476. static float round_hypot(float a, float b){
  103477. if(a>0.){
  103478. if(b>0.)return sqrt(a*a+b*b);
  103479. if(a>-b)return sqrt(a*a+b*b);
  103480. return -sqrt(b*b+a*a);
  103481. }
  103482. if(b<0.)return -sqrt(a*a+b*b);
  103483. if(-a>b)return -sqrt(a*a+b*b);
  103484. return sqrt(b*b+a*a);
  103485. }
  103486. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103487. vorbis_info_psy_global *g,
  103488. vorbis_look_psy *p,
  103489. vorbis_info_mapping0 *vi,
  103490. float **mdct){
  103491. int i,j,n=p->n;
  103492. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103493. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103494. for(i=0;i<vi->coupling_steps;i++){
  103495. float *mdctM=mdct[vi->coupling_mag[i]];
  103496. float *mdctA=mdct[vi->coupling_ang[i]];
  103497. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103498. for(j=0;j<limit;j++)
  103499. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103500. for(;j<n;j++)
  103501. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103502. }
  103503. return(ret);
  103504. }
  103505. static int apsort(const void *a, const void *b){
  103506. float f1=fabs(**(float**)a);
  103507. float f2=fabs(**(float**)b);
  103508. return (f1<f2)-(f1>f2);
  103509. }
  103510. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103511. vorbis_look_psy *p,
  103512. vorbis_info_mapping0 *vi,
  103513. float **mags){
  103514. if(p->vi->normal_point_p){
  103515. int i,j,k,n=p->n;
  103516. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103517. int partition=p->vi->normal_partition;
  103518. float **work=(float**) alloca(sizeof(*work)*partition);
  103519. for(i=0;i<vi->coupling_steps;i++){
  103520. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103521. for(j=0;j<n;j+=partition){
  103522. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103523. qsort(work,partition,sizeof(*work),apsort);
  103524. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103525. }
  103526. }
  103527. return(ret);
  103528. }
  103529. return(NULL);
  103530. }
  103531. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103532. float *magnitudes,int *sortedindex){
  103533. int i,j,n=p->n;
  103534. vorbis_info_psy *vi=p->vi;
  103535. int partition=vi->normal_partition;
  103536. float **work=(float**) alloca(sizeof(*work)*partition);
  103537. int start=vi->normal_start;
  103538. for(j=start;j<n;j+=partition){
  103539. if(j+partition>n)partition=n-j;
  103540. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103541. qsort(work,partition,sizeof(*work),apsort);
  103542. for(i=0;i<partition;i++){
  103543. sortedindex[i+j-start]=work[i]-magnitudes;
  103544. }
  103545. }
  103546. }
  103547. void _vp_noise_normalize(vorbis_look_psy *p,
  103548. float *in,float *out,int *sortedindex){
  103549. int flag=0,i,j=0,n=p->n;
  103550. vorbis_info_psy *vi=p->vi;
  103551. int partition=vi->normal_partition;
  103552. int start=vi->normal_start;
  103553. if(start>n)start=n;
  103554. if(vi->normal_channel_p){
  103555. for(;j<start;j++)
  103556. out[j]=rint(in[j]);
  103557. for(;j+partition<=n;j+=partition){
  103558. float acc=0.;
  103559. int k;
  103560. for(i=j;i<j+partition;i++)
  103561. acc+=in[i]*in[i];
  103562. for(i=0;i<partition;i++){
  103563. k=sortedindex[i+j-start];
  103564. if(in[k]*in[k]>=.25f){
  103565. out[k]=rint(in[k]);
  103566. acc-=in[k]*in[k];
  103567. flag=1;
  103568. }else{
  103569. if(acc<vi->normal_thresh)break;
  103570. out[k]=unitnorm(in[k]);
  103571. acc-=1.;
  103572. }
  103573. }
  103574. for(;i<partition;i++){
  103575. k=sortedindex[i+j-start];
  103576. out[k]=0.;
  103577. }
  103578. }
  103579. }
  103580. for(;j<n;j++)
  103581. out[j]=rint(in[j]);
  103582. }
  103583. void _vp_couple(int blobno,
  103584. vorbis_info_psy_global *g,
  103585. vorbis_look_psy *p,
  103586. vorbis_info_mapping0 *vi,
  103587. float **res,
  103588. float **mag_memo,
  103589. int **mag_sort,
  103590. int **ifloor,
  103591. int *nonzero,
  103592. int sliding_lowpass){
  103593. int i,j,k,n=p->n;
  103594. for(i=0;i<vi->coupling_steps;i++){
  103595. if(nonzero[vi->coupling_mag[i]] ||
  103596. nonzero[vi->coupling_ang[i]]){
  103597. float *rM=res[vi->coupling_mag[i]];
  103598. float *rA=res[vi->coupling_ang[i]];
  103599. float *qM=rM+n;
  103600. float *qA=rA+n;
  103601. int *floorM=ifloor[vi->coupling_mag[i]];
  103602. int *floorA=ifloor[vi->coupling_ang[i]];
  103603. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103604. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103605. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103606. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103607. int pointlimit=limit;
  103608. nonzero[vi->coupling_mag[i]]=1;
  103609. nonzero[vi->coupling_ang[i]]=1;
  103610. if(n > 1000)
  103611. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103612. for(j=0;j<p->n;j+=partition){
  103613. float acc=0.f;
  103614. for(k=0;k<partition;k++){
  103615. int l=k+j;
  103616. if(l<sliding_lowpass){
  103617. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103618. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103619. precomputed_couple_point(mag_memo[i][l],
  103620. floorM[l],floorA[l],
  103621. qM+l,qA+l);
  103622. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103623. }else{
  103624. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103625. }
  103626. }else{
  103627. qM[l]=0.;
  103628. qA[l]=0.;
  103629. }
  103630. }
  103631. if(p->vi->normal_point_p){
  103632. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103633. int l=mag_sort[i][j+k];
  103634. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103635. qM[l]=unitnorm(qM[l]);
  103636. acc-=1.f;
  103637. }
  103638. }
  103639. }
  103640. }
  103641. }
  103642. }
  103643. }
  103644. void hf_reduction(vorbis_info_psy_global *g,
  103645. vorbis_look_psy *p,
  103646. vorbis_info_mapping0 *vi,
  103647. float **mdct){
  103648. int i,j,n=p->n, de=0.3*p->m_val;
  103649. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103650. for(i=0; i<vi->coupling_steps; i++){
  103651. for(j=limit; j<n; j++)
  103652. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103653. }
  103654. }
  103655. #endif
  103656. /*** End of inlined file: psy.c ***/
  103657. /*** Start of inlined file: registry.c ***/
  103658. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103659. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103660. // tasks..
  103661. #if JUCE_MSVC
  103662. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103663. #endif
  103664. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103665. #if JUCE_USE_OGGVORBIS
  103666. extern vorbis_func_floor floor0_exportbundle;
  103667. extern vorbis_func_floor floor1_exportbundle;
  103668. extern vorbis_func_residue residue0_exportbundle;
  103669. extern vorbis_func_residue residue1_exportbundle;
  103670. extern vorbis_func_residue residue2_exportbundle;
  103671. extern vorbis_func_mapping mapping0_exportbundle;
  103672. vorbis_func_floor *_floor_P[]={
  103673. &floor0_exportbundle,
  103674. &floor1_exportbundle,
  103675. };
  103676. vorbis_func_residue *_residue_P[]={
  103677. &residue0_exportbundle,
  103678. &residue1_exportbundle,
  103679. &residue2_exportbundle,
  103680. };
  103681. vorbis_func_mapping *_mapping_P[]={
  103682. &mapping0_exportbundle,
  103683. };
  103684. #endif
  103685. /*** End of inlined file: registry.c ***/
  103686. /*** Start of inlined file: res0.c ***/
  103687. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103688. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103689. // tasks..
  103690. #if JUCE_MSVC
  103691. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103692. #endif
  103693. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103694. #if JUCE_USE_OGGVORBIS
  103695. #include <stdlib.h>
  103696. #include <string.h>
  103697. #include <math.h>
  103698. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103699. #include <stdio.h>
  103700. #endif
  103701. typedef struct {
  103702. vorbis_info_residue0 *info;
  103703. int parts;
  103704. int stages;
  103705. codebook *fullbooks;
  103706. codebook *phrasebook;
  103707. codebook ***partbooks;
  103708. int partvals;
  103709. int **decodemap;
  103710. long postbits;
  103711. long phrasebits;
  103712. long frames;
  103713. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  103714. int train_seq;
  103715. long *training_data[8][64];
  103716. float training_max[8][64];
  103717. float training_min[8][64];
  103718. float tmin;
  103719. float tmax;
  103720. #endif
  103721. } vorbis_look_residue0;
  103722. void res0_free_info(vorbis_info_residue *i){
  103723. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  103724. if(info){
  103725. memset(info,0,sizeof(*info));
  103726. _ogg_free(info);
  103727. }
  103728. }
  103729. void res0_free_look(vorbis_look_residue *i){
  103730. int j;
  103731. if(i){
  103732. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  103733. #ifdef TRAIN_RES
  103734. {
  103735. int j,k,l;
  103736. for(j=0;j<look->parts;j++){
  103737. for(k=0;k<8;k++)
  103738. if(look->training_data[k][j]){
  103739. char buffer[80];
  103740. FILE *of;
  103741. codebook *statebook=look->partbooks[j][k];
  103742. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  103743. of=fopen(buffer,"a");
  103744. for(l=0;l<statebook->entries;l++)
  103745. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  103746. fclose(of);
  103747. _ogg_free(look->training_data[k][j]);
  103748. look->training_data[k][j]=NULL;
  103749. }
  103750. }
  103751. }
  103752. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  103753. #endif
  103754. for(j=0;j<look->parts;j++)
  103755. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  103756. _ogg_free(look->partbooks);
  103757. for(j=0;j<look->partvals;j++)
  103758. _ogg_free(look->decodemap[j]);
  103759. _ogg_free(look->decodemap);
  103760. memset(look,0,sizeof(*look));
  103761. _ogg_free(look);
  103762. }
  103763. }
  103764. static int icount(unsigned int v){
  103765. int ret=0;
  103766. while(v){
  103767. ret+=v&1;
  103768. v>>=1;
  103769. }
  103770. return(ret);
  103771. }
  103772. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  103773. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103774. int j,acc=0;
  103775. oggpack_write(opb,info->begin,24);
  103776. oggpack_write(opb,info->end,24);
  103777. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  103778. code with a partitioned book */
  103779. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  103780. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  103781. for(j=0;j<info->partitions;j++){
  103782. if(ilog(info->secondstages[j])>3){
  103783. oggpack_write(opb,info->secondstages[j],3);
  103784. oggpack_write(opb,1,1);
  103785. oggpack_write(opb,info->secondstages[j]>>3,5);
  103786. }else
  103787. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  103788. acc+=icount(info->secondstages[j]);
  103789. }
  103790. for(j=0;j<acc;j++)
  103791. oggpack_write(opb,info->booklist[j],8);
  103792. }
  103793. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  103794. int j,acc=0;
  103795. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  103796. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  103797. info->begin=oggpack_read(opb,24);
  103798. info->end=oggpack_read(opb,24);
  103799. info->grouping=oggpack_read(opb,24)+1;
  103800. info->partitions=oggpack_read(opb,6)+1;
  103801. info->groupbook=oggpack_read(opb,8);
  103802. for(j=0;j<info->partitions;j++){
  103803. int cascade=oggpack_read(opb,3);
  103804. if(oggpack_read(opb,1))
  103805. cascade|=(oggpack_read(opb,5)<<3);
  103806. info->secondstages[j]=cascade;
  103807. acc+=icount(cascade);
  103808. }
  103809. for(j=0;j<acc;j++)
  103810. info->booklist[j]=oggpack_read(opb,8);
  103811. if(info->groupbook>=ci->books)goto errout;
  103812. for(j=0;j<acc;j++)
  103813. if(info->booklist[j]>=ci->books)goto errout;
  103814. return(info);
  103815. errout:
  103816. res0_free_info(info);
  103817. return(NULL);
  103818. }
  103819. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  103820. vorbis_info_residue *vr){
  103821. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103822. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  103823. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  103824. int j,k,acc=0;
  103825. int dim;
  103826. int maxstage=0;
  103827. look->info=info;
  103828. look->parts=info->partitions;
  103829. look->fullbooks=ci->fullbooks;
  103830. look->phrasebook=ci->fullbooks+info->groupbook;
  103831. dim=look->phrasebook->dim;
  103832. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  103833. for(j=0;j<look->parts;j++){
  103834. int stages=ilog(info->secondstages[j]);
  103835. if(stages){
  103836. if(stages>maxstage)maxstage=stages;
  103837. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  103838. for(k=0;k<stages;k++)
  103839. if(info->secondstages[j]&(1<<k)){
  103840. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  103841. #ifdef TRAIN_RES
  103842. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  103843. sizeof(***look->training_data));
  103844. #endif
  103845. }
  103846. }
  103847. }
  103848. look->partvals=rint(pow((float)look->parts,(float)dim));
  103849. look->stages=maxstage;
  103850. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  103851. for(j=0;j<look->partvals;j++){
  103852. long val=j;
  103853. long mult=look->partvals/look->parts;
  103854. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  103855. for(k=0;k<dim;k++){
  103856. long deco=val/mult;
  103857. val-=deco*mult;
  103858. mult/=look->parts;
  103859. look->decodemap[j][k]=deco;
  103860. }
  103861. }
  103862. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103863. {
  103864. static int train_seq=0;
  103865. look->train_seq=train_seq++;
  103866. }
  103867. #endif
  103868. return(look);
  103869. }
  103870. static int local_book_besterror(codebook *book,float *a){
  103871. int dim=book->dim,i,k,o;
  103872. int best=0;
  103873. encode_aux_threshmatch *tt=book->c->thresh_tree;
  103874. for(k=0,o=dim;k<dim;++k){
  103875. float val=a[--o];
  103876. i=tt->threshvals>>1;
  103877. if(val<tt->quantthresh[i]){
  103878. if(val<tt->quantthresh[i-1]){
  103879. for(--i;i>0;--i)
  103880. if(val>=tt->quantthresh[i-1])
  103881. break;
  103882. }
  103883. }else{
  103884. for(++i;i<tt->threshvals-1;++i)
  103885. if(val<tt->quantthresh[i])break;
  103886. }
  103887. best=(best*tt->quantvals)+tt->quantmap[i];
  103888. }
  103889. if(book->c->lengthlist[best]<=0){
  103890. const static_codebook *c=book->c;
  103891. int i,j;
  103892. float bestf=0.f;
  103893. float *e=book->valuelist;
  103894. best=-1;
  103895. for(i=0;i<book->entries;i++){
  103896. if(c->lengthlist[i]>0){
  103897. float thisx=0.f;
  103898. for(j=0;j<dim;j++){
  103899. float val=(e[j]-a[j]);
  103900. thisx+=val*val;
  103901. }
  103902. if(best==-1 || thisx<bestf){
  103903. bestf=thisx;
  103904. best=i;
  103905. }
  103906. }
  103907. e+=dim;
  103908. }
  103909. }
  103910. {
  103911. float *ptr=book->valuelist+best*dim;
  103912. for(i=0;i<dim;i++)
  103913. *a++ -= *ptr++;
  103914. }
  103915. return(best);
  103916. }
  103917. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  103918. codebook *book,long *acc){
  103919. int i,bits=0;
  103920. int dim=book->dim;
  103921. int step=n/dim;
  103922. for(i=0;i<step;i++){
  103923. int entry=local_book_besterror(book,vec+i*dim);
  103924. #ifdef TRAIN_RES
  103925. acc[entry]++;
  103926. #endif
  103927. bits+=vorbis_book_encode(book,entry,opb);
  103928. }
  103929. return(bits);
  103930. }
  103931. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  103932. float **in,int ch){
  103933. long i,j,k;
  103934. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  103935. vorbis_info_residue0 *info=look->info;
  103936. int samples_per_partition=info->grouping;
  103937. int possible_partitions=info->partitions;
  103938. int n=info->end-info->begin;
  103939. int partvals=n/samples_per_partition;
  103940. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  103941. float scale=100./samples_per_partition;
  103942. for(i=0;i<ch;i++){
  103943. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  103944. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  103945. }
  103946. for(i=0;i<partvals;i++){
  103947. int offset=i*samples_per_partition+info->begin;
  103948. for(j=0;j<ch;j++){
  103949. float max=0.;
  103950. float ent=0.;
  103951. for(k=0;k<samples_per_partition;k++){
  103952. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  103953. ent+=fabs(rint(in[j][offset+k]));
  103954. }
  103955. ent*=scale;
  103956. for(k=0;k<possible_partitions-1;k++)
  103957. if(max<=info->classmetric1[k] &&
  103958. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  103959. break;
  103960. partword[j][i]=k;
  103961. }
  103962. }
  103963. #ifdef TRAIN_RESAUX
  103964. {
  103965. FILE *of;
  103966. char buffer[80];
  103967. for(i=0;i<ch;i++){
  103968. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  103969. of=fopen(buffer,"a");
  103970. for(j=0;j<partvals;j++)
  103971. fprintf(of,"%ld, ",partword[i][j]);
  103972. fprintf(of,"\n");
  103973. fclose(of);
  103974. }
  103975. }
  103976. #endif
  103977. look->frames++;
  103978. return(partword);
  103979. }
  103980. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  103981. int ch){
  103982. long i,j,k,l;
  103983. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  103984. vorbis_info_residue0 *info=look->info;
  103985. int samples_per_partition=info->grouping;
  103986. int possible_partitions=info->partitions;
  103987. int n=info->end-info->begin;
  103988. int partvals=n/samples_per_partition;
  103989. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  103990. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103991. FILE *of;
  103992. char buffer[80];
  103993. #endif
  103994. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  103995. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  103996. for(i=0,l=info->begin/ch;i<partvals;i++){
  103997. float magmax=0.f;
  103998. float angmax=0.f;
  103999. for(j=0;j<samples_per_partition;j+=ch){
  104000. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104001. for(k=1;k<ch;k++)
  104002. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104003. l++;
  104004. }
  104005. for(j=0;j<possible_partitions-1;j++)
  104006. if(magmax<=info->classmetric1[j] &&
  104007. angmax<=info->classmetric2[j])
  104008. break;
  104009. partword[0][i]=j;
  104010. }
  104011. #ifdef TRAIN_RESAUX
  104012. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104013. of=fopen(buffer,"a");
  104014. for(i=0;i<partvals;i++)
  104015. fprintf(of,"%ld, ",partword[0][i]);
  104016. fprintf(of,"\n");
  104017. fclose(of);
  104018. #endif
  104019. look->frames++;
  104020. return(partword);
  104021. }
  104022. static int _01forward(oggpack_buffer *opb,
  104023. vorbis_block *vb,vorbis_look_residue *vl,
  104024. float **in,int ch,
  104025. long **partword,
  104026. int (*encode)(oggpack_buffer *,float *,int,
  104027. codebook *,long *)){
  104028. long i,j,k,s;
  104029. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104030. vorbis_info_residue0 *info=look->info;
  104031. int samples_per_partition=info->grouping;
  104032. int possible_partitions=info->partitions;
  104033. int partitions_per_word=look->phrasebook->dim;
  104034. int n=info->end-info->begin;
  104035. int partvals=n/samples_per_partition;
  104036. long resbits[128];
  104037. long resvals[128];
  104038. #ifdef TRAIN_RES
  104039. for(i=0;i<ch;i++)
  104040. for(j=info->begin;j<info->end;j++){
  104041. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104042. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104043. }
  104044. #endif
  104045. memset(resbits,0,sizeof(resbits));
  104046. memset(resvals,0,sizeof(resvals));
  104047. for(s=0;s<look->stages;s++){
  104048. for(i=0;i<partvals;){
  104049. if(s==0){
  104050. for(j=0;j<ch;j++){
  104051. long val=partword[j][i];
  104052. for(k=1;k<partitions_per_word;k++){
  104053. val*=possible_partitions;
  104054. if(i+k<partvals)
  104055. val+=partword[j][i+k];
  104056. }
  104057. if(val<look->phrasebook->entries)
  104058. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104059. #if 0 /*def TRAIN_RES*/
  104060. else
  104061. fprintf(stderr,"!");
  104062. #endif
  104063. }
  104064. }
  104065. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104066. long offset=i*samples_per_partition+info->begin;
  104067. for(j=0;j<ch;j++){
  104068. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104069. if(info->secondstages[partword[j][i]]&(1<<s)){
  104070. codebook *statebook=look->partbooks[partword[j][i]][s];
  104071. if(statebook){
  104072. int ret;
  104073. long *accumulator=NULL;
  104074. #ifdef TRAIN_RES
  104075. accumulator=look->training_data[s][partword[j][i]];
  104076. {
  104077. int l;
  104078. float *samples=in[j]+offset;
  104079. for(l=0;l<samples_per_partition;l++){
  104080. if(samples[l]<look->training_min[s][partword[j][i]])
  104081. look->training_min[s][partword[j][i]]=samples[l];
  104082. if(samples[l]>look->training_max[s][partword[j][i]])
  104083. look->training_max[s][partword[j][i]]=samples[l];
  104084. }
  104085. }
  104086. #endif
  104087. ret=encode(opb,in[j]+offset,samples_per_partition,
  104088. statebook,accumulator);
  104089. look->postbits+=ret;
  104090. resbits[partword[j][i]]+=ret;
  104091. }
  104092. }
  104093. }
  104094. }
  104095. }
  104096. }
  104097. return(0);
  104098. }
  104099. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104100. float **in,int ch,
  104101. long (*decodepart)(codebook *, float *,
  104102. oggpack_buffer *,int)){
  104103. long i,j,k,l,s;
  104104. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104105. vorbis_info_residue0 *info=look->info;
  104106. int samples_per_partition=info->grouping;
  104107. int partitions_per_word=look->phrasebook->dim;
  104108. int n=info->end-info->begin;
  104109. int partvals=n/samples_per_partition;
  104110. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104111. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104112. for(j=0;j<ch;j++)
  104113. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104114. for(s=0;s<look->stages;s++){
  104115. for(i=0,l=0;i<partvals;l++){
  104116. if(s==0){
  104117. for(j=0;j<ch;j++){
  104118. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104119. if(temp==-1)goto eopbreak;
  104120. partword[j][l]=look->decodemap[temp];
  104121. if(partword[j][l]==NULL)goto errout;
  104122. }
  104123. }
  104124. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104125. for(j=0;j<ch;j++){
  104126. long offset=info->begin+i*samples_per_partition;
  104127. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104128. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104129. if(stagebook){
  104130. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104131. samples_per_partition)==-1)goto eopbreak;
  104132. }
  104133. }
  104134. }
  104135. }
  104136. }
  104137. errout:
  104138. eopbreak:
  104139. return(0);
  104140. }
  104141. #if 0
  104142. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104143. float **in,int *nonzero,int ch){
  104144. int i,used=0;
  104145. for(i=0;i<ch;i++)
  104146. if(nonzero[i])
  104147. in[used++]=in[i];
  104148. if(used)
  104149. return(_01class(vb,vl,in,used));
  104150. else
  104151. return(0);
  104152. }
  104153. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104154. float **in,float **out,int *nonzero,int ch,
  104155. long **partword){
  104156. int i,j,used=0,n=vb->pcmend/2;
  104157. for(i=0;i<ch;i++)
  104158. if(nonzero[i]){
  104159. if(out)
  104160. for(j=0;j<n;j++)
  104161. out[i][j]+=in[i][j];
  104162. in[used++]=in[i];
  104163. }
  104164. if(used){
  104165. int ret=_01forward(vb,vl,in,used,partword,
  104166. _interleaved_encodepart);
  104167. if(out){
  104168. used=0;
  104169. for(i=0;i<ch;i++)
  104170. if(nonzero[i]){
  104171. for(j=0;j<n;j++)
  104172. out[i][j]-=in[used][j];
  104173. used++;
  104174. }
  104175. }
  104176. return(ret);
  104177. }else{
  104178. return(0);
  104179. }
  104180. }
  104181. #endif
  104182. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104183. float **in,int *nonzero,int ch){
  104184. int i,used=0;
  104185. for(i=0;i<ch;i++)
  104186. if(nonzero[i])
  104187. in[used++]=in[i];
  104188. if(used)
  104189. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104190. else
  104191. return(0);
  104192. }
  104193. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104194. float **in,float **out,int *nonzero,int ch,
  104195. long **partword){
  104196. int i,j,used=0,n=vb->pcmend/2;
  104197. for(i=0;i<ch;i++)
  104198. if(nonzero[i]){
  104199. if(out)
  104200. for(j=0;j<n;j++)
  104201. out[i][j]+=in[i][j];
  104202. in[used++]=in[i];
  104203. }
  104204. if(used){
  104205. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104206. if(out){
  104207. used=0;
  104208. for(i=0;i<ch;i++)
  104209. if(nonzero[i]){
  104210. for(j=0;j<n;j++)
  104211. out[i][j]-=in[used][j];
  104212. used++;
  104213. }
  104214. }
  104215. return(ret);
  104216. }else{
  104217. return(0);
  104218. }
  104219. }
  104220. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104221. float **in,int *nonzero,int ch){
  104222. int i,used=0;
  104223. for(i=0;i<ch;i++)
  104224. if(nonzero[i])
  104225. in[used++]=in[i];
  104226. if(used)
  104227. return(_01class(vb,vl,in,used));
  104228. else
  104229. return(0);
  104230. }
  104231. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104232. float **in,int *nonzero,int ch){
  104233. int i,used=0;
  104234. for(i=0;i<ch;i++)
  104235. if(nonzero[i])
  104236. in[used++]=in[i];
  104237. if(used)
  104238. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104239. else
  104240. return(0);
  104241. }
  104242. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104243. float **in,int *nonzero,int ch){
  104244. int i,used=0;
  104245. for(i=0;i<ch;i++)
  104246. if(nonzero[i])used++;
  104247. if(used)
  104248. return(_2class(vb,vl,in,ch));
  104249. else
  104250. return(0);
  104251. }
  104252. int res2_forward(oggpack_buffer *opb,
  104253. vorbis_block *vb,vorbis_look_residue *vl,
  104254. float **in,float **out,int *nonzero,int ch,
  104255. long **partword){
  104256. long i,j,k,n=vb->pcmend/2,used=0;
  104257. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104258. for(i=0;i<ch;i++){
  104259. float *pcm=in[i];
  104260. if(nonzero[i])used++;
  104261. for(j=0,k=i;j<n;j++,k+=ch)
  104262. work[k]=pcm[j];
  104263. }
  104264. if(used){
  104265. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104266. if(out){
  104267. for(i=0;i<ch;i++){
  104268. float *pcm=in[i];
  104269. float *sofar=out[i];
  104270. for(j=0,k=i;j<n;j++,k+=ch)
  104271. sofar[j]+=pcm[j]-work[k];
  104272. }
  104273. }
  104274. return(ret);
  104275. }else{
  104276. return(0);
  104277. }
  104278. }
  104279. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104280. float **in,int *nonzero,int ch){
  104281. long i,k,l,s;
  104282. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104283. vorbis_info_residue0 *info=look->info;
  104284. int samples_per_partition=info->grouping;
  104285. int partitions_per_word=look->phrasebook->dim;
  104286. int n=info->end-info->begin;
  104287. int partvals=n/samples_per_partition;
  104288. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104289. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104290. for(i=0;i<ch;i++)if(nonzero[i])break;
  104291. if(i==ch)return(0); /* no nonzero vectors */
  104292. for(s=0;s<look->stages;s++){
  104293. for(i=0,l=0;i<partvals;l++){
  104294. if(s==0){
  104295. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104296. if(temp==-1)goto eopbreak;
  104297. partword[l]=look->decodemap[temp];
  104298. if(partword[l]==NULL)goto errout;
  104299. }
  104300. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104301. if(info->secondstages[partword[l][k]]&(1<<s)){
  104302. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104303. if(stagebook){
  104304. if(vorbis_book_decodevv_add(stagebook,in,
  104305. i*samples_per_partition+info->begin,ch,
  104306. &vb->opb,samples_per_partition)==-1)
  104307. goto eopbreak;
  104308. }
  104309. }
  104310. }
  104311. }
  104312. errout:
  104313. eopbreak:
  104314. return(0);
  104315. }
  104316. vorbis_func_residue residue0_exportbundle={
  104317. NULL,
  104318. &res0_unpack,
  104319. &res0_look,
  104320. &res0_free_info,
  104321. &res0_free_look,
  104322. NULL,
  104323. NULL,
  104324. &res0_inverse
  104325. };
  104326. vorbis_func_residue residue1_exportbundle={
  104327. &res0_pack,
  104328. &res0_unpack,
  104329. &res0_look,
  104330. &res0_free_info,
  104331. &res0_free_look,
  104332. &res1_class,
  104333. &res1_forward,
  104334. &res1_inverse
  104335. };
  104336. vorbis_func_residue residue2_exportbundle={
  104337. &res0_pack,
  104338. &res0_unpack,
  104339. &res0_look,
  104340. &res0_free_info,
  104341. &res0_free_look,
  104342. &res2_class,
  104343. &res2_forward,
  104344. &res2_inverse
  104345. };
  104346. #endif
  104347. /*** End of inlined file: res0.c ***/
  104348. /*** Start of inlined file: sharedbook.c ***/
  104349. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104350. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104351. // tasks..
  104352. #if JUCE_MSVC
  104353. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104354. #endif
  104355. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104356. #if JUCE_USE_OGGVORBIS
  104357. #include <stdlib.h>
  104358. #include <math.h>
  104359. #include <string.h>
  104360. int _ilog(unsigned int v){
  104361. int ret=0;
  104362. while(v){
  104363. ret++;
  104364. v>>=1;
  104365. }
  104366. return(ret);
  104367. }
  104368. #define VQ_FEXP 10
  104369. #define VQ_FMAN 21
  104370. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104371. long _float32_pack(float val){
  104372. int sign=0;
  104373. long exp;
  104374. long mant;
  104375. if(val<0){
  104376. sign=0x80000000;
  104377. val= -val;
  104378. }
  104379. exp= floor(log(val)/log(2.f));
  104380. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104381. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104382. return(sign|exp|mant);
  104383. }
  104384. float _float32_unpack(long val){
  104385. double mant=val&0x1fffff;
  104386. int sign=val&0x80000000;
  104387. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104388. if(sign)mant= -mant;
  104389. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104390. }
  104391. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104392. long i,j,count=0;
  104393. ogg_uint32_t marker[33];
  104394. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104395. memset(marker,0,sizeof(marker));
  104396. for(i=0;i<n;i++){
  104397. long length=l[i];
  104398. if(length>0){
  104399. ogg_uint32_t entry=marker[length];
  104400. if(length<32 && (entry>>length)){
  104401. _ogg_free(r);
  104402. return(NULL);
  104403. }
  104404. r[count++]=entry;
  104405. {
  104406. for(j=length;j>0;j--){
  104407. if(marker[j]&1){
  104408. if(j==1)
  104409. marker[1]++;
  104410. else
  104411. marker[j]=marker[j-1]<<1;
  104412. break; /* invariant says next upper marker would already
  104413. have been moved if it was on the same path */
  104414. }
  104415. marker[j]++;
  104416. }
  104417. }
  104418. for(j=length+1;j<33;j++)
  104419. if((marker[j]>>1) == entry){
  104420. entry=marker[j];
  104421. marker[j]=marker[j-1]<<1;
  104422. }else
  104423. break;
  104424. }else
  104425. if(sparsecount==0)count++;
  104426. }
  104427. for(i=0,count=0;i<n;i++){
  104428. ogg_uint32_t temp=0;
  104429. for(j=0;j<l[i];j++){
  104430. temp<<=1;
  104431. temp|=(r[count]>>j)&1;
  104432. }
  104433. if(sparsecount){
  104434. if(l[i])
  104435. r[count++]=temp;
  104436. }else
  104437. r[count++]=temp;
  104438. }
  104439. return(r);
  104440. }
  104441. long _book_maptype1_quantvals(const static_codebook *b){
  104442. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104443. while(1){
  104444. long acc=1;
  104445. long acc1=1;
  104446. int i;
  104447. for(i=0;i<b->dim;i++){
  104448. acc*=vals;
  104449. acc1*=vals+1;
  104450. }
  104451. if(acc<=b->entries && acc1>b->entries){
  104452. return(vals);
  104453. }else{
  104454. if(acc>b->entries){
  104455. vals--;
  104456. }else{
  104457. vals++;
  104458. }
  104459. }
  104460. }
  104461. }
  104462. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104463. long j,k,count=0;
  104464. if(b->maptype==1 || b->maptype==2){
  104465. int quantvals;
  104466. float mindel=_float32_unpack(b->q_min);
  104467. float delta=_float32_unpack(b->q_delta);
  104468. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104469. switch(b->maptype){
  104470. case 1:
  104471. quantvals=_book_maptype1_quantvals(b);
  104472. for(j=0;j<b->entries;j++){
  104473. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104474. float last=0.f;
  104475. int indexdiv=1;
  104476. for(k=0;k<b->dim;k++){
  104477. int index= (j/indexdiv)%quantvals;
  104478. float val=b->quantlist[index];
  104479. val=fabs(val)*delta+mindel+last;
  104480. if(b->q_sequencep)last=val;
  104481. if(sparsemap)
  104482. r[sparsemap[count]*b->dim+k]=val;
  104483. else
  104484. r[count*b->dim+k]=val;
  104485. indexdiv*=quantvals;
  104486. }
  104487. count++;
  104488. }
  104489. }
  104490. break;
  104491. case 2:
  104492. for(j=0;j<b->entries;j++){
  104493. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104494. float last=0.f;
  104495. for(k=0;k<b->dim;k++){
  104496. float val=b->quantlist[j*b->dim+k];
  104497. val=fabs(val)*delta+mindel+last;
  104498. if(b->q_sequencep)last=val;
  104499. if(sparsemap)
  104500. r[sparsemap[count]*b->dim+k]=val;
  104501. else
  104502. r[count*b->dim+k]=val;
  104503. }
  104504. count++;
  104505. }
  104506. }
  104507. break;
  104508. }
  104509. return(r);
  104510. }
  104511. return(NULL);
  104512. }
  104513. void vorbis_staticbook_clear(static_codebook *b){
  104514. if(b->allocedp){
  104515. if(b->quantlist)_ogg_free(b->quantlist);
  104516. if(b->lengthlist)_ogg_free(b->lengthlist);
  104517. if(b->nearest_tree){
  104518. _ogg_free(b->nearest_tree->ptr0);
  104519. _ogg_free(b->nearest_tree->ptr1);
  104520. _ogg_free(b->nearest_tree->p);
  104521. _ogg_free(b->nearest_tree->q);
  104522. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104523. _ogg_free(b->nearest_tree);
  104524. }
  104525. if(b->thresh_tree){
  104526. _ogg_free(b->thresh_tree->quantthresh);
  104527. _ogg_free(b->thresh_tree->quantmap);
  104528. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104529. _ogg_free(b->thresh_tree);
  104530. }
  104531. memset(b,0,sizeof(*b));
  104532. }
  104533. }
  104534. void vorbis_staticbook_destroy(static_codebook *b){
  104535. if(b->allocedp){
  104536. vorbis_staticbook_clear(b);
  104537. _ogg_free(b);
  104538. }
  104539. }
  104540. void vorbis_book_clear(codebook *b){
  104541. if(b->valuelist)_ogg_free(b->valuelist);
  104542. if(b->codelist)_ogg_free(b->codelist);
  104543. if(b->dec_index)_ogg_free(b->dec_index);
  104544. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104545. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104546. memset(b,0,sizeof(*b));
  104547. }
  104548. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104549. memset(c,0,sizeof(*c));
  104550. c->c=s;
  104551. c->entries=s->entries;
  104552. c->used_entries=s->entries;
  104553. c->dim=s->dim;
  104554. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104555. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104556. return(0);
  104557. }
  104558. static int sort32a(const void *a,const void *b){
  104559. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104560. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104561. }
  104562. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104563. int i,j,n=0,tabn;
  104564. int *sortindex;
  104565. memset(c,0,sizeof(*c));
  104566. for(i=0;i<s->entries;i++)
  104567. if(s->lengthlist[i]>0)
  104568. n++;
  104569. c->entries=s->entries;
  104570. c->used_entries=n;
  104571. c->dim=s->dim;
  104572. {
  104573. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104574. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104575. if(codes==NULL)goto err_out;
  104576. for(i=0;i<n;i++){
  104577. codes[i]=ogg_bitreverse(codes[i]);
  104578. codep[i]=codes+i;
  104579. }
  104580. qsort(codep,n,sizeof(*codep),sort32a);
  104581. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104582. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104583. for(i=0;i<n;i++){
  104584. int position=codep[i]-codes;
  104585. sortindex[position]=i;
  104586. }
  104587. for(i=0;i<n;i++)
  104588. c->codelist[sortindex[i]]=codes[i];
  104589. _ogg_free(codes);
  104590. }
  104591. c->valuelist=_book_unquantize(s,n,sortindex);
  104592. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104593. for(n=0,i=0;i<s->entries;i++)
  104594. if(s->lengthlist[i]>0)
  104595. c->dec_index[sortindex[n++]]=i;
  104596. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104597. for(n=0,i=0;i<s->entries;i++)
  104598. if(s->lengthlist[i]>0)
  104599. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104600. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104601. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104602. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104603. tabn=1<<c->dec_firsttablen;
  104604. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104605. c->dec_maxlength=0;
  104606. for(i=0;i<n;i++){
  104607. if(c->dec_maxlength<c->dec_codelengths[i])
  104608. c->dec_maxlength=c->dec_codelengths[i];
  104609. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104610. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104611. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104612. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104613. }
  104614. }
  104615. {
  104616. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104617. long lo=0,hi=0;
  104618. for(i=0;i<tabn;i++){
  104619. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104620. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104621. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104622. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104623. {
  104624. unsigned long loval=lo;
  104625. unsigned long hival=n-hi;
  104626. if(loval>0x7fff)loval=0x7fff;
  104627. if(hival>0x7fff)hival=0x7fff;
  104628. c->dec_firsttable[ogg_bitreverse(word)]=
  104629. 0x80000000UL | (loval<<15) | hival;
  104630. }
  104631. }
  104632. }
  104633. }
  104634. return(0);
  104635. err_out:
  104636. vorbis_book_clear(c);
  104637. return(-1);
  104638. }
  104639. static float _dist(int el,float *ref, float *b,int step){
  104640. int i;
  104641. float acc=0.f;
  104642. for(i=0;i<el;i++){
  104643. float val=(ref[i]-b[i*step]);
  104644. acc+=val*val;
  104645. }
  104646. return(acc);
  104647. }
  104648. int _best(codebook *book, float *a, int step){
  104649. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104650. #if 0
  104651. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104652. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104653. #endif
  104654. int dim=book->dim;
  104655. int k,o;
  104656. if(tt){
  104657. int index=0,i;
  104658. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104659. i=tt->threshvals>>1;
  104660. if(a[o]<tt->quantthresh[i]){
  104661. for(;i>0;i--)
  104662. if(a[o]>=tt->quantthresh[i-1])
  104663. break;
  104664. }else{
  104665. for(i++;i<tt->threshvals-1;i++)
  104666. if(a[o]<tt->quantthresh[i])break;
  104667. }
  104668. index=(index*tt->quantvals)+tt->quantmap[i];
  104669. }
  104670. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104671. use a decision tree after all
  104672. and fall through*/
  104673. return(index);
  104674. }
  104675. #if 0
  104676. if(pt){
  104677. const static_codebook *c=book->c;
  104678. int i,besti=-1;
  104679. float best=0.f;
  104680. int entry=0;
  104681. if(c->q_sequencep){
  104682. int pv;
  104683. long mul=1;
  104684. float qlast=0;
  104685. for(k=0,o=0;k<dim;k++,o+=step){
  104686. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104687. if(pv<0 || pv>=pt->mapentries)break;
  104688. entry+=pt->pigeonmap[pv]*mul;
  104689. mul*=pt->quantvals;
  104690. qlast+=pv*pt->del+pt->min;
  104691. }
  104692. }else{
  104693. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104694. int pv=(int)((a[o]-pt->min)/pt->del);
  104695. if(pv<0 || pv>=pt->mapentries)break;
  104696. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  104697. }
  104698. }
  104699. if(k==dim && pt->fitlength[entry]){
  104700. long *list=pt->fitlist+pt->fitmap[entry];
  104701. for(i=0;i<pt->fitlength[entry];i++){
  104702. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  104703. if(besti==-1 || this<best){
  104704. best=this;
  104705. besti=list[i];
  104706. }
  104707. }
  104708. return(besti);
  104709. }
  104710. }
  104711. if(nt){
  104712. while(1){
  104713. float c=0.f;
  104714. float *p=book->valuelist+nt->p[ptr];
  104715. float *q=book->valuelist+nt->q[ptr];
  104716. for(k=0,o=0;k<dim;k++,o+=step)
  104717. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  104718. if(c>0.f) /* in A */
  104719. ptr= -nt->ptr0[ptr];
  104720. else /* in B */
  104721. ptr= -nt->ptr1[ptr];
  104722. if(ptr<=0)break;
  104723. }
  104724. return(-ptr);
  104725. }
  104726. #endif
  104727. {
  104728. const static_codebook *c=book->c;
  104729. int i,besti=-1;
  104730. float best=0.f;
  104731. float *e=book->valuelist;
  104732. for(i=0;i<book->entries;i++){
  104733. if(c->lengthlist[i]>0){
  104734. float thisx=_dist(dim,e,a,step);
  104735. if(besti==-1 || thisx<best){
  104736. best=thisx;
  104737. besti=i;
  104738. }
  104739. }
  104740. e+=dim;
  104741. }
  104742. return(besti);
  104743. }
  104744. }
  104745. long vorbis_book_codeword(codebook *book,int entry){
  104746. if(book->c) /* only use with encode; decode optimizations are
  104747. allowed to break this */
  104748. return book->codelist[entry];
  104749. return -1;
  104750. }
  104751. long vorbis_book_codelen(codebook *book,int entry){
  104752. if(book->c) /* only use with encode; decode optimizations are
  104753. allowed to break this */
  104754. return book->c->lengthlist[entry];
  104755. return -1;
  104756. }
  104757. #ifdef _V_SELFTEST
  104758. #include <stdio.h>
  104759. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  104760. static long partial_quantlist1[]={0,7,2};
  104761. static_codebook test1={
  104762. 4,16,
  104763. NULL,
  104764. 0,
  104765. 0,0,0,0,
  104766. NULL,
  104767. NULL,NULL
  104768. };
  104769. static float *test1_result=NULL;
  104770. static_codebook test2={
  104771. 4,3,
  104772. NULL,
  104773. 2,
  104774. -533200896,1611661312,4,0,
  104775. full_quantlist1,
  104776. NULL,NULL
  104777. };
  104778. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  104779. static_codebook test3={
  104780. 4,3,
  104781. NULL,
  104782. 2,
  104783. -533200896,1611661312,4,1,
  104784. full_quantlist1,
  104785. NULL,NULL
  104786. };
  104787. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  104788. static_codebook test4={
  104789. 3,27,
  104790. NULL,
  104791. 1,
  104792. -533200896,1611661312,4,0,
  104793. partial_quantlist1,
  104794. NULL,NULL
  104795. };
  104796. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  104797. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  104798. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  104799. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  104800. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  104801. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  104802. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  104803. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  104804. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  104805. static_codebook test5={
  104806. 3,27,
  104807. NULL,
  104808. 1,
  104809. -533200896,1611661312,4,1,
  104810. partial_quantlist1,
  104811. NULL,NULL
  104812. };
  104813. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  104814. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  104815. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  104816. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  104817. -3, 1, 5, 4, 8,12, -1, 3, 7,
  104818. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  104819. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  104820. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  104821. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  104822. void run_test(static_codebook *b,float *comp){
  104823. float *out=_book_unquantize(b,b->entries,NULL);
  104824. int i;
  104825. if(comp){
  104826. if(!out){
  104827. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  104828. exit(1);
  104829. }
  104830. for(i=0;i<b->entries*b->dim;i++)
  104831. if(fabs(out[i]-comp[i])>.0001){
  104832. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  104833. "position %d, %g != %g\n",i,out[i],comp[i]);
  104834. exit(1);
  104835. }
  104836. }else{
  104837. if(out){
  104838. fprintf(stderr,"_book_unquantize returned a value array: \n"
  104839. " correct result should have been NULL\n");
  104840. exit(1);
  104841. }
  104842. }
  104843. }
  104844. int main(){
  104845. fprintf(stderr,"Dequant test 1... ");
  104846. run_test(&test1,test1_result);
  104847. fprintf(stderr,"OK\nDequant test 2... ");
  104848. run_test(&test2,test2_result);
  104849. fprintf(stderr,"OK\nDequant test 3... ");
  104850. run_test(&test3,test3_result);
  104851. fprintf(stderr,"OK\nDequant test 4... ");
  104852. run_test(&test4,test4_result);
  104853. fprintf(stderr,"OK\nDequant test 5... ");
  104854. run_test(&test5,test5_result);
  104855. fprintf(stderr,"OK\n\n");
  104856. return(0);
  104857. }
  104858. #endif
  104859. #endif
  104860. /*** End of inlined file: sharedbook.c ***/
  104861. /*** Start of inlined file: smallft.c ***/
  104862. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104863. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104864. // tasks..
  104865. #if JUCE_MSVC
  104866. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104867. #endif
  104868. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104869. #if JUCE_USE_OGGVORBIS
  104870. #include <stdlib.h>
  104871. #include <string.h>
  104872. #include <math.h>
  104873. static void drfti1(int n, float *wa, int *ifac){
  104874. static int ntryh[4] = { 4,2,3,5 };
  104875. static float tpi = 6.28318530717958648f;
  104876. float arg,argh,argld,fi;
  104877. int ntry=0,i,j=-1;
  104878. int k1, l1, l2, ib;
  104879. int ld, ii, ip, is, nq, nr;
  104880. int ido, ipm, nfm1;
  104881. int nl=n;
  104882. int nf=0;
  104883. L101:
  104884. j++;
  104885. if (j < 4)
  104886. ntry=ntryh[j];
  104887. else
  104888. ntry+=2;
  104889. L104:
  104890. nq=nl/ntry;
  104891. nr=nl-ntry*nq;
  104892. if (nr!=0) goto L101;
  104893. nf++;
  104894. ifac[nf+1]=ntry;
  104895. nl=nq;
  104896. if(ntry!=2)goto L107;
  104897. if(nf==1)goto L107;
  104898. for (i=1;i<nf;i++){
  104899. ib=nf-i+1;
  104900. ifac[ib+1]=ifac[ib];
  104901. }
  104902. ifac[2] = 2;
  104903. L107:
  104904. if(nl!=1)goto L104;
  104905. ifac[0]=n;
  104906. ifac[1]=nf;
  104907. argh=tpi/n;
  104908. is=0;
  104909. nfm1=nf-1;
  104910. l1=1;
  104911. if(nfm1==0)return;
  104912. for (k1=0;k1<nfm1;k1++){
  104913. ip=ifac[k1+2];
  104914. ld=0;
  104915. l2=l1*ip;
  104916. ido=n/l2;
  104917. ipm=ip-1;
  104918. for (j=0;j<ipm;j++){
  104919. ld+=l1;
  104920. i=is;
  104921. argld=(float)ld*argh;
  104922. fi=0.f;
  104923. for (ii=2;ii<ido;ii+=2){
  104924. fi+=1.f;
  104925. arg=fi*argld;
  104926. wa[i++]=cos(arg);
  104927. wa[i++]=sin(arg);
  104928. }
  104929. is+=ido;
  104930. }
  104931. l1=l2;
  104932. }
  104933. }
  104934. static void fdrffti(int n, float *wsave, int *ifac){
  104935. if (n == 1) return;
  104936. drfti1(n, wsave+n, ifac);
  104937. }
  104938. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  104939. int i,k;
  104940. float ti2,tr2;
  104941. int t0,t1,t2,t3,t4,t5,t6;
  104942. t1=0;
  104943. t0=(t2=l1*ido);
  104944. t3=ido<<1;
  104945. for(k=0;k<l1;k++){
  104946. ch[t1<<1]=cc[t1]+cc[t2];
  104947. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  104948. t1+=ido;
  104949. t2+=ido;
  104950. }
  104951. if(ido<2)return;
  104952. if(ido==2)goto L105;
  104953. t1=0;
  104954. t2=t0;
  104955. for(k=0;k<l1;k++){
  104956. t3=t2;
  104957. t4=(t1<<1)+(ido<<1);
  104958. t5=t1;
  104959. t6=t1+t1;
  104960. for(i=2;i<ido;i+=2){
  104961. t3+=2;
  104962. t4-=2;
  104963. t5+=2;
  104964. t6+=2;
  104965. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  104966. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  104967. ch[t6]=cc[t5]+ti2;
  104968. ch[t4]=ti2-cc[t5];
  104969. ch[t6-1]=cc[t5-1]+tr2;
  104970. ch[t4-1]=cc[t5-1]-tr2;
  104971. }
  104972. t1+=ido;
  104973. t2+=ido;
  104974. }
  104975. if(ido%2==1)return;
  104976. L105:
  104977. t3=(t2=(t1=ido)-1);
  104978. t2+=t0;
  104979. for(k=0;k<l1;k++){
  104980. ch[t1]=-cc[t2];
  104981. ch[t1-1]=cc[t3];
  104982. t1+=ido<<1;
  104983. t2+=ido;
  104984. t3+=ido;
  104985. }
  104986. }
  104987. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  104988. float *wa2,float *wa3){
  104989. static float hsqt2 = .70710678118654752f;
  104990. int i,k,t0,t1,t2,t3,t4,t5,t6;
  104991. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  104992. t0=l1*ido;
  104993. t1=t0;
  104994. t4=t1<<1;
  104995. t2=t1+(t1<<1);
  104996. t3=0;
  104997. for(k=0;k<l1;k++){
  104998. tr1=cc[t1]+cc[t2];
  104999. tr2=cc[t3]+cc[t4];
  105000. ch[t5=t3<<2]=tr1+tr2;
  105001. ch[(ido<<2)+t5-1]=tr2-tr1;
  105002. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105003. ch[t5]=cc[t2]-cc[t1];
  105004. t1+=ido;
  105005. t2+=ido;
  105006. t3+=ido;
  105007. t4+=ido;
  105008. }
  105009. if(ido<2)return;
  105010. if(ido==2)goto L105;
  105011. t1=0;
  105012. for(k=0;k<l1;k++){
  105013. t2=t1;
  105014. t4=t1<<2;
  105015. t5=(t6=ido<<1)+t4;
  105016. for(i=2;i<ido;i+=2){
  105017. t3=(t2+=2);
  105018. t4+=2;
  105019. t5-=2;
  105020. t3+=t0;
  105021. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105022. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105023. t3+=t0;
  105024. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105025. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105026. t3+=t0;
  105027. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105028. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105029. tr1=cr2+cr4;
  105030. tr4=cr4-cr2;
  105031. ti1=ci2+ci4;
  105032. ti4=ci2-ci4;
  105033. ti2=cc[t2]+ci3;
  105034. ti3=cc[t2]-ci3;
  105035. tr2=cc[t2-1]+cr3;
  105036. tr3=cc[t2-1]-cr3;
  105037. ch[t4-1]=tr1+tr2;
  105038. ch[t4]=ti1+ti2;
  105039. ch[t5-1]=tr3-ti4;
  105040. ch[t5]=tr4-ti3;
  105041. ch[t4+t6-1]=ti4+tr3;
  105042. ch[t4+t6]=tr4+ti3;
  105043. ch[t5+t6-1]=tr2-tr1;
  105044. ch[t5+t6]=ti1-ti2;
  105045. }
  105046. t1+=ido;
  105047. }
  105048. if(ido&1)return;
  105049. L105:
  105050. t2=(t1=t0+ido-1)+(t0<<1);
  105051. t3=ido<<2;
  105052. t4=ido;
  105053. t5=ido<<1;
  105054. t6=ido;
  105055. for(k=0;k<l1;k++){
  105056. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105057. tr1=hsqt2*(cc[t1]-cc[t2]);
  105058. ch[t4-1]=tr1+cc[t6-1];
  105059. ch[t4+t5-1]=cc[t6-1]-tr1;
  105060. ch[t4]=ti1-cc[t1+t0];
  105061. ch[t4+t5]=ti1+cc[t1+t0];
  105062. t1+=ido;
  105063. t2+=ido;
  105064. t4+=t3;
  105065. t6+=ido;
  105066. }
  105067. }
  105068. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105069. float *c2,float *ch,float *ch2,float *wa){
  105070. static float tpi=6.283185307179586f;
  105071. int idij,ipph,i,j,k,l,ic,ik,is;
  105072. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105073. float dc2,ai1,ai2,ar1,ar2,ds2;
  105074. int nbd;
  105075. float dcp,arg,dsp,ar1h,ar2h;
  105076. int idp2,ipp2;
  105077. arg=tpi/(float)ip;
  105078. dcp=cos(arg);
  105079. dsp=sin(arg);
  105080. ipph=(ip+1)>>1;
  105081. ipp2=ip;
  105082. idp2=ido;
  105083. nbd=(ido-1)>>1;
  105084. t0=l1*ido;
  105085. t10=ip*ido;
  105086. if(ido==1)goto L119;
  105087. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105088. t1=0;
  105089. for(j=1;j<ip;j++){
  105090. t1+=t0;
  105091. t2=t1;
  105092. for(k=0;k<l1;k++){
  105093. ch[t2]=c1[t2];
  105094. t2+=ido;
  105095. }
  105096. }
  105097. is=-ido;
  105098. t1=0;
  105099. if(nbd>l1){
  105100. for(j=1;j<ip;j++){
  105101. t1+=t0;
  105102. is+=ido;
  105103. t2= -ido+t1;
  105104. for(k=0;k<l1;k++){
  105105. idij=is-1;
  105106. t2+=ido;
  105107. t3=t2;
  105108. for(i=2;i<ido;i+=2){
  105109. idij+=2;
  105110. t3+=2;
  105111. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105112. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105113. }
  105114. }
  105115. }
  105116. }else{
  105117. for(j=1;j<ip;j++){
  105118. is+=ido;
  105119. idij=is-1;
  105120. t1+=t0;
  105121. t2=t1;
  105122. for(i=2;i<ido;i+=2){
  105123. idij+=2;
  105124. t2+=2;
  105125. t3=t2;
  105126. for(k=0;k<l1;k++){
  105127. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105128. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105129. t3+=ido;
  105130. }
  105131. }
  105132. }
  105133. }
  105134. t1=0;
  105135. t2=ipp2*t0;
  105136. if(nbd<l1){
  105137. for(j=1;j<ipph;j++){
  105138. t1+=t0;
  105139. t2-=t0;
  105140. t3=t1;
  105141. t4=t2;
  105142. for(i=2;i<ido;i+=2){
  105143. t3+=2;
  105144. t4+=2;
  105145. t5=t3-ido;
  105146. t6=t4-ido;
  105147. for(k=0;k<l1;k++){
  105148. t5+=ido;
  105149. t6+=ido;
  105150. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105151. c1[t6-1]=ch[t5]-ch[t6];
  105152. c1[t5]=ch[t5]+ch[t6];
  105153. c1[t6]=ch[t6-1]-ch[t5-1];
  105154. }
  105155. }
  105156. }
  105157. }else{
  105158. for(j=1;j<ipph;j++){
  105159. t1+=t0;
  105160. t2-=t0;
  105161. t3=t1;
  105162. t4=t2;
  105163. for(k=0;k<l1;k++){
  105164. t5=t3;
  105165. t6=t4;
  105166. for(i=2;i<ido;i+=2){
  105167. t5+=2;
  105168. t6+=2;
  105169. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105170. c1[t6-1]=ch[t5]-ch[t6];
  105171. c1[t5]=ch[t5]+ch[t6];
  105172. c1[t6]=ch[t6-1]-ch[t5-1];
  105173. }
  105174. t3+=ido;
  105175. t4+=ido;
  105176. }
  105177. }
  105178. }
  105179. L119:
  105180. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105181. t1=0;
  105182. t2=ipp2*idl1;
  105183. for(j=1;j<ipph;j++){
  105184. t1+=t0;
  105185. t2-=t0;
  105186. t3=t1-ido;
  105187. t4=t2-ido;
  105188. for(k=0;k<l1;k++){
  105189. t3+=ido;
  105190. t4+=ido;
  105191. c1[t3]=ch[t3]+ch[t4];
  105192. c1[t4]=ch[t4]-ch[t3];
  105193. }
  105194. }
  105195. ar1=1.f;
  105196. ai1=0.f;
  105197. t1=0;
  105198. t2=ipp2*idl1;
  105199. t3=(ip-1)*idl1;
  105200. for(l=1;l<ipph;l++){
  105201. t1+=idl1;
  105202. t2-=idl1;
  105203. ar1h=dcp*ar1-dsp*ai1;
  105204. ai1=dcp*ai1+dsp*ar1;
  105205. ar1=ar1h;
  105206. t4=t1;
  105207. t5=t2;
  105208. t6=t3;
  105209. t7=idl1;
  105210. for(ik=0;ik<idl1;ik++){
  105211. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105212. ch2[t5++]=ai1*c2[t6++];
  105213. }
  105214. dc2=ar1;
  105215. ds2=ai1;
  105216. ar2=ar1;
  105217. ai2=ai1;
  105218. t4=idl1;
  105219. t5=(ipp2-1)*idl1;
  105220. for(j=2;j<ipph;j++){
  105221. t4+=idl1;
  105222. t5-=idl1;
  105223. ar2h=dc2*ar2-ds2*ai2;
  105224. ai2=dc2*ai2+ds2*ar2;
  105225. ar2=ar2h;
  105226. t6=t1;
  105227. t7=t2;
  105228. t8=t4;
  105229. t9=t5;
  105230. for(ik=0;ik<idl1;ik++){
  105231. ch2[t6++]+=ar2*c2[t8++];
  105232. ch2[t7++]+=ai2*c2[t9++];
  105233. }
  105234. }
  105235. }
  105236. t1=0;
  105237. for(j=1;j<ipph;j++){
  105238. t1+=idl1;
  105239. t2=t1;
  105240. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105241. }
  105242. if(ido<l1)goto L132;
  105243. t1=0;
  105244. t2=0;
  105245. for(k=0;k<l1;k++){
  105246. t3=t1;
  105247. t4=t2;
  105248. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105249. t1+=ido;
  105250. t2+=t10;
  105251. }
  105252. goto L135;
  105253. L132:
  105254. for(i=0;i<ido;i++){
  105255. t1=i;
  105256. t2=i;
  105257. for(k=0;k<l1;k++){
  105258. cc[t2]=ch[t1];
  105259. t1+=ido;
  105260. t2+=t10;
  105261. }
  105262. }
  105263. L135:
  105264. t1=0;
  105265. t2=ido<<1;
  105266. t3=0;
  105267. t4=ipp2*t0;
  105268. for(j=1;j<ipph;j++){
  105269. t1+=t2;
  105270. t3+=t0;
  105271. t4-=t0;
  105272. t5=t1;
  105273. t6=t3;
  105274. t7=t4;
  105275. for(k=0;k<l1;k++){
  105276. cc[t5-1]=ch[t6];
  105277. cc[t5]=ch[t7];
  105278. t5+=t10;
  105279. t6+=ido;
  105280. t7+=ido;
  105281. }
  105282. }
  105283. if(ido==1)return;
  105284. if(nbd<l1)goto L141;
  105285. t1=-ido;
  105286. t3=0;
  105287. t4=0;
  105288. t5=ipp2*t0;
  105289. for(j=1;j<ipph;j++){
  105290. t1+=t2;
  105291. t3+=t2;
  105292. t4+=t0;
  105293. t5-=t0;
  105294. t6=t1;
  105295. t7=t3;
  105296. t8=t4;
  105297. t9=t5;
  105298. for(k=0;k<l1;k++){
  105299. for(i=2;i<ido;i+=2){
  105300. ic=idp2-i;
  105301. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105302. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105303. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105304. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105305. }
  105306. t6+=t10;
  105307. t7+=t10;
  105308. t8+=ido;
  105309. t9+=ido;
  105310. }
  105311. }
  105312. return;
  105313. L141:
  105314. t1=-ido;
  105315. t3=0;
  105316. t4=0;
  105317. t5=ipp2*t0;
  105318. for(j=1;j<ipph;j++){
  105319. t1+=t2;
  105320. t3+=t2;
  105321. t4+=t0;
  105322. t5-=t0;
  105323. for(i=2;i<ido;i+=2){
  105324. t6=idp2+t1-i;
  105325. t7=i+t3;
  105326. t8=i+t4;
  105327. t9=i+t5;
  105328. for(k=0;k<l1;k++){
  105329. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105330. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105331. cc[t7]=ch[t8]+ch[t9];
  105332. cc[t6]=ch[t9]-ch[t8];
  105333. t6+=t10;
  105334. t7+=t10;
  105335. t8+=ido;
  105336. t9+=ido;
  105337. }
  105338. }
  105339. }
  105340. }
  105341. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105342. int i,k1,l1,l2;
  105343. int na,kh,nf;
  105344. int ip,iw,ido,idl1,ix2,ix3;
  105345. nf=ifac[1];
  105346. na=1;
  105347. l2=n;
  105348. iw=n;
  105349. for(k1=0;k1<nf;k1++){
  105350. kh=nf-k1;
  105351. ip=ifac[kh+1];
  105352. l1=l2/ip;
  105353. ido=n/l2;
  105354. idl1=ido*l1;
  105355. iw-=(ip-1)*ido;
  105356. na=1-na;
  105357. if(ip!=4)goto L102;
  105358. ix2=iw+ido;
  105359. ix3=ix2+ido;
  105360. if(na!=0)
  105361. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105362. else
  105363. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105364. goto L110;
  105365. L102:
  105366. if(ip!=2)goto L104;
  105367. if(na!=0)goto L103;
  105368. dradf2(ido,l1,c,ch,wa+iw-1);
  105369. goto L110;
  105370. L103:
  105371. dradf2(ido,l1,ch,c,wa+iw-1);
  105372. goto L110;
  105373. L104:
  105374. if(ido==1)na=1-na;
  105375. if(na!=0)goto L109;
  105376. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105377. na=1;
  105378. goto L110;
  105379. L109:
  105380. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105381. na=0;
  105382. L110:
  105383. l2=l1;
  105384. }
  105385. if(na==1)return;
  105386. for(i=0;i<n;i++)c[i]=ch[i];
  105387. }
  105388. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105389. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105390. float ti2,tr2;
  105391. t0=l1*ido;
  105392. t1=0;
  105393. t2=0;
  105394. t3=(ido<<1)-1;
  105395. for(k=0;k<l1;k++){
  105396. ch[t1]=cc[t2]+cc[t3+t2];
  105397. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105398. t2=(t1+=ido)<<1;
  105399. }
  105400. if(ido<2)return;
  105401. if(ido==2)goto L105;
  105402. t1=0;
  105403. t2=0;
  105404. for(k=0;k<l1;k++){
  105405. t3=t1;
  105406. t5=(t4=t2)+(ido<<1);
  105407. t6=t0+t1;
  105408. for(i=2;i<ido;i+=2){
  105409. t3+=2;
  105410. t4+=2;
  105411. t5-=2;
  105412. t6+=2;
  105413. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105414. tr2=cc[t4-1]-cc[t5-1];
  105415. ch[t3]=cc[t4]-cc[t5];
  105416. ti2=cc[t4]+cc[t5];
  105417. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105418. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105419. }
  105420. t2=(t1+=ido)<<1;
  105421. }
  105422. if(ido%2==1)return;
  105423. L105:
  105424. t1=ido-1;
  105425. t2=ido-1;
  105426. for(k=0;k<l1;k++){
  105427. ch[t1]=cc[t2]+cc[t2];
  105428. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105429. t1+=ido;
  105430. t2+=ido<<1;
  105431. }
  105432. }
  105433. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105434. float *wa2){
  105435. static float taur = -.5f;
  105436. static float taui = .8660254037844386f;
  105437. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105438. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105439. t0=l1*ido;
  105440. t1=0;
  105441. t2=t0<<1;
  105442. t3=ido<<1;
  105443. t4=ido+(ido<<1);
  105444. t5=0;
  105445. for(k=0;k<l1;k++){
  105446. tr2=cc[t3-1]+cc[t3-1];
  105447. cr2=cc[t5]+(taur*tr2);
  105448. ch[t1]=cc[t5]+tr2;
  105449. ci3=taui*(cc[t3]+cc[t3]);
  105450. ch[t1+t0]=cr2-ci3;
  105451. ch[t1+t2]=cr2+ci3;
  105452. t1+=ido;
  105453. t3+=t4;
  105454. t5+=t4;
  105455. }
  105456. if(ido==1)return;
  105457. t1=0;
  105458. t3=ido<<1;
  105459. for(k=0;k<l1;k++){
  105460. t7=t1+(t1<<1);
  105461. t6=(t5=t7+t3);
  105462. t8=t1;
  105463. t10=(t9=t1+t0)+t0;
  105464. for(i=2;i<ido;i+=2){
  105465. t5+=2;
  105466. t6-=2;
  105467. t7+=2;
  105468. t8+=2;
  105469. t9+=2;
  105470. t10+=2;
  105471. tr2=cc[t5-1]+cc[t6-1];
  105472. cr2=cc[t7-1]+(taur*tr2);
  105473. ch[t8-1]=cc[t7-1]+tr2;
  105474. ti2=cc[t5]-cc[t6];
  105475. ci2=cc[t7]+(taur*ti2);
  105476. ch[t8]=cc[t7]+ti2;
  105477. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105478. ci3=taui*(cc[t5]+cc[t6]);
  105479. dr2=cr2-ci3;
  105480. dr3=cr2+ci3;
  105481. di2=ci2+cr3;
  105482. di3=ci2-cr3;
  105483. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105484. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105485. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105486. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105487. }
  105488. t1+=ido;
  105489. }
  105490. }
  105491. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105492. float *wa2,float *wa3){
  105493. static float sqrt2=1.414213562373095f;
  105494. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105495. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105496. t0=l1*ido;
  105497. t1=0;
  105498. t2=ido<<2;
  105499. t3=0;
  105500. t6=ido<<1;
  105501. for(k=0;k<l1;k++){
  105502. t4=t3+t6;
  105503. t5=t1;
  105504. tr3=cc[t4-1]+cc[t4-1];
  105505. tr4=cc[t4]+cc[t4];
  105506. tr1=cc[t3]-cc[(t4+=t6)-1];
  105507. tr2=cc[t3]+cc[t4-1];
  105508. ch[t5]=tr2+tr3;
  105509. ch[t5+=t0]=tr1-tr4;
  105510. ch[t5+=t0]=tr2-tr3;
  105511. ch[t5+=t0]=tr1+tr4;
  105512. t1+=ido;
  105513. t3+=t2;
  105514. }
  105515. if(ido<2)return;
  105516. if(ido==2)goto L105;
  105517. t1=0;
  105518. for(k=0;k<l1;k++){
  105519. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105520. t7=t1;
  105521. for(i=2;i<ido;i+=2){
  105522. t2+=2;
  105523. t3+=2;
  105524. t4-=2;
  105525. t5-=2;
  105526. t7+=2;
  105527. ti1=cc[t2]+cc[t5];
  105528. ti2=cc[t2]-cc[t5];
  105529. ti3=cc[t3]-cc[t4];
  105530. tr4=cc[t3]+cc[t4];
  105531. tr1=cc[t2-1]-cc[t5-1];
  105532. tr2=cc[t2-1]+cc[t5-1];
  105533. ti4=cc[t3-1]-cc[t4-1];
  105534. tr3=cc[t3-1]+cc[t4-1];
  105535. ch[t7-1]=tr2+tr3;
  105536. cr3=tr2-tr3;
  105537. ch[t7]=ti2+ti3;
  105538. ci3=ti2-ti3;
  105539. cr2=tr1-tr4;
  105540. cr4=tr1+tr4;
  105541. ci2=ti1+ti4;
  105542. ci4=ti1-ti4;
  105543. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105544. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105545. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105546. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105547. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105548. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105549. }
  105550. t1+=ido;
  105551. }
  105552. if(ido%2 == 1)return;
  105553. L105:
  105554. t1=ido;
  105555. t2=ido<<2;
  105556. t3=ido-1;
  105557. t4=ido+(ido<<1);
  105558. for(k=0;k<l1;k++){
  105559. t5=t3;
  105560. ti1=cc[t1]+cc[t4];
  105561. ti2=cc[t4]-cc[t1];
  105562. tr1=cc[t1-1]-cc[t4-1];
  105563. tr2=cc[t1-1]+cc[t4-1];
  105564. ch[t5]=tr2+tr2;
  105565. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105566. ch[t5+=t0]=ti2+ti2;
  105567. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105568. t3+=ido;
  105569. t1+=t2;
  105570. t4+=t2;
  105571. }
  105572. }
  105573. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105574. float *c2,float *ch,float *ch2,float *wa){
  105575. static float tpi=6.283185307179586f;
  105576. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105577. t11,t12;
  105578. float dc2,ai1,ai2,ar1,ar2,ds2;
  105579. int nbd;
  105580. float dcp,arg,dsp,ar1h,ar2h;
  105581. int ipp2;
  105582. t10=ip*ido;
  105583. t0=l1*ido;
  105584. arg=tpi/(float)ip;
  105585. dcp=cos(arg);
  105586. dsp=sin(arg);
  105587. nbd=(ido-1)>>1;
  105588. ipp2=ip;
  105589. ipph=(ip+1)>>1;
  105590. if(ido<l1)goto L103;
  105591. t1=0;
  105592. t2=0;
  105593. for(k=0;k<l1;k++){
  105594. t3=t1;
  105595. t4=t2;
  105596. for(i=0;i<ido;i++){
  105597. ch[t3]=cc[t4];
  105598. t3++;
  105599. t4++;
  105600. }
  105601. t1+=ido;
  105602. t2+=t10;
  105603. }
  105604. goto L106;
  105605. L103:
  105606. t1=0;
  105607. for(i=0;i<ido;i++){
  105608. t2=t1;
  105609. t3=t1;
  105610. for(k=0;k<l1;k++){
  105611. ch[t2]=cc[t3];
  105612. t2+=ido;
  105613. t3+=t10;
  105614. }
  105615. t1++;
  105616. }
  105617. L106:
  105618. t1=0;
  105619. t2=ipp2*t0;
  105620. t7=(t5=ido<<1);
  105621. for(j=1;j<ipph;j++){
  105622. t1+=t0;
  105623. t2-=t0;
  105624. t3=t1;
  105625. t4=t2;
  105626. t6=t5;
  105627. for(k=0;k<l1;k++){
  105628. ch[t3]=cc[t6-1]+cc[t6-1];
  105629. ch[t4]=cc[t6]+cc[t6];
  105630. t3+=ido;
  105631. t4+=ido;
  105632. t6+=t10;
  105633. }
  105634. t5+=t7;
  105635. }
  105636. if (ido == 1)goto L116;
  105637. if(nbd<l1)goto L112;
  105638. t1=0;
  105639. t2=ipp2*t0;
  105640. t7=0;
  105641. for(j=1;j<ipph;j++){
  105642. t1+=t0;
  105643. t2-=t0;
  105644. t3=t1;
  105645. t4=t2;
  105646. t7+=(ido<<1);
  105647. t8=t7;
  105648. for(k=0;k<l1;k++){
  105649. t5=t3;
  105650. t6=t4;
  105651. t9=t8;
  105652. t11=t8;
  105653. for(i=2;i<ido;i+=2){
  105654. t5+=2;
  105655. t6+=2;
  105656. t9+=2;
  105657. t11-=2;
  105658. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105659. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105660. ch[t5]=cc[t9]-cc[t11];
  105661. ch[t6]=cc[t9]+cc[t11];
  105662. }
  105663. t3+=ido;
  105664. t4+=ido;
  105665. t8+=t10;
  105666. }
  105667. }
  105668. goto L116;
  105669. L112:
  105670. t1=0;
  105671. t2=ipp2*t0;
  105672. t7=0;
  105673. for(j=1;j<ipph;j++){
  105674. t1+=t0;
  105675. t2-=t0;
  105676. t3=t1;
  105677. t4=t2;
  105678. t7+=(ido<<1);
  105679. t8=t7;
  105680. t9=t7;
  105681. for(i=2;i<ido;i+=2){
  105682. t3+=2;
  105683. t4+=2;
  105684. t8+=2;
  105685. t9-=2;
  105686. t5=t3;
  105687. t6=t4;
  105688. t11=t8;
  105689. t12=t9;
  105690. for(k=0;k<l1;k++){
  105691. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105692. ch[t6-1]=cc[t11-1]-cc[t12-1];
  105693. ch[t5]=cc[t11]-cc[t12];
  105694. ch[t6]=cc[t11]+cc[t12];
  105695. t5+=ido;
  105696. t6+=ido;
  105697. t11+=t10;
  105698. t12+=t10;
  105699. }
  105700. }
  105701. }
  105702. L116:
  105703. ar1=1.f;
  105704. ai1=0.f;
  105705. t1=0;
  105706. t9=(t2=ipp2*idl1);
  105707. t3=(ip-1)*idl1;
  105708. for(l=1;l<ipph;l++){
  105709. t1+=idl1;
  105710. t2-=idl1;
  105711. ar1h=dcp*ar1-dsp*ai1;
  105712. ai1=dcp*ai1+dsp*ar1;
  105713. ar1=ar1h;
  105714. t4=t1;
  105715. t5=t2;
  105716. t6=0;
  105717. t7=idl1;
  105718. t8=t3;
  105719. for(ik=0;ik<idl1;ik++){
  105720. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  105721. c2[t5++]=ai1*ch2[t8++];
  105722. }
  105723. dc2=ar1;
  105724. ds2=ai1;
  105725. ar2=ar1;
  105726. ai2=ai1;
  105727. t6=idl1;
  105728. t7=t9-idl1;
  105729. for(j=2;j<ipph;j++){
  105730. t6+=idl1;
  105731. t7-=idl1;
  105732. ar2h=dc2*ar2-ds2*ai2;
  105733. ai2=dc2*ai2+ds2*ar2;
  105734. ar2=ar2h;
  105735. t4=t1;
  105736. t5=t2;
  105737. t11=t6;
  105738. t12=t7;
  105739. for(ik=0;ik<idl1;ik++){
  105740. c2[t4++]+=ar2*ch2[t11++];
  105741. c2[t5++]+=ai2*ch2[t12++];
  105742. }
  105743. }
  105744. }
  105745. t1=0;
  105746. for(j=1;j<ipph;j++){
  105747. t1+=idl1;
  105748. t2=t1;
  105749. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  105750. }
  105751. t1=0;
  105752. t2=ipp2*t0;
  105753. for(j=1;j<ipph;j++){
  105754. t1+=t0;
  105755. t2-=t0;
  105756. t3=t1;
  105757. t4=t2;
  105758. for(k=0;k<l1;k++){
  105759. ch[t3]=c1[t3]-c1[t4];
  105760. ch[t4]=c1[t3]+c1[t4];
  105761. t3+=ido;
  105762. t4+=ido;
  105763. }
  105764. }
  105765. if(ido==1)goto L132;
  105766. if(nbd<l1)goto L128;
  105767. t1=0;
  105768. t2=ipp2*t0;
  105769. for(j=1;j<ipph;j++){
  105770. t1+=t0;
  105771. t2-=t0;
  105772. t3=t1;
  105773. t4=t2;
  105774. for(k=0;k<l1;k++){
  105775. t5=t3;
  105776. t6=t4;
  105777. for(i=2;i<ido;i+=2){
  105778. t5+=2;
  105779. t6+=2;
  105780. ch[t5-1]=c1[t5-1]-c1[t6];
  105781. ch[t6-1]=c1[t5-1]+c1[t6];
  105782. ch[t5]=c1[t5]+c1[t6-1];
  105783. ch[t6]=c1[t5]-c1[t6-1];
  105784. }
  105785. t3+=ido;
  105786. t4+=ido;
  105787. }
  105788. }
  105789. goto L132;
  105790. L128:
  105791. t1=0;
  105792. t2=ipp2*t0;
  105793. for(j=1;j<ipph;j++){
  105794. t1+=t0;
  105795. t2-=t0;
  105796. t3=t1;
  105797. t4=t2;
  105798. for(i=2;i<ido;i+=2){
  105799. t3+=2;
  105800. t4+=2;
  105801. t5=t3;
  105802. t6=t4;
  105803. for(k=0;k<l1;k++){
  105804. ch[t5-1]=c1[t5-1]-c1[t6];
  105805. ch[t6-1]=c1[t5-1]+c1[t6];
  105806. ch[t5]=c1[t5]+c1[t6-1];
  105807. ch[t6]=c1[t5]-c1[t6-1];
  105808. t5+=ido;
  105809. t6+=ido;
  105810. }
  105811. }
  105812. }
  105813. L132:
  105814. if(ido==1)return;
  105815. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105816. t1=0;
  105817. for(j=1;j<ip;j++){
  105818. t2=(t1+=t0);
  105819. for(k=0;k<l1;k++){
  105820. c1[t2]=ch[t2];
  105821. t2+=ido;
  105822. }
  105823. }
  105824. if(nbd>l1)goto L139;
  105825. is= -ido-1;
  105826. t1=0;
  105827. for(j=1;j<ip;j++){
  105828. is+=ido;
  105829. t1+=t0;
  105830. idij=is;
  105831. t2=t1;
  105832. for(i=2;i<ido;i+=2){
  105833. t2+=2;
  105834. idij+=2;
  105835. t3=t2;
  105836. for(k=0;k<l1;k++){
  105837. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  105838. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  105839. t3+=ido;
  105840. }
  105841. }
  105842. }
  105843. return;
  105844. L139:
  105845. is= -ido-1;
  105846. t1=0;
  105847. for(j=1;j<ip;j++){
  105848. is+=ido;
  105849. t1+=t0;
  105850. t2=t1;
  105851. for(k=0;k<l1;k++){
  105852. idij=is;
  105853. t3=t2;
  105854. for(i=2;i<ido;i+=2){
  105855. idij+=2;
  105856. t3+=2;
  105857. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  105858. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  105859. }
  105860. t2+=ido;
  105861. }
  105862. }
  105863. }
  105864. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  105865. int i,k1,l1,l2;
  105866. int na;
  105867. int nf,ip,iw,ix2,ix3,ido,idl1;
  105868. nf=ifac[1];
  105869. na=0;
  105870. l1=1;
  105871. iw=1;
  105872. for(k1=0;k1<nf;k1++){
  105873. ip=ifac[k1 + 2];
  105874. l2=ip*l1;
  105875. ido=n/l2;
  105876. idl1=ido*l1;
  105877. if(ip!=4)goto L103;
  105878. ix2=iw+ido;
  105879. ix3=ix2+ido;
  105880. if(na!=0)
  105881. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105882. else
  105883. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105884. na=1-na;
  105885. goto L115;
  105886. L103:
  105887. if(ip!=2)goto L106;
  105888. if(na!=0)
  105889. dradb2(ido,l1,ch,c,wa+iw-1);
  105890. else
  105891. dradb2(ido,l1,c,ch,wa+iw-1);
  105892. na=1-na;
  105893. goto L115;
  105894. L106:
  105895. if(ip!=3)goto L109;
  105896. ix2=iw+ido;
  105897. if(na!=0)
  105898. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  105899. else
  105900. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  105901. na=1-na;
  105902. goto L115;
  105903. L109:
  105904. if(na!=0)
  105905. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105906. else
  105907. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105908. if(ido==1)na=1-na;
  105909. L115:
  105910. l1=l2;
  105911. iw+=(ip-1)*ido;
  105912. }
  105913. if(na==0)return;
  105914. for(i=0;i<n;i++)c[i]=ch[i];
  105915. }
  105916. void drft_forward(drft_lookup *l,float *data){
  105917. if(l->n==1)return;
  105918. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  105919. }
  105920. void drft_backward(drft_lookup *l,float *data){
  105921. if (l->n==1)return;
  105922. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  105923. }
  105924. void drft_init(drft_lookup *l,int n){
  105925. l->n=n;
  105926. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  105927. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  105928. fdrffti(n, l->trigcache, l->splitcache);
  105929. }
  105930. void drft_clear(drft_lookup *l){
  105931. if(l){
  105932. if(l->trigcache)_ogg_free(l->trigcache);
  105933. if(l->splitcache)_ogg_free(l->splitcache);
  105934. memset(l,0,sizeof(*l));
  105935. }
  105936. }
  105937. #endif
  105938. /*** End of inlined file: smallft.c ***/
  105939. /*** Start of inlined file: synthesis.c ***/
  105940. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105941. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105942. // tasks..
  105943. #if JUCE_MSVC
  105944. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105945. #endif
  105946. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105947. #if JUCE_USE_OGGVORBIS
  105948. #include <stdio.h>
  105949. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  105950. vorbis_dsp_state *vd=vb->vd;
  105951. private_state *b=(private_state*)vd->backend_state;
  105952. vorbis_info *vi=vd->vi;
  105953. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  105954. oggpack_buffer *opb=&vb->opb;
  105955. int type,mode,i;
  105956. _vorbis_block_ripcord(vb);
  105957. oggpack_readinit(opb,op->packet,op->bytes);
  105958. if(oggpack_read(opb,1)!=0){
  105959. return(OV_ENOTAUDIO);
  105960. }
  105961. mode=oggpack_read(opb,b->modebits);
  105962. if(mode==-1)return(OV_EBADPACKET);
  105963. vb->mode=mode;
  105964. vb->W=ci->mode_param[mode]->blockflag;
  105965. if(vb->W){
  105966. vb->lW=oggpack_read(opb,1);
  105967. vb->nW=oggpack_read(opb,1);
  105968. if(vb->nW==-1) return(OV_EBADPACKET);
  105969. }else{
  105970. vb->lW=0;
  105971. vb->nW=0;
  105972. }
  105973. vb->granulepos=op->granulepos;
  105974. vb->sequence=op->packetno;
  105975. vb->eofflag=op->e_o_s;
  105976. vb->pcmend=ci->blocksizes[vb->W];
  105977. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  105978. for(i=0;i<vi->channels;i++)
  105979. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  105980. type=ci->map_type[ci->mode_param[mode]->mapping];
  105981. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  105982. mapping]));
  105983. }
  105984. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  105985. vorbis_dsp_state *vd=vb->vd;
  105986. private_state *b=(private_state*)vd->backend_state;
  105987. vorbis_info *vi=vd->vi;
  105988. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  105989. oggpack_buffer *opb=&vb->opb;
  105990. int mode;
  105991. _vorbis_block_ripcord(vb);
  105992. oggpack_readinit(opb,op->packet,op->bytes);
  105993. if(oggpack_read(opb,1)!=0){
  105994. return(OV_ENOTAUDIO);
  105995. }
  105996. mode=oggpack_read(opb,b->modebits);
  105997. if(mode==-1)return(OV_EBADPACKET);
  105998. vb->mode=mode;
  105999. vb->W=ci->mode_param[mode]->blockflag;
  106000. if(vb->W){
  106001. vb->lW=oggpack_read(opb,1);
  106002. vb->nW=oggpack_read(opb,1);
  106003. if(vb->nW==-1) return(OV_EBADPACKET);
  106004. }else{
  106005. vb->lW=0;
  106006. vb->nW=0;
  106007. }
  106008. vb->granulepos=op->granulepos;
  106009. vb->sequence=op->packetno;
  106010. vb->eofflag=op->e_o_s;
  106011. vb->pcmend=0;
  106012. vb->pcm=NULL;
  106013. return(0);
  106014. }
  106015. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106016. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106017. oggpack_buffer opb;
  106018. int mode;
  106019. oggpack_readinit(&opb,op->packet,op->bytes);
  106020. if(oggpack_read(&opb,1)!=0){
  106021. return(OV_ENOTAUDIO);
  106022. }
  106023. {
  106024. int modebits=0;
  106025. int v=ci->modes;
  106026. while(v>1){
  106027. modebits++;
  106028. v>>=1;
  106029. }
  106030. mode=oggpack_read(&opb,modebits);
  106031. }
  106032. if(mode==-1)return(OV_EBADPACKET);
  106033. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106034. }
  106035. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106036. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106037. if(ci->blocksizes[0]<=64 && flag)return -1;
  106038. ci->halfrate_flag=(flag?1:0);
  106039. return 0;
  106040. }
  106041. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106042. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106043. return ci->halfrate_flag;
  106044. }
  106045. #endif
  106046. /*** End of inlined file: synthesis.c ***/
  106047. /*** Start of inlined file: vorbisenc.c ***/
  106048. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106049. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106050. // tasks..
  106051. #if JUCE_MSVC
  106052. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106053. #endif
  106054. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106055. #if JUCE_USE_OGGVORBIS
  106056. #include <stdlib.h>
  106057. #include <string.h>
  106058. #include <math.h>
  106059. typedef struct {
  106060. static_codebook *books[12][3];
  106061. } static_bookblock;
  106062. typedef struct {
  106063. int res_type;
  106064. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106065. vorbis_info_residue0 *res;
  106066. static_codebook *book_aux;
  106067. static_codebook *book_aux_managed;
  106068. static_bookblock *books_base;
  106069. static_bookblock *books_base_managed;
  106070. } vorbis_residue_template;
  106071. typedef struct {
  106072. vorbis_info_mapping0 *map;
  106073. vorbis_residue_template *res;
  106074. } vorbis_mapping_template;
  106075. typedef struct vp_adjblock{
  106076. int block[P_BANDS];
  106077. } vp_adjblock;
  106078. typedef struct {
  106079. int data[NOISE_COMPAND_LEVELS];
  106080. } compandblock;
  106081. typedef struct {
  106082. int att[P_NOISECURVES];
  106083. float boost;
  106084. float decay;
  106085. } att3;
  106086. typedef struct { int data[P_NOISECURVES]; } adj3;
  106087. typedef struct {
  106088. int pre[PACKETBLOBS];
  106089. int post[PACKETBLOBS];
  106090. float kHz[PACKETBLOBS];
  106091. float lowpasskHz[PACKETBLOBS];
  106092. } adj_stereo;
  106093. typedef struct {
  106094. int lo;
  106095. int hi;
  106096. int fixed;
  106097. } noiseguard;
  106098. typedef struct {
  106099. int data[P_NOISECURVES][17];
  106100. } noise3;
  106101. typedef struct {
  106102. int mappings;
  106103. double *rate_mapping;
  106104. double *quality_mapping;
  106105. int coupling_restriction;
  106106. long samplerate_min_restriction;
  106107. long samplerate_max_restriction;
  106108. int *blocksize_short;
  106109. int *blocksize_long;
  106110. att3 *psy_tone_masteratt;
  106111. int *psy_tone_0dB;
  106112. int *psy_tone_dBsuppress;
  106113. vp_adjblock *psy_tone_adj_impulse;
  106114. vp_adjblock *psy_tone_adj_long;
  106115. vp_adjblock *psy_tone_adj_other;
  106116. noiseguard *psy_noiseguards;
  106117. noise3 *psy_noise_bias_impulse;
  106118. noise3 *psy_noise_bias_padding;
  106119. noise3 *psy_noise_bias_trans;
  106120. noise3 *psy_noise_bias_long;
  106121. int *psy_noise_dBsuppress;
  106122. compandblock *psy_noise_compand;
  106123. double *psy_noise_compand_short_mapping;
  106124. double *psy_noise_compand_long_mapping;
  106125. int *psy_noise_normal_start[2];
  106126. int *psy_noise_normal_partition[2];
  106127. double *psy_noise_normal_thresh;
  106128. int *psy_ath_float;
  106129. int *psy_ath_abs;
  106130. double *psy_lowpass;
  106131. vorbis_info_psy_global *global_params;
  106132. double *global_mapping;
  106133. adj_stereo *stereo_modes;
  106134. static_codebook ***floor_books;
  106135. vorbis_info_floor1 *floor_params;
  106136. int *floor_short_mapping;
  106137. int *floor_long_mapping;
  106138. vorbis_mapping_template *maps;
  106139. } ve_setup_data_template;
  106140. static vorbis_info_mode _mode_template[2]={
  106141. {0,0,0,0},
  106142. {1,0,0,1}
  106143. };
  106144. static vorbis_info_mapping0 _map_nominal[2]={
  106145. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106146. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106147. };
  106148. /*** Start of inlined file: setup_44.h ***/
  106149. /*** Start of inlined file: floor_all.h ***/
  106150. /*** Start of inlined file: floor_books.h ***/
  106151. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106152. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106153. };
  106154. static static_codebook _huff_book_line_256x7_0sub1 = {
  106155. 1, 9,
  106156. _huff_lengthlist_line_256x7_0sub1,
  106157. 0, 0, 0, 0, 0,
  106158. NULL,
  106159. NULL,
  106160. NULL,
  106161. NULL,
  106162. 0
  106163. };
  106164. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106166. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106167. };
  106168. static static_codebook _huff_book_line_256x7_0sub2 = {
  106169. 1, 25,
  106170. _huff_lengthlist_line_256x7_0sub2,
  106171. 0, 0, 0, 0, 0,
  106172. NULL,
  106173. NULL,
  106174. NULL,
  106175. NULL,
  106176. 0
  106177. };
  106178. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106181. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106182. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106183. };
  106184. static static_codebook _huff_book_line_256x7_0sub3 = {
  106185. 1, 64,
  106186. _huff_lengthlist_line_256x7_0sub3,
  106187. 0, 0, 0, 0, 0,
  106188. NULL,
  106189. NULL,
  106190. NULL,
  106191. NULL,
  106192. 0
  106193. };
  106194. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106195. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106196. };
  106197. static static_codebook _huff_book_line_256x7_1sub1 = {
  106198. 1, 9,
  106199. _huff_lengthlist_line_256x7_1sub1,
  106200. 0, 0, 0, 0, 0,
  106201. NULL,
  106202. NULL,
  106203. NULL,
  106204. NULL,
  106205. 0
  106206. };
  106207. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106209. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106210. };
  106211. static static_codebook _huff_book_line_256x7_1sub2 = {
  106212. 1, 25,
  106213. _huff_lengthlist_line_256x7_1sub2,
  106214. 0, 0, 0, 0, 0,
  106215. NULL,
  106216. NULL,
  106217. NULL,
  106218. NULL,
  106219. 0
  106220. };
  106221. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106224. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106225. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106226. };
  106227. static static_codebook _huff_book_line_256x7_1sub3 = {
  106228. 1, 64,
  106229. _huff_lengthlist_line_256x7_1sub3,
  106230. 0, 0, 0, 0, 0,
  106231. NULL,
  106232. NULL,
  106233. NULL,
  106234. NULL,
  106235. 0
  106236. };
  106237. static long _huff_lengthlist_line_256x7_class0[] = {
  106238. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106239. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106240. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106241. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106242. };
  106243. static static_codebook _huff_book_line_256x7_class0 = {
  106244. 1, 64,
  106245. _huff_lengthlist_line_256x7_class0,
  106246. 0, 0, 0, 0, 0,
  106247. NULL,
  106248. NULL,
  106249. NULL,
  106250. NULL,
  106251. 0
  106252. };
  106253. static long _huff_lengthlist_line_256x7_class1[] = {
  106254. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106255. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106256. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106257. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106258. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106259. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106260. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106261. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106262. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106263. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106264. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106265. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106266. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106267. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106268. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106269. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106270. };
  106271. static static_codebook _huff_book_line_256x7_class1 = {
  106272. 1, 256,
  106273. _huff_lengthlist_line_256x7_class1,
  106274. 0, 0, 0, 0, 0,
  106275. NULL,
  106276. NULL,
  106277. NULL,
  106278. NULL,
  106279. 0
  106280. };
  106281. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106282. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106283. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106284. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106285. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106286. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106287. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106288. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106289. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106290. };
  106291. static static_codebook _huff_book_line_512x17_0sub0 = {
  106292. 1, 128,
  106293. _huff_lengthlist_line_512x17_0sub0,
  106294. 0, 0, 0, 0, 0,
  106295. NULL,
  106296. NULL,
  106297. NULL,
  106298. NULL,
  106299. 0
  106300. };
  106301. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106302. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106303. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106304. };
  106305. static static_codebook _huff_book_line_512x17_1sub0 = {
  106306. 1, 32,
  106307. _huff_lengthlist_line_512x17_1sub0,
  106308. 0, 0, 0, 0, 0,
  106309. NULL,
  106310. NULL,
  106311. NULL,
  106312. NULL,
  106313. 0
  106314. };
  106315. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106318. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106319. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106320. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106321. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106322. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106323. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106324. };
  106325. static static_codebook _huff_book_line_512x17_1sub1 = {
  106326. 1, 128,
  106327. _huff_lengthlist_line_512x17_1sub1,
  106328. 0, 0, 0, 0, 0,
  106329. NULL,
  106330. NULL,
  106331. NULL,
  106332. NULL,
  106333. 0
  106334. };
  106335. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106336. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106337. 5, 3,
  106338. };
  106339. static static_codebook _huff_book_line_512x17_2sub1 = {
  106340. 1, 18,
  106341. _huff_lengthlist_line_512x17_2sub1,
  106342. 0, 0, 0, 0, 0,
  106343. NULL,
  106344. NULL,
  106345. NULL,
  106346. NULL,
  106347. 0
  106348. };
  106349. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106351. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106352. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106353. 9, 8,
  106354. };
  106355. static static_codebook _huff_book_line_512x17_2sub2 = {
  106356. 1, 50,
  106357. _huff_lengthlist_line_512x17_2sub2,
  106358. 0, 0, 0, 0, 0,
  106359. NULL,
  106360. NULL,
  106361. NULL,
  106362. NULL,
  106363. 0
  106364. };
  106365. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106369. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106370. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106371. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106372. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106373. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106374. };
  106375. static static_codebook _huff_book_line_512x17_2sub3 = {
  106376. 1, 128,
  106377. _huff_lengthlist_line_512x17_2sub3,
  106378. 0, 0, 0, 0, 0,
  106379. NULL,
  106380. NULL,
  106381. NULL,
  106382. NULL,
  106383. 0
  106384. };
  106385. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106386. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106387. 5, 5,
  106388. };
  106389. static static_codebook _huff_book_line_512x17_3sub1 = {
  106390. 1, 18,
  106391. _huff_lengthlist_line_512x17_3sub1,
  106392. 0, 0, 0, 0, 0,
  106393. NULL,
  106394. NULL,
  106395. NULL,
  106396. NULL,
  106397. 0
  106398. };
  106399. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106401. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106402. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106403. 11,14,
  106404. };
  106405. static static_codebook _huff_book_line_512x17_3sub2 = {
  106406. 1, 50,
  106407. _huff_lengthlist_line_512x17_3sub2,
  106408. 0, 0, 0, 0, 0,
  106409. NULL,
  106410. NULL,
  106411. NULL,
  106412. NULL,
  106413. 0
  106414. };
  106415. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106419. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106420. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106421. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106422. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106423. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106424. };
  106425. static static_codebook _huff_book_line_512x17_3sub3 = {
  106426. 1, 128,
  106427. _huff_lengthlist_line_512x17_3sub3,
  106428. 0, 0, 0, 0, 0,
  106429. NULL,
  106430. NULL,
  106431. NULL,
  106432. NULL,
  106433. 0
  106434. };
  106435. static long _huff_lengthlist_line_512x17_class1[] = {
  106436. 1, 2, 3, 6, 5, 4, 7, 7,
  106437. };
  106438. static static_codebook _huff_book_line_512x17_class1 = {
  106439. 1, 8,
  106440. _huff_lengthlist_line_512x17_class1,
  106441. 0, 0, 0, 0, 0,
  106442. NULL,
  106443. NULL,
  106444. NULL,
  106445. NULL,
  106446. 0
  106447. };
  106448. static long _huff_lengthlist_line_512x17_class2[] = {
  106449. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106450. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106451. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106452. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106453. };
  106454. static static_codebook _huff_book_line_512x17_class2 = {
  106455. 1, 64,
  106456. _huff_lengthlist_line_512x17_class2,
  106457. 0, 0, 0, 0, 0,
  106458. NULL,
  106459. NULL,
  106460. NULL,
  106461. NULL,
  106462. 0
  106463. };
  106464. static long _huff_lengthlist_line_512x17_class3[] = {
  106465. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106466. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106467. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106468. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106469. };
  106470. static static_codebook _huff_book_line_512x17_class3 = {
  106471. 1, 64,
  106472. _huff_lengthlist_line_512x17_class3,
  106473. 0, 0, 0, 0, 0,
  106474. NULL,
  106475. NULL,
  106476. NULL,
  106477. NULL,
  106478. 0
  106479. };
  106480. static long _huff_lengthlist_line_128x4_class0[] = {
  106481. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106482. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106483. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106484. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106485. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106486. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106487. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106488. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106489. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106490. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106491. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106492. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106493. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106494. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106495. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106496. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106497. };
  106498. static static_codebook _huff_book_line_128x4_class0 = {
  106499. 1, 256,
  106500. _huff_lengthlist_line_128x4_class0,
  106501. 0, 0, 0, 0, 0,
  106502. NULL,
  106503. NULL,
  106504. NULL,
  106505. NULL,
  106506. 0
  106507. };
  106508. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106509. 2, 2, 2, 2,
  106510. };
  106511. static static_codebook _huff_book_line_128x4_0sub0 = {
  106512. 1, 4,
  106513. _huff_lengthlist_line_128x4_0sub0,
  106514. 0, 0, 0, 0, 0,
  106515. NULL,
  106516. NULL,
  106517. NULL,
  106518. NULL,
  106519. 0
  106520. };
  106521. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106522. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106523. };
  106524. static static_codebook _huff_book_line_128x4_0sub1 = {
  106525. 1, 10,
  106526. _huff_lengthlist_line_128x4_0sub1,
  106527. 0, 0, 0, 0, 0,
  106528. NULL,
  106529. NULL,
  106530. NULL,
  106531. NULL,
  106532. 0
  106533. };
  106534. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106536. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106537. };
  106538. static static_codebook _huff_book_line_128x4_0sub2 = {
  106539. 1, 25,
  106540. _huff_lengthlist_line_128x4_0sub2,
  106541. 0, 0, 0, 0, 0,
  106542. NULL,
  106543. NULL,
  106544. NULL,
  106545. NULL,
  106546. 0
  106547. };
  106548. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106551. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106552. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106553. };
  106554. static static_codebook _huff_book_line_128x4_0sub3 = {
  106555. 1, 64,
  106556. _huff_lengthlist_line_128x4_0sub3,
  106557. 0, 0, 0, 0, 0,
  106558. NULL,
  106559. NULL,
  106560. NULL,
  106561. NULL,
  106562. 0
  106563. };
  106564. static long _huff_lengthlist_line_256x4_class0[] = {
  106565. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106566. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106567. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106568. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106569. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106570. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106571. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106572. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106573. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106574. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106575. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106576. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106577. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106578. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106579. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106580. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106581. };
  106582. static static_codebook _huff_book_line_256x4_class0 = {
  106583. 1, 256,
  106584. _huff_lengthlist_line_256x4_class0,
  106585. 0, 0, 0, 0, 0,
  106586. NULL,
  106587. NULL,
  106588. NULL,
  106589. NULL,
  106590. 0
  106591. };
  106592. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106593. 2, 2, 2, 2,
  106594. };
  106595. static static_codebook _huff_book_line_256x4_0sub0 = {
  106596. 1, 4,
  106597. _huff_lengthlist_line_256x4_0sub0,
  106598. 0, 0, 0, 0, 0,
  106599. NULL,
  106600. NULL,
  106601. NULL,
  106602. NULL,
  106603. 0
  106604. };
  106605. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106606. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106607. };
  106608. static static_codebook _huff_book_line_256x4_0sub1 = {
  106609. 1, 10,
  106610. _huff_lengthlist_line_256x4_0sub1,
  106611. 0, 0, 0, 0, 0,
  106612. NULL,
  106613. NULL,
  106614. NULL,
  106615. NULL,
  106616. 0
  106617. };
  106618. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106620. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106621. };
  106622. static static_codebook _huff_book_line_256x4_0sub2 = {
  106623. 1, 25,
  106624. _huff_lengthlist_line_256x4_0sub2,
  106625. 0, 0, 0, 0, 0,
  106626. NULL,
  106627. NULL,
  106628. NULL,
  106629. NULL,
  106630. 0
  106631. };
  106632. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106635. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106636. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106637. };
  106638. static static_codebook _huff_book_line_256x4_0sub3 = {
  106639. 1, 64,
  106640. _huff_lengthlist_line_256x4_0sub3,
  106641. 0, 0, 0, 0, 0,
  106642. NULL,
  106643. NULL,
  106644. NULL,
  106645. NULL,
  106646. 0
  106647. };
  106648. static long _huff_lengthlist_line_128x7_class0[] = {
  106649. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106650. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106651. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106652. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106653. };
  106654. static static_codebook _huff_book_line_128x7_class0 = {
  106655. 1, 64,
  106656. _huff_lengthlist_line_128x7_class0,
  106657. 0, 0, 0, 0, 0,
  106658. NULL,
  106659. NULL,
  106660. NULL,
  106661. NULL,
  106662. 0
  106663. };
  106664. static long _huff_lengthlist_line_128x7_class1[] = {
  106665. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106666. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106667. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106668. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106669. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106670. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106671. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106672. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106673. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106674. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106675. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106676. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106677. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106678. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106679. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106680. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106681. };
  106682. static static_codebook _huff_book_line_128x7_class1 = {
  106683. 1, 256,
  106684. _huff_lengthlist_line_128x7_class1,
  106685. 0, 0, 0, 0, 0,
  106686. NULL,
  106687. NULL,
  106688. NULL,
  106689. NULL,
  106690. 0
  106691. };
  106692. static long _huff_lengthlist_line_128x7_0sub1[] = {
  106693. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  106694. };
  106695. static static_codebook _huff_book_line_128x7_0sub1 = {
  106696. 1, 9,
  106697. _huff_lengthlist_line_128x7_0sub1,
  106698. 0, 0, 0, 0, 0,
  106699. NULL,
  106700. NULL,
  106701. NULL,
  106702. NULL,
  106703. 0
  106704. };
  106705. static long _huff_lengthlist_line_128x7_0sub2[] = {
  106706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  106707. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  106708. };
  106709. static static_codebook _huff_book_line_128x7_0sub2 = {
  106710. 1, 25,
  106711. _huff_lengthlist_line_128x7_0sub2,
  106712. 0, 0, 0, 0, 0,
  106713. NULL,
  106714. NULL,
  106715. NULL,
  106716. NULL,
  106717. 0
  106718. };
  106719. static long _huff_lengthlist_line_128x7_0sub3[] = {
  106720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  106722. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106723. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  106724. };
  106725. static static_codebook _huff_book_line_128x7_0sub3 = {
  106726. 1, 64,
  106727. _huff_lengthlist_line_128x7_0sub3,
  106728. 0, 0, 0, 0, 0,
  106729. NULL,
  106730. NULL,
  106731. NULL,
  106732. NULL,
  106733. 0
  106734. };
  106735. static long _huff_lengthlist_line_128x7_1sub1[] = {
  106736. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  106737. };
  106738. static static_codebook _huff_book_line_128x7_1sub1 = {
  106739. 1, 9,
  106740. _huff_lengthlist_line_128x7_1sub1,
  106741. 0, 0, 0, 0, 0,
  106742. NULL,
  106743. NULL,
  106744. NULL,
  106745. NULL,
  106746. 0
  106747. };
  106748. static long _huff_lengthlist_line_128x7_1sub2[] = {
  106749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  106750. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  106751. };
  106752. static static_codebook _huff_book_line_128x7_1sub2 = {
  106753. 1, 25,
  106754. _huff_lengthlist_line_128x7_1sub2,
  106755. 0, 0, 0, 0, 0,
  106756. NULL,
  106757. NULL,
  106758. NULL,
  106759. NULL,
  106760. 0
  106761. };
  106762. static long _huff_lengthlist_line_128x7_1sub3[] = {
  106763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  106765. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  106766. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  106767. };
  106768. static static_codebook _huff_book_line_128x7_1sub3 = {
  106769. 1, 64,
  106770. _huff_lengthlist_line_128x7_1sub3,
  106771. 0, 0, 0, 0, 0,
  106772. NULL,
  106773. NULL,
  106774. NULL,
  106775. NULL,
  106776. 0
  106777. };
  106778. static long _huff_lengthlist_line_128x11_class1[] = {
  106779. 1, 6, 3, 7, 2, 4, 5, 7,
  106780. };
  106781. static static_codebook _huff_book_line_128x11_class1 = {
  106782. 1, 8,
  106783. _huff_lengthlist_line_128x11_class1,
  106784. 0, 0, 0, 0, 0,
  106785. NULL,
  106786. NULL,
  106787. NULL,
  106788. NULL,
  106789. 0
  106790. };
  106791. static long _huff_lengthlist_line_128x11_class2[] = {
  106792. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  106793. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  106794. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  106795. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  106796. };
  106797. static static_codebook _huff_book_line_128x11_class2 = {
  106798. 1, 64,
  106799. _huff_lengthlist_line_128x11_class2,
  106800. 0, 0, 0, 0, 0,
  106801. NULL,
  106802. NULL,
  106803. NULL,
  106804. NULL,
  106805. 0
  106806. };
  106807. static long _huff_lengthlist_line_128x11_class3[] = {
  106808. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  106809. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  106810. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  106811. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  106812. };
  106813. static static_codebook _huff_book_line_128x11_class3 = {
  106814. 1, 64,
  106815. _huff_lengthlist_line_128x11_class3,
  106816. 0, 0, 0, 0, 0,
  106817. NULL,
  106818. NULL,
  106819. NULL,
  106820. NULL,
  106821. 0
  106822. };
  106823. static long _huff_lengthlist_line_128x11_0sub0[] = {
  106824. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106825. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  106826. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  106827. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  106828. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  106829. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  106830. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  106831. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106832. };
  106833. static static_codebook _huff_book_line_128x11_0sub0 = {
  106834. 1, 128,
  106835. _huff_lengthlist_line_128x11_0sub0,
  106836. 0, 0, 0, 0, 0,
  106837. NULL,
  106838. NULL,
  106839. NULL,
  106840. NULL,
  106841. 0
  106842. };
  106843. static long _huff_lengthlist_line_128x11_1sub0[] = {
  106844. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  106845. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  106846. };
  106847. static static_codebook _huff_book_line_128x11_1sub0 = {
  106848. 1, 32,
  106849. _huff_lengthlist_line_128x11_1sub0,
  106850. 0, 0, 0, 0, 0,
  106851. NULL,
  106852. NULL,
  106853. NULL,
  106854. NULL,
  106855. 0
  106856. };
  106857. static long _huff_lengthlist_line_128x11_1sub1[] = {
  106858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106860. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  106861. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  106862. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  106863. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  106864. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  106865. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  106866. };
  106867. static static_codebook _huff_book_line_128x11_1sub1 = {
  106868. 1, 128,
  106869. _huff_lengthlist_line_128x11_1sub1,
  106870. 0, 0, 0, 0, 0,
  106871. NULL,
  106872. NULL,
  106873. NULL,
  106874. NULL,
  106875. 0
  106876. };
  106877. static long _huff_lengthlist_line_128x11_2sub1[] = {
  106878. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  106879. 5, 5,
  106880. };
  106881. static static_codebook _huff_book_line_128x11_2sub1 = {
  106882. 1, 18,
  106883. _huff_lengthlist_line_128x11_2sub1,
  106884. 0, 0, 0, 0, 0,
  106885. NULL,
  106886. NULL,
  106887. NULL,
  106888. NULL,
  106889. 0
  106890. };
  106891. static long _huff_lengthlist_line_128x11_2sub2[] = {
  106892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106893. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  106894. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  106895. 8,11,
  106896. };
  106897. static static_codebook _huff_book_line_128x11_2sub2 = {
  106898. 1, 50,
  106899. _huff_lengthlist_line_128x11_2sub2,
  106900. 0, 0, 0, 0, 0,
  106901. NULL,
  106902. NULL,
  106903. NULL,
  106904. NULL,
  106905. 0
  106906. };
  106907. static long _huff_lengthlist_line_128x11_2sub3[] = {
  106908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106911. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  106912. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106913. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106914. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106915. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106916. };
  106917. static static_codebook _huff_book_line_128x11_2sub3 = {
  106918. 1, 128,
  106919. _huff_lengthlist_line_128x11_2sub3,
  106920. 0, 0, 0, 0, 0,
  106921. NULL,
  106922. NULL,
  106923. NULL,
  106924. NULL,
  106925. 0
  106926. };
  106927. static long _huff_lengthlist_line_128x11_3sub1[] = {
  106928. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  106929. 5, 4,
  106930. };
  106931. static static_codebook _huff_book_line_128x11_3sub1 = {
  106932. 1, 18,
  106933. _huff_lengthlist_line_128x11_3sub1,
  106934. 0, 0, 0, 0, 0,
  106935. NULL,
  106936. NULL,
  106937. NULL,
  106938. NULL,
  106939. 0
  106940. };
  106941. static long _huff_lengthlist_line_128x11_3sub2[] = {
  106942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106943. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  106944. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  106945. 12, 6,
  106946. };
  106947. static static_codebook _huff_book_line_128x11_3sub2 = {
  106948. 1, 50,
  106949. _huff_lengthlist_line_128x11_3sub2,
  106950. 0, 0, 0, 0, 0,
  106951. NULL,
  106952. NULL,
  106953. NULL,
  106954. NULL,
  106955. 0
  106956. };
  106957. static long _huff_lengthlist_line_128x11_3sub3[] = {
  106958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106961. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  106962. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  106963. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106964. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106965. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  106966. };
  106967. static static_codebook _huff_book_line_128x11_3sub3 = {
  106968. 1, 128,
  106969. _huff_lengthlist_line_128x11_3sub3,
  106970. 0, 0, 0, 0, 0,
  106971. NULL,
  106972. NULL,
  106973. NULL,
  106974. NULL,
  106975. 0
  106976. };
  106977. static long _huff_lengthlist_line_128x17_class1[] = {
  106978. 1, 3, 4, 7, 2, 5, 6, 7,
  106979. };
  106980. static static_codebook _huff_book_line_128x17_class1 = {
  106981. 1, 8,
  106982. _huff_lengthlist_line_128x17_class1,
  106983. 0, 0, 0, 0, 0,
  106984. NULL,
  106985. NULL,
  106986. NULL,
  106987. NULL,
  106988. 0
  106989. };
  106990. static long _huff_lengthlist_line_128x17_class2[] = {
  106991. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  106992. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  106993. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  106994. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106995. };
  106996. static static_codebook _huff_book_line_128x17_class2 = {
  106997. 1, 64,
  106998. _huff_lengthlist_line_128x17_class2,
  106999. 0, 0, 0, 0, 0,
  107000. NULL,
  107001. NULL,
  107002. NULL,
  107003. NULL,
  107004. 0
  107005. };
  107006. static long _huff_lengthlist_line_128x17_class3[] = {
  107007. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107008. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107009. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107010. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107011. };
  107012. static static_codebook _huff_book_line_128x17_class3 = {
  107013. 1, 64,
  107014. _huff_lengthlist_line_128x17_class3,
  107015. 0, 0, 0, 0, 0,
  107016. NULL,
  107017. NULL,
  107018. NULL,
  107019. NULL,
  107020. 0
  107021. };
  107022. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107023. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107024. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107025. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107026. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107027. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107028. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107029. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107030. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107031. };
  107032. static static_codebook _huff_book_line_128x17_0sub0 = {
  107033. 1, 128,
  107034. _huff_lengthlist_line_128x17_0sub0,
  107035. 0, 0, 0, 0, 0,
  107036. NULL,
  107037. NULL,
  107038. NULL,
  107039. NULL,
  107040. 0
  107041. };
  107042. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107043. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107044. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107045. };
  107046. static static_codebook _huff_book_line_128x17_1sub0 = {
  107047. 1, 32,
  107048. _huff_lengthlist_line_128x17_1sub0,
  107049. 0, 0, 0, 0, 0,
  107050. NULL,
  107051. NULL,
  107052. NULL,
  107053. NULL,
  107054. 0
  107055. };
  107056. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107059. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107060. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107061. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107062. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107063. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107064. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107065. };
  107066. static static_codebook _huff_book_line_128x17_1sub1 = {
  107067. 1, 128,
  107068. _huff_lengthlist_line_128x17_1sub1,
  107069. 0, 0, 0, 0, 0,
  107070. NULL,
  107071. NULL,
  107072. NULL,
  107073. NULL,
  107074. 0
  107075. };
  107076. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107077. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107078. 9, 4,
  107079. };
  107080. static static_codebook _huff_book_line_128x17_2sub1 = {
  107081. 1, 18,
  107082. _huff_lengthlist_line_128x17_2sub1,
  107083. 0, 0, 0, 0, 0,
  107084. NULL,
  107085. NULL,
  107086. NULL,
  107087. NULL,
  107088. 0
  107089. };
  107090. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107092. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107093. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107094. 13,13,
  107095. };
  107096. static static_codebook _huff_book_line_128x17_2sub2 = {
  107097. 1, 50,
  107098. _huff_lengthlist_line_128x17_2sub2,
  107099. 0, 0, 0, 0, 0,
  107100. NULL,
  107101. NULL,
  107102. NULL,
  107103. NULL,
  107104. 0
  107105. };
  107106. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107110. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107111. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107112. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107113. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107114. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107115. };
  107116. static static_codebook _huff_book_line_128x17_2sub3 = {
  107117. 1, 128,
  107118. _huff_lengthlist_line_128x17_2sub3,
  107119. 0, 0, 0, 0, 0,
  107120. NULL,
  107121. NULL,
  107122. NULL,
  107123. NULL,
  107124. 0
  107125. };
  107126. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107127. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107128. 6, 4,
  107129. };
  107130. static static_codebook _huff_book_line_128x17_3sub1 = {
  107131. 1, 18,
  107132. _huff_lengthlist_line_128x17_3sub1,
  107133. 0, 0, 0, 0, 0,
  107134. NULL,
  107135. NULL,
  107136. NULL,
  107137. NULL,
  107138. 0
  107139. };
  107140. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107142. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107143. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107144. 10, 8,
  107145. };
  107146. static static_codebook _huff_book_line_128x17_3sub2 = {
  107147. 1, 50,
  107148. _huff_lengthlist_line_128x17_3sub2,
  107149. 0, 0, 0, 0, 0,
  107150. NULL,
  107151. NULL,
  107152. NULL,
  107153. NULL,
  107154. 0
  107155. };
  107156. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107160. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107161. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107162. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107163. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107164. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107165. };
  107166. static static_codebook _huff_book_line_128x17_3sub3 = {
  107167. 1, 128,
  107168. _huff_lengthlist_line_128x17_3sub3,
  107169. 0, 0, 0, 0, 0,
  107170. NULL,
  107171. NULL,
  107172. NULL,
  107173. NULL,
  107174. 0
  107175. };
  107176. static long _huff_lengthlist_line_1024x27_class1[] = {
  107177. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107178. };
  107179. static static_codebook _huff_book_line_1024x27_class1 = {
  107180. 1, 16,
  107181. _huff_lengthlist_line_1024x27_class1,
  107182. 0, 0, 0, 0, 0,
  107183. NULL,
  107184. NULL,
  107185. NULL,
  107186. NULL,
  107187. 0
  107188. };
  107189. static long _huff_lengthlist_line_1024x27_class2[] = {
  107190. 1, 4, 2, 6, 3, 7, 5, 7,
  107191. };
  107192. static static_codebook _huff_book_line_1024x27_class2 = {
  107193. 1, 8,
  107194. _huff_lengthlist_line_1024x27_class2,
  107195. 0, 0, 0, 0, 0,
  107196. NULL,
  107197. NULL,
  107198. NULL,
  107199. NULL,
  107200. 0
  107201. };
  107202. static long _huff_lengthlist_line_1024x27_class3[] = {
  107203. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107204. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107205. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107206. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107207. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107208. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107209. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107210. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107211. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107212. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107213. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107214. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107215. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107216. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107217. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107218. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107219. };
  107220. static static_codebook _huff_book_line_1024x27_class3 = {
  107221. 1, 256,
  107222. _huff_lengthlist_line_1024x27_class3,
  107223. 0, 0, 0, 0, 0,
  107224. NULL,
  107225. NULL,
  107226. NULL,
  107227. NULL,
  107228. 0
  107229. };
  107230. static long _huff_lengthlist_line_1024x27_class4[] = {
  107231. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107232. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107233. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107234. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107235. };
  107236. static static_codebook _huff_book_line_1024x27_class4 = {
  107237. 1, 64,
  107238. _huff_lengthlist_line_1024x27_class4,
  107239. 0, 0, 0, 0, 0,
  107240. NULL,
  107241. NULL,
  107242. NULL,
  107243. NULL,
  107244. 0
  107245. };
  107246. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107247. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107248. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107249. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107250. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107251. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107252. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107253. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107254. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107255. };
  107256. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107257. 1, 128,
  107258. _huff_lengthlist_line_1024x27_0sub0,
  107259. 0, 0, 0, 0, 0,
  107260. NULL,
  107261. NULL,
  107262. NULL,
  107263. NULL,
  107264. 0
  107265. };
  107266. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107267. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107268. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107269. };
  107270. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107271. 1, 32,
  107272. _huff_lengthlist_line_1024x27_1sub0,
  107273. 0, 0, 0, 0, 0,
  107274. NULL,
  107275. NULL,
  107276. NULL,
  107277. NULL,
  107278. 0
  107279. };
  107280. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107283. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107284. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107285. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107286. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107287. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107288. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107289. };
  107290. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107291. 1, 128,
  107292. _huff_lengthlist_line_1024x27_1sub1,
  107293. 0, 0, 0, 0, 0,
  107294. NULL,
  107295. NULL,
  107296. NULL,
  107297. NULL,
  107298. 0
  107299. };
  107300. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107301. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107302. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107303. };
  107304. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107305. 1, 32,
  107306. _huff_lengthlist_line_1024x27_2sub0,
  107307. 0, 0, 0, 0, 0,
  107308. NULL,
  107309. NULL,
  107310. NULL,
  107311. NULL,
  107312. 0
  107313. };
  107314. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107317. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107318. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107319. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107320. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107321. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107322. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107323. };
  107324. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107325. 1, 128,
  107326. _huff_lengthlist_line_1024x27_2sub1,
  107327. 0, 0, 0, 0, 0,
  107328. NULL,
  107329. NULL,
  107330. NULL,
  107331. NULL,
  107332. 0
  107333. };
  107334. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107335. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107336. 5, 5,
  107337. };
  107338. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107339. 1, 18,
  107340. _huff_lengthlist_line_1024x27_3sub1,
  107341. 0, 0, 0, 0, 0,
  107342. NULL,
  107343. NULL,
  107344. NULL,
  107345. NULL,
  107346. 0
  107347. };
  107348. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107350. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107351. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107352. 9,11,
  107353. };
  107354. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107355. 1, 50,
  107356. _huff_lengthlist_line_1024x27_3sub2,
  107357. 0, 0, 0, 0, 0,
  107358. NULL,
  107359. NULL,
  107360. NULL,
  107361. NULL,
  107362. 0
  107363. };
  107364. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107368. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107369. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107370. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107371. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107372. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107373. };
  107374. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107375. 1, 128,
  107376. _huff_lengthlist_line_1024x27_3sub3,
  107377. 0, 0, 0, 0, 0,
  107378. NULL,
  107379. NULL,
  107380. NULL,
  107381. NULL,
  107382. 0
  107383. };
  107384. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107385. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107386. 5, 4,
  107387. };
  107388. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107389. 1, 18,
  107390. _huff_lengthlist_line_1024x27_4sub1,
  107391. 0, 0, 0, 0, 0,
  107392. NULL,
  107393. NULL,
  107394. NULL,
  107395. NULL,
  107396. 0
  107397. };
  107398. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107400. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107401. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107402. 9,12,
  107403. };
  107404. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107405. 1, 50,
  107406. _huff_lengthlist_line_1024x27_4sub2,
  107407. 0, 0, 0, 0, 0,
  107408. NULL,
  107409. NULL,
  107410. NULL,
  107411. NULL,
  107412. 0
  107413. };
  107414. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107418. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107419. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107420. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107421. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107422. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107423. };
  107424. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107425. 1, 128,
  107426. _huff_lengthlist_line_1024x27_4sub3,
  107427. 0, 0, 0, 0, 0,
  107428. NULL,
  107429. NULL,
  107430. NULL,
  107431. NULL,
  107432. 0
  107433. };
  107434. static long _huff_lengthlist_line_2048x27_class1[] = {
  107435. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107436. };
  107437. static static_codebook _huff_book_line_2048x27_class1 = {
  107438. 1, 16,
  107439. _huff_lengthlist_line_2048x27_class1,
  107440. 0, 0, 0, 0, 0,
  107441. NULL,
  107442. NULL,
  107443. NULL,
  107444. NULL,
  107445. 0
  107446. };
  107447. static long _huff_lengthlist_line_2048x27_class2[] = {
  107448. 1, 2, 3, 6, 4, 7, 5, 7,
  107449. };
  107450. static static_codebook _huff_book_line_2048x27_class2 = {
  107451. 1, 8,
  107452. _huff_lengthlist_line_2048x27_class2,
  107453. 0, 0, 0, 0, 0,
  107454. NULL,
  107455. NULL,
  107456. NULL,
  107457. NULL,
  107458. 0
  107459. };
  107460. static long _huff_lengthlist_line_2048x27_class3[] = {
  107461. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107462. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107463. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107464. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107465. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107466. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107467. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107468. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107469. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107470. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107471. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107472. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107473. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107474. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107475. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107476. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107477. };
  107478. static static_codebook _huff_book_line_2048x27_class3 = {
  107479. 1, 256,
  107480. _huff_lengthlist_line_2048x27_class3,
  107481. 0, 0, 0, 0, 0,
  107482. NULL,
  107483. NULL,
  107484. NULL,
  107485. NULL,
  107486. 0
  107487. };
  107488. static long _huff_lengthlist_line_2048x27_class4[] = {
  107489. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107490. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107491. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107492. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107493. };
  107494. static static_codebook _huff_book_line_2048x27_class4 = {
  107495. 1, 64,
  107496. _huff_lengthlist_line_2048x27_class4,
  107497. 0, 0, 0, 0, 0,
  107498. NULL,
  107499. NULL,
  107500. NULL,
  107501. NULL,
  107502. 0
  107503. };
  107504. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107505. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107506. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107507. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107508. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107509. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107510. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107511. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107512. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107513. };
  107514. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107515. 1, 128,
  107516. _huff_lengthlist_line_2048x27_0sub0,
  107517. 0, 0, 0, 0, 0,
  107518. NULL,
  107519. NULL,
  107520. NULL,
  107521. NULL,
  107522. 0
  107523. };
  107524. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107525. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107526. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107527. };
  107528. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107529. 1, 32,
  107530. _huff_lengthlist_line_2048x27_1sub0,
  107531. 0, 0, 0, 0, 0,
  107532. NULL,
  107533. NULL,
  107534. NULL,
  107535. NULL,
  107536. 0
  107537. };
  107538. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107541. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107542. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107543. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107544. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107545. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107546. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107547. };
  107548. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107549. 1, 128,
  107550. _huff_lengthlist_line_2048x27_1sub1,
  107551. 0, 0, 0, 0, 0,
  107552. NULL,
  107553. NULL,
  107554. NULL,
  107555. NULL,
  107556. 0
  107557. };
  107558. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107559. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107560. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107561. };
  107562. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107563. 1, 32,
  107564. _huff_lengthlist_line_2048x27_2sub0,
  107565. 0, 0, 0, 0, 0,
  107566. NULL,
  107567. NULL,
  107568. NULL,
  107569. NULL,
  107570. 0
  107571. };
  107572. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107575. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107576. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107577. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107578. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107579. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107580. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107581. };
  107582. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107583. 1, 128,
  107584. _huff_lengthlist_line_2048x27_2sub1,
  107585. 0, 0, 0, 0, 0,
  107586. NULL,
  107587. NULL,
  107588. NULL,
  107589. NULL,
  107590. 0
  107591. };
  107592. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107593. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107594. 5, 5,
  107595. };
  107596. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107597. 1, 18,
  107598. _huff_lengthlist_line_2048x27_3sub1,
  107599. 0, 0, 0, 0, 0,
  107600. NULL,
  107601. NULL,
  107602. NULL,
  107603. NULL,
  107604. 0
  107605. };
  107606. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107608. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107609. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107610. 10,12,
  107611. };
  107612. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107613. 1, 50,
  107614. _huff_lengthlist_line_2048x27_3sub2,
  107615. 0, 0, 0, 0, 0,
  107616. NULL,
  107617. NULL,
  107618. NULL,
  107619. NULL,
  107620. 0
  107621. };
  107622. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107626. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107627. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107628. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107629. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107630. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107631. };
  107632. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107633. 1, 128,
  107634. _huff_lengthlist_line_2048x27_3sub3,
  107635. 0, 0, 0, 0, 0,
  107636. NULL,
  107637. NULL,
  107638. NULL,
  107639. NULL,
  107640. 0
  107641. };
  107642. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107643. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107644. 4, 5,
  107645. };
  107646. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107647. 1, 18,
  107648. _huff_lengthlist_line_2048x27_4sub1,
  107649. 0, 0, 0, 0, 0,
  107650. NULL,
  107651. NULL,
  107652. NULL,
  107653. NULL,
  107654. 0
  107655. };
  107656. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107658. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107659. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107660. 10,10,
  107661. };
  107662. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107663. 1, 50,
  107664. _huff_lengthlist_line_2048x27_4sub2,
  107665. 0, 0, 0, 0, 0,
  107666. NULL,
  107667. NULL,
  107668. NULL,
  107669. NULL,
  107670. 0
  107671. };
  107672. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107676. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107677. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107678. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107679. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107680. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107681. };
  107682. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107683. 1, 128,
  107684. _huff_lengthlist_line_2048x27_4sub3,
  107685. 0, 0, 0, 0, 0,
  107686. NULL,
  107687. NULL,
  107688. NULL,
  107689. NULL,
  107690. 0
  107691. };
  107692. static long _huff_lengthlist_line_256x4low_class0[] = {
  107693. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  107694. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  107695. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  107696. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  107697. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  107698. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  107699. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  107700. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  107701. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  107702. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  107703. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  107704. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  107705. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  107706. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  107707. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  107708. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  107709. };
  107710. static static_codebook _huff_book_line_256x4low_class0 = {
  107711. 1, 256,
  107712. _huff_lengthlist_line_256x4low_class0,
  107713. 0, 0, 0, 0, 0,
  107714. NULL,
  107715. NULL,
  107716. NULL,
  107717. NULL,
  107718. 0
  107719. };
  107720. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  107721. 1, 3, 2, 3,
  107722. };
  107723. static static_codebook _huff_book_line_256x4low_0sub0 = {
  107724. 1, 4,
  107725. _huff_lengthlist_line_256x4low_0sub0,
  107726. 0, 0, 0, 0, 0,
  107727. NULL,
  107728. NULL,
  107729. NULL,
  107730. NULL,
  107731. 0
  107732. };
  107733. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  107734. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  107735. };
  107736. static static_codebook _huff_book_line_256x4low_0sub1 = {
  107737. 1, 10,
  107738. _huff_lengthlist_line_256x4low_0sub1,
  107739. 0, 0, 0, 0, 0,
  107740. NULL,
  107741. NULL,
  107742. NULL,
  107743. NULL,
  107744. 0
  107745. };
  107746. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  107747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  107748. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  107749. };
  107750. static static_codebook _huff_book_line_256x4low_0sub2 = {
  107751. 1, 25,
  107752. _huff_lengthlist_line_256x4low_0sub2,
  107753. 0, 0, 0, 0, 0,
  107754. NULL,
  107755. NULL,
  107756. NULL,
  107757. NULL,
  107758. 0
  107759. };
  107760. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  107761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  107763. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  107764. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  107765. };
  107766. static static_codebook _huff_book_line_256x4low_0sub3 = {
  107767. 1, 64,
  107768. _huff_lengthlist_line_256x4low_0sub3,
  107769. 0, 0, 0, 0, 0,
  107770. NULL,
  107771. NULL,
  107772. NULL,
  107773. NULL,
  107774. 0
  107775. };
  107776. /*** End of inlined file: floor_books.h ***/
  107777. static static_codebook *_floor_128x4_books[]={
  107778. &_huff_book_line_128x4_class0,
  107779. &_huff_book_line_128x4_0sub0,
  107780. &_huff_book_line_128x4_0sub1,
  107781. &_huff_book_line_128x4_0sub2,
  107782. &_huff_book_line_128x4_0sub3,
  107783. };
  107784. static static_codebook *_floor_256x4_books[]={
  107785. &_huff_book_line_256x4_class0,
  107786. &_huff_book_line_256x4_0sub0,
  107787. &_huff_book_line_256x4_0sub1,
  107788. &_huff_book_line_256x4_0sub2,
  107789. &_huff_book_line_256x4_0sub3,
  107790. };
  107791. static static_codebook *_floor_128x7_books[]={
  107792. &_huff_book_line_128x7_class0,
  107793. &_huff_book_line_128x7_class1,
  107794. &_huff_book_line_128x7_0sub1,
  107795. &_huff_book_line_128x7_0sub2,
  107796. &_huff_book_line_128x7_0sub3,
  107797. &_huff_book_line_128x7_1sub1,
  107798. &_huff_book_line_128x7_1sub2,
  107799. &_huff_book_line_128x7_1sub3,
  107800. };
  107801. static static_codebook *_floor_256x7_books[]={
  107802. &_huff_book_line_256x7_class0,
  107803. &_huff_book_line_256x7_class1,
  107804. &_huff_book_line_256x7_0sub1,
  107805. &_huff_book_line_256x7_0sub2,
  107806. &_huff_book_line_256x7_0sub3,
  107807. &_huff_book_line_256x7_1sub1,
  107808. &_huff_book_line_256x7_1sub2,
  107809. &_huff_book_line_256x7_1sub3,
  107810. };
  107811. static static_codebook *_floor_128x11_books[]={
  107812. &_huff_book_line_128x11_class1,
  107813. &_huff_book_line_128x11_class2,
  107814. &_huff_book_line_128x11_class3,
  107815. &_huff_book_line_128x11_0sub0,
  107816. &_huff_book_line_128x11_1sub0,
  107817. &_huff_book_line_128x11_1sub1,
  107818. &_huff_book_line_128x11_2sub1,
  107819. &_huff_book_line_128x11_2sub2,
  107820. &_huff_book_line_128x11_2sub3,
  107821. &_huff_book_line_128x11_3sub1,
  107822. &_huff_book_line_128x11_3sub2,
  107823. &_huff_book_line_128x11_3sub3,
  107824. };
  107825. static static_codebook *_floor_128x17_books[]={
  107826. &_huff_book_line_128x17_class1,
  107827. &_huff_book_line_128x17_class2,
  107828. &_huff_book_line_128x17_class3,
  107829. &_huff_book_line_128x17_0sub0,
  107830. &_huff_book_line_128x17_1sub0,
  107831. &_huff_book_line_128x17_1sub1,
  107832. &_huff_book_line_128x17_2sub1,
  107833. &_huff_book_line_128x17_2sub2,
  107834. &_huff_book_line_128x17_2sub3,
  107835. &_huff_book_line_128x17_3sub1,
  107836. &_huff_book_line_128x17_3sub2,
  107837. &_huff_book_line_128x17_3sub3,
  107838. };
  107839. static static_codebook *_floor_256x4low_books[]={
  107840. &_huff_book_line_256x4low_class0,
  107841. &_huff_book_line_256x4low_0sub0,
  107842. &_huff_book_line_256x4low_0sub1,
  107843. &_huff_book_line_256x4low_0sub2,
  107844. &_huff_book_line_256x4low_0sub3,
  107845. };
  107846. static static_codebook *_floor_1024x27_books[]={
  107847. &_huff_book_line_1024x27_class1,
  107848. &_huff_book_line_1024x27_class2,
  107849. &_huff_book_line_1024x27_class3,
  107850. &_huff_book_line_1024x27_class4,
  107851. &_huff_book_line_1024x27_0sub0,
  107852. &_huff_book_line_1024x27_1sub0,
  107853. &_huff_book_line_1024x27_1sub1,
  107854. &_huff_book_line_1024x27_2sub0,
  107855. &_huff_book_line_1024x27_2sub1,
  107856. &_huff_book_line_1024x27_3sub1,
  107857. &_huff_book_line_1024x27_3sub2,
  107858. &_huff_book_line_1024x27_3sub3,
  107859. &_huff_book_line_1024x27_4sub1,
  107860. &_huff_book_line_1024x27_4sub2,
  107861. &_huff_book_line_1024x27_4sub3,
  107862. };
  107863. static static_codebook *_floor_2048x27_books[]={
  107864. &_huff_book_line_2048x27_class1,
  107865. &_huff_book_line_2048x27_class2,
  107866. &_huff_book_line_2048x27_class3,
  107867. &_huff_book_line_2048x27_class4,
  107868. &_huff_book_line_2048x27_0sub0,
  107869. &_huff_book_line_2048x27_1sub0,
  107870. &_huff_book_line_2048x27_1sub1,
  107871. &_huff_book_line_2048x27_2sub0,
  107872. &_huff_book_line_2048x27_2sub1,
  107873. &_huff_book_line_2048x27_3sub1,
  107874. &_huff_book_line_2048x27_3sub2,
  107875. &_huff_book_line_2048x27_3sub3,
  107876. &_huff_book_line_2048x27_4sub1,
  107877. &_huff_book_line_2048x27_4sub2,
  107878. &_huff_book_line_2048x27_4sub3,
  107879. };
  107880. static static_codebook *_floor_512x17_books[]={
  107881. &_huff_book_line_512x17_class1,
  107882. &_huff_book_line_512x17_class2,
  107883. &_huff_book_line_512x17_class3,
  107884. &_huff_book_line_512x17_0sub0,
  107885. &_huff_book_line_512x17_1sub0,
  107886. &_huff_book_line_512x17_1sub1,
  107887. &_huff_book_line_512x17_2sub1,
  107888. &_huff_book_line_512x17_2sub2,
  107889. &_huff_book_line_512x17_2sub3,
  107890. &_huff_book_line_512x17_3sub1,
  107891. &_huff_book_line_512x17_3sub2,
  107892. &_huff_book_line_512x17_3sub3,
  107893. };
  107894. static static_codebook **_floor_books[10]={
  107895. _floor_128x4_books,
  107896. _floor_256x4_books,
  107897. _floor_128x7_books,
  107898. _floor_256x7_books,
  107899. _floor_128x11_books,
  107900. _floor_128x17_books,
  107901. _floor_256x4low_books,
  107902. _floor_1024x27_books,
  107903. _floor_2048x27_books,
  107904. _floor_512x17_books,
  107905. };
  107906. static vorbis_info_floor1 _floor[10]={
  107907. {
  107908. 1,{0},{4},{2},{0},
  107909. {{1,2,3,4}},
  107910. 4,{0,128, 33,8,16,70},
  107911. 60,30,500, 1.,18., -1
  107912. },
  107913. {
  107914. 1,{0},{4},{2},{0},
  107915. {{1,2,3,4}},
  107916. 4,{0,256, 66,16,32,140},
  107917. 60,30,500, 1.,18., -1
  107918. },
  107919. {
  107920. 2,{0,1},{3,4},{2,2},{0,1},
  107921. {{-1,2,3,4},{-1,5,6,7}},
  107922. 4,{0,128, 14,4,58, 2,8,28,90},
  107923. 60,30,500, 1.,18., -1
  107924. },
  107925. {
  107926. 2,{0,1},{3,4},{2,2},{0,1},
  107927. {{-1,2,3,4},{-1,5,6,7}},
  107928. 4,{0,256, 28,8,116, 4,16,56,180},
  107929. 60,30,500, 1.,18., -1
  107930. },
  107931. {
  107932. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  107933. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  107934. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  107935. 60,30,500, 1,18., -1
  107936. },
  107937. {
  107938. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  107939. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  107940. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  107941. 60,30,500, 1,18., -1
  107942. },
  107943. {
  107944. 1,{0},{4},{2},{0},
  107945. {{1,2,3,4}},
  107946. 4,{0,256, 66,16,32,140},
  107947. 60,30,500, 1.,18., -1
  107948. },
  107949. {
  107950. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  107951. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  107952. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  107953. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  107954. 60,30,500, 3,18., -1 /* lowpass */
  107955. },
  107956. {
  107957. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  107958. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  107959. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  107960. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  107961. 60,30,500, 3,18., -1 /* lowpass */
  107962. },
  107963. {
  107964. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  107965. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  107966. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  107967. 7,23,39, 55,79,110, 156,232,360},
  107968. 60,30,500, 1,18., -1 /* lowpass! */
  107969. },
  107970. };
  107971. /*** End of inlined file: floor_all.h ***/
  107972. /*** Start of inlined file: residue_44.h ***/
  107973. /*** Start of inlined file: res_books_stereo.h ***/
  107974. static long _vq_quantlist__16c0_s_p1_0[] = {
  107975. 1,
  107976. 0,
  107977. 2,
  107978. };
  107979. static long _vq_lengthlist__16c0_s_p1_0[] = {
  107980. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  107981. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107985. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  107986. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107990. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  107991. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108026. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  108031. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108036. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108071. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108072. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108076. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108077. 0, 0, 0, 0, 0, 9,10,12, 0, 0, 0, 0, 0, 0, 0, 0,
  108078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108081. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108082. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108390. 0,
  108391. };
  108392. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108393. -0.5, 0.5,
  108394. };
  108395. static long _vq_quantmap__16c0_s_p1_0[] = {
  108396. 1, 0, 2,
  108397. };
  108398. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108399. _vq_quantthresh__16c0_s_p1_0,
  108400. _vq_quantmap__16c0_s_p1_0,
  108401. 3,
  108402. 3
  108403. };
  108404. static static_codebook _16c0_s_p1_0 = {
  108405. 8, 6561,
  108406. _vq_lengthlist__16c0_s_p1_0,
  108407. 1, -535822336, 1611661312, 2, 0,
  108408. _vq_quantlist__16c0_s_p1_0,
  108409. NULL,
  108410. &_vq_auxt__16c0_s_p1_0,
  108411. NULL,
  108412. 0
  108413. };
  108414. static long _vq_quantlist__16c0_s_p2_0[] = {
  108415. 2,
  108416. 1,
  108417. 3,
  108418. 0,
  108419. 4,
  108420. };
  108421. static long _vq_lengthlist__16c0_s_p2_0[] = {
  108422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108461. 0,
  108462. };
  108463. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108464. -1.5, -0.5, 0.5, 1.5,
  108465. };
  108466. static long _vq_quantmap__16c0_s_p2_0[] = {
  108467. 3, 1, 0, 2, 4,
  108468. };
  108469. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108470. _vq_quantthresh__16c0_s_p2_0,
  108471. _vq_quantmap__16c0_s_p2_0,
  108472. 5,
  108473. 5
  108474. };
  108475. static static_codebook _16c0_s_p2_0 = {
  108476. 4, 625,
  108477. _vq_lengthlist__16c0_s_p2_0,
  108478. 1, -533725184, 1611661312, 3, 0,
  108479. _vq_quantlist__16c0_s_p2_0,
  108480. NULL,
  108481. &_vq_auxt__16c0_s_p2_0,
  108482. NULL,
  108483. 0
  108484. };
  108485. static long _vq_quantlist__16c0_s_p3_0[] = {
  108486. 2,
  108487. 1,
  108488. 3,
  108489. 0,
  108490. 4,
  108491. };
  108492. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108493. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108496. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108499. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  108500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108532. 0,
  108533. };
  108534. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108535. -1.5, -0.5, 0.5, 1.5,
  108536. };
  108537. static long _vq_quantmap__16c0_s_p3_0[] = {
  108538. 3, 1, 0, 2, 4,
  108539. };
  108540. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108541. _vq_quantthresh__16c0_s_p3_0,
  108542. _vq_quantmap__16c0_s_p3_0,
  108543. 5,
  108544. 5
  108545. };
  108546. static static_codebook _16c0_s_p3_0 = {
  108547. 4, 625,
  108548. _vq_lengthlist__16c0_s_p3_0,
  108549. 1, -533725184, 1611661312, 3, 0,
  108550. _vq_quantlist__16c0_s_p3_0,
  108551. NULL,
  108552. &_vq_auxt__16c0_s_p3_0,
  108553. NULL,
  108554. 0
  108555. };
  108556. static long _vq_quantlist__16c0_s_p4_0[] = {
  108557. 4,
  108558. 3,
  108559. 5,
  108560. 2,
  108561. 6,
  108562. 1,
  108563. 7,
  108564. 0,
  108565. 8,
  108566. };
  108567. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108568. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108569. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108570. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108571. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108572. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108573. 0,
  108574. };
  108575. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108576. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108577. };
  108578. static long _vq_quantmap__16c0_s_p4_0[] = {
  108579. 7, 5, 3, 1, 0, 2, 4, 6,
  108580. 8,
  108581. };
  108582. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108583. _vq_quantthresh__16c0_s_p4_0,
  108584. _vq_quantmap__16c0_s_p4_0,
  108585. 9,
  108586. 9
  108587. };
  108588. static static_codebook _16c0_s_p4_0 = {
  108589. 2, 81,
  108590. _vq_lengthlist__16c0_s_p4_0,
  108591. 1, -531628032, 1611661312, 4, 0,
  108592. _vq_quantlist__16c0_s_p4_0,
  108593. NULL,
  108594. &_vq_auxt__16c0_s_p4_0,
  108595. NULL,
  108596. 0
  108597. };
  108598. static long _vq_quantlist__16c0_s_p5_0[] = {
  108599. 4,
  108600. 3,
  108601. 5,
  108602. 2,
  108603. 6,
  108604. 1,
  108605. 7,
  108606. 0,
  108607. 8,
  108608. };
  108609. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108610. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108611. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108612. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108613. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108614. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108615. 10,
  108616. };
  108617. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108618. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108619. };
  108620. static long _vq_quantmap__16c0_s_p5_0[] = {
  108621. 7, 5, 3, 1, 0, 2, 4, 6,
  108622. 8,
  108623. };
  108624. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108625. _vq_quantthresh__16c0_s_p5_0,
  108626. _vq_quantmap__16c0_s_p5_0,
  108627. 9,
  108628. 9
  108629. };
  108630. static static_codebook _16c0_s_p5_0 = {
  108631. 2, 81,
  108632. _vq_lengthlist__16c0_s_p5_0,
  108633. 1, -531628032, 1611661312, 4, 0,
  108634. _vq_quantlist__16c0_s_p5_0,
  108635. NULL,
  108636. &_vq_auxt__16c0_s_p5_0,
  108637. NULL,
  108638. 0
  108639. };
  108640. static long _vq_quantlist__16c0_s_p6_0[] = {
  108641. 8,
  108642. 7,
  108643. 9,
  108644. 6,
  108645. 10,
  108646. 5,
  108647. 11,
  108648. 4,
  108649. 12,
  108650. 3,
  108651. 13,
  108652. 2,
  108653. 14,
  108654. 1,
  108655. 15,
  108656. 0,
  108657. 16,
  108658. };
  108659. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108660. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108661. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108662. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108663. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108664. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108665. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108666. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108667. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108668. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108669. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108670. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108671. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108672. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108673. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108674. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108675. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108676. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108677. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108678. 14,
  108679. };
  108680. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108681. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108682. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108683. };
  108684. static long _vq_quantmap__16c0_s_p6_0[] = {
  108685. 15, 13, 11, 9, 7, 5, 3, 1,
  108686. 0, 2, 4, 6, 8, 10, 12, 14,
  108687. 16,
  108688. };
  108689. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108690. _vq_quantthresh__16c0_s_p6_0,
  108691. _vq_quantmap__16c0_s_p6_0,
  108692. 17,
  108693. 17
  108694. };
  108695. static static_codebook _16c0_s_p6_0 = {
  108696. 2, 289,
  108697. _vq_lengthlist__16c0_s_p6_0,
  108698. 1, -529530880, 1611661312, 5, 0,
  108699. _vq_quantlist__16c0_s_p6_0,
  108700. NULL,
  108701. &_vq_auxt__16c0_s_p6_0,
  108702. NULL,
  108703. 0
  108704. };
  108705. static long _vq_quantlist__16c0_s_p7_0[] = {
  108706. 1,
  108707. 0,
  108708. 2,
  108709. };
  108710. static long _vq_lengthlist__16c0_s_p7_0[] = {
  108711. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  108712. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  108713. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  108714. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  108715. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  108716. 13,
  108717. };
  108718. static float _vq_quantthresh__16c0_s_p7_0[] = {
  108719. -5.5, 5.5,
  108720. };
  108721. static long _vq_quantmap__16c0_s_p7_0[] = {
  108722. 1, 0, 2,
  108723. };
  108724. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  108725. _vq_quantthresh__16c0_s_p7_0,
  108726. _vq_quantmap__16c0_s_p7_0,
  108727. 3,
  108728. 3
  108729. };
  108730. static static_codebook _16c0_s_p7_0 = {
  108731. 4, 81,
  108732. _vq_lengthlist__16c0_s_p7_0,
  108733. 1, -529137664, 1618345984, 2, 0,
  108734. _vq_quantlist__16c0_s_p7_0,
  108735. NULL,
  108736. &_vq_auxt__16c0_s_p7_0,
  108737. NULL,
  108738. 0
  108739. };
  108740. static long _vq_quantlist__16c0_s_p7_1[] = {
  108741. 5,
  108742. 4,
  108743. 6,
  108744. 3,
  108745. 7,
  108746. 2,
  108747. 8,
  108748. 1,
  108749. 9,
  108750. 0,
  108751. 10,
  108752. };
  108753. static long _vq_lengthlist__16c0_s_p7_1[] = {
  108754. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  108755. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  108756. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  108757. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  108758. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  108759. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  108760. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  108761. 11,11,11, 9, 9, 9, 9,10,10,
  108762. };
  108763. static float _vq_quantthresh__16c0_s_p7_1[] = {
  108764. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  108765. 3.5, 4.5,
  108766. };
  108767. static long _vq_quantmap__16c0_s_p7_1[] = {
  108768. 9, 7, 5, 3, 1, 0, 2, 4,
  108769. 6, 8, 10,
  108770. };
  108771. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  108772. _vq_quantthresh__16c0_s_p7_1,
  108773. _vq_quantmap__16c0_s_p7_1,
  108774. 11,
  108775. 11
  108776. };
  108777. static static_codebook _16c0_s_p7_1 = {
  108778. 2, 121,
  108779. _vq_lengthlist__16c0_s_p7_1,
  108780. 1, -531365888, 1611661312, 4, 0,
  108781. _vq_quantlist__16c0_s_p7_1,
  108782. NULL,
  108783. &_vq_auxt__16c0_s_p7_1,
  108784. NULL,
  108785. 0
  108786. };
  108787. static long _vq_quantlist__16c0_s_p8_0[] = {
  108788. 6,
  108789. 5,
  108790. 7,
  108791. 4,
  108792. 8,
  108793. 3,
  108794. 9,
  108795. 2,
  108796. 10,
  108797. 1,
  108798. 11,
  108799. 0,
  108800. 12,
  108801. };
  108802. static long _vq_lengthlist__16c0_s_p8_0[] = {
  108803. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  108804. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  108805. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  108806. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  108807. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  108808. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  108809. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  108810. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  108811. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  108812. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  108813. 0,12,13,13,12,13,14,14,14,
  108814. };
  108815. static float _vq_quantthresh__16c0_s_p8_0[] = {
  108816. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  108817. 12.5, 17.5, 22.5, 27.5,
  108818. };
  108819. static long _vq_quantmap__16c0_s_p8_0[] = {
  108820. 11, 9, 7, 5, 3, 1, 0, 2,
  108821. 4, 6, 8, 10, 12,
  108822. };
  108823. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  108824. _vq_quantthresh__16c0_s_p8_0,
  108825. _vq_quantmap__16c0_s_p8_0,
  108826. 13,
  108827. 13
  108828. };
  108829. static static_codebook _16c0_s_p8_0 = {
  108830. 2, 169,
  108831. _vq_lengthlist__16c0_s_p8_0,
  108832. 1, -526516224, 1616117760, 4, 0,
  108833. _vq_quantlist__16c0_s_p8_0,
  108834. NULL,
  108835. &_vq_auxt__16c0_s_p8_0,
  108836. NULL,
  108837. 0
  108838. };
  108839. static long _vq_quantlist__16c0_s_p8_1[] = {
  108840. 2,
  108841. 1,
  108842. 3,
  108843. 0,
  108844. 4,
  108845. };
  108846. static long _vq_lengthlist__16c0_s_p8_1[] = {
  108847. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  108848. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  108849. };
  108850. static float _vq_quantthresh__16c0_s_p8_1[] = {
  108851. -1.5, -0.5, 0.5, 1.5,
  108852. };
  108853. static long _vq_quantmap__16c0_s_p8_1[] = {
  108854. 3, 1, 0, 2, 4,
  108855. };
  108856. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  108857. _vq_quantthresh__16c0_s_p8_1,
  108858. _vq_quantmap__16c0_s_p8_1,
  108859. 5,
  108860. 5
  108861. };
  108862. static static_codebook _16c0_s_p8_1 = {
  108863. 2, 25,
  108864. _vq_lengthlist__16c0_s_p8_1,
  108865. 1, -533725184, 1611661312, 3, 0,
  108866. _vq_quantlist__16c0_s_p8_1,
  108867. NULL,
  108868. &_vq_auxt__16c0_s_p8_1,
  108869. NULL,
  108870. 0
  108871. };
  108872. static long _vq_quantlist__16c0_s_p9_0[] = {
  108873. 1,
  108874. 0,
  108875. 2,
  108876. };
  108877. static long _vq_lengthlist__16c0_s_p9_0[] = {
  108878. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  108879. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  108880. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108881. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108882. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108883. 7,
  108884. };
  108885. static float _vq_quantthresh__16c0_s_p9_0[] = {
  108886. -157.5, 157.5,
  108887. };
  108888. static long _vq_quantmap__16c0_s_p9_0[] = {
  108889. 1, 0, 2,
  108890. };
  108891. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  108892. _vq_quantthresh__16c0_s_p9_0,
  108893. _vq_quantmap__16c0_s_p9_0,
  108894. 3,
  108895. 3
  108896. };
  108897. static static_codebook _16c0_s_p9_0 = {
  108898. 4, 81,
  108899. _vq_lengthlist__16c0_s_p9_0,
  108900. 1, -518803456, 1628680192, 2, 0,
  108901. _vq_quantlist__16c0_s_p9_0,
  108902. NULL,
  108903. &_vq_auxt__16c0_s_p9_0,
  108904. NULL,
  108905. 0
  108906. };
  108907. static long _vq_quantlist__16c0_s_p9_1[] = {
  108908. 7,
  108909. 6,
  108910. 8,
  108911. 5,
  108912. 9,
  108913. 4,
  108914. 10,
  108915. 3,
  108916. 11,
  108917. 2,
  108918. 12,
  108919. 1,
  108920. 13,
  108921. 0,
  108922. 14,
  108923. };
  108924. static long _vq_lengthlist__16c0_s_p9_1[] = {
  108925. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  108926. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  108927. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  108928. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  108929. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108930. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108931. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108932. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108933. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108934. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108935. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108936. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108937. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108938. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108939. 10,
  108940. };
  108941. static float _vq_quantthresh__16c0_s_p9_1[] = {
  108942. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  108943. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  108944. };
  108945. static long _vq_quantmap__16c0_s_p9_1[] = {
  108946. 13, 11, 9, 7, 5, 3, 1, 0,
  108947. 2, 4, 6, 8, 10, 12, 14,
  108948. };
  108949. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  108950. _vq_quantthresh__16c0_s_p9_1,
  108951. _vq_quantmap__16c0_s_p9_1,
  108952. 15,
  108953. 15
  108954. };
  108955. static static_codebook _16c0_s_p9_1 = {
  108956. 2, 225,
  108957. _vq_lengthlist__16c0_s_p9_1,
  108958. 1, -520986624, 1620377600, 4, 0,
  108959. _vq_quantlist__16c0_s_p9_1,
  108960. NULL,
  108961. &_vq_auxt__16c0_s_p9_1,
  108962. NULL,
  108963. 0
  108964. };
  108965. static long _vq_quantlist__16c0_s_p9_2[] = {
  108966. 10,
  108967. 9,
  108968. 11,
  108969. 8,
  108970. 12,
  108971. 7,
  108972. 13,
  108973. 6,
  108974. 14,
  108975. 5,
  108976. 15,
  108977. 4,
  108978. 16,
  108979. 3,
  108980. 17,
  108981. 2,
  108982. 18,
  108983. 1,
  108984. 19,
  108985. 0,
  108986. 20,
  108987. };
  108988. static long _vq_lengthlist__16c0_s_p9_2[] = {
  108989. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  108990. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  108991. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  108992. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  108993. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  108994. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  108995. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  108996. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  108997. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  108998. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  108999. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109000. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109001. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109002. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109003. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109004. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109005. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109006. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109007. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109008. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109009. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109010. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109011. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109012. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109013. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109014. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109015. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109016. 10,11,10,10,11, 9,10,10,10,
  109017. };
  109018. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109019. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109020. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109021. 6.5, 7.5, 8.5, 9.5,
  109022. };
  109023. static long _vq_quantmap__16c0_s_p9_2[] = {
  109024. 19, 17, 15, 13, 11, 9, 7, 5,
  109025. 3, 1, 0, 2, 4, 6, 8, 10,
  109026. 12, 14, 16, 18, 20,
  109027. };
  109028. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109029. _vq_quantthresh__16c0_s_p9_2,
  109030. _vq_quantmap__16c0_s_p9_2,
  109031. 21,
  109032. 21
  109033. };
  109034. static static_codebook _16c0_s_p9_2 = {
  109035. 2, 441,
  109036. _vq_lengthlist__16c0_s_p9_2,
  109037. 1, -529268736, 1611661312, 5, 0,
  109038. _vq_quantlist__16c0_s_p9_2,
  109039. NULL,
  109040. &_vq_auxt__16c0_s_p9_2,
  109041. NULL,
  109042. 0
  109043. };
  109044. static long _huff_lengthlist__16c0_s_single[] = {
  109045. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109046. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109047. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109048. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109049. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109050. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109051. 16,16,18,18,
  109052. };
  109053. static static_codebook _huff_book__16c0_s_single = {
  109054. 2, 100,
  109055. _huff_lengthlist__16c0_s_single,
  109056. 0, 0, 0, 0, 0,
  109057. NULL,
  109058. NULL,
  109059. NULL,
  109060. NULL,
  109061. 0
  109062. };
  109063. static long _huff_lengthlist__16c1_s_long[] = {
  109064. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109065. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109066. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109067. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109068. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109069. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109070. 12,11,11,13,
  109071. };
  109072. static static_codebook _huff_book__16c1_s_long = {
  109073. 2, 100,
  109074. _huff_lengthlist__16c1_s_long,
  109075. 0, 0, 0, 0, 0,
  109076. NULL,
  109077. NULL,
  109078. NULL,
  109079. NULL,
  109080. 0
  109081. };
  109082. static long _vq_quantlist__16c1_s_p1_0[] = {
  109083. 1,
  109084. 0,
  109085. 2,
  109086. };
  109087. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109088. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109089. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109093. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109094. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109098. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109099. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109134. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109139. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109144. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109179. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109180. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109184. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109185. 0, 0, 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  109186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109189. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109190. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109498. 0,
  109499. };
  109500. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109501. -0.5, 0.5,
  109502. };
  109503. static long _vq_quantmap__16c1_s_p1_0[] = {
  109504. 1, 0, 2,
  109505. };
  109506. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109507. _vq_quantthresh__16c1_s_p1_0,
  109508. _vq_quantmap__16c1_s_p1_0,
  109509. 3,
  109510. 3
  109511. };
  109512. static static_codebook _16c1_s_p1_0 = {
  109513. 8, 6561,
  109514. _vq_lengthlist__16c1_s_p1_0,
  109515. 1, -535822336, 1611661312, 2, 0,
  109516. _vq_quantlist__16c1_s_p1_0,
  109517. NULL,
  109518. &_vq_auxt__16c1_s_p1_0,
  109519. NULL,
  109520. 0
  109521. };
  109522. static long _vq_quantlist__16c1_s_p2_0[] = {
  109523. 2,
  109524. 1,
  109525. 3,
  109526. 0,
  109527. 4,
  109528. };
  109529. static long _vq_lengthlist__16c1_s_p2_0[] = {
  109530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109569. 0,
  109570. };
  109571. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109572. -1.5, -0.5, 0.5, 1.5,
  109573. };
  109574. static long _vq_quantmap__16c1_s_p2_0[] = {
  109575. 3, 1, 0, 2, 4,
  109576. };
  109577. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109578. _vq_quantthresh__16c1_s_p2_0,
  109579. _vq_quantmap__16c1_s_p2_0,
  109580. 5,
  109581. 5
  109582. };
  109583. static static_codebook _16c1_s_p2_0 = {
  109584. 4, 625,
  109585. _vq_lengthlist__16c1_s_p2_0,
  109586. 1, -533725184, 1611661312, 3, 0,
  109587. _vq_quantlist__16c1_s_p2_0,
  109588. NULL,
  109589. &_vq_auxt__16c1_s_p2_0,
  109590. NULL,
  109591. 0
  109592. };
  109593. static long _vq_quantlist__16c1_s_p3_0[] = {
  109594. 2,
  109595. 1,
  109596. 3,
  109597. 0,
  109598. 4,
  109599. };
  109600. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109601. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109604. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109607. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109640. 0,
  109641. };
  109642. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109643. -1.5, -0.5, 0.5, 1.5,
  109644. };
  109645. static long _vq_quantmap__16c1_s_p3_0[] = {
  109646. 3, 1, 0, 2, 4,
  109647. };
  109648. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109649. _vq_quantthresh__16c1_s_p3_0,
  109650. _vq_quantmap__16c1_s_p3_0,
  109651. 5,
  109652. 5
  109653. };
  109654. static static_codebook _16c1_s_p3_0 = {
  109655. 4, 625,
  109656. _vq_lengthlist__16c1_s_p3_0,
  109657. 1, -533725184, 1611661312, 3, 0,
  109658. _vq_quantlist__16c1_s_p3_0,
  109659. NULL,
  109660. &_vq_auxt__16c1_s_p3_0,
  109661. NULL,
  109662. 0
  109663. };
  109664. static long _vq_quantlist__16c1_s_p4_0[] = {
  109665. 4,
  109666. 3,
  109667. 5,
  109668. 2,
  109669. 6,
  109670. 1,
  109671. 7,
  109672. 0,
  109673. 8,
  109674. };
  109675. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109676. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109677. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109678. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109679. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109680. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109681. 0,
  109682. };
  109683. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109684. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109685. };
  109686. static long _vq_quantmap__16c1_s_p4_0[] = {
  109687. 7, 5, 3, 1, 0, 2, 4, 6,
  109688. 8,
  109689. };
  109690. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109691. _vq_quantthresh__16c1_s_p4_0,
  109692. _vq_quantmap__16c1_s_p4_0,
  109693. 9,
  109694. 9
  109695. };
  109696. static static_codebook _16c1_s_p4_0 = {
  109697. 2, 81,
  109698. _vq_lengthlist__16c1_s_p4_0,
  109699. 1, -531628032, 1611661312, 4, 0,
  109700. _vq_quantlist__16c1_s_p4_0,
  109701. NULL,
  109702. &_vq_auxt__16c1_s_p4_0,
  109703. NULL,
  109704. 0
  109705. };
  109706. static long _vq_quantlist__16c1_s_p5_0[] = {
  109707. 4,
  109708. 3,
  109709. 5,
  109710. 2,
  109711. 6,
  109712. 1,
  109713. 7,
  109714. 0,
  109715. 8,
  109716. };
  109717. static long _vq_lengthlist__16c1_s_p5_0[] = {
  109718. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109719. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  109720. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  109721. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  109722. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109723. 10,
  109724. };
  109725. static float _vq_quantthresh__16c1_s_p5_0[] = {
  109726. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109727. };
  109728. static long _vq_quantmap__16c1_s_p5_0[] = {
  109729. 7, 5, 3, 1, 0, 2, 4, 6,
  109730. 8,
  109731. };
  109732. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  109733. _vq_quantthresh__16c1_s_p5_0,
  109734. _vq_quantmap__16c1_s_p5_0,
  109735. 9,
  109736. 9
  109737. };
  109738. static static_codebook _16c1_s_p5_0 = {
  109739. 2, 81,
  109740. _vq_lengthlist__16c1_s_p5_0,
  109741. 1, -531628032, 1611661312, 4, 0,
  109742. _vq_quantlist__16c1_s_p5_0,
  109743. NULL,
  109744. &_vq_auxt__16c1_s_p5_0,
  109745. NULL,
  109746. 0
  109747. };
  109748. static long _vq_quantlist__16c1_s_p6_0[] = {
  109749. 8,
  109750. 7,
  109751. 9,
  109752. 6,
  109753. 10,
  109754. 5,
  109755. 11,
  109756. 4,
  109757. 12,
  109758. 3,
  109759. 13,
  109760. 2,
  109761. 14,
  109762. 1,
  109763. 15,
  109764. 0,
  109765. 16,
  109766. };
  109767. static long _vq_lengthlist__16c1_s_p6_0[] = {
  109768. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  109769. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  109770. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  109771. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  109772. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  109773. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109774. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109775. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109776. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  109777. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109778. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  109779. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  109780. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  109781. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  109782. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  109783. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  109784. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  109785. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  109786. 14,
  109787. };
  109788. static float _vq_quantthresh__16c1_s_p6_0[] = {
  109789. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109790. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109791. };
  109792. static long _vq_quantmap__16c1_s_p6_0[] = {
  109793. 15, 13, 11, 9, 7, 5, 3, 1,
  109794. 0, 2, 4, 6, 8, 10, 12, 14,
  109795. 16,
  109796. };
  109797. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  109798. _vq_quantthresh__16c1_s_p6_0,
  109799. _vq_quantmap__16c1_s_p6_0,
  109800. 17,
  109801. 17
  109802. };
  109803. static static_codebook _16c1_s_p6_0 = {
  109804. 2, 289,
  109805. _vq_lengthlist__16c1_s_p6_0,
  109806. 1, -529530880, 1611661312, 5, 0,
  109807. _vq_quantlist__16c1_s_p6_0,
  109808. NULL,
  109809. &_vq_auxt__16c1_s_p6_0,
  109810. NULL,
  109811. 0
  109812. };
  109813. static long _vq_quantlist__16c1_s_p7_0[] = {
  109814. 1,
  109815. 0,
  109816. 2,
  109817. };
  109818. static long _vq_lengthlist__16c1_s_p7_0[] = {
  109819. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  109820. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109821. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  109822. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  109823. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  109824. 11,
  109825. };
  109826. static float _vq_quantthresh__16c1_s_p7_0[] = {
  109827. -5.5, 5.5,
  109828. };
  109829. static long _vq_quantmap__16c1_s_p7_0[] = {
  109830. 1, 0, 2,
  109831. };
  109832. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  109833. _vq_quantthresh__16c1_s_p7_0,
  109834. _vq_quantmap__16c1_s_p7_0,
  109835. 3,
  109836. 3
  109837. };
  109838. static static_codebook _16c1_s_p7_0 = {
  109839. 4, 81,
  109840. _vq_lengthlist__16c1_s_p7_0,
  109841. 1, -529137664, 1618345984, 2, 0,
  109842. _vq_quantlist__16c1_s_p7_0,
  109843. NULL,
  109844. &_vq_auxt__16c1_s_p7_0,
  109845. NULL,
  109846. 0
  109847. };
  109848. static long _vq_quantlist__16c1_s_p7_1[] = {
  109849. 5,
  109850. 4,
  109851. 6,
  109852. 3,
  109853. 7,
  109854. 2,
  109855. 8,
  109856. 1,
  109857. 9,
  109858. 0,
  109859. 10,
  109860. };
  109861. static long _vq_lengthlist__16c1_s_p7_1[] = {
  109862. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  109863. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  109864. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  109865. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  109866. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  109867. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  109868. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  109869. 10,10,10, 8, 8, 8, 8, 9, 9,
  109870. };
  109871. static float _vq_quantthresh__16c1_s_p7_1[] = {
  109872. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109873. 3.5, 4.5,
  109874. };
  109875. static long _vq_quantmap__16c1_s_p7_1[] = {
  109876. 9, 7, 5, 3, 1, 0, 2, 4,
  109877. 6, 8, 10,
  109878. };
  109879. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  109880. _vq_quantthresh__16c1_s_p7_1,
  109881. _vq_quantmap__16c1_s_p7_1,
  109882. 11,
  109883. 11
  109884. };
  109885. static static_codebook _16c1_s_p7_1 = {
  109886. 2, 121,
  109887. _vq_lengthlist__16c1_s_p7_1,
  109888. 1, -531365888, 1611661312, 4, 0,
  109889. _vq_quantlist__16c1_s_p7_1,
  109890. NULL,
  109891. &_vq_auxt__16c1_s_p7_1,
  109892. NULL,
  109893. 0
  109894. };
  109895. static long _vq_quantlist__16c1_s_p8_0[] = {
  109896. 6,
  109897. 5,
  109898. 7,
  109899. 4,
  109900. 8,
  109901. 3,
  109902. 9,
  109903. 2,
  109904. 10,
  109905. 1,
  109906. 11,
  109907. 0,
  109908. 12,
  109909. };
  109910. static long _vq_lengthlist__16c1_s_p8_0[] = {
  109911. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  109912. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  109913. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  109914. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  109915. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  109916. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  109917. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  109918. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  109919. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  109920. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  109921. 0,12,12,12,12,13,13,14,15,
  109922. };
  109923. static float _vq_quantthresh__16c1_s_p8_0[] = {
  109924. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109925. 12.5, 17.5, 22.5, 27.5,
  109926. };
  109927. static long _vq_quantmap__16c1_s_p8_0[] = {
  109928. 11, 9, 7, 5, 3, 1, 0, 2,
  109929. 4, 6, 8, 10, 12,
  109930. };
  109931. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  109932. _vq_quantthresh__16c1_s_p8_0,
  109933. _vq_quantmap__16c1_s_p8_0,
  109934. 13,
  109935. 13
  109936. };
  109937. static static_codebook _16c1_s_p8_0 = {
  109938. 2, 169,
  109939. _vq_lengthlist__16c1_s_p8_0,
  109940. 1, -526516224, 1616117760, 4, 0,
  109941. _vq_quantlist__16c1_s_p8_0,
  109942. NULL,
  109943. &_vq_auxt__16c1_s_p8_0,
  109944. NULL,
  109945. 0
  109946. };
  109947. static long _vq_quantlist__16c1_s_p8_1[] = {
  109948. 2,
  109949. 1,
  109950. 3,
  109951. 0,
  109952. 4,
  109953. };
  109954. static long _vq_lengthlist__16c1_s_p8_1[] = {
  109955. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  109956. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  109957. };
  109958. static float _vq_quantthresh__16c1_s_p8_1[] = {
  109959. -1.5, -0.5, 0.5, 1.5,
  109960. };
  109961. static long _vq_quantmap__16c1_s_p8_1[] = {
  109962. 3, 1, 0, 2, 4,
  109963. };
  109964. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  109965. _vq_quantthresh__16c1_s_p8_1,
  109966. _vq_quantmap__16c1_s_p8_1,
  109967. 5,
  109968. 5
  109969. };
  109970. static static_codebook _16c1_s_p8_1 = {
  109971. 2, 25,
  109972. _vq_lengthlist__16c1_s_p8_1,
  109973. 1, -533725184, 1611661312, 3, 0,
  109974. _vq_quantlist__16c1_s_p8_1,
  109975. NULL,
  109976. &_vq_auxt__16c1_s_p8_1,
  109977. NULL,
  109978. 0
  109979. };
  109980. static long _vq_quantlist__16c1_s_p9_0[] = {
  109981. 6,
  109982. 5,
  109983. 7,
  109984. 4,
  109985. 8,
  109986. 3,
  109987. 9,
  109988. 2,
  109989. 10,
  109990. 1,
  109991. 11,
  109992. 0,
  109993. 12,
  109994. };
  109995. static long _vq_lengthlist__16c1_s_p9_0[] = {
  109996. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  109997. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  109998. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  109999. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110000. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110001. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110002. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110003. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110004. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110005. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110006. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110007. };
  110008. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110009. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110010. 787.5, 1102.5, 1417.5, 1732.5,
  110011. };
  110012. static long _vq_quantmap__16c1_s_p9_0[] = {
  110013. 11, 9, 7, 5, 3, 1, 0, 2,
  110014. 4, 6, 8, 10, 12,
  110015. };
  110016. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110017. _vq_quantthresh__16c1_s_p9_0,
  110018. _vq_quantmap__16c1_s_p9_0,
  110019. 13,
  110020. 13
  110021. };
  110022. static static_codebook _16c1_s_p9_0 = {
  110023. 2, 169,
  110024. _vq_lengthlist__16c1_s_p9_0,
  110025. 1, -513964032, 1628680192, 4, 0,
  110026. _vq_quantlist__16c1_s_p9_0,
  110027. NULL,
  110028. &_vq_auxt__16c1_s_p9_0,
  110029. NULL,
  110030. 0
  110031. };
  110032. static long _vq_quantlist__16c1_s_p9_1[] = {
  110033. 7,
  110034. 6,
  110035. 8,
  110036. 5,
  110037. 9,
  110038. 4,
  110039. 10,
  110040. 3,
  110041. 11,
  110042. 2,
  110043. 12,
  110044. 1,
  110045. 13,
  110046. 0,
  110047. 14,
  110048. };
  110049. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110050. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110051. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110052. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110053. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110054. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110055. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110056. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110057. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110058. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110059. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110060. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110061. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110062. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110063. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110064. 13,
  110065. };
  110066. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110067. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110068. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110069. };
  110070. static long _vq_quantmap__16c1_s_p9_1[] = {
  110071. 13, 11, 9, 7, 5, 3, 1, 0,
  110072. 2, 4, 6, 8, 10, 12, 14,
  110073. };
  110074. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110075. _vq_quantthresh__16c1_s_p9_1,
  110076. _vq_quantmap__16c1_s_p9_1,
  110077. 15,
  110078. 15
  110079. };
  110080. static static_codebook _16c1_s_p9_1 = {
  110081. 2, 225,
  110082. _vq_lengthlist__16c1_s_p9_1,
  110083. 1, -520986624, 1620377600, 4, 0,
  110084. _vq_quantlist__16c1_s_p9_1,
  110085. NULL,
  110086. &_vq_auxt__16c1_s_p9_1,
  110087. NULL,
  110088. 0
  110089. };
  110090. static long _vq_quantlist__16c1_s_p9_2[] = {
  110091. 10,
  110092. 9,
  110093. 11,
  110094. 8,
  110095. 12,
  110096. 7,
  110097. 13,
  110098. 6,
  110099. 14,
  110100. 5,
  110101. 15,
  110102. 4,
  110103. 16,
  110104. 3,
  110105. 17,
  110106. 2,
  110107. 18,
  110108. 1,
  110109. 19,
  110110. 0,
  110111. 20,
  110112. };
  110113. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110114. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110115. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110116. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110117. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110118. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110119. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110120. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110121. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110122. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110123. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110124. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110125. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110126. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110127. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110128. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110129. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110130. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110131. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110132. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110133. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110134. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110135. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110136. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110137. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110138. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110139. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110140. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110141. 11,11,11,11,12,11,11,12,11,
  110142. };
  110143. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110144. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110145. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110146. 6.5, 7.5, 8.5, 9.5,
  110147. };
  110148. static long _vq_quantmap__16c1_s_p9_2[] = {
  110149. 19, 17, 15, 13, 11, 9, 7, 5,
  110150. 3, 1, 0, 2, 4, 6, 8, 10,
  110151. 12, 14, 16, 18, 20,
  110152. };
  110153. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110154. _vq_quantthresh__16c1_s_p9_2,
  110155. _vq_quantmap__16c1_s_p9_2,
  110156. 21,
  110157. 21
  110158. };
  110159. static static_codebook _16c1_s_p9_2 = {
  110160. 2, 441,
  110161. _vq_lengthlist__16c1_s_p9_2,
  110162. 1, -529268736, 1611661312, 5, 0,
  110163. _vq_quantlist__16c1_s_p9_2,
  110164. NULL,
  110165. &_vq_auxt__16c1_s_p9_2,
  110166. NULL,
  110167. 0
  110168. };
  110169. static long _huff_lengthlist__16c1_s_short[] = {
  110170. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110171. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110172. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110173. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110174. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110175. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110176. 9, 9,10,13,
  110177. };
  110178. static static_codebook _huff_book__16c1_s_short = {
  110179. 2, 100,
  110180. _huff_lengthlist__16c1_s_short,
  110181. 0, 0, 0, 0, 0,
  110182. NULL,
  110183. NULL,
  110184. NULL,
  110185. NULL,
  110186. 0
  110187. };
  110188. static long _huff_lengthlist__16c2_s_long[] = {
  110189. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110190. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110191. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110192. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110193. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110194. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110195. 14,14,16,18,
  110196. };
  110197. static static_codebook _huff_book__16c2_s_long = {
  110198. 2, 100,
  110199. _huff_lengthlist__16c2_s_long,
  110200. 0, 0, 0, 0, 0,
  110201. NULL,
  110202. NULL,
  110203. NULL,
  110204. NULL,
  110205. 0
  110206. };
  110207. static long _vq_quantlist__16c2_s_p1_0[] = {
  110208. 1,
  110209. 0,
  110210. 2,
  110211. };
  110212. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110213. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110214. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110218. 0,
  110219. };
  110220. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110221. -0.5, 0.5,
  110222. };
  110223. static long _vq_quantmap__16c2_s_p1_0[] = {
  110224. 1, 0, 2,
  110225. };
  110226. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110227. _vq_quantthresh__16c2_s_p1_0,
  110228. _vq_quantmap__16c2_s_p1_0,
  110229. 3,
  110230. 3
  110231. };
  110232. static static_codebook _16c2_s_p1_0 = {
  110233. 4, 81,
  110234. _vq_lengthlist__16c2_s_p1_0,
  110235. 1, -535822336, 1611661312, 2, 0,
  110236. _vq_quantlist__16c2_s_p1_0,
  110237. NULL,
  110238. &_vq_auxt__16c2_s_p1_0,
  110239. NULL,
  110240. 0
  110241. };
  110242. static long _vq_quantlist__16c2_s_p2_0[] = {
  110243. 2,
  110244. 1,
  110245. 3,
  110246. 0,
  110247. 4,
  110248. };
  110249. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110250. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110251. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110252. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110253. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110254. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110255. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110256. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110257. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110262. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110263. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110264. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110265. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110270. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110271. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110272. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110273. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110278. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110279. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110280. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110281. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110286. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110287. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110288. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110289. 13,
  110290. };
  110291. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110292. -1.5, -0.5, 0.5, 1.5,
  110293. };
  110294. static long _vq_quantmap__16c2_s_p2_0[] = {
  110295. 3, 1, 0, 2, 4,
  110296. };
  110297. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110298. _vq_quantthresh__16c2_s_p2_0,
  110299. _vq_quantmap__16c2_s_p2_0,
  110300. 5,
  110301. 5
  110302. };
  110303. static static_codebook _16c2_s_p2_0 = {
  110304. 4, 625,
  110305. _vq_lengthlist__16c2_s_p2_0,
  110306. 1, -533725184, 1611661312, 3, 0,
  110307. _vq_quantlist__16c2_s_p2_0,
  110308. NULL,
  110309. &_vq_auxt__16c2_s_p2_0,
  110310. NULL,
  110311. 0
  110312. };
  110313. static long _vq_quantlist__16c2_s_p3_0[] = {
  110314. 4,
  110315. 3,
  110316. 5,
  110317. 2,
  110318. 6,
  110319. 1,
  110320. 7,
  110321. 0,
  110322. 8,
  110323. };
  110324. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110325. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110326. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110327. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110328. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110330. 0,
  110331. };
  110332. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110333. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110334. };
  110335. static long _vq_quantmap__16c2_s_p3_0[] = {
  110336. 7, 5, 3, 1, 0, 2, 4, 6,
  110337. 8,
  110338. };
  110339. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110340. _vq_quantthresh__16c2_s_p3_0,
  110341. _vq_quantmap__16c2_s_p3_0,
  110342. 9,
  110343. 9
  110344. };
  110345. static static_codebook _16c2_s_p3_0 = {
  110346. 2, 81,
  110347. _vq_lengthlist__16c2_s_p3_0,
  110348. 1, -531628032, 1611661312, 4, 0,
  110349. _vq_quantlist__16c2_s_p3_0,
  110350. NULL,
  110351. &_vq_auxt__16c2_s_p3_0,
  110352. NULL,
  110353. 0
  110354. };
  110355. static long _vq_quantlist__16c2_s_p4_0[] = {
  110356. 8,
  110357. 7,
  110358. 9,
  110359. 6,
  110360. 10,
  110361. 5,
  110362. 11,
  110363. 4,
  110364. 12,
  110365. 3,
  110366. 13,
  110367. 2,
  110368. 14,
  110369. 1,
  110370. 15,
  110371. 0,
  110372. 16,
  110373. };
  110374. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110375. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110376. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110377. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110378. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110379. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110380. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110381. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110382. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110383. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110384. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110393. 0,
  110394. };
  110395. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110396. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110397. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110398. };
  110399. static long _vq_quantmap__16c2_s_p4_0[] = {
  110400. 15, 13, 11, 9, 7, 5, 3, 1,
  110401. 0, 2, 4, 6, 8, 10, 12, 14,
  110402. 16,
  110403. };
  110404. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110405. _vq_quantthresh__16c2_s_p4_0,
  110406. _vq_quantmap__16c2_s_p4_0,
  110407. 17,
  110408. 17
  110409. };
  110410. static static_codebook _16c2_s_p4_0 = {
  110411. 2, 289,
  110412. _vq_lengthlist__16c2_s_p4_0,
  110413. 1, -529530880, 1611661312, 5, 0,
  110414. _vq_quantlist__16c2_s_p4_0,
  110415. NULL,
  110416. &_vq_auxt__16c2_s_p4_0,
  110417. NULL,
  110418. 0
  110419. };
  110420. static long _vq_quantlist__16c2_s_p5_0[] = {
  110421. 1,
  110422. 0,
  110423. 2,
  110424. };
  110425. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110426. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110427. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110428. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110429. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110430. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110431. 12,
  110432. };
  110433. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110434. -5.5, 5.5,
  110435. };
  110436. static long _vq_quantmap__16c2_s_p5_0[] = {
  110437. 1, 0, 2,
  110438. };
  110439. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110440. _vq_quantthresh__16c2_s_p5_0,
  110441. _vq_quantmap__16c2_s_p5_0,
  110442. 3,
  110443. 3
  110444. };
  110445. static static_codebook _16c2_s_p5_0 = {
  110446. 4, 81,
  110447. _vq_lengthlist__16c2_s_p5_0,
  110448. 1, -529137664, 1618345984, 2, 0,
  110449. _vq_quantlist__16c2_s_p5_0,
  110450. NULL,
  110451. &_vq_auxt__16c2_s_p5_0,
  110452. NULL,
  110453. 0
  110454. };
  110455. static long _vq_quantlist__16c2_s_p5_1[] = {
  110456. 5,
  110457. 4,
  110458. 6,
  110459. 3,
  110460. 7,
  110461. 2,
  110462. 8,
  110463. 1,
  110464. 9,
  110465. 0,
  110466. 10,
  110467. };
  110468. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110469. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110470. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110471. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110472. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110473. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110474. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110475. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110476. 11,11,11, 7, 7, 8, 8, 8, 8,
  110477. };
  110478. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110479. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110480. 3.5, 4.5,
  110481. };
  110482. static long _vq_quantmap__16c2_s_p5_1[] = {
  110483. 9, 7, 5, 3, 1, 0, 2, 4,
  110484. 6, 8, 10,
  110485. };
  110486. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110487. _vq_quantthresh__16c2_s_p5_1,
  110488. _vq_quantmap__16c2_s_p5_1,
  110489. 11,
  110490. 11
  110491. };
  110492. static static_codebook _16c2_s_p5_1 = {
  110493. 2, 121,
  110494. _vq_lengthlist__16c2_s_p5_1,
  110495. 1, -531365888, 1611661312, 4, 0,
  110496. _vq_quantlist__16c2_s_p5_1,
  110497. NULL,
  110498. &_vq_auxt__16c2_s_p5_1,
  110499. NULL,
  110500. 0
  110501. };
  110502. static long _vq_quantlist__16c2_s_p6_0[] = {
  110503. 6,
  110504. 5,
  110505. 7,
  110506. 4,
  110507. 8,
  110508. 3,
  110509. 9,
  110510. 2,
  110511. 10,
  110512. 1,
  110513. 11,
  110514. 0,
  110515. 12,
  110516. };
  110517. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110518. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110519. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110520. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110521. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110522. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110523. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110528. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110529. };
  110530. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110531. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110532. 12.5, 17.5, 22.5, 27.5,
  110533. };
  110534. static long _vq_quantmap__16c2_s_p6_0[] = {
  110535. 11, 9, 7, 5, 3, 1, 0, 2,
  110536. 4, 6, 8, 10, 12,
  110537. };
  110538. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110539. _vq_quantthresh__16c2_s_p6_0,
  110540. _vq_quantmap__16c2_s_p6_0,
  110541. 13,
  110542. 13
  110543. };
  110544. static static_codebook _16c2_s_p6_0 = {
  110545. 2, 169,
  110546. _vq_lengthlist__16c2_s_p6_0,
  110547. 1, -526516224, 1616117760, 4, 0,
  110548. _vq_quantlist__16c2_s_p6_0,
  110549. NULL,
  110550. &_vq_auxt__16c2_s_p6_0,
  110551. NULL,
  110552. 0
  110553. };
  110554. static long _vq_quantlist__16c2_s_p6_1[] = {
  110555. 2,
  110556. 1,
  110557. 3,
  110558. 0,
  110559. 4,
  110560. };
  110561. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110562. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110563. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110564. };
  110565. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110566. -1.5, -0.5, 0.5, 1.5,
  110567. };
  110568. static long _vq_quantmap__16c2_s_p6_1[] = {
  110569. 3, 1, 0, 2, 4,
  110570. };
  110571. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110572. _vq_quantthresh__16c2_s_p6_1,
  110573. _vq_quantmap__16c2_s_p6_1,
  110574. 5,
  110575. 5
  110576. };
  110577. static static_codebook _16c2_s_p6_1 = {
  110578. 2, 25,
  110579. _vq_lengthlist__16c2_s_p6_1,
  110580. 1, -533725184, 1611661312, 3, 0,
  110581. _vq_quantlist__16c2_s_p6_1,
  110582. NULL,
  110583. &_vq_auxt__16c2_s_p6_1,
  110584. NULL,
  110585. 0
  110586. };
  110587. static long _vq_quantlist__16c2_s_p7_0[] = {
  110588. 6,
  110589. 5,
  110590. 7,
  110591. 4,
  110592. 8,
  110593. 3,
  110594. 9,
  110595. 2,
  110596. 10,
  110597. 1,
  110598. 11,
  110599. 0,
  110600. 12,
  110601. };
  110602. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110603. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110604. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110605. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110606. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110607. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110608. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110609. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110610. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110611. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110612. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110613. 18,13,14,13,13,14,13,15,14,
  110614. };
  110615. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110616. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110617. 27.5, 38.5, 49.5, 60.5,
  110618. };
  110619. static long _vq_quantmap__16c2_s_p7_0[] = {
  110620. 11, 9, 7, 5, 3, 1, 0, 2,
  110621. 4, 6, 8, 10, 12,
  110622. };
  110623. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110624. _vq_quantthresh__16c2_s_p7_0,
  110625. _vq_quantmap__16c2_s_p7_0,
  110626. 13,
  110627. 13
  110628. };
  110629. static static_codebook _16c2_s_p7_0 = {
  110630. 2, 169,
  110631. _vq_lengthlist__16c2_s_p7_0,
  110632. 1, -523206656, 1618345984, 4, 0,
  110633. _vq_quantlist__16c2_s_p7_0,
  110634. NULL,
  110635. &_vq_auxt__16c2_s_p7_0,
  110636. NULL,
  110637. 0
  110638. };
  110639. static long _vq_quantlist__16c2_s_p7_1[] = {
  110640. 5,
  110641. 4,
  110642. 6,
  110643. 3,
  110644. 7,
  110645. 2,
  110646. 8,
  110647. 1,
  110648. 9,
  110649. 0,
  110650. 10,
  110651. };
  110652. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110653. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110654. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110655. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110656. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110657. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110658. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110659. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110660. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110661. };
  110662. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110663. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110664. 3.5, 4.5,
  110665. };
  110666. static long _vq_quantmap__16c2_s_p7_1[] = {
  110667. 9, 7, 5, 3, 1, 0, 2, 4,
  110668. 6, 8, 10,
  110669. };
  110670. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110671. _vq_quantthresh__16c2_s_p7_1,
  110672. _vq_quantmap__16c2_s_p7_1,
  110673. 11,
  110674. 11
  110675. };
  110676. static static_codebook _16c2_s_p7_1 = {
  110677. 2, 121,
  110678. _vq_lengthlist__16c2_s_p7_1,
  110679. 1, -531365888, 1611661312, 4, 0,
  110680. _vq_quantlist__16c2_s_p7_1,
  110681. NULL,
  110682. &_vq_auxt__16c2_s_p7_1,
  110683. NULL,
  110684. 0
  110685. };
  110686. static long _vq_quantlist__16c2_s_p8_0[] = {
  110687. 7,
  110688. 6,
  110689. 8,
  110690. 5,
  110691. 9,
  110692. 4,
  110693. 10,
  110694. 3,
  110695. 11,
  110696. 2,
  110697. 12,
  110698. 1,
  110699. 13,
  110700. 0,
  110701. 14,
  110702. };
  110703. static long _vq_lengthlist__16c2_s_p8_0[] = {
  110704. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  110705. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  110706. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  110707. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  110708. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  110709. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  110710. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  110711. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  110712. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  110713. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  110714. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  110715. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  110716. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  110717. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  110718. 13,
  110719. };
  110720. static float _vq_quantthresh__16c2_s_p8_0[] = {
  110721. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110722. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110723. };
  110724. static long _vq_quantmap__16c2_s_p8_0[] = {
  110725. 13, 11, 9, 7, 5, 3, 1, 0,
  110726. 2, 4, 6, 8, 10, 12, 14,
  110727. };
  110728. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  110729. _vq_quantthresh__16c2_s_p8_0,
  110730. _vq_quantmap__16c2_s_p8_0,
  110731. 15,
  110732. 15
  110733. };
  110734. static static_codebook _16c2_s_p8_0 = {
  110735. 2, 225,
  110736. _vq_lengthlist__16c2_s_p8_0,
  110737. 1, -520986624, 1620377600, 4, 0,
  110738. _vq_quantlist__16c2_s_p8_0,
  110739. NULL,
  110740. &_vq_auxt__16c2_s_p8_0,
  110741. NULL,
  110742. 0
  110743. };
  110744. static long _vq_quantlist__16c2_s_p8_1[] = {
  110745. 10,
  110746. 9,
  110747. 11,
  110748. 8,
  110749. 12,
  110750. 7,
  110751. 13,
  110752. 6,
  110753. 14,
  110754. 5,
  110755. 15,
  110756. 4,
  110757. 16,
  110758. 3,
  110759. 17,
  110760. 2,
  110761. 18,
  110762. 1,
  110763. 19,
  110764. 0,
  110765. 20,
  110766. };
  110767. static long _vq_lengthlist__16c2_s_p8_1[] = {
  110768. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  110769. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  110770. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  110771. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  110772. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  110773. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  110774. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  110775. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  110776. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  110777. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  110778. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  110779. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  110780. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  110781. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  110782. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  110783. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  110784. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  110785. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  110786. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  110787. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  110788. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  110789. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  110790. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  110791. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  110792. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  110793. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  110794. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  110795. 10,11,10,10,10,10,10,10,10,
  110796. };
  110797. static float _vq_quantthresh__16c2_s_p8_1[] = {
  110798. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110799. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110800. 6.5, 7.5, 8.5, 9.5,
  110801. };
  110802. static long _vq_quantmap__16c2_s_p8_1[] = {
  110803. 19, 17, 15, 13, 11, 9, 7, 5,
  110804. 3, 1, 0, 2, 4, 6, 8, 10,
  110805. 12, 14, 16, 18, 20,
  110806. };
  110807. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  110808. _vq_quantthresh__16c2_s_p8_1,
  110809. _vq_quantmap__16c2_s_p8_1,
  110810. 21,
  110811. 21
  110812. };
  110813. static static_codebook _16c2_s_p8_1 = {
  110814. 2, 441,
  110815. _vq_lengthlist__16c2_s_p8_1,
  110816. 1, -529268736, 1611661312, 5, 0,
  110817. _vq_quantlist__16c2_s_p8_1,
  110818. NULL,
  110819. &_vq_auxt__16c2_s_p8_1,
  110820. NULL,
  110821. 0
  110822. };
  110823. static long _vq_quantlist__16c2_s_p9_0[] = {
  110824. 6,
  110825. 5,
  110826. 7,
  110827. 4,
  110828. 8,
  110829. 3,
  110830. 9,
  110831. 2,
  110832. 10,
  110833. 1,
  110834. 11,
  110835. 0,
  110836. 12,
  110837. };
  110838. static long _vq_lengthlist__16c2_s_p9_0[] = {
  110839. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110840. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110841. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110842. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110843. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110844. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110845. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110846. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110847. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110848. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110849. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110850. };
  110851. static float _vq_quantthresh__16c2_s_p9_0[] = {
  110852. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  110853. 2327.5, 3258.5, 4189.5, 5120.5,
  110854. };
  110855. static long _vq_quantmap__16c2_s_p9_0[] = {
  110856. 11, 9, 7, 5, 3, 1, 0, 2,
  110857. 4, 6, 8, 10, 12,
  110858. };
  110859. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  110860. _vq_quantthresh__16c2_s_p9_0,
  110861. _vq_quantmap__16c2_s_p9_0,
  110862. 13,
  110863. 13
  110864. };
  110865. static static_codebook _16c2_s_p9_0 = {
  110866. 2, 169,
  110867. _vq_lengthlist__16c2_s_p9_0,
  110868. 1, -510275072, 1631393792, 4, 0,
  110869. _vq_quantlist__16c2_s_p9_0,
  110870. NULL,
  110871. &_vq_auxt__16c2_s_p9_0,
  110872. NULL,
  110873. 0
  110874. };
  110875. static long _vq_quantlist__16c2_s_p9_1[] = {
  110876. 8,
  110877. 7,
  110878. 9,
  110879. 6,
  110880. 10,
  110881. 5,
  110882. 11,
  110883. 4,
  110884. 12,
  110885. 3,
  110886. 13,
  110887. 2,
  110888. 14,
  110889. 1,
  110890. 15,
  110891. 0,
  110892. 16,
  110893. };
  110894. static long _vq_lengthlist__16c2_s_p9_1[] = {
  110895. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  110896. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  110897. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  110898. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  110899. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  110900. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  110901. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  110902. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  110903. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  110904. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  110905. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110906. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110907. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110908. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110909. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110910. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  110911. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  110912. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110913. 10,
  110914. };
  110915. static float _vq_quantthresh__16c2_s_p9_1[] = {
  110916. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  110917. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  110918. };
  110919. static long _vq_quantmap__16c2_s_p9_1[] = {
  110920. 15, 13, 11, 9, 7, 5, 3, 1,
  110921. 0, 2, 4, 6, 8, 10, 12, 14,
  110922. 16,
  110923. };
  110924. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  110925. _vq_quantthresh__16c2_s_p9_1,
  110926. _vq_quantmap__16c2_s_p9_1,
  110927. 17,
  110928. 17
  110929. };
  110930. static static_codebook _16c2_s_p9_1 = {
  110931. 2, 289,
  110932. _vq_lengthlist__16c2_s_p9_1,
  110933. 1, -518488064, 1622704128, 5, 0,
  110934. _vq_quantlist__16c2_s_p9_1,
  110935. NULL,
  110936. &_vq_auxt__16c2_s_p9_1,
  110937. NULL,
  110938. 0
  110939. };
  110940. static long _vq_quantlist__16c2_s_p9_2[] = {
  110941. 13,
  110942. 12,
  110943. 14,
  110944. 11,
  110945. 15,
  110946. 10,
  110947. 16,
  110948. 9,
  110949. 17,
  110950. 8,
  110951. 18,
  110952. 7,
  110953. 19,
  110954. 6,
  110955. 20,
  110956. 5,
  110957. 21,
  110958. 4,
  110959. 22,
  110960. 3,
  110961. 23,
  110962. 2,
  110963. 24,
  110964. 1,
  110965. 25,
  110966. 0,
  110967. 26,
  110968. };
  110969. static long _vq_lengthlist__16c2_s_p9_2[] = {
  110970. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  110971. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  110972. };
  110973. static float _vq_quantthresh__16c2_s_p9_2[] = {
  110974. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  110975. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110976. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  110977. 11.5, 12.5,
  110978. };
  110979. static long _vq_quantmap__16c2_s_p9_2[] = {
  110980. 25, 23, 21, 19, 17, 15, 13, 11,
  110981. 9, 7, 5, 3, 1, 0, 2, 4,
  110982. 6, 8, 10, 12, 14, 16, 18, 20,
  110983. 22, 24, 26,
  110984. };
  110985. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  110986. _vq_quantthresh__16c2_s_p9_2,
  110987. _vq_quantmap__16c2_s_p9_2,
  110988. 27,
  110989. 27
  110990. };
  110991. static static_codebook _16c2_s_p9_2 = {
  110992. 1, 27,
  110993. _vq_lengthlist__16c2_s_p9_2,
  110994. 1, -528875520, 1611661312, 5, 0,
  110995. _vq_quantlist__16c2_s_p9_2,
  110996. NULL,
  110997. &_vq_auxt__16c2_s_p9_2,
  110998. NULL,
  110999. 0
  111000. };
  111001. static long _huff_lengthlist__16c2_s_short[] = {
  111002. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111003. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111004. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111005. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111006. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111007. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111008. 15,12,14,14,
  111009. };
  111010. static static_codebook _huff_book__16c2_s_short = {
  111011. 2, 100,
  111012. _huff_lengthlist__16c2_s_short,
  111013. 0, 0, 0, 0, 0,
  111014. NULL,
  111015. NULL,
  111016. NULL,
  111017. NULL,
  111018. 0
  111019. };
  111020. static long _vq_quantlist__8c0_s_p1_0[] = {
  111021. 1,
  111022. 0,
  111023. 2,
  111024. };
  111025. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111026. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111027. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111031. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111032. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111036. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111037. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111072. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  111077. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111082. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111117. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111118. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111122. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111123. 0, 0, 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 0, 0,
  111124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111127. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111128. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111436. 0,
  111437. };
  111438. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111439. -0.5, 0.5,
  111440. };
  111441. static long _vq_quantmap__8c0_s_p1_0[] = {
  111442. 1, 0, 2,
  111443. };
  111444. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111445. _vq_quantthresh__8c0_s_p1_0,
  111446. _vq_quantmap__8c0_s_p1_0,
  111447. 3,
  111448. 3
  111449. };
  111450. static static_codebook _8c0_s_p1_0 = {
  111451. 8, 6561,
  111452. _vq_lengthlist__8c0_s_p1_0,
  111453. 1, -535822336, 1611661312, 2, 0,
  111454. _vq_quantlist__8c0_s_p1_0,
  111455. NULL,
  111456. &_vq_auxt__8c0_s_p1_0,
  111457. NULL,
  111458. 0
  111459. };
  111460. static long _vq_quantlist__8c0_s_p2_0[] = {
  111461. 2,
  111462. 1,
  111463. 3,
  111464. 0,
  111465. 4,
  111466. };
  111467. static long _vq_lengthlist__8c0_s_p2_0[] = {
  111468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111507. 0,
  111508. };
  111509. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111510. -1.5, -0.5, 0.5, 1.5,
  111511. };
  111512. static long _vq_quantmap__8c0_s_p2_0[] = {
  111513. 3, 1, 0, 2, 4,
  111514. };
  111515. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111516. _vq_quantthresh__8c0_s_p2_0,
  111517. _vq_quantmap__8c0_s_p2_0,
  111518. 5,
  111519. 5
  111520. };
  111521. static static_codebook _8c0_s_p2_0 = {
  111522. 4, 625,
  111523. _vq_lengthlist__8c0_s_p2_0,
  111524. 1, -533725184, 1611661312, 3, 0,
  111525. _vq_quantlist__8c0_s_p2_0,
  111526. NULL,
  111527. &_vq_auxt__8c0_s_p2_0,
  111528. NULL,
  111529. 0
  111530. };
  111531. static long _vq_quantlist__8c0_s_p3_0[] = {
  111532. 2,
  111533. 1,
  111534. 3,
  111535. 0,
  111536. 4,
  111537. };
  111538. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111539. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111542. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111545. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  111546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111578. 0,
  111579. };
  111580. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111581. -1.5, -0.5, 0.5, 1.5,
  111582. };
  111583. static long _vq_quantmap__8c0_s_p3_0[] = {
  111584. 3, 1, 0, 2, 4,
  111585. };
  111586. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111587. _vq_quantthresh__8c0_s_p3_0,
  111588. _vq_quantmap__8c0_s_p3_0,
  111589. 5,
  111590. 5
  111591. };
  111592. static static_codebook _8c0_s_p3_0 = {
  111593. 4, 625,
  111594. _vq_lengthlist__8c0_s_p3_0,
  111595. 1, -533725184, 1611661312, 3, 0,
  111596. _vq_quantlist__8c0_s_p3_0,
  111597. NULL,
  111598. &_vq_auxt__8c0_s_p3_0,
  111599. NULL,
  111600. 0
  111601. };
  111602. static long _vq_quantlist__8c0_s_p4_0[] = {
  111603. 4,
  111604. 3,
  111605. 5,
  111606. 2,
  111607. 6,
  111608. 1,
  111609. 7,
  111610. 0,
  111611. 8,
  111612. };
  111613. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111614. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111615. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111616. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111617. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111618. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111619. 0,
  111620. };
  111621. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111622. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111623. };
  111624. static long _vq_quantmap__8c0_s_p4_0[] = {
  111625. 7, 5, 3, 1, 0, 2, 4, 6,
  111626. 8,
  111627. };
  111628. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111629. _vq_quantthresh__8c0_s_p4_0,
  111630. _vq_quantmap__8c0_s_p4_0,
  111631. 9,
  111632. 9
  111633. };
  111634. static static_codebook _8c0_s_p4_0 = {
  111635. 2, 81,
  111636. _vq_lengthlist__8c0_s_p4_0,
  111637. 1, -531628032, 1611661312, 4, 0,
  111638. _vq_quantlist__8c0_s_p4_0,
  111639. NULL,
  111640. &_vq_auxt__8c0_s_p4_0,
  111641. NULL,
  111642. 0
  111643. };
  111644. static long _vq_quantlist__8c0_s_p5_0[] = {
  111645. 4,
  111646. 3,
  111647. 5,
  111648. 2,
  111649. 6,
  111650. 1,
  111651. 7,
  111652. 0,
  111653. 8,
  111654. };
  111655. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111656. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111657. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111658. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111659. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111660. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111661. 10,
  111662. };
  111663. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111664. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111665. };
  111666. static long _vq_quantmap__8c0_s_p5_0[] = {
  111667. 7, 5, 3, 1, 0, 2, 4, 6,
  111668. 8,
  111669. };
  111670. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111671. _vq_quantthresh__8c0_s_p5_0,
  111672. _vq_quantmap__8c0_s_p5_0,
  111673. 9,
  111674. 9
  111675. };
  111676. static static_codebook _8c0_s_p5_0 = {
  111677. 2, 81,
  111678. _vq_lengthlist__8c0_s_p5_0,
  111679. 1, -531628032, 1611661312, 4, 0,
  111680. _vq_quantlist__8c0_s_p5_0,
  111681. NULL,
  111682. &_vq_auxt__8c0_s_p5_0,
  111683. NULL,
  111684. 0
  111685. };
  111686. static long _vq_quantlist__8c0_s_p6_0[] = {
  111687. 8,
  111688. 7,
  111689. 9,
  111690. 6,
  111691. 10,
  111692. 5,
  111693. 11,
  111694. 4,
  111695. 12,
  111696. 3,
  111697. 13,
  111698. 2,
  111699. 14,
  111700. 1,
  111701. 15,
  111702. 0,
  111703. 16,
  111704. };
  111705. static long _vq_lengthlist__8c0_s_p6_0[] = {
  111706. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  111707. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  111708. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  111709. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  111710. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  111711. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  111712. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  111713. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  111714. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  111715. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  111716. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  111717. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  111718. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  111719. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  111720. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  111721. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  111722. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  111723. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  111724. 14,
  111725. };
  111726. static float _vq_quantthresh__8c0_s_p6_0[] = {
  111727. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111728. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111729. };
  111730. static long _vq_quantmap__8c0_s_p6_0[] = {
  111731. 15, 13, 11, 9, 7, 5, 3, 1,
  111732. 0, 2, 4, 6, 8, 10, 12, 14,
  111733. 16,
  111734. };
  111735. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  111736. _vq_quantthresh__8c0_s_p6_0,
  111737. _vq_quantmap__8c0_s_p6_0,
  111738. 17,
  111739. 17
  111740. };
  111741. static static_codebook _8c0_s_p6_0 = {
  111742. 2, 289,
  111743. _vq_lengthlist__8c0_s_p6_0,
  111744. 1, -529530880, 1611661312, 5, 0,
  111745. _vq_quantlist__8c0_s_p6_0,
  111746. NULL,
  111747. &_vq_auxt__8c0_s_p6_0,
  111748. NULL,
  111749. 0
  111750. };
  111751. static long _vq_quantlist__8c0_s_p7_0[] = {
  111752. 1,
  111753. 0,
  111754. 2,
  111755. };
  111756. static long _vq_lengthlist__8c0_s_p7_0[] = {
  111757. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  111758. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  111759. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  111760. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  111761. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  111762. 10,
  111763. };
  111764. static float _vq_quantthresh__8c0_s_p7_0[] = {
  111765. -5.5, 5.5,
  111766. };
  111767. static long _vq_quantmap__8c0_s_p7_0[] = {
  111768. 1, 0, 2,
  111769. };
  111770. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  111771. _vq_quantthresh__8c0_s_p7_0,
  111772. _vq_quantmap__8c0_s_p7_0,
  111773. 3,
  111774. 3
  111775. };
  111776. static static_codebook _8c0_s_p7_0 = {
  111777. 4, 81,
  111778. _vq_lengthlist__8c0_s_p7_0,
  111779. 1, -529137664, 1618345984, 2, 0,
  111780. _vq_quantlist__8c0_s_p7_0,
  111781. NULL,
  111782. &_vq_auxt__8c0_s_p7_0,
  111783. NULL,
  111784. 0
  111785. };
  111786. static long _vq_quantlist__8c0_s_p7_1[] = {
  111787. 5,
  111788. 4,
  111789. 6,
  111790. 3,
  111791. 7,
  111792. 2,
  111793. 8,
  111794. 1,
  111795. 9,
  111796. 0,
  111797. 10,
  111798. };
  111799. static long _vq_lengthlist__8c0_s_p7_1[] = {
  111800. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  111801. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  111802. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  111803. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  111804. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  111805. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  111806. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  111807. 10,10,10, 9, 9, 9,10,10,10,
  111808. };
  111809. static float _vq_quantthresh__8c0_s_p7_1[] = {
  111810. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111811. 3.5, 4.5,
  111812. };
  111813. static long _vq_quantmap__8c0_s_p7_1[] = {
  111814. 9, 7, 5, 3, 1, 0, 2, 4,
  111815. 6, 8, 10,
  111816. };
  111817. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  111818. _vq_quantthresh__8c0_s_p7_1,
  111819. _vq_quantmap__8c0_s_p7_1,
  111820. 11,
  111821. 11
  111822. };
  111823. static static_codebook _8c0_s_p7_1 = {
  111824. 2, 121,
  111825. _vq_lengthlist__8c0_s_p7_1,
  111826. 1, -531365888, 1611661312, 4, 0,
  111827. _vq_quantlist__8c0_s_p7_1,
  111828. NULL,
  111829. &_vq_auxt__8c0_s_p7_1,
  111830. NULL,
  111831. 0
  111832. };
  111833. static long _vq_quantlist__8c0_s_p8_0[] = {
  111834. 6,
  111835. 5,
  111836. 7,
  111837. 4,
  111838. 8,
  111839. 3,
  111840. 9,
  111841. 2,
  111842. 10,
  111843. 1,
  111844. 11,
  111845. 0,
  111846. 12,
  111847. };
  111848. static long _vq_lengthlist__8c0_s_p8_0[] = {
  111849. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  111850. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  111851. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  111852. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  111853. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  111854. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  111855. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  111856. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  111857. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  111858. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  111859. 0, 0,13,13,11,13,13,11,12,
  111860. };
  111861. static float _vq_quantthresh__8c0_s_p8_0[] = {
  111862. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111863. 12.5, 17.5, 22.5, 27.5,
  111864. };
  111865. static long _vq_quantmap__8c0_s_p8_0[] = {
  111866. 11, 9, 7, 5, 3, 1, 0, 2,
  111867. 4, 6, 8, 10, 12,
  111868. };
  111869. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  111870. _vq_quantthresh__8c0_s_p8_0,
  111871. _vq_quantmap__8c0_s_p8_0,
  111872. 13,
  111873. 13
  111874. };
  111875. static static_codebook _8c0_s_p8_0 = {
  111876. 2, 169,
  111877. _vq_lengthlist__8c0_s_p8_0,
  111878. 1, -526516224, 1616117760, 4, 0,
  111879. _vq_quantlist__8c0_s_p8_0,
  111880. NULL,
  111881. &_vq_auxt__8c0_s_p8_0,
  111882. NULL,
  111883. 0
  111884. };
  111885. static long _vq_quantlist__8c0_s_p8_1[] = {
  111886. 2,
  111887. 1,
  111888. 3,
  111889. 0,
  111890. 4,
  111891. };
  111892. static long _vq_lengthlist__8c0_s_p8_1[] = {
  111893. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  111894. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  111895. };
  111896. static float _vq_quantthresh__8c0_s_p8_1[] = {
  111897. -1.5, -0.5, 0.5, 1.5,
  111898. };
  111899. static long _vq_quantmap__8c0_s_p8_1[] = {
  111900. 3, 1, 0, 2, 4,
  111901. };
  111902. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  111903. _vq_quantthresh__8c0_s_p8_1,
  111904. _vq_quantmap__8c0_s_p8_1,
  111905. 5,
  111906. 5
  111907. };
  111908. static static_codebook _8c0_s_p8_1 = {
  111909. 2, 25,
  111910. _vq_lengthlist__8c0_s_p8_1,
  111911. 1, -533725184, 1611661312, 3, 0,
  111912. _vq_quantlist__8c0_s_p8_1,
  111913. NULL,
  111914. &_vq_auxt__8c0_s_p8_1,
  111915. NULL,
  111916. 0
  111917. };
  111918. static long _vq_quantlist__8c0_s_p9_0[] = {
  111919. 1,
  111920. 0,
  111921. 2,
  111922. };
  111923. static long _vq_lengthlist__8c0_s_p9_0[] = {
  111924. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111925. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111926. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  111927. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  111928. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  111929. 7,
  111930. };
  111931. static float _vq_quantthresh__8c0_s_p9_0[] = {
  111932. -157.5, 157.5,
  111933. };
  111934. static long _vq_quantmap__8c0_s_p9_0[] = {
  111935. 1, 0, 2,
  111936. };
  111937. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  111938. _vq_quantthresh__8c0_s_p9_0,
  111939. _vq_quantmap__8c0_s_p9_0,
  111940. 3,
  111941. 3
  111942. };
  111943. static static_codebook _8c0_s_p9_0 = {
  111944. 4, 81,
  111945. _vq_lengthlist__8c0_s_p9_0,
  111946. 1, -518803456, 1628680192, 2, 0,
  111947. _vq_quantlist__8c0_s_p9_0,
  111948. NULL,
  111949. &_vq_auxt__8c0_s_p9_0,
  111950. NULL,
  111951. 0
  111952. };
  111953. static long _vq_quantlist__8c0_s_p9_1[] = {
  111954. 7,
  111955. 6,
  111956. 8,
  111957. 5,
  111958. 9,
  111959. 4,
  111960. 10,
  111961. 3,
  111962. 11,
  111963. 2,
  111964. 12,
  111965. 1,
  111966. 13,
  111967. 0,
  111968. 14,
  111969. };
  111970. static long _vq_lengthlist__8c0_s_p9_1[] = {
  111971. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  111972. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  111973. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  111974. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  111975. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  111976. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  111977. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  111978. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  111979. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  111980. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  111981. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  111982. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  111983. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  111984. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  111985. 11,
  111986. };
  111987. static float _vq_quantthresh__8c0_s_p9_1[] = {
  111988. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111989. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111990. };
  111991. static long _vq_quantmap__8c0_s_p9_1[] = {
  111992. 13, 11, 9, 7, 5, 3, 1, 0,
  111993. 2, 4, 6, 8, 10, 12, 14,
  111994. };
  111995. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  111996. _vq_quantthresh__8c0_s_p9_1,
  111997. _vq_quantmap__8c0_s_p9_1,
  111998. 15,
  111999. 15
  112000. };
  112001. static static_codebook _8c0_s_p9_1 = {
  112002. 2, 225,
  112003. _vq_lengthlist__8c0_s_p9_1,
  112004. 1, -520986624, 1620377600, 4, 0,
  112005. _vq_quantlist__8c0_s_p9_1,
  112006. NULL,
  112007. &_vq_auxt__8c0_s_p9_1,
  112008. NULL,
  112009. 0
  112010. };
  112011. static long _vq_quantlist__8c0_s_p9_2[] = {
  112012. 10,
  112013. 9,
  112014. 11,
  112015. 8,
  112016. 12,
  112017. 7,
  112018. 13,
  112019. 6,
  112020. 14,
  112021. 5,
  112022. 15,
  112023. 4,
  112024. 16,
  112025. 3,
  112026. 17,
  112027. 2,
  112028. 18,
  112029. 1,
  112030. 19,
  112031. 0,
  112032. 20,
  112033. };
  112034. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112035. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112036. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112037. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112038. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112039. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112040. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112041. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112042. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112043. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112044. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112045. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112046. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112047. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112048. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112049. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112050. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112051. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112052. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112053. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112054. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112055. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112056. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112057. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112058. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112059. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112060. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112061. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112062. 10,11, 9,11,10, 9,10, 9,10,
  112063. };
  112064. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112065. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112066. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112067. 6.5, 7.5, 8.5, 9.5,
  112068. };
  112069. static long _vq_quantmap__8c0_s_p9_2[] = {
  112070. 19, 17, 15, 13, 11, 9, 7, 5,
  112071. 3, 1, 0, 2, 4, 6, 8, 10,
  112072. 12, 14, 16, 18, 20,
  112073. };
  112074. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112075. _vq_quantthresh__8c0_s_p9_2,
  112076. _vq_quantmap__8c0_s_p9_2,
  112077. 21,
  112078. 21
  112079. };
  112080. static static_codebook _8c0_s_p9_2 = {
  112081. 2, 441,
  112082. _vq_lengthlist__8c0_s_p9_2,
  112083. 1, -529268736, 1611661312, 5, 0,
  112084. _vq_quantlist__8c0_s_p9_2,
  112085. NULL,
  112086. &_vq_auxt__8c0_s_p9_2,
  112087. NULL,
  112088. 0
  112089. };
  112090. static long _huff_lengthlist__8c0_s_single[] = {
  112091. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112092. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112093. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112094. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112095. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112096. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112097. 17,16,17,17,
  112098. };
  112099. static static_codebook _huff_book__8c0_s_single = {
  112100. 2, 100,
  112101. _huff_lengthlist__8c0_s_single,
  112102. 0, 0, 0, 0, 0,
  112103. NULL,
  112104. NULL,
  112105. NULL,
  112106. NULL,
  112107. 0
  112108. };
  112109. static long _vq_quantlist__8c1_s_p1_0[] = {
  112110. 1,
  112111. 0,
  112112. 2,
  112113. };
  112114. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112115. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112116. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112120. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112121. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112125. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112126. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112161. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  112166. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112171. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112206. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112207. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112211. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112212. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  112213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112216. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112217. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112525. 0,
  112526. };
  112527. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112528. -0.5, 0.5,
  112529. };
  112530. static long _vq_quantmap__8c1_s_p1_0[] = {
  112531. 1, 0, 2,
  112532. };
  112533. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112534. _vq_quantthresh__8c1_s_p1_0,
  112535. _vq_quantmap__8c1_s_p1_0,
  112536. 3,
  112537. 3
  112538. };
  112539. static static_codebook _8c1_s_p1_0 = {
  112540. 8, 6561,
  112541. _vq_lengthlist__8c1_s_p1_0,
  112542. 1, -535822336, 1611661312, 2, 0,
  112543. _vq_quantlist__8c1_s_p1_0,
  112544. NULL,
  112545. &_vq_auxt__8c1_s_p1_0,
  112546. NULL,
  112547. 0
  112548. };
  112549. static long _vq_quantlist__8c1_s_p2_0[] = {
  112550. 2,
  112551. 1,
  112552. 3,
  112553. 0,
  112554. 4,
  112555. };
  112556. static long _vq_lengthlist__8c1_s_p2_0[] = {
  112557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112596. 0,
  112597. };
  112598. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112599. -1.5, -0.5, 0.5, 1.5,
  112600. };
  112601. static long _vq_quantmap__8c1_s_p2_0[] = {
  112602. 3, 1, 0, 2, 4,
  112603. };
  112604. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112605. _vq_quantthresh__8c1_s_p2_0,
  112606. _vq_quantmap__8c1_s_p2_0,
  112607. 5,
  112608. 5
  112609. };
  112610. static static_codebook _8c1_s_p2_0 = {
  112611. 4, 625,
  112612. _vq_lengthlist__8c1_s_p2_0,
  112613. 1, -533725184, 1611661312, 3, 0,
  112614. _vq_quantlist__8c1_s_p2_0,
  112615. NULL,
  112616. &_vq_auxt__8c1_s_p2_0,
  112617. NULL,
  112618. 0
  112619. };
  112620. static long _vq_quantlist__8c1_s_p3_0[] = {
  112621. 2,
  112622. 1,
  112623. 3,
  112624. 0,
  112625. 4,
  112626. };
  112627. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112628. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112631. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112634. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112667. 0,
  112668. };
  112669. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112670. -1.5, -0.5, 0.5, 1.5,
  112671. };
  112672. static long _vq_quantmap__8c1_s_p3_0[] = {
  112673. 3, 1, 0, 2, 4,
  112674. };
  112675. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112676. _vq_quantthresh__8c1_s_p3_0,
  112677. _vq_quantmap__8c1_s_p3_0,
  112678. 5,
  112679. 5
  112680. };
  112681. static static_codebook _8c1_s_p3_0 = {
  112682. 4, 625,
  112683. _vq_lengthlist__8c1_s_p3_0,
  112684. 1, -533725184, 1611661312, 3, 0,
  112685. _vq_quantlist__8c1_s_p3_0,
  112686. NULL,
  112687. &_vq_auxt__8c1_s_p3_0,
  112688. NULL,
  112689. 0
  112690. };
  112691. static long _vq_quantlist__8c1_s_p4_0[] = {
  112692. 4,
  112693. 3,
  112694. 5,
  112695. 2,
  112696. 6,
  112697. 1,
  112698. 7,
  112699. 0,
  112700. 8,
  112701. };
  112702. static long _vq_lengthlist__8c1_s_p4_0[] = {
  112703. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112704. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112705. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112706. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112707. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112708. 0,
  112709. };
  112710. static float _vq_quantthresh__8c1_s_p4_0[] = {
  112711. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112712. };
  112713. static long _vq_quantmap__8c1_s_p4_0[] = {
  112714. 7, 5, 3, 1, 0, 2, 4, 6,
  112715. 8,
  112716. };
  112717. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  112718. _vq_quantthresh__8c1_s_p4_0,
  112719. _vq_quantmap__8c1_s_p4_0,
  112720. 9,
  112721. 9
  112722. };
  112723. static static_codebook _8c1_s_p4_0 = {
  112724. 2, 81,
  112725. _vq_lengthlist__8c1_s_p4_0,
  112726. 1, -531628032, 1611661312, 4, 0,
  112727. _vq_quantlist__8c1_s_p4_0,
  112728. NULL,
  112729. &_vq_auxt__8c1_s_p4_0,
  112730. NULL,
  112731. 0
  112732. };
  112733. static long _vq_quantlist__8c1_s_p5_0[] = {
  112734. 4,
  112735. 3,
  112736. 5,
  112737. 2,
  112738. 6,
  112739. 1,
  112740. 7,
  112741. 0,
  112742. 8,
  112743. };
  112744. static long _vq_lengthlist__8c1_s_p5_0[] = {
  112745. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  112746. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  112747. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  112748. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  112749. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112750. 10,
  112751. };
  112752. static float _vq_quantthresh__8c1_s_p5_0[] = {
  112753. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112754. };
  112755. static long _vq_quantmap__8c1_s_p5_0[] = {
  112756. 7, 5, 3, 1, 0, 2, 4, 6,
  112757. 8,
  112758. };
  112759. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  112760. _vq_quantthresh__8c1_s_p5_0,
  112761. _vq_quantmap__8c1_s_p5_0,
  112762. 9,
  112763. 9
  112764. };
  112765. static static_codebook _8c1_s_p5_0 = {
  112766. 2, 81,
  112767. _vq_lengthlist__8c1_s_p5_0,
  112768. 1, -531628032, 1611661312, 4, 0,
  112769. _vq_quantlist__8c1_s_p5_0,
  112770. NULL,
  112771. &_vq_auxt__8c1_s_p5_0,
  112772. NULL,
  112773. 0
  112774. };
  112775. static long _vq_quantlist__8c1_s_p6_0[] = {
  112776. 8,
  112777. 7,
  112778. 9,
  112779. 6,
  112780. 10,
  112781. 5,
  112782. 11,
  112783. 4,
  112784. 12,
  112785. 3,
  112786. 13,
  112787. 2,
  112788. 14,
  112789. 1,
  112790. 15,
  112791. 0,
  112792. 16,
  112793. };
  112794. static long _vq_lengthlist__8c1_s_p6_0[] = {
  112795. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  112796. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112797. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  112798. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  112799. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  112800. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  112801. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  112802. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  112803. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  112804. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112805. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  112806. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  112807. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  112808. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  112809. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  112810. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  112811. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  112812. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  112813. 14,
  112814. };
  112815. static float _vq_quantthresh__8c1_s_p6_0[] = {
  112816. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112817. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112818. };
  112819. static long _vq_quantmap__8c1_s_p6_0[] = {
  112820. 15, 13, 11, 9, 7, 5, 3, 1,
  112821. 0, 2, 4, 6, 8, 10, 12, 14,
  112822. 16,
  112823. };
  112824. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  112825. _vq_quantthresh__8c1_s_p6_0,
  112826. _vq_quantmap__8c1_s_p6_0,
  112827. 17,
  112828. 17
  112829. };
  112830. static static_codebook _8c1_s_p6_0 = {
  112831. 2, 289,
  112832. _vq_lengthlist__8c1_s_p6_0,
  112833. 1, -529530880, 1611661312, 5, 0,
  112834. _vq_quantlist__8c1_s_p6_0,
  112835. NULL,
  112836. &_vq_auxt__8c1_s_p6_0,
  112837. NULL,
  112838. 0
  112839. };
  112840. static long _vq_quantlist__8c1_s_p7_0[] = {
  112841. 1,
  112842. 0,
  112843. 2,
  112844. };
  112845. static long _vq_lengthlist__8c1_s_p7_0[] = {
  112846. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  112847. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  112848. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  112849. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  112850. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  112851. 9,
  112852. };
  112853. static float _vq_quantthresh__8c1_s_p7_0[] = {
  112854. -5.5, 5.5,
  112855. };
  112856. static long _vq_quantmap__8c1_s_p7_0[] = {
  112857. 1, 0, 2,
  112858. };
  112859. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  112860. _vq_quantthresh__8c1_s_p7_0,
  112861. _vq_quantmap__8c1_s_p7_0,
  112862. 3,
  112863. 3
  112864. };
  112865. static static_codebook _8c1_s_p7_0 = {
  112866. 4, 81,
  112867. _vq_lengthlist__8c1_s_p7_0,
  112868. 1, -529137664, 1618345984, 2, 0,
  112869. _vq_quantlist__8c1_s_p7_0,
  112870. NULL,
  112871. &_vq_auxt__8c1_s_p7_0,
  112872. NULL,
  112873. 0
  112874. };
  112875. static long _vq_quantlist__8c1_s_p7_1[] = {
  112876. 5,
  112877. 4,
  112878. 6,
  112879. 3,
  112880. 7,
  112881. 2,
  112882. 8,
  112883. 1,
  112884. 9,
  112885. 0,
  112886. 10,
  112887. };
  112888. static long _vq_lengthlist__8c1_s_p7_1[] = {
  112889. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  112890. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  112891. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  112892. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  112893. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  112894. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  112895. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  112896. 10,10,10, 8, 8, 8, 8, 8, 8,
  112897. };
  112898. static float _vq_quantthresh__8c1_s_p7_1[] = {
  112899. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112900. 3.5, 4.5,
  112901. };
  112902. static long _vq_quantmap__8c1_s_p7_1[] = {
  112903. 9, 7, 5, 3, 1, 0, 2, 4,
  112904. 6, 8, 10,
  112905. };
  112906. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  112907. _vq_quantthresh__8c1_s_p7_1,
  112908. _vq_quantmap__8c1_s_p7_1,
  112909. 11,
  112910. 11
  112911. };
  112912. static static_codebook _8c1_s_p7_1 = {
  112913. 2, 121,
  112914. _vq_lengthlist__8c1_s_p7_1,
  112915. 1, -531365888, 1611661312, 4, 0,
  112916. _vq_quantlist__8c1_s_p7_1,
  112917. NULL,
  112918. &_vq_auxt__8c1_s_p7_1,
  112919. NULL,
  112920. 0
  112921. };
  112922. static long _vq_quantlist__8c1_s_p8_0[] = {
  112923. 6,
  112924. 5,
  112925. 7,
  112926. 4,
  112927. 8,
  112928. 3,
  112929. 9,
  112930. 2,
  112931. 10,
  112932. 1,
  112933. 11,
  112934. 0,
  112935. 12,
  112936. };
  112937. static long _vq_lengthlist__8c1_s_p8_0[] = {
  112938. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  112939. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  112940. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  112941. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  112942. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  112943. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  112944. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  112945. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  112946. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  112947. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  112948. 0,12,12,11,10,12,11,13,12,
  112949. };
  112950. static float _vq_quantthresh__8c1_s_p8_0[] = {
  112951. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112952. 12.5, 17.5, 22.5, 27.5,
  112953. };
  112954. static long _vq_quantmap__8c1_s_p8_0[] = {
  112955. 11, 9, 7, 5, 3, 1, 0, 2,
  112956. 4, 6, 8, 10, 12,
  112957. };
  112958. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  112959. _vq_quantthresh__8c1_s_p8_0,
  112960. _vq_quantmap__8c1_s_p8_0,
  112961. 13,
  112962. 13
  112963. };
  112964. static static_codebook _8c1_s_p8_0 = {
  112965. 2, 169,
  112966. _vq_lengthlist__8c1_s_p8_0,
  112967. 1, -526516224, 1616117760, 4, 0,
  112968. _vq_quantlist__8c1_s_p8_0,
  112969. NULL,
  112970. &_vq_auxt__8c1_s_p8_0,
  112971. NULL,
  112972. 0
  112973. };
  112974. static long _vq_quantlist__8c1_s_p8_1[] = {
  112975. 2,
  112976. 1,
  112977. 3,
  112978. 0,
  112979. 4,
  112980. };
  112981. static long _vq_lengthlist__8c1_s_p8_1[] = {
  112982. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  112983. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  112984. };
  112985. static float _vq_quantthresh__8c1_s_p8_1[] = {
  112986. -1.5, -0.5, 0.5, 1.5,
  112987. };
  112988. static long _vq_quantmap__8c1_s_p8_1[] = {
  112989. 3, 1, 0, 2, 4,
  112990. };
  112991. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  112992. _vq_quantthresh__8c1_s_p8_1,
  112993. _vq_quantmap__8c1_s_p8_1,
  112994. 5,
  112995. 5
  112996. };
  112997. static static_codebook _8c1_s_p8_1 = {
  112998. 2, 25,
  112999. _vq_lengthlist__8c1_s_p8_1,
  113000. 1, -533725184, 1611661312, 3, 0,
  113001. _vq_quantlist__8c1_s_p8_1,
  113002. NULL,
  113003. &_vq_auxt__8c1_s_p8_1,
  113004. NULL,
  113005. 0
  113006. };
  113007. static long _vq_quantlist__8c1_s_p9_0[] = {
  113008. 6,
  113009. 5,
  113010. 7,
  113011. 4,
  113012. 8,
  113013. 3,
  113014. 9,
  113015. 2,
  113016. 10,
  113017. 1,
  113018. 11,
  113019. 0,
  113020. 12,
  113021. };
  113022. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113023. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113024. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113025. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113026. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113027. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113028. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113029. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113030. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113031. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113032. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113033. 10,10,10,10,10, 9, 9, 9, 9,
  113034. };
  113035. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113036. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113037. 787.5, 1102.5, 1417.5, 1732.5,
  113038. };
  113039. static long _vq_quantmap__8c1_s_p9_0[] = {
  113040. 11, 9, 7, 5, 3, 1, 0, 2,
  113041. 4, 6, 8, 10, 12,
  113042. };
  113043. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113044. _vq_quantthresh__8c1_s_p9_0,
  113045. _vq_quantmap__8c1_s_p9_0,
  113046. 13,
  113047. 13
  113048. };
  113049. static static_codebook _8c1_s_p9_0 = {
  113050. 2, 169,
  113051. _vq_lengthlist__8c1_s_p9_0,
  113052. 1, -513964032, 1628680192, 4, 0,
  113053. _vq_quantlist__8c1_s_p9_0,
  113054. NULL,
  113055. &_vq_auxt__8c1_s_p9_0,
  113056. NULL,
  113057. 0
  113058. };
  113059. static long _vq_quantlist__8c1_s_p9_1[] = {
  113060. 7,
  113061. 6,
  113062. 8,
  113063. 5,
  113064. 9,
  113065. 4,
  113066. 10,
  113067. 3,
  113068. 11,
  113069. 2,
  113070. 12,
  113071. 1,
  113072. 13,
  113073. 0,
  113074. 14,
  113075. };
  113076. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113077. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113078. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113079. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113080. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113081. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113082. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113083. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113084. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113085. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113086. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113087. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113088. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113089. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113090. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113091. 15,
  113092. };
  113093. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113094. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113095. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113096. };
  113097. static long _vq_quantmap__8c1_s_p9_1[] = {
  113098. 13, 11, 9, 7, 5, 3, 1, 0,
  113099. 2, 4, 6, 8, 10, 12, 14,
  113100. };
  113101. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113102. _vq_quantthresh__8c1_s_p9_1,
  113103. _vq_quantmap__8c1_s_p9_1,
  113104. 15,
  113105. 15
  113106. };
  113107. static static_codebook _8c1_s_p9_1 = {
  113108. 2, 225,
  113109. _vq_lengthlist__8c1_s_p9_1,
  113110. 1, -520986624, 1620377600, 4, 0,
  113111. _vq_quantlist__8c1_s_p9_1,
  113112. NULL,
  113113. &_vq_auxt__8c1_s_p9_1,
  113114. NULL,
  113115. 0
  113116. };
  113117. static long _vq_quantlist__8c1_s_p9_2[] = {
  113118. 10,
  113119. 9,
  113120. 11,
  113121. 8,
  113122. 12,
  113123. 7,
  113124. 13,
  113125. 6,
  113126. 14,
  113127. 5,
  113128. 15,
  113129. 4,
  113130. 16,
  113131. 3,
  113132. 17,
  113133. 2,
  113134. 18,
  113135. 1,
  113136. 19,
  113137. 0,
  113138. 20,
  113139. };
  113140. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113141. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113142. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113143. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113144. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113145. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113146. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113147. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113148. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113149. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113150. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113151. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113152. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113153. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113154. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113155. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113156. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113157. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113158. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113159. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113160. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113161. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113162. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113163. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113164. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113165. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113166. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113167. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113168. 10,10,10,10,10,10,10,10,10,
  113169. };
  113170. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113171. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113172. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113173. 6.5, 7.5, 8.5, 9.5,
  113174. };
  113175. static long _vq_quantmap__8c1_s_p9_2[] = {
  113176. 19, 17, 15, 13, 11, 9, 7, 5,
  113177. 3, 1, 0, 2, 4, 6, 8, 10,
  113178. 12, 14, 16, 18, 20,
  113179. };
  113180. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113181. _vq_quantthresh__8c1_s_p9_2,
  113182. _vq_quantmap__8c1_s_p9_2,
  113183. 21,
  113184. 21
  113185. };
  113186. static static_codebook _8c1_s_p9_2 = {
  113187. 2, 441,
  113188. _vq_lengthlist__8c1_s_p9_2,
  113189. 1, -529268736, 1611661312, 5, 0,
  113190. _vq_quantlist__8c1_s_p9_2,
  113191. NULL,
  113192. &_vq_auxt__8c1_s_p9_2,
  113193. NULL,
  113194. 0
  113195. };
  113196. static long _huff_lengthlist__8c1_s_single[] = {
  113197. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113198. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113199. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113200. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113201. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113202. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113203. 9, 7, 7, 8,
  113204. };
  113205. static static_codebook _huff_book__8c1_s_single = {
  113206. 2, 100,
  113207. _huff_lengthlist__8c1_s_single,
  113208. 0, 0, 0, 0, 0,
  113209. NULL,
  113210. NULL,
  113211. NULL,
  113212. NULL,
  113213. 0
  113214. };
  113215. static long _huff_lengthlist__44c2_s_long[] = {
  113216. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113217. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113218. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113219. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113220. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113221. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113222. 10, 8, 8, 9,
  113223. };
  113224. static static_codebook _huff_book__44c2_s_long = {
  113225. 2, 100,
  113226. _huff_lengthlist__44c2_s_long,
  113227. 0, 0, 0, 0, 0,
  113228. NULL,
  113229. NULL,
  113230. NULL,
  113231. NULL,
  113232. 0
  113233. };
  113234. static long _vq_quantlist__44c2_s_p1_0[] = {
  113235. 1,
  113236. 0,
  113237. 2,
  113238. };
  113239. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113240. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113241. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113245. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113246. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113250. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113251. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113286. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113291. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113296. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113331. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113332. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113336. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113337. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  113338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113341. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113342. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113650. 0,
  113651. };
  113652. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113653. -0.5, 0.5,
  113654. };
  113655. static long _vq_quantmap__44c2_s_p1_0[] = {
  113656. 1, 0, 2,
  113657. };
  113658. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113659. _vq_quantthresh__44c2_s_p1_0,
  113660. _vq_quantmap__44c2_s_p1_0,
  113661. 3,
  113662. 3
  113663. };
  113664. static static_codebook _44c2_s_p1_0 = {
  113665. 8, 6561,
  113666. _vq_lengthlist__44c2_s_p1_0,
  113667. 1, -535822336, 1611661312, 2, 0,
  113668. _vq_quantlist__44c2_s_p1_0,
  113669. NULL,
  113670. &_vq_auxt__44c2_s_p1_0,
  113671. NULL,
  113672. 0
  113673. };
  113674. static long _vq_quantlist__44c2_s_p2_0[] = {
  113675. 2,
  113676. 1,
  113677. 3,
  113678. 0,
  113679. 4,
  113680. };
  113681. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113682. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113683. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113684. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113685. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113686. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113691. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113692. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  113693. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  113694. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113699. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  113700. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  113701. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  113702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113707. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  113708. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  113709. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  113710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113721. 0,
  113722. };
  113723. static float _vq_quantthresh__44c2_s_p2_0[] = {
  113724. -1.5, -0.5, 0.5, 1.5,
  113725. };
  113726. static long _vq_quantmap__44c2_s_p2_0[] = {
  113727. 3, 1, 0, 2, 4,
  113728. };
  113729. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  113730. _vq_quantthresh__44c2_s_p2_0,
  113731. _vq_quantmap__44c2_s_p2_0,
  113732. 5,
  113733. 5
  113734. };
  113735. static static_codebook _44c2_s_p2_0 = {
  113736. 4, 625,
  113737. _vq_lengthlist__44c2_s_p2_0,
  113738. 1, -533725184, 1611661312, 3, 0,
  113739. _vq_quantlist__44c2_s_p2_0,
  113740. NULL,
  113741. &_vq_auxt__44c2_s_p2_0,
  113742. NULL,
  113743. 0
  113744. };
  113745. static long _vq_quantlist__44c2_s_p3_0[] = {
  113746. 2,
  113747. 1,
  113748. 3,
  113749. 0,
  113750. 4,
  113751. };
  113752. static long _vq_lengthlist__44c2_s_p3_0[] = {
  113753. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113756. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  113758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113759. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113792. 0,
  113793. };
  113794. static float _vq_quantthresh__44c2_s_p3_0[] = {
  113795. -1.5, -0.5, 0.5, 1.5,
  113796. };
  113797. static long _vq_quantmap__44c2_s_p3_0[] = {
  113798. 3, 1, 0, 2, 4,
  113799. };
  113800. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  113801. _vq_quantthresh__44c2_s_p3_0,
  113802. _vq_quantmap__44c2_s_p3_0,
  113803. 5,
  113804. 5
  113805. };
  113806. static static_codebook _44c2_s_p3_0 = {
  113807. 4, 625,
  113808. _vq_lengthlist__44c2_s_p3_0,
  113809. 1, -533725184, 1611661312, 3, 0,
  113810. _vq_quantlist__44c2_s_p3_0,
  113811. NULL,
  113812. &_vq_auxt__44c2_s_p3_0,
  113813. NULL,
  113814. 0
  113815. };
  113816. static long _vq_quantlist__44c2_s_p4_0[] = {
  113817. 4,
  113818. 3,
  113819. 5,
  113820. 2,
  113821. 6,
  113822. 1,
  113823. 7,
  113824. 0,
  113825. 8,
  113826. };
  113827. static long _vq_lengthlist__44c2_s_p4_0[] = {
  113828. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  113829. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  113830. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  113831. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  113832. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113833. 0,
  113834. };
  113835. static float _vq_quantthresh__44c2_s_p4_0[] = {
  113836. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113837. };
  113838. static long _vq_quantmap__44c2_s_p4_0[] = {
  113839. 7, 5, 3, 1, 0, 2, 4, 6,
  113840. 8,
  113841. };
  113842. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  113843. _vq_quantthresh__44c2_s_p4_0,
  113844. _vq_quantmap__44c2_s_p4_0,
  113845. 9,
  113846. 9
  113847. };
  113848. static static_codebook _44c2_s_p4_0 = {
  113849. 2, 81,
  113850. _vq_lengthlist__44c2_s_p4_0,
  113851. 1, -531628032, 1611661312, 4, 0,
  113852. _vq_quantlist__44c2_s_p4_0,
  113853. NULL,
  113854. &_vq_auxt__44c2_s_p4_0,
  113855. NULL,
  113856. 0
  113857. };
  113858. static long _vq_quantlist__44c2_s_p5_0[] = {
  113859. 4,
  113860. 3,
  113861. 5,
  113862. 2,
  113863. 6,
  113864. 1,
  113865. 7,
  113866. 0,
  113867. 8,
  113868. };
  113869. static long _vq_lengthlist__44c2_s_p5_0[] = {
  113870. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  113871. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  113872. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  113873. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  113874. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  113875. 11,
  113876. };
  113877. static float _vq_quantthresh__44c2_s_p5_0[] = {
  113878. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113879. };
  113880. static long _vq_quantmap__44c2_s_p5_0[] = {
  113881. 7, 5, 3, 1, 0, 2, 4, 6,
  113882. 8,
  113883. };
  113884. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  113885. _vq_quantthresh__44c2_s_p5_0,
  113886. _vq_quantmap__44c2_s_p5_0,
  113887. 9,
  113888. 9
  113889. };
  113890. static static_codebook _44c2_s_p5_0 = {
  113891. 2, 81,
  113892. _vq_lengthlist__44c2_s_p5_0,
  113893. 1, -531628032, 1611661312, 4, 0,
  113894. _vq_quantlist__44c2_s_p5_0,
  113895. NULL,
  113896. &_vq_auxt__44c2_s_p5_0,
  113897. NULL,
  113898. 0
  113899. };
  113900. static long _vq_quantlist__44c2_s_p6_0[] = {
  113901. 8,
  113902. 7,
  113903. 9,
  113904. 6,
  113905. 10,
  113906. 5,
  113907. 11,
  113908. 4,
  113909. 12,
  113910. 3,
  113911. 13,
  113912. 2,
  113913. 14,
  113914. 1,
  113915. 15,
  113916. 0,
  113917. 16,
  113918. };
  113919. static long _vq_lengthlist__44c2_s_p6_0[] = {
  113920. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  113921. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113922. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  113923. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  113924. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  113925. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  113926. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  113927. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  113928. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  113929. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113930. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113931. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  113932. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113933. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113934. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113935. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  113936. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113937. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113938. 14,
  113939. };
  113940. static float _vq_quantthresh__44c2_s_p6_0[] = {
  113941. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113942. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113943. };
  113944. static long _vq_quantmap__44c2_s_p6_0[] = {
  113945. 15, 13, 11, 9, 7, 5, 3, 1,
  113946. 0, 2, 4, 6, 8, 10, 12, 14,
  113947. 16,
  113948. };
  113949. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  113950. _vq_quantthresh__44c2_s_p6_0,
  113951. _vq_quantmap__44c2_s_p6_0,
  113952. 17,
  113953. 17
  113954. };
  113955. static static_codebook _44c2_s_p6_0 = {
  113956. 2, 289,
  113957. _vq_lengthlist__44c2_s_p6_0,
  113958. 1, -529530880, 1611661312, 5, 0,
  113959. _vq_quantlist__44c2_s_p6_0,
  113960. NULL,
  113961. &_vq_auxt__44c2_s_p6_0,
  113962. NULL,
  113963. 0
  113964. };
  113965. static long _vq_quantlist__44c2_s_p7_0[] = {
  113966. 1,
  113967. 0,
  113968. 2,
  113969. };
  113970. static long _vq_lengthlist__44c2_s_p7_0[] = {
  113971. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  113972. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  113973. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  113974. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  113975. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  113976. 11,
  113977. };
  113978. static float _vq_quantthresh__44c2_s_p7_0[] = {
  113979. -5.5, 5.5,
  113980. };
  113981. static long _vq_quantmap__44c2_s_p7_0[] = {
  113982. 1, 0, 2,
  113983. };
  113984. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  113985. _vq_quantthresh__44c2_s_p7_0,
  113986. _vq_quantmap__44c2_s_p7_0,
  113987. 3,
  113988. 3
  113989. };
  113990. static static_codebook _44c2_s_p7_0 = {
  113991. 4, 81,
  113992. _vq_lengthlist__44c2_s_p7_0,
  113993. 1, -529137664, 1618345984, 2, 0,
  113994. _vq_quantlist__44c2_s_p7_0,
  113995. NULL,
  113996. &_vq_auxt__44c2_s_p7_0,
  113997. NULL,
  113998. 0
  113999. };
  114000. static long _vq_quantlist__44c2_s_p7_1[] = {
  114001. 5,
  114002. 4,
  114003. 6,
  114004. 3,
  114005. 7,
  114006. 2,
  114007. 8,
  114008. 1,
  114009. 9,
  114010. 0,
  114011. 10,
  114012. };
  114013. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114014. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114015. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114016. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114017. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114018. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114019. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114020. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114021. 10,10,10, 8, 8, 8, 8, 8, 8,
  114022. };
  114023. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114024. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114025. 3.5, 4.5,
  114026. };
  114027. static long _vq_quantmap__44c2_s_p7_1[] = {
  114028. 9, 7, 5, 3, 1, 0, 2, 4,
  114029. 6, 8, 10,
  114030. };
  114031. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114032. _vq_quantthresh__44c2_s_p7_1,
  114033. _vq_quantmap__44c2_s_p7_1,
  114034. 11,
  114035. 11
  114036. };
  114037. static static_codebook _44c2_s_p7_1 = {
  114038. 2, 121,
  114039. _vq_lengthlist__44c2_s_p7_1,
  114040. 1, -531365888, 1611661312, 4, 0,
  114041. _vq_quantlist__44c2_s_p7_1,
  114042. NULL,
  114043. &_vq_auxt__44c2_s_p7_1,
  114044. NULL,
  114045. 0
  114046. };
  114047. static long _vq_quantlist__44c2_s_p8_0[] = {
  114048. 6,
  114049. 5,
  114050. 7,
  114051. 4,
  114052. 8,
  114053. 3,
  114054. 9,
  114055. 2,
  114056. 10,
  114057. 1,
  114058. 11,
  114059. 0,
  114060. 12,
  114061. };
  114062. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114063. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114064. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114065. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114066. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114067. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114068. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114069. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114070. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114071. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114072. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114073. 0,12,12,12,12,13,12,14,14,
  114074. };
  114075. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114076. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114077. 12.5, 17.5, 22.5, 27.5,
  114078. };
  114079. static long _vq_quantmap__44c2_s_p8_0[] = {
  114080. 11, 9, 7, 5, 3, 1, 0, 2,
  114081. 4, 6, 8, 10, 12,
  114082. };
  114083. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114084. _vq_quantthresh__44c2_s_p8_0,
  114085. _vq_quantmap__44c2_s_p8_0,
  114086. 13,
  114087. 13
  114088. };
  114089. static static_codebook _44c2_s_p8_0 = {
  114090. 2, 169,
  114091. _vq_lengthlist__44c2_s_p8_0,
  114092. 1, -526516224, 1616117760, 4, 0,
  114093. _vq_quantlist__44c2_s_p8_0,
  114094. NULL,
  114095. &_vq_auxt__44c2_s_p8_0,
  114096. NULL,
  114097. 0
  114098. };
  114099. static long _vq_quantlist__44c2_s_p8_1[] = {
  114100. 2,
  114101. 1,
  114102. 3,
  114103. 0,
  114104. 4,
  114105. };
  114106. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114107. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114108. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114109. };
  114110. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114111. -1.5, -0.5, 0.5, 1.5,
  114112. };
  114113. static long _vq_quantmap__44c2_s_p8_1[] = {
  114114. 3, 1, 0, 2, 4,
  114115. };
  114116. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114117. _vq_quantthresh__44c2_s_p8_1,
  114118. _vq_quantmap__44c2_s_p8_1,
  114119. 5,
  114120. 5
  114121. };
  114122. static static_codebook _44c2_s_p8_1 = {
  114123. 2, 25,
  114124. _vq_lengthlist__44c2_s_p8_1,
  114125. 1, -533725184, 1611661312, 3, 0,
  114126. _vq_quantlist__44c2_s_p8_1,
  114127. NULL,
  114128. &_vq_auxt__44c2_s_p8_1,
  114129. NULL,
  114130. 0
  114131. };
  114132. static long _vq_quantlist__44c2_s_p9_0[] = {
  114133. 6,
  114134. 5,
  114135. 7,
  114136. 4,
  114137. 8,
  114138. 3,
  114139. 9,
  114140. 2,
  114141. 10,
  114142. 1,
  114143. 11,
  114144. 0,
  114145. 12,
  114146. };
  114147. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114148. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114149. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114150. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114151. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114152. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114153. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114154. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114155. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114156. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114157. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114158. 11,11,11,11,11,11,11,11,11,
  114159. };
  114160. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114161. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114162. 552.5, 773.5, 994.5, 1215.5,
  114163. };
  114164. static long _vq_quantmap__44c2_s_p9_0[] = {
  114165. 11, 9, 7, 5, 3, 1, 0, 2,
  114166. 4, 6, 8, 10, 12,
  114167. };
  114168. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114169. _vq_quantthresh__44c2_s_p9_0,
  114170. _vq_quantmap__44c2_s_p9_0,
  114171. 13,
  114172. 13
  114173. };
  114174. static static_codebook _44c2_s_p9_0 = {
  114175. 2, 169,
  114176. _vq_lengthlist__44c2_s_p9_0,
  114177. 1, -514541568, 1627103232, 4, 0,
  114178. _vq_quantlist__44c2_s_p9_0,
  114179. NULL,
  114180. &_vq_auxt__44c2_s_p9_0,
  114181. NULL,
  114182. 0
  114183. };
  114184. static long _vq_quantlist__44c2_s_p9_1[] = {
  114185. 6,
  114186. 5,
  114187. 7,
  114188. 4,
  114189. 8,
  114190. 3,
  114191. 9,
  114192. 2,
  114193. 10,
  114194. 1,
  114195. 11,
  114196. 0,
  114197. 12,
  114198. };
  114199. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114200. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114201. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114202. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114203. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114204. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114205. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114206. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114207. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114208. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114209. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114210. 17,13,12,12,10,13,11,14,14,
  114211. };
  114212. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114213. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114214. 42.5, 59.5, 76.5, 93.5,
  114215. };
  114216. static long _vq_quantmap__44c2_s_p9_1[] = {
  114217. 11, 9, 7, 5, 3, 1, 0, 2,
  114218. 4, 6, 8, 10, 12,
  114219. };
  114220. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114221. _vq_quantthresh__44c2_s_p9_1,
  114222. _vq_quantmap__44c2_s_p9_1,
  114223. 13,
  114224. 13
  114225. };
  114226. static static_codebook _44c2_s_p9_1 = {
  114227. 2, 169,
  114228. _vq_lengthlist__44c2_s_p9_1,
  114229. 1, -522616832, 1620115456, 4, 0,
  114230. _vq_quantlist__44c2_s_p9_1,
  114231. NULL,
  114232. &_vq_auxt__44c2_s_p9_1,
  114233. NULL,
  114234. 0
  114235. };
  114236. static long _vq_quantlist__44c2_s_p9_2[] = {
  114237. 8,
  114238. 7,
  114239. 9,
  114240. 6,
  114241. 10,
  114242. 5,
  114243. 11,
  114244. 4,
  114245. 12,
  114246. 3,
  114247. 13,
  114248. 2,
  114249. 14,
  114250. 1,
  114251. 15,
  114252. 0,
  114253. 16,
  114254. };
  114255. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114256. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114257. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114258. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114259. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114260. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114261. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114262. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114263. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114264. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114265. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114266. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114267. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114268. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114269. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114270. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114271. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114272. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114273. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114274. 10,
  114275. };
  114276. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114277. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114278. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114279. };
  114280. static long _vq_quantmap__44c2_s_p9_2[] = {
  114281. 15, 13, 11, 9, 7, 5, 3, 1,
  114282. 0, 2, 4, 6, 8, 10, 12, 14,
  114283. 16,
  114284. };
  114285. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114286. _vq_quantthresh__44c2_s_p9_2,
  114287. _vq_quantmap__44c2_s_p9_2,
  114288. 17,
  114289. 17
  114290. };
  114291. static static_codebook _44c2_s_p9_2 = {
  114292. 2, 289,
  114293. _vq_lengthlist__44c2_s_p9_2,
  114294. 1, -529530880, 1611661312, 5, 0,
  114295. _vq_quantlist__44c2_s_p9_2,
  114296. NULL,
  114297. &_vq_auxt__44c2_s_p9_2,
  114298. NULL,
  114299. 0
  114300. };
  114301. static long _huff_lengthlist__44c2_s_short[] = {
  114302. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114303. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114304. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114305. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114306. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114307. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114308. 6, 8, 9,12,
  114309. };
  114310. static static_codebook _huff_book__44c2_s_short = {
  114311. 2, 100,
  114312. _huff_lengthlist__44c2_s_short,
  114313. 0, 0, 0, 0, 0,
  114314. NULL,
  114315. NULL,
  114316. NULL,
  114317. NULL,
  114318. 0
  114319. };
  114320. static long _huff_lengthlist__44c3_s_long[] = {
  114321. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114322. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114323. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114324. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114325. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114326. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114327. 9, 8, 8, 8,
  114328. };
  114329. static static_codebook _huff_book__44c3_s_long = {
  114330. 2, 100,
  114331. _huff_lengthlist__44c3_s_long,
  114332. 0, 0, 0, 0, 0,
  114333. NULL,
  114334. NULL,
  114335. NULL,
  114336. NULL,
  114337. 0
  114338. };
  114339. static long _vq_quantlist__44c3_s_p1_0[] = {
  114340. 1,
  114341. 0,
  114342. 2,
  114343. };
  114344. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114345. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114346. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114350. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114351. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114355. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114356. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114391. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114396. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  114401. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114436. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114437. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114441. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114442. 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  114443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114446. 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114447. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  114448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114755. 0,
  114756. };
  114757. static float _vq_quantthresh__44c3_s_p1_0[] = {
  114758. -0.5, 0.5,
  114759. };
  114760. static long _vq_quantmap__44c3_s_p1_0[] = {
  114761. 1, 0, 2,
  114762. };
  114763. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  114764. _vq_quantthresh__44c3_s_p1_0,
  114765. _vq_quantmap__44c3_s_p1_0,
  114766. 3,
  114767. 3
  114768. };
  114769. static static_codebook _44c3_s_p1_0 = {
  114770. 8, 6561,
  114771. _vq_lengthlist__44c3_s_p1_0,
  114772. 1, -535822336, 1611661312, 2, 0,
  114773. _vq_quantlist__44c3_s_p1_0,
  114774. NULL,
  114775. &_vq_auxt__44c3_s_p1_0,
  114776. NULL,
  114777. 0
  114778. };
  114779. static long _vq_quantlist__44c3_s_p2_0[] = {
  114780. 2,
  114781. 1,
  114782. 3,
  114783. 0,
  114784. 4,
  114785. };
  114786. static long _vq_lengthlist__44c3_s_p2_0[] = {
  114787. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  114788. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  114789. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  114790. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  114791. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114796. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  114797. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  114798. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  114799. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114804. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  114805. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  114806. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  114807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114812. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  114813. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  114814. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  114815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114826. 0,
  114827. };
  114828. static float _vq_quantthresh__44c3_s_p2_0[] = {
  114829. -1.5, -0.5, 0.5, 1.5,
  114830. };
  114831. static long _vq_quantmap__44c3_s_p2_0[] = {
  114832. 3, 1, 0, 2, 4,
  114833. };
  114834. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  114835. _vq_quantthresh__44c3_s_p2_0,
  114836. _vq_quantmap__44c3_s_p2_0,
  114837. 5,
  114838. 5
  114839. };
  114840. static static_codebook _44c3_s_p2_0 = {
  114841. 4, 625,
  114842. _vq_lengthlist__44c3_s_p2_0,
  114843. 1, -533725184, 1611661312, 3, 0,
  114844. _vq_quantlist__44c3_s_p2_0,
  114845. NULL,
  114846. &_vq_auxt__44c3_s_p2_0,
  114847. NULL,
  114848. 0
  114849. };
  114850. static long _vq_quantlist__44c3_s_p3_0[] = {
  114851. 2,
  114852. 1,
  114853. 3,
  114854. 0,
  114855. 4,
  114856. };
  114857. static long _vq_lengthlist__44c3_s_p3_0[] = {
  114858. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114861. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114864. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114897. 0,
  114898. };
  114899. static float _vq_quantthresh__44c3_s_p3_0[] = {
  114900. -1.5, -0.5, 0.5, 1.5,
  114901. };
  114902. static long _vq_quantmap__44c3_s_p3_0[] = {
  114903. 3, 1, 0, 2, 4,
  114904. };
  114905. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  114906. _vq_quantthresh__44c3_s_p3_0,
  114907. _vq_quantmap__44c3_s_p3_0,
  114908. 5,
  114909. 5
  114910. };
  114911. static static_codebook _44c3_s_p3_0 = {
  114912. 4, 625,
  114913. _vq_lengthlist__44c3_s_p3_0,
  114914. 1, -533725184, 1611661312, 3, 0,
  114915. _vq_quantlist__44c3_s_p3_0,
  114916. NULL,
  114917. &_vq_auxt__44c3_s_p3_0,
  114918. NULL,
  114919. 0
  114920. };
  114921. static long _vq_quantlist__44c3_s_p4_0[] = {
  114922. 4,
  114923. 3,
  114924. 5,
  114925. 2,
  114926. 6,
  114927. 1,
  114928. 7,
  114929. 0,
  114930. 8,
  114931. };
  114932. static long _vq_lengthlist__44c3_s_p4_0[] = {
  114933. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  114934. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  114935. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  114936. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  114937. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114938. 0,
  114939. };
  114940. static float _vq_quantthresh__44c3_s_p4_0[] = {
  114941. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114942. };
  114943. static long _vq_quantmap__44c3_s_p4_0[] = {
  114944. 7, 5, 3, 1, 0, 2, 4, 6,
  114945. 8,
  114946. };
  114947. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  114948. _vq_quantthresh__44c3_s_p4_0,
  114949. _vq_quantmap__44c3_s_p4_0,
  114950. 9,
  114951. 9
  114952. };
  114953. static static_codebook _44c3_s_p4_0 = {
  114954. 2, 81,
  114955. _vq_lengthlist__44c3_s_p4_0,
  114956. 1, -531628032, 1611661312, 4, 0,
  114957. _vq_quantlist__44c3_s_p4_0,
  114958. NULL,
  114959. &_vq_auxt__44c3_s_p4_0,
  114960. NULL,
  114961. 0
  114962. };
  114963. static long _vq_quantlist__44c3_s_p5_0[] = {
  114964. 4,
  114965. 3,
  114966. 5,
  114967. 2,
  114968. 6,
  114969. 1,
  114970. 7,
  114971. 0,
  114972. 8,
  114973. };
  114974. static long _vq_lengthlist__44c3_s_p5_0[] = {
  114975. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  114976. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  114977. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  114978. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  114979. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  114980. 11,
  114981. };
  114982. static float _vq_quantthresh__44c3_s_p5_0[] = {
  114983. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114984. };
  114985. static long _vq_quantmap__44c3_s_p5_0[] = {
  114986. 7, 5, 3, 1, 0, 2, 4, 6,
  114987. 8,
  114988. };
  114989. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  114990. _vq_quantthresh__44c3_s_p5_0,
  114991. _vq_quantmap__44c3_s_p5_0,
  114992. 9,
  114993. 9
  114994. };
  114995. static static_codebook _44c3_s_p5_0 = {
  114996. 2, 81,
  114997. _vq_lengthlist__44c3_s_p5_0,
  114998. 1, -531628032, 1611661312, 4, 0,
  114999. _vq_quantlist__44c3_s_p5_0,
  115000. NULL,
  115001. &_vq_auxt__44c3_s_p5_0,
  115002. NULL,
  115003. 0
  115004. };
  115005. static long _vq_quantlist__44c3_s_p6_0[] = {
  115006. 8,
  115007. 7,
  115008. 9,
  115009. 6,
  115010. 10,
  115011. 5,
  115012. 11,
  115013. 4,
  115014. 12,
  115015. 3,
  115016. 13,
  115017. 2,
  115018. 14,
  115019. 1,
  115020. 15,
  115021. 0,
  115022. 16,
  115023. };
  115024. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115025. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115026. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115027. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115028. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115029. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115030. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115031. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115032. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115033. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115034. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115035. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115036. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115037. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115038. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115039. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115040. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115041. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115042. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115043. 13,
  115044. };
  115045. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115046. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115047. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115048. };
  115049. static long _vq_quantmap__44c3_s_p6_0[] = {
  115050. 15, 13, 11, 9, 7, 5, 3, 1,
  115051. 0, 2, 4, 6, 8, 10, 12, 14,
  115052. 16,
  115053. };
  115054. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115055. _vq_quantthresh__44c3_s_p6_0,
  115056. _vq_quantmap__44c3_s_p6_0,
  115057. 17,
  115058. 17
  115059. };
  115060. static static_codebook _44c3_s_p6_0 = {
  115061. 2, 289,
  115062. _vq_lengthlist__44c3_s_p6_0,
  115063. 1, -529530880, 1611661312, 5, 0,
  115064. _vq_quantlist__44c3_s_p6_0,
  115065. NULL,
  115066. &_vq_auxt__44c3_s_p6_0,
  115067. NULL,
  115068. 0
  115069. };
  115070. static long _vq_quantlist__44c3_s_p7_0[] = {
  115071. 1,
  115072. 0,
  115073. 2,
  115074. };
  115075. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115076. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115077. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115078. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115079. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115080. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115081. 10,
  115082. };
  115083. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115084. -5.5, 5.5,
  115085. };
  115086. static long _vq_quantmap__44c3_s_p7_0[] = {
  115087. 1, 0, 2,
  115088. };
  115089. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115090. _vq_quantthresh__44c3_s_p7_0,
  115091. _vq_quantmap__44c3_s_p7_0,
  115092. 3,
  115093. 3
  115094. };
  115095. static static_codebook _44c3_s_p7_0 = {
  115096. 4, 81,
  115097. _vq_lengthlist__44c3_s_p7_0,
  115098. 1, -529137664, 1618345984, 2, 0,
  115099. _vq_quantlist__44c3_s_p7_0,
  115100. NULL,
  115101. &_vq_auxt__44c3_s_p7_0,
  115102. NULL,
  115103. 0
  115104. };
  115105. static long _vq_quantlist__44c3_s_p7_1[] = {
  115106. 5,
  115107. 4,
  115108. 6,
  115109. 3,
  115110. 7,
  115111. 2,
  115112. 8,
  115113. 1,
  115114. 9,
  115115. 0,
  115116. 10,
  115117. };
  115118. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115119. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115120. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115121. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115122. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115123. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115124. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115125. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115126. 10,10,10, 8, 8, 8, 8, 8, 8,
  115127. };
  115128. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115129. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115130. 3.5, 4.5,
  115131. };
  115132. static long _vq_quantmap__44c3_s_p7_1[] = {
  115133. 9, 7, 5, 3, 1, 0, 2, 4,
  115134. 6, 8, 10,
  115135. };
  115136. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115137. _vq_quantthresh__44c3_s_p7_1,
  115138. _vq_quantmap__44c3_s_p7_1,
  115139. 11,
  115140. 11
  115141. };
  115142. static static_codebook _44c3_s_p7_1 = {
  115143. 2, 121,
  115144. _vq_lengthlist__44c3_s_p7_1,
  115145. 1, -531365888, 1611661312, 4, 0,
  115146. _vq_quantlist__44c3_s_p7_1,
  115147. NULL,
  115148. &_vq_auxt__44c3_s_p7_1,
  115149. NULL,
  115150. 0
  115151. };
  115152. static long _vq_quantlist__44c3_s_p8_0[] = {
  115153. 6,
  115154. 5,
  115155. 7,
  115156. 4,
  115157. 8,
  115158. 3,
  115159. 9,
  115160. 2,
  115161. 10,
  115162. 1,
  115163. 11,
  115164. 0,
  115165. 12,
  115166. };
  115167. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115168. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115169. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115170. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115171. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115172. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115173. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115174. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115175. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115176. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115177. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115178. 0,13,13,12,12,13,12,14,13,
  115179. };
  115180. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115181. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115182. 12.5, 17.5, 22.5, 27.5,
  115183. };
  115184. static long _vq_quantmap__44c3_s_p8_0[] = {
  115185. 11, 9, 7, 5, 3, 1, 0, 2,
  115186. 4, 6, 8, 10, 12,
  115187. };
  115188. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115189. _vq_quantthresh__44c3_s_p8_0,
  115190. _vq_quantmap__44c3_s_p8_0,
  115191. 13,
  115192. 13
  115193. };
  115194. static static_codebook _44c3_s_p8_0 = {
  115195. 2, 169,
  115196. _vq_lengthlist__44c3_s_p8_0,
  115197. 1, -526516224, 1616117760, 4, 0,
  115198. _vq_quantlist__44c3_s_p8_0,
  115199. NULL,
  115200. &_vq_auxt__44c3_s_p8_0,
  115201. NULL,
  115202. 0
  115203. };
  115204. static long _vq_quantlist__44c3_s_p8_1[] = {
  115205. 2,
  115206. 1,
  115207. 3,
  115208. 0,
  115209. 4,
  115210. };
  115211. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115212. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115213. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115214. };
  115215. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115216. -1.5, -0.5, 0.5, 1.5,
  115217. };
  115218. static long _vq_quantmap__44c3_s_p8_1[] = {
  115219. 3, 1, 0, 2, 4,
  115220. };
  115221. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115222. _vq_quantthresh__44c3_s_p8_1,
  115223. _vq_quantmap__44c3_s_p8_1,
  115224. 5,
  115225. 5
  115226. };
  115227. static static_codebook _44c3_s_p8_1 = {
  115228. 2, 25,
  115229. _vq_lengthlist__44c3_s_p8_1,
  115230. 1, -533725184, 1611661312, 3, 0,
  115231. _vq_quantlist__44c3_s_p8_1,
  115232. NULL,
  115233. &_vq_auxt__44c3_s_p8_1,
  115234. NULL,
  115235. 0
  115236. };
  115237. static long _vq_quantlist__44c3_s_p9_0[] = {
  115238. 6,
  115239. 5,
  115240. 7,
  115241. 4,
  115242. 8,
  115243. 3,
  115244. 9,
  115245. 2,
  115246. 10,
  115247. 1,
  115248. 11,
  115249. 0,
  115250. 12,
  115251. };
  115252. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115253. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115254. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115255. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115256. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115257. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115258. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115259. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115260. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115261. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115262. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115263. 11,11,11,11,11,11,11,11,11,
  115264. };
  115265. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115266. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115267. 637.5, 892.5, 1147.5, 1402.5,
  115268. };
  115269. static long _vq_quantmap__44c3_s_p9_0[] = {
  115270. 11, 9, 7, 5, 3, 1, 0, 2,
  115271. 4, 6, 8, 10, 12,
  115272. };
  115273. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115274. _vq_quantthresh__44c3_s_p9_0,
  115275. _vq_quantmap__44c3_s_p9_0,
  115276. 13,
  115277. 13
  115278. };
  115279. static static_codebook _44c3_s_p9_0 = {
  115280. 2, 169,
  115281. _vq_lengthlist__44c3_s_p9_0,
  115282. 1, -514332672, 1627381760, 4, 0,
  115283. _vq_quantlist__44c3_s_p9_0,
  115284. NULL,
  115285. &_vq_auxt__44c3_s_p9_0,
  115286. NULL,
  115287. 0
  115288. };
  115289. static long _vq_quantlist__44c3_s_p9_1[] = {
  115290. 7,
  115291. 6,
  115292. 8,
  115293. 5,
  115294. 9,
  115295. 4,
  115296. 10,
  115297. 3,
  115298. 11,
  115299. 2,
  115300. 12,
  115301. 1,
  115302. 13,
  115303. 0,
  115304. 14,
  115305. };
  115306. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115307. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115308. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115309. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115310. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115311. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115312. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115313. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115314. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115315. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115316. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115317. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115318. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115319. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115320. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115321. 15,
  115322. };
  115323. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115324. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115325. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115326. };
  115327. static long _vq_quantmap__44c3_s_p9_1[] = {
  115328. 13, 11, 9, 7, 5, 3, 1, 0,
  115329. 2, 4, 6, 8, 10, 12, 14,
  115330. };
  115331. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115332. _vq_quantthresh__44c3_s_p9_1,
  115333. _vq_quantmap__44c3_s_p9_1,
  115334. 15,
  115335. 15
  115336. };
  115337. static static_codebook _44c3_s_p9_1 = {
  115338. 2, 225,
  115339. _vq_lengthlist__44c3_s_p9_1,
  115340. 1, -522338304, 1620115456, 4, 0,
  115341. _vq_quantlist__44c3_s_p9_1,
  115342. NULL,
  115343. &_vq_auxt__44c3_s_p9_1,
  115344. NULL,
  115345. 0
  115346. };
  115347. static long _vq_quantlist__44c3_s_p9_2[] = {
  115348. 8,
  115349. 7,
  115350. 9,
  115351. 6,
  115352. 10,
  115353. 5,
  115354. 11,
  115355. 4,
  115356. 12,
  115357. 3,
  115358. 13,
  115359. 2,
  115360. 14,
  115361. 1,
  115362. 15,
  115363. 0,
  115364. 16,
  115365. };
  115366. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115367. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115368. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115369. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115370. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115371. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115372. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115373. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115374. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115375. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115376. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115377. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115378. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115379. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115380. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115381. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115382. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115383. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115384. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115385. 10,
  115386. };
  115387. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115388. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115389. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115390. };
  115391. static long _vq_quantmap__44c3_s_p9_2[] = {
  115392. 15, 13, 11, 9, 7, 5, 3, 1,
  115393. 0, 2, 4, 6, 8, 10, 12, 14,
  115394. 16,
  115395. };
  115396. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115397. _vq_quantthresh__44c3_s_p9_2,
  115398. _vq_quantmap__44c3_s_p9_2,
  115399. 17,
  115400. 17
  115401. };
  115402. static static_codebook _44c3_s_p9_2 = {
  115403. 2, 289,
  115404. _vq_lengthlist__44c3_s_p9_2,
  115405. 1, -529530880, 1611661312, 5, 0,
  115406. _vq_quantlist__44c3_s_p9_2,
  115407. NULL,
  115408. &_vq_auxt__44c3_s_p9_2,
  115409. NULL,
  115410. 0
  115411. };
  115412. static long _huff_lengthlist__44c3_s_short[] = {
  115413. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115414. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115415. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115416. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115417. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115418. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115419. 6, 8, 9,11,
  115420. };
  115421. static static_codebook _huff_book__44c3_s_short = {
  115422. 2, 100,
  115423. _huff_lengthlist__44c3_s_short,
  115424. 0, 0, 0, 0, 0,
  115425. NULL,
  115426. NULL,
  115427. NULL,
  115428. NULL,
  115429. 0
  115430. };
  115431. static long _huff_lengthlist__44c4_s_long[] = {
  115432. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115433. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115434. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115435. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115436. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115437. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115438. 9, 8, 7, 7,
  115439. };
  115440. static static_codebook _huff_book__44c4_s_long = {
  115441. 2, 100,
  115442. _huff_lengthlist__44c4_s_long,
  115443. 0, 0, 0, 0, 0,
  115444. NULL,
  115445. NULL,
  115446. NULL,
  115447. NULL,
  115448. 0
  115449. };
  115450. static long _vq_quantlist__44c4_s_p1_0[] = {
  115451. 1,
  115452. 0,
  115453. 2,
  115454. };
  115455. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115456. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115457. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115461. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115462. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115466. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115467. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115502. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115507. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115512. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115547. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115548. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115552. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115553. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  115554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115557. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115558. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115866. 0,
  115867. };
  115868. static float _vq_quantthresh__44c4_s_p1_0[] = {
  115869. -0.5, 0.5,
  115870. };
  115871. static long _vq_quantmap__44c4_s_p1_0[] = {
  115872. 1, 0, 2,
  115873. };
  115874. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  115875. _vq_quantthresh__44c4_s_p1_0,
  115876. _vq_quantmap__44c4_s_p1_0,
  115877. 3,
  115878. 3
  115879. };
  115880. static static_codebook _44c4_s_p1_0 = {
  115881. 8, 6561,
  115882. _vq_lengthlist__44c4_s_p1_0,
  115883. 1, -535822336, 1611661312, 2, 0,
  115884. _vq_quantlist__44c4_s_p1_0,
  115885. NULL,
  115886. &_vq_auxt__44c4_s_p1_0,
  115887. NULL,
  115888. 0
  115889. };
  115890. static long _vq_quantlist__44c4_s_p2_0[] = {
  115891. 2,
  115892. 1,
  115893. 3,
  115894. 0,
  115895. 4,
  115896. };
  115897. static long _vq_lengthlist__44c4_s_p2_0[] = {
  115898. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115899. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115900. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115901. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115902. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115907. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  115908. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115909. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115910. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115915. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115916. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115917. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115923. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115924. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115925. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115937. 0,
  115938. };
  115939. static float _vq_quantthresh__44c4_s_p2_0[] = {
  115940. -1.5, -0.5, 0.5, 1.5,
  115941. };
  115942. static long _vq_quantmap__44c4_s_p2_0[] = {
  115943. 3, 1, 0, 2, 4,
  115944. };
  115945. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  115946. _vq_quantthresh__44c4_s_p2_0,
  115947. _vq_quantmap__44c4_s_p2_0,
  115948. 5,
  115949. 5
  115950. };
  115951. static static_codebook _44c4_s_p2_0 = {
  115952. 4, 625,
  115953. _vq_lengthlist__44c4_s_p2_0,
  115954. 1, -533725184, 1611661312, 3, 0,
  115955. _vq_quantlist__44c4_s_p2_0,
  115956. NULL,
  115957. &_vq_auxt__44c4_s_p2_0,
  115958. NULL,
  115959. 0
  115960. };
  115961. static long _vq_quantlist__44c4_s_p3_0[] = {
  115962. 2,
  115963. 1,
  115964. 3,
  115965. 0,
  115966. 4,
  115967. };
  115968. static long _vq_lengthlist__44c4_s_p3_0[] = {
  115969. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  115971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115972. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115975. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116008. 0,
  116009. };
  116010. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116011. -1.5, -0.5, 0.5, 1.5,
  116012. };
  116013. static long _vq_quantmap__44c4_s_p3_0[] = {
  116014. 3, 1, 0, 2, 4,
  116015. };
  116016. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116017. _vq_quantthresh__44c4_s_p3_0,
  116018. _vq_quantmap__44c4_s_p3_0,
  116019. 5,
  116020. 5
  116021. };
  116022. static static_codebook _44c4_s_p3_0 = {
  116023. 4, 625,
  116024. _vq_lengthlist__44c4_s_p3_0,
  116025. 1, -533725184, 1611661312, 3, 0,
  116026. _vq_quantlist__44c4_s_p3_0,
  116027. NULL,
  116028. &_vq_auxt__44c4_s_p3_0,
  116029. NULL,
  116030. 0
  116031. };
  116032. static long _vq_quantlist__44c4_s_p4_0[] = {
  116033. 4,
  116034. 3,
  116035. 5,
  116036. 2,
  116037. 6,
  116038. 1,
  116039. 7,
  116040. 0,
  116041. 8,
  116042. };
  116043. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116044. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116045. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116046. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116047. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116048. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116049. 0,
  116050. };
  116051. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116052. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116053. };
  116054. static long _vq_quantmap__44c4_s_p4_0[] = {
  116055. 7, 5, 3, 1, 0, 2, 4, 6,
  116056. 8,
  116057. };
  116058. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116059. _vq_quantthresh__44c4_s_p4_0,
  116060. _vq_quantmap__44c4_s_p4_0,
  116061. 9,
  116062. 9
  116063. };
  116064. static static_codebook _44c4_s_p4_0 = {
  116065. 2, 81,
  116066. _vq_lengthlist__44c4_s_p4_0,
  116067. 1, -531628032, 1611661312, 4, 0,
  116068. _vq_quantlist__44c4_s_p4_0,
  116069. NULL,
  116070. &_vq_auxt__44c4_s_p4_0,
  116071. NULL,
  116072. 0
  116073. };
  116074. static long _vq_quantlist__44c4_s_p5_0[] = {
  116075. 4,
  116076. 3,
  116077. 5,
  116078. 2,
  116079. 6,
  116080. 1,
  116081. 7,
  116082. 0,
  116083. 8,
  116084. };
  116085. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116086. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116087. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116088. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116089. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116090. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116091. 10,
  116092. };
  116093. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116094. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116095. };
  116096. static long _vq_quantmap__44c4_s_p5_0[] = {
  116097. 7, 5, 3, 1, 0, 2, 4, 6,
  116098. 8,
  116099. };
  116100. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116101. _vq_quantthresh__44c4_s_p5_0,
  116102. _vq_quantmap__44c4_s_p5_0,
  116103. 9,
  116104. 9
  116105. };
  116106. static static_codebook _44c4_s_p5_0 = {
  116107. 2, 81,
  116108. _vq_lengthlist__44c4_s_p5_0,
  116109. 1, -531628032, 1611661312, 4, 0,
  116110. _vq_quantlist__44c4_s_p5_0,
  116111. NULL,
  116112. &_vq_auxt__44c4_s_p5_0,
  116113. NULL,
  116114. 0
  116115. };
  116116. static long _vq_quantlist__44c4_s_p6_0[] = {
  116117. 8,
  116118. 7,
  116119. 9,
  116120. 6,
  116121. 10,
  116122. 5,
  116123. 11,
  116124. 4,
  116125. 12,
  116126. 3,
  116127. 13,
  116128. 2,
  116129. 14,
  116130. 1,
  116131. 15,
  116132. 0,
  116133. 16,
  116134. };
  116135. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116136. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116137. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116138. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116139. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116140. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116141. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116142. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116143. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116144. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116145. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116146. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116147. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116148. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116149. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116150. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116151. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116152. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116153. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116154. 13,
  116155. };
  116156. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116157. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116158. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116159. };
  116160. static long _vq_quantmap__44c4_s_p6_0[] = {
  116161. 15, 13, 11, 9, 7, 5, 3, 1,
  116162. 0, 2, 4, 6, 8, 10, 12, 14,
  116163. 16,
  116164. };
  116165. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116166. _vq_quantthresh__44c4_s_p6_0,
  116167. _vq_quantmap__44c4_s_p6_0,
  116168. 17,
  116169. 17
  116170. };
  116171. static static_codebook _44c4_s_p6_0 = {
  116172. 2, 289,
  116173. _vq_lengthlist__44c4_s_p6_0,
  116174. 1, -529530880, 1611661312, 5, 0,
  116175. _vq_quantlist__44c4_s_p6_0,
  116176. NULL,
  116177. &_vq_auxt__44c4_s_p6_0,
  116178. NULL,
  116179. 0
  116180. };
  116181. static long _vq_quantlist__44c4_s_p7_0[] = {
  116182. 1,
  116183. 0,
  116184. 2,
  116185. };
  116186. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116187. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116188. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116189. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116190. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116191. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116192. 10,
  116193. };
  116194. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116195. -5.5, 5.5,
  116196. };
  116197. static long _vq_quantmap__44c4_s_p7_0[] = {
  116198. 1, 0, 2,
  116199. };
  116200. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116201. _vq_quantthresh__44c4_s_p7_0,
  116202. _vq_quantmap__44c4_s_p7_0,
  116203. 3,
  116204. 3
  116205. };
  116206. static static_codebook _44c4_s_p7_0 = {
  116207. 4, 81,
  116208. _vq_lengthlist__44c4_s_p7_0,
  116209. 1, -529137664, 1618345984, 2, 0,
  116210. _vq_quantlist__44c4_s_p7_0,
  116211. NULL,
  116212. &_vq_auxt__44c4_s_p7_0,
  116213. NULL,
  116214. 0
  116215. };
  116216. static long _vq_quantlist__44c4_s_p7_1[] = {
  116217. 5,
  116218. 4,
  116219. 6,
  116220. 3,
  116221. 7,
  116222. 2,
  116223. 8,
  116224. 1,
  116225. 9,
  116226. 0,
  116227. 10,
  116228. };
  116229. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116230. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116231. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116232. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116233. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116234. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116235. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116236. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116237. 10,10,10, 8, 8, 8, 8, 9, 9,
  116238. };
  116239. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116240. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116241. 3.5, 4.5,
  116242. };
  116243. static long _vq_quantmap__44c4_s_p7_1[] = {
  116244. 9, 7, 5, 3, 1, 0, 2, 4,
  116245. 6, 8, 10,
  116246. };
  116247. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116248. _vq_quantthresh__44c4_s_p7_1,
  116249. _vq_quantmap__44c4_s_p7_1,
  116250. 11,
  116251. 11
  116252. };
  116253. static static_codebook _44c4_s_p7_1 = {
  116254. 2, 121,
  116255. _vq_lengthlist__44c4_s_p7_1,
  116256. 1, -531365888, 1611661312, 4, 0,
  116257. _vq_quantlist__44c4_s_p7_1,
  116258. NULL,
  116259. &_vq_auxt__44c4_s_p7_1,
  116260. NULL,
  116261. 0
  116262. };
  116263. static long _vq_quantlist__44c4_s_p8_0[] = {
  116264. 6,
  116265. 5,
  116266. 7,
  116267. 4,
  116268. 8,
  116269. 3,
  116270. 9,
  116271. 2,
  116272. 10,
  116273. 1,
  116274. 11,
  116275. 0,
  116276. 12,
  116277. };
  116278. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116279. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116280. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116281. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116282. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116283. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116284. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116285. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116286. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116287. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116288. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116289. 0,13,12,12,12,12,12,13,13,
  116290. };
  116291. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116292. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116293. 12.5, 17.5, 22.5, 27.5,
  116294. };
  116295. static long _vq_quantmap__44c4_s_p8_0[] = {
  116296. 11, 9, 7, 5, 3, 1, 0, 2,
  116297. 4, 6, 8, 10, 12,
  116298. };
  116299. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116300. _vq_quantthresh__44c4_s_p8_0,
  116301. _vq_quantmap__44c4_s_p8_0,
  116302. 13,
  116303. 13
  116304. };
  116305. static static_codebook _44c4_s_p8_0 = {
  116306. 2, 169,
  116307. _vq_lengthlist__44c4_s_p8_0,
  116308. 1, -526516224, 1616117760, 4, 0,
  116309. _vq_quantlist__44c4_s_p8_0,
  116310. NULL,
  116311. &_vq_auxt__44c4_s_p8_0,
  116312. NULL,
  116313. 0
  116314. };
  116315. static long _vq_quantlist__44c4_s_p8_1[] = {
  116316. 2,
  116317. 1,
  116318. 3,
  116319. 0,
  116320. 4,
  116321. };
  116322. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116323. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116324. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116325. };
  116326. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116327. -1.5, -0.5, 0.5, 1.5,
  116328. };
  116329. static long _vq_quantmap__44c4_s_p8_1[] = {
  116330. 3, 1, 0, 2, 4,
  116331. };
  116332. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116333. _vq_quantthresh__44c4_s_p8_1,
  116334. _vq_quantmap__44c4_s_p8_1,
  116335. 5,
  116336. 5
  116337. };
  116338. static static_codebook _44c4_s_p8_1 = {
  116339. 2, 25,
  116340. _vq_lengthlist__44c4_s_p8_1,
  116341. 1, -533725184, 1611661312, 3, 0,
  116342. _vq_quantlist__44c4_s_p8_1,
  116343. NULL,
  116344. &_vq_auxt__44c4_s_p8_1,
  116345. NULL,
  116346. 0
  116347. };
  116348. static long _vq_quantlist__44c4_s_p9_0[] = {
  116349. 6,
  116350. 5,
  116351. 7,
  116352. 4,
  116353. 8,
  116354. 3,
  116355. 9,
  116356. 2,
  116357. 10,
  116358. 1,
  116359. 11,
  116360. 0,
  116361. 12,
  116362. };
  116363. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116364. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116365. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116366. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116367. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116368. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116369. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116370. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116371. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116372. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116373. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116374. 12,12,12,12,12,12,12,12,12,
  116375. };
  116376. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116377. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116378. 787.5, 1102.5, 1417.5, 1732.5,
  116379. };
  116380. static long _vq_quantmap__44c4_s_p9_0[] = {
  116381. 11, 9, 7, 5, 3, 1, 0, 2,
  116382. 4, 6, 8, 10, 12,
  116383. };
  116384. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116385. _vq_quantthresh__44c4_s_p9_0,
  116386. _vq_quantmap__44c4_s_p9_0,
  116387. 13,
  116388. 13
  116389. };
  116390. static static_codebook _44c4_s_p9_0 = {
  116391. 2, 169,
  116392. _vq_lengthlist__44c4_s_p9_0,
  116393. 1, -513964032, 1628680192, 4, 0,
  116394. _vq_quantlist__44c4_s_p9_0,
  116395. NULL,
  116396. &_vq_auxt__44c4_s_p9_0,
  116397. NULL,
  116398. 0
  116399. };
  116400. static long _vq_quantlist__44c4_s_p9_1[] = {
  116401. 7,
  116402. 6,
  116403. 8,
  116404. 5,
  116405. 9,
  116406. 4,
  116407. 10,
  116408. 3,
  116409. 11,
  116410. 2,
  116411. 12,
  116412. 1,
  116413. 13,
  116414. 0,
  116415. 14,
  116416. };
  116417. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116418. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116419. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116420. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116421. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116422. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116423. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116424. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116425. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116426. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116427. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116428. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116429. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116430. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116431. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116432. 15,
  116433. };
  116434. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116435. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116436. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116437. };
  116438. static long _vq_quantmap__44c4_s_p9_1[] = {
  116439. 13, 11, 9, 7, 5, 3, 1, 0,
  116440. 2, 4, 6, 8, 10, 12, 14,
  116441. };
  116442. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116443. _vq_quantthresh__44c4_s_p9_1,
  116444. _vq_quantmap__44c4_s_p9_1,
  116445. 15,
  116446. 15
  116447. };
  116448. static static_codebook _44c4_s_p9_1 = {
  116449. 2, 225,
  116450. _vq_lengthlist__44c4_s_p9_1,
  116451. 1, -520986624, 1620377600, 4, 0,
  116452. _vq_quantlist__44c4_s_p9_1,
  116453. NULL,
  116454. &_vq_auxt__44c4_s_p9_1,
  116455. NULL,
  116456. 0
  116457. };
  116458. static long _vq_quantlist__44c4_s_p9_2[] = {
  116459. 10,
  116460. 9,
  116461. 11,
  116462. 8,
  116463. 12,
  116464. 7,
  116465. 13,
  116466. 6,
  116467. 14,
  116468. 5,
  116469. 15,
  116470. 4,
  116471. 16,
  116472. 3,
  116473. 17,
  116474. 2,
  116475. 18,
  116476. 1,
  116477. 19,
  116478. 0,
  116479. 20,
  116480. };
  116481. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116482. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116483. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116484. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116485. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116486. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116487. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116488. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116489. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116490. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116491. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116492. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116493. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116494. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116495. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116496. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116497. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116498. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116499. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116500. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116501. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116502. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116503. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116504. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116505. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116506. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116507. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116508. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116509. 10,10,10,10,10,10,10,10,10,
  116510. };
  116511. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116512. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116513. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116514. 6.5, 7.5, 8.5, 9.5,
  116515. };
  116516. static long _vq_quantmap__44c4_s_p9_2[] = {
  116517. 19, 17, 15, 13, 11, 9, 7, 5,
  116518. 3, 1, 0, 2, 4, 6, 8, 10,
  116519. 12, 14, 16, 18, 20,
  116520. };
  116521. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116522. _vq_quantthresh__44c4_s_p9_2,
  116523. _vq_quantmap__44c4_s_p9_2,
  116524. 21,
  116525. 21
  116526. };
  116527. static static_codebook _44c4_s_p9_2 = {
  116528. 2, 441,
  116529. _vq_lengthlist__44c4_s_p9_2,
  116530. 1, -529268736, 1611661312, 5, 0,
  116531. _vq_quantlist__44c4_s_p9_2,
  116532. NULL,
  116533. &_vq_auxt__44c4_s_p9_2,
  116534. NULL,
  116535. 0
  116536. };
  116537. static long _huff_lengthlist__44c4_s_short[] = {
  116538. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116539. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116540. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116541. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116542. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116543. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116544. 7, 9,12,17,
  116545. };
  116546. static static_codebook _huff_book__44c4_s_short = {
  116547. 2, 100,
  116548. _huff_lengthlist__44c4_s_short,
  116549. 0, 0, 0, 0, 0,
  116550. NULL,
  116551. NULL,
  116552. NULL,
  116553. NULL,
  116554. 0
  116555. };
  116556. static long _huff_lengthlist__44c5_s_long[] = {
  116557. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116558. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116559. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116560. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116561. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116562. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116563. 9, 8, 7, 7,
  116564. };
  116565. static static_codebook _huff_book__44c5_s_long = {
  116566. 2, 100,
  116567. _huff_lengthlist__44c5_s_long,
  116568. 0, 0, 0, 0, 0,
  116569. NULL,
  116570. NULL,
  116571. NULL,
  116572. NULL,
  116573. 0
  116574. };
  116575. static long _vq_quantlist__44c5_s_p1_0[] = {
  116576. 1,
  116577. 0,
  116578. 2,
  116579. };
  116580. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116581. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116582. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116586. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116587. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116591. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116592. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116627. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116632. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  116633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116637. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  116638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116672. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116673. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116677. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116678. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  116679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116682. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116683. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  116684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116991. 0,
  116992. };
  116993. static float _vq_quantthresh__44c5_s_p1_0[] = {
  116994. -0.5, 0.5,
  116995. };
  116996. static long _vq_quantmap__44c5_s_p1_0[] = {
  116997. 1, 0, 2,
  116998. };
  116999. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117000. _vq_quantthresh__44c5_s_p1_0,
  117001. _vq_quantmap__44c5_s_p1_0,
  117002. 3,
  117003. 3
  117004. };
  117005. static static_codebook _44c5_s_p1_0 = {
  117006. 8, 6561,
  117007. _vq_lengthlist__44c5_s_p1_0,
  117008. 1, -535822336, 1611661312, 2, 0,
  117009. _vq_quantlist__44c5_s_p1_0,
  117010. NULL,
  117011. &_vq_auxt__44c5_s_p1_0,
  117012. NULL,
  117013. 0
  117014. };
  117015. static long _vq_quantlist__44c5_s_p2_0[] = {
  117016. 2,
  117017. 1,
  117018. 3,
  117019. 0,
  117020. 4,
  117021. };
  117022. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117023. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117024. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117025. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117026. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117027. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117032. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117033. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117034. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117035. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117040. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117041. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117042. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117048. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117049. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117050. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117062. 0,
  117063. };
  117064. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117065. -1.5, -0.5, 0.5, 1.5,
  117066. };
  117067. static long _vq_quantmap__44c5_s_p2_0[] = {
  117068. 3, 1, 0, 2, 4,
  117069. };
  117070. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117071. _vq_quantthresh__44c5_s_p2_0,
  117072. _vq_quantmap__44c5_s_p2_0,
  117073. 5,
  117074. 5
  117075. };
  117076. static static_codebook _44c5_s_p2_0 = {
  117077. 4, 625,
  117078. _vq_lengthlist__44c5_s_p2_0,
  117079. 1, -533725184, 1611661312, 3, 0,
  117080. _vq_quantlist__44c5_s_p2_0,
  117081. NULL,
  117082. &_vq_auxt__44c5_s_p2_0,
  117083. NULL,
  117084. 0
  117085. };
  117086. static long _vq_quantlist__44c5_s_p3_0[] = {
  117087. 2,
  117088. 1,
  117089. 3,
  117090. 0,
  117091. 4,
  117092. };
  117093. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117094. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117097. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117100. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117133. 0,
  117134. };
  117135. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117136. -1.5, -0.5, 0.5, 1.5,
  117137. };
  117138. static long _vq_quantmap__44c5_s_p3_0[] = {
  117139. 3, 1, 0, 2, 4,
  117140. };
  117141. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117142. _vq_quantthresh__44c5_s_p3_0,
  117143. _vq_quantmap__44c5_s_p3_0,
  117144. 5,
  117145. 5
  117146. };
  117147. static static_codebook _44c5_s_p3_0 = {
  117148. 4, 625,
  117149. _vq_lengthlist__44c5_s_p3_0,
  117150. 1, -533725184, 1611661312, 3, 0,
  117151. _vq_quantlist__44c5_s_p3_0,
  117152. NULL,
  117153. &_vq_auxt__44c5_s_p3_0,
  117154. NULL,
  117155. 0
  117156. };
  117157. static long _vq_quantlist__44c5_s_p4_0[] = {
  117158. 4,
  117159. 3,
  117160. 5,
  117161. 2,
  117162. 6,
  117163. 1,
  117164. 7,
  117165. 0,
  117166. 8,
  117167. };
  117168. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117169. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117170. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117171. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117172. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117173. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117174. 0,
  117175. };
  117176. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117177. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117178. };
  117179. static long _vq_quantmap__44c5_s_p4_0[] = {
  117180. 7, 5, 3, 1, 0, 2, 4, 6,
  117181. 8,
  117182. };
  117183. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117184. _vq_quantthresh__44c5_s_p4_0,
  117185. _vq_quantmap__44c5_s_p4_0,
  117186. 9,
  117187. 9
  117188. };
  117189. static static_codebook _44c5_s_p4_0 = {
  117190. 2, 81,
  117191. _vq_lengthlist__44c5_s_p4_0,
  117192. 1, -531628032, 1611661312, 4, 0,
  117193. _vq_quantlist__44c5_s_p4_0,
  117194. NULL,
  117195. &_vq_auxt__44c5_s_p4_0,
  117196. NULL,
  117197. 0
  117198. };
  117199. static long _vq_quantlist__44c5_s_p5_0[] = {
  117200. 4,
  117201. 3,
  117202. 5,
  117203. 2,
  117204. 6,
  117205. 1,
  117206. 7,
  117207. 0,
  117208. 8,
  117209. };
  117210. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117211. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117212. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117213. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117214. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117215. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117216. 10,
  117217. };
  117218. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117219. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117220. };
  117221. static long _vq_quantmap__44c5_s_p5_0[] = {
  117222. 7, 5, 3, 1, 0, 2, 4, 6,
  117223. 8,
  117224. };
  117225. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117226. _vq_quantthresh__44c5_s_p5_0,
  117227. _vq_quantmap__44c5_s_p5_0,
  117228. 9,
  117229. 9
  117230. };
  117231. static static_codebook _44c5_s_p5_0 = {
  117232. 2, 81,
  117233. _vq_lengthlist__44c5_s_p5_0,
  117234. 1, -531628032, 1611661312, 4, 0,
  117235. _vq_quantlist__44c5_s_p5_0,
  117236. NULL,
  117237. &_vq_auxt__44c5_s_p5_0,
  117238. NULL,
  117239. 0
  117240. };
  117241. static long _vq_quantlist__44c5_s_p6_0[] = {
  117242. 8,
  117243. 7,
  117244. 9,
  117245. 6,
  117246. 10,
  117247. 5,
  117248. 11,
  117249. 4,
  117250. 12,
  117251. 3,
  117252. 13,
  117253. 2,
  117254. 14,
  117255. 1,
  117256. 15,
  117257. 0,
  117258. 16,
  117259. };
  117260. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117261. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117262. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117263. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117264. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117265. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117266. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117267. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117268. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117269. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117270. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117271. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117272. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117273. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117274. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117275. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117276. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117277. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117278. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117279. 13,
  117280. };
  117281. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117282. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117283. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117284. };
  117285. static long _vq_quantmap__44c5_s_p6_0[] = {
  117286. 15, 13, 11, 9, 7, 5, 3, 1,
  117287. 0, 2, 4, 6, 8, 10, 12, 14,
  117288. 16,
  117289. };
  117290. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117291. _vq_quantthresh__44c5_s_p6_0,
  117292. _vq_quantmap__44c5_s_p6_0,
  117293. 17,
  117294. 17
  117295. };
  117296. static static_codebook _44c5_s_p6_0 = {
  117297. 2, 289,
  117298. _vq_lengthlist__44c5_s_p6_0,
  117299. 1, -529530880, 1611661312, 5, 0,
  117300. _vq_quantlist__44c5_s_p6_0,
  117301. NULL,
  117302. &_vq_auxt__44c5_s_p6_0,
  117303. NULL,
  117304. 0
  117305. };
  117306. static long _vq_quantlist__44c5_s_p7_0[] = {
  117307. 1,
  117308. 0,
  117309. 2,
  117310. };
  117311. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117312. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117313. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117314. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117315. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117316. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117317. 10,
  117318. };
  117319. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117320. -5.5, 5.5,
  117321. };
  117322. static long _vq_quantmap__44c5_s_p7_0[] = {
  117323. 1, 0, 2,
  117324. };
  117325. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117326. _vq_quantthresh__44c5_s_p7_0,
  117327. _vq_quantmap__44c5_s_p7_0,
  117328. 3,
  117329. 3
  117330. };
  117331. static static_codebook _44c5_s_p7_0 = {
  117332. 4, 81,
  117333. _vq_lengthlist__44c5_s_p7_0,
  117334. 1, -529137664, 1618345984, 2, 0,
  117335. _vq_quantlist__44c5_s_p7_0,
  117336. NULL,
  117337. &_vq_auxt__44c5_s_p7_0,
  117338. NULL,
  117339. 0
  117340. };
  117341. static long _vq_quantlist__44c5_s_p7_1[] = {
  117342. 5,
  117343. 4,
  117344. 6,
  117345. 3,
  117346. 7,
  117347. 2,
  117348. 8,
  117349. 1,
  117350. 9,
  117351. 0,
  117352. 10,
  117353. };
  117354. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117355. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117356. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117357. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117358. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117359. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117360. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117361. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117362. 10,10,10, 8, 8, 8, 8, 8, 8,
  117363. };
  117364. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117365. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117366. 3.5, 4.5,
  117367. };
  117368. static long _vq_quantmap__44c5_s_p7_1[] = {
  117369. 9, 7, 5, 3, 1, 0, 2, 4,
  117370. 6, 8, 10,
  117371. };
  117372. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117373. _vq_quantthresh__44c5_s_p7_1,
  117374. _vq_quantmap__44c5_s_p7_1,
  117375. 11,
  117376. 11
  117377. };
  117378. static static_codebook _44c5_s_p7_1 = {
  117379. 2, 121,
  117380. _vq_lengthlist__44c5_s_p7_1,
  117381. 1, -531365888, 1611661312, 4, 0,
  117382. _vq_quantlist__44c5_s_p7_1,
  117383. NULL,
  117384. &_vq_auxt__44c5_s_p7_1,
  117385. NULL,
  117386. 0
  117387. };
  117388. static long _vq_quantlist__44c5_s_p8_0[] = {
  117389. 6,
  117390. 5,
  117391. 7,
  117392. 4,
  117393. 8,
  117394. 3,
  117395. 9,
  117396. 2,
  117397. 10,
  117398. 1,
  117399. 11,
  117400. 0,
  117401. 12,
  117402. };
  117403. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117404. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117405. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117406. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117407. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117408. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117409. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117410. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117411. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117412. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117413. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117414. 0,12,12,12,12,12,12,13,13,
  117415. };
  117416. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117417. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117418. 12.5, 17.5, 22.5, 27.5,
  117419. };
  117420. static long _vq_quantmap__44c5_s_p8_0[] = {
  117421. 11, 9, 7, 5, 3, 1, 0, 2,
  117422. 4, 6, 8, 10, 12,
  117423. };
  117424. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117425. _vq_quantthresh__44c5_s_p8_0,
  117426. _vq_quantmap__44c5_s_p8_0,
  117427. 13,
  117428. 13
  117429. };
  117430. static static_codebook _44c5_s_p8_0 = {
  117431. 2, 169,
  117432. _vq_lengthlist__44c5_s_p8_0,
  117433. 1, -526516224, 1616117760, 4, 0,
  117434. _vq_quantlist__44c5_s_p8_0,
  117435. NULL,
  117436. &_vq_auxt__44c5_s_p8_0,
  117437. NULL,
  117438. 0
  117439. };
  117440. static long _vq_quantlist__44c5_s_p8_1[] = {
  117441. 2,
  117442. 1,
  117443. 3,
  117444. 0,
  117445. 4,
  117446. };
  117447. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117448. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117449. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117450. };
  117451. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117452. -1.5, -0.5, 0.5, 1.5,
  117453. };
  117454. static long _vq_quantmap__44c5_s_p8_1[] = {
  117455. 3, 1, 0, 2, 4,
  117456. };
  117457. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117458. _vq_quantthresh__44c5_s_p8_1,
  117459. _vq_quantmap__44c5_s_p8_1,
  117460. 5,
  117461. 5
  117462. };
  117463. static static_codebook _44c5_s_p8_1 = {
  117464. 2, 25,
  117465. _vq_lengthlist__44c5_s_p8_1,
  117466. 1, -533725184, 1611661312, 3, 0,
  117467. _vq_quantlist__44c5_s_p8_1,
  117468. NULL,
  117469. &_vq_auxt__44c5_s_p8_1,
  117470. NULL,
  117471. 0
  117472. };
  117473. static long _vq_quantlist__44c5_s_p9_0[] = {
  117474. 7,
  117475. 6,
  117476. 8,
  117477. 5,
  117478. 9,
  117479. 4,
  117480. 10,
  117481. 3,
  117482. 11,
  117483. 2,
  117484. 12,
  117485. 1,
  117486. 13,
  117487. 0,
  117488. 14,
  117489. };
  117490. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117491. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117492. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117493. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117494. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117495. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117496. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117497. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117498. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117499. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117500. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117501. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117502. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117503. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117504. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117505. 12,
  117506. };
  117507. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117508. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117509. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117510. };
  117511. static long _vq_quantmap__44c5_s_p9_0[] = {
  117512. 13, 11, 9, 7, 5, 3, 1, 0,
  117513. 2, 4, 6, 8, 10, 12, 14,
  117514. };
  117515. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117516. _vq_quantthresh__44c5_s_p9_0,
  117517. _vq_quantmap__44c5_s_p9_0,
  117518. 15,
  117519. 15
  117520. };
  117521. static static_codebook _44c5_s_p9_0 = {
  117522. 2, 225,
  117523. _vq_lengthlist__44c5_s_p9_0,
  117524. 1, -512522752, 1628852224, 4, 0,
  117525. _vq_quantlist__44c5_s_p9_0,
  117526. NULL,
  117527. &_vq_auxt__44c5_s_p9_0,
  117528. NULL,
  117529. 0
  117530. };
  117531. static long _vq_quantlist__44c5_s_p9_1[] = {
  117532. 8,
  117533. 7,
  117534. 9,
  117535. 6,
  117536. 10,
  117537. 5,
  117538. 11,
  117539. 4,
  117540. 12,
  117541. 3,
  117542. 13,
  117543. 2,
  117544. 14,
  117545. 1,
  117546. 15,
  117547. 0,
  117548. 16,
  117549. };
  117550. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117551. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117552. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117553. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117554. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117555. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117556. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117557. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117558. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117559. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117560. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117561. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117562. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117563. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117564. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117565. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117566. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117567. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117568. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117569. 15,
  117570. };
  117571. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117572. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117573. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117574. };
  117575. static long _vq_quantmap__44c5_s_p9_1[] = {
  117576. 15, 13, 11, 9, 7, 5, 3, 1,
  117577. 0, 2, 4, 6, 8, 10, 12, 14,
  117578. 16,
  117579. };
  117580. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117581. _vq_quantthresh__44c5_s_p9_1,
  117582. _vq_quantmap__44c5_s_p9_1,
  117583. 17,
  117584. 17
  117585. };
  117586. static static_codebook _44c5_s_p9_1 = {
  117587. 2, 289,
  117588. _vq_lengthlist__44c5_s_p9_1,
  117589. 1, -520814592, 1620377600, 5, 0,
  117590. _vq_quantlist__44c5_s_p9_1,
  117591. NULL,
  117592. &_vq_auxt__44c5_s_p9_1,
  117593. NULL,
  117594. 0
  117595. };
  117596. static long _vq_quantlist__44c5_s_p9_2[] = {
  117597. 10,
  117598. 9,
  117599. 11,
  117600. 8,
  117601. 12,
  117602. 7,
  117603. 13,
  117604. 6,
  117605. 14,
  117606. 5,
  117607. 15,
  117608. 4,
  117609. 16,
  117610. 3,
  117611. 17,
  117612. 2,
  117613. 18,
  117614. 1,
  117615. 19,
  117616. 0,
  117617. 20,
  117618. };
  117619. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117620. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117621. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117622. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117623. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117624. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117625. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117626. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117627. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117628. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117629. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117630. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117631. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117632. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117633. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117634. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117635. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117636. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117637. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117638. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117639. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117640. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117641. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117642. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117643. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117644. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117645. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117646. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117647. 10,10,10,10,10,10,10,10,10,
  117648. };
  117649. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117650. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117651. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117652. 6.5, 7.5, 8.5, 9.5,
  117653. };
  117654. static long _vq_quantmap__44c5_s_p9_2[] = {
  117655. 19, 17, 15, 13, 11, 9, 7, 5,
  117656. 3, 1, 0, 2, 4, 6, 8, 10,
  117657. 12, 14, 16, 18, 20,
  117658. };
  117659. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117660. _vq_quantthresh__44c5_s_p9_2,
  117661. _vq_quantmap__44c5_s_p9_2,
  117662. 21,
  117663. 21
  117664. };
  117665. static static_codebook _44c5_s_p9_2 = {
  117666. 2, 441,
  117667. _vq_lengthlist__44c5_s_p9_2,
  117668. 1, -529268736, 1611661312, 5, 0,
  117669. _vq_quantlist__44c5_s_p9_2,
  117670. NULL,
  117671. &_vq_auxt__44c5_s_p9_2,
  117672. NULL,
  117673. 0
  117674. };
  117675. static long _huff_lengthlist__44c5_s_short[] = {
  117676. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117677. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117678. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117679. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117680. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117681. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117682. 6, 8,11,16,
  117683. };
  117684. static static_codebook _huff_book__44c5_s_short = {
  117685. 2, 100,
  117686. _huff_lengthlist__44c5_s_short,
  117687. 0, 0, 0, 0, 0,
  117688. NULL,
  117689. NULL,
  117690. NULL,
  117691. NULL,
  117692. 0
  117693. };
  117694. static long _huff_lengthlist__44c6_s_long[] = {
  117695. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  117696. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  117697. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  117698. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  117699. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  117700. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  117701. 11,10,10,12,
  117702. };
  117703. static static_codebook _huff_book__44c6_s_long = {
  117704. 2, 100,
  117705. _huff_lengthlist__44c6_s_long,
  117706. 0, 0, 0, 0, 0,
  117707. NULL,
  117708. NULL,
  117709. NULL,
  117710. NULL,
  117711. 0
  117712. };
  117713. static long _vq_quantlist__44c6_s_p1_0[] = {
  117714. 1,
  117715. 0,
  117716. 2,
  117717. };
  117718. static long _vq_lengthlist__44c6_s_p1_0[] = {
  117719. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  117720. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  117721. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  117722. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  117723. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  117724. 8,
  117725. };
  117726. static float _vq_quantthresh__44c6_s_p1_0[] = {
  117727. -0.5, 0.5,
  117728. };
  117729. static long _vq_quantmap__44c6_s_p1_0[] = {
  117730. 1, 0, 2,
  117731. };
  117732. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  117733. _vq_quantthresh__44c6_s_p1_0,
  117734. _vq_quantmap__44c6_s_p1_0,
  117735. 3,
  117736. 3
  117737. };
  117738. static static_codebook _44c6_s_p1_0 = {
  117739. 4, 81,
  117740. _vq_lengthlist__44c6_s_p1_0,
  117741. 1, -535822336, 1611661312, 2, 0,
  117742. _vq_quantlist__44c6_s_p1_0,
  117743. NULL,
  117744. &_vq_auxt__44c6_s_p1_0,
  117745. NULL,
  117746. 0
  117747. };
  117748. static long _vq_quantlist__44c6_s_p2_0[] = {
  117749. 2,
  117750. 1,
  117751. 3,
  117752. 0,
  117753. 4,
  117754. };
  117755. static long _vq_lengthlist__44c6_s_p2_0[] = {
  117756. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  117757. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  117758. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  117759. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  117760. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  117761. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  117762. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  117763. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  117764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117765. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  117766. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  117767. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  117768. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  117769. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  117770. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  117771. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  117772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117773. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  117774. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  117775. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  117776. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  117777. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  117778. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  117779. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117781. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  117782. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  117783. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  117784. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  117785. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  117786. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  117787. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  117792. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  117793. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  117794. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  117795. 13,
  117796. };
  117797. static float _vq_quantthresh__44c6_s_p2_0[] = {
  117798. -1.5, -0.5, 0.5, 1.5,
  117799. };
  117800. static long _vq_quantmap__44c6_s_p2_0[] = {
  117801. 3, 1, 0, 2, 4,
  117802. };
  117803. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  117804. _vq_quantthresh__44c6_s_p2_0,
  117805. _vq_quantmap__44c6_s_p2_0,
  117806. 5,
  117807. 5
  117808. };
  117809. static static_codebook _44c6_s_p2_0 = {
  117810. 4, 625,
  117811. _vq_lengthlist__44c6_s_p2_0,
  117812. 1, -533725184, 1611661312, 3, 0,
  117813. _vq_quantlist__44c6_s_p2_0,
  117814. NULL,
  117815. &_vq_auxt__44c6_s_p2_0,
  117816. NULL,
  117817. 0
  117818. };
  117819. static long _vq_quantlist__44c6_s_p3_0[] = {
  117820. 4,
  117821. 3,
  117822. 5,
  117823. 2,
  117824. 6,
  117825. 1,
  117826. 7,
  117827. 0,
  117828. 8,
  117829. };
  117830. static long _vq_lengthlist__44c6_s_p3_0[] = {
  117831. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117832. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  117833. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  117834. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  117835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117836. 0,
  117837. };
  117838. static float _vq_quantthresh__44c6_s_p3_0[] = {
  117839. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117840. };
  117841. static long _vq_quantmap__44c6_s_p3_0[] = {
  117842. 7, 5, 3, 1, 0, 2, 4, 6,
  117843. 8,
  117844. };
  117845. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  117846. _vq_quantthresh__44c6_s_p3_0,
  117847. _vq_quantmap__44c6_s_p3_0,
  117848. 9,
  117849. 9
  117850. };
  117851. static static_codebook _44c6_s_p3_0 = {
  117852. 2, 81,
  117853. _vq_lengthlist__44c6_s_p3_0,
  117854. 1, -531628032, 1611661312, 4, 0,
  117855. _vq_quantlist__44c6_s_p3_0,
  117856. NULL,
  117857. &_vq_auxt__44c6_s_p3_0,
  117858. NULL,
  117859. 0
  117860. };
  117861. static long _vq_quantlist__44c6_s_p4_0[] = {
  117862. 8,
  117863. 7,
  117864. 9,
  117865. 6,
  117866. 10,
  117867. 5,
  117868. 11,
  117869. 4,
  117870. 12,
  117871. 3,
  117872. 13,
  117873. 2,
  117874. 14,
  117875. 1,
  117876. 15,
  117877. 0,
  117878. 16,
  117879. };
  117880. static long _vq_lengthlist__44c6_s_p4_0[] = {
  117881. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  117882. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  117883. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  117884. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117885. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117886. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117887. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  117888. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  117889. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  117890. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  117891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117899. 0,
  117900. };
  117901. static float _vq_quantthresh__44c6_s_p4_0[] = {
  117902. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117903. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117904. };
  117905. static long _vq_quantmap__44c6_s_p4_0[] = {
  117906. 15, 13, 11, 9, 7, 5, 3, 1,
  117907. 0, 2, 4, 6, 8, 10, 12, 14,
  117908. 16,
  117909. };
  117910. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  117911. _vq_quantthresh__44c6_s_p4_0,
  117912. _vq_quantmap__44c6_s_p4_0,
  117913. 17,
  117914. 17
  117915. };
  117916. static static_codebook _44c6_s_p4_0 = {
  117917. 2, 289,
  117918. _vq_lengthlist__44c6_s_p4_0,
  117919. 1, -529530880, 1611661312, 5, 0,
  117920. _vq_quantlist__44c6_s_p4_0,
  117921. NULL,
  117922. &_vq_auxt__44c6_s_p4_0,
  117923. NULL,
  117924. 0
  117925. };
  117926. static long _vq_quantlist__44c6_s_p5_0[] = {
  117927. 1,
  117928. 0,
  117929. 2,
  117930. };
  117931. static long _vq_lengthlist__44c6_s_p5_0[] = {
  117932. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  117933. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  117934. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  117935. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  117936. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  117937. 12,
  117938. };
  117939. static float _vq_quantthresh__44c6_s_p5_0[] = {
  117940. -5.5, 5.5,
  117941. };
  117942. static long _vq_quantmap__44c6_s_p5_0[] = {
  117943. 1, 0, 2,
  117944. };
  117945. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  117946. _vq_quantthresh__44c6_s_p5_0,
  117947. _vq_quantmap__44c6_s_p5_0,
  117948. 3,
  117949. 3
  117950. };
  117951. static static_codebook _44c6_s_p5_0 = {
  117952. 4, 81,
  117953. _vq_lengthlist__44c6_s_p5_0,
  117954. 1, -529137664, 1618345984, 2, 0,
  117955. _vq_quantlist__44c6_s_p5_0,
  117956. NULL,
  117957. &_vq_auxt__44c6_s_p5_0,
  117958. NULL,
  117959. 0
  117960. };
  117961. static long _vq_quantlist__44c6_s_p5_1[] = {
  117962. 5,
  117963. 4,
  117964. 6,
  117965. 3,
  117966. 7,
  117967. 2,
  117968. 8,
  117969. 1,
  117970. 9,
  117971. 0,
  117972. 10,
  117973. };
  117974. static long _vq_lengthlist__44c6_s_p5_1[] = {
  117975. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  117976. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  117977. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  117978. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  117979. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  117980. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  117981. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  117982. 11,10,10, 7, 7, 8, 8, 8, 8,
  117983. };
  117984. static float _vq_quantthresh__44c6_s_p5_1[] = {
  117985. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117986. 3.5, 4.5,
  117987. };
  117988. static long _vq_quantmap__44c6_s_p5_1[] = {
  117989. 9, 7, 5, 3, 1, 0, 2, 4,
  117990. 6, 8, 10,
  117991. };
  117992. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  117993. _vq_quantthresh__44c6_s_p5_1,
  117994. _vq_quantmap__44c6_s_p5_1,
  117995. 11,
  117996. 11
  117997. };
  117998. static static_codebook _44c6_s_p5_1 = {
  117999. 2, 121,
  118000. _vq_lengthlist__44c6_s_p5_1,
  118001. 1, -531365888, 1611661312, 4, 0,
  118002. _vq_quantlist__44c6_s_p5_1,
  118003. NULL,
  118004. &_vq_auxt__44c6_s_p5_1,
  118005. NULL,
  118006. 0
  118007. };
  118008. static long _vq_quantlist__44c6_s_p6_0[] = {
  118009. 6,
  118010. 5,
  118011. 7,
  118012. 4,
  118013. 8,
  118014. 3,
  118015. 9,
  118016. 2,
  118017. 10,
  118018. 1,
  118019. 11,
  118020. 0,
  118021. 12,
  118022. };
  118023. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118024. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118025. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118026. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118027. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118028. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118029. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118034. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118035. };
  118036. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118037. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118038. 12.5, 17.5, 22.5, 27.5,
  118039. };
  118040. static long _vq_quantmap__44c6_s_p6_0[] = {
  118041. 11, 9, 7, 5, 3, 1, 0, 2,
  118042. 4, 6, 8, 10, 12,
  118043. };
  118044. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118045. _vq_quantthresh__44c6_s_p6_0,
  118046. _vq_quantmap__44c6_s_p6_0,
  118047. 13,
  118048. 13
  118049. };
  118050. static static_codebook _44c6_s_p6_0 = {
  118051. 2, 169,
  118052. _vq_lengthlist__44c6_s_p6_0,
  118053. 1, -526516224, 1616117760, 4, 0,
  118054. _vq_quantlist__44c6_s_p6_0,
  118055. NULL,
  118056. &_vq_auxt__44c6_s_p6_0,
  118057. NULL,
  118058. 0
  118059. };
  118060. static long _vq_quantlist__44c6_s_p6_1[] = {
  118061. 2,
  118062. 1,
  118063. 3,
  118064. 0,
  118065. 4,
  118066. };
  118067. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118068. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118069. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118070. };
  118071. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118072. -1.5, -0.5, 0.5, 1.5,
  118073. };
  118074. static long _vq_quantmap__44c6_s_p6_1[] = {
  118075. 3, 1, 0, 2, 4,
  118076. };
  118077. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118078. _vq_quantthresh__44c6_s_p6_1,
  118079. _vq_quantmap__44c6_s_p6_1,
  118080. 5,
  118081. 5
  118082. };
  118083. static static_codebook _44c6_s_p6_1 = {
  118084. 2, 25,
  118085. _vq_lengthlist__44c6_s_p6_1,
  118086. 1, -533725184, 1611661312, 3, 0,
  118087. _vq_quantlist__44c6_s_p6_1,
  118088. NULL,
  118089. &_vq_auxt__44c6_s_p6_1,
  118090. NULL,
  118091. 0
  118092. };
  118093. static long _vq_quantlist__44c6_s_p7_0[] = {
  118094. 6,
  118095. 5,
  118096. 7,
  118097. 4,
  118098. 8,
  118099. 3,
  118100. 9,
  118101. 2,
  118102. 10,
  118103. 1,
  118104. 11,
  118105. 0,
  118106. 12,
  118107. };
  118108. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118109. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118110. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118111. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118112. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118113. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118114. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118115. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118116. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118117. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118118. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118119. 20,13,13,13,13,13,13,14,14,
  118120. };
  118121. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118122. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118123. 27.5, 38.5, 49.5, 60.5,
  118124. };
  118125. static long _vq_quantmap__44c6_s_p7_0[] = {
  118126. 11, 9, 7, 5, 3, 1, 0, 2,
  118127. 4, 6, 8, 10, 12,
  118128. };
  118129. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118130. _vq_quantthresh__44c6_s_p7_0,
  118131. _vq_quantmap__44c6_s_p7_0,
  118132. 13,
  118133. 13
  118134. };
  118135. static static_codebook _44c6_s_p7_0 = {
  118136. 2, 169,
  118137. _vq_lengthlist__44c6_s_p7_0,
  118138. 1, -523206656, 1618345984, 4, 0,
  118139. _vq_quantlist__44c6_s_p7_0,
  118140. NULL,
  118141. &_vq_auxt__44c6_s_p7_0,
  118142. NULL,
  118143. 0
  118144. };
  118145. static long _vq_quantlist__44c6_s_p7_1[] = {
  118146. 5,
  118147. 4,
  118148. 6,
  118149. 3,
  118150. 7,
  118151. 2,
  118152. 8,
  118153. 1,
  118154. 9,
  118155. 0,
  118156. 10,
  118157. };
  118158. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118159. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118160. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118161. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118162. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118163. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118164. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118165. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118166. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118167. };
  118168. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118169. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118170. 3.5, 4.5,
  118171. };
  118172. static long _vq_quantmap__44c6_s_p7_1[] = {
  118173. 9, 7, 5, 3, 1, 0, 2, 4,
  118174. 6, 8, 10,
  118175. };
  118176. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118177. _vq_quantthresh__44c6_s_p7_1,
  118178. _vq_quantmap__44c6_s_p7_1,
  118179. 11,
  118180. 11
  118181. };
  118182. static static_codebook _44c6_s_p7_1 = {
  118183. 2, 121,
  118184. _vq_lengthlist__44c6_s_p7_1,
  118185. 1, -531365888, 1611661312, 4, 0,
  118186. _vq_quantlist__44c6_s_p7_1,
  118187. NULL,
  118188. &_vq_auxt__44c6_s_p7_1,
  118189. NULL,
  118190. 0
  118191. };
  118192. static long _vq_quantlist__44c6_s_p8_0[] = {
  118193. 7,
  118194. 6,
  118195. 8,
  118196. 5,
  118197. 9,
  118198. 4,
  118199. 10,
  118200. 3,
  118201. 11,
  118202. 2,
  118203. 12,
  118204. 1,
  118205. 13,
  118206. 0,
  118207. 14,
  118208. };
  118209. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118210. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118211. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118212. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118213. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118214. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118215. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118216. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118217. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118218. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118219. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118220. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118221. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118222. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118223. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118224. 14,
  118225. };
  118226. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118227. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118228. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118229. };
  118230. static long _vq_quantmap__44c6_s_p8_0[] = {
  118231. 13, 11, 9, 7, 5, 3, 1, 0,
  118232. 2, 4, 6, 8, 10, 12, 14,
  118233. };
  118234. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118235. _vq_quantthresh__44c6_s_p8_0,
  118236. _vq_quantmap__44c6_s_p8_0,
  118237. 15,
  118238. 15
  118239. };
  118240. static static_codebook _44c6_s_p8_0 = {
  118241. 2, 225,
  118242. _vq_lengthlist__44c6_s_p8_0,
  118243. 1, -520986624, 1620377600, 4, 0,
  118244. _vq_quantlist__44c6_s_p8_0,
  118245. NULL,
  118246. &_vq_auxt__44c6_s_p8_0,
  118247. NULL,
  118248. 0
  118249. };
  118250. static long _vq_quantlist__44c6_s_p8_1[] = {
  118251. 10,
  118252. 9,
  118253. 11,
  118254. 8,
  118255. 12,
  118256. 7,
  118257. 13,
  118258. 6,
  118259. 14,
  118260. 5,
  118261. 15,
  118262. 4,
  118263. 16,
  118264. 3,
  118265. 17,
  118266. 2,
  118267. 18,
  118268. 1,
  118269. 19,
  118270. 0,
  118271. 20,
  118272. };
  118273. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118274. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118275. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118276. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118277. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118278. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118279. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118280. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118281. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118282. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118283. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118284. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118285. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118286. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118287. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118288. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118289. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118290. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118291. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118292. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118293. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118294. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118295. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118296. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118297. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118298. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118299. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118300. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118301. 10,10,10,10,10,10,10,10,10,
  118302. };
  118303. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118304. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118305. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118306. 6.5, 7.5, 8.5, 9.5,
  118307. };
  118308. static long _vq_quantmap__44c6_s_p8_1[] = {
  118309. 19, 17, 15, 13, 11, 9, 7, 5,
  118310. 3, 1, 0, 2, 4, 6, 8, 10,
  118311. 12, 14, 16, 18, 20,
  118312. };
  118313. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118314. _vq_quantthresh__44c6_s_p8_1,
  118315. _vq_quantmap__44c6_s_p8_1,
  118316. 21,
  118317. 21
  118318. };
  118319. static static_codebook _44c6_s_p8_1 = {
  118320. 2, 441,
  118321. _vq_lengthlist__44c6_s_p8_1,
  118322. 1, -529268736, 1611661312, 5, 0,
  118323. _vq_quantlist__44c6_s_p8_1,
  118324. NULL,
  118325. &_vq_auxt__44c6_s_p8_1,
  118326. NULL,
  118327. 0
  118328. };
  118329. static long _vq_quantlist__44c6_s_p9_0[] = {
  118330. 6,
  118331. 5,
  118332. 7,
  118333. 4,
  118334. 8,
  118335. 3,
  118336. 9,
  118337. 2,
  118338. 10,
  118339. 1,
  118340. 11,
  118341. 0,
  118342. 12,
  118343. };
  118344. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118345. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118346. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118347. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118348. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118349. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118350. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118351. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118352. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118353. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118354. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118355. 10,10,10,10,10,10,10,10,10,
  118356. };
  118357. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118358. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118359. 1592.5, 2229.5, 2866.5, 3503.5,
  118360. };
  118361. static long _vq_quantmap__44c6_s_p9_0[] = {
  118362. 11, 9, 7, 5, 3, 1, 0, 2,
  118363. 4, 6, 8, 10, 12,
  118364. };
  118365. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118366. _vq_quantthresh__44c6_s_p9_0,
  118367. _vq_quantmap__44c6_s_p9_0,
  118368. 13,
  118369. 13
  118370. };
  118371. static static_codebook _44c6_s_p9_0 = {
  118372. 2, 169,
  118373. _vq_lengthlist__44c6_s_p9_0,
  118374. 1, -511845376, 1630791680, 4, 0,
  118375. _vq_quantlist__44c6_s_p9_0,
  118376. NULL,
  118377. &_vq_auxt__44c6_s_p9_0,
  118378. NULL,
  118379. 0
  118380. };
  118381. static long _vq_quantlist__44c6_s_p9_1[] = {
  118382. 6,
  118383. 5,
  118384. 7,
  118385. 4,
  118386. 8,
  118387. 3,
  118388. 9,
  118389. 2,
  118390. 10,
  118391. 1,
  118392. 11,
  118393. 0,
  118394. 12,
  118395. };
  118396. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118397. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118398. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118399. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118400. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118401. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118402. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118403. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118404. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118405. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118406. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118407. 15,12,10,11,11,13,11,12,13,
  118408. };
  118409. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118410. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118411. 122.5, 171.5, 220.5, 269.5,
  118412. };
  118413. static long _vq_quantmap__44c6_s_p9_1[] = {
  118414. 11, 9, 7, 5, 3, 1, 0, 2,
  118415. 4, 6, 8, 10, 12,
  118416. };
  118417. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118418. _vq_quantthresh__44c6_s_p9_1,
  118419. _vq_quantmap__44c6_s_p9_1,
  118420. 13,
  118421. 13
  118422. };
  118423. static static_codebook _44c6_s_p9_1 = {
  118424. 2, 169,
  118425. _vq_lengthlist__44c6_s_p9_1,
  118426. 1, -518889472, 1622704128, 4, 0,
  118427. _vq_quantlist__44c6_s_p9_1,
  118428. NULL,
  118429. &_vq_auxt__44c6_s_p9_1,
  118430. NULL,
  118431. 0
  118432. };
  118433. static long _vq_quantlist__44c6_s_p9_2[] = {
  118434. 24,
  118435. 23,
  118436. 25,
  118437. 22,
  118438. 26,
  118439. 21,
  118440. 27,
  118441. 20,
  118442. 28,
  118443. 19,
  118444. 29,
  118445. 18,
  118446. 30,
  118447. 17,
  118448. 31,
  118449. 16,
  118450. 32,
  118451. 15,
  118452. 33,
  118453. 14,
  118454. 34,
  118455. 13,
  118456. 35,
  118457. 12,
  118458. 36,
  118459. 11,
  118460. 37,
  118461. 10,
  118462. 38,
  118463. 9,
  118464. 39,
  118465. 8,
  118466. 40,
  118467. 7,
  118468. 41,
  118469. 6,
  118470. 42,
  118471. 5,
  118472. 43,
  118473. 4,
  118474. 44,
  118475. 3,
  118476. 45,
  118477. 2,
  118478. 46,
  118479. 1,
  118480. 47,
  118481. 0,
  118482. 48,
  118483. };
  118484. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118485. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118486. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118487. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118488. 7,
  118489. };
  118490. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118491. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118492. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118493. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118494. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118495. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118496. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118497. };
  118498. static long _vq_quantmap__44c6_s_p9_2[] = {
  118499. 47, 45, 43, 41, 39, 37, 35, 33,
  118500. 31, 29, 27, 25, 23, 21, 19, 17,
  118501. 15, 13, 11, 9, 7, 5, 3, 1,
  118502. 0, 2, 4, 6, 8, 10, 12, 14,
  118503. 16, 18, 20, 22, 24, 26, 28, 30,
  118504. 32, 34, 36, 38, 40, 42, 44, 46,
  118505. 48,
  118506. };
  118507. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118508. _vq_quantthresh__44c6_s_p9_2,
  118509. _vq_quantmap__44c6_s_p9_2,
  118510. 49,
  118511. 49
  118512. };
  118513. static static_codebook _44c6_s_p9_2 = {
  118514. 1, 49,
  118515. _vq_lengthlist__44c6_s_p9_2,
  118516. 1, -526909440, 1611661312, 6, 0,
  118517. _vq_quantlist__44c6_s_p9_2,
  118518. NULL,
  118519. &_vq_auxt__44c6_s_p9_2,
  118520. NULL,
  118521. 0
  118522. };
  118523. static long _huff_lengthlist__44c6_s_short[] = {
  118524. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118525. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118526. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118527. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118528. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118529. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118530. 9,10,17,18,
  118531. };
  118532. static static_codebook _huff_book__44c6_s_short = {
  118533. 2, 100,
  118534. _huff_lengthlist__44c6_s_short,
  118535. 0, 0, 0, 0, 0,
  118536. NULL,
  118537. NULL,
  118538. NULL,
  118539. NULL,
  118540. 0
  118541. };
  118542. static long _huff_lengthlist__44c7_s_long[] = {
  118543. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118544. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118545. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118546. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118547. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118548. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118549. 11,10,10,12,
  118550. };
  118551. static static_codebook _huff_book__44c7_s_long = {
  118552. 2, 100,
  118553. _huff_lengthlist__44c7_s_long,
  118554. 0, 0, 0, 0, 0,
  118555. NULL,
  118556. NULL,
  118557. NULL,
  118558. NULL,
  118559. 0
  118560. };
  118561. static long _vq_quantlist__44c7_s_p1_0[] = {
  118562. 1,
  118563. 0,
  118564. 2,
  118565. };
  118566. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118567. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118568. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118569. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118570. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118571. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118572. 8,
  118573. };
  118574. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118575. -0.5, 0.5,
  118576. };
  118577. static long _vq_quantmap__44c7_s_p1_0[] = {
  118578. 1, 0, 2,
  118579. };
  118580. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118581. _vq_quantthresh__44c7_s_p1_0,
  118582. _vq_quantmap__44c7_s_p1_0,
  118583. 3,
  118584. 3
  118585. };
  118586. static static_codebook _44c7_s_p1_0 = {
  118587. 4, 81,
  118588. _vq_lengthlist__44c7_s_p1_0,
  118589. 1, -535822336, 1611661312, 2, 0,
  118590. _vq_quantlist__44c7_s_p1_0,
  118591. NULL,
  118592. &_vq_auxt__44c7_s_p1_0,
  118593. NULL,
  118594. 0
  118595. };
  118596. static long _vq_quantlist__44c7_s_p2_0[] = {
  118597. 2,
  118598. 1,
  118599. 3,
  118600. 0,
  118601. 4,
  118602. };
  118603. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118604. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118605. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118606. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118607. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118608. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118609. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118610. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118611. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118613. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118614. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118615. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118616. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118617. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118618. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118619. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118621. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118622. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118623. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118624. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118625. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118626. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118627. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118629. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118630. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118631. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118632. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118633. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118634. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118635. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118640. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118641. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118642. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118643. 13,
  118644. };
  118645. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118646. -1.5, -0.5, 0.5, 1.5,
  118647. };
  118648. static long _vq_quantmap__44c7_s_p2_0[] = {
  118649. 3, 1, 0, 2, 4,
  118650. };
  118651. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118652. _vq_quantthresh__44c7_s_p2_0,
  118653. _vq_quantmap__44c7_s_p2_0,
  118654. 5,
  118655. 5
  118656. };
  118657. static static_codebook _44c7_s_p2_0 = {
  118658. 4, 625,
  118659. _vq_lengthlist__44c7_s_p2_0,
  118660. 1, -533725184, 1611661312, 3, 0,
  118661. _vq_quantlist__44c7_s_p2_0,
  118662. NULL,
  118663. &_vq_auxt__44c7_s_p2_0,
  118664. NULL,
  118665. 0
  118666. };
  118667. static long _vq_quantlist__44c7_s_p3_0[] = {
  118668. 4,
  118669. 3,
  118670. 5,
  118671. 2,
  118672. 6,
  118673. 1,
  118674. 7,
  118675. 0,
  118676. 8,
  118677. };
  118678. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118679. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118680. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118681. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118682. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118684. 0,
  118685. };
  118686. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118687. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118688. };
  118689. static long _vq_quantmap__44c7_s_p3_0[] = {
  118690. 7, 5, 3, 1, 0, 2, 4, 6,
  118691. 8,
  118692. };
  118693. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  118694. _vq_quantthresh__44c7_s_p3_0,
  118695. _vq_quantmap__44c7_s_p3_0,
  118696. 9,
  118697. 9
  118698. };
  118699. static static_codebook _44c7_s_p3_0 = {
  118700. 2, 81,
  118701. _vq_lengthlist__44c7_s_p3_0,
  118702. 1, -531628032, 1611661312, 4, 0,
  118703. _vq_quantlist__44c7_s_p3_0,
  118704. NULL,
  118705. &_vq_auxt__44c7_s_p3_0,
  118706. NULL,
  118707. 0
  118708. };
  118709. static long _vq_quantlist__44c7_s_p4_0[] = {
  118710. 8,
  118711. 7,
  118712. 9,
  118713. 6,
  118714. 10,
  118715. 5,
  118716. 11,
  118717. 4,
  118718. 12,
  118719. 3,
  118720. 13,
  118721. 2,
  118722. 14,
  118723. 1,
  118724. 15,
  118725. 0,
  118726. 16,
  118727. };
  118728. static long _vq_lengthlist__44c7_s_p4_0[] = {
  118729. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  118730. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  118731. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  118732. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  118733. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  118734. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  118735. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  118736. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118737. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  118738. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  118739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118747. 0,
  118748. };
  118749. static float _vq_quantthresh__44c7_s_p4_0[] = {
  118750. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118751. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118752. };
  118753. static long _vq_quantmap__44c7_s_p4_0[] = {
  118754. 15, 13, 11, 9, 7, 5, 3, 1,
  118755. 0, 2, 4, 6, 8, 10, 12, 14,
  118756. 16,
  118757. };
  118758. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  118759. _vq_quantthresh__44c7_s_p4_0,
  118760. _vq_quantmap__44c7_s_p4_0,
  118761. 17,
  118762. 17
  118763. };
  118764. static static_codebook _44c7_s_p4_0 = {
  118765. 2, 289,
  118766. _vq_lengthlist__44c7_s_p4_0,
  118767. 1, -529530880, 1611661312, 5, 0,
  118768. _vq_quantlist__44c7_s_p4_0,
  118769. NULL,
  118770. &_vq_auxt__44c7_s_p4_0,
  118771. NULL,
  118772. 0
  118773. };
  118774. static long _vq_quantlist__44c7_s_p5_0[] = {
  118775. 1,
  118776. 0,
  118777. 2,
  118778. };
  118779. static long _vq_lengthlist__44c7_s_p5_0[] = {
  118780. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  118781. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  118782. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  118783. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118784. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  118785. 12,
  118786. };
  118787. static float _vq_quantthresh__44c7_s_p5_0[] = {
  118788. -5.5, 5.5,
  118789. };
  118790. static long _vq_quantmap__44c7_s_p5_0[] = {
  118791. 1, 0, 2,
  118792. };
  118793. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  118794. _vq_quantthresh__44c7_s_p5_0,
  118795. _vq_quantmap__44c7_s_p5_0,
  118796. 3,
  118797. 3
  118798. };
  118799. static static_codebook _44c7_s_p5_0 = {
  118800. 4, 81,
  118801. _vq_lengthlist__44c7_s_p5_0,
  118802. 1, -529137664, 1618345984, 2, 0,
  118803. _vq_quantlist__44c7_s_p5_0,
  118804. NULL,
  118805. &_vq_auxt__44c7_s_p5_0,
  118806. NULL,
  118807. 0
  118808. };
  118809. static long _vq_quantlist__44c7_s_p5_1[] = {
  118810. 5,
  118811. 4,
  118812. 6,
  118813. 3,
  118814. 7,
  118815. 2,
  118816. 8,
  118817. 1,
  118818. 9,
  118819. 0,
  118820. 10,
  118821. };
  118822. static long _vq_lengthlist__44c7_s_p5_1[] = {
  118823. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118824. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  118825. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  118826. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  118827. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  118828. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  118829. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  118830. 11,11,11, 7, 7, 8, 8, 8, 8,
  118831. };
  118832. static float _vq_quantthresh__44c7_s_p5_1[] = {
  118833. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118834. 3.5, 4.5,
  118835. };
  118836. static long _vq_quantmap__44c7_s_p5_1[] = {
  118837. 9, 7, 5, 3, 1, 0, 2, 4,
  118838. 6, 8, 10,
  118839. };
  118840. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  118841. _vq_quantthresh__44c7_s_p5_1,
  118842. _vq_quantmap__44c7_s_p5_1,
  118843. 11,
  118844. 11
  118845. };
  118846. static static_codebook _44c7_s_p5_1 = {
  118847. 2, 121,
  118848. _vq_lengthlist__44c7_s_p5_1,
  118849. 1, -531365888, 1611661312, 4, 0,
  118850. _vq_quantlist__44c7_s_p5_1,
  118851. NULL,
  118852. &_vq_auxt__44c7_s_p5_1,
  118853. NULL,
  118854. 0
  118855. };
  118856. static long _vq_quantlist__44c7_s_p6_0[] = {
  118857. 6,
  118858. 5,
  118859. 7,
  118860. 4,
  118861. 8,
  118862. 3,
  118863. 9,
  118864. 2,
  118865. 10,
  118866. 1,
  118867. 11,
  118868. 0,
  118869. 12,
  118870. };
  118871. static long _vq_lengthlist__44c7_s_p6_0[] = {
  118872. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  118873. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  118874. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  118875. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  118876. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  118877. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  118878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118882. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118883. };
  118884. static float _vq_quantthresh__44c7_s_p6_0[] = {
  118885. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118886. 12.5, 17.5, 22.5, 27.5,
  118887. };
  118888. static long _vq_quantmap__44c7_s_p6_0[] = {
  118889. 11, 9, 7, 5, 3, 1, 0, 2,
  118890. 4, 6, 8, 10, 12,
  118891. };
  118892. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  118893. _vq_quantthresh__44c7_s_p6_0,
  118894. _vq_quantmap__44c7_s_p6_0,
  118895. 13,
  118896. 13
  118897. };
  118898. static static_codebook _44c7_s_p6_0 = {
  118899. 2, 169,
  118900. _vq_lengthlist__44c7_s_p6_0,
  118901. 1, -526516224, 1616117760, 4, 0,
  118902. _vq_quantlist__44c7_s_p6_0,
  118903. NULL,
  118904. &_vq_auxt__44c7_s_p6_0,
  118905. NULL,
  118906. 0
  118907. };
  118908. static long _vq_quantlist__44c7_s_p6_1[] = {
  118909. 2,
  118910. 1,
  118911. 3,
  118912. 0,
  118913. 4,
  118914. };
  118915. static long _vq_lengthlist__44c7_s_p6_1[] = {
  118916. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118917. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118918. };
  118919. static float _vq_quantthresh__44c7_s_p6_1[] = {
  118920. -1.5, -0.5, 0.5, 1.5,
  118921. };
  118922. static long _vq_quantmap__44c7_s_p6_1[] = {
  118923. 3, 1, 0, 2, 4,
  118924. };
  118925. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  118926. _vq_quantthresh__44c7_s_p6_1,
  118927. _vq_quantmap__44c7_s_p6_1,
  118928. 5,
  118929. 5
  118930. };
  118931. static static_codebook _44c7_s_p6_1 = {
  118932. 2, 25,
  118933. _vq_lengthlist__44c7_s_p6_1,
  118934. 1, -533725184, 1611661312, 3, 0,
  118935. _vq_quantlist__44c7_s_p6_1,
  118936. NULL,
  118937. &_vq_auxt__44c7_s_p6_1,
  118938. NULL,
  118939. 0
  118940. };
  118941. static long _vq_quantlist__44c7_s_p7_0[] = {
  118942. 6,
  118943. 5,
  118944. 7,
  118945. 4,
  118946. 8,
  118947. 3,
  118948. 9,
  118949. 2,
  118950. 10,
  118951. 1,
  118952. 11,
  118953. 0,
  118954. 12,
  118955. };
  118956. static long _vq_lengthlist__44c7_s_p7_0[] = {
  118957. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  118958. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  118959. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  118960. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  118961. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  118962. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  118963. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  118964. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  118965. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  118966. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  118967. 19,13,13,13,13,14,14,15,15,
  118968. };
  118969. static float _vq_quantthresh__44c7_s_p7_0[] = {
  118970. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118971. 27.5, 38.5, 49.5, 60.5,
  118972. };
  118973. static long _vq_quantmap__44c7_s_p7_0[] = {
  118974. 11, 9, 7, 5, 3, 1, 0, 2,
  118975. 4, 6, 8, 10, 12,
  118976. };
  118977. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  118978. _vq_quantthresh__44c7_s_p7_0,
  118979. _vq_quantmap__44c7_s_p7_0,
  118980. 13,
  118981. 13
  118982. };
  118983. static static_codebook _44c7_s_p7_0 = {
  118984. 2, 169,
  118985. _vq_lengthlist__44c7_s_p7_0,
  118986. 1, -523206656, 1618345984, 4, 0,
  118987. _vq_quantlist__44c7_s_p7_0,
  118988. NULL,
  118989. &_vq_auxt__44c7_s_p7_0,
  118990. NULL,
  118991. 0
  118992. };
  118993. static long _vq_quantlist__44c7_s_p7_1[] = {
  118994. 5,
  118995. 4,
  118996. 6,
  118997. 3,
  118998. 7,
  118999. 2,
  119000. 8,
  119001. 1,
  119002. 9,
  119003. 0,
  119004. 10,
  119005. };
  119006. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119007. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119008. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119009. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119010. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119011. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119012. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119013. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119014. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119015. };
  119016. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119017. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119018. 3.5, 4.5,
  119019. };
  119020. static long _vq_quantmap__44c7_s_p7_1[] = {
  119021. 9, 7, 5, 3, 1, 0, 2, 4,
  119022. 6, 8, 10,
  119023. };
  119024. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119025. _vq_quantthresh__44c7_s_p7_1,
  119026. _vq_quantmap__44c7_s_p7_1,
  119027. 11,
  119028. 11
  119029. };
  119030. static static_codebook _44c7_s_p7_1 = {
  119031. 2, 121,
  119032. _vq_lengthlist__44c7_s_p7_1,
  119033. 1, -531365888, 1611661312, 4, 0,
  119034. _vq_quantlist__44c7_s_p7_1,
  119035. NULL,
  119036. &_vq_auxt__44c7_s_p7_1,
  119037. NULL,
  119038. 0
  119039. };
  119040. static long _vq_quantlist__44c7_s_p8_0[] = {
  119041. 7,
  119042. 6,
  119043. 8,
  119044. 5,
  119045. 9,
  119046. 4,
  119047. 10,
  119048. 3,
  119049. 11,
  119050. 2,
  119051. 12,
  119052. 1,
  119053. 13,
  119054. 0,
  119055. 14,
  119056. };
  119057. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119058. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119059. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119060. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119061. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119062. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119063. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119064. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119065. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119066. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119067. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119068. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119069. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119070. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119071. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119072. 14,
  119073. };
  119074. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119075. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119076. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119077. };
  119078. static long _vq_quantmap__44c7_s_p8_0[] = {
  119079. 13, 11, 9, 7, 5, 3, 1, 0,
  119080. 2, 4, 6, 8, 10, 12, 14,
  119081. };
  119082. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119083. _vq_quantthresh__44c7_s_p8_0,
  119084. _vq_quantmap__44c7_s_p8_0,
  119085. 15,
  119086. 15
  119087. };
  119088. static static_codebook _44c7_s_p8_0 = {
  119089. 2, 225,
  119090. _vq_lengthlist__44c7_s_p8_0,
  119091. 1, -520986624, 1620377600, 4, 0,
  119092. _vq_quantlist__44c7_s_p8_0,
  119093. NULL,
  119094. &_vq_auxt__44c7_s_p8_0,
  119095. NULL,
  119096. 0
  119097. };
  119098. static long _vq_quantlist__44c7_s_p8_1[] = {
  119099. 10,
  119100. 9,
  119101. 11,
  119102. 8,
  119103. 12,
  119104. 7,
  119105. 13,
  119106. 6,
  119107. 14,
  119108. 5,
  119109. 15,
  119110. 4,
  119111. 16,
  119112. 3,
  119113. 17,
  119114. 2,
  119115. 18,
  119116. 1,
  119117. 19,
  119118. 0,
  119119. 20,
  119120. };
  119121. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119122. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119123. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119124. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119125. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119126. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119127. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119128. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119129. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119130. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119131. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119132. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119133. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119134. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119135. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119136. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119137. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119138. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119139. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119140. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119141. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119142. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119143. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119144. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119145. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119146. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119147. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119148. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119149. 10,10,10,10,10,10,10,10,10,
  119150. };
  119151. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119152. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119153. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119154. 6.5, 7.5, 8.5, 9.5,
  119155. };
  119156. static long _vq_quantmap__44c7_s_p8_1[] = {
  119157. 19, 17, 15, 13, 11, 9, 7, 5,
  119158. 3, 1, 0, 2, 4, 6, 8, 10,
  119159. 12, 14, 16, 18, 20,
  119160. };
  119161. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119162. _vq_quantthresh__44c7_s_p8_1,
  119163. _vq_quantmap__44c7_s_p8_1,
  119164. 21,
  119165. 21
  119166. };
  119167. static static_codebook _44c7_s_p8_1 = {
  119168. 2, 441,
  119169. _vq_lengthlist__44c7_s_p8_1,
  119170. 1, -529268736, 1611661312, 5, 0,
  119171. _vq_quantlist__44c7_s_p8_1,
  119172. NULL,
  119173. &_vq_auxt__44c7_s_p8_1,
  119174. NULL,
  119175. 0
  119176. };
  119177. static long _vq_quantlist__44c7_s_p9_0[] = {
  119178. 6,
  119179. 5,
  119180. 7,
  119181. 4,
  119182. 8,
  119183. 3,
  119184. 9,
  119185. 2,
  119186. 10,
  119187. 1,
  119188. 11,
  119189. 0,
  119190. 12,
  119191. };
  119192. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119193. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119194. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119195. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119196. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119197. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119198. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119199. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119200. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119201. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119202. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119203. 11,11,11,11,11,11,11,11,11,
  119204. };
  119205. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119206. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119207. 1592.5, 2229.5, 2866.5, 3503.5,
  119208. };
  119209. static long _vq_quantmap__44c7_s_p9_0[] = {
  119210. 11, 9, 7, 5, 3, 1, 0, 2,
  119211. 4, 6, 8, 10, 12,
  119212. };
  119213. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119214. _vq_quantthresh__44c7_s_p9_0,
  119215. _vq_quantmap__44c7_s_p9_0,
  119216. 13,
  119217. 13
  119218. };
  119219. static static_codebook _44c7_s_p9_0 = {
  119220. 2, 169,
  119221. _vq_lengthlist__44c7_s_p9_0,
  119222. 1, -511845376, 1630791680, 4, 0,
  119223. _vq_quantlist__44c7_s_p9_0,
  119224. NULL,
  119225. &_vq_auxt__44c7_s_p9_0,
  119226. NULL,
  119227. 0
  119228. };
  119229. static long _vq_quantlist__44c7_s_p9_1[] = {
  119230. 6,
  119231. 5,
  119232. 7,
  119233. 4,
  119234. 8,
  119235. 3,
  119236. 9,
  119237. 2,
  119238. 10,
  119239. 1,
  119240. 11,
  119241. 0,
  119242. 12,
  119243. };
  119244. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119245. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119246. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119247. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119248. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119249. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119250. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119251. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119252. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119253. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119254. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119255. 15,11,11,10,10,12,12,12,12,
  119256. };
  119257. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119258. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119259. 122.5, 171.5, 220.5, 269.5,
  119260. };
  119261. static long _vq_quantmap__44c7_s_p9_1[] = {
  119262. 11, 9, 7, 5, 3, 1, 0, 2,
  119263. 4, 6, 8, 10, 12,
  119264. };
  119265. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119266. _vq_quantthresh__44c7_s_p9_1,
  119267. _vq_quantmap__44c7_s_p9_1,
  119268. 13,
  119269. 13
  119270. };
  119271. static static_codebook _44c7_s_p9_1 = {
  119272. 2, 169,
  119273. _vq_lengthlist__44c7_s_p9_1,
  119274. 1, -518889472, 1622704128, 4, 0,
  119275. _vq_quantlist__44c7_s_p9_1,
  119276. NULL,
  119277. &_vq_auxt__44c7_s_p9_1,
  119278. NULL,
  119279. 0
  119280. };
  119281. static long _vq_quantlist__44c7_s_p9_2[] = {
  119282. 24,
  119283. 23,
  119284. 25,
  119285. 22,
  119286. 26,
  119287. 21,
  119288. 27,
  119289. 20,
  119290. 28,
  119291. 19,
  119292. 29,
  119293. 18,
  119294. 30,
  119295. 17,
  119296. 31,
  119297. 16,
  119298. 32,
  119299. 15,
  119300. 33,
  119301. 14,
  119302. 34,
  119303. 13,
  119304. 35,
  119305. 12,
  119306. 36,
  119307. 11,
  119308. 37,
  119309. 10,
  119310. 38,
  119311. 9,
  119312. 39,
  119313. 8,
  119314. 40,
  119315. 7,
  119316. 41,
  119317. 6,
  119318. 42,
  119319. 5,
  119320. 43,
  119321. 4,
  119322. 44,
  119323. 3,
  119324. 45,
  119325. 2,
  119326. 46,
  119327. 1,
  119328. 47,
  119329. 0,
  119330. 48,
  119331. };
  119332. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119333. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119334. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119335. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119336. 7,
  119337. };
  119338. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119339. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119340. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119341. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119342. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119343. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119344. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119345. };
  119346. static long _vq_quantmap__44c7_s_p9_2[] = {
  119347. 47, 45, 43, 41, 39, 37, 35, 33,
  119348. 31, 29, 27, 25, 23, 21, 19, 17,
  119349. 15, 13, 11, 9, 7, 5, 3, 1,
  119350. 0, 2, 4, 6, 8, 10, 12, 14,
  119351. 16, 18, 20, 22, 24, 26, 28, 30,
  119352. 32, 34, 36, 38, 40, 42, 44, 46,
  119353. 48,
  119354. };
  119355. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119356. _vq_quantthresh__44c7_s_p9_2,
  119357. _vq_quantmap__44c7_s_p9_2,
  119358. 49,
  119359. 49
  119360. };
  119361. static static_codebook _44c7_s_p9_2 = {
  119362. 1, 49,
  119363. _vq_lengthlist__44c7_s_p9_2,
  119364. 1, -526909440, 1611661312, 6, 0,
  119365. _vq_quantlist__44c7_s_p9_2,
  119366. NULL,
  119367. &_vq_auxt__44c7_s_p9_2,
  119368. NULL,
  119369. 0
  119370. };
  119371. static long _huff_lengthlist__44c7_s_short[] = {
  119372. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119373. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119374. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119375. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119376. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119377. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119378. 10, 9,11,14,
  119379. };
  119380. static static_codebook _huff_book__44c7_s_short = {
  119381. 2, 100,
  119382. _huff_lengthlist__44c7_s_short,
  119383. 0, 0, 0, 0, 0,
  119384. NULL,
  119385. NULL,
  119386. NULL,
  119387. NULL,
  119388. 0
  119389. };
  119390. static long _huff_lengthlist__44c8_s_long[] = {
  119391. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119392. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119393. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119394. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119395. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119396. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119397. 11, 9, 9,10,
  119398. };
  119399. static static_codebook _huff_book__44c8_s_long = {
  119400. 2, 100,
  119401. _huff_lengthlist__44c8_s_long,
  119402. 0, 0, 0, 0, 0,
  119403. NULL,
  119404. NULL,
  119405. NULL,
  119406. NULL,
  119407. 0
  119408. };
  119409. static long _vq_quantlist__44c8_s_p1_0[] = {
  119410. 1,
  119411. 0,
  119412. 2,
  119413. };
  119414. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119415. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119416. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119417. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119418. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119419. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119420. 8,
  119421. };
  119422. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119423. -0.5, 0.5,
  119424. };
  119425. static long _vq_quantmap__44c8_s_p1_0[] = {
  119426. 1, 0, 2,
  119427. };
  119428. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119429. _vq_quantthresh__44c8_s_p1_0,
  119430. _vq_quantmap__44c8_s_p1_0,
  119431. 3,
  119432. 3
  119433. };
  119434. static static_codebook _44c8_s_p1_0 = {
  119435. 4, 81,
  119436. _vq_lengthlist__44c8_s_p1_0,
  119437. 1, -535822336, 1611661312, 2, 0,
  119438. _vq_quantlist__44c8_s_p1_0,
  119439. NULL,
  119440. &_vq_auxt__44c8_s_p1_0,
  119441. NULL,
  119442. 0
  119443. };
  119444. static long _vq_quantlist__44c8_s_p2_0[] = {
  119445. 2,
  119446. 1,
  119447. 3,
  119448. 0,
  119449. 4,
  119450. };
  119451. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119452. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119453. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119454. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119455. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119456. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119457. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119458. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119459. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119461. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119462. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119463. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119464. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119465. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119466. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119467. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119469. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119470. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119471. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119472. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119473. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119474. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119475. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119477. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119478. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119479. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119480. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119481. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119482. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119483. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119488. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119489. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119490. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119491. 13,
  119492. };
  119493. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119494. -1.5, -0.5, 0.5, 1.5,
  119495. };
  119496. static long _vq_quantmap__44c8_s_p2_0[] = {
  119497. 3, 1, 0, 2, 4,
  119498. };
  119499. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119500. _vq_quantthresh__44c8_s_p2_0,
  119501. _vq_quantmap__44c8_s_p2_0,
  119502. 5,
  119503. 5
  119504. };
  119505. static static_codebook _44c8_s_p2_0 = {
  119506. 4, 625,
  119507. _vq_lengthlist__44c8_s_p2_0,
  119508. 1, -533725184, 1611661312, 3, 0,
  119509. _vq_quantlist__44c8_s_p2_0,
  119510. NULL,
  119511. &_vq_auxt__44c8_s_p2_0,
  119512. NULL,
  119513. 0
  119514. };
  119515. static long _vq_quantlist__44c8_s_p3_0[] = {
  119516. 4,
  119517. 3,
  119518. 5,
  119519. 2,
  119520. 6,
  119521. 1,
  119522. 7,
  119523. 0,
  119524. 8,
  119525. };
  119526. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119527. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119528. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119529. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119530. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119532. 0,
  119533. };
  119534. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119535. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119536. };
  119537. static long _vq_quantmap__44c8_s_p3_0[] = {
  119538. 7, 5, 3, 1, 0, 2, 4, 6,
  119539. 8,
  119540. };
  119541. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119542. _vq_quantthresh__44c8_s_p3_0,
  119543. _vq_quantmap__44c8_s_p3_0,
  119544. 9,
  119545. 9
  119546. };
  119547. static static_codebook _44c8_s_p3_0 = {
  119548. 2, 81,
  119549. _vq_lengthlist__44c8_s_p3_0,
  119550. 1, -531628032, 1611661312, 4, 0,
  119551. _vq_quantlist__44c8_s_p3_0,
  119552. NULL,
  119553. &_vq_auxt__44c8_s_p3_0,
  119554. NULL,
  119555. 0
  119556. };
  119557. static long _vq_quantlist__44c8_s_p4_0[] = {
  119558. 8,
  119559. 7,
  119560. 9,
  119561. 6,
  119562. 10,
  119563. 5,
  119564. 11,
  119565. 4,
  119566. 12,
  119567. 3,
  119568. 13,
  119569. 2,
  119570. 14,
  119571. 1,
  119572. 15,
  119573. 0,
  119574. 16,
  119575. };
  119576. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119577. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119578. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119579. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119580. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119581. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119582. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119583. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119584. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119585. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119586. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119595. 0,
  119596. };
  119597. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119598. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119599. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119600. };
  119601. static long _vq_quantmap__44c8_s_p4_0[] = {
  119602. 15, 13, 11, 9, 7, 5, 3, 1,
  119603. 0, 2, 4, 6, 8, 10, 12, 14,
  119604. 16,
  119605. };
  119606. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119607. _vq_quantthresh__44c8_s_p4_0,
  119608. _vq_quantmap__44c8_s_p4_0,
  119609. 17,
  119610. 17
  119611. };
  119612. static static_codebook _44c8_s_p4_0 = {
  119613. 2, 289,
  119614. _vq_lengthlist__44c8_s_p4_0,
  119615. 1, -529530880, 1611661312, 5, 0,
  119616. _vq_quantlist__44c8_s_p4_0,
  119617. NULL,
  119618. &_vq_auxt__44c8_s_p4_0,
  119619. NULL,
  119620. 0
  119621. };
  119622. static long _vq_quantlist__44c8_s_p5_0[] = {
  119623. 1,
  119624. 0,
  119625. 2,
  119626. };
  119627. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119628. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119629. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119630. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119631. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119632. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119633. 12,
  119634. };
  119635. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119636. -5.5, 5.5,
  119637. };
  119638. static long _vq_quantmap__44c8_s_p5_0[] = {
  119639. 1, 0, 2,
  119640. };
  119641. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119642. _vq_quantthresh__44c8_s_p5_0,
  119643. _vq_quantmap__44c8_s_p5_0,
  119644. 3,
  119645. 3
  119646. };
  119647. static static_codebook _44c8_s_p5_0 = {
  119648. 4, 81,
  119649. _vq_lengthlist__44c8_s_p5_0,
  119650. 1, -529137664, 1618345984, 2, 0,
  119651. _vq_quantlist__44c8_s_p5_0,
  119652. NULL,
  119653. &_vq_auxt__44c8_s_p5_0,
  119654. NULL,
  119655. 0
  119656. };
  119657. static long _vq_quantlist__44c8_s_p5_1[] = {
  119658. 5,
  119659. 4,
  119660. 6,
  119661. 3,
  119662. 7,
  119663. 2,
  119664. 8,
  119665. 1,
  119666. 9,
  119667. 0,
  119668. 10,
  119669. };
  119670. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119671. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119672. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119673. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119674. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119675. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119676. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119677. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119678. 11,11,11, 7, 7, 7, 7, 8, 8,
  119679. };
  119680. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119681. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119682. 3.5, 4.5,
  119683. };
  119684. static long _vq_quantmap__44c8_s_p5_1[] = {
  119685. 9, 7, 5, 3, 1, 0, 2, 4,
  119686. 6, 8, 10,
  119687. };
  119688. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119689. _vq_quantthresh__44c8_s_p5_1,
  119690. _vq_quantmap__44c8_s_p5_1,
  119691. 11,
  119692. 11
  119693. };
  119694. static static_codebook _44c8_s_p5_1 = {
  119695. 2, 121,
  119696. _vq_lengthlist__44c8_s_p5_1,
  119697. 1, -531365888, 1611661312, 4, 0,
  119698. _vq_quantlist__44c8_s_p5_1,
  119699. NULL,
  119700. &_vq_auxt__44c8_s_p5_1,
  119701. NULL,
  119702. 0
  119703. };
  119704. static long _vq_quantlist__44c8_s_p6_0[] = {
  119705. 6,
  119706. 5,
  119707. 7,
  119708. 4,
  119709. 8,
  119710. 3,
  119711. 9,
  119712. 2,
  119713. 10,
  119714. 1,
  119715. 11,
  119716. 0,
  119717. 12,
  119718. };
  119719. static long _vq_lengthlist__44c8_s_p6_0[] = {
  119720. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  119721. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  119722. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  119723. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  119724. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  119725. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  119726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119730. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119731. };
  119732. static float _vq_quantthresh__44c8_s_p6_0[] = {
  119733. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119734. 12.5, 17.5, 22.5, 27.5,
  119735. };
  119736. static long _vq_quantmap__44c8_s_p6_0[] = {
  119737. 11, 9, 7, 5, 3, 1, 0, 2,
  119738. 4, 6, 8, 10, 12,
  119739. };
  119740. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  119741. _vq_quantthresh__44c8_s_p6_0,
  119742. _vq_quantmap__44c8_s_p6_0,
  119743. 13,
  119744. 13
  119745. };
  119746. static static_codebook _44c8_s_p6_0 = {
  119747. 2, 169,
  119748. _vq_lengthlist__44c8_s_p6_0,
  119749. 1, -526516224, 1616117760, 4, 0,
  119750. _vq_quantlist__44c8_s_p6_0,
  119751. NULL,
  119752. &_vq_auxt__44c8_s_p6_0,
  119753. NULL,
  119754. 0
  119755. };
  119756. static long _vq_quantlist__44c8_s_p6_1[] = {
  119757. 2,
  119758. 1,
  119759. 3,
  119760. 0,
  119761. 4,
  119762. };
  119763. static long _vq_lengthlist__44c8_s_p6_1[] = {
  119764. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119765. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119766. };
  119767. static float _vq_quantthresh__44c8_s_p6_1[] = {
  119768. -1.5, -0.5, 0.5, 1.5,
  119769. };
  119770. static long _vq_quantmap__44c8_s_p6_1[] = {
  119771. 3, 1, 0, 2, 4,
  119772. };
  119773. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  119774. _vq_quantthresh__44c8_s_p6_1,
  119775. _vq_quantmap__44c8_s_p6_1,
  119776. 5,
  119777. 5
  119778. };
  119779. static static_codebook _44c8_s_p6_1 = {
  119780. 2, 25,
  119781. _vq_lengthlist__44c8_s_p6_1,
  119782. 1, -533725184, 1611661312, 3, 0,
  119783. _vq_quantlist__44c8_s_p6_1,
  119784. NULL,
  119785. &_vq_auxt__44c8_s_p6_1,
  119786. NULL,
  119787. 0
  119788. };
  119789. static long _vq_quantlist__44c8_s_p7_0[] = {
  119790. 6,
  119791. 5,
  119792. 7,
  119793. 4,
  119794. 8,
  119795. 3,
  119796. 9,
  119797. 2,
  119798. 10,
  119799. 1,
  119800. 11,
  119801. 0,
  119802. 12,
  119803. };
  119804. static long _vq_lengthlist__44c8_s_p7_0[] = {
  119805. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  119806. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119807. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  119808. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  119809. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  119810. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  119811. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  119812. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  119813. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  119814. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  119815. 20,13,13,13,13,14,13,15,15,
  119816. };
  119817. static float _vq_quantthresh__44c8_s_p7_0[] = {
  119818. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119819. 27.5, 38.5, 49.5, 60.5,
  119820. };
  119821. static long _vq_quantmap__44c8_s_p7_0[] = {
  119822. 11, 9, 7, 5, 3, 1, 0, 2,
  119823. 4, 6, 8, 10, 12,
  119824. };
  119825. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  119826. _vq_quantthresh__44c8_s_p7_0,
  119827. _vq_quantmap__44c8_s_p7_0,
  119828. 13,
  119829. 13
  119830. };
  119831. static static_codebook _44c8_s_p7_0 = {
  119832. 2, 169,
  119833. _vq_lengthlist__44c8_s_p7_0,
  119834. 1, -523206656, 1618345984, 4, 0,
  119835. _vq_quantlist__44c8_s_p7_0,
  119836. NULL,
  119837. &_vq_auxt__44c8_s_p7_0,
  119838. NULL,
  119839. 0
  119840. };
  119841. static long _vq_quantlist__44c8_s_p7_1[] = {
  119842. 5,
  119843. 4,
  119844. 6,
  119845. 3,
  119846. 7,
  119847. 2,
  119848. 8,
  119849. 1,
  119850. 9,
  119851. 0,
  119852. 10,
  119853. };
  119854. static long _vq_lengthlist__44c8_s_p7_1[] = {
  119855. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  119856. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  119857. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119858. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119859. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119860. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119861. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119862. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119863. };
  119864. static float _vq_quantthresh__44c8_s_p7_1[] = {
  119865. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119866. 3.5, 4.5,
  119867. };
  119868. static long _vq_quantmap__44c8_s_p7_1[] = {
  119869. 9, 7, 5, 3, 1, 0, 2, 4,
  119870. 6, 8, 10,
  119871. };
  119872. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  119873. _vq_quantthresh__44c8_s_p7_1,
  119874. _vq_quantmap__44c8_s_p7_1,
  119875. 11,
  119876. 11
  119877. };
  119878. static static_codebook _44c8_s_p7_1 = {
  119879. 2, 121,
  119880. _vq_lengthlist__44c8_s_p7_1,
  119881. 1, -531365888, 1611661312, 4, 0,
  119882. _vq_quantlist__44c8_s_p7_1,
  119883. NULL,
  119884. &_vq_auxt__44c8_s_p7_1,
  119885. NULL,
  119886. 0
  119887. };
  119888. static long _vq_quantlist__44c8_s_p8_0[] = {
  119889. 7,
  119890. 6,
  119891. 8,
  119892. 5,
  119893. 9,
  119894. 4,
  119895. 10,
  119896. 3,
  119897. 11,
  119898. 2,
  119899. 12,
  119900. 1,
  119901. 13,
  119902. 0,
  119903. 14,
  119904. };
  119905. static long _vq_lengthlist__44c8_s_p8_0[] = {
  119906. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  119907. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  119908. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  119909. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  119910. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  119911. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  119912. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  119913. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  119914. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  119915. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  119916. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  119917. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119918. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  119919. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  119920. 15,
  119921. };
  119922. static float _vq_quantthresh__44c8_s_p8_0[] = {
  119923. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119924. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119925. };
  119926. static long _vq_quantmap__44c8_s_p8_0[] = {
  119927. 13, 11, 9, 7, 5, 3, 1, 0,
  119928. 2, 4, 6, 8, 10, 12, 14,
  119929. };
  119930. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  119931. _vq_quantthresh__44c8_s_p8_0,
  119932. _vq_quantmap__44c8_s_p8_0,
  119933. 15,
  119934. 15
  119935. };
  119936. static static_codebook _44c8_s_p8_0 = {
  119937. 2, 225,
  119938. _vq_lengthlist__44c8_s_p8_0,
  119939. 1, -520986624, 1620377600, 4, 0,
  119940. _vq_quantlist__44c8_s_p8_0,
  119941. NULL,
  119942. &_vq_auxt__44c8_s_p8_0,
  119943. NULL,
  119944. 0
  119945. };
  119946. static long _vq_quantlist__44c8_s_p8_1[] = {
  119947. 10,
  119948. 9,
  119949. 11,
  119950. 8,
  119951. 12,
  119952. 7,
  119953. 13,
  119954. 6,
  119955. 14,
  119956. 5,
  119957. 15,
  119958. 4,
  119959. 16,
  119960. 3,
  119961. 17,
  119962. 2,
  119963. 18,
  119964. 1,
  119965. 19,
  119966. 0,
  119967. 20,
  119968. };
  119969. static long _vq_lengthlist__44c8_s_p8_1[] = {
  119970. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119971. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119972. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119973. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119974. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119975. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119976. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119977. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119978. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119979. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119980. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  119981. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  119982. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  119983. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119984. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  119985. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  119986. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  119987. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  119988. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  119989. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  119990. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  119991. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  119992. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  119993. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  119994. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  119995. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  119996. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  119997. 10, 9, 9,10,10, 9,10, 9, 9,
  119998. };
  119999. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120000. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120001. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120002. 6.5, 7.5, 8.5, 9.5,
  120003. };
  120004. static long _vq_quantmap__44c8_s_p8_1[] = {
  120005. 19, 17, 15, 13, 11, 9, 7, 5,
  120006. 3, 1, 0, 2, 4, 6, 8, 10,
  120007. 12, 14, 16, 18, 20,
  120008. };
  120009. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120010. _vq_quantthresh__44c8_s_p8_1,
  120011. _vq_quantmap__44c8_s_p8_1,
  120012. 21,
  120013. 21
  120014. };
  120015. static static_codebook _44c8_s_p8_1 = {
  120016. 2, 441,
  120017. _vq_lengthlist__44c8_s_p8_1,
  120018. 1, -529268736, 1611661312, 5, 0,
  120019. _vq_quantlist__44c8_s_p8_1,
  120020. NULL,
  120021. &_vq_auxt__44c8_s_p8_1,
  120022. NULL,
  120023. 0
  120024. };
  120025. static long _vq_quantlist__44c8_s_p9_0[] = {
  120026. 8,
  120027. 7,
  120028. 9,
  120029. 6,
  120030. 10,
  120031. 5,
  120032. 11,
  120033. 4,
  120034. 12,
  120035. 3,
  120036. 13,
  120037. 2,
  120038. 14,
  120039. 1,
  120040. 15,
  120041. 0,
  120042. 16,
  120043. };
  120044. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120045. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120046. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120047. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120048. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120049. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120050. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120051. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120052. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120053. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120054. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120055. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120056. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120057. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120058. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120059. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120060. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120061. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120062. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120063. 10,
  120064. };
  120065. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120066. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120067. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120068. };
  120069. static long _vq_quantmap__44c8_s_p9_0[] = {
  120070. 15, 13, 11, 9, 7, 5, 3, 1,
  120071. 0, 2, 4, 6, 8, 10, 12, 14,
  120072. 16,
  120073. };
  120074. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120075. _vq_quantthresh__44c8_s_p9_0,
  120076. _vq_quantmap__44c8_s_p9_0,
  120077. 17,
  120078. 17
  120079. };
  120080. static static_codebook _44c8_s_p9_0 = {
  120081. 2, 289,
  120082. _vq_lengthlist__44c8_s_p9_0,
  120083. 1, -509798400, 1631393792, 5, 0,
  120084. _vq_quantlist__44c8_s_p9_0,
  120085. NULL,
  120086. &_vq_auxt__44c8_s_p9_0,
  120087. NULL,
  120088. 0
  120089. };
  120090. static long _vq_quantlist__44c8_s_p9_1[] = {
  120091. 9,
  120092. 8,
  120093. 10,
  120094. 7,
  120095. 11,
  120096. 6,
  120097. 12,
  120098. 5,
  120099. 13,
  120100. 4,
  120101. 14,
  120102. 3,
  120103. 15,
  120104. 2,
  120105. 16,
  120106. 1,
  120107. 17,
  120108. 0,
  120109. 18,
  120110. };
  120111. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120112. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120113. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120114. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120115. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120116. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120117. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120118. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120119. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120120. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120121. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120122. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120123. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120124. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120125. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120126. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120127. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120128. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120129. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120130. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120131. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120132. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120133. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120134. 14,13,13,14,14,15,14,15,14,
  120135. };
  120136. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120137. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120138. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120139. 367.5, 416.5,
  120140. };
  120141. static long _vq_quantmap__44c8_s_p9_1[] = {
  120142. 17, 15, 13, 11, 9, 7, 5, 3,
  120143. 1, 0, 2, 4, 6, 8, 10, 12,
  120144. 14, 16, 18,
  120145. };
  120146. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120147. _vq_quantthresh__44c8_s_p9_1,
  120148. _vq_quantmap__44c8_s_p9_1,
  120149. 19,
  120150. 19
  120151. };
  120152. static static_codebook _44c8_s_p9_1 = {
  120153. 2, 361,
  120154. _vq_lengthlist__44c8_s_p9_1,
  120155. 1, -518287360, 1622704128, 5, 0,
  120156. _vq_quantlist__44c8_s_p9_1,
  120157. NULL,
  120158. &_vq_auxt__44c8_s_p9_1,
  120159. NULL,
  120160. 0
  120161. };
  120162. static long _vq_quantlist__44c8_s_p9_2[] = {
  120163. 24,
  120164. 23,
  120165. 25,
  120166. 22,
  120167. 26,
  120168. 21,
  120169. 27,
  120170. 20,
  120171. 28,
  120172. 19,
  120173. 29,
  120174. 18,
  120175. 30,
  120176. 17,
  120177. 31,
  120178. 16,
  120179. 32,
  120180. 15,
  120181. 33,
  120182. 14,
  120183. 34,
  120184. 13,
  120185. 35,
  120186. 12,
  120187. 36,
  120188. 11,
  120189. 37,
  120190. 10,
  120191. 38,
  120192. 9,
  120193. 39,
  120194. 8,
  120195. 40,
  120196. 7,
  120197. 41,
  120198. 6,
  120199. 42,
  120200. 5,
  120201. 43,
  120202. 4,
  120203. 44,
  120204. 3,
  120205. 45,
  120206. 2,
  120207. 46,
  120208. 1,
  120209. 47,
  120210. 0,
  120211. 48,
  120212. };
  120213. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120214. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120215. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120216. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120217. 7,
  120218. };
  120219. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120220. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120221. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120222. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120223. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120224. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120225. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120226. };
  120227. static long _vq_quantmap__44c8_s_p9_2[] = {
  120228. 47, 45, 43, 41, 39, 37, 35, 33,
  120229. 31, 29, 27, 25, 23, 21, 19, 17,
  120230. 15, 13, 11, 9, 7, 5, 3, 1,
  120231. 0, 2, 4, 6, 8, 10, 12, 14,
  120232. 16, 18, 20, 22, 24, 26, 28, 30,
  120233. 32, 34, 36, 38, 40, 42, 44, 46,
  120234. 48,
  120235. };
  120236. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120237. _vq_quantthresh__44c8_s_p9_2,
  120238. _vq_quantmap__44c8_s_p9_2,
  120239. 49,
  120240. 49
  120241. };
  120242. static static_codebook _44c8_s_p9_2 = {
  120243. 1, 49,
  120244. _vq_lengthlist__44c8_s_p9_2,
  120245. 1, -526909440, 1611661312, 6, 0,
  120246. _vq_quantlist__44c8_s_p9_2,
  120247. NULL,
  120248. &_vq_auxt__44c8_s_p9_2,
  120249. NULL,
  120250. 0
  120251. };
  120252. static long _huff_lengthlist__44c8_s_short[] = {
  120253. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120254. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120255. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120256. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120257. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120258. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120259. 10, 9,11,14,
  120260. };
  120261. static static_codebook _huff_book__44c8_s_short = {
  120262. 2, 100,
  120263. _huff_lengthlist__44c8_s_short,
  120264. 0, 0, 0, 0, 0,
  120265. NULL,
  120266. NULL,
  120267. NULL,
  120268. NULL,
  120269. 0
  120270. };
  120271. static long _huff_lengthlist__44c9_s_long[] = {
  120272. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120273. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120274. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120275. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120276. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120277. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120278. 10, 9, 8, 9,
  120279. };
  120280. static static_codebook _huff_book__44c9_s_long = {
  120281. 2, 100,
  120282. _huff_lengthlist__44c9_s_long,
  120283. 0, 0, 0, 0, 0,
  120284. NULL,
  120285. NULL,
  120286. NULL,
  120287. NULL,
  120288. 0
  120289. };
  120290. static long _vq_quantlist__44c9_s_p1_0[] = {
  120291. 1,
  120292. 0,
  120293. 2,
  120294. };
  120295. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120296. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120297. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120298. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120299. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120300. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120301. 7,
  120302. };
  120303. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120304. -0.5, 0.5,
  120305. };
  120306. static long _vq_quantmap__44c9_s_p1_0[] = {
  120307. 1, 0, 2,
  120308. };
  120309. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120310. _vq_quantthresh__44c9_s_p1_0,
  120311. _vq_quantmap__44c9_s_p1_0,
  120312. 3,
  120313. 3
  120314. };
  120315. static static_codebook _44c9_s_p1_0 = {
  120316. 4, 81,
  120317. _vq_lengthlist__44c9_s_p1_0,
  120318. 1, -535822336, 1611661312, 2, 0,
  120319. _vq_quantlist__44c9_s_p1_0,
  120320. NULL,
  120321. &_vq_auxt__44c9_s_p1_0,
  120322. NULL,
  120323. 0
  120324. };
  120325. static long _vq_quantlist__44c9_s_p2_0[] = {
  120326. 2,
  120327. 1,
  120328. 3,
  120329. 0,
  120330. 4,
  120331. };
  120332. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120333. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120334. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120335. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120336. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120337. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120338. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120339. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120340. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120342. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120343. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120344. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120345. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120346. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120347. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120348. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120350. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120351. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120352. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120353. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120354. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120355. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120356. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120358. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120359. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120360. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120361. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120362. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120363. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120364. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120369. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120370. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120371. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120372. 12,
  120373. };
  120374. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120375. -1.5, -0.5, 0.5, 1.5,
  120376. };
  120377. static long _vq_quantmap__44c9_s_p2_0[] = {
  120378. 3, 1, 0, 2, 4,
  120379. };
  120380. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120381. _vq_quantthresh__44c9_s_p2_0,
  120382. _vq_quantmap__44c9_s_p2_0,
  120383. 5,
  120384. 5
  120385. };
  120386. static static_codebook _44c9_s_p2_0 = {
  120387. 4, 625,
  120388. _vq_lengthlist__44c9_s_p2_0,
  120389. 1, -533725184, 1611661312, 3, 0,
  120390. _vq_quantlist__44c9_s_p2_0,
  120391. NULL,
  120392. &_vq_auxt__44c9_s_p2_0,
  120393. NULL,
  120394. 0
  120395. };
  120396. static long _vq_quantlist__44c9_s_p3_0[] = {
  120397. 4,
  120398. 3,
  120399. 5,
  120400. 2,
  120401. 6,
  120402. 1,
  120403. 7,
  120404. 0,
  120405. 8,
  120406. };
  120407. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120408. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120409. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120410. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120411. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120413. 0,
  120414. };
  120415. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120416. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120417. };
  120418. static long _vq_quantmap__44c9_s_p3_0[] = {
  120419. 7, 5, 3, 1, 0, 2, 4, 6,
  120420. 8,
  120421. };
  120422. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120423. _vq_quantthresh__44c9_s_p3_0,
  120424. _vq_quantmap__44c9_s_p3_0,
  120425. 9,
  120426. 9
  120427. };
  120428. static static_codebook _44c9_s_p3_0 = {
  120429. 2, 81,
  120430. _vq_lengthlist__44c9_s_p3_0,
  120431. 1, -531628032, 1611661312, 4, 0,
  120432. _vq_quantlist__44c9_s_p3_0,
  120433. NULL,
  120434. &_vq_auxt__44c9_s_p3_0,
  120435. NULL,
  120436. 0
  120437. };
  120438. static long _vq_quantlist__44c9_s_p4_0[] = {
  120439. 8,
  120440. 7,
  120441. 9,
  120442. 6,
  120443. 10,
  120444. 5,
  120445. 11,
  120446. 4,
  120447. 12,
  120448. 3,
  120449. 13,
  120450. 2,
  120451. 14,
  120452. 1,
  120453. 15,
  120454. 0,
  120455. 16,
  120456. };
  120457. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120458. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120459. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120460. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120461. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120462. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120463. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120464. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120465. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120466. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120467. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120476. 0,
  120477. };
  120478. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120479. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120480. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120481. };
  120482. static long _vq_quantmap__44c9_s_p4_0[] = {
  120483. 15, 13, 11, 9, 7, 5, 3, 1,
  120484. 0, 2, 4, 6, 8, 10, 12, 14,
  120485. 16,
  120486. };
  120487. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120488. _vq_quantthresh__44c9_s_p4_0,
  120489. _vq_quantmap__44c9_s_p4_0,
  120490. 17,
  120491. 17
  120492. };
  120493. static static_codebook _44c9_s_p4_0 = {
  120494. 2, 289,
  120495. _vq_lengthlist__44c9_s_p4_0,
  120496. 1, -529530880, 1611661312, 5, 0,
  120497. _vq_quantlist__44c9_s_p4_0,
  120498. NULL,
  120499. &_vq_auxt__44c9_s_p4_0,
  120500. NULL,
  120501. 0
  120502. };
  120503. static long _vq_quantlist__44c9_s_p5_0[] = {
  120504. 1,
  120505. 0,
  120506. 2,
  120507. };
  120508. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120509. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120510. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120511. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120512. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120513. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120514. 12,
  120515. };
  120516. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120517. -5.5, 5.5,
  120518. };
  120519. static long _vq_quantmap__44c9_s_p5_0[] = {
  120520. 1, 0, 2,
  120521. };
  120522. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120523. _vq_quantthresh__44c9_s_p5_0,
  120524. _vq_quantmap__44c9_s_p5_0,
  120525. 3,
  120526. 3
  120527. };
  120528. static static_codebook _44c9_s_p5_0 = {
  120529. 4, 81,
  120530. _vq_lengthlist__44c9_s_p5_0,
  120531. 1, -529137664, 1618345984, 2, 0,
  120532. _vq_quantlist__44c9_s_p5_0,
  120533. NULL,
  120534. &_vq_auxt__44c9_s_p5_0,
  120535. NULL,
  120536. 0
  120537. };
  120538. static long _vq_quantlist__44c9_s_p5_1[] = {
  120539. 5,
  120540. 4,
  120541. 6,
  120542. 3,
  120543. 7,
  120544. 2,
  120545. 8,
  120546. 1,
  120547. 9,
  120548. 0,
  120549. 10,
  120550. };
  120551. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120552. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120553. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120554. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120555. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120556. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120557. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120558. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120559. 11,11,11, 7, 7, 7, 7, 7, 7,
  120560. };
  120561. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120562. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120563. 3.5, 4.5,
  120564. };
  120565. static long _vq_quantmap__44c9_s_p5_1[] = {
  120566. 9, 7, 5, 3, 1, 0, 2, 4,
  120567. 6, 8, 10,
  120568. };
  120569. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120570. _vq_quantthresh__44c9_s_p5_1,
  120571. _vq_quantmap__44c9_s_p5_1,
  120572. 11,
  120573. 11
  120574. };
  120575. static static_codebook _44c9_s_p5_1 = {
  120576. 2, 121,
  120577. _vq_lengthlist__44c9_s_p5_1,
  120578. 1, -531365888, 1611661312, 4, 0,
  120579. _vq_quantlist__44c9_s_p5_1,
  120580. NULL,
  120581. &_vq_auxt__44c9_s_p5_1,
  120582. NULL,
  120583. 0
  120584. };
  120585. static long _vq_quantlist__44c9_s_p6_0[] = {
  120586. 6,
  120587. 5,
  120588. 7,
  120589. 4,
  120590. 8,
  120591. 3,
  120592. 9,
  120593. 2,
  120594. 10,
  120595. 1,
  120596. 11,
  120597. 0,
  120598. 12,
  120599. };
  120600. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120601. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120602. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120603. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120604. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120605. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120606. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120611. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120612. };
  120613. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120614. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120615. 12.5, 17.5, 22.5, 27.5,
  120616. };
  120617. static long _vq_quantmap__44c9_s_p6_0[] = {
  120618. 11, 9, 7, 5, 3, 1, 0, 2,
  120619. 4, 6, 8, 10, 12,
  120620. };
  120621. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120622. _vq_quantthresh__44c9_s_p6_0,
  120623. _vq_quantmap__44c9_s_p6_0,
  120624. 13,
  120625. 13
  120626. };
  120627. static static_codebook _44c9_s_p6_0 = {
  120628. 2, 169,
  120629. _vq_lengthlist__44c9_s_p6_0,
  120630. 1, -526516224, 1616117760, 4, 0,
  120631. _vq_quantlist__44c9_s_p6_0,
  120632. NULL,
  120633. &_vq_auxt__44c9_s_p6_0,
  120634. NULL,
  120635. 0
  120636. };
  120637. static long _vq_quantlist__44c9_s_p6_1[] = {
  120638. 2,
  120639. 1,
  120640. 3,
  120641. 0,
  120642. 4,
  120643. };
  120644. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120645. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120646. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120647. };
  120648. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120649. -1.5, -0.5, 0.5, 1.5,
  120650. };
  120651. static long _vq_quantmap__44c9_s_p6_1[] = {
  120652. 3, 1, 0, 2, 4,
  120653. };
  120654. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120655. _vq_quantthresh__44c9_s_p6_1,
  120656. _vq_quantmap__44c9_s_p6_1,
  120657. 5,
  120658. 5
  120659. };
  120660. static static_codebook _44c9_s_p6_1 = {
  120661. 2, 25,
  120662. _vq_lengthlist__44c9_s_p6_1,
  120663. 1, -533725184, 1611661312, 3, 0,
  120664. _vq_quantlist__44c9_s_p6_1,
  120665. NULL,
  120666. &_vq_auxt__44c9_s_p6_1,
  120667. NULL,
  120668. 0
  120669. };
  120670. static long _vq_quantlist__44c9_s_p7_0[] = {
  120671. 6,
  120672. 5,
  120673. 7,
  120674. 4,
  120675. 8,
  120676. 3,
  120677. 9,
  120678. 2,
  120679. 10,
  120680. 1,
  120681. 11,
  120682. 0,
  120683. 12,
  120684. };
  120685. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120686. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120687. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120688. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120689. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120690. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120691. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120692. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  120693. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  120694. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  120695. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  120696. 19,12,12,12,12,13,13,14,14,
  120697. };
  120698. static float _vq_quantthresh__44c9_s_p7_0[] = {
  120699. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120700. 27.5, 38.5, 49.5, 60.5,
  120701. };
  120702. static long _vq_quantmap__44c9_s_p7_0[] = {
  120703. 11, 9, 7, 5, 3, 1, 0, 2,
  120704. 4, 6, 8, 10, 12,
  120705. };
  120706. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  120707. _vq_quantthresh__44c9_s_p7_0,
  120708. _vq_quantmap__44c9_s_p7_0,
  120709. 13,
  120710. 13
  120711. };
  120712. static static_codebook _44c9_s_p7_0 = {
  120713. 2, 169,
  120714. _vq_lengthlist__44c9_s_p7_0,
  120715. 1, -523206656, 1618345984, 4, 0,
  120716. _vq_quantlist__44c9_s_p7_0,
  120717. NULL,
  120718. &_vq_auxt__44c9_s_p7_0,
  120719. NULL,
  120720. 0
  120721. };
  120722. static long _vq_quantlist__44c9_s_p7_1[] = {
  120723. 5,
  120724. 4,
  120725. 6,
  120726. 3,
  120727. 7,
  120728. 2,
  120729. 8,
  120730. 1,
  120731. 9,
  120732. 0,
  120733. 10,
  120734. };
  120735. static long _vq_lengthlist__44c9_s_p7_1[] = {
  120736. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  120737. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120738. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  120739. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120740. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120741. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120742. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120743. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120744. };
  120745. static float _vq_quantthresh__44c9_s_p7_1[] = {
  120746. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120747. 3.5, 4.5,
  120748. };
  120749. static long _vq_quantmap__44c9_s_p7_1[] = {
  120750. 9, 7, 5, 3, 1, 0, 2, 4,
  120751. 6, 8, 10,
  120752. };
  120753. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  120754. _vq_quantthresh__44c9_s_p7_1,
  120755. _vq_quantmap__44c9_s_p7_1,
  120756. 11,
  120757. 11
  120758. };
  120759. static static_codebook _44c9_s_p7_1 = {
  120760. 2, 121,
  120761. _vq_lengthlist__44c9_s_p7_1,
  120762. 1, -531365888, 1611661312, 4, 0,
  120763. _vq_quantlist__44c9_s_p7_1,
  120764. NULL,
  120765. &_vq_auxt__44c9_s_p7_1,
  120766. NULL,
  120767. 0
  120768. };
  120769. static long _vq_quantlist__44c9_s_p8_0[] = {
  120770. 7,
  120771. 6,
  120772. 8,
  120773. 5,
  120774. 9,
  120775. 4,
  120776. 10,
  120777. 3,
  120778. 11,
  120779. 2,
  120780. 12,
  120781. 1,
  120782. 13,
  120783. 0,
  120784. 14,
  120785. };
  120786. static long _vq_lengthlist__44c9_s_p8_0[] = {
  120787. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  120788. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  120789. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  120790. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  120791. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  120792. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  120793. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  120794. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  120795. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  120796. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  120797. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  120798. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  120799. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  120800. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  120801. 14,
  120802. };
  120803. static float _vq_quantthresh__44c9_s_p8_0[] = {
  120804. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120805. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120806. };
  120807. static long _vq_quantmap__44c9_s_p8_0[] = {
  120808. 13, 11, 9, 7, 5, 3, 1, 0,
  120809. 2, 4, 6, 8, 10, 12, 14,
  120810. };
  120811. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  120812. _vq_quantthresh__44c9_s_p8_0,
  120813. _vq_quantmap__44c9_s_p8_0,
  120814. 15,
  120815. 15
  120816. };
  120817. static static_codebook _44c9_s_p8_0 = {
  120818. 2, 225,
  120819. _vq_lengthlist__44c9_s_p8_0,
  120820. 1, -520986624, 1620377600, 4, 0,
  120821. _vq_quantlist__44c9_s_p8_0,
  120822. NULL,
  120823. &_vq_auxt__44c9_s_p8_0,
  120824. NULL,
  120825. 0
  120826. };
  120827. static long _vq_quantlist__44c9_s_p8_1[] = {
  120828. 10,
  120829. 9,
  120830. 11,
  120831. 8,
  120832. 12,
  120833. 7,
  120834. 13,
  120835. 6,
  120836. 14,
  120837. 5,
  120838. 15,
  120839. 4,
  120840. 16,
  120841. 3,
  120842. 17,
  120843. 2,
  120844. 18,
  120845. 1,
  120846. 19,
  120847. 0,
  120848. 20,
  120849. };
  120850. static long _vq_lengthlist__44c9_s_p8_1[] = {
  120851. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120852. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120853. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120854. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120855. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120856. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120857. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  120858. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120859. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120860. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120861. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120862. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120863. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120864. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120865. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120866. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  120867. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  120868. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  120869. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  120870. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  120871. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  120872. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  120873. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  120874. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  120875. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  120876. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  120877. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  120878. 9, 9, 9,10, 9, 9, 9, 9, 9,
  120879. };
  120880. static float _vq_quantthresh__44c9_s_p8_1[] = {
  120881. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120882. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120883. 6.5, 7.5, 8.5, 9.5,
  120884. };
  120885. static long _vq_quantmap__44c9_s_p8_1[] = {
  120886. 19, 17, 15, 13, 11, 9, 7, 5,
  120887. 3, 1, 0, 2, 4, 6, 8, 10,
  120888. 12, 14, 16, 18, 20,
  120889. };
  120890. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  120891. _vq_quantthresh__44c9_s_p8_1,
  120892. _vq_quantmap__44c9_s_p8_1,
  120893. 21,
  120894. 21
  120895. };
  120896. static static_codebook _44c9_s_p8_1 = {
  120897. 2, 441,
  120898. _vq_lengthlist__44c9_s_p8_1,
  120899. 1, -529268736, 1611661312, 5, 0,
  120900. _vq_quantlist__44c9_s_p8_1,
  120901. NULL,
  120902. &_vq_auxt__44c9_s_p8_1,
  120903. NULL,
  120904. 0
  120905. };
  120906. static long _vq_quantlist__44c9_s_p9_0[] = {
  120907. 9,
  120908. 8,
  120909. 10,
  120910. 7,
  120911. 11,
  120912. 6,
  120913. 12,
  120914. 5,
  120915. 13,
  120916. 4,
  120917. 14,
  120918. 3,
  120919. 15,
  120920. 2,
  120921. 16,
  120922. 1,
  120923. 17,
  120924. 0,
  120925. 18,
  120926. };
  120927. static long _vq_lengthlist__44c9_s_p9_0[] = {
  120928. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120929. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  120930. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  120931. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  120932. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120933. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120934. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120935. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120936. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120937. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120938. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120939. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120940. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120941. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120942. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120943. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  120944. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  120945. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120946. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120947. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120948. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120949. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120950. 11,11,11,11,11,11,11,11,11,
  120951. };
  120952. static float _vq_quantthresh__44c9_s_p9_0[] = {
  120953. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  120954. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  120955. 6982.5, 7913.5,
  120956. };
  120957. static long _vq_quantmap__44c9_s_p9_0[] = {
  120958. 17, 15, 13, 11, 9, 7, 5, 3,
  120959. 1, 0, 2, 4, 6, 8, 10, 12,
  120960. 14, 16, 18,
  120961. };
  120962. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  120963. _vq_quantthresh__44c9_s_p9_0,
  120964. _vq_quantmap__44c9_s_p9_0,
  120965. 19,
  120966. 19
  120967. };
  120968. static static_codebook _44c9_s_p9_0 = {
  120969. 2, 361,
  120970. _vq_lengthlist__44c9_s_p9_0,
  120971. 1, -508535424, 1631393792, 5, 0,
  120972. _vq_quantlist__44c9_s_p9_0,
  120973. NULL,
  120974. &_vq_auxt__44c9_s_p9_0,
  120975. NULL,
  120976. 0
  120977. };
  120978. static long _vq_quantlist__44c9_s_p9_1[] = {
  120979. 9,
  120980. 8,
  120981. 10,
  120982. 7,
  120983. 11,
  120984. 6,
  120985. 12,
  120986. 5,
  120987. 13,
  120988. 4,
  120989. 14,
  120990. 3,
  120991. 15,
  120992. 2,
  120993. 16,
  120994. 1,
  120995. 17,
  120996. 0,
  120997. 18,
  120998. };
  120999. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121000. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121001. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121002. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121003. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121004. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121005. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121006. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121007. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121008. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121009. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121010. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121011. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121012. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121013. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121014. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121015. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121016. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121017. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121018. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121019. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121020. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121021. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121022. 13,13,13,14,13,14,15,15,15,
  121023. };
  121024. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121025. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121026. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121027. 367.5, 416.5,
  121028. };
  121029. static long _vq_quantmap__44c9_s_p9_1[] = {
  121030. 17, 15, 13, 11, 9, 7, 5, 3,
  121031. 1, 0, 2, 4, 6, 8, 10, 12,
  121032. 14, 16, 18,
  121033. };
  121034. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121035. _vq_quantthresh__44c9_s_p9_1,
  121036. _vq_quantmap__44c9_s_p9_1,
  121037. 19,
  121038. 19
  121039. };
  121040. static static_codebook _44c9_s_p9_1 = {
  121041. 2, 361,
  121042. _vq_lengthlist__44c9_s_p9_1,
  121043. 1, -518287360, 1622704128, 5, 0,
  121044. _vq_quantlist__44c9_s_p9_1,
  121045. NULL,
  121046. &_vq_auxt__44c9_s_p9_1,
  121047. NULL,
  121048. 0
  121049. };
  121050. static long _vq_quantlist__44c9_s_p9_2[] = {
  121051. 24,
  121052. 23,
  121053. 25,
  121054. 22,
  121055. 26,
  121056. 21,
  121057. 27,
  121058. 20,
  121059. 28,
  121060. 19,
  121061. 29,
  121062. 18,
  121063. 30,
  121064. 17,
  121065. 31,
  121066. 16,
  121067. 32,
  121068. 15,
  121069. 33,
  121070. 14,
  121071. 34,
  121072. 13,
  121073. 35,
  121074. 12,
  121075. 36,
  121076. 11,
  121077. 37,
  121078. 10,
  121079. 38,
  121080. 9,
  121081. 39,
  121082. 8,
  121083. 40,
  121084. 7,
  121085. 41,
  121086. 6,
  121087. 42,
  121088. 5,
  121089. 43,
  121090. 4,
  121091. 44,
  121092. 3,
  121093. 45,
  121094. 2,
  121095. 46,
  121096. 1,
  121097. 47,
  121098. 0,
  121099. 48,
  121100. };
  121101. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121102. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121103. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121104. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121105. 7,
  121106. };
  121107. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121108. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121109. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121110. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121111. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121112. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121113. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121114. };
  121115. static long _vq_quantmap__44c9_s_p9_2[] = {
  121116. 47, 45, 43, 41, 39, 37, 35, 33,
  121117. 31, 29, 27, 25, 23, 21, 19, 17,
  121118. 15, 13, 11, 9, 7, 5, 3, 1,
  121119. 0, 2, 4, 6, 8, 10, 12, 14,
  121120. 16, 18, 20, 22, 24, 26, 28, 30,
  121121. 32, 34, 36, 38, 40, 42, 44, 46,
  121122. 48,
  121123. };
  121124. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121125. _vq_quantthresh__44c9_s_p9_2,
  121126. _vq_quantmap__44c9_s_p9_2,
  121127. 49,
  121128. 49
  121129. };
  121130. static static_codebook _44c9_s_p9_2 = {
  121131. 1, 49,
  121132. _vq_lengthlist__44c9_s_p9_2,
  121133. 1, -526909440, 1611661312, 6, 0,
  121134. _vq_quantlist__44c9_s_p9_2,
  121135. NULL,
  121136. &_vq_auxt__44c9_s_p9_2,
  121137. NULL,
  121138. 0
  121139. };
  121140. static long _huff_lengthlist__44c9_s_short[] = {
  121141. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121142. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121143. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121144. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121145. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121146. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121147. 9, 8,10,13,
  121148. };
  121149. static static_codebook _huff_book__44c9_s_short = {
  121150. 2, 100,
  121151. _huff_lengthlist__44c9_s_short,
  121152. 0, 0, 0, 0, 0,
  121153. NULL,
  121154. NULL,
  121155. NULL,
  121156. NULL,
  121157. 0
  121158. };
  121159. static long _huff_lengthlist__44c0_s_long[] = {
  121160. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121161. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121162. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121163. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121164. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121165. 12,
  121166. };
  121167. static static_codebook _huff_book__44c0_s_long = {
  121168. 2, 81,
  121169. _huff_lengthlist__44c0_s_long,
  121170. 0, 0, 0, 0, 0,
  121171. NULL,
  121172. NULL,
  121173. NULL,
  121174. NULL,
  121175. 0
  121176. };
  121177. static long _vq_quantlist__44c0_s_p1_0[] = {
  121178. 1,
  121179. 0,
  121180. 2,
  121181. };
  121182. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121183. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121184. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121188. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121189. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121193. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121194. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121229. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121234. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121239. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121274. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121275. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121279. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121280. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  121281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121284. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121285. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121593. 0,
  121594. };
  121595. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121596. -0.5, 0.5,
  121597. };
  121598. static long _vq_quantmap__44c0_s_p1_0[] = {
  121599. 1, 0, 2,
  121600. };
  121601. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121602. _vq_quantthresh__44c0_s_p1_0,
  121603. _vq_quantmap__44c0_s_p1_0,
  121604. 3,
  121605. 3
  121606. };
  121607. static static_codebook _44c0_s_p1_0 = {
  121608. 8, 6561,
  121609. _vq_lengthlist__44c0_s_p1_0,
  121610. 1, -535822336, 1611661312, 2, 0,
  121611. _vq_quantlist__44c0_s_p1_0,
  121612. NULL,
  121613. &_vq_auxt__44c0_s_p1_0,
  121614. NULL,
  121615. 0
  121616. };
  121617. static long _vq_quantlist__44c0_s_p2_0[] = {
  121618. 2,
  121619. 1,
  121620. 3,
  121621. 0,
  121622. 4,
  121623. };
  121624. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121625. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121628. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121631. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  121632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121664. 0,
  121665. };
  121666. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121667. -1.5, -0.5, 0.5, 1.5,
  121668. };
  121669. static long _vq_quantmap__44c0_s_p2_0[] = {
  121670. 3, 1, 0, 2, 4,
  121671. };
  121672. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121673. _vq_quantthresh__44c0_s_p2_0,
  121674. _vq_quantmap__44c0_s_p2_0,
  121675. 5,
  121676. 5
  121677. };
  121678. static static_codebook _44c0_s_p2_0 = {
  121679. 4, 625,
  121680. _vq_lengthlist__44c0_s_p2_0,
  121681. 1, -533725184, 1611661312, 3, 0,
  121682. _vq_quantlist__44c0_s_p2_0,
  121683. NULL,
  121684. &_vq_auxt__44c0_s_p2_0,
  121685. NULL,
  121686. 0
  121687. };
  121688. static long _vq_quantlist__44c0_s_p3_0[] = {
  121689. 4,
  121690. 3,
  121691. 5,
  121692. 2,
  121693. 6,
  121694. 1,
  121695. 7,
  121696. 0,
  121697. 8,
  121698. };
  121699. static long _vq_lengthlist__44c0_s_p3_0[] = {
  121700. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  121701. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  121702. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  121703. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  121704. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121705. 0,
  121706. };
  121707. static float _vq_quantthresh__44c0_s_p3_0[] = {
  121708. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121709. };
  121710. static long _vq_quantmap__44c0_s_p3_0[] = {
  121711. 7, 5, 3, 1, 0, 2, 4, 6,
  121712. 8,
  121713. };
  121714. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  121715. _vq_quantthresh__44c0_s_p3_0,
  121716. _vq_quantmap__44c0_s_p3_0,
  121717. 9,
  121718. 9
  121719. };
  121720. static static_codebook _44c0_s_p3_0 = {
  121721. 2, 81,
  121722. _vq_lengthlist__44c0_s_p3_0,
  121723. 1, -531628032, 1611661312, 4, 0,
  121724. _vq_quantlist__44c0_s_p3_0,
  121725. NULL,
  121726. &_vq_auxt__44c0_s_p3_0,
  121727. NULL,
  121728. 0
  121729. };
  121730. static long _vq_quantlist__44c0_s_p4_0[] = {
  121731. 4,
  121732. 3,
  121733. 5,
  121734. 2,
  121735. 6,
  121736. 1,
  121737. 7,
  121738. 0,
  121739. 8,
  121740. };
  121741. static long _vq_lengthlist__44c0_s_p4_0[] = {
  121742. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  121743. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  121744. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  121745. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  121746. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  121747. 10,
  121748. };
  121749. static float _vq_quantthresh__44c0_s_p4_0[] = {
  121750. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121751. };
  121752. static long _vq_quantmap__44c0_s_p4_0[] = {
  121753. 7, 5, 3, 1, 0, 2, 4, 6,
  121754. 8,
  121755. };
  121756. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  121757. _vq_quantthresh__44c0_s_p4_0,
  121758. _vq_quantmap__44c0_s_p4_0,
  121759. 9,
  121760. 9
  121761. };
  121762. static static_codebook _44c0_s_p4_0 = {
  121763. 2, 81,
  121764. _vq_lengthlist__44c0_s_p4_0,
  121765. 1, -531628032, 1611661312, 4, 0,
  121766. _vq_quantlist__44c0_s_p4_0,
  121767. NULL,
  121768. &_vq_auxt__44c0_s_p4_0,
  121769. NULL,
  121770. 0
  121771. };
  121772. static long _vq_quantlist__44c0_s_p5_0[] = {
  121773. 8,
  121774. 7,
  121775. 9,
  121776. 6,
  121777. 10,
  121778. 5,
  121779. 11,
  121780. 4,
  121781. 12,
  121782. 3,
  121783. 13,
  121784. 2,
  121785. 14,
  121786. 1,
  121787. 15,
  121788. 0,
  121789. 16,
  121790. };
  121791. static long _vq_lengthlist__44c0_s_p5_0[] = {
  121792. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  121793. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  121794. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  121795. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  121796. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  121797. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  121798. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  121799. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  121800. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  121801. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  121802. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  121803. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  121804. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  121805. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  121806. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  121807. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  121808. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  121809. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  121810. 14,
  121811. };
  121812. static float _vq_quantthresh__44c0_s_p5_0[] = {
  121813. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121814. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121815. };
  121816. static long _vq_quantmap__44c0_s_p5_0[] = {
  121817. 15, 13, 11, 9, 7, 5, 3, 1,
  121818. 0, 2, 4, 6, 8, 10, 12, 14,
  121819. 16,
  121820. };
  121821. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  121822. _vq_quantthresh__44c0_s_p5_0,
  121823. _vq_quantmap__44c0_s_p5_0,
  121824. 17,
  121825. 17
  121826. };
  121827. static static_codebook _44c0_s_p5_0 = {
  121828. 2, 289,
  121829. _vq_lengthlist__44c0_s_p5_0,
  121830. 1, -529530880, 1611661312, 5, 0,
  121831. _vq_quantlist__44c0_s_p5_0,
  121832. NULL,
  121833. &_vq_auxt__44c0_s_p5_0,
  121834. NULL,
  121835. 0
  121836. };
  121837. static long _vq_quantlist__44c0_s_p6_0[] = {
  121838. 1,
  121839. 0,
  121840. 2,
  121841. };
  121842. static long _vq_lengthlist__44c0_s_p6_0[] = {
  121843. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  121844. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  121845. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  121846. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  121847. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  121848. 10,
  121849. };
  121850. static float _vq_quantthresh__44c0_s_p6_0[] = {
  121851. -5.5, 5.5,
  121852. };
  121853. static long _vq_quantmap__44c0_s_p6_0[] = {
  121854. 1, 0, 2,
  121855. };
  121856. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  121857. _vq_quantthresh__44c0_s_p6_0,
  121858. _vq_quantmap__44c0_s_p6_0,
  121859. 3,
  121860. 3
  121861. };
  121862. static static_codebook _44c0_s_p6_0 = {
  121863. 4, 81,
  121864. _vq_lengthlist__44c0_s_p6_0,
  121865. 1, -529137664, 1618345984, 2, 0,
  121866. _vq_quantlist__44c0_s_p6_0,
  121867. NULL,
  121868. &_vq_auxt__44c0_s_p6_0,
  121869. NULL,
  121870. 0
  121871. };
  121872. static long _vq_quantlist__44c0_s_p6_1[] = {
  121873. 5,
  121874. 4,
  121875. 6,
  121876. 3,
  121877. 7,
  121878. 2,
  121879. 8,
  121880. 1,
  121881. 9,
  121882. 0,
  121883. 10,
  121884. };
  121885. static long _vq_lengthlist__44c0_s_p6_1[] = {
  121886. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  121887. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  121888. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  121889. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  121890. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  121891. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  121892. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  121893. 10,10,10, 8, 8, 8, 8, 8, 8,
  121894. };
  121895. static float _vq_quantthresh__44c0_s_p6_1[] = {
  121896. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121897. 3.5, 4.5,
  121898. };
  121899. static long _vq_quantmap__44c0_s_p6_1[] = {
  121900. 9, 7, 5, 3, 1, 0, 2, 4,
  121901. 6, 8, 10,
  121902. };
  121903. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  121904. _vq_quantthresh__44c0_s_p6_1,
  121905. _vq_quantmap__44c0_s_p6_1,
  121906. 11,
  121907. 11
  121908. };
  121909. static static_codebook _44c0_s_p6_1 = {
  121910. 2, 121,
  121911. _vq_lengthlist__44c0_s_p6_1,
  121912. 1, -531365888, 1611661312, 4, 0,
  121913. _vq_quantlist__44c0_s_p6_1,
  121914. NULL,
  121915. &_vq_auxt__44c0_s_p6_1,
  121916. NULL,
  121917. 0
  121918. };
  121919. static long _vq_quantlist__44c0_s_p7_0[] = {
  121920. 6,
  121921. 5,
  121922. 7,
  121923. 4,
  121924. 8,
  121925. 3,
  121926. 9,
  121927. 2,
  121928. 10,
  121929. 1,
  121930. 11,
  121931. 0,
  121932. 12,
  121933. };
  121934. static long _vq_lengthlist__44c0_s_p7_0[] = {
  121935. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  121936. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  121937. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  121938. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  121939. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  121940. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  121941. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  121942. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  121943. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  121944. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  121945. 0,12,12,11,11,12,12,13,13,
  121946. };
  121947. static float _vq_quantthresh__44c0_s_p7_0[] = {
  121948. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121949. 12.5, 17.5, 22.5, 27.5,
  121950. };
  121951. static long _vq_quantmap__44c0_s_p7_0[] = {
  121952. 11, 9, 7, 5, 3, 1, 0, 2,
  121953. 4, 6, 8, 10, 12,
  121954. };
  121955. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  121956. _vq_quantthresh__44c0_s_p7_0,
  121957. _vq_quantmap__44c0_s_p7_0,
  121958. 13,
  121959. 13
  121960. };
  121961. static static_codebook _44c0_s_p7_0 = {
  121962. 2, 169,
  121963. _vq_lengthlist__44c0_s_p7_0,
  121964. 1, -526516224, 1616117760, 4, 0,
  121965. _vq_quantlist__44c0_s_p7_0,
  121966. NULL,
  121967. &_vq_auxt__44c0_s_p7_0,
  121968. NULL,
  121969. 0
  121970. };
  121971. static long _vq_quantlist__44c0_s_p7_1[] = {
  121972. 2,
  121973. 1,
  121974. 3,
  121975. 0,
  121976. 4,
  121977. };
  121978. static long _vq_lengthlist__44c0_s_p7_1[] = {
  121979. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  121980. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  121981. };
  121982. static float _vq_quantthresh__44c0_s_p7_1[] = {
  121983. -1.5, -0.5, 0.5, 1.5,
  121984. };
  121985. static long _vq_quantmap__44c0_s_p7_1[] = {
  121986. 3, 1, 0, 2, 4,
  121987. };
  121988. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  121989. _vq_quantthresh__44c0_s_p7_1,
  121990. _vq_quantmap__44c0_s_p7_1,
  121991. 5,
  121992. 5
  121993. };
  121994. static static_codebook _44c0_s_p7_1 = {
  121995. 2, 25,
  121996. _vq_lengthlist__44c0_s_p7_1,
  121997. 1, -533725184, 1611661312, 3, 0,
  121998. _vq_quantlist__44c0_s_p7_1,
  121999. NULL,
  122000. &_vq_auxt__44c0_s_p7_1,
  122001. NULL,
  122002. 0
  122003. };
  122004. static long _vq_quantlist__44c0_s_p8_0[] = {
  122005. 2,
  122006. 1,
  122007. 3,
  122008. 0,
  122009. 4,
  122010. };
  122011. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122012. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122013. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122014. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122015. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122016. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122017. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122018. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122019. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122020. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122021. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122022. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122023. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122024. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122025. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122026. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122027. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122028. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122029. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122030. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122031. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122032. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122033. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122034. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122035. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122036. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122037. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122038. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122039. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122040. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122041. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122042. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122043. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122044. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122045. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122046. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122047. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122048. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122049. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122050. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122051. 11,
  122052. };
  122053. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122054. -331.5, -110.5, 110.5, 331.5,
  122055. };
  122056. static long _vq_quantmap__44c0_s_p8_0[] = {
  122057. 3, 1, 0, 2, 4,
  122058. };
  122059. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122060. _vq_quantthresh__44c0_s_p8_0,
  122061. _vq_quantmap__44c0_s_p8_0,
  122062. 5,
  122063. 5
  122064. };
  122065. static static_codebook _44c0_s_p8_0 = {
  122066. 4, 625,
  122067. _vq_lengthlist__44c0_s_p8_0,
  122068. 1, -518283264, 1627103232, 3, 0,
  122069. _vq_quantlist__44c0_s_p8_0,
  122070. NULL,
  122071. &_vq_auxt__44c0_s_p8_0,
  122072. NULL,
  122073. 0
  122074. };
  122075. static long _vq_quantlist__44c0_s_p8_1[] = {
  122076. 6,
  122077. 5,
  122078. 7,
  122079. 4,
  122080. 8,
  122081. 3,
  122082. 9,
  122083. 2,
  122084. 10,
  122085. 1,
  122086. 11,
  122087. 0,
  122088. 12,
  122089. };
  122090. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122091. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122092. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122093. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122094. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122095. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122096. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122097. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122098. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122099. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122100. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122101. 16,13,13,12,12,14,14,15,13,
  122102. };
  122103. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122104. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122105. 42.5, 59.5, 76.5, 93.5,
  122106. };
  122107. static long _vq_quantmap__44c0_s_p8_1[] = {
  122108. 11, 9, 7, 5, 3, 1, 0, 2,
  122109. 4, 6, 8, 10, 12,
  122110. };
  122111. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122112. _vq_quantthresh__44c0_s_p8_1,
  122113. _vq_quantmap__44c0_s_p8_1,
  122114. 13,
  122115. 13
  122116. };
  122117. static static_codebook _44c0_s_p8_1 = {
  122118. 2, 169,
  122119. _vq_lengthlist__44c0_s_p8_1,
  122120. 1, -522616832, 1620115456, 4, 0,
  122121. _vq_quantlist__44c0_s_p8_1,
  122122. NULL,
  122123. &_vq_auxt__44c0_s_p8_1,
  122124. NULL,
  122125. 0
  122126. };
  122127. static long _vq_quantlist__44c0_s_p8_2[] = {
  122128. 8,
  122129. 7,
  122130. 9,
  122131. 6,
  122132. 10,
  122133. 5,
  122134. 11,
  122135. 4,
  122136. 12,
  122137. 3,
  122138. 13,
  122139. 2,
  122140. 14,
  122141. 1,
  122142. 15,
  122143. 0,
  122144. 16,
  122145. };
  122146. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122147. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122148. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122149. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122150. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122151. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122152. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122153. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122154. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122155. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122156. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122157. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122158. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122159. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122160. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122161. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122162. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122163. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122164. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122165. 10,
  122166. };
  122167. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122168. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122169. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122170. };
  122171. static long _vq_quantmap__44c0_s_p8_2[] = {
  122172. 15, 13, 11, 9, 7, 5, 3, 1,
  122173. 0, 2, 4, 6, 8, 10, 12, 14,
  122174. 16,
  122175. };
  122176. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122177. _vq_quantthresh__44c0_s_p8_2,
  122178. _vq_quantmap__44c0_s_p8_2,
  122179. 17,
  122180. 17
  122181. };
  122182. static static_codebook _44c0_s_p8_2 = {
  122183. 2, 289,
  122184. _vq_lengthlist__44c0_s_p8_2,
  122185. 1, -529530880, 1611661312, 5, 0,
  122186. _vq_quantlist__44c0_s_p8_2,
  122187. NULL,
  122188. &_vq_auxt__44c0_s_p8_2,
  122189. NULL,
  122190. 0
  122191. };
  122192. static long _huff_lengthlist__44c0_s_short[] = {
  122193. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122194. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122195. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122196. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122197. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122198. 12,
  122199. };
  122200. static static_codebook _huff_book__44c0_s_short = {
  122201. 2, 81,
  122202. _huff_lengthlist__44c0_s_short,
  122203. 0, 0, 0, 0, 0,
  122204. NULL,
  122205. NULL,
  122206. NULL,
  122207. NULL,
  122208. 0
  122209. };
  122210. static long _huff_lengthlist__44c0_sm_long[] = {
  122211. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122212. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122213. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122214. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122215. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122216. 13,
  122217. };
  122218. static static_codebook _huff_book__44c0_sm_long = {
  122219. 2, 81,
  122220. _huff_lengthlist__44c0_sm_long,
  122221. 0, 0, 0, 0, 0,
  122222. NULL,
  122223. NULL,
  122224. NULL,
  122225. NULL,
  122226. 0
  122227. };
  122228. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122229. 1,
  122230. 0,
  122231. 2,
  122232. };
  122233. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122234. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122235. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122239. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122240. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122244. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122245. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122280. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  122281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122285. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122290. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122325. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122326. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122330. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122331. 0, 0, 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  122332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122335. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122336. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  122337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122644. 0,
  122645. };
  122646. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122647. -0.5, 0.5,
  122648. };
  122649. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122650. 1, 0, 2,
  122651. };
  122652. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122653. _vq_quantthresh__44c0_sm_p1_0,
  122654. _vq_quantmap__44c0_sm_p1_0,
  122655. 3,
  122656. 3
  122657. };
  122658. static static_codebook _44c0_sm_p1_0 = {
  122659. 8, 6561,
  122660. _vq_lengthlist__44c0_sm_p1_0,
  122661. 1, -535822336, 1611661312, 2, 0,
  122662. _vq_quantlist__44c0_sm_p1_0,
  122663. NULL,
  122664. &_vq_auxt__44c0_sm_p1_0,
  122665. NULL,
  122666. 0
  122667. };
  122668. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122669. 2,
  122670. 1,
  122671. 3,
  122672. 0,
  122673. 4,
  122674. };
  122675. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122676. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122679. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122682. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122715. 0,
  122716. };
  122717. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  122718. -1.5, -0.5, 0.5, 1.5,
  122719. };
  122720. static long _vq_quantmap__44c0_sm_p2_0[] = {
  122721. 3, 1, 0, 2, 4,
  122722. };
  122723. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  122724. _vq_quantthresh__44c0_sm_p2_0,
  122725. _vq_quantmap__44c0_sm_p2_0,
  122726. 5,
  122727. 5
  122728. };
  122729. static static_codebook _44c0_sm_p2_0 = {
  122730. 4, 625,
  122731. _vq_lengthlist__44c0_sm_p2_0,
  122732. 1, -533725184, 1611661312, 3, 0,
  122733. _vq_quantlist__44c0_sm_p2_0,
  122734. NULL,
  122735. &_vq_auxt__44c0_sm_p2_0,
  122736. NULL,
  122737. 0
  122738. };
  122739. static long _vq_quantlist__44c0_sm_p3_0[] = {
  122740. 4,
  122741. 3,
  122742. 5,
  122743. 2,
  122744. 6,
  122745. 1,
  122746. 7,
  122747. 0,
  122748. 8,
  122749. };
  122750. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  122751. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  122752. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  122753. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  122754. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  122755. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122756. 0,
  122757. };
  122758. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  122759. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122760. };
  122761. static long _vq_quantmap__44c0_sm_p3_0[] = {
  122762. 7, 5, 3, 1, 0, 2, 4, 6,
  122763. 8,
  122764. };
  122765. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  122766. _vq_quantthresh__44c0_sm_p3_0,
  122767. _vq_quantmap__44c0_sm_p3_0,
  122768. 9,
  122769. 9
  122770. };
  122771. static static_codebook _44c0_sm_p3_0 = {
  122772. 2, 81,
  122773. _vq_lengthlist__44c0_sm_p3_0,
  122774. 1, -531628032, 1611661312, 4, 0,
  122775. _vq_quantlist__44c0_sm_p3_0,
  122776. NULL,
  122777. &_vq_auxt__44c0_sm_p3_0,
  122778. NULL,
  122779. 0
  122780. };
  122781. static long _vq_quantlist__44c0_sm_p4_0[] = {
  122782. 4,
  122783. 3,
  122784. 5,
  122785. 2,
  122786. 6,
  122787. 1,
  122788. 7,
  122789. 0,
  122790. 8,
  122791. };
  122792. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  122793. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  122794. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  122795. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  122796. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  122797. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  122798. 11,
  122799. };
  122800. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  122801. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122802. };
  122803. static long _vq_quantmap__44c0_sm_p4_0[] = {
  122804. 7, 5, 3, 1, 0, 2, 4, 6,
  122805. 8,
  122806. };
  122807. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  122808. _vq_quantthresh__44c0_sm_p4_0,
  122809. _vq_quantmap__44c0_sm_p4_0,
  122810. 9,
  122811. 9
  122812. };
  122813. static static_codebook _44c0_sm_p4_0 = {
  122814. 2, 81,
  122815. _vq_lengthlist__44c0_sm_p4_0,
  122816. 1, -531628032, 1611661312, 4, 0,
  122817. _vq_quantlist__44c0_sm_p4_0,
  122818. NULL,
  122819. &_vq_auxt__44c0_sm_p4_0,
  122820. NULL,
  122821. 0
  122822. };
  122823. static long _vq_quantlist__44c0_sm_p5_0[] = {
  122824. 8,
  122825. 7,
  122826. 9,
  122827. 6,
  122828. 10,
  122829. 5,
  122830. 11,
  122831. 4,
  122832. 12,
  122833. 3,
  122834. 13,
  122835. 2,
  122836. 14,
  122837. 1,
  122838. 15,
  122839. 0,
  122840. 16,
  122841. };
  122842. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  122843. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  122844. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  122845. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122846. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  122847. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  122848. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  122849. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  122850. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122851. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  122852. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  122853. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122854. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122855. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  122856. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  122857. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  122858. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  122859. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  122860. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122861. 14,
  122862. };
  122863. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  122864. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122865. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122866. };
  122867. static long _vq_quantmap__44c0_sm_p5_0[] = {
  122868. 15, 13, 11, 9, 7, 5, 3, 1,
  122869. 0, 2, 4, 6, 8, 10, 12, 14,
  122870. 16,
  122871. };
  122872. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  122873. _vq_quantthresh__44c0_sm_p5_0,
  122874. _vq_quantmap__44c0_sm_p5_0,
  122875. 17,
  122876. 17
  122877. };
  122878. static static_codebook _44c0_sm_p5_0 = {
  122879. 2, 289,
  122880. _vq_lengthlist__44c0_sm_p5_0,
  122881. 1, -529530880, 1611661312, 5, 0,
  122882. _vq_quantlist__44c0_sm_p5_0,
  122883. NULL,
  122884. &_vq_auxt__44c0_sm_p5_0,
  122885. NULL,
  122886. 0
  122887. };
  122888. static long _vq_quantlist__44c0_sm_p6_0[] = {
  122889. 1,
  122890. 0,
  122891. 2,
  122892. };
  122893. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  122894. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  122895. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  122896. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  122897. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  122898. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122899. 11,
  122900. };
  122901. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  122902. -5.5, 5.5,
  122903. };
  122904. static long _vq_quantmap__44c0_sm_p6_0[] = {
  122905. 1, 0, 2,
  122906. };
  122907. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  122908. _vq_quantthresh__44c0_sm_p6_0,
  122909. _vq_quantmap__44c0_sm_p6_0,
  122910. 3,
  122911. 3
  122912. };
  122913. static static_codebook _44c0_sm_p6_0 = {
  122914. 4, 81,
  122915. _vq_lengthlist__44c0_sm_p6_0,
  122916. 1, -529137664, 1618345984, 2, 0,
  122917. _vq_quantlist__44c0_sm_p6_0,
  122918. NULL,
  122919. &_vq_auxt__44c0_sm_p6_0,
  122920. NULL,
  122921. 0
  122922. };
  122923. static long _vq_quantlist__44c0_sm_p6_1[] = {
  122924. 5,
  122925. 4,
  122926. 6,
  122927. 3,
  122928. 7,
  122929. 2,
  122930. 8,
  122931. 1,
  122932. 9,
  122933. 0,
  122934. 10,
  122935. };
  122936. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  122937. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  122938. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  122939. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122940. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  122941. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  122942. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122943. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122944. 10,10,10, 8, 8, 8, 8, 8, 8,
  122945. };
  122946. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  122947. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122948. 3.5, 4.5,
  122949. };
  122950. static long _vq_quantmap__44c0_sm_p6_1[] = {
  122951. 9, 7, 5, 3, 1, 0, 2, 4,
  122952. 6, 8, 10,
  122953. };
  122954. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  122955. _vq_quantthresh__44c0_sm_p6_1,
  122956. _vq_quantmap__44c0_sm_p6_1,
  122957. 11,
  122958. 11
  122959. };
  122960. static static_codebook _44c0_sm_p6_1 = {
  122961. 2, 121,
  122962. _vq_lengthlist__44c0_sm_p6_1,
  122963. 1, -531365888, 1611661312, 4, 0,
  122964. _vq_quantlist__44c0_sm_p6_1,
  122965. NULL,
  122966. &_vq_auxt__44c0_sm_p6_1,
  122967. NULL,
  122968. 0
  122969. };
  122970. static long _vq_quantlist__44c0_sm_p7_0[] = {
  122971. 6,
  122972. 5,
  122973. 7,
  122974. 4,
  122975. 8,
  122976. 3,
  122977. 9,
  122978. 2,
  122979. 10,
  122980. 1,
  122981. 11,
  122982. 0,
  122983. 12,
  122984. };
  122985. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  122986. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122987. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  122988. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122989. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122990. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122991. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  122992. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122993. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122994. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122995. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  122996. 0,12,12,11,11,13,12,14,14,
  122997. };
  122998. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  122999. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123000. 12.5, 17.5, 22.5, 27.5,
  123001. };
  123002. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123003. 11, 9, 7, 5, 3, 1, 0, 2,
  123004. 4, 6, 8, 10, 12,
  123005. };
  123006. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123007. _vq_quantthresh__44c0_sm_p7_0,
  123008. _vq_quantmap__44c0_sm_p7_0,
  123009. 13,
  123010. 13
  123011. };
  123012. static static_codebook _44c0_sm_p7_0 = {
  123013. 2, 169,
  123014. _vq_lengthlist__44c0_sm_p7_0,
  123015. 1, -526516224, 1616117760, 4, 0,
  123016. _vq_quantlist__44c0_sm_p7_0,
  123017. NULL,
  123018. &_vq_auxt__44c0_sm_p7_0,
  123019. NULL,
  123020. 0
  123021. };
  123022. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123023. 2,
  123024. 1,
  123025. 3,
  123026. 0,
  123027. 4,
  123028. };
  123029. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123030. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123031. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123032. };
  123033. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123034. -1.5, -0.5, 0.5, 1.5,
  123035. };
  123036. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123037. 3, 1, 0, 2, 4,
  123038. };
  123039. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123040. _vq_quantthresh__44c0_sm_p7_1,
  123041. _vq_quantmap__44c0_sm_p7_1,
  123042. 5,
  123043. 5
  123044. };
  123045. static static_codebook _44c0_sm_p7_1 = {
  123046. 2, 25,
  123047. _vq_lengthlist__44c0_sm_p7_1,
  123048. 1, -533725184, 1611661312, 3, 0,
  123049. _vq_quantlist__44c0_sm_p7_1,
  123050. NULL,
  123051. &_vq_auxt__44c0_sm_p7_1,
  123052. NULL,
  123053. 0
  123054. };
  123055. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123056. 4,
  123057. 3,
  123058. 5,
  123059. 2,
  123060. 6,
  123061. 1,
  123062. 7,
  123063. 0,
  123064. 8,
  123065. };
  123066. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123067. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123068. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123069. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123070. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123071. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123072. 12,
  123073. };
  123074. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123075. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123076. };
  123077. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123078. 7, 5, 3, 1, 0, 2, 4, 6,
  123079. 8,
  123080. };
  123081. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123082. _vq_quantthresh__44c0_sm_p8_0,
  123083. _vq_quantmap__44c0_sm_p8_0,
  123084. 9,
  123085. 9
  123086. };
  123087. static static_codebook _44c0_sm_p8_0 = {
  123088. 2, 81,
  123089. _vq_lengthlist__44c0_sm_p8_0,
  123090. 1, -516186112, 1627103232, 4, 0,
  123091. _vq_quantlist__44c0_sm_p8_0,
  123092. NULL,
  123093. &_vq_auxt__44c0_sm_p8_0,
  123094. NULL,
  123095. 0
  123096. };
  123097. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123098. 6,
  123099. 5,
  123100. 7,
  123101. 4,
  123102. 8,
  123103. 3,
  123104. 9,
  123105. 2,
  123106. 10,
  123107. 1,
  123108. 11,
  123109. 0,
  123110. 12,
  123111. };
  123112. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123113. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123114. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123115. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123116. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123117. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123118. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123119. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123120. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123121. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123122. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123123. 20,13,13,12,12,16,13,15,13,
  123124. };
  123125. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123126. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123127. 42.5, 59.5, 76.5, 93.5,
  123128. };
  123129. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123130. 11, 9, 7, 5, 3, 1, 0, 2,
  123131. 4, 6, 8, 10, 12,
  123132. };
  123133. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123134. _vq_quantthresh__44c0_sm_p8_1,
  123135. _vq_quantmap__44c0_sm_p8_1,
  123136. 13,
  123137. 13
  123138. };
  123139. static static_codebook _44c0_sm_p8_1 = {
  123140. 2, 169,
  123141. _vq_lengthlist__44c0_sm_p8_1,
  123142. 1, -522616832, 1620115456, 4, 0,
  123143. _vq_quantlist__44c0_sm_p8_1,
  123144. NULL,
  123145. &_vq_auxt__44c0_sm_p8_1,
  123146. NULL,
  123147. 0
  123148. };
  123149. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123150. 8,
  123151. 7,
  123152. 9,
  123153. 6,
  123154. 10,
  123155. 5,
  123156. 11,
  123157. 4,
  123158. 12,
  123159. 3,
  123160. 13,
  123161. 2,
  123162. 14,
  123163. 1,
  123164. 15,
  123165. 0,
  123166. 16,
  123167. };
  123168. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123169. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123170. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123171. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123172. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123173. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123174. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123175. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123176. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123177. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123178. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123179. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123180. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123181. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123182. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123183. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123184. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123185. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123186. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123187. 9,
  123188. };
  123189. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123190. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123191. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123192. };
  123193. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123194. 15, 13, 11, 9, 7, 5, 3, 1,
  123195. 0, 2, 4, 6, 8, 10, 12, 14,
  123196. 16,
  123197. };
  123198. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123199. _vq_quantthresh__44c0_sm_p8_2,
  123200. _vq_quantmap__44c0_sm_p8_2,
  123201. 17,
  123202. 17
  123203. };
  123204. static static_codebook _44c0_sm_p8_2 = {
  123205. 2, 289,
  123206. _vq_lengthlist__44c0_sm_p8_2,
  123207. 1, -529530880, 1611661312, 5, 0,
  123208. _vq_quantlist__44c0_sm_p8_2,
  123209. NULL,
  123210. &_vq_auxt__44c0_sm_p8_2,
  123211. NULL,
  123212. 0
  123213. };
  123214. static long _huff_lengthlist__44c0_sm_short[] = {
  123215. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123216. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123217. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123218. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123219. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123220. 12,
  123221. };
  123222. static static_codebook _huff_book__44c0_sm_short = {
  123223. 2, 81,
  123224. _huff_lengthlist__44c0_sm_short,
  123225. 0, 0, 0, 0, 0,
  123226. NULL,
  123227. NULL,
  123228. NULL,
  123229. NULL,
  123230. 0
  123231. };
  123232. static long _huff_lengthlist__44c1_s_long[] = {
  123233. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123234. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123235. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123236. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123237. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123238. 11,
  123239. };
  123240. static static_codebook _huff_book__44c1_s_long = {
  123241. 2, 81,
  123242. _huff_lengthlist__44c1_s_long,
  123243. 0, 0, 0, 0, 0,
  123244. NULL,
  123245. NULL,
  123246. NULL,
  123247. NULL,
  123248. 0
  123249. };
  123250. static long _vq_quantlist__44c1_s_p1_0[] = {
  123251. 1,
  123252. 0,
  123253. 2,
  123254. };
  123255. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123256. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123257. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123261. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123262. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123266. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123267. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123302. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123307. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  123308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  123312. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123347. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123348. 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123352. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123353. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  123354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123357. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123358. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123666. 0,
  123667. };
  123668. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123669. -0.5, 0.5,
  123670. };
  123671. static long _vq_quantmap__44c1_s_p1_0[] = {
  123672. 1, 0, 2,
  123673. };
  123674. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123675. _vq_quantthresh__44c1_s_p1_0,
  123676. _vq_quantmap__44c1_s_p1_0,
  123677. 3,
  123678. 3
  123679. };
  123680. static static_codebook _44c1_s_p1_0 = {
  123681. 8, 6561,
  123682. _vq_lengthlist__44c1_s_p1_0,
  123683. 1, -535822336, 1611661312, 2, 0,
  123684. _vq_quantlist__44c1_s_p1_0,
  123685. NULL,
  123686. &_vq_auxt__44c1_s_p1_0,
  123687. NULL,
  123688. 0
  123689. };
  123690. static long _vq_quantlist__44c1_s_p2_0[] = {
  123691. 2,
  123692. 1,
  123693. 3,
  123694. 0,
  123695. 4,
  123696. };
  123697. static long _vq_lengthlist__44c1_s_p2_0[] = {
  123698. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  123700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123701. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  123703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123704. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123737. 0,
  123738. };
  123739. static float _vq_quantthresh__44c1_s_p2_0[] = {
  123740. -1.5, -0.5, 0.5, 1.5,
  123741. };
  123742. static long _vq_quantmap__44c1_s_p2_0[] = {
  123743. 3, 1, 0, 2, 4,
  123744. };
  123745. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  123746. _vq_quantthresh__44c1_s_p2_0,
  123747. _vq_quantmap__44c1_s_p2_0,
  123748. 5,
  123749. 5
  123750. };
  123751. static static_codebook _44c1_s_p2_0 = {
  123752. 4, 625,
  123753. _vq_lengthlist__44c1_s_p2_0,
  123754. 1, -533725184, 1611661312, 3, 0,
  123755. _vq_quantlist__44c1_s_p2_0,
  123756. NULL,
  123757. &_vq_auxt__44c1_s_p2_0,
  123758. NULL,
  123759. 0
  123760. };
  123761. static long _vq_quantlist__44c1_s_p3_0[] = {
  123762. 4,
  123763. 3,
  123764. 5,
  123765. 2,
  123766. 6,
  123767. 1,
  123768. 7,
  123769. 0,
  123770. 8,
  123771. };
  123772. static long _vq_lengthlist__44c1_s_p3_0[] = {
  123773. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  123774. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  123775. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  123776. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  123777. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123778. 0,
  123779. };
  123780. static float _vq_quantthresh__44c1_s_p3_0[] = {
  123781. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123782. };
  123783. static long _vq_quantmap__44c1_s_p3_0[] = {
  123784. 7, 5, 3, 1, 0, 2, 4, 6,
  123785. 8,
  123786. };
  123787. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  123788. _vq_quantthresh__44c1_s_p3_0,
  123789. _vq_quantmap__44c1_s_p3_0,
  123790. 9,
  123791. 9
  123792. };
  123793. static static_codebook _44c1_s_p3_0 = {
  123794. 2, 81,
  123795. _vq_lengthlist__44c1_s_p3_0,
  123796. 1, -531628032, 1611661312, 4, 0,
  123797. _vq_quantlist__44c1_s_p3_0,
  123798. NULL,
  123799. &_vq_auxt__44c1_s_p3_0,
  123800. NULL,
  123801. 0
  123802. };
  123803. static long _vq_quantlist__44c1_s_p4_0[] = {
  123804. 4,
  123805. 3,
  123806. 5,
  123807. 2,
  123808. 6,
  123809. 1,
  123810. 7,
  123811. 0,
  123812. 8,
  123813. };
  123814. static long _vq_lengthlist__44c1_s_p4_0[] = {
  123815. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  123816. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  123817. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  123818. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  123819. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123820. 11,
  123821. };
  123822. static float _vq_quantthresh__44c1_s_p4_0[] = {
  123823. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123824. };
  123825. static long _vq_quantmap__44c1_s_p4_0[] = {
  123826. 7, 5, 3, 1, 0, 2, 4, 6,
  123827. 8,
  123828. };
  123829. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  123830. _vq_quantthresh__44c1_s_p4_0,
  123831. _vq_quantmap__44c1_s_p4_0,
  123832. 9,
  123833. 9
  123834. };
  123835. static static_codebook _44c1_s_p4_0 = {
  123836. 2, 81,
  123837. _vq_lengthlist__44c1_s_p4_0,
  123838. 1, -531628032, 1611661312, 4, 0,
  123839. _vq_quantlist__44c1_s_p4_0,
  123840. NULL,
  123841. &_vq_auxt__44c1_s_p4_0,
  123842. NULL,
  123843. 0
  123844. };
  123845. static long _vq_quantlist__44c1_s_p5_0[] = {
  123846. 8,
  123847. 7,
  123848. 9,
  123849. 6,
  123850. 10,
  123851. 5,
  123852. 11,
  123853. 4,
  123854. 12,
  123855. 3,
  123856. 13,
  123857. 2,
  123858. 14,
  123859. 1,
  123860. 15,
  123861. 0,
  123862. 16,
  123863. };
  123864. static long _vq_lengthlist__44c1_s_p5_0[] = {
  123865. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  123866. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  123867. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123868. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  123869. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  123870. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  123871. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  123872. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123873. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  123874. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  123875. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123876. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123877. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  123878. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  123879. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  123880. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  123881. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  123882. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123883. 14,
  123884. };
  123885. static float _vq_quantthresh__44c1_s_p5_0[] = {
  123886. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123887. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123888. };
  123889. static long _vq_quantmap__44c1_s_p5_0[] = {
  123890. 15, 13, 11, 9, 7, 5, 3, 1,
  123891. 0, 2, 4, 6, 8, 10, 12, 14,
  123892. 16,
  123893. };
  123894. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  123895. _vq_quantthresh__44c1_s_p5_0,
  123896. _vq_quantmap__44c1_s_p5_0,
  123897. 17,
  123898. 17
  123899. };
  123900. static static_codebook _44c1_s_p5_0 = {
  123901. 2, 289,
  123902. _vq_lengthlist__44c1_s_p5_0,
  123903. 1, -529530880, 1611661312, 5, 0,
  123904. _vq_quantlist__44c1_s_p5_0,
  123905. NULL,
  123906. &_vq_auxt__44c1_s_p5_0,
  123907. NULL,
  123908. 0
  123909. };
  123910. static long _vq_quantlist__44c1_s_p6_0[] = {
  123911. 1,
  123912. 0,
  123913. 2,
  123914. };
  123915. static long _vq_lengthlist__44c1_s_p6_0[] = {
  123916. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123917. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  123918. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  123919. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  123920. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  123921. 11,
  123922. };
  123923. static float _vq_quantthresh__44c1_s_p6_0[] = {
  123924. -5.5, 5.5,
  123925. };
  123926. static long _vq_quantmap__44c1_s_p6_0[] = {
  123927. 1, 0, 2,
  123928. };
  123929. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  123930. _vq_quantthresh__44c1_s_p6_0,
  123931. _vq_quantmap__44c1_s_p6_0,
  123932. 3,
  123933. 3
  123934. };
  123935. static static_codebook _44c1_s_p6_0 = {
  123936. 4, 81,
  123937. _vq_lengthlist__44c1_s_p6_0,
  123938. 1, -529137664, 1618345984, 2, 0,
  123939. _vq_quantlist__44c1_s_p6_0,
  123940. NULL,
  123941. &_vq_auxt__44c1_s_p6_0,
  123942. NULL,
  123943. 0
  123944. };
  123945. static long _vq_quantlist__44c1_s_p6_1[] = {
  123946. 5,
  123947. 4,
  123948. 6,
  123949. 3,
  123950. 7,
  123951. 2,
  123952. 8,
  123953. 1,
  123954. 9,
  123955. 0,
  123956. 10,
  123957. };
  123958. static long _vq_lengthlist__44c1_s_p6_1[] = {
  123959. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  123960. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  123961. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123962. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  123963. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  123964. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123965. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123966. 10,10,10, 8, 8, 8, 8, 8, 8,
  123967. };
  123968. static float _vq_quantthresh__44c1_s_p6_1[] = {
  123969. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123970. 3.5, 4.5,
  123971. };
  123972. static long _vq_quantmap__44c1_s_p6_1[] = {
  123973. 9, 7, 5, 3, 1, 0, 2, 4,
  123974. 6, 8, 10,
  123975. };
  123976. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  123977. _vq_quantthresh__44c1_s_p6_1,
  123978. _vq_quantmap__44c1_s_p6_1,
  123979. 11,
  123980. 11
  123981. };
  123982. static static_codebook _44c1_s_p6_1 = {
  123983. 2, 121,
  123984. _vq_lengthlist__44c1_s_p6_1,
  123985. 1, -531365888, 1611661312, 4, 0,
  123986. _vq_quantlist__44c1_s_p6_1,
  123987. NULL,
  123988. &_vq_auxt__44c1_s_p6_1,
  123989. NULL,
  123990. 0
  123991. };
  123992. static long _vq_quantlist__44c1_s_p7_0[] = {
  123993. 6,
  123994. 5,
  123995. 7,
  123996. 4,
  123997. 8,
  123998. 3,
  123999. 9,
  124000. 2,
  124001. 10,
  124002. 1,
  124003. 11,
  124004. 0,
  124005. 12,
  124006. };
  124007. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124008. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124009. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124010. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124011. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124012. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124013. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124014. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124015. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124016. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124017. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124018. 0,12,11,11,11,13,10,14,13,
  124019. };
  124020. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124021. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124022. 12.5, 17.5, 22.5, 27.5,
  124023. };
  124024. static long _vq_quantmap__44c1_s_p7_0[] = {
  124025. 11, 9, 7, 5, 3, 1, 0, 2,
  124026. 4, 6, 8, 10, 12,
  124027. };
  124028. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124029. _vq_quantthresh__44c1_s_p7_0,
  124030. _vq_quantmap__44c1_s_p7_0,
  124031. 13,
  124032. 13
  124033. };
  124034. static static_codebook _44c1_s_p7_0 = {
  124035. 2, 169,
  124036. _vq_lengthlist__44c1_s_p7_0,
  124037. 1, -526516224, 1616117760, 4, 0,
  124038. _vq_quantlist__44c1_s_p7_0,
  124039. NULL,
  124040. &_vq_auxt__44c1_s_p7_0,
  124041. NULL,
  124042. 0
  124043. };
  124044. static long _vq_quantlist__44c1_s_p7_1[] = {
  124045. 2,
  124046. 1,
  124047. 3,
  124048. 0,
  124049. 4,
  124050. };
  124051. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124052. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124053. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124054. };
  124055. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124056. -1.5, -0.5, 0.5, 1.5,
  124057. };
  124058. static long _vq_quantmap__44c1_s_p7_1[] = {
  124059. 3, 1, 0, 2, 4,
  124060. };
  124061. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124062. _vq_quantthresh__44c1_s_p7_1,
  124063. _vq_quantmap__44c1_s_p7_1,
  124064. 5,
  124065. 5
  124066. };
  124067. static static_codebook _44c1_s_p7_1 = {
  124068. 2, 25,
  124069. _vq_lengthlist__44c1_s_p7_1,
  124070. 1, -533725184, 1611661312, 3, 0,
  124071. _vq_quantlist__44c1_s_p7_1,
  124072. NULL,
  124073. &_vq_auxt__44c1_s_p7_1,
  124074. NULL,
  124075. 0
  124076. };
  124077. static long _vq_quantlist__44c1_s_p8_0[] = {
  124078. 6,
  124079. 5,
  124080. 7,
  124081. 4,
  124082. 8,
  124083. 3,
  124084. 9,
  124085. 2,
  124086. 10,
  124087. 1,
  124088. 11,
  124089. 0,
  124090. 12,
  124091. };
  124092. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124093. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124094. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124095. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124096. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124097. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124098. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124099. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124100. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124101. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124102. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124103. 10,10,10,10,10,10,10,10,10,
  124104. };
  124105. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124106. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124107. 552.5, 773.5, 994.5, 1215.5,
  124108. };
  124109. static long _vq_quantmap__44c1_s_p8_0[] = {
  124110. 11, 9, 7, 5, 3, 1, 0, 2,
  124111. 4, 6, 8, 10, 12,
  124112. };
  124113. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124114. _vq_quantthresh__44c1_s_p8_0,
  124115. _vq_quantmap__44c1_s_p8_0,
  124116. 13,
  124117. 13
  124118. };
  124119. static static_codebook _44c1_s_p8_0 = {
  124120. 2, 169,
  124121. _vq_lengthlist__44c1_s_p8_0,
  124122. 1, -514541568, 1627103232, 4, 0,
  124123. _vq_quantlist__44c1_s_p8_0,
  124124. NULL,
  124125. &_vq_auxt__44c1_s_p8_0,
  124126. NULL,
  124127. 0
  124128. };
  124129. static long _vq_quantlist__44c1_s_p8_1[] = {
  124130. 6,
  124131. 5,
  124132. 7,
  124133. 4,
  124134. 8,
  124135. 3,
  124136. 9,
  124137. 2,
  124138. 10,
  124139. 1,
  124140. 11,
  124141. 0,
  124142. 12,
  124143. };
  124144. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124145. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124146. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124147. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124148. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124149. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124150. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124151. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124152. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124153. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124154. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124155. 16,13,12,12,11,14,12,15,13,
  124156. };
  124157. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124158. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124159. 42.5, 59.5, 76.5, 93.5,
  124160. };
  124161. static long _vq_quantmap__44c1_s_p8_1[] = {
  124162. 11, 9, 7, 5, 3, 1, 0, 2,
  124163. 4, 6, 8, 10, 12,
  124164. };
  124165. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124166. _vq_quantthresh__44c1_s_p8_1,
  124167. _vq_quantmap__44c1_s_p8_1,
  124168. 13,
  124169. 13
  124170. };
  124171. static static_codebook _44c1_s_p8_1 = {
  124172. 2, 169,
  124173. _vq_lengthlist__44c1_s_p8_1,
  124174. 1, -522616832, 1620115456, 4, 0,
  124175. _vq_quantlist__44c1_s_p8_1,
  124176. NULL,
  124177. &_vq_auxt__44c1_s_p8_1,
  124178. NULL,
  124179. 0
  124180. };
  124181. static long _vq_quantlist__44c1_s_p8_2[] = {
  124182. 8,
  124183. 7,
  124184. 9,
  124185. 6,
  124186. 10,
  124187. 5,
  124188. 11,
  124189. 4,
  124190. 12,
  124191. 3,
  124192. 13,
  124193. 2,
  124194. 14,
  124195. 1,
  124196. 15,
  124197. 0,
  124198. 16,
  124199. };
  124200. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124201. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124202. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124203. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124204. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124205. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124206. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124207. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124208. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124209. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124210. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124211. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124212. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124213. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124214. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124215. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124216. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124217. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124218. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124219. 9,
  124220. };
  124221. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124222. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124223. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124224. };
  124225. static long _vq_quantmap__44c1_s_p8_2[] = {
  124226. 15, 13, 11, 9, 7, 5, 3, 1,
  124227. 0, 2, 4, 6, 8, 10, 12, 14,
  124228. 16,
  124229. };
  124230. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124231. _vq_quantthresh__44c1_s_p8_2,
  124232. _vq_quantmap__44c1_s_p8_2,
  124233. 17,
  124234. 17
  124235. };
  124236. static static_codebook _44c1_s_p8_2 = {
  124237. 2, 289,
  124238. _vq_lengthlist__44c1_s_p8_2,
  124239. 1, -529530880, 1611661312, 5, 0,
  124240. _vq_quantlist__44c1_s_p8_2,
  124241. NULL,
  124242. &_vq_auxt__44c1_s_p8_2,
  124243. NULL,
  124244. 0
  124245. };
  124246. static long _huff_lengthlist__44c1_s_short[] = {
  124247. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124248. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124249. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124250. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124251. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124252. 11,
  124253. };
  124254. static static_codebook _huff_book__44c1_s_short = {
  124255. 2, 81,
  124256. _huff_lengthlist__44c1_s_short,
  124257. 0, 0, 0, 0, 0,
  124258. NULL,
  124259. NULL,
  124260. NULL,
  124261. NULL,
  124262. 0
  124263. };
  124264. static long _huff_lengthlist__44c1_sm_long[] = {
  124265. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124266. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124267. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124268. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124269. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124270. 11,
  124271. };
  124272. static static_codebook _huff_book__44c1_sm_long = {
  124273. 2, 81,
  124274. _huff_lengthlist__44c1_sm_long,
  124275. 0, 0, 0, 0, 0,
  124276. NULL,
  124277. NULL,
  124278. NULL,
  124279. NULL,
  124280. 0
  124281. };
  124282. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124283. 1,
  124284. 0,
  124285. 2,
  124286. };
  124287. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124288. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124289. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124293. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124294. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124298. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124299. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124334. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124339. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  124344. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124379. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124380. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124384. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124385. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  124386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124389. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124390. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  124391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124698. 0,
  124699. };
  124700. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  124701. -0.5, 0.5,
  124702. };
  124703. static long _vq_quantmap__44c1_sm_p1_0[] = {
  124704. 1, 0, 2,
  124705. };
  124706. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  124707. _vq_quantthresh__44c1_sm_p1_0,
  124708. _vq_quantmap__44c1_sm_p1_0,
  124709. 3,
  124710. 3
  124711. };
  124712. static static_codebook _44c1_sm_p1_0 = {
  124713. 8, 6561,
  124714. _vq_lengthlist__44c1_sm_p1_0,
  124715. 1, -535822336, 1611661312, 2, 0,
  124716. _vq_quantlist__44c1_sm_p1_0,
  124717. NULL,
  124718. &_vq_auxt__44c1_sm_p1_0,
  124719. NULL,
  124720. 0
  124721. };
  124722. static long _vq_quantlist__44c1_sm_p2_0[] = {
  124723. 2,
  124724. 1,
  124725. 3,
  124726. 0,
  124727. 4,
  124728. };
  124729. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  124730. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124733. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  124735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124736. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124769. 0,
  124770. };
  124771. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  124772. -1.5, -0.5, 0.5, 1.5,
  124773. };
  124774. static long _vq_quantmap__44c1_sm_p2_0[] = {
  124775. 3, 1, 0, 2, 4,
  124776. };
  124777. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  124778. _vq_quantthresh__44c1_sm_p2_0,
  124779. _vq_quantmap__44c1_sm_p2_0,
  124780. 5,
  124781. 5
  124782. };
  124783. static static_codebook _44c1_sm_p2_0 = {
  124784. 4, 625,
  124785. _vq_lengthlist__44c1_sm_p2_0,
  124786. 1, -533725184, 1611661312, 3, 0,
  124787. _vq_quantlist__44c1_sm_p2_0,
  124788. NULL,
  124789. &_vq_auxt__44c1_sm_p2_0,
  124790. NULL,
  124791. 0
  124792. };
  124793. static long _vq_quantlist__44c1_sm_p3_0[] = {
  124794. 4,
  124795. 3,
  124796. 5,
  124797. 2,
  124798. 6,
  124799. 1,
  124800. 7,
  124801. 0,
  124802. 8,
  124803. };
  124804. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  124805. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  124806. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  124807. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124808. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124809. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124810. 0,
  124811. };
  124812. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  124813. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124814. };
  124815. static long _vq_quantmap__44c1_sm_p3_0[] = {
  124816. 7, 5, 3, 1, 0, 2, 4, 6,
  124817. 8,
  124818. };
  124819. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  124820. _vq_quantthresh__44c1_sm_p3_0,
  124821. _vq_quantmap__44c1_sm_p3_0,
  124822. 9,
  124823. 9
  124824. };
  124825. static static_codebook _44c1_sm_p3_0 = {
  124826. 2, 81,
  124827. _vq_lengthlist__44c1_sm_p3_0,
  124828. 1, -531628032, 1611661312, 4, 0,
  124829. _vq_quantlist__44c1_sm_p3_0,
  124830. NULL,
  124831. &_vq_auxt__44c1_sm_p3_0,
  124832. NULL,
  124833. 0
  124834. };
  124835. static long _vq_quantlist__44c1_sm_p4_0[] = {
  124836. 4,
  124837. 3,
  124838. 5,
  124839. 2,
  124840. 6,
  124841. 1,
  124842. 7,
  124843. 0,
  124844. 8,
  124845. };
  124846. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  124847. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  124848. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  124849. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  124850. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  124851. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124852. 11,
  124853. };
  124854. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  124855. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124856. };
  124857. static long _vq_quantmap__44c1_sm_p4_0[] = {
  124858. 7, 5, 3, 1, 0, 2, 4, 6,
  124859. 8,
  124860. };
  124861. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  124862. _vq_quantthresh__44c1_sm_p4_0,
  124863. _vq_quantmap__44c1_sm_p4_0,
  124864. 9,
  124865. 9
  124866. };
  124867. static static_codebook _44c1_sm_p4_0 = {
  124868. 2, 81,
  124869. _vq_lengthlist__44c1_sm_p4_0,
  124870. 1, -531628032, 1611661312, 4, 0,
  124871. _vq_quantlist__44c1_sm_p4_0,
  124872. NULL,
  124873. &_vq_auxt__44c1_sm_p4_0,
  124874. NULL,
  124875. 0
  124876. };
  124877. static long _vq_quantlist__44c1_sm_p5_0[] = {
  124878. 8,
  124879. 7,
  124880. 9,
  124881. 6,
  124882. 10,
  124883. 5,
  124884. 11,
  124885. 4,
  124886. 12,
  124887. 3,
  124888. 13,
  124889. 2,
  124890. 14,
  124891. 1,
  124892. 15,
  124893. 0,
  124894. 16,
  124895. };
  124896. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  124897. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124898. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124899. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  124900. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124901. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124902. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  124903. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  124904. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124905. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124906. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  124907. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124908. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124909. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124910. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124911. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  124912. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124913. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  124914. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124915. 14,
  124916. };
  124917. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  124918. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124919. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124920. };
  124921. static long _vq_quantmap__44c1_sm_p5_0[] = {
  124922. 15, 13, 11, 9, 7, 5, 3, 1,
  124923. 0, 2, 4, 6, 8, 10, 12, 14,
  124924. 16,
  124925. };
  124926. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  124927. _vq_quantthresh__44c1_sm_p5_0,
  124928. _vq_quantmap__44c1_sm_p5_0,
  124929. 17,
  124930. 17
  124931. };
  124932. static static_codebook _44c1_sm_p5_0 = {
  124933. 2, 289,
  124934. _vq_lengthlist__44c1_sm_p5_0,
  124935. 1, -529530880, 1611661312, 5, 0,
  124936. _vq_quantlist__44c1_sm_p5_0,
  124937. NULL,
  124938. &_vq_auxt__44c1_sm_p5_0,
  124939. NULL,
  124940. 0
  124941. };
  124942. static long _vq_quantlist__44c1_sm_p6_0[] = {
  124943. 1,
  124944. 0,
  124945. 2,
  124946. };
  124947. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  124948. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124949. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  124950. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  124951. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  124952. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  124953. 11,
  124954. };
  124955. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  124956. -5.5, 5.5,
  124957. };
  124958. static long _vq_quantmap__44c1_sm_p6_0[] = {
  124959. 1, 0, 2,
  124960. };
  124961. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  124962. _vq_quantthresh__44c1_sm_p6_0,
  124963. _vq_quantmap__44c1_sm_p6_0,
  124964. 3,
  124965. 3
  124966. };
  124967. static static_codebook _44c1_sm_p6_0 = {
  124968. 4, 81,
  124969. _vq_lengthlist__44c1_sm_p6_0,
  124970. 1, -529137664, 1618345984, 2, 0,
  124971. _vq_quantlist__44c1_sm_p6_0,
  124972. NULL,
  124973. &_vq_auxt__44c1_sm_p6_0,
  124974. NULL,
  124975. 0
  124976. };
  124977. static long _vq_quantlist__44c1_sm_p6_1[] = {
  124978. 5,
  124979. 4,
  124980. 6,
  124981. 3,
  124982. 7,
  124983. 2,
  124984. 8,
  124985. 1,
  124986. 9,
  124987. 0,
  124988. 10,
  124989. };
  124990. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  124991. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  124992. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  124993. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  124994. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124995. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124996. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  124997. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124998. 10,10,10, 8, 8, 8, 8, 8, 8,
  124999. };
  125000. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125001. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125002. 3.5, 4.5,
  125003. };
  125004. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125005. 9, 7, 5, 3, 1, 0, 2, 4,
  125006. 6, 8, 10,
  125007. };
  125008. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125009. _vq_quantthresh__44c1_sm_p6_1,
  125010. _vq_quantmap__44c1_sm_p6_1,
  125011. 11,
  125012. 11
  125013. };
  125014. static static_codebook _44c1_sm_p6_1 = {
  125015. 2, 121,
  125016. _vq_lengthlist__44c1_sm_p6_1,
  125017. 1, -531365888, 1611661312, 4, 0,
  125018. _vq_quantlist__44c1_sm_p6_1,
  125019. NULL,
  125020. &_vq_auxt__44c1_sm_p6_1,
  125021. NULL,
  125022. 0
  125023. };
  125024. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125025. 6,
  125026. 5,
  125027. 7,
  125028. 4,
  125029. 8,
  125030. 3,
  125031. 9,
  125032. 2,
  125033. 10,
  125034. 1,
  125035. 11,
  125036. 0,
  125037. 12,
  125038. };
  125039. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125040. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125041. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125042. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125043. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125044. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125045. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125046. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125047. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125048. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125049. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125050. 0,12,12,11,11,13,12,14,13,
  125051. };
  125052. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125053. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125054. 12.5, 17.5, 22.5, 27.5,
  125055. };
  125056. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125057. 11, 9, 7, 5, 3, 1, 0, 2,
  125058. 4, 6, 8, 10, 12,
  125059. };
  125060. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125061. _vq_quantthresh__44c1_sm_p7_0,
  125062. _vq_quantmap__44c1_sm_p7_0,
  125063. 13,
  125064. 13
  125065. };
  125066. static static_codebook _44c1_sm_p7_0 = {
  125067. 2, 169,
  125068. _vq_lengthlist__44c1_sm_p7_0,
  125069. 1, -526516224, 1616117760, 4, 0,
  125070. _vq_quantlist__44c1_sm_p7_0,
  125071. NULL,
  125072. &_vq_auxt__44c1_sm_p7_0,
  125073. NULL,
  125074. 0
  125075. };
  125076. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125077. 2,
  125078. 1,
  125079. 3,
  125080. 0,
  125081. 4,
  125082. };
  125083. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125084. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125085. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125086. };
  125087. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125088. -1.5, -0.5, 0.5, 1.5,
  125089. };
  125090. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125091. 3, 1, 0, 2, 4,
  125092. };
  125093. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125094. _vq_quantthresh__44c1_sm_p7_1,
  125095. _vq_quantmap__44c1_sm_p7_1,
  125096. 5,
  125097. 5
  125098. };
  125099. static static_codebook _44c1_sm_p7_1 = {
  125100. 2, 25,
  125101. _vq_lengthlist__44c1_sm_p7_1,
  125102. 1, -533725184, 1611661312, 3, 0,
  125103. _vq_quantlist__44c1_sm_p7_1,
  125104. NULL,
  125105. &_vq_auxt__44c1_sm_p7_1,
  125106. NULL,
  125107. 0
  125108. };
  125109. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125110. 6,
  125111. 5,
  125112. 7,
  125113. 4,
  125114. 8,
  125115. 3,
  125116. 9,
  125117. 2,
  125118. 10,
  125119. 1,
  125120. 11,
  125121. 0,
  125122. 12,
  125123. };
  125124. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125125. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125126. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125127. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125128. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125129. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125130. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125131. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125132. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125133. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125134. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125135. 13,13,13,13,13,13,13,13,13,
  125136. };
  125137. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125138. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125139. 552.5, 773.5, 994.5, 1215.5,
  125140. };
  125141. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125142. 11, 9, 7, 5, 3, 1, 0, 2,
  125143. 4, 6, 8, 10, 12,
  125144. };
  125145. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125146. _vq_quantthresh__44c1_sm_p8_0,
  125147. _vq_quantmap__44c1_sm_p8_0,
  125148. 13,
  125149. 13
  125150. };
  125151. static static_codebook _44c1_sm_p8_0 = {
  125152. 2, 169,
  125153. _vq_lengthlist__44c1_sm_p8_0,
  125154. 1, -514541568, 1627103232, 4, 0,
  125155. _vq_quantlist__44c1_sm_p8_0,
  125156. NULL,
  125157. &_vq_auxt__44c1_sm_p8_0,
  125158. NULL,
  125159. 0
  125160. };
  125161. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125162. 6,
  125163. 5,
  125164. 7,
  125165. 4,
  125166. 8,
  125167. 3,
  125168. 9,
  125169. 2,
  125170. 10,
  125171. 1,
  125172. 11,
  125173. 0,
  125174. 12,
  125175. };
  125176. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125177. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125178. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125179. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125180. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125181. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125182. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125183. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125184. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125185. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125186. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125187. 20,13,12,12,12,14,12,14,13,
  125188. };
  125189. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125190. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125191. 42.5, 59.5, 76.5, 93.5,
  125192. };
  125193. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125194. 11, 9, 7, 5, 3, 1, 0, 2,
  125195. 4, 6, 8, 10, 12,
  125196. };
  125197. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125198. _vq_quantthresh__44c1_sm_p8_1,
  125199. _vq_quantmap__44c1_sm_p8_1,
  125200. 13,
  125201. 13
  125202. };
  125203. static static_codebook _44c1_sm_p8_1 = {
  125204. 2, 169,
  125205. _vq_lengthlist__44c1_sm_p8_1,
  125206. 1, -522616832, 1620115456, 4, 0,
  125207. _vq_quantlist__44c1_sm_p8_1,
  125208. NULL,
  125209. &_vq_auxt__44c1_sm_p8_1,
  125210. NULL,
  125211. 0
  125212. };
  125213. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125214. 8,
  125215. 7,
  125216. 9,
  125217. 6,
  125218. 10,
  125219. 5,
  125220. 11,
  125221. 4,
  125222. 12,
  125223. 3,
  125224. 13,
  125225. 2,
  125226. 14,
  125227. 1,
  125228. 15,
  125229. 0,
  125230. 16,
  125231. };
  125232. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125233. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125234. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125235. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125236. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125237. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125238. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125239. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125240. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125241. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125242. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125243. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125244. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125245. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125246. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125247. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125248. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125249. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125250. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125251. 9,
  125252. };
  125253. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125254. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125255. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125256. };
  125257. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125258. 15, 13, 11, 9, 7, 5, 3, 1,
  125259. 0, 2, 4, 6, 8, 10, 12, 14,
  125260. 16,
  125261. };
  125262. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125263. _vq_quantthresh__44c1_sm_p8_2,
  125264. _vq_quantmap__44c1_sm_p8_2,
  125265. 17,
  125266. 17
  125267. };
  125268. static static_codebook _44c1_sm_p8_2 = {
  125269. 2, 289,
  125270. _vq_lengthlist__44c1_sm_p8_2,
  125271. 1, -529530880, 1611661312, 5, 0,
  125272. _vq_quantlist__44c1_sm_p8_2,
  125273. NULL,
  125274. &_vq_auxt__44c1_sm_p8_2,
  125275. NULL,
  125276. 0
  125277. };
  125278. static long _huff_lengthlist__44c1_sm_short[] = {
  125279. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125280. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125281. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125282. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125283. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125284. 11,
  125285. };
  125286. static static_codebook _huff_book__44c1_sm_short = {
  125287. 2, 81,
  125288. _huff_lengthlist__44c1_sm_short,
  125289. 0, 0, 0, 0, 0,
  125290. NULL,
  125291. NULL,
  125292. NULL,
  125293. NULL,
  125294. 0
  125295. };
  125296. static long _huff_lengthlist__44cn1_s_long[] = {
  125297. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125298. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125299. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125300. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125301. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125302. 20,
  125303. };
  125304. static static_codebook _huff_book__44cn1_s_long = {
  125305. 2, 81,
  125306. _huff_lengthlist__44cn1_s_long,
  125307. 0, 0, 0, 0, 0,
  125308. NULL,
  125309. NULL,
  125310. NULL,
  125311. NULL,
  125312. 0
  125313. };
  125314. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125315. 1,
  125316. 0,
  125317. 2,
  125318. };
  125319. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125320. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125321. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125325. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125326. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125330. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125331. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  125366. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  125367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  125371. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  125376. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  125377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125411. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125412. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125416. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125417. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  125418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125421. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125422. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  125423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125730. 0,
  125731. };
  125732. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  125733. -0.5, 0.5,
  125734. };
  125735. static long _vq_quantmap__44cn1_s_p1_0[] = {
  125736. 1, 0, 2,
  125737. };
  125738. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  125739. _vq_quantthresh__44cn1_s_p1_0,
  125740. _vq_quantmap__44cn1_s_p1_0,
  125741. 3,
  125742. 3
  125743. };
  125744. static static_codebook _44cn1_s_p1_0 = {
  125745. 8, 6561,
  125746. _vq_lengthlist__44cn1_s_p1_0,
  125747. 1, -535822336, 1611661312, 2, 0,
  125748. _vq_quantlist__44cn1_s_p1_0,
  125749. NULL,
  125750. &_vq_auxt__44cn1_s_p1_0,
  125751. NULL,
  125752. 0
  125753. };
  125754. static long _vq_quantlist__44cn1_s_p2_0[] = {
  125755. 2,
  125756. 1,
  125757. 3,
  125758. 0,
  125759. 4,
  125760. };
  125761. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  125762. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  125764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125765. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  125767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125768. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125801. 0,
  125802. };
  125803. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  125804. -1.5, -0.5, 0.5, 1.5,
  125805. };
  125806. static long _vq_quantmap__44cn1_s_p2_0[] = {
  125807. 3, 1, 0, 2, 4,
  125808. };
  125809. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  125810. _vq_quantthresh__44cn1_s_p2_0,
  125811. _vq_quantmap__44cn1_s_p2_0,
  125812. 5,
  125813. 5
  125814. };
  125815. static static_codebook _44cn1_s_p2_0 = {
  125816. 4, 625,
  125817. _vq_lengthlist__44cn1_s_p2_0,
  125818. 1, -533725184, 1611661312, 3, 0,
  125819. _vq_quantlist__44cn1_s_p2_0,
  125820. NULL,
  125821. &_vq_auxt__44cn1_s_p2_0,
  125822. NULL,
  125823. 0
  125824. };
  125825. static long _vq_quantlist__44cn1_s_p3_0[] = {
  125826. 4,
  125827. 3,
  125828. 5,
  125829. 2,
  125830. 6,
  125831. 1,
  125832. 7,
  125833. 0,
  125834. 8,
  125835. };
  125836. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  125837. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  125838. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  125839. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125840. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125841. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125842. 0,
  125843. };
  125844. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  125845. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125846. };
  125847. static long _vq_quantmap__44cn1_s_p3_0[] = {
  125848. 7, 5, 3, 1, 0, 2, 4, 6,
  125849. 8,
  125850. };
  125851. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  125852. _vq_quantthresh__44cn1_s_p3_0,
  125853. _vq_quantmap__44cn1_s_p3_0,
  125854. 9,
  125855. 9
  125856. };
  125857. static static_codebook _44cn1_s_p3_0 = {
  125858. 2, 81,
  125859. _vq_lengthlist__44cn1_s_p3_0,
  125860. 1, -531628032, 1611661312, 4, 0,
  125861. _vq_quantlist__44cn1_s_p3_0,
  125862. NULL,
  125863. &_vq_auxt__44cn1_s_p3_0,
  125864. NULL,
  125865. 0
  125866. };
  125867. static long _vq_quantlist__44cn1_s_p4_0[] = {
  125868. 4,
  125869. 3,
  125870. 5,
  125871. 2,
  125872. 6,
  125873. 1,
  125874. 7,
  125875. 0,
  125876. 8,
  125877. };
  125878. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  125879. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  125880. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  125881. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  125882. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  125883. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  125884. 11,
  125885. };
  125886. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  125887. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125888. };
  125889. static long _vq_quantmap__44cn1_s_p4_0[] = {
  125890. 7, 5, 3, 1, 0, 2, 4, 6,
  125891. 8,
  125892. };
  125893. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  125894. _vq_quantthresh__44cn1_s_p4_0,
  125895. _vq_quantmap__44cn1_s_p4_0,
  125896. 9,
  125897. 9
  125898. };
  125899. static static_codebook _44cn1_s_p4_0 = {
  125900. 2, 81,
  125901. _vq_lengthlist__44cn1_s_p4_0,
  125902. 1, -531628032, 1611661312, 4, 0,
  125903. _vq_quantlist__44cn1_s_p4_0,
  125904. NULL,
  125905. &_vq_auxt__44cn1_s_p4_0,
  125906. NULL,
  125907. 0
  125908. };
  125909. static long _vq_quantlist__44cn1_s_p5_0[] = {
  125910. 8,
  125911. 7,
  125912. 9,
  125913. 6,
  125914. 10,
  125915. 5,
  125916. 11,
  125917. 4,
  125918. 12,
  125919. 3,
  125920. 13,
  125921. 2,
  125922. 14,
  125923. 1,
  125924. 15,
  125925. 0,
  125926. 16,
  125927. };
  125928. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  125929. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  125930. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125931. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  125932. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125933. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125934. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  125935. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  125936. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  125937. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125938. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  125939. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125940. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125941. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  125942. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125943. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  125944. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  125945. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  125946. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  125947. 14,
  125948. };
  125949. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  125950. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125951. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125952. };
  125953. static long _vq_quantmap__44cn1_s_p5_0[] = {
  125954. 15, 13, 11, 9, 7, 5, 3, 1,
  125955. 0, 2, 4, 6, 8, 10, 12, 14,
  125956. 16,
  125957. };
  125958. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  125959. _vq_quantthresh__44cn1_s_p5_0,
  125960. _vq_quantmap__44cn1_s_p5_0,
  125961. 17,
  125962. 17
  125963. };
  125964. static static_codebook _44cn1_s_p5_0 = {
  125965. 2, 289,
  125966. _vq_lengthlist__44cn1_s_p5_0,
  125967. 1, -529530880, 1611661312, 5, 0,
  125968. _vq_quantlist__44cn1_s_p5_0,
  125969. NULL,
  125970. &_vq_auxt__44cn1_s_p5_0,
  125971. NULL,
  125972. 0
  125973. };
  125974. static long _vq_quantlist__44cn1_s_p6_0[] = {
  125975. 1,
  125976. 0,
  125977. 2,
  125978. };
  125979. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  125980. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  125981. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  125982. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  125983. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  125984. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  125985. 10,
  125986. };
  125987. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  125988. -5.5, 5.5,
  125989. };
  125990. static long _vq_quantmap__44cn1_s_p6_0[] = {
  125991. 1, 0, 2,
  125992. };
  125993. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  125994. _vq_quantthresh__44cn1_s_p6_0,
  125995. _vq_quantmap__44cn1_s_p6_0,
  125996. 3,
  125997. 3
  125998. };
  125999. static static_codebook _44cn1_s_p6_0 = {
  126000. 4, 81,
  126001. _vq_lengthlist__44cn1_s_p6_0,
  126002. 1, -529137664, 1618345984, 2, 0,
  126003. _vq_quantlist__44cn1_s_p6_0,
  126004. NULL,
  126005. &_vq_auxt__44cn1_s_p6_0,
  126006. NULL,
  126007. 0
  126008. };
  126009. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126010. 5,
  126011. 4,
  126012. 6,
  126013. 3,
  126014. 7,
  126015. 2,
  126016. 8,
  126017. 1,
  126018. 9,
  126019. 0,
  126020. 10,
  126021. };
  126022. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126023. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126024. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126025. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126026. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126027. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126028. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126029. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126030. 10,10,10, 9, 9, 9, 9, 9, 9,
  126031. };
  126032. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126033. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126034. 3.5, 4.5,
  126035. };
  126036. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126037. 9, 7, 5, 3, 1, 0, 2, 4,
  126038. 6, 8, 10,
  126039. };
  126040. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126041. _vq_quantthresh__44cn1_s_p6_1,
  126042. _vq_quantmap__44cn1_s_p6_1,
  126043. 11,
  126044. 11
  126045. };
  126046. static static_codebook _44cn1_s_p6_1 = {
  126047. 2, 121,
  126048. _vq_lengthlist__44cn1_s_p6_1,
  126049. 1, -531365888, 1611661312, 4, 0,
  126050. _vq_quantlist__44cn1_s_p6_1,
  126051. NULL,
  126052. &_vq_auxt__44cn1_s_p6_1,
  126053. NULL,
  126054. 0
  126055. };
  126056. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126057. 6,
  126058. 5,
  126059. 7,
  126060. 4,
  126061. 8,
  126062. 3,
  126063. 9,
  126064. 2,
  126065. 10,
  126066. 1,
  126067. 11,
  126068. 0,
  126069. 12,
  126070. };
  126071. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126072. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126073. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126074. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126075. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126076. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126077. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126078. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126079. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126080. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126081. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126082. 0,13,13,12,12,13,13,13,14,
  126083. };
  126084. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126085. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126086. 12.5, 17.5, 22.5, 27.5,
  126087. };
  126088. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126089. 11, 9, 7, 5, 3, 1, 0, 2,
  126090. 4, 6, 8, 10, 12,
  126091. };
  126092. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126093. _vq_quantthresh__44cn1_s_p7_0,
  126094. _vq_quantmap__44cn1_s_p7_0,
  126095. 13,
  126096. 13
  126097. };
  126098. static static_codebook _44cn1_s_p7_0 = {
  126099. 2, 169,
  126100. _vq_lengthlist__44cn1_s_p7_0,
  126101. 1, -526516224, 1616117760, 4, 0,
  126102. _vq_quantlist__44cn1_s_p7_0,
  126103. NULL,
  126104. &_vq_auxt__44cn1_s_p7_0,
  126105. NULL,
  126106. 0
  126107. };
  126108. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126109. 2,
  126110. 1,
  126111. 3,
  126112. 0,
  126113. 4,
  126114. };
  126115. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126116. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126117. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126118. };
  126119. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126120. -1.5, -0.5, 0.5, 1.5,
  126121. };
  126122. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126123. 3, 1, 0, 2, 4,
  126124. };
  126125. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126126. _vq_quantthresh__44cn1_s_p7_1,
  126127. _vq_quantmap__44cn1_s_p7_1,
  126128. 5,
  126129. 5
  126130. };
  126131. static static_codebook _44cn1_s_p7_1 = {
  126132. 2, 25,
  126133. _vq_lengthlist__44cn1_s_p7_1,
  126134. 1, -533725184, 1611661312, 3, 0,
  126135. _vq_quantlist__44cn1_s_p7_1,
  126136. NULL,
  126137. &_vq_auxt__44cn1_s_p7_1,
  126138. NULL,
  126139. 0
  126140. };
  126141. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126142. 2,
  126143. 1,
  126144. 3,
  126145. 0,
  126146. 4,
  126147. };
  126148. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126149. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126150. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126151. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126152. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126153. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126154. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126155. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126156. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126157. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126158. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126159. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126160. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126161. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126162. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126163. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126164. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126165. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126166. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126167. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126168. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126169. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126170. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126171. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126172. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126173. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126174. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126175. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126176. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126177. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126178. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126179. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126180. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126181. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126182. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126183. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126184. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126185. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126186. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126187. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126188. 12,
  126189. };
  126190. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126191. -331.5, -110.5, 110.5, 331.5,
  126192. };
  126193. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126194. 3, 1, 0, 2, 4,
  126195. };
  126196. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126197. _vq_quantthresh__44cn1_s_p8_0,
  126198. _vq_quantmap__44cn1_s_p8_0,
  126199. 5,
  126200. 5
  126201. };
  126202. static static_codebook _44cn1_s_p8_0 = {
  126203. 4, 625,
  126204. _vq_lengthlist__44cn1_s_p8_0,
  126205. 1, -518283264, 1627103232, 3, 0,
  126206. _vq_quantlist__44cn1_s_p8_0,
  126207. NULL,
  126208. &_vq_auxt__44cn1_s_p8_0,
  126209. NULL,
  126210. 0
  126211. };
  126212. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126213. 6,
  126214. 5,
  126215. 7,
  126216. 4,
  126217. 8,
  126218. 3,
  126219. 9,
  126220. 2,
  126221. 10,
  126222. 1,
  126223. 11,
  126224. 0,
  126225. 12,
  126226. };
  126227. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126228. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126229. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126230. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126231. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126232. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126233. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126234. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126235. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126236. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126237. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126238. 15,12,12,11,11,14,12,13,14,
  126239. };
  126240. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126241. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126242. 42.5, 59.5, 76.5, 93.5,
  126243. };
  126244. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126245. 11, 9, 7, 5, 3, 1, 0, 2,
  126246. 4, 6, 8, 10, 12,
  126247. };
  126248. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126249. _vq_quantthresh__44cn1_s_p8_1,
  126250. _vq_quantmap__44cn1_s_p8_1,
  126251. 13,
  126252. 13
  126253. };
  126254. static static_codebook _44cn1_s_p8_1 = {
  126255. 2, 169,
  126256. _vq_lengthlist__44cn1_s_p8_1,
  126257. 1, -522616832, 1620115456, 4, 0,
  126258. _vq_quantlist__44cn1_s_p8_1,
  126259. NULL,
  126260. &_vq_auxt__44cn1_s_p8_1,
  126261. NULL,
  126262. 0
  126263. };
  126264. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126265. 8,
  126266. 7,
  126267. 9,
  126268. 6,
  126269. 10,
  126270. 5,
  126271. 11,
  126272. 4,
  126273. 12,
  126274. 3,
  126275. 13,
  126276. 2,
  126277. 14,
  126278. 1,
  126279. 15,
  126280. 0,
  126281. 16,
  126282. };
  126283. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126284. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126285. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126286. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126287. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126288. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126289. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126290. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126291. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126292. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126293. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126294. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126295. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126296. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126297. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126298. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126299. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126300. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126301. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126302. 9,
  126303. };
  126304. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126305. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126306. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126307. };
  126308. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126309. 15, 13, 11, 9, 7, 5, 3, 1,
  126310. 0, 2, 4, 6, 8, 10, 12, 14,
  126311. 16,
  126312. };
  126313. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126314. _vq_quantthresh__44cn1_s_p8_2,
  126315. _vq_quantmap__44cn1_s_p8_2,
  126316. 17,
  126317. 17
  126318. };
  126319. static static_codebook _44cn1_s_p8_2 = {
  126320. 2, 289,
  126321. _vq_lengthlist__44cn1_s_p8_2,
  126322. 1, -529530880, 1611661312, 5, 0,
  126323. _vq_quantlist__44cn1_s_p8_2,
  126324. NULL,
  126325. &_vq_auxt__44cn1_s_p8_2,
  126326. NULL,
  126327. 0
  126328. };
  126329. static long _huff_lengthlist__44cn1_s_short[] = {
  126330. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126331. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126332. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126333. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126334. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126335. 10,
  126336. };
  126337. static static_codebook _huff_book__44cn1_s_short = {
  126338. 2, 81,
  126339. _huff_lengthlist__44cn1_s_short,
  126340. 0, 0, 0, 0, 0,
  126341. NULL,
  126342. NULL,
  126343. NULL,
  126344. NULL,
  126345. 0
  126346. };
  126347. static long _huff_lengthlist__44cn1_sm_long[] = {
  126348. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126349. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126350. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126351. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126352. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126353. 17,
  126354. };
  126355. static static_codebook _huff_book__44cn1_sm_long = {
  126356. 2, 81,
  126357. _huff_lengthlist__44cn1_sm_long,
  126358. 0, 0, 0, 0, 0,
  126359. NULL,
  126360. NULL,
  126361. NULL,
  126362. NULL,
  126363. 0
  126364. };
  126365. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126366. 1,
  126367. 0,
  126368. 2,
  126369. };
  126370. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126371. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126372. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126376. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126377. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126381. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126382. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126417. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  126422. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  126427. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  126428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126462. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126463. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126467. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126468. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  126469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126472. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126473. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  126474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126781. 0,
  126782. };
  126783. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  126784. -0.5, 0.5,
  126785. };
  126786. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  126787. 1, 0, 2,
  126788. };
  126789. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  126790. _vq_quantthresh__44cn1_sm_p1_0,
  126791. _vq_quantmap__44cn1_sm_p1_0,
  126792. 3,
  126793. 3
  126794. };
  126795. static static_codebook _44cn1_sm_p1_0 = {
  126796. 8, 6561,
  126797. _vq_lengthlist__44cn1_sm_p1_0,
  126798. 1, -535822336, 1611661312, 2, 0,
  126799. _vq_quantlist__44cn1_sm_p1_0,
  126800. NULL,
  126801. &_vq_auxt__44cn1_sm_p1_0,
  126802. NULL,
  126803. 0
  126804. };
  126805. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  126806. 2,
  126807. 1,
  126808. 3,
  126809. 0,
  126810. 4,
  126811. };
  126812. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  126813. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126816. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126819. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126852. 0,
  126853. };
  126854. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  126855. -1.5, -0.5, 0.5, 1.5,
  126856. };
  126857. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  126858. 3, 1, 0, 2, 4,
  126859. };
  126860. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  126861. _vq_quantthresh__44cn1_sm_p2_0,
  126862. _vq_quantmap__44cn1_sm_p2_0,
  126863. 5,
  126864. 5
  126865. };
  126866. static static_codebook _44cn1_sm_p2_0 = {
  126867. 4, 625,
  126868. _vq_lengthlist__44cn1_sm_p2_0,
  126869. 1, -533725184, 1611661312, 3, 0,
  126870. _vq_quantlist__44cn1_sm_p2_0,
  126871. NULL,
  126872. &_vq_auxt__44cn1_sm_p2_0,
  126873. NULL,
  126874. 0
  126875. };
  126876. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  126877. 4,
  126878. 3,
  126879. 5,
  126880. 2,
  126881. 6,
  126882. 1,
  126883. 7,
  126884. 0,
  126885. 8,
  126886. };
  126887. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  126888. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  126889. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  126890. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  126891. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  126892. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126893. 0,
  126894. };
  126895. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  126896. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126897. };
  126898. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  126899. 7, 5, 3, 1, 0, 2, 4, 6,
  126900. 8,
  126901. };
  126902. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  126903. _vq_quantthresh__44cn1_sm_p3_0,
  126904. _vq_quantmap__44cn1_sm_p3_0,
  126905. 9,
  126906. 9
  126907. };
  126908. static static_codebook _44cn1_sm_p3_0 = {
  126909. 2, 81,
  126910. _vq_lengthlist__44cn1_sm_p3_0,
  126911. 1, -531628032, 1611661312, 4, 0,
  126912. _vq_quantlist__44cn1_sm_p3_0,
  126913. NULL,
  126914. &_vq_auxt__44cn1_sm_p3_0,
  126915. NULL,
  126916. 0
  126917. };
  126918. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  126919. 4,
  126920. 3,
  126921. 5,
  126922. 2,
  126923. 6,
  126924. 1,
  126925. 7,
  126926. 0,
  126927. 8,
  126928. };
  126929. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  126930. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  126931. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  126932. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  126933. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126934. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126935. 11,
  126936. };
  126937. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  126938. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126939. };
  126940. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  126941. 7, 5, 3, 1, 0, 2, 4, 6,
  126942. 8,
  126943. };
  126944. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  126945. _vq_quantthresh__44cn1_sm_p4_0,
  126946. _vq_quantmap__44cn1_sm_p4_0,
  126947. 9,
  126948. 9
  126949. };
  126950. static static_codebook _44cn1_sm_p4_0 = {
  126951. 2, 81,
  126952. _vq_lengthlist__44cn1_sm_p4_0,
  126953. 1, -531628032, 1611661312, 4, 0,
  126954. _vq_quantlist__44cn1_sm_p4_0,
  126955. NULL,
  126956. &_vq_auxt__44cn1_sm_p4_0,
  126957. NULL,
  126958. 0
  126959. };
  126960. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  126961. 8,
  126962. 7,
  126963. 9,
  126964. 6,
  126965. 10,
  126966. 5,
  126967. 11,
  126968. 4,
  126969. 12,
  126970. 3,
  126971. 13,
  126972. 2,
  126973. 14,
  126974. 1,
  126975. 15,
  126976. 0,
  126977. 16,
  126978. };
  126979. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  126980. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  126981. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  126982. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  126983. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126984. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  126985. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  126986. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  126987. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  126988. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  126989. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  126990. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  126991. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  126992. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  126993. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  126994. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  126995. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  126996. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  126997. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  126998. 14,
  126999. };
  127000. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127001. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127002. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127003. };
  127004. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127005. 15, 13, 11, 9, 7, 5, 3, 1,
  127006. 0, 2, 4, 6, 8, 10, 12, 14,
  127007. 16,
  127008. };
  127009. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127010. _vq_quantthresh__44cn1_sm_p5_0,
  127011. _vq_quantmap__44cn1_sm_p5_0,
  127012. 17,
  127013. 17
  127014. };
  127015. static static_codebook _44cn1_sm_p5_0 = {
  127016. 2, 289,
  127017. _vq_lengthlist__44cn1_sm_p5_0,
  127018. 1, -529530880, 1611661312, 5, 0,
  127019. _vq_quantlist__44cn1_sm_p5_0,
  127020. NULL,
  127021. &_vq_auxt__44cn1_sm_p5_0,
  127022. NULL,
  127023. 0
  127024. };
  127025. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127026. 1,
  127027. 0,
  127028. 2,
  127029. };
  127030. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127031. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127032. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127033. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127034. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127035. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127036. 10,
  127037. };
  127038. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127039. -5.5, 5.5,
  127040. };
  127041. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127042. 1, 0, 2,
  127043. };
  127044. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127045. _vq_quantthresh__44cn1_sm_p6_0,
  127046. _vq_quantmap__44cn1_sm_p6_0,
  127047. 3,
  127048. 3
  127049. };
  127050. static static_codebook _44cn1_sm_p6_0 = {
  127051. 4, 81,
  127052. _vq_lengthlist__44cn1_sm_p6_0,
  127053. 1, -529137664, 1618345984, 2, 0,
  127054. _vq_quantlist__44cn1_sm_p6_0,
  127055. NULL,
  127056. &_vq_auxt__44cn1_sm_p6_0,
  127057. NULL,
  127058. 0
  127059. };
  127060. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127061. 5,
  127062. 4,
  127063. 6,
  127064. 3,
  127065. 7,
  127066. 2,
  127067. 8,
  127068. 1,
  127069. 9,
  127070. 0,
  127071. 10,
  127072. };
  127073. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127074. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127075. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127076. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127077. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127078. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127079. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127080. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127081. 10,10,10, 8, 9, 8, 8, 9, 8,
  127082. };
  127083. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127084. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127085. 3.5, 4.5,
  127086. };
  127087. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127088. 9, 7, 5, 3, 1, 0, 2, 4,
  127089. 6, 8, 10,
  127090. };
  127091. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127092. _vq_quantthresh__44cn1_sm_p6_1,
  127093. _vq_quantmap__44cn1_sm_p6_1,
  127094. 11,
  127095. 11
  127096. };
  127097. static static_codebook _44cn1_sm_p6_1 = {
  127098. 2, 121,
  127099. _vq_lengthlist__44cn1_sm_p6_1,
  127100. 1, -531365888, 1611661312, 4, 0,
  127101. _vq_quantlist__44cn1_sm_p6_1,
  127102. NULL,
  127103. &_vq_auxt__44cn1_sm_p6_1,
  127104. NULL,
  127105. 0
  127106. };
  127107. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127108. 6,
  127109. 5,
  127110. 7,
  127111. 4,
  127112. 8,
  127113. 3,
  127114. 9,
  127115. 2,
  127116. 10,
  127117. 1,
  127118. 11,
  127119. 0,
  127120. 12,
  127121. };
  127122. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127123. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127124. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127125. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127126. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127127. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127128. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127129. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127130. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127131. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127132. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127133. 0,13,12,12,12,13,13,13,14,
  127134. };
  127135. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127136. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127137. 12.5, 17.5, 22.5, 27.5,
  127138. };
  127139. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127140. 11, 9, 7, 5, 3, 1, 0, 2,
  127141. 4, 6, 8, 10, 12,
  127142. };
  127143. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127144. _vq_quantthresh__44cn1_sm_p7_0,
  127145. _vq_quantmap__44cn1_sm_p7_0,
  127146. 13,
  127147. 13
  127148. };
  127149. static static_codebook _44cn1_sm_p7_0 = {
  127150. 2, 169,
  127151. _vq_lengthlist__44cn1_sm_p7_0,
  127152. 1, -526516224, 1616117760, 4, 0,
  127153. _vq_quantlist__44cn1_sm_p7_0,
  127154. NULL,
  127155. &_vq_auxt__44cn1_sm_p7_0,
  127156. NULL,
  127157. 0
  127158. };
  127159. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127160. 2,
  127161. 1,
  127162. 3,
  127163. 0,
  127164. 4,
  127165. };
  127166. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127167. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127168. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127169. };
  127170. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127171. -1.5, -0.5, 0.5, 1.5,
  127172. };
  127173. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127174. 3, 1, 0, 2, 4,
  127175. };
  127176. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127177. _vq_quantthresh__44cn1_sm_p7_1,
  127178. _vq_quantmap__44cn1_sm_p7_1,
  127179. 5,
  127180. 5
  127181. };
  127182. static static_codebook _44cn1_sm_p7_1 = {
  127183. 2, 25,
  127184. _vq_lengthlist__44cn1_sm_p7_1,
  127185. 1, -533725184, 1611661312, 3, 0,
  127186. _vq_quantlist__44cn1_sm_p7_1,
  127187. NULL,
  127188. &_vq_auxt__44cn1_sm_p7_1,
  127189. NULL,
  127190. 0
  127191. };
  127192. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127193. 4,
  127194. 3,
  127195. 5,
  127196. 2,
  127197. 6,
  127198. 1,
  127199. 7,
  127200. 0,
  127201. 8,
  127202. };
  127203. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127204. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127205. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127206. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127207. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127208. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127209. 14,
  127210. };
  127211. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127212. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127213. };
  127214. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127215. 7, 5, 3, 1, 0, 2, 4, 6,
  127216. 8,
  127217. };
  127218. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127219. _vq_quantthresh__44cn1_sm_p8_0,
  127220. _vq_quantmap__44cn1_sm_p8_0,
  127221. 9,
  127222. 9
  127223. };
  127224. static static_codebook _44cn1_sm_p8_0 = {
  127225. 2, 81,
  127226. _vq_lengthlist__44cn1_sm_p8_0,
  127227. 1, -516186112, 1627103232, 4, 0,
  127228. _vq_quantlist__44cn1_sm_p8_0,
  127229. NULL,
  127230. &_vq_auxt__44cn1_sm_p8_0,
  127231. NULL,
  127232. 0
  127233. };
  127234. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127235. 6,
  127236. 5,
  127237. 7,
  127238. 4,
  127239. 8,
  127240. 3,
  127241. 9,
  127242. 2,
  127243. 10,
  127244. 1,
  127245. 11,
  127246. 0,
  127247. 12,
  127248. };
  127249. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127250. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127251. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127252. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127253. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127254. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127255. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127256. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127257. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127258. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127259. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127260. 17,12,12,11,10,13,11,13,13,
  127261. };
  127262. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127263. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127264. 42.5, 59.5, 76.5, 93.5,
  127265. };
  127266. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127267. 11, 9, 7, 5, 3, 1, 0, 2,
  127268. 4, 6, 8, 10, 12,
  127269. };
  127270. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127271. _vq_quantthresh__44cn1_sm_p8_1,
  127272. _vq_quantmap__44cn1_sm_p8_1,
  127273. 13,
  127274. 13
  127275. };
  127276. static static_codebook _44cn1_sm_p8_1 = {
  127277. 2, 169,
  127278. _vq_lengthlist__44cn1_sm_p8_1,
  127279. 1, -522616832, 1620115456, 4, 0,
  127280. _vq_quantlist__44cn1_sm_p8_1,
  127281. NULL,
  127282. &_vq_auxt__44cn1_sm_p8_1,
  127283. NULL,
  127284. 0
  127285. };
  127286. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127287. 8,
  127288. 7,
  127289. 9,
  127290. 6,
  127291. 10,
  127292. 5,
  127293. 11,
  127294. 4,
  127295. 12,
  127296. 3,
  127297. 13,
  127298. 2,
  127299. 14,
  127300. 1,
  127301. 15,
  127302. 0,
  127303. 16,
  127304. };
  127305. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127306. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127307. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127308. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127309. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127310. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127311. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127312. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127313. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127314. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127315. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127316. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127317. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127318. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127319. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127320. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127321. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127322. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127323. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127324. 9,
  127325. };
  127326. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127327. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127328. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127329. };
  127330. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127331. 15, 13, 11, 9, 7, 5, 3, 1,
  127332. 0, 2, 4, 6, 8, 10, 12, 14,
  127333. 16,
  127334. };
  127335. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127336. _vq_quantthresh__44cn1_sm_p8_2,
  127337. _vq_quantmap__44cn1_sm_p8_2,
  127338. 17,
  127339. 17
  127340. };
  127341. static static_codebook _44cn1_sm_p8_2 = {
  127342. 2, 289,
  127343. _vq_lengthlist__44cn1_sm_p8_2,
  127344. 1, -529530880, 1611661312, 5, 0,
  127345. _vq_quantlist__44cn1_sm_p8_2,
  127346. NULL,
  127347. &_vq_auxt__44cn1_sm_p8_2,
  127348. NULL,
  127349. 0
  127350. };
  127351. static long _huff_lengthlist__44cn1_sm_short[] = {
  127352. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127353. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127354. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127355. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127356. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127357. 9,
  127358. };
  127359. static static_codebook _huff_book__44cn1_sm_short = {
  127360. 2, 81,
  127361. _huff_lengthlist__44cn1_sm_short,
  127362. 0, 0, 0, 0, 0,
  127363. NULL,
  127364. NULL,
  127365. NULL,
  127366. NULL,
  127367. 0
  127368. };
  127369. /*** End of inlined file: res_books_stereo.h ***/
  127370. static vorbis_info_residue0 _residue_44_low={
  127371. 0,-1, -1, 9,-1,
  127372. {0},
  127373. {-1},
  127374. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127375. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127376. };
  127377. static vorbis_info_residue0 _residue_44_mid={
  127378. 0,-1, -1, 10,-1,
  127379. {0},
  127380. {-1},
  127381. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127382. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127383. };
  127384. static vorbis_info_residue0 _residue_44_high={
  127385. 0,-1, -1, 10,-1,
  127386. {0},
  127387. {-1},
  127388. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127389. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127390. };
  127391. static static_bookblock _resbook_44s_n1={
  127392. {
  127393. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127394. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127395. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127396. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127397. }
  127398. };
  127399. static static_bookblock _resbook_44sm_n1={
  127400. {
  127401. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127402. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127403. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127404. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127405. }
  127406. };
  127407. static static_bookblock _resbook_44s_0={
  127408. {
  127409. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127410. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127411. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127412. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127413. }
  127414. };
  127415. static static_bookblock _resbook_44sm_0={
  127416. {
  127417. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127418. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127419. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127420. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127421. }
  127422. };
  127423. static static_bookblock _resbook_44s_1={
  127424. {
  127425. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127426. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127427. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127428. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127429. }
  127430. };
  127431. static static_bookblock _resbook_44sm_1={
  127432. {
  127433. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127434. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127435. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127436. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127437. }
  127438. };
  127439. static static_bookblock _resbook_44s_2={
  127440. {
  127441. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127442. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127443. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127444. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127445. }
  127446. };
  127447. static static_bookblock _resbook_44s_3={
  127448. {
  127449. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127450. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127451. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127452. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127453. }
  127454. };
  127455. static static_bookblock _resbook_44s_4={
  127456. {
  127457. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127458. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127459. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127460. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127461. }
  127462. };
  127463. static static_bookblock _resbook_44s_5={
  127464. {
  127465. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127466. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127467. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127468. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127469. }
  127470. };
  127471. static static_bookblock _resbook_44s_6={
  127472. {
  127473. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127474. {0,0,&_44c6_s_p4_0},
  127475. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127476. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127477. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127478. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127479. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127480. }
  127481. };
  127482. static static_bookblock _resbook_44s_7={
  127483. {
  127484. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127485. {0,0,&_44c7_s_p4_0},
  127486. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127487. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127488. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127489. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127490. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127491. }
  127492. };
  127493. static static_bookblock _resbook_44s_8={
  127494. {
  127495. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127496. {0,0,&_44c8_s_p4_0},
  127497. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127498. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127499. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127500. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127501. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127502. }
  127503. };
  127504. static static_bookblock _resbook_44s_9={
  127505. {
  127506. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127507. {0,0,&_44c9_s_p4_0},
  127508. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127509. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127510. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127511. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127512. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127513. }
  127514. };
  127515. static vorbis_residue_template _res_44s_n1[]={
  127516. {2,0, &_residue_44_low,
  127517. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127518. &_resbook_44s_n1,&_resbook_44sm_n1},
  127519. {2,0, &_residue_44_low,
  127520. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127521. &_resbook_44s_n1,&_resbook_44sm_n1}
  127522. };
  127523. static vorbis_residue_template _res_44s_0[]={
  127524. {2,0, &_residue_44_low,
  127525. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127526. &_resbook_44s_0,&_resbook_44sm_0},
  127527. {2,0, &_residue_44_low,
  127528. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127529. &_resbook_44s_0,&_resbook_44sm_0}
  127530. };
  127531. static vorbis_residue_template _res_44s_1[]={
  127532. {2,0, &_residue_44_low,
  127533. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127534. &_resbook_44s_1,&_resbook_44sm_1},
  127535. {2,0, &_residue_44_low,
  127536. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127537. &_resbook_44s_1,&_resbook_44sm_1}
  127538. };
  127539. static vorbis_residue_template _res_44s_2[]={
  127540. {2,0, &_residue_44_mid,
  127541. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127542. &_resbook_44s_2,&_resbook_44s_2},
  127543. {2,0, &_residue_44_mid,
  127544. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127545. &_resbook_44s_2,&_resbook_44s_2}
  127546. };
  127547. static vorbis_residue_template _res_44s_3[]={
  127548. {2,0, &_residue_44_mid,
  127549. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127550. &_resbook_44s_3,&_resbook_44s_3},
  127551. {2,0, &_residue_44_mid,
  127552. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127553. &_resbook_44s_3,&_resbook_44s_3}
  127554. };
  127555. static vorbis_residue_template _res_44s_4[]={
  127556. {2,0, &_residue_44_mid,
  127557. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127558. &_resbook_44s_4,&_resbook_44s_4},
  127559. {2,0, &_residue_44_mid,
  127560. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127561. &_resbook_44s_4,&_resbook_44s_4}
  127562. };
  127563. static vorbis_residue_template _res_44s_5[]={
  127564. {2,0, &_residue_44_mid,
  127565. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127566. &_resbook_44s_5,&_resbook_44s_5},
  127567. {2,0, &_residue_44_mid,
  127568. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127569. &_resbook_44s_5,&_resbook_44s_5}
  127570. };
  127571. static vorbis_residue_template _res_44s_6[]={
  127572. {2,0, &_residue_44_high,
  127573. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127574. &_resbook_44s_6,&_resbook_44s_6},
  127575. {2,0, &_residue_44_high,
  127576. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127577. &_resbook_44s_6,&_resbook_44s_6}
  127578. };
  127579. static vorbis_residue_template _res_44s_7[]={
  127580. {2,0, &_residue_44_high,
  127581. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127582. &_resbook_44s_7,&_resbook_44s_7},
  127583. {2,0, &_residue_44_high,
  127584. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127585. &_resbook_44s_7,&_resbook_44s_7}
  127586. };
  127587. static vorbis_residue_template _res_44s_8[]={
  127588. {2,0, &_residue_44_high,
  127589. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127590. &_resbook_44s_8,&_resbook_44s_8},
  127591. {2,0, &_residue_44_high,
  127592. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127593. &_resbook_44s_8,&_resbook_44s_8}
  127594. };
  127595. static vorbis_residue_template _res_44s_9[]={
  127596. {2,0, &_residue_44_high,
  127597. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127598. &_resbook_44s_9,&_resbook_44s_9},
  127599. {2,0, &_residue_44_high,
  127600. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127601. &_resbook_44s_9,&_resbook_44s_9}
  127602. };
  127603. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127604. { _map_nominal, _res_44s_n1 }, /* -1 */
  127605. { _map_nominal, _res_44s_0 }, /* 0 */
  127606. { _map_nominal, _res_44s_1 }, /* 1 */
  127607. { _map_nominal, _res_44s_2 }, /* 2 */
  127608. { _map_nominal, _res_44s_3 }, /* 3 */
  127609. { _map_nominal, _res_44s_4 }, /* 4 */
  127610. { _map_nominal, _res_44s_5 }, /* 5 */
  127611. { _map_nominal, _res_44s_6 }, /* 6 */
  127612. { _map_nominal, _res_44s_7 }, /* 7 */
  127613. { _map_nominal, _res_44s_8 }, /* 8 */
  127614. { _map_nominal, _res_44s_9 }, /* 9 */
  127615. };
  127616. /*** End of inlined file: residue_44.h ***/
  127617. /*** Start of inlined file: psych_44.h ***/
  127618. static vorbis_info_psy_global _psy_global_44[5]={
  127619. {8, /* lines per eighth octave */
  127620. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127621. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127622. -6.f,
  127623. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127624. },
  127625. {8, /* lines per eighth octave */
  127626. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127627. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127628. -6.f,
  127629. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127630. },
  127631. {8, /* lines per eighth octave */
  127632. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127633. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127634. -6.f,
  127635. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127636. },
  127637. {8, /* lines per eighth octave */
  127638. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127639. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127640. -6.f,
  127641. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127642. },
  127643. {8, /* lines per eighth octave */
  127644. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127645. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127646. -6.f,
  127647. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127648. },
  127649. };
  127650. static compandblock _psy_compand_44[6]={
  127651. {{
  127652. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127653. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127654. 16,17,18,19,20,21,22, 23, /* 23dB */
  127655. 24,25,26,27,28,29,30, 31, /* 31dB */
  127656. 32,33,34,35,36,37,38, 39, /* 39dB */
  127657. }},
  127658. {{
  127659. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127660. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127661. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127662. 15,16,17,17,17,18,18, 19, /* 31dB */
  127663. 19,19,20,21,22,23,24, 25, /* 39dB */
  127664. }},
  127665. {{
  127666. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127667. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127668. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127669. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127670. 11,12,13,14,15,16,17, 18, /* 39dB */
  127671. }},
  127672. {{
  127673. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127674. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127675. 16,17,18,19,20,21,22, 23, /* 23dB */
  127676. 24,25,26,27,28,29,30, 31, /* 31dB */
  127677. 32,33,34,35,36,37,38, 39, /* 39dB */
  127678. }},
  127679. {{
  127680. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127681. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127682. 13,14,14,14,15,15,15, 15, /* 23dB */
  127683. 16,16,17,17,17,18,18, 19, /* 31dB */
  127684. 19,19,20,21,22,23,24, 25, /* 39dB */
  127685. }},
  127686. {{
  127687. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127688. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127689. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127690. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127691. 11,12,13,14,15,16,17, 18, /* 39dB */
  127692. }}
  127693. };
  127694. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  127695. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  127696. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  127697. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  127698. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  127699. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  127700. /* 4 */
  127701. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127702. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127703. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127704. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127705. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127706. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127707. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127708. };
  127709. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  127710. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  127711. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  127712. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  127713. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  127714. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  127715. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127716. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127717. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127718. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127719. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127720. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127721. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127722. };
  127723. static noise3 _psy_noisebias_trans[12]={
  127724. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127725. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127726. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127727. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127728. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  127729. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127730. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127731. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127732. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127733. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127734. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127735. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  127736. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127737. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127738. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127739. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127740. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127741. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127742. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127743. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127744. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  127745. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127746. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127747. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127748. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127749. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  127750. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127751. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  127752. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  127753. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127754. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127755. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  127756. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  127757. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  127758. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  127759. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127760. };
  127761. static noise3 _psy_noisebias_long[12]={
  127762. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  127763. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  127764. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127765. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  127766. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  127767. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127768. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127769. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127770. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127771. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127772. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127773. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127774. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127775. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127776. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  127777. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127778. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127779. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  127780. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127781. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127782. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  127783. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127784. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127785. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  127786. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127787. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  127788. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127789. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  127790. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  127791. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127792. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127793. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  127794. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127795. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  127796. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  127797. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127798. };
  127799. static noise3 _psy_noisebias_impulse[12]={
  127800. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127801. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127802. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127803. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  127804. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  127805. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127806. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  127807. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  127808. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  127809. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  127810. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127811. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127812. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  127813. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127814. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127815. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  127816. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127817. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127818. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  127819. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  127820. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  127821. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  127822. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  127823. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  127824. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  127825. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  127826. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  127827. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  127828. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  127829. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  127830. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127831. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  127832. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127833. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  127834. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  127835. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127836. };
  127837. static noise3 _psy_noisebias_padding[12]={
  127838. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127839. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127840. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127841. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127842. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  127843. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  127844. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  127845. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  127846. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  127847. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  127848. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  127849. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127850. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  127851. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  127852. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127853. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  127854. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  127855. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127856. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127857. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  127858. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  127859. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127860. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  127861. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  127862. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127863. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  127864. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  127865. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  127866. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  127867. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  127868. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  127869. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  127870. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  127871. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  127872. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  127873. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127874. };
  127875. static noiseguard _psy_noiseguards_44[4]={
  127876. {3,3,15},
  127877. {3,3,15},
  127878. {10,10,100},
  127879. {10,10,100},
  127880. };
  127881. static int _psy_tone_suppress[12]={
  127882. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  127883. };
  127884. static int _psy_tone_0dB[12]={
  127885. 90,90,95,95,95,95,105,105,105,105,105,105,
  127886. };
  127887. static int _psy_noise_suppress[12]={
  127888. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  127889. };
  127890. static vorbis_info_psy _psy_info_template={
  127891. -1,
  127892. -140.,-140.,
  127893. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  127894. 1, -0.f, .5f, .5f, 0,0,0,
  127895. {{-1},{-1},{-1}},{-1},105.f,
  127896. 0,0,-1,-1,0.,
  127897. };
  127898. static int _psy_ath_floater[12]={
  127899. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  127900. };
  127901. static int _psy_ath_abs[12]={
  127902. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  127903. };
  127904. static adj_stereo _psy_stereo_modes_44[12]={
  127905. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  127906. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  127907. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  127908. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  127909. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  127910. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  127911. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  127912. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  127913. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  127914. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  127915. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  127916. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127917. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  127918. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  127919. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  127920. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127921. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  127922. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  127923. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  127924. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127925. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127926. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  127927. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  127928. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127929. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127930. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  127931. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  127932. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127933. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127934. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127935. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  127936. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127937. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127938. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127939. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  127940. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127941. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127942. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127943. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  127944. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127945. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127946. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127947. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  127948. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127949. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127950. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  127951. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  127952. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127953. };
  127954. static att3 _psy_tone_masteratt_44[12]={
  127955. {{ 35, 21, 9}, 0, 0}, /* -1 */
  127956. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  127957. /* 1 */
  127958. {{ 25, 12, 2}, 0, 0}, /* 1 */
  127959. /* 2 */
  127960. {{ 20, 9, -3}, 0, 0}, /* 2 */
  127961. {{ 20, 9, -4}, 0, 0}, /* 3 */
  127962. {{ 20, 9, -4}, 0, 0}, /* 4 */
  127963. {{ 20, 6, -6}, 0, 0}, /* 5 */
  127964. {{ 20, 3, -10}, 0, 0}, /* 6 */
  127965. {{ 18, 1, -14}, 0, 0}, /* 7 */
  127966. {{ 18, 0, -16}, 0, 0}, /* 8 */
  127967. {{ 18, -2, -16}, 0, 0}, /* 9 */
  127968. {{ 12, -2, -20}, 0, 0}, /* 10 */
  127969. };
  127970. static double _psy_lowpass_44[12]={
  127971. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  127972. };
  127973. static int _noise_start_short_44[11]={
  127974. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  127975. };
  127976. static int _noise_start_long_44[11]={
  127977. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  127978. };
  127979. static int _noise_part_short_44[11]={
  127980. 8,8,8,8,8,8,8,8,8,8,8
  127981. };
  127982. static int _noise_part_long_44[11]={
  127983. 32,32,32,32,32,32,32,32,32,32,32
  127984. };
  127985. static double _noise_thresh_44[11]={
  127986. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  127987. };
  127988. static double _noise_thresh_5only[2]={
  127989. .5,.5,
  127990. };
  127991. /*** End of inlined file: psych_44.h ***/
  127992. static double rate_mapping_44_stereo[12]={
  127993. 22500.,32000.,40000.,48000.,56000.,64000.,
  127994. 80000.,96000.,112000.,128000.,160000.,250001.
  127995. };
  127996. static double quality_mapping_44[12]={
  127997. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  127998. };
  127999. static int blocksize_short_44[11]={
  128000. 512,256,256,256,256,256,256,256,256,256,256
  128001. };
  128002. static int blocksize_long_44[11]={
  128003. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128004. };
  128005. static double _psy_compand_short_mapping[12]={
  128006. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128007. };
  128008. static double _psy_compand_long_mapping[12]={
  128009. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128010. };
  128011. static double _global_mapping_44[12]={
  128012. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128013. };
  128014. static int _floor_short_mapping_44[11]={
  128015. 1,0,0,2,2,4,5,5,5,5,5
  128016. };
  128017. static int _floor_long_mapping_44[11]={
  128018. 8,7,7,7,7,7,7,7,7,7,7
  128019. };
  128020. ve_setup_data_template ve_setup_44_stereo={
  128021. 11,
  128022. rate_mapping_44_stereo,
  128023. quality_mapping_44,
  128024. 2,
  128025. 40000,
  128026. 50000,
  128027. blocksize_short_44,
  128028. blocksize_long_44,
  128029. _psy_tone_masteratt_44,
  128030. _psy_tone_0dB,
  128031. _psy_tone_suppress,
  128032. _vp_tonemask_adj_otherblock,
  128033. _vp_tonemask_adj_longblock,
  128034. _vp_tonemask_adj_otherblock,
  128035. _psy_noiseguards_44,
  128036. _psy_noisebias_impulse,
  128037. _psy_noisebias_padding,
  128038. _psy_noisebias_trans,
  128039. _psy_noisebias_long,
  128040. _psy_noise_suppress,
  128041. _psy_compand_44,
  128042. _psy_compand_short_mapping,
  128043. _psy_compand_long_mapping,
  128044. {_noise_start_short_44,_noise_start_long_44},
  128045. {_noise_part_short_44,_noise_part_long_44},
  128046. _noise_thresh_44,
  128047. _psy_ath_floater,
  128048. _psy_ath_abs,
  128049. _psy_lowpass_44,
  128050. _psy_global_44,
  128051. _global_mapping_44,
  128052. _psy_stereo_modes_44,
  128053. _floor_books,
  128054. _floor,
  128055. _floor_short_mapping_44,
  128056. _floor_long_mapping_44,
  128057. _mapres_template_44_stereo
  128058. };
  128059. /*** End of inlined file: setup_44.h ***/
  128060. /*** Start of inlined file: setup_44u.h ***/
  128061. /*** Start of inlined file: residue_44u.h ***/
  128062. /*** Start of inlined file: res_books_uncoupled.h ***/
  128063. static long _vq_quantlist__16u0__p1_0[] = {
  128064. 1,
  128065. 0,
  128066. 2,
  128067. };
  128068. static long _vq_lengthlist__16u0__p1_0[] = {
  128069. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128070. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128071. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128072. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128073. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128074. 12,
  128075. };
  128076. static float _vq_quantthresh__16u0__p1_0[] = {
  128077. -0.5, 0.5,
  128078. };
  128079. static long _vq_quantmap__16u0__p1_0[] = {
  128080. 1, 0, 2,
  128081. };
  128082. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128083. _vq_quantthresh__16u0__p1_0,
  128084. _vq_quantmap__16u0__p1_0,
  128085. 3,
  128086. 3
  128087. };
  128088. static static_codebook _16u0__p1_0 = {
  128089. 4, 81,
  128090. _vq_lengthlist__16u0__p1_0,
  128091. 1, -535822336, 1611661312, 2, 0,
  128092. _vq_quantlist__16u0__p1_0,
  128093. NULL,
  128094. &_vq_auxt__16u0__p1_0,
  128095. NULL,
  128096. 0
  128097. };
  128098. static long _vq_quantlist__16u0__p2_0[] = {
  128099. 1,
  128100. 0,
  128101. 2,
  128102. };
  128103. static long _vq_lengthlist__16u0__p2_0[] = {
  128104. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128105. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128106. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128107. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128108. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128109. 8,
  128110. };
  128111. static float _vq_quantthresh__16u0__p2_0[] = {
  128112. -0.5, 0.5,
  128113. };
  128114. static long _vq_quantmap__16u0__p2_0[] = {
  128115. 1, 0, 2,
  128116. };
  128117. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128118. _vq_quantthresh__16u0__p2_0,
  128119. _vq_quantmap__16u0__p2_0,
  128120. 3,
  128121. 3
  128122. };
  128123. static static_codebook _16u0__p2_0 = {
  128124. 4, 81,
  128125. _vq_lengthlist__16u0__p2_0,
  128126. 1, -535822336, 1611661312, 2, 0,
  128127. _vq_quantlist__16u0__p2_0,
  128128. NULL,
  128129. &_vq_auxt__16u0__p2_0,
  128130. NULL,
  128131. 0
  128132. };
  128133. static long _vq_quantlist__16u0__p3_0[] = {
  128134. 2,
  128135. 1,
  128136. 3,
  128137. 0,
  128138. 4,
  128139. };
  128140. static long _vq_lengthlist__16u0__p3_0[] = {
  128141. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128142. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128143. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128144. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128145. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128146. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128147. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128148. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128149. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128150. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128151. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128152. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128153. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128154. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128155. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128156. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128157. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128158. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128159. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128160. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128161. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128162. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128163. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128164. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128165. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128166. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128167. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128168. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128169. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128170. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128171. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128172. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128173. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128174. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128175. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128176. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128177. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128178. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128179. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128180. 18,
  128181. };
  128182. static float _vq_quantthresh__16u0__p3_0[] = {
  128183. -1.5, -0.5, 0.5, 1.5,
  128184. };
  128185. static long _vq_quantmap__16u0__p3_0[] = {
  128186. 3, 1, 0, 2, 4,
  128187. };
  128188. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128189. _vq_quantthresh__16u0__p3_0,
  128190. _vq_quantmap__16u0__p3_0,
  128191. 5,
  128192. 5
  128193. };
  128194. static static_codebook _16u0__p3_0 = {
  128195. 4, 625,
  128196. _vq_lengthlist__16u0__p3_0,
  128197. 1, -533725184, 1611661312, 3, 0,
  128198. _vq_quantlist__16u0__p3_0,
  128199. NULL,
  128200. &_vq_auxt__16u0__p3_0,
  128201. NULL,
  128202. 0
  128203. };
  128204. static long _vq_quantlist__16u0__p4_0[] = {
  128205. 2,
  128206. 1,
  128207. 3,
  128208. 0,
  128209. 4,
  128210. };
  128211. static long _vq_lengthlist__16u0__p4_0[] = {
  128212. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128213. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128214. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128215. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128216. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128217. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128218. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128219. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128220. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128221. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128222. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128223. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128224. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128225. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128226. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128227. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128228. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128229. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128230. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128231. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128232. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128233. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128234. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128235. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128236. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128237. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128238. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128239. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128240. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128241. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128242. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128243. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128244. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128245. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128246. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128247. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128248. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128249. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128250. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128251. 11,
  128252. };
  128253. static float _vq_quantthresh__16u0__p4_0[] = {
  128254. -1.5, -0.5, 0.5, 1.5,
  128255. };
  128256. static long _vq_quantmap__16u0__p4_0[] = {
  128257. 3, 1, 0, 2, 4,
  128258. };
  128259. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128260. _vq_quantthresh__16u0__p4_0,
  128261. _vq_quantmap__16u0__p4_0,
  128262. 5,
  128263. 5
  128264. };
  128265. static static_codebook _16u0__p4_0 = {
  128266. 4, 625,
  128267. _vq_lengthlist__16u0__p4_0,
  128268. 1, -533725184, 1611661312, 3, 0,
  128269. _vq_quantlist__16u0__p4_0,
  128270. NULL,
  128271. &_vq_auxt__16u0__p4_0,
  128272. NULL,
  128273. 0
  128274. };
  128275. static long _vq_quantlist__16u0__p5_0[] = {
  128276. 4,
  128277. 3,
  128278. 5,
  128279. 2,
  128280. 6,
  128281. 1,
  128282. 7,
  128283. 0,
  128284. 8,
  128285. };
  128286. static long _vq_lengthlist__16u0__p5_0[] = {
  128287. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128288. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128289. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128290. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128291. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128292. 12,
  128293. };
  128294. static float _vq_quantthresh__16u0__p5_0[] = {
  128295. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128296. };
  128297. static long _vq_quantmap__16u0__p5_0[] = {
  128298. 7, 5, 3, 1, 0, 2, 4, 6,
  128299. 8,
  128300. };
  128301. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128302. _vq_quantthresh__16u0__p5_0,
  128303. _vq_quantmap__16u0__p5_0,
  128304. 9,
  128305. 9
  128306. };
  128307. static static_codebook _16u0__p5_0 = {
  128308. 2, 81,
  128309. _vq_lengthlist__16u0__p5_0,
  128310. 1, -531628032, 1611661312, 4, 0,
  128311. _vq_quantlist__16u0__p5_0,
  128312. NULL,
  128313. &_vq_auxt__16u0__p5_0,
  128314. NULL,
  128315. 0
  128316. };
  128317. static long _vq_quantlist__16u0__p6_0[] = {
  128318. 6,
  128319. 5,
  128320. 7,
  128321. 4,
  128322. 8,
  128323. 3,
  128324. 9,
  128325. 2,
  128326. 10,
  128327. 1,
  128328. 11,
  128329. 0,
  128330. 12,
  128331. };
  128332. static long _vq_lengthlist__16u0__p6_0[] = {
  128333. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128334. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128335. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128336. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128337. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128338. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128339. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128340. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128341. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128342. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128343. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128344. };
  128345. static float _vq_quantthresh__16u0__p6_0[] = {
  128346. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128347. 12.5, 17.5, 22.5, 27.5,
  128348. };
  128349. static long _vq_quantmap__16u0__p6_0[] = {
  128350. 11, 9, 7, 5, 3, 1, 0, 2,
  128351. 4, 6, 8, 10, 12,
  128352. };
  128353. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128354. _vq_quantthresh__16u0__p6_0,
  128355. _vq_quantmap__16u0__p6_0,
  128356. 13,
  128357. 13
  128358. };
  128359. static static_codebook _16u0__p6_0 = {
  128360. 2, 169,
  128361. _vq_lengthlist__16u0__p6_0,
  128362. 1, -526516224, 1616117760, 4, 0,
  128363. _vq_quantlist__16u0__p6_0,
  128364. NULL,
  128365. &_vq_auxt__16u0__p6_0,
  128366. NULL,
  128367. 0
  128368. };
  128369. static long _vq_quantlist__16u0__p6_1[] = {
  128370. 2,
  128371. 1,
  128372. 3,
  128373. 0,
  128374. 4,
  128375. };
  128376. static long _vq_lengthlist__16u0__p6_1[] = {
  128377. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128378. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128379. };
  128380. static float _vq_quantthresh__16u0__p6_1[] = {
  128381. -1.5, -0.5, 0.5, 1.5,
  128382. };
  128383. static long _vq_quantmap__16u0__p6_1[] = {
  128384. 3, 1, 0, 2, 4,
  128385. };
  128386. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128387. _vq_quantthresh__16u0__p6_1,
  128388. _vq_quantmap__16u0__p6_1,
  128389. 5,
  128390. 5
  128391. };
  128392. static static_codebook _16u0__p6_1 = {
  128393. 2, 25,
  128394. _vq_lengthlist__16u0__p6_1,
  128395. 1, -533725184, 1611661312, 3, 0,
  128396. _vq_quantlist__16u0__p6_1,
  128397. NULL,
  128398. &_vq_auxt__16u0__p6_1,
  128399. NULL,
  128400. 0
  128401. };
  128402. static long _vq_quantlist__16u0__p7_0[] = {
  128403. 1,
  128404. 0,
  128405. 2,
  128406. };
  128407. static long _vq_lengthlist__16u0__p7_0[] = {
  128408. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128409. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128410. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128411. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128412. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128413. 7,
  128414. };
  128415. static float _vq_quantthresh__16u0__p7_0[] = {
  128416. -157.5, 157.5,
  128417. };
  128418. static long _vq_quantmap__16u0__p7_0[] = {
  128419. 1, 0, 2,
  128420. };
  128421. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128422. _vq_quantthresh__16u0__p7_0,
  128423. _vq_quantmap__16u0__p7_0,
  128424. 3,
  128425. 3
  128426. };
  128427. static static_codebook _16u0__p7_0 = {
  128428. 4, 81,
  128429. _vq_lengthlist__16u0__p7_0,
  128430. 1, -518803456, 1628680192, 2, 0,
  128431. _vq_quantlist__16u0__p7_0,
  128432. NULL,
  128433. &_vq_auxt__16u0__p7_0,
  128434. NULL,
  128435. 0
  128436. };
  128437. static long _vq_quantlist__16u0__p7_1[] = {
  128438. 7,
  128439. 6,
  128440. 8,
  128441. 5,
  128442. 9,
  128443. 4,
  128444. 10,
  128445. 3,
  128446. 11,
  128447. 2,
  128448. 12,
  128449. 1,
  128450. 13,
  128451. 0,
  128452. 14,
  128453. };
  128454. static long _vq_lengthlist__16u0__p7_1[] = {
  128455. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128456. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128457. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128458. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128459. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128460. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128461. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128462. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128463. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128464. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128465. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128466. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128467. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128468. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128469. 10,
  128470. };
  128471. static float _vq_quantthresh__16u0__p7_1[] = {
  128472. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128473. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128474. };
  128475. static long _vq_quantmap__16u0__p7_1[] = {
  128476. 13, 11, 9, 7, 5, 3, 1, 0,
  128477. 2, 4, 6, 8, 10, 12, 14,
  128478. };
  128479. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128480. _vq_quantthresh__16u0__p7_1,
  128481. _vq_quantmap__16u0__p7_1,
  128482. 15,
  128483. 15
  128484. };
  128485. static static_codebook _16u0__p7_1 = {
  128486. 2, 225,
  128487. _vq_lengthlist__16u0__p7_1,
  128488. 1, -520986624, 1620377600, 4, 0,
  128489. _vq_quantlist__16u0__p7_1,
  128490. NULL,
  128491. &_vq_auxt__16u0__p7_1,
  128492. NULL,
  128493. 0
  128494. };
  128495. static long _vq_quantlist__16u0__p7_2[] = {
  128496. 10,
  128497. 9,
  128498. 11,
  128499. 8,
  128500. 12,
  128501. 7,
  128502. 13,
  128503. 6,
  128504. 14,
  128505. 5,
  128506. 15,
  128507. 4,
  128508. 16,
  128509. 3,
  128510. 17,
  128511. 2,
  128512. 18,
  128513. 1,
  128514. 19,
  128515. 0,
  128516. 20,
  128517. };
  128518. static long _vq_lengthlist__16u0__p7_2[] = {
  128519. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128520. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128521. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128522. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128523. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128524. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128525. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128526. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128527. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128528. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128529. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128530. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128531. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128532. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128533. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128534. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128535. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128536. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128537. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128538. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128539. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128540. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128541. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128542. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128543. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128544. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128545. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128546. 10,10,12,11,10,11,11,11,10,
  128547. };
  128548. static float _vq_quantthresh__16u0__p7_2[] = {
  128549. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128550. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128551. 6.5, 7.5, 8.5, 9.5,
  128552. };
  128553. static long _vq_quantmap__16u0__p7_2[] = {
  128554. 19, 17, 15, 13, 11, 9, 7, 5,
  128555. 3, 1, 0, 2, 4, 6, 8, 10,
  128556. 12, 14, 16, 18, 20,
  128557. };
  128558. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128559. _vq_quantthresh__16u0__p7_2,
  128560. _vq_quantmap__16u0__p7_2,
  128561. 21,
  128562. 21
  128563. };
  128564. static static_codebook _16u0__p7_2 = {
  128565. 2, 441,
  128566. _vq_lengthlist__16u0__p7_2,
  128567. 1, -529268736, 1611661312, 5, 0,
  128568. _vq_quantlist__16u0__p7_2,
  128569. NULL,
  128570. &_vq_auxt__16u0__p7_2,
  128571. NULL,
  128572. 0
  128573. };
  128574. static long _huff_lengthlist__16u0__single[] = {
  128575. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128576. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128577. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128578. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128579. };
  128580. static static_codebook _huff_book__16u0__single = {
  128581. 2, 64,
  128582. _huff_lengthlist__16u0__single,
  128583. 0, 0, 0, 0, 0,
  128584. NULL,
  128585. NULL,
  128586. NULL,
  128587. NULL,
  128588. 0
  128589. };
  128590. static long _huff_lengthlist__16u1__long[] = {
  128591. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128592. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128593. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128594. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128595. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128596. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128597. 16,13,16,18,
  128598. };
  128599. static static_codebook _huff_book__16u1__long = {
  128600. 2, 100,
  128601. _huff_lengthlist__16u1__long,
  128602. 0, 0, 0, 0, 0,
  128603. NULL,
  128604. NULL,
  128605. NULL,
  128606. NULL,
  128607. 0
  128608. };
  128609. static long _vq_quantlist__16u1__p1_0[] = {
  128610. 1,
  128611. 0,
  128612. 2,
  128613. };
  128614. static long _vq_lengthlist__16u1__p1_0[] = {
  128615. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128616. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128617. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128618. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128619. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128620. 11,
  128621. };
  128622. static float _vq_quantthresh__16u1__p1_0[] = {
  128623. -0.5, 0.5,
  128624. };
  128625. static long _vq_quantmap__16u1__p1_0[] = {
  128626. 1, 0, 2,
  128627. };
  128628. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128629. _vq_quantthresh__16u1__p1_0,
  128630. _vq_quantmap__16u1__p1_0,
  128631. 3,
  128632. 3
  128633. };
  128634. static static_codebook _16u1__p1_0 = {
  128635. 4, 81,
  128636. _vq_lengthlist__16u1__p1_0,
  128637. 1, -535822336, 1611661312, 2, 0,
  128638. _vq_quantlist__16u1__p1_0,
  128639. NULL,
  128640. &_vq_auxt__16u1__p1_0,
  128641. NULL,
  128642. 0
  128643. };
  128644. static long _vq_quantlist__16u1__p2_0[] = {
  128645. 1,
  128646. 0,
  128647. 2,
  128648. };
  128649. static long _vq_lengthlist__16u1__p2_0[] = {
  128650. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128651. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128652. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128653. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128654. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128655. 8,
  128656. };
  128657. static float _vq_quantthresh__16u1__p2_0[] = {
  128658. -0.5, 0.5,
  128659. };
  128660. static long _vq_quantmap__16u1__p2_0[] = {
  128661. 1, 0, 2,
  128662. };
  128663. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128664. _vq_quantthresh__16u1__p2_0,
  128665. _vq_quantmap__16u1__p2_0,
  128666. 3,
  128667. 3
  128668. };
  128669. static static_codebook _16u1__p2_0 = {
  128670. 4, 81,
  128671. _vq_lengthlist__16u1__p2_0,
  128672. 1, -535822336, 1611661312, 2, 0,
  128673. _vq_quantlist__16u1__p2_0,
  128674. NULL,
  128675. &_vq_auxt__16u1__p2_0,
  128676. NULL,
  128677. 0
  128678. };
  128679. static long _vq_quantlist__16u1__p3_0[] = {
  128680. 2,
  128681. 1,
  128682. 3,
  128683. 0,
  128684. 4,
  128685. };
  128686. static long _vq_lengthlist__16u1__p3_0[] = {
  128687. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128688. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128689. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128690. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128691. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128692. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  128693. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  128694. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  128695. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  128696. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  128697. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  128698. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  128699. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  128700. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  128701. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  128702. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  128703. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  128704. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  128705. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  128706. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  128707. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  128708. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  128709. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  128710. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  128711. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  128712. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  128713. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  128714. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  128715. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  128716. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  128717. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  128718. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  128719. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  128720. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  128721. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  128722. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  128723. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  128724. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  128725. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  128726. 16,
  128727. };
  128728. static float _vq_quantthresh__16u1__p3_0[] = {
  128729. -1.5, -0.5, 0.5, 1.5,
  128730. };
  128731. static long _vq_quantmap__16u1__p3_0[] = {
  128732. 3, 1, 0, 2, 4,
  128733. };
  128734. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  128735. _vq_quantthresh__16u1__p3_0,
  128736. _vq_quantmap__16u1__p3_0,
  128737. 5,
  128738. 5
  128739. };
  128740. static static_codebook _16u1__p3_0 = {
  128741. 4, 625,
  128742. _vq_lengthlist__16u1__p3_0,
  128743. 1, -533725184, 1611661312, 3, 0,
  128744. _vq_quantlist__16u1__p3_0,
  128745. NULL,
  128746. &_vq_auxt__16u1__p3_0,
  128747. NULL,
  128748. 0
  128749. };
  128750. static long _vq_quantlist__16u1__p4_0[] = {
  128751. 2,
  128752. 1,
  128753. 3,
  128754. 0,
  128755. 4,
  128756. };
  128757. static long _vq_lengthlist__16u1__p4_0[] = {
  128758. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  128759. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  128760. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  128761. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  128762. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  128763. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  128764. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  128765. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  128766. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  128767. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  128768. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  128769. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  128770. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  128771. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  128772. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  128773. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  128774. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  128775. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  128776. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  128777. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  128778. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  128779. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  128780. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  128781. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  128782. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  128783. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  128784. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  128785. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  128786. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  128787. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  128788. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  128789. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  128790. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  128791. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  128792. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  128793. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  128794. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  128795. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  128796. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  128797. 11,
  128798. };
  128799. static float _vq_quantthresh__16u1__p4_0[] = {
  128800. -1.5, -0.5, 0.5, 1.5,
  128801. };
  128802. static long _vq_quantmap__16u1__p4_0[] = {
  128803. 3, 1, 0, 2, 4,
  128804. };
  128805. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  128806. _vq_quantthresh__16u1__p4_0,
  128807. _vq_quantmap__16u1__p4_0,
  128808. 5,
  128809. 5
  128810. };
  128811. static static_codebook _16u1__p4_0 = {
  128812. 4, 625,
  128813. _vq_lengthlist__16u1__p4_0,
  128814. 1, -533725184, 1611661312, 3, 0,
  128815. _vq_quantlist__16u1__p4_0,
  128816. NULL,
  128817. &_vq_auxt__16u1__p4_0,
  128818. NULL,
  128819. 0
  128820. };
  128821. static long _vq_quantlist__16u1__p5_0[] = {
  128822. 4,
  128823. 3,
  128824. 5,
  128825. 2,
  128826. 6,
  128827. 1,
  128828. 7,
  128829. 0,
  128830. 8,
  128831. };
  128832. static long _vq_lengthlist__16u1__p5_0[] = {
  128833. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128834. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  128835. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  128836. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  128837. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  128838. 13,
  128839. };
  128840. static float _vq_quantthresh__16u1__p5_0[] = {
  128841. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128842. };
  128843. static long _vq_quantmap__16u1__p5_0[] = {
  128844. 7, 5, 3, 1, 0, 2, 4, 6,
  128845. 8,
  128846. };
  128847. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  128848. _vq_quantthresh__16u1__p5_0,
  128849. _vq_quantmap__16u1__p5_0,
  128850. 9,
  128851. 9
  128852. };
  128853. static static_codebook _16u1__p5_0 = {
  128854. 2, 81,
  128855. _vq_lengthlist__16u1__p5_0,
  128856. 1, -531628032, 1611661312, 4, 0,
  128857. _vq_quantlist__16u1__p5_0,
  128858. NULL,
  128859. &_vq_auxt__16u1__p5_0,
  128860. NULL,
  128861. 0
  128862. };
  128863. static long _vq_quantlist__16u1__p6_0[] = {
  128864. 4,
  128865. 3,
  128866. 5,
  128867. 2,
  128868. 6,
  128869. 1,
  128870. 7,
  128871. 0,
  128872. 8,
  128873. };
  128874. static long _vq_lengthlist__16u1__p6_0[] = {
  128875. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  128876. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  128877. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  128878. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  128879. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  128880. 11,
  128881. };
  128882. static float _vq_quantthresh__16u1__p6_0[] = {
  128883. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128884. };
  128885. static long _vq_quantmap__16u1__p6_0[] = {
  128886. 7, 5, 3, 1, 0, 2, 4, 6,
  128887. 8,
  128888. };
  128889. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  128890. _vq_quantthresh__16u1__p6_0,
  128891. _vq_quantmap__16u1__p6_0,
  128892. 9,
  128893. 9
  128894. };
  128895. static static_codebook _16u1__p6_0 = {
  128896. 2, 81,
  128897. _vq_lengthlist__16u1__p6_0,
  128898. 1, -531628032, 1611661312, 4, 0,
  128899. _vq_quantlist__16u1__p6_0,
  128900. NULL,
  128901. &_vq_auxt__16u1__p6_0,
  128902. NULL,
  128903. 0
  128904. };
  128905. static long _vq_quantlist__16u1__p7_0[] = {
  128906. 1,
  128907. 0,
  128908. 2,
  128909. };
  128910. static long _vq_lengthlist__16u1__p7_0[] = {
  128911. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  128912. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  128913. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  128914. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  128915. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  128916. 13,
  128917. };
  128918. static float _vq_quantthresh__16u1__p7_0[] = {
  128919. -5.5, 5.5,
  128920. };
  128921. static long _vq_quantmap__16u1__p7_0[] = {
  128922. 1, 0, 2,
  128923. };
  128924. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  128925. _vq_quantthresh__16u1__p7_0,
  128926. _vq_quantmap__16u1__p7_0,
  128927. 3,
  128928. 3
  128929. };
  128930. static static_codebook _16u1__p7_0 = {
  128931. 4, 81,
  128932. _vq_lengthlist__16u1__p7_0,
  128933. 1, -529137664, 1618345984, 2, 0,
  128934. _vq_quantlist__16u1__p7_0,
  128935. NULL,
  128936. &_vq_auxt__16u1__p7_0,
  128937. NULL,
  128938. 0
  128939. };
  128940. static long _vq_quantlist__16u1__p7_1[] = {
  128941. 5,
  128942. 4,
  128943. 6,
  128944. 3,
  128945. 7,
  128946. 2,
  128947. 8,
  128948. 1,
  128949. 9,
  128950. 0,
  128951. 10,
  128952. };
  128953. static long _vq_lengthlist__16u1__p7_1[] = {
  128954. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  128955. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  128956. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  128957. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  128958. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  128959. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  128960. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  128961. 8, 9, 9,10,10,10,10,10,10,
  128962. };
  128963. static float _vq_quantthresh__16u1__p7_1[] = {
  128964. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  128965. 3.5, 4.5,
  128966. };
  128967. static long _vq_quantmap__16u1__p7_1[] = {
  128968. 9, 7, 5, 3, 1, 0, 2, 4,
  128969. 6, 8, 10,
  128970. };
  128971. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  128972. _vq_quantthresh__16u1__p7_1,
  128973. _vq_quantmap__16u1__p7_1,
  128974. 11,
  128975. 11
  128976. };
  128977. static static_codebook _16u1__p7_1 = {
  128978. 2, 121,
  128979. _vq_lengthlist__16u1__p7_1,
  128980. 1, -531365888, 1611661312, 4, 0,
  128981. _vq_quantlist__16u1__p7_1,
  128982. NULL,
  128983. &_vq_auxt__16u1__p7_1,
  128984. NULL,
  128985. 0
  128986. };
  128987. static long _vq_quantlist__16u1__p8_0[] = {
  128988. 5,
  128989. 4,
  128990. 6,
  128991. 3,
  128992. 7,
  128993. 2,
  128994. 8,
  128995. 1,
  128996. 9,
  128997. 0,
  128998. 10,
  128999. };
  129000. static long _vq_lengthlist__16u1__p8_0[] = {
  129001. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129002. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129003. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129004. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129005. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129006. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129007. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129008. 13,14,14,15,15,16,16,15,16,
  129009. };
  129010. static float _vq_quantthresh__16u1__p8_0[] = {
  129011. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129012. 38.5, 49.5,
  129013. };
  129014. static long _vq_quantmap__16u1__p8_0[] = {
  129015. 9, 7, 5, 3, 1, 0, 2, 4,
  129016. 6, 8, 10,
  129017. };
  129018. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129019. _vq_quantthresh__16u1__p8_0,
  129020. _vq_quantmap__16u1__p8_0,
  129021. 11,
  129022. 11
  129023. };
  129024. static static_codebook _16u1__p8_0 = {
  129025. 2, 121,
  129026. _vq_lengthlist__16u1__p8_0,
  129027. 1, -524582912, 1618345984, 4, 0,
  129028. _vq_quantlist__16u1__p8_0,
  129029. NULL,
  129030. &_vq_auxt__16u1__p8_0,
  129031. NULL,
  129032. 0
  129033. };
  129034. static long _vq_quantlist__16u1__p8_1[] = {
  129035. 5,
  129036. 4,
  129037. 6,
  129038. 3,
  129039. 7,
  129040. 2,
  129041. 8,
  129042. 1,
  129043. 9,
  129044. 0,
  129045. 10,
  129046. };
  129047. static long _vq_lengthlist__16u1__p8_1[] = {
  129048. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129049. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129050. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129051. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129052. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129053. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129054. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129055. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129056. };
  129057. static float _vq_quantthresh__16u1__p8_1[] = {
  129058. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129059. 3.5, 4.5,
  129060. };
  129061. static long _vq_quantmap__16u1__p8_1[] = {
  129062. 9, 7, 5, 3, 1, 0, 2, 4,
  129063. 6, 8, 10,
  129064. };
  129065. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129066. _vq_quantthresh__16u1__p8_1,
  129067. _vq_quantmap__16u1__p8_1,
  129068. 11,
  129069. 11
  129070. };
  129071. static static_codebook _16u1__p8_1 = {
  129072. 2, 121,
  129073. _vq_lengthlist__16u1__p8_1,
  129074. 1, -531365888, 1611661312, 4, 0,
  129075. _vq_quantlist__16u1__p8_1,
  129076. NULL,
  129077. &_vq_auxt__16u1__p8_1,
  129078. NULL,
  129079. 0
  129080. };
  129081. static long _vq_quantlist__16u1__p9_0[] = {
  129082. 7,
  129083. 6,
  129084. 8,
  129085. 5,
  129086. 9,
  129087. 4,
  129088. 10,
  129089. 3,
  129090. 11,
  129091. 2,
  129092. 12,
  129093. 1,
  129094. 13,
  129095. 0,
  129096. 14,
  129097. };
  129098. static long _vq_lengthlist__16u1__p9_0[] = {
  129099. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129100. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129101. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129102. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129103. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129104. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129105. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129106. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129107. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129108. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129109. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129110. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129111. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129112. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129113. 8,
  129114. };
  129115. static float _vq_quantthresh__16u1__p9_0[] = {
  129116. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129117. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129118. };
  129119. static long _vq_quantmap__16u1__p9_0[] = {
  129120. 13, 11, 9, 7, 5, 3, 1, 0,
  129121. 2, 4, 6, 8, 10, 12, 14,
  129122. };
  129123. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129124. _vq_quantthresh__16u1__p9_0,
  129125. _vq_quantmap__16u1__p9_0,
  129126. 15,
  129127. 15
  129128. };
  129129. static static_codebook _16u1__p9_0 = {
  129130. 2, 225,
  129131. _vq_lengthlist__16u1__p9_0,
  129132. 1, -514071552, 1627381760, 4, 0,
  129133. _vq_quantlist__16u1__p9_0,
  129134. NULL,
  129135. &_vq_auxt__16u1__p9_0,
  129136. NULL,
  129137. 0
  129138. };
  129139. static long _vq_quantlist__16u1__p9_1[] = {
  129140. 7,
  129141. 6,
  129142. 8,
  129143. 5,
  129144. 9,
  129145. 4,
  129146. 10,
  129147. 3,
  129148. 11,
  129149. 2,
  129150. 12,
  129151. 1,
  129152. 13,
  129153. 0,
  129154. 14,
  129155. };
  129156. static long _vq_lengthlist__16u1__p9_1[] = {
  129157. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129158. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129159. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129160. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129161. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129162. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129163. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129164. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129165. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129166. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129167. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129168. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129169. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129170. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129171. 9,
  129172. };
  129173. static float _vq_quantthresh__16u1__p9_1[] = {
  129174. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129175. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129176. };
  129177. static long _vq_quantmap__16u1__p9_1[] = {
  129178. 13, 11, 9, 7, 5, 3, 1, 0,
  129179. 2, 4, 6, 8, 10, 12, 14,
  129180. };
  129181. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129182. _vq_quantthresh__16u1__p9_1,
  129183. _vq_quantmap__16u1__p9_1,
  129184. 15,
  129185. 15
  129186. };
  129187. static static_codebook _16u1__p9_1 = {
  129188. 2, 225,
  129189. _vq_lengthlist__16u1__p9_1,
  129190. 1, -522338304, 1620115456, 4, 0,
  129191. _vq_quantlist__16u1__p9_1,
  129192. NULL,
  129193. &_vq_auxt__16u1__p9_1,
  129194. NULL,
  129195. 0
  129196. };
  129197. static long _vq_quantlist__16u1__p9_2[] = {
  129198. 8,
  129199. 7,
  129200. 9,
  129201. 6,
  129202. 10,
  129203. 5,
  129204. 11,
  129205. 4,
  129206. 12,
  129207. 3,
  129208. 13,
  129209. 2,
  129210. 14,
  129211. 1,
  129212. 15,
  129213. 0,
  129214. 16,
  129215. };
  129216. static long _vq_lengthlist__16u1__p9_2[] = {
  129217. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129218. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129219. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129220. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129221. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129222. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129223. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129224. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129225. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129226. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129227. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129228. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129229. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129230. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129231. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129232. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129233. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129234. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129235. 10,
  129236. };
  129237. static float _vq_quantthresh__16u1__p9_2[] = {
  129238. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129239. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129240. };
  129241. static long _vq_quantmap__16u1__p9_2[] = {
  129242. 15, 13, 11, 9, 7, 5, 3, 1,
  129243. 0, 2, 4, 6, 8, 10, 12, 14,
  129244. 16,
  129245. };
  129246. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129247. _vq_quantthresh__16u1__p9_2,
  129248. _vq_quantmap__16u1__p9_2,
  129249. 17,
  129250. 17
  129251. };
  129252. static static_codebook _16u1__p9_2 = {
  129253. 2, 289,
  129254. _vq_lengthlist__16u1__p9_2,
  129255. 1, -529530880, 1611661312, 5, 0,
  129256. _vq_quantlist__16u1__p9_2,
  129257. NULL,
  129258. &_vq_auxt__16u1__p9_2,
  129259. NULL,
  129260. 0
  129261. };
  129262. static long _huff_lengthlist__16u1__short[] = {
  129263. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129264. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129265. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129266. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129267. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129268. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129269. 16,16,16,16,
  129270. };
  129271. static static_codebook _huff_book__16u1__short = {
  129272. 2, 100,
  129273. _huff_lengthlist__16u1__short,
  129274. 0, 0, 0, 0, 0,
  129275. NULL,
  129276. NULL,
  129277. NULL,
  129278. NULL,
  129279. 0
  129280. };
  129281. static long _huff_lengthlist__16u2__long[] = {
  129282. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129283. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129284. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129285. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129286. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129287. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129288. 13,14,18,18,
  129289. };
  129290. static static_codebook _huff_book__16u2__long = {
  129291. 2, 100,
  129292. _huff_lengthlist__16u2__long,
  129293. 0, 0, 0, 0, 0,
  129294. NULL,
  129295. NULL,
  129296. NULL,
  129297. NULL,
  129298. 0
  129299. };
  129300. static long _huff_lengthlist__16u2__short[] = {
  129301. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129302. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129303. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129304. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129305. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129306. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129307. 16,16,16,16,
  129308. };
  129309. static static_codebook _huff_book__16u2__short = {
  129310. 2, 100,
  129311. _huff_lengthlist__16u2__short,
  129312. 0, 0, 0, 0, 0,
  129313. NULL,
  129314. NULL,
  129315. NULL,
  129316. NULL,
  129317. 0
  129318. };
  129319. static long _vq_quantlist__16u2_p1_0[] = {
  129320. 1,
  129321. 0,
  129322. 2,
  129323. };
  129324. static long _vq_lengthlist__16u2_p1_0[] = {
  129325. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129326. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129327. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129328. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129329. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129330. 10,
  129331. };
  129332. static float _vq_quantthresh__16u2_p1_0[] = {
  129333. -0.5, 0.5,
  129334. };
  129335. static long _vq_quantmap__16u2_p1_0[] = {
  129336. 1, 0, 2,
  129337. };
  129338. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129339. _vq_quantthresh__16u2_p1_0,
  129340. _vq_quantmap__16u2_p1_0,
  129341. 3,
  129342. 3
  129343. };
  129344. static static_codebook _16u2_p1_0 = {
  129345. 4, 81,
  129346. _vq_lengthlist__16u2_p1_0,
  129347. 1, -535822336, 1611661312, 2, 0,
  129348. _vq_quantlist__16u2_p1_0,
  129349. NULL,
  129350. &_vq_auxt__16u2_p1_0,
  129351. NULL,
  129352. 0
  129353. };
  129354. static long _vq_quantlist__16u2_p2_0[] = {
  129355. 2,
  129356. 1,
  129357. 3,
  129358. 0,
  129359. 4,
  129360. };
  129361. static long _vq_lengthlist__16u2_p2_0[] = {
  129362. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129363. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129364. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129365. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129366. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129367. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129368. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129369. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129370. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129371. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129372. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129373. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129374. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129375. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129376. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129377. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129378. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129379. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129380. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129381. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129382. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129383. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129384. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129385. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129386. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129387. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129388. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129389. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129390. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129391. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129392. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129393. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129394. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129395. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129396. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129397. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129398. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129399. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129400. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129401. 13,
  129402. };
  129403. static float _vq_quantthresh__16u2_p2_0[] = {
  129404. -1.5, -0.5, 0.5, 1.5,
  129405. };
  129406. static long _vq_quantmap__16u2_p2_0[] = {
  129407. 3, 1, 0, 2, 4,
  129408. };
  129409. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129410. _vq_quantthresh__16u2_p2_0,
  129411. _vq_quantmap__16u2_p2_0,
  129412. 5,
  129413. 5
  129414. };
  129415. static static_codebook _16u2_p2_0 = {
  129416. 4, 625,
  129417. _vq_lengthlist__16u2_p2_0,
  129418. 1, -533725184, 1611661312, 3, 0,
  129419. _vq_quantlist__16u2_p2_0,
  129420. NULL,
  129421. &_vq_auxt__16u2_p2_0,
  129422. NULL,
  129423. 0
  129424. };
  129425. static long _vq_quantlist__16u2_p3_0[] = {
  129426. 4,
  129427. 3,
  129428. 5,
  129429. 2,
  129430. 6,
  129431. 1,
  129432. 7,
  129433. 0,
  129434. 8,
  129435. };
  129436. static long _vq_lengthlist__16u2_p3_0[] = {
  129437. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129438. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129439. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129440. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129441. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129442. 11,
  129443. };
  129444. static float _vq_quantthresh__16u2_p3_0[] = {
  129445. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129446. };
  129447. static long _vq_quantmap__16u2_p3_0[] = {
  129448. 7, 5, 3, 1, 0, 2, 4, 6,
  129449. 8,
  129450. };
  129451. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129452. _vq_quantthresh__16u2_p3_0,
  129453. _vq_quantmap__16u2_p3_0,
  129454. 9,
  129455. 9
  129456. };
  129457. static static_codebook _16u2_p3_0 = {
  129458. 2, 81,
  129459. _vq_lengthlist__16u2_p3_0,
  129460. 1, -531628032, 1611661312, 4, 0,
  129461. _vq_quantlist__16u2_p3_0,
  129462. NULL,
  129463. &_vq_auxt__16u2_p3_0,
  129464. NULL,
  129465. 0
  129466. };
  129467. static long _vq_quantlist__16u2_p4_0[] = {
  129468. 8,
  129469. 7,
  129470. 9,
  129471. 6,
  129472. 10,
  129473. 5,
  129474. 11,
  129475. 4,
  129476. 12,
  129477. 3,
  129478. 13,
  129479. 2,
  129480. 14,
  129481. 1,
  129482. 15,
  129483. 0,
  129484. 16,
  129485. };
  129486. static long _vq_lengthlist__16u2_p4_0[] = {
  129487. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129488. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129489. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129490. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129491. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129492. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129493. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129494. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129495. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129496. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129497. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129498. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129499. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129500. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129501. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129502. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129503. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129504. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129505. 14,
  129506. };
  129507. static float _vq_quantthresh__16u2_p4_0[] = {
  129508. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129509. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129510. };
  129511. static long _vq_quantmap__16u2_p4_0[] = {
  129512. 15, 13, 11, 9, 7, 5, 3, 1,
  129513. 0, 2, 4, 6, 8, 10, 12, 14,
  129514. 16,
  129515. };
  129516. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129517. _vq_quantthresh__16u2_p4_0,
  129518. _vq_quantmap__16u2_p4_0,
  129519. 17,
  129520. 17
  129521. };
  129522. static static_codebook _16u2_p4_0 = {
  129523. 2, 289,
  129524. _vq_lengthlist__16u2_p4_0,
  129525. 1, -529530880, 1611661312, 5, 0,
  129526. _vq_quantlist__16u2_p4_0,
  129527. NULL,
  129528. &_vq_auxt__16u2_p4_0,
  129529. NULL,
  129530. 0
  129531. };
  129532. static long _vq_quantlist__16u2_p5_0[] = {
  129533. 1,
  129534. 0,
  129535. 2,
  129536. };
  129537. static long _vq_lengthlist__16u2_p5_0[] = {
  129538. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129539. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129540. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129541. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129542. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129543. 10,
  129544. };
  129545. static float _vq_quantthresh__16u2_p5_0[] = {
  129546. -5.5, 5.5,
  129547. };
  129548. static long _vq_quantmap__16u2_p5_0[] = {
  129549. 1, 0, 2,
  129550. };
  129551. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129552. _vq_quantthresh__16u2_p5_0,
  129553. _vq_quantmap__16u2_p5_0,
  129554. 3,
  129555. 3
  129556. };
  129557. static static_codebook _16u2_p5_0 = {
  129558. 4, 81,
  129559. _vq_lengthlist__16u2_p5_0,
  129560. 1, -529137664, 1618345984, 2, 0,
  129561. _vq_quantlist__16u2_p5_0,
  129562. NULL,
  129563. &_vq_auxt__16u2_p5_0,
  129564. NULL,
  129565. 0
  129566. };
  129567. static long _vq_quantlist__16u2_p5_1[] = {
  129568. 5,
  129569. 4,
  129570. 6,
  129571. 3,
  129572. 7,
  129573. 2,
  129574. 8,
  129575. 1,
  129576. 9,
  129577. 0,
  129578. 10,
  129579. };
  129580. static long _vq_lengthlist__16u2_p5_1[] = {
  129581. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129582. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129583. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129584. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129585. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129586. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129587. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129588. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129589. };
  129590. static float _vq_quantthresh__16u2_p5_1[] = {
  129591. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129592. 3.5, 4.5,
  129593. };
  129594. static long _vq_quantmap__16u2_p5_1[] = {
  129595. 9, 7, 5, 3, 1, 0, 2, 4,
  129596. 6, 8, 10,
  129597. };
  129598. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129599. _vq_quantthresh__16u2_p5_1,
  129600. _vq_quantmap__16u2_p5_1,
  129601. 11,
  129602. 11
  129603. };
  129604. static static_codebook _16u2_p5_1 = {
  129605. 2, 121,
  129606. _vq_lengthlist__16u2_p5_1,
  129607. 1, -531365888, 1611661312, 4, 0,
  129608. _vq_quantlist__16u2_p5_1,
  129609. NULL,
  129610. &_vq_auxt__16u2_p5_1,
  129611. NULL,
  129612. 0
  129613. };
  129614. static long _vq_quantlist__16u2_p6_0[] = {
  129615. 6,
  129616. 5,
  129617. 7,
  129618. 4,
  129619. 8,
  129620. 3,
  129621. 9,
  129622. 2,
  129623. 10,
  129624. 1,
  129625. 11,
  129626. 0,
  129627. 12,
  129628. };
  129629. static long _vq_lengthlist__16u2_p6_0[] = {
  129630. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129631. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129632. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129633. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129634. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129635. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129636. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129637. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129638. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129639. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129640. 12,13,13,14,14,14,14,15,15,
  129641. };
  129642. static float _vq_quantthresh__16u2_p6_0[] = {
  129643. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129644. 12.5, 17.5, 22.5, 27.5,
  129645. };
  129646. static long _vq_quantmap__16u2_p6_0[] = {
  129647. 11, 9, 7, 5, 3, 1, 0, 2,
  129648. 4, 6, 8, 10, 12,
  129649. };
  129650. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129651. _vq_quantthresh__16u2_p6_0,
  129652. _vq_quantmap__16u2_p6_0,
  129653. 13,
  129654. 13
  129655. };
  129656. static static_codebook _16u2_p6_0 = {
  129657. 2, 169,
  129658. _vq_lengthlist__16u2_p6_0,
  129659. 1, -526516224, 1616117760, 4, 0,
  129660. _vq_quantlist__16u2_p6_0,
  129661. NULL,
  129662. &_vq_auxt__16u2_p6_0,
  129663. NULL,
  129664. 0
  129665. };
  129666. static long _vq_quantlist__16u2_p6_1[] = {
  129667. 2,
  129668. 1,
  129669. 3,
  129670. 0,
  129671. 4,
  129672. };
  129673. static long _vq_lengthlist__16u2_p6_1[] = {
  129674. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129675. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129676. };
  129677. static float _vq_quantthresh__16u2_p6_1[] = {
  129678. -1.5, -0.5, 0.5, 1.5,
  129679. };
  129680. static long _vq_quantmap__16u2_p6_1[] = {
  129681. 3, 1, 0, 2, 4,
  129682. };
  129683. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129684. _vq_quantthresh__16u2_p6_1,
  129685. _vq_quantmap__16u2_p6_1,
  129686. 5,
  129687. 5
  129688. };
  129689. static static_codebook _16u2_p6_1 = {
  129690. 2, 25,
  129691. _vq_lengthlist__16u2_p6_1,
  129692. 1, -533725184, 1611661312, 3, 0,
  129693. _vq_quantlist__16u2_p6_1,
  129694. NULL,
  129695. &_vq_auxt__16u2_p6_1,
  129696. NULL,
  129697. 0
  129698. };
  129699. static long _vq_quantlist__16u2_p7_0[] = {
  129700. 6,
  129701. 5,
  129702. 7,
  129703. 4,
  129704. 8,
  129705. 3,
  129706. 9,
  129707. 2,
  129708. 10,
  129709. 1,
  129710. 11,
  129711. 0,
  129712. 12,
  129713. };
  129714. static long _vq_lengthlist__16u2_p7_0[] = {
  129715. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  129716. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  129717. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  129718. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  129719. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  129720. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  129721. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  129722. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  129723. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  129724. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  129725. 12,13,13,13,14,14,14,15,14,
  129726. };
  129727. static float _vq_quantthresh__16u2_p7_0[] = {
  129728. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  129729. 27.5, 38.5, 49.5, 60.5,
  129730. };
  129731. static long _vq_quantmap__16u2_p7_0[] = {
  129732. 11, 9, 7, 5, 3, 1, 0, 2,
  129733. 4, 6, 8, 10, 12,
  129734. };
  129735. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  129736. _vq_quantthresh__16u2_p7_0,
  129737. _vq_quantmap__16u2_p7_0,
  129738. 13,
  129739. 13
  129740. };
  129741. static static_codebook _16u2_p7_0 = {
  129742. 2, 169,
  129743. _vq_lengthlist__16u2_p7_0,
  129744. 1, -523206656, 1618345984, 4, 0,
  129745. _vq_quantlist__16u2_p7_0,
  129746. NULL,
  129747. &_vq_auxt__16u2_p7_0,
  129748. NULL,
  129749. 0
  129750. };
  129751. static long _vq_quantlist__16u2_p7_1[] = {
  129752. 5,
  129753. 4,
  129754. 6,
  129755. 3,
  129756. 7,
  129757. 2,
  129758. 8,
  129759. 1,
  129760. 9,
  129761. 0,
  129762. 10,
  129763. };
  129764. static long _vq_lengthlist__16u2_p7_1[] = {
  129765. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  129766. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  129767. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  129768. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  129769. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  129770. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  129771. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  129772. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129773. };
  129774. static float _vq_quantthresh__16u2_p7_1[] = {
  129775. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129776. 3.5, 4.5,
  129777. };
  129778. static long _vq_quantmap__16u2_p7_1[] = {
  129779. 9, 7, 5, 3, 1, 0, 2, 4,
  129780. 6, 8, 10,
  129781. };
  129782. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  129783. _vq_quantthresh__16u2_p7_1,
  129784. _vq_quantmap__16u2_p7_1,
  129785. 11,
  129786. 11
  129787. };
  129788. static static_codebook _16u2_p7_1 = {
  129789. 2, 121,
  129790. _vq_lengthlist__16u2_p7_1,
  129791. 1, -531365888, 1611661312, 4, 0,
  129792. _vq_quantlist__16u2_p7_1,
  129793. NULL,
  129794. &_vq_auxt__16u2_p7_1,
  129795. NULL,
  129796. 0
  129797. };
  129798. static long _vq_quantlist__16u2_p8_0[] = {
  129799. 7,
  129800. 6,
  129801. 8,
  129802. 5,
  129803. 9,
  129804. 4,
  129805. 10,
  129806. 3,
  129807. 11,
  129808. 2,
  129809. 12,
  129810. 1,
  129811. 13,
  129812. 0,
  129813. 14,
  129814. };
  129815. static long _vq_lengthlist__16u2_p8_0[] = {
  129816. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  129817. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  129818. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  129819. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  129820. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  129821. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  129822. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  129823. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  129824. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  129825. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  129826. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  129827. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  129828. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  129829. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  129830. 14,
  129831. };
  129832. static float _vq_quantthresh__16u2_p8_0[] = {
  129833. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129834. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129835. };
  129836. static long _vq_quantmap__16u2_p8_0[] = {
  129837. 13, 11, 9, 7, 5, 3, 1, 0,
  129838. 2, 4, 6, 8, 10, 12, 14,
  129839. };
  129840. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  129841. _vq_quantthresh__16u2_p8_0,
  129842. _vq_quantmap__16u2_p8_0,
  129843. 15,
  129844. 15
  129845. };
  129846. static static_codebook _16u2_p8_0 = {
  129847. 2, 225,
  129848. _vq_lengthlist__16u2_p8_0,
  129849. 1, -520986624, 1620377600, 4, 0,
  129850. _vq_quantlist__16u2_p8_0,
  129851. NULL,
  129852. &_vq_auxt__16u2_p8_0,
  129853. NULL,
  129854. 0
  129855. };
  129856. static long _vq_quantlist__16u2_p8_1[] = {
  129857. 10,
  129858. 9,
  129859. 11,
  129860. 8,
  129861. 12,
  129862. 7,
  129863. 13,
  129864. 6,
  129865. 14,
  129866. 5,
  129867. 15,
  129868. 4,
  129869. 16,
  129870. 3,
  129871. 17,
  129872. 2,
  129873. 18,
  129874. 1,
  129875. 19,
  129876. 0,
  129877. 20,
  129878. };
  129879. static long _vq_lengthlist__16u2_p8_1[] = {
  129880. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  129881. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  129882. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  129883. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  129884. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  129885. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  129886. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  129887. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  129888. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  129889. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  129890. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  129891. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  129892. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  129893. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  129894. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  129895. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  129896. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  129897. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  129898. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  129899. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  129900. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  129901. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  129902. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  129903. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  129904. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  129905. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  129906. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  129907. 11,11,10,11,11,11,10,11,11,
  129908. };
  129909. static float _vq_quantthresh__16u2_p8_1[] = {
  129910. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129911. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129912. 6.5, 7.5, 8.5, 9.5,
  129913. };
  129914. static long _vq_quantmap__16u2_p8_1[] = {
  129915. 19, 17, 15, 13, 11, 9, 7, 5,
  129916. 3, 1, 0, 2, 4, 6, 8, 10,
  129917. 12, 14, 16, 18, 20,
  129918. };
  129919. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  129920. _vq_quantthresh__16u2_p8_1,
  129921. _vq_quantmap__16u2_p8_1,
  129922. 21,
  129923. 21
  129924. };
  129925. static static_codebook _16u2_p8_1 = {
  129926. 2, 441,
  129927. _vq_lengthlist__16u2_p8_1,
  129928. 1, -529268736, 1611661312, 5, 0,
  129929. _vq_quantlist__16u2_p8_1,
  129930. NULL,
  129931. &_vq_auxt__16u2_p8_1,
  129932. NULL,
  129933. 0
  129934. };
  129935. static long _vq_quantlist__16u2_p9_0[] = {
  129936. 5586,
  129937. 4655,
  129938. 6517,
  129939. 3724,
  129940. 7448,
  129941. 2793,
  129942. 8379,
  129943. 1862,
  129944. 9310,
  129945. 931,
  129946. 10241,
  129947. 0,
  129948. 11172,
  129949. 5521,
  129950. 5651,
  129951. };
  129952. static long _vq_lengthlist__16u2_p9_0[] = {
  129953. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  129954. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129955. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129956. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129957. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129958. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129959. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129960. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129961. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129962. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129963. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129964. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129965. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  129966. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  129967. 5,
  129968. };
  129969. static float _vq_quantthresh__16u2_p9_0[] = {
  129970. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  129971. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  129972. };
  129973. static long _vq_quantmap__16u2_p9_0[] = {
  129974. 11, 9, 7, 5, 3, 1, 13, 0,
  129975. 14, 2, 4, 6, 8, 10, 12,
  129976. };
  129977. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  129978. _vq_quantthresh__16u2_p9_0,
  129979. _vq_quantmap__16u2_p9_0,
  129980. 15,
  129981. 15
  129982. };
  129983. static static_codebook _16u2_p9_0 = {
  129984. 2, 225,
  129985. _vq_lengthlist__16u2_p9_0,
  129986. 1, -510275072, 1611661312, 14, 0,
  129987. _vq_quantlist__16u2_p9_0,
  129988. NULL,
  129989. &_vq_auxt__16u2_p9_0,
  129990. NULL,
  129991. 0
  129992. };
  129993. static long _vq_quantlist__16u2_p9_1[] = {
  129994. 392,
  129995. 343,
  129996. 441,
  129997. 294,
  129998. 490,
  129999. 245,
  130000. 539,
  130001. 196,
  130002. 588,
  130003. 147,
  130004. 637,
  130005. 98,
  130006. 686,
  130007. 49,
  130008. 735,
  130009. 0,
  130010. 784,
  130011. 388,
  130012. 396,
  130013. };
  130014. static long _vq_lengthlist__16u2_p9_1[] = {
  130015. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130016. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130017. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130018. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130019. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130020. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130021. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130022. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130023. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130024. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130025. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130026. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130027. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130028. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130029. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130030. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130031. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130032. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130033. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130034. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130035. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130036. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130037. 11,11,11,11,11,11,11, 5, 4,
  130038. };
  130039. static float _vq_quantthresh__16u2_p9_1[] = {
  130040. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130041. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130042. 318.5, 367.5,
  130043. };
  130044. static long _vq_quantmap__16u2_p9_1[] = {
  130045. 15, 13, 11, 9, 7, 5, 3, 1,
  130046. 17, 0, 18, 2, 4, 6, 8, 10,
  130047. 12, 14, 16,
  130048. };
  130049. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130050. _vq_quantthresh__16u2_p9_1,
  130051. _vq_quantmap__16u2_p9_1,
  130052. 19,
  130053. 19
  130054. };
  130055. static static_codebook _16u2_p9_1 = {
  130056. 2, 361,
  130057. _vq_lengthlist__16u2_p9_1,
  130058. 1, -518488064, 1611661312, 10, 0,
  130059. _vq_quantlist__16u2_p9_1,
  130060. NULL,
  130061. &_vq_auxt__16u2_p9_1,
  130062. NULL,
  130063. 0
  130064. };
  130065. static long _vq_quantlist__16u2_p9_2[] = {
  130066. 24,
  130067. 23,
  130068. 25,
  130069. 22,
  130070. 26,
  130071. 21,
  130072. 27,
  130073. 20,
  130074. 28,
  130075. 19,
  130076. 29,
  130077. 18,
  130078. 30,
  130079. 17,
  130080. 31,
  130081. 16,
  130082. 32,
  130083. 15,
  130084. 33,
  130085. 14,
  130086. 34,
  130087. 13,
  130088. 35,
  130089. 12,
  130090. 36,
  130091. 11,
  130092. 37,
  130093. 10,
  130094. 38,
  130095. 9,
  130096. 39,
  130097. 8,
  130098. 40,
  130099. 7,
  130100. 41,
  130101. 6,
  130102. 42,
  130103. 5,
  130104. 43,
  130105. 4,
  130106. 44,
  130107. 3,
  130108. 45,
  130109. 2,
  130110. 46,
  130111. 1,
  130112. 47,
  130113. 0,
  130114. 48,
  130115. };
  130116. static long _vq_lengthlist__16u2_p9_2[] = {
  130117. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130118. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130119. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130120. 11,
  130121. };
  130122. static float _vq_quantthresh__16u2_p9_2[] = {
  130123. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130124. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130125. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130126. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130127. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130128. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130129. };
  130130. static long _vq_quantmap__16u2_p9_2[] = {
  130131. 47, 45, 43, 41, 39, 37, 35, 33,
  130132. 31, 29, 27, 25, 23, 21, 19, 17,
  130133. 15, 13, 11, 9, 7, 5, 3, 1,
  130134. 0, 2, 4, 6, 8, 10, 12, 14,
  130135. 16, 18, 20, 22, 24, 26, 28, 30,
  130136. 32, 34, 36, 38, 40, 42, 44, 46,
  130137. 48,
  130138. };
  130139. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130140. _vq_quantthresh__16u2_p9_2,
  130141. _vq_quantmap__16u2_p9_2,
  130142. 49,
  130143. 49
  130144. };
  130145. static static_codebook _16u2_p9_2 = {
  130146. 1, 49,
  130147. _vq_lengthlist__16u2_p9_2,
  130148. 1, -526909440, 1611661312, 6, 0,
  130149. _vq_quantlist__16u2_p9_2,
  130150. NULL,
  130151. &_vq_auxt__16u2_p9_2,
  130152. NULL,
  130153. 0
  130154. };
  130155. static long _vq_quantlist__8u0__p1_0[] = {
  130156. 1,
  130157. 0,
  130158. 2,
  130159. };
  130160. static long _vq_lengthlist__8u0__p1_0[] = {
  130161. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130162. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130163. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130164. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130165. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130166. 11,
  130167. };
  130168. static float _vq_quantthresh__8u0__p1_0[] = {
  130169. -0.5, 0.5,
  130170. };
  130171. static long _vq_quantmap__8u0__p1_0[] = {
  130172. 1, 0, 2,
  130173. };
  130174. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130175. _vq_quantthresh__8u0__p1_0,
  130176. _vq_quantmap__8u0__p1_0,
  130177. 3,
  130178. 3
  130179. };
  130180. static static_codebook _8u0__p1_0 = {
  130181. 4, 81,
  130182. _vq_lengthlist__8u0__p1_0,
  130183. 1, -535822336, 1611661312, 2, 0,
  130184. _vq_quantlist__8u0__p1_0,
  130185. NULL,
  130186. &_vq_auxt__8u0__p1_0,
  130187. NULL,
  130188. 0
  130189. };
  130190. static long _vq_quantlist__8u0__p2_0[] = {
  130191. 1,
  130192. 0,
  130193. 2,
  130194. };
  130195. static long _vq_lengthlist__8u0__p2_0[] = {
  130196. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130197. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130198. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130199. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130200. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130201. 8,
  130202. };
  130203. static float _vq_quantthresh__8u0__p2_0[] = {
  130204. -0.5, 0.5,
  130205. };
  130206. static long _vq_quantmap__8u0__p2_0[] = {
  130207. 1, 0, 2,
  130208. };
  130209. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130210. _vq_quantthresh__8u0__p2_0,
  130211. _vq_quantmap__8u0__p2_0,
  130212. 3,
  130213. 3
  130214. };
  130215. static static_codebook _8u0__p2_0 = {
  130216. 4, 81,
  130217. _vq_lengthlist__8u0__p2_0,
  130218. 1, -535822336, 1611661312, 2, 0,
  130219. _vq_quantlist__8u0__p2_0,
  130220. NULL,
  130221. &_vq_auxt__8u0__p2_0,
  130222. NULL,
  130223. 0
  130224. };
  130225. static long _vq_quantlist__8u0__p3_0[] = {
  130226. 2,
  130227. 1,
  130228. 3,
  130229. 0,
  130230. 4,
  130231. };
  130232. static long _vq_lengthlist__8u0__p3_0[] = {
  130233. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130234. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130235. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130236. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130237. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130238. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130239. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130240. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130241. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130242. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130243. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130244. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130245. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130246. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130247. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130248. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130249. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130250. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130251. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130252. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130253. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130254. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130255. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130256. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130257. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130258. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130259. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130260. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130261. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130262. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130263. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130264. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130265. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130266. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130267. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130268. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130269. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130270. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130271. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130272. 16,
  130273. };
  130274. static float _vq_quantthresh__8u0__p3_0[] = {
  130275. -1.5, -0.5, 0.5, 1.5,
  130276. };
  130277. static long _vq_quantmap__8u0__p3_0[] = {
  130278. 3, 1, 0, 2, 4,
  130279. };
  130280. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130281. _vq_quantthresh__8u0__p3_0,
  130282. _vq_quantmap__8u0__p3_0,
  130283. 5,
  130284. 5
  130285. };
  130286. static static_codebook _8u0__p3_0 = {
  130287. 4, 625,
  130288. _vq_lengthlist__8u0__p3_0,
  130289. 1, -533725184, 1611661312, 3, 0,
  130290. _vq_quantlist__8u0__p3_0,
  130291. NULL,
  130292. &_vq_auxt__8u0__p3_0,
  130293. NULL,
  130294. 0
  130295. };
  130296. static long _vq_quantlist__8u0__p4_0[] = {
  130297. 2,
  130298. 1,
  130299. 3,
  130300. 0,
  130301. 4,
  130302. };
  130303. static long _vq_lengthlist__8u0__p4_0[] = {
  130304. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130305. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130306. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130307. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130308. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130309. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130310. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130311. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130312. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130313. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130314. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130315. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130316. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130317. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130318. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130319. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130320. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130321. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130322. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130323. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130324. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130325. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130326. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130327. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130328. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130329. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130330. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130331. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130332. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130333. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130334. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130335. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130336. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130337. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130338. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130339. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130340. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130341. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130342. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130343. 12,
  130344. };
  130345. static float _vq_quantthresh__8u0__p4_0[] = {
  130346. -1.5, -0.5, 0.5, 1.5,
  130347. };
  130348. static long _vq_quantmap__8u0__p4_0[] = {
  130349. 3, 1, 0, 2, 4,
  130350. };
  130351. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130352. _vq_quantthresh__8u0__p4_0,
  130353. _vq_quantmap__8u0__p4_0,
  130354. 5,
  130355. 5
  130356. };
  130357. static static_codebook _8u0__p4_0 = {
  130358. 4, 625,
  130359. _vq_lengthlist__8u0__p4_0,
  130360. 1, -533725184, 1611661312, 3, 0,
  130361. _vq_quantlist__8u0__p4_0,
  130362. NULL,
  130363. &_vq_auxt__8u0__p4_0,
  130364. NULL,
  130365. 0
  130366. };
  130367. static long _vq_quantlist__8u0__p5_0[] = {
  130368. 4,
  130369. 3,
  130370. 5,
  130371. 2,
  130372. 6,
  130373. 1,
  130374. 7,
  130375. 0,
  130376. 8,
  130377. };
  130378. static long _vq_lengthlist__8u0__p5_0[] = {
  130379. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130380. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130381. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130382. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130383. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130384. 12,
  130385. };
  130386. static float _vq_quantthresh__8u0__p5_0[] = {
  130387. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130388. };
  130389. static long _vq_quantmap__8u0__p5_0[] = {
  130390. 7, 5, 3, 1, 0, 2, 4, 6,
  130391. 8,
  130392. };
  130393. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130394. _vq_quantthresh__8u0__p5_0,
  130395. _vq_quantmap__8u0__p5_0,
  130396. 9,
  130397. 9
  130398. };
  130399. static static_codebook _8u0__p5_0 = {
  130400. 2, 81,
  130401. _vq_lengthlist__8u0__p5_0,
  130402. 1, -531628032, 1611661312, 4, 0,
  130403. _vq_quantlist__8u0__p5_0,
  130404. NULL,
  130405. &_vq_auxt__8u0__p5_0,
  130406. NULL,
  130407. 0
  130408. };
  130409. static long _vq_quantlist__8u0__p6_0[] = {
  130410. 6,
  130411. 5,
  130412. 7,
  130413. 4,
  130414. 8,
  130415. 3,
  130416. 9,
  130417. 2,
  130418. 10,
  130419. 1,
  130420. 11,
  130421. 0,
  130422. 12,
  130423. };
  130424. static long _vq_lengthlist__8u0__p6_0[] = {
  130425. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130426. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130427. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130428. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130429. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130430. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130431. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130432. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130433. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130434. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130435. 16, 0,15, 0,17, 0, 0, 0, 0,
  130436. };
  130437. static float _vq_quantthresh__8u0__p6_0[] = {
  130438. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130439. 12.5, 17.5, 22.5, 27.5,
  130440. };
  130441. static long _vq_quantmap__8u0__p6_0[] = {
  130442. 11, 9, 7, 5, 3, 1, 0, 2,
  130443. 4, 6, 8, 10, 12,
  130444. };
  130445. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130446. _vq_quantthresh__8u0__p6_0,
  130447. _vq_quantmap__8u0__p6_0,
  130448. 13,
  130449. 13
  130450. };
  130451. static static_codebook _8u0__p6_0 = {
  130452. 2, 169,
  130453. _vq_lengthlist__8u0__p6_0,
  130454. 1, -526516224, 1616117760, 4, 0,
  130455. _vq_quantlist__8u0__p6_0,
  130456. NULL,
  130457. &_vq_auxt__8u0__p6_0,
  130458. NULL,
  130459. 0
  130460. };
  130461. static long _vq_quantlist__8u0__p6_1[] = {
  130462. 2,
  130463. 1,
  130464. 3,
  130465. 0,
  130466. 4,
  130467. };
  130468. static long _vq_lengthlist__8u0__p6_1[] = {
  130469. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130470. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130471. };
  130472. static float _vq_quantthresh__8u0__p6_1[] = {
  130473. -1.5, -0.5, 0.5, 1.5,
  130474. };
  130475. static long _vq_quantmap__8u0__p6_1[] = {
  130476. 3, 1, 0, 2, 4,
  130477. };
  130478. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130479. _vq_quantthresh__8u0__p6_1,
  130480. _vq_quantmap__8u0__p6_1,
  130481. 5,
  130482. 5
  130483. };
  130484. static static_codebook _8u0__p6_1 = {
  130485. 2, 25,
  130486. _vq_lengthlist__8u0__p6_1,
  130487. 1, -533725184, 1611661312, 3, 0,
  130488. _vq_quantlist__8u0__p6_1,
  130489. NULL,
  130490. &_vq_auxt__8u0__p6_1,
  130491. NULL,
  130492. 0
  130493. };
  130494. static long _vq_quantlist__8u0__p7_0[] = {
  130495. 1,
  130496. 0,
  130497. 2,
  130498. };
  130499. static long _vq_lengthlist__8u0__p7_0[] = {
  130500. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130501. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130502. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130503. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130504. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130505. 7,
  130506. };
  130507. static float _vq_quantthresh__8u0__p7_0[] = {
  130508. -157.5, 157.5,
  130509. };
  130510. static long _vq_quantmap__8u0__p7_0[] = {
  130511. 1, 0, 2,
  130512. };
  130513. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130514. _vq_quantthresh__8u0__p7_0,
  130515. _vq_quantmap__8u0__p7_0,
  130516. 3,
  130517. 3
  130518. };
  130519. static static_codebook _8u0__p7_0 = {
  130520. 4, 81,
  130521. _vq_lengthlist__8u0__p7_0,
  130522. 1, -518803456, 1628680192, 2, 0,
  130523. _vq_quantlist__8u0__p7_0,
  130524. NULL,
  130525. &_vq_auxt__8u0__p7_0,
  130526. NULL,
  130527. 0
  130528. };
  130529. static long _vq_quantlist__8u0__p7_1[] = {
  130530. 7,
  130531. 6,
  130532. 8,
  130533. 5,
  130534. 9,
  130535. 4,
  130536. 10,
  130537. 3,
  130538. 11,
  130539. 2,
  130540. 12,
  130541. 1,
  130542. 13,
  130543. 0,
  130544. 14,
  130545. };
  130546. static long _vq_lengthlist__8u0__p7_1[] = {
  130547. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130548. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130549. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130550. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130551. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130552. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130553. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130554. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130555. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130556. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130557. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130558. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130559. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130560. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130561. 10,
  130562. };
  130563. static float _vq_quantthresh__8u0__p7_1[] = {
  130564. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130565. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130566. };
  130567. static long _vq_quantmap__8u0__p7_1[] = {
  130568. 13, 11, 9, 7, 5, 3, 1, 0,
  130569. 2, 4, 6, 8, 10, 12, 14,
  130570. };
  130571. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130572. _vq_quantthresh__8u0__p7_1,
  130573. _vq_quantmap__8u0__p7_1,
  130574. 15,
  130575. 15
  130576. };
  130577. static static_codebook _8u0__p7_1 = {
  130578. 2, 225,
  130579. _vq_lengthlist__8u0__p7_1,
  130580. 1, -520986624, 1620377600, 4, 0,
  130581. _vq_quantlist__8u0__p7_1,
  130582. NULL,
  130583. &_vq_auxt__8u0__p7_1,
  130584. NULL,
  130585. 0
  130586. };
  130587. static long _vq_quantlist__8u0__p7_2[] = {
  130588. 10,
  130589. 9,
  130590. 11,
  130591. 8,
  130592. 12,
  130593. 7,
  130594. 13,
  130595. 6,
  130596. 14,
  130597. 5,
  130598. 15,
  130599. 4,
  130600. 16,
  130601. 3,
  130602. 17,
  130603. 2,
  130604. 18,
  130605. 1,
  130606. 19,
  130607. 0,
  130608. 20,
  130609. };
  130610. static long _vq_lengthlist__8u0__p7_2[] = {
  130611. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130612. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130613. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130614. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130615. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130616. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130617. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130618. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130619. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130620. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130621. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130622. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130623. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130624. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130625. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130626. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130627. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130628. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130629. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130630. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130631. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130632. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130633. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130634. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130635. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130636. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130637. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130638. 11,12,11,11,11,10,10,11,11,
  130639. };
  130640. static float _vq_quantthresh__8u0__p7_2[] = {
  130641. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130642. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130643. 6.5, 7.5, 8.5, 9.5,
  130644. };
  130645. static long _vq_quantmap__8u0__p7_2[] = {
  130646. 19, 17, 15, 13, 11, 9, 7, 5,
  130647. 3, 1, 0, 2, 4, 6, 8, 10,
  130648. 12, 14, 16, 18, 20,
  130649. };
  130650. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130651. _vq_quantthresh__8u0__p7_2,
  130652. _vq_quantmap__8u0__p7_2,
  130653. 21,
  130654. 21
  130655. };
  130656. static static_codebook _8u0__p7_2 = {
  130657. 2, 441,
  130658. _vq_lengthlist__8u0__p7_2,
  130659. 1, -529268736, 1611661312, 5, 0,
  130660. _vq_quantlist__8u0__p7_2,
  130661. NULL,
  130662. &_vq_auxt__8u0__p7_2,
  130663. NULL,
  130664. 0
  130665. };
  130666. static long _huff_lengthlist__8u0__single[] = {
  130667. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130668. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130669. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130670. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130671. };
  130672. static static_codebook _huff_book__8u0__single = {
  130673. 2, 64,
  130674. _huff_lengthlist__8u0__single,
  130675. 0, 0, 0, 0, 0,
  130676. NULL,
  130677. NULL,
  130678. NULL,
  130679. NULL,
  130680. 0
  130681. };
  130682. static long _vq_quantlist__8u1__p1_0[] = {
  130683. 1,
  130684. 0,
  130685. 2,
  130686. };
  130687. static long _vq_lengthlist__8u1__p1_0[] = {
  130688. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130689. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130690. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130691. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130692. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  130693. 10,
  130694. };
  130695. static float _vq_quantthresh__8u1__p1_0[] = {
  130696. -0.5, 0.5,
  130697. };
  130698. static long _vq_quantmap__8u1__p1_0[] = {
  130699. 1, 0, 2,
  130700. };
  130701. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  130702. _vq_quantthresh__8u1__p1_0,
  130703. _vq_quantmap__8u1__p1_0,
  130704. 3,
  130705. 3
  130706. };
  130707. static static_codebook _8u1__p1_0 = {
  130708. 4, 81,
  130709. _vq_lengthlist__8u1__p1_0,
  130710. 1, -535822336, 1611661312, 2, 0,
  130711. _vq_quantlist__8u1__p1_0,
  130712. NULL,
  130713. &_vq_auxt__8u1__p1_0,
  130714. NULL,
  130715. 0
  130716. };
  130717. static long _vq_quantlist__8u1__p2_0[] = {
  130718. 1,
  130719. 0,
  130720. 2,
  130721. };
  130722. static long _vq_lengthlist__8u1__p2_0[] = {
  130723. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  130724. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  130725. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  130726. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  130727. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  130728. 7,
  130729. };
  130730. static float _vq_quantthresh__8u1__p2_0[] = {
  130731. -0.5, 0.5,
  130732. };
  130733. static long _vq_quantmap__8u1__p2_0[] = {
  130734. 1, 0, 2,
  130735. };
  130736. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  130737. _vq_quantthresh__8u1__p2_0,
  130738. _vq_quantmap__8u1__p2_0,
  130739. 3,
  130740. 3
  130741. };
  130742. static static_codebook _8u1__p2_0 = {
  130743. 4, 81,
  130744. _vq_lengthlist__8u1__p2_0,
  130745. 1, -535822336, 1611661312, 2, 0,
  130746. _vq_quantlist__8u1__p2_0,
  130747. NULL,
  130748. &_vq_auxt__8u1__p2_0,
  130749. NULL,
  130750. 0
  130751. };
  130752. static long _vq_quantlist__8u1__p3_0[] = {
  130753. 2,
  130754. 1,
  130755. 3,
  130756. 0,
  130757. 4,
  130758. };
  130759. static long _vq_lengthlist__8u1__p3_0[] = {
  130760. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130761. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130762. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  130763. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  130764. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  130765. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  130766. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  130767. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  130768. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  130769. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  130770. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  130771. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  130772. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  130773. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  130774. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  130775. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  130776. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  130777. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  130778. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  130779. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  130780. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  130781. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  130782. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  130783. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  130784. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  130785. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  130786. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  130787. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  130788. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  130789. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  130790. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  130791. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  130792. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  130793. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  130794. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  130795. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  130796. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  130797. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  130798. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  130799. 16,
  130800. };
  130801. static float _vq_quantthresh__8u1__p3_0[] = {
  130802. -1.5, -0.5, 0.5, 1.5,
  130803. };
  130804. static long _vq_quantmap__8u1__p3_0[] = {
  130805. 3, 1, 0, 2, 4,
  130806. };
  130807. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  130808. _vq_quantthresh__8u1__p3_0,
  130809. _vq_quantmap__8u1__p3_0,
  130810. 5,
  130811. 5
  130812. };
  130813. static static_codebook _8u1__p3_0 = {
  130814. 4, 625,
  130815. _vq_lengthlist__8u1__p3_0,
  130816. 1, -533725184, 1611661312, 3, 0,
  130817. _vq_quantlist__8u1__p3_0,
  130818. NULL,
  130819. &_vq_auxt__8u1__p3_0,
  130820. NULL,
  130821. 0
  130822. };
  130823. static long _vq_quantlist__8u1__p4_0[] = {
  130824. 2,
  130825. 1,
  130826. 3,
  130827. 0,
  130828. 4,
  130829. };
  130830. static long _vq_lengthlist__8u1__p4_0[] = {
  130831. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  130832. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  130833. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  130834. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  130835. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  130836. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  130837. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  130838. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  130839. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  130840. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  130841. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  130842. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  130843. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  130844. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  130845. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  130846. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  130847. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  130848. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  130849. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  130850. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  130851. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  130852. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  130853. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  130854. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  130855. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  130856. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  130857. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  130858. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  130859. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  130860. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  130861. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  130862. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  130863. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  130864. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  130865. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  130866. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  130867. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  130868. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  130869. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  130870. 10,
  130871. };
  130872. static float _vq_quantthresh__8u1__p4_0[] = {
  130873. -1.5, -0.5, 0.5, 1.5,
  130874. };
  130875. static long _vq_quantmap__8u1__p4_0[] = {
  130876. 3, 1, 0, 2, 4,
  130877. };
  130878. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  130879. _vq_quantthresh__8u1__p4_0,
  130880. _vq_quantmap__8u1__p4_0,
  130881. 5,
  130882. 5
  130883. };
  130884. static static_codebook _8u1__p4_0 = {
  130885. 4, 625,
  130886. _vq_lengthlist__8u1__p4_0,
  130887. 1, -533725184, 1611661312, 3, 0,
  130888. _vq_quantlist__8u1__p4_0,
  130889. NULL,
  130890. &_vq_auxt__8u1__p4_0,
  130891. NULL,
  130892. 0
  130893. };
  130894. static long _vq_quantlist__8u1__p5_0[] = {
  130895. 4,
  130896. 3,
  130897. 5,
  130898. 2,
  130899. 6,
  130900. 1,
  130901. 7,
  130902. 0,
  130903. 8,
  130904. };
  130905. static long _vq_lengthlist__8u1__p5_0[] = {
  130906. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  130907. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  130908. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  130909. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  130910. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  130911. 13,
  130912. };
  130913. static float _vq_quantthresh__8u1__p5_0[] = {
  130914. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130915. };
  130916. static long _vq_quantmap__8u1__p5_0[] = {
  130917. 7, 5, 3, 1, 0, 2, 4, 6,
  130918. 8,
  130919. };
  130920. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  130921. _vq_quantthresh__8u1__p5_0,
  130922. _vq_quantmap__8u1__p5_0,
  130923. 9,
  130924. 9
  130925. };
  130926. static static_codebook _8u1__p5_0 = {
  130927. 2, 81,
  130928. _vq_lengthlist__8u1__p5_0,
  130929. 1, -531628032, 1611661312, 4, 0,
  130930. _vq_quantlist__8u1__p5_0,
  130931. NULL,
  130932. &_vq_auxt__8u1__p5_0,
  130933. NULL,
  130934. 0
  130935. };
  130936. static long _vq_quantlist__8u1__p6_0[] = {
  130937. 4,
  130938. 3,
  130939. 5,
  130940. 2,
  130941. 6,
  130942. 1,
  130943. 7,
  130944. 0,
  130945. 8,
  130946. };
  130947. static long _vq_lengthlist__8u1__p6_0[] = {
  130948. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  130949. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  130950. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  130951. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  130952. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  130953. 10,
  130954. };
  130955. static float _vq_quantthresh__8u1__p6_0[] = {
  130956. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130957. };
  130958. static long _vq_quantmap__8u1__p6_0[] = {
  130959. 7, 5, 3, 1, 0, 2, 4, 6,
  130960. 8,
  130961. };
  130962. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  130963. _vq_quantthresh__8u1__p6_0,
  130964. _vq_quantmap__8u1__p6_0,
  130965. 9,
  130966. 9
  130967. };
  130968. static static_codebook _8u1__p6_0 = {
  130969. 2, 81,
  130970. _vq_lengthlist__8u1__p6_0,
  130971. 1, -531628032, 1611661312, 4, 0,
  130972. _vq_quantlist__8u1__p6_0,
  130973. NULL,
  130974. &_vq_auxt__8u1__p6_0,
  130975. NULL,
  130976. 0
  130977. };
  130978. static long _vq_quantlist__8u1__p7_0[] = {
  130979. 1,
  130980. 0,
  130981. 2,
  130982. };
  130983. static long _vq_lengthlist__8u1__p7_0[] = {
  130984. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  130985. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  130986. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  130987. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  130988. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  130989. 11,
  130990. };
  130991. static float _vq_quantthresh__8u1__p7_0[] = {
  130992. -5.5, 5.5,
  130993. };
  130994. static long _vq_quantmap__8u1__p7_0[] = {
  130995. 1, 0, 2,
  130996. };
  130997. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  130998. _vq_quantthresh__8u1__p7_0,
  130999. _vq_quantmap__8u1__p7_0,
  131000. 3,
  131001. 3
  131002. };
  131003. static static_codebook _8u1__p7_0 = {
  131004. 4, 81,
  131005. _vq_lengthlist__8u1__p7_0,
  131006. 1, -529137664, 1618345984, 2, 0,
  131007. _vq_quantlist__8u1__p7_0,
  131008. NULL,
  131009. &_vq_auxt__8u1__p7_0,
  131010. NULL,
  131011. 0
  131012. };
  131013. static long _vq_quantlist__8u1__p7_1[] = {
  131014. 5,
  131015. 4,
  131016. 6,
  131017. 3,
  131018. 7,
  131019. 2,
  131020. 8,
  131021. 1,
  131022. 9,
  131023. 0,
  131024. 10,
  131025. };
  131026. static long _vq_lengthlist__8u1__p7_1[] = {
  131027. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131028. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131029. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131030. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131031. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131032. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131033. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131034. 9, 9, 9, 9, 9,10,10,10,10,
  131035. };
  131036. static float _vq_quantthresh__8u1__p7_1[] = {
  131037. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131038. 3.5, 4.5,
  131039. };
  131040. static long _vq_quantmap__8u1__p7_1[] = {
  131041. 9, 7, 5, 3, 1, 0, 2, 4,
  131042. 6, 8, 10,
  131043. };
  131044. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131045. _vq_quantthresh__8u1__p7_1,
  131046. _vq_quantmap__8u1__p7_1,
  131047. 11,
  131048. 11
  131049. };
  131050. static static_codebook _8u1__p7_1 = {
  131051. 2, 121,
  131052. _vq_lengthlist__8u1__p7_1,
  131053. 1, -531365888, 1611661312, 4, 0,
  131054. _vq_quantlist__8u1__p7_1,
  131055. NULL,
  131056. &_vq_auxt__8u1__p7_1,
  131057. NULL,
  131058. 0
  131059. };
  131060. static long _vq_quantlist__8u1__p8_0[] = {
  131061. 5,
  131062. 4,
  131063. 6,
  131064. 3,
  131065. 7,
  131066. 2,
  131067. 8,
  131068. 1,
  131069. 9,
  131070. 0,
  131071. 10,
  131072. };
  131073. static long _vq_lengthlist__8u1__p8_0[] = {
  131074. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131075. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131076. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131077. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131078. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131079. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131080. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131081. 12,13,13,14,14,15,15,15,15,
  131082. };
  131083. static float _vq_quantthresh__8u1__p8_0[] = {
  131084. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131085. 38.5, 49.5,
  131086. };
  131087. static long _vq_quantmap__8u1__p8_0[] = {
  131088. 9, 7, 5, 3, 1, 0, 2, 4,
  131089. 6, 8, 10,
  131090. };
  131091. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131092. _vq_quantthresh__8u1__p8_0,
  131093. _vq_quantmap__8u1__p8_0,
  131094. 11,
  131095. 11
  131096. };
  131097. static static_codebook _8u1__p8_0 = {
  131098. 2, 121,
  131099. _vq_lengthlist__8u1__p8_0,
  131100. 1, -524582912, 1618345984, 4, 0,
  131101. _vq_quantlist__8u1__p8_0,
  131102. NULL,
  131103. &_vq_auxt__8u1__p8_0,
  131104. NULL,
  131105. 0
  131106. };
  131107. static long _vq_quantlist__8u1__p8_1[] = {
  131108. 5,
  131109. 4,
  131110. 6,
  131111. 3,
  131112. 7,
  131113. 2,
  131114. 8,
  131115. 1,
  131116. 9,
  131117. 0,
  131118. 10,
  131119. };
  131120. static long _vq_lengthlist__8u1__p8_1[] = {
  131121. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131122. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131123. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131124. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131125. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131126. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131127. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131128. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131129. };
  131130. static float _vq_quantthresh__8u1__p8_1[] = {
  131131. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131132. 3.5, 4.5,
  131133. };
  131134. static long _vq_quantmap__8u1__p8_1[] = {
  131135. 9, 7, 5, 3, 1, 0, 2, 4,
  131136. 6, 8, 10,
  131137. };
  131138. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131139. _vq_quantthresh__8u1__p8_1,
  131140. _vq_quantmap__8u1__p8_1,
  131141. 11,
  131142. 11
  131143. };
  131144. static static_codebook _8u1__p8_1 = {
  131145. 2, 121,
  131146. _vq_lengthlist__8u1__p8_1,
  131147. 1, -531365888, 1611661312, 4, 0,
  131148. _vq_quantlist__8u1__p8_1,
  131149. NULL,
  131150. &_vq_auxt__8u1__p8_1,
  131151. NULL,
  131152. 0
  131153. };
  131154. static long _vq_quantlist__8u1__p9_0[] = {
  131155. 7,
  131156. 6,
  131157. 8,
  131158. 5,
  131159. 9,
  131160. 4,
  131161. 10,
  131162. 3,
  131163. 11,
  131164. 2,
  131165. 12,
  131166. 1,
  131167. 13,
  131168. 0,
  131169. 14,
  131170. };
  131171. static long _vq_lengthlist__8u1__p9_0[] = {
  131172. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131173. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131174. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131175. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131176. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131177. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131178. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131179. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131180. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131181. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131182. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131183. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131184. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131185. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131186. 10,
  131187. };
  131188. static float _vq_quantthresh__8u1__p9_0[] = {
  131189. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131190. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131191. };
  131192. static long _vq_quantmap__8u1__p9_0[] = {
  131193. 13, 11, 9, 7, 5, 3, 1, 0,
  131194. 2, 4, 6, 8, 10, 12, 14,
  131195. };
  131196. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131197. _vq_quantthresh__8u1__p9_0,
  131198. _vq_quantmap__8u1__p9_0,
  131199. 15,
  131200. 15
  131201. };
  131202. static static_codebook _8u1__p9_0 = {
  131203. 2, 225,
  131204. _vq_lengthlist__8u1__p9_0,
  131205. 1, -514071552, 1627381760, 4, 0,
  131206. _vq_quantlist__8u1__p9_0,
  131207. NULL,
  131208. &_vq_auxt__8u1__p9_0,
  131209. NULL,
  131210. 0
  131211. };
  131212. static long _vq_quantlist__8u1__p9_1[] = {
  131213. 7,
  131214. 6,
  131215. 8,
  131216. 5,
  131217. 9,
  131218. 4,
  131219. 10,
  131220. 3,
  131221. 11,
  131222. 2,
  131223. 12,
  131224. 1,
  131225. 13,
  131226. 0,
  131227. 14,
  131228. };
  131229. static long _vq_lengthlist__8u1__p9_1[] = {
  131230. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131231. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131232. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131233. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131234. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131235. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131236. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131237. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131238. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131239. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131240. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131241. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131242. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131243. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131244. 13,
  131245. };
  131246. static float _vq_quantthresh__8u1__p9_1[] = {
  131247. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131248. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131249. };
  131250. static long _vq_quantmap__8u1__p9_1[] = {
  131251. 13, 11, 9, 7, 5, 3, 1, 0,
  131252. 2, 4, 6, 8, 10, 12, 14,
  131253. };
  131254. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131255. _vq_quantthresh__8u1__p9_1,
  131256. _vq_quantmap__8u1__p9_1,
  131257. 15,
  131258. 15
  131259. };
  131260. static static_codebook _8u1__p9_1 = {
  131261. 2, 225,
  131262. _vq_lengthlist__8u1__p9_1,
  131263. 1, -522338304, 1620115456, 4, 0,
  131264. _vq_quantlist__8u1__p9_1,
  131265. NULL,
  131266. &_vq_auxt__8u1__p9_1,
  131267. NULL,
  131268. 0
  131269. };
  131270. static long _vq_quantlist__8u1__p9_2[] = {
  131271. 8,
  131272. 7,
  131273. 9,
  131274. 6,
  131275. 10,
  131276. 5,
  131277. 11,
  131278. 4,
  131279. 12,
  131280. 3,
  131281. 13,
  131282. 2,
  131283. 14,
  131284. 1,
  131285. 15,
  131286. 0,
  131287. 16,
  131288. };
  131289. static long _vq_lengthlist__8u1__p9_2[] = {
  131290. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131291. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131292. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131293. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131294. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131295. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131296. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131297. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131298. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131299. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131300. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131301. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131302. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131303. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131304. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131305. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131306. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131307. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131308. 10,
  131309. };
  131310. static float _vq_quantthresh__8u1__p9_2[] = {
  131311. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131312. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131313. };
  131314. static long _vq_quantmap__8u1__p9_2[] = {
  131315. 15, 13, 11, 9, 7, 5, 3, 1,
  131316. 0, 2, 4, 6, 8, 10, 12, 14,
  131317. 16,
  131318. };
  131319. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131320. _vq_quantthresh__8u1__p9_2,
  131321. _vq_quantmap__8u1__p9_2,
  131322. 17,
  131323. 17
  131324. };
  131325. static static_codebook _8u1__p9_2 = {
  131326. 2, 289,
  131327. _vq_lengthlist__8u1__p9_2,
  131328. 1, -529530880, 1611661312, 5, 0,
  131329. _vq_quantlist__8u1__p9_2,
  131330. NULL,
  131331. &_vq_auxt__8u1__p9_2,
  131332. NULL,
  131333. 0
  131334. };
  131335. static long _huff_lengthlist__8u1__single[] = {
  131336. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131337. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131338. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131339. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131340. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131341. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131342. 13, 8, 8,15,
  131343. };
  131344. static static_codebook _huff_book__8u1__single = {
  131345. 2, 100,
  131346. _huff_lengthlist__8u1__single,
  131347. 0, 0, 0, 0, 0,
  131348. NULL,
  131349. NULL,
  131350. NULL,
  131351. NULL,
  131352. 0
  131353. };
  131354. static long _huff_lengthlist__44u0__long[] = {
  131355. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131356. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131357. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131358. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131359. };
  131360. static static_codebook _huff_book__44u0__long = {
  131361. 2, 64,
  131362. _huff_lengthlist__44u0__long,
  131363. 0, 0, 0, 0, 0,
  131364. NULL,
  131365. NULL,
  131366. NULL,
  131367. NULL,
  131368. 0
  131369. };
  131370. static long _vq_quantlist__44u0__p1_0[] = {
  131371. 1,
  131372. 0,
  131373. 2,
  131374. };
  131375. static long _vq_lengthlist__44u0__p1_0[] = {
  131376. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131377. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131378. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131379. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131380. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131381. 13,
  131382. };
  131383. static float _vq_quantthresh__44u0__p1_0[] = {
  131384. -0.5, 0.5,
  131385. };
  131386. static long _vq_quantmap__44u0__p1_0[] = {
  131387. 1, 0, 2,
  131388. };
  131389. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131390. _vq_quantthresh__44u0__p1_0,
  131391. _vq_quantmap__44u0__p1_0,
  131392. 3,
  131393. 3
  131394. };
  131395. static static_codebook _44u0__p1_0 = {
  131396. 4, 81,
  131397. _vq_lengthlist__44u0__p1_0,
  131398. 1, -535822336, 1611661312, 2, 0,
  131399. _vq_quantlist__44u0__p1_0,
  131400. NULL,
  131401. &_vq_auxt__44u0__p1_0,
  131402. NULL,
  131403. 0
  131404. };
  131405. static long _vq_quantlist__44u0__p2_0[] = {
  131406. 1,
  131407. 0,
  131408. 2,
  131409. };
  131410. static long _vq_lengthlist__44u0__p2_0[] = {
  131411. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131412. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131413. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131414. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131415. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131416. 9,
  131417. };
  131418. static float _vq_quantthresh__44u0__p2_0[] = {
  131419. -0.5, 0.5,
  131420. };
  131421. static long _vq_quantmap__44u0__p2_0[] = {
  131422. 1, 0, 2,
  131423. };
  131424. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131425. _vq_quantthresh__44u0__p2_0,
  131426. _vq_quantmap__44u0__p2_0,
  131427. 3,
  131428. 3
  131429. };
  131430. static static_codebook _44u0__p2_0 = {
  131431. 4, 81,
  131432. _vq_lengthlist__44u0__p2_0,
  131433. 1, -535822336, 1611661312, 2, 0,
  131434. _vq_quantlist__44u0__p2_0,
  131435. NULL,
  131436. &_vq_auxt__44u0__p2_0,
  131437. NULL,
  131438. 0
  131439. };
  131440. static long _vq_quantlist__44u0__p3_0[] = {
  131441. 2,
  131442. 1,
  131443. 3,
  131444. 0,
  131445. 4,
  131446. };
  131447. static long _vq_lengthlist__44u0__p3_0[] = {
  131448. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131449. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131450. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131451. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131452. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131453. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131454. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131455. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131456. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131457. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131458. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131459. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131460. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131461. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131462. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131463. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131464. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131465. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131466. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131467. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131468. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131469. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131470. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131471. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131472. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131473. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131474. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131475. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131476. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131477. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131478. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131479. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131480. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131481. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131482. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131483. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131484. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131485. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131486. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131487. 19,
  131488. };
  131489. static float _vq_quantthresh__44u0__p3_0[] = {
  131490. -1.5, -0.5, 0.5, 1.5,
  131491. };
  131492. static long _vq_quantmap__44u0__p3_0[] = {
  131493. 3, 1, 0, 2, 4,
  131494. };
  131495. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131496. _vq_quantthresh__44u0__p3_0,
  131497. _vq_quantmap__44u0__p3_0,
  131498. 5,
  131499. 5
  131500. };
  131501. static static_codebook _44u0__p3_0 = {
  131502. 4, 625,
  131503. _vq_lengthlist__44u0__p3_0,
  131504. 1, -533725184, 1611661312, 3, 0,
  131505. _vq_quantlist__44u0__p3_0,
  131506. NULL,
  131507. &_vq_auxt__44u0__p3_0,
  131508. NULL,
  131509. 0
  131510. };
  131511. static long _vq_quantlist__44u0__p4_0[] = {
  131512. 2,
  131513. 1,
  131514. 3,
  131515. 0,
  131516. 4,
  131517. };
  131518. static long _vq_lengthlist__44u0__p4_0[] = {
  131519. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131520. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131521. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131522. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131523. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131524. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131525. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131526. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131527. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131528. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131529. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131530. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131531. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131532. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131533. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131534. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131535. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131536. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131537. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131538. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131539. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131540. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131541. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131542. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131543. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131544. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131545. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131546. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131547. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131548. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131549. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131550. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131551. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131552. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131553. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131554. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131555. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131556. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131557. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131558. 12,
  131559. };
  131560. static float _vq_quantthresh__44u0__p4_0[] = {
  131561. -1.5, -0.5, 0.5, 1.5,
  131562. };
  131563. static long _vq_quantmap__44u0__p4_0[] = {
  131564. 3, 1, 0, 2, 4,
  131565. };
  131566. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131567. _vq_quantthresh__44u0__p4_0,
  131568. _vq_quantmap__44u0__p4_0,
  131569. 5,
  131570. 5
  131571. };
  131572. static static_codebook _44u0__p4_0 = {
  131573. 4, 625,
  131574. _vq_lengthlist__44u0__p4_0,
  131575. 1, -533725184, 1611661312, 3, 0,
  131576. _vq_quantlist__44u0__p4_0,
  131577. NULL,
  131578. &_vq_auxt__44u0__p4_0,
  131579. NULL,
  131580. 0
  131581. };
  131582. static long _vq_quantlist__44u0__p5_0[] = {
  131583. 4,
  131584. 3,
  131585. 5,
  131586. 2,
  131587. 6,
  131588. 1,
  131589. 7,
  131590. 0,
  131591. 8,
  131592. };
  131593. static long _vq_lengthlist__44u0__p5_0[] = {
  131594. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131595. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131596. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131597. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131598. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131599. 12,
  131600. };
  131601. static float _vq_quantthresh__44u0__p5_0[] = {
  131602. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131603. };
  131604. static long _vq_quantmap__44u0__p5_0[] = {
  131605. 7, 5, 3, 1, 0, 2, 4, 6,
  131606. 8,
  131607. };
  131608. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131609. _vq_quantthresh__44u0__p5_0,
  131610. _vq_quantmap__44u0__p5_0,
  131611. 9,
  131612. 9
  131613. };
  131614. static static_codebook _44u0__p5_0 = {
  131615. 2, 81,
  131616. _vq_lengthlist__44u0__p5_0,
  131617. 1, -531628032, 1611661312, 4, 0,
  131618. _vq_quantlist__44u0__p5_0,
  131619. NULL,
  131620. &_vq_auxt__44u0__p5_0,
  131621. NULL,
  131622. 0
  131623. };
  131624. static long _vq_quantlist__44u0__p6_0[] = {
  131625. 6,
  131626. 5,
  131627. 7,
  131628. 4,
  131629. 8,
  131630. 3,
  131631. 9,
  131632. 2,
  131633. 10,
  131634. 1,
  131635. 11,
  131636. 0,
  131637. 12,
  131638. };
  131639. static long _vq_lengthlist__44u0__p6_0[] = {
  131640. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131641. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131642. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131643. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131644. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131645. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131646. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131647. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131648. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131649. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131650. 15,17,16,17,18,17,17,18, 0,
  131651. };
  131652. static float _vq_quantthresh__44u0__p6_0[] = {
  131653. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131654. 12.5, 17.5, 22.5, 27.5,
  131655. };
  131656. static long _vq_quantmap__44u0__p6_0[] = {
  131657. 11, 9, 7, 5, 3, 1, 0, 2,
  131658. 4, 6, 8, 10, 12,
  131659. };
  131660. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131661. _vq_quantthresh__44u0__p6_0,
  131662. _vq_quantmap__44u0__p6_0,
  131663. 13,
  131664. 13
  131665. };
  131666. static static_codebook _44u0__p6_0 = {
  131667. 2, 169,
  131668. _vq_lengthlist__44u0__p6_0,
  131669. 1, -526516224, 1616117760, 4, 0,
  131670. _vq_quantlist__44u0__p6_0,
  131671. NULL,
  131672. &_vq_auxt__44u0__p6_0,
  131673. NULL,
  131674. 0
  131675. };
  131676. static long _vq_quantlist__44u0__p6_1[] = {
  131677. 2,
  131678. 1,
  131679. 3,
  131680. 0,
  131681. 4,
  131682. };
  131683. static long _vq_lengthlist__44u0__p6_1[] = {
  131684. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131685. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131686. };
  131687. static float _vq_quantthresh__44u0__p6_1[] = {
  131688. -1.5, -0.5, 0.5, 1.5,
  131689. };
  131690. static long _vq_quantmap__44u0__p6_1[] = {
  131691. 3, 1, 0, 2, 4,
  131692. };
  131693. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  131694. _vq_quantthresh__44u0__p6_1,
  131695. _vq_quantmap__44u0__p6_1,
  131696. 5,
  131697. 5
  131698. };
  131699. static static_codebook _44u0__p6_1 = {
  131700. 2, 25,
  131701. _vq_lengthlist__44u0__p6_1,
  131702. 1, -533725184, 1611661312, 3, 0,
  131703. _vq_quantlist__44u0__p6_1,
  131704. NULL,
  131705. &_vq_auxt__44u0__p6_1,
  131706. NULL,
  131707. 0
  131708. };
  131709. static long _vq_quantlist__44u0__p7_0[] = {
  131710. 2,
  131711. 1,
  131712. 3,
  131713. 0,
  131714. 4,
  131715. };
  131716. static long _vq_lengthlist__44u0__p7_0[] = {
  131717. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  131718. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131719. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131720. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131721. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131722. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131723. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131724. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  131725. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131726. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131727. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131728. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131729. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131730. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131731. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131732. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131733. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131734. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131735. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131736. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131737. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131738. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131739. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131740. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131741. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131742. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131743. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131744. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131745. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131746. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131747. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  131748. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131749. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131750. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131751. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131752. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131753. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131754. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131755. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131756. 10,
  131757. };
  131758. static float _vq_quantthresh__44u0__p7_0[] = {
  131759. -253.5, -84.5, 84.5, 253.5,
  131760. };
  131761. static long _vq_quantmap__44u0__p7_0[] = {
  131762. 3, 1, 0, 2, 4,
  131763. };
  131764. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  131765. _vq_quantthresh__44u0__p7_0,
  131766. _vq_quantmap__44u0__p7_0,
  131767. 5,
  131768. 5
  131769. };
  131770. static static_codebook _44u0__p7_0 = {
  131771. 4, 625,
  131772. _vq_lengthlist__44u0__p7_0,
  131773. 1, -518709248, 1626677248, 3, 0,
  131774. _vq_quantlist__44u0__p7_0,
  131775. NULL,
  131776. &_vq_auxt__44u0__p7_0,
  131777. NULL,
  131778. 0
  131779. };
  131780. static long _vq_quantlist__44u0__p7_1[] = {
  131781. 6,
  131782. 5,
  131783. 7,
  131784. 4,
  131785. 8,
  131786. 3,
  131787. 9,
  131788. 2,
  131789. 10,
  131790. 1,
  131791. 11,
  131792. 0,
  131793. 12,
  131794. };
  131795. static long _vq_lengthlist__44u0__p7_1[] = {
  131796. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  131797. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  131798. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  131799. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  131800. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  131801. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  131802. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  131803. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  131804. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  131805. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  131806. 15,15,15,15,15,15,15,15,15,
  131807. };
  131808. static float _vq_quantthresh__44u0__p7_1[] = {
  131809. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  131810. 32.5, 45.5, 58.5, 71.5,
  131811. };
  131812. static long _vq_quantmap__44u0__p7_1[] = {
  131813. 11, 9, 7, 5, 3, 1, 0, 2,
  131814. 4, 6, 8, 10, 12,
  131815. };
  131816. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  131817. _vq_quantthresh__44u0__p7_1,
  131818. _vq_quantmap__44u0__p7_1,
  131819. 13,
  131820. 13
  131821. };
  131822. static static_codebook _44u0__p7_1 = {
  131823. 2, 169,
  131824. _vq_lengthlist__44u0__p7_1,
  131825. 1, -523010048, 1618608128, 4, 0,
  131826. _vq_quantlist__44u0__p7_1,
  131827. NULL,
  131828. &_vq_auxt__44u0__p7_1,
  131829. NULL,
  131830. 0
  131831. };
  131832. static long _vq_quantlist__44u0__p7_2[] = {
  131833. 6,
  131834. 5,
  131835. 7,
  131836. 4,
  131837. 8,
  131838. 3,
  131839. 9,
  131840. 2,
  131841. 10,
  131842. 1,
  131843. 11,
  131844. 0,
  131845. 12,
  131846. };
  131847. static long _vq_lengthlist__44u0__p7_2[] = {
  131848. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  131849. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  131850. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  131851. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  131852. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  131853. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  131854. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  131855. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  131856. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  131857. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  131858. 9, 9, 9,10, 9, 9,10,10, 9,
  131859. };
  131860. static float _vq_quantthresh__44u0__p7_2[] = {
  131861. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  131862. 2.5, 3.5, 4.5, 5.5,
  131863. };
  131864. static long _vq_quantmap__44u0__p7_2[] = {
  131865. 11, 9, 7, 5, 3, 1, 0, 2,
  131866. 4, 6, 8, 10, 12,
  131867. };
  131868. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  131869. _vq_quantthresh__44u0__p7_2,
  131870. _vq_quantmap__44u0__p7_2,
  131871. 13,
  131872. 13
  131873. };
  131874. static static_codebook _44u0__p7_2 = {
  131875. 2, 169,
  131876. _vq_lengthlist__44u0__p7_2,
  131877. 1, -531103744, 1611661312, 4, 0,
  131878. _vq_quantlist__44u0__p7_2,
  131879. NULL,
  131880. &_vq_auxt__44u0__p7_2,
  131881. NULL,
  131882. 0
  131883. };
  131884. static long _huff_lengthlist__44u0__short[] = {
  131885. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  131886. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  131887. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  131888. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  131889. };
  131890. static static_codebook _huff_book__44u0__short = {
  131891. 2, 64,
  131892. _huff_lengthlist__44u0__short,
  131893. 0, 0, 0, 0, 0,
  131894. NULL,
  131895. NULL,
  131896. NULL,
  131897. NULL,
  131898. 0
  131899. };
  131900. static long _huff_lengthlist__44u1__long[] = {
  131901. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131902. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131903. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131904. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131905. };
  131906. static static_codebook _huff_book__44u1__long = {
  131907. 2, 64,
  131908. _huff_lengthlist__44u1__long,
  131909. 0, 0, 0, 0, 0,
  131910. NULL,
  131911. NULL,
  131912. NULL,
  131913. NULL,
  131914. 0
  131915. };
  131916. static long _vq_quantlist__44u1__p1_0[] = {
  131917. 1,
  131918. 0,
  131919. 2,
  131920. };
  131921. static long _vq_lengthlist__44u1__p1_0[] = {
  131922. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131923. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131924. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131925. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131926. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131927. 13,
  131928. };
  131929. static float _vq_quantthresh__44u1__p1_0[] = {
  131930. -0.5, 0.5,
  131931. };
  131932. static long _vq_quantmap__44u1__p1_0[] = {
  131933. 1, 0, 2,
  131934. };
  131935. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  131936. _vq_quantthresh__44u1__p1_0,
  131937. _vq_quantmap__44u1__p1_0,
  131938. 3,
  131939. 3
  131940. };
  131941. static static_codebook _44u1__p1_0 = {
  131942. 4, 81,
  131943. _vq_lengthlist__44u1__p1_0,
  131944. 1, -535822336, 1611661312, 2, 0,
  131945. _vq_quantlist__44u1__p1_0,
  131946. NULL,
  131947. &_vq_auxt__44u1__p1_0,
  131948. NULL,
  131949. 0
  131950. };
  131951. static long _vq_quantlist__44u1__p2_0[] = {
  131952. 1,
  131953. 0,
  131954. 2,
  131955. };
  131956. static long _vq_lengthlist__44u1__p2_0[] = {
  131957. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131958. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131959. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131960. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131961. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131962. 9,
  131963. };
  131964. static float _vq_quantthresh__44u1__p2_0[] = {
  131965. -0.5, 0.5,
  131966. };
  131967. static long _vq_quantmap__44u1__p2_0[] = {
  131968. 1, 0, 2,
  131969. };
  131970. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  131971. _vq_quantthresh__44u1__p2_0,
  131972. _vq_quantmap__44u1__p2_0,
  131973. 3,
  131974. 3
  131975. };
  131976. static static_codebook _44u1__p2_0 = {
  131977. 4, 81,
  131978. _vq_lengthlist__44u1__p2_0,
  131979. 1, -535822336, 1611661312, 2, 0,
  131980. _vq_quantlist__44u1__p2_0,
  131981. NULL,
  131982. &_vq_auxt__44u1__p2_0,
  131983. NULL,
  131984. 0
  131985. };
  131986. static long _vq_quantlist__44u1__p3_0[] = {
  131987. 2,
  131988. 1,
  131989. 3,
  131990. 0,
  131991. 4,
  131992. };
  131993. static long _vq_lengthlist__44u1__p3_0[] = {
  131994. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131995. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131996. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131997. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131998. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131999. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132000. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132001. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132002. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132003. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132004. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132005. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132006. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132007. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132008. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132009. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132010. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132011. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132012. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132013. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132014. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132015. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132016. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132017. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132018. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132019. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132020. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132021. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132022. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132023. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132024. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132025. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132026. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132027. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132028. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132029. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132030. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132031. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132032. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132033. 19,
  132034. };
  132035. static float _vq_quantthresh__44u1__p3_0[] = {
  132036. -1.5, -0.5, 0.5, 1.5,
  132037. };
  132038. static long _vq_quantmap__44u1__p3_0[] = {
  132039. 3, 1, 0, 2, 4,
  132040. };
  132041. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132042. _vq_quantthresh__44u1__p3_0,
  132043. _vq_quantmap__44u1__p3_0,
  132044. 5,
  132045. 5
  132046. };
  132047. static static_codebook _44u1__p3_0 = {
  132048. 4, 625,
  132049. _vq_lengthlist__44u1__p3_0,
  132050. 1, -533725184, 1611661312, 3, 0,
  132051. _vq_quantlist__44u1__p3_0,
  132052. NULL,
  132053. &_vq_auxt__44u1__p3_0,
  132054. NULL,
  132055. 0
  132056. };
  132057. static long _vq_quantlist__44u1__p4_0[] = {
  132058. 2,
  132059. 1,
  132060. 3,
  132061. 0,
  132062. 4,
  132063. };
  132064. static long _vq_lengthlist__44u1__p4_0[] = {
  132065. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132066. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132067. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132068. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132069. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132070. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132071. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132072. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132073. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132074. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132075. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132076. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132077. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132078. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132079. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132080. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132081. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132082. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132083. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132084. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132085. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132086. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132087. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132088. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132089. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132090. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132091. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132092. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132093. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132094. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132095. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132096. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132097. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132098. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132099. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132100. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132101. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132102. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132103. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132104. 12,
  132105. };
  132106. static float _vq_quantthresh__44u1__p4_0[] = {
  132107. -1.5, -0.5, 0.5, 1.5,
  132108. };
  132109. static long _vq_quantmap__44u1__p4_0[] = {
  132110. 3, 1, 0, 2, 4,
  132111. };
  132112. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132113. _vq_quantthresh__44u1__p4_0,
  132114. _vq_quantmap__44u1__p4_0,
  132115. 5,
  132116. 5
  132117. };
  132118. static static_codebook _44u1__p4_0 = {
  132119. 4, 625,
  132120. _vq_lengthlist__44u1__p4_0,
  132121. 1, -533725184, 1611661312, 3, 0,
  132122. _vq_quantlist__44u1__p4_0,
  132123. NULL,
  132124. &_vq_auxt__44u1__p4_0,
  132125. NULL,
  132126. 0
  132127. };
  132128. static long _vq_quantlist__44u1__p5_0[] = {
  132129. 4,
  132130. 3,
  132131. 5,
  132132. 2,
  132133. 6,
  132134. 1,
  132135. 7,
  132136. 0,
  132137. 8,
  132138. };
  132139. static long _vq_lengthlist__44u1__p5_0[] = {
  132140. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132141. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132142. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132143. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132144. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132145. 12,
  132146. };
  132147. static float _vq_quantthresh__44u1__p5_0[] = {
  132148. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132149. };
  132150. static long _vq_quantmap__44u1__p5_0[] = {
  132151. 7, 5, 3, 1, 0, 2, 4, 6,
  132152. 8,
  132153. };
  132154. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132155. _vq_quantthresh__44u1__p5_0,
  132156. _vq_quantmap__44u1__p5_0,
  132157. 9,
  132158. 9
  132159. };
  132160. static static_codebook _44u1__p5_0 = {
  132161. 2, 81,
  132162. _vq_lengthlist__44u1__p5_0,
  132163. 1, -531628032, 1611661312, 4, 0,
  132164. _vq_quantlist__44u1__p5_0,
  132165. NULL,
  132166. &_vq_auxt__44u1__p5_0,
  132167. NULL,
  132168. 0
  132169. };
  132170. static long _vq_quantlist__44u1__p6_0[] = {
  132171. 6,
  132172. 5,
  132173. 7,
  132174. 4,
  132175. 8,
  132176. 3,
  132177. 9,
  132178. 2,
  132179. 10,
  132180. 1,
  132181. 11,
  132182. 0,
  132183. 12,
  132184. };
  132185. static long _vq_lengthlist__44u1__p6_0[] = {
  132186. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132187. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132188. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132189. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132190. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132191. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132192. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132193. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132194. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132195. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132196. 15,17,16,17,18,17,17,18, 0,
  132197. };
  132198. static float _vq_quantthresh__44u1__p6_0[] = {
  132199. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132200. 12.5, 17.5, 22.5, 27.5,
  132201. };
  132202. static long _vq_quantmap__44u1__p6_0[] = {
  132203. 11, 9, 7, 5, 3, 1, 0, 2,
  132204. 4, 6, 8, 10, 12,
  132205. };
  132206. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132207. _vq_quantthresh__44u1__p6_0,
  132208. _vq_quantmap__44u1__p6_0,
  132209. 13,
  132210. 13
  132211. };
  132212. static static_codebook _44u1__p6_0 = {
  132213. 2, 169,
  132214. _vq_lengthlist__44u1__p6_0,
  132215. 1, -526516224, 1616117760, 4, 0,
  132216. _vq_quantlist__44u1__p6_0,
  132217. NULL,
  132218. &_vq_auxt__44u1__p6_0,
  132219. NULL,
  132220. 0
  132221. };
  132222. static long _vq_quantlist__44u1__p6_1[] = {
  132223. 2,
  132224. 1,
  132225. 3,
  132226. 0,
  132227. 4,
  132228. };
  132229. static long _vq_lengthlist__44u1__p6_1[] = {
  132230. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132231. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132232. };
  132233. static float _vq_quantthresh__44u1__p6_1[] = {
  132234. -1.5, -0.5, 0.5, 1.5,
  132235. };
  132236. static long _vq_quantmap__44u1__p6_1[] = {
  132237. 3, 1, 0, 2, 4,
  132238. };
  132239. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132240. _vq_quantthresh__44u1__p6_1,
  132241. _vq_quantmap__44u1__p6_1,
  132242. 5,
  132243. 5
  132244. };
  132245. static static_codebook _44u1__p6_1 = {
  132246. 2, 25,
  132247. _vq_lengthlist__44u1__p6_1,
  132248. 1, -533725184, 1611661312, 3, 0,
  132249. _vq_quantlist__44u1__p6_1,
  132250. NULL,
  132251. &_vq_auxt__44u1__p6_1,
  132252. NULL,
  132253. 0
  132254. };
  132255. static long _vq_quantlist__44u1__p7_0[] = {
  132256. 3,
  132257. 2,
  132258. 4,
  132259. 1,
  132260. 5,
  132261. 0,
  132262. 6,
  132263. };
  132264. static long _vq_lengthlist__44u1__p7_0[] = {
  132265. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132266. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132267. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132268. 8,
  132269. };
  132270. static float _vq_quantthresh__44u1__p7_0[] = {
  132271. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132272. };
  132273. static long _vq_quantmap__44u1__p7_0[] = {
  132274. 5, 3, 1, 0, 2, 4, 6,
  132275. };
  132276. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132277. _vq_quantthresh__44u1__p7_0,
  132278. _vq_quantmap__44u1__p7_0,
  132279. 7,
  132280. 7
  132281. };
  132282. static static_codebook _44u1__p7_0 = {
  132283. 2, 49,
  132284. _vq_lengthlist__44u1__p7_0,
  132285. 1, -518017024, 1626677248, 3, 0,
  132286. _vq_quantlist__44u1__p7_0,
  132287. NULL,
  132288. &_vq_auxt__44u1__p7_0,
  132289. NULL,
  132290. 0
  132291. };
  132292. static long _vq_quantlist__44u1__p7_1[] = {
  132293. 6,
  132294. 5,
  132295. 7,
  132296. 4,
  132297. 8,
  132298. 3,
  132299. 9,
  132300. 2,
  132301. 10,
  132302. 1,
  132303. 11,
  132304. 0,
  132305. 12,
  132306. };
  132307. static long _vq_lengthlist__44u1__p7_1[] = {
  132308. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132309. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132310. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132311. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132312. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132313. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132314. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132315. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132316. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132317. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132318. 15,15,15,15,15,15,15,15,15,
  132319. };
  132320. static float _vq_quantthresh__44u1__p7_1[] = {
  132321. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132322. 32.5, 45.5, 58.5, 71.5,
  132323. };
  132324. static long _vq_quantmap__44u1__p7_1[] = {
  132325. 11, 9, 7, 5, 3, 1, 0, 2,
  132326. 4, 6, 8, 10, 12,
  132327. };
  132328. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132329. _vq_quantthresh__44u1__p7_1,
  132330. _vq_quantmap__44u1__p7_1,
  132331. 13,
  132332. 13
  132333. };
  132334. static static_codebook _44u1__p7_1 = {
  132335. 2, 169,
  132336. _vq_lengthlist__44u1__p7_1,
  132337. 1, -523010048, 1618608128, 4, 0,
  132338. _vq_quantlist__44u1__p7_1,
  132339. NULL,
  132340. &_vq_auxt__44u1__p7_1,
  132341. NULL,
  132342. 0
  132343. };
  132344. static long _vq_quantlist__44u1__p7_2[] = {
  132345. 6,
  132346. 5,
  132347. 7,
  132348. 4,
  132349. 8,
  132350. 3,
  132351. 9,
  132352. 2,
  132353. 10,
  132354. 1,
  132355. 11,
  132356. 0,
  132357. 12,
  132358. };
  132359. static long _vq_lengthlist__44u1__p7_2[] = {
  132360. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132361. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132362. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132363. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132364. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132365. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132366. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132367. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132368. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132369. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132370. 9, 9, 9,10, 9, 9,10,10, 9,
  132371. };
  132372. static float _vq_quantthresh__44u1__p7_2[] = {
  132373. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132374. 2.5, 3.5, 4.5, 5.5,
  132375. };
  132376. static long _vq_quantmap__44u1__p7_2[] = {
  132377. 11, 9, 7, 5, 3, 1, 0, 2,
  132378. 4, 6, 8, 10, 12,
  132379. };
  132380. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132381. _vq_quantthresh__44u1__p7_2,
  132382. _vq_quantmap__44u1__p7_2,
  132383. 13,
  132384. 13
  132385. };
  132386. static static_codebook _44u1__p7_2 = {
  132387. 2, 169,
  132388. _vq_lengthlist__44u1__p7_2,
  132389. 1, -531103744, 1611661312, 4, 0,
  132390. _vq_quantlist__44u1__p7_2,
  132391. NULL,
  132392. &_vq_auxt__44u1__p7_2,
  132393. NULL,
  132394. 0
  132395. };
  132396. static long _huff_lengthlist__44u1__short[] = {
  132397. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132398. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132399. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132400. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132401. };
  132402. static static_codebook _huff_book__44u1__short = {
  132403. 2, 64,
  132404. _huff_lengthlist__44u1__short,
  132405. 0, 0, 0, 0, 0,
  132406. NULL,
  132407. NULL,
  132408. NULL,
  132409. NULL,
  132410. 0
  132411. };
  132412. static long _huff_lengthlist__44u2__long[] = {
  132413. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132414. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132415. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132416. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132417. };
  132418. static static_codebook _huff_book__44u2__long = {
  132419. 2, 64,
  132420. _huff_lengthlist__44u2__long,
  132421. 0, 0, 0, 0, 0,
  132422. NULL,
  132423. NULL,
  132424. NULL,
  132425. NULL,
  132426. 0
  132427. };
  132428. static long _vq_quantlist__44u2__p1_0[] = {
  132429. 1,
  132430. 0,
  132431. 2,
  132432. };
  132433. static long _vq_lengthlist__44u2__p1_0[] = {
  132434. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132435. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132436. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132437. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132438. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132439. 13,
  132440. };
  132441. static float _vq_quantthresh__44u2__p1_0[] = {
  132442. -0.5, 0.5,
  132443. };
  132444. static long _vq_quantmap__44u2__p1_0[] = {
  132445. 1, 0, 2,
  132446. };
  132447. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132448. _vq_quantthresh__44u2__p1_0,
  132449. _vq_quantmap__44u2__p1_0,
  132450. 3,
  132451. 3
  132452. };
  132453. static static_codebook _44u2__p1_0 = {
  132454. 4, 81,
  132455. _vq_lengthlist__44u2__p1_0,
  132456. 1, -535822336, 1611661312, 2, 0,
  132457. _vq_quantlist__44u2__p1_0,
  132458. NULL,
  132459. &_vq_auxt__44u2__p1_0,
  132460. NULL,
  132461. 0
  132462. };
  132463. static long _vq_quantlist__44u2__p2_0[] = {
  132464. 1,
  132465. 0,
  132466. 2,
  132467. };
  132468. static long _vq_lengthlist__44u2__p2_0[] = {
  132469. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132470. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132471. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132472. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132473. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132474. 9,
  132475. };
  132476. static float _vq_quantthresh__44u2__p2_0[] = {
  132477. -0.5, 0.5,
  132478. };
  132479. static long _vq_quantmap__44u2__p2_0[] = {
  132480. 1, 0, 2,
  132481. };
  132482. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132483. _vq_quantthresh__44u2__p2_0,
  132484. _vq_quantmap__44u2__p2_0,
  132485. 3,
  132486. 3
  132487. };
  132488. static static_codebook _44u2__p2_0 = {
  132489. 4, 81,
  132490. _vq_lengthlist__44u2__p2_0,
  132491. 1, -535822336, 1611661312, 2, 0,
  132492. _vq_quantlist__44u2__p2_0,
  132493. NULL,
  132494. &_vq_auxt__44u2__p2_0,
  132495. NULL,
  132496. 0
  132497. };
  132498. static long _vq_quantlist__44u2__p3_0[] = {
  132499. 2,
  132500. 1,
  132501. 3,
  132502. 0,
  132503. 4,
  132504. };
  132505. static long _vq_lengthlist__44u2__p3_0[] = {
  132506. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132507. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132508. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132509. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132510. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132511. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132512. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132513. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132514. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132515. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132516. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132517. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132518. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132519. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132520. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132521. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132522. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132523. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132524. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132525. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132526. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132527. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132528. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132529. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132530. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132531. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132532. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132533. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132534. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132535. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132536. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132537. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132538. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132539. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132540. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132541. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132542. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132543. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132544. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132545. 0,
  132546. };
  132547. static float _vq_quantthresh__44u2__p3_0[] = {
  132548. -1.5, -0.5, 0.5, 1.5,
  132549. };
  132550. static long _vq_quantmap__44u2__p3_0[] = {
  132551. 3, 1, 0, 2, 4,
  132552. };
  132553. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132554. _vq_quantthresh__44u2__p3_0,
  132555. _vq_quantmap__44u2__p3_0,
  132556. 5,
  132557. 5
  132558. };
  132559. static static_codebook _44u2__p3_0 = {
  132560. 4, 625,
  132561. _vq_lengthlist__44u2__p3_0,
  132562. 1, -533725184, 1611661312, 3, 0,
  132563. _vq_quantlist__44u2__p3_0,
  132564. NULL,
  132565. &_vq_auxt__44u2__p3_0,
  132566. NULL,
  132567. 0
  132568. };
  132569. static long _vq_quantlist__44u2__p4_0[] = {
  132570. 2,
  132571. 1,
  132572. 3,
  132573. 0,
  132574. 4,
  132575. };
  132576. static long _vq_lengthlist__44u2__p4_0[] = {
  132577. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132578. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132579. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132580. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132581. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132582. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132583. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132584. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132585. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132586. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132587. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132588. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132589. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132590. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132591. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132592. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132593. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132594. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132595. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132596. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132597. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132598. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132599. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132600. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132601. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132602. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132603. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132604. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132605. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132606. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132607. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132608. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132609. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132610. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132611. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132612. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132613. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132614. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132615. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132616. 13,
  132617. };
  132618. static float _vq_quantthresh__44u2__p4_0[] = {
  132619. -1.5, -0.5, 0.5, 1.5,
  132620. };
  132621. static long _vq_quantmap__44u2__p4_0[] = {
  132622. 3, 1, 0, 2, 4,
  132623. };
  132624. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132625. _vq_quantthresh__44u2__p4_0,
  132626. _vq_quantmap__44u2__p4_0,
  132627. 5,
  132628. 5
  132629. };
  132630. static static_codebook _44u2__p4_0 = {
  132631. 4, 625,
  132632. _vq_lengthlist__44u2__p4_0,
  132633. 1, -533725184, 1611661312, 3, 0,
  132634. _vq_quantlist__44u2__p4_0,
  132635. NULL,
  132636. &_vq_auxt__44u2__p4_0,
  132637. NULL,
  132638. 0
  132639. };
  132640. static long _vq_quantlist__44u2__p5_0[] = {
  132641. 4,
  132642. 3,
  132643. 5,
  132644. 2,
  132645. 6,
  132646. 1,
  132647. 7,
  132648. 0,
  132649. 8,
  132650. };
  132651. static long _vq_lengthlist__44u2__p5_0[] = {
  132652. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132653. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132654. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132655. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132656. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132657. 13,
  132658. };
  132659. static float _vq_quantthresh__44u2__p5_0[] = {
  132660. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132661. };
  132662. static long _vq_quantmap__44u2__p5_0[] = {
  132663. 7, 5, 3, 1, 0, 2, 4, 6,
  132664. 8,
  132665. };
  132666. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132667. _vq_quantthresh__44u2__p5_0,
  132668. _vq_quantmap__44u2__p5_0,
  132669. 9,
  132670. 9
  132671. };
  132672. static static_codebook _44u2__p5_0 = {
  132673. 2, 81,
  132674. _vq_lengthlist__44u2__p5_0,
  132675. 1, -531628032, 1611661312, 4, 0,
  132676. _vq_quantlist__44u2__p5_0,
  132677. NULL,
  132678. &_vq_auxt__44u2__p5_0,
  132679. NULL,
  132680. 0
  132681. };
  132682. static long _vq_quantlist__44u2__p6_0[] = {
  132683. 6,
  132684. 5,
  132685. 7,
  132686. 4,
  132687. 8,
  132688. 3,
  132689. 9,
  132690. 2,
  132691. 10,
  132692. 1,
  132693. 11,
  132694. 0,
  132695. 12,
  132696. };
  132697. static long _vq_lengthlist__44u2__p6_0[] = {
  132698. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  132699. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  132700. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  132701. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  132702. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  132703. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  132704. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  132705. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  132706. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  132707. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  132708. 15,17,17,16,18,17,18, 0, 0,
  132709. };
  132710. static float _vq_quantthresh__44u2__p6_0[] = {
  132711. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132712. 12.5, 17.5, 22.5, 27.5,
  132713. };
  132714. static long _vq_quantmap__44u2__p6_0[] = {
  132715. 11, 9, 7, 5, 3, 1, 0, 2,
  132716. 4, 6, 8, 10, 12,
  132717. };
  132718. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  132719. _vq_quantthresh__44u2__p6_0,
  132720. _vq_quantmap__44u2__p6_0,
  132721. 13,
  132722. 13
  132723. };
  132724. static static_codebook _44u2__p6_0 = {
  132725. 2, 169,
  132726. _vq_lengthlist__44u2__p6_0,
  132727. 1, -526516224, 1616117760, 4, 0,
  132728. _vq_quantlist__44u2__p6_0,
  132729. NULL,
  132730. &_vq_auxt__44u2__p6_0,
  132731. NULL,
  132732. 0
  132733. };
  132734. static long _vq_quantlist__44u2__p6_1[] = {
  132735. 2,
  132736. 1,
  132737. 3,
  132738. 0,
  132739. 4,
  132740. };
  132741. static long _vq_lengthlist__44u2__p6_1[] = {
  132742. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  132743. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  132744. };
  132745. static float _vq_quantthresh__44u2__p6_1[] = {
  132746. -1.5, -0.5, 0.5, 1.5,
  132747. };
  132748. static long _vq_quantmap__44u2__p6_1[] = {
  132749. 3, 1, 0, 2, 4,
  132750. };
  132751. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  132752. _vq_quantthresh__44u2__p6_1,
  132753. _vq_quantmap__44u2__p6_1,
  132754. 5,
  132755. 5
  132756. };
  132757. static static_codebook _44u2__p6_1 = {
  132758. 2, 25,
  132759. _vq_lengthlist__44u2__p6_1,
  132760. 1, -533725184, 1611661312, 3, 0,
  132761. _vq_quantlist__44u2__p6_1,
  132762. NULL,
  132763. &_vq_auxt__44u2__p6_1,
  132764. NULL,
  132765. 0
  132766. };
  132767. static long _vq_quantlist__44u2__p7_0[] = {
  132768. 4,
  132769. 3,
  132770. 5,
  132771. 2,
  132772. 6,
  132773. 1,
  132774. 7,
  132775. 0,
  132776. 8,
  132777. };
  132778. static long _vq_lengthlist__44u2__p7_0[] = {
  132779. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  132780. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  132781. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132782. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132783. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132784. 11,
  132785. };
  132786. static float _vq_quantthresh__44u2__p7_0[] = {
  132787. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  132788. };
  132789. static long _vq_quantmap__44u2__p7_0[] = {
  132790. 7, 5, 3, 1, 0, 2, 4, 6,
  132791. 8,
  132792. };
  132793. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  132794. _vq_quantthresh__44u2__p7_0,
  132795. _vq_quantmap__44u2__p7_0,
  132796. 9,
  132797. 9
  132798. };
  132799. static static_codebook _44u2__p7_0 = {
  132800. 2, 81,
  132801. _vq_lengthlist__44u2__p7_0,
  132802. 1, -516612096, 1626677248, 4, 0,
  132803. _vq_quantlist__44u2__p7_0,
  132804. NULL,
  132805. &_vq_auxt__44u2__p7_0,
  132806. NULL,
  132807. 0
  132808. };
  132809. static long _vq_quantlist__44u2__p7_1[] = {
  132810. 6,
  132811. 5,
  132812. 7,
  132813. 4,
  132814. 8,
  132815. 3,
  132816. 9,
  132817. 2,
  132818. 10,
  132819. 1,
  132820. 11,
  132821. 0,
  132822. 12,
  132823. };
  132824. static long _vq_lengthlist__44u2__p7_1[] = {
  132825. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  132826. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  132827. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  132828. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  132829. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  132830. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  132831. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  132832. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  132833. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  132834. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  132835. 14,14,14,17,15,17,17,17,17,
  132836. };
  132837. static float _vq_quantthresh__44u2__p7_1[] = {
  132838. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132839. 32.5, 45.5, 58.5, 71.5,
  132840. };
  132841. static long _vq_quantmap__44u2__p7_1[] = {
  132842. 11, 9, 7, 5, 3, 1, 0, 2,
  132843. 4, 6, 8, 10, 12,
  132844. };
  132845. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  132846. _vq_quantthresh__44u2__p7_1,
  132847. _vq_quantmap__44u2__p7_1,
  132848. 13,
  132849. 13
  132850. };
  132851. static static_codebook _44u2__p7_1 = {
  132852. 2, 169,
  132853. _vq_lengthlist__44u2__p7_1,
  132854. 1, -523010048, 1618608128, 4, 0,
  132855. _vq_quantlist__44u2__p7_1,
  132856. NULL,
  132857. &_vq_auxt__44u2__p7_1,
  132858. NULL,
  132859. 0
  132860. };
  132861. static long _vq_quantlist__44u2__p7_2[] = {
  132862. 6,
  132863. 5,
  132864. 7,
  132865. 4,
  132866. 8,
  132867. 3,
  132868. 9,
  132869. 2,
  132870. 10,
  132871. 1,
  132872. 11,
  132873. 0,
  132874. 12,
  132875. };
  132876. static long _vq_lengthlist__44u2__p7_2[] = {
  132877. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  132878. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  132879. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  132880. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132881. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  132882. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  132883. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  132884. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132885. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  132886. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  132887. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132888. };
  132889. static float _vq_quantthresh__44u2__p7_2[] = {
  132890. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132891. 2.5, 3.5, 4.5, 5.5,
  132892. };
  132893. static long _vq_quantmap__44u2__p7_2[] = {
  132894. 11, 9, 7, 5, 3, 1, 0, 2,
  132895. 4, 6, 8, 10, 12,
  132896. };
  132897. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  132898. _vq_quantthresh__44u2__p7_2,
  132899. _vq_quantmap__44u2__p7_2,
  132900. 13,
  132901. 13
  132902. };
  132903. static static_codebook _44u2__p7_2 = {
  132904. 2, 169,
  132905. _vq_lengthlist__44u2__p7_2,
  132906. 1, -531103744, 1611661312, 4, 0,
  132907. _vq_quantlist__44u2__p7_2,
  132908. NULL,
  132909. &_vq_auxt__44u2__p7_2,
  132910. NULL,
  132911. 0
  132912. };
  132913. static long _huff_lengthlist__44u2__short[] = {
  132914. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  132915. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  132916. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  132917. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  132918. };
  132919. static static_codebook _huff_book__44u2__short = {
  132920. 2, 64,
  132921. _huff_lengthlist__44u2__short,
  132922. 0, 0, 0, 0, 0,
  132923. NULL,
  132924. NULL,
  132925. NULL,
  132926. NULL,
  132927. 0
  132928. };
  132929. static long _huff_lengthlist__44u3__long[] = {
  132930. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  132931. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  132932. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  132933. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  132934. };
  132935. static static_codebook _huff_book__44u3__long = {
  132936. 2, 64,
  132937. _huff_lengthlist__44u3__long,
  132938. 0, 0, 0, 0, 0,
  132939. NULL,
  132940. NULL,
  132941. NULL,
  132942. NULL,
  132943. 0
  132944. };
  132945. static long _vq_quantlist__44u3__p1_0[] = {
  132946. 1,
  132947. 0,
  132948. 2,
  132949. };
  132950. static long _vq_lengthlist__44u3__p1_0[] = {
  132951. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  132952. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132953. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  132954. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  132955. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  132956. 13,
  132957. };
  132958. static float _vq_quantthresh__44u3__p1_0[] = {
  132959. -0.5, 0.5,
  132960. };
  132961. static long _vq_quantmap__44u3__p1_0[] = {
  132962. 1, 0, 2,
  132963. };
  132964. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  132965. _vq_quantthresh__44u3__p1_0,
  132966. _vq_quantmap__44u3__p1_0,
  132967. 3,
  132968. 3
  132969. };
  132970. static static_codebook _44u3__p1_0 = {
  132971. 4, 81,
  132972. _vq_lengthlist__44u3__p1_0,
  132973. 1, -535822336, 1611661312, 2, 0,
  132974. _vq_quantlist__44u3__p1_0,
  132975. NULL,
  132976. &_vq_auxt__44u3__p1_0,
  132977. NULL,
  132978. 0
  132979. };
  132980. static long _vq_quantlist__44u3__p2_0[] = {
  132981. 1,
  132982. 0,
  132983. 2,
  132984. };
  132985. static long _vq_lengthlist__44u3__p2_0[] = {
  132986. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132987. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  132988. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132989. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132990. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  132991. 9,
  132992. };
  132993. static float _vq_quantthresh__44u3__p2_0[] = {
  132994. -0.5, 0.5,
  132995. };
  132996. static long _vq_quantmap__44u3__p2_0[] = {
  132997. 1, 0, 2,
  132998. };
  132999. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133000. _vq_quantthresh__44u3__p2_0,
  133001. _vq_quantmap__44u3__p2_0,
  133002. 3,
  133003. 3
  133004. };
  133005. static static_codebook _44u3__p2_0 = {
  133006. 4, 81,
  133007. _vq_lengthlist__44u3__p2_0,
  133008. 1, -535822336, 1611661312, 2, 0,
  133009. _vq_quantlist__44u3__p2_0,
  133010. NULL,
  133011. &_vq_auxt__44u3__p2_0,
  133012. NULL,
  133013. 0
  133014. };
  133015. static long _vq_quantlist__44u3__p3_0[] = {
  133016. 2,
  133017. 1,
  133018. 3,
  133019. 0,
  133020. 4,
  133021. };
  133022. static long _vq_lengthlist__44u3__p3_0[] = {
  133023. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133024. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133025. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133026. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133027. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133028. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133029. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133030. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133031. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133032. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133033. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133034. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133035. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133036. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133037. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133038. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133039. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133040. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133041. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133042. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133043. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133044. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133045. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133046. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133047. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133048. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133049. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133050. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133051. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133052. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133053. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133054. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133055. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133056. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133057. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133058. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133059. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133060. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133061. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133062. 0,
  133063. };
  133064. static float _vq_quantthresh__44u3__p3_0[] = {
  133065. -1.5, -0.5, 0.5, 1.5,
  133066. };
  133067. static long _vq_quantmap__44u3__p3_0[] = {
  133068. 3, 1, 0, 2, 4,
  133069. };
  133070. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133071. _vq_quantthresh__44u3__p3_0,
  133072. _vq_quantmap__44u3__p3_0,
  133073. 5,
  133074. 5
  133075. };
  133076. static static_codebook _44u3__p3_0 = {
  133077. 4, 625,
  133078. _vq_lengthlist__44u3__p3_0,
  133079. 1, -533725184, 1611661312, 3, 0,
  133080. _vq_quantlist__44u3__p3_0,
  133081. NULL,
  133082. &_vq_auxt__44u3__p3_0,
  133083. NULL,
  133084. 0
  133085. };
  133086. static long _vq_quantlist__44u3__p4_0[] = {
  133087. 2,
  133088. 1,
  133089. 3,
  133090. 0,
  133091. 4,
  133092. };
  133093. static long _vq_lengthlist__44u3__p4_0[] = {
  133094. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133095. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133096. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133097. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133098. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133099. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133100. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133101. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133102. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133103. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133104. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133105. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133106. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133107. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133108. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133109. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133110. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133111. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133112. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133113. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133114. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133115. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133116. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133117. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133118. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133119. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133120. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133121. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133122. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133123. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133124. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133125. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133126. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133127. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133128. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133129. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133130. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133131. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133132. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133133. 13,
  133134. };
  133135. static float _vq_quantthresh__44u3__p4_0[] = {
  133136. -1.5, -0.5, 0.5, 1.5,
  133137. };
  133138. static long _vq_quantmap__44u3__p4_0[] = {
  133139. 3, 1, 0, 2, 4,
  133140. };
  133141. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133142. _vq_quantthresh__44u3__p4_0,
  133143. _vq_quantmap__44u3__p4_0,
  133144. 5,
  133145. 5
  133146. };
  133147. static static_codebook _44u3__p4_0 = {
  133148. 4, 625,
  133149. _vq_lengthlist__44u3__p4_0,
  133150. 1, -533725184, 1611661312, 3, 0,
  133151. _vq_quantlist__44u3__p4_0,
  133152. NULL,
  133153. &_vq_auxt__44u3__p4_0,
  133154. NULL,
  133155. 0
  133156. };
  133157. static long _vq_quantlist__44u3__p5_0[] = {
  133158. 4,
  133159. 3,
  133160. 5,
  133161. 2,
  133162. 6,
  133163. 1,
  133164. 7,
  133165. 0,
  133166. 8,
  133167. };
  133168. static long _vq_lengthlist__44u3__p5_0[] = {
  133169. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133170. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133171. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133172. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133173. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133174. 12,
  133175. };
  133176. static float _vq_quantthresh__44u3__p5_0[] = {
  133177. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133178. };
  133179. static long _vq_quantmap__44u3__p5_0[] = {
  133180. 7, 5, 3, 1, 0, 2, 4, 6,
  133181. 8,
  133182. };
  133183. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133184. _vq_quantthresh__44u3__p5_0,
  133185. _vq_quantmap__44u3__p5_0,
  133186. 9,
  133187. 9
  133188. };
  133189. static static_codebook _44u3__p5_0 = {
  133190. 2, 81,
  133191. _vq_lengthlist__44u3__p5_0,
  133192. 1, -531628032, 1611661312, 4, 0,
  133193. _vq_quantlist__44u3__p5_0,
  133194. NULL,
  133195. &_vq_auxt__44u3__p5_0,
  133196. NULL,
  133197. 0
  133198. };
  133199. static long _vq_quantlist__44u3__p6_0[] = {
  133200. 6,
  133201. 5,
  133202. 7,
  133203. 4,
  133204. 8,
  133205. 3,
  133206. 9,
  133207. 2,
  133208. 10,
  133209. 1,
  133210. 11,
  133211. 0,
  133212. 12,
  133213. };
  133214. static long _vq_lengthlist__44u3__p6_0[] = {
  133215. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133216. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133217. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133218. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133219. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133220. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133221. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133222. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133223. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133224. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133225. 15,16,16,16,17,18,16,20,18,
  133226. };
  133227. static float _vq_quantthresh__44u3__p6_0[] = {
  133228. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133229. 12.5, 17.5, 22.5, 27.5,
  133230. };
  133231. static long _vq_quantmap__44u3__p6_0[] = {
  133232. 11, 9, 7, 5, 3, 1, 0, 2,
  133233. 4, 6, 8, 10, 12,
  133234. };
  133235. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133236. _vq_quantthresh__44u3__p6_0,
  133237. _vq_quantmap__44u3__p6_0,
  133238. 13,
  133239. 13
  133240. };
  133241. static static_codebook _44u3__p6_0 = {
  133242. 2, 169,
  133243. _vq_lengthlist__44u3__p6_0,
  133244. 1, -526516224, 1616117760, 4, 0,
  133245. _vq_quantlist__44u3__p6_0,
  133246. NULL,
  133247. &_vq_auxt__44u3__p6_0,
  133248. NULL,
  133249. 0
  133250. };
  133251. static long _vq_quantlist__44u3__p6_1[] = {
  133252. 2,
  133253. 1,
  133254. 3,
  133255. 0,
  133256. 4,
  133257. };
  133258. static long _vq_lengthlist__44u3__p6_1[] = {
  133259. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133260. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133261. };
  133262. static float _vq_quantthresh__44u3__p6_1[] = {
  133263. -1.5, -0.5, 0.5, 1.5,
  133264. };
  133265. static long _vq_quantmap__44u3__p6_1[] = {
  133266. 3, 1, 0, 2, 4,
  133267. };
  133268. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133269. _vq_quantthresh__44u3__p6_1,
  133270. _vq_quantmap__44u3__p6_1,
  133271. 5,
  133272. 5
  133273. };
  133274. static static_codebook _44u3__p6_1 = {
  133275. 2, 25,
  133276. _vq_lengthlist__44u3__p6_1,
  133277. 1, -533725184, 1611661312, 3, 0,
  133278. _vq_quantlist__44u3__p6_1,
  133279. NULL,
  133280. &_vq_auxt__44u3__p6_1,
  133281. NULL,
  133282. 0
  133283. };
  133284. static long _vq_quantlist__44u3__p7_0[] = {
  133285. 4,
  133286. 3,
  133287. 5,
  133288. 2,
  133289. 6,
  133290. 1,
  133291. 7,
  133292. 0,
  133293. 8,
  133294. };
  133295. static long _vq_lengthlist__44u3__p7_0[] = {
  133296. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133297. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133298. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133299. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133300. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133301. 9,
  133302. };
  133303. static float _vq_quantthresh__44u3__p7_0[] = {
  133304. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133305. };
  133306. static long _vq_quantmap__44u3__p7_0[] = {
  133307. 7, 5, 3, 1, 0, 2, 4, 6,
  133308. 8,
  133309. };
  133310. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133311. _vq_quantthresh__44u3__p7_0,
  133312. _vq_quantmap__44u3__p7_0,
  133313. 9,
  133314. 9
  133315. };
  133316. static static_codebook _44u3__p7_0 = {
  133317. 2, 81,
  133318. _vq_lengthlist__44u3__p7_0,
  133319. 1, -515907584, 1627381760, 4, 0,
  133320. _vq_quantlist__44u3__p7_0,
  133321. NULL,
  133322. &_vq_auxt__44u3__p7_0,
  133323. NULL,
  133324. 0
  133325. };
  133326. static long _vq_quantlist__44u3__p7_1[] = {
  133327. 7,
  133328. 6,
  133329. 8,
  133330. 5,
  133331. 9,
  133332. 4,
  133333. 10,
  133334. 3,
  133335. 11,
  133336. 2,
  133337. 12,
  133338. 1,
  133339. 13,
  133340. 0,
  133341. 14,
  133342. };
  133343. static long _vq_lengthlist__44u3__p7_1[] = {
  133344. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133345. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133346. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133347. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133348. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133349. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133350. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133351. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133352. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133353. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133354. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133355. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133356. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133357. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133358. 17,
  133359. };
  133360. static float _vq_quantthresh__44u3__p7_1[] = {
  133361. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133362. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133363. };
  133364. static long _vq_quantmap__44u3__p7_1[] = {
  133365. 13, 11, 9, 7, 5, 3, 1, 0,
  133366. 2, 4, 6, 8, 10, 12, 14,
  133367. };
  133368. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133369. _vq_quantthresh__44u3__p7_1,
  133370. _vq_quantmap__44u3__p7_1,
  133371. 15,
  133372. 15
  133373. };
  133374. static static_codebook _44u3__p7_1 = {
  133375. 2, 225,
  133376. _vq_lengthlist__44u3__p7_1,
  133377. 1, -522338304, 1620115456, 4, 0,
  133378. _vq_quantlist__44u3__p7_1,
  133379. NULL,
  133380. &_vq_auxt__44u3__p7_1,
  133381. NULL,
  133382. 0
  133383. };
  133384. static long _vq_quantlist__44u3__p7_2[] = {
  133385. 8,
  133386. 7,
  133387. 9,
  133388. 6,
  133389. 10,
  133390. 5,
  133391. 11,
  133392. 4,
  133393. 12,
  133394. 3,
  133395. 13,
  133396. 2,
  133397. 14,
  133398. 1,
  133399. 15,
  133400. 0,
  133401. 16,
  133402. };
  133403. static long _vq_lengthlist__44u3__p7_2[] = {
  133404. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133405. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133406. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133407. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133408. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133409. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133410. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133411. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133412. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133413. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133414. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133415. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133416. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133417. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133418. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133419. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133420. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133421. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133422. 11,
  133423. };
  133424. static float _vq_quantthresh__44u3__p7_2[] = {
  133425. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133426. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133427. };
  133428. static long _vq_quantmap__44u3__p7_2[] = {
  133429. 15, 13, 11, 9, 7, 5, 3, 1,
  133430. 0, 2, 4, 6, 8, 10, 12, 14,
  133431. 16,
  133432. };
  133433. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133434. _vq_quantthresh__44u3__p7_2,
  133435. _vq_quantmap__44u3__p7_2,
  133436. 17,
  133437. 17
  133438. };
  133439. static static_codebook _44u3__p7_2 = {
  133440. 2, 289,
  133441. _vq_lengthlist__44u3__p7_2,
  133442. 1, -529530880, 1611661312, 5, 0,
  133443. _vq_quantlist__44u3__p7_2,
  133444. NULL,
  133445. &_vq_auxt__44u3__p7_2,
  133446. NULL,
  133447. 0
  133448. };
  133449. static long _huff_lengthlist__44u3__short[] = {
  133450. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133451. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133452. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133453. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133454. };
  133455. static static_codebook _huff_book__44u3__short = {
  133456. 2, 64,
  133457. _huff_lengthlist__44u3__short,
  133458. 0, 0, 0, 0, 0,
  133459. NULL,
  133460. NULL,
  133461. NULL,
  133462. NULL,
  133463. 0
  133464. };
  133465. static long _huff_lengthlist__44u4__long[] = {
  133466. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133467. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133468. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133469. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133470. };
  133471. static static_codebook _huff_book__44u4__long = {
  133472. 2, 64,
  133473. _huff_lengthlist__44u4__long,
  133474. 0, 0, 0, 0, 0,
  133475. NULL,
  133476. NULL,
  133477. NULL,
  133478. NULL,
  133479. 0
  133480. };
  133481. static long _vq_quantlist__44u4__p1_0[] = {
  133482. 1,
  133483. 0,
  133484. 2,
  133485. };
  133486. static long _vq_lengthlist__44u4__p1_0[] = {
  133487. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133488. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133489. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133490. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133491. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133492. 13,
  133493. };
  133494. static float _vq_quantthresh__44u4__p1_0[] = {
  133495. -0.5, 0.5,
  133496. };
  133497. static long _vq_quantmap__44u4__p1_0[] = {
  133498. 1, 0, 2,
  133499. };
  133500. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133501. _vq_quantthresh__44u4__p1_0,
  133502. _vq_quantmap__44u4__p1_0,
  133503. 3,
  133504. 3
  133505. };
  133506. static static_codebook _44u4__p1_0 = {
  133507. 4, 81,
  133508. _vq_lengthlist__44u4__p1_0,
  133509. 1, -535822336, 1611661312, 2, 0,
  133510. _vq_quantlist__44u4__p1_0,
  133511. NULL,
  133512. &_vq_auxt__44u4__p1_0,
  133513. NULL,
  133514. 0
  133515. };
  133516. static long _vq_quantlist__44u4__p2_0[] = {
  133517. 1,
  133518. 0,
  133519. 2,
  133520. };
  133521. static long _vq_lengthlist__44u4__p2_0[] = {
  133522. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133523. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133524. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133525. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133526. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133527. 9,
  133528. };
  133529. static float _vq_quantthresh__44u4__p2_0[] = {
  133530. -0.5, 0.5,
  133531. };
  133532. static long _vq_quantmap__44u4__p2_0[] = {
  133533. 1, 0, 2,
  133534. };
  133535. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133536. _vq_quantthresh__44u4__p2_0,
  133537. _vq_quantmap__44u4__p2_0,
  133538. 3,
  133539. 3
  133540. };
  133541. static static_codebook _44u4__p2_0 = {
  133542. 4, 81,
  133543. _vq_lengthlist__44u4__p2_0,
  133544. 1, -535822336, 1611661312, 2, 0,
  133545. _vq_quantlist__44u4__p2_0,
  133546. NULL,
  133547. &_vq_auxt__44u4__p2_0,
  133548. NULL,
  133549. 0
  133550. };
  133551. static long _vq_quantlist__44u4__p3_0[] = {
  133552. 2,
  133553. 1,
  133554. 3,
  133555. 0,
  133556. 4,
  133557. };
  133558. static long _vq_lengthlist__44u4__p3_0[] = {
  133559. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133560. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133561. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133562. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133563. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133564. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133565. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133566. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133567. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133568. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133569. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133570. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133571. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133572. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133573. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133574. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133575. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133576. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133577. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133578. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133579. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133580. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133581. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133582. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133583. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133584. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133585. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133586. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133587. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133588. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133589. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133590. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133591. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133592. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133593. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133594. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133595. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133596. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133597. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133598. 0,
  133599. };
  133600. static float _vq_quantthresh__44u4__p3_0[] = {
  133601. -1.5, -0.5, 0.5, 1.5,
  133602. };
  133603. static long _vq_quantmap__44u4__p3_0[] = {
  133604. 3, 1, 0, 2, 4,
  133605. };
  133606. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133607. _vq_quantthresh__44u4__p3_0,
  133608. _vq_quantmap__44u4__p3_0,
  133609. 5,
  133610. 5
  133611. };
  133612. static static_codebook _44u4__p3_0 = {
  133613. 4, 625,
  133614. _vq_lengthlist__44u4__p3_0,
  133615. 1, -533725184, 1611661312, 3, 0,
  133616. _vq_quantlist__44u4__p3_0,
  133617. NULL,
  133618. &_vq_auxt__44u4__p3_0,
  133619. NULL,
  133620. 0
  133621. };
  133622. static long _vq_quantlist__44u4__p4_0[] = {
  133623. 2,
  133624. 1,
  133625. 3,
  133626. 0,
  133627. 4,
  133628. };
  133629. static long _vq_lengthlist__44u4__p4_0[] = {
  133630. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133631. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133632. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133633. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133634. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133635. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133636. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133637. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133638. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133639. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133640. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133641. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133642. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133643. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133644. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133645. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133646. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133647. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133648. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133649. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133650. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133651. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133652. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133653. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133654. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133655. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133656. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133657. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133658. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133659. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133660. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133661. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133662. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133663. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133664. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133665. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133666. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133667. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133668. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133669. 13,
  133670. };
  133671. static float _vq_quantthresh__44u4__p4_0[] = {
  133672. -1.5, -0.5, 0.5, 1.5,
  133673. };
  133674. static long _vq_quantmap__44u4__p4_0[] = {
  133675. 3, 1, 0, 2, 4,
  133676. };
  133677. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133678. _vq_quantthresh__44u4__p4_0,
  133679. _vq_quantmap__44u4__p4_0,
  133680. 5,
  133681. 5
  133682. };
  133683. static static_codebook _44u4__p4_0 = {
  133684. 4, 625,
  133685. _vq_lengthlist__44u4__p4_0,
  133686. 1, -533725184, 1611661312, 3, 0,
  133687. _vq_quantlist__44u4__p4_0,
  133688. NULL,
  133689. &_vq_auxt__44u4__p4_0,
  133690. NULL,
  133691. 0
  133692. };
  133693. static long _vq_quantlist__44u4__p5_0[] = {
  133694. 4,
  133695. 3,
  133696. 5,
  133697. 2,
  133698. 6,
  133699. 1,
  133700. 7,
  133701. 0,
  133702. 8,
  133703. };
  133704. static long _vq_lengthlist__44u4__p5_0[] = {
  133705. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133706. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133707. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  133708. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133709. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  133710. 12,
  133711. };
  133712. static float _vq_quantthresh__44u4__p5_0[] = {
  133713. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133714. };
  133715. static long _vq_quantmap__44u4__p5_0[] = {
  133716. 7, 5, 3, 1, 0, 2, 4, 6,
  133717. 8,
  133718. };
  133719. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  133720. _vq_quantthresh__44u4__p5_0,
  133721. _vq_quantmap__44u4__p5_0,
  133722. 9,
  133723. 9
  133724. };
  133725. static static_codebook _44u4__p5_0 = {
  133726. 2, 81,
  133727. _vq_lengthlist__44u4__p5_0,
  133728. 1, -531628032, 1611661312, 4, 0,
  133729. _vq_quantlist__44u4__p5_0,
  133730. NULL,
  133731. &_vq_auxt__44u4__p5_0,
  133732. NULL,
  133733. 0
  133734. };
  133735. static long _vq_quantlist__44u4__p6_0[] = {
  133736. 6,
  133737. 5,
  133738. 7,
  133739. 4,
  133740. 8,
  133741. 3,
  133742. 9,
  133743. 2,
  133744. 10,
  133745. 1,
  133746. 11,
  133747. 0,
  133748. 12,
  133749. };
  133750. static long _vq_lengthlist__44u4__p6_0[] = {
  133751. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  133752. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133753. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133754. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133755. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  133756. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  133757. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  133758. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  133759. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  133760. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  133761. 16,16,16,17,17,18,17,20,21,
  133762. };
  133763. static float _vq_quantthresh__44u4__p6_0[] = {
  133764. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133765. 12.5, 17.5, 22.5, 27.5,
  133766. };
  133767. static long _vq_quantmap__44u4__p6_0[] = {
  133768. 11, 9, 7, 5, 3, 1, 0, 2,
  133769. 4, 6, 8, 10, 12,
  133770. };
  133771. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  133772. _vq_quantthresh__44u4__p6_0,
  133773. _vq_quantmap__44u4__p6_0,
  133774. 13,
  133775. 13
  133776. };
  133777. static static_codebook _44u4__p6_0 = {
  133778. 2, 169,
  133779. _vq_lengthlist__44u4__p6_0,
  133780. 1, -526516224, 1616117760, 4, 0,
  133781. _vq_quantlist__44u4__p6_0,
  133782. NULL,
  133783. &_vq_auxt__44u4__p6_0,
  133784. NULL,
  133785. 0
  133786. };
  133787. static long _vq_quantlist__44u4__p6_1[] = {
  133788. 2,
  133789. 1,
  133790. 3,
  133791. 0,
  133792. 4,
  133793. };
  133794. static long _vq_lengthlist__44u4__p6_1[] = {
  133795. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133796. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133797. };
  133798. static float _vq_quantthresh__44u4__p6_1[] = {
  133799. -1.5, -0.5, 0.5, 1.5,
  133800. };
  133801. static long _vq_quantmap__44u4__p6_1[] = {
  133802. 3, 1, 0, 2, 4,
  133803. };
  133804. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  133805. _vq_quantthresh__44u4__p6_1,
  133806. _vq_quantmap__44u4__p6_1,
  133807. 5,
  133808. 5
  133809. };
  133810. static static_codebook _44u4__p6_1 = {
  133811. 2, 25,
  133812. _vq_lengthlist__44u4__p6_1,
  133813. 1, -533725184, 1611661312, 3, 0,
  133814. _vq_quantlist__44u4__p6_1,
  133815. NULL,
  133816. &_vq_auxt__44u4__p6_1,
  133817. NULL,
  133818. 0
  133819. };
  133820. static long _vq_quantlist__44u4__p7_0[] = {
  133821. 6,
  133822. 5,
  133823. 7,
  133824. 4,
  133825. 8,
  133826. 3,
  133827. 9,
  133828. 2,
  133829. 10,
  133830. 1,
  133831. 11,
  133832. 0,
  133833. 12,
  133834. };
  133835. static long _vq_lengthlist__44u4__p7_0[] = {
  133836. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  133837. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  133838. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133839. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133840. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133841. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133842. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133843. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133844. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133845. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133846. 11,11,11,11,11,11,11,11,11,
  133847. };
  133848. static float _vq_quantthresh__44u4__p7_0[] = {
  133849. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  133850. 637.5, 892.5, 1147.5, 1402.5,
  133851. };
  133852. static long _vq_quantmap__44u4__p7_0[] = {
  133853. 11, 9, 7, 5, 3, 1, 0, 2,
  133854. 4, 6, 8, 10, 12,
  133855. };
  133856. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  133857. _vq_quantthresh__44u4__p7_0,
  133858. _vq_quantmap__44u4__p7_0,
  133859. 13,
  133860. 13
  133861. };
  133862. static static_codebook _44u4__p7_0 = {
  133863. 2, 169,
  133864. _vq_lengthlist__44u4__p7_0,
  133865. 1, -514332672, 1627381760, 4, 0,
  133866. _vq_quantlist__44u4__p7_0,
  133867. NULL,
  133868. &_vq_auxt__44u4__p7_0,
  133869. NULL,
  133870. 0
  133871. };
  133872. static long _vq_quantlist__44u4__p7_1[] = {
  133873. 7,
  133874. 6,
  133875. 8,
  133876. 5,
  133877. 9,
  133878. 4,
  133879. 10,
  133880. 3,
  133881. 11,
  133882. 2,
  133883. 12,
  133884. 1,
  133885. 13,
  133886. 0,
  133887. 14,
  133888. };
  133889. static long _vq_lengthlist__44u4__p7_1[] = {
  133890. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  133891. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  133892. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  133893. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  133894. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  133895. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  133896. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  133897. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  133898. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  133899. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  133900. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  133901. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  133902. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  133903. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  133904. 16,
  133905. };
  133906. static float _vq_quantthresh__44u4__p7_1[] = {
  133907. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133908. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133909. };
  133910. static long _vq_quantmap__44u4__p7_1[] = {
  133911. 13, 11, 9, 7, 5, 3, 1, 0,
  133912. 2, 4, 6, 8, 10, 12, 14,
  133913. };
  133914. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  133915. _vq_quantthresh__44u4__p7_1,
  133916. _vq_quantmap__44u4__p7_1,
  133917. 15,
  133918. 15
  133919. };
  133920. static static_codebook _44u4__p7_1 = {
  133921. 2, 225,
  133922. _vq_lengthlist__44u4__p7_1,
  133923. 1, -522338304, 1620115456, 4, 0,
  133924. _vq_quantlist__44u4__p7_1,
  133925. NULL,
  133926. &_vq_auxt__44u4__p7_1,
  133927. NULL,
  133928. 0
  133929. };
  133930. static long _vq_quantlist__44u4__p7_2[] = {
  133931. 8,
  133932. 7,
  133933. 9,
  133934. 6,
  133935. 10,
  133936. 5,
  133937. 11,
  133938. 4,
  133939. 12,
  133940. 3,
  133941. 13,
  133942. 2,
  133943. 14,
  133944. 1,
  133945. 15,
  133946. 0,
  133947. 16,
  133948. };
  133949. static long _vq_lengthlist__44u4__p7_2[] = {
  133950. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133951. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133952. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133953. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133954. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133955. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133956. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133957. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  133958. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  133959. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  133960. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133961. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  133962. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  133963. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  133964. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  133965. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  133966. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133967. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  133968. 10,
  133969. };
  133970. static float _vq_quantthresh__44u4__p7_2[] = {
  133971. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133972. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133973. };
  133974. static long _vq_quantmap__44u4__p7_2[] = {
  133975. 15, 13, 11, 9, 7, 5, 3, 1,
  133976. 0, 2, 4, 6, 8, 10, 12, 14,
  133977. 16,
  133978. };
  133979. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  133980. _vq_quantthresh__44u4__p7_2,
  133981. _vq_quantmap__44u4__p7_2,
  133982. 17,
  133983. 17
  133984. };
  133985. static static_codebook _44u4__p7_2 = {
  133986. 2, 289,
  133987. _vq_lengthlist__44u4__p7_2,
  133988. 1, -529530880, 1611661312, 5, 0,
  133989. _vq_quantlist__44u4__p7_2,
  133990. NULL,
  133991. &_vq_auxt__44u4__p7_2,
  133992. NULL,
  133993. 0
  133994. };
  133995. static long _huff_lengthlist__44u4__short[] = {
  133996. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  133997. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  133998. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  133999. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134000. };
  134001. static static_codebook _huff_book__44u4__short = {
  134002. 2, 64,
  134003. _huff_lengthlist__44u4__short,
  134004. 0, 0, 0, 0, 0,
  134005. NULL,
  134006. NULL,
  134007. NULL,
  134008. NULL,
  134009. 0
  134010. };
  134011. static long _huff_lengthlist__44u5__long[] = {
  134012. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134013. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134014. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134015. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134016. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134017. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134018. 14, 8, 7, 8,
  134019. };
  134020. static static_codebook _huff_book__44u5__long = {
  134021. 2, 100,
  134022. _huff_lengthlist__44u5__long,
  134023. 0, 0, 0, 0, 0,
  134024. NULL,
  134025. NULL,
  134026. NULL,
  134027. NULL,
  134028. 0
  134029. };
  134030. static long _vq_quantlist__44u5__p1_0[] = {
  134031. 1,
  134032. 0,
  134033. 2,
  134034. };
  134035. static long _vq_lengthlist__44u5__p1_0[] = {
  134036. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134037. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134038. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134039. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134040. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134041. 12,
  134042. };
  134043. static float _vq_quantthresh__44u5__p1_0[] = {
  134044. -0.5, 0.5,
  134045. };
  134046. static long _vq_quantmap__44u5__p1_0[] = {
  134047. 1, 0, 2,
  134048. };
  134049. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134050. _vq_quantthresh__44u5__p1_0,
  134051. _vq_quantmap__44u5__p1_0,
  134052. 3,
  134053. 3
  134054. };
  134055. static static_codebook _44u5__p1_0 = {
  134056. 4, 81,
  134057. _vq_lengthlist__44u5__p1_0,
  134058. 1, -535822336, 1611661312, 2, 0,
  134059. _vq_quantlist__44u5__p1_0,
  134060. NULL,
  134061. &_vq_auxt__44u5__p1_0,
  134062. NULL,
  134063. 0
  134064. };
  134065. static long _vq_quantlist__44u5__p2_0[] = {
  134066. 1,
  134067. 0,
  134068. 2,
  134069. };
  134070. static long _vq_lengthlist__44u5__p2_0[] = {
  134071. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134072. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134073. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134074. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134075. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134076. 9,
  134077. };
  134078. static float _vq_quantthresh__44u5__p2_0[] = {
  134079. -0.5, 0.5,
  134080. };
  134081. static long _vq_quantmap__44u5__p2_0[] = {
  134082. 1, 0, 2,
  134083. };
  134084. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134085. _vq_quantthresh__44u5__p2_0,
  134086. _vq_quantmap__44u5__p2_0,
  134087. 3,
  134088. 3
  134089. };
  134090. static static_codebook _44u5__p2_0 = {
  134091. 4, 81,
  134092. _vq_lengthlist__44u5__p2_0,
  134093. 1, -535822336, 1611661312, 2, 0,
  134094. _vq_quantlist__44u5__p2_0,
  134095. NULL,
  134096. &_vq_auxt__44u5__p2_0,
  134097. NULL,
  134098. 0
  134099. };
  134100. static long _vq_quantlist__44u5__p3_0[] = {
  134101. 2,
  134102. 1,
  134103. 3,
  134104. 0,
  134105. 4,
  134106. };
  134107. static long _vq_lengthlist__44u5__p3_0[] = {
  134108. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134109. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134110. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134111. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134112. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134113. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134114. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134115. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134116. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134117. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134118. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134119. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134120. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134121. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134122. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134123. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134124. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134125. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134126. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134127. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134128. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134129. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134130. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134131. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134132. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134133. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134134. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134135. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134136. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134137. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134138. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134139. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134140. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134141. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134142. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134143. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134144. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134145. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134146. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134147. 0,
  134148. };
  134149. static float _vq_quantthresh__44u5__p3_0[] = {
  134150. -1.5, -0.5, 0.5, 1.5,
  134151. };
  134152. static long _vq_quantmap__44u5__p3_0[] = {
  134153. 3, 1, 0, 2, 4,
  134154. };
  134155. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134156. _vq_quantthresh__44u5__p3_0,
  134157. _vq_quantmap__44u5__p3_0,
  134158. 5,
  134159. 5
  134160. };
  134161. static static_codebook _44u5__p3_0 = {
  134162. 4, 625,
  134163. _vq_lengthlist__44u5__p3_0,
  134164. 1, -533725184, 1611661312, 3, 0,
  134165. _vq_quantlist__44u5__p3_0,
  134166. NULL,
  134167. &_vq_auxt__44u5__p3_0,
  134168. NULL,
  134169. 0
  134170. };
  134171. static long _vq_quantlist__44u5__p4_0[] = {
  134172. 2,
  134173. 1,
  134174. 3,
  134175. 0,
  134176. 4,
  134177. };
  134178. static long _vq_lengthlist__44u5__p4_0[] = {
  134179. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134180. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134181. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134182. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134183. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134184. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134185. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134186. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134187. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134188. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134189. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134190. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134191. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134192. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134193. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134194. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134195. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134196. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134197. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134198. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134199. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134200. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134201. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134202. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134203. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134204. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134205. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134206. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134207. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134208. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134209. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134210. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134211. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134212. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134213. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134214. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134215. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134216. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134217. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134218. 12,
  134219. };
  134220. static float _vq_quantthresh__44u5__p4_0[] = {
  134221. -1.5, -0.5, 0.5, 1.5,
  134222. };
  134223. static long _vq_quantmap__44u5__p4_0[] = {
  134224. 3, 1, 0, 2, 4,
  134225. };
  134226. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134227. _vq_quantthresh__44u5__p4_0,
  134228. _vq_quantmap__44u5__p4_0,
  134229. 5,
  134230. 5
  134231. };
  134232. static static_codebook _44u5__p4_0 = {
  134233. 4, 625,
  134234. _vq_lengthlist__44u5__p4_0,
  134235. 1, -533725184, 1611661312, 3, 0,
  134236. _vq_quantlist__44u5__p4_0,
  134237. NULL,
  134238. &_vq_auxt__44u5__p4_0,
  134239. NULL,
  134240. 0
  134241. };
  134242. static long _vq_quantlist__44u5__p5_0[] = {
  134243. 4,
  134244. 3,
  134245. 5,
  134246. 2,
  134247. 6,
  134248. 1,
  134249. 7,
  134250. 0,
  134251. 8,
  134252. };
  134253. static long _vq_lengthlist__44u5__p5_0[] = {
  134254. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134255. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134256. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134257. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134258. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134259. 14,
  134260. };
  134261. static float _vq_quantthresh__44u5__p5_0[] = {
  134262. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134263. };
  134264. static long _vq_quantmap__44u5__p5_0[] = {
  134265. 7, 5, 3, 1, 0, 2, 4, 6,
  134266. 8,
  134267. };
  134268. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134269. _vq_quantthresh__44u5__p5_0,
  134270. _vq_quantmap__44u5__p5_0,
  134271. 9,
  134272. 9
  134273. };
  134274. static static_codebook _44u5__p5_0 = {
  134275. 2, 81,
  134276. _vq_lengthlist__44u5__p5_0,
  134277. 1, -531628032, 1611661312, 4, 0,
  134278. _vq_quantlist__44u5__p5_0,
  134279. NULL,
  134280. &_vq_auxt__44u5__p5_0,
  134281. NULL,
  134282. 0
  134283. };
  134284. static long _vq_quantlist__44u5__p6_0[] = {
  134285. 4,
  134286. 3,
  134287. 5,
  134288. 2,
  134289. 6,
  134290. 1,
  134291. 7,
  134292. 0,
  134293. 8,
  134294. };
  134295. static long _vq_lengthlist__44u5__p6_0[] = {
  134296. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134297. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134298. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134299. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134300. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134301. 11,
  134302. };
  134303. static float _vq_quantthresh__44u5__p6_0[] = {
  134304. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134305. };
  134306. static long _vq_quantmap__44u5__p6_0[] = {
  134307. 7, 5, 3, 1, 0, 2, 4, 6,
  134308. 8,
  134309. };
  134310. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134311. _vq_quantthresh__44u5__p6_0,
  134312. _vq_quantmap__44u5__p6_0,
  134313. 9,
  134314. 9
  134315. };
  134316. static static_codebook _44u5__p6_0 = {
  134317. 2, 81,
  134318. _vq_lengthlist__44u5__p6_0,
  134319. 1, -531628032, 1611661312, 4, 0,
  134320. _vq_quantlist__44u5__p6_0,
  134321. NULL,
  134322. &_vq_auxt__44u5__p6_0,
  134323. NULL,
  134324. 0
  134325. };
  134326. static long _vq_quantlist__44u5__p7_0[] = {
  134327. 1,
  134328. 0,
  134329. 2,
  134330. };
  134331. static long _vq_lengthlist__44u5__p7_0[] = {
  134332. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134333. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134334. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134335. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134336. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134337. 12,
  134338. };
  134339. static float _vq_quantthresh__44u5__p7_0[] = {
  134340. -5.5, 5.5,
  134341. };
  134342. static long _vq_quantmap__44u5__p7_0[] = {
  134343. 1, 0, 2,
  134344. };
  134345. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134346. _vq_quantthresh__44u5__p7_0,
  134347. _vq_quantmap__44u5__p7_0,
  134348. 3,
  134349. 3
  134350. };
  134351. static static_codebook _44u5__p7_0 = {
  134352. 4, 81,
  134353. _vq_lengthlist__44u5__p7_0,
  134354. 1, -529137664, 1618345984, 2, 0,
  134355. _vq_quantlist__44u5__p7_0,
  134356. NULL,
  134357. &_vq_auxt__44u5__p7_0,
  134358. NULL,
  134359. 0
  134360. };
  134361. static long _vq_quantlist__44u5__p7_1[] = {
  134362. 5,
  134363. 4,
  134364. 6,
  134365. 3,
  134366. 7,
  134367. 2,
  134368. 8,
  134369. 1,
  134370. 9,
  134371. 0,
  134372. 10,
  134373. };
  134374. static long _vq_lengthlist__44u5__p7_1[] = {
  134375. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134376. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134377. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134378. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134379. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134380. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134381. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134382. 9, 9, 9, 9, 9,10,10,10,10,
  134383. };
  134384. static float _vq_quantthresh__44u5__p7_1[] = {
  134385. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134386. 3.5, 4.5,
  134387. };
  134388. static long _vq_quantmap__44u5__p7_1[] = {
  134389. 9, 7, 5, 3, 1, 0, 2, 4,
  134390. 6, 8, 10,
  134391. };
  134392. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134393. _vq_quantthresh__44u5__p7_1,
  134394. _vq_quantmap__44u5__p7_1,
  134395. 11,
  134396. 11
  134397. };
  134398. static static_codebook _44u5__p7_1 = {
  134399. 2, 121,
  134400. _vq_lengthlist__44u5__p7_1,
  134401. 1, -531365888, 1611661312, 4, 0,
  134402. _vq_quantlist__44u5__p7_1,
  134403. NULL,
  134404. &_vq_auxt__44u5__p7_1,
  134405. NULL,
  134406. 0
  134407. };
  134408. static long _vq_quantlist__44u5__p8_0[] = {
  134409. 5,
  134410. 4,
  134411. 6,
  134412. 3,
  134413. 7,
  134414. 2,
  134415. 8,
  134416. 1,
  134417. 9,
  134418. 0,
  134419. 10,
  134420. };
  134421. static long _vq_lengthlist__44u5__p8_0[] = {
  134422. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134423. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134424. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134425. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134426. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134427. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134428. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134429. 12,13,13,14,14,14,14,15,15,
  134430. };
  134431. static float _vq_quantthresh__44u5__p8_0[] = {
  134432. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134433. 38.5, 49.5,
  134434. };
  134435. static long _vq_quantmap__44u5__p8_0[] = {
  134436. 9, 7, 5, 3, 1, 0, 2, 4,
  134437. 6, 8, 10,
  134438. };
  134439. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134440. _vq_quantthresh__44u5__p8_0,
  134441. _vq_quantmap__44u5__p8_0,
  134442. 11,
  134443. 11
  134444. };
  134445. static static_codebook _44u5__p8_0 = {
  134446. 2, 121,
  134447. _vq_lengthlist__44u5__p8_0,
  134448. 1, -524582912, 1618345984, 4, 0,
  134449. _vq_quantlist__44u5__p8_0,
  134450. NULL,
  134451. &_vq_auxt__44u5__p8_0,
  134452. NULL,
  134453. 0
  134454. };
  134455. static long _vq_quantlist__44u5__p8_1[] = {
  134456. 5,
  134457. 4,
  134458. 6,
  134459. 3,
  134460. 7,
  134461. 2,
  134462. 8,
  134463. 1,
  134464. 9,
  134465. 0,
  134466. 10,
  134467. };
  134468. static long _vq_lengthlist__44u5__p8_1[] = {
  134469. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134470. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134471. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134472. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134473. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134474. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134475. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134476. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134477. };
  134478. static float _vq_quantthresh__44u5__p8_1[] = {
  134479. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134480. 3.5, 4.5,
  134481. };
  134482. static long _vq_quantmap__44u5__p8_1[] = {
  134483. 9, 7, 5, 3, 1, 0, 2, 4,
  134484. 6, 8, 10,
  134485. };
  134486. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134487. _vq_quantthresh__44u5__p8_1,
  134488. _vq_quantmap__44u5__p8_1,
  134489. 11,
  134490. 11
  134491. };
  134492. static static_codebook _44u5__p8_1 = {
  134493. 2, 121,
  134494. _vq_lengthlist__44u5__p8_1,
  134495. 1, -531365888, 1611661312, 4, 0,
  134496. _vq_quantlist__44u5__p8_1,
  134497. NULL,
  134498. &_vq_auxt__44u5__p8_1,
  134499. NULL,
  134500. 0
  134501. };
  134502. static long _vq_quantlist__44u5__p9_0[] = {
  134503. 6,
  134504. 5,
  134505. 7,
  134506. 4,
  134507. 8,
  134508. 3,
  134509. 9,
  134510. 2,
  134511. 10,
  134512. 1,
  134513. 11,
  134514. 0,
  134515. 12,
  134516. };
  134517. static long _vq_lengthlist__44u5__p9_0[] = {
  134518. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134519. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134520. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134521. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134522. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134523. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134524. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134525. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134526. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134527. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134528. 12,12,12,12,12,12,12,12,12,
  134529. };
  134530. static float _vq_quantthresh__44u5__p9_0[] = {
  134531. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134532. 637.5, 892.5, 1147.5, 1402.5,
  134533. };
  134534. static long _vq_quantmap__44u5__p9_0[] = {
  134535. 11, 9, 7, 5, 3, 1, 0, 2,
  134536. 4, 6, 8, 10, 12,
  134537. };
  134538. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134539. _vq_quantthresh__44u5__p9_0,
  134540. _vq_quantmap__44u5__p9_0,
  134541. 13,
  134542. 13
  134543. };
  134544. static static_codebook _44u5__p9_0 = {
  134545. 2, 169,
  134546. _vq_lengthlist__44u5__p9_0,
  134547. 1, -514332672, 1627381760, 4, 0,
  134548. _vq_quantlist__44u5__p9_0,
  134549. NULL,
  134550. &_vq_auxt__44u5__p9_0,
  134551. NULL,
  134552. 0
  134553. };
  134554. static long _vq_quantlist__44u5__p9_1[] = {
  134555. 7,
  134556. 6,
  134557. 8,
  134558. 5,
  134559. 9,
  134560. 4,
  134561. 10,
  134562. 3,
  134563. 11,
  134564. 2,
  134565. 12,
  134566. 1,
  134567. 13,
  134568. 0,
  134569. 14,
  134570. };
  134571. static long _vq_lengthlist__44u5__p9_1[] = {
  134572. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134573. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134574. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134575. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134576. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134577. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134578. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134579. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134580. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134581. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134582. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134583. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134584. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134585. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134586. 14,
  134587. };
  134588. static float _vq_quantthresh__44u5__p9_1[] = {
  134589. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134590. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134591. };
  134592. static long _vq_quantmap__44u5__p9_1[] = {
  134593. 13, 11, 9, 7, 5, 3, 1, 0,
  134594. 2, 4, 6, 8, 10, 12, 14,
  134595. };
  134596. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134597. _vq_quantthresh__44u5__p9_1,
  134598. _vq_quantmap__44u5__p9_1,
  134599. 15,
  134600. 15
  134601. };
  134602. static static_codebook _44u5__p9_1 = {
  134603. 2, 225,
  134604. _vq_lengthlist__44u5__p9_1,
  134605. 1, -522338304, 1620115456, 4, 0,
  134606. _vq_quantlist__44u5__p9_1,
  134607. NULL,
  134608. &_vq_auxt__44u5__p9_1,
  134609. NULL,
  134610. 0
  134611. };
  134612. static long _vq_quantlist__44u5__p9_2[] = {
  134613. 8,
  134614. 7,
  134615. 9,
  134616. 6,
  134617. 10,
  134618. 5,
  134619. 11,
  134620. 4,
  134621. 12,
  134622. 3,
  134623. 13,
  134624. 2,
  134625. 14,
  134626. 1,
  134627. 15,
  134628. 0,
  134629. 16,
  134630. };
  134631. static long _vq_lengthlist__44u5__p9_2[] = {
  134632. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134633. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134634. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134635. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134636. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134637. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134638. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134639. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134640. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134641. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134642. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134643. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134644. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134645. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134646. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134647. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134648. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134649. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134650. 10,
  134651. };
  134652. static float _vq_quantthresh__44u5__p9_2[] = {
  134653. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134654. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134655. };
  134656. static long _vq_quantmap__44u5__p9_2[] = {
  134657. 15, 13, 11, 9, 7, 5, 3, 1,
  134658. 0, 2, 4, 6, 8, 10, 12, 14,
  134659. 16,
  134660. };
  134661. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134662. _vq_quantthresh__44u5__p9_2,
  134663. _vq_quantmap__44u5__p9_2,
  134664. 17,
  134665. 17
  134666. };
  134667. static static_codebook _44u5__p9_2 = {
  134668. 2, 289,
  134669. _vq_lengthlist__44u5__p9_2,
  134670. 1, -529530880, 1611661312, 5, 0,
  134671. _vq_quantlist__44u5__p9_2,
  134672. NULL,
  134673. &_vq_auxt__44u5__p9_2,
  134674. NULL,
  134675. 0
  134676. };
  134677. static long _huff_lengthlist__44u5__short[] = {
  134678. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134679. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134680. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134681. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134682. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134683. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134684. 6, 8,15,17,
  134685. };
  134686. static static_codebook _huff_book__44u5__short = {
  134687. 2, 100,
  134688. _huff_lengthlist__44u5__short,
  134689. 0, 0, 0, 0, 0,
  134690. NULL,
  134691. NULL,
  134692. NULL,
  134693. NULL,
  134694. 0
  134695. };
  134696. static long _huff_lengthlist__44u6__long[] = {
  134697. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  134698. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  134699. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  134700. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  134701. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  134702. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  134703. 13, 8, 7, 7,
  134704. };
  134705. static static_codebook _huff_book__44u6__long = {
  134706. 2, 100,
  134707. _huff_lengthlist__44u6__long,
  134708. 0, 0, 0, 0, 0,
  134709. NULL,
  134710. NULL,
  134711. NULL,
  134712. NULL,
  134713. 0
  134714. };
  134715. static long _vq_quantlist__44u6__p1_0[] = {
  134716. 1,
  134717. 0,
  134718. 2,
  134719. };
  134720. static long _vq_lengthlist__44u6__p1_0[] = {
  134721. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134722. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134723. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134724. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  134725. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134726. 12,
  134727. };
  134728. static float _vq_quantthresh__44u6__p1_0[] = {
  134729. -0.5, 0.5,
  134730. };
  134731. static long _vq_quantmap__44u6__p1_0[] = {
  134732. 1, 0, 2,
  134733. };
  134734. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  134735. _vq_quantthresh__44u6__p1_0,
  134736. _vq_quantmap__44u6__p1_0,
  134737. 3,
  134738. 3
  134739. };
  134740. static static_codebook _44u6__p1_0 = {
  134741. 4, 81,
  134742. _vq_lengthlist__44u6__p1_0,
  134743. 1, -535822336, 1611661312, 2, 0,
  134744. _vq_quantlist__44u6__p1_0,
  134745. NULL,
  134746. &_vq_auxt__44u6__p1_0,
  134747. NULL,
  134748. 0
  134749. };
  134750. static long _vq_quantlist__44u6__p2_0[] = {
  134751. 1,
  134752. 0,
  134753. 2,
  134754. };
  134755. static long _vq_lengthlist__44u6__p2_0[] = {
  134756. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134757. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134758. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  134759. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134760. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134761. 9,
  134762. };
  134763. static float _vq_quantthresh__44u6__p2_0[] = {
  134764. -0.5, 0.5,
  134765. };
  134766. static long _vq_quantmap__44u6__p2_0[] = {
  134767. 1, 0, 2,
  134768. };
  134769. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  134770. _vq_quantthresh__44u6__p2_0,
  134771. _vq_quantmap__44u6__p2_0,
  134772. 3,
  134773. 3
  134774. };
  134775. static static_codebook _44u6__p2_0 = {
  134776. 4, 81,
  134777. _vq_lengthlist__44u6__p2_0,
  134778. 1, -535822336, 1611661312, 2, 0,
  134779. _vq_quantlist__44u6__p2_0,
  134780. NULL,
  134781. &_vq_auxt__44u6__p2_0,
  134782. NULL,
  134783. 0
  134784. };
  134785. static long _vq_quantlist__44u6__p3_0[] = {
  134786. 2,
  134787. 1,
  134788. 3,
  134789. 0,
  134790. 4,
  134791. };
  134792. static long _vq_lengthlist__44u6__p3_0[] = {
  134793. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134794. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  134795. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134796. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  134797. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  134798. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  134799. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  134800. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  134801. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  134802. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134803. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  134804. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134805. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  134806. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  134807. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  134808. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  134809. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134810. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  134811. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  134812. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  134813. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  134814. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  134815. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  134816. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  134817. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  134818. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  134819. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  134820. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  134821. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  134822. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  134823. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  134824. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  134825. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  134826. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  134827. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  134828. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  134829. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  134830. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  134831. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  134832. 19,
  134833. };
  134834. static float _vq_quantthresh__44u6__p3_0[] = {
  134835. -1.5, -0.5, 0.5, 1.5,
  134836. };
  134837. static long _vq_quantmap__44u6__p3_0[] = {
  134838. 3, 1, 0, 2, 4,
  134839. };
  134840. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  134841. _vq_quantthresh__44u6__p3_0,
  134842. _vq_quantmap__44u6__p3_0,
  134843. 5,
  134844. 5
  134845. };
  134846. static static_codebook _44u6__p3_0 = {
  134847. 4, 625,
  134848. _vq_lengthlist__44u6__p3_0,
  134849. 1, -533725184, 1611661312, 3, 0,
  134850. _vq_quantlist__44u6__p3_0,
  134851. NULL,
  134852. &_vq_auxt__44u6__p3_0,
  134853. NULL,
  134854. 0
  134855. };
  134856. static long _vq_quantlist__44u6__p4_0[] = {
  134857. 2,
  134858. 1,
  134859. 3,
  134860. 0,
  134861. 4,
  134862. };
  134863. static long _vq_lengthlist__44u6__p4_0[] = {
  134864. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134865. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134866. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  134867. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  134868. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  134869. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  134870. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  134871. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  134872. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  134873. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  134874. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  134875. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  134876. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134877. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  134878. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  134879. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  134880. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  134881. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  134882. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134883. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  134884. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  134885. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  134886. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  134887. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  134888. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  134889. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  134890. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  134891. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  134892. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  134893. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  134894. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  134895. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  134896. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  134897. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  134898. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  134899. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  134900. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  134901. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  134902. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  134903. 13,
  134904. };
  134905. static float _vq_quantthresh__44u6__p4_0[] = {
  134906. -1.5, -0.5, 0.5, 1.5,
  134907. };
  134908. static long _vq_quantmap__44u6__p4_0[] = {
  134909. 3, 1, 0, 2, 4,
  134910. };
  134911. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  134912. _vq_quantthresh__44u6__p4_0,
  134913. _vq_quantmap__44u6__p4_0,
  134914. 5,
  134915. 5
  134916. };
  134917. static static_codebook _44u6__p4_0 = {
  134918. 4, 625,
  134919. _vq_lengthlist__44u6__p4_0,
  134920. 1, -533725184, 1611661312, 3, 0,
  134921. _vq_quantlist__44u6__p4_0,
  134922. NULL,
  134923. &_vq_auxt__44u6__p4_0,
  134924. NULL,
  134925. 0
  134926. };
  134927. static long _vq_quantlist__44u6__p5_0[] = {
  134928. 4,
  134929. 3,
  134930. 5,
  134931. 2,
  134932. 6,
  134933. 1,
  134934. 7,
  134935. 0,
  134936. 8,
  134937. };
  134938. static long _vq_lengthlist__44u6__p5_0[] = {
  134939. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134940. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  134941. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134942. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  134943. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  134944. 14,
  134945. };
  134946. static float _vq_quantthresh__44u6__p5_0[] = {
  134947. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134948. };
  134949. static long _vq_quantmap__44u6__p5_0[] = {
  134950. 7, 5, 3, 1, 0, 2, 4, 6,
  134951. 8,
  134952. };
  134953. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  134954. _vq_quantthresh__44u6__p5_0,
  134955. _vq_quantmap__44u6__p5_0,
  134956. 9,
  134957. 9
  134958. };
  134959. static static_codebook _44u6__p5_0 = {
  134960. 2, 81,
  134961. _vq_lengthlist__44u6__p5_0,
  134962. 1, -531628032, 1611661312, 4, 0,
  134963. _vq_quantlist__44u6__p5_0,
  134964. NULL,
  134965. &_vq_auxt__44u6__p5_0,
  134966. NULL,
  134967. 0
  134968. };
  134969. static long _vq_quantlist__44u6__p6_0[] = {
  134970. 4,
  134971. 3,
  134972. 5,
  134973. 2,
  134974. 6,
  134975. 1,
  134976. 7,
  134977. 0,
  134978. 8,
  134979. };
  134980. static long _vq_lengthlist__44u6__p6_0[] = {
  134981. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134982. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  134983. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  134984. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  134985. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  134986. 12,
  134987. };
  134988. static float _vq_quantthresh__44u6__p6_0[] = {
  134989. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134990. };
  134991. static long _vq_quantmap__44u6__p6_0[] = {
  134992. 7, 5, 3, 1, 0, 2, 4, 6,
  134993. 8,
  134994. };
  134995. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  134996. _vq_quantthresh__44u6__p6_0,
  134997. _vq_quantmap__44u6__p6_0,
  134998. 9,
  134999. 9
  135000. };
  135001. static static_codebook _44u6__p6_0 = {
  135002. 2, 81,
  135003. _vq_lengthlist__44u6__p6_0,
  135004. 1, -531628032, 1611661312, 4, 0,
  135005. _vq_quantlist__44u6__p6_0,
  135006. NULL,
  135007. &_vq_auxt__44u6__p6_0,
  135008. NULL,
  135009. 0
  135010. };
  135011. static long _vq_quantlist__44u6__p7_0[] = {
  135012. 1,
  135013. 0,
  135014. 2,
  135015. };
  135016. static long _vq_lengthlist__44u6__p7_0[] = {
  135017. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135018. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135019. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135020. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135021. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135022. 10,
  135023. };
  135024. static float _vq_quantthresh__44u6__p7_0[] = {
  135025. -5.5, 5.5,
  135026. };
  135027. static long _vq_quantmap__44u6__p7_0[] = {
  135028. 1, 0, 2,
  135029. };
  135030. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135031. _vq_quantthresh__44u6__p7_0,
  135032. _vq_quantmap__44u6__p7_0,
  135033. 3,
  135034. 3
  135035. };
  135036. static static_codebook _44u6__p7_0 = {
  135037. 4, 81,
  135038. _vq_lengthlist__44u6__p7_0,
  135039. 1, -529137664, 1618345984, 2, 0,
  135040. _vq_quantlist__44u6__p7_0,
  135041. NULL,
  135042. &_vq_auxt__44u6__p7_0,
  135043. NULL,
  135044. 0
  135045. };
  135046. static long _vq_quantlist__44u6__p7_1[] = {
  135047. 5,
  135048. 4,
  135049. 6,
  135050. 3,
  135051. 7,
  135052. 2,
  135053. 8,
  135054. 1,
  135055. 9,
  135056. 0,
  135057. 10,
  135058. };
  135059. static long _vq_lengthlist__44u6__p7_1[] = {
  135060. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135061. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135062. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135063. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135064. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135065. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135066. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135067. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135068. };
  135069. static float _vq_quantthresh__44u6__p7_1[] = {
  135070. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135071. 3.5, 4.5,
  135072. };
  135073. static long _vq_quantmap__44u6__p7_1[] = {
  135074. 9, 7, 5, 3, 1, 0, 2, 4,
  135075. 6, 8, 10,
  135076. };
  135077. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135078. _vq_quantthresh__44u6__p7_1,
  135079. _vq_quantmap__44u6__p7_1,
  135080. 11,
  135081. 11
  135082. };
  135083. static static_codebook _44u6__p7_1 = {
  135084. 2, 121,
  135085. _vq_lengthlist__44u6__p7_1,
  135086. 1, -531365888, 1611661312, 4, 0,
  135087. _vq_quantlist__44u6__p7_1,
  135088. NULL,
  135089. &_vq_auxt__44u6__p7_1,
  135090. NULL,
  135091. 0
  135092. };
  135093. static long _vq_quantlist__44u6__p8_0[] = {
  135094. 5,
  135095. 4,
  135096. 6,
  135097. 3,
  135098. 7,
  135099. 2,
  135100. 8,
  135101. 1,
  135102. 9,
  135103. 0,
  135104. 10,
  135105. };
  135106. static long _vq_lengthlist__44u6__p8_0[] = {
  135107. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135108. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135109. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135110. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135111. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135112. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135113. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135114. 12,13,13,14,14,14,15,15,15,
  135115. };
  135116. static float _vq_quantthresh__44u6__p8_0[] = {
  135117. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135118. 38.5, 49.5,
  135119. };
  135120. static long _vq_quantmap__44u6__p8_0[] = {
  135121. 9, 7, 5, 3, 1, 0, 2, 4,
  135122. 6, 8, 10,
  135123. };
  135124. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135125. _vq_quantthresh__44u6__p8_0,
  135126. _vq_quantmap__44u6__p8_0,
  135127. 11,
  135128. 11
  135129. };
  135130. static static_codebook _44u6__p8_0 = {
  135131. 2, 121,
  135132. _vq_lengthlist__44u6__p8_0,
  135133. 1, -524582912, 1618345984, 4, 0,
  135134. _vq_quantlist__44u6__p8_0,
  135135. NULL,
  135136. &_vq_auxt__44u6__p8_0,
  135137. NULL,
  135138. 0
  135139. };
  135140. static long _vq_quantlist__44u6__p8_1[] = {
  135141. 5,
  135142. 4,
  135143. 6,
  135144. 3,
  135145. 7,
  135146. 2,
  135147. 8,
  135148. 1,
  135149. 9,
  135150. 0,
  135151. 10,
  135152. };
  135153. static long _vq_lengthlist__44u6__p8_1[] = {
  135154. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135155. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135156. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135157. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135158. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135159. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135160. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135161. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135162. };
  135163. static float _vq_quantthresh__44u6__p8_1[] = {
  135164. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135165. 3.5, 4.5,
  135166. };
  135167. static long _vq_quantmap__44u6__p8_1[] = {
  135168. 9, 7, 5, 3, 1, 0, 2, 4,
  135169. 6, 8, 10,
  135170. };
  135171. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135172. _vq_quantthresh__44u6__p8_1,
  135173. _vq_quantmap__44u6__p8_1,
  135174. 11,
  135175. 11
  135176. };
  135177. static static_codebook _44u6__p8_1 = {
  135178. 2, 121,
  135179. _vq_lengthlist__44u6__p8_1,
  135180. 1, -531365888, 1611661312, 4, 0,
  135181. _vq_quantlist__44u6__p8_1,
  135182. NULL,
  135183. &_vq_auxt__44u6__p8_1,
  135184. NULL,
  135185. 0
  135186. };
  135187. static long _vq_quantlist__44u6__p9_0[] = {
  135188. 7,
  135189. 6,
  135190. 8,
  135191. 5,
  135192. 9,
  135193. 4,
  135194. 10,
  135195. 3,
  135196. 11,
  135197. 2,
  135198. 12,
  135199. 1,
  135200. 13,
  135201. 0,
  135202. 14,
  135203. };
  135204. static long _vq_lengthlist__44u6__p9_0[] = {
  135205. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135206. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135207. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135208. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135209. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135210. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135211. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135212. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135213. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135214. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135215. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135216. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135217. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135218. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135219. 14,
  135220. };
  135221. static float _vq_quantthresh__44u6__p9_0[] = {
  135222. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135223. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135224. };
  135225. static long _vq_quantmap__44u6__p9_0[] = {
  135226. 13, 11, 9, 7, 5, 3, 1, 0,
  135227. 2, 4, 6, 8, 10, 12, 14,
  135228. };
  135229. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135230. _vq_quantthresh__44u6__p9_0,
  135231. _vq_quantmap__44u6__p9_0,
  135232. 15,
  135233. 15
  135234. };
  135235. static static_codebook _44u6__p9_0 = {
  135236. 2, 225,
  135237. _vq_lengthlist__44u6__p9_0,
  135238. 1, -514071552, 1627381760, 4, 0,
  135239. _vq_quantlist__44u6__p9_0,
  135240. NULL,
  135241. &_vq_auxt__44u6__p9_0,
  135242. NULL,
  135243. 0
  135244. };
  135245. static long _vq_quantlist__44u6__p9_1[] = {
  135246. 7,
  135247. 6,
  135248. 8,
  135249. 5,
  135250. 9,
  135251. 4,
  135252. 10,
  135253. 3,
  135254. 11,
  135255. 2,
  135256. 12,
  135257. 1,
  135258. 13,
  135259. 0,
  135260. 14,
  135261. };
  135262. static long _vq_lengthlist__44u6__p9_1[] = {
  135263. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135264. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135265. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135266. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135267. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135268. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135269. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135270. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135271. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135272. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135273. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135274. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135275. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135276. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135277. 13,
  135278. };
  135279. static float _vq_quantthresh__44u6__p9_1[] = {
  135280. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135281. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135282. };
  135283. static long _vq_quantmap__44u6__p9_1[] = {
  135284. 13, 11, 9, 7, 5, 3, 1, 0,
  135285. 2, 4, 6, 8, 10, 12, 14,
  135286. };
  135287. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135288. _vq_quantthresh__44u6__p9_1,
  135289. _vq_quantmap__44u6__p9_1,
  135290. 15,
  135291. 15
  135292. };
  135293. static static_codebook _44u6__p9_1 = {
  135294. 2, 225,
  135295. _vq_lengthlist__44u6__p9_1,
  135296. 1, -522338304, 1620115456, 4, 0,
  135297. _vq_quantlist__44u6__p9_1,
  135298. NULL,
  135299. &_vq_auxt__44u6__p9_1,
  135300. NULL,
  135301. 0
  135302. };
  135303. static long _vq_quantlist__44u6__p9_2[] = {
  135304. 8,
  135305. 7,
  135306. 9,
  135307. 6,
  135308. 10,
  135309. 5,
  135310. 11,
  135311. 4,
  135312. 12,
  135313. 3,
  135314. 13,
  135315. 2,
  135316. 14,
  135317. 1,
  135318. 15,
  135319. 0,
  135320. 16,
  135321. };
  135322. static long _vq_lengthlist__44u6__p9_2[] = {
  135323. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135324. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135325. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135326. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135327. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135328. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135329. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135330. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135331. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135332. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135333. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135334. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135335. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135336. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135337. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135338. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135339. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135340. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135341. 10,
  135342. };
  135343. static float _vq_quantthresh__44u6__p9_2[] = {
  135344. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135345. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135346. };
  135347. static long _vq_quantmap__44u6__p9_2[] = {
  135348. 15, 13, 11, 9, 7, 5, 3, 1,
  135349. 0, 2, 4, 6, 8, 10, 12, 14,
  135350. 16,
  135351. };
  135352. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135353. _vq_quantthresh__44u6__p9_2,
  135354. _vq_quantmap__44u6__p9_2,
  135355. 17,
  135356. 17
  135357. };
  135358. static static_codebook _44u6__p9_2 = {
  135359. 2, 289,
  135360. _vq_lengthlist__44u6__p9_2,
  135361. 1, -529530880, 1611661312, 5, 0,
  135362. _vq_quantlist__44u6__p9_2,
  135363. NULL,
  135364. &_vq_auxt__44u6__p9_2,
  135365. NULL,
  135366. 0
  135367. };
  135368. static long _huff_lengthlist__44u6__short[] = {
  135369. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135370. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135371. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135372. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135373. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135374. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135375. 7, 6, 9,16,
  135376. };
  135377. static static_codebook _huff_book__44u6__short = {
  135378. 2, 100,
  135379. _huff_lengthlist__44u6__short,
  135380. 0, 0, 0, 0, 0,
  135381. NULL,
  135382. NULL,
  135383. NULL,
  135384. NULL,
  135385. 0
  135386. };
  135387. static long _huff_lengthlist__44u7__long[] = {
  135388. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135389. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135390. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135391. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135392. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135393. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135394. 12, 8, 6, 7,
  135395. };
  135396. static static_codebook _huff_book__44u7__long = {
  135397. 2, 100,
  135398. _huff_lengthlist__44u7__long,
  135399. 0, 0, 0, 0, 0,
  135400. NULL,
  135401. NULL,
  135402. NULL,
  135403. NULL,
  135404. 0
  135405. };
  135406. static long _vq_quantlist__44u7__p1_0[] = {
  135407. 1,
  135408. 0,
  135409. 2,
  135410. };
  135411. static long _vq_lengthlist__44u7__p1_0[] = {
  135412. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135413. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135414. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135415. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135416. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135417. 12,
  135418. };
  135419. static float _vq_quantthresh__44u7__p1_0[] = {
  135420. -0.5, 0.5,
  135421. };
  135422. static long _vq_quantmap__44u7__p1_0[] = {
  135423. 1, 0, 2,
  135424. };
  135425. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135426. _vq_quantthresh__44u7__p1_0,
  135427. _vq_quantmap__44u7__p1_0,
  135428. 3,
  135429. 3
  135430. };
  135431. static static_codebook _44u7__p1_0 = {
  135432. 4, 81,
  135433. _vq_lengthlist__44u7__p1_0,
  135434. 1, -535822336, 1611661312, 2, 0,
  135435. _vq_quantlist__44u7__p1_0,
  135436. NULL,
  135437. &_vq_auxt__44u7__p1_0,
  135438. NULL,
  135439. 0
  135440. };
  135441. static long _vq_quantlist__44u7__p2_0[] = {
  135442. 1,
  135443. 0,
  135444. 2,
  135445. };
  135446. static long _vq_lengthlist__44u7__p2_0[] = {
  135447. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135448. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135449. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135450. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135451. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135452. 9,
  135453. };
  135454. static float _vq_quantthresh__44u7__p2_0[] = {
  135455. -0.5, 0.5,
  135456. };
  135457. static long _vq_quantmap__44u7__p2_0[] = {
  135458. 1, 0, 2,
  135459. };
  135460. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135461. _vq_quantthresh__44u7__p2_0,
  135462. _vq_quantmap__44u7__p2_0,
  135463. 3,
  135464. 3
  135465. };
  135466. static static_codebook _44u7__p2_0 = {
  135467. 4, 81,
  135468. _vq_lengthlist__44u7__p2_0,
  135469. 1, -535822336, 1611661312, 2, 0,
  135470. _vq_quantlist__44u7__p2_0,
  135471. NULL,
  135472. &_vq_auxt__44u7__p2_0,
  135473. NULL,
  135474. 0
  135475. };
  135476. static long _vq_quantlist__44u7__p3_0[] = {
  135477. 2,
  135478. 1,
  135479. 3,
  135480. 0,
  135481. 4,
  135482. };
  135483. static long _vq_lengthlist__44u7__p3_0[] = {
  135484. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135485. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135486. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135487. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135488. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135489. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135490. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135491. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135492. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135493. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135494. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135495. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135496. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135497. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135498. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135499. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135500. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135501. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135502. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135503. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135504. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135505. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135506. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135507. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135508. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135509. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135510. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135511. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135512. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135513. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135514. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135515. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135516. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135517. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135518. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135519. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135520. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135521. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135522. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135523. 0,
  135524. };
  135525. static float _vq_quantthresh__44u7__p3_0[] = {
  135526. -1.5, -0.5, 0.5, 1.5,
  135527. };
  135528. static long _vq_quantmap__44u7__p3_0[] = {
  135529. 3, 1, 0, 2, 4,
  135530. };
  135531. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135532. _vq_quantthresh__44u7__p3_0,
  135533. _vq_quantmap__44u7__p3_0,
  135534. 5,
  135535. 5
  135536. };
  135537. static static_codebook _44u7__p3_0 = {
  135538. 4, 625,
  135539. _vq_lengthlist__44u7__p3_0,
  135540. 1, -533725184, 1611661312, 3, 0,
  135541. _vq_quantlist__44u7__p3_0,
  135542. NULL,
  135543. &_vq_auxt__44u7__p3_0,
  135544. NULL,
  135545. 0
  135546. };
  135547. static long _vq_quantlist__44u7__p4_0[] = {
  135548. 2,
  135549. 1,
  135550. 3,
  135551. 0,
  135552. 4,
  135553. };
  135554. static long _vq_lengthlist__44u7__p4_0[] = {
  135555. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135556. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135557. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135558. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135559. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135560. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135561. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135562. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135563. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135564. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135565. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135566. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135567. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135568. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135569. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135570. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135571. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135572. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135573. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135574. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135575. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135576. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135577. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135578. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135579. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135580. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135581. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135582. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135583. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135584. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135585. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135586. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135587. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135588. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135589. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135590. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135591. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135592. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135593. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135594. 14,
  135595. };
  135596. static float _vq_quantthresh__44u7__p4_0[] = {
  135597. -1.5, -0.5, 0.5, 1.5,
  135598. };
  135599. static long _vq_quantmap__44u7__p4_0[] = {
  135600. 3, 1, 0, 2, 4,
  135601. };
  135602. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135603. _vq_quantthresh__44u7__p4_0,
  135604. _vq_quantmap__44u7__p4_0,
  135605. 5,
  135606. 5
  135607. };
  135608. static static_codebook _44u7__p4_0 = {
  135609. 4, 625,
  135610. _vq_lengthlist__44u7__p4_0,
  135611. 1, -533725184, 1611661312, 3, 0,
  135612. _vq_quantlist__44u7__p4_0,
  135613. NULL,
  135614. &_vq_auxt__44u7__p4_0,
  135615. NULL,
  135616. 0
  135617. };
  135618. static long _vq_quantlist__44u7__p5_0[] = {
  135619. 4,
  135620. 3,
  135621. 5,
  135622. 2,
  135623. 6,
  135624. 1,
  135625. 7,
  135626. 0,
  135627. 8,
  135628. };
  135629. static long _vq_lengthlist__44u7__p5_0[] = {
  135630. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135631. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135632. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135633. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135634. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135635. 14,
  135636. };
  135637. static float _vq_quantthresh__44u7__p5_0[] = {
  135638. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135639. };
  135640. static long _vq_quantmap__44u7__p5_0[] = {
  135641. 7, 5, 3, 1, 0, 2, 4, 6,
  135642. 8,
  135643. };
  135644. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135645. _vq_quantthresh__44u7__p5_0,
  135646. _vq_quantmap__44u7__p5_0,
  135647. 9,
  135648. 9
  135649. };
  135650. static static_codebook _44u7__p5_0 = {
  135651. 2, 81,
  135652. _vq_lengthlist__44u7__p5_0,
  135653. 1, -531628032, 1611661312, 4, 0,
  135654. _vq_quantlist__44u7__p5_0,
  135655. NULL,
  135656. &_vq_auxt__44u7__p5_0,
  135657. NULL,
  135658. 0
  135659. };
  135660. static long _vq_quantlist__44u7__p6_0[] = {
  135661. 4,
  135662. 3,
  135663. 5,
  135664. 2,
  135665. 6,
  135666. 1,
  135667. 7,
  135668. 0,
  135669. 8,
  135670. };
  135671. static long _vq_lengthlist__44u7__p6_0[] = {
  135672. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135673. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135674. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135675. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135676. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135677. 12,
  135678. };
  135679. static float _vq_quantthresh__44u7__p6_0[] = {
  135680. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135681. };
  135682. static long _vq_quantmap__44u7__p6_0[] = {
  135683. 7, 5, 3, 1, 0, 2, 4, 6,
  135684. 8,
  135685. };
  135686. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135687. _vq_quantthresh__44u7__p6_0,
  135688. _vq_quantmap__44u7__p6_0,
  135689. 9,
  135690. 9
  135691. };
  135692. static static_codebook _44u7__p6_0 = {
  135693. 2, 81,
  135694. _vq_lengthlist__44u7__p6_0,
  135695. 1, -531628032, 1611661312, 4, 0,
  135696. _vq_quantlist__44u7__p6_0,
  135697. NULL,
  135698. &_vq_auxt__44u7__p6_0,
  135699. NULL,
  135700. 0
  135701. };
  135702. static long _vq_quantlist__44u7__p7_0[] = {
  135703. 1,
  135704. 0,
  135705. 2,
  135706. };
  135707. static long _vq_lengthlist__44u7__p7_0[] = {
  135708. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  135709. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  135710. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  135711. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  135712. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  135713. 10,
  135714. };
  135715. static float _vq_quantthresh__44u7__p7_0[] = {
  135716. -5.5, 5.5,
  135717. };
  135718. static long _vq_quantmap__44u7__p7_0[] = {
  135719. 1, 0, 2,
  135720. };
  135721. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  135722. _vq_quantthresh__44u7__p7_0,
  135723. _vq_quantmap__44u7__p7_0,
  135724. 3,
  135725. 3
  135726. };
  135727. static static_codebook _44u7__p7_0 = {
  135728. 4, 81,
  135729. _vq_lengthlist__44u7__p7_0,
  135730. 1, -529137664, 1618345984, 2, 0,
  135731. _vq_quantlist__44u7__p7_0,
  135732. NULL,
  135733. &_vq_auxt__44u7__p7_0,
  135734. NULL,
  135735. 0
  135736. };
  135737. static long _vq_quantlist__44u7__p7_1[] = {
  135738. 5,
  135739. 4,
  135740. 6,
  135741. 3,
  135742. 7,
  135743. 2,
  135744. 8,
  135745. 1,
  135746. 9,
  135747. 0,
  135748. 10,
  135749. };
  135750. static long _vq_lengthlist__44u7__p7_1[] = {
  135751. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  135752. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  135753. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  135754. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  135755. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  135756. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135757. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  135758. 8, 9, 9, 9, 9, 9,10,10,10,
  135759. };
  135760. static float _vq_quantthresh__44u7__p7_1[] = {
  135761. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135762. 3.5, 4.5,
  135763. };
  135764. static long _vq_quantmap__44u7__p7_1[] = {
  135765. 9, 7, 5, 3, 1, 0, 2, 4,
  135766. 6, 8, 10,
  135767. };
  135768. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  135769. _vq_quantthresh__44u7__p7_1,
  135770. _vq_quantmap__44u7__p7_1,
  135771. 11,
  135772. 11
  135773. };
  135774. static static_codebook _44u7__p7_1 = {
  135775. 2, 121,
  135776. _vq_lengthlist__44u7__p7_1,
  135777. 1, -531365888, 1611661312, 4, 0,
  135778. _vq_quantlist__44u7__p7_1,
  135779. NULL,
  135780. &_vq_auxt__44u7__p7_1,
  135781. NULL,
  135782. 0
  135783. };
  135784. static long _vq_quantlist__44u7__p8_0[] = {
  135785. 5,
  135786. 4,
  135787. 6,
  135788. 3,
  135789. 7,
  135790. 2,
  135791. 8,
  135792. 1,
  135793. 9,
  135794. 0,
  135795. 10,
  135796. };
  135797. static long _vq_lengthlist__44u7__p8_0[] = {
  135798. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  135799. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  135800. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  135801. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  135802. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  135803. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  135804. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  135805. 12,13,13,14,14,15,15,15,16,
  135806. };
  135807. static float _vq_quantthresh__44u7__p8_0[] = {
  135808. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135809. 38.5, 49.5,
  135810. };
  135811. static long _vq_quantmap__44u7__p8_0[] = {
  135812. 9, 7, 5, 3, 1, 0, 2, 4,
  135813. 6, 8, 10,
  135814. };
  135815. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  135816. _vq_quantthresh__44u7__p8_0,
  135817. _vq_quantmap__44u7__p8_0,
  135818. 11,
  135819. 11
  135820. };
  135821. static static_codebook _44u7__p8_0 = {
  135822. 2, 121,
  135823. _vq_lengthlist__44u7__p8_0,
  135824. 1, -524582912, 1618345984, 4, 0,
  135825. _vq_quantlist__44u7__p8_0,
  135826. NULL,
  135827. &_vq_auxt__44u7__p8_0,
  135828. NULL,
  135829. 0
  135830. };
  135831. static long _vq_quantlist__44u7__p8_1[] = {
  135832. 5,
  135833. 4,
  135834. 6,
  135835. 3,
  135836. 7,
  135837. 2,
  135838. 8,
  135839. 1,
  135840. 9,
  135841. 0,
  135842. 10,
  135843. };
  135844. static long _vq_lengthlist__44u7__p8_1[] = {
  135845. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  135846. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  135847. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  135848. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  135849. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  135850. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  135851. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  135852. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  135853. };
  135854. static float _vq_quantthresh__44u7__p8_1[] = {
  135855. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135856. 3.5, 4.5,
  135857. };
  135858. static long _vq_quantmap__44u7__p8_1[] = {
  135859. 9, 7, 5, 3, 1, 0, 2, 4,
  135860. 6, 8, 10,
  135861. };
  135862. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  135863. _vq_quantthresh__44u7__p8_1,
  135864. _vq_quantmap__44u7__p8_1,
  135865. 11,
  135866. 11
  135867. };
  135868. static static_codebook _44u7__p8_1 = {
  135869. 2, 121,
  135870. _vq_lengthlist__44u7__p8_1,
  135871. 1, -531365888, 1611661312, 4, 0,
  135872. _vq_quantlist__44u7__p8_1,
  135873. NULL,
  135874. &_vq_auxt__44u7__p8_1,
  135875. NULL,
  135876. 0
  135877. };
  135878. static long _vq_quantlist__44u7__p9_0[] = {
  135879. 5,
  135880. 4,
  135881. 6,
  135882. 3,
  135883. 7,
  135884. 2,
  135885. 8,
  135886. 1,
  135887. 9,
  135888. 0,
  135889. 10,
  135890. };
  135891. static long _vq_lengthlist__44u7__p9_0[] = {
  135892. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  135893. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  135894. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  135895. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  135896. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  135897. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  135898. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135899. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135900. };
  135901. static float _vq_quantthresh__44u7__p9_0[] = {
  135902. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  135903. 2229.5, 2866.5,
  135904. };
  135905. static long _vq_quantmap__44u7__p9_0[] = {
  135906. 9, 7, 5, 3, 1, 0, 2, 4,
  135907. 6, 8, 10,
  135908. };
  135909. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  135910. _vq_quantthresh__44u7__p9_0,
  135911. _vq_quantmap__44u7__p9_0,
  135912. 11,
  135913. 11
  135914. };
  135915. static static_codebook _44u7__p9_0 = {
  135916. 2, 121,
  135917. _vq_lengthlist__44u7__p9_0,
  135918. 1, -512171520, 1630791680, 4, 0,
  135919. _vq_quantlist__44u7__p9_0,
  135920. NULL,
  135921. &_vq_auxt__44u7__p9_0,
  135922. NULL,
  135923. 0
  135924. };
  135925. static long _vq_quantlist__44u7__p9_1[] = {
  135926. 6,
  135927. 5,
  135928. 7,
  135929. 4,
  135930. 8,
  135931. 3,
  135932. 9,
  135933. 2,
  135934. 10,
  135935. 1,
  135936. 11,
  135937. 0,
  135938. 12,
  135939. };
  135940. static long _vq_lengthlist__44u7__p9_1[] = {
  135941. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  135942. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  135943. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  135944. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  135945. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  135946. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  135947. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  135948. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  135949. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  135950. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  135951. 15,15,15,15,17,17,16,17,16,
  135952. };
  135953. static float _vq_quantthresh__44u7__p9_1[] = {
  135954. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  135955. 122.5, 171.5, 220.5, 269.5,
  135956. };
  135957. static long _vq_quantmap__44u7__p9_1[] = {
  135958. 11, 9, 7, 5, 3, 1, 0, 2,
  135959. 4, 6, 8, 10, 12,
  135960. };
  135961. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  135962. _vq_quantthresh__44u7__p9_1,
  135963. _vq_quantmap__44u7__p9_1,
  135964. 13,
  135965. 13
  135966. };
  135967. static static_codebook _44u7__p9_1 = {
  135968. 2, 169,
  135969. _vq_lengthlist__44u7__p9_1,
  135970. 1, -518889472, 1622704128, 4, 0,
  135971. _vq_quantlist__44u7__p9_1,
  135972. NULL,
  135973. &_vq_auxt__44u7__p9_1,
  135974. NULL,
  135975. 0
  135976. };
  135977. static long _vq_quantlist__44u7__p9_2[] = {
  135978. 24,
  135979. 23,
  135980. 25,
  135981. 22,
  135982. 26,
  135983. 21,
  135984. 27,
  135985. 20,
  135986. 28,
  135987. 19,
  135988. 29,
  135989. 18,
  135990. 30,
  135991. 17,
  135992. 31,
  135993. 16,
  135994. 32,
  135995. 15,
  135996. 33,
  135997. 14,
  135998. 34,
  135999. 13,
  136000. 35,
  136001. 12,
  136002. 36,
  136003. 11,
  136004. 37,
  136005. 10,
  136006. 38,
  136007. 9,
  136008. 39,
  136009. 8,
  136010. 40,
  136011. 7,
  136012. 41,
  136013. 6,
  136014. 42,
  136015. 5,
  136016. 43,
  136017. 4,
  136018. 44,
  136019. 3,
  136020. 45,
  136021. 2,
  136022. 46,
  136023. 1,
  136024. 47,
  136025. 0,
  136026. 48,
  136027. };
  136028. static long _vq_lengthlist__44u7__p9_2[] = {
  136029. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136030. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136031. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136032. 8,
  136033. };
  136034. static float _vq_quantthresh__44u7__p9_2[] = {
  136035. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136036. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136037. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136038. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136039. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136040. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136041. };
  136042. static long _vq_quantmap__44u7__p9_2[] = {
  136043. 47, 45, 43, 41, 39, 37, 35, 33,
  136044. 31, 29, 27, 25, 23, 21, 19, 17,
  136045. 15, 13, 11, 9, 7, 5, 3, 1,
  136046. 0, 2, 4, 6, 8, 10, 12, 14,
  136047. 16, 18, 20, 22, 24, 26, 28, 30,
  136048. 32, 34, 36, 38, 40, 42, 44, 46,
  136049. 48,
  136050. };
  136051. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136052. _vq_quantthresh__44u7__p9_2,
  136053. _vq_quantmap__44u7__p9_2,
  136054. 49,
  136055. 49
  136056. };
  136057. static static_codebook _44u7__p9_2 = {
  136058. 1, 49,
  136059. _vq_lengthlist__44u7__p9_2,
  136060. 1, -526909440, 1611661312, 6, 0,
  136061. _vq_quantlist__44u7__p9_2,
  136062. NULL,
  136063. &_vq_auxt__44u7__p9_2,
  136064. NULL,
  136065. 0
  136066. };
  136067. static long _huff_lengthlist__44u7__short[] = {
  136068. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136069. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136070. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136071. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136072. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136073. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136074. 6, 8, 5, 9,
  136075. };
  136076. static static_codebook _huff_book__44u7__short = {
  136077. 2, 100,
  136078. _huff_lengthlist__44u7__short,
  136079. 0, 0, 0, 0, 0,
  136080. NULL,
  136081. NULL,
  136082. NULL,
  136083. NULL,
  136084. 0
  136085. };
  136086. static long _huff_lengthlist__44u8__long[] = {
  136087. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136088. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136089. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136090. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136091. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136092. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136093. 10, 8, 8, 9,
  136094. };
  136095. static static_codebook _huff_book__44u8__long = {
  136096. 2, 100,
  136097. _huff_lengthlist__44u8__long,
  136098. 0, 0, 0, 0, 0,
  136099. NULL,
  136100. NULL,
  136101. NULL,
  136102. NULL,
  136103. 0
  136104. };
  136105. static long _huff_lengthlist__44u8__short[] = {
  136106. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136107. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136108. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136109. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136110. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136111. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136112. 10,10,15,17,
  136113. };
  136114. static static_codebook _huff_book__44u8__short = {
  136115. 2, 100,
  136116. _huff_lengthlist__44u8__short,
  136117. 0, 0, 0, 0, 0,
  136118. NULL,
  136119. NULL,
  136120. NULL,
  136121. NULL,
  136122. 0
  136123. };
  136124. static long _vq_quantlist__44u8_p1_0[] = {
  136125. 1,
  136126. 0,
  136127. 2,
  136128. };
  136129. static long _vq_lengthlist__44u8_p1_0[] = {
  136130. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136131. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136132. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136133. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136134. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136135. 10,
  136136. };
  136137. static float _vq_quantthresh__44u8_p1_0[] = {
  136138. -0.5, 0.5,
  136139. };
  136140. static long _vq_quantmap__44u8_p1_0[] = {
  136141. 1, 0, 2,
  136142. };
  136143. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136144. _vq_quantthresh__44u8_p1_0,
  136145. _vq_quantmap__44u8_p1_0,
  136146. 3,
  136147. 3
  136148. };
  136149. static static_codebook _44u8_p1_0 = {
  136150. 4, 81,
  136151. _vq_lengthlist__44u8_p1_0,
  136152. 1, -535822336, 1611661312, 2, 0,
  136153. _vq_quantlist__44u8_p1_0,
  136154. NULL,
  136155. &_vq_auxt__44u8_p1_0,
  136156. NULL,
  136157. 0
  136158. };
  136159. static long _vq_quantlist__44u8_p2_0[] = {
  136160. 2,
  136161. 1,
  136162. 3,
  136163. 0,
  136164. 4,
  136165. };
  136166. static long _vq_lengthlist__44u8_p2_0[] = {
  136167. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136168. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136169. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136170. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136171. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136172. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136173. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136174. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136175. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136176. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136177. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136178. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136179. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136180. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136181. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136182. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136183. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136184. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136185. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136186. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136187. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136188. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136189. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136190. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136191. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136192. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136193. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136194. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136195. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136196. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136197. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136198. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136199. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136200. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136201. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136202. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136203. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136204. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136205. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136206. 14,
  136207. };
  136208. static float _vq_quantthresh__44u8_p2_0[] = {
  136209. -1.5, -0.5, 0.5, 1.5,
  136210. };
  136211. static long _vq_quantmap__44u8_p2_0[] = {
  136212. 3, 1, 0, 2, 4,
  136213. };
  136214. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136215. _vq_quantthresh__44u8_p2_0,
  136216. _vq_quantmap__44u8_p2_0,
  136217. 5,
  136218. 5
  136219. };
  136220. static static_codebook _44u8_p2_0 = {
  136221. 4, 625,
  136222. _vq_lengthlist__44u8_p2_0,
  136223. 1, -533725184, 1611661312, 3, 0,
  136224. _vq_quantlist__44u8_p2_0,
  136225. NULL,
  136226. &_vq_auxt__44u8_p2_0,
  136227. NULL,
  136228. 0
  136229. };
  136230. static long _vq_quantlist__44u8_p3_0[] = {
  136231. 4,
  136232. 3,
  136233. 5,
  136234. 2,
  136235. 6,
  136236. 1,
  136237. 7,
  136238. 0,
  136239. 8,
  136240. };
  136241. static long _vq_lengthlist__44u8_p3_0[] = {
  136242. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136243. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136244. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136245. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136246. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136247. 12,
  136248. };
  136249. static float _vq_quantthresh__44u8_p3_0[] = {
  136250. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136251. };
  136252. static long _vq_quantmap__44u8_p3_0[] = {
  136253. 7, 5, 3, 1, 0, 2, 4, 6,
  136254. 8,
  136255. };
  136256. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136257. _vq_quantthresh__44u8_p3_0,
  136258. _vq_quantmap__44u8_p3_0,
  136259. 9,
  136260. 9
  136261. };
  136262. static static_codebook _44u8_p3_0 = {
  136263. 2, 81,
  136264. _vq_lengthlist__44u8_p3_0,
  136265. 1, -531628032, 1611661312, 4, 0,
  136266. _vq_quantlist__44u8_p3_0,
  136267. NULL,
  136268. &_vq_auxt__44u8_p3_0,
  136269. NULL,
  136270. 0
  136271. };
  136272. static long _vq_quantlist__44u8_p4_0[] = {
  136273. 8,
  136274. 7,
  136275. 9,
  136276. 6,
  136277. 10,
  136278. 5,
  136279. 11,
  136280. 4,
  136281. 12,
  136282. 3,
  136283. 13,
  136284. 2,
  136285. 14,
  136286. 1,
  136287. 15,
  136288. 0,
  136289. 16,
  136290. };
  136291. static long _vq_lengthlist__44u8_p4_0[] = {
  136292. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136293. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136294. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136295. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136296. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136297. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136298. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136299. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136300. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136301. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136302. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136303. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136304. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136305. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136306. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136307. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136308. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136309. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136310. 14,
  136311. };
  136312. static float _vq_quantthresh__44u8_p4_0[] = {
  136313. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136314. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136315. };
  136316. static long _vq_quantmap__44u8_p4_0[] = {
  136317. 15, 13, 11, 9, 7, 5, 3, 1,
  136318. 0, 2, 4, 6, 8, 10, 12, 14,
  136319. 16,
  136320. };
  136321. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136322. _vq_quantthresh__44u8_p4_0,
  136323. _vq_quantmap__44u8_p4_0,
  136324. 17,
  136325. 17
  136326. };
  136327. static static_codebook _44u8_p4_0 = {
  136328. 2, 289,
  136329. _vq_lengthlist__44u8_p4_0,
  136330. 1, -529530880, 1611661312, 5, 0,
  136331. _vq_quantlist__44u8_p4_0,
  136332. NULL,
  136333. &_vq_auxt__44u8_p4_0,
  136334. NULL,
  136335. 0
  136336. };
  136337. static long _vq_quantlist__44u8_p5_0[] = {
  136338. 1,
  136339. 0,
  136340. 2,
  136341. };
  136342. static long _vq_lengthlist__44u8_p5_0[] = {
  136343. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136344. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136345. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136346. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136347. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136348. 10,
  136349. };
  136350. static float _vq_quantthresh__44u8_p5_0[] = {
  136351. -5.5, 5.5,
  136352. };
  136353. static long _vq_quantmap__44u8_p5_0[] = {
  136354. 1, 0, 2,
  136355. };
  136356. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136357. _vq_quantthresh__44u8_p5_0,
  136358. _vq_quantmap__44u8_p5_0,
  136359. 3,
  136360. 3
  136361. };
  136362. static static_codebook _44u8_p5_0 = {
  136363. 4, 81,
  136364. _vq_lengthlist__44u8_p5_0,
  136365. 1, -529137664, 1618345984, 2, 0,
  136366. _vq_quantlist__44u8_p5_0,
  136367. NULL,
  136368. &_vq_auxt__44u8_p5_0,
  136369. NULL,
  136370. 0
  136371. };
  136372. static long _vq_quantlist__44u8_p5_1[] = {
  136373. 5,
  136374. 4,
  136375. 6,
  136376. 3,
  136377. 7,
  136378. 2,
  136379. 8,
  136380. 1,
  136381. 9,
  136382. 0,
  136383. 10,
  136384. };
  136385. static long _vq_lengthlist__44u8_p5_1[] = {
  136386. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136387. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136388. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136389. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136390. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136391. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136392. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136393. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136394. };
  136395. static float _vq_quantthresh__44u8_p5_1[] = {
  136396. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136397. 3.5, 4.5,
  136398. };
  136399. static long _vq_quantmap__44u8_p5_1[] = {
  136400. 9, 7, 5, 3, 1, 0, 2, 4,
  136401. 6, 8, 10,
  136402. };
  136403. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136404. _vq_quantthresh__44u8_p5_1,
  136405. _vq_quantmap__44u8_p5_1,
  136406. 11,
  136407. 11
  136408. };
  136409. static static_codebook _44u8_p5_1 = {
  136410. 2, 121,
  136411. _vq_lengthlist__44u8_p5_1,
  136412. 1, -531365888, 1611661312, 4, 0,
  136413. _vq_quantlist__44u8_p5_1,
  136414. NULL,
  136415. &_vq_auxt__44u8_p5_1,
  136416. NULL,
  136417. 0
  136418. };
  136419. static long _vq_quantlist__44u8_p6_0[] = {
  136420. 6,
  136421. 5,
  136422. 7,
  136423. 4,
  136424. 8,
  136425. 3,
  136426. 9,
  136427. 2,
  136428. 10,
  136429. 1,
  136430. 11,
  136431. 0,
  136432. 12,
  136433. };
  136434. static long _vq_lengthlist__44u8_p6_0[] = {
  136435. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136436. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136437. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136438. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136439. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136440. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136441. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136442. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136443. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136444. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136445. 11,11,11,11,11,12,11,12,12,
  136446. };
  136447. static float _vq_quantthresh__44u8_p6_0[] = {
  136448. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136449. 12.5, 17.5, 22.5, 27.5,
  136450. };
  136451. static long _vq_quantmap__44u8_p6_0[] = {
  136452. 11, 9, 7, 5, 3, 1, 0, 2,
  136453. 4, 6, 8, 10, 12,
  136454. };
  136455. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136456. _vq_quantthresh__44u8_p6_0,
  136457. _vq_quantmap__44u8_p6_0,
  136458. 13,
  136459. 13
  136460. };
  136461. static static_codebook _44u8_p6_0 = {
  136462. 2, 169,
  136463. _vq_lengthlist__44u8_p6_0,
  136464. 1, -526516224, 1616117760, 4, 0,
  136465. _vq_quantlist__44u8_p6_0,
  136466. NULL,
  136467. &_vq_auxt__44u8_p6_0,
  136468. NULL,
  136469. 0
  136470. };
  136471. static long _vq_quantlist__44u8_p6_1[] = {
  136472. 2,
  136473. 1,
  136474. 3,
  136475. 0,
  136476. 4,
  136477. };
  136478. static long _vq_lengthlist__44u8_p6_1[] = {
  136479. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136480. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136481. };
  136482. static float _vq_quantthresh__44u8_p6_1[] = {
  136483. -1.5, -0.5, 0.5, 1.5,
  136484. };
  136485. static long _vq_quantmap__44u8_p6_1[] = {
  136486. 3, 1, 0, 2, 4,
  136487. };
  136488. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136489. _vq_quantthresh__44u8_p6_1,
  136490. _vq_quantmap__44u8_p6_1,
  136491. 5,
  136492. 5
  136493. };
  136494. static static_codebook _44u8_p6_1 = {
  136495. 2, 25,
  136496. _vq_lengthlist__44u8_p6_1,
  136497. 1, -533725184, 1611661312, 3, 0,
  136498. _vq_quantlist__44u8_p6_1,
  136499. NULL,
  136500. &_vq_auxt__44u8_p6_1,
  136501. NULL,
  136502. 0
  136503. };
  136504. static long _vq_quantlist__44u8_p7_0[] = {
  136505. 6,
  136506. 5,
  136507. 7,
  136508. 4,
  136509. 8,
  136510. 3,
  136511. 9,
  136512. 2,
  136513. 10,
  136514. 1,
  136515. 11,
  136516. 0,
  136517. 12,
  136518. };
  136519. static long _vq_lengthlist__44u8_p7_0[] = {
  136520. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136521. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136522. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136523. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136524. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136525. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136526. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136527. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136528. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136529. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136530. 13,13,14,14,14,15,15,15,16,
  136531. };
  136532. static float _vq_quantthresh__44u8_p7_0[] = {
  136533. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136534. 27.5, 38.5, 49.5, 60.5,
  136535. };
  136536. static long _vq_quantmap__44u8_p7_0[] = {
  136537. 11, 9, 7, 5, 3, 1, 0, 2,
  136538. 4, 6, 8, 10, 12,
  136539. };
  136540. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136541. _vq_quantthresh__44u8_p7_0,
  136542. _vq_quantmap__44u8_p7_0,
  136543. 13,
  136544. 13
  136545. };
  136546. static static_codebook _44u8_p7_0 = {
  136547. 2, 169,
  136548. _vq_lengthlist__44u8_p7_0,
  136549. 1, -523206656, 1618345984, 4, 0,
  136550. _vq_quantlist__44u8_p7_0,
  136551. NULL,
  136552. &_vq_auxt__44u8_p7_0,
  136553. NULL,
  136554. 0
  136555. };
  136556. static long _vq_quantlist__44u8_p7_1[] = {
  136557. 5,
  136558. 4,
  136559. 6,
  136560. 3,
  136561. 7,
  136562. 2,
  136563. 8,
  136564. 1,
  136565. 9,
  136566. 0,
  136567. 10,
  136568. };
  136569. static long _vq_lengthlist__44u8_p7_1[] = {
  136570. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136571. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136572. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136573. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136574. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136575. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136576. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136577. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136578. };
  136579. static float _vq_quantthresh__44u8_p7_1[] = {
  136580. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136581. 3.5, 4.5,
  136582. };
  136583. static long _vq_quantmap__44u8_p7_1[] = {
  136584. 9, 7, 5, 3, 1, 0, 2, 4,
  136585. 6, 8, 10,
  136586. };
  136587. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136588. _vq_quantthresh__44u8_p7_1,
  136589. _vq_quantmap__44u8_p7_1,
  136590. 11,
  136591. 11
  136592. };
  136593. static static_codebook _44u8_p7_1 = {
  136594. 2, 121,
  136595. _vq_lengthlist__44u8_p7_1,
  136596. 1, -531365888, 1611661312, 4, 0,
  136597. _vq_quantlist__44u8_p7_1,
  136598. NULL,
  136599. &_vq_auxt__44u8_p7_1,
  136600. NULL,
  136601. 0
  136602. };
  136603. static long _vq_quantlist__44u8_p8_0[] = {
  136604. 7,
  136605. 6,
  136606. 8,
  136607. 5,
  136608. 9,
  136609. 4,
  136610. 10,
  136611. 3,
  136612. 11,
  136613. 2,
  136614. 12,
  136615. 1,
  136616. 13,
  136617. 0,
  136618. 14,
  136619. };
  136620. static long _vq_lengthlist__44u8_p8_0[] = {
  136621. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136622. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136623. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136624. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136625. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136626. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136627. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136628. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136629. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136630. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136631. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136632. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136633. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136634. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136635. 17,
  136636. };
  136637. static float _vq_quantthresh__44u8_p8_0[] = {
  136638. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136639. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136640. };
  136641. static long _vq_quantmap__44u8_p8_0[] = {
  136642. 13, 11, 9, 7, 5, 3, 1, 0,
  136643. 2, 4, 6, 8, 10, 12, 14,
  136644. };
  136645. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136646. _vq_quantthresh__44u8_p8_0,
  136647. _vq_quantmap__44u8_p8_0,
  136648. 15,
  136649. 15
  136650. };
  136651. static static_codebook _44u8_p8_0 = {
  136652. 2, 225,
  136653. _vq_lengthlist__44u8_p8_0,
  136654. 1, -520986624, 1620377600, 4, 0,
  136655. _vq_quantlist__44u8_p8_0,
  136656. NULL,
  136657. &_vq_auxt__44u8_p8_0,
  136658. NULL,
  136659. 0
  136660. };
  136661. static long _vq_quantlist__44u8_p8_1[] = {
  136662. 10,
  136663. 9,
  136664. 11,
  136665. 8,
  136666. 12,
  136667. 7,
  136668. 13,
  136669. 6,
  136670. 14,
  136671. 5,
  136672. 15,
  136673. 4,
  136674. 16,
  136675. 3,
  136676. 17,
  136677. 2,
  136678. 18,
  136679. 1,
  136680. 19,
  136681. 0,
  136682. 20,
  136683. };
  136684. static long _vq_lengthlist__44u8_p8_1[] = {
  136685. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136686. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136687. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136688. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136689. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136690. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136691. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136692. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  136693. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136694. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136695. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  136696. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  136697. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136698. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136699. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136700. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  136701. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  136702. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  136703. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  136704. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  136705. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136706. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136707. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136708. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  136709. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  136710. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136711. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  136712. 10,10,10,10,10,10,10,10,10,
  136713. };
  136714. static float _vq_quantthresh__44u8_p8_1[] = {
  136715. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  136716. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  136717. 6.5, 7.5, 8.5, 9.5,
  136718. };
  136719. static long _vq_quantmap__44u8_p8_1[] = {
  136720. 19, 17, 15, 13, 11, 9, 7, 5,
  136721. 3, 1, 0, 2, 4, 6, 8, 10,
  136722. 12, 14, 16, 18, 20,
  136723. };
  136724. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  136725. _vq_quantthresh__44u8_p8_1,
  136726. _vq_quantmap__44u8_p8_1,
  136727. 21,
  136728. 21
  136729. };
  136730. static static_codebook _44u8_p8_1 = {
  136731. 2, 441,
  136732. _vq_lengthlist__44u8_p8_1,
  136733. 1, -529268736, 1611661312, 5, 0,
  136734. _vq_quantlist__44u8_p8_1,
  136735. NULL,
  136736. &_vq_auxt__44u8_p8_1,
  136737. NULL,
  136738. 0
  136739. };
  136740. static long _vq_quantlist__44u8_p9_0[] = {
  136741. 4,
  136742. 3,
  136743. 5,
  136744. 2,
  136745. 6,
  136746. 1,
  136747. 7,
  136748. 0,
  136749. 8,
  136750. };
  136751. static long _vq_lengthlist__44u8_p9_0[] = {
  136752. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  136753. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136754. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136755. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136756. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136757. 8,
  136758. };
  136759. static float _vq_quantthresh__44u8_p9_0[] = {
  136760. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  136761. };
  136762. static long _vq_quantmap__44u8_p9_0[] = {
  136763. 7, 5, 3, 1, 0, 2, 4, 6,
  136764. 8,
  136765. };
  136766. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  136767. _vq_quantthresh__44u8_p9_0,
  136768. _vq_quantmap__44u8_p9_0,
  136769. 9,
  136770. 9
  136771. };
  136772. static static_codebook _44u8_p9_0 = {
  136773. 2, 81,
  136774. _vq_lengthlist__44u8_p9_0,
  136775. 1, -511895552, 1631393792, 4, 0,
  136776. _vq_quantlist__44u8_p9_0,
  136777. NULL,
  136778. &_vq_auxt__44u8_p9_0,
  136779. NULL,
  136780. 0
  136781. };
  136782. static long _vq_quantlist__44u8_p9_1[] = {
  136783. 9,
  136784. 8,
  136785. 10,
  136786. 7,
  136787. 11,
  136788. 6,
  136789. 12,
  136790. 5,
  136791. 13,
  136792. 4,
  136793. 14,
  136794. 3,
  136795. 15,
  136796. 2,
  136797. 16,
  136798. 1,
  136799. 17,
  136800. 0,
  136801. 18,
  136802. };
  136803. static long _vq_lengthlist__44u8_p9_1[] = {
  136804. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  136805. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  136806. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  136807. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  136808. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  136809. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  136810. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  136811. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  136812. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  136813. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  136814. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  136815. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  136816. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  136817. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  136818. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  136819. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  136820. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  136821. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  136822. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  136823. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  136824. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  136825. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  136826. 16,15,16,16,16,16,16,16,16,
  136827. };
  136828. static float _vq_quantthresh__44u8_p9_1[] = {
  136829. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  136830. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  136831. 367.5, 416.5,
  136832. };
  136833. static long _vq_quantmap__44u8_p9_1[] = {
  136834. 17, 15, 13, 11, 9, 7, 5, 3,
  136835. 1, 0, 2, 4, 6, 8, 10, 12,
  136836. 14, 16, 18,
  136837. };
  136838. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  136839. _vq_quantthresh__44u8_p9_1,
  136840. _vq_quantmap__44u8_p9_1,
  136841. 19,
  136842. 19
  136843. };
  136844. static static_codebook _44u8_p9_1 = {
  136845. 2, 361,
  136846. _vq_lengthlist__44u8_p9_1,
  136847. 1, -518287360, 1622704128, 5, 0,
  136848. _vq_quantlist__44u8_p9_1,
  136849. NULL,
  136850. &_vq_auxt__44u8_p9_1,
  136851. NULL,
  136852. 0
  136853. };
  136854. static long _vq_quantlist__44u8_p9_2[] = {
  136855. 24,
  136856. 23,
  136857. 25,
  136858. 22,
  136859. 26,
  136860. 21,
  136861. 27,
  136862. 20,
  136863. 28,
  136864. 19,
  136865. 29,
  136866. 18,
  136867. 30,
  136868. 17,
  136869. 31,
  136870. 16,
  136871. 32,
  136872. 15,
  136873. 33,
  136874. 14,
  136875. 34,
  136876. 13,
  136877. 35,
  136878. 12,
  136879. 36,
  136880. 11,
  136881. 37,
  136882. 10,
  136883. 38,
  136884. 9,
  136885. 39,
  136886. 8,
  136887. 40,
  136888. 7,
  136889. 41,
  136890. 6,
  136891. 42,
  136892. 5,
  136893. 43,
  136894. 4,
  136895. 44,
  136896. 3,
  136897. 45,
  136898. 2,
  136899. 46,
  136900. 1,
  136901. 47,
  136902. 0,
  136903. 48,
  136904. };
  136905. static long _vq_lengthlist__44u8_p9_2[] = {
  136906. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  136907. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136908. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136909. 7,
  136910. };
  136911. static float _vq_quantthresh__44u8_p9_2[] = {
  136912. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136913. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136914. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136915. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136916. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136917. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136918. };
  136919. static long _vq_quantmap__44u8_p9_2[] = {
  136920. 47, 45, 43, 41, 39, 37, 35, 33,
  136921. 31, 29, 27, 25, 23, 21, 19, 17,
  136922. 15, 13, 11, 9, 7, 5, 3, 1,
  136923. 0, 2, 4, 6, 8, 10, 12, 14,
  136924. 16, 18, 20, 22, 24, 26, 28, 30,
  136925. 32, 34, 36, 38, 40, 42, 44, 46,
  136926. 48,
  136927. };
  136928. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  136929. _vq_quantthresh__44u8_p9_2,
  136930. _vq_quantmap__44u8_p9_2,
  136931. 49,
  136932. 49
  136933. };
  136934. static static_codebook _44u8_p9_2 = {
  136935. 1, 49,
  136936. _vq_lengthlist__44u8_p9_2,
  136937. 1, -526909440, 1611661312, 6, 0,
  136938. _vq_quantlist__44u8_p9_2,
  136939. NULL,
  136940. &_vq_auxt__44u8_p9_2,
  136941. NULL,
  136942. 0
  136943. };
  136944. static long _huff_lengthlist__44u9__long[] = {
  136945. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  136946. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  136947. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  136948. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  136949. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  136950. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  136951. 10, 8, 8, 9,
  136952. };
  136953. static static_codebook _huff_book__44u9__long = {
  136954. 2, 100,
  136955. _huff_lengthlist__44u9__long,
  136956. 0, 0, 0, 0, 0,
  136957. NULL,
  136958. NULL,
  136959. NULL,
  136960. NULL,
  136961. 0
  136962. };
  136963. static long _huff_lengthlist__44u9__short[] = {
  136964. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  136965. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  136966. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  136967. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  136968. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  136969. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  136970. 9, 9,12,15,
  136971. };
  136972. static static_codebook _huff_book__44u9__short = {
  136973. 2, 100,
  136974. _huff_lengthlist__44u9__short,
  136975. 0, 0, 0, 0, 0,
  136976. NULL,
  136977. NULL,
  136978. NULL,
  136979. NULL,
  136980. 0
  136981. };
  136982. static long _vq_quantlist__44u9_p1_0[] = {
  136983. 1,
  136984. 0,
  136985. 2,
  136986. };
  136987. static long _vq_lengthlist__44u9_p1_0[] = {
  136988. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  136989. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  136990. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  136991. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  136992. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  136993. 10,
  136994. };
  136995. static float _vq_quantthresh__44u9_p1_0[] = {
  136996. -0.5, 0.5,
  136997. };
  136998. static long _vq_quantmap__44u9_p1_0[] = {
  136999. 1, 0, 2,
  137000. };
  137001. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137002. _vq_quantthresh__44u9_p1_0,
  137003. _vq_quantmap__44u9_p1_0,
  137004. 3,
  137005. 3
  137006. };
  137007. static static_codebook _44u9_p1_0 = {
  137008. 4, 81,
  137009. _vq_lengthlist__44u9_p1_0,
  137010. 1, -535822336, 1611661312, 2, 0,
  137011. _vq_quantlist__44u9_p1_0,
  137012. NULL,
  137013. &_vq_auxt__44u9_p1_0,
  137014. NULL,
  137015. 0
  137016. };
  137017. static long _vq_quantlist__44u9_p2_0[] = {
  137018. 2,
  137019. 1,
  137020. 3,
  137021. 0,
  137022. 4,
  137023. };
  137024. static long _vq_lengthlist__44u9_p2_0[] = {
  137025. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137026. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137027. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137028. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137029. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137030. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137031. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137032. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137033. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137034. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137035. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137036. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137037. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137038. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137039. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137040. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137041. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137042. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137043. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137044. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137045. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137046. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137047. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137048. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137049. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137050. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137051. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137052. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137053. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137054. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137055. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137056. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137057. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137058. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137059. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137060. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137061. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137062. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137063. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137064. 14,
  137065. };
  137066. static float _vq_quantthresh__44u9_p2_0[] = {
  137067. -1.5, -0.5, 0.5, 1.5,
  137068. };
  137069. static long _vq_quantmap__44u9_p2_0[] = {
  137070. 3, 1, 0, 2, 4,
  137071. };
  137072. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137073. _vq_quantthresh__44u9_p2_0,
  137074. _vq_quantmap__44u9_p2_0,
  137075. 5,
  137076. 5
  137077. };
  137078. static static_codebook _44u9_p2_0 = {
  137079. 4, 625,
  137080. _vq_lengthlist__44u9_p2_0,
  137081. 1, -533725184, 1611661312, 3, 0,
  137082. _vq_quantlist__44u9_p2_0,
  137083. NULL,
  137084. &_vq_auxt__44u9_p2_0,
  137085. NULL,
  137086. 0
  137087. };
  137088. static long _vq_quantlist__44u9_p3_0[] = {
  137089. 4,
  137090. 3,
  137091. 5,
  137092. 2,
  137093. 6,
  137094. 1,
  137095. 7,
  137096. 0,
  137097. 8,
  137098. };
  137099. static long _vq_lengthlist__44u9_p3_0[] = {
  137100. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137101. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137102. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137103. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137104. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137105. 11,
  137106. };
  137107. static float _vq_quantthresh__44u9_p3_0[] = {
  137108. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137109. };
  137110. static long _vq_quantmap__44u9_p3_0[] = {
  137111. 7, 5, 3, 1, 0, 2, 4, 6,
  137112. 8,
  137113. };
  137114. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137115. _vq_quantthresh__44u9_p3_0,
  137116. _vq_quantmap__44u9_p3_0,
  137117. 9,
  137118. 9
  137119. };
  137120. static static_codebook _44u9_p3_0 = {
  137121. 2, 81,
  137122. _vq_lengthlist__44u9_p3_0,
  137123. 1, -531628032, 1611661312, 4, 0,
  137124. _vq_quantlist__44u9_p3_0,
  137125. NULL,
  137126. &_vq_auxt__44u9_p3_0,
  137127. NULL,
  137128. 0
  137129. };
  137130. static long _vq_quantlist__44u9_p4_0[] = {
  137131. 8,
  137132. 7,
  137133. 9,
  137134. 6,
  137135. 10,
  137136. 5,
  137137. 11,
  137138. 4,
  137139. 12,
  137140. 3,
  137141. 13,
  137142. 2,
  137143. 14,
  137144. 1,
  137145. 15,
  137146. 0,
  137147. 16,
  137148. };
  137149. static long _vq_lengthlist__44u9_p4_0[] = {
  137150. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137151. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137152. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137153. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137154. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137155. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137156. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137157. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137158. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137159. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137160. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137161. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137162. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137163. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137164. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137165. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137166. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137167. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137168. 14,
  137169. };
  137170. static float _vq_quantthresh__44u9_p4_0[] = {
  137171. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137172. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137173. };
  137174. static long _vq_quantmap__44u9_p4_0[] = {
  137175. 15, 13, 11, 9, 7, 5, 3, 1,
  137176. 0, 2, 4, 6, 8, 10, 12, 14,
  137177. 16,
  137178. };
  137179. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137180. _vq_quantthresh__44u9_p4_0,
  137181. _vq_quantmap__44u9_p4_0,
  137182. 17,
  137183. 17
  137184. };
  137185. static static_codebook _44u9_p4_0 = {
  137186. 2, 289,
  137187. _vq_lengthlist__44u9_p4_0,
  137188. 1, -529530880, 1611661312, 5, 0,
  137189. _vq_quantlist__44u9_p4_0,
  137190. NULL,
  137191. &_vq_auxt__44u9_p4_0,
  137192. NULL,
  137193. 0
  137194. };
  137195. static long _vq_quantlist__44u9_p5_0[] = {
  137196. 1,
  137197. 0,
  137198. 2,
  137199. };
  137200. static long _vq_lengthlist__44u9_p5_0[] = {
  137201. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137202. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137203. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137204. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137205. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137206. 10,
  137207. };
  137208. static float _vq_quantthresh__44u9_p5_0[] = {
  137209. -5.5, 5.5,
  137210. };
  137211. static long _vq_quantmap__44u9_p5_0[] = {
  137212. 1, 0, 2,
  137213. };
  137214. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137215. _vq_quantthresh__44u9_p5_0,
  137216. _vq_quantmap__44u9_p5_0,
  137217. 3,
  137218. 3
  137219. };
  137220. static static_codebook _44u9_p5_0 = {
  137221. 4, 81,
  137222. _vq_lengthlist__44u9_p5_0,
  137223. 1, -529137664, 1618345984, 2, 0,
  137224. _vq_quantlist__44u9_p5_0,
  137225. NULL,
  137226. &_vq_auxt__44u9_p5_0,
  137227. NULL,
  137228. 0
  137229. };
  137230. static long _vq_quantlist__44u9_p5_1[] = {
  137231. 5,
  137232. 4,
  137233. 6,
  137234. 3,
  137235. 7,
  137236. 2,
  137237. 8,
  137238. 1,
  137239. 9,
  137240. 0,
  137241. 10,
  137242. };
  137243. static long _vq_lengthlist__44u9_p5_1[] = {
  137244. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137245. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137246. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137247. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137248. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137249. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137250. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137251. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137252. };
  137253. static float _vq_quantthresh__44u9_p5_1[] = {
  137254. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137255. 3.5, 4.5,
  137256. };
  137257. static long _vq_quantmap__44u9_p5_1[] = {
  137258. 9, 7, 5, 3, 1, 0, 2, 4,
  137259. 6, 8, 10,
  137260. };
  137261. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137262. _vq_quantthresh__44u9_p5_1,
  137263. _vq_quantmap__44u9_p5_1,
  137264. 11,
  137265. 11
  137266. };
  137267. static static_codebook _44u9_p5_1 = {
  137268. 2, 121,
  137269. _vq_lengthlist__44u9_p5_1,
  137270. 1, -531365888, 1611661312, 4, 0,
  137271. _vq_quantlist__44u9_p5_1,
  137272. NULL,
  137273. &_vq_auxt__44u9_p5_1,
  137274. NULL,
  137275. 0
  137276. };
  137277. static long _vq_quantlist__44u9_p6_0[] = {
  137278. 6,
  137279. 5,
  137280. 7,
  137281. 4,
  137282. 8,
  137283. 3,
  137284. 9,
  137285. 2,
  137286. 10,
  137287. 1,
  137288. 11,
  137289. 0,
  137290. 12,
  137291. };
  137292. static long _vq_lengthlist__44u9_p6_0[] = {
  137293. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137294. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137295. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137296. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137297. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137298. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137299. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137300. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137301. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137302. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137303. 10,11,11,11,11,12,11,12,12,
  137304. };
  137305. static float _vq_quantthresh__44u9_p6_0[] = {
  137306. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137307. 12.5, 17.5, 22.5, 27.5,
  137308. };
  137309. static long _vq_quantmap__44u9_p6_0[] = {
  137310. 11, 9, 7, 5, 3, 1, 0, 2,
  137311. 4, 6, 8, 10, 12,
  137312. };
  137313. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137314. _vq_quantthresh__44u9_p6_0,
  137315. _vq_quantmap__44u9_p6_0,
  137316. 13,
  137317. 13
  137318. };
  137319. static static_codebook _44u9_p6_0 = {
  137320. 2, 169,
  137321. _vq_lengthlist__44u9_p6_0,
  137322. 1, -526516224, 1616117760, 4, 0,
  137323. _vq_quantlist__44u9_p6_0,
  137324. NULL,
  137325. &_vq_auxt__44u9_p6_0,
  137326. NULL,
  137327. 0
  137328. };
  137329. static long _vq_quantlist__44u9_p6_1[] = {
  137330. 2,
  137331. 1,
  137332. 3,
  137333. 0,
  137334. 4,
  137335. };
  137336. static long _vq_lengthlist__44u9_p6_1[] = {
  137337. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137338. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137339. };
  137340. static float _vq_quantthresh__44u9_p6_1[] = {
  137341. -1.5, -0.5, 0.5, 1.5,
  137342. };
  137343. static long _vq_quantmap__44u9_p6_1[] = {
  137344. 3, 1, 0, 2, 4,
  137345. };
  137346. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137347. _vq_quantthresh__44u9_p6_1,
  137348. _vq_quantmap__44u9_p6_1,
  137349. 5,
  137350. 5
  137351. };
  137352. static static_codebook _44u9_p6_1 = {
  137353. 2, 25,
  137354. _vq_lengthlist__44u9_p6_1,
  137355. 1, -533725184, 1611661312, 3, 0,
  137356. _vq_quantlist__44u9_p6_1,
  137357. NULL,
  137358. &_vq_auxt__44u9_p6_1,
  137359. NULL,
  137360. 0
  137361. };
  137362. static long _vq_quantlist__44u9_p7_0[] = {
  137363. 6,
  137364. 5,
  137365. 7,
  137366. 4,
  137367. 8,
  137368. 3,
  137369. 9,
  137370. 2,
  137371. 10,
  137372. 1,
  137373. 11,
  137374. 0,
  137375. 12,
  137376. };
  137377. static long _vq_lengthlist__44u9_p7_0[] = {
  137378. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137379. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137380. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137381. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137382. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137383. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137384. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137385. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137386. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137387. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137388. 12,13,13,14,14,14,15,15,15,
  137389. };
  137390. static float _vq_quantthresh__44u9_p7_0[] = {
  137391. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137392. 27.5, 38.5, 49.5, 60.5,
  137393. };
  137394. static long _vq_quantmap__44u9_p7_0[] = {
  137395. 11, 9, 7, 5, 3, 1, 0, 2,
  137396. 4, 6, 8, 10, 12,
  137397. };
  137398. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137399. _vq_quantthresh__44u9_p7_0,
  137400. _vq_quantmap__44u9_p7_0,
  137401. 13,
  137402. 13
  137403. };
  137404. static static_codebook _44u9_p7_0 = {
  137405. 2, 169,
  137406. _vq_lengthlist__44u9_p7_0,
  137407. 1, -523206656, 1618345984, 4, 0,
  137408. _vq_quantlist__44u9_p7_0,
  137409. NULL,
  137410. &_vq_auxt__44u9_p7_0,
  137411. NULL,
  137412. 0
  137413. };
  137414. static long _vq_quantlist__44u9_p7_1[] = {
  137415. 5,
  137416. 4,
  137417. 6,
  137418. 3,
  137419. 7,
  137420. 2,
  137421. 8,
  137422. 1,
  137423. 9,
  137424. 0,
  137425. 10,
  137426. };
  137427. static long _vq_lengthlist__44u9_p7_1[] = {
  137428. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137429. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137430. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137431. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137432. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137433. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137434. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137435. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137436. };
  137437. static float _vq_quantthresh__44u9_p7_1[] = {
  137438. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137439. 3.5, 4.5,
  137440. };
  137441. static long _vq_quantmap__44u9_p7_1[] = {
  137442. 9, 7, 5, 3, 1, 0, 2, 4,
  137443. 6, 8, 10,
  137444. };
  137445. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137446. _vq_quantthresh__44u9_p7_1,
  137447. _vq_quantmap__44u9_p7_1,
  137448. 11,
  137449. 11
  137450. };
  137451. static static_codebook _44u9_p7_1 = {
  137452. 2, 121,
  137453. _vq_lengthlist__44u9_p7_1,
  137454. 1, -531365888, 1611661312, 4, 0,
  137455. _vq_quantlist__44u9_p7_1,
  137456. NULL,
  137457. &_vq_auxt__44u9_p7_1,
  137458. NULL,
  137459. 0
  137460. };
  137461. static long _vq_quantlist__44u9_p8_0[] = {
  137462. 7,
  137463. 6,
  137464. 8,
  137465. 5,
  137466. 9,
  137467. 4,
  137468. 10,
  137469. 3,
  137470. 11,
  137471. 2,
  137472. 12,
  137473. 1,
  137474. 13,
  137475. 0,
  137476. 14,
  137477. };
  137478. static long _vq_lengthlist__44u9_p8_0[] = {
  137479. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137480. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137481. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137482. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137483. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137484. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137485. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137486. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137487. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137488. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137489. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137490. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137491. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137492. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137493. 15,
  137494. };
  137495. static float _vq_quantthresh__44u9_p8_0[] = {
  137496. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137497. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137498. };
  137499. static long _vq_quantmap__44u9_p8_0[] = {
  137500. 13, 11, 9, 7, 5, 3, 1, 0,
  137501. 2, 4, 6, 8, 10, 12, 14,
  137502. };
  137503. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137504. _vq_quantthresh__44u9_p8_0,
  137505. _vq_quantmap__44u9_p8_0,
  137506. 15,
  137507. 15
  137508. };
  137509. static static_codebook _44u9_p8_0 = {
  137510. 2, 225,
  137511. _vq_lengthlist__44u9_p8_0,
  137512. 1, -520986624, 1620377600, 4, 0,
  137513. _vq_quantlist__44u9_p8_0,
  137514. NULL,
  137515. &_vq_auxt__44u9_p8_0,
  137516. NULL,
  137517. 0
  137518. };
  137519. static long _vq_quantlist__44u9_p8_1[] = {
  137520. 10,
  137521. 9,
  137522. 11,
  137523. 8,
  137524. 12,
  137525. 7,
  137526. 13,
  137527. 6,
  137528. 14,
  137529. 5,
  137530. 15,
  137531. 4,
  137532. 16,
  137533. 3,
  137534. 17,
  137535. 2,
  137536. 18,
  137537. 1,
  137538. 19,
  137539. 0,
  137540. 20,
  137541. };
  137542. static long _vq_lengthlist__44u9_p8_1[] = {
  137543. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137544. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137545. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137546. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137547. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137548. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137549. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137550. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137551. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137552. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137553. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137554. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137555. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137556. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137557. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137558. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137559. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137560. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137561. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137562. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137563. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137564. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137565. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137566. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137567. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137568. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137569. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137570. 10,10,10,10,10,10,10,10,10,
  137571. };
  137572. static float _vq_quantthresh__44u9_p8_1[] = {
  137573. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137574. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137575. 6.5, 7.5, 8.5, 9.5,
  137576. };
  137577. static long _vq_quantmap__44u9_p8_1[] = {
  137578. 19, 17, 15, 13, 11, 9, 7, 5,
  137579. 3, 1, 0, 2, 4, 6, 8, 10,
  137580. 12, 14, 16, 18, 20,
  137581. };
  137582. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137583. _vq_quantthresh__44u9_p8_1,
  137584. _vq_quantmap__44u9_p8_1,
  137585. 21,
  137586. 21
  137587. };
  137588. static static_codebook _44u9_p8_1 = {
  137589. 2, 441,
  137590. _vq_lengthlist__44u9_p8_1,
  137591. 1, -529268736, 1611661312, 5, 0,
  137592. _vq_quantlist__44u9_p8_1,
  137593. NULL,
  137594. &_vq_auxt__44u9_p8_1,
  137595. NULL,
  137596. 0
  137597. };
  137598. static long _vq_quantlist__44u9_p9_0[] = {
  137599. 7,
  137600. 6,
  137601. 8,
  137602. 5,
  137603. 9,
  137604. 4,
  137605. 10,
  137606. 3,
  137607. 11,
  137608. 2,
  137609. 12,
  137610. 1,
  137611. 13,
  137612. 0,
  137613. 14,
  137614. };
  137615. static long _vq_lengthlist__44u9_p9_0[] = {
  137616. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137617. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137618. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137619. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137620. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137621. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137622. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137623. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137624. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137625. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137626. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137627. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137628. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137629. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137630. 10,
  137631. };
  137632. static float _vq_quantthresh__44u9_p9_0[] = {
  137633. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137634. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137635. };
  137636. static long _vq_quantmap__44u9_p9_0[] = {
  137637. 13, 11, 9, 7, 5, 3, 1, 0,
  137638. 2, 4, 6, 8, 10, 12, 14,
  137639. };
  137640. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137641. _vq_quantthresh__44u9_p9_0,
  137642. _vq_quantmap__44u9_p9_0,
  137643. 15,
  137644. 15
  137645. };
  137646. static static_codebook _44u9_p9_0 = {
  137647. 2, 225,
  137648. _vq_lengthlist__44u9_p9_0,
  137649. 1, -510036736, 1631393792, 4, 0,
  137650. _vq_quantlist__44u9_p9_0,
  137651. NULL,
  137652. &_vq_auxt__44u9_p9_0,
  137653. NULL,
  137654. 0
  137655. };
  137656. static long _vq_quantlist__44u9_p9_1[] = {
  137657. 9,
  137658. 8,
  137659. 10,
  137660. 7,
  137661. 11,
  137662. 6,
  137663. 12,
  137664. 5,
  137665. 13,
  137666. 4,
  137667. 14,
  137668. 3,
  137669. 15,
  137670. 2,
  137671. 16,
  137672. 1,
  137673. 17,
  137674. 0,
  137675. 18,
  137676. };
  137677. static long _vq_lengthlist__44u9_p9_1[] = {
  137678. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137679. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137680. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137681. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137682. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137683. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137684. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137685. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137686. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137687. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137688. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137689. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137690. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137691. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137692. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  137693. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  137694. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  137695. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  137696. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  137697. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  137698. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  137699. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  137700. 17,17,15,17,15,17,16,16,17,
  137701. };
  137702. static float _vq_quantthresh__44u9_p9_1[] = {
  137703. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137704. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137705. 367.5, 416.5,
  137706. };
  137707. static long _vq_quantmap__44u9_p9_1[] = {
  137708. 17, 15, 13, 11, 9, 7, 5, 3,
  137709. 1, 0, 2, 4, 6, 8, 10, 12,
  137710. 14, 16, 18,
  137711. };
  137712. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  137713. _vq_quantthresh__44u9_p9_1,
  137714. _vq_quantmap__44u9_p9_1,
  137715. 19,
  137716. 19
  137717. };
  137718. static static_codebook _44u9_p9_1 = {
  137719. 2, 361,
  137720. _vq_lengthlist__44u9_p9_1,
  137721. 1, -518287360, 1622704128, 5, 0,
  137722. _vq_quantlist__44u9_p9_1,
  137723. NULL,
  137724. &_vq_auxt__44u9_p9_1,
  137725. NULL,
  137726. 0
  137727. };
  137728. static long _vq_quantlist__44u9_p9_2[] = {
  137729. 24,
  137730. 23,
  137731. 25,
  137732. 22,
  137733. 26,
  137734. 21,
  137735. 27,
  137736. 20,
  137737. 28,
  137738. 19,
  137739. 29,
  137740. 18,
  137741. 30,
  137742. 17,
  137743. 31,
  137744. 16,
  137745. 32,
  137746. 15,
  137747. 33,
  137748. 14,
  137749. 34,
  137750. 13,
  137751. 35,
  137752. 12,
  137753. 36,
  137754. 11,
  137755. 37,
  137756. 10,
  137757. 38,
  137758. 9,
  137759. 39,
  137760. 8,
  137761. 40,
  137762. 7,
  137763. 41,
  137764. 6,
  137765. 42,
  137766. 5,
  137767. 43,
  137768. 4,
  137769. 44,
  137770. 3,
  137771. 45,
  137772. 2,
  137773. 46,
  137774. 1,
  137775. 47,
  137776. 0,
  137777. 48,
  137778. };
  137779. static long _vq_lengthlist__44u9_p9_2[] = {
  137780. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  137781. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137782. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137783. 7,
  137784. };
  137785. static float _vq_quantthresh__44u9_p9_2[] = {
  137786. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137787. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137788. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137789. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137790. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137791. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137792. };
  137793. static long _vq_quantmap__44u9_p9_2[] = {
  137794. 47, 45, 43, 41, 39, 37, 35, 33,
  137795. 31, 29, 27, 25, 23, 21, 19, 17,
  137796. 15, 13, 11, 9, 7, 5, 3, 1,
  137797. 0, 2, 4, 6, 8, 10, 12, 14,
  137798. 16, 18, 20, 22, 24, 26, 28, 30,
  137799. 32, 34, 36, 38, 40, 42, 44, 46,
  137800. 48,
  137801. };
  137802. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  137803. _vq_quantthresh__44u9_p9_2,
  137804. _vq_quantmap__44u9_p9_2,
  137805. 49,
  137806. 49
  137807. };
  137808. static static_codebook _44u9_p9_2 = {
  137809. 1, 49,
  137810. _vq_lengthlist__44u9_p9_2,
  137811. 1, -526909440, 1611661312, 6, 0,
  137812. _vq_quantlist__44u9_p9_2,
  137813. NULL,
  137814. &_vq_auxt__44u9_p9_2,
  137815. NULL,
  137816. 0
  137817. };
  137818. static long _huff_lengthlist__44un1__long[] = {
  137819. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  137820. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  137821. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  137822. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  137823. };
  137824. static static_codebook _huff_book__44un1__long = {
  137825. 2, 64,
  137826. _huff_lengthlist__44un1__long,
  137827. 0, 0, 0, 0, 0,
  137828. NULL,
  137829. NULL,
  137830. NULL,
  137831. NULL,
  137832. 0
  137833. };
  137834. static long _vq_quantlist__44un1__p1_0[] = {
  137835. 1,
  137836. 0,
  137837. 2,
  137838. };
  137839. static long _vq_lengthlist__44un1__p1_0[] = {
  137840. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  137841. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  137842. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  137843. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  137844. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  137845. 12,
  137846. };
  137847. static float _vq_quantthresh__44un1__p1_0[] = {
  137848. -0.5, 0.5,
  137849. };
  137850. static long _vq_quantmap__44un1__p1_0[] = {
  137851. 1, 0, 2,
  137852. };
  137853. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  137854. _vq_quantthresh__44un1__p1_0,
  137855. _vq_quantmap__44un1__p1_0,
  137856. 3,
  137857. 3
  137858. };
  137859. static static_codebook _44un1__p1_0 = {
  137860. 4, 81,
  137861. _vq_lengthlist__44un1__p1_0,
  137862. 1, -535822336, 1611661312, 2, 0,
  137863. _vq_quantlist__44un1__p1_0,
  137864. NULL,
  137865. &_vq_auxt__44un1__p1_0,
  137866. NULL,
  137867. 0
  137868. };
  137869. static long _vq_quantlist__44un1__p2_0[] = {
  137870. 1,
  137871. 0,
  137872. 2,
  137873. };
  137874. static long _vq_lengthlist__44un1__p2_0[] = {
  137875. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  137876. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  137877. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  137878. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  137879. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  137880. 8,
  137881. };
  137882. static float _vq_quantthresh__44un1__p2_0[] = {
  137883. -0.5, 0.5,
  137884. };
  137885. static long _vq_quantmap__44un1__p2_0[] = {
  137886. 1, 0, 2,
  137887. };
  137888. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  137889. _vq_quantthresh__44un1__p2_0,
  137890. _vq_quantmap__44un1__p2_0,
  137891. 3,
  137892. 3
  137893. };
  137894. static static_codebook _44un1__p2_0 = {
  137895. 4, 81,
  137896. _vq_lengthlist__44un1__p2_0,
  137897. 1, -535822336, 1611661312, 2, 0,
  137898. _vq_quantlist__44un1__p2_0,
  137899. NULL,
  137900. &_vq_auxt__44un1__p2_0,
  137901. NULL,
  137902. 0
  137903. };
  137904. static long _vq_quantlist__44un1__p3_0[] = {
  137905. 2,
  137906. 1,
  137907. 3,
  137908. 0,
  137909. 4,
  137910. };
  137911. static long _vq_lengthlist__44un1__p3_0[] = {
  137912. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  137913. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  137914. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  137915. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  137916. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  137917. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  137918. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  137919. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  137920. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  137921. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  137922. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  137923. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  137924. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  137925. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  137926. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  137927. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  137928. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  137929. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  137930. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  137931. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  137932. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  137933. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  137934. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  137935. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  137936. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  137937. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  137938. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  137939. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  137940. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  137941. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  137942. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  137943. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  137944. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  137945. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  137946. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  137947. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  137948. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  137949. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  137950. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  137951. 17,
  137952. };
  137953. static float _vq_quantthresh__44un1__p3_0[] = {
  137954. -1.5, -0.5, 0.5, 1.5,
  137955. };
  137956. static long _vq_quantmap__44un1__p3_0[] = {
  137957. 3, 1, 0, 2, 4,
  137958. };
  137959. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  137960. _vq_quantthresh__44un1__p3_0,
  137961. _vq_quantmap__44un1__p3_0,
  137962. 5,
  137963. 5
  137964. };
  137965. static static_codebook _44un1__p3_0 = {
  137966. 4, 625,
  137967. _vq_lengthlist__44un1__p3_0,
  137968. 1, -533725184, 1611661312, 3, 0,
  137969. _vq_quantlist__44un1__p3_0,
  137970. NULL,
  137971. &_vq_auxt__44un1__p3_0,
  137972. NULL,
  137973. 0
  137974. };
  137975. static long _vq_quantlist__44un1__p4_0[] = {
  137976. 2,
  137977. 1,
  137978. 3,
  137979. 0,
  137980. 4,
  137981. };
  137982. static long _vq_lengthlist__44un1__p4_0[] = {
  137983. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  137984. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  137985. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  137986. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  137987. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  137988. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  137989. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  137990. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  137991. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  137992. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  137993. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  137994. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  137995. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  137996. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  137997. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  137998. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  137999. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138000. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138001. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138002. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138003. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138004. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138005. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138006. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138007. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138008. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138009. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138010. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138011. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138012. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138013. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138014. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138015. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138016. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138017. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138018. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138019. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138020. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138021. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138022. 12,
  138023. };
  138024. static float _vq_quantthresh__44un1__p4_0[] = {
  138025. -1.5, -0.5, 0.5, 1.5,
  138026. };
  138027. static long _vq_quantmap__44un1__p4_0[] = {
  138028. 3, 1, 0, 2, 4,
  138029. };
  138030. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138031. _vq_quantthresh__44un1__p4_0,
  138032. _vq_quantmap__44un1__p4_0,
  138033. 5,
  138034. 5
  138035. };
  138036. static static_codebook _44un1__p4_0 = {
  138037. 4, 625,
  138038. _vq_lengthlist__44un1__p4_0,
  138039. 1, -533725184, 1611661312, 3, 0,
  138040. _vq_quantlist__44un1__p4_0,
  138041. NULL,
  138042. &_vq_auxt__44un1__p4_0,
  138043. NULL,
  138044. 0
  138045. };
  138046. static long _vq_quantlist__44un1__p5_0[] = {
  138047. 4,
  138048. 3,
  138049. 5,
  138050. 2,
  138051. 6,
  138052. 1,
  138053. 7,
  138054. 0,
  138055. 8,
  138056. };
  138057. static long _vq_lengthlist__44un1__p5_0[] = {
  138058. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138059. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138060. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138061. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138062. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138063. 12,
  138064. };
  138065. static float _vq_quantthresh__44un1__p5_0[] = {
  138066. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138067. };
  138068. static long _vq_quantmap__44un1__p5_0[] = {
  138069. 7, 5, 3, 1, 0, 2, 4, 6,
  138070. 8,
  138071. };
  138072. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138073. _vq_quantthresh__44un1__p5_0,
  138074. _vq_quantmap__44un1__p5_0,
  138075. 9,
  138076. 9
  138077. };
  138078. static static_codebook _44un1__p5_0 = {
  138079. 2, 81,
  138080. _vq_lengthlist__44un1__p5_0,
  138081. 1, -531628032, 1611661312, 4, 0,
  138082. _vq_quantlist__44un1__p5_0,
  138083. NULL,
  138084. &_vq_auxt__44un1__p5_0,
  138085. NULL,
  138086. 0
  138087. };
  138088. static long _vq_quantlist__44un1__p6_0[] = {
  138089. 6,
  138090. 5,
  138091. 7,
  138092. 4,
  138093. 8,
  138094. 3,
  138095. 9,
  138096. 2,
  138097. 10,
  138098. 1,
  138099. 11,
  138100. 0,
  138101. 12,
  138102. };
  138103. static long _vq_lengthlist__44un1__p6_0[] = {
  138104. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138105. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138106. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138107. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138108. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138109. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138110. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138111. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138112. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138113. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138114. 16, 0,15,18,18, 0,16, 0, 0,
  138115. };
  138116. static float _vq_quantthresh__44un1__p6_0[] = {
  138117. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138118. 12.5, 17.5, 22.5, 27.5,
  138119. };
  138120. static long _vq_quantmap__44un1__p6_0[] = {
  138121. 11, 9, 7, 5, 3, 1, 0, 2,
  138122. 4, 6, 8, 10, 12,
  138123. };
  138124. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138125. _vq_quantthresh__44un1__p6_0,
  138126. _vq_quantmap__44un1__p6_0,
  138127. 13,
  138128. 13
  138129. };
  138130. static static_codebook _44un1__p6_0 = {
  138131. 2, 169,
  138132. _vq_lengthlist__44un1__p6_0,
  138133. 1, -526516224, 1616117760, 4, 0,
  138134. _vq_quantlist__44un1__p6_0,
  138135. NULL,
  138136. &_vq_auxt__44un1__p6_0,
  138137. NULL,
  138138. 0
  138139. };
  138140. static long _vq_quantlist__44un1__p6_1[] = {
  138141. 2,
  138142. 1,
  138143. 3,
  138144. 0,
  138145. 4,
  138146. };
  138147. static long _vq_lengthlist__44un1__p6_1[] = {
  138148. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138149. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138150. };
  138151. static float _vq_quantthresh__44un1__p6_1[] = {
  138152. -1.5, -0.5, 0.5, 1.5,
  138153. };
  138154. static long _vq_quantmap__44un1__p6_1[] = {
  138155. 3, 1, 0, 2, 4,
  138156. };
  138157. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138158. _vq_quantthresh__44un1__p6_1,
  138159. _vq_quantmap__44un1__p6_1,
  138160. 5,
  138161. 5
  138162. };
  138163. static static_codebook _44un1__p6_1 = {
  138164. 2, 25,
  138165. _vq_lengthlist__44un1__p6_1,
  138166. 1, -533725184, 1611661312, 3, 0,
  138167. _vq_quantlist__44un1__p6_1,
  138168. NULL,
  138169. &_vq_auxt__44un1__p6_1,
  138170. NULL,
  138171. 0
  138172. };
  138173. static long _vq_quantlist__44un1__p7_0[] = {
  138174. 2,
  138175. 1,
  138176. 3,
  138177. 0,
  138178. 4,
  138179. };
  138180. static long _vq_lengthlist__44un1__p7_0[] = {
  138181. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138182. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138183. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138184. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138185. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138186. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138187. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138188. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138189. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138190. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138191. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138192. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138193. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138194. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138195. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138196. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138197. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138198. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138199. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138200. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138201. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138202. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138203. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138204. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138205. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138206. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138207. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138208. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138209. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138210. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138211. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138212. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138213. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138214. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138215. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138216. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138217. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138218. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138219. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138220. 10,
  138221. };
  138222. static float _vq_quantthresh__44un1__p7_0[] = {
  138223. -253.5, -84.5, 84.5, 253.5,
  138224. };
  138225. static long _vq_quantmap__44un1__p7_0[] = {
  138226. 3, 1, 0, 2, 4,
  138227. };
  138228. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138229. _vq_quantthresh__44un1__p7_0,
  138230. _vq_quantmap__44un1__p7_0,
  138231. 5,
  138232. 5
  138233. };
  138234. static static_codebook _44un1__p7_0 = {
  138235. 4, 625,
  138236. _vq_lengthlist__44un1__p7_0,
  138237. 1, -518709248, 1626677248, 3, 0,
  138238. _vq_quantlist__44un1__p7_0,
  138239. NULL,
  138240. &_vq_auxt__44un1__p7_0,
  138241. NULL,
  138242. 0
  138243. };
  138244. static long _vq_quantlist__44un1__p7_1[] = {
  138245. 6,
  138246. 5,
  138247. 7,
  138248. 4,
  138249. 8,
  138250. 3,
  138251. 9,
  138252. 2,
  138253. 10,
  138254. 1,
  138255. 11,
  138256. 0,
  138257. 12,
  138258. };
  138259. static long _vq_lengthlist__44un1__p7_1[] = {
  138260. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138261. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138262. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138263. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138264. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138265. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138266. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138267. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138268. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138269. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138270. 12,13,13,12,13,13,14,14,14,
  138271. };
  138272. static float _vq_quantthresh__44un1__p7_1[] = {
  138273. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138274. 32.5, 45.5, 58.5, 71.5,
  138275. };
  138276. static long _vq_quantmap__44un1__p7_1[] = {
  138277. 11, 9, 7, 5, 3, 1, 0, 2,
  138278. 4, 6, 8, 10, 12,
  138279. };
  138280. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138281. _vq_quantthresh__44un1__p7_1,
  138282. _vq_quantmap__44un1__p7_1,
  138283. 13,
  138284. 13
  138285. };
  138286. static static_codebook _44un1__p7_1 = {
  138287. 2, 169,
  138288. _vq_lengthlist__44un1__p7_1,
  138289. 1, -523010048, 1618608128, 4, 0,
  138290. _vq_quantlist__44un1__p7_1,
  138291. NULL,
  138292. &_vq_auxt__44un1__p7_1,
  138293. NULL,
  138294. 0
  138295. };
  138296. static long _vq_quantlist__44un1__p7_2[] = {
  138297. 6,
  138298. 5,
  138299. 7,
  138300. 4,
  138301. 8,
  138302. 3,
  138303. 9,
  138304. 2,
  138305. 10,
  138306. 1,
  138307. 11,
  138308. 0,
  138309. 12,
  138310. };
  138311. static long _vq_lengthlist__44un1__p7_2[] = {
  138312. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138313. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138314. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138315. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138316. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138317. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138318. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138319. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138320. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138321. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138322. 9, 9, 9,10,10,10,10,10,10,
  138323. };
  138324. static float _vq_quantthresh__44un1__p7_2[] = {
  138325. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138326. 2.5, 3.5, 4.5, 5.5,
  138327. };
  138328. static long _vq_quantmap__44un1__p7_2[] = {
  138329. 11, 9, 7, 5, 3, 1, 0, 2,
  138330. 4, 6, 8, 10, 12,
  138331. };
  138332. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138333. _vq_quantthresh__44un1__p7_2,
  138334. _vq_quantmap__44un1__p7_2,
  138335. 13,
  138336. 13
  138337. };
  138338. static static_codebook _44un1__p7_2 = {
  138339. 2, 169,
  138340. _vq_lengthlist__44un1__p7_2,
  138341. 1, -531103744, 1611661312, 4, 0,
  138342. _vq_quantlist__44un1__p7_2,
  138343. NULL,
  138344. &_vq_auxt__44un1__p7_2,
  138345. NULL,
  138346. 0
  138347. };
  138348. static long _huff_lengthlist__44un1__short[] = {
  138349. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138350. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138351. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138352. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138353. };
  138354. static static_codebook _huff_book__44un1__short = {
  138355. 2, 64,
  138356. _huff_lengthlist__44un1__short,
  138357. 0, 0, 0, 0, 0,
  138358. NULL,
  138359. NULL,
  138360. NULL,
  138361. NULL,
  138362. 0
  138363. };
  138364. /*** End of inlined file: res_books_uncoupled.h ***/
  138365. static vorbis_info_residue0 _residue_44_low_un={
  138366. 0,-1, -1, 8,-1,
  138367. {0},
  138368. {-1},
  138369. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138370. { -1, 25, -1, 45, -1, -1, -1}
  138371. };
  138372. static vorbis_info_residue0 _residue_44_mid_un={
  138373. 0,-1, -1, 10,-1,
  138374. {0},
  138375. {-1},
  138376. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138377. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138378. };
  138379. static vorbis_info_residue0 _residue_44_hi_un={
  138380. 0,-1, -1, 10,-1,
  138381. {0},
  138382. {-1},
  138383. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138384. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138385. };
  138386. static vorbis_info_mapping0 _map_nominal_u[2]={
  138387. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138388. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138389. };
  138390. static static_bookblock _resbook_44u_n1={
  138391. {
  138392. {0},
  138393. {0,0,&_44un1__p1_0},
  138394. {0,0,&_44un1__p2_0},
  138395. {0,0,&_44un1__p3_0},
  138396. {0,0,&_44un1__p4_0},
  138397. {0,0,&_44un1__p5_0},
  138398. {&_44un1__p6_0,&_44un1__p6_1},
  138399. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138400. }
  138401. };
  138402. static static_bookblock _resbook_44u_0={
  138403. {
  138404. {0},
  138405. {0,0,&_44u0__p1_0},
  138406. {0,0,&_44u0__p2_0},
  138407. {0,0,&_44u0__p3_0},
  138408. {0,0,&_44u0__p4_0},
  138409. {0,0,&_44u0__p5_0},
  138410. {&_44u0__p6_0,&_44u0__p6_1},
  138411. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138412. }
  138413. };
  138414. static static_bookblock _resbook_44u_1={
  138415. {
  138416. {0},
  138417. {0,0,&_44u1__p1_0},
  138418. {0,0,&_44u1__p2_0},
  138419. {0,0,&_44u1__p3_0},
  138420. {0,0,&_44u1__p4_0},
  138421. {0,0,&_44u1__p5_0},
  138422. {&_44u1__p6_0,&_44u1__p6_1},
  138423. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138424. }
  138425. };
  138426. static static_bookblock _resbook_44u_2={
  138427. {
  138428. {0},
  138429. {0,0,&_44u2__p1_0},
  138430. {0,0,&_44u2__p2_0},
  138431. {0,0,&_44u2__p3_0},
  138432. {0,0,&_44u2__p4_0},
  138433. {0,0,&_44u2__p5_0},
  138434. {&_44u2__p6_0,&_44u2__p6_1},
  138435. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138436. }
  138437. };
  138438. static static_bookblock _resbook_44u_3={
  138439. {
  138440. {0},
  138441. {0,0,&_44u3__p1_0},
  138442. {0,0,&_44u3__p2_0},
  138443. {0,0,&_44u3__p3_0},
  138444. {0,0,&_44u3__p4_0},
  138445. {0,0,&_44u3__p5_0},
  138446. {&_44u3__p6_0,&_44u3__p6_1},
  138447. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138448. }
  138449. };
  138450. static static_bookblock _resbook_44u_4={
  138451. {
  138452. {0},
  138453. {0,0,&_44u4__p1_0},
  138454. {0,0,&_44u4__p2_0},
  138455. {0,0,&_44u4__p3_0},
  138456. {0,0,&_44u4__p4_0},
  138457. {0,0,&_44u4__p5_0},
  138458. {&_44u4__p6_0,&_44u4__p6_1},
  138459. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138460. }
  138461. };
  138462. static static_bookblock _resbook_44u_5={
  138463. {
  138464. {0},
  138465. {0,0,&_44u5__p1_0},
  138466. {0,0,&_44u5__p2_0},
  138467. {0,0,&_44u5__p3_0},
  138468. {0,0,&_44u5__p4_0},
  138469. {0,0,&_44u5__p5_0},
  138470. {0,0,&_44u5__p6_0},
  138471. {&_44u5__p7_0,&_44u5__p7_1},
  138472. {&_44u5__p8_0,&_44u5__p8_1},
  138473. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138474. }
  138475. };
  138476. static static_bookblock _resbook_44u_6={
  138477. {
  138478. {0},
  138479. {0,0,&_44u6__p1_0},
  138480. {0,0,&_44u6__p2_0},
  138481. {0,0,&_44u6__p3_0},
  138482. {0,0,&_44u6__p4_0},
  138483. {0,0,&_44u6__p5_0},
  138484. {0,0,&_44u6__p6_0},
  138485. {&_44u6__p7_0,&_44u6__p7_1},
  138486. {&_44u6__p8_0,&_44u6__p8_1},
  138487. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138488. }
  138489. };
  138490. static static_bookblock _resbook_44u_7={
  138491. {
  138492. {0},
  138493. {0,0,&_44u7__p1_0},
  138494. {0,0,&_44u7__p2_0},
  138495. {0,0,&_44u7__p3_0},
  138496. {0,0,&_44u7__p4_0},
  138497. {0,0,&_44u7__p5_0},
  138498. {0,0,&_44u7__p6_0},
  138499. {&_44u7__p7_0,&_44u7__p7_1},
  138500. {&_44u7__p8_0,&_44u7__p8_1},
  138501. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138502. }
  138503. };
  138504. static static_bookblock _resbook_44u_8={
  138505. {
  138506. {0},
  138507. {0,0,&_44u8_p1_0},
  138508. {0,0,&_44u8_p2_0},
  138509. {0,0,&_44u8_p3_0},
  138510. {0,0,&_44u8_p4_0},
  138511. {&_44u8_p5_0,&_44u8_p5_1},
  138512. {&_44u8_p6_0,&_44u8_p6_1},
  138513. {&_44u8_p7_0,&_44u8_p7_1},
  138514. {&_44u8_p8_0,&_44u8_p8_1},
  138515. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138516. }
  138517. };
  138518. static static_bookblock _resbook_44u_9={
  138519. {
  138520. {0},
  138521. {0,0,&_44u9_p1_0},
  138522. {0,0,&_44u9_p2_0},
  138523. {0,0,&_44u9_p3_0},
  138524. {0,0,&_44u9_p4_0},
  138525. {&_44u9_p5_0,&_44u9_p5_1},
  138526. {&_44u9_p6_0,&_44u9_p6_1},
  138527. {&_44u9_p7_0,&_44u9_p7_1},
  138528. {&_44u9_p8_0,&_44u9_p8_1},
  138529. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138530. }
  138531. };
  138532. static vorbis_residue_template _res_44u_n1[]={
  138533. {1,0, &_residue_44_low_un,
  138534. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138535. &_resbook_44u_n1,&_resbook_44u_n1},
  138536. {1,0, &_residue_44_low_un,
  138537. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138538. &_resbook_44u_n1,&_resbook_44u_n1}
  138539. };
  138540. static vorbis_residue_template _res_44u_0[]={
  138541. {1,0, &_residue_44_low_un,
  138542. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138543. &_resbook_44u_0,&_resbook_44u_0},
  138544. {1,0, &_residue_44_low_un,
  138545. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138546. &_resbook_44u_0,&_resbook_44u_0}
  138547. };
  138548. static vorbis_residue_template _res_44u_1[]={
  138549. {1,0, &_residue_44_low_un,
  138550. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138551. &_resbook_44u_1,&_resbook_44u_1},
  138552. {1,0, &_residue_44_low_un,
  138553. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138554. &_resbook_44u_1,&_resbook_44u_1}
  138555. };
  138556. static vorbis_residue_template _res_44u_2[]={
  138557. {1,0, &_residue_44_low_un,
  138558. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138559. &_resbook_44u_2,&_resbook_44u_2},
  138560. {1,0, &_residue_44_low_un,
  138561. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138562. &_resbook_44u_2,&_resbook_44u_2}
  138563. };
  138564. static vorbis_residue_template _res_44u_3[]={
  138565. {1,0, &_residue_44_low_un,
  138566. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138567. &_resbook_44u_3,&_resbook_44u_3},
  138568. {1,0, &_residue_44_low_un,
  138569. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138570. &_resbook_44u_3,&_resbook_44u_3}
  138571. };
  138572. static vorbis_residue_template _res_44u_4[]={
  138573. {1,0, &_residue_44_low_un,
  138574. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138575. &_resbook_44u_4,&_resbook_44u_4},
  138576. {1,0, &_residue_44_low_un,
  138577. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138578. &_resbook_44u_4,&_resbook_44u_4}
  138579. };
  138580. static vorbis_residue_template _res_44u_5[]={
  138581. {1,0, &_residue_44_mid_un,
  138582. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138583. &_resbook_44u_5,&_resbook_44u_5},
  138584. {1,0, &_residue_44_mid_un,
  138585. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138586. &_resbook_44u_5,&_resbook_44u_5}
  138587. };
  138588. static vorbis_residue_template _res_44u_6[]={
  138589. {1,0, &_residue_44_mid_un,
  138590. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138591. &_resbook_44u_6,&_resbook_44u_6},
  138592. {1,0, &_residue_44_mid_un,
  138593. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138594. &_resbook_44u_6,&_resbook_44u_6}
  138595. };
  138596. static vorbis_residue_template _res_44u_7[]={
  138597. {1,0, &_residue_44_mid_un,
  138598. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138599. &_resbook_44u_7,&_resbook_44u_7},
  138600. {1,0, &_residue_44_mid_un,
  138601. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138602. &_resbook_44u_7,&_resbook_44u_7}
  138603. };
  138604. static vorbis_residue_template _res_44u_8[]={
  138605. {1,0, &_residue_44_hi_un,
  138606. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138607. &_resbook_44u_8,&_resbook_44u_8},
  138608. {1,0, &_residue_44_hi_un,
  138609. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138610. &_resbook_44u_8,&_resbook_44u_8}
  138611. };
  138612. static vorbis_residue_template _res_44u_9[]={
  138613. {1,0, &_residue_44_hi_un,
  138614. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138615. &_resbook_44u_9,&_resbook_44u_9},
  138616. {1,0, &_residue_44_hi_un,
  138617. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138618. &_resbook_44u_9,&_resbook_44u_9}
  138619. };
  138620. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138621. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138622. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138623. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138624. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138625. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138626. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138627. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138628. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138629. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138630. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138631. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138632. };
  138633. /*** End of inlined file: residue_44u.h ***/
  138634. static double rate_mapping_44_un[12]={
  138635. 32000.,48000.,60000.,70000.,80000.,86000.,
  138636. 96000.,110000.,120000.,140000.,160000.,240001.
  138637. };
  138638. ve_setup_data_template ve_setup_44_uncoupled={
  138639. 11,
  138640. rate_mapping_44_un,
  138641. quality_mapping_44,
  138642. -1,
  138643. 40000,
  138644. 50000,
  138645. blocksize_short_44,
  138646. blocksize_long_44,
  138647. _psy_tone_masteratt_44,
  138648. _psy_tone_0dB,
  138649. _psy_tone_suppress,
  138650. _vp_tonemask_adj_otherblock,
  138651. _vp_tonemask_adj_longblock,
  138652. _vp_tonemask_adj_otherblock,
  138653. _psy_noiseguards_44,
  138654. _psy_noisebias_impulse,
  138655. _psy_noisebias_padding,
  138656. _psy_noisebias_trans,
  138657. _psy_noisebias_long,
  138658. _psy_noise_suppress,
  138659. _psy_compand_44,
  138660. _psy_compand_short_mapping,
  138661. _psy_compand_long_mapping,
  138662. {_noise_start_short_44,_noise_start_long_44},
  138663. {_noise_part_short_44,_noise_part_long_44},
  138664. _noise_thresh_44,
  138665. _psy_ath_floater,
  138666. _psy_ath_abs,
  138667. _psy_lowpass_44,
  138668. _psy_global_44,
  138669. _global_mapping_44,
  138670. NULL,
  138671. _floor_books,
  138672. _floor,
  138673. _floor_short_mapping_44,
  138674. _floor_long_mapping_44,
  138675. _mapres_template_44_uncoupled
  138676. };
  138677. /*** End of inlined file: setup_44u.h ***/
  138678. /*** Start of inlined file: setup_32.h ***/
  138679. static double rate_mapping_32[12]={
  138680. 18000.,28000.,35000.,45000.,56000.,60000.,
  138681. 75000.,90000.,100000.,115000.,150000.,190000.,
  138682. };
  138683. static double rate_mapping_32_un[12]={
  138684. 30000.,42000.,52000.,64000.,72000.,78000.,
  138685. 86000.,92000.,110000.,120000.,140000.,190000.,
  138686. };
  138687. static double _psy_lowpass_32[12]={
  138688. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138689. };
  138690. ve_setup_data_template ve_setup_32_stereo={
  138691. 11,
  138692. rate_mapping_32,
  138693. quality_mapping_44,
  138694. 2,
  138695. 26000,
  138696. 40000,
  138697. blocksize_short_44,
  138698. blocksize_long_44,
  138699. _psy_tone_masteratt_44,
  138700. _psy_tone_0dB,
  138701. _psy_tone_suppress,
  138702. _vp_tonemask_adj_otherblock,
  138703. _vp_tonemask_adj_longblock,
  138704. _vp_tonemask_adj_otherblock,
  138705. _psy_noiseguards_44,
  138706. _psy_noisebias_impulse,
  138707. _psy_noisebias_padding,
  138708. _psy_noisebias_trans,
  138709. _psy_noisebias_long,
  138710. _psy_noise_suppress,
  138711. _psy_compand_44,
  138712. _psy_compand_short_mapping,
  138713. _psy_compand_long_mapping,
  138714. {_noise_start_short_44,_noise_start_long_44},
  138715. {_noise_part_short_44,_noise_part_long_44},
  138716. _noise_thresh_44,
  138717. _psy_ath_floater,
  138718. _psy_ath_abs,
  138719. _psy_lowpass_32,
  138720. _psy_global_44,
  138721. _global_mapping_44,
  138722. _psy_stereo_modes_44,
  138723. _floor_books,
  138724. _floor,
  138725. _floor_short_mapping_44,
  138726. _floor_long_mapping_44,
  138727. _mapres_template_44_stereo
  138728. };
  138729. ve_setup_data_template ve_setup_32_uncoupled={
  138730. 11,
  138731. rate_mapping_32_un,
  138732. quality_mapping_44,
  138733. -1,
  138734. 26000,
  138735. 40000,
  138736. blocksize_short_44,
  138737. blocksize_long_44,
  138738. _psy_tone_masteratt_44,
  138739. _psy_tone_0dB,
  138740. _psy_tone_suppress,
  138741. _vp_tonemask_adj_otherblock,
  138742. _vp_tonemask_adj_longblock,
  138743. _vp_tonemask_adj_otherblock,
  138744. _psy_noiseguards_44,
  138745. _psy_noisebias_impulse,
  138746. _psy_noisebias_padding,
  138747. _psy_noisebias_trans,
  138748. _psy_noisebias_long,
  138749. _psy_noise_suppress,
  138750. _psy_compand_44,
  138751. _psy_compand_short_mapping,
  138752. _psy_compand_long_mapping,
  138753. {_noise_start_short_44,_noise_start_long_44},
  138754. {_noise_part_short_44,_noise_part_long_44},
  138755. _noise_thresh_44,
  138756. _psy_ath_floater,
  138757. _psy_ath_abs,
  138758. _psy_lowpass_32,
  138759. _psy_global_44,
  138760. _global_mapping_44,
  138761. NULL,
  138762. _floor_books,
  138763. _floor,
  138764. _floor_short_mapping_44,
  138765. _floor_long_mapping_44,
  138766. _mapres_template_44_uncoupled
  138767. };
  138768. /*** End of inlined file: setup_32.h ***/
  138769. /*** Start of inlined file: setup_8.h ***/
  138770. /*** Start of inlined file: psych_8.h ***/
  138771. static att3 _psy_tone_masteratt_8[3]={
  138772. {{ 32, 25, 12}, 0, 0}, /* 0 */
  138773. {{ 30, 25, 12}, 0, 0}, /* 0 */
  138774. {{ 20, 0, -14}, 0, 0}, /* 0 */
  138775. };
  138776. static vp_adjblock _vp_tonemask_adj_8[3]={
  138777. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138778. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138779. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  138780. };
  138781. static noise3 _psy_noisebias_8[3]={
  138782. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138783. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  138784. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138785. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138786. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  138787. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138788. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  138789. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  138790. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  138791. };
  138792. static adj_stereo _psy_stereo_modes_8[3]={
  138793. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138794. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138795. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138796. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138797. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138798. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138799. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138800. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138801. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138802. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138803. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138804. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138805. };
  138806. static noiseguard _psy_noiseguards_8[2]={
  138807. {10,10,-1},
  138808. {10,10,-1},
  138809. };
  138810. static compandblock _psy_compand_8[2]={
  138811. {{
  138812. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  138813. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  138814. 12,12,13,13,14,14,15, 15, /* 23dB */
  138815. 16,16,17,17,17,18,18, 19, /* 31dB */
  138816. 19,19,20,21,22,23,24, 25, /* 39dB */
  138817. }},
  138818. {{
  138819. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  138820. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  138821. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  138822. 9,10,11,12,13,14,15, 16, /* 31dB */
  138823. 17,18,19,20,21,22,23, 24, /* 39dB */
  138824. }},
  138825. };
  138826. static double _psy_lowpass_8[3]={3.,4.,4.};
  138827. static int _noise_start_8[2]={
  138828. 64,64,
  138829. };
  138830. static int _noise_part_8[2]={
  138831. 8,8,
  138832. };
  138833. static int _psy_ath_floater_8[3]={
  138834. -100,-100,-105,
  138835. };
  138836. static int _psy_ath_abs_8[3]={
  138837. -130,-130,-140,
  138838. };
  138839. /*** End of inlined file: psych_8.h ***/
  138840. /*** Start of inlined file: residue_8.h ***/
  138841. static static_bookblock _resbook_8s_0={
  138842. {
  138843. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  138844. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  138845. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  138846. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  138847. }
  138848. };
  138849. static static_bookblock _resbook_8s_1={
  138850. {
  138851. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  138852. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  138853. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  138854. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  138855. }
  138856. };
  138857. static vorbis_residue_template _res_8s_0[]={
  138858. {2,0, &_residue_44_mid,
  138859. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  138860. &_resbook_8s_0,&_resbook_8s_0},
  138861. };
  138862. static vorbis_residue_template _res_8s_1[]={
  138863. {2,0, &_residue_44_mid,
  138864. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  138865. &_resbook_8s_1,&_resbook_8s_1},
  138866. };
  138867. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  138868. { _map_nominal, _res_8s_0 }, /* 0 */
  138869. { _map_nominal, _res_8s_1 }, /* 1 */
  138870. };
  138871. static static_bookblock _resbook_8u_0={
  138872. {
  138873. {0},
  138874. {0,0,&_8u0__p1_0},
  138875. {0,0,&_8u0__p2_0},
  138876. {0,0,&_8u0__p3_0},
  138877. {0,0,&_8u0__p4_0},
  138878. {0,0,&_8u0__p5_0},
  138879. {&_8u0__p6_0,&_8u0__p6_1},
  138880. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  138881. }
  138882. };
  138883. static static_bookblock _resbook_8u_1={
  138884. {
  138885. {0},
  138886. {0,0,&_8u1__p1_0},
  138887. {0,0,&_8u1__p2_0},
  138888. {0,0,&_8u1__p3_0},
  138889. {0,0,&_8u1__p4_0},
  138890. {0,0,&_8u1__p5_0},
  138891. {0,0,&_8u1__p6_0},
  138892. {&_8u1__p7_0,&_8u1__p7_1},
  138893. {&_8u1__p8_0,&_8u1__p8_1},
  138894. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  138895. }
  138896. };
  138897. static vorbis_residue_template _res_8u_0[]={
  138898. {1,0, &_residue_44_low_un,
  138899. &_huff_book__8u0__single,&_huff_book__8u0__single,
  138900. &_resbook_8u_0,&_resbook_8u_0},
  138901. };
  138902. static vorbis_residue_template _res_8u_1[]={
  138903. {1,0, &_residue_44_mid_un,
  138904. &_huff_book__8u1__single,&_huff_book__8u1__single,
  138905. &_resbook_8u_1,&_resbook_8u_1},
  138906. };
  138907. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  138908. { _map_nominal_u, _res_8u_0 }, /* 0 */
  138909. { _map_nominal_u, _res_8u_1 }, /* 1 */
  138910. };
  138911. /*** End of inlined file: residue_8.h ***/
  138912. static int blocksize_8[2]={
  138913. 512,512
  138914. };
  138915. static int _floor_mapping_8[2]={
  138916. 6,6,
  138917. };
  138918. static double rate_mapping_8[3]={
  138919. 6000.,9000.,32000.,
  138920. };
  138921. static double rate_mapping_8_uncoupled[3]={
  138922. 8000.,14000.,42000.,
  138923. };
  138924. static double quality_mapping_8[3]={
  138925. -.1,.0,1.
  138926. };
  138927. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  138928. static double _global_mapping_8[3]={ 1., 2., 3. };
  138929. ve_setup_data_template ve_setup_8_stereo={
  138930. 2,
  138931. rate_mapping_8,
  138932. quality_mapping_8,
  138933. 2,
  138934. 8000,
  138935. 9000,
  138936. blocksize_8,
  138937. blocksize_8,
  138938. _psy_tone_masteratt_8,
  138939. _psy_tone_0dB,
  138940. _psy_tone_suppress,
  138941. _vp_tonemask_adj_8,
  138942. NULL,
  138943. _vp_tonemask_adj_8,
  138944. _psy_noiseguards_8,
  138945. _psy_noisebias_8,
  138946. _psy_noisebias_8,
  138947. NULL,
  138948. NULL,
  138949. _psy_noise_suppress,
  138950. _psy_compand_8,
  138951. _psy_compand_8_mapping,
  138952. NULL,
  138953. {_noise_start_8,_noise_start_8},
  138954. {_noise_part_8,_noise_part_8},
  138955. _noise_thresh_5only,
  138956. _psy_ath_floater_8,
  138957. _psy_ath_abs_8,
  138958. _psy_lowpass_8,
  138959. _psy_global_44,
  138960. _global_mapping_8,
  138961. _psy_stereo_modes_8,
  138962. _floor_books,
  138963. _floor,
  138964. _floor_mapping_8,
  138965. NULL,
  138966. _mapres_template_8_stereo
  138967. };
  138968. ve_setup_data_template ve_setup_8_uncoupled={
  138969. 2,
  138970. rate_mapping_8_uncoupled,
  138971. quality_mapping_8,
  138972. -1,
  138973. 8000,
  138974. 9000,
  138975. blocksize_8,
  138976. blocksize_8,
  138977. _psy_tone_masteratt_8,
  138978. _psy_tone_0dB,
  138979. _psy_tone_suppress,
  138980. _vp_tonemask_adj_8,
  138981. NULL,
  138982. _vp_tonemask_adj_8,
  138983. _psy_noiseguards_8,
  138984. _psy_noisebias_8,
  138985. _psy_noisebias_8,
  138986. NULL,
  138987. NULL,
  138988. _psy_noise_suppress,
  138989. _psy_compand_8,
  138990. _psy_compand_8_mapping,
  138991. NULL,
  138992. {_noise_start_8,_noise_start_8},
  138993. {_noise_part_8,_noise_part_8},
  138994. _noise_thresh_5only,
  138995. _psy_ath_floater_8,
  138996. _psy_ath_abs_8,
  138997. _psy_lowpass_8,
  138998. _psy_global_44,
  138999. _global_mapping_8,
  139000. _psy_stereo_modes_8,
  139001. _floor_books,
  139002. _floor,
  139003. _floor_mapping_8,
  139004. NULL,
  139005. _mapres_template_8_uncoupled
  139006. };
  139007. /*** End of inlined file: setup_8.h ***/
  139008. /*** Start of inlined file: setup_11.h ***/
  139009. /*** Start of inlined file: psych_11.h ***/
  139010. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139011. static att3 _psy_tone_masteratt_11[3]={
  139012. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139013. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139014. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139015. };
  139016. static vp_adjblock _vp_tonemask_adj_11[3]={
  139017. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139018. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139019. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139020. };
  139021. static noise3 _psy_noisebias_11[3]={
  139022. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139023. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139024. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139025. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139026. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139027. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139028. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139029. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139030. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139031. };
  139032. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139033. /*** End of inlined file: psych_11.h ***/
  139034. static int blocksize_11[2]={
  139035. 512,512
  139036. };
  139037. static int _floor_mapping_11[2]={
  139038. 6,6,
  139039. };
  139040. static double rate_mapping_11[3]={
  139041. 8000.,13000.,44000.,
  139042. };
  139043. static double rate_mapping_11_uncoupled[3]={
  139044. 12000.,20000.,50000.,
  139045. };
  139046. static double quality_mapping_11[3]={
  139047. -.1,.0,1.
  139048. };
  139049. ve_setup_data_template ve_setup_11_stereo={
  139050. 2,
  139051. rate_mapping_11,
  139052. quality_mapping_11,
  139053. 2,
  139054. 9000,
  139055. 15000,
  139056. blocksize_11,
  139057. blocksize_11,
  139058. _psy_tone_masteratt_11,
  139059. _psy_tone_0dB,
  139060. _psy_tone_suppress,
  139061. _vp_tonemask_adj_11,
  139062. NULL,
  139063. _vp_tonemask_adj_11,
  139064. _psy_noiseguards_8,
  139065. _psy_noisebias_11,
  139066. _psy_noisebias_11,
  139067. NULL,
  139068. NULL,
  139069. _psy_noise_suppress,
  139070. _psy_compand_8,
  139071. _psy_compand_8_mapping,
  139072. NULL,
  139073. {_noise_start_8,_noise_start_8},
  139074. {_noise_part_8,_noise_part_8},
  139075. _noise_thresh_11,
  139076. _psy_ath_floater_8,
  139077. _psy_ath_abs_8,
  139078. _psy_lowpass_11,
  139079. _psy_global_44,
  139080. _global_mapping_8,
  139081. _psy_stereo_modes_8,
  139082. _floor_books,
  139083. _floor,
  139084. _floor_mapping_11,
  139085. NULL,
  139086. _mapres_template_8_stereo
  139087. };
  139088. ve_setup_data_template ve_setup_11_uncoupled={
  139089. 2,
  139090. rate_mapping_11_uncoupled,
  139091. quality_mapping_11,
  139092. -1,
  139093. 9000,
  139094. 15000,
  139095. blocksize_11,
  139096. blocksize_11,
  139097. _psy_tone_masteratt_11,
  139098. _psy_tone_0dB,
  139099. _psy_tone_suppress,
  139100. _vp_tonemask_adj_11,
  139101. NULL,
  139102. _vp_tonemask_adj_11,
  139103. _psy_noiseguards_8,
  139104. _psy_noisebias_11,
  139105. _psy_noisebias_11,
  139106. NULL,
  139107. NULL,
  139108. _psy_noise_suppress,
  139109. _psy_compand_8,
  139110. _psy_compand_8_mapping,
  139111. NULL,
  139112. {_noise_start_8,_noise_start_8},
  139113. {_noise_part_8,_noise_part_8},
  139114. _noise_thresh_11,
  139115. _psy_ath_floater_8,
  139116. _psy_ath_abs_8,
  139117. _psy_lowpass_11,
  139118. _psy_global_44,
  139119. _global_mapping_8,
  139120. _psy_stereo_modes_8,
  139121. _floor_books,
  139122. _floor,
  139123. _floor_mapping_11,
  139124. NULL,
  139125. _mapres_template_8_uncoupled
  139126. };
  139127. /*** End of inlined file: setup_11.h ***/
  139128. /*** Start of inlined file: setup_16.h ***/
  139129. /*** Start of inlined file: psych_16.h ***/
  139130. static adj_stereo _psy_stereo_modes_16[4]={
  139131. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139132. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139133. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139134. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139135. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139136. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139137. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139138. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139139. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139140. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139141. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139142. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139143. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139144. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139145. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139146. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139147. };
  139148. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139149. static att3 _psy_tone_masteratt_16[4]={
  139150. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139151. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139152. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139153. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139154. };
  139155. static vp_adjblock _vp_tonemask_adj_16[4]={
  139156. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139157. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139158. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139159. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139160. };
  139161. static noise3 _psy_noisebias_16_short[4]={
  139162. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139163. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139164. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139165. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139166. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139167. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139168. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139169. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139170. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139171. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139172. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139173. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139174. };
  139175. static noise3 _psy_noisebias_16_impulse[4]={
  139176. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139177. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139178. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139179. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139180. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139181. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139182. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139183. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139184. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139185. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139186. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139187. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139188. };
  139189. static noise3 _psy_noisebias_16[4]={
  139190. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139191. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139192. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139193. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139194. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139195. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139196. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139197. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139198. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139199. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139200. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139201. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139202. };
  139203. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139204. static int _noise_start_16[3]={ 256,256,9999 };
  139205. static int _noise_part_16[4]={ 8,8,8,8 };
  139206. static int _psy_ath_floater_16[4]={
  139207. -100,-100,-100,-105,
  139208. };
  139209. static int _psy_ath_abs_16[4]={
  139210. -130,-130,-130,-140,
  139211. };
  139212. /*** End of inlined file: psych_16.h ***/
  139213. /*** Start of inlined file: residue_16.h ***/
  139214. static static_bookblock _resbook_16s_0={
  139215. {
  139216. {0},
  139217. {0,0,&_16c0_s_p1_0},
  139218. {0,0,&_16c0_s_p2_0},
  139219. {0,0,&_16c0_s_p3_0},
  139220. {0,0,&_16c0_s_p4_0},
  139221. {0,0,&_16c0_s_p5_0},
  139222. {0,0,&_16c0_s_p6_0},
  139223. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139224. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139225. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139226. }
  139227. };
  139228. static static_bookblock _resbook_16s_1={
  139229. {
  139230. {0},
  139231. {0,0,&_16c1_s_p1_0},
  139232. {0,0,&_16c1_s_p2_0},
  139233. {0,0,&_16c1_s_p3_0},
  139234. {0,0,&_16c1_s_p4_0},
  139235. {0,0,&_16c1_s_p5_0},
  139236. {0,0,&_16c1_s_p6_0},
  139237. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139238. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139239. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139240. }
  139241. };
  139242. static static_bookblock _resbook_16s_2={
  139243. {
  139244. {0},
  139245. {0,0,&_16c2_s_p1_0},
  139246. {0,0,&_16c2_s_p2_0},
  139247. {0,0,&_16c2_s_p3_0},
  139248. {0,0,&_16c2_s_p4_0},
  139249. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139250. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139251. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139252. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139253. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139254. }
  139255. };
  139256. static vorbis_residue_template _res_16s_0[]={
  139257. {2,0, &_residue_44_mid,
  139258. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139259. &_resbook_16s_0,&_resbook_16s_0},
  139260. };
  139261. static vorbis_residue_template _res_16s_1[]={
  139262. {2,0, &_residue_44_mid,
  139263. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139264. &_resbook_16s_1,&_resbook_16s_1},
  139265. {2,0, &_residue_44_mid,
  139266. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139267. &_resbook_16s_1,&_resbook_16s_1}
  139268. };
  139269. static vorbis_residue_template _res_16s_2[]={
  139270. {2,0, &_residue_44_high,
  139271. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139272. &_resbook_16s_2,&_resbook_16s_2},
  139273. {2,0, &_residue_44_high,
  139274. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139275. &_resbook_16s_2,&_resbook_16s_2}
  139276. };
  139277. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139278. { _map_nominal, _res_16s_0 }, /* 0 */
  139279. { _map_nominal, _res_16s_1 }, /* 1 */
  139280. { _map_nominal, _res_16s_2 }, /* 2 */
  139281. };
  139282. static static_bookblock _resbook_16u_0={
  139283. {
  139284. {0},
  139285. {0,0,&_16u0__p1_0},
  139286. {0,0,&_16u0__p2_0},
  139287. {0,0,&_16u0__p3_0},
  139288. {0,0,&_16u0__p4_0},
  139289. {0,0,&_16u0__p5_0},
  139290. {&_16u0__p6_0,&_16u0__p6_1},
  139291. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139292. }
  139293. };
  139294. static static_bookblock _resbook_16u_1={
  139295. {
  139296. {0},
  139297. {0,0,&_16u1__p1_0},
  139298. {0,0,&_16u1__p2_0},
  139299. {0,0,&_16u1__p3_0},
  139300. {0,0,&_16u1__p4_0},
  139301. {0,0,&_16u1__p5_0},
  139302. {0,0,&_16u1__p6_0},
  139303. {&_16u1__p7_0,&_16u1__p7_1},
  139304. {&_16u1__p8_0,&_16u1__p8_1},
  139305. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139306. }
  139307. };
  139308. static static_bookblock _resbook_16u_2={
  139309. {
  139310. {0},
  139311. {0,0,&_16u2_p1_0},
  139312. {0,0,&_16u2_p2_0},
  139313. {0,0,&_16u2_p3_0},
  139314. {0,0,&_16u2_p4_0},
  139315. {&_16u2_p5_0,&_16u2_p5_1},
  139316. {&_16u2_p6_0,&_16u2_p6_1},
  139317. {&_16u2_p7_0,&_16u2_p7_1},
  139318. {&_16u2_p8_0,&_16u2_p8_1},
  139319. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139320. }
  139321. };
  139322. static vorbis_residue_template _res_16u_0[]={
  139323. {1,0, &_residue_44_low_un,
  139324. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139325. &_resbook_16u_0,&_resbook_16u_0},
  139326. };
  139327. static vorbis_residue_template _res_16u_1[]={
  139328. {1,0, &_residue_44_mid_un,
  139329. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139330. &_resbook_16u_1,&_resbook_16u_1},
  139331. {1,0, &_residue_44_mid_un,
  139332. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139333. &_resbook_16u_1,&_resbook_16u_1}
  139334. };
  139335. static vorbis_residue_template _res_16u_2[]={
  139336. {1,0, &_residue_44_hi_un,
  139337. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139338. &_resbook_16u_2,&_resbook_16u_2},
  139339. {1,0, &_residue_44_hi_un,
  139340. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139341. &_resbook_16u_2,&_resbook_16u_2}
  139342. };
  139343. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139344. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139345. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139346. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139347. };
  139348. /*** End of inlined file: residue_16.h ***/
  139349. static int blocksize_16_short[3]={
  139350. 1024,512,512
  139351. };
  139352. static int blocksize_16_long[3]={
  139353. 1024,1024,1024
  139354. };
  139355. static int _floor_mapping_16_short[3]={
  139356. 9,3,3
  139357. };
  139358. static int _floor_mapping_16[3]={
  139359. 9,9,9
  139360. };
  139361. static double rate_mapping_16[4]={
  139362. 12000.,20000.,44000.,86000.
  139363. };
  139364. static double rate_mapping_16_uncoupled[4]={
  139365. 16000.,28000.,64000.,100000.
  139366. };
  139367. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139368. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139369. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139370. ve_setup_data_template ve_setup_16_stereo={
  139371. 3,
  139372. rate_mapping_16,
  139373. quality_mapping_16,
  139374. 2,
  139375. 15000,
  139376. 19000,
  139377. blocksize_16_short,
  139378. blocksize_16_long,
  139379. _psy_tone_masteratt_16,
  139380. _psy_tone_0dB,
  139381. _psy_tone_suppress,
  139382. _vp_tonemask_adj_16,
  139383. _vp_tonemask_adj_16,
  139384. _vp_tonemask_adj_16,
  139385. _psy_noiseguards_8,
  139386. _psy_noisebias_16_impulse,
  139387. _psy_noisebias_16_short,
  139388. _psy_noisebias_16_short,
  139389. _psy_noisebias_16,
  139390. _psy_noise_suppress,
  139391. _psy_compand_8,
  139392. _psy_compand_16_mapping,
  139393. _psy_compand_16_mapping,
  139394. {_noise_start_16,_noise_start_16},
  139395. { _noise_part_16, _noise_part_16},
  139396. _noise_thresh_16,
  139397. _psy_ath_floater_16,
  139398. _psy_ath_abs_16,
  139399. _psy_lowpass_16,
  139400. _psy_global_44,
  139401. _global_mapping_16,
  139402. _psy_stereo_modes_16,
  139403. _floor_books,
  139404. _floor,
  139405. _floor_mapping_16_short,
  139406. _floor_mapping_16,
  139407. _mapres_template_16_stereo
  139408. };
  139409. ve_setup_data_template ve_setup_16_uncoupled={
  139410. 3,
  139411. rate_mapping_16_uncoupled,
  139412. quality_mapping_16,
  139413. -1,
  139414. 15000,
  139415. 19000,
  139416. blocksize_16_short,
  139417. blocksize_16_long,
  139418. _psy_tone_masteratt_16,
  139419. _psy_tone_0dB,
  139420. _psy_tone_suppress,
  139421. _vp_tonemask_adj_16,
  139422. _vp_tonemask_adj_16,
  139423. _vp_tonemask_adj_16,
  139424. _psy_noiseguards_8,
  139425. _psy_noisebias_16_impulse,
  139426. _psy_noisebias_16_short,
  139427. _psy_noisebias_16_short,
  139428. _psy_noisebias_16,
  139429. _psy_noise_suppress,
  139430. _psy_compand_8,
  139431. _psy_compand_16_mapping,
  139432. _psy_compand_16_mapping,
  139433. {_noise_start_16,_noise_start_16},
  139434. { _noise_part_16, _noise_part_16},
  139435. _noise_thresh_16,
  139436. _psy_ath_floater_16,
  139437. _psy_ath_abs_16,
  139438. _psy_lowpass_16,
  139439. _psy_global_44,
  139440. _global_mapping_16,
  139441. _psy_stereo_modes_16,
  139442. _floor_books,
  139443. _floor,
  139444. _floor_mapping_16_short,
  139445. _floor_mapping_16,
  139446. _mapres_template_16_uncoupled
  139447. };
  139448. /*** End of inlined file: setup_16.h ***/
  139449. /*** Start of inlined file: setup_22.h ***/
  139450. static double rate_mapping_22[4]={
  139451. 15000.,20000.,44000.,86000.
  139452. };
  139453. static double rate_mapping_22_uncoupled[4]={
  139454. 16000.,28000.,50000.,90000.
  139455. };
  139456. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139457. ve_setup_data_template ve_setup_22_stereo={
  139458. 3,
  139459. rate_mapping_22,
  139460. quality_mapping_16,
  139461. 2,
  139462. 19000,
  139463. 26000,
  139464. blocksize_16_short,
  139465. blocksize_16_long,
  139466. _psy_tone_masteratt_16,
  139467. _psy_tone_0dB,
  139468. _psy_tone_suppress,
  139469. _vp_tonemask_adj_16,
  139470. _vp_tonemask_adj_16,
  139471. _vp_tonemask_adj_16,
  139472. _psy_noiseguards_8,
  139473. _psy_noisebias_16_impulse,
  139474. _psy_noisebias_16_short,
  139475. _psy_noisebias_16_short,
  139476. _psy_noisebias_16,
  139477. _psy_noise_suppress,
  139478. _psy_compand_8,
  139479. _psy_compand_8_mapping,
  139480. _psy_compand_8_mapping,
  139481. {_noise_start_16,_noise_start_16},
  139482. { _noise_part_16, _noise_part_16},
  139483. _noise_thresh_16,
  139484. _psy_ath_floater_16,
  139485. _psy_ath_abs_16,
  139486. _psy_lowpass_22,
  139487. _psy_global_44,
  139488. _global_mapping_16,
  139489. _psy_stereo_modes_16,
  139490. _floor_books,
  139491. _floor,
  139492. _floor_mapping_16_short,
  139493. _floor_mapping_16,
  139494. _mapres_template_16_stereo
  139495. };
  139496. ve_setup_data_template ve_setup_22_uncoupled={
  139497. 3,
  139498. rate_mapping_22_uncoupled,
  139499. quality_mapping_16,
  139500. -1,
  139501. 19000,
  139502. 26000,
  139503. blocksize_16_short,
  139504. blocksize_16_long,
  139505. _psy_tone_masteratt_16,
  139506. _psy_tone_0dB,
  139507. _psy_tone_suppress,
  139508. _vp_tonemask_adj_16,
  139509. _vp_tonemask_adj_16,
  139510. _vp_tonemask_adj_16,
  139511. _psy_noiseguards_8,
  139512. _psy_noisebias_16_impulse,
  139513. _psy_noisebias_16_short,
  139514. _psy_noisebias_16_short,
  139515. _psy_noisebias_16,
  139516. _psy_noise_suppress,
  139517. _psy_compand_8,
  139518. _psy_compand_8_mapping,
  139519. _psy_compand_8_mapping,
  139520. {_noise_start_16,_noise_start_16},
  139521. { _noise_part_16, _noise_part_16},
  139522. _noise_thresh_16,
  139523. _psy_ath_floater_16,
  139524. _psy_ath_abs_16,
  139525. _psy_lowpass_22,
  139526. _psy_global_44,
  139527. _global_mapping_16,
  139528. _psy_stereo_modes_16,
  139529. _floor_books,
  139530. _floor,
  139531. _floor_mapping_16_short,
  139532. _floor_mapping_16,
  139533. _mapres_template_16_uncoupled
  139534. };
  139535. /*** End of inlined file: setup_22.h ***/
  139536. /*** Start of inlined file: setup_X.h ***/
  139537. static double rate_mapping_X[12]={
  139538. -1.,-1.,-1.,-1.,-1.,-1.,
  139539. -1.,-1.,-1.,-1.,-1.,-1.
  139540. };
  139541. ve_setup_data_template ve_setup_X_stereo={
  139542. 11,
  139543. rate_mapping_X,
  139544. quality_mapping_44,
  139545. 2,
  139546. 50000,
  139547. 200000,
  139548. blocksize_short_44,
  139549. blocksize_long_44,
  139550. _psy_tone_masteratt_44,
  139551. _psy_tone_0dB,
  139552. _psy_tone_suppress,
  139553. _vp_tonemask_adj_otherblock,
  139554. _vp_tonemask_adj_longblock,
  139555. _vp_tonemask_adj_otherblock,
  139556. _psy_noiseguards_44,
  139557. _psy_noisebias_impulse,
  139558. _psy_noisebias_padding,
  139559. _psy_noisebias_trans,
  139560. _psy_noisebias_long,
  139561. _psy_noise_suppress,
  139562. _psy_compand_44,
  139563. _psy_compand_short_mapping,
  139564. _psy_compand_long_mapping,
  139565. {_noise_start_short_44,_noise_start_long_44},
  139566. {_noise_part_short_44,_noise_part_long_44},
  139567. _noise_thresh_44,
  139568. _psy_ath_floater,
  139569. _psy_ath_abs,
  139570. _psy_lowpass_44,
  139571. _psy_global_44,
  139572. _global_mapping_44,
  139573. _psy_stereo_modes_44,
  139574. _floor_books,
  139575. _floor,
  139576. _floor_short_mapping_44,
  139577. _floor_long_mapping_44,
  139578. _mapres_template_44_stereo
  139579. };
  139580. ve_setup_data_template ve_setup_X_uncoupled={
  139581. 11,
  139582. rate_mapping_X,
  139583. quality_mapping_44,
  139584. -1,
  139585. 50000,
  139586. 200000,
  139587. blocksize_short_44,
  139588. blocksize_long_44,
  139589. _psy_tone_masteratt_44,
  139590. _psy_tone_0dB,
  139591. _psy_tone_suppress,
  139592. _vp_tonemask_adj_otherblock,
  139593. _vp_tonemask_adj_longblock,
  139594. _vp_tonemask_adj_otherblock,
  139595. _psy_noiseguards_44,
  139596. _psy_noisebias_impulse,
  139597. _psy_noisebias_padding,
  139598. _psy_noisebias_trans,
  139599. _psy_noisebias_long,
  139600. _psy_noise_suppress,
  139601. _psy_compand_44,
  139602. _psy_compand_short_mapping,
  139603. _psy_compand_long_mapping,
  139604. {_noise_start_short_44,_noise_start_long_44},
  139605. {_noise_part_short_44,_noise_part_long_44},
  139606. _noise_thresh_44,
  139607. _psy_ath_floater,
  139608. _psy_ath_abs,
  139609. _psy_lowpass_44,
  139610. _psy_global_44,
  139611. _global_mapping_44,
  139612. NULL,
  139613. _floor_books,
  139614. _floor,
  139615. _floor_short_mapping_44,
  139616. _floor_long_mapping_44,
  139617. _mapres_template_44_uncoupled
  139618. };
  139619. ve_setup_data_template ve_setup_XX_stereo={
  139620. 2,
  139621. rate_mapping_X,
  139622. quality_mapping_8,
  139623. 2,
  139624. 0,
  139625. 8000,
  139626. blocksize_8,
  139627. blocksize_8,
  139628. _psy_tone_masteratt_8,
  139629. _psy_tone_0dB,
  139630. _psy_tone_suppress,
  139631. _vp_tonemask_adj_8,
  139632. NULL,
  139633. _vp_tonemask_adj_8,
  139634. _psy_noiseguards_8,
  139635. _psy_noisebias_8,
  139636. _psy_noisebias_8,
  139637. NULL,
  139638. NULL,
  139639. _psy_noise_suppress,
  139640. _psy_compand_8,
  139641. _psy_compand_8_mapping,
  139642. NULL,
  139643. {_noise_start_8,_noise_start_8},
  139644. {_noise_part_8,_noise_part_8},
  139645. _noise_thresh_5only,
  139646. _psy_ath_floater_8,
  139647. _psy_ath_abs_8,
  139648. _psy_lowpass_8,
  139649. _psy_global_44,
  139650. _global_mapping_8,
  139651. _psy_stereo_modes_8,
  139652. _floor_books,
  139653. _floor,
  139654. _floor_mapping_8,
  139655. NULL,
  139656. _mapres_template_8_stereo
  139657. };
  139658. ve_setup_data_template ve_setup_XX_uncoupled={
  139659. 2,
  139660. rate_mapping_X,
  139661. quality_mapping_8,
  139662. -1,
  139663. 0,
  139664. 8000,
  139665. blocksize_8,
  139666. blocksize_8,
  139667. _psy_tone_masteratt_8,
  139668. _psy_tone_0dB,
  139669. _psy_tone_suppress,
  139670. _vp_tonemask_adj_8,
  139671. NULL,
  139672. _vp_tonemask_adj_8,
  139673. _psy_noiseguards_8,
  139674. _psy_noisebias_8,
  139675. _psy_noisebias_8,
  139676. NULL,
  139677. NULL,
  139678. _psy_noise_suppress,
  139679. _psy_compand_8,
  139680. _psy_compand_8_mapping,
  139681. NULL,
  139682. {_noise_start_8,_noise_start_8},
  139683. {_noise_part_8,_noise_part_8},
  139684. _noise_thresh_5only,
  139685. _psy_ath_floater_8,
  139686. _psy_ath_abs_8,
  139687. _psy_lowpass_8,
  139688. _psy_global_44,
  139689. _global_mapping_8,
  139690. _psy_stereo_modes_8,
  139691. _floor_books,
  139692. _floor,
  139693. _floor_mapping_8,
  139694. NULL,
  139695. _mapres_template_8_uncoupled
  139696. };
  139697. /*** End of inlined file: setup_X.h ***/
  139698. static ve_setup_data_template *setup_list[]={
  139699. &ve_setup_44_stereo,
  139700. &ve_setup_44_uncoupled,
  139701. &ve_setup_32_stereo,
  139702. &ve_setup_32_uncoupled,
  139703. &ve_setup_22_stereo,
  139704. &ve_setup_22_uncoupled,
  139705. &ve_setup_16_stereo,
  139706. &ve_setup_16_uncoupled,
  139707. &ve_setup_11_stereo,
  139708. &ve_setup_11_uncoupled,
  139709. &ve_setup_8_stereo,
  139710. &ve_setup_8_uncoupled,
  139711. &ve_setup_X_stereo,
  139712. &ve_setup_X_uncoupled,
  139713. &ve_setup_XX_stereo,
  139714. &ve_setup_XX_uncoupled,
  139715. 0
  139716. };
  139717. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  139718. if(vi && vi->codec_setup){
  139719. vi->version=0;
  139720. vi->channels=ch;
  139721. vi->rate=rate;
  139722. return(0);
  139723. }
  139724. return(OV_EINVAL);
  139725. }
  139726. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  139727. static_codebook ***books,
  139728. vorbis_info_floor1 *in,
  139729. int *x){
  139730. int i,k,is=s;
  139731. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  139732. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139733. memcpy(f,in+x[is],sizeof(*f));
  139734. f->n=ci->blocksizes[block]>>1;
  139735. {
  139736. int partitions=f->partitions;
  139737. int maxclass=-1;
  139738. int maxbook=-1;
  139739. for(i=0;i<partitions;i++)
  139740. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  139741. for(i=0;i<=maxclass;i++){
  139742. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  139743. f->class_book[i]+=ci->books;
  139744. for(k=0;k<(1<<f->class_subs[i]);k++){
  139745. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  139746. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  139747. }
  139748. }
  139749. for(i=0;i<=maxbook;i++)
  139750. ci->book_param[ci->books++]=books[x[is]][i];
  139751. }
  139752. ci->floor_type[ci->floors]=1;
  139753. ci->floor_param[ci->floors]=f;
  139754. ci->floors++;
  139755. return;
  139756. }
  139757. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  139758. vorbis_info_psy_global *in,
  139759. double *x){
  139760. int i,is=s;
  139761. double ds=s-is;
  139762. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139763. vorbis_info_psy_global *g=&ci->psy_g_param;
  139764. memcpy(g,in+(int)x[is],sizeof(*g));
  139765. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139766. is=(int)ds;
  139767. ds-=is;
  139768. if(ds==0 && is>0){
  139769. is--;
  139770. ds=1.;
  139771. }
  139772. for(i=0;i<4;i++){
  139773. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  139774. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  139775. }
  139776. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  139777. return;
  139778. }
  139779. static void vorbis_encode_global_stereo(vorbis_info *vi,
  139780. highlevel_encode_setup *hi,
  139781. adj_stereo *p){
  139782. float s=hi->stereo_point_setting;
  139783. int i,is=s;
  139784. double ds=s-is;
  139785. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139786. vorbis_info_psy_global *g=&ci->psy_g_param;
  139787. if(p){
  139788. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  139789. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  139790. if(hi->managed){
  139791. for(i=0;i<PACKETBLOBS;i++){
  139792. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  139793. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139794. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139795. g->coupling_pkHz[i]=kHz;
  139796. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  139797. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139798. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139799. }
  139800. }else{
  139801. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  139802. for(i=0;i<PACKETBLOBS;i++){
  139803. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139804. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139805. g->coupling_pkHz[i]=kHz;
  139806. }
  139807. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  139808. for(i=0;i<PACKETBLOBS;i++){
  139809. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139810. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139811. }
  139812. }
  139813. }else{
  139814. for(i=0;i<PACKETBLOBS;i++){
  139815. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  139816. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  139817. }
  139818. }
  139819. return;
  139820. }
  139821. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  139822. int *nn_start,
  139823. int *nn_partition,
  139824. double *nn_thresh,
  139825. int block){
  139826. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  139827. vorbis_info_psy *p=ci->psy_param[block];
  139828. highlevel_encode_setup *hi=&ci->hi;
  139829. int is=s;
  139830. if(block>=ci->psys)
  139831. ci->psys=block+1;
  139832. if(!p){
  139833. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  139834. ci->psy_param[block]=p;
  139835. }
  139836. memcpy(p,&_psy_info_template,sizeof(*p));
  139837. p->blockflag=block>>1;
  139838. if(hi->noise_normalize_p){
  139839. p->normal_channel_p=1;
  139840. p->normal_point_p=1;
  139841. p->normal_start=nn_start[is];
  139842. p->normal_partition=nn_partition[is];
  139843. p->normal_thresh=nn_thresh[is];
  139844. }
  139845. return;
  139846. }
  139847. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  139848. att3 *att,
  139849. int *max,
  139850. vp_adjblock *in){
  139851. int i,is=s;
  139852. double ds=s-is;
  139853. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  139854. vorbis_info_psy *p=ci->psy_param[block];
  139855. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  139856. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  139857. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  139858. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  139859. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  139860. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  139861. for(i=0;i<P_BANDS;i++)
  139862. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  139863. return;
  139864. }
  139865. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  139866. compandblock *in, double *x){
  139867. int i,is=s;
  139868. double ds=s-is;
  139869. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139870. vorbis_info_psy *p=ci->psy_param[block];
  139871. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139872. is=(int)ds;
  139873. ds-=is;
  139874. if(ds==0 && is>0){
  139875. is--;
  139876. ds=1.;
  139877. }
  139878. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  139879. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  139880. return;
  139881. }
  139882. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  139883. int *suppress){
  139884. int is=s;
  139885. double ds=s-is;
  139886. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139887. vorbis_info_psy *p=ci->psy_param[block];
  139888. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  139889. return;
  139890. }
  139891. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  139892. int *suppress,
  139893. noise3 *in,
  139894. noiseguard *guard,
  139895. double userbias){
  139896. int i,is=s,j;
  139897. double ds=s-is;
  139898. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139899. vorbis_info_psy *p=ci->psy_param[block];
  139900. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  139901. p->noisewindowlomin=guard[block].lo;
  139902. p->noisewindowhimin=guard[block].hi;
  139903. p->noisewindowfixed=guard[block].fixed;
  139904. for(j=0;j<P_NOISECURVES;j++)
  139905. for(i=0;i<P_BANDS;i++)
  139906. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  139907. for(j=0;j<P_NOISECURVES;j++){
  139908. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  139909. for(i=0;i<P_BANDS;i++){
  139910. p->noiseoff[j][i]+=userbias;
  139911. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  139912. }
  139913. }
  139914. return;
  139915. }
  139916. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  139917. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139918. vorbis_info_psy *p=ci->psy_param[block];
  139919. p->ath_adjatt=ci->hi.ath_floating_dB;
  139920. p->ath_maxatt=ci->hi.ath_absolute_dB;
  139921. return;
  139922. }
  139923. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  139924. int i;
  139925. for(i=0;i<ci->books;i++)
  139926. if(ci->book_param[i]==book)return(i);
  139927. return(ci->books++);
  139928. }
  139929. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  139930. int *shortb,int *longb){
  139931. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139932. int is=s;
  139933. int blockshort=shortb[is];
  139934. int blocklong=longb[is];
  139935. ci->blocksizes[0]=blockshort;
  139936. ci->blocksizes[1]=blocklong;
  139937. }
  139938. static void vorbis_encode_residue_setup(vorbis_info *vi,
  139939. int number, int block,
  139940. vorbis_residue_template *res){
  139941. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139942. int i,n;
  139943. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  139944. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  139945. memcpy(r,res->res,sizeof(*r));
  139946. if(ci->residues<=number)ci->residues=number+1;
  139947. switch(ci->blocksizes[block]){
  139948. case 64:case 128:case 256:
  139949. r->grouping=16;
  139950. break;
  139951. default:
  139952. r->grouping=32;
  139953. break;
  139954. }
  139955. ci->residue_type[number]=res->res_type;
  139956. n=r->end=ci->blocksizes[block]>>1;
  139957. if(res->res_type==2)
  139958. n=r->end*=vi->channels;
  139959. {
  139960. int booklist=0,k;
  139961. if(ci->hi.managed){
  139962. for(i=0;i<r->partitions;i++)
  139963. for(k=0;k<3;k++)
  139964. if(res->books_base_managed->books[i][k])
  139965. r->secondstages[i]|=(1<<k);
  139966. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  139967. ci->book_param[r->groupbook]=res->book_aux_managed;
  139968. for(i=0;i<r->partitions;i++){
  139969. for(k=0;k<3;k++){
  139970. if(res->books_base_managed->books[i][k]){
  139971. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  139972. r->booklist[booklist++]=bookid;
  139973. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  139974. }
  139975. }
  139976. }
  139977. }else{
  139978. for(i=0;i<r->partitions;i++)
  139979. for(k=0;k<3;k++)
  139980. if(res->books_base->books[i][k])
  139981. r->secondstages[i]|=(1<<k);
  139982. r->groupbook=book_dup_or_new(ci,res->book_aux);
  139983. ci->book_param[r->groupbook]=res->book_aux;
  139984. for(i=0;i<r->partitions;i++){
  139985. for(k=0;k<3;k++){
  139986. if(res->books_base->books[i][k]){
  139987. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  139988. r->booklist[booklist++]=bookid;
  139989. ci->book_param[bookid]=res->books_base->books[i][k];
  139990. }
  139991. }
  139992. }
  139993. }
  139994. }
  139995. {
  139996. double freq=ci->hi.lowpass_kHz*1000.;
  139997. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  139998. double nyq=vi->rate/2.;
  139999. long blocksize=ci->blocksizes[block]>>1;
  140000. if(freq>nyq)freq=nyq;
  140001. f->n=freq/nyq*blocksize;
  140002. if(res->limit_type){
  140003. if(ci->hi.managed)
  140004. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140005. else
  140006. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140007. if(freq>nyq)freq=nyq;
  140008. }
  140009. if(ci->residue_type[block]==2)
  140010. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140011. r->grouping;
  140012. else
  140013. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140014. r->grouping;
  140015. }
  140016. }
  140017. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140018. vorbis_mapping_template *maps){
  140019. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140020. int i,j,is=s,modes=2;
  140021. vorbis_info_mapping0 *map=maps[is].map;
  140022. vorbis_info_mode *mode=_mode_template;
  140023. vorbis_residue_template *res=maps[is].res;
  140024. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140025. for(i=0;i<modes;i++){
  140026. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140027. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140028. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140029. if(i>=ci->modes)ci->modes=i+1;
  140030. ci->map_type[i]=0;
  140031. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140032. if(i>=ci->maps)ci->maps=i+1;
  140033. for(j=0;j<map[i].submaps;j++)
  140034. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140035. ,res+map[i].residuesubmap[j]);
  140036. }
  140037. }
  140038. static double setting_to_approx_bitrate(vorbis_info *vi){
  140039. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140040. highlevel_encode_setup *hi=&ci->hi;
  140041. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140042. int is=hi->base_setting;
  140043. double ds=hi->base_setting-is;
  140044. int ch=vi->channels;
  140045. double *r=setup->rate_mapping;
  140046. if(r==NULL)
  140047. return(-1);
  140048. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140049. }
  140050. static void get_setup_template(vorbis_info *vi,
  140051. long ch,long srate,
  140052. double req,int q_or_bitrate){
  140053. int i=0,j;
  140054. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140055. highlevel_encode_setup *hi=&ci->hi;
  140056. if(q_or_bitrate)req/=ch;
  140057. while(setup_list[i]){
  140058. if(setup_list[i]->coupling_restriction==-1 ||
  140059. setup_list[i]->coupling_restriction==ch){
  140060. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140061. srate<=setup_list[i]->samplerate_max_restriction){
  140062. int mappings=setup_list[i]->mappings;
  140063. double *map=(q_or_bitrate?
  140064. setup_list[i]->rate_mapping:
  140065. setup_list[i]->quality_mapping);
  140066. if(req<map[0]){++i;continue;}
  140067. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140068. for(j=0;j<mappings;j++)
  140069. if(req>=map[j] && req<map[j+1])break;
  140070. hi->setup=setup_list[i];
  140071. if(j==mappings)
  140072. hi->base_setting=j-.001;
  140073. else{
  140074. float low=map[j];
  140075. float high=map[j+1];
  140076. float del=(req-low)/(high-low);
  140077. hi->base_setting=j+del;
  140078. }
  140079. return;
  140080. }
  140081. }
  140082. i++;
  140083. }
  140084. hi->setup=NULL;
  140085. }
  140086. int vorbis_encode_setup_init(vorbis_info *vi){
  140087. int i0=0,singleblock=0;
  140088. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140089. ve_setup_data_template *setup=NULL;
  140090. highlevel_encode_setup *hi=&ci->hi;
  140091. if(ci==NULL)return(OV_EINVAL);
  140092. if(!hi->impulse_block_p)i0=1;
  140093. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140094. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140095. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140096. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140097. setup=(ve_setup_data_template *)hi->setup;
  140098. if(setup==NULL)return(OV_EINVAL);
  140099. hi->set_in_stone=1;
  140100. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140101. setup->blocksize_short,
  140102. setup->blocksize_long);
  140103. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140104. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140105. setup->floor_books,
  140106. setup->floor_params,
  140107. setup->floor_short_mapping);
  140108. if(!singleblock)
  140109. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140110. setup->floor_books,
  140111. setup->floor_params,
  140112. setup->floor_long_mapping);
  140113. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140114. setup->global_params,
  140115. setup->global_mapping);
  140116. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140117. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140118. setup->psy_noise_normal_start[0],
  140119. setup->psy_noise_normal_partition[0],
  140120. setup->psy_noise_normal_thresh,
  140121. 0);
  140122. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140123. setup->psy_noise_normal_start[0],
  140124. setup->psy_noise_normal_partition[0],
  140125. setup->psy_noise_normal_thresh,
  140126. 1);
  140127. if(!singleblock){
  140128. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140129. setup->psy_noise_normal_start[1],
  140130. setup->psy_noise_normal_partition[1],
  140131. setup->psy_noise_normal_thresh,
  140132. 2);
  140133. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140134. setup->psy_noise_normal_start[1],
  140135. setup->psy_noise_normal_partition[1],
  140136. setup->psy_noise_normal_thresh,
  140137. 3);
  140138. }
  140139. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140140. setup->psy_tone_masteratt,
  140141. setup->psy_tone_0dB,
  140142. setup->psy_tone_adj_impulse);
  140143. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140144. setup->psy_tone_masteratt,
  140145. setup->psy_tone_0dB,
  140146. setup->psy_tone_adj_other);
  140147. if(!singleblock){
  140148. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140149. setup->psy_tone_masteratt,
  140150. setup->psy_tone_0dB,
  140151. setup->psy_tone_adj_other);
  140152. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140153. setup->psy_tone_masteratt,
  140154. setup->psy_tone_0dB,
  140155. setup->psy_tone_adj_long);
  140156. }
  140157. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140158. setup->psy_noise_compand,
  140159. setup->psy_noise_compand_short_mapping);
  140160. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140161. setup->psy_noise_compand,
  140162. setup->psy_noise_compand_short_mapping);
  140163. if(!singleblock){
  140164. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140165. setup->psy_noise_compand,
  140166. setup->psy_noise_compand_long_mapping);
  140167. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140168. setup->psy_noise_compand,
  140169. setup->psy_noise_compand_long_mapping);
  140170. }
  140171. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140172. setup->psy_tone_dBsuppress);
  140173. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140174. setup->psy_tone_dBsuppress);
  140175. if(!singleblock){
  140176. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140177. setup->psy_tone_dBsuppress);
  140178. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140179. setup->psy_tone_dBsuppress);
  140180. }
  140181. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140182. setup->psy_noise_dBsuppress,
  140183. setup->psy_noise_bias_impulse,
  140184. setup->psy_noiseguards,
  140185. (i0==0?hi->impulse_noisetune:0.));
  140186. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140187. setup->psy_noise_dBsuppress,
  140188. setup->psy_noise_bias_padding,
  140189. setup->psy_noiseguards,0.);
  140190. if(!singleblock){
  140191. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140192. setup->psy_noise_dBsuppress,
  140193. setup->psy_noise_bias_trans,
  140194. setup->psy_noiseguards,0.);
  140195. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140196. setup->psy_noise_dBsuppress,
  140197. setup->psy_noise_bias_long,
  140198. setup->psy_noiseguards,0.);
  140199. }
  140200. vorbis_encode_ath_setup(vi,0);
  140201. vorbis_encode_ath_setup(vi,1);
  140202. if(!singleblock){
  140203. vorbis_encode_ath_setup(vi,2);
  140204. vorbis_encode_ath_setup(vi,3);
  140205. }
  140206. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140207. if(hi->bitrate_av>0)
  140208. vi->bitrate_nominal=hi->bitrate_av;
  140209. else{
  140210. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140211. }
  140212. vi->bitrate_lower=hi->bitrate_min;
  140213. vi->bitrate_upper=hi->bitrate_max;
  140214. if(hi->bitrate_av)
  140215. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140216. else
  140217. vi->bitrate_window=0.;
  140218. if(hi->managed){
  140219. ci->bi.avg_rate=hi->bitrate_av;
  140220. ci->bi.min_rate=hi->bitrate_min;
  140221. ci->bi.max_rate=hi->bitrate_max;
  140222. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140223. ci->bi.reservoir_bias=
  140224. hi->bitrate_reservoir_bias;
  140225. ci->bi.slew_damp=hi->bitrate_av_damp;
  140226. }
  140227. return(0);
  140228. }
  140229. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140230. long channels,
  140231. long rate){
  140232. int ret=0,i,is;
  140233. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140234. highlevel_encode_setup *hi=&ci->hi;
  140235. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140236. double ds;
  140237. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140238. if(ret)return(ret);
  140239. is=hi->base_setting;
  140240. ds=hi->base_setting-is;
  140241. hi->short_setting=hi->base_setting;
  140242. hi->long_setting=hi->base_setting;
  140243. hi->managed=0;
  140244. hi->impulse_block_p=1;
  140245. hi->noise_normalize_p=1;
  140246. hi->stereo_point_setting=hi->base_setting;
  140247. hi->lowpass_kHz=
  140248. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140249. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140250. setup->psy_ath_float[is+1]*ds;
  140251. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140252. setup->psy_ath_abs[is+1]*ds;
  140253. hi->amplitude_track_dBpersec=-6.;
  140254. hi->trigger_setting=hi->base_setting;
  140255. for(i=0;i<4;i++){
  140256. hi->block[i].tone_mask_setting=hi->base_setting;
  140257. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140258. hi->block[i].noise_bias_setting=hi->base_setting;
  140259. hi->block[i].noise_compand_setting=hi->base_setting;
  140260. }
  140261. return(ret);
  140262. }
  140263. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140264. long channels,
  140265. long rate,
  140266. float quality){
  140267. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140268. highlevel_encode_setup *hi=&ci->hi;
  140269. quality+=.0000001;
  140270. if(quality>=1.)quality=.9999;
  140271. get_setup_template(vi,channels,rate,quality,0);
  140272. if(!hi->setup)return OV_EIMPL;
  140273. return vorbis_encode_setup_setting(vi,channels,rate);
  140274. }
  140275. int vorbis_encode_init_vbr(vorbis_info *vi,
  140276. long channels,
  140277. long rate,
  140278. float base_quality /* 0. to 1. */
  140279. ){
  140280. int ret=0;
  140281. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140282. if(ret){
  140283. vorbis_info_clear(vi);
  140284. return ret;
  140285. }
  140286. ret=vorbis_encode_setup_init(vi);
  140287. if(ret)
  140288. vorbis_info_clear(vi);
  140289. return(ret);
  140290. }
  140291. int vorbis_encode_setup_managed(vorbis_info *vi,
  140292. long channels,
  140293. long rate,
  140294. long max_bitrate,
  140295. long nominal_bitrate,
  140296. long min_bitrate){
  140297. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140298. highlevel_encode_setup *hi=&ci->hi;
  140299. double tnominal=nominal_bitrate;
  140300. int ret=0;
  140301. if(nominal_bitrate<=0.){
  140302. if(max_bitrate>0.){
  140303. if(min_bitrate>0.)
  140304. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140305. else
  140306. nominal_bitrate=max_bitrate*.875;
  140307. }else{
  140308. if(min_bitrate>0.){
  140309. nominal_bitrate=min_bitrate;
  140310. }else{
  140311. return(OV_EINVAL);
  140312. }
  140313. }
  140314. }
  140315. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140316. if(!hi->setup)return OV_EIMPL;
  140317. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140318. if(ret){
  140319. vorbis_info_clear(vi);
  140320. return ret;
  140321. }
  140322. hi->managed=1;
  140323. hi->bitrate_min=min_bitrate;
  140324. hi->bitrate_max=max_bitrate;
  140325. hi->bitrate_av=tnominal;
  140326. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140327. hi->bitrate_reservoir=nominal_bitrate*2;
  140328. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140329. return(ret);
  140330. }
  140331. int vorbis_encode_init(vorbis_info *vi,
  140332. long channels,
  140333. long rate,
  140334. long max_bitrate,
  140335. long nominal_bitrate,
  140336. long min_bitrate){
  140337. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140338. max_bitrate,
  140339. nominal_bitrate,
  140340. min_bitrate);
  140341. if(ret){
  140342. vorbis_info_clear(vi);
  140343. return(ret);
  140344. }
  140345. ret=vorbis_encode_setup_init(vi);
  140346. if(ret)
  140347. vorbis_info_clear(vi);
  140348. return(ret);
  140349. }
  140350. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140351. if(vi){
  140352. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140353. highlevel_encode_setup *hi=&ci->hi;
  140354. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140355. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140356. switch(number){
  140357. case OV_ECTL_RATEMANAGE_GET:
  140358. {
  140359. struct ovectl_ratemanage_arg *ai=
  140360. (struct ovectl_ratemanage_arg *)arg;
  140361. ai->management_active=hi->managed;
  140362. ai->bitrate_hard_window=ai->bitrate_av_window=
  140363. (double)hi->bitrate_reservoir/vi->rate;
  140364. ai->bitrate_av_window_center=1.;
  140365. ai->bitrate_hard_min=hi->bitrate_min;
  140366. ai->bitrate_hard_max=hi->bitrate_max;
  140367. ai->bitrate_av_lo=hi->bitrate_av;
  140368. ai->bitrate_av_hi=hi->bitrate_av;
  140369. }
  140370. return(0);
  140371. case OV_ECTL_RATEMANAGE_SET:
  140372. {
  140373. struct ovectl_ratemanage_arg *ai=
  140374. (struct ovectl_ratemanage_arg *)arg;
  140375. if(ai==NULL){
  140376. hi->managed=0;
  140377. }else{
  140378. hi->managed=ai->management_active;
  140379. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140380. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140381. }
  140382. }
  140383. return 0;
  140384. case OV_ECTL_RATEMANAGE_AVG:
  140385. {
  140386. struct ovectl_ratemanage_arg *ai=
  140387. (struct ovectl_ratemanage_arg *)arg;
  140388. if(ai==NULL){
  140389. hi->bitrate_av=0;
  140390. }else{
  140391. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140392. }
  140393. }
  140394. return(0);
  140395. case OV_ECTL_RATEMANAGE_HARD:
  140396. {
  140397. struct ovectl_ratemanage_arg *ai=
  140398. (struct ovectl_ratemanage_arg *)arg;
  140399. if(ai==NULL){
  140400. hi->bitrate_min=0;
  140401. hi->bitrate_max=0;
  140402. }else{
  140403. hi->bitrate_min=ai->bitrate_hard_min;
  140404. hi->bitrate_max=ai->bitrate_hard_max;
  140405. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140406. (hi->bitrate_max+hi->bitrate_min)*.5;
  140407. }
  140408. if(hi->bitrate_reservoir<128.)
  140409. hi->bitrate_reservoir=128.;
  140410. }
  140411. return(0);
  140412. case OV_ECTL_RATEMANAGE2_GET:
  140413. {
  140414. struct ovectl_ratemanage2_arg *ai=
  140415. (struct ovectl_ratemanage2_arg *)arg;
  140416. if(ai==NULL)return OV_EINVAL;
  140417. ai->management_active=hi->managed;
  140418. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140419. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140420. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140421. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140422. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140423. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140424. }
  140425. return (0);
  140426. case OV_ECTL_RATEMANAGE2_SET:
  140427. {
  140428. struct ovectl_ratemanage2_arg *ai=
  140429. (struct ovectl_ratemanage2_arg *)arg;
  140430. if(ai==NULL){
  140431. hi->managed=0;
  140432. }else{
  140433. if(ai->bitrate_limit_min_kbps>0 &&
  140434. ai->bitrate_average_kbps>0 &&
  140435. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140436. return OV_EINVAL;
  140437. if(ai->bitrate_limit_max_kbps>0 &&
  140438. ai->bitrate_average_kbps>0 &&
  140439. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140440. return OV_EINVAL;
  140441. if(ai->bitrate_limit_min_kbps>0 &&
  140442. ai->bitrate_limit_max_kbps>0 &&
  140443. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140444. return OV_EINVAL;
  140445. if(ai->bitrate_average_damping <= 0.)
  140446. return OV_EINVAL;
  140447. if(ai->bitrate_limit_reservoir_bits < 0)
  140448. return OV_EINVAL;
  140449. if(ai->bitrate_limit_reservoir_bias < 0.)
  140450. return OV_EINVAL;
  140451. if(ai->bitrate_limit_reservoir_bias > 1.)
  140452. return OV_EINVAL;
  140453. hi->managed=ai->management_active;
  140454. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140455. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140456. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140457. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140458. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140459. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140460. }
  140461. }
  140462. return 0;
  140463. case OV_ECTL_LOWPASS_GET:
  140464. {
  140465. double *farg=(double *)arg;
  140466. *farg=hi->lowpass_kHz;
  140467. }
  140468. return(0);
  140469. case OV_ECTL_LOWPASS_SET:
  140470. {
  140471. double *farg=(double *)arg;
  140472. hi->lowpass_kHz=*farg;
  140473. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140474. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140475. }
  140476. return(0);
  140477. case OV_ECTL_IBLOCK_GET:
  140478. {
  140479. double *farg=(double *)arg;
  140480. *farg=hi->impulse_noisetune;
  140481. }
  140482. return(0);
  140483. case OV_ECTL_IBLOCK_SET:
  140484. {
  140485. double *farg=(double *)arg;
  140486. hi->impulse_noisetune=*farg;
  140487. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140488. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140489. }
  140490. return(0);
  140491. }
  140492. return(OV_EIMPL);
  140493. }
  140494. return(OV_EINVAL);
  140495. }
  140496. #endif
  140497. /*** End of inlined file: vorbisenc.c ***/
  140498. /*** Start of inlined file: vorbisfile.c ***/
  140499. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140500. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140501. // tasks..
  140502. #if JUCE_MSVC
  140503. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140504. #endif
  140505. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140506. #if JUCE_USE_OGGVORBIS
  140507. #include <stdlib.h>
  140508. #include <stdio.h>
  140509. #include <errno.h>
  140510. #include <string.h>
  140511. #include <math.h>
  140512. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140513. over 8k gets what they deserve */
  140514. static long _get_data(OggVorbis_File *vf){
  140515. errno=0;
  140516. if(vf->datasource){
  140517. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140518. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140519. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140520. if(bytes==0 && errno)return(-1);
  140521. return(bytes);
  140522. }else
  140523. return(0);
  140524. }
  140525. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140526. if(vf->datasource){
  140527. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140528. vf->offset=offset;
  140529. ogg_sync_reset(&vf->oy);
  140530. }else{
  140531. return;
  140532. }
  140533. }
  140534. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140535. ogg_int64_t boundary){
  140536. if(boundary>0)boundary+=vf->offset;
  140537. while(1){
  140538. long more;
  140539. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140540. more=ogg_sync_pageseek(&vf->oy,og);
  140541. if(more<0){
  140542. vf->offset-=more;
  140543. }else{
  140544. if(more==0){
  140545. if(!boundary)return(OV_FALSE);
  140546. {
  140547. long ret=_get_data(vf);
  140548. if(ret==0)return(OV_EOF);
  140549. if(ret<0)return(OV_EREAD);
  140550. }
  140551. }else{
  140552. ogg_int64_t ret=vf->offset;
  140553. vf->offset+=more;
  140554. return(ret);
  140555. }
  140556. }
  140557. }
  140558. }
  140559. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140560. ogg_int64_t begin=vf->offset;
  140561. ogg_int64_t end=begin;
  140562. ogg_int64_t ret;
  140563. ogg_int64_t offset=-1;
  140564. while(offset==-1){
  140565. begin-=CHUNKSIZE;
  140566. if(begin<0)
  140567. begin=0;
  140568. _seek_helper(vf,begin);
  140569. while(vf->offset<end){
  140570. ret=_get_next_page(vf,og,end-vf->offset);
  140571. if(ret==OV_EREAD)return(OV_EREAD);
  140572. if(ret<0){
  140573. break;
  140574. }else{
  140575. offset=ret;
  140576. }
  140577. }
  140578. }
  140579. _seek_helper(vf,offset);
  140580. ret=_get_next_page(vf,og,CHUNKSIZE);
  140581. if(ret<0)
  140582. return(OV_EFAULT);
  140583. return(offset);
  140584. }
  140585. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140586. ogg_int64_t begin,
  140587. ogg_int64_t searched,
  140588. ogg_int64_t end,
  140589. long currentno,
  140590. long m){
  140591. ogg_int64_t endsearched=end;
  140592. ogg_int64_t next=end;
  140593. ogg_page og;
  140594. ogg_int64_t ret;
  140595. while(searched<endsearched){
  140596. ogg_int64_t bisect;
  140597. if(endsearched-searched<CHUNKSIZE){
  140598. bisect=searched;
  140599. }else{
  140600. bisect=(searched+endsearched)/2;
  140601. }
  140602. _seek_helper(vf,bisect);
  140603. ret=_get_next_page(vf,&og,-1);
  140604. if(ret==OV_EREAD)return(OV_EREAD);
  140605. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140606. endsearched=bisect;
  140607. if(ret>=0)next=ret;
  140608. }else{
  140609. searched=ret+og.header_len+og.body_len;
  140610. }
  140611. }
  140612. _seek_helper(vf,next);
  140613. ret=_get_next_page(vf,&og,-1);
  140614. if(ret==OV_EREAD)return(OV_EREAD);
  140615. if(searched>=end || ret<0){
  140616. vf->links=m+1;
  140617. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140618. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140619. vf->offsets[m+1]=searched;
  140620. }else{
  140621. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140622. end,ogg_page_serialno(&og),m+1);
  140623. if(ret==OV_EREAD)return(OV_EREAD);
  140624. }
  140625. vf->offsets[m]=begin;
  140626. vf->serialnos[m]=currentno;
  140627. return(0);
  140628. }
  140629. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140630. long *serialno,ogg_page *og_ptr){
  140631. ogg_page og;
  140632. ogg_packet op;
  140633. int i,ret;
  140634. if(!og_ptr){
  140635. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140636. if(llret==OV_EREAD)return(OV_EREAD);
  140637. if(llret<0)return OV_ENOTVORBIS;
  140638. og_ptr=&og;
  140639. }
  140640. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140641. if(serialno)*serialno=vf->os.serialno;
  140642. vf->ready_state=STREAMSET;
  140643. vorbis_info_init(vi);
  140644. vorbis_comment_init(vc);
  140645. i=0;
  140646. while(i<3){
  140647. ogg_stream_pagein(&vf->os,og_ptr);
  140648. while(i<3){
  140649. int result=ogg_stream_packetout(&vf->os,&op);
  140650. if(result==0)break;
  140651. if(result==-1){
  140652. ret=OV_EBADHEADER;
  140653. goto bail_header;
  140654. }
  140655. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140656. goto bail_header;
  140657. }
  140658. i++;
  140659. }
  140660. if(i<3)
  140661. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140662. ret=OV_EBADHEADER;
  140663. goto bail_header;
  140664. }
  140665. }
  140666. return 0;
  140667. bail_header:
  140668. vorbis_info_clear(vi);
  140669. vorbis_comment_clear(vc);
  140670. vf->ready_state=OPENED;
  140671. return ret;
  140672. }
  140673. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140674. ogg_page og;
  140675. int i;
  140676. ogg_int64_t ret;
  140677. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140678. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140679. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140680. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140681. for(i=0;i<vf->links;i++){
  140682. if(i==0){
  140683. vf->dataoffsets[i]=dataoffset;
  140684. _seek_helper(vf,dataoffset);
  140685. }else{
  140686. _seek_helper(vf,vf->offsets[i]);
  140687. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140688. vf->dataoffsets[i]=-1;
  140689. }else{
  140690. vf->dataoffsets[i]=vf->offset;
  140691. }
  140692. }
  140693. if(vf->dataoffsets[i]!=-1){
  140694. ogg_int64_t accumulated=0;
  140695. long lastblock=-1;
  140696. int result;
  140697. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  140698. while(1){
  140699. ogg_packet op;
  140700. ret=_get_next_page(vf,&og,-1);
  140701. if(ret<0)
  140702. break;
  140703. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  140704. break;
  140705. ogg_stream_pagein(&vf->os,&og);
  140706. while((result=ogg_stream_packetout(&vf->os,&op))){
  140707. if(result>0){ /* ignore holes */
  140708. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  140709. if(lastblock!=-1)
  140710. accumulated+=(lastblock+thisblock)>>2;
  140711. lastblock=thisblock;
  140712. }
  140713. }
  140714. if(ogg_page_granulepos(&og)!=-1){
  140715. accumulated= ogg_page_granulepos(&og)-accumulated;
  140716. break;
  140717. }
  140718. }
  140719. if(accumulated<0)accumulated=0;
  140720. vf->pcmlengths[i*2]=accumulated;
  140721. }
  140722. {
  140723. ogg_int64_t end=vf->offsets[i+1];
  140724. _seek_helper(vf,end);
  140725. while(1){
  140726. ret=_get_prev_page(vf,&og);
  140727. if(ret<0){
  140728. vorbis_info_clear(vf->vi+i);
  140729. vorbis_comment_clear(vf->vc+i);
  140730. break;
  140731. }
  140732. if(ogg_page_granulepos(&og)!=-1){
  140733. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  140734. break;
  140735. }
  140736. vf->offset=ret;
  140737. }
  140738. }
  140739. }
  140740. }
  140741. static int _make_decode_ready(OggVorbis_File *vf){
  140742. if(vf->ready_state>STREAMSET)return 0;
  140743. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  140744. if(vf->seekable){
  140745. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  140746. return OV_EBADLINK;
  140747. }else{
  140748. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  140749. return OV_EBADLINK;
  140750. }
  140751. vorbis_block_init(&vf->vd,&vf->vb);
  140752. vf->ready_state=INITSET;
  140753. vf->bittrack=0.f;
  140754. vf->samptrack=0.f;
  140755. return 0;
  140756. }
  140757. static int _open_seekable2(OggVorbis_File *vf){
  140758. long serialno=vf->current_serialno;
  140759. ogg_int64_t dataoffset=vf->offset, end;
  140760. ogg_page og;
  140761. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  140762. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  140763. end=_get_prev_page(vf,&og);
  140764. if(end<0)return(end);
  140765. if(ogg_page_serialno(&og)!=serialno){
  140766. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  140767. }else{
  140768. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  140769. }
  140770. _prefetch_all_headers(vf,dataoffset);
  140771. return(ov_raw_seek(vf,0));
  140772. }
  140773. static void _decode_clear(OggVorbis_File *vf){
  140774. vorbis_dsp_clear(&vf->vd);
  140775. vorbis_block_clear(&vf->vb);
  140776. vf->ready_state=OPENED;
  140777. }
  140778. static int _fetch_and_process_packet(OggVorbis_File *vf,
  140779. ogg_packet *op_in,
  140780. int readp,
  140781. int spanp){
  140782. ogg_page og;
  140783. while(1){
  140784. if(vf->ready_state==INITSET){
  140785. while(1) {
  140786. ogg_packet op;
  140787. ogg_packet *op_ptr=(op_in?op_in:&op);
  140788. int result=ogg_stream_packetout(&vf->os,op_ptr);
  140789. ogg_int64_t granulepos;
  140790. op_in=NULL;
  140791. if(result==-1)return(OV_HOLE); /* hole in the data. */
  140792. if(result>0){
  140793. granulepos=op_ptr->granulepos;
  140794. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  140795. header handling. The
  140796. header packets aren't
  140797. audio, so if/when we
  140798. submit them,
  140799. vorbis_synthesis will
  140800. reject them */
  140801. {
  140802. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  140803. if(oldsamples)return(OV_EFAULT);
  140804. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  140805. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  140806. vf->bittrack+=op_ptr->bytes*8;
  140807. }
  140808. if(granulepos!=-1 && !op_ptr->e_o_s){
  140809. int link=(vf->seekable?vf->current_link:0);
  140810. int i,samples;
  140811. if(vf->seekable && link>0)
  140812. granulepos-=vf->pcmlengths[link*2];
  140813. if(granulepos<0)granulepos=0; /* actually, this
  140814. shouldn't be possible
  140815. here unless the stream
  140816. is very broken */
  140817. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  140818. granulepos-=samples;
  140819. for(i=0;i<link;i++)
  140820. granulepos+=vf->pcmlengths[i*2+1];
  140821. vf->pcm_offset=granulepos;
  140822. }
  140823. return(1);
  140824. }
  140825. }
  140826. else
  140827. break;
  140828. }
  140829. }
  140830. if(vf->ready_state>=OPENED){
  140831. ogg_int64_t ret;
  140832. if(!readp)return(0);
  140833. if((ret=_get_next_page(vf,&og,-1))<0){
  140834. return(OV_EOF); /* eof.
  140835. leave unitialized */
  140836. }
  140837. vf->bittrack+=og.header_len*8;
  140838. if(vf->ready_state==INITSET){
  140839. if(vf->current_serialno!=ogg_page_serialno(&og)){
  140840. if(!spanp)
  140841. return(OV_EOF);
  140842. _decode_clear(vf);
  140843. if(!vf->seekable){
  140844. vorbis_info_clear(vf->vi);
  140845. vorbis_comment_clear(vf->vc);
  140846. }
  140847. }
  140848. }
  140849. }
  140850. if(vf->ready_state!=INITSET){
  140851. int link;
  140852. if(vf->ready_state<STREAMSET){
  140853. if(vf->seekable){
  140854. vf->current_serialno=ogg_page_serialno(&og);
  140855. for(link=0;link<vf->links;link++)
  140856. if(vf->serialnos[link]==vf->current_serialno)break;
  140857. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  140858. stream. error out,
  140859. leave machine
  140860. uninitialized */
  140861. vf->current_link=link;
  140862. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  140863. vf->ready_state=STREAMSET;
  140864. }else{
  140865. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  140866. if(ret)return(ret);
  140867. vf->current_link++;
  140868. link=0;
  140869. }
  140870. }
  140871. {
  140872. int ret=_make_decode_ready(vf);
  140873. if(ret<0)return ret;
  140874. }
  140875. }
  140876. ogg_stream_pagein(&vf->os,&og);
  140877. }
  140878. }
  140879. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  140880. if(f==NULL)return(-1);
  140881. return fseek(f,off,whence);
  140882. }
  140883. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  140884. long ibytes, ov_callbacks callbacks){
  140885. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  140886. int ret;
  140887. memset(vf,0,sizeof(*vf));
  140888. vf->datasource=f;
  140889. vf->callbacks = callbacks;
  140890. ogg_sync_init(&vf->oy);
  140891. if(initial){
  140892. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  140893. memcpy(buffer,initial,ibytes);
  140894. ogg_sync_wrote(&vf->oy,ibytes);
  140895. }
  140896. if(offsettest!=-1)vf->seekable=1;
  140897. vf->links=1;
  140898. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  140899. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  140900. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  140901. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  140902. vf->datasource=NULL;
  140903. ov_clear(vf);
  140904. }else
  140905. vf->ready_state=PARTOPEN;
  140906. return(ret);
  140907. }
  140908. static int _ov_open2(OggVorbis_File *vf){
  140909. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  140910. vf->ready_state=OPENED;
  140911. if(vf->seekable){
  140912. int ret=_open_seekable2(vf);
  140913. if(ret){
  140914. vf->datasource=NULL;
  140915. ov_clear(vf);
  140916. }
  140917. return(ret);
  140918. }else
  140919. vf->ready_state=STREAMSET;
  140920. return 0;
  140921. }
  140922. int ov_clear(OggVorbis_File *vf){
  140923. if(vf){
  140924. vorbis_block_clear(&vf->vb);
  140925. vorbis_dsp_clear(&vf->vd);
  140926. ogg_stream_clear(&vf->os);
  140927. if(vf->vi && vf->links){
  140928. int i;
  140929. for(i=0;i<vf->links;i++){
  140930. vorbis_info_clear(vf->vi+i);
  140931. vorbis_comment_clear(vf->vc+i);
  140932. }
  140933. _ogg_free(vf->vi);
  140934. _ogg_free(vf->vc);
  140935. }
  140936. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  140937. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  140938. if(vf->serialnos)_ogg_free(vf->serialnos);
  140939. if(vf->offsets)_ogg_free(vf->offsets);
  140940. ogg_sync_clear(&vf->oy);
  140941. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  140942. memset(vf,0,sizeof(*vf));
  140943. }
  140944. #ifdef DEBUG_LEAKS
  140945. _VDBG_dump();
  140946. #endif
  140947. return(0);
  140948. }
  140949. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  140950. ov_callbacks callbacks){
  140951. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  140952. if(ret)return ret;
  140953. return _ov_open2(vf);
  140954. }
  140955. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  140956. ov_callbacks callbacks = {
  140957. (size_t (*)(void *, size_t, size_t, void *)) fread,
  140958. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  140959. (int (*)(void *)) fclose,
  140960. (long (*)(void *)) ftell
  140961. };
  140962. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  140963. }
  140964. int ov_halfrate(OggVorbis_File *vf,int flag){
  140965. int i;
  140966. if(vf->vi==NULL)return OV_EINVAL;
  140967. if(!vf->seekable)return OV_EINVAL;
  140968. if(vf->ready_state>=STREAMSET)
  140969. _decode_clear(vf); /* clear out stream state; later on libvorbis
  140970. will be able to swap this on the fly, but
  140971. for now dumping the decode machine is needed
  140972. to reinit the MDCT lookups. 1.1 libvorbis
  140973. is planned to be able to switch on the fly */
  140974. for(i=0;i<vf->links;i++){
  140975. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  140976. ov_halfrate(vf,0);
  140977. return OV_EINVAL;
  140978. }
  140979. }
  140980. return 0;
  140981. }
  140982. int ov_halfrate_p(OggVorbis_File *vf){
  140983. if(vf->vi==NULL)return OV_EINVAL;
  140984. return vorbis_synthesis_halfrate_p(vf->vi);
  140985. }
  140986. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  140987. ov_callbacks callbacks)
  140988. {
  140989. return _ov_open1(f,vf,initial,ibytes,callbacks);
  140990. }
  140991. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  140992. ov_callbacks callbacks = {
  140993. (size_t (*)(void *, size_t, size_t, void *)) fread,
  140994. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  140995. (int (*)(void *)) fclose,
  140996. (long (*)(void *)) ftell
  140997. };
  140998. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  140999. }
  141000. int ov_test_open(OggVorbis_File *vf){
  141001. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141002. return _ov_open2(vf);
  141003. }
  141004. long ov_streams(OggVorbis_File *vf){
  141005. return vf->links;
  141006. }
  141007. long ov_seekable(OggVorbis_File *vf){
  141008. return vf->seekable;
  141009. }
  141010. long ov_bitrate(OggVorbis_File *vf,int i){
  141011. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141012. if(i>=vf->links)return(OV_EINVAL);
  141013. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141014. if(i<0){
  141015. ogg_int64_t bits=0;
  141016. int i;
  141017. float br;
  141018. for(i=0;i<vf->links;i++)
  141019. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141020. br = bits/ov_time_total(vf,-1);
  141021. return(rint(br));
  141022. }else{
  141023. if(vf->seekable){
  141024. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141025. }else{
  141026. if(vf->vi[i].bitrate_nominal>0){
  141027. return vf->vi[i].bitrate_nominal;
  141028. }else{
  141029. if(vf->vi[i].bitrate_upper>0){
  141030. if(vf->vi[i].bitrate_lower>0){
  141031. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141032. }else{
  141033. return vf->vi[i].bitrate_upper;
  141034. }
  141035. }
  141036. return(OV_FALSE);
  141037. }
  141038. }
  141039. }
  141040. }
  141041. long ov_bitrate_instant(OggVorbis_File *vf){
  141042. int link=(vf->seekable?vf->current_link:0);
  141043. long ret;
  141044. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141045. if(vf->samptrack==0)return(OV_FALSE);
  141046. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141047. vf->bittrack=0.f;
  141048. vf->samptrack=0.f;
  141049. return(ret);
  141050. }
  141051. long ov_serialnumber(OggVorbis_File *vf,int i){
  141052. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141053. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141054. if(i<0){
  141055. return(vf->current_serialno);
  141056. }else{
  141057. return(vf->serialnos[i]);
  141058. }
  141059. }
  141060. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141061. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141062. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141063. if(i<0){
  141064. ogg_int64_t acc=0;
  141065. int i;
  141066. for(i=0;i<vf->links;i++)
  141067. acc+=ov_raw_total(vf,i);
  141068. return(acc);
  141069. }else{
  141070. return(vf->offsets[i+1]-vf->offsets[i]);
  141071. }
  141072. }
  141073. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141074. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141075. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141076. if(i<0){
  141077. ogg_int64_t acc=0;
  141078. int i;
  141079. for(i=0;i<vf->links;i++)
  141080. acc+=ov_pcm_total(vf,i);
  141081. return(acc);
  141082. }else{
  141083. return(vf->pcmlengths[i*2+1]);
  141084. }
  141085. }
  141086. double ov_time_total(OggVorbis_File *vf,int i){
  141087. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141088. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141089. if(i<0){
  141090. double acc=0;
  141091. int i;
  141092. for(i=0;i<vf->links;i++)
  141093. acc+=ov_time_total(vf,i);
  141094. return(acc);
  141095. }else{
  141096. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141097. }
  141098. }
  141099. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141100. ogg_stream_state work_os;
  141101. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141102. if(!vf->seekable)
  141103. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141104. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141105. vf->pcm_offset=-1;
  141106. ogg_stream_reset_serialno(&vf->os,
  141107. vf->current_serialno); /* must set serialno */
  141108. vorbis_synthesis_restart(&vf->vd);
  141109. _seek_helper(vf,pos);
  141110. {
  141111. ogg_page og;
  141112. ogg_packet op;
  141113. int lastblock=0;
  141114. int accblock=0;
  141115. int thisblock;
  141116. int eosflag;
  141117. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141118. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141119. return from not necessarily
  141120. starting from the beginning */
  141121. while(1){
  141122. if(vf->ready_state>=STREAMSET){
  141123. int result=ogg_stream_packetout(&work_os,&op);
  141124. if(result>0){
  141125. if(vf->vi[vf->current_link].codec_setup){
  141126. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141127. if(thisblock<0){
  141128. ogg_stream_packetout(&vf->os,NULL);
  141129. thisblock=0;
  141130. }else{
  141131. if(eosflag)
  141132. ogg_stream_packetout(&vf->os,NULL);
  141133. else
  141134. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141135. }
  141136. if(op.granulepos!=-1){
  141137. int i,link=vf->current_link;
  141138. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141139. if(granulepos<0)granulepos=0;
  141140. for(i=0;i<link;i++)
  141141. granulepos+=vf->pcmlengths[i*2+1];
  141142. vf->pcm_offset=granulepos-accblock;
  141143. break;
  141144. }
  141145. lastblock=thisblock;
  141146. continue;
  141147. }else
  141148. ogg_stream_packetout(&vf->os,NULL);
  141149. }
  141150. }
  141151. if(!lastblock){
  141152. if(_get_next_page(vf,&og,-1)<0){
  141153. vf->pcm_offset=ov_pcm_total(vf,-1);
  141154. break;
  141155. }
  141156. }else{
  141157. vf->pcm_offset=-1;
  141158. break;
  141159. }
  141160. if(vf->ready_state>=STREAMSET)
  141161. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141162. _decode_clear(vf); /* clear out stream state */
  141163. ogg_stream_clear(&work_os);
  141164. }
  141165. if(vf->ready_state<STREAMSET){
  141166. int link;
  141167. vf->current_serialno=ogg_page_serialno(&og);
  141168. for(link=0;link<vf->links;link++)
  141169. if(vf->serialnos[link]==vf->current_serialno)break;
  141170. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141171. error out, leave
  141172. machine uninitialized */
  141173. vf->current_link=link;
  141174. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141175. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141176. vf->ready_state=STREAMSET;
  141177. }
  141178. ogg_stream_pagein(&vf->os,&og);
  141179. ogg_stream_pagein(&work_os,&og);
  141180. eosflag=ogg_page_eos(&og);
  141181. }
  141182. }
  141183. ogg_stream_clear(&work_os);
  141184. vf->bittrack=0.f;
  141185. vf->samptrack=0.f;
  141186. return(0);
  141187. seek_error:
  141188. vf->pcm_offset=-1;
  141189. ogg_stream_clear(&work_os);
  141190. _decode_clear(vf);
  141191. return OV_EBADLINK;
  141192. }
  141193. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141194. int link=-1;
  141195. ogg_int64_t result=0;
  141196. ogg_int64_t total=ov_pcm_total(vf,-1);
  141197. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141198. if(!vf->seekable)return(OV_ENOSEEK);
  141199. if(pos<0 || pos>total)return(OV_EINVAL);
  141200. for(link=vf->links-1;link>=0;link--){
  141201. total-=vf->pcmlengths[link*2+1];
  141202. if(pos>=total)break;
  141203. }
  141204. {
  141205. ogg_int64_t end=vf->offsets[link+1];
  141206. ogg_int64_t begin=vf->offsets[link];
  141207. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141208. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141209. ogg_int64_t target=pos-total+begintime;
  141210. ogg_int64_t best=begin;
  141211. ogg_page og;
  141212. while(begin<end){
  141213. ogg_int64_t bisect;
  141214. if(end-begin<CHUNKSIZE){
  141215. bisect=begin;
  141216. }else{
  141217. bisect=begin +
  141218. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141219. if(bisect<=begin)
  141220. bisect=begin+1;
  141221. }
  141222. _seek_helper(vf,bisect);
  141223. while(begin<end){
  141224. result=_get_next_page(vf,&og,end-vf->offset);
  141225. if(result==OV_EREAD) goto seek_error;
  141226. if(result<0){
  141227. if(bisect<=begin+1)
  141228. end=begin; /* found it */
  141229. else{
  141230. if(bisect==0) goto seek_error;
  141231. bisect-=CHUNKSIZE;
  141232. if(bisect<=begin)bisect=begin+1;
  141233. _seek_helper(vf,bisect);
  141234. }
  141235. }else{
  141236. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141237. if(granulepos==-1)continue;
  141238. if(granulepos<target){
  141239. best=result; /* raw offset of packet with granulepos */
  141240. begin=vf->offset; /* raw offset of next page */
  141241. begintime=granulepos;
  141242. if(target-begintime>44100)break;
  141243. bisect=begin; /* *not* begin + 1 */
  141244. }else{
  141245. if(bisect<=begin+1)
  141246. end=begin; /* found it */
  141247. else{
  141248. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141249. end=result;
  141250. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141251. if(bisect<=begin)bisect=begin+1;
  141252. _seek_helper(vf,bisect);
  141253. }else{
  141254. end=result;
  141255. endtime=granulepos;
  141256. break;
  141257. }
  141258. }
  141259. }
  141260. }
  141261. }
  141262. }
  141263. {
  141264. ogg_page og;
  141265. ogg_packet op;
  141266. _seek_helper(vf,best);
  141267. vf->pcm_offset=-1;
  141268. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141269. if(link!=vf->current_link){
  141270. _decode_clear(vf);
  141271. vf->current_link=link;
  141272. vf->current_serialno=ogg_page_serialno(&og);
  141273. vf->ready_state=STREAMSET;
  141274. }else{
  141275. vorbis_synthesis_restart(&vf->vd);
  141276. }
  141277. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141278. ogg_stream_pagein(&vf->os,&og);
  141279. while(1){
  141280. result=ogg_stream_packetpeek(&vf->os,&op);
  141281. if(result==0){
  141282. _seek_helper(vf,best);
  141283. while(1){
  141284. result=_get_prev_page(vf,&og);
  141285. if(result<0) goto seek_error;
  141286. if(ogg_page_granulepos(&og)>-1 ||
  141287. !ogg_page_continued(&og)){
  141288. return ov_raw_seek(vf,result);
  141289. }
  141290. vf->offset=result;
  141291. }
  141292. }
  141293. if(result<0){
  141294. result = OV_EBADPACKET;
  141295. goto seek_error;
  141296. }
  141297. if(op.granulepos!=-1){
  141298. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141299. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141300. vf->pcm_offset+=total;
  141301. break;
  141302. }else
  141303. result=ogg_stream_packetout(&vf->os,NULL);
  141304. }
  141305. }
  141306. }
  141307. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141308. result=OV_EFAULT;
  141309. goto seek_error;
  141310. }
  141311. vf->bittrack=0.f;
  141312. vf->samptrack=0.f;
  141313. return(0);
  141314. seek_error:
  141315. vf->pcm_offset=-1;
  141316. _decode_clear(vf);
  141317. return (int)result;
  141318. }
  141319. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141320. int thisblock,lastblock=0;
  141321. int ret=ov_pcm_seek_page(vf,pos);
  141322. if(ret<0)return(ret);
  141323. if((ret=_make_decode_ready(vf)))return ret;
  141324. while(1){
  141325. ogg_packet op;
  141326. ogg_page og;
  141327. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141328. if(ret>0){
  141329. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141330. if(thisblock<0){
  141331. ogg_stream_packetout(&vf->os,NULL);
  141332. continue; /* non audio packet */
  141333. }
  141334. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141335. if(vf->pcm_offset+((thisblock+
  141336. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141337. ogg_stream_packetout(&vf->os,NULL);
  141338. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141339. only tracking, no
  141340. pcm_decode */
  141341. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141342. if(op.granulepos>-1){
  141343. int i;
  141344. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141345. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141346. for(i=0;i<vf->current_link;i++)
  141347. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141348. }
  141349. lastblock=thisblock;
  141350. }else{
  141351. if(ret<0 && ret!=OV_HOLE)break;
  141352. if(_get_next_page(vf,&og,-1)<0)break;
  141353. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141354. if(vf->ready_state<STREAMSET){
  141355. int link;
  141356. vf->current_serialno=ogg_page_serialno(&og);
  141357. for(link=0;link<vf->links;link++)
  141358. if(vf->serialnos[link]==vf->current_serialno)break;
  141359. if(link==vf->links)return(OV_EBADLINK);
  141360. vf->current_link=link;
  141361. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141362. vf->ready_state=STREAMSET;
  141363. ret=_make_decode_ready(vf);
  141364. if(ret)return ret;
  141365. lastblock=0;
  141366. }
  141367. ogg_stream_pagein(&vf->os,&og);
  141368. }
  141369. }
  141370. vf->bittrack=0.f;
  141371. vf->samptrack=0.f;
  141372. while(vf->pcm_offset<pos){
  141373. ogg_int64_t target=pos-vf->pcm_offset;
  141374. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141375. if(samples>target)samples=target;
  141376. vorbis_synthesis_read(&vf->vd,samples);
  141377. vf->pcm_offset+=samples;
  141378. if(samples<target)
  141379. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141380. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141381. }
  141382. return 0;
  141383. }
  141384. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141385. int link=-1;
  141386. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141387. double time_total=ov_time_total(vf,-1);
  141388. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141389. if(!vf->seekable)return(OV_ENOSEEK);
  141390. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141391. for(link=vf->links-1;link>=0;link--){
  141392. pcm_total-=vf->pcmlengths[link*2+1];
  141393. time_total-=ov_time_total(vf,link);
  141394. if(seconds>=time_total)break;
  141395. }
  141396. {
  141397. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141398. return(ov_pcm_seek(vf,target));
  141399. }
  141400. }
  141401. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141402. int link=-1;
  141403. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141404. double time_total=ov_time_total(vf,-1);
  141405. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141406. if(!vf->seekable)return(OV_ENOSEEK);
  141407. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141408. for(link=vf->links-1;link>=0;link--){
  141409. pcm_total-=vf->pcmlengths[link*2+1];
  141410. time_total-=ov_time_total(vf,link);
  141411. if(seconds>=time_total)break;
  141412. }
  141413. {
  141414. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141415. return(ov_pcm_seek_page(vf,target));
  141416. }
  141417. }
  141418. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141419. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141420. return(vf->offset);
  141421. }
  141422. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141423. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141424. return(vf->pcm_offset);
  141425. }
  141426. double ov_time_tell(OggVorbis_File *vf){
  141427. int link=0;
  141428. ogg_int64_t pcm_total=0;
  141429. double time_total=0.f;
  141430. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141431. if(vf->seekable){
  141432. pcm_total=ov_pcm_total(vf,-1);
  141433. time_total=ov_time_total(vf,-1);
  141434. for(link=vf->links-1;link>=0;link--){
  141435. pcm_total-=vf->pcmlengths[link*2+1];
  141436. time_total-=ov_time_total(vf,link);
  141437. if(vf->pcm_offset>=pcm_total)break;
  141438. }
  141439. }
  141440. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141441. }
  141442. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141443. if(vf->seekable){
  141444. if(link<0)
  141445. if(vf->ready_state>=STREAMSET)
  141446. return vf->vi+vf->current_link;
  141447. else
  141448. return vf->vi;
  141449. else
  141450. if(link>=vf->links)
  141451. return NULL;
  141452. else
  141453. return vf->vi+link;
  141454. }else{
  141455. return vf->vi;
  141456. }
  141457. }
  141458. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141459. if(vf->seekable){
  141460. if(link<0)
  141461. if(vf->ready_state>=STREAMSET)
  141462. return vf->vc+vf->current_link;
  141463. else
  141464. return vf->vc;
  141465. else
  141466. if(link>=vf->links)
  141467. return NULL;
  141468. else
  141469. return vf->vc+link;
  141470. }else{
  141471. return vf->vc;
  141472. }
  141473. }
  141474. static int host_is_big_endian() {
  141475. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141476. unsigned char *bytewise = (unsigned char *)&pattern;
  141477. if (bytewise[0] == 0xfe) return 1;
  141478. return 0;
  141479. }
  141480. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141481. int bigendianp,int word,int sgned,int *bitstream){
  141482. int i,j;
  141483. int host_endian = host_is_big_endian();
  141484. float **pcm;
  141485. long samples;
  141486. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141487. while(1){
  141488. if(vf->ready_state==INITSET){
  141489. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141490. if(samples)break;
  141491. }
  141492. {
  141493. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141494. if(ret==OV_EOF)
  141495. return(0);
  141496. if(ret<=0)
  141497. return(ret);
  141498. }
  141499. }
  141500. if(samples>0){
  141501. long channels=ov_info(vf,-1)->channels;
  141502. long bytespersample=word * channels;
  141503. vorbis_fpu_control fpu;
  141504. (void) fpu; // (to avoid a warning about it being unused)
  141505. if(samples>length/bytespersample)samples=length/bytespersample;
  141506. if(samples <= 0)
  141507. return OV_EINVAL;
  141508. {
  141509. int val;
  141510. if(word==1){
  141511. int off=(sgned?0:128);
  141512. vorbis_fpu_setround(&fpu);
  141513. for(j=0;j<samples;j++)
  141514. for(i=0;i<channels;i++){
  141515. val=vorbis_ftoi(pcm[i][j]*128.f);
  141516. if(val>127)val=127;
  141517. else if(val<-128)val=-128;
  141518. *buffer++=val+off;
  141519. }
  141520. vorbis_fpu_restore(fpu);
  141521. }else{
  141522. int off=(sgned?0:32768);
  141523. if(host_endian==bigendianp){
  141524. if(sgned){
  141525. vorbis_fpu_setround(&fpu);
  141526. for(i=0;i<channels;i++) { /* It's faster in this order */
  141527. float *src=pcm[i];
  141528. short *dest=((short *)buffer)+i;
  141529. for(j=0;j<samples;j++) {
  141530. val=vorbis_ftoi(src[j]*32768.f);
  141531. if(val>32767)val=32767;
  141532. else if(val<-32768)val=-32768;
  141533. *dest=val;
  141534. dest+=channels;
  141535. }
  141536. }
  141537. vorbis_fpu_restore(fpu);
  141538. }else{
  141539. vorbis_fpu_setround(&fpu);
  141540. for(i=0;i<channels;i++) {
  141541. float *src=pcm[i];
  141542. short *dest=((short *)buffer)+i;
  141543. for(j=0;j<samples;j++) {
  141544. val=vorbis_ftoi(src[j]*32768.f);
  141545. if(val>32767)val=32767;
  141546. else if(val<-32768)val=-32768;
  141547. *dest=val+off;
  141548. dest+=channels;
  141549. }
  141550. }
  141551. vorbis_fpu_restore(fpu);
  141552. }
  141553. }else if(bigendianp){
  141554. vorbis_fpu_setround(&fpu);
  141555. for(j=0;j<samples;j++)
  141556. for(i=0;i<channels;i++){
  141557. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141558. if(val>32767)val=32767;
  141559. else if(val<-32768)val=-32768;
  141560. val+=off;
  141561. *buffer++=(val>>8);
  141562. *buffer++=(val&0xff);
  141563. }
  141564. vorbis_fpu_restore(fpu);
  141565. }else{
  141566. int val;
  141567. vorbis_fpu_setround(&fpu);
  141568. for(j=0;j<samples;j++)
  141569. for(i=0;i<channels;i++){
  141570. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141571. if(val>32767)val=32767;
  141572. else if(val<-32768)val=-32768;
  141573. val+=off;
  141574. *buffer++=(val&0xff);
  141575. *buffer++=(val>>8);
  141576. }
  141577. vorbis_fpu_restore(fpu);
  141578. }
  141579. }
  141580. }
  141581. vorbis_synthesis_read(&vf->vd,samples);
  141582. vf->pcm_offset+=samples;
  141583. if(bitstream)*bitstream=vf->current_link;
  141584. return(samples*bytespersample);
  141585. }else{
  141586. return(samples);
  141587. }
  141588. }
  141589. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141590. int *bitstream){
  141591. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141592. while(1){
  141593. if(vf->ready_state==INITSET){
  141594. float **pcm;
  141595. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141596. if(samples){
  141597. if(pcm_channels)*pcm_channels=pcm;
  141598. if(samples>length)samples=length;
  141599. vorbis_synthesis_read(&vf->vd,samples);
  141600. vf->pcm_offset+=samples;
  141601. if(bitstream)*bitstream=vf->current_link;
  141602. return samples;
  141603. }
  141604. }
  141605. {
  141606. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141607. if(ret==OV_EOF)return(0);
  141608. if(ret<=0)return(ret);
  141609. }
  141610. }
  141611. }
  141612. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141613. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141614. ogg_int64_t off);
  141615. static void _ov_splice(float **pcm,float **lappcm,
  141616. int n1, int n2,
  141617. int ch1, int ch2,
  141618. float *w1, float *w2){
  141619. int i,j;
  141620. float *w=w1;
  141621. int n=n1;
  141622. if(n1>n2){
  141623. n=n2;
  141624. w=w2;
  141625. }
  141626. for(j=0;j<ch1 && j<ch2;j++){
  141627. float *s=lappcm[j];
  141628. float *d=pcm[j];
  141629. for(i=0;i<n;i++){
  141630. float wd=w[i]*w[i];
  141631. float ws=1.-wd;
  141632. d[i]=d[i]*wd + s[i]*ws;
  141633. }
  141634. }
  141635. for(;j<ch2;j++){
  141636. float *d=pcm[j];
  141637. for(i=0;i<n;i++){
  141638. float wd=w[i]*w[i];
  141639. d[i]=d[i]*wd;
  141640. }
  141641. }
  141642. }
  141643. static int _ov_initset(OggVorbis_File *vf){
  141644. while(1){
  141645. if(vf->ready_state==INITSET)break;
  141646. {
  141647. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141648. if(ret<0 && ret!=OV_HOLE)return(ret);
  141649. }
  141650. }
  141651. return 0;
  141652. }
  141653. static int _ov_initprime(OggVorbis_File *vf){
  141654. vorbis_dsp_state *vd=&vf->vd;
  141655. while(1){
  141656. if(vf->ready_state==INITSET)
  141657. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141658. {
  141659. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141660. if(ret<0 && ret!=OV_HOLE)return(ret);
  141661. }
  141662. }
  141663. return 0;
  141664. }
  141665. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141666. float **lappcm,int lapsize){
  141667. int lapcount=0,i;
  141668. float **pcm;
  141669. while(lapcount<lapsize){
  141670. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141671. if(samples){
  141672. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141673. for(i=0;i<vi->channels;i++)
  141674. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141675. lapcount+=samples;
  141676. vorbis_synthesis_read(vd,samples);
  141677. }else{
  141678. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141679. if(ret==OV_EOF)break;
  141680. }
  141681. }
  141682. if(lapcount<lapsize){
  141683. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141684. if(samples==0){
  141685. for(i=0;i<vi->channels;i++)
  141686. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141687. lapcount=lapsize;
  141688. }else{
  141689. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141690. for(i=0;i<vi->channels;i++)
  141691. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141692. lapcount+=samples;
  141693. }
  141694. }
  141695. }
  141696. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  141697. vorbis_info *vi1,*vi2;
  141698. float **lappcm;
  141699. float **pcm;
  141700. float *w1,*w2;
  141701. int n1,n2,i,ret,hs1,hs2;
  141702. if(vf1==vf2)return(0); /* degenerate case */
  141703. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  141704. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  141705. ret=_ov_initset(vf1);
  141706. if(ret)return(ret);
  141707. ret=_ov_initprime(vf2);
  141708. if(ret)return(ret);
  141709. vi1=ov_info(vf1,-1);
  141710. vi2=ov_info(vf2,-1);
  141711. hs1=ov_halfrate_p(vf1);
  141712. hs2=ov_halfrate_p(vf2);
  141713. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  141714. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  141715. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  141716. w1=vorbis_window(&vf1->vd,0);
  141717. w2=vorbis_window(&vf2->vd,0);
  141718. for(i=0;i<vi1->channels;i++)
  141719. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141720. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  141721. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  141722. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  141723. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  141724. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  141725. return(0);
  141726. }
  141727. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  141728. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  141729. vorbis_info *vi;
  141730. float **lappcm;
  141731. float **pcm;
  141732. float *w1,*w2;
  141733. int n1,n2,ch1,ch2,hs;
  141734. int i,ret;
  141735. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141736. ret=_ov_initset(vf);
  141737. if(ret)return(ret);
  141738. vi=ov_info(vf,-1);
  141739. hs=ov_halfrate_p(vf);
  141740. ch1=vi->channels;
  141741. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141742. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141743. persistent; even if the decode state
  141744. from this link gets dumped, this
  141745. window array continues to exist */
  141746. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141747. for(i=0;i<ch1;i++)
  141748. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141749. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141750. ret=localseek(vf,pos);
  141751. if(ret)return ret;
  141752. ret=_ov_initprime(vf);
  141753. if(ret)return(ret);
  141754. vi=ov_info(vf,-1);
  141755. ch2=vi->channels;
  141756. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141757. w2=vorbis_window(&vf->vd,0);
  141758. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141759. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141760. return(0);
  141761. }
  141762. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141763. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  141764. }
  141765. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141766. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  141767. }
  141768. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141769. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  141770. }
  141771. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  141772. int (*localseek)(OggVorbis_File *,double)){
  141773. vorbis_info *vi;
  141774. float **lappcm;
  141775. float **pcm;
  141776. float *w1,*w2;
  141777. int n1,n2,ch1,ch2,hs;
  141778. int i,ret;
  141779. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141780. ret=_ov_initset(vf);
  141781. if(ret)return(ret);
  141782. vi=ov_info(vf,-1);
  141783. hs=ov_halfrate_p(vf);
  141784. ch1=vi->channels;
  141785. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141786. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141787. persistent; even if the decode state
  141788. from this link gets dumped, this
  141789. window array continues to exist */
  141790. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141791. for(i=0;i<ch1;i++)
  141792. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141793. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141794. ret=localseek(vf,pos);
  141795. if(ret)return ret;
  141796. ret=_ov_initprime(vf);
  141797. if(ret)return(ret);
  141798. vi=ov_info(vf,-1);
  141799. ch2=vi->channels;
  141800. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141801. w2=vorbis_window(&vf->vd,0);
  141802. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141803. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141804. return(0);
  141805. }
  141806. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  141807. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  141808. }
  141809. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  141810. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  141811. }
  141812. #endif
  141813. /*** End of inlined file: vorbisfile.c ***/
  141814. /*** Start of inlined file: window.c ***/
  141815. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141816. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141817. // tasks..
  141818. #if JUCE_MSVC
  141819. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141820. #endif
  141821. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141822. #if JUCE_USE_OGGVORBIS
  141823. #include <stdlib.h>
  141824. #include <math.h>
  141825. static float vwin64[32] = {
  141826. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  141827. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  141828. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  141829. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  141830. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  141831. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  141832. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  141833. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  141834. };
  141835. static float vwin128[64] = {
  141836. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  141837. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  141838. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  141839. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  141840. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  141841. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  141842. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  141843. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  141844. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  141845. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  141846. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  141847. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  141848. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  141849. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  141850. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  141851. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  141852. };
  141853. static float vwin256[128] = {
  141854. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  141855. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  141856. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  141857. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  141858. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  141859. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  141860. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  141861. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  141862. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  141863. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  141864. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  141865. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  141866. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  141867. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  141868. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  141869. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  141870. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  141871. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  141872. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  141873. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  141874. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  141875. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  141876. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  141877. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  141878. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  141879. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  141880. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  141881. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  141882. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  141883. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  141884. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  141885. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  141886. };
  141887. static float vwin512[256] = {
  141888. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  141889. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  141890. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  141891. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  141892. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  141893. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  141894. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  141895. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  141896. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  141897. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  141898. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  141899. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  141900. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  141901. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  141902. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  141903. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  141904. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  141905. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  141906. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  141907. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  141908. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  141909. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  141910. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  141911. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  141912. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  141913. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  141914. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  141915. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  141916. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  141917. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  141918. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  141919. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  141920. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  141921. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  141922. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  141923. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  141924. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  141925. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  141926. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  141927. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  141928. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  141929. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  141930. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  141931. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  141932. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  141933. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  141934. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  141935. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  141936. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  141937. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  141938. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  141939. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  141940. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  141941. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  141942. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  141943. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  141944. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  141945. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  141946. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  141947. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  141948. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  141949. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  141950. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  141951. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  141952. };
  141953. static float vwin1024[512] = {
  141954. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  141955. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  141956. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  141957. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  141958. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  141959. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  141960. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  141961. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  141962. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  141963. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  141964. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  141965. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  141966. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  141967. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  141968. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  141969. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  141970. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  141971. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  141972. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  141973. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  141974. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  141975. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  141976. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  141977. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  141978. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  141979. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  141980. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  141981. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  141982. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  141983. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  141984. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  141985. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  141986. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  141987. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  141988. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  141989. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  141990. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  141991. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  141992. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  141993. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  141994. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  141995. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  141996. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  141997. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  141998. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  141999. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142000. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142001. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142002. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142003. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142004. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142005. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142006. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142007. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142008. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142009. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142010. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142011. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142012. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142013. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142014. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142015. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142016. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142017. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142018. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142019. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142020. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142021. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142022. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142023. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142024. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142025. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142026. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142027. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142028. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142029. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142030. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142031. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142032. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142033. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142034. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142035. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142036. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142037. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142038. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142039. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142040. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142041. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142042. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142043. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142044. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142045. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142046. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142047. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142048. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142049. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142050. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142051. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142052. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142053. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142054. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142055. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142056. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142057. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142058. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142059. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142060. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142061. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142062. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142063. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142064. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142065. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142066. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142067. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142068. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142069. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142070. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142071. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142072. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142073. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142074. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142075. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142076. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142077. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142078. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142079. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142080. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142081. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142082. };
  142083. static float vwin2048[1024] = {
  142084. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142085. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142086. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142087. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142088. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142089. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142090. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142091. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142092. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142093. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142094. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142095. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142096. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142097. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142098. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142099. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142100. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142101. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142102. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142103. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142104. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142105. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142106. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142107. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142108. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142109. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142110. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142111. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142112. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142113. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142114. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142115. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142116. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142117. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142118. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142119. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142120. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142121. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142122. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142123. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142124. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142125. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142126. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142127. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142128. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142129. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142130. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142131. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142132. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142133. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142134. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142135. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142136. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142137. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142138. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142139. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142140. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142141. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142142. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142143. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142144. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142145. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142146. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142147. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142148. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142149. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142150. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142151. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142152. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142153. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142154. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142155. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142156. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142157. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142158. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142159. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142160. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142161. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142162. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142163. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142164. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142165. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142166. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142167. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142168. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142169. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142170. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142171. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142172. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142173. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142174. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142175. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142176. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142177. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142178. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142179. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142180. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142181. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142182. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142183. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142184. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142185. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142186. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142187. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142188. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142189. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142190. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142191. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142192. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142193. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142194. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142195. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142196. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142197. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142198. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142199. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142200. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142201. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142202. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142203. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142204. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142205. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142206. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142207. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142208. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142209. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142210. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142211. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142212. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142213. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142214. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142215. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142216. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142217. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142218. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142219. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142220. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142221. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142222. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142223. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142224. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142225. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142226. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142227. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142228. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142229. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142230. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142231. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142232. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142233. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142234. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142235. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142236. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142237. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142238. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142239. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142240. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142241. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142242. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142243. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142244. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142245. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142246. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142247. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142248. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142249. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142250. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142251. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142252. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142253. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142254. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142255. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142256. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142257. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142258. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142259. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142260. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142261. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142262. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142263. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142264. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142265. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142266. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142267. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142268. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142269. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142270. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142271. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142272. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142273. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142274. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142275. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142276. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142277. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142278. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142279. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142280. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142281. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142282. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142283. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142284. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142285. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142286. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142287. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142288. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142289. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142290. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142291. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142292. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142293. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142294. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142295. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142296. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142297. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142298. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142299. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142300. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142301. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142302. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142303. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142304. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142305. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142306. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142307. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142308. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142309. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142310. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142311. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142312. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142313. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142314. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142315. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142316. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142317. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142318. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142319. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142320. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142321. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142322. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142323. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142324. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142325. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142326. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142327. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142328. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142329. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142330. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142331. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142332. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142333. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142334. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142335. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142336. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142337. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142338. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142339. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142340. };
  142341. static float vwin4096[2048] = {
  142342. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142343. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142344. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142345. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142346. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142347. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142348. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142349. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142350. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142351. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142352. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142353. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142354. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142355. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142356. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142357. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142358. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142359. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142360. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142361. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142362. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142363. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142364. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142365. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142366. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142367. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142368. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142369. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142370. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142371. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142372. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142373. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142374. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142375. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142376. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142377. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142378. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142379. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142380. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142381. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142382. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142383. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142384. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142385. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142386. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142387. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142388. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142389. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142390. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142391. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142392. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142393. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142394. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142395. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142396. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142397. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142398. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142399. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142400. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142401. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142402. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142403. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142404. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142405. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142406. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142407. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142408. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142409. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142410. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142411. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142412. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142413. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142414. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142415. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142416. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142417. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142418. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142419. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142420. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142421. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142422. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142423. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142424. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142425. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142426. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142427. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142428. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142429. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142430. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142431. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142432. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142433. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142434. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142435. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142436. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142437. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142438. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142439. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142440. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142441. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142442. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142443. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142444. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142445. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142446. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142447. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142448. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142449. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142450. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142451. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142452. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142453. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142454. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142455. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142456. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142457. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142458. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142459. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142460. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142461. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142462. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142463. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142464. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142465. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142466. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142467. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142468. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142469. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142470. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142471. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142472. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142473. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142474. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142475. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142476. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142477. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142478. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142479. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142480. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142481. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142482. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142483. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142484. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142485. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142486. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142487. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142488. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142489. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142490. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142491. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142492. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142493. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142494. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142495. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142496. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142497. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142498. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142499. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142500. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142501. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142502. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142503. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142504. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142505. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142506. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142507. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142508. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142509. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142510. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142511. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142512. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142513. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142514. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142515. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142516. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142517. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142518. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142519. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142520. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142521. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142522. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142523. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142524. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142525. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142526. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142527. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142528. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142529. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142530. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142531. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142532. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142533. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142534. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142535. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142536. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142537. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142538. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142539. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142540. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142541. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142542. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142543. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142544. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142545. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142546. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142547. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142548. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142549. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142550. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142551. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142552. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142553. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142554. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142555. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142556. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142557. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142558. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142559. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142560. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142561. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142562. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142563. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142564. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142565. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142566. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142567. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142568. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142569. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142570. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142571. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142572. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142573. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142574. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142575. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142576. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142577. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142578. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142579. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142580. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142581. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142582. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142583. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142584. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142585. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142586. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142587. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142588. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142589. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142590. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142591. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142592. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142593. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142594. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142595. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142596. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142597. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142598. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142599. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142600. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142601. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142602. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142603. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142604. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142605. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142606. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142607. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142608. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142609. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142610. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142611. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142612. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142613. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142614. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142615. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142616. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142617. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142618. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142619. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142620. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142621. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142622. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142623. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142624. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142625. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142626. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142627. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142628. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142629. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142630. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142631. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142632. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142633. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142634. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142635. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142636. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142637. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142638. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142639. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142640. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142641. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142642. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142643. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142644. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142645. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142646. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142647. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142648. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142649. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142650. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142651. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142652. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142653. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142654. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142655. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142656. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142657. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142658. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142659. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142660. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142661. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142662. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142663. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142664. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142665. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142666. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142667. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142668. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142669. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142670. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142671. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142672. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142673. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142674. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142675. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142676. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142677. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142678. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142679. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142680. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142681. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142682. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142683. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142684. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142685. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142686. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142687. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142688. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142689. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142690. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142691. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142692. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  142693. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  142694. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  142695. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  142696. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  142697. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  142698. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  142699. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  142700. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  142701. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  142702. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  142703. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  142704. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  142705. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  142706. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  142707. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  142708. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  142709. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  142710. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  142711. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  142712. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  142713. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  142714. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  142715. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  142716. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  142717. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  142718. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  142719. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  142720. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  142721. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  142722. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  142723. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  142724. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  142725. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  142726. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  142727. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  142728. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  142729. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  142730. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  142731. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  142732. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  142733. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  142734. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  142735. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  142736. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  142737. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  142738. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  142739. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  142740. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  142741. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  142742. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  142743. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  142744. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  142745. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  142746. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  142747. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  142748. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  142749. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  142750. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  142751. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  142752. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  142753. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  142754. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  142755. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  142756. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  142757. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  142758. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  142759. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  142760. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  142761. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  142762. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  142763. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  142764. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  142765. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  142766. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  142767. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  142768. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  142769. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  142770. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  142771. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  142772. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  142773. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  142774. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  142775. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  142776. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  142777. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  142778. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  142779. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  142780. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  142781. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  142782. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  142783. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  142784. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  142785. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  142786. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  142787. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  142788. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  142789. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  142790. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  142791. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  142792. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  142793. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  142794. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  142795. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  142796. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  142797. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  142798. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  142799. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  142800. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  142801. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  142802. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  142803. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  142804. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  142805. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  142806. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  142807. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  142808. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  142809. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  142810. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  142811. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  142812. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  142813. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  142814. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  142815. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  142816. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  142817. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  142818. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  142819. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  142820. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  142821. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  142822. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  142823. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  142824. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  142825. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  142826. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  142827. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  142828. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  142829. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  142830. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  142831. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  142832. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  142833. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  142834. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  142835. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  142836. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  142837. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  142838. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  142839. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  142840. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  142841. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  142842. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  142843. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  142844. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  142845. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  142846. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  142847. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  142848. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  142849. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  142850. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  142851. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  142852. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  142853. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  142854. };
  142855. static float vwin8192[4096] = {
  142856. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  142857. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  142858. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  142859. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  142860. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  142861. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  142862. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  142863. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  142864. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  142865. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  142866. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  142867. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  142868. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  142869. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  142870. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  142871. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  142872. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  142873. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  142874. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  142875. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  142876. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  142877. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  142878. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  142879. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  142880. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  142881. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  142882. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  142883. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  142884. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  142885. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  142886. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  142887. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  142888. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  142889. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  142890. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  142891. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  142892. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  142893. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  142894. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  142895. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  142896. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  142897. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  142898. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  142899. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  142900. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  142901. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  142902. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  142903. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  142904. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  142905. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  142906. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  142907. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  142908. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  142909. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  142910. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  142911. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  142912. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  142913. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  142914. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  142915. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  142916. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  142917. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  142918. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  142919. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  142920. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  142921. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  142922. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  142923. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  142924. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  142925. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  142926. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  142927. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  142928. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  142929. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  142930. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  142931. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  142932. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  142933. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  142934. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  142935. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  142936. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  142937. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  142938. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  142939. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  142940. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  142941. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  142942. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  142943. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  142944. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  142945. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  142946. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  142947. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  142948. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  142949. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  142950. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  142951. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  142952. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  142953. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  142954. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  142955. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  142956. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  142957. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  142958. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  142959. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  142960. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  142961. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  142962. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  142963. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  142964. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  142965. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  142966. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  142967. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  142968. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  142969. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  142970. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  142971. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  142972. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  142973. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  142974. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  142975. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  142976. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  142977. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  142978. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  142979. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  142980. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  142981. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  142982. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  142983. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  142984. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  142985. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  142986. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  142987. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  142988. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  142989. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  142990. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  142991. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  142992. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  142993. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  142994. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  142995. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  142996. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  142997. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  142998. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  142999. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143000. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143001. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143002. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143003. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143004. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143005. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143006. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143007. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143008. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143009. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143010. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143011. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143012. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143013. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143014. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143015. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143016. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143017. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143018. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143019. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143020. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143021. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143022. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143023. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143024. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143025. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143026. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143027. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143028. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143029. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143030. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143031. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143032. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143033. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143034. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143035. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143036. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143037. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143038. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143039. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143040. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143041. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143042. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143043. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143044. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143045. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143046. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143047. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143048. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143049. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143050. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143051. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143052. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143053. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143054. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143055. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143056. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143057. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143058. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143059. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143060. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143061. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143062. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143063. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143064. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143065. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143066. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143067. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143068. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143069. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143070. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143071. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143072. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143073. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143074. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143075. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143076. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143077. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143078. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143079. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143080. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143081. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143082. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143083. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143084. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143085. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143086. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143087. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143088. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143089. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143090. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143091. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143092. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143093. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143094. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143095. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143096. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143097. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143098. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143099. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143100. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143101. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143102. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143103. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143104. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143105. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143106. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143107. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143108. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143109. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143110. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143111. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143112. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143113. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143114. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143115. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143116. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143117. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143118. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143119. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143120. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143121. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143122. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143123. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143124. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143125. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143126. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143127. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143128. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143129. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143130. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143131. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143132. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143133. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143134. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143135. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143136. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143137. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143138. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143139. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143140. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143141. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143142. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143143. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143144. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143145. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143146. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143147. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143148. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143149. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143150. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143151. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143152. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143153. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143154. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143155. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143156. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143157. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143158. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143159. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143160. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143161. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143162. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143163. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143164. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143165. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143166. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143167. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143168. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143169. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143170. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143171. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143172. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143173. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143174. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143175. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143176. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143177. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143178. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143179. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143180. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143181. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143182. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143183. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143184. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143185. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143186. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143187. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143188. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143189. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143190. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143191. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143192. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143193. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143194. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143195. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143196. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143197. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143198. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143199. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143200. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143201. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143202. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143203. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143204. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143205. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143206. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143207. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143208. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143209. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143210. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143211. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143212. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143213. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143214. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143215. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143216. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143217. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143218. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143219. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143220. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143221. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143222. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143223. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143224. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143225. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143226. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143227. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143228. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143229. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143230. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143231. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143232. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143233. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143234. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143235. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143236. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143237. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143238. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143239. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143240. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143241. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143242. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143243. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143244. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143245. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143246. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143247. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143248. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143249. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143250. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143251. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143252. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143253. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143254. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143255. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143256. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143257. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143258. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143259. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143260. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143261. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143262. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143263. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143264. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143265. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143266. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143267. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143268. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143269. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143270. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143271. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143272. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143273. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143274. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143275. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143276. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143277. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143278. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143279. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143280. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143281. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143282. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143283. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143284. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143285. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143286. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143287. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143288. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143289. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143290. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143291. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143292. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143293. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143294. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143295. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143296. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143297. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143298. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143299. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143300. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143301. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143302. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143303. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143304. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143305. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143306. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143307. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143308. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143309. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143310. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143311. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143312. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143313. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143314. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143315. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143316. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143317. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143318. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143319. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143320. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143321. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143322. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143323. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143324. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143325. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143326. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143327. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143328. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143329. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143330. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143331. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143332. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143333. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143334. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143335. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143336. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143337. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143338. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143339. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143340. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143341. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143342. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143343. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143344. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143345. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143346. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143347. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143348. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143349. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143350. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143351. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143352. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143353. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143354. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143355. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143356. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143357. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143358. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143359. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143360. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143361. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143362. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143363. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143364. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143365. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143366. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143367. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143368. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143369. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143370. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143371. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143372. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143373. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143374. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143375. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143376. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143377. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143378. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143379. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143380. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143381. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143382. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143383. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143384. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143385. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143386. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143387. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143388. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143389. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143390. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143391. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143392. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143393. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143394. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143395. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143396. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143397. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143398. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143399. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143400. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143401. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143402. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143403. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143404. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143405. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143406. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143407. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143408. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143409. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143410. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143411. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143412. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143413. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143414. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143415. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143416. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143417. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143418. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143419. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143420. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143421. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143422. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143423. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143424. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143425. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143426. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143427. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143428. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143429. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143430. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143431. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143432. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143433. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143434. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143435. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143436. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143437. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143438. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143439. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143440. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143441. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143442. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143443. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143444. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143445. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143446. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143447. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143448. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143449. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143450. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143451. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143452. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143453. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143454. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143455. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143456. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143457. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143458. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143459. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143460. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143461. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143462. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143463. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143464. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143465. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143466. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143467. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143468. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143469. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143470. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143471. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143472. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143473. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143474. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143475. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143476. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143477. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143478. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143479. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143480. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143481. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143482. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143483. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143484. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143485. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143486. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143487. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143488. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143489. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143490. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143491. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143492. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143493. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143494. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143495. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143496. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143497. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143498. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143499. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143500. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143501. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143502. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143503. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143504. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143505. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143506. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143507. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143508. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143509. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143510. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143511. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143512. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143513. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143514. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143515. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143516. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143517. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143518. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143519. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143520. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143521. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143522. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143523. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143524. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143525. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143526. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143527. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143528. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143529. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143530. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143531. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143532. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143533. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143534. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143535. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143536. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143537. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143538. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143539. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143540. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143541. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143542. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143543. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143544. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143545. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143546. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143547. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143548. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143549. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143550. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143551. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143552. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143553. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143554. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143555. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143556. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143557. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143558. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143559. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143560. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143561. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143562. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143563. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143564. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143565. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143566. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143567. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143568. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143569. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143570. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143571. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143572. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143573. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143574. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143575. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143576. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143577. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143578. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143579. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143580. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143581. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143582. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143583. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143584. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143585. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143586. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143587. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143588. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143589. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143590. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143591. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143592. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143593. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143594. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143595. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143596. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143597. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143598. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143599. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143600. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143601. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143602. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143603. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143604. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143605. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143606. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143607. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143608. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143609. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143610. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143611. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143612. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143613. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143614. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143615. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143616. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143617. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143618. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143619. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143620. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143621. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143622. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143623. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143624. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143625. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143626. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143627. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143628. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143629. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143630. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143631. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143632. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143633. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143634. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143635. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143636. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143637. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143638. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143639. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143640. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143641. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143642. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143643. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143644. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143645. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143646. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143647. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143648. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143649. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143650. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143651. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143652. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143653. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143654. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143655. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143656. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143657. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143658. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143659. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143660. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143661. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143662. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143663. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143664. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143665. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143666. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143667. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143668. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143669. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143670. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143671. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143672. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143673. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143674. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143675. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143676. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143677. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143678. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143679. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143680. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143681. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143682. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143683. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143684. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143685. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143686. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143687. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143688. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143689. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143690. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143691. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143692. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  143693. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  143694. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  143695. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  143696. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  143697. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  143698. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  143699. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  143700. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  143701. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  143702. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  143703. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  143704. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  143705. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  143706. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  143707. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  143708. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  143709. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  143710. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  143711. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  143712. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  143713. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  143714. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  143715. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  143716. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  143717. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  143718. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  143719. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  143720. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  143721. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  143722. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  143723. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  143724. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  143725. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  143726. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  143727. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  143728. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  143729. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  143730. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  143731. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  143732. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  143733. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  143734. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  143735. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  143736. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  143737. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  143738. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  143739. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  143740. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  143741. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  143742. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  143743. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  143744. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  143745. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  143746. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  143747. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  143748. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  143749. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  143750. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  143751. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  143752. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  143753. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  143754. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  143755. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  143756. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  143757. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  143758. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  143759. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  143760. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  143761. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  143762. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  143763. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  143764. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  143765. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  143766. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  143767. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  143768. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  143769. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  143770. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  143771. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  143772. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  143773. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  143774. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  143775. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  143776. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  143777. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  143778. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  143779. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  143780. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  143781. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  143782. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  143783. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  143784. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  143785. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  143786. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  143787. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  143788. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  143789. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  143790. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  143791. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  143792. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  143793. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  143794. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  143795. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  143796. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  143797. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  143798. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  143799. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  143800. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  143801. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  143802. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  143803. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  143804. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  143805. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  143806. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  143807. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  143808. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  143809. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  143810. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  143811. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  143812. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  143813. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  143814. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  143815. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  143816. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  143817. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  143818. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  143819. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  143820. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  143821. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  143822. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  143823. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  143824. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  143825. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  143826. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  143827. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  143828. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  143829. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  143830. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  143831. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  143832. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  143833. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  143834. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  143835. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  143836. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  143837. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  143838. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  143839. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  143840. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  143841. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  143842. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  143843. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  143844. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  143845. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  143846. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  143847. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  143848. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  143849. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  143850. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  143851. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  143852. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  143853. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  143854. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  143855. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  143856. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  143857. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  143858. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  143859. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  143860. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  143861. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  143862. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  143863. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  143864. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  143865. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  143866. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  143867. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  143868. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  143869. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  143870. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  143871. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  143872. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  143873. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  143874. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  143875. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  143876. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  143877. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  143878. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143879. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143880. };
  143881. static float *vwin[8] = {
  143882. vwin64,
  143883. vwin128,
  143884. vwin256,
  143885. vwin512,
  143886. vwin1024,
  143887. vwin2048,
  143888. vwin4096,
  143889. vwin8192,
  143890. };
  143891. float *_vorbis_window_get(int n){
  143892. return vwin[n];
  143893. }
  143894. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  143895. int lW,int W,int nW){
  143896. lW=(W?lW:0);
  143897. nW=(W?nW:0);
  143898. {
  143899. float *windowLW=vwin[winno[lW]];
  143900. float *windowNW=vwin[winno[nW]];
  143901. long n=blocksizes[W];
  143902. long ln=blocksizes[lW];
  143903. long rn=blocksizes[nW];
  143904. long leftbegin=n/4-ln/4;
  143905. long leftend=leftbegin+ln/2;
  143906. long rightbegin=n/2+n/4-rn/4;
  143907. long rightend=rightbegin+rn/2;
  143908. int i,p;
  143909. for(i=0;i<leftbegin;i++)
  143910. d[i]=0.f;
  143911. for(p=0;i<leftend;i++,p++)
  143912. d[i]*=windowLW[p];
  143913. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  143914. d[i]*=windowNW[p];
  143915. for(;i<n;i++)
  143916. d[i]=0.f;
  143917. }
  143918. }
  143919. #endif
  143920. /*** End of inlined file: window.c ***/
  143921. #else
  143922. #include <vorbis/vorbisenc.h>
  143923. #include <vorbis/codec.h>
  143924. #include <vorbis/vorbisfile.h>
  143925. #endif
  143926. }
  143927. #undef max
  143928. #undef min
  143929. BEGIN_JUCE_NAMESPACE
  143930. static const char* const oggFormatName = "Ogg-Vorbis file";
  143931. static const juce_wchar* const oggExtensions[] = { T(".ogg"), 0 };
  143932. class OggReader : public AudioFormatReader
  143933. {
  143934. OggVorbisNamespace::OggVorbis_File ovFile;
  143935. OggVorbisNamespace::ov_callbacks callbacks;
  143936. AudioSampleBuffer reservoir;
  143937. int reservoirStart, samplesInReservoir;
  143938. public:
  143939. OggReader (InputStream* const inp)
  143940. : AudioFormatReader (inp, TRANS (oggFormatName)),
  143941. reservoir (2, 4096),
  143942. reservoirStart (0),
  143943. samplesInReservoir (0)
  143944. {
  143945. using namespace OggVorbisNamespace;
  143946. sampleRate = 0;
  143947. usesFloatingPointData = true;
  143948. callbacks.read_func = &oggReadCallback;
  143949. callbacks.seek_func = &oggSeekCallback;
  143950. callbacks.close_func = &oggCloseCallback;
  143951. callbacks.tell_func = &oggTellCallback;
  143952. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  143953. if (err == 0)
  143954. {
  143955. vorbis_info* info = ov_info (&ovFile, -1);
  143956. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  143957. numChannels = info->channels;
  143958. bitsPerSample = 16;
  143959. sampleRate = info->rate;
  143960. reservoir.setSize (numChannels,
  143961. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  143962. }
  143963. }
  143964. ~OggReader()
  143965. {
  143966. OggVorbisNamespace::ov_clear (&ovFile);
  143967. }
  143968. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  143969. int64 startSampleInFile, int numSamples)
  143970. {
  143971. while (numSamples > 0)
  143972. {
  143973. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  143974. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  143975. {
  143976. // got a few samples overlapping, so use them before seeking..
  143977. const int numToUse = jmin (numSamples, numAvailable);
  143978. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  143979. if (destSamples[i] != 0)
  143980. memcpy (destSamples[i] + startOffsetInDestBuffer,
  143981. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  143982. sizeof (float) * numToUse);
  143983. startSampleInFile += numToUse;
  143984. numSamples -= numToUse;
  143985. startOffsetInDestBuffer += numToUse;
  143986. if (numSamples == 0)
  143987. break;
  143988. }
  143989. if (startSampleInFile < reservoirStart
  143990. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  143991. {
  143992. // buffer miss, so refill the reservoir
  143993. int bitStream = 0;
  143994. reservoirStart = jmax (0, (int) startSampleInFile);
  143995. samplesInReservoir = reservoir.getNumSamples();
  143996. if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
  143997. OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
  143998. int offset = 0;
  143999. int numToRead = samplesInReservoir;
  144000. while (numToRead > 0)
  144001. {
  144002. float** dataIn = 0;
  144003. const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144004. if (samps <= 0)
  144005. break;
  144006. jassert (samps <= numToRead);
  144007. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144008. {
  144009. memcpy (reservoir.getSampleData (i, offset),
  144010. dataIn[i],
  144011. sizeof (float) * samps);
  144012. }
  144013. numToRead -= samps;
  144014. offset += samps;
  144015. }
  144016. if (numToRead > 0)
  144017. reservoir.clear (offset, numToRead);
  144018. }
  144019. }
  144020. if (numSamples > 0)
  144021. {
  144022. for (int i = numDestChannels; --i >= 0;)
  144023. if (destSamples[i] != 0)
  144024. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144025. sizeof (int) * numSamples);
  144026. }
  144027. return true;
  144028. }
  144029. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144030. {
  144031. return (size_t) (static_cast <InputStream*> (datasource)->read (ptr, (int) (size * nmemb)) / size);
  144032. }
  144033. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144034. {
  144035. InputStream* const in = static_cast <InputStream*> (datasource);
  144036. if (whence == SEEK_CUR)
  144037. offset += in->getPosition();
  144038. else if (whence == SEEK_END)
  144039. offset += in->getTotalLength();
  144040. in->setPosition (offset);
  144041. return 0;
  144042. }
  144043. static int oggCloseCallback (void*)
  144044. {
  144045. return 0;
  144046. }
  144047. static long oggTellCallback (void* datasource)
  144048. {
  144049. return (long) static_cast <InputStream*> (datasource)->getPosition();
  144050. }
  144051. juce_UseDebuggingNewOperator
  144052. };
  144053. class OggWriter : public AudioFormatWriter
  144054. {
  144055. OggVorbisNamespace::ogg_stream_state os;
  144056. OggVorbisNamespace::ogg_page og;
  144057. OggVorbisNamespace::ogg_packet op;
  144058. OggVorbisNamespace::vorbis_info vi;
  144059. OggVorbisNamespace::vorbis_comment vc;
  144060. OggVorbisNamespace::vorbis_dsp_state vd;
  144061. OggVorbisNamespace::vorbis_block vb;
  144062. public:
  144063. bool ok;
  144064. OggWriter (OutputStream* const out,
  144065. const double sampleRate,
  144066. const int numChannels,
  144067. const int bitsPerSample,
  144068. const int qualityIndex)
  144069. : AudioFormatWriter (out, TRANS (oggFormatName),
  144070. sampleRate,
  144071. numChannels,
  144072. bitsPerSample)
  144073. {
  144074. using namespace OggVorbisNamespace;
  144075. ok = false;
  144076. vorbis_info_init (&vi);
  144077. if (vorbis_encode_init_vbr (&vi,
  144078. numChannels,
  144079. (int) sampleRate,
  144080. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144081. {
  144082. vorbis_comment_init (&vc);
  144083. if (JUCEApplication::getInstance() != 0)
  144084. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144085. vorbis_analysis_init (&vd, &vi);
  144086. vorbis_block_init (&vd, &vb);
  144087. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144088. ogg_packet header;
  144089. ogg_packet header_comm;
  144090. ogg_packet header_code;
  144091. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144092. ogg_stream_packetin (&os, &header);
  144093. ogg_stream_packetin (&os, &header_comm);
  144094. ogg_stream_packetin (&os, &header_code);
  144095. for (;;)
  144096. {
  144097. if (ogg_stream_flush (&os, &og) == 0)
  144098. break;
  144099. output->write (og.header, og.header_len);
  144100. output->write (og.body, og.body_len);
  144101. }
  144102. ok = true;
  144103. }
  144104. }
  144105. ~OggWriter()
  144106. {
  144107. using namespace OggVorbisNamespace;
  144108. if (ok)
  144109. {
  144110. // write a zero-length packet to show ogg that we're finished..
  144111. write (0, 0);
  144112. ogg_stream_clear (&os);
  144113. vorbis_block_clear (&vb);
  144114. vorbis_dsp_clear (&vd);
  144115. vorbis_comment_clear (&vc);
  144116. vorbis_info_clear (&vi);
  144117. output->flush();
  144118. }
  144119. else
  144120. {
  144121. vorbis_info_clear (&vi);
  144122. output = 0; // to stop the base class deleting this, as it needs to be returned
  144123. // to the caller of createWriter()
  144124. }
  144125. }
  144126. bool write (const int** samplesToWrite, int numSamples)
  144127. {
  144128. using namespace OggVorbisNamespace;
  144129. if (! ok)
  144130. return false;
  144131. if (numSamples > 0)
  144132. {
  144133. const double gain = 1.0 / 0x80000000u;
  144134. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144135. for (int i = numChannels; --i >= 0;)
  144136. {
  144137. float* const dst = vorbisBuffer[i];
  144138. const int* const src = samplesToWrite [i];
  144139. if (src != 0 && dst != 0)
  144140. {
  144141. for (int j = 0; j < numSamples; ++j)
  144142. dst[j] = (float) (src[j] * gain);
  144143. }
  144144. }
  144145. }
  144146. vorbis_analysis_wrote (&vd, numSamples);
  144147. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144148. {
  144149. vorbis_analysis (&vb, 0);
  144150. vorbis_bitrate_addblock (&vb);
  144151. while (vorbis_bitrate_flushpacket (&vd, &op))
  144152. {
  144153. ogg_stream_packetin (&os, &op);
  144154. for (;;)
  144155. {
  144156. if (ogg_stream_pageout (&os, &og) == 0)
  144157. break;
  144158. output->write (og.header, og.header_len);
  144159. output->write (og.body, og.body_len);
  144160. if (ogg_page_eos (&og))
  144161. break;
  144162. }
  144163. }
  144164. }
  144165. return true;
  144166. }
  144167. juce_UseDebuggingNewOperator
  144168. };
  144169. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144170. : AudioFormat (TRANS (oggFormatName), (const juce_wchar**) oggExtensions)
  144171. {
  144172. }
  144173. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144174. {
  144175. }
  144176. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144177. {
  144178. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144179. return Array <int> (rates);
  144180. }
  144181. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144182. {
  144183. Array <int> depths;
  144184. depths.add (32);
  144185. return depths;
  144186. }
  144187. bool OggVorbisAudioFormat::canDoStereo()
  144188. {
  144189. return true;
  144190. }
  144191. bool OggVorbisAudioFormat::canDoMono()
  144192. {
  144193. return true;
  144194. }
  144195. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144196. const bool deleteStreamIfOpeningFails)
  144197. {
  144198. ScopedPointer <OggReader> r (new OggReader (in));
  144199. if (r->sampleRate != 0)
  144200. return r.release();
  144201. if (! deleteStreamIfOpeningFails)
  144202. r->input = 0;
  144203. return 0;
  144204. }
  144205. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144206. double sampleRate,
  144207. unsigned int numChannels,
  144208. int bitsPerSample,
  144209. const StringPairArray& /*metadataValues*/,
  144210. int qualityOptionIndex)
  144211. {
  144212. ScopedPointer <OggWriter> w (new OggWriter (out,
  144213. sampleRate,
  144214. numChannels,
  144215. bitsPerSample,
  144216. qualityOptionIndex));
  144217. return w->ok ? w.release() : 0;
  144218. }
  144219. bool OggVorbisAudioFormat::isCompressed()
  144220. {
  144221. return true;
  144222. }
  144223. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144224. {
  144225. StringArray s;
  144226. s.add ("Low Quality");
  144227. s.add ("Medium Quality");
  144228. s.add ("High Quality");
  144229. return s;
  144230. }
  144231. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144232. {
  144233. FileInputStream* const in = source.createInputStream();
  144234. if (in != 0)
  144235. {
  144236. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144237. if (r != 0)
  144238. {
  144239. const int64 numSamps = r->lengthInSamples;
  144240. r = 0;
  144241. const int64 fileNumSamps = source.getSize() / 4;
  144242. const double ratio = numSamps / (double) fileNumSamps;
  144243. if (ratio > 12.0)
  144244. return 0;
  144245. else if (ratio > 6.0)
  144246. return 1;
  144247. else
  144248. return 2;
  144249. }
  144250. }
  144251. return 1;
  144252. }
  144253. END_JUCE_NAMESPACE
  144254. #endif
  144255. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144256. #endif
  144257. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144258. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144259. #if JUCE_MSVC
  144260. #pragma warning (push)
  144261. #endif
  144262. namespace jpeglibNamespace
  144263. {
  144264. #if JUCE_INCLUDE_JPEGLIB_CODE
  144265. #if JUCE_MINGW
  144266. typedef unsigned char boolean;
  144267. #endif
  144268. extern "C"
  144269. {
  144270. #define JPEG_INTERNALS
  144271. #undef FAR
  144272. /*** Start of inlined file: jpeglib.h ***/
  144273. #ifndef JPEGLIB_H
  144274. #define JPEGLIB_H
  144275. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144276. /*** Start of inlined file: jconfig.h ***/
  144277. // disable all the warnings under MSVC
  144278. #ifdef _MSC_VER
  144279. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144280. #endif
  144281. #ifdef __BORLANDC__
  144282. #pragma warn -8057
  144283. #pragma warn -8019
  144284. #pragma warn -8004
  144285. #pragma warn -8008
  144286. #endif
  144287. #define HAVE_PROTOTYPES
  144288. #define HAVE_UNSIGNED_CHAR
  144289. #define HAVE_UNSIGNED_SHORT
  144290. #undef CHAR_IS_UNSIGNED
  144291. #define HAVE_STDDEF_H
  144292. #define HAVE_STDLIB_H
  144293. #undef NEED_BSD_STRINGS
  144294. #undef NEED_SYS_TYPES_H
  144295. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144296. #undef NEED_SHORT_EXTERNAL_NAMES
  144297. #undef INCOMPLETE_TYPES_BROKEN
  144298. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144299. typedef unsigned char boolean;
  144300. #endif
  144301. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144302. #ifdef JPEG_INTERNALS
  144303. #undef RIGHT_SHIFT_IS_UNSIGNED
  144304. #endif /* JPEG_INTERNALS */
  144305. #ifdef JPEG_CJPEG_DJPEG
  144306. #define BMP_SUPPORTED /* BMP image file format */
  144307. #define GIF_SUPPORTED /* GIF image file format */
  144308. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144309. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144310. #define TARGA_SUPPORTED /* Targa image file format */
  144311. #define TWO_FILE_COMMANDLINE /* optional */
  144312. #define USE_SETMODE /* Microsoft has setmode() */
  144313. #undef NEED_SIGNAL_CATCHER
  144314. #undef DONT_USE_B_MODE
  144315. #undef PROGRESS_REPORT /* optional */
  144316. #endif /* JPEG_CJPEG_DJPEG */
  144317. /*** End of inlined file: jconfig.h ***/
  144318. /* widely used configuration options */
  144319. #endif
  144320. /*** Start of inlined file: jmorecfg.h ***/
  144321. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144322. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144323. #if BITS_IN_JSAMPLE == 8
  144324. #ifdef HAVE_UNSIGNED_CHAR
  144325. typedef unsigned char JSAMPLE;
  144326. #define GETJSAMPLE(value) ((int) (value))
  144327. #else /* not HAVE_UNSIGNED_CHAR */
  144328. typedef char JSAMPLE;
  144329. #ifdef CHAR_IS_UNSIGNED
  144330. #define GETJSAMPLE(value) ((int) (value))
  144331. #else
  144332. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144333. #endif /* CHAR_IS_UNSIGNED */
  144334. #endif /* HAVE_UNSIGNED_CHAR */
  144335. #define MAXJSAMPLE 255
  144336. #define CENTERJSAMPLE 128
  144337. #endif /* BITS_IN_JSAMPLE == 8 */
  144338. #if BITS_IN_JSAMPLE == 12
  144339. typedef short JSAMPLE;
  144340. #define GETJSAMPLE(value) ((int) (value))
  144341. #define MAXJSAMPLE 4095
  144342. #define CENTERJSAMPLE 2048
  144343. #endif /* BITS_IN_JSAMPLE == 12 */
  144344. typedef short JCOEF;
  144345. #ifdef HAVE_UNSIGNED_CHAR
  144346. typedef unsigned char JOCTET;
  144347. #define GETJOCTET(value) (value)
  144348. #else /* not HAVE_UNSIGNED_CHAR */
  144349. typedef char JOCTET;
  144350. #ifdef CHAR_IS_UNSIGNED
  144351. #define GETJOCTET(value) (value)
  144352. #else
  144353. #define GETJOCTET(value) ((value) & 0xFF)
  144354. #endif /* CHAR_IS_UNSIGNED */
  144355. #endif /* HAVE_UNSIGNED_CHAR */
  144356. #ifdef HAVE_UNSIGNED_CHAR
  144357. typedef unsigned char UINT8;
  144358. #else /* not HAVE_UNSIGNED_CHAR */
  144359. #ifdef CHAR_IS_UNSIGNED
  144360. typedef char UINT8;
  144361. #else /* not CHAR_IS_UNSIGNED */
  144362. typedef short UINT8;
  144363. #endif /* CHAR_IS_UNSIGNED */
  144364. #endif /* HAVE_UNSIGNED_CHAR */
  144365. #ifdef HAVE_UNSIGNED_SHORT
  144366. typedef unsigned short UINT16;
  144367. #else /* not HAVE_UNSIGNED_SHORT */
  144368. typedef unsigned int UINT16;
  144369. #endif /* HAVE_UNSIGNED_SHORT */
  144370. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144371. typedef short INT16;
  144372. #endif
  144373. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144374. typedef long INT32;
  144375. #endif
  144376. typedef unsigned int JDIMENSION;
  144377. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144378. #define METHODDEF(type) static type
  144379. #define LOCAL(type) static type
  144380. #define GLOBAL(type) type
  144381. #define EXTERN(type) extern type
  144382. #ifdef HAVE_PROTOTYPES
  144383. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144384. #else
  144385. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144386. #endif
  144387. #ifdef NEED_FAR_POINTERS
  144388. #define FAR far
  144389. #else
  144390. #define FAR
  144391. #endif
  144392. #ifndef HAVE_BOOLEAN
  144393. typedef int boolean;
  144394. #endif
  144395. #ifndef FALSE /* in case these macros already exist */
  144396. #define FALSE 0 /* values of boolean */
  144397. #endif
  144398. #ifndef TRUE
  144399. #define TRUE 1
  144400. #endif
  144401. #ifdef JPEG_INTERNALS
  144402. #define JPEG_INTERNAL_OPTIONS
  144403. #endif
  144404. #ifdef JPEG_INTERNAL_OPTIONS
  144405. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144406. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144407. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144408. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144409. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144410. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144411. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144412. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144413. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144414. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144415. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144416. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144417. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144418. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144419. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144420. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144421. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144422. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144423. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144424. #define RGB_GREEN 1 /* Offset of Green */
  144425. #define RGB_BLUE 2 /* Offset of Blue */
  144426. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144427. #ifndef INLINE
  144428. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144429. #define INLINE __inline__
  144430. #endif
  144431. #ifndef INLINE
  144432. #define INLINE /* default is to define it as empty */
  144433. #endif
  144434. #endif
  144435. #ifndef MULTIPLIER
  144436. #define MULTIPLIER int /* type for fastest integer multiply */
  144437. #endif
  144438. #ifndef FAST_FLOAT
  144439. #ifdef HAVE_PROTOTYPES
  144440. #define FAST_FLOAT float
  144441. #else
  144442. #define FAST_FLOAT double
  144443. #endif
  144444. #endif
  144445. #endif /* JPEG_INTERNAL_OPTIONS */
  144446. /*** End of inlined file: jmorecfg.h ***/
  144447. /* seldom changed options */
  144448. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144449. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144450. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144451. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144452. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144453. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144454. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144455. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144456. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144457. #ifndef D_MAX_BLOCKS_IN_MCU
  144458. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144459. #endif
  144460. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144461. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144462. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144463. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144464. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144465. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144466. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144467. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144468. typedef struct {
  144469. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144470. boolean sent_table; /* TRUE when table has been output */
  144471. } JQUANT_TBL;
  144472. typedef struct {
  144473. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144474. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144475. boolean sent_table; /* TRUE when table has been output */
  144476. } JHUFF_TBL;
  144477. typedef struct {
  144478. int component_id; /* identifier for this component (0..255) */
  144479. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144480. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144481. int v_samp_factor; /* vertical sampling factor (1..4) */
  144482. int quant_tbl_no; /* quantization table selector (0..3) */
  144483. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144484. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144485. JDIMENSION width_in_blocks;
  144486. JDIMENSION height_in_blocks;
  144487. int DCT_scaled_size;
  144488. JDIMENSION downsampled_width; /* actual width in samples */
  144489. JDIMENSION downsampled_height; /* actual height in samples */
  144490. boolean component_needed; /* do we need the value of this component? */
  144491. int MCU_width; /* number of blocks per MCU, horizontally */
  144492. int MCU_height; /* number of blocks per MCU, vertically */
  144493. int MCU_blocks; /* MCU_width * MCU_height */
  144494. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144495. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144496. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144497. JQUANT_TBL * quant_table;
  144498. void * dct_table;
  144499. } jpeg_component_info;
  144500. typedef struct {
  144501. int comps_in_scan; /* number of components encoded in this scan */
  144502. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144503. int Ss, Se; /* progressive JPEG spectral selection parms */
  144504. int Ah, Al; /* progressive JPEG successive approx. parms */
  144505. } jpeg_scan_info;
  144506. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144507. struct jpeg_marker_struct {
  144508. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144509. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144510. unsigned int original_length; /* # bytes of data in the file */
  144511. unsigned int data_length; /* # bytes of data saved at data[] */
  144512. JOCTET FAR * data; /* the data contained in the marker */
  144513. };
  144514. typedef enum {
  144515. JCS_UNKNOWN, /* error/unspecified */
  144516. JCS_GRAYSCALE, /* monochrome */
  144517. JCS_RGB, /* red/green/blue */
  144518. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144519. JCS_CMYK, /* C/M/Y/K */
  144520. JCS_YCCK /* Y/Cb/Cr/K */
  144521. } J_COLOR_SPACE;
  144522. typedef enum {
  144523. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144524. JDCT_IFAST, /* faster, less accurate integer method */
  144525. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144526. } J_DCT_METHOD;
  144527. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144528. #define JDCT_DEFAULT JDCT_ISLOW
  144529. #endif
  144530. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144531. #define JDCT_FASTEST JDCT_IFAST
  144532. #endif
  144533. typedef enum {
  144534. JDITHER_NONE, /* no dithering */
  144535. JDITHER_ORDERED, /* simple ordered dither */
  144536. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144537. } J_DITHER_MODE;
  144538. #define jpeg_common_fields \
  144539. struct jpeg_error_mgr * err; /* Error handler module */\
  144540. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144541. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144542. void * client_data; /* Available for use by application */\
  144543. boolean is_decompressor; /* So common code can tell which is which */\
  144544. int global_state /* For checking call sequence validity */
  144545. struct jpeg_common_struct {
  144546. jpeg_common_fields; /* Fields common to both master struct types */
  144547. };
  144548. typedef struct jpeg_common_struct * j_common_ptr;
  144549. typedef struct jpeg_compress_struct * j_compress_ptr;
  144550. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144551. struct jpeg_compress_struct {
  144552. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144553. struct jpeg_destination_mgr * dest;
  144554. JDIMENSION image_width; /* input image width */
  144555. JDIMENSION image_height; /* input image height */
  144556. int input_components; /* # of color components in input image */
  144557. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144558. double input_gamma; /* image gamma of input image */
  144559. int data_precision; /* bits of precision in image data */
  144560. int num_components; /* # of color components in JPEG image */
  144561. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144562. jpeg_component_info * comp_info;
  144563. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144564. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144565. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144566. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144567. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144568. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144569. int num_scans; /* # of entries in scan_info array */
  144570. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144571. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144572. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144573. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144574. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144575. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144576. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144577. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144578. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144579. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144580. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144581. UINT8 JFIF_minor_version;
  144582. UINT8 density_unit; /* JFIF code for pixel size units */
  144583. UINT16 X_density; /* Horizontal pixel density */
  144584. UINT16 Y_density; /* Vertical pixel density */
  144585. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144586. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144587. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144588. int max_h_samp_factor; /* largest h_samp_factor */
  144589. int max_v_samp_factor; /* largest v_samp_factor */
  144590. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144591. int comps_in_scan; /* # of JPEG components in this scan */
  144592. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144593. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144594. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144595. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144596. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144597. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144598. struct jpeg_comp_master * master;
  144599. struct jpeg_c_main_controller * main;
  144600. struct jpeg_c_prep_controller * prep;
  144601. struct jpeg_c_coef_controller * coef;
  144602. struct jpeg_marker_writer * marker;
  144603. struct jpeg_color_converter * cconvert;
  144604. struct jpeg_downsampler * downsample;
  144605. struct jpeg_forward_dct * fdct;
  144606. struct jpeg_entropy_encoder * entropy;
  144607. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144608. int script_space_size;
  144609. };
  144610. struct jpeg_decompress_struct {
  144611. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144612. struct jpeg_source_mgr * src;
  144613. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144614. JDIMENSION image_height; /* nominal image height */
  144615. int num_components; /* # of color components in JPEG image */
  144616. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144617. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144618. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144619. double output_gamma; /* image gamma wanted in output */
  144620. boolean buffered_image; /* TRUE=multiple output passes */
  144621. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144622. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144623. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144624. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144625. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144626. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144627. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144628. int desired_number_of_colors; /* max # colors to use in created colormap */
  144629. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144630. boolean enable_external_quant;/* enable future use of external colormap */
  144631. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144632. JDIMENSION output_width; /* scaled image width */
  144633. JDIMENSION output_height; /* scaled image height */
  144634. int out_color_components; /* # of color components in out_color_space */
  144635. int output_components; /* # of color components returned */
  144636. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144637. int actual_number_of_colors; /* number of entries in use */
  144638. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144639. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144640. int input_scan_number; /* Number of SOS markers seen so far */
  144641. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144642. int output_scan_number; /* Nominal scan number being displayed */
  144643. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144644. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144645. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144646. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144647. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144648. int data_precision; /* bits of precision in image data */
  144649. jpeg_component_info * comp_info;
  144650. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144651. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144652. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144653. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144654. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144655. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144656. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144657. UINT8 JFIF_major_version; /* JFIF version number */
  144658. UINT8 JFIF_minor_version;
  144659. UINT8 density_unit; /* JFIF code for pixel size units */
  144660. UINT16 X_density; /* Horizontal pixel density */
  144661. UINT16 Y_density; /* Vertical pixel density */
  144662. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144663. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144664. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144665. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144666. int max_h_samp_factor; /* largest h_samp_factor */
  144667. int max_v_samp_factor; /* largest v_samp_factor */
  144668. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144669. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144670. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144671. int comps_in_scan; /* # of JPEG components in this scan */
  144672. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144673. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144674. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144675. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144676. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144677. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144678. int unread_marker;
  144679. struct jpeg_decomp_master * master;
  144680. struct jpeg_d_main_controller * main;
  144681. struct jpeg_d_coef_controller * coef;
  144682. struct jpeg_d_post_controller * post;
  144683. struct jpeg_input_controller * inputctl;
  144684. struct jpeg_marker_reader * marker;
  144685. struct jpeg_entropy_decoder * entropy;
  144686. struct jpeg_inverse_dct * idct;
  144687. struct jpeg_upsampler * upsample;
  144688. struct jpeg_color_deconverter * cconvert;
  144689. struct jpeg_color_quantizer * cquantize;
  144690. };
  144691. struct jpeg_error_mgr {
  144692. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144693. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144694. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144695. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144696. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144697. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  144698. int msg_code;
  144699. #define JMSG_STR_PARM_MAX 80
  144700. union {
  144701. int i[8];
  144702. char s[JMSG_STR_PARM_MAX];
  144703. } msg_parm;
  144704. int trace_level; /* max msg_level that will be displayed */
  144705. long num_warnings; /* number of corrupt-data warnings */
  144706. const char * const * jpeg_message_table; /* Library errors */
  144707. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  144708. const char * const * addon_message_table; /* Non-library errors */
  144709. int first_addon_message; /* code for first string in addon table */
  144710. int last_addon_message; /* code for last string in addon table */
  144711. };
  144712. struct jpeg_progress_mgr {
  144713. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  144714. long pass_counter; /* work units completed in this pass */
  144715. long pass_limit; /* total number of work units in this pass */
  144716. int completed_passes; /* passes completed so far */
  144717. int total_passes; /* total number of passes expected */
  144718. };
  144719. struct jpeg_destination_mgr {
  144720. JOCTET * next_output_byte; /* => next byte to write in buffer */
  144721. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  144722. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  144723. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  144724. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  144725. };
  144726. struct jpeg_source_mgr {
  144727. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  144728. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  144729. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  144730. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  144731. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  144732. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  144733. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  144734. };
  144735. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  144736. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  144737. #define JPOOL_NUMPOOLS 2
  144738. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  144739. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  144740. struct jpeg_memory_mgr {
  144741. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  144742. size_t sizeofobject));
  144743. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  144744. size_t sizeofobject));
  144745. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  144746. JDIMENSION samplesperrow,
  144747. JDIMENSION numrows));
  144748. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  144749. JDIMENSION blocksperrow,
  144750. JDIMENSION numrows));
  144751. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  144752. int pool_id,
  144753. boolean pre_zero,
  144754. JDIMENSION samplesperrow,
  144755. JDIMENSION numrows,
  144756. JDIMENSION maxaccess));
  144757. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  144758. int pool_id,
  144759. boolean pre_zero,
  144760. JDIMENSION blocksperrow,
  144761. JDIMENSION numrows,
  144762. JDIMENSION maxaccess));
  144763. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  144764. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  144765. jvirt_sarray_ptr ptr,
  144766. JDIMENSION start_row,
  144767. JDIMENSION num_rows,
  144768. boolean writable));
  144769. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  144770. jvirt_barray_ptr ptr,
  144771. JDIMENSION start_row,
  144772. JDIMENSION num_rows,
  144773. boolean writable));
  144774. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  144775. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  144776. long max_memory_to_use;
  144777. long max_alloc_chunk;
  144778. };
  144779. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  144780. #ifdef HAVE_PROTOTYPES
  144781. #define JPP(arglist) arglist
  144782. #else
  144783. #define JPP(arglist) ()
  144784. #endif
  144785. #ifdef NEED_SHORT_EXTERNAL_NAMES
  144786. #define jpeg_std_error jStdError
  144787. #define jpeg_CreateCompress jCreaCompress
  144788. #define jpeg_CreateDecompress jCreaDecompress
  144789. #define jpeg_destroy_compress jDestCompress
  144790. #define jpeg_destroy_decompress jDestDecompress
  144791. #define jpeg_stdio_dest jStdDest
  144792. #define jpeg_stdio_src jStdSrc
  144793. #define jpeg_set_defaults jSetDefaults
  144794. #define jpeg_set_colorspace jSetColorspace
  144795. #define jpeg_default_colorspace jDefColorspace
  144796. #define jpeg_set_quality jSetQuality
  144797. #define jpeg_set_linear_quality jSetLQuality
  144798. #define jpeg_add_quant_table jAddQuantTable
  144799. #define jpeg_quality_scaling jQualityScaling
  144800. #define jpeg_simple_progression jSimProgress
  144801. #define jpeg_suppress_tables jSuppressTables
  144802. #define jpeg_alloc_quant_table jAlcQTable
  144803. #define jpeg_alloc_huff_table jAlcHTable
  144804. #define jpeg_start_compress jStrtCompress
  144805. #define jpeg_write_scanlines jWrtScanlines
  144806. #define jpeg_finish_compress jFinCompress
  144807. #define jpeg_write_raw_data jWrtRawData
  144808. #define jpeg_write_marker jWrtMarker
  144809. #define jpeg_write_m_header jWrtMHeader
  144810. #define jpeg_write_m_byte jWrtMByte
  144811. #define jpeg_write_tables jWrtTables
  144812. #define jpeg_read_header jReadHeader
  144813. #define jpeg_start_decompress jStrtDecompress
  144814. #define jpeg_read_scanlines jReadScanlines
  144815. #define jpeg_finish_decompress jFinDecompress
  144816. #define jpeg_read_raw_data jReadRawData
  144817. #define jpeg_has_multiple_scans jHasMultScn
  144818. #define jpeg_start_output jStrtOutput
  144819. #define jpeg_finish_output jFinOutput
  144820. #define jpeg_input_complete jInComplete
  144821. #define jpeg_new_colormap jNewCMap
  144822. #define jpeg_consume_input jConsumeInput
  144823. #define jpeg_calc_output_dimensions jCalcDimensions
  144824. #define jpeg_save_markers jSaveMarkers
  144825. #define jpeg_set_marker_processor jSetMarker
  144826. #define jpeg_read_coefficients jReadCoefs
  144827. #define jpeg_write_coefficients jWrtCoefs
  144828. #define jpeg_copy_critical_parameters jCopyCrit
  144829. #define jpeg_abort_compress jAbrtCompress
  144830. #define jpeg_abort_decompress jAbrtDecompress
  144831. #define jpeg_abort jAbort
  144832. #define jpeg_destroy jDestroy
  144833. #define jpeg_resync_to_restart jResyncRestart
  144834. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  144835. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  144836. JPP((struct jpeg_error_mgr * err));
  144837. #define jpeg_create_compress(cinfo) \
  144838. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  144839. (size_t) sizeof(struct jpeg_compress_struct))
  144840. #define jpeg_create_decompress(cinfo) \
  144841. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  144842. (size_t) sizeof(struct jpeg_decompress_struct))
  144843. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  144844. int version, size_t structsize));
  144845. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  144846. int version, size_t structsize));
  144847. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  144848. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  144849. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  144850. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  144851. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  144852. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  144853. J_COLOR_SPACE colorspace));
  144854. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  144855. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  144856. boolean force_baseline));
  144857. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  144858. int scale_factor,
  144859. boolean force_baseline));
  144860. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  144861. const unsigned int *basic_table,
  144862. int scale_factor,
  144863. boolean force_baseline));
  144864. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  144865. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  144866. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  144867. boolean suppress));
  144868. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  144869. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  144870. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  144871. boolean write_all_tables));
  144872. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  144873. JSAMPARRAY scanlines,
  144874. JDIMENSION num_lines));
  144875. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  144876. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  144877. JSAMPIMAGE data,
  144878. JDIMENSION num_lines));
  144879. EXTERN(void) jpeg_write_marker
  144880. JPP((j_compress_ptr cinfo, int marker,
  144881. const JOCTET * dataptr, unsigned int datalen));
  144882. EXTERN(void) jpeg_write_m_header
  144883. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  144884. EXTERN(void) jpeg_write_m_byte
  144885. JPP((j_compress_ptr cinfo, int val));
  144886. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  144887. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  144888. boolean require_image));
  144889. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  144890. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  144891. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  144892. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  144893. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  144894. JSAMPARRAY scanlines,
  144895. JDIMENSION max_lines));
  144896. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  144897. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  144898. JSAMPIMAGE data,
  144899. JDIMENSION max_lines));
  144900. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  144901. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  144902. int scan_number));
  144903. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  144904. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  144905. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  144906. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  144907. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  144908. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  144909. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  144910. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  144911. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  144912. EXTERN(void) jpeg_save_markers
  144913. JPP((j_decompress_ptr cinfo, int marker_code,
  144914. unsigned int length_limit));
  144915. EXTERN(void) jpeg_set_marker_processor
  144916. JPP((j_decompress_ptr cinfo, int marker_code,
  144917. jpeg_marker_parser_method routine));
  144918. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  144919. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  144920. jvirt_barray_ptr * coef_arrays));
  144921. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  144922. j_compress_ptr dstinfo));
  144923. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  144924. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  144925. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  144926. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  144927. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  144928. int desired));
  144929. #define JPEG_RST0 0xD0 /* RST0 marker code */
  144930. #define JPEG_EOI 0xD9 /* EOI marker code */
  144931. #define JPEG_APP0 0xE0 /* APP0 marker code */
  144932. #define JPEG_COM 0xFE /* COM marker code */
  144933. #ifdef INCOMPLETE_TYPES_BROKEN
  144934. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  144935. struct jvirt_sarray_control { long dummy; };
  144936. struct jvirt_barray_control { long dummy; };
  144937. struct jpeg_comp_master { long dummy; };
  144938. struct jpeg_c_main_controller { long dummy; };
  144939. struct jpeg_c_prep_controller { long dummy; };
  144940. struct jpeg_c_coef_controller { long dummy; };
  144941. struct jpeg_marker_writer { long dummy; };
  144942. struct jpeg_color_converter { long dummy; };
  144943. struct jpeg_downsampler { long dummy; };
  144944. struct jpeg_forward_dct { long dummy; };
  144945. struct jpeg_entropy_encoder { long dummy; };
  144946. struct jpeg_decomp_master { long dummy; };
  144947. struct jpeg_d_main_controller { long dummy; };
  144948. struct jpeg_d_coef_controller { long dummy; };
  144949. struct jpeg_d_post_controller { long dummy; };
  144950. struct jpeg_input_controller { long dummy; };
  144951. struct jpeg_marker_reader { long dummy; };
  144952. struct jpeg_entropy_decoder { long dummy; };
  144953. struct jpeg_inverse_dct { long dummy; };
  144954. struct jpeg_upsampler { long dummy; };
  144955. struct jpeg_color_deconverter { long dummy; };
  144956. struct jpeg_color_quantizer { long dummy; };
  144957. #endif /* JPEG_INTERNALS */
  144958. #endif /* INCOMPLETE_TYPES_BROKEN */
  144959. #ifdef JPEG_INTERNALS
  144960. /*** Start of inlined file: jpegint.h ***/
  144961. typedef enum { /* Operating modes for buffer controllers */
  144962. JBUF_PASS_THRU, /* Plain stripwise operation */
  144963. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  144964. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  144965. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  144966. } J_BUF_MODE;
  144967. #define CSTATE_START 100 /* after create_compress */
  144968. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  144969. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  144970. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  144971. #define DSTATE_START 200 /* after create_decompress */
  144972. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  144973. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  144974. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  144975. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  144976. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  144977. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  144978. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  144979. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  144980. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  144981. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  144982. struct jpeg_comp_master {
  144983. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  144984. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  144985. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  144986. boolean call_pass_startup; /* True if pass_startup must be called */
  144987. boolean is_last_pass; /* True during last pass */
  144988. };
  144989. struct jpeg_c_main_controller {
  144990. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  144991. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  144992. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  144993. JDIMENSION in_rows_avail));
  144994. };
  144995. struct jpeg_c_prep_controller {
  144996. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  144997. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  144998. JSAMPARRAY input_buf,
  144999. JDIMENSION *in_row_ctr,
  145000. JDIMENSION in_rows_avail,
  145001. JSAMPIMAGE output_buf,
  145002. JDIMENSION *out_row_group_ctr,
  145003. JDIMENSION out_row_groups_avail));
  145004. };
  145005. struct jpeg_c_coef_controller {
  145006. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145007. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145008. JSAMPIMAGE input_buf));
  145009. };
  145010. struct jpeg_color_converter {
  145011. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145012. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145013. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145014. JDIMENSION output_row, int num_rows));
  145015. };
  145016. struct jpeg_downsampler {
  145017. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145018. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145019. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145020. JSAMPIMAGE output_buf,
  145021. JDIMENSION out_row_group_index));
  145022. boolean need_context_rows; /* TRUE if need rows above & below */
  145023. };
  145024. struct jpeg_forward_dct {
  145025. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145026. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145027. jpeg_component_info * compptr,
  145028. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145029. JDIMENSION start_row, JDIMENSION start_col,
  145030. JDIMENSION num_blocks));
  145031. };
  145032. struct jpeg_entropy_encoder {
  145033. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145034. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145035. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145036. };
  145037. struct jpeg_marker_writer {
  145038. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145039. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145040. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145041. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145042. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145043. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145044. unsigned int datalen));
  145045. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145046. };
  145047. struct jpeg_decomp_master {
  145048. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145049. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145050. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145051. };
  145052. struct jpeg_input_controller {
  145053. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145054. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145055. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145056. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145057. boolean has_multiple_scans; /* True if file has multiple scans */
  145058. boolean eoi_reached; /* True when EOI has been consumed */
  145059. };
  145060. struct jpeg_d_main_controller {
  145061. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145062. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145063. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145064. JDIMENSION out_rows_avail));
  145065. };
  145066. struct jpeg_d_coef_controller {
  145067. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145068. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145069. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145070. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145071. JSAMPIMAGE output_buf));
  145072. jvirt_barray_ptr *coef_arrays;
  145073. };
  145074. struct jpeg_d_post_controller {
  145075. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145076. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145077. JSAMPIMAGE input_buf,
  145078. JDIMENSION *in_row_group_ctr,
  145079. JDIMENSION in_row_groups_avail,
  145080. JSAMPARRAY output_buf,
  145081. JDIMENSION *out_row_ctr,
  145082. JDIMENSION out_rows_avail));
  145083. };
  145084. struct jpeg_marker_reader {
  145085. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145086. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145087. jpeg_marker_parser_method read_restart_marker;
  145088. boolean saw_SOI; /* found SOI? */
  145089. boolean saw_SOF; /* found SOF? */
  145090. int next_restart_num; /* next restart number expected (0-7) */
  145091. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145092. };
  145093. struct jpeg_entropy_decoder {
  145094. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145095. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145096. JBLOCKROW *MCU_data));
  145097. boolean insufficient_data; /* set TRUE after emitting warning */
  145098. };
  145099. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145100. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145101. JCOEFPTR coef_block,
  145102. JSAMPARRAY output_buf, JDIMENSION output_col));
  145103. struct jpeg_inverse_dct {
  145104. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145105. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145106. };
  145107. struct jpeg_upsampler {
  145108. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145109. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145110. JSAMPIMAGE input_buf,
  145111. JDIMENSION *in_row_group_ctr,
  145112. JDIMENSION in_row_groups_avail,
  145113. JSAMPARRAY output_buf,
  145114. JDIMENSION *out_row_ctr,
  145115. JDIMENSION out_rows_avail));
  145116. boolean need_context_rows; /* TRUE if need rows above & below */
  145117. };
  145118. struct jpeg_color_deconverter {
  145119. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145120. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145121. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145122. JSAMPARRAY output_buf, int num_rows));
  145123. };
  145124. struct jpeg_color_quantizer {
  145125. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145126. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145127. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145128. int num_rows));
  145129. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145130. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145131. };
  145132. #undef MAX
  145133. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145134. #undef MIN
  145135. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145136. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145137. #define SHIFT_TEMPS INT32 shift_temp;
  145138. #define RIGHT_SHIFT(x,shft) \
  145139. ((shift_temp = (x)) < 0 ? \
  145140. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145141. (shift_temp >> (shft)))
  145142. #else
  145143. #define SHIFT_TEMPS
  145144. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145145. #endif
  145146. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145147. #define jinit_compress_master jICompress
  145148. #define jinit_c_master_control jICMaster
  145149. #define jinit_c_main_controller jICMainC
  145150. #define jinit_c_prep_controller jICPrepC
  145151. #define jinit_c_coef_controller jICCoefC
  145152. #define jinit_color_converter jICColor
  145153. #define jinit_downsampler jIDownsampler
  145154. #define jinit_forward_dct jIFDCT
  145155. #define jinit_huff_encoder jIHEncoder
  145156. #define jinit_phuff_encoder jIPHEncoder
  145157. #define jinit_marker_writer jIMWriter
  145158. #define jinit_master_decompress jIDMaster
  145159. #define jinit_d_main_controller jIDMainC
  145160. #define jinit_d_coef_controller jIDCoefC
  145161. #define jinit_d_post_controller jIDPostC
  145162. #define jinit_input_controller jIInCtlr
  145163. #define jinit_marker_reader jIMReader
  145164. #define jinit_huff_decoder jIHDecoder
  145165. #define jinit_phuff_decoder jIPHDecoder
  145166. #define jinit_inverse_dct jIIDCT
  145167. #define jinit_upsampler jIUpsampler
  145168. #define jinit_color_deconverter jIDColor
  145169. #define jinit_1pass_quantizer jI1Quant
  145170. #define jinit_2pass_quantizer jI2Quant
  145171. #define jinit_merged_upsampler jIMUpsampler
  145172. #define jinit_memory_mgr jIMemMgr
  145173. #define jdiv_round_up jDivRound
  145174. #define jround_up jRound
  145175. #define jcopy_sample_rows jCopySamples
  145176. #define jcopy_block_row jCopyBlocks
  145177. #define jzero_far jZeroFar
  145178. #define jpeg_zigzag_order jZIGTable
  145179. #define jpeg_natural_order jZAGTable
  145180. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145181. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145182. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145183. boolean transcode_only));
  145184. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145185. boolean need_full_buffer));
  145186. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145187. boolean need_full_buffer));
  145188. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145189. boolean need_full_buffer));
  145190. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145191. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145192. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145193. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145194. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145195. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145196. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145197. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145198. boolean need_full_buffer));
  145199. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145200. boolean need_full_buffer));
  145201. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145202. boolean need_full_buffer));
  145203. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145204. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145205. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145206. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145207. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145208. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145209. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145210. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145211. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145212. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145213. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145214. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145215. EXTERN(long) jround_up JPP((long a, long b));
  145216. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145217. JSAMPARRAY output_array, int dest_row,
  145218. int num_rows, JDIMENSION num_cols));
  145219. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145220. JDIMENSION num_blocks));
  145221. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145222. #if 0 /* This table is not actually needed in v6a */
  145223. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145224. #endif
  145225. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145226. #ifdef INCOMPLETE_TYPES_BROKEN
  145227. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145228. struct jvirt_sarray_control { long dummy; };
  145229. struct jvirt_barray_control { long dummy; };
  145230. #endif
  145231. #endif /* INCOMPLETE_TYPES_BROKEN */
  145232. /*** End of inlined file: jpegint.h ***/
  145233. /* fetch private declarations */
  145234. /*** Start of inlined file: jerror.h ***/
  145235. #ifndef JMESSAGE
  145236. #ifndef JERROR_H
  145237. #define JMAKE_ENUM_LIST
  145238. #else
  145239. #define JMESSAGE(code,string)
  145240. #endif /* JERROR_H */
  145241. #endif /* JMESSAGE */
  145242. #ifdef JMAKE_ENUM_LIST
  145243. typedef enum {
  145244. #define JMESSAGE(code,string) code ,
  145245. #endif /* JMAKE_ENUM_LIST */
  145246. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145247. JMESSAGE(JERR_ARITH_NOTIMPL,
  145248. "Sorry, there are legal restrictions on arithmetic coding")
  145249. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145250. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145251. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145252. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145253. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145254. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145255. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145256. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145257. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145258. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145259. JMESSAGE(JERR_BAD_LIB_VERSION,
  145260. "Wrong JPEG library version: library is %d, caller expects %d")
  145261. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145262. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145263. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145264. JMESSAGE(JERR_BAD_PROGRESSION,
  145265. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145266. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145267. "Invalid progressive parameters at scan script entry %d")
  145268. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145269. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145270. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145271. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145272. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145273. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145274. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145275. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145276. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145277. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145278. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145279. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145280. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145281. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145282. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145283. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145284. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145285. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145286. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145287. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145288. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145289. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145290. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145291. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145292. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145293. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145294. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145295. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145296. "Cannot transcode due to multiple use of quantization table %d")
  145297. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145298. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145299. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145300. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145301. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145302. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145303. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145304. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145305. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145306. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145307. JMESSAGE(JERR_QUANT_COMPONENTS,
  145308. "Cannot quantize more than %d color components")
  145309. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145310. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145311. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145312. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145313. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145314. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145315. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145316. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145317. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145318. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145319. JMESSAGE(JERR_TFILE_WRITE,
  145320. "Write failed on temporary file --- out of disk space?")
  145321. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145322. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145323. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145324. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145325. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145326. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145327. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145328. JMESSAGE(JMSG_VERSION, JVERSION)
  145329. JMESSAGE(JTRC_16BIT_TABLES,
  145330. "Caution: quantization tables are too coarse for baseline JPEG")
  145331. JMESSAGE(JTRC_ADOBE,
  145332. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145333. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145334. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145335. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145336. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145337. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145338. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145339. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145340. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145341. JMESSAGE(JTRC_EOI, "End Of Image")
  145342. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145343. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145344. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145345. "Warning: thumbnail image size does not match data length %u")
  145346. JMESSAGE(JTRC_JFIF_EXTENSION,
  145347. "JFIF extension marker: type 0x%02x, length %u")
  145348. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145349. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145350. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145351. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145352. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145353. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145354. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145355. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145356. JMESSAGE(JTRC_RST, "RST%d")
  145357. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145358. "Smoothing not supported with nonstandard sampling ratios")
  145359. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145360. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145361. JMESSAGE(JTRC_SOI, "Start of Image")
  145362. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145363. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145364. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145365. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145366. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145367. JMESSAGE(JTRC_THUMB_JPEG,
  145368. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145369. JMESSAGE(JTRC_THUMB_PALETTE,
  145370. "JFIF extension marker: palette thumbnail image, length %u")
  145371. JMESSAGE(JTRC_THUMB_RGB,
  145372. "JFIF extension marker: RGB thumbnail image, length %u")
  145373. JMESSAGE(JTRC_UNKNOWN_IDS,
  145374. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145375. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145376. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145377. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145378. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145379. "Inconsistent progression sequence for component %d coefficient %d")
  145380. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145381. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145382. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145383. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145384. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145385. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145386. JMESSAGE(JWRN_MUST_RESYNC,
  145387. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145388. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145389. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145390. #ifdef JMAKE_ENUM_LIST
  145391. JMSG_LASTMSGCODE
  145392. } J_MESSAGE_CODE;
  145393. #undef JMAKE_ENUM_LIST
  145394. #endif /* JMAKE_ENUM_LIST */
  145395. #undef JMESSAGE
  145396. #ifndef JERROR_H
  145397. #define JERROR_H
  145398. #define ERREXIT(cinfo,code) \
  145399. ((cinfo)->err->msg_code = (code), \
  145400. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145401. #define ERREXIT1(cinfo,code,p1) \
  145402. ((cinfo)->err->msg_code = (code), \
  145403. (cinfo)->err->msg_parm.i[0] = (p1), \
  145404. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145405. #define ERREXIT2(cinfo,code,p1,p2) \
  145406. ((cinfo)->err->msg_code = (code), \
  145407. (cinfo)->err->msg_parm.i[0] = (p1), \
  145408. (cinfo)->err->msg_parm.i[1] = (p2), \
  145409. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145410. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145411. ((cinfo)->err->msg_code = (code), \
  145412. (cinfo)->err->msg_parm.i[0] = (p1), \
  145413. (cinfo)->err->msg_parm.i[1] = (p2), \
  145414. (cinfo)->err->msg_parm.i[2] = (p3), \
  145415. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145416. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145417. ((cinfo)->err->msg_code = (code), \
  145418. (cinfo)->err->msg_parm.i[0] = (p1), \
  145419. (cinfo)->err->msg_parm.i[1] = (p2), \
  145420. (cinfo)->err->msg_parm.i[2] = (p3), \
  145421. (cinfo)->err->msg_parm.i[3] = (p4), \
  145422. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145423. #define ERREXITS(cinfo,code,str) \
  145424. ((cinfo)->err->msg_code = (code), \
  145425. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145426. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145427. #define MAKESTMT(stuff) do { stuff } while (0)
  145428. #define WARNMS(cinfo,code) \
  145429. ((cinfo)->err->msg_code = (code), \
  145430. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145431. #define WARNMS1(cinfo,code,p1) \
  145432. ((cinfo)->err->msg_code = (code), \
  145433. (cinfo)->err->msg_parm.i[0] = (p1), \
  145434. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145435. #define WARNMS2(cinfo,code,p1,p2) \
  145436. ((cinfo)->err->msg_code = (code), \
  145437. (cinfo)->err->msg_parm.i[0] = (p1), \
  145438. (cinfo)->err->msg_parm.i[1] = (p2), \
  145439. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145440. #define TRACEMS(cinfo,lvl,code) \
  145441. ((cinfo)->err->msg_code = (code), \
  145442. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145443. #define TRACEMS1(cinfo,lvl,code,p1) \
  145444. ((cinfo)->err->msg_code = (code), \
  145445. (cinfo)->err->msg_parm.i[0] = (p1), \
  145446. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145447. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145448. ((cinfo)->err->msg_code = (code), \
  145449. (cinfo)->err->msg_parm.i[0] = (p1), \
  145450. (cinfo)->err->msg_parm.i[1] = (p2), \
  145451. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145452. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145453. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145454. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145455. (cinfo)->err->msg_code = (code); \
  145456. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145457. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145458. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145459. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145460. (cinfo)->err->msg_code = (code); \
  145461. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145462. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145463. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145464. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145465. _mp[4] = (p5); \
  145466. (cinfo)->err->msg_code = (code); \
  145467. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145468. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145469. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145470. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145471. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145472. (cinfo)->err->msg_code = (code); \
  145473. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145474. #define TRACEMSS(cinfo,lvl,code,str) \
  145475. ((cinfo)->err->msg_code = (code), \
  145476. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145477. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145478. #endif /* JERROR_H */
  145479. /*** End of inlined file: jerror.h ***/
  145480. /* fetch error codes too */
  145481. #endif
  145482. #endif /* JPEGLIB_H */
  145483. /*** End of inlined file: jpeglib.h ***/
  145484. /*** Start of inlined file: jcapimin.c ***/
  145485. #define JPEG_INTERNALS
  145486. /*** Start of inlined file: jinclude.h ***/
  145487. #ifndef __jinclude_h__
  145488. #define __jinclude_h__
  145489. /*** Start of inlined file: jconfig.h ***/
  145490. // disable all the warnings under MSVC
  145491. #ifdef _MSC_VER
  145492. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145493. #endif
  145494. #ifdef __BORLANDC__
  145495. #pragma warn -8057
  145496. #pragma warn -8019
  145497. #pragma warn -8004
  145498. #pragma warn -8008
  145499. #endif
  145500. #define HAVE_PROTOTYPES
  145501. #define HAVE_UNSIGNED_CHAR
  145502. #define HAVE_UNSIGNED_SHORT
  145503. #undef CHAR_IS_UNSIGNED
  145504. #define HAVE_STDDEF_H
  145505. #define HAVE_STDLIB_H
  145506. #undef NEED_BSD_STRINGS
  145507. #undef NEED_SYS_TYPES_H
  145508. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145509. #undef NEED_SHORT_EXTERNAL_NAMES
  145510. #undef INCOMPLETE_TYPES_BROKEN
  145511. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145512. typedef unsigned char boolean;
  145513. #endif
  145514. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145515. #ifdef JPEG_INTERNALS
  145516. #undef RIGHT_SHIFT_IS_UNSIGNED
  145517. #endif /* JPEG_INTERNALS */
  145518. #ifdef JPEG_CJPEG_DJPEG
  145519. #define BMP_SUPPORTED /* BMP image file format */
  145520. #define GIF_SUPPORTED /* GIF image file format */
  145521. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145522. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145523. #define TARGA_SUPPORTED /* Targa image file format */
  145524. #define TWO_FILE_COMMANDLINE /* optional */
  145525. #define USE_SETMODE /* Microsoft has setmode() */
  145526. #undef NEED_SIGNAL_CATCHER
  145527. #undef DONT_USE_B_MODE
  145528. #undef PROGRESS_REPORT /* optional */
  145529. #endif /* JPEG_CJPEG_DJPEG */
  145530. /*** End of inlined file: jconfig.h ***/
  145531. /* auto configuration options */
  145532. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145533. #ifdef HAVE_STDDEF_H
  145534. #include <stddef.h>
  145535. #endif
  145536. #ifdef HAVE_STDLIB_H
  145537. #include <stdlib.h>
  145538. #endif
  145539. #ifdef NEED_SYS_TYPES_H
  145540. #include <sys/types.h>
  145541. #endif
  145542. #include <stdio.h>
  145543. #ifdef NEED_BSD_STRINGS
  145544. #include <strings.h>
  145545. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145546. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145547. #else /* not BSD, assume ANSI/SysV string lib */
  145548. #include <string.h>
  145549. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145550. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145551. #endif
  145552. #define SIZEOF(object) ((size_t) sizeof(object))
  145553. #define JFREAD(file,buf,sizeofbuf) \
  145554. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145555. #define JFWRITE(file,buf,sizeofbuf) \
  145556. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145557. typedef enum { /* JPEG marker codes */
  145558. M_SOF0 = 0xc0,
  145559. M_SOF1 = 0xc1,
  145560. M_SOF2 = 0xc2,
  145561. M_SOF3 = 0xc3,
  145562. M_SOF5 = 0xc5,
  145563. M_SOF6 = 0xc6,
  145564. M_SOF7 = 0xc7,
  145565. M_JPG = 0xc8,
  145566. M_SOF9 = 0xc9,
  145567. M_SOF10 = 0xca,
  145568. M_SOF11 = 0xcb,
  145569. M_SOF13 = 0xcd,
  145570. M_SOF14 = 0xce,
  145571. M_SOF15 = 0xcf,
  145572. M_DHT = 0xc4,
  145573. M_DAC = 0xcc,
  145574. M_RST0 = 0xd0,
  145575. M_RST1 = 0xd1,
  145576. M_RST2 = 0xd2,
  145577. M_RST3 = 0xd3,
  145578. M_RST4 = 0xd4,
  145579. M_RST5 = 0xd5,
  145580. M_RST6 = 0xd6,
  145581. M_RST7 = 0xd7,
  145582. M_SOI = 0xd8,
  145583. M_EOI = 0xd9,
  145584. M_SOS = 0xda,
  145585. M_DQT = 0xdb,
  145586. M_DNL = 0xdc,
  145587. M_DRI = 0xdd,
  145588. M_DHP = 0xde,
  145589. M_EXP = 0xdf,
  145590. M_APP0 = 0xe0,
  145591. M_APP1 = 0xe1,
  145592. M_APP2 = 0xe2,
  145593. M_APP3 = 0xe3,
  145594. M_APP4 = 0xe4,
  145595. M_APP5 = 0xe5,
  145596. M_APP6 = 0xe6,
  145597. M_APP7 = 0xe7,
  145598. M_APP8 = 0xe8,
  145599. M_APP9 = 0xe9,
  145600. M_APP10 = 0xea,
  145601. M_APP11 = 0xeb,
  145602. M_APP12 = 0xec,
  145603. M_APP13 = 0xed,
  145604. M_APP14 = 0xee,
  145605. M_APP15 = 0xef,
  145606. M_JPG0 = 0xf0,
  145607. M_JPG13 = 0xfd,
  145608. M_COM = 0xfe,
  145609. M_TEM = 0x01,
  145610. M_ERROR = 0x100
  145611. } JPEG_MARKER;
  145612. #ifdef AVOID_TABLES
  145613. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145614. #else
  145615. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145616. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145617. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145618. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145619. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145620. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145621. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145622. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145623. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145624. #endif /* AVOID_TABLES */
  145625. #endif
  145626. /*** End of inlined file: jinclude.h ***/
  145627. GLOBAL(void)
  145628. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145629. {
  145630. int i;
  145631. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145632. if (version != JPEG_LIB_VERSION)
  145633. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145634. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145635. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145636. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145637. {
  145638. struct jpeg_error_mgr * err = cinfo->err;
  145639. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145640. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145641. cinfo->err = err;
  145642. cinfo->client_data = client_data;
  145643. }
  145644. cinfo->is_decompressor = FALSE;
  145645. jinit_memory_mgr((j_common_ptr) cinfo);
  145646. cinfo->progress = NULL;
  145647. cinfo->dest = NULL;
  145648. cinfo->comp_info = NULL;
  145649. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145650. cinfo->quant_tbl_ptrs[i] = NULL;
  145651. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145652. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145653. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145654. }
  145655. cinfo->script_space = NULL;
  145656. cinfo->input_gamma = 1.0; /* in case application forgets */
  145657. cinfo->global_state = CSTATE_START;
  145658. }
  145659. GLOBAL(void)
  145660. jpeg_destroy_compress (j_compress_ptr cinfo)
  145661. {
  145662. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145663. }
  145664. GLOBAL(void)
  145665. jpeg_abort_compress (j_compress_ptr cinfo)
  145666. {
  145667. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145668. }
  145669. GLOBAL(void)
  145670. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145671. {
  145672. int i;
  145673. JQUANT_TBL * qtbl;
  145674. JHUFF_TBL * htbl;
  145675. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145676. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145677. qtbl->sent_table = suppress;
  145678. }
  145679. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145680. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145681. htbl->sent_table = suppress;
  145682. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145683. htbl->sent_table = suppress;
  145684. }
  145685. }
  145686. GLOBAL(void)
  145687. jpeg_finish_compress (j_compress_ptr cinfo)
  145688. {
  145689. JDIMENSION iMCU_row;
  145690. if (cinfo->global_state == CSTATE_SCANNING ||
  145691. cinfo->global_state == CSTATE_RAW_OK) {
  145692. if (cinfo->next_scanline < cinfo->image_height)
  145693. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145694. (*cinfo->master->finish_pass) (cinfo);
  145695. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145696. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145697. while (! cinfo->master->is_last_pass) {
  145698. (*cinfo->master->prepare_for_pass) (cinfo);
  145699. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  145700. if (cinfo->progress != NULL) {
  145701. cinfo->progress->pass_counter = (long) iMCU_row;
  145702. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  145703. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145704. }
  145705. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  145706. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  145707. }
  145708. (*cinfo->master->finish_pass) (cinfo);
  145709. }
  145710. (*cinfo->marker->write_file_trailer) (cinfo);
  145711. (*cinfo->dest->term_destination) (cinfo);
  145712. jpeg_abort((j_common_ptr) cinfo);
  145713. }
  145714. GLOBAL(void)
  145715. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  145716. const JOCTET *dataptr, unsigned int datalen)
  145717. {
  145718. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  145719. if (cinfo->next_scanline != 0 ||
  145720. (cinfo->global_state != CSTATE_SCANNING &&
  145721. cinfo->global_state != CSTATE_RAW_OK &&
  145722. cinfo->global_state != CSTATE_WRCOEFS))
  145723. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145724. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145725. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  145726. while (datalen--) {
  145727. (*write_marker_byte) (cinfo, *dataptr);
  145728. dataptr++;
  145729. }
  145730. }
  145731. GLOBAL(void)
  145732. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  145733. {
  145734. if (cinfo->next_scanline != 0 ||
  145735. (cinfo->global_state != CSTATE_SCANNING &&
  145736. cinfo->global_state != CSTATE_RAW_OK &&
  145737. cinfo->global_state != CSTATE_WRCOEFS))
  145738. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145739. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145740. }
  145741. GLOBAL(void)
  145742. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  145743. {
  145744. (*cinfo->marker->write_marker_byte) (cinfo, val);
  145745. }
  145746. GLOBAL(void)
  145747. jpeg_write_tables (j_compress_ptr cinfo)
  145748. {
  145749. if (cinfo->global_state != CSTATE_START)
  145750. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145751. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145752. (*cinfo->dest->init_destination) (cinfo);
  145753. jinit_marker_writer(cinfo);
  145754. (*cinfo->marker->write_tables_only) (cinfo);
  145755. (*cinfo->dest->term_destination) (cinfo);
  145756. }
  145757. /*** End of inlined file: jcapimin.c ***/
  145758. /*** Start of inlined file: jcapistd.c ***/
  145759. #define JPEG_INTERNALS
  145760. GLOBAL(void)
  145761. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  145762. {
  145763. if (cinfo->global_state != CSTATE_START)
  145764. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145765. if (write_all_tables)
  145766. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  145767. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145768. (*cinfo->dest->init_destination) (cinfo);
  145769. jinit_compress_master(cinfo);
  145770. (*cinfo->master->prepare_for_pass) (cinfo);
  145771. cinfo->next_scanline = 0;
  145772. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  145773. }
  145774. GLOBAL(JDIMENSION)
  145775. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  145776. JDIMENSION num_lines)
  145777. {
  145778. JDIMENSION row_ctr, rows_left;
  145779. if (cinfo->global_state != CSTATE_SCANNING)
  145780. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145781. if (cinfo->next_scanline >= cinfo->image_height)
  145782. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145783. if (cinfo->progress != NULL) {
  145784. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145785. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145786. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145787. }
  145788. if (cinfo->master->call_pass_startup)
  145789. (*cinfo->master->pass_startup) (cinfo);
  145790. rows_left = cinfo->image_height - cinfo->next_scanline;
  145791. if (num_lines > rows_left)
  145792. num_lines = rows_left;
  145793. row_ctr = 0;
  145794. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  145795. cinfo->next_scanline += row_ctr;
  145796. return row_ctr;
  145797. }
  145798. GLOBAL(JDIMENSION)
  145799. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  145800. JDIMENSION num_lines)
  145801. {
  145802. JDIMENSION lines_per_iMCU_row;
  145803. if (cinfo->global_state != CSTATE_RAW_OK)
  145804. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145805. if (cinfo->next_scanline >= cinfo->image_height) {
  145806. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145807. return 0;
  145808. }
  145809. if (cinfo->progress != NULL) {
  145810. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145811. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145812. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145813. }
  145814. if (cinfo->master->call_pass_startup)
  145815. (*cinfo->master->pass_startup) (cinfo);
  145816. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  145817. if (num_lines < lines_per_iMCU_row)
  145818. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  145819. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  145820. return 0;
  145821. }
  145822. cinfo->next_scanline += lines_per_iMCU_row;
  145823. return lines_per_iMCU_row;
  145824. }
  145825. /*** End of inlined file: jcapistd.c ***/
  145826. /*** Start of inlined file: jccoefct.c ***/
  145827. #define JPEG_INTERNALS
  145828. #ifdef ENTROPY_OPT_SUPPORTED
  145829. #define FULL_COEF_BUFFER_SUPPORTED
  145830. #else
  145831. #ifdef C_MULTISCAN_FILES_SUPPORTED
  145832. #define FULL_COEF_BUFFER_SUPPORTED
  145833. #endif
  145834. #endif
  145835. typedef struct {
  145836. struct jpeg_c_coef_controller pub; /* public fields */
  145837. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  145838. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  145839. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  145840. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  145841. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  145842. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  145843. } my_coef_controller;
  145844. typedef my_coef_controller * my_coef_ptr;
  145845. METHODDEF(boolean) compress_data
  145846. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145847. #ifdef FULL_COEF_BUFFER_SUPPORTED
  145848. METHODDEF(boolean) compress_first_pass
  145849. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145850. METHODDEF(boolean) compress_output
  145851. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145852. #endif
  145853. LOCAL(void)
  145854. start_iMCU_row (j_compress_ptr cinfo)
  145855. {
  145856. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145857. if (cinfo->comps_in_scan > 1) {
  145858. coef->MCU_rows_per_iMCU_row = 1;
  145859. } else {
  145860. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  145861. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  145862. else
  145863. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  145864. }
  145865. coef->mcu_ctr = 0;
  145866. coef->MCU_vert_offset = 0;
  145867. }
  145868. METHODDEF(void)
  145869. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  145870. {
  145871. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145872. coef->iMCU_row_num = 0;
  145873. start_iMCU_row(cinfo);
  145874. switch (pass_mode) {
  145875. case JBUF_PASS_THRU:
  145876. if (coef->whole_image[0] != NULL)
  145877. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145878. coef->pub.compress_data = compress_data;
  145879. break;
  145880. #ifdef FULL_COEF_BUFFER_SUPPORTED
  145881. case JBUF_SAVE_AND_PASS:
  145882. if (coef->whole_image[0] == NULL)
  145883. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145884. coef->pub.compress_data = compress_first_pass;
  145885. break;
  145886. case JBUF_CRANK_DEST:
  145887. if (coef->whole_image[0] == NULL)
  145888. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145889. coef->pub.compress_data = compress_output;
  145890. break;
  145891. #endif
  145892. default:
  145893. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145894. break;
  145895. }
  145896. }
  145897. METHODDEF(boolean)
  145898. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  145899. {
  145900. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145901. JDIMENSION MCU_col_num; /* index of current MCU within row */
  145902. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  145903. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  145904. int blkn, bi, ci, yindex, yoffset, blockcnt;
  145905. JDIMENSION ypos, xpos;
  145906. jpeg_component_info *compptr;
  145907. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  145908. yoffset++) {
  145909. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  145910. MCU_col_num++) {
  145911. blkn = 0;
  145912. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  145913. compptr = cinfo->cur_comp_info[ci];
  145914. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  145915. : compptr->last_col_width;
  145916. xpos = MCU_col_num * compptr->MCU_sample_width;
  145917. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  145918. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  145919. if (coef->iMCU_row_num < last_iMCU_row ||
  145920. yoffset+yindex < compptr->last_row_height) {
  145921. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  145922. input_buf[compptr->component_index],
  145923. coef->MCU_buffer[blkn],
  145924. ypos, xpos, (JDIMENSION) blockcnt);
  145925. if (blockcnt < compptr->MCU_width) {
  145926. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  145927. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  145928. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  145929. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  145930. }
  145931. }
  145932. } else {
  145933. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  145934. compptr->MCU_width * SIZEOF(JBLOCK));
  145935. for (bi = 0; bi < compptr->MCU_width; bi++) {
  145936. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  145937. }
  145938. }
  145939. blkn += compptr->MCU_width;
  145940. ypos += DCTSIZE;
  145941. }
  145942. }
  145943. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  145944. coef->MCU_vert_offset = yoffset;
  145945. coef->mcu_ctr = MCU_col_num;
  145946. return FALSE;
  145947. }
  145948. }
  145949. coef->mcu_ctr = 0;
  145950. }
  145951. coef->iMCU_row_num++;
  145952. start_iMCU_row(cinfo);
  145953. return TRUE;
  145954. }
  145955. #ifdef FULL_COEF_BUFFER_SUPPORTED
  145956. METHODDEF(boolean)
  145957. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  145958. {
  145959. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145960. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  145961. JDIMENSION blocks_across, MCUs_across, MCUindex;
  145962. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  145963. JCOEF lastDC;
  145964. jpeg_component_info *compptr;
  145965. JBLOCKARRAY buffer;
  145966. JBLOCKROW thisblockrow, lastblockrow;
  145967. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  145968. ci++, compptr++) {
  145969. buffer = (*cinfo->mem->access_virt_barray)
  145970. ((j_common_ptr) cinfo, coef->whole_image[ci],
  145971. coef->iMCU_row_num * compptr->v_samp_factor,
  145972. (JDIMENSION) compptr->v_samp_factor, TRUE);
  145973. if (coef->iMCU_row_num < last_iMCU_row)
  145974. block_rows = compptr->v_samp_factor;
  145975. else {
  145976. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  145977. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  145978. }
  145979. blocks_across = compptr->width_in_blocks;
  145980. h_samp_factor = compptr->h_samp_factor;
  145981. ndummy = (int) (blocks_across % h_samp_factor);
  145982. if (ndummy > 0)
  145983. ndummy = h_samp_factor - ndummy;
  145984. for (block_row = 0; block_row < block_rows; block_row++) {
  145985. thisblockrow = buffer[block_row];
  145986. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  145987. input_buf[ci], thisblockrow,
  145988. (JDIMENSION) (block_row * DCTSIZE),
  145989. (JDIMENSION) 0, blocks_across);
  145990. if (ndummy > 0) {
  145991. thisblockrow += blocks_across; /* => first dummy block */
  145992. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  145993. lastDC = thisblockrow[-1][0];
  145994. for (bi = 0; bi < ndummy; bi++) {
  145995. thisblockrow[bi][0] = lastDC;
  145996. }
  145997. }
  145998. }
  145999. if (coef->iMCU_row_num == last_iMCU_row) {
  146000. blocks_across += ndummy; /* include lower right corner */
  146001. MCUs_across = blocks_across / h_samp_factor;
  146002. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146003. block_row++) {
  146004. thisblockrow = buffer[block_row];
  146005. lastblockrow = buffer[block_row-1];
  146006. jzero_far((void FAR *) thisblockrow,
  146007. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146008. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146009. lastDC = lastblockrow[h_samp_factor-1][0];
  146010. for (bi = 0; bi < h_samp_factor; bi++) {
  146011. thisblockrow[bi][0] = lastDC;
  146012. }
  146013. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146014. lastblockrow += h_samp_factor;
  146015. }
  146016. }
  146017. }
  146018. }
  146019. return compress_output(cinfo, input_buf);
  146020. }
  146021. METHODDEF(boolean)
  146022. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146023. {
  146024. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146025. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146026. int blkn, ci, xindex, yindex, yoffset;
  146027. JDIMENSION start_col;
  146028. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146029. JBLOCKROW buffer_ptr;
  146030. jpeg_component_info *compptr;
  146031. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146032. compptr = cinfo->cur_comp_info[ci];
  146033. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146034. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146035. coef->iMCU_row_num * compptr->v_samp_factor,
  146036. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146037. }
  146038. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146039. yoffset++) {
  146040. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146041. MCU_col_num++) {
  146042. blkn = 0; /* index of current DCT block within MCU */
  146043. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146044. compptr = cinfo->cur_comp_info[ci];
  146045. start_col = MCU_col_num * compptr->MCU_width;
  146046. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146047. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146048. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146049. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146050. }
  146051. }
  146052. }
  146053. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146054. coef->MCU_vert_offset = yoffset;
  146055. coef->mcu_ctr = MCU_col_num;
  146056. return FALSE;
  146057. }
  146058. }
  146059. coef->mcu_ctr = 0;
  146060. }
  146061. coef->iMCU_row_num++;
  146062. start_iMCU_row(cinfo);
  146063. return TRUE;
  146064. }
  146065. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146066. GLOBAL(void)
  146067. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146068. {
  146069. my_coef_ptr coef;
  146070. coef = (my_coef_ptr)
  146071. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146072. SIZEOF(my_coef_controller));
  146073. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146074. coef->pub.start_pass = start_pass_coef;
  146075. if (need_full_buffer) {
  146076. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146077. int ci;
  146078. jpeg_component_info *compptr;
  146079. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146080. ci++, compptr++) {
  146081. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146082. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146083. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146084. (long) compptr->h_samp_factor),
  146085. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146086. (long) compptr->v_samp_factor),
  146087. (JDIMENSION) compptr->v_samp_factor);
  146088. }
  146089. #else
  146090. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146091. #endif
  146092. } else {
  146093. JBLOCKROW buffer;
  146094. int i;
  146095. buffer = (JBLOCKROW)
  146096. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146097. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146098. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146099. coef->MCU_buffer[i] = buffer + i;
  146100. }
  146101. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146102. }
  146103. }
  146104. /*** End of inlined file: jccoefct.c ***/
  146105. /*** Start of inlined file: jccolor.c ***/
  146106. #define JPEG_INTERNALS
  146107. typedef struct {
  146108. struct jpeg_color_converter pub; /* public fields */
  146109. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146110. } my_color_converter;
  146111. typedef my_color_converter * my_cconvert_ptr;
  146112. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146113. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146114. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146115. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146116. #define R_Y_OFF 0 /* offset to R => Y section */
  146117. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146118. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146119. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146120. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146121. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146122. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146123. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146124. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146125. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146126. METHODDEF(void)
  146127. rgb_ycc_start (j_compress_ptr cinfo)
  146128. {
  146129. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146130. INT32 * rgb_ycc_tab;
  146131. INT32 i;
  146132. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146133. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146134. (TABLE_SIZE * SIZEOF(INT32)));
  146135. for (i = 0; i <= MAXJSAMPLE; i++) {
  146136. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146137. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146138. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146139. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146140. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146141. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146142. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146143. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146144. }
  146145. }
  146146. METHODDEF(void)
  146147. rgb_ycc_convert (j_compress_ptr cinfo,
  146148. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146149. JDIMENSION output_row, int num_rows)
  146150. {
  146151. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146152. register int r, g, b;
  146153. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146154. register JSAMPROW inptr;
  146155. register JSAMPROW outptr0, outptr1, outptr2;
  146156. register JDIMENSION col;
  146157. JDIMENSION num_cols = cinfo->image_width;
  146158. while (--num_rows >= 0) {
  146159. inptr = *input_buf++;
  146160. outptr0 = output_buf[0][output_row];
  146161. outptr1 = output_buf[1][output_row];
  146162. outptr2 = output_buf[2][output_row];
  146163. output_row++;
  146164. for (col = 0; col < num_cols; col++) {
  146165. r = GETJSAMPLE(inptr[RGB_RED]);
  146166. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146167. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146168. inptr += RGB_PIXELSIZE;
  146169. outptr0[col] = (JSAMPLE)
  146170. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146171. >> SCALEBITS);
  146172. outptr1[col] = (JSAMPLE)
  146173. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146174. >> SCALEBITS);
  146175. outptr2[col] = (JSAMPLE)
  146176. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146177. >> SCALEBITS);
  146178. }
  146179. }
  146180. }
  146181. METHODDEF(void)
  146182. rgb_gray_convert (j_compress_ptr cinfo,
  146183. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146184. JDIMENSION output_row, int num_rows)
  146185. {
  146186. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146187. register int r, g, b;
  146188. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146189. register JSAMPROW inptr;
  146190. register JSAMPROW outptr;
  146191. register JDIMENSION col;
  146192. JDIMENSION num_cols = cinfo->image_width;
  146193. while (--num_rows >= 0) {
  146194. inptr = *input_buf++;
  146195. outptr = output_buf[0][output_row];
  146196. output_row++;
  146197. for (col = 0; col < num_cols; col++) {
  146198. r = GETJSAMPLE(inptr[RGB_RED]);
  146199. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146200. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146201. inptr += RGB_PIXELSIZE;
  146202. outptr[col] = (JSAMPLE)
  146203. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146204. >> SCALEBITS);
  146205. }
  146206. }
  146207. }
  146208. METHODDEF(void)
  146209. cmyk_ycck_convert (j_compress_ptr cinfo,
  146210. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146211. JDIMENSION output_row, int num_rows)
  146212. {
  146213. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146214. register int r, g, b;
  146215. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146216. register JSAMPROW inptr;
  146217. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146218. register JDIMENSION col;
  146219. JDIMENSION num_cols = cinfo->image_width;
  146220. while (--num_rows >= 0) {
  146221. inptr = *input_buf++;
  146222. outptr0 = output_buf[0][output_row];
  146223. outptr1 = output_buf[1][output_row];
  146224. outptr2 = output_buf[2][output_row];
  146225. outptr3 = output_buf[3][output_row];
  146226. output_row++;
  146227. for (col = 0; col < num_cols; col++) {
  146228. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146229. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146230. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146231. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146232. inptr += 4;
  146233. outptr0[col] = (JSAMPLE)
  146234. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146235. >> SCALEBITS);
  146236. outptr1[col] = (JSAMPLE)
  146237. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146238. >> SCALEBITS);
  146239. outptr2[col] = (JSAMPLE)
  146240. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146241. >> SCALEBITS);
  146242. }
  146243. }
  146244. }
  146245. METHODDEF(void)
  146246. grayscale_convert (j_compress_ptr cinfo,
  146247. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146248. JDIMENSION output_row, int num_rows)
  146249. {
  146250. register JSAMPROW inptr;
  146251. register JSAMPROW outptr;
  146252. register JDIMENSION col;
  146253. JDIMENSION num_cols = cinfo->image_width;
  146254. int instride = cinfo->input_components;
  146255. while (--num_rows >= 0) {
  146256. inptr = *input_buf++;
  146257. outptr = output_buf[0][output_row];
  146258. output_row++;
  146259. for (col = 0; col < num_cols; col++) {
  146260. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146261. inptr += instride;
  146262. }
  146263. }
  146264. }
  146265. METHODDEF(void)
  146266. null_convert (j_compress_ptr cinfo,
  146267. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146268. JDIMENSION output_row, int num_rows)
  146269. {
  146270. register JSAMPROW inptr;
  146271. register JSAMPROW outptr;
  146272. register JDIMENSION col;
  146273. register int ci;
  146274. int nc = cinfo->num_components;
  146275. JDIMENSION num_cols = cinfo->image_width;
  146276. while (--num_rows >= 0) {
  146277. for (ci = 0; ci < nc; ci++) {
  146278. inptr = *input_buf;
  146279. outptr = output_buf[ci][output_row];
  146280. for (col = 0; col < num_cols; col++) {
  146281. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146282. inptr += nc;
  146283. }
  146284. }
  146285. input_buf++;
  146286. output_row++;
  146287. }
  146288. }
  146289. METHODDEF(void)
  146290. null_method (j_compress_ptr cinfo)
  146291. {
  146292. }
  146293. GLOBAL(void)
  146294. jinit_color_converter (j_compress_ptr cinfo)
  146295. {
  146296. my_cconvert_ptr cconvert;
  146297. cconvert = (my_cconvert_ptr)
  146298. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146299. SIZEOF(my_color_converter));
  146300. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146301. cconvert->pub.start_pass = null_method;
  146302. switch (cinfo->in_color_space) {
  146303. case JCS_GRAYSCALE:
  146304. if (cinfo->input_components != 1)
  146305. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146306. break;
  146307. case JCS_RGB:
  146308. #if RGB_PIXELSIZE != 3
  146309. if (cinfo->input_components != RGB_PIXELSIZE)
  146310. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146311. break;
  146312. #endif /* else share code with YCbCr */
  146313. case JCS_YCbCr:
  146314. if (cinfo->input_components != 3)
  146315. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146316. break;
  146317. case JCS_CMYK:
  146318. case JCS_YCCK:
  146319. if (cinfo->input_components != 4)
  146320. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146321. break;
  146322. default: /* JCS_UNKNOWN can be anything */
  146323. if (cinfo->input_components < 1)
  146324. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146325. break;
  146326. }
  146327. switch (cinfo->jpeg_color_space) {
  146328. case JCS_GRAYSCALE:
  146329. if (cinfo->num_components != 1)
  146330. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146331. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146332. cconvert->pub.color_convert = grayscale_convert;
  146333. else if (cinfo->in_color_space == JCS_RGB) {
  146334. cconvert->pub.start_pass = rgb_ycc_start;
  146335. cconvert->pub.color_convert = rgb_gray_convert;
  146336. } else if (cinfo->in_color_space == JCS_YCbCr)
  146337. cconvert->pub.color_convert = grayscale_convert;
  146338. else
  146339. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146340. break;
  146341. case JCS_RGB:
  146342. if (cinfo->num_components != 3)
  146343. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146344. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146345. cconvert->pub.color_convert = null_convert;
  146346. else
  146347. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146348. break;
  146349. case JCS_YCbCr:
  146350. if (cinfo->num_components != 3)
  146351. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146352. if (cinfo->in_color_space == JCS_RGB) {
  146353. cconvert->pub.start_pass = rgb_ycc_start;
  146354. cconvert->pub.color_convert = rgb_ycc_convert;
  146355. } else if (cinfo->in_color_space == JCS_YCbCr)
  146356. cconvert->pub.color_convert = null_convert;
  146357. else
  146358. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146359. break;
  146360. case JCS_CMYK:
  146361. if (cinfo->num_components != 4)
  146362. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146363. if (cinfo->in_color_space == JCS_CMYK)
  146364. cconvert->pub.color_convert = null_convert;
  146365. else
  146366. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146367. break;
  146368. case JCS_YCCK:
  146369. if (cinfo->num_components != 4)
  146370. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146371. if (cinfo->in_color_space == JCS_CMYK) {
  146372. cconvert->pub.start_pass = rgb_ycc_start;
  146373. cconvert->pub.color_convert = cmyk_ycck_convert;
  146374. } else if (cinfo->in_color_space == JCS_YCCK)
  146375. cconvert->pub.color_convert = null_convert;
  146376. else
  146377. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146378. break;
  146379. default: /* allow null conversion of JCS_UNKNOWN */
  146380. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146381. cinfo->num_components != cinfo->input_components)
  146382. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146383. cconvert->pub.color_convert = null_convert;
  146384. break;
  146385. }
  146386. }
  146387. /*** End of inlined file: jccolor.c ***/
  146388. #undef FIX
  146389. /*** Start of inlined file: jcdctmgr.c ***/
  146390. #define JPEG_INTERNALS
  146391. /*** Start of inlined file: jdct.h ***/
  146392. #ifndef __jdct_h__
  146393. #define __jdct_h__
  146394. #if BITS_IN_JSAMPLE == 8
  146395. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146396. #else
  146397. typedef INT32 DCTELEM; /* must have 32 bits */
  146398. #endif
  146399. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146400. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146401. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146402. #if BITS_IN_JSAMPLE == 8
  146403. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146404. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146405. #else
  146406. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146407. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146408. #endif
  146409. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146410. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146411. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146412. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146413. #define jpeg_fdct_islow jFDislow
  146414. #define jpeg_fdct_ifast jFDifast
  146415. #define jpeg_fdct_float jFDfloat
  146416. #define jpeg_idct_islow jRDislow
  146417. #define jpeg_idct_ifast jRDifast
  146418. #define jpeg_idct_float jRDfloat
  146419. #define jpeg_idct_4x4 jRD4x4
  146420. #define jpeg_idct_2x2 jRD2x2
  146421. #define jpeg_idct_1x1 jRD1x1
  146422. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146423. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146424. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146425. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146426. EXTERN(void) jpeg_idct_islow
  146427. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146428. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146429. EXTERN(void) jpeg_idct_ifast
  146430. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146431. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146432. EXTERN(void) jpeg_idct_float
  146433. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146434. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146435. EXTERN(void) jpeg_idct_4x4
  146436. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146437. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146438. EXTERN(void) jpeg_idct_2x2
  146439. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146440. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146441. EXTERN(void) jpeg_idct_1x1
  146442. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146443. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146444. #define ONE ((INT32) 1)
  146445. #define CONST_SCALE (ONE << CONST_BITS)
  146446. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146447. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146448. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146449. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146450. #endif
  146451. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146452. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146453. #endif
  146454. #ifndef MULTIPLY16C16 /* default definition */
  146455. #define MULTIPLY16C16(var,const) ((var) * (const))
  146456. #endif
  146457. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146458. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146459. #endif
  146460. #ifndef MULTIPLY16V16 /* default definition */
  146461. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146462. #endif
  146463. #endif
  146464. /*** End of inlined file: jdct.h ***/
  146465. /* Private declarations for DCT subsystem */
  146466. typedef struct {
  146467. struct jpeg_forward_dct pub; /* public fields */
  146468. forward_DCT_method_ptr do_dct;
  146469. DCTELEM * divisors[NUM_QUANT_TBLS];
  146470. #ifdef DCT_FLOAT_SUPPORTED
  146471. float_DCT_method_ptr do_float_dct;
  146472. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146473. #endif
  146474. } my_fdct_controller;
  146475. typedef my_fdct_controller * my_fdct_ptr;
  146476. METHODDEF(void)
  146477. start_pass_fdctmgr (j_compress_ptr cinfo)
  146478. {
  146479. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146480. int ci, qtblno, i;
  146481. jpeg_component_info *compptr;
  146482. JQUANT_TBL * qtbl;
  146483. DCTELEM * dtbl;
  146484. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146485. ci++, compptr++) {
  146486. qtblno = compptr->quant_tbl_no;
  146487. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146488. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146489. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146490. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146491. switch (cinfo->dct_method) {
  146492. #ifdef DCT_ISLOW_SUPPORTED
  146493. case JDCT_ISLOW:
  146494. if (fdct->divisors[qtblno] == NULL) {
  146495. fdct->divisors[qtblno] = (DCTELEM *)
  146496. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146497. DCTSIZE2 * SIZEOF(DCTELEM));
  146498. }
  146499. dtbl = fdct->divisors[qtblno];
  146500. for (i = 0; i < DCTSIZE2; i++) {
  146501. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146502. }
  146503. break;
  146504. #endif
  146505. #ifdef DCT_IFAST_SUPPORTED
  146506. case JDCT_IFAST:
  146507. {
  146508. #define CONST_BITS 14
  146509. static const INT16 aanscales[DCTSIZE2] = {
  146510. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146511. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146512. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146513. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146514. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146515. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146516. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146517. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146518. };
  146519. SHIFT_TEMPS
  146520. if (fdct->divisors[qtblno] == NULL) {
  146521. fdct->divisors[qtblno] = (DCTELEM *)
  146522. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146523. DCTSIZE2 * SIZEOF(DCTELEM));
  146524. }
  146525. dtbl = fdct->divisors[qtblno];
  146526. for (i = 0; i < DCTSIZE2; i++) {
  146527. dtbl[i] = (DCTELEM)
  146528. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146529. (INT32) aanscales[i]),
  146530. CONST_BITS-3);
  146531. }
  146532. }
  146533. break;
  146534. #endif
  146535. #ifdef DCT_FLOAT_SUPPORTED
  146536. case JDCT_FLOAT:
  146537. {
  146538. FAST_FLOAT * fdtbl;
  146539. int row, col;
  146540. static const double aanscalefactor[DCTSIZE] = {
  146541. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146542. 1.0, 0.785694958, 0.541196100, 0.275899379
  146543. };
  146544. if (fdct->float_divisors[qtblno] == NULL) {
  146545. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146546. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146547. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146548. }
  146549. fdtbl = fdct->float_divisors[qtblno];
  146550. i = 0;
  146551. for (row = 0; row < DCTSIZE; row++) {
  146552. for (col = 0; col < DCTSIZE; col++) {
  146553. fdtbl[i] = (FAST_FLOAT)
  146554. (1.0 / (((double) qtbl->quantval[i] *
  146555. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146556. i++;
  146557. }
  146558. }
  146559. }
  146560. break;
  146561. #endif
  146562. default:
  146563. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146564. break;
  146565. }
  146566. }
  146567. }
  146568. METHODDEF(void)
  146569. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146570. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146571. JDIMENSION start_row, JDIMENSION start_col,
  146572. JDIMENSION num_blocks)
  146573. {
  146574. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146575. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146576. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146577. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146578. JDIMENSION bi;
  146579. sample_data += start_row; /* fold in the vertical offset once */
  146580. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146581. { register DCTELEM *workspaceptr;
  146582. register JSAMPROW elemptr;
  146583. register int elemr;
  146584. workspaceptr = workspace;
  146585. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146586. elemptr = sample_data[elemr] + start_col;
  146587. #if DCTSIZE == 8 /* unroll the inner loop */
  146588. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146589. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146590. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146591. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146592. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146593. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146594. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146595. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146596. #else
  146597. { register int elemc;
  146598. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146599. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146600. }
  146601. }
  146602. #endif
  146603. }
  146604. }
  146605. (*do_dct) (workspace);
  146606. { register DCTELEM temp, qval;
  146607. register int i;
  146608. register JCOEFPTR output_ptr = coef_blocks[bi];
  146609. for (i = 0; i < DCTSIZE2; i++) {
  146610. qval = divisors[i];
  146611. temp = workspace[i];
  146612. #ifdef FAST_DIVIDE
  146613. #define DIVIDE_BY(a,b) a /= b
  146614. #else
  146615. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146616. #endif
  146617. if (temp < 0) {
  146618. temp = -temp;
  146619. temp += qval>>1; /* for rounding */
  146620. DIVIDE_BY(temp, qval);
  146621. temp = -temp;
  146622. } else {
  146623. temp += qval>>1; /* for rounding */
  146624. DIVIDE_BY(temp, qval);
  146625. }
  146626. output_ptr[i] = (JCOEF) temp;
  146627. }
  146628. }
  146629. }
  146630. }
  146631. #ifdef DCT_FLOAT_SUPPORTED
  146632. METHODDEF(void)
  146633. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146634. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146635. JDIMENSION start_row, JDIMENSION start_col,
  146636. JDIMENSION num_blocks)
  146637. {
  146638. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146639. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146640. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146641. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146642. JDIMENSION bi;
  146643. sample_data += start_row; /* fold in the vertical offset once */
  146644. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146645. { register FAST_FLOAT *workspaceptr;
  146646. register JSAMPROW elemptr;
  146647. register int elemr;
  146648. workspaceptr = workspace;
  146649. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146650. elemptr = sample_data[elemr] + start_col;
  146651. #if DCTSIZE == 8 /* unroll the inner loop */
  146652. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146653. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146654. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146655. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146656. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146657. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146658. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146659. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146660. #else
  146661. { register int elemc;
  146662. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146663. *workspaceptr++ = (FAST_FLOAT)
  146664. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146665. }
  146666. }
  146667. #endif
  146668. }
  146669. }
  146670. (*do_dct) (workspace);
  146671. { register FAST_FLOAT temp;
  146672. register int i;
  146673. register JCOEFPTR output_ptr = coef_blocks[bi];
  146674. for (i = 0; i < DCTSIZE2; i++) {
  146675. temp = workspace[i] * divisors[i];
  146676. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146677. }
  146678. }
  146679. }
  146680. }
  146681. #endif /* DCT_FLOAT_SUPPORTED */
  146682. GLOBAL(void)
  146683. jinit_forward_dct (j_compress_ptr cinfo)
  146684. {
  146685. my_fdct_ptr fdct;
  146686. int i;
  146687. fdct = (my_fdct_ptr)
  146688. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146689. SIZEOF(my_fdct_controller));
  146690. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146691. fdct->pub.start_pass = start_pass_fdctmgr;
  146692. switch (cinfo->dct_method) {
  146693. #ifdef DCT_ISLOW_SUPPORTED
  146694. case JDCT_ISLOW:
  146695. fdct->pub.forward_DCT = forward_DCT;
  146696. fdct->do_dct = jpeg_fdct_islow;
  146697. break;
  146698. #endif
  146699. #ifdef DCT_IFAST_SUPPORTED
  146700. case JDCT_IFAST:
  146701. fdct->pub.forward_DCT = forward_DCT;
  146702. fdct->do_dct = jpeg_fdct_ifast;
  146703. break;
  146704. #endif
  146705. #ifdef DCT_FLOAT_SUPPORTED
  146706. case JDCT_FLOAT:
  146707. fdct->pub.forward_DCT = forward_DCT_float;
  146708. fdct->do_float_dct = jpeg_fdct_float;
  146709. break;
  146710. #endif
  146711. default:
  146712. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146713. break;
  146714. }
  146715. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146716. fdct->divisors[i] = NULL;
  146717. #ifdef DCT_FLOAT_SUPPORTED
  146718. fdct->float_divisors[i] = NULL;
  146719. #endif
  146720. }
  146721. }
  146722. /*** End of inlined file: jcdctmgr.c ***/
  146723. #undef CONST_BITS
  146724. /*** Start of inlined file: jchuff.c ***/
  146725. #define JPEG_INTERNALS
  146726. /*** Start of inlined file: jchuff.h ***/
  146727. #ifndef _jchuff_h_
  146728. #define _jchuff_h_
  146729. #if BITS_IN_JSAMPLE == 8
  146730. #define MAX_COEF_BITS 10
  146731. #else
  146732. #define MAX_COEF_BITS 14
  146733. #endif
  146734. typedef struct {
  146735. unsigned int ehufco[256]; /* code for each symbol */
  146736. char ehufsi[256]; /* length of code for each symbol */
  146737. } c_derived_tbl;
  146738. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146739. #define jpeg_make_c_derived_tbl jMkCDerived
  146740. #define jpeg_gen_optimal_table jGenOptTbl
  146741. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146742. EXTERN(void) jpeg_make_c_derived_tbl
  146743. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  146744. c_derived_tbl ** pdtbl));
  146745. EXTERN(void) jpeg_gen_optimal_table
  146746. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  146747. #endif
  146748. /*** End of inlined file: jchuff.h ***/
  146749. /* Declarations shared with jcphuff.c */
  146750. typedef struct {
  146751. INT32 put_buffer; /* current bit-accumulation buffer */
  146752. int put_bits; /* # of bits now in it */
  146753. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  146754. } savable_state;
  146755. #ifndef NO_STRUCT_ASSIGN
  146756. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  146757. #else
  146758. #if MAX_COMPS_IN_SCAN == 4
  146759. #define ASSIGN_STATE(dest,src) \
  146760. ((dest).put_buffer = (src).put_buffer, \
  146761. (dest).put_bits = (src).put_bits, \
  146762. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  146763. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  146764. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  146765. (dest).last_dc_val[3] = (src).last_dc_val[3])
  146766. #endif
  146767. #endif
  146768. typedef struct {
  146769. struct jpeg_entropy_encoder pub; /* public fields */
  146770. savable_state saved; /* Bit buffer & DC state at start of MCU */
  146771. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  146772. int next_restart_num; /* next restart number to write (0-7) */
  146773. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  146774. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  146775. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  146776. long * dc_count_ptrs[NUM_HUFF_TBLS];
  146777. long * ac_count_ptrs[NUM_HUFF_TBLS];
  146778. #endif
  146779. } huff_entropy_encoder;
  146780. typedef huff_entropy_encoder * huff_entropy_ptr;
  146781. typedef struct {
  146782. JOCTET * next_output_byte; /* => next byte to write in buffer */
  146783. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  146784. savable_state cur; /* Current bit buffer & DC state */
  146785. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  146786. } working_state;
  146787. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  146788. JBLOCKROW *MCU_data));
  146789. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  146790. #ifdef ENTROPY_OPT_SUPPORTED
  146791. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  146792. JBLOCKROW *MCU_data));
  146793. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  146794. #endif
  146795. METHODDEF(void)
  146796. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  146797. {
  146798. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  146799. int ci, dctbl, actbl;
  146800. jpeg_component_info * compptr;
  146801. if (gather_statistics) {
  146802. #ifdef ENTROPY_OPT_SUPPORTED
  146803. entropy->pub.encode_mcu = encode_mcu_gather;
  146804. entropy->pub.finish_pass = finish_pass_gather;
  146805. #else
  146806. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146807. #endif
  146808. } else {
  146809. entropy->pub.encode_mcu = encode_mcu_huff;
  146810. entropy->pub.finish_pass = finish_pass_huff;
  146811. }
  146812. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146813. compptr = cinfo->cur_comp_info[ci];
  146814. dctbl = compptr->dc_tbl_no;
  146815. actbl = compptr->ac_tbl_no;
  146816. if (gather_statistics) {
  146817. #ifdef ENTROPY_OPT_SUPPORTED
  146818. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  146819. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  146820. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  146821. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  146822. if (entropy->dc_count_ptrs[dctbl] == NULL)
  146823. entropy->dc_count_ptrs[dctbl] = (long *)
  146824. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146825. 257 * SIZEOF(long));
  146826. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  146827. if (entropy->ac_count_ptrs[actbl] == NULL)
  146828. entropy->ac_count_ptrs[actbl] = (long *)
  146829. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146830. 257 * SIZEOF(long));
  146831. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  146832. #endif
  146833. } else {
  146834. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  146835. & entropy->dc_derived_tbls[dctbl]);
  146836. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  146837. & entropy->ac_derived_tbls[actbl]);
  146838. }
  146839. entropy->saved.last_dc_val[ci] = 0;
  146840. }
  146841. entropy->saved.put_buffer = 0;
  146842. entropy->saved.put_bits = 0;
  146843. entropy->restarts_to_go = cinfo->restart_interval;
  146844. entropy->next_restart_num = 0;
  146845. }
  146846. GLOBAL(void)
  146847. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  146848. c_derived_tbl ** pdtbl)
  146849. {
  146850. JHUFF_TBL *htbl;
  146851. c_derived_tbl *dtbl;
  146852. int p, i, l, lastp, si, maxsymbol;
  146853. char huffsize[257];
  146854. unsigned int huffcode[257];
  146855. unsigned int code;
  146856. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  146857. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  146858. htbl =
  146859. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  146860. if (htbl == NULL)
  146861. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  146862. if (*pdtbl == NULL)
  146863. *pdtbl = (c_derived_tbl *)
  146864. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146865. SIZEOF(c_derived_tbl));
  146866. dtbl = *pdtbl;
  146867. p = 0;
  146868. for (l = 1; l <= 16; l++) {
  146869. i = (int) htbl->bits[l];
  146870. if (i < 0 || p + i > 256) /* protect against table overrun */
  146871. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  146872. while (i--)
  146873. huffsize[p++] = (char) l;
  146874. }
  146875. huffsize[p] = 0;
  146876. lastp = p;
  146877. code = 0;
  146878. si = huffsize[0];
  146879. p = 0;
  146880. while (huffsize[p]) {
  146881. while (((int) huffsize[p]) == si) {
  146882. huffcode[p++] = code;
  146883. code++;
  146884. }
  146885. if (((INT32) code) >= (((INT32) 1) << si))
  146886. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  146887. code <<= 1;
  146888. si++;
  146889. }
  146890. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  146891. maxsymbol = isDC ? 15 : 255;
  146892. for (p = 0; p < lastp; p++) {
  146893. i = htbl->huffval[p];
  146894. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  146895. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  146896. dtbl->ehufco[i] = huffcode[p];
  146897. dtbl->ehufsi[i] = huffsize[p];
  146898. }
  146899. }
  146900. #define emit_byte(state,val,action) \
  146901. { *(state)->next_output_byte++ = (JOCTET) (val); \
  146902. if (--(state)->free_in_buffer == 0) \
  146903. if (! dump_buffer(state)) \
  146904. { action; } }
  146905. LOCAL(boolean)
  146906. dump_buffer (working_state * state)
  146907. {
  146908. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  146909. if (! (*dest->empty_output_buffer) (state->cinfo))
  146910. return FALSE;
  146911. state->next_output_byte = dest->next_output_byte;
  146912. state->free_in_buffer = dest->free_in_buffer;
  146913. return TRUE;
  146914. }
  146915. INLINE
  146916. LOCAL(boolean)
  146917. emit_bits (working_state * state, unsigned int code, int size)
  146918. {
  146919. register INT32 put_buffer = (INT32) code;
  146920. register int put_bits = state->cur.put_bits;
  146921. if (size == 0)
  146922. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  146923. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  146924. put_bits += size; /* new number of bits in buffer */
  146925. put_buffer <<= 24 - put_bits; /* align incoming bits */
  146926. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  146927. while (put_bits >= 8) {
  146928. int c = (int) ((put_buffer >> 16) & 0xFF);
  146929. emit_byte(state, c, return FALSE);
  146930. if (c == 0xFF) { /* need to stuff a zero byte? */
  146931. emit_byte(state, 0, return FALSE);
  146932. }
  146933. put_buffer <<= 8;
  146934. put_bits -= 8;
  146935. }
  146936. state->cur.put_buffer = put_buffer; /* update state variables */
  146937. state->cur.put_bits = put_bits;
  146938. return TRUE;
  146939. }
  146940. LOCAL(boolean)
  146941. flush_bits (working_state * state)
  146942. {
  146943. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  146944. return FALSE;
  146945. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  146946. state->cur.put_bits = 0;
  146947. return TRUE;
  146948. }
  146949. LOCAL(boolean)
  146950. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  146951. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  146952. {
  146953. register int temp, temp2;
  146954. register int nbits;
  146955. register int k, r, i;
  146956. temp = temp2 = block[0] - last_dc_val;
  146957. if (temp < 0) {
  146958. temp = -temp; /* temp is abs value of input */
  146959. temp2--;
  146960. }
  146961. nbits = 0;
  146962. while (temp) {
  146963. nbits++;
  146964. temp >>= 1;
  146965. }
  146966. if (nbits > MAX_COEF_BITS+1)
  146967. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  146968. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  146969. return FALSE;
  146970. if (nbits) /* emit_bits rejects calls with size 0 */
  146971. if (! emit_bits(state, (unsigned int) temp2, nbits))
  146972. return FALSE;
  146973. r = 0; /* r = run length of zeros */
  146974. for (k = 1; k < DCTSIZE2; k++) {
  146975. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  146976. r++;
  146977. } else {
  146978. while (r > 15) {
  146979. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  146980. return FALSE;
  146981. r -= 16;
  146982. }
  146983. temp2 = temp;
  146984. if (temp < 0) {
  146985. temp = -temp; /* temp is abs value of input */
  146986. temp2--;
  146987. }
  146988. nbits = 1; /* there must be at least one 1 bit */
  146989. while ((temp >>= 1))
  146990. nbits++;
  146991. if (nbits > MAX_COEF_BITS)
  146992. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  146993. i = (r << 4) + nbits;
  146994. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  146995. return FALSE;
  146996. if (! emit_bits(state, (unsigned int) temp2, nbits))
  146997. return FALSE;
  146998. r = 0;
  146999. }
  147000. }
  147001. if (r > 0)
  147002. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147003. return FALSE;
  147004. return TRUE;
  147005. }
  147006. LOCAL(boolean)
  147007. emit_restart (working_state * state, int restart_num)
  147008. {
  147009. int ci;
  147010. if (! flush_bits(state))
  147011. return FALSE;
  147012. emit_byte(state, 0xFF, return FALSE);
  147013. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147014. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147015. state->cur.last_dc_val[ci] = 0;
  147016. return TRUE;
  147017. }
  147018. METHODDEF(boolean)
  147019. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147020. {
  147021. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147022. working_state state;
  147023. int blkn, ci;
  147024. jpeg_component_info * compptr;
  147025. state.next_output_byte = cinfo->dest->next_output_byte;
  147026. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147027. ASSIGN_STATE(state.cur, entropy->saved);
  147028. state.cinfo = cinfo;
  147029. if (cinfo->restart_interval) {
  147030. if (entropy->restarts_to_go == 0)
  147031. if (! emit_restart(&state, entropy->next_restart_num))
  147032. return FALSE;
  147033. }
  147034. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147035. ci = cinfo->MCU_membership[blkn];
  147036. compptr = cinfo->cur_comp_info[ci];
  147037. if (! encode_one_block(&state,
  147038. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147039. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147040. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147041. return FALSE;
  147042. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147043. }
  147044. cinfo->dest->next_output_byte = state.next_output_byte;
  147045. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147046. ASSIGN_STATE(entropy->saved, state.cur);
  147047. if (cinfo->restart_interval) {
  147048. if (entropy->restarts_to_go == 0) {
  147049. entropy->restarts_to_go = cinfo->restart_interval;
  147050. entropy->next_restart_num++;
  147051. entropy->next_restart_num &= 7;
  147052. }
  147053. entropy->restarts_to_go--;
  147054. }
  147055. return TRUE;
  147056. }
  147057. METHODDEF(void)
  147058. finish_pass_huff (j_compress_ptr cinfo)
  147059. {
  147060. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147061. working_state state;
  147062. state.next_output_byte = cinfo->dest->next_output_byte;
  147063. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147064. ASSIGN_STATE(state.cur, entropy->saved);
  147065. state.cinfo = cinfo;
  147066. if (! flush_bits(&state))
  147067. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147068. cinfo->dest->next_output_byte = state.next_output_byte;
  147069. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147070. ASSIGN_STATE(entropy->saved, state.cur);
  147071. }
  147072. #ifdef ENTROPY_OPT_SUPPORTED
  147073. LOCAL(void)
  147074. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147075. long dc_counts[], long ac_counts[])
  147076. {
  147077. register int temp;
  147078. register int nbits;
  147079. register int k, r;
  147080. temp = block[0] - last_dc_val;
  147081. if (temp < 0)
  147082. temp = -temp;
  147083. nbits = 0;
  147084. while (temp) {
  147085. nbits++;
  147086. temp >>= 1;
  147087. }
  147088. if (nbits > MAX_COEF_BITS+1)
  147089. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147090. dc_counts[nbits]++;
  147091. r = 0; /* r = run length of zeros */
  147092. for (k = 1; k < DCTSIZE2; k++) {
  147093. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147094. r++;
  147095. } else {
  147096. while (r > 15) {
  147097. ac_counts[0xF0]++;
  147098. r -= 16;
  147099. }
  147100. if (temp < 0)
  147101. temp = -temp;
  147102. nbits = 1; /* there must be at least one 1 bit */
  147103. while ((temp >>= 1))
  147104. nbits++;
  147105. if (nbits > MAX_COEF_BITS)
  147106. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147107. ac_counts[(r << 4) + nbits]++;
  147108. r = 0;
  147109. }
  147110. }
  147111. if (r > 0)
  147112. ac_counts[0]++;
  147113. }
  147114. METHODDEF(boolean)
  147115. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147116. {
  147117. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147118. int blkn, ci;
  147119. jpeg_component_info * compptr;
  147120. if (cinfo->restart_interval) {
  147121. if (entropy->restarts_to_go == 0) {
  147122. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147123. entropy->saved.last_dc_val[ci] = 0;
  147124. entropy->restarts_to_go = cinfo->restart_interval;
  147125. }
  147126. entropy->restarts_to_go--;
  147127. }
  147128. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147129. ci = cinfo->MCU_membership[blkn];
  147130. compptr = cinfo->cur_comp_info[ci];
  147131. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147132. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147133. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147134. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147135. }
  147136. return TRUE;
  147137. }
  147138. GLOBAL(void)
  147139. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147140. {
  147141. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147142. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147143. int codesize[257]; /* codesize[k] = code length of symbol k */
  147144. int others[257]; /* next symbol in current branch of tree */
  147145. int c1, c2;
  147146. int p, i, j;
  147147. long v;
  147148. MEMZERO(bits, SIZEOF(bits));
  147149. MEMZERO(codesize, SIZEOF(codesize));
  147150. for (i = 0; i < 257; i++)
  147151. others[i] = -1; /* init links to empty */
  147152. freq[256] = 1; /* make sure 256 has a nonzero count */
  147153. for (;;) {
  147154. c1 = -1;
  147155. v = 1000000000L;
  147156. for (i = 0; i <= 256; i++) {
  147157. if (freq[i] && freq[i] <= v) {
  147158. v = freq[i];
  147159. c1 = i;
  147160. }
  147161. }
  147162. c2 = -1;
  147163. v = 1000000000L;
  147164. for (i = 0; i <= 256; i++) {
  147165. if (freq[i] && freq[i] <= v && i != c1) {
  147166. v = freq[i];
  147167. c2 = i;
  147168. }
  147169. }
  147170. if (c2 < 0)
  147171. break;
  147172. freq[c1] += freq[c2];
  147173. freq[c2] = 0;
  147174. codesize[c1]++;
  147175. while (others[c1] >= 0) {
  147176. c1 = others[c1];
  147177. codesize[c1]++;
  147178. }
  147179. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147180. codesize[c2]++;
  147181. while (others[c2] >= 0) {
  147182. c2 = others[c2];
  147183. codesize[c2]++;
  147184. }
  147185. }
  147186. for (i = 0; i <= 256; i++) {
  147187. if (codesize[i]) {
  147188. if (codesize[i] > MAX_CLEN)
  147189. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147190. bits[codesize[i]]++;
  147191. }
  147192. }
  147193. for (i = MAX_CLEN; i > 16; i--) {
  147194. while (bits[i] > 0) {
  147195. j = i - 2; /* find length of new prefix to be used */
  147196. while (bits[j] == 0)
  147197. j--;
  147198. bits[i] -= 2; /* remove two symbols */
  147199. bits[i-1]++; /* one goes in this length */
  147200. bits[j+1] += 2; /* two new symbols in this length */
  147201. bits[j]--; /* symbol of this length is now a prefix */
  147202. }
  147203. }
  147204. while (bits[i] == 0) /* find largest codelength still in use */
  147205. i--;
  147206. bits[i]--;
  147207. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147208. p = 0;
  147209. for (i = 1; i <= MAX_CLEN; i++) {
  147210. for (j = 0; j <= 255; j++) {
  147211. if (codesize[j] == i) {
  147212. htbl->huffval[p] = (UINT8) j;
  147213. p++;
  147214. }
  147215. }
  147216. }
  147217. htbl->sent_table = FALSE;
  147218. }
  147219. METHODDEF(void)
  147220. finish_pass_gather (j_compress_ptr cinfo)
  147221. {
  147222. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147223. int ci, dctbl, actbl;
  147224. jpeg_component_info * compptr;
  147225. JHUFF_TBL **htblptr;
  147226. boolean did_dc[NUM_HUFF_TBLS];
  147227. boolean did_ac[NUM_HUFF_TBLS];
  147228. MEMZERO(did_dc, SIZEOF(did_dc));
  147229. MEMZERO(did_ac, SIZEOF(did_ac));
  147230. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147231. compptr = cinfo->cur_comp_info[ci];
  147232. dctbl = compptr->dc_tbl_no;
  147233. actbl = compptr->ac_tbl_no;
  147234. if (! did_dc[dctbl]) {
  147235. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147236. if (*htblptr == NULL)
  147237. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147238. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147239. did_dc[dctbl] = TRUE;
  147240. }
  147241. if (! did_ac[actbl]) {
  147242. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147243. if (*htblptr == NULL)
  147244. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147245. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147246. did_ac[actbl] = TRUE;
  147247. }
  147248. }
  147249. }
  147250. #endif /* ENTROPY_OPT_SUPPORTED */
  147251. GLOBAL(void)
  147252. jinit_huff_encoder (j_compress_ptr cinfo)
  147253. {
  147254. huff_entropy_ptr entropy;
  147255. int i;
  147256. entropy = (huff_entropy_ptr)
  147257. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147258. SIZEOF(huff_entropy_encoder));
  147259. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147260. entropy->pub.start_pass = start_pass_huff;
  147261. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147262. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147263. #ifdef ENTROPY_OPT_SUPPORTED
  147264. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147265. #endif
  147266. }
  147267. }
  147268. /*** End of inlined file: jchuff.c ***/
  147269. #undef emit_byte
  147270. /*** Start of inlined file: jcinit.c ***/
  147271. #define JPEG_INTERNALS
  147272. GLOBAL(void)
  147273. jinit_compress_master (j_compress_ptr cinfo)
  147274. {
  147275. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147276. if (! cinfo->raw_data_in) {
  147277. jinit_color_converter(cinfo);
  147278. jinit_downsampler(cinfo);
  147279. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147280. }
  147281. jinit_forward_dct(cinfo);
  147282. if (cinfo->arith_code) {
  147283. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147284. } else {
  147285. if (cinfo->progressive_mode) {
  147286. #ifdef C_PROGRESSIVE_SUPPORTED
  147287. jinit_phuff_encoder(cinfo);
  147288. #else
  147289. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147290. #endif
  147291. } else
  147292. jinit_huff_encoder(cinfo);
  147293. }
  147294. jinit_c_coef_controller(cinfo,
  147295. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147296. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147297. jinit_marker_writer(cinfo);
  147298. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147299. (*cinfo->marker->write_file_header) (cinfo);
  147300. }
  147301. /*** End of inlined file: jcinit.c ***/
  147302. /*** Start of inlined file: jcmainct.c ***/
  147303. #define JPEG_INTERNALS
  147304. #undef FULL_MAIN_BUFFER_SUPPORTED
  147305. typedef struct {
  147306. struct jpeg_c_main_controller pub; /* public fields */
  147307. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147308. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147309. boolean suspended; /* remember if we suspended output */
  147310. J_BUF_MODE pass_mode; /* current operating mode */
  147311. JSAMPARRAY buffer[MAX_COMPONENTS];
  147312. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147313. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147314. #endif
  147315. } my_main_controller;
  147316. typedef my_main_controller * my_main_ptr;
  147317. METHODDEF(void) process_data_simple_main
  147318. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147319. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147320. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147321. METHODDEF(void) process_data_buffer_main
  147322. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147323. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147324. #endif
  147325. METHODDEF(void)
  147326. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147327. {
  147328. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147329. if (cinfo->raw_data_in)
  147330. return;
  147331. main_->cur_iMCU_row = 0; /* initialize counters */
  147332. main_->rowgroup_ctr = 0;
  147333. main_->suspended = FALSE;
  147334. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147335. switch (pass_mode) {
  147336. case JBUF_PASS_THRU:
  147337. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147338. if (main_->whole_image[0] != NULL)
  147339. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147340. #endif
  147341. main_->pub.process_data = process_data_simple_main;
  147342. break;
  147343. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147344. case JBUF_SAVE_SOURCE:
  147345. case JBUF_CRANK_DEST:
  147346. case JBUF_SAVE_AND_PASS:
  147347. if (main_->whole_image[0] == NULL)
  147348. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147349. main_->pub.process_data = process_data_buffer_main;
  147350. break;
  147351. #endif
  147352. default:
  147353. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147354. break;
  147355. }
  147356. }
  147357. METHODDEF(void)
  147358. process_data_simple_main (j_compress_ptr cinfo,
  147359. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147360. JDIMENSION in_rows_avail)
  147361. {
  147362. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147363. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147364. if (main_->rowgroup_ctr < DCTSIZE)
  147365. (*cinfo->prep->pre_process_data) (cinfo,
  147366. input_buf, in_row_ctr, in_rows_avail,
  147367. main_->buffer, &main_->rowgroup_ctr,
  147368. (JDIMENSION) DCTSIZE);
  147369. if (main_->rowgroup_ctr != DCTSIZE)
  147370. return;
  147371. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147372. if (! main_->suspended) {
  147373. (*in_row_ctr)--;
  147374. main_->suspended = TRUE;
  147375. }
  147376. return;
  147377. }
  147378. if (main_->suspended) {
  147379. (*in_row_ctr)++;
  147380. main_->suspended = FALSE;
  147381. }
  147382. main_->rowgroup_ctr = 0;
  147383. main_->cur_iMCU_row++;
  147384. }
  147385. }
  147386. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147387. METHODDEF(void)
  147388. process_data_buffer_main (j_compress_ptr cinfo,
  147389. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147390. JDIMENSION in_rows_avail)
  147391. {
  147392. my_main_ptr main = (my_main_ptr) cinfo->main;
  147393. int ci;
  147394. jpeg_component_info *compptr;
  147395. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147396. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147397. if (main->rowgroup_ctr == 0) {
  147398. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147399. ci++, compptr++) {
  147400. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147401. ((j_common_ptr) cinfo, main->whole_image[ci],
  147402. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147403. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147404. }
  147405. if (! writing) {
  147406. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147407. main->rowgroup_ctr = DCTSIZE;
  147408. }
  147409. }
  147410. if (writing) {
  147411. (*cinfo->prep->pre_process_data) (cinfo,
  147412. input_buf, in_row_ctr, in_rows_avail,
  147413. main->buffer, &main->rowgroup_ctr,
  147414. (JDIMENSION) DCTSIZE);
  147415. if (main->rowgroup_ctr < DCTSIZE)
  147416. return;
  147417. }
  147418. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147419. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147420. if (! main->suspended) {
  147421. (*in_row_ctr)--;
  147422. main->suspended = TRUE;
  147423. }
  147424. return;
  147425. }
  147426. if (main->suspended) {
  147427. (*in_row_ctr)++;
  147428. main->suspended = FALSE;
  147429. }
  147430. }
  147431. main->rowgroup_ctr = 0;
  147432. main->cur_iMCU_row++;
  147433. }
  147434. }
  147435. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147436. GLOBAL(void)
  147437. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147438. {
  147439. my_main_ptr main_;
  147440. int ci;
  147441. jpeg_component_info *compptr;
  147442. main_ = (my_main_ptr)
  147443. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147444. SIZEOF(my_main_controller));
  147445. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147446. main_->pub.start_pass = start_pass_main;
  147447. if (cinfo->raw_data_in)
  147448. return;
  147449. if (need_full_buffer) {
  147450. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147451. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147452. ci++, compptr++) {
  147453. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147454. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147455. compptr->width_in_blocks * DCTSIZE,
  147456. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147457. (long) compptr->v_samp_factor) * DCTSIZE,
  147458. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147459. }
  147460. #else
  147461. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147462. #endif
  147463. } else {
  147464. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147465. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147466. #endif
  147467. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147468. ci++, compptr++) {
  147469. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147470. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147471. compptr->width_in_blocks * DCTSIZE,
  147472. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147473. }
  147474. }
  147475. }
  147476. /*** End of inlined file: jcmainct.c ***/
  147477. /*** Start of inlined file: jcmarker.c ***/
  147478. #define JPEG_INTERNALS
  147479. typedef struct {
  147480. struct jpeg_marker_writer pub; /* public fields */
  147481. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147482. } my_marker_writer;
  147483. typedef my_marker_writer * my_marker_ptr;
  147484. LOCAL(void)
  147485. emit_byte (j_compress_ptr cinfo, int val)
  147486. {
  147487. struct jpeg_destination_mgr * dest = cinfo->dest;
  147488. *(dest->next_output_byte)++ = (JOCTET) val;
  147489. if (--dest->free_in_buffer == 0) {
  147490. if (! (*dest->empty_output_buffer) (cinfo))
  147491. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147492. }
  147493. }
  147494. LOCAL(void)
  147495. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147496. {
  147497. emit_byte(cinfo, 0xFF);
  147498. emit_byte(cinfo, (int) mark);
  147499. }
  147500. LOCAL(void)
  147501. emit_2bytes (j_compress_ptr cinfo, int value)
  147502. {
  147503. emit_byte(cinfo, (value >> 8) & 0xFF);
  147504. emit_byte(cinfo, value & 0xFF);
  147505. }
  147506. LOCAL(int)
  147507. emit_dqt (j_compress_ptr cinfo, int index)
  147508. {
  147509. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147510. int prec;
  147511. int i;
  147512. if (qtbl == NULL)
  147513. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147514. prec = 0;
  147515. for (i = 0; i < DCTSIZE2; i++) {
  147516. if (qtbl->quantval[i] > 255)
  147517. prec = 1;
  147518. }
  147519. if (! qtbl->sent_table) {
  147520. emit_marker(cinfo, M_DQT);
  147521. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147522. emit_byte(cinfo, index + (prec<<4));
  147523. for (i = 0; i < DCTSIZE2; i++) {
  147524. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147525. if (prec)
  147526. emit_byte(cinfo, (int) (qval >> 8));
  147527. emit_byte(cinfo, (int) (qval & 0xFF));
  147528. }
  147529. qtbl->sent_table = TRUE;
  147530. }
  147531. return prec;
  147532. }
  147533. LOCAL(void)
  147534. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147535. {
  147536. JHUFF_TBL * htbl;
  147537. int length, i;
  147538. if (is_ac) {
  147539. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147540. index += 0x10; /* output index has AC bit set */
  147541. } else {
  147542. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147543. }
  147544. if (htbl == NULL)
  147545. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147546. if (! htbl->sent_table) {
  147547. emit_marker(cinfo, M_DHT);
  147548. length = 0;
  147549. for (i = 1; i <= 16; i++)
  147550. length += htbl->bits[i];
  147551. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147552. emit_byte(cinfo, index);
  147553. for (i = 1; i <= 16; i++)
  147554. emit_byte(cinfo, htbl->bits[i]);
  147555. for (i = 0; i < length; i++)
  147556. emit_byte(cinfo, htbl->huffval[i]);
  147557. htbl->sent_table = TRUE;
  147558. }
  147559. }
  147560. LOCAL(void)
  147561. emit_dac (j_compress_ptr cinfo)
  147562. {
  147563. #ifdef C_ARITH_CODING_SUPPORTED
  147564. char dc_in_use[NUM_ARITH_TBLS];
  147565. char ac_in_use[NUM_ARITH_TBLS];
  147566. int length, i;
  147567. jpeg_component_info *compptr;
  147568. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147569. dc_in_use[i] = ac_in_use[i] = 0;
  147570. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147571. compptr = cinfo->cur_comp_info[i];
  147572. dc_in_use[compptr->dc_tbl_no] = 1;
  147573. ac_in_use[compptr->ac_tbl_no] = 1;
  147574. }
  147575. length = 0;
  147576. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147577. length += dc_in_use[i] + ac_in_use[i];
  147578. emit_marker(cinfo, M_DAC);
  147579. emit_2bytes(cinfo, length*2 + 2);
  147580. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147581. if (dc_in_use[i]) {
  147582. emit_byte(cinfo, i);
  147583. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147584. }
  147585. if (ac_in_use[i]) {
  147586. emit_byte(cinfo, i + 0x10);
  147587. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147588. }
  147589. }
  147590. #endif /* C_ARITH_CODING_SUPPORTED */
  147591. }
  147592. LOCAL(void)
  147593. emit_dri (j_compress_ptr cinfo)
  147594. {
  147595. emit_marker(cinfo, M_DRI);
  147596. emit_2bytes(cinfo, 4); /* fixed length */
  147597. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147598. }
  147599. LOCAL(void)
  147600. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147601. {
  147602. int ci;
  147603. jpeg_component_info *compptr;
  147604. emit_marker(cinfo, code);
  147605. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147606. if ((long) cinfo->image_height > 65535L ||
  147607. (long) cinfo->image_width > 65535L)
  147608. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147609. emit_byte(cinfo, cinfo->data_precision);
  147610. emit_2bytes(cinfo, (int) cinfo->image_height);
  147611. emit_2bytes(cinfo, (int) cinfo->image_width);
  147612. emit_byte(cinfo, cinfo->num_components);
  147613. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147614. ci++, compptr++) {
  147615. emit_byte(cinfo, compptr->component_id);
  147616. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147617. emit_byte(cinfo, compptr->quant_tbl_no);
  147618. }
  147619. }
  147620. LOCAL(void)
  147621. emit_sos (j_compress_ptr cinfo)
  147622. {
  147623. int i, td, ta;
  147624. jpeg_component_info *compptr;
  147625. emit_marker(cinfo, M_SOS);
  147626. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147627. emit_byte(cinfo, cinfo->comps_in_scan);
  147628. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147629. compptr = cinfo->cur_comp_info[i];
  147630. emit_byte(cinfo, compptr->component_id);
  147631. td = compptr->dc_tbl_no;
  147632. ta = compptr->ac_tbl_no;
  147633. if (cinfo->progressive_mode) {
  147634. if (cinfo->Ss == 0) {
  147635. ta = 0; /* DC scan */
  147636. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147637. td = 0; /* no DC table either */
  147638. } else {
  147639. td = 0; /* AC scan */
  147640. }
  147641. }
  147642. emit_byte(cinfo, (td << 4) + ta);
  147643. }
  147644. emit_byte(cinfo, cinfo->Ss);
  147645. emit_byte(cinfo, cinfo->Se);
  147646. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147647. }
  147648. LOCAL(void)
  147649. emit_jfif_app0 (j_compress_ptr cinfo)
  147650. {
  147651. emit_marker(cinfo, M_APP0);
  147652. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147653. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147654. emit_byte(cinfo, 0x46);
  147655. emit_byte(cinfo, 0x49);
  147656. emit_byte(cinfo, 0x46);
  147657. emit_byte(cinfo, 0);
  147658. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147659. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147660. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147661. emit_2bytes(cinfo, (int) cinfo->X_density);
  147662. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147663. emit_byte(cinfo, 0); /* No thumbnail image */
  147664. emit_byte(cinfo, 0);
  147665. }
  147666. LOCAL(void)
  147667. emit_adobe_app14 (j_compress_ptr cinfo)
  147668. {
  147669. emit_marker(cinfo, M_APP14);
  147670. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147671. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147672. emit_byte(cinfo, 0x64);
  147673. emit_byte(cinfo, 0x6F);
  147674. emit_byte(cinfo, 0x62);
  147675. emit_byte(cinfo, 0x65);
  147676. emit_2bytes(cinfo, 100); /* Version */
  147677. emit_2bytes(cinfo, 0); /* Flags0 */
  147678. emit_2bytes(cinfo, 0); /* Flags1 */
  147679. switch (cinfo->jpeg_color_space) {
  147680. case JCS_YCbCr:
  147681. emit_byte(cinfo, 1); /* Color transform = 1 */
  147682. break;
  147683. case JCS_YCCK:
  147684. emit_byte(cinfo, 2); /* Color transform = 2 */
  147685. break;
  147686. default:
  147687. emit_byte(cinfo, 0); /* Color transform = 0 */
  147688. break;
  147689. }
  147690. }
  147691. METHODDEF(void)
  147692. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147693. {
  147694. if (datalen > (unsigned int) 65533) /* safety check */
  147695. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147696. emit_marker(cinfo, (JPEG_MARKER) marker);
  147697. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  147698. }
  147699. METHODDEF(void)
  147700. write_marker_byte (j_compress_ptr cinfo, int val)
  147701. {
  147702. emit_byte(cinfo, val);
  147703. }
  147704. METHODDEF(void)
  147705. write_file_header (j_compress_ptr cinfo)
  147706. {
  147707. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147708. emit_marker(cinfo, M_SOI); /* first the SOI */
  147709. marker->last_restart_interval = 0;
  147710. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  147711. emit_jfif_app0(cinfo);
  147712. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  147713. emit_adobe_app14(cinfo);
  147714. }
  147715. METHODDEF(void)
  147716. write_frame_header (j_compress_ptr cinfo)
  147717. {
  147718. int ci, prec;
  147719. boolean is_baseline;
  147720. jpeg_component_info *compptr;
  147721. prec = 0;
  147722. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147723. ci++, compptr++) {
  147724. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  147725. }
  147726. if (cinfo->arith_code || cinfo->progressive_mode ||
  147727. cinfo->data_precision != 8) {
  147728. is_baseline = FALSE;
  147729. } else {
  147730. is_baseline = TRUE;
  147731. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147732. ci++, compptr++) {
  147733. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  147734. is_baseline = FALSE;
  147735. }
  147736. if (prec && is_baseline) {
  147737. is_baseline = FALSE;
  147738. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  147739. }
  147740. }
  147741. if (cinfo->arith_code) {
  147742. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  147743. } else {
  147744. if (cinfo->progressive_mode)
  147745. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  147746. else if (is_baseline)
  147747. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  147748. else
  147749. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  147750. }
  147751. }
  147752. METHODDEF(void)
  147753. write_scan_header (j_compress_ptr cinfo)
  147754. {
  147755. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147756. int i;
  147757. jpeg_component_info *compptr;
  147758. if (cinfo->arith_code) {
  147759. emit_dac(cinfo);
  147760. } else {
  147761. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147762. compptr = cinfo->cur_comp_info[i];
  147763. if (cinfo->progressive_mode) {
  147764. if (cinfo->Ss == 0) {
  147765. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  147766. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147767. } else {
  147768. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147769. }
  147770. } else {
  147771. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147772. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147773. }
  147774. }
  147775. }
  147776. if (cinfo->restart_interval != marker->last_restart_interval) {
  147777. emit_dri(cinfo);
  147778. marker->last_restart_interval = cinfo->restart_interval;
  147779. }
  147780. emit_sos(cinfo);
  147781. }
  147782. METHODDEF(void)
  147783. write_file_trailer (j_compress_ptr cinfo)
  147784. {
  147785. emit_marker(cinfo, M_EOI);
  147786. }
  147787. METHODDEF(void)
  147788. write_tables_only (j_compress_ptr cinfo)
  147789. {
  147790. int i;
  147791. emit_marker(cinfo, M_SOI);
  147792. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147793. if (cinfo->quant_tbl_ptrs[i] != NULL)
  147794. (void) emit_dqt(cinfo, i);
  147795. }
  147796. if (! cinfo->arith_code) {
  147797. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147798. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  147799. emit_dht(cinfo, i, FALSE);
  147800. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  147801. emit_dht(cinfo, i, TRUE);
  147802. }
  147803. }
  147804. emit_marker(cinfo, M_EOI);
  147805. }
  147806. GLOBAL(void)
  147807. jinit_marker_writer (j_compress_ptr cinfo)
  147808. {
  147809. my_marker_ptr marker;
  147810. marker = (my_marker_ptr)
  147811. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147812. SIZEOF(my_marker_writer));
  147813. cinfo->marker = (struct jpeg_marker_writer *) marker;
  147814. marker->pub.write_file_header = write_file_header;
  147815. marker->pub.write_frame_header = write_frame_header;
  147816. marker->pub.write_scan_header = write_scan_header;
  147817. marker->pub.write_file_trailer = write_file_trailer;
  147818. marker->pub.write_tables_only = write_tables_only;
  147819. marker->pub.write_marker_header = write_marker_header;
  147820. marker->pub.write_marker_byte = write_marker_byte;
  147821. marker->last_restart_interval = 0;
  147822. }
  147823. /*** End of inlined file: jcmarker.c ***/
  147824. /*** Start of inlined file: jcmaster.c ***/
  147825. #define JPEG_INTERNALS
  147826. typedef enum {
  147827. main_pass, /* input data, also do first output step */
  147828. huff_opt_pass, /* Huffman code optimization pass */
  147829. output_pass /* data output pass */
  147830. } c_pass_type;
  147831. typedef struct {
  147832. struct jpeg_comp_master pub; /* public fields */
  147833. c_pass_type pass_type; /* the type of the current pass */
  147834. int pass_number; /* # of passes completed */
  147835. int total_passes; /* total # of passes needed */
  147836. int scan_number; /* current index in scan_info[] */
  147837. } my_comp_master;
  147838. typedef my_comp_master * my_master_ptr;
  147839. LOCAL(void)
  147840. initial_setup (j_compress_ptr cinfo)
  147841. {
  147842. int ci;
  147843. jpeg_component_info *compptr;
  147844. long samplesperrow;
  147845. JDIMENSION jd_samplesperrow;
  147846. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  147847. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  147848. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  147849. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  147850. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  147851. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  147852. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  147853. jd_samplesperrow = (JDIMENSION) samplesperrow;
  147854. if ((long) jd_samplesperrow != samplesperrow)
  147855. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  147856. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  147857. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  147858. if (cinfo->num_components > MAX_COMPONENTS)
  147859. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  147860. MAX_COMPONENTS);
  147861. cinfo->max_h_samp_factor = 1;
  147862. cinfo->max_v_samp_factor = 1;
  147863. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147864. ci++, compptr++) {
  147865. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  147866. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  147867. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  147868. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  147869. compptr->h_samp_factor);
  147870. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  147871. compptr->v_samp_factor);
  147872. }
  147873. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147874. ci++, compptr++) {
  147875. compptr->component_index = ci;
  147876. compptr->DCT_scaled_size = DCTSIZE;
  147877. compptr->width_in_blocks = (JDIMENSION)
  147878. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  147879. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  147880. compptr->height_in_blocks = (JDIMENSION)
  147881. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  147882. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  147883. compptr->downsampled_width = (JDIMENSION)
  147884. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  147885. (long) cinfo->max_h_samp_factor);
  147886. compptr->downsampled_height = (JDIMENSION)
  147887. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  147888. (long) cinfo->max_v_samp_factor);
  147889. compptr->component_needed = TRUE;
  147890. }
  147891. cinfo->total_iMCU_rows = (JDIMENSION)
  147892. jdiv_round_up((long) cinfo->image_height,
  147893. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  147894. }
  147895. #ifdef C_MULTISCAN_FILES_SUPPORTED
  147896. LOCAL(void)
  147897. validate_script (j_compress_ptr cinfo)
  147898. {
  147899. const jpeg_scan_info * scanptr;
  147900. int scanno, ncomps, ci, coefi, thisi;
  147901. int Ss, Se, Ah, Al;
  147902. boolean component_sent[MAX_COMPONENTS];
  147903. #ifdef C_PROGRESSIVE_SUPPORTED
  147904. int * last_bitpos_ptr;
  147905. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  147906. #endif
  147907. if (cinfo->num_scans <= 0)
  147908. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  147909. scanptr = cinfo->scan_info;
  147910. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  147911. #ifdef C_PROGRESSIVE_SUPPORTED
  147912. cinfo->progressive_mode = TRUE;
  147913. last_bitpos_ptr = & last_bitpos[0][0];
  147914. for (ci = 0; ci < cinfo->num_components; ci++)
  147915. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  147916. *last_bitpos_ptr++ = -1;
  147917. #else
  147918. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147919. #endif
  147920. } else {
  147921. cinfo->progressive_mode = FALSE;
  147922. for (ci = 0; ci < cinfo->num_components; ci++)
  147923. component_sent[ci] = FALSE;
  147924. }
  147925. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  147926. ncomps = scanptr->comps_in_scan;
  147927. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  147928. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  147929. for (ci = 0; ci < ncomps; ci++) {
  147930. thisi = scanptr->component_index[ci];
  147931. if (thisi < 0 || thisi >= cinfo->num_components)
  147932. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  147933. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  147934. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  147935. }
  147936. Ss = scanptr->Ss;
  147937. Se = scanptr->Se;
  147938. Ah = scanptr->Ah;
  147939. Al = scanptr->Al;
  147940. if (cinfo->progressive_mode) {
  147941. #ifdef C_PROGRESSIVE_SUPPORTED
  147942. #if BITS_IN_JSAMPLE == 8
  147943. #define MAX_AH_AL 10
  147944. #else
  147945. #define MAX_AH_AL 13
  147946. #endif
  147947. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  147948. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  147949. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  147950. if (Ss == 0) {
  147951. if (Se != 0) /* DC and AC together not OK */
  147952. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  147953. } else {
  147954. if (ncomps != 1) /* AC scans must be for only one component */
  147955. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  147956. }
  147957. for (ci = 0; ci < ncomps; ci++) {
  147958. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  147959. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  147960. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  147961. for (coefi = Ss; coefi <= Se; coefi++) {
  147962. if (last_bitpos_ptr[coefi] < 0) {
  147963. if (Ah != 0)
  147964. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  147965. } else {
  147966. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  147967. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  147968. }
  147969. last_bitpos_ptr[coefi] = Al;
  147970. }
  147971. }
  147972. #endif
  147973. } else {
  147974. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  147975. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  147976. for (ci = 0; ci < ncomps; ci++) {
  147977. thisi = scanptr->component_index[ci];
  147978. if (component_sent[thisi])
  147979. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  147980. component_sent[thisi] = TRUE;
  147981. }
  147982. }
  147983. }
  147984. if (cinfo->progressive_mode) {
  147985. #ifdef C_PROGRESSIVE_SUPPORTED
  147986. for (ci = 0; ci < cinfo->num_components; ci++) {
  147987. if (last_bitpos[ci][0] < 0)
  147988. ERREXIT(cinfo, JERR_MISSING_DATA);
  147989. }
  147990. #endif
  147991. } else {
  147992. for (ci = 0; ci < cinfo->num_components; ci++) {
  147993. if (! component_sent[ci])
  147994. ERREXIT(cinfo, JERR_MISSING_DATA);
  147995. }
  147996. }
  147997. }
  147998. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  147999. LOCAL(void)
  148000. select_scan_parameters (j_compress_ptr cinfo)
  148001. {
  148002. int ci;
  148003. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148004. if (cinfo->scan_info != NULL) {
  148005. my_master_ptr master = (my_master_ptr) cinfo->master;
  148006. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148007. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148008. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148009. cinfo->cur_comp_info[ci] =
  148010. &cinfo->comp_info[scanptr->component_index[ci]];
  148011. }
  148012. cinfo->Ss = scanptr->Ss;
  148013. cinfo->Se = scanptr->Se;
  148014. cinfo->Ah = scanptr->Ah;
  148015. cinfo->Al = scanptr->Al;
  148016. }
  148017. else
  148018. #endif
  148019. {
  148020. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148021. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148022. MAX_COMPS_IN_SCAN);
  148023. cinfo->comps_in_scan = cinfo->num_components;
  148024. for (ci = 0; ci < cinfo->num_components; ci++) {
  148025. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148026. }
  148027. cinfo->Ss = 0;
  148028. cinfo->Se = DCTSIZE2-1;
  148029. cinfo->Ah = 0;
  148030. cinfo->Al = 0;
  148031. }
  148032. }
  148033. LOCAL(void)
  148034. per_scan_setup (j_compress_ptr cinfo)
  148035. {
  148036. int ci, mcublks, tmp;
  148037. jpeg_component_info *compptr;
  148038. if (cinfo->comps_in_scan == 1) {
  148039. compptr = cinfo->cur_comp_info[0];
  148040. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148041. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148042. compptr->MCU_width = 1;
  148043. compptr->MCU_height = 1;
  148044. compptr->MCU_blocks = 1;
  148045. compptr->MCU_sample_width = DCTSIZE;
  148046. compptr->last_col_width = 1;
  148047. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148048. if (tmp == 0) tmp = compptr->v_samp_factor;
  148049. compptr->last_row_height = tmp;
  148050. cinfo->blocks_in_MCU = 1;
  148051. cinfo->MCU_membership[0] = 0;
  148052. } else {
  148053. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148054. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148055. MAX_COMPS_IN_SCAN);
  148056. cinfo->MCUs_per_row = (JDIMENSION)
  148057. jdiv_round_up((long) cinfo->image_width,
  148058. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148059. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148060. jdiv_round_up((long) cinfo->image_height,
  148061. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148062. cinfo->blocks_in_MCU = 0;
  148063. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148064. compptr = cinfo->cur_comp_info[ci];
  148065. compptr->MCU_width = compptr->h_samp_factor;
  148066. compptr->MCU_height = compptr->v_samp_factor;
  148067. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148068. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148069. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148070. if (tmp == 0) tmp = compptr->MCU_width;
  148071. compptr->last_col_width = tmp;
  148072. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148073. if (tmp == 0) tmp = compptr->MCU_height;
  148074. compptr->last_row_height = tmp;
  148075. mcublks = compptr->MCU_blocks;
  148076. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148077. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148078. while (mcublks-- > 0) {
  148079. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148080. }
  148081. }
  148082. }
  148083. if (cinfo->restart_in_rows > 0) {
  148084. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148085. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148086. }
  148087. }
  148088. METHODDEF(void)
  148089. prepare_for_pass (j_compress_ptr cinfo)
  148090. {
  148091. my_master_ptr master = (my_master_ptr) cinfo->master;
  148092. switch (master->pass_type) {
  148093. case main_pass:
  148094. select_scan_parameters(cinfo);
  148095. per_scan_setup(cinfo);
  148096. if (! cinfo->raw_data_in) {
  148097. (*cinfo->cconvert->start_pass) (cinfo);
  148098. (*cinfo->downsample->start_pass) (cinfo);
  148099. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148100. }
  148101. (*cinfo->fdct->start_pass) (cinfo);
  148102. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148103. (*cinfo->coef->start_pass) (cinfo,
  148104. (master->total_passes > 1 ?
  148105. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148106. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148107. if (cinfo->optimize_coding) {
  148108. master->pub.call_pass_startup = FALSE;
  148109. } else {
  148110. master->pub.call_pass_startup = TRUE;
  148111. }
  148112. break;
  148113. #ifdef ENTROPY_OPT_SUPPORTED
  148114. case huff_opt_pass:
  148115. select_scan_parameters(cinfo);
  148116. per_scan_setup(cinfo);
  148117. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148118. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148119. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148120. master->pub.call_pass_startup = FALSE;
  148121. break;
  148122. }
  148123. master->pass_type = output_pass;
  148124. master->pass_number++;
  148125. #endif
  148126. case output_pass:
  148127. if (! cinfo->optimize_coding) {
  148128. select_scan_parameters(cinfo);
  148129. per_scan_setup(cinfo);
  148130. }
  148131. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148132. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148133. if (master->scan_number == 0)
  148134. (*cinfo->marker->write_frame_header) (cinfo);
  148135. (*cinfo->marker->write_scan_header) (cinfo);
  148136. master->pub.call_pass_startup = FALSE;
  148137. break;
  148138. default:
  148139. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148140. }
  148141. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148142. if (cinfo->progress != NULL) {
  148143. cinfo->progress->completed_passes = master->pass_number;
  148144. cinfo->progress->total_passes = master->total_passes;
  148145. }
  148146. }
  148147. METHODDEF(void)
  148148. pass_startup (j_compress_ptr cinfo)
  148149. {
  148150. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148151. (*cinfo->marker->write_frame_header) (cinfo);
  148152. (*cinfo->marker->write_scan_header) (cinfo);
  148153. }
  148154. METHODDEF(void)
  148155. finish_pass_master (j_compress_ptr cinfo)
  148156. {
  148157. my_master_ptr master = (my_master_ptr) cinfo->master;
  148158. (*cinfo->entropy->finish_pass) (cinfo);
  148159. switch (master->pass_type) {
  148160. case main_pass:
  148161. master->pass_type = output_pass;
  148162. if (! cinfo->optimize_coding)
  148163. master->scan_number++;
  148164. break;
  148165. case huff_opt_pass:
  148166. master->pass_type = output_pass;
  148167. break;
  148168. case output_pass:
  148169. if (cinfo->optimize_coding)
  148170. master->pass_type = huff_opt_pass;
  148171. master->scan_number++;
  148172. break;
  148173. }
  148174. master->pass_number++;
  148175. }
  148176. GLOBAL(void)
  148177. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148178. {
  148179. my_master_ptr master;
  148180. master = (my_master_ptr)
  148181. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148182. SIZEOF(my_comp_master));
  148183. cinfo->master = (struct jpeg_comp_master *) master;
  148184. master->pub.prepare_for_pass = prepare_for_pass;
  148185. master->pub.pass_startup = pass_startup;
  148186. master->pub.finish_pass = finish_pass_master;
  148187. master->pub.is_last_pass = FALSE;
  148188. initial_setup(cinfo);
  148189. if (cinfo->scan_info != NULL) {
  148190. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148191. validate_script(cinfo);
  148192. #else
  148193. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148194. #endif
  148195. } else {
  148196. cinfo->progressive_mode = FALSE;
  148197. cinfo->num_scans = 1;
  148198. }
  148199. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148200. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148201. if (transcode_only) {
  148202. if (cinfo->optimize_coding)
  148203. master->pass_type = huff_opt_pass;
  148204. else
  148205. master->pass_type = output_pass;
  148206. } else {
  148207. master->pass_type = main_pass;
  148208. }
  148209. master->scan_number = 0;
  148210. master->pass_number = 0;
  148211. if (cinfo->optimize_coding)
  148212. master->total_passes = cinfo->num_scans * 2;
  148213. else
  148214. master->total_passes = cinfo->num_scans;
  148215. }
  148216. /*** End of inlined file: jcmaster.c ***/
  148217. /*** Start of inlined file: jcomapi.c ***/
  148218. #define JPEG_INTERNALS
  148219. GLOBAL(void)
  148220. jpeg_abort (j_common_ptr cinfo)
  148221. {
  148222. int pool;
  148223. if (cinfo->mem == NULL)
  148224. return;
  148225. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148226. (*cinfo->mem->free_pool) (cinfo, pool);
  148227. }
  148228. if (cinfo->is_decompressor) {
  148229. cinfo->global_state = DSTATE_START;
  148230. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148231. } else {
  148232. cinfo->global_state = CSTATE_START;
  148233. }
  148234. }
  148235. GLOBAL(void)
  148236. jpeg_destroy (j_common_ptr cinfo)
  148237. {
  148238. if (cinfo->mem != NULL)
  148239. (*cinfo->mem->self_destruct) (cinfo);
  148240. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148241. cinfo->global_state = 0; /* mark it destroyed */
  148242. }
  148243. GLOBAL(JQUANT_TBL *)
  148244. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148245. {
  148246. JQUANT_TBL *tbl;
  148247. tbl = (JQUANT_TBL *)
  148248. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148249. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148250. return tbl;
  148251. }
  148252. GLOBAL(JHUFF_TBL *)
  148253. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148254. {
  148255. JHUFF_TBL *tbl;
  148256. tbl = (JHUFF_TBL *)
  148257. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148258. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148259. return tbl;
  148260. }
  148261. /*** End of inlined file: jcomapi.c ***/
  148262. /*** Start of inlined file: jcparam.c ***/
  148263. #define JPEG_INTERNALS
  148264. GLOBAL(void)
  148265. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148266. const unsigned int *basic_table,
  148267. int scale_factor, boolean force_baseline)
  148268. {
  148269. JQUANT_TBL ** qtblptr;
  148270. int i;
  148271. long temp;
  148272. if (cinfo->global_state != CSTATE_START)
  148273. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148274. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148275. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148276. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148277. if (*qtblptr == NULL)
  148278. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148279. for (i = 0; i < DCTSIZE2; i++) {
  148280. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148281. if (temp <= 0L) temp = 1L;
  148282. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148283. if (force_baseline && temp > 255L)
  148284. temp = 255L; /* limit to baseline range if requested */
  148285. (*qtblptr)->quantval[i] = (UINT16) temp;
  148286. }
  148287. (*qtblptr)->sent_table = FALSE;
  148288. }
  148289. GLOBAL(void)
  148290. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148291. boolean force_baseline)
  148292. {
  148293. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148294. 16, 11, 10, 16, 24, 40, 51, 61,
  148295. 12, 12, 14, 19, 26, 58, 60, 55,
  148296. 14, 13, 16, 24, 40, 57, 69, 56,
  148297. 14, 17, 22, 29, 51, 87, 80, 62,
  148298. 18, 22, 37, 56, 68, 109, 103, 77,
  148299. 24, 35, 55, 64, 81, 104, 113, 92,
  148300. 49, 64, 78, 87, 103, 121, 120, 101,
  148301. 72, 92, 95, 98, 112, 100, 103, 99
  148302. };
  148303. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148304. 17, 18, 24, 47, 99, 99, 99, 99,
  148305. 18, 21, 26, 66, 99, 99, 99, 99,
  148306. 24, 26, 56, 99, 99, 99, 99, 99,
  148307. 47, 66, 99, 99, 99, 99, 99, 99,
  148308. 99, 99, 99, 99, 99, 99, 99, 99,
  148309. 99, 99, 99, 99, 99, 99, 99, 99,
  148310. 99, 99, 99, 99, 99, 99, 99, 99,
  148311. 99, 99, 99, 99, 99, 99, 99, 99
  148312. };
  148313. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148314. scale_factor, force_baseline);
  148315. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148316. scale_factor, force_baseline);
  148317. }
  148318. GLOBAL(int)
  148319. jpeg_quality_scaling (int quality)
  148320. {
  148321. if (quality <= 0) quality = 1;
  148322. if (quality > 100) quality = 100;
  148323. if (quality < 50)
  148324. quality = 5000 / quality;
  148325. else
  148326. quality = 200 - quality*2;
  148327. return quality;
  148328. }
  148329. GLOBAL(void)
  148330. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148331. {
  148332. quality = jpeg_quality_scaling(quality);
  148333. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148334. }
  148335. LOCAL(void)
  148336. add_huff_table (j_compress_ptr cinfo,
  148337. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148338. {
  148339. int nsymbols, len;
  148340. if (*htblptr == NULL)
  148341. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148342. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148343. nsymbols = 0;
  148344. for (len = 1; len <= 16; len++)
  148345. nsymbols += bits[len];
  148346. if (nsymbols < 1 || nsymbols > 256)
  148347. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148348. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148349. (*htblptr)->sent_table = FALSE;
  148350. }
  148351. LOCAL(void)
  148352. std_huff_tables (j_compress_ptr cinfo)
  148353. {
  148354. static const UINT8 bits_dc_luminance[17] =
  148355. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148356. static const UINT8 val_dc_luminance[] =
  148357. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148358. static const UINT8 bits_dc_chrominance[17] =
  148359. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148360. static const UINT8 val_dc_chrominance[] =
  148361. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148362. static const UINT8 bits_ac_luminance[17] =
  148363. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148364. static const UINT8 val_ac_luminance[] =
  148365. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148366. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148367. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148368. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148369. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148370. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148371. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148372. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148373. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148374. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148375. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148376. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148377. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148378. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148379. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148380. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148381. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148382. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148383. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148384. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148385. 0xf9, 0xfa };
  148386. static const UINT8 bits_ac_chrominance[17] =
  148387. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148388. static const UINT8 val_ac_chrominance[] =
  148389. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148390. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148391. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148392. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148393. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148394. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148395. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148396. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148397. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148398. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148399. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148400. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148401. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148402. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148403. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148404. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148405. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148406. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148407. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148408. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148409. 0xf9, 0xfa };
  148410. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148411. bits_dc_luminance, val_dc_luminance);
  148412. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148413. bits_ac_luminance, val_ac_luminance);
  148414. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148415. bits_dc_chrominance, val_dc_chrominance);
  148416. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148417. bits_ac_chrominance, val_ac_chrominance);
  148418. }
  148419. GLOBAL(void)
  148420. jpeg_set_defaults (j_compress_ptr cinfo)
  148421. {
  148422. int i;
  148423. if (cinfo->global_state != CSTATE_START)
  148424. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148425. if (cinfo->comp_info == NULL)
  148426. cinfo->comp_info = (jpeg_component_info *)
  148427. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148428. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148429. cinfo->data_precision = BITS_IN_JSAMPLE;
  148430. jpeg_set_quality(cinfo, 75, TRUE);
  148431. std_huff_tables(cinfo);
  148432. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148433. cinfo->arith_dc_L[i] = 0;
  148434. cinfo->arith_dc_U[i] = 1;
  148435. cinfo->arith_ac_K[i] = 5;
  148436. }
  148437. cinfo->scan_info = NULL;
  148438. cinfo->num_scans = 0;
  148439. cinfo->raw_data_in = FALSE;
  148440. cinfo->arith_code = FALSE;
  148441. cinfo->optimize_coding = FALSE;
  148442. if (cinfo->data_precision > 8)
  148443. cinfo->optimize_coding = TRUE;
  148444. cinfo->CCIR601_sampling = FALSE;
  148445. cinfo->smoothing_factor = 0;
  148446. cinfo->dct_method = JDCT_DEFAULT;
  148447. cinfo->restart_interval = 0;
  148448. cinfo->restart_in_rows = 0;
  148449. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148450. cinfo->JFIF_minor_version = 1;
  148451. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148452. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148453. cinfo->Y_density = 1;
  148454. jpeg_default_colorspace(cinfo);
  148455. }
  148456. GLOBAL(void)
  148457. jpeg_default_colorspace (j_compress_ptr cinfo)
  148458. {
  148459. switch (cinfo->in_color_space) {
  148460. case JCS_GRAYSCALE:
  148461. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148462. break;
  148463. case JCS_RGB:
  148464. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148465. break;
  148466. case JCS_YCbCr:
  148467. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148468. break;
  148469. case JCS_CMYK:
  148470. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148471. break;
  148472. case JCS_YCCK:
  148473. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148474. break;
  148475. case JCS_UNKNOWN:
  148476. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148477. break;
  148478. default:
  148479. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148480. }
  148481. }
  148482. GLOBAL(void)
  148483. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148484. {
  148485. jpeg_component_info * compptr;
  148486. int ci;
  148487. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148488. (compptr = &cinfo->comp_info[index], \
  148489. compptr->component_id = (id), \
  148490. compptr->h_samp_factor = (hsamp), \
  148491. compptr->v_samp_factor = (vsamp), \
  148492. compptr->quant_tbl_no = (quant), \
  148493. compptr->dc_tbl_no = (dctbl), \
  148494. compptr->ac_tbl_no = (actbl) )
  148495. if (cinfo->global_state != CSTATE_START)
  148496. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148497. cinfo->jpeg_color_space = colorspace;
  148498. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148499. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148500. switch (colorspace) {
  148501. case JCS_GRAYSCALE:
  148502. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148503. cinfo->num_components = 1;
  148504. SET_COMP(0, 1, 1,1, 0, 0,0);
  148505. break;
  148506. case JCS_RGB:
  148507. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148508. cinfo->num_components = 3;
  148509. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148510. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148511. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148512. break;
  148513. case JCS_YCbCr:
  148514. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148515. cinfo->num_components = 3;
  148516. SET_COMP(0, 1, 2,2, 0, 0,0);
  148517. SET_COMP(1, 2, 1,1, 1, 1,1);
  148518. SET_COMP(2, 3, 1,1, 1, 1,1);
  148519. break;
  148520. case JCS_CMYK:
  148521. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148522. cinfo->num_components = 4;
  148523. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148524. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148525. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148526. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148527. break;
  148528. case JCS_YCCK:
  148529. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148530. cinfo->num_components = 4;
  148531. SET_COMP(0, 1, 2,2, 0, 0,0);
  148532. SET_COMP(1, 2, 1,1, 1, 1,1);
  148533. SET_COMP(2, 3, 1,1, 1, 1,1);
  148534. SET_COMP(3, 4, 2,2, 0, 0,0);
  148535. break;
  148536. case JCS_UNKNOWN:
  148537. cinfo->num_components = cinfo->input_components;
  148538. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148539. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148540. MAX_COMPONENTS);
  148541. for (ci = 0; ci < cinfo->num_components; ci++) {
  148542. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148543. }
  148544. break;
  148545. default:
  148546. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148547. }
  148548. }
  148549. #ifdef C_PROGRESSIVE_SUPPORTED
  148550. LOCAL(jpeg_scan_info *)
  148551. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148552. int Ss, int Se, int Ah, int Al)
  148553. {
  148554. scanptr->comps_in_scan = 1;
  148555. scanptr->component_index[0] = ci;
  148556. scanptr->Ss = Ss;
  148557. scanptr->Se = Se;
  148558. scanptr->Ah = Ah;
  148559. scanptr->Al = Al;
  148560. scanptr++;
  148561. return scanptr;
  148562. }
  148563. LOCAL(jpeg_scan_info *)
  148564. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148565. int Ss, int Se, int Ah, int Al)
  148566. {
  148567. int ci;
  148568. for (ci = 0; ci < ncomps; ci++) {
  148569. scanptr->comps_in_scan = 1;
  148570. scanptr->component_index[0] = ci;
  148571. scanptr->Ss = Ss;
  148572. scanptr->Se = Se;
  148573. scanptr->Ah = Ah;
  148574. scanptr->Al = Al;
  148575. scanptr++;
  148576. }
  148577. return scanptr;
  148578. }
  148579. LOCAL(jpeg_scan_info *)
  148580. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148581. {
  148582. int ci;
  148583. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148584. scanptr->comps_in_scan = ncomps;
  148585. for (ci = 0; ci < ncomps; ci++)
  148586. scanptr->component_index[ci] = ci;
  148587. scanptr->Ss = scanptr->Se = 0;
  148588. scanptr->Ah = Ah;
  148589. scanptr->Al = Al;
  148590. scanptr++;
  148591. } else {
  148592. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148593. }
  148594. return scanptr;
  148595. }
  148596. GLOBAL(void)
  148597. jpeg_simple_progression (j_compress_ptr cinfo)
  148598. {
  148599. int ncomps = cinfo->num_components;
  148600. int nscans;
  148601. jpeg_scan_info * scanptr;
  148602. if (cinfo->global_state != CSTATE_START)
  148603. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148604. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148605. nscans = 10;
  148606. } else {
  148607. if (ncomps > MAX_COMPS_IN_SCAN)
  148608. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148609. else
  148610. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148611. }
  148612. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148613. cinfo->script_space_size = MAX(nscans, 10);
  148614. cinfo->script_space = (jpeg_scan_info *)
  148615. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148616. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148617. }
  148618. scanptr = cinfo->script_space;
  148619. cinfo->scan_info = scanptr;
  148620. cinfo->num_scans = nscans;
  148621. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148622. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148623. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148624. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148625. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148626. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148627. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148628. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148629. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148630. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148631. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148632. } else {
  148633. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148634. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148635. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148636. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148637. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148638. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148639. }
  148640. }
  148641. #endif /* C_PROGRESSIVE_SUPPORTED */
  148642. /*** End of inlined file: jcparam.c ***/
  148643. /*** Start of inlined file: jcphuff.c ***/
  148644. #define JPEG_INTERNALS
  148645. #ifdef C_PROGRESSIVE_SUPPORTED
  148646. typedef struct {
  148647. struct jpeg_entropy_encoder pub; /* public fields */
  148648. boolean gather_statistics;
  148649. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148650. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148651. INT32 put_buffer; /* current bit-accumulation buffer */
  148652. int put_bits; /* # of bits now in it */
  148653. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148654. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148655. int ac_tbl_no; /* the table number of the single component */
  148656. unsigned int EOBRUN; /* run length of EOBs */
  148657. unsigned int BE; /* # of buffered correction bits before MCU */
  148658. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148659. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148660. int next_restart_num; /* next restart number to write (0-7) */
  148661. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148662. long * count_ptrs[NUM_HUFF_TBLS];
  148663. } phuff_entropy_encoder;
  148664. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148665. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148666. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148667. #define ISHIFT_TEMPS int ishift_temp;
  148668. #define IRIGHT_SHIFT(x,shft) \
  148669. ((ishift_temp = (x)) < 0 ? \
  148670. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148671. (ishift_temp >> (shft)))
  148672. #else
  148673. #define ISHIFT_TEMPS
  148674. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148675. #endif
  148676. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148677. JBLOCKROW *MCU_data));
  148678. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148679. JBLOCKROW *MCU_data));
  148680. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148681. JBLOCKROW *MCU_data));
  148682. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148683. JBLOCKROW *MCU_data));
  148684. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148685. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148686. METHODDEF(void)
  148687. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148688. {
  148689. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148690. boolean is_DC_band;
  148691. int ci, tbl;
  148692. jpeg_component_info * compptr;
  148693. entropy->cinfo = cinfo;
  148694. entropy->gather_statistics = gather_statistics;
  148695. is_DC_band = (cinfo->Ss == 0);
  148696. if (cinfo->Ah == 0) {
  148697. if (is_DC_band)
  148698. entropy->pub.encode_mcu = encode_mcu_DC_first;
  148699. else
  148700. entropy->pub.encode_mcu = encode_mcu_AC_first;
  148701. } else {
  148702. if (is_DC_band)
  148703. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  148704. else {
  148705. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  148706. if (entropy->bit_buffer == NULL)
  148707. entropy->bit_buffer = (char *)
  148708. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148709. MAX_CORR_BITS * SIZEOF(char));
  148710. }
  148711. }
  148712. if (gather_statistics)
  148713. entropy->pub.finish_pass = finish_pass_gather_phuff;
  148714. else
  148715. entropy->pub.finish_pass = finish_pass_phuff;
  148716. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148717. compptr = cinfo->cur_comp_info[ci];
  148718. entropy->last_dc_val[ci] = 0;
  148719. if (is_DC_band) {
  148720. if (cinfo->Ah != 0) /* DC refinement needs no table */
  148721. continue;
  148722. tbl = compptr->dc_tbl_no;
  148723. } else {
  148724. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  148725. }
  148726. if (gather_statistics) {
  148727. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  148728. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  148729. if (entropy->count_ptrs[tbl] == NULL)
  148730. entropy->count_ptrs[tbl] = (long *)
  148731. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148732. 257 * SIZEOF(long));
  148733. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  148734. } else {
  148735. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  148736. & entropy->derived_tbls[tbl]);
  148737. }
  148738. }
  148739. entropy->EOBRUN = 0;
  148740. entropy->BE = 0;
  148741. entropy->put_buffer = 0;
  148742. entropy->put_bits = 0;
  148743. entropy->restarts_to_go = cinfo->restart_interval;
  148744. entropy->next_restart_num = 0;
  148745. }
  148746. #define emit_byte(entropy,val) \
  148747. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  148748. if (--(entropy)->free_in_buffer == 0) \
  148749. dump_buffer_p(entropy); }
  148750. LOCAL(void)
  148751. dump_buffer_p (phuff_entropy_ptr entropy)
  148752. {
  148753. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  148754. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  148755. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  148756. entropy->next_output_byte = dest->next_output_byte;
  148757. entropy->free_in_buffer = dest->free_in_buffer;
  148758. }
  148759. INLINE
  148760. LOCAL(void)
  148761. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  148762. {
  148763. register INT32 put_buffer = (INT32) code;
  148764. register int put_bits = entropy->put_bits;
  148765. if (size == 0)
  148766. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148767. if (entropy->gather_statistics)
  148768. return; /* do nothing if we're only getting stats */
  148769. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  148770. put_bits += size; /* new number of bits in buffer */
  148771. put_buffer <<= 24 - put_bits; /* align incoming bits */
  148772. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  148773. while (put_bits >= 8) {
  148774. int c = (int) ((put_buffer >> 16) & 0xFF);
  148775. emit_byte(entropy, c);
  148776. if (c == 0xFF) { /* need to stuff a zero byte? */
  148777. emit_byte(entropy, 0);
  148778. }
  148779. put_buffer <<= 8;
  148780. put_bits -= 8;
  148781. }
  148782. entropy->put_buffer = put_buffer; /* update variables */
  148783. entropy->put_bits = put_bits;
  148784. }
  148785. LOCAL(void)
  148786. flush_bits_p (phuff_entropy_ptr entropy)
  148787. {
  148788. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  148789. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  148790. entropy->put_bits = 0;
  148791. }
  148792. INLINE
  148793. LOCAL(void)
  148794. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  148795. {
  148796. if (entropy->gather_statistics)
  148797. entropy->count_ptrs[tbl_no][symbol]++;
  148798. else {
  148799. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  148800. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  148801. }
  148802. }
  148803. LOCAL(void)
  148804. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  148805. unsigned int nbits)
  148806. {
  148807. if (entropy->gather_statistics)
  148808. return; /* no real work */
  148809. while (nbits > 0) {
  148810. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  148811. bufstart++;
  148812. nbits--;
  148813. }
  148814. }
  148815. LOCAL(void)
  148816. emit_eobrun (phuff_entropy_ptr entropy)
  148817. {
  148818. register int temp, nbits;
  148819. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  148820. temp = entropy->EOBRUN;
  148821. nbits = 0;
  148822. while ((temp >>= 1))
  148823. nbits++;
  148824. if (nbits > 14)
  148825. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148826. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  148827. if (nbits)
  148828. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  148829. entropy->EOBRUN = 0;
  148830. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  148831. entropy->BE = 0;
  148832. }
  148833. }
  148834. LOCAL(void)
  148835. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  148836. {
  148837. int ci;
  148838. emit_eobrun(entropy);
  148839. if (! entropy->gather_statistics) {
  148840. flush_bits_p(entropy);
  148841. emit_byte(entropy, 0xFF);
  148842. emit_byte(entropy, JPEG_RST0 + restart_num);
  148843. }
  148844. if (entropy->cinfo->Ss == 0) {
  148845. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  148846. entropy->last_dc_val[ci] = 0;
  148847. } else {
  148848. entropy->EOBRUN = 0;
  148849. entropy->BE = 0;
  148850. }
  148851. }
  148852. METHODDEF(boolean)
  148853. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148854. {
  148855. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148856. register int temp, temp2;
  148857. register int nbits;
  148858. int blkn, ci;
  148859. int Al = cinfo->Al;
  148860. JBLOCKROW block;
  148861. jpeg_component_info * compptr;
  148862. ISHIFT_TEMPS
  148863. entropy->next_output_byte = cinfo->dest->next_output_byte;
  148864. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  148865. if (cinfo->restart_interval)
  148866. if (entropy->restarts_to_go == 0)
  148867. emit_restart_p(entropy, entropy->next_restart_num);
  148868. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  148869. block = MCU_data[blkn];
  148870. ci = cinfo->MCU_membership[blkn];
  148871. compptr = cinfo->cur_comp_info[ci];
  148872. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  148873. temp = temp2 - entropy->last_dc_val[ci];
  148874. entropy->last_dc_val[ci] = temp2;
  148875. temp2 = temp;
  148876. if (temp < 0) {
  148877. temp = -temp; /* temp is abs value of input */
  148878. temp2--;
  148879. }
  148880. nbits = 0;
  148881. while (temp) {
  148882. nbits++;
  148883. temp >>= 1;
  148884. }
  148885. if (nbits > MAX_COEF_BITS+1)
  148886. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  148887. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  148888. if (nbits) /* emit_bits rejects calls with size 0 */
  148889. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  148890. }
  148891. cinfo->dest->next_output_byte = entropy->next_output_byte;
  148892. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  148893. if (cinfo->restart_interval) {
  148894. if (entropy->restarts_to_go == 0) {
  148895. entropy->restarts_to_go = cinfo->restart_interval;
  148896. entropy->next_restart_num++;
  148897. entropy->next_restart_num &= 7;
  148898. }
  148899. entropy->restarts_to_go--;
  148900. }
  148901. return TRUE;
  148902. }
  148903. METHODDEF(boolean)
  148904. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148905. {
  148906. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148907. register int temp, temp2;
  148908. register int nbits;
  148909. register int r, k;
  148910. int Se = cinfo->Se;
  148911. int Al = cinfo->Al;
  148912. JBLOCKROW block;
  148913. entropy->next_output_byte = cinfo->dest->next_output_byte;
  148914. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  148915. if (cinfo->restart_interval)
  148916. if (entropy->restarts_to_go == 0)
  148917. emit_restart_p(entropy, entropy->next_restart_num);
  148918. block = MCU_data[0];
  148919. r = 0; /* r = run length of zeros */
  148920. for (k = cinfo->Ss; k <= Se; k++) {
  148921. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  148922. r++;
  148923. continue;
  148924. }
  148925. if (temp < 0) {
  148926. temp = -temp; /* temp is abs value of input */
  148927. temp >>= Al; /* apply the point transform */
  148928. temp2 = ~temp;
  148929. } else {
  148930. temp >>= Al; /* apply the point transform */
  148931. temp2 = temp;
  148932. }
  148933. if (temp == 0) {
  148934. r++;
  148935. continue;
  148936. }
  148937. if (entropy->EOBRUN > 0)
  148938. emit_eobrun(entropy);
  148939. while (r > 15) {
  148940. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  148941. r -= 16;
  148942. }
  148943. nbits = 1; /* there must be at least one 1 bit */
  148944. while ((temp >>= 1))
  148945. nbits++;
  148946. if (nbits > MAX_COEF_BITS)
  148947. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  148948. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  148949. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  148950. r = 0; /* reset zero run length */
  148951. }
  148952. if (r > 0) { /* If there are trailing zeroes, */
  148953. entropy->EOBRUN++; /* count an EOB */
  148954. if (entropy->EOBRUN == 0x7FFF)
  148955. emit_eobrun(entropy); /* force it out to avoid overflow */
  148956. }
  148957. cinfo->dest->next_output_byte = entropy->next_output_byte;
  148958. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  148959. if (cinfo->restart_interval) {
  148960. if (entropy->restarts_to_go == 0) {
  148961. entropy->restarts_to_go = cinfo->restart_interval;
  148962. entropy->next_restart_num++;
  148963. entropy->next_restart_num &= 7;
  148964. }
  148965. entropy->restarts_to_go--;
  148966. }
  148967. return TRUE;
  148968. }
  148969. METHODDEF(boolean)
  148970. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148971. {
  148972. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148973. register int temp;
  148974. int blkn;
  148975. int Al = cinfo->Al;
  148976. JBLOCKROW block;
  148977. entropy->next_output_byte = cinfo->dest->next_output_byte;
  148978. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  148979. if (cinfo->restart_interval)
  148980. if (entropy->restarts_to_go == 0)
  148981. emit_restart_p(entropy, entropy->next_restart_num);
  148982. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  148983. block = MCU_data[blkn];
  148984. temp = (*block)[0];
  148985. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  148986. }
  148987. cinfo->dest->next_output_byte = entropy->next_output_byte;
  148988. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  148989. if (cinfo->restart_interval) {
  148990. if (entropy->restarts_to_go == 0) {
  148991. entropy->restarts_to_go = cinfo->restart_interval;
  148992. entropy->next_restart_num++;
  148993. entropy->next_restart_num &= 7;
  148994. }
  148995. entropy->restarts_to_go--;
  148996. }
  148997. return TRUE;
  148998. }
  148999. METHODDEF(boolean)
  149000. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149001. {
  149002. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149003. register int temp;
  149004. register int r, k;
  149005. int EOB;
  149006. char *BR_buffer;
  149007. unsigned int BR;
  149008. int Se = cinfo->Se;
  149009. int Al = cinfo->Al;
  149010. JBLOCKROW block;
  149011. int absvalues[DCTSIZE2];
  149012. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149013. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149014. if (cinfo->restart_interval)
  149015. if (entropy->restarts_to_go == 0)
  149016. emit_restart_p(entropy, entropy->next_restart_num);
  149017. block = MCU_data[0];
  149018. EOB = 0;
  149019. for (k = cinfo->Ss; k <= Se; k++) {
  149020. temp = (*block)[jpeg_natural_order[k]];
  149021. if (temp < 0)
  149022. temp = -temp; /* temp is abs value of input */
  149023. temp >>= Al; /* apply the point transform */
  149024. absvalues[k] = temp; /* save abs value for main pass */
  149025. if (temp == 1)
  149026. EOB = k; /* EOB = index of last newly-nonzero coef */
  149027. }
  149028. r = 0; /* r = run length of zeros */
  149029. BR = 0; /* BR = count of buffered bits added now */
  149030. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149031. for (k = cinfo->Ss; k <= Se; k++) {
  149032. if ((temp = absvalues[k]) == 0) {
  149033. r++;
  149034. continue;
  149035. }
  149036. while (r > 15 && k <= EOB) {
  149037. emit_eobrun(entropy);
  149038. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149039. r -= 16;
  149040. emit_buffered_bits(entropy, BR_buffer, BR);
  149041. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149042. BR = 0;
  149043. }
  149044. if (temp > 1) {
  149045. BR_buffer[BR++] = (char) (temp & 1);
  149046. continue;
  149047. }
  149048. emit_eobrun(entropy);
  149049. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149050. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149051. emit_bits_p(entropy, (unsigned int) temp, 1);
  149052. emit_buffered_bits(entropy, BR_buffer, BR);
  149053. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149054. BR = 0;
  149055. r = 0; /* reset zero run length */
  149056. }
  149057. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149058. entropy->EOBRUN++; /* count an EOB */
  149059. entropy->BE += BR; /* concat my correction bits to older ones */
  149060. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149061. emit_eobrun(entropy);
  149062. }
  149063. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149064. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149065. if (cinfo->restart_interval) {
  149066. if (entropy->restarts_to_go == 0) {
  149067. entropy->restarts_to_go = cinfo->restart_interval;
  149068. entropy->next_restart_num++;
  149069. entropy->next_restart_num &= 7;
  149070. }
  149071. entropy->restarts_to_go--;
  149072. }
  149073. return TRUE;
  149074. }
  149075. METHODDEF(void)
  149076. finish_pass_phuff (j_compress_ptr cinfo)
  149077. {
  149078. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149079. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149080. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149081. emit_eobrun(entropy);
  149082. flush_bits_p(entropy);
  149083. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149084. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149085. }
  149086. METHODDEF(void)
  149087. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149088. {
  149089. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149090. boolean is_DC_band;
  149091. int ci, tbl;
  149092. jpeg_component_info * compptr;
  149093. JHUFF_TBL **htblptr;
  149094. boolean did[NUM_HUFF_TBLS];
  149095. emit_eobrun(entropy);
  149096. is_DC_band = (cinfo->Ss == 0);
  149097. MEMZERO(did, SIZEOF(did));
  149098. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149099. compptr = cinfo->cur_comp_info[ci];
  149100. if (is_DC_band) {
  149101. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149102. continue;
  149103. tbl = compptr->dc_tbl_no;
  149104. } else {
  149105. tbl = compptr->ac_tbl_no;
  149106. }
  149107. if (! did[tbl]) {
  149108. if (is_DC_band)
  149109. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149110. else
  149111. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149112. if (*htblptr == NULL)
  149113. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149114. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149115. did[tbl] = TRUE;
  149116. }
  149117. }
  149118. }
  149119. GLOBAL(void)
  149120. jinit_phuff_encoder (j_compress_ptr cinfo)
  149121. {
  149122. phuff_entropy_ptr entropy;
  149123. int i;
  149124. entropy = (phuff_entropy_ptr)
  149125. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149126. SIZEOF(phuff_entropy_encoder));
  149127. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149128. entropy->pub.start_pass = start_pass_phuff;
  149129. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149130. entropy->derived_tbls[i] = NULL;
  149131. entropy->count_ptrs[i] = NULL;
  149132. }
  149133. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149134. }
  149135. #endif /* C_PROGRESSIVE_SUPPORTED */
  149136. /*** End of inlined file: jcphuff.c ***/
  149137. /*** Start of inlined file: jcprepct.c ***/
  149138. #define JPEG_INTERNALS
  149139. #ifdef INPUT_SMOOTHING_SUPPORTED
  149140. #define CONTEXT_ROWS_SUPPORTED
  149141. #endif
  149142. typedef struct {
  149143. struct jpeg_c_prep_controller pub; /* public fields */
  149144. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149145. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149146. int next_buf_row; /* index of next row to store in color_buf */
  149147. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149148. int this_row_group; /* starting row index of group to process */
  149149. int next_buf_stop; /* downsample when we reach this index */
  149150. #endif
  149151. } my_prep_controller;
  149152. typedef my_prep_controller * my_prep_ptr;
  149153. METHODDEF(void)
  149154. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149155. {
  149156. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149157. if (pass_mode != JBUF_PASS_THRU)
  149158. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149159. prep->rows_to_go = cinfo->image_height;
  149160. prep->next_buf_row = 0;
  149161. #ifdef CONTEXT_ROWS_SUPPORTED
  149162. prep->this_row_group = 0;
  149163. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149164. #endif
  149165. }
  149166. LOCAL(void)
  149167. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149168. int input_rows, int output_rows)
  149169. {
  149170. register int row;
  149171. for (row = input_rows; row < output_rows; row++) {
  149172. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149173. 1, num_cols);
  149174. }
  149175. }
  149176. METHODDEF(void)
  149177. pre_process_data (j_compress_ptr cinfo,
  149178. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149179. JDIMENSION in_rows_avail,
  149180. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149181. JDIMENSION out_row_groups_avail)
  149182. {
  149183. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149184. int numrows, ci;
  149185. JDIMENSION inrows;
  149186. jpeg_component_info * compptr;
  149187. while (*in_row_ctr < in_rows_avail &&
  149188. *out_row_group_ctr < out_row_groups_avail) {
  149189. inrows = in_rows_avail - *in_row_ctr;
  149190. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149191. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149192. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149193. prep->color_buf,
  149194. (JDIMENSION) prep->next_buf_row,
  149195. numrows);
  149196. *in_row_ctr += numrows;
  149197. prep->next_buf_row += numrows;
  149198. prep->rows_to_go -= numrows;
  149199. if (prep->rows_to_go == 0 &&
  149200. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149201. for (ci = 0; ci < cinfo->num_components; ci++) {
  149202. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149203. prep->next_buf_row, cinfo->max_v_samp_factor);
  149204. }
  149205. prep->next_buf_row = cinfo->max_v_samp_factor;
  149206. }
  149207. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149208. (*cinfo->downsample->downsample) (cinfo,
  149209. prep->color_buf, (JDIMENSION) 0,
  149210. output_buf, *out_row_group_ctr);
  149211. prep->next_buf_row = 0;
  149212. (*out_row_group_ctr)++;
  149213. }
  149214. if (prep->rows_to_go == 0 &&
  149215. *out_row_group_ctr < out_row_groups_avail) {
  149216. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149217. ci++, compptr++) {
  149218. expand_bottom_edge(output_buf[ci],
  149219. compptr->width_in_blocks * DCTSIZE,
  149220. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149221. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149222. }
  149223. *out_row_group_ctr = out_row_groups_avail;
  149224. break; /* can exit outer loop without test */
  149225. }
  149226. }
  149227. }
  149228. #ifdef CONTEXT_ROWS_SUPPORTED
  149229. METHODDEF(void)
  149230. pre_process_context (j_compress_ptr cinfo,
  149231. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149232. JDIMENSION in_rows_avail,
  149233. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149234. JDIMENSION out_row_groups_avail)
  149235. {
  149236. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149237. int numrows, ci;
  149238. int buf_height = cinfo->max_v_samp_factor * 3;
  149239. JDIMENSION inrows;
  149240. while (*out_row_group_ctr < out_row_groups_avail) {
  149241. if (*in_row_ctr < in_rows_avail) {
  149242. inrows = in_rows_avail - *in_row_ctr;
  149243. numrows = prep->next_buf_stop - prep->next_buf_row;
  149244. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149245. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149246. prep->color_buf,
  149247. (JDIMENSION) prep->next_buf_row,
  149248. numrows);
  149249. if (prep->rows_to_go == cinfo->image_height) {
  149250. for (ci = 0; ci < cinfo->num_components; ci++) {
  149251. int row;
  149252. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149253. jcopy_sample_rows(prep->color_buf[ci], 0,
  149254. prep->color_buf[ci], -row,
  149255. 1, cinfo->image_width);
  149256. }
  149257. }
  149258. }
  149259. *in_row_ctr += numrows;
  149260. prep->next_buf_row += numrows;
  149261. prep->rows_to_go -= numrows;
  149262. } else {
  149263. if (prep->rows_to_go != 0)
  149264. break;
  149265. if (prep->next_buf_row < prep->next_buf_stop) {
  149266. for (ci = 0; ci < cinfo->num_components; ci++) {
  149267. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149268. prep->next_buf_row, prep->next_buf_stop);
  149269. }
  149270. prep->next_buf_row = prep->next_buf_stop;
  149271. }
  149272. }
  149273. if (prep->next_buf_row == prep->next_buf_stop) {
  149274. (*cinfo->downsample->downsample) (cinfo,
  149275. prep->color_buf,
  149276. (JDIMENSION) prep->this_row_group,
  149277. output_buf, *out_row_group_ctr);
  149278. (*out_row_group_ctr)++;
  149279. prep->this_row_group += cinfo->max_v_samp_factor;
  149280. if (prep->this_row_group >= buf_height)
  149281. prep->this_row_group = 0;
  149282. if (prep->next_buf_row >= buf_height)
  149283. prep->next_buf_row = 0;
  149284. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149285. }
  149286. }
  149287. }
  149288. LOCAL(void)
  149289. create_context_buffer (j_compress_ptr cinfo)
  149290. {
  149291. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149292. int rgroup_height = cinfo->max_v_samp_factor;
  149293. int ci, i;
  149294. jpeg_component_info * compptr;
  149295. JSAMPARRAY true_buffer, fake_buffer;
  149296. fake_buffer = (JSAMPARRAY)
  149297. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149298. (cinfo->num_components * 5 * rgroup_height) *
  149299. SIZEOF(JSAMPROW));
  149300. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149301. ci++, compptr++) {
  149302. true_buffer = (*cinfo->mem->alloc_sarray)
  149303. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149304. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149305. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149306. (JDIMENSION) (3 * rgroup_height));
  149307. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149308. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149309. for (i = 0; i < rgroup_height; i++) {
  149310. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149311. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149312. }
  149313. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149314. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149315. }
  149316. }
  149317. #endif /* CONTEXT_ROWS_SUPPORTED */
  149318. GLOBAL(void)
  149319. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149320. {
  149321. my_prep_ptr prep;
  149322. int ci;
  149323. jpeg_component_info * compptr;
  149324. if (need_full_buffer) /* safety check */
  149325. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149326. prep = (my_prep_ptr)
  149327. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149328. SIZEOF(my_prep_controller));
  149329. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149330. prep->pub.start_pass = start_pass_prep;
  149331. if (cinfo->downsample->need_context_rows) {
  149332. #ifdef CONTEXT_ROWS_SUPPORTED
  149333. prep->pub.pre_process_data = pre_process_context;
  149334. create_context_buffer(cinfo);
  149335. #else
  149336. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149337. #endif
  149338. } else {
  149339. prep->pub.pre_process_data = pre_process_data;
  149340. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149341. ci++, compptr++) {
  149342. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149343. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149344. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149345. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149346. (JDIMENSION) cinfo->max_v_samp_factor);
  149347. }
  149348. }
  149349. }
  149350. /*** End of inlined file: jcprepct.c ***/
  149351. /*** Start of inlined file: jcsample.c ***/
  149352. #define JPEG_INTERNALS
  149353. typedef JMETHOD(void, downsample1_ptr,
  149354. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149355. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149356. typedef struct {
  149357. struct jpeg_downsampler pub; /* public fields */
  149358. downsample1_ptr methods[MAX_COMPONENTS];
  149359. } my_downsampler;
  149360. typedef my_downsampler * my_downsample_ptr;
  149361. METHODDEF(void)
  149362. start_pass_downsample (j_compress_ptr cinfo)
  149363. {
  149364. }
  149365. LOCAL(void)
  149366. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149367. JDIMENSION input_cols, JDIMENSION output_cols)
  149368. {
  149369. register JSAMPROW ptr;
  149370. register JSAMPLE pixval;
  149371. register int count;
  149372. int row;
  149373. int numcols = (int) (output_cols - input_cols);
  149374. if (numcols > 0) {
  149375. for (row = 0; row < num_rows; row++) {
  149376. ptr = image_data[row] + input_cols;
  149377. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149378. for (count = numcols; count > 0; count--)
  149379. *ptr++ = pixval;
  149380. }
  149381. }
  149382. }
  149383. METHODDEF(void)
  149384. sep_downsample (j_compress_ptr cinfo,
  149385. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149386. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149387. {
  149388. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149389. int ci;
  149390. jpeg_component_info * compptr;
  149391. JSAMPARRAY in_ptr, out_ptr;
  149392. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149393. ci++, compptr++) {
  149394. in_ptr = input_buf[ci] + in_row_index;
  149395. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149396. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149397. }
  149398. }
  149399. METHODDEF(void)
  149400. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149401. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149402. {
  149403. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149404. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149405. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149406. JSAMPROW inptr, outptr;
  149407. INT32 outvalue;
  149408. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149409. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149410. numpix = h_expand * v_expand;
  149411. numpix2 = numpix/2;
  149412. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149413. cinfo->image_width, output_cols * h_expand);
  149414. inrow = 0;
  149415. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149416. outptr = output_data[outrow];
  149417. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149418. outcol++, outcol_h += h_expand) {
  149419. outvalue = 0;
  149420. for (v = 0; v < v_expand; v++) {
  149421. inptr = input_data[inrow+v] + outcol_h;
  149422. for (h = 0; h < h_expand; h++) {
  149423. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149424. }
  149425. }
  149426. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149427. }
  149428. inrow += v_expand;
  149429. }
  149430. }
  149431. METHODDEF(void)
  149432. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149433. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149434. {
  149435. jcopy_sample_rows(input_data, 0, output_data, 0,
  149436. cinfo->max_v_samp_factor, cinfo->image_width);
  149437. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149438. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149439. }
  149440. METHODDEF(void)
  149441. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149442. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149443. {
  149444. int outrow;
  149445. JDIMENSION outcol;
  149446. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149447. register JSAMPROW inptr, outptr;
  149448. register int bias;
  149449. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149450. cinfo->image_width, output_cols * 2);
  149451. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149452. outptr = output_data[outrow];
  149453. inptr = input_data[outrow];
  149454. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149455. for (outcol = 0; outcol < output_cols; outcol++) {
  149456. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149457. + bias) >> 1);
  149458. bias ^= 1; /* 0=>1, 1=>0 */
  149459. inptr += 2;
  149460. }
  149461. }
  149462. }
  149463. METHODDEF(void)
  149464. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149465. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149466. {
  149467. int inrow, outrow;
  149468. JDIMENSION outcol;
  149469. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149470. register JSAMPROW inptr0, inptr1, outptr;
  149471. register int bias;
  149472. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149473. cinfo->image_width, output_cols * 2);
  149474. inrow = 0;
  149475. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149476. outptr = output_data[outrow];
  149477. inptr0 = input_data[inrow];
  149478. inptr1 = input_data[inrow+1];
  149479. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149480. for (outcol = 0; outcol < output_cols; outcol++) {
  149481. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149482. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149483. + bias) >> 2);
  149484. bias ^= 3; /* 1=>2, 2=>1 */
  149485. inptr0 += 2; inptr1 += 2;
  149486. }
  149487. inrow += 2;
  149488. }
  149489. }
  149490. #ifdef INPUT_SMOOTHING_SUPPORTED
  149491. METHODDEF(void)
  149492. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149493. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149494. {
  149495. int inrow, outrow;
  149496. JDIMENSION colctr;
  149497. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149498. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149499. INT32 membersum, neighsum, memberscale, neighscale;
  149500. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149501. cinfo->image_width, output_cols * 2);
  149502. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149503. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149504. inrow = 0;
  149505. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149506. outptr = output_data[outrow];
  149507. inptr0 = input_data[inrow];
  149508. inptr1 = input_data[inrow+1];
  149509. above_ptr = input_data[inrow-1];
  149510. below_ptr = input_data[inrow+2];
  149511. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149512. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149513. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149514. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149515. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149516. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149517. neighsum += neighsum;
  149518. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149519. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149520. membersum = membersum * memberscale + neighsum * neighscale;
  149521. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149522. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149523. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149524. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149525. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149526. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149527. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149528. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149529. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149530. neighsum += neighsum;
  149531. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149532. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149533. membersum = membersum * memberscale + neighsum * neighscale;
  149534. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149535. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149536. }
  149537. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149538. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149539. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149540. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149541. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149542. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149543. neighsum += neighsum;
  149544. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149545. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149546. membersum = membersum * memberscale + neighsum * neighscale;
  149547. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149548. inrow += 2;
  149549. }
  149550. }
  149551. METHODDEF(void)
  149552. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149553. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149554. {
  149555. int outrow;
  149556. JDIMENSION colctr;
  149557. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149558. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149559. INT32 membersum, neighsum, memberscale, neighscale;
  149560. int colsum, lastcolsum, nextcolsum;
  149561. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149562. cinfo->image_width, output_cols);
  149563. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149564. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149565. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149566. outptr = output_data[outrow];
  149567. inptr = input_data[outrow];
  149568. above_ptr = input_data[outrow-1];
  149569. below_ptr = input_data[outrow+1];
  149570. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149571. GETJSAMPLE(*inptr);
  149572. membersum = GETJSAMPLE(*inptr++);
  149573. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149574. GETJSAMPLE(*inptr);
  149575. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149576. membersum = membersum * memberscale + neighsum * neighscale;
  149577. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149578. lastcolsum = colsum; colsum = nextcolsum;
  149579. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149580. membersum = GETJSAMPLE(*inptr++);
  149581. above_ptr++; below_ptr++;
  149582. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149583. GETJSAMPLE(*inptr);
  149584. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149585. membersum = membersum * memberscale + neighsum * neighscale;
  149586. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149587. lastcolsum = colsum; colsum = nextcolsum;
  149588. }
  149589. membersum = GETJSAMPLE(*inptr);
  149590. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149591. membersum = membersum * memberscale + neighsum * neighscale;
  149592. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149593. }
  149594. }
  149595. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149596. GLOBAL(void)
  149597. jinit_downsampler (j_compress_ptr cinfo)
  149598. {
  149599. my_downsample_ptr downsample;
  149600. int ci;
  149601. jpeg_component_info * compptr;
  149602. boolean smoothok = TRUE;
  149603. downsample = (my_downsample_ptr)
  149604. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149605. SIZEOF(my_downsampler));
  149606. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149607. downsample->pub.start_pass = start_pass_downsample;
  149608. downsample->pub.downsample = sep_downsample;
  149609. downsample->pub.need_context_rows = FALSE;
  149610. if (cinfo->CCIR601_sampling)
  149611. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149612. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149613. ci++, compptr++) {
  149614. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149615. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149616. #ifdef INPUT_SMOOTHING_SUPPORTED
  149617. if (cinfo->smoothing_factor) {
  149618. downsample->methods[ci] = fullsize_smooth_downsample;
  149619. downsample->pub.need_context_rows = TRUE;
  149620. } else
  149621. #endif
  149622. downsample->methods[ci] = fullsize_downsample;
  149623. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149624. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149625. smoothok = FALSE;
  149626. downsample->methods[ci] = h2v1_downsample;
  149627. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149628. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149629. #ifdef INPUT_SMOOTHING_SUPPORTED
  149630. if (cinfo->smoothing_factor) {
  149631. downsample->methods[ci] = h2v2_smooth_downsample;
  149632. downsample->pub.need_context_rows = TRUE;
  149633. } else
  149634. #endif
  149635. downsample->methods[ci] = h2v2_downsample;
  149636. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149637. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149638. smoothok = FALSE;
  149639. downsample->methods[ci] = int_downsample;
  149640. } else
  149641. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149642. }
  149643. #ifdef INPUT_SMOOTHING_SUPPORTED
  149644. if (cinfo->smoothing_factor && !smoothok)
  149645. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149646. #endif
  149647. }
  149648. /*** End of inlined file: jcsample.c ***/
  149649. /*** Start of inlined file: jctrans.c ***/
  149650. #define JPEG_INTERNALS
  149651. LOCAL(void) transencode_master_selection
  149652. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149653. LOCAL(void) transencode_coef_controller
  149654. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149655. GLOBAL(void)
  149656. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149657. {
  149658. if (cinfo->global_state != CSTATE_START)
  149659. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149660. jpeg_suppress_tables(cinfo, FALSE);
  149661. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149662. (*cinfo->dest->init_destination) (cinfo);
  149663. transencode_master_selection(cinfo, coef_arrays);
  149664. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149665. cinfo->global_state = CSTATE_WRCOEFS;
  149666. }
  149667. GLOBAL(void)
  149668. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149669. j_compress_ptr dstinfo)
  149670. {
  149671. JQUANT_TBL ** qtblptr;
  149672. jpeg_component_info *incomp, *outcomp;
  149673. JQUANT_TBL *c_quant, *slot_quant;
  149674. int tblno, ci, coefi;
  149675. if (dstinfo->global_state != CSTATE_START)
  149676. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149677. dstinfo->image_width = srcinfo->image_width;
  149678. dstinfo->image_height = srcinfo->image_height;
  149679. dstinfo->input_components = srcinfo->num_components;
  149680. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149681. jpeg_set_defaults(dstinfo);
  149682. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149683. dstinfo->data_precision = srcinfo->data_precision;
  149684. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149685. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149686. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149687. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149688. if (*qtblptr == NULL)
  149689. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149690. MEMCOPY((*qtblptr)->quantval,
  149691. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149692. SIZEOF((*qtblptr)->quantval));
  149693. (*qtblptr)->sent_table = FALSE;
  149694. }
  149695. }
  149696. dstinfo->num_components = srcinfo->num_components;
  149697. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  149698. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  149699. MAX_COMPONENTS);
  149700. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  149701. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  149702. outcomp->component_id = incomp->component_id;
  149703. outcomp->h_samp_factor = incomp->h_samp_factor;
  149704. outcomp->v_samp_factor = incomp->v_samp_factor;
  149705. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  149706. tblno = outcomp->quant_tbl_no;
  149707. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  149708. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  149709. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  149710. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  149711. c_quant = incomp->quant_table;
  149712. if (c_quant != NULL) {
  149713. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  149714. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  149715. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  149716. }
  149717. }
  149718. }
  149719. if (srcinfo->saw_JFIF_marker) {
  149720. if (srcinfo->JFIF_major_version == 1) {
  149721. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  149722. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  149723. }
  149724. dstinfo->density_unit = srcinfo->density_unit;
  149725. dstinfo->X_density = srcinfo->X_density;
  149726. dstinfo->Y_density = srcinfo->Y_density;
  149727. }
  149728. }
  149729. LOCAL(void)
  149730. transencode_master_selection (j_compress_ptr cinfo,
  149731. jvirt_barray_ptr * coef_arrays)
  149732. {
  149733. cinfo->input_components = 1;
  149734. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  149735. if (cinfo->arith_code) {
  149736. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  149737. } else {
  149738. if (cinfo->progressive_mode) {
  149739. #ifdef C_PROGRESSIVE_SUPPORTED
  149740. jinit_phuff_encoder(cinfo);
  149741. #else
  149742. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149743. #endif
  149744. } else
  149745. jinit_huff_encoder(cinfo);
  149746. }
  149747. transencode_coef_controller(cinfo, coef_arrays);
  149748. jinit_marker_writer(cinfo);
  149749. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  149750. (*cinfo->marker->write_file_header) (cinfo);
  149751. }
  149752. typedef struct {
  149753. struct jpeg_c_coef_controller pub; /* public fields */
  149754. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  149755. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  149756. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  149757. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  149758. jvirt_barray_ptr * whole_image;
  149759. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  149760. } my_coef_controller2;
  149761. typedef my_coef_controller2 * my_coef_ptr2;
  149762. LOCAL(void)
  149763. start_iMCU_row2 (j_compress_ptr cinfo)
  149764. {
  149765. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149766. if (cinfo->comps_in_scan > 1) {
  149767. coef->MCU_rows_per_iMCU_row = 1;
  149768. } else {
  149769. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  149770. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  149771. else
  149772. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  149773. }
  149774. coef->mcu_ctr = 0;
  149775. coef->MCU_vert_offset = 0;
  149776. }
  149777. METHODDEF(void)
  149778. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149779. {
  149780. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149781. if (pass_mode != JBUF_CRANK_DEST)
  149782. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149783. coef->iMCU_row_num = 0;
  149784. start_iMCU_row2(cinfo);
  149785. }
  149786. METHODDEF(boolean)
  149787. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  149788. {
  149789. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149790. JDIMENSION MCU_col_num; /* index of current MCU within row */
  149791. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  149792. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  149793. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  149794. JDIMENSION start_col;
  149795. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  149796. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  149797. JBLOCKROW buffer_ptr;
  149798. jpeg_component_info *compptr;
  149799. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149800. compptr = cinfo->cur_comp_info[ci];
  149801. buffer[ci] = (*cinfo->mem->access_virt_barray)
  149802. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  149803. coef->iMCU_row_num * compptr->v_samp_factor,
  149804. (JDIMENSION) compptr->v_samp_factor, FALSE);
  149805. }
  149806. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  149807. yoffset++) {
  149808. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  149809. MCU_col_num++) {
  149810. blkn = 0; /* index of current DCT block within MCU */
  149811. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149812. compptr = cinfo->cur_comp_info[ci];
  149813. start_col = MCU_col_num * compptr->MCU_width;
  149814. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  149815. : compptr->last_col_width;
  149816. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  149817. if (coef->iMCU_row_num < last_iMCU_row ||
  149818. yindex+yoffset < compptr->last_row_height) {
  149819. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  149820. for (xindex = 0; xindex < blockcnt; xindex++)
  149821. MCU_buffer[blkn++] = buffer_ptr++;
  149822. } else {
  149823. xindex = 0;
  149824. }
  149825. for (; xindex < compptr->MCU_width; xindex++) {
  149826. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  149827. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  149828. blkn++;
  149829. }
  149830. }
  149831. }
  149832. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  149833. coef->MCU_vert_offset = yoffset;
  149834. coef->mcu_ctr = MCU_col_num;
  149835. return FALSE;
  149836. }
  149837. }
  149838. coef->mcu_ctr = 0;
  149839. }
  149840. coef->iMCU_row_num++;
  149841. start_iMCU_row2(cinfo);
  149842. return TRUE;
  149843. }
  149844. LOCAL(void)
  149845. transencode_coef_controller (j_compress_ptr cinfo,
  149846. jvirt_barray_ptr * coef_arrays)
  149847. {
  149848. my_coef_ptr2 coef;
  149849. JBLOCKROW buffer;
  149850. int i;
  149851. coef = (my_coef_ptr2)
  149852. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149853. SIZEOF(my_coef_controller2));
  149854. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  149855. coef->pub.start_pass = start_pass_coef2;
  149856. coef->pub.compress_data = compress_output2;
  149857. coef->whole_image = coef_arrays;
  149858. buffer = (JBLOCKROW)
  149859. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149860. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  149861. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  149862. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  149863. coef->dummy_buffer[i] = buffer + i;
  149864. }
  149865. }
  149866. /*** End of inlined file: jctrans.c ***/
  149867. /*** Start of inlined file: jdapistd.c ***/
  149868. #define JPEG_INTERNALS
  149869. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  149870. GLOBAL(boolean)
  149871. jpeg_start_decompress (j_decompress_ptr cinfo)
  149872. {
  149873. if (cinfo->global_state == DSTATE_READY) {
  149874. jinit_master_decompress(cinfo);
  149875. if (cinfo->buffered_image) {
  149876. cinfo->global_state = DSTATE_BUFIMAGE;
  149877. return TRUE;
  149878. }
  149879. cinfo->global_state = DSTATE_PRELOAD;
  149880. }
  149881. if (cinfo->global_state == DSTATE_PRELOAD) {
  149882. if (cinfo->inputctl->has_multiple_scans) {
  149883. #ifdef D_MULTISCAN_FILES_SUPPORTED
  149884. for (;;) {
  149885. int retcode;
  149886. if (cinfo->progress != NULL)
  149887. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  149888. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  149889. if (retcode == JPEG_SUSPENDED)
  149890. return FALSE;
  149891. if (retcode == JPEG_REACHED_EOI)
  149892. break;
  149893. if (cinfo->progress != NULL &&
  149894. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  149895. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  149896. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  149897. }
  149898. }
  149899. }
  149900. #else
  149901. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149902. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  149903. }
  149904. cinfo->output_scan_number = cinfo->input_scan_number;
  149905. } else if (cinfo->global_state != DSTATE_PRESCAN)
  149906. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149907. return output_pass_setup(cinfo);
  149908. }
  149909. LOCAL(boolean)
  149910. output_pass_setup (j_decompress_ptr cinfo)
  149911. {
  149912. if (cinfo->global_state != DSTATE_PRESCAN) {
  149913. (*cinfo->master->prepare_for_output_pass) (cinfo);
  149914. cinfo->output_scanline = 0;
  149915. cinfo->global_state = DSTATE_PRESCAN;
  149916. }
  149917. while (cinfo->master->is_dummy_pass) {
  149918. #ifdef QUANT_2PASS_SUPPORTED
  149919. while (cinfo->output_scanline < cinfo->output_height) {
  149920. JDIMENSION last_scanline;
  149921. if (cinfo->progress != NULL) {
  149922. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  149923. cinfo->progress->pass_limit = (long) cinfo->output_height;
  149924. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  149925. }
  149926. last_scanline = cinfo->output_scanline;
  149927. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  149928. &cinfo->output_scanline, (JDIMENSION) 0);
  149929. if (cinfo->output_scanline == last_scanline)
  149930. return FALSE; /* No progress made, must suspend */
  149931. }
  149932. (*cinfo->master->finish_output_pass) (cinfo);
  149933. (*cinfo->master->prepare_for_output_pass) (cinfo);
  149934. cinfo->output_scanline = 0;
  149935. #else
  149936. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149937. #endif /* QUANT_2PASS_SUPPORTED */
  149938. }
  149939. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  149940. return TRUE;
  149941. }
  149942. GLOBAL(JDIMENSION)
  149943. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  149944. JDIMENSION max_lines)
  149945. {
  149946. JDIMENSION row_ctr;
  149947. if (cinfo->global_state != DSTATE_SCANNING)
  149948. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149949. if (cinfo->output_scanline >= cinfo->output_height) {
  149950. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  149951. return 0;
  149952. }
  149953. if (cinfo->progress != NULL) {
  149954. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  149955. cinfo->progress->pass_limit = (long) cinfo->output_height;
  149956. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  149957. }
  149958. row_ctr = 0;
  149959. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  149960. cinfo->output_scanline += row_ctr;
  149961. return row_ctr;
  149962. }
  149963. GLOBAL(JDIMENSION)
  149964. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  149965. JDIMENSION max_lines)
  149966. {
  149967. JDIMENSION lines_per_iMCU_row;
  149968. if (cinfo->global_state != DSTATE_RAW_OK)
  149969. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149970. if (cinfo->output_scanline >= cinfo->output_height) {
  149971. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  149972. return 0;
  149973. }
  149974. if (cinfo->progress != NULL) {
  149975. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  149976. cinfo->progress->pass_limit = (long) cinfo->output_height;
  149977. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  149978. }
  149979. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  149980. if (max_lines < lines_per_iMCU_row)
  149981. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  149982. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  149983. return 0; /* suspension forced, can do nothing more */
  149984. cinfo->output_scanline += lines_per_iMCU_row;
  149985. return lines_per_iMCU_row;
  149986. }
  149987. #ifdef D_MULTISCAN_FILES_SUPPORTED
  149988. GLOBAL(boolean)
  149989. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  149990. {
  149991. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  149992. cinfo->global_state != DSTATE_PRESCAN)
  149993. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149994. if (scan_number <= 0)
  149995. scan_number = 1;
  149996. if (cinfo->inputctl->eoi_reached &&
  149997. scan_number > cinfo->input_scan_number)
  149998. scan_number = cinfo->input_scan_number;
  149999. cinfo->output_scan_number = scan_number;
  150000. return output_pass_setup(cinfo);
  150001. }
  150002. GLOBAL(boolean)
  150003. jpeg_finish_output (j_decompress_ptr cinfo)
  150004. {
  150005. if ((cinfo->global_state == DSTATE_SCANNING ||
  150006. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150007. (*cinfo->master->finish_output_pass) (cinfo);
  150008. cinfo->global_state = DSTATE_BUFPOST;
  150009. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150010. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150011. }
  150012. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150013. ! cinfo->inputctl->eoi_reached) {
  150014. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150015. return FALSE; /* Suspend, come back later */
  150016. }
  150017. cinfo->global_state = DSTATE_BUFIMAGE;
  150018. return TRUE;
  150019. }
  150020. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150021. /*** End of inlined file: jdapistd.c ***/
  150022. /*** Start of inlined file: jdapimin.c ***/
  150023. #define JPEG_INTERNALS
  150024. GLOBAL(void)
  150025. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150026. {
  150027. int i;
  150028. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150029. if (version != JPEG_LIB_VERSION)
  150030. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150031. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150032. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150033. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150034. {
  150035. struct jpeg_error_mgr * err = cinfo->err;
  150036. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150037. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150038. cinfo->err = err;
  150039. cinfo->client_data = client_data;
  150040. }
  150041. cinfo->is_decompressor = TRUE;
  150042. jinit_memory_mgr((j_common_ptr) cinfo);
  150043. cinfo->progress = NULL;
  150044. cinfo->src = NULL;
  150045. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150046. cinfo->quant_tbl_ptrs[i] = NULL;
  150047. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150048. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150049. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150050. }
  150051. cinfo->marker_list = NULL;
  150052. jinit_marker_reader(cinfo);
  150053. jinit_input_controller(cinfo);
  150054. cinfo->global_state = DSTATE_START;
  150055. }
  150056. GLOBAL(void)
  150057. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150058. {
  150059. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150060. }
  150061. GLOBAL(void)
  150062. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150063. {
  150064. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150065. }
  150066. LOCAL(void)
  150067. default_decompress_parms (j_decompress_ptr cinfo)
  150068. {
  150069. switch (cinfo->num_components) {
  150070. case 1:
  150071. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150072. cinfo->out_color_space = JCS_GRAYSCALE;
  150073. break;
  150074. case 3:
  150075. if (cinfo->saw_JFIF_marker) {
  150076. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150077. } else if (cinfo->saw_Adobe_marker) {
  150078. switch (cinfo->Adobe_transform) {
  150079. case 0:
  150080. cinfo->jpeg_color_space = JCS_RGB;
  150081. break;
  150082. case 1:
  150083. cinfo->jpeg_color_space = JCS_YCbCr;
  150084. break;
  150085. default:
  150086. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150087. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150088. break;
  150089. }
  150090. } else {
  150091. int cid0 = cinfo->comp_info[0].component_id;
  150092. int cid1 = cinfo->comp_info[1].component_id;
  150093. int cid2 = cinfo->comp_info[2].component_id;
  150094. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150095. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150096. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150097. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150098. else {
  150099. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150100. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150101. }
  150102. }
  150103. cinfo->out_color_space = JCS_RGB;
  150104. break;
  150105. case 4:
  150106. if (cinfo->saw_Adobe_marker) {
  150107. switch (cinfo->Adobe_transform) {
  150108. case 0:
  150109. cinfo->jpeg_color_space = JCS_CMYK;
  150110. break;
  150111. case 2:
  150112. cinfo->jpeg_color_space = JCS_YCCK;
  150113. break;
  150114. default:
  150115. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150116. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150117. break;
  150118. }
  150119. } else {
  150120. cinfo->jpeg_color_space = JCS_CMYK;
  150121. }
  150122. cinfo->out_color_space = JCS_CMYK;
  150123. break;
  150124. default:
  150125. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150126. cinfo->out_color_space = JCS_UNKNOWN;
  150127. break;
  150128. }
  150129. cinfo->scale_num = 1; /* 1:1 scaling */
  150130. cinfo->scale_denom = 1;
  150131. cinfo->output_gamma = 1.0;
  150132. cinfo->buffered_image = FALSE;
  150133. cinfo->raw_data_out = FALSE;
  150134. cinfo->dct_method = JDCT_DEFAULT;
  150135. cinfo->do_fancy_upsampling = TRUE;
  150136. cinfo->do_block_smoothing = TRUE;
  150137. cinfo->quantize_colors = FALSE;
  150138. cinfo->dither_mode = JDITHER_FS;
  150139. #ifdef QUANT_2PASS_SUPPORTED
  150140. cinfo->two_pass_quantize = TRUE;
  150141. #else
  150142. cinfo->two_pass_quantize = FALSE;
  150143. #endif
  150144. cinfo->desired_number_of_colors = 256;
  150145. cinfo->colormap = NULL;
  150146. cinfo->enable_1pass_quant = FALSE;
  150147. cinfo->enable_external_quant = FALSE;
  150148. cinfo->enable_2pass_quant = FALSE;
  150149. }
  150150. GLOBAL(int)
  150151. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150152. {
  150153. int retcode;
  150154. if (cinfo->global_state != DSTATE_START &&
  150155. cinfo->global_state != DSTATE_INHEADER)
  150156. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150157. retcode = jpeg_consume_input(cinfo);
  150158. switch (retcode) {
  150159. case JPEG_REACHED_SOS:
  150160. retcode = JPEG_HEADER_OK;
  150161. break;
  150162. case JPEG_REACHED_EOI:
  150163. if (require_image) /* Complain if application wanted an image */
  150164. ERREXIT(cinfo, JERR_NO_IMAGE);
  150165. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150166. retcode = JPEG_HEADER_TABLES_ONLY;
  150167. break;
  150168. case JPEG_SUSPENDED:
  150169. break;
  150170. }
  150171. return retcode;
  150172. }
  150173. GLOBAL(int)
  150174. jpeg_consume_input (j_decompress_ptr cinfo)
  150175. {
  150176. int retcode = JPEG_SUSPENDED;
  150177. switch (cinfo->global_state) {
  150178. case DSTATE_START:
  150179. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150180. (*cinfo->src->init_source) (cinfo);
  150181. cinfo->global_state = DSTATE_INHEADER;
  150182. case DSTATE_INHEADER:
  150183. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150184. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150185. default_decompress_parms(cinfo);
  150186. cinfo->global_state = DSTATE_READY;
  150187. }
  150188. break;
  150189. case DSTATE_READY:
  150190. retcode = JPEG_REACHED_SOS;
  150191. break;
  150192. case DSTATE_PRELOAD:
  150193. case DSTATE_PRESCAN:
  150194. case DSTATE_SCANNING:
  150195. case DSTATE_RAW_OK:
  150196. case DSTATE_BUFIMAGE:
  150197. case DSTATE_BUFPOST:
  150198. case DSTATE_STOPPING:
  150199. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150200. break;
  150201. default:
  150202. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150203. }
  150204. return retcode;
  150205. }
  150206. GLOBAL(boolean)
  150207. jpeg_input_complete (j_decompress_ptr cinfo)
  150208. {
  150209. if (cinfo->global_state < DSTATE_START ||
  150210. cinfo->global_state > DSTATE_STOPPING)
  150211. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150212. return cinfo->inputctl->eoi_reached;
  150213. }
  150214. GLOBAL(boolean)
  150215. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150216. {
  150217. if (cinfo->global_state < DSTATE_READY ||
  150218. cinfo->global_state > DSTATE_STOPPING)
  150219. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150220. return cinfo->inputctl->has_multiple_scans;
  150221. }
  150222. GLOBAL(boolean)
  150223. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150224. {
  150225. if ((cinfo->global_state == DSTATE_SCANNING ||
  150226. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150227. if (cinfo->output_scanline < cinfo->output_height)
  150228. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150229. (*cinfo->master->finish_output_pass) (cinfo);
  150230. cinfo->global_state = DSTATE_STOPPING;
  150231. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150232. cinfo->global_state = DSTATE_STOPPING;
  150233. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150234. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150235. }
  150236. while (! cinfo->inputctl->eoi_reached) {
  150237. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150238. return FALSE; /* Suspend, come back later */
  150239. }
  150240. (*cinfo->src->term_source) (cinfo);
  150241. jpeg_abort((j_common_ptr) cinfo);
  150242. return TRUE;
  150243. }
  150244. /*** End of inlined file: jdapimin.c ***/
  150245. /*** Start of inlined file: jdatasrc.c ***/
  150246. /*** Start of inlined file: jerror.h ***/
  150247. #ifndef JMESSAGE
  150248. #ifndef JERROR_H
  150249. #define JMAKE_ENUM_LIST
  150250. #else
  150251. #define JMESSAGE(code,string)
  150252. #endif /* JERROR_H */
  150253. #endif /* JMESSAGE */
  150254. #ifdef JMAKE_ENUM_LIST
  150255. typedef enum {
  150256. #define JMESSAGE(code,string) code ,
  150257. #endif /* JMAKE_ENUM_LIST */
  150258. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150259. JMESSAGE(JERR_ARITH_NOTIMPL,
  150260. "Sorry, there are legal restrictions on arithmetic coding")
  150261. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150262. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150263. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150264. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150265. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150266. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150267. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150268. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150269. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150270. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150271. JMESSAGE(JERR_BAD_LIB_VERSION,
  150272. "Wrong JPEG library version: library is %d, caller expects %d")
  150273. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150274. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150275. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150276. JMESSAGE(JERR_BAD_PROGRESSION,
  150277. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150278. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150279. "Invalid progressive parameters at scan script entry %d")
  150280. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150281. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150282. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150283. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150284. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150285. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150286. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150287. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150288. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150289. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150290. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150291. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150292. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150293. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150294. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150295. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150296. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150297. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150298. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150299. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150300. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150301. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150302. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150303. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150304. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150305. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150306. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150307. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150308. "Cannot transcode due to multiple use of quantization table %d")
  150309. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150310. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150311. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150312. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150313. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150314. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150315. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150316. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150317. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150318. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150319. JMESSAGE(JERR_QUANT_COMPONENTS,
  150320. "Cannot quantize more than %d color components")
  150321. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150322. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150323. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150324. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150325. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150326. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150327. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150328. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150329. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150330. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150331. JMESSAGE(JERR_TFILE_WRITE,
  150332. "Write failed on temporary file --- out of disk space?")
  150333. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150334. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150335. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150336. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150337. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150338. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150339. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150340. JMESSAGE(JMSG_VERSION, JVERSION)
  150341. JMESSAGE(JTRC_16BIT_TABLES,
  150342. "Caution: quantization tables are too coarse for baseline JPEG")
  150343. JMESSAGE(JTRC_ADOBE,
  150344. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150345. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150346. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150347. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150348. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150349. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150350. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150351. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150352. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150353. JMESSAGE(JTRC_EOI, "End Of Image")
  150354. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150355. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150356. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150357. "Warning: thumbnail image size does not match data length %u")
  150358. JMESSAGE(JTRC_JFIF_EXTENSION,
  150359. "JFIF extension marker: type 0x%02x, length %u")
  150360. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150361. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150362. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150363. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150364. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150365. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150366. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150367. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150368. JMESSAGE(JTRC_RST, "RST%d")
  150369. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150370. "Smoothing not supported with nonstandard sampling ratios")
  150371. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150372. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150373. JMESSAGE(JTRC_SOI, "Start of Image")
  150374. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150375. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150376. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150377. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150378. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150379. JMESSAGE(JTRC_THUMB_JPEG,
  150380. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150381. JMESSAGE(JTRC_THUMB_PALETTE,
  150382. "JFIF extension marker: palette thumbnail image, length %u")
  150383. JMESSAGE(JTRC_THUMB_RGB,
  150384. "JFIF extension marker: RGB thumbnail image, length %u")
  150385. JMESSAGE(JTRC_UNKNOWN_IDS,
  150386. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150387. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150388. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150389. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150390. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150391. "Inconsistent progression sequence for component %d coefficient %d")
  150392. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150393. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150394. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150395. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150396. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150397. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150398. JMESSAGE(JWRN_MUST_RESYNC,
  150399. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150400. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150401. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150402. #ifdef JMAKE_ENUM_LIST
  150403. JMSG_LASTMSGCODE
  150404. } J_MESSAGE_CODE;
  150405. #undef JMAKE_ENUM_LIST
  150406. #endif /* JMAKE_ENUM_LIST */
  150407. #undef JMESSAGE
  150408. #ifndef JERROR_H
  150409. #define JERROR_H
  150410. #define ERREXIT(cinfo,code) \
  150411. ((cinfo)->err->msg_code = (code), \
  150412. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150413. #define ERREXIT1(cinfo,code,p1) \
  150414. ((cinfo)->err->msg_code = (code), \
  150415. (cinfo)->err->msg_parm.i[0] = (p1), \
  150416. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150417. #define ERREXIT2(cinfo,code,p1,p2) \
  150418. ((cinfo)->err->msg_code = (code), \
  150419. (cinfo)->err->msg_parm.i[0] = (p1), \
  150420. (cinfo)->err->msg_parm.i[1] = (p2), \
  150421. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150422. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150423. ((cinfo)->err->msg_code = (code), \
  150424. (cinfo)->err->msg_parm.i[0] = (p1), \
  150425. (cinfo)->err->msg_parm.i[1] = (p2), \
  150426. (cinfo)->err->msg_parm.i[2] = (p3), \
  150427. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150428. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150429. ((cinfo)->err->msg_code = (code), \
  150430. (cinfo)->err->msg_parm.i[0] = (p1), \
  150431. (cinfo)->err->msg_parm.i[1] = (p2), \
  150432. (cinfo)->err->msg_parm.i[2] = (p3), \
  150433. (cinfo)->err->msg_parm.i[3] = (p4), \
  150434. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150435. #define ERREXITS(cinfo,code,str) \
  150436. ((cinfo)->err->msg_code = (code), \
  150437. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150438. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150439. #define MAKESTMT(stuff) do { stuff } while (0)
  150440. #define WARNMS(cinfo,code) \
  150441. ((cinfo)->err->msg_code = (code), \
  150442. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150443. #define WARNMS1(cinfo,code,p1) \
  150444. ((cinfo)->err->msg_code = (code), \
  150445. (cinfo)->err->msg_parm.i[0] = (p1), \
  150446. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150447. #define WARNMS2(cinfo,code,p1,p2) \
  150448. ((cinfo)->err->msg_code = (code), \
  150449. (cinfo)->err->msg_parm.i[0] = (p1), \
  150450. (cinfo)->err->msg_parm.i[1] = (p2), \
  150451. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150452. #define TRACEMS(cinfo,lvl,code) \
  150453. ((cinfo)->err->msg_code = (code), \
  150454. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150455. #define TRACEMS1(cinfo,lvl,code,p1) \
  150456. ((cinfo)->err->msg_code = (code), \
  150457. (cinfo)->err->msg_parm.i[0] = (p1), \
  150458. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150459. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150460. ((cinfo)->err->msg_code = (code), \
  150461. (cinfo)->err->msg_parm.i[0] = (p1), \
  150462. (cinfo)->err->msg_parm.i[1] = (p2), \
  150463. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150464. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150465. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150466. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150467. (cinfo)->err->msg_code = (code); \
  150468. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150469. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150470. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150471. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150472. (cinfo)->err->msg_code = (code); \
  150473. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150474. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150475. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150476. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150477. _mp[4] = (p5); \
  150478. (cinfo)->err->msg_code = (code); \
  150479. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150480. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150481. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150482. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150483. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150484. (cinfo)->err->msg_code = (code); \
  150485. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150486. #define TRACEMSS(cinfo,lvl,code,str) \
  150487. ((cinfo)->err->msg_code = (code), \
  150488. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150489. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150490. #endif /* JERROR_H */
  150491. /*** End of inlined file: jerror.h ***/
  150492. typedef struct {
  150493. struct jpeg_source_mgr pub; /* public fields */
  150494. FILE * infile; /* source stream */
  150495. JOCTET * buffer; /* start of buffer */
  150496. boolean start_of_file; /* have we gotten any data yet? */
  150497. } my_source_mgr;
  150498. typedef my_source_mgr * my_src_ptr;
  150499. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150500. METHODDEF(void)
  150501. init_source (j_decompress_ptr cinfo)
  150502. {
  150503. my_src_ptr src = (my_src_ptr) cinfo->src;
  150504. src->start_of_file = TRUE;
  150505. }
  150506. METHODDEF(boolean)
  150507. fill_input_buffer (j_decompress_ptr cinfo)
  150508. {
  150509. my_src_ptr src = (my_src_ptr) cinfo->src;
  150510. size_t nbytes;
  150511. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150512. if (nbytes <= 0) {
  150513. if (src->start_of_file) /* Treat empty input file as fatal error */
  150514. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150515. WARNMS(cinfo, JWRN_JPEG_EOF);
  150516. src->buffer[0] = (JOCTET) 0xFF;
  150517. src->buffer[1] = (JOCTET) JPEG_EOI;
  150518. nbytes = 2;
  150519. }
  150520. src->pub.next_input_byte = src->buffer;
  150521. src->pub.bytes_in_buffer = nbytes;
  150522. src->start_of_file = FALSE;
  150523. return TRUE;
  150524. }
  150525. METHODDEF(void)
  150526. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150527. {
  150528. my_src_ptr src = (my_src_ptr) cinfo->src;
  150529. if (num_bytes > 0) {
  150530. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150531. num_bytes -= (long) src->pub.bytes_in_buffer;
  150532. (void) fill_input_buffer(cinfo);
  150533. }
  150534. src->pub.next_input_byte += (size_t) num_bytes;
  150535. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150536. }
  150537. }
  150538. METHODDEF(void)
  150539. term_source (j_decompress_ptr cinfo)
  150540. {
  150541. }
  150542. GLOBAL(void)
  150543. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150544. {
  150545. my_src_ptr src;
  150546. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150547. cinfo->src = (struct jpeg_source_mgr *)
  150548. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150549. SIZEOF(my_source_mgr));
  150550. src = (my_src_ptr) cinfo->src;
  150551. src->buffer = (JOCTET *)
  150552. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150553. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150554. }
  150555. src = (my_src_ptr) cinfo->src;
  150556. src->pub.init_source = init_source;
  150557. src->pub.fill_input_buffer = fill_input_buffer;
  150558. src->pub.skip_input_data = skip_input_data;
  150559. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150560. src->pub.term_source = term_source;
  150561. src->infile = infile;
  150562. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150563. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150564. }
  150565. /*** End of inlined file: jdatasrc.c ***/
  150566. /*** Start of inlined file: jdcoefct.c ***/
  150567. #define JPEG_INTERNALS
  150568. #ifndef D_PROGRESSIVE_SUPPORTED
  150569. #undef BLOCK_SMOOTHING_SUPPORTED
  150570. #endif
  150571. typedef struct {
  150572. struct jpeg_d_coef_controller pub; /* public fields */
  150573. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150574. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150575. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150576. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150577. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150578. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150579. #endif
  150580. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150581. int * coef_bits_latch;
  150582. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150583. #endif
  150584. } my_coef_controller3;
  150585. typedef my_coef_controller3 * my_coef_ptr3;
  150586. METHODDEF(int) decompress_onepass
  150587. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150588. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150589. METHODDEF(int) decompress_data
  150590. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150591. #endif
  150592. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150593. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150594. METHODDEF(int) decompress_smooth_data
  150595. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150596. #endif
  150597. LOCAL(void)
  150598. start_iMCU_row3 (j_decompress_ptr cinfo)
  150599. {
  150600. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150601. if (cinfo->comps_in_scan > 1) {
  150602. coef->MCU_rows_per_iMCU_row = 1;
  150603. } else {
  150604. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150605. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150606. else
  150607. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150608. }
  150609. coef->MCU_ctr = 0;
  150610. coef->MCU_vert_offset = 0;
  150611. }
  150612. METHODDEF(void)
  150613. start_input_pass (j_decompress_ptr cinfo)
  150614. {
  150615. cinfo->input_iMCU_row = 0;
  150616. start_iMCU_row3(cinfo);
  150617. }
  150618. METHODDEF(void)
  150619. start_output_pass (j_decompress_ptr cinfo)
  150620. {
  150621. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150622. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150623. if (coef->pub.coef_arrays != NULL) {
  150624. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150625. coef->pub.decompress_data = decompress_smooth_data;
  150626. else
  150627. coef->pub.decompress_data = decompress_data;
  150628. }
  150629. #endif
  150630. cinfo->output_iMCU_row = 0;
  150631. }
  150632. METHODDEF(int)
  150633. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150634. {
  150635. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150636. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150637. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150638. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150639. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150640. JSAMPARRAY output_ptr;
  150641. JDIMENSION start_col, output_col;
  150642. jpeg_component_info *compptr;
  150643. inverse_DCT_method_ptr inverse_DCT;
  150644. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150645. yoffset++) {
  150646. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150647. MCU_col_num++) {
  150648. jzero_far((void FAR *) coef->MCU_buffer[0],
  150649. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150650. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150651. coef->MCU_vert_offset = yoffset;
  150652. coef->MCU_ctr = MCU_col_num;
  150653. return JPEG_SUSPENDED;
  150654. }
  150655. blkn = 0; /* index of current DCT block within MCU */
  150656. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150657. compptr = cinfo->cur_comp_info[ci];
  150658. if (! compptr->component_needed) {
  150659. blkn += compptr->MCU_blocks;
  150660. continue;
  150661. }
  150662. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150663. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150664. : compptr->last_col_width;
  150665. output_ptr = output_buf[compptr->component_index] +
  150666. yoffset * compptr->DCT_scaled_size;
  150667. start_col = MCU_col_num * compptr->MCU_sample_width;
  150668. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150669. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150670. yoffset+yindex < compptr->last_row_height) {
  150671. output_col = start_col;
  150672. for (xindex = 0; xindex < useful_width; xindex++) {
  150673. (*inverse_DCT) (cinfo, compptr,
  150674. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150675. output_ptr, output_col);
  150676. output_col += compptr->DCT_scaled_size;
  150677. }
  150678. }
  150679. blkn += compptr->MCU_width;
  150680. output_ptr += compptr->DCT_scaled_size;
  150681. }
  150682. }
  150683. }
  150684. coef->MCU_ctr = 0;
  150685. }
  150686. cinfo->output_iMCU_row++;
  150687. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150688. start_iMCU_row3(cinfo);
  150689. return JPEG_ROW_COMPLETED;
  150690. }
  150691. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150692. return JPEG_SCAN_COMPLETED;
  150693. }
  150694. METHODDEF(int)
  150695. dummy_consume_data (j_decompress_ptr cinfo)
  150696. {
  150697. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  150698. }
  150699. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150700. METHODDEF(int)
  150701. consume_data (j_decompress_ptr cinfo)
  150702. {
  150703. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150704. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150705. int blkn, ci, xindex, yindex, yoffset;
  150706. JDIMENSION start_col;
  150707. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150708. JBLOCKROW buffer_ptr;
  150709. jpeg_component_info *compptr;
  150710. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150711. compptr = cinfo->cur_comp_info[ci];
  150712. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150713. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150714. cinfo->input_iMCU_row * compptr->v_samp_factor,
  150715. (JDIMENSION) compptr->v_samp_factor, TRUE);
  150716. }
  150717. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150718. yoffset++) {
  150719. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150720. MCU_col_num++) {
  150721. blkn = 0; /* index of current DCT block within MCU */
  150722. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150723. compptr = cinfo->cur_comp_info[ci];
  150724. start_col = MCU_col_num * compptr->MCU_width;
  150725. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150726. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150727. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  150728. coef->MCU_buffer[blkn++] = buffer_ptr++;
  150729. }
  150730. }
  150731. }
  150732. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150733. coef->MCU_vert_offset = yoffset;
  150734. coef->MCU_ctr = MCU_col_num;
  150735. return JPEG_SUSPENDED;
  150736. }
  150737. }
  150738. coef->MCU_ctr = 0;
  150739. }
  150740. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150741. start_iMCU_row3(cinfo);
  150742. return JPEG_ROW_COMPLETED;
  150743. }
  150744. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150745. return JPEG_SCAN_COMPLETED;
  150746. }
  150747. METHODDEF(int)
  150748. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150749. {
  150750. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150751. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150752. JDIMENSION block_num;
  150753. int ci, block_row, block_rows;
  150754. JBLOCKARRAY buffer;
  150755. JBLOCKROW buffer_ptr;
  150756. JSAMPARRAY output_ptr;
  150757. JDIMENSION output_col;
  150758. jpeg_component_info *compptr;
  150759. inverse_DCT_method_ptr inverse_DCT;
  150760. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  150761. (cinfo->input_scan_number == cinfo->output_scan_number &&
  150762. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  150763. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150764. return JPEG_SUSPENDED;
  150765. }
  150766. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150767. ci++, compptr++) {
  150768. if (! compptr->component_needed)
  150769. continue;
  150770. buffer = (*cinfo->mem->access_virt_barray)
  150771. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150772. cinfo->output_iMCU_row * compptr->v_samp_factor,
  150773. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150774. if (cinfo->output_iMCU_row < last_iMCU_row)
  150775. block_rows = compptr->v_samp_factor;
  150776. else {
  150777. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  150778. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  150779. }
  150780. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  150781. output_ptr = output_buf[ci];
  150782. for (block_row = 0; block_row < block_rows; block_row++) {
  150783. buffer_ptr = buffer[block_row];
  150784. output_col = 0;
  150785. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  150786. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  150787. output_ptr, output_col);
  150788. buffer_ptr++;
  150789. output_col += compptr->DCT_scaled_size;
  150790. }
  150791. output_ptr += compptr->DCT_scaled_size;
  150792. }
  150793. }
  150794. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  150795. return JPEG_ROW_COMPLETED;
  150796. return JPEG_SCAN_COMPLETED;
  150797. }
  150798. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150799. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150800. #define Q01_POS 1
  150801. #define Q10_POS 8
  150802. #define Q20_POS 16
  150803. #define Q11_POS 9
  150804. #define Q02_POS 2
  150805. LOCAL(boolean)
  150806. smoothing_ok (j_decompress_ptr cinfo)
  150807. {
  150808. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150809. boolean smoothing_useful = FALSE;
  150810. int ci, coefi;
  150811. jpeg_component_info *compptr;
  150812. JQUANT_TBL * qtable;
  150813. int * coef_bits;
  150814. int * coef_bits_latch;
  150815. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  150816. return FALSE;
  150817. if (coef->coef_bits_latch == NULL)
  150818. coef->coef_bits_latch = (int *)
  150819. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150820. cinfo->num_components *
  150821. (SAVED_COEFS * SIZEOF(int)));
  150822. coef_bits_latch = coef->coef_bits_latch;
  150823. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150824. ci++, compptr++) {
  150825. if ((qtable = compptr->quant_table) == NULL)
  150826. return FALSE;
  150827. if (qtable->quantval[0] == 0 ||
  150828. qtable->quantval[Q01_POS] == 0 ||
  150829. qtable->quantval[Q10_POS] == 0 ||
  150830. qtable->quantval[Q20_POS] == 0 ||
  150831. qtable->quantval[Q11_POS] == 0 ||
  150832. qtable->quantval[Q02_POS] == 0)
  150833. return FALSE;
  150834. coef_bits = cinfo->coef_bits[ci];
  150835. if (coef_bits[0] < 0)
  150836. return FALSE;
  150837. for (coefi = 1; coefi <= 5; coefi++) {
  150838. coef_bits_latch[coefi] = coef_bits[coefi];
  150839. if (coef_bits[coefi] != 0)
  150840. smoothing_useful = TRUE;
  150841. }
  150842. coef_bits_latch += SAVED_COEFS;
  150843. }
  150844. return smoothing_useful;
  150845. }
  150846. METHODDEF(int)
  150847. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150848. {
  150849. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150850. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150851. JDIMENSION block_num, last_block_column;
  150852. int ci, block_row, block_rows, access_rows;
  150853. JBLOCKARRAY buffer;
  150854. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  150855. JSAMPARRAY output_ptr;
  150856. JDIMENSION output_col;
  150857. jpeg_component_info *compptr;
  150858. inverse_DCT_method_ptr inverse_DCT;
  150859. boolean first_row, last_row;
  150860. JBLOCK workspace;
  150861. int *coef_bits;
  150862. JQUANT_TBL *quanttbl;
  150863. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  150864. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  150865. int Al, pred;
  150866. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150867. ! cinfo->inputctl->eoi_reached) {
  150868. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  150869. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  150870. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  150871. break;
  150872. }
  150873. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150874. return JPEG_SUSPENDED;
  150875. }
  150876. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150877. ci++, compptr++) {
  150878. if (! compptr->component_needed)
  150879. continue;
  150880. if (cinfo->output_iMCU_row < last_iMCU_row) {
  150881. block_rows = compptr->v_samp_factor;
  150882. access_rows = block_rows * 2; /* this and next iMCU row */
  150883. last_row = FALSE;
  150884. } else {
  150885. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  150886. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  150887. access_rows = block_rows; /* this iMCU row only */
  150888. last_row = TRUE;
  150889. }
  150890. if (cinfo->output_iMCU_row > 0) {
  150891. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  150892. buffer = (*cinfo->mem->access_virt_barray)
  150893. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150894. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  150895. (JDIMENSION) access_rows, FALSE);
  150896. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  150897. first_row = FALSE;
  150898. } else {
  150899. buffer = (*cinfo->mem->access_virt_barray)
  150900. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150901. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  150902. first_row = TRUE;
  150903. }
  150904. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  150905. quanttbl = compptr->quant_table;
  150906. Q00 = quanttbl->quantval[0];
  150907. Q01 = quanttbl->quantval[Q01_POS];
  150908. Q10 = quanttbl->quantval[Q10_POS];
  150909. Q20 = quanttbl->quantval[Q20_POS];
  150910. Q11 = quanttbl->quantval[Q11_POS];
  150911. Q02 = quanttbl->quantval[Q02_POS];
  150912. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  150913. output_ptr = output_buf[ci];
  150914. for (block_row = 0; block_row < block_rows; block_row++) {
  150915. buffer_ptr = buffer[block_row];
  150916. if (first_row && block_row == 0)
  150917. prev_block_row = buffer_ptr;
  150918. else
  150919. prev_block_row = buffer[block_row-1];
  150920. if (last_row && block_row == block_rows-1)
  150921. next_block_row = buffer_ptr;
  150922. else
  150923. next_block_row = buffer[block_row+1];
  150924. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  150925. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  150926. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  150927. output_col = 0;
  150928. last_block_column = compptr->width_in_blocks - 1;
  150929. for (block_num = 0; block_num <= last_block_column; block_num++) {
  150930. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  150931. if (block_num < last_block_column) {
  150932. DC3 = (int) prev_block_row[1][0];
  150933. DC6 = (int) buffer_ptr[1][0];
  150934. DC9 = (int) next_block_row[1][0];
  150935. }
  150936. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  150937. num = 36 * Q00 * (DC4 - DC6);
  150938. if (num >= 0) {
  150939. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  150940. if (Al > 0 && pred >= (1<<Al))
  150941. pred = (1<<Al)-1;
  150942. } else {
  150943. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  150944. if (Al > 0 && pred >= (1<<Al))
  150945. pred = (1<<Al)-1;
  150946. pred = -pred;
  150947. }
  150948. workspace[1] = (JCOEF) pred;
  150949. }
  150950. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  150951. num = 36 * Q00 * (DC2 - DC8);
  150952. if (num >= 0) {
  150953. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  150954. if (Al > 0 && pred >= (1<<Al))
  150955. pred = (1<<Al)-1;
  150956. } else {
  150957. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  150958. if (Al > 0 && pred >= (1<<Al))
  150959. pred = (1<<Al)-1;
  150960. pred = -pred;
  150961. }
  150962. workspace[8] = (JCOEF) pred;
  150963. }
  150964. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  150965. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  150966. if (num >= 0) {
  150967. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  150968. if (Al > 0 && pred >= (1<<Al))
  150969. pred = (1<<Al)-1;
  150970. } else {
  150971. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  150972. if (Al > 0 && pred >= (1<<Al))
  150973. pred = (1<<Al)-1;
  150974. pred = -pred;
  150975. }
  150976. workspace[16] = (JCOEF) pred;
  150977. }
  150978. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  150979. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  150980. if (num >= 0) {
  150981. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  150982. if (Al > 0 && pred >= (1<<Al))
  150983. pred = (1<<Al)-1;
  150984. } else {
  150985. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  150986. if (Al > 0 && pred >= (1<<Al))
  150987. pred = (1<<Al)-1;
  150988. pred = -pred;
  150989. }
  150990. workspace[9] = (JCOEF) pred;
  150991. }
  150992. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  150993. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  150994. if (num >= 0) {
  150995. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  150996. if (Al > 0 && pred >= (1<<Al))
  150997. pred = (1<<Al)-1;
  150998. } else {
  150999. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151000. if (Al > 0 && pred >= (1<<Al))
  151001. pred = (1<<Al)-1;
  151002. pred = -pred;
  151003. }
  151004. workspace[2] = (JCOEF) pred;
  151005. }
  151006. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151007. output_ptr, output_col);
  151008. DC1 = DC2; DC2 = DC3;
  151009. DC4 = DC5; DC5 = DC6;
  151010. DC7 = DC8; DC8 = DC9;
  151011. buffer_ptr++, prev_block_row++, next_block_row++;
  151012. output_col += compptr->DCT_scaled_size;
  151013. }
  151014. output_ptr += compptr->DCT_scaled_size;
  151015. }
  151016. }
  151017. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151018. return JPEG_ROW_COMPLETED;
  151019. return JPEG_SCAN_COMPLETED;
  151020. }
  151021. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151022. GLOBAL(void)
  151023. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151024. {
  151025. my_coef_ptr3 coef;
  151026. coef = (my_coef_ptr3)
  151027. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151028. SIZEOF(my_coef_controller3));
  151029. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151030. coef->pub.start_input_pass = start_input_pass;
  151031. coef->pub.start_output_pass = start_output_pass;
  151032. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151033. coef->coef_bits_latch = NULL;
  151034. #endif
  151035. if (need_full_buffer) {
  151036. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151037. int ci, access_rows;
  151038. jpeg_component_info *compptr;
  151039. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151040. ci++, compptr++) {
  151041. access_rows = compptr->v_samp_factor;
  151042. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151043. if (cinfo->progressive_mode)
  151044. access_rows *= 3;
  151045. #endif
  151046. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151047. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151048. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151049. (long) compptr->h_samp_factor),
  151050. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151051. (long) compptr->v_samp_factor),
  151052. (JDIMENSION) access_rows);
  151053. }
  151054. coef->pub.consume_data = consume_data;
  151055. coef->pub.decompress_data = decompress_data;
  151056. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151057. #else
  151058. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151059. #endif
  151060. } else {
  151061. JBLOCKROW buffer;
  151062. int i;
  151063. buffer = (JBLOCKROW)
  151064. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151065. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151066. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151067. coef->MCU_buffer[i] = buffer + i;
  151068. }
  151069. coef->pub.consume_data = dummy_consume_data;
  151070. coef->pub.decompress_data = decompress_onepass;
  151071. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151072. }
  151073. }
  151074. /*** End of inlined file: jdcoefct.c ***/
  151075. #undef FIX
  151076. /*** Start of inlined file: jdcolor.c ***/
  151077. #define JPEG_INTERNALS
  151078. typedef struct {
  151079. struct jpeg_color_deconverter pub; /* public fields */
  151080. int * Cr_r_tab; /* => table for Cr to R conversion */
  151081. int * Cb_b_tab; /* => table for Cb to B conversion */
  151082. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151083. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151084. } my_color_deconverter2;
  151085. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151086. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151087. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151088. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151089. LOCAL(void)
  151090. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151091. {
  151092. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151093. int i;
  151094. INT32 x;
  151095. SHIFT_TEMPS
  151096. cconvert->Cr_r_tab = (int *)
  151097. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151098. (MAXJSAMPLE+1) * SIZEOF(int));
  151099. cconvert->Cb_b_tab = (int *)
  151100. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151101. (MAXJSAMPLE+1) * SIZEOF(int));
  151102. cconvert->Cr_g_tab = (INT32 *)
  151103. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151104. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151105. cconvert->Cb_g_tab = (INT32 *)
  151106. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151107. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151108. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151109. cconvert->Cr_r_tab[i] = (int)
  151110. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151111. cconvert->Cb_b_tab[i] = (int)
  151112. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151113. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151114. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151115. }
  151116. }
  151117. METHODDEF(void)
  151118. ycc_rgb_convert (j_decompress_ptr cinfo,
  151119. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151120. JSAMPARRAY output_buf, int num_rows)
  151121. {
  151122. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151123. register int y, cb, cr;
  151124. register JSAMPROW outptr;
  151125. register JSAMPROW inptr0, inptr1, inptr2;
  151126. register JDIMENSION col;
  151127. JDIMENSION num_cols = cinfo->output_width;
  151128. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151129. register int * Crrtab = cconvert->Cr_r_tab;
  151130. register int * Cbbtab = cconvert->Cb_b_tab;
  151131. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151132. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151133. SHIFT_TEMPS
  151134. while (--num_rows >= 0) {
  151135. inptr0 = input_buf[0][input_row];
  151136. inptr1 = input_buf[1][input_row];
  151137. inptr2 = input_buf[2][input_row];
  151138. input_row++;
  151139. outptr = *output_buf++;
  151140. for (col = 0; col < num_cols; col++) {
  151141. y = GETJSAMPLE(inptr0[col]);
  151142. cb = GETJSAMPLE(inptr1[col]);
  151143. cr = GETJSAMPLE(inptr2[col]);
  151144. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151145. outptr[RGB_GREEN] = range_limit[y +
  151146. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151147. SCALEBITS))];
  151148. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151149. outptr += RGB_PIXELSIZE;
  151150. }
  151151. }
  151152. }
  151153. METHODDEF(void)
  151154. null_convert2 (j_decompress_ptr cinfo,
  151155. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151156. JSAMPARRAY output_buf, int num_rows)
  151157. {
  151158. register JSAMPROW inptr, outptr;
  151159. register JDIMENSION count;
  151160. register int num_components = cinfo->num_components;
  151161. JDIMENSION num_cols = cinfo->output_width;
  151162. int ci;
  151163. while (--num_rows >= 0) {
  151164. for (ci = 0; ci < num_components; ci++) {
  151165. inptr = input_buf[ci][input_row];
  151166. outptr = output_buf[0] + ci;
  151167. for (count = num_cols; count > 0; count--) {
  151168. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151169. outptr += num_components;
  151170. }
  151171. }
  151172. input_row++;
  151173. output_buf++;
  151174. }
  151175. }
  151176. METHODDEF(void)
  151177. grayscale_convert2 (j_decompress_ptr cinfo,
  151178. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151179. JSAMPARRAY output_buf, int num_rows)
  151180. {
  151181. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151182. num_rows, cinfo->output_width);
  151183. }
  151184. METHODDEF(void)
  151185. gray_rgb_convert (j_decompress_ptr cinfo,
  151186. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151187. JSAMPARRAY output_buf, int num_rows)
  151188. {
  151189. register JSAMPROW inptr, outptr;
  151190. register JDIMENSION col;
  151191. JDIMENSION num_cols = cinfo->output_width;
  151192. while (--num_rows >= 0) {
  151193. inptr = input_buf[0][input_row++];
  151194. outptr = *output_buf++;
  151195. for (col = 0; col < num_cols; col++) {
  151196. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151197. outptr += RGB_PIXELSIZE;
  151198. }
  151199. }
  151200. }
  151201. METHODDEF(void)
  151202. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151203. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151204. JSAMPARRAY output_buf, int num_rows)
  151205. {
  151206. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151207. register int y, cb, cr;
  151208. register JSAMPROW outptr;
  151209. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151210. register JDIMENSION col;
  151211. JDIMENSION num_cols = cinfo->output_width;
  151212. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151213. register int * Crrtab = cconvert->Cr_r_tab;
  151214. register int * Cbbtab = cconvert->Cb_b_tab;
  151215. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151216. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151217. SHIFT_TEMPS
  151218. while (--num_rows >= 0) {
  151219. inptr0 = input_buf[0][input_row];
  151220. inptr1 = input_buf[1][input_row];
  151221. inptr2 = input_buf[2][input_row];
  151222. inptr3 = input_buf[3][input_row];
  151223. input_row++;
  151224. outptr = *output_buf++;
  151225. for (col = 0; col < num_cols; col++) {
  151226. y = GETJSAMPLE(inptr0[col]);
  151227. cb = GETJSAMPLE(inptr1[col]);
  151228. cr = GETJSAMPLE(inptr2[col]);
  151229. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151230. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151231. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151232. SCALEBITS)))];
  151233. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151234. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151235. outptr += 4;
  151236. }
  151237. }
  151238. }
  151239. METHODDEF(void)
  151240. start_pass_dcolor (j_decompress_ptr cinfo)
  151241. {
  151242. }
  151243. GLOBAL(void)
  151244. jinit_color_deconverter (j_decompress_ptr cinfo)
  151245. {
  151246. my_cconvert_ptr2 cconvert;
  151247. int ci;
  151248. cconvert = (my_cconvert_ptr2)
  151249. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151250. SIZEOF(my_color_deconverter2));
  151251. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151252. cconvert->pub.start_pass = start_pass_dcolor;
  151253. switch (cinfo->jpeg_color_space) {
  151254. case JCS_GRAYSCALE:
  151255. if (cinfo->num_components != 1)
  151256. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151257. break;
  151258. case JCS_RGB:
  151259. case JCS_YCbCr:
  151260. if (cinfo->num_components != 3)
  151261. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151262. break;
  151263. case JCS_CMYK:
  151264. case JCS_YCCK:
  151265. if (cinfo->num_components != 4)
  151266. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151267. break;
  151268. default: /* JCS_UNKNOWN can be anything */
  151269. if (cinfo->num_components < 1)
  151270. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151271. break;
  151272. }
  151273. switch (cinfo->out_color_space) {
  151274. case JCS_GRAYSCALE:
  151275. cinfo->out_color_components = 1;
  151276. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151277. cinfo->jpeg_color_space == JCS_YCbCr) {
  151278. cconvert->pub.color_convert = grayscale_convert2;
  151279. for (ci = 1; ci < cinfo->num_components; ci++)
  151280. cinfo->comp_info[ci].component_needed = FALSE;
  151281. } else
  151282. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151283. break;
  151284. case JCS_RGB:
  151285. cinfo->out_color_components = RGB_PIXELSIZE;
  151286. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151287. cconvert->pub.color_convert = ycc_rgb_convert;
  151288. build_ycc_rgb_table(cinfo);
  151289. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151290. cconvert->pub.color_convert = gray_rgb_convert;
  151291. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151292. cconvert->pub.color_convert = null_convert2;
  151293. } else
  151294. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151295. break;
  151296. case JCS_CMYK:
  151297. cinfo->out_color_components = 4;
  151298. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151299. cconvert->pub.color_convert = ycck_cmyk_convert;
  151300. build_ycc_rgb_table(cinfo);
  151301. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151302. cconvert->pub.color_convert = null_convert2;
  151303. } else
  151304. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151305. break;
  151306. default:
  151307. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151308. cinfo->out_color_components = cinfo->num_components;
  151309. cconvert->pub.color_convert = null_convert2;
  151310. } else /* unsupported non-null conversion */
  151311. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151312. break;
  151313. }
  151314. if (cinfo->quantize_colors)
  151315. cinfo->output_components = 1; /* single colormapped output component */
  151316. else
  151317. cinfo->output_components = cinfo->out_color_components;
  151318. }
  151319. /*** End of inlined file: jdcolor.c ***/
  151320. #undef FIX
  151321. /*** Start of inlined file: jddctmgr.c ***/
  151322. #define JPEG_INTERNALS
  151323. typedef struct {
  151324. struct jpeg_inverse_dct pub; /* public fields */
  151325. int cur_method[MAX_COMPONENTS];
  151326. } my_idct_controller;
  151327. typedef my_idct_controller * my_idct_ptr;
  151328. typedef union {
  151329. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151330. #ifdef DCT_IFAST_SUPPORTED
  151331. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151332. #endif
  151333. #ifdef DCT_FLOAT_SUPPORTED
  151334. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151335. #endif
  151336. } multiplier_table;
  151337. #ifdef DCT_ISLOW_SUPPORTED
  151338. #define PROVIDE_ISLOW_TABLES
  151339. #else
  151340. #ifdef IDCT_SCALING_SUPPORTED
  151341. #define PROVIDE_ISLOW_TABLES
  151342. #endif
  151343. #endif
  151344. METHODDEF(void)
  151345. start_pass (j_decompress_ptr cinfo)
  151346. {
  151347. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151348. int ci, i;
  151349. jpeg_component_info *compptr;
  151350. int method = 0;
  151351. inverse_DCT_method_ptr method_ptr = NULL;
  151352. JQUANT_TBL * qtbl;
  151353. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151354. ci++, compptr++) {
  151355. switch (compptr->DCT_scaled_size) {
  151356. #ifdef IDCT_SCALING_SUPPORTED
  151357. case 1:
  151358. method_ptr = jpeg_idct_1x1;
  151359. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151360. break;
  151361. case 2:
  151362. method_ptr = jpeg_idct_2x2;
  151363. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151364. break;
  151365. case 4:
  151366. method_ptr = jpeg_idct_4x4;
  151367. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151368. break;
  151369. #endif
  151370. case DCTSIZE:
  151371. switch (cinfo->dct_method) {
  151372. #ifdef DCT_ISLOW_SUPPORTED
  151373. case JDCT_ISLOW:
  151374. method_ptr = jpeg_idct_islow;
  151375. method = JDCT_ISLOW;
  151376. break;
  151377. #endif
  151378. #ifdef DCT_IFAST_SUPPORTED
  151379. case JDCT_IFAST:
  151380. method_ptr = jpeg_idct_ifast;
  151381. method = JDCT_IFAST;
  151382. break;
  151383. #endif
  151384. #ifdef DCT_FLOAT_SUPPORTED
  151385. case JDCT_FLOAT:
  151386. method_ptr = jpeg_idct_float;
  151387. method = JDCT_FLOAT;
  151388. break;
  151389. #endif
  151390. default:
  151391. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151392. break;
  151393. }
  151394. break;
  151395. default:
  151396. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151397. break;
  151398. }
  151399. idct->pub.inverse_DCT[ci] = method_ptr;
  151400. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151401. continue;
  151402. qtbl = compptr->quant_table;
  151403. if (qtbl == NULL) /* happens if no data yet for component */
  151404. continue;
  151405. idct->cur_method[ci] = method;
  151406. switch (method) {
  151407. #ifdef PROVIDE_ISLOW_TABLES
  151408. case JDCT_ISLOW:
  151409. {
  151410. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151411. for (i = 0; i < DCTSIZE2; i++) {
  151412. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151413. }
  151414. }
  151415. break;
  151416. #endif
  151417. #ifdef DCT_IFAST_SUPPORTED
  151418. case JDCT_IFAST:
  151419. {
  151420. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151421. #define CONST_BITS 14
  151422. static const INT16 aanscales[DCTSIZE2] = {
  151423. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151424. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151425. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151426. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151427. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151428. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151429. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151430. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151431. };
  151432. SHIFT_TEMPS
  151433. for (i = 0; i < DCTSIZE2; i++) {
  151434. ifmtbl[i] = (IFAST_MULT_TYPE)
  151435. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151436. (INT32) aanscales[i]),
  151437. CONST_BITS-IFAST_SCALE_BITS);
  151438. }
  151439. }
  151440. break;
  151441. #endif
  151442. #ifdef DCT_FLOAT_SUPPORTED
  151443. case JDCT_FLOAT:
  151444. {
  151445. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151446. int row, col;
  151447. static const double aanscalefactor[DCTSIZE] = {
  151448. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151449. 1.0, 0.785694958, 0.541196100, 0.275899379
  151450. };
  151451. i = 0;
  151452. for (row = 0; row < DCTSIZE; row++) {
  151453. for (col = 0; col < DCTSIZE; col++) {
  151454. fmtbl[i] = (FLOAT_MULT_TYPE)
  151455. ((double) qtbl->quantval[i] *
  151456. aanscalefactor[row] * aanscalefactor[col]);
  151457. i++;
  151458. }
  151459. }
  151460. }
  151461. break;
  151462. #endif
  151463. default:
  151464. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151465. break;
  151466. }
  151467. }
  151468. }
  151469. GLOBAL(void)
  151470. jinit_inverse_dct (j_decompress_ptr cinfo)
  151471. {
  151472. my_idct_ptr idct;
  151473. int ci;
  151474. jpeg_component_info *compptr;
  151475. idct = (my_idct_ptr)
  151476. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151477. SIZEOF(my_idct_controller));
  151478. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151479. idct->pub.start_pass = start_pass;
  151480. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151481. ci++, compptr++) {
  151482. compptr->dct_table =
  151483. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151484. SIZEOF(multiplier_table));
  151485. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151486. idct->cur_method[ci] = -1;
  151487. }
  151488. }
  151489. /*** End of inlined file: jddctmgr.c ***/
  151490. #undef CONST_BITS
  151491. #undef ASSIGN_STATE
  151492. /*** Start of inlined file: jdhuff.c ***/
  151493. #define JPEG_INTERNALS
  151494. /*** Start of inlined file: jdhuff.h ***/
  151495. #ifndef __jdhuff_h__
  151496. #define __jdhuff_h__
  151497. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151498. #define jpeg_make_d_derived_tbl jMkDDerived
  151499. #define jpeg_fill_bit_buffer jFilBitBuf
  151500. #define jpeg_huff_decode jHufDecode
  151501. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151502. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151503. typedef struct {
  151504. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151505. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151506. JHUFF_TBL *pub;
  151507. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151508. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151509. } d_derived_tbl;
  151510. EXTERN(void) jpeg_make_d_derived_tbl
  151511. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151512. d_derived_tbl ** pdtbl));
  151513. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151514. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151515. typedef struct { /* Bitreading state saved across MCUs */
  151516. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151517. int bits_left; /* # of unused bits in it */
  151518. } bitread_perm_state;
  151519. typedef struct { /* Bitreading working state within an MCU */
  151520. const JOCTET * next_input_byte; /* => next byte to read from source */
  151521. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151522. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151523. int bits_left; /* # of unused bits in it */
  151524. j_decompress_ptr cinfo; /* back link to decompress master record */
  151525. } bitread_working_state;
  151526. #define BITREAD_STATE_VARS \
  151527. register bit_buf_type get_buffer; \
  151528. register int bits_left; \
  151529. bitread_working_state br_state
  151530. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151531. br_state.cinfo = cinfop; \
  151532. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151533. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151534. get_buffer = permstate.get_buffer; \
  151535. bits_left = permstate.bits_left;
  151536. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151537. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151538. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151539. permstate.get_buffer = get_buffer; \
  151540. permstate.bits_left = bits_left
  151541. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151542. { if (bits_left < (nbits)) { \
  151543. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151544. { action; } \
  151545. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151546. #define GET_BITS(nbits) \
  151547. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151548. #define PEEK_BITS(nbits) \
  151549. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151550. #define DROP_BITS(nbits) \
  151551. (bits_left -= (nbits))
  151552. EXTERN(boolean) jpeg_fill_bit_buffer
  151553. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151554. register int bits_left, int nbits));
  151555. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151556. { register int nb, look; \
  151557. if (bits_left < HUFF_LOOKAHEAD) { \
  151558. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151559. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151560. if (bits_left < HUFF_LOOKAHEAD) { \
  151561. nb = 1; goto slowlabel; \
  151562. } \
  151563. } \
  151564. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151565. if ((nb = htbl->look_nbits[look]) != 0) { \
  151566. DROP_BITS(nb); \
  151567. result = htbl->look_sym[look]; \
  151568. } else { \
  151569. nb = HUFF_LOOKAHEAD+1; \
  151570. slowlabel: \
  151571. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151572. { failaction; } \
  151573. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151574. } \
  151575. }
  151576. EXTERN(int) jpeg_huff_decode
  151577. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151578. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151579. #endif
  151580. /*** End of inlined file: jdhuff.h ***/
  151581. /* Declarations shared with jdphuff.c */
  151582. typedef struct {
  151583. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151584. } savable_state2;
  151585. #ifndef NO_STRUCT_ASSIGN
  151586. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151587. #else
  151588. #if MAX_COMPS_IN_SCAN == 4
  151589. #define ASSIGN_STATE(dest,src) \
  151590. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151591. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151592. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151593. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151594. #endif
  151595. #endif
  151596. typedef struct {
  151597. struct jpeg_entropy_decoder pub; /* public fields */
  151598. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151599. savable_state2 saved; /* Other state at start of MCU */
  151600. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151601. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151602. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151603. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151604. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151605. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151606. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151607. } huff_entropy_decoder2;
  151608. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151609. METHODDEF(void)
  151610. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151611. {
  151612. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151613. int ci, blkn, dctbl, actbl;
  151614. jpeg_component_info * compptr;
  151615. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151616. cinfo->Ah != 0 || cinfo->Al != 0)
  151617. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151618. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151619. compptr = cinfo->cur_comp_info[ci];
  151620. dctbl = compptr->dc_tbl_no;
  151621. actbl = compptr->ac_tbl_no;
  151622. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151623. & entropy->dc_derived_tbls[dctbl]);
  151624. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151625. & entropy->ac_derived_tbls[actbl]);
  151626. entropy->saved.last_dc_val[ci] = 0;
  151627. }
  151628. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151629. ci = cinfo->MCU_membership[blkn];
  151630. compptr = cinfo->cur_comp_info[ci];
  151631. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151632. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151633. if (compptr->component_needed) {
  151634. entropy->dc_needed[blkn] = TRUE;
  151635. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151636. } else {
  151637. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151638. }
  151639. }
  151640. entropy->bitstate.bits_left = 0;
  151641. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151642. entropy->pub.insufficient_data = FALSE;
  151643. entropy->restarts_to_go = cinfo->restart_interval;
  151644. }
  151645. GLOBAL(void)
  151646. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151647. d_derived_tbl ** pdtbl)
  151648. {
  151649. JHUFF_TBL *htbl;
  151650. d_derived_tbl *dtbl;
  151651. int p, i, l, si, numsymbols;
  151652. int lookbits, ctr;
  151653. char huffsize[257];
  151654. unsigned int huffcode[257];
  151655. unsigned int code;
  151656. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151657. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151658. htbl =
  151659. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151660. if (htbl == NULL)
  151661. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151662. if (*pdtbl == NULL)
  151663. *pdtbl = (d_derived_tbl *)
  151664. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151665. SIZEOF(d_derived_tbl));
  151666. dtbl = *pdtbl;
  151667. dtbl->pub = htbl; /* fill in back link */
  151668. p = 0;
  151669. for (l = 1; l <= 16; l++) {
  151670. i = (int) htbl->bits[l];
  151671. if (i < 0 || p + i > 256) /* protect against table overrun */
  151672. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151673. while (i--)
  151674. huffsize[p++] = (char) l;
  151675. }
  151676. huffsize[p] = 0;
  151677. numsymbols = p;
  151678. code = 0;
  151679. si = huffsize[0];
  151680. p = 0;
  151681. while (huffsize[p]) {
  151682. while (((int) huffsize[p]) == si) {
  151683. huffcode[p++] = code;
  151684. code++;
  151685. }
  151686. if (((INT32) code) >= (((INT32) 1) << si))
  151687. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151688. code <<= 1;
  151689. si++;
  151690. }
  151691. p = 0;
  151692. for (l = 1; l <= 16; l++) {
  151693. if (htbl->bits[l]) {
  151694. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151695. p += htbl->bits[l];
  151696. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151697. } else {
  151698. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  151699. }
  151700. }
  151701. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  151702. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  151703. p = 0;
  151704. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  151705. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  151706. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  151707. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  151708. dtbl->look_nbits[lookbits] = l;
  151709. dtbl->look_sym[lookbits] = htbl->huffval[p];
  151710. lookbits++;
  151711. }
  151712. }
  151713. }
  151714. if (isDC) {
  151715. for (i = 0; i < numsymbols; i++) {
  151716. int sym = htbl->huffval[i];
  151717. if (sym < 0 || sym > 15)
  151718. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151719. }
  151720. }
  151721. }
  151722. #ifdef SLOW_SHIFT_32
  151723. #define MIN_GET_BITS 15 /* minimum allowable value */
  151724. #else
  151725. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  151726. #endif
  151727. GLOBAL(boolean)
  151728. jpeg_fill_bit_buffer (bitread_working_state * state,
  151729. register bit_buf_type get_buffer, register int bits_left,
  151730. int nbits)
  151731. {
  151732. register const JOCTET * next_input_byte = state->next_input_byte;
  151733. register size_t bytes_in_buffer = state->bytes_in_buffer;
  151734. j_decompress_ptr cinfo = state->cinfo;
  151735. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  151736. while (bits_left < MIN_GET_BITS) {
  151737. register int c;
  151738. if (bytes_in_buffer == 0) {
  151739. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151740. return FALSE;
  151741. next_input_byte = cinfo->src->next_input_byte;
  151742. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151743. }
  151744. bytes_in_buffer--;
  151745. c = GETJOCTET(*next_input_byte++);
  151746. if (c == 0xFF) {
  151747. do {
  151748. if (bytes_in_buffer == 0) {
  151749. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151750. return FALSE;
  151751. next_input_byte = cinfo->src->next_input_byte;
  151752. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151753. }
  151754. bytes_in_buffer--;
  151755. c = GETJOCTET(*next_input_byte++);
  151756. } while (c == 0xFF);
  151757. if (c == 0) {
  151758. c = 0xFF;
  151759. } else {
  151760. cinfo->unread_marker = c;
  151761. goto no_more_bytes;
  151762. }
  151763. }
  151764. get_buffer = (get_buffer << 8) | c;
  151765. bits_left += 8;
  151766. } /* end while */
  151767. } else {
  151768. no_more_bytes:
  151769. if (nbits > bits_left) {
  151770. if (! cinfo->entropy->insufficient_data) {
  151771. WARNMS(cinfo, JWRN_HIT_MARKER);
  151772. cinfo->entropy->insufficient_data = TRUE;
  151773. }
  151774. get_buffer <<= MIN_GET_BITS - bits_left;
  151775. bits_left = MIN_GET_BITS;
  151776. }
  151777. }
  151778. state->next_input_byte = next_input_byte;
  151779. state->bytes_in_buffer = bytes_in_buffer;
  151780. state->get_buffer = get_buffer;
  151781. state->bits_left = bits_left;
  151782. return TRUE;
  151783. }
  151784. GLOBAL(int)
  151785. jpeg_huff_decode (bitread_working_state * state,
  151786. register bit_buf_type get_buffer, register int bits_left,
  151787. d_derived_tbl * htbl, int min_bits)
  151788. {
  151789. register int l = min_bits;
  151790. register INT32 code;
  151791. CHECK_BIT_BUFFER(*state, l, return -1);
  151792. code = GET_BITS(l);
  151793. while (code > htbl->maxcode[l]) {
  151794. code <<= 1;
  151795. CHECK_BIT_BUFFER(*state, 1, return -1);
  151796. code |= GET_BITS(1);
  151797. l++;
  151798. }
  151799. state->get_buffer = get_buffer;
  151800. state->bits_left = bits_left;
  151801. if (l > 16) {
  151802. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  151803. return 0; /* fake a zero as the safest result */
  151804. }
  151805. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  151806. }
  151807. LOCAL(boolean)
  151808. process_restart (j_decompress_ptr cinfo)
  151809. {
  151810. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151811. int ci;
  151812. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  151813. entropy->bitstate.bits_left = 0;
  151814. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  151815. return FALSE;
  151816. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  151817. entropy->saved.last_dc_val[ci] = 0;
  151818. entropy->restarts_to_go = cinfo->restart_interval;
  151819. if (cinfo->unread_marker == 0)
  151820. entropy->pub.insufficient_data = FALSE;
  151821. return TRUE;
  151822. }
  151823. METHODDEF(boolean)
  151824. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  151825. {
  151826. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151827. int blkn;
  151828. BITREAD_STATE_VARS;
  151829. savable_state2 state;
  151830. if (cinfo->restart_interval) {
  151831. if (entropy->restarts_to_go == 0)
  151832. if (! process_restart(cinfo))
  151833. return FALSE;
  151834. }
  151835. if (! entropy->pub.insufficient_data) {
  151836. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  151837. ASSIGN_STATE(state, entropy->saved);
  151838. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151839. JBLOCKROW block = MCU_data[blkn];
  151840. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  151841. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  151842. register int s, k, r;
  151843. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  151844. if (s) {
  151845. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151846. r = GET_BITS(s);
  151847. s = HUFF_EXTEND(r, s);
  151848. }
  151849. if (entropy->dc_needed[blkn]) {
  151850. int ci = cinfo->MCU_membership[blkn];
  151851. s += state.last_dc_val[ci];
  151852. state.last_dc_val[ci] = s;
  151853. (*block)[0] = (JCOEF) s;
  151854. }
  151855. if (entropy->ac_needed[blkn]) {
  151856. for (k = 1; k < DCTSIZE2; k++) {
  151857. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  151858. r = s >> 4;
  151859. s &= 15;
  151860. if (s) {
  151861. k += r;
  151862. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151863. r = GET_BITS(s);
  151864. s = HUFF_EXTEND(r, s);
  151865. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  151866. } else {
  151867. if (r != 15)
  151868. break;
  151869. k += 15;
  151870. }
  151871. }
  151872. } else {
  151873. for (k = 1; k < DCTSIZE2; k++) {
  151874. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  151875. r = s >> 4;
  151876. s &= 15;
  151877. if (s) {
  151878. k += r;
  151879. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151880. DROP_BITS(s);
  151881. } else {
  151882. if (r != 15)
  151883. break;
  151884. k += 15;
  151885. }
  151886. }
  151887. }
  151888. }
  151889. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  151890. ASSIGN_STATE(entropy->saved, state);
  151891. }
  151892. entropy->restarts_to_go--;
  151893. return TRUE;
  151894. }
  151895. GLOBAL(void)
  151896. jinit_huff_decoder (j_decompress_ptr cinfo)
  151897. {
  151898. huff_entropy_ptr2 entropy;
  151899. int i;
  151900. entropy = (huff_entropy_ptr2)
  151901. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151902. SIZEOF(huff_entropy_decoder2));
  151903. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  151904. entropy->pub.start_pass = start_pass_huff_decoder;
  151905. entropy->pub.decode_mcu = decode_mcu;
  151906. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  151907. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  151908. }
  151909. }
  151910. /*** End of inlined file: jdhuff.c ***/
  151911. /*** Start of inlined file: jdinput.c ***/
  151912. #define JPEG_INTERNALS
  151913. typedef struct {
  151914. struct jpeg_input_controller pub; /* public fields */
  151915. boolean inheaders; /* TRUE until first SOS is reached */
  151916. } my_input_controller;
  151917. typedef my_input_controller * my_inputctl_ptr;
  151918. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  151919. LOCAL(void)
  151920. initial_setup2 (j_decompress_ptr cinfo)
  151921. {
  151922. int ci;
  151923. jpeg_component_info *compptr;
  151924. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  151925. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  151926. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  151927. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  151928. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  151929. if (cinfo->num_components > MAX_COMPONENTS)
  151930. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  151931. MAX_COMPONENTS);
  151932. cinfo->max_h_samp_factor = 1;
  151933. cinfo->max_v_samp_factor = 1;
  151934. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151935. ci++, compptr++) {
  151936. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  151937. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  151938. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  151939. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  151940. compptr->h_samp_factor);
  151941. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  151942. compptr->v_samp_factor);
  151943. }
  151944. cinfo->min_DCT_scaled_size = DCTSIZE;
  151945. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151946. ci++, compptr++) {
  151947. compptr->DCT_scaled_size = DCTSIZE;
  151948. compptr->width_in_blocks = (JDIMENSION)
  151949. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  151950. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  151951. compptr->height_in_blocks = (JDIMENSION)
  151952. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  151953. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  151954. compptr->downsampled_width = (JDIMENSION)
  151955. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  151956. (long) cinfo->max_h_samp_factor);
  151957. compptr->downsampled_height = (JDIMENSION)
  151958. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  151959. (long) cinfo->max_v_samp_factor);
  151960. compptr->component_needed = TRUE;
  151961. compptr->quant_table = NULL;
  151962. }
  151963. cinfo->total_iMCU_rows = (JDIMENSION)
  151964. jdiv_round_up((long) cinfo->image_height,
  151965. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  151966. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  151967. cinfo->inputctl->has_multiple_scans = TRUE;
  151968. else
  151969. cinfo->inputctl->has_multiple_scans = FALSE;
  151970. }
  151971. LOCAL(void)
  151972. per_scan_setup2 (j_decompress_ptr cinfo)
  151973. {
  151974. int ci, mcublks, tmp;
  151975. jpeg_component_info *compptr;
  151976. if (cinfo->comps_in_scan == 1) {
  151977. compptr = cinfo->cur_comp_info[0];
  151978. cinfo->MCUs_per_row = compptr->width_in_blocks;
  151979. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  151980. compptr->MCU_width = 1;
  151981. compptr->MCU_height = 1;
  151982. compptr->MCU_blocks = 1;
  151983. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  151984. compptr->last_col_width = 1;
  151985. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151986. if (tmp == 0) tmp = compptr->v_samp_factor;
  151987. compptr->last_row_height = tmp;
  151988. cinfo->blocks_in_MCU = 1;
  151989. cinfo->MCU_membership[0] = 0;
  151990. } else {
  151991. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  151992. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  151993. MAX_COMPS_IN_SCAN);
  151994. cinfo->MCUs_per_row = (JDIMENSION)
  151995. jdiv_round_up((long) cinfo->image_width,
  151996. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  151997. cinfo->MCU_rows_in_scan = (JDIMENSION)
  151998. jdiv_round_up((long) cinfo->image_height,
  151999. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152000. cinfo->blocks_in_MCU = 0;
  152001. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152002. compptr = cinfo->cur_comp_info[ci];
  152003. compptr->MCU_width = compptr->h_samp_factor;
  152004. compptr->MCU_height = compptr->v_samp_factor;
  152005. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152006. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152007. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152008. if (tmp == 0) tmp = compptr->MCU_width;
  152009. compptr->last_col_width = tmp;
  152010. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152011. if (tmp == 0) tmp = compptr->MCU_height;
  152012. compptr->last_row_height = tmp;
  152013. mcublks = compptr->MCU_blocks;
  152014. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152015. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152016. while (mcublks-- > 0) {
  152017. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152018. }
  152019. }
  152020. }
  152021. }
  152022. LOCAL(void)
  152023. latch_quant_tables (j_decompress_ptr cinfo)
  152024. {
  152025. int ci, qtblno;
  152026. jpeg_component_info *compptr;
  152027. JQUANT_TBL * qtbl;
  152028. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152029. compptr = cinfo->cur_comp_info[ci];
  152030. if (compptr->quant_table != NULL)
  152031. continue;
  152032. qtblno = compptr->quant_tbl_no;
  152033. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152034. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152035. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152036. qtbl = (JQUANT_TBL *)
  152037. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152038. SIZEOF(JQUANT_TBL));
  152039. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152040. compptr->quant_table = qtbl;
  152041. }
  152042. }
  152043. METHODDEF(void)
  152044. start_input_pass2 (j_decompress_ptr cinfo)
  152045. {
  152046. per_scan_setup2(cinfo);
  152047. latch_quant_tables(cinfo);
  152048. (*cinfo->entropy->start_pass) (cinfo);
  152049. (*cinfo->coef->start_input_pass) (cinfo);
  152050. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152051. }
  152052. METHODDEF(void)
  152053. finish_input_pass (j_decompress_ptr cinfo)
  152054. {
  152055. cinfo->inputctl->consume_input = consume_markers;
  152056. }
  152057. METHODDEF(int)
  152058. consume_markers (j_decompress_ptr cinfo)
  152059. {
  152060. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152061. int val;
  152062. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152063. return JPEG_REACHED_EOI;
  152064. val = (*cinfo->marker->read_markers) (cinfo);
  152065. switch (val) {
  152066. case JPEG_REACHED_SOS: /* Found SOS */
  152067. if (inputctl->inheaders) { /* 1st SOS */
  152068. initial_setup2(cinfo);
  152069. inputctl->inheaders = FALSE;
  152070. } else { /* 2nd or later SOS marker */
  152071. if (! inputctl->pub.has_multiple_scans)
  152072. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152073. start_input_pass2(cinfo);
  152074. }
  152075. break;
  152076. case JPEG_REACHED_EOI: /* Found EOI */
  152077. inputctl->pub.eoi_reached = TRUE;
  152078. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152079. if (cinfo->marker->saw_SOF)
  152080. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152081. } else {
  152082. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152083. cinfo->output_scan_number = cinfo->input_scan_number;
  152084. }
  152085. break;
  152086. case JPEG_SUSPENDED:
  152087. break;
  152088. }
  152089. return val;
  152090. }
  152091. METHODDEF(void)
  152092. reset_input_controller (j_decompress_ptr cinfo)
  152093. {
  152094. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152095. inputctl->pub.consume_input = consume_markers;
  152096. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152097. inputctl->pub.eoi_reached = FALSE;
  152098. inputctl->inheaders = TRUE;
  152099. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152100. (*cinfo->marker->reset_marker_reader) (cinfo);
  152101. cinfo->coef_bits = NULL;
  152102. }
  152103. GLOBAL(void)
  152104. jinit_input_controller (j_decompress_ptr cinfo)
  152105. {
  152106. my_inputctl_ptr inputctl;
  152107. inputctl = (my_inputctl_ptr)
  152108. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152109. SIZEOF(my_input_controller));
  152110. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152111. inputctl->pub.consume_input = consume_markers;
  152112. inputctl->pub.reset_input_controller = reset_input_controller;
  152113. inputctl->pub.start_input_pass = start_input_pass2;
  152114. inputctl->pub.finish_input_pass = finish_input_pass;
  152115. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152116. inputctl->pub.eoi_reached = FALSE;
  152117. inputctl->inheaders = TRUE;
  152118. }
  152119. /*** End of inlined file: jdinput.c ***/
  152120. /*** Start of inlined file: jdmainct.c ***/
  152121. #define JPEG_INTERNALS
  152122. typedef struct {
  152123. struct jpeg_d_main_controller pub; /* public fields */
  152124. JSAMPARRAY buffer[MAX_COMPONENTS];
  152125. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152126. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152127. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152128. int whichptr; /* indicates which pointer set is now in use */
  152129. int context_state; /* process_data state machine status */
  152130. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152131. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152132. } my_main_controller4;
  152133. typedef my_main_controller4 * my_main_ptr4;
  152134. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152135. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152136. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152137. METHODDEF(void) process_data_simple_main2
  152138. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152139. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152140. METHODDEF(void) process_data_context_main
  152141. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152142. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152143. #ifdef QUANT_2PASS_SUPPORTED
  152144. METHODDEF(void) process_data_crank_post
  152145. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152146. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152147. #endif
  152148. LOCAL(void)
  152149. alloc_funny_pointers (j_decompress_ptr cinfo)
  152150. {
  152151. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152152. int ci, rgroup;
  152153. int M = cinfo->min_DCT_scaled_size;
  152154. jpeg_component_info *compptr;
  152155. JSAMPARRAY xbuf;
  152156. main_->xbuffer[0] = (JSAMPIMAGE)
  152157. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152158. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152159. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152160. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152161. ci++, compptr++) {
  152162. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152163. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152164. xbuf = (JSAMPARRAY)
  152165. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152166. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152167. xbuf += rgroup; /* want one row group at negative offsets */
  152168. main_->xbuffer[0][ci] = xbuf;
  152169. xbuf += rgroup * (M + 4);
  152170. main_->xbuffer[1][ci] = xbuf;
  152171. }
  152172. }
  152173. LOCAL(void)
  152174. make_funny_pointers (j_decompress_ptr cinfo)
  152175. {
  152176. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152177. int ci, i, rgroup;
  152178. int M = cinfo->min_DCT_scaled_size;
  152179. jpeg_component_info *compptr;
  152180. JSAMPARRAY buf, xbuf0, xbuf1;
  152181. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152182. ci++, compptr++) {
  152183. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152184. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152185. xbuf0 = main_->xbuffer[0][ci];
  152186. xbuf1 = main_->xbuffer[1][ci];
  152187. buf = main_->buffer[ci];
  152188. for (i = 0; i < rgroup * (M + 2); i++) {
  152189. xbuf0[i] = xbuf1[i] = buf[i];
  152190. }
  152191. for (i = 0; i < rgroup * 2; i++) {
  152192. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152193. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152194. }
  152195. for (i = 0; i < rgroup; i++) {
  152196. xbuf0[i - rgroup] = xbuf0[0];
  152197. }
  152198. }
  152199. }
  152200. LOCAL(void)
  152201. set_wraparound_pointers (j_decompress_ptr cinfo)
  152202. {
  152203. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152204. int ci, i, rgroup;
  152205. int M = cinfo->min_DCT_scaled_size;
  152206. jpeg_component_info *compptr;
  152207. JSAMPARRAY xbuf0, xbuf1;
  152208. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152209. ci++, compptr++) {
  152210. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152211. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152212. xbuf0 = main_->xbuffer[0][ci];
  152213. xbuf1 = main_->xbuffer[1][ci];
  152214. for (i = 0; i < rgroup; i++) {
  152215. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152216. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152217. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152218. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152219. }
  152220. }
  152221. }
  152222. LOCAL(void)
  152223. set_bottom_pointers (j_decompress_ptr cinfo)
  152224. {
  152225. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152226. int ci, i, rgroup, iMCUheight, rows_left;
  152227. jpeg_component_info *compptr;
  152228. JSAMPARRAY xbuf;
  152229. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152230. ci++, compptr++) {
  152231. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152232. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152233. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152234. if (rows_left == 0) rows_left = iMCUheight;
  152235. if (ci == 0) {
  152236. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152237. }
  152238. xbuf = main_->xbuffer[main_->whichptr][ci];
  152239. for (i = 0; i < rgroup * 2; i++) {
  152240. xbuf[rows_left + i] = xbuf[rows_left-1];
  152241. }
  152242. }
  152243. }
  152244. METHODDEF(void)
  152245. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152246. {
  152247. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152248. switch (pass_mode) {
  152249. case JBUF_PASS_THRU:
  152250. if (cinfo->upsample->need_context_rows) {
  152251. main_->pub.process_data = process_data_context_main;
  152252. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152253. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152254. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152255. main_->iMCU_row_ctr = 0;
  152256. } else {
  152257. main_->pub.process_data = process_data_simple_main2;
  152258. }
  152259. main_->buffer_full = FALSE; /* Mark buffer empty */
  152260. main_->rowgroup_ctr = 0;
  152261. break;
  152262. #ifdef QUANT_2PASS_SUPPORTED
  152263. case JBUF_CRANK_DEST:
  152264. main_->pub.process_data = process_data_crank_post;
  152265. break;
  152266. #endif
  152267. default:
  152268. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152269. break;
  152270. }
  152271. }
  152272. METHODDEF(void)
  152273. process_data_simple_main2 (j_decompress_ptr cinfo,
  152274. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152275. JDIMENSION out_rows_avail)
  152276. {
  152277. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152278. JDIMENSION rowgroups_avail;
  152279. if (! main_->buffer_full) {
  152280. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152281. return; /* suspension forced, can do nothing more */
  152282. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152283. }
  152284. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152285. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152286. &main_->rowgroup_ctr, rowgroups_avail,
  152287. output_buf, out_row_ctr, out_rows_avail);
  152288. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152289. main_->buffer_full = FALSE;
  152290. main_->rowgroup_ctr = 0;
  152291. }
  152292. }
  152293. METHODDEF(void)
  152294. process_data_context_main (j_decompress_ptr cinfo,
  152295. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152296. JDIMENSION out_rows_avail)
  152297. {
  152298. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152299. if (! main_->buffer_full) {
  152300. if (! (*cinfo->coef->decompress_data) (cinfo,
  152301. main_->xbuffer[main_->whichptr]))
  152302. return; /* suspension forced, can do nothing more */
  152303. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152304. main_->iMCU_row_ctr++; /* count rows received */
  152305. }
  152306. switch (main_->context_state) {
  152307. case CTX_POSTPONED_ROW:
  152308. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152309. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152310. output_buf, out_row_ctr, out_rows_avail);
  152311. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152312. return; /* Need to suspend */
  152313. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152314. if (*out_row_ctr >= out_rows_avail)
  152315. return; /* Postprocessor exactly filled output buf */
  152316. case CTX_PREPARE_FOR_IMCU:
  152317. main_->rowgroup_ctr = 0;
  152318. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152319. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152320. set_bottom_pointers(cinfo);
  152321. main_->context_state = CTX_PROCESS_IMCU;
  152322. case CTX_PROCESS_IMCU:
  152323. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152324. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152325. output_buf, out_row_ctr, out_rows_avail);
  152326. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152327. return; /* Need to suspend */
  152328. if (main_->iMCU_row_ctr == 1)
  152329. set_wraparound_pointers(cinfo);
  152330. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152331. main_->buffer_full = FALSE;
  152332. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152333. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152334. main_->context_state = CTX_POSTPONED_ROW;
  152335. }
  152336. }
  152337. #ifdef QUANT_2PASS_SUPPORTED
  152338. METHODDEF(void)
  152339. process_data_crank_post (j_decompress_ptr cinfo,
  152340. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152341. JDIMENSION out_rows_avail)
  152342. {
  152343. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152344. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152345. output_buf, out_row_ctr, out_rows_avail);
  152346. }
  152347. #endif /* QUANT_2PASS_SUPPORTED */
  152348. GLOBAL(void)
  152349. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152350. {
  152351. my_main_ptr4 main_;
  152352. int ci, rgroup, ngroups;
  152353. jpeg_component_info *compptr;
  152354. main_ = (my_main_ptr4)
  152355. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152356. SIZEOF(my_main_controller4));
  152357. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152358. main_->pub.start_pass = start_pass_main2;
  152359. if (need_full_buffer) /* shouldn't happen */
  152360. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152361. if (cinfo->upsample->need_context_rows) {
  152362. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152363. ERREXIT(cinfo, JERR_NOTIMPL);
  152364. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152365. ngroups = cinfo->min_DCT_scaled_size + 2;
  152366. } else {
  152367. ngroups = cinfo->min_DCT_scaled_size;
  152368. }
  152369. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152370. ci++, compptr++) {
  152371. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152372. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152373. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152374. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152375. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152376. (JDIMENSION) (rgroup * ngroups));
  152377. }
  152378. }
  152379. /*** End of inlined file: jdmainct.c ***/
  152380. /*** Start of inlined file: jdmarker.c ***/
  152381. #define JPEG_INTERNALS
  152382. typedef struct {
  152383. struct jpeg_marker_reader pub; /* public fields */
  152384. jpeg_marker_parser_method process_COM;
  152385. jpeg_marker_parser_method process_APPn[16];
  152386. unsigned int length_limit_COM;
  152387. unsigned int length_limit_APPn[16];
  152388. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152389. unsigned int bytes_read; /* data bytes read so far in marker */
  152390. } my_marker_reader;
  152391. typedef my_marker_reader * my_marker_ptr2;
  152392. #define INPUT_VARS(cinfo) \
  152393. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152394. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152395. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152396. #define INPUT_SYNC(cinfo) \
  152397. ( datasrc->next_input_byte = next_input_byte, \
  152398. datasrc->bytes_in_buffer = bytes_in_buffer )
  152399. #define INPUT_RELOAD(cinfo) \
  152400. ( next_input_byte = datasrc->next_input_byte, \
  152401. bytes_in_buffer = datasrc->bytes_in_buffer )
  152402. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152403. if (bytes_in_buffer == 0) { \
  152404. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152405. { action; } \
  152406. INPUT_RELOAD(cinfo); \
  152407. }
  152408. #define INPUT_BYTE(cinfo,V,action) \
  152409. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152410. bytes_in_buffer--; \
  152411. V = GETJOCTET(*next_input_byte++); )
  152412. #define INPUT_2BYTES(cinfo,V,action) \
  152413. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152414. bytes_in_buffer--; \
  152415. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152416. MAKE_BYTE_AVAIL(cinfo,action); \
  152417. bytes_in_buffer--; \
  152418. V += GETJOCTET(*next_input_byte++); )
  152419. LOCAL(boolean)
  152420. get_soi (j_decompress_ptr cinfo)
  152421. {
  152422. int i;
  152423. TRACEMS(cinfo, 1, JTRC_SOI);
  152424. if (cinfo->marker->saw_SOI)
  152425. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152426. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152427. cinfo->arith_dc_L[i] = 0;
  152428. cinfo->arith_dc_U[i] = 1;
  152429. cinfo->arith_ac_K[i] = 5;
  152430. }
  152431. cinfo->restart_interval = 0;
  152432. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152433. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152434. cinfo->saw_JFIF_marker = FALSE;
  152435. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152436. cinfo->JFIF_minor_version = 1;
  152437. cinfo->density_unit = 0;
  152438. cinfo->X_density = 1;
  152439. cinfo->Y_density = 1;
  152440. cinfo->saw_Adobe_marker = FALSE;
  152441. cinfo->Adobe_transform = 0;
  152442. cinfo->marker->saw_SOI = TRUE;
  152443. return TRUE;
  152444. }
  152445. LOCAL(boolean)
  152446. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152447. {
  152448. INT32 length;
  152449. int c, ci;
  152450. jpeg_component_info * compptr;
  152451. INPUT_VARS(cinfo);
  152452. cinfo->progressive_mode = is_prog;
  152453. cinfo->arith_code = is_arith;
  152454. INPUT_2BYTES(cinfo, length, return FALSE);
  152455. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152456. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152457. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152458. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152459. length -= 8;
  152460. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152461. (int) cinfo->image_width, (int) cinfo->image_height,
  152462. cinfo->num_components);
  152463. if (cinfo->marker->saw_SOF)
  152464. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152465. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152466. || cinfo->num_components <= 0)
  152467. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152468. if (length != (cinfo->num_components * 3))
  152469. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152470. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152471. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152472. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152473. cinfo->num_components * SIZEOF(jpeg_component_info));
  152474. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152475. ci++, compptr++) {
  152476. compptr->component_index = ci;
  152477. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152478. INPUT_BYTE(cinfo, c, return FALSE);
  152479. compptr->h_samp_factor = (c >> 4) & 15;
  152480. compptr->v_samp_factor = (c ) & 15;
  152481. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152482. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152483. compptr->component_id, compptr->h_samp_factor,
  152484. compptr->v_samp_factor, compptr->quant_tbl_no);
  152485. }
  152486. cinfo->marker->saw_SOF = TRUE;
  152487. INPUT_SYNC(cinfo);
  152488. return TRUE;
  152489. }
  152490. LOCAL(boolean)
  152491. get_sos (j_decompress_ptr cinfo)
  152492. {
  152493. INT32 length;
  152494. int i, ci, n, c, cc;
  152495. jpeg_component_info * compptr;
  152496. INPUT_VARS(cinfo);
  152497. if (! cinfo->marker->saw_SOF)
  152498. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152499. INPUT_2BYTES(cinfo, length, return FALSE);
  152500. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152501. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152502. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152503. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152504. cinfo->comps_in_scan = n;
  152505. for (i = 0; i < n; i++) {
  152506. INPUT_BYTE(cinfo, cc, return FALSE);
  152507. INPUT_BYTE(cinfo, c, return FALSE);
  152508. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152509. ci++, compptr++) {
  152510. if (cc == compptr->component_id)
  152511. goto id_found;
  152512. }
  152513. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152514. id_found:
  152515. cinfo->cur_comp_info[i] = compptr;
  152516. compptr->dc_tbl_no = (c >> 4) & 15;
  152517. compptr->ac_tbl_no = (c ) & 15;
  152518. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152519. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152520. }
  152521. INPUT_BYTE(cinfo, c, return FALSE);
  152522. cinfo->Ss = c;
  152523. INPUT_BYTE(cinfo, c, return FALSE);
  152524. cinfo->Se = c;
  152525. INPUT_BYTE(cinfo, c, return FALSE);
  152526. cinfo->Ah = (c >> 4) & 15;
  152527. cinfo->Al = (c ) & 15;
  152528. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152529. cinfo->Ah, cinfo->Al);
  152530. cinfo->marker->next_restart_num = 0;
  152531. cinfo->input_scan_number++;
  152532. INPUT_SYNC(cinfo);
  152533. return TRUE;
  152534. }
  152535. #ifdef D_ARITH_CODING_SUPPORTED
  152536. LOCAL(boolean)
  152537. get_dac (j_decompress_ptr cinfo)
  152538. {
  152539. INT32 length;
  152540. int index, val;
  152541. INPUT_VARS(cinfo);
  152542. INPUT_2BYTES(cinfo, length, return FALSE);
  152543. length -= 2;
  152544. while (length > 0) {
  152545. INPUT_BYTE(cinfo, index, return FALSE);
  152546. INPUT_BYTE(cinfo, val, return FALSE);
  152547. length -= 2;
  152548. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152549. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152550. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152551. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152552. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152553. } else { /* define DC table */
  152554. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152555. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152556. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152557. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152558. }
  152559. }
  152560. if (length != 0)
  152561. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152562. INPUT_SYNC(cinfo);
  152563. return TRUE;
  152564. }
  152565. #else /* ! D_ARITH_CODING_SUPPORTED */
  152566. #define get_dac(cinfo) skip_variable(cinfo)
  152567. #endif /* D_ARITH_CODING_SUPPORTED */
  152568. LOCAL(boolean)
  152569. get_dht (j_decompress_ptr cinfo)
  152570. {
  152571. INT32 length;
  152572. UINT8 bits[17];
  152573. UINT8 huffval[256];
  152574. int i, index, count;
  152575. JHUFF_TBL **htblptr;
  152576. INPUT_VARS(cinfo);
  152577. INPUT_2BYTES(cinfo, length, return FALSE);
  152578. length -= 2;
  152579. while (length > 16) {
  152580. INPUT_BYTE(cinfo, index, return FALSE);
  152581. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152582. bits[0] = 0;
  152583. count = 0;
  152584. for (i = 1; i <= 16; i++) {
  152585. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152586. count += bits[i];
  152587. }
  152588. length -= 1 + 16;
  152589. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152590. bits[1], bits[2], bits[3], bits[4],
  152591. bits[5], bits[6], bits[7], bits[8]);
  152592. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152593. bits[9], bits[10], bits[11], bits[12],
  152594. bits[13], bits[14], bits[15], bits[16]);
  152595. if (count > 256 || ((INT32) count) > length)
  152596. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152597. for (i = 0; i < count; i++)
  152598. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152599. length -= count;
  152600. if (index & 0x10) { /* AC table definition */
  152601. index -= 0x10;
  152602. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152603. } else { /* DC table definition */
  152604. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152605. }
  152606. if (index < 0 || index >= NUM_HUFF_TBLS)
  152607. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152608. if (*htblptr == NULL)
  152609. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152610. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152611. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152612. }
  152613. if (length != 0)
  152614. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152615. INPUT_SYNC(cinfo);
  152616. return TRUE;
  152617. }
  152618. LOCAL(boolean)
  152619. get_dqt (j_decompress_ptr cinfo)
  152620. {
  152621. INT32 length;
  152622. int n, i, prec;
  152623. unsigned int tmp;
  152624. JQUANT_TBL *quant_ptr;
  152625. INPUT_VARS(cinfo);
  152626. INPUT_2BYTES(cinfo, length, return FALSE);
  152627. length -= 2;
  152628. while (length > 0) {
  152629. INPUT_BYTE(cinfo, n, return FALSE);
  152630. prec = n >> 4;
  152631. n &= 0x0F;
  152632. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152633. if (n >= NUM_QUANT_TBLS)
  152634. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152635. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152636. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152637. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152638. for (i = 0; i < DCTSIZE2; i++) {
  152639. if (prec)
  152640. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152641. else
  152642. INPUT_BYTE(cinfo, tmp, return FALSE);
  152643. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152644. }
  152645. if (cinfo->err->trace_level >= 2) {
  152646. for (i = 0; i < DCTSIZE2; i += 8) {
  152647. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152648. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152649. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152650. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152651. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152652. }
  152653. }
  152654. length -= DCTSIZE2+1;
  152655. if (prec) length -= DCTSIZE2;
  152656. }
  152657. if (length != 0)
  152658. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152659. INPUT_SYNC(cinfo);
  152660. return TRUE;
  152661. }
  152662. LOCAL(boolean)
  152663. get_dri (j_decompress_ptr cinfo)
  152664. {
  152665. INT32 length;
  152666. unsigned int tmp;
  152667. INPUT_VARS(cinfo);
  152668. INPUT_2BYTES(cinfo, length, return FALSE);
  152669. if (length != 4)
  152670. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152671. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152672. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152673. cinfo->restart_interval = tmp;
  152674. INPUT_SYNC(cinfo);
  152675. return TRUE;
  152676. }
  152677. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152678. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152679. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152680. LOCAL(void)
  152681. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152682. unsigned int datalen, INT32 remaining)
  152683. {
  152684. INT32 totallen = (INT32) datalen + remaining;
  152685. if (datalen >= APP0_DATA_LEN &&
  152686. GETJOCTET(data[0]) == 0x4A &&
  152687. GETJOCTET(data[1]) == 0x46 &&
  152688. GETJOCTET(data[2]) == 0x49 &&
  152689. GETJOCTET(data[3]) == 0x46 &&
  152690. GETJOCTET(data[4]) == 0) {
  152691. cinfo->saw_JFIF_marker = TRUE;
  152692. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152693. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152694. cinfo->density_unit = GETJOCTET(data[7]);
  152695. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152696. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152697. if (cinfo->JFIF_major_version != 1)
  152698. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  152699. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  152700. TRACEMS5(cinfo, 1, JTRC_JFIF,
  152701. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  152702. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  152703. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  152704. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  152705. GETJOCTET(data[12]), GETJOCTET(data[13]));
  152706. totallen -= APP0_DATA_LEN;
  152707. if (totallen !=
  152708. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  152709. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  152710. } else if (datalen >= 6 &&
  152711. GETJOCTET(data[0]) == 0x4A &&
  152712. GETJOCTET(data[1]) == 0x46 &&
  152713. GETJOCTET(data[2]) == 0x58 &&
  152714. GETJOCTET(data[3]) == 0x58 &&
  152715. GETJOCTET(data[4]) == 0) {
  152716. switch (GETJOCTET(data[5])) {
  152717. case 0x10:
  152718. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  152719. break;
  152720. case 0x11:
  152721. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  152722. break;
  152723. case 0x13:
  152724. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  152725. break;
  152726. default:
  152727. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  152728. GETJOCTET(data[5]), (int) totallen);
  152729. break;
  152730. }
  152731. } else {
  152732. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  152733. }
  152734. }
  152735. LOCAL(void)
  152736. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152737. unsigned int datalen, INT32 remaining)
  152738. {
  152739. unsigned int version, flags0, flags1, transform;
  152740. if (datalen >= APP14_DATA_LEN &&
  152741. GETJOCTET(data[0]) == 0x41 &&
  152742. GETJOCTET(data[1]) == 0x64 &&
  152743. GETJOCTET(data[2]) == 0x6F &&
  152744. GETJOCTET(data[3]) == 0x62 &&
  152745. GETJOCTET(data[4]) == 0x65) {
  152746. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  152747. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  152748. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  152749. transform = GETJOCTET(data[11]);
  152750. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  152751. cinfo->saw_Adobe_marker = TRUE;
  152752. cinfo->Adobe_transform = (UINT8) transform;
  152753. } else {
  152754. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  152755. }
  152756. }
  152757. METHODDEF(boolean)
  152758. get_interesting_appn (j_decompress_ptr cinfo)
  152759. {
  152760. INT32 length;
  152761. JOCTET b[APPN_DATA_LEN];
  152762. unsigned int i, numtoread;
  152763. INPUT_VARS(cinfo);
  152764. INPUT_2BYTES(cinfo, length, return FALSE);
  152765. length -= 2;
  152766. if (length >= APPN_DATA_LEN)
  152767. numtoread = APPN_DATA_LEN;
  152768. else if (length > 0)
  152769. numtoread = (unsigned int) length;
  152770. else
  152771. numtoread = 0;
  152772. for (i = 0; i < numtoread; i++)
  152773. INPUT_BYTE(cinfo, b[i], return FALSE);
  152774. length -= numtoread;
  152775. switch (cinfo->unread_marker) {
  152776. case M_APP0:
  152777. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  152778. break;
  152779. case M_APP14:
  152780. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  152781. break;
  152782. default:
  152783. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  152784. break;
  152785. }
  152786. INPUT_SYNC(cinfo);
  152787. if (length > 0)
  152788. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152789. return TRUE;
  152790. }
  152791. #ifdef SAVE_MARKERS_SUPPORTED
  152792. METHODDEF(boolean)
  152793. save_marker (j_decompress_ptr cinfo)
  152794. {
  152795. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  152796. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  152797. unsigned int bytes_read, data_length;
  152798. JOCTET FAR * data;
  152799. INT32 length = 0;
  152800. INPUT_VARS(cinfo);
  152801. if (cur_marker == NULL) {
  152802. INPUT_2BYTES(cinfo, length, return FALSE);
  152803. length -= 2;
  152804. if (length >= 0) { /* watch out for bogus length word */
  152805. unsigned int limit;
  152806. if (cinfo->unread_marker == (int) M_COM)
  152807. limit = marker->length_limit_COM;
  152808. else
  152809. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  152810. if ((unsigned int) length < limit)
  152811. limit = (unsigned int) length;
  152812. cur_marker = (jpeg_saved_marker_ptr)
  152813. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152814. SIZEOF(struct jpeg_marker_struct) + limit);
  152815. cur_marker->next = NULL;
  152816. cur_marker->marker = (UINT8) cinfo->unread_marker;
  152817. cur_marker->original_length = (unsigned int) length;
  152818. cur_marker->data_length = limit;
  152819. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  152820. marker->cur_marker = cur_marker;
  152821. marker->bytes_read = 0;
  152822. bytes_read = 0;
  152823. data_length = limit;
  152824. } else {
  152825. bytes_read = data_length = 0;
  152826. data = NULL;
  152827. }
  152828. } else {
  152829. bytes_read = marker->bytes_read;
  152830. data_length = cur_marker->data_length;
  152831. data = cur_marker->data + bytes_read;
  152832. }
  152833. while (bytes_read < data_length) {
  152834. INPUT_SYNC(cinfo); /* move the restart point to here */
  152835. marker->bytes_read = bytes_read;
  152836. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  152837. while (bytes_read < data_length && bytes_in_buffer > 0) {
  152838. *data++ = *next_input_byte++;
  152839. bytes_in_buffer--;
  152840. bytes_read++;
  152841. }
  152842. }
  152843. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  152844. if (cinfo->marker_list == NULL) {
  152845. cinfo->marker_list = cur_marker;
  152846. } else {
  152847. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  152848. while (prev->next != NULL)
  152849. prev = prev->next;
  152850. prev->next = cur_marker;
  152851. }
  152852. data = cur_marker->data;
  152853. length = cur_marker->original_length - data_length;
  152854. }
  152855. marker->cur_marker = NULL;
  152856. switch (cinfo->unread_marker) {
  152857. case M_APP0:
  152858. examine_app0(cinfo, data, data_length, length);
  152859. break;
  152860. case M_APP14:
  152861. examine_app14(cinfo, data, data_length, length);
  152862. break;
  152863. default:
  152864. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  152865. (int) (data_length + length));
  152866. break;
  152867. }
  152868. INPUT_SYNC(cinfo); /* do before skip_input_data */
  152869. if (length > 0)
  152870. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152871. return TRUE;
  152872. }
  152873. #endif /* SAVE_MARKERS_SUPPORTED */
  152874. METHODDEF(boolean)
  152875. skip_variable (j_decompress_ptr cinfo)
  152876. {
  152877. INT32 length;
  152878. INPUT_VARS(cinfo);
  152879. INPUT_2BYTES(cinfo, length, return FALSE);
  152880. length -= 2;
  152881. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  152882. INPUT_SYNC(cinfo); /* do before skip_input_data */
  152883. if (length > 0)
  152884. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152885. return TRUE;
  152886. }
  152887. LOCAL(boolean)
  152888. next_marker (j_decompress_ptr cinfo)
  152889. {
  152890. int c;
  152891. INPUT_VARS(cinfo);
  152892. for (;;) {
  152893. INPUT_BYTE(cinfo, c, return FALSE);
  152894. while (c != 0xFF) {
  152895. cinfo->marker->discarded_bytes++;
  152896. INPUT_SYNC(cinfo);
  152897. INPUT_BYTE(cinfo, c, return FALSE);
  152898. }
  152899. do {
  152900. INPUT_BYTE(cinfo, c, return FALSE);
  152901. } while (c == 0xFF);
  152902. if (c != 0)
  152903. break; /* found a valid marker, exit loop */
  152904. cinfo->marker->discarded_bytes += 2;
  152905. INPUT_SYNC(cinfo);
  152906. }
  152907. if (cinfo->marker->discarded_bytes != 0) {
  152908. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  152909. cinfo->marker->discarded_bytes = 0;
  152910. }
  152911. cinfo->unread_marker = c;
  152912. INPUT_SYNC(cinfo);
  152913. return TRUE;
  152914. }
  152915. LOCAL(boolean)
  152916. first_marker (j_decompress_ptr cinfo)
  152917. {
  152918. int c, c2;
  152919. INPUT_VARS(cinfo);
  152920. INPUT_BYTE(cinfo, c, return FALSE);
  152921. INPUT_BYTE(cinfo, c2, return FALSE);
  152922. if (c != 0xFF || c2 != (int) M_SOI)
  152923. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  152924. cinfo->unread_marker = c2;
  152925. INPUT_SYNC(cinfo);
  152926. return TRUE;
  152927. }
  152928. METHODDEF(int)
  152929. read_markers (j_decompress_ptr cinfo)
  152930. {
  152931. for (;;) {
  152932. if (cinfo->unread_marker == 0) {
  152933. if (! cinfo->marker->saw_SOI) {
  152934. if (! first_marker(cinfo))
  152935. return JPEG_SUSPENDED;
  152936. } else {
  152937. if (! next_marker(cinfo))
  152938. return JPEG_SUSPENDED;
  152939. }
  152940. }
  152941. switch (cinfo->unread_marker) {
  152942. case M_SOI:
  152943. if (! get_soi(cinfo))
  152944. return JPEG_SUSPENDED;
  152945. break;
  152946. case M_SOF0: /* Baseline */
  152947. case M_SOF1: /* Extended sequential, Huffman */
  152948. if (! get_sof(cinfo, FALSE, FALSE))
  152949. return JPEG_SUSPENDED;
  152950. break;
  152951. case M_SOF2: /* Progressive, Huffman */
  152952. if (! get_sof(cinfo, TRUE, FALSE))
  152953. return JPEG_SUSPENDED;
  152954. break;
  152955. case M_SOF9: /* Extended sequential, arithmetic */
  152956. if (! get_sof(cinfo, FALSE, TRUE))
  152957. return JPEG_SUSPENDED;
  152958. break;
  152959. case M_SOF10: /* Progressive, arithmetic */
  152960. if (! get_sof(cinfo, TRUE, TRUE))
  152961. return JPEG_SUSPENDED;
  152962. break;
  152963. case M_SOF3: /* Lossless, Huffman */
  152964. case M_SOF5: /* Differential sequential, Huffman */
  152965. case M_SOF6: /* Differential progressive, Huffman */
  152966. case M_SOF7: /* Differential lossless, Huffman */
  152967. case M_JPG: /* Reserved for JPEG extensions */
  152968. case M_SOF11: /* Lossless, arithmetic */
  152969. case M_SOF13: /* Differential sequential, arithmetic */
  152970. case M_SOF14: /* Differential progressive, arithmetic */
  152971. case M_SOF15: /* Differential lossless, arithmetic */
  152972. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  152973. break;
  152974. case M_SOS:
  152975. if (! get_sos(cinfo))
  152976. return JPEG_SUSPENDED;
  152977. cinfo->unread_marker = 0; /* processed the marker */
  152978. return JPEG_REACHED_SOS;
  152979. case M_EOI:
  152980. TRACEMS(cinfo, 1, JTRC_EOI);
  152981. cinfo->unread_marker = 0; /* processed the marker */
  152982. return JPEG_REACHED_EOI;
  152983. case M_DAC:
  152984. if (! get_dac(cinfo))
  152985. return JPEG_SUSPENDED;
  152986. break;
  152987. case M_DHT:
  152988. if (! get_dht(cinfo))
  152989. return JPEG_SUSPENDED;
  152990. break;
  152991. case M_DQT:
  152992. if (! get_dqt(cinfo))
  152993. return JPEG_SUSPENDED;
  152994. break;
  152995. case M_DRI:
  152996. if (! get_dri(cinfo))
  152997. return JPEG_SUSPENDED;
  152998. break;
  152999. case M_APP0:
  153000. case M_APP1:
  153001. case M_APP2:
  153002. case M_APP3:
  153003. case M_APP4:
  153004. case M_APP5:
  153005. case M_APP6:
  153006. case M_APP7:
  153007. case M_APP8:
  153008. case M_APP9:
  153009. case M_APP10:
  153010. case M_APP11:
  153011. case M_APP12:
  153012. case M_APP13:
  153013. case M_APP14:
  153014. case M_APP15:
  153015. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153016. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153017. return JPEG_SUSPENDED;
  153018. break;
  153019. case M_COM:
  153020. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153021. return JPEG_SUSPENDED;
  153022. break;
  153023. case M_RST0: /* these are all parameterless */
  153024. case M_RST1:
  153025. case M_RST2:
  153026. case M_RST3:
  153027. case M_RST4:
  153028. case M_RST5:
  153029. case M_RST6:
  153030. case M_RST7:
  153031. case M_TEM:
  153032. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153033. break;
  153034. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153035. if (! skip_variable(cinfo))
  153036. return JPEG_SUSPENDED;
  153037. break;
  153038. default: /* must be DHP, EXP, JPGn, or RESn */
  153039. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153040. break;
  153041. }
  153042. cinfo->unread_marker = 0;
  153043. } /* end loop */
  153044. }
  153045. METHODDEF(boolean)
  153046. read_restart_marker (j_decompress_ptr cinfo)
  153047. {
  153048. if (cinfo->unread_marker == 0) {
  153049. if (! next_marker(cinfo))
  153050. return FALSE;
  153051. }
  153052. if (cinfo->unread_marker ==
  153053. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153054. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153055. cinfo->unread_marker = 0;
  153056. } else {
  153057. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153058. cinfo->marker->next_restart_num))
  153059. return FALSE;
  153060. }
  153061. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153062. return TRUE;
  153063. }
  153064. GLOBAL(boolean)
  153065. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153066. {
  153067. int marker = cinfo->unread_marker;
  153068. int action = 1;
  153069. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153070. for (;;) {
  153071. if (marker < (int) M_SOF0)
  153072. action = 2; /* invalid marker */
  153073. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153074. action = 3; /* valid non-restart marker */
  153075. else {
  153076. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153077. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153078. action = 3; /* one of the next two expected restarts */
  153079. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153080. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153081. action = 2; /* a prior restart, so advance */
  153082. else
  153083. action = 1; /* desired restart or too far away */
  153084. }
  153085. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153086. switch (action) {
  153087. case 1:
  153088. cinfo->unread_marker = 0;
  153089. return TRUE;
  153090. case 2:
  153091. if (! next_marker(cinfo))
  153092. return FALSE;
  153093. marker = cinfo->unread_marker;
  153094. break;
  153095. case 3:
  153096. return TRUE;
  153097. }
  153098. } /* end loop */
  153099. }
  153100. METHODDEF(void)
  153101. reset_marker_reader (j_decompress_ptr cinfo)
  153102. {
  153103. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153104. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153105. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153106. cinfo->unread_marker = 0; /* no pending marker */
  153107. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153108. marker->pub.saw_SOF = FALSE;
  153109. marker->pub.discarded_bytes = 0;
  153110. marker->cur_marker = NULL;
  153111. }
  153112. GLOBAL(void)
  153113. jinit_marker_reader (j_decompress_ptr cinfo)
  153114. {
  153115. my_marker_ptr2 marker;
  153116. int i;
  153117. marker = (my_marker_ptr2)
  153118. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153119. SIZEOF(my_marker_reader));
  153120. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153121. marker->pub.reset_marker_reader = reset_marker_reader;
  153122. marker->pub.read_markers = read_markers;
  153123. marker->pub.read_restart_marker = read_restart_marker;
  153124. marker->process_COM = skip_variable;
  153125. marker->length_limit_COM = 0;
  153126. for (i = 0; i < 16; i++) {
  153127. marker->process_APPn[i] = skip_variable;
  153128. marker->length_limit_APPn[i] = 0;
  153129. }
  153130. marker->process_APPn[0] = get_interesting_appn;
  153131. marker->process_APPn[14] = get_interesting_appn;
  153132. reset_marker_reader(cinfo);
  153133. }
  153134. #ifdef SAVE_MARKERS_SUPPORTED
  153135. GLOBAL(void)
  153136. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153137. unsigned int length_limit)
  153138. {
  153139. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153140. long maxlength;
  153141. jpeg_marker_parser_method processor;
  153142. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153143. if (((long) length_limit) > maxlength)
  153144. length_limit = (unsigned int) maxlength;
  153145. if (length_limit) {
  153146. processor = save_marker;
  153147. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153148. length_limit = APP0_DATA_LEN;
  153149. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153150. length_limit = APP14_DATA_LEN;
  153151. } else {
  153152. processor = skip_variable;
  153153. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153154. processor = get_interesting_appn;
  153155. }
  153156. if (marker_code == (int) M_COM) {
  153157. marker->process_COM = processor;
  153158. marker->length_limit_COM = length_limit;
  153159. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153160. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153161. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153162. } else
  153163. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153164. }
  153165. #endif /* SAVE_MARKERS_SUPPORTED */
  153166. GLOBAL(void)
  153167. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153168. jpeg_marker_parser_method routine)
  153169. {
  153170. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153171. if (marker_code == (int) M_COM)
  153172. marker->process_COM = routine;
  153173. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153174. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153175. else
  153176. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153177. }
  153178. /*** End of inlined file: jdmarker.c ***/
  153179. /*** Start of inlined file: jdmaster.c ***/
  153180. #define JPEG_INTERNALS
  153181. typedef struct {
  153182. struct jpeg_decomp_master pub; /* public fields */
  153183. int pass_number; /* # of passes completed */
  153184. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153185. struct jpeg_color_quantizer * quantizer_1pass;
  153186. struct jpeg_color_quantizer * quantizer_2pass;
  153187. } my_decomp_master;
  153188. typedef my_decomp_master * my_master_ptr6;
  153189. LOCAL(boolean)
  153190. use_merged_upsample (j_decompress_ptr cinfo)
  153191. {
  153192. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153193. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153194. return FALSE;
  153195. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153196. cinfo->out_color_space != JCS_RGB ||
  153197. cinfo->out_color_components != RGB_PIXELSIZE)
  153198. return FALSE;
  153199. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153200. cinfo->comp_info[1].h_samp_factor != 1 ||
  153201. cinfo->comp_info[2].h_samp_factor != 1 ||
  153202. cinfo->comp_info[0].v_samp_factor > 2 ||
  153203. cinfo->comp_info[1].v_samp_factor != 1 ||
  153204. cinfo->comp_info[2].v_samp_factor != 1)
  153205. return FALSE;
  153206. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153207. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153208. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153209. return FALSE;
  153210. return TRUE; /* by golly, it'll work... */
  153211. #else
  153212. return FALSE;
  153213. #endif
  153214. }
  153215. GLOBAL(void)
  153216. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153217. {
  153218. #ifdef IDCT_SCALING_SUPPORTED
  153219. int ci;
  153220. jpeg_component_info *compptr;
  153221. #endif
  153222. if (cinfo->global_state != DSTATE_READY)
  153223. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153224. #ifdef IDCT_SCALING_SUPPORTED
  153225. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153226. cinfo->output_width = (JDIMENSION)
  153227. jdiv_round_up((long) cinfo->image_width, 8L);
  153228. cinfo->output_height = (JDIMENSION)
  153229. jdiv_round_up((long) cinfo->image_height, 8L);
  153230. cinfo->min_DCT_scaled_size = 1;
  153231. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153232. cinfo->output_width = (JDIMENSION)
  153233. jdiv_round_up((long) cinfo->image_width, 4L);
  153234. cinfo->output_height = (JDIMENSION)
  153235. jdiv_round_up((long) cinfo->image_height, 4L);
  153236. cinfo->min_DCT_scaled_size = 2;
  153237. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153238. cinfo->output_width = (JDIMENSION)
  153239. jdiv_round_up((long) cinfo->image_width, 2L);
  153240. cinfo->output_height = (JDIMENSION)
  153241. jdiv_round_up((long) cinfo->image_height, 2L);
  153242. cinfo->min_DCT_scaled_size = 4;
  153243. } else {
  153244. cinfo->output_width = cinfo->image_width;
  153245. cinfo->output_height = cinfo->image_height;
  153246. cinfo->min_DCT_scaled_size = DCTSIZE;
  153247. }
  153248. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153249. ci++, compptr++) {
  153250. int ssize = cinfo->min_DCT_scaled_size;
  153251. while (ssize < DCTSIZE &&
  153252. (compptr->h_samp_factor * ssize * 2 <=
  153253. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153254. (compptr->v_samp_factor * ssize * 2 <=
  153255. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153256. ssize = ssize * 2;
  153257. }
  153258. compptr->DCT_scaled_size = ssize;
  153259. }
  153260. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153261. ci++, compptr++) {
  153262. compptr->downsampled_width = (JDIMENSION)
  153263. jdiv_round_up((long) cinfo->image_width *
  153264. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153265. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153266. compptr->downsampled_height = (JDIMENSION)
  153267. jdiv_round_up((long) cinfo->image_height *
  153268. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153269. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153270. }
  153271. #else /* !IDCT_SCALING_SUPPORTED */
  153272. cinfo->output_width = cinfo->image_width;
  153273. cinfo->output_height = cinfo->image_height;
  153274. #endif /* IDCT_SCALING_SUPPORTED */
  153275. switch (cinfo->out_color_space) {
  153276. case JCS_GRAYSCALE:
  153277. cinfo->out_color_components = 1;
  153278. break;
  153279. case JCS_RGB:
  153280. #if RGB_PIXELSIZE != 3
  153281. cinfo->out_color_components = RGB_PIXELSIZE;
  153282. break;
  153283. #endif /* else share code with YCbCr */
  153284. case JCS_YCbCr:
  153285. cinfo->out_color_components = 3;
  153286. break;
  153287. case JCS_CMYK:
  153288. case JCS_YCCK:
  153289. cinfo->out_color_components = 4;
  153290. break;
  153291. default: /* else must be same colorspace as in file */
  153292. cinfo->out_color_components = cinfo->num_components;
  153293. break;
  153294. }
  153295. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153296. cinfo->out_color_components);
  153297. if (use_merged_upsample(cinfo))
  153298. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153299. else
  153300. cinfo->rec_outbuf_height = 1;
  153301. }
  153302. LOCAL(void)
  153303. prepare_range_limit_table (j_decompress_ptr cinfo)
  153304. {
  153305. JSAMPLE * table;
  153306. int i;
  153307. table = (JSAMPLE *)
  153308. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153309. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153310. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153311. cinfo->sample_range_limit = table;
  153312. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153313. for (i = 0; i <= MAXJSAMPLE; i++)
  153314. table[i] = (JSAMPLE) i;
  153315. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153316. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153317. table[i] = MAXJSAMPLE;
  153318. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153319. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153320. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153321. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153322. }
  153323. LOCAL(void)
  153324. master_selection (j_decompress_ptr cinfo)
  153325. {
  153326. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153327. boolean use_c_buffer;
  153328. long samplesperrow;
  153329. JDIMENSION jd_samplesperrow;
  153330. jpeg_calc_output_dimensions(cinfo);
  153331. prepare_range_limit_table(cinfo);
  153332. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153333. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153334. if ((long) jd_samplesperrow != samplesperrow)
  153335. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153336. master->pass_number = 0;
  153337. master->using_merged_upsample = use_merged_upsample(cinfo);
  153338. master->quantizer_1pass = NULL;
  153339. master->quantizer_2pass = NULL;
  153340. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153341. cinfo->enable_1pass_quant = FALSE;
  153342. cinfo->enable_external_quant = FALSE;
  153343. cinfo->enable_2pass_quant = FALSE;
  153344. }
  153345. if (cinfo->quantize_colors) {
  153346. if (cinfo->raw_data_out)
  153347. ERREXIT(cinfo, JERR_NOTIMPL);
  153348. if (cinfo->out_color_components != 3) {
  153349. cinfo->enable_1pass_quant = TRUE;
  153350. cinfo->enable_external_quant = FALSE;
  153351. cinfo->enable_2pass_quant = FALSE;
  153352. cinfo->colormap = NULL;
  153353. } else if (cinfo->colormap != NULL) {
  153354. cinfo->enable_external_quant = TRUE;
  153355. } else if (cinfo->two_pass_quantize) {
  153356. cinfo->enable_2pass_quant = TRUE;
  153357. } else {
  153358. cinfo->enable_1pass_quant = TRUE;
  153359. }
  153360. if (cinfo->enable_1pass_quant) {
  153361. #ifdef QUANT_1PASS_SUPPORTED
  153362. jinit_1pass_quantizer(cinfo);
  153363. master->quantizer_1pass = cinfo->cquantize;
  153364. #else
  153365. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153366. #endif
  153367. }
  153368. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153369. #ifdef QUANT_2PASS_SUPPORTED
  153370. jinit_2pass_quantizer(cinfo);
  153371. master->quantizer_2pass = cinfo->cquantize;
  153372. #else
  153373. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153374. #endif
  153375. }
  153376. }
  153377. if (! cinfo->raw_data_out) {
  153378. if (master->using_merged_upsample) {
  153379. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153380. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153381. #else
  153382. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153383. #endif
  153384. } else {
  153385. jinit_color_deconverter(cinfo);
  153386. jinit_upsampler(cinfo);
  153387. }
  153388. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153389. }
  153390. jinit_inverse_dct(cinfo);
  153391. if (cinfo->arith_code) {
  153392. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153393. } else {
  153394. if (cinfo->progressive_mode) {
  153395. #ifdef D_PROGRESSIVE_SUPPORTED
  153396. jinit_phuff_decoder(cinfo);
  153397. #else
  153398. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153399. #endif
  153400. } else
  153401. jinit_huff_decoder(cinfo);
  153402. }
  153403. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153404. jinit_d_coef_controller(cinfo, use_c_buffer);
  153405. if (! cinfo->raw_data_out)
  153406. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153407. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153408. (*cinfo->inputctl->start_input_pass) (cinfo);
  153409. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153410. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153411. cinfo->inputctl->has_multiple_scans) {
  153412. int nscans;
  153413. if (cinfo->progressive_mode) {
  153414. nscans = 2 + 3 * cinfo->num_components;
  153415. } else {
  153416. nscans = cinfo->num_components;
  153417. }
  153418. cinfo->progress->pass_counter = 0L;
  153419. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153420. cinfo->progress->completed_passes = 0;
  153421. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153422. master->pass_number++;
  153423. }
  153424. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153425. }
  153426. METHODDEF(void)
  153427. prepare_for_output_pass (j_decompress_ptr cinfo)
  153428. {
  153429. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153430. if (master->pub.is_dummy_pass) {
  153431. #ifdef QUANT_2PASS_SUPPORTED
  153432. master->pub.is_dummy_pass = FALSE;
  153433. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153434. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153435. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153436. #else
  153437. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153438. #endif /* QUANT_2PASS_SUPPORTED */
  153439. } else {
  153440. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153441. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153442. cinfo->cquantize = master->quantizer_2pass;
  153443. master->pub.is_dummy_pass = TRUE;
  153444. } else if (cinfo->enable_1pass_quant) {
  153445. cinfo->cquantize = master->quantizer_1pass;
  153446. } else {
  153447. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153448. }
  153449. }
  153450. (*cinfo->idct->start_pass) (cinfo);
  153451. (*cinfo->coef->start_output_pass) (cinfo);
  153452. if (! cinfo->raw_data_out) {
  153453. if (! master->using_merged_upsample)
  153454. (*cinfo->cconvert->start_pass) (cinfo);
  153455. (*cinfo->upsample->start_pass) (cinfo);
  153456. if (cinfo->quantize_colors)
  153457. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153458. (*cinfo->post->start_pass) (cinfo,
  153459. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153460. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153461. }
  153462. }
  153463. if (cinfo->progress != NULL) {
  153464. cinfo->progress->completed_passes = master->pass_number;
  153465. cinfo->progress->total_passes = master->pass_number +
  153466. (master->pub.is_dummy_pass ? 2 : 1);
  153467. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153468. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153469. }
  153470. }
  153471. }
  153472. METHODDEF(void)
  153473. finish_output_pass (j_decompress_ptr cinfo)
  153474. {
  153475. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153476. if (cinfo->quantize_colors)
  153477. (*cinfo->cquantize->finish_pass) (cinfo);
  153478. master->pass_number++;
  153479. }
  153480. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153481. GLOBAL(void)
  153482. jpeg_new_colormap (j_decompress_ptr cinfo)
  153483. {
  153484. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153485. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153486. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153487. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153488. cinfo->colormap != NULL) {
  153489. cinfo->cquantize = master->quantizer_2pass;
  153490. (*cinfo->cquantize->new_color_map) (cinfo);
  153491. master->pub.is_dummy_pass = FALSE; /* just in case */
  153492. } else
  153493. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153494. }
  153495. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153496. GLOBAL(void)
  153497. jinit_master_decompress (j_decompress_ptr cinfo)
  153498. {
  153499. my_master_ptr6 master;
  153500. master = (my_master_ptr6)
  153501. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153502. SIZEOF(my_decomp_master));
  153503. cinfo->master = (struct jpeg_decomp_master *) master;
  153504. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153505. master->pub.finish_output_pass = finish_output_pass;
  153506. master->pub.is_dummy_pass = FALSE;
  153507. master_selection(cinfo);
  153508. }
  153509. /*** End of inlined file: jdmaster.c ***/
  153510. #undef FIX
  153511. /*** Start of inlined file: jdmerge.c ***/
  153512. #define JPEG_INTERNALS
  153513. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153514. typedef struct {
  153515. struct jpeg_upsampler pub; /* public fields */
  153516. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153517. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153518. JSAMPARRAY output_buf));
  153519. int * Cr_r_tab; /* => table for Cr to R conversion */
  153520. int * Cb_b_tab; /* => table for Cb to B conversion */
  153521. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153522. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153523. JSAMPROW spare_row;
  153524. boolean spare_full; /* T if spare buffer is occupied */
  153525. JDIMENSION out_row_width; /* samples per output row */
  153526. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153527. } my_upsampler;
  153528. typedef my_upsampler * my_upsample_ptr;
  153529. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153530. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153531. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153532. LOCAL(void)
  153533. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153534. {
  153535. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153536. int i;
  153537. INT32 x;
  153538. SHIFT_TEMPS
  153539. upsample->Cr_r_tab = (int *)
  153540. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153541. (MAXJSAMPLE+1) * SIZEOF(int));
  153542. upsample->Cb_b_tab = (int *)
  153543. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153544. (MAXJSAMPLE+1) * SIZEOF(int));
  153545. upsample->Cr_g_tab = (INT32 *)
  153546. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153547. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153548. upsample->Cb_g_tab = (INT32 *)
  153549. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153550. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153551. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153552. upsample->Cr_r_tab[i] = (int)
  153553. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153554. upsample->Cb_b_tab[i] = (int)
  153555. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153556. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153557. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153558. }
  153559. }
  153560. METHODDEF(void)
  153561. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153562. {
  153563. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153564. upsample->spare_full = FALSE;
  153565. upsample->rows_to_go = cinfo->output_height;
  153566. }
  153567. METHODDEF(void)
  153568. merged_2v_upsample (j_decompress_ptr cinfo,
  153569. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153570. JDIMENSION in_row_groups_avail,
  153571. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153572. JDIMENSION out_rows_avail)
  153573. {
  153574. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153575. JSAMPROW work_ptrs[2];
  153576. JDIMENSION num_rows; /* number of rows returned to caller */
  153577. if (upsample->spare_full) {
  153578. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153579. 1, upsample->out_row_width);
  153580. num_rows = 1;
  153581. upsample->spare_full = FALSE;
  153582. } else {
  153583. num_rows = 2;
  153584. if (num_rows > upsample->rows_to_go)
  153585. num_rows = upsample->rows_to_go;
  153586. out_rows_avail -= *out_row_ctr;
  153587. if (num_rows > out_rows_avail)
  153588. num_rows = out_rows_avail;
  153589. work_ptrs[0] = output_buf[*out_row_ctr];
  153590. if (num_rows > 1) {
  153591. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153592. } else {
  153593. work_ptrs[1] = upsample->spare_row;
  153594. upsample->spare_full = TRUE;
  153595. }
  153596. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153597. }
  153598. *out_row_ctr += num_rows;
  153599. upsample->rows_to_go -= num_rows;
  153600. if (! upsample->spare_full)
  153601. (*in_row_group_ctr)++;
  153602. }
  153603. METHODDEF(void)
  153604. merged_1v_upsample (j_decompress_ptr cinfo,
  153605. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153606. JDIMENSION in_row_groups_avail,
  153607. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153608. JDIMENSION out_rows_avail)
  153609. {
  153610. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153611. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153612. output_buf + *out_row_ctr);
  153613. (*out_row_ctr)++;
  153614. (*in_row_group_ctr)++;
  153615. }
  153616. METHODDEF(void)
  153617. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153618. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153619. JSAMPARRAY output_buf)
  153620. {
  153621. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153622. register int y, cred, cgreen, cblue;
  153623. int cb, cr;
  153624. register JSAMPROW outptr;
  153625. JSAMPROW inptr0, inptr1, inptr2;
  153626. JDIMENSION col;
  153627. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153628. int * Crrtab = upsample->Cr_r_tab;
  153629. int * Cbbtab = upsample->Cb_b_tab;
  153630. INT32 * Crgtab = upsample->Cr_g_tab;
  153631. INT32 * Cbgtab = upsample->Cb_g_tab;
  153632. SHIFT_TEMPS
  153633. inptr0 = input_buf[0][in_row_group_ctr];
  153634. inptr1 = input_buf[1][in_row_group_ctr];
  153635. inptr2 = input_buf[2][in_row_group_ctr];
  153636. outptr = output_buf[0];
  153637. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153638. cb = GETJSAMPLE(*inptr1++);
  153639. cr = GETJSAMPLE(*inptr2++);
  153640. cred = Crrtab[cr];
  153641. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153642. cblue = Cbbtab[cb];
  153643. y = GETJSAMPLE(*inptr0++);
  153644. outptr[RGB_RED] = range_limit[y + cred];
  153645. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153646. outptr[RGB_BLUE] = range_limit[y + cblue];
  153647. outptr += RGB_PIXELSIZE;
  153648. y = GETJSAMPLE(*inptr0++);
  153649. outptr[RGB_RED] = range_limit[y + cred];
  153650. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153651. outptr[RGB_BLUE] = range_limit[y + cblue];
  153652. outptr += RGB_PIXELSIZE;
  153653. }
  153654. if (cinfo->output_width & 1) {
  153655. cb = GETJSAMPLE(*inptr1);
  153656. cr = GETJSAMPLE(*inptr2);
  153657. cred = Crrtab[cr];
  153658. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153659. cblue = Cbbtab[cb];
  153660. y = GETJSAMPLE(*inptr0);
  153661. outptr[RGB_RED] = range_limit[y + cred];
  153662. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153663. outptr[RGB_BLUE] = range_limit[y + cblue];
  153664. }
  153665. }
  153666. METHODDEF(void)
  153667. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153668. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153669. JSAMPARRAY output_buf)
  153670. {
  153671. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153672. register int y, cred, cgreen, cblue;
  153673. int cb, cr;
  153674. register JSAMPROW outptr0, outptr1;
  153675. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153676. JDIMENSION col;
  153677. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153678. int * Crrtab = upsample->Cr_r_tab;
  153679. int * Cbbtab = upsample->Cb_b_tab;
  153680. INT32 * Crgtab = upsample->Cr_g_tab;
  153681. INT32 * Cbgtab = upsample->Cb_g_tab;
  153682. SHIFT_TEMPS
  153683. inptr00 = input_buf[0][in_row_group_ctr*2];
  153684. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153685. inptr1 = input_buf[1][in_row_group_ctr];
  153686. inptr2 = input_buf[2][in_row_group_ctr];
  153687. outptr0 = output_buf[0];
  153688. outptr1 = output_buf[1];
  153689. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153690. cb = GETJSAMPLE(*inptr1++);
  153691. cr = GETJSAMPLE(*inptr2++);
  153692. cred = Crrtab[cr];
  153693. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153694. cblue = Cbbtab[cb];
  153695. y = GETJSAMPLE(*inptr00++);
  153696. outptr0[RGB_RED] = range_limit[y + cred];
  153697. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153698. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153699. outptr0 += RGB_PIXELSIZE;
  153700. y = GETJSAMPLE(*inptr00++);
  153701. outptr0[RGB_RED] = range_limit[y + cred];
  153702. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153703. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153704. outptr0 += RGB_PIXELSIZE;
  153705. y = GETJSAMPLE(*inptr01++);
  153706. outptr1[RGB_RED] = range_limit[y + cred];
  153707. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153708. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153709. outptr1 += RGB_PIXELSIZE;
  153710. y = GETJSAMPLE(*inptr01++);
  153711. outptr1[RGB_RED] = range_limit[y + cred];
  153712. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153713. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153714. outptr1 += RGB_PIXELSIZE;
  153715. }
  153716. if (cinfo->output_width & 1) {
  153717. cb = GETJSAMPLE(*inptr1);
  153718. cr = GETJSAMPLE(*inptr2);
  153719. cred = Crrtab[cr];
  153720. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153721. cblue = Cbbtab[cb];
  153722. y = GETJSAMPLE(*inptr00);
  153723. outptr0[RGB_RED] = range_limit[y + cred];
  153724. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153725. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153726. y = GETJSAMPLE(*inptr01);
  153727. outptr1[RGB_RED] = range_limit[y + cred];
  153728. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153729. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153730. }
  153731. }
  153732. GLOBAL(void)
  153733. jinit_merged_upsampler (j_decompress_ptr cinfo)
  153734. {
  153735. my_upsample_ptr upsample;
  153736. upsample = (my_upsample_ptr)
  153737. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153738. SIZEOF(my_upsampler));
  153739. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  153740. upsample->pub.start_pass = start_pass_merged_upsample;
  153741. upsample->pub.need_context_rows = FALSE;
  153742. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  153743. if (cinfo->max_v_samp_factor == 2) {
  153744. upsample->pub.upsample = merged_2v_upsample;
  153745. upsample->upmethod = h2v2_merged_upsample;
  153746. upsample->spare_row = (JSAMPROW)
  153747. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153748. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  153749. } else {
  153750. upsample->pub.upsample = merged_1v_upsample;
  153751. upsample->upmethod = h2v1_merged_upsample;
  153752. upsample->spare_row = NULL;
  153753. }
  153754. build_ycc_rgb_table2(cinfo);
  153755. }
  153756. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  153757. /*** End of inlined file: jdmerge.c ***/
  153758. #undef ASSIGN_STATE
  153759. /*** Start of inlined file: jdphuff.c ***/
  153760. #define JPEG_INTERNALS
  153761. #ifdef D_PROGRESSIVE_SUPPORTED
  153762. typedef struct {
  153763. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  153764. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  153765. } savable_state3;
  153766. #ifndef NO_STRUCT_ASSIGN
  153767. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  153768. #else
  153769. #if MAX_COMPS_IN_SCAN == 4
  153770. #define ASSIGN_STATE(dest,src) \
  153771. ((dest).EOBRUN = (src).EOBRUN, \
  153772. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  153773. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  153774. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  153775. (dest).last_dc_val[3] = (src).last_dc_val[3])
  153776. #endif
  153777. #endif
  153778. typedef struct {
  153779. struct jpeg_entropy_decoder pub; /* public fields */
  153780. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  153781. savable_state3 saved; /* Other state at start of MCU */
  153782. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  153783. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  153784. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  153785. } phuff_entropy_decoder;
  153786. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  153787. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  153788. JBLOCKROW *MCU_data));
  153789. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  153790. JBLOCKROW *MCU_data));
  153791. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  153792. JBLOCKROW *MCU_data));
  153793. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  153794. JBLOCKROW *MCU_data));
  153795. METHODDEF(void)
  153796. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  153797. {
  153798. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153799. boolean is_DC_band, bad;
  153800. int ci, coefi, tbl;
  153801. int *coef_bit_ptr;
  153802. jpeg_component_info * compptr;
  153803. is_DC_band = (cinfo->Ss == 0);
  153804. bad = FALSE;
  153805. if (is_DC_band) {
  153806. if (cinfo->Se != 0)
  153807. bad = TRUE;
  153808. } else {
  153809. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  153810. bad = TRUE;
  153811. if (cinfo->comps_in_scan != 1)
  153812. bad = TRUE;
  153813. }
  153814. if (cinfo->Ah != 0) {
  153815. if (cinfo->Al != cinfo->Ah-1)
  153816. bad = TRUE;
  153817. }
  153818. if (cinfo->Al > 13) /* need not check for < 0 */
  153819. bad = TRUE;
  153820. if (bad)
  153821. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  153822. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  153823. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153824. int cindex = cinfo->cur_comp_info[ci]->component_index;
  153825. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  153826. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  153827. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  153828. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  153829. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  153830. if (cinfo->Ah != expected)
  153831. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  153832. coef_bit_ptr[coefi] = cinfo->Al;
  153833. }
  153834. }
  153835. if (cinfo->Ah == 0) {
  153836. if (is_DC_band)
  153837. entropy->pub.decode_mcu = decode_mcu_DC_first;
  153838. else
  153839. entropy->pub.decode_mcu = decode_mcu_AC_first;
  153840. } else {
  153841. if (is_DC_band)
  153842. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  153843. else
  153844. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  153845. }
  153846. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153847. compptr = cinfo->cur_comp_info[ci];
  153848. if (is_DC_band) {
  153849. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  153850. tbl = compptr->dc_tbl_no;
  153851. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  153852. & entropy->derived_tbls[tbl]);
  153853. }
  153854. } else {
  153855. tbl = compptr->ac_tbl_no;
  153856. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  153857. & entropy->derived_tbls[tbl]);
  153858. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  153859. }
  153860. entropy->saved.last_dc_val[ci] = 0;
  153861. }
  153862. entropy->bitstate.bits_left = 0;
  153863. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  153864. entropy->pub.insufficient_data = FALSE;
  153865. entropy->saved.EOBRUN = 0;
  153866. entropy->restarts_to_go = cinfo->restart_interval;
  153867. }
  153868. LOCAL(boolean)
  153869. process_restartp (j_decompress_ptr cinfo)
  153870. {
  153871. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153872. int ci;
  153873. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  153874. entropy->bitstate.bits_left = 0;
  153875. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  153876. return FALSE;
  153877. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  153878. entropy->saved.last_dc_val[ci] = 0;
  153879. entropy->saved.EOBRUN = 0;
  153880. entropy->restarts_to_go = cinfo->restart_interval;
  153881. if (cinfo->unread_marker == 0)
  153882. entropy->pub.insufficient_data = FALSE;
  153883. return TRUE;
  153884. }
  153885. METHODDEF(boolean)
  153886. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  153887. {
  153888. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153889. int Al = cinfo->Al;
  153890. register int s, r;
  153891. int blkn, ci;
  153892. JBLOCKROW block;
  153893. BITREAD_STATE_VARS;
  153894. savable_state3 state;
  153895. d_derived_tbl * tbl;
  153896. jpeg_component_info * compptr;
  153897. if (cinfo->restart_interval) {
  153898. if (entropy->restarts_to_go == 0)
  153899. if (! process_restartp(cinfo))
  153900. return FALSE;
  153901. }
  153902. if (! entropy->pub.insufficient_data) {
  153903. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  153904. ASSIGN_STATE(state, entropy->saved);
  153905. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  153906. block = MCU_data[blkn];
  153907. ci = cinfo->MCU_membership[blkn];
  153908. compptr = cinfo->cur_comp_info[ci];
  153909. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  153910. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  153911. if (s) {
  153912. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  153913. r = GET_BITS(s);
  153914. s = HUFF_EXTEND(r, s);
  153915. }
  153916. s += state.last_dc_val[ci];
  153917. state.last_dc_val[ci] = s;
  153918. (*block)[0] = (JCOEF) (s << Al);
  153919. }
  153920. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  153921. ASSIGN_STATE(entropy->saved, state);
  153922. }
  153923. entropy->restarts_to_go--;
  153924. return TRUE;
  153925. }
  153926. METHODDEF(boolean)
  153927. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  153928. {
  153929. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153930. int Se = cinfo->Se;
  153931. int Al = cinfo->Al;
  153932. register int s, k, r;
  153933. unsigned int EOBRUN;
  153934. JBLOCKROW block;
  153935. BITREAD_STATE_VARS;
  153936. d_derived_tbl * tbl;
  153937. if (cinfo->restart_interval) {
  153938. if (entropy->restarts_to_go == 0)
  153939. if (! process_restartp(cinfo))
  153940. return FALSE;
  153941. }
  153942. if (! entropy->pub.insufficient_data) {
  153943. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  153944. if (EOBRUN > 0) /* if it's a band of zeroes... */
  153945. EOBRUN--; /* ...process it now (we do nothing) */
  153946. else {
  153947. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  153948. block = MCU_data[0];
  153949. tbl = entropy->ac_derived_tbl;
  153950. for (k = cinfo->Ss; k <= Se; k++) {
  153951. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  153952. r = s >> 4;
  153953. s &= 15;
  153954. if (s) {
  153955. k += r;
  153956. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  153957. r = GET_BITS(s);
  153958. s = HUFF_EXTEND(r, s);
  153959. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  153960. } else {
  153961. if (r == 15) { /* ZRL */
  153962. k += 15; /* skip 15 zeroes in band */
  153963. } else { /* EOBr, run length is 2^r + appended bits */
  153964. EOBRUN = 1 << r;
  153965. if (r) { /* EOBr, r > 0 */
  153966. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  153967. r = GET_BITS(r);
  153968. EOBRUN += r;
  153969. }
  153970. EOBRUN--; /* this band is processed at this moment */
  153971. break; /* force end-of-band */
  153972. }
  153973. }
  153974. }
  153975. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  153976. }
  153977. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  153978. }
  153979. entropy->restarts_to_go--;
  153980. return TRUE;
  153981. }
  153982. METHODDEF(boolean)
  153983. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  153984. {
  153985. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153986. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  153987. int blkn;
  153988. JBLOCKROW block;
  153989. BITREAD_STATE_VARS;
  153990. if (cinfo->restart_interval) {
  153991. if (entropy->restarts_to_go == 0)
  153992. if (! process_restartp(cinfo))
  153993. return FALSE;
  153994. }
  153995. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  153996. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  153997. block = MCU_data[blkn];
  153998. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  153999. if (GET_BITS(1))
  154000. (*block)[0] |= p1;
  154001. }
  154002. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154003. entropy->restarts_to_go--;
  154004. return TRUE;
  154005. }
  154006. METHODDEF(boolean)
  154007. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154008. {
  154009. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154010. int Se = cinfo->Se;
  154011. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154012. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154013. register int s, k, r;
  154014. unsigned int EOBRUN;
  154015. JBLOCKROW block;
  154016. JCOEFPTR thiscoef;
  154017. BITREAD_STATE_VARS;
  154018. d_derived_tbl * tbl;
  154019. int num_newnz;
  154020. int newnz_pos[DCTSIZE2];
  154021. if (cinfo->restart_interval) {
  154022. if (entropy->restarts_to_go == 0)
  154023. if (! process_restartp(cinfo))
  154024. return FALSE;
  154025. }
  154026. if (! entropy->pub.insufficient_data) {
  154027. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154028. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154029. block = MCU_data[0];
  154030. tbl = entropy->ac_derived_tbl;
  154031. num_newnz = 0;
  154032. k = cinfo->Ss;
  154033. if (EOBRUN == 0) {
  154034. for (; k <= Se; k++) {
  154035. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154036. r = s >> 4;
  154037. s &= 15;
  154038. if (s) {
  154039. if (s != 1) /* size of new coef should always be 1 */
  154040. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154041. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154042. if (GET_BITS(1))
  154043. s = p1; /* newly nonzero coef is positive */
  154044. else
  154045. s = m1; /* newly nonzero coef is negative */
  154046. } else {
  154047. if (r != 15) {
  154048. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154049. if (r) {
  154050. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154051. r = GET_BITS(r);
  154052. EOBRUN += r;
  154053. }
  154054. break; /* rest of block is handled by EOB logic */
  154055. }
  154056. }
  154057. do {
  154058. thiscoef = *block + jpeg_natural_order[k];
  154059. if (*thiscoef != 0) {
  154060. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154061. if (GET_BITS(1)) {
  154062. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154063. if (*thiscoef >= 0)
  154064. *thiscoef += p1;
  154065. else
  154066. *thiscoef += m1;
  154067. }
  154068. }
  154069. } else {
  154070. if (--r < 0)
  154071. break; /* reached target zero coefficient */
  154072. }
  154073. k++;
  154074. } while (k <= Se);
  154075. if (s) {
  154076. int pos = jpeg_natural_order[k];
  154077. (*block)[pos] = (JCOEF) s;
  154078. newnz_pos[num_newnz++] = pos;
  154079. }
  154080. }
  154081. }
  154082. if (EOBRUN > 0) {
  154083. for (; k <= Se; k++) {
  154084. thiscoef = *block + jpeg_natural_order[k];
  154085. if (*thiscoef != 0) {
  154086. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154087. if (GET_BITS(1)) {
  154088. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154089. if (*thiscoef >= 0)
  154090. *thiscoef += p1;
  154091. else
  154092. *thiscoef += m1;
  154093. }
  154094. }
  154095. }
  154096. }
  154097. EOBRUN--;
  154098. }
  154099. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154100. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154101. }
  154102. entropy->restarts_to_go--;
  154103. return TRUE;
  154104. undoit:
  154105. while (num_newnz > 0)
  154106. (*block)[newnz_pos[--num_newnz]] = 0;
  154107. return FALSE;
  154108. }
  154109. GLOBAL(void)
  154110. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154111. {
  154112. phuff_entropy_ptr2 entropy;
  154113. int *coef_bit_ptr;
  154114. int ci, i;
  154115. entropy = (phuff_entropy_ptr2)
  154116. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154117. SIZEOF(phuff_entropy_decoder));
  154118. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154119. entropy->pub.start_pass = start_pass_phuff_decoder;
  154120. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154121. entropy->derived_tbls[i] = NULL;
  154122. }
  154123. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154124. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154125. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154126. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154127. for (ci = 0; ci < cinfo->num_components; ci++)
  154128. for (i = 0; i < DCTSIZE2; i++)
  154129. *coef_bit_ptr++ = -1;
  154130. }
  154131. #endif /* D_PROGRESSIVE_SUPPORTED */
  154132. /*** End of inlined file: jdphuff.c ***/
  154133. /*** Start of inlined file: jdpostct.c ***/
  154134. #define JPEG_INTERNALS
  154135. typedef struct {
  154136. struct jpeg_d_post_controller pub; /* public fields */
  154137. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154138. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154139. JDIMENSION strip_height; /* buffer size in rows */
  154140. JDIMENSION starting_row; /* row # of first row in current strip */
  154141. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154142. } my_post_controller;
  154143. typedef my_post_controller * my_post_ptr;
  154144. METHODDEF(void) post_process_1pass
  154145. JPP((j_decompress_ptr cinfo,
  154146. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154147. JDIMENSION in_row_groups_avail,
  154148. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154149. JDIMENSION out_rows_avail));
  154150. #ifdef QUANT_2PASS_SUPPORTED
  154151. METHODDEF(void) post_process_prepass
  154152. JPP((j_decompress_ptr cinfo,
  154153. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154154. JDIMENSION in_row_groups_avail,
  154155. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154156. JDIMENSION out_rows_avail));
  154157. METHODDEF(void) post_process_2pass
  154158. JPP((j_decompress_ptr cinfo,
  154159. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154160. JDIMENSION in_row_groups_avail,
  154161. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154162. JDIMENSION out_rows_avail));
  154163. #endif
  154164. METHODDEF(void)
  154165. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154166. {
  154167. my_post_ptr post = (my_post_ptr) cinfo->post;
  154168. switch (pass_mode) {
  154169. case JBUF_PASS_THRU:
  154170. if (cinfo->quantize_colors) {
  154171. post->pub.post_process_data = post_process_1pass;
  154172. if (post->buffer == NULL) {
  154173. post->buffer = (*cinfo->mem->access_virt_sarray)
  154174. ((j_common_ptr) cinfo, post->whole_image,
  154175. (JDIMENSION) 0, post->strip_height, TRUE);
  154176. }
  154177. } else {
  154178. post->pub.post_process_data = cinfo->upsample->upsample;
  154179. }
  154180. break;
  154181. #ifdef QUANT_2PASS_SUPPORTED
  154182. case JBUF_SAVE_AND_PASS:
  154183. if (post->whole_image == NULL)
  154184. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154185. post->pub.post_process_data = post_process_prepass;
  154186. break;
  154187. case JBUF_CRANK_DEST:
  154188. if (post->whole_image == NULL)
  154189. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154190. post->pub.post_process_data = post_process_2pass;
  154191. break;
  154192. #endif /* QUANT_2PASS_SUPPORTED */
  154193. default:
  154194. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154195. break;
  154196. }
  154197. post->starting_row = post->next_row = 0;
  154198. }
  154199. METHODDEF(void)
  154200. post_process_1pass (j_decompress_ptr cinfo,
  154201. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154202. JDIMENSION in_row_groups_avail,
  154203. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154204. JDIMENSION out_rows_avail)
  154205. {
  154206. my_post_ptr post = (my_post_ptr) cinfo->post;
  154207. JDIMENSION num_rows, max_rows;
  154208. max_rows = out_rows_avail - *out_row_ctr;
  154209. if (max_rows > post->strip_height)
  154210. max_rows = post->strip_height;
  154211. num_rows = 0;
  154212. (*cinfo->upsample->upsample) (cinfo,
  154213. input_buf, in_row_group_ctr, in_row_groups_avail,
  154214. post->buffer, &num_rows, max_rows);
  154215. (*cinfo->cquantize->color_quantize) (cinfo,
  154216. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154217. *out_row_ctr += num_rows;
  154218. }
  154219. #ifdef QUANT_2PASS_SUPPORTED
  154220. METHODDEF(void)
  154221. post_process_prepass (j_decompress_ptr cinfo,
  154222. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154223. JDIMENSION in_row_groups_avail,
  154224. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154225. JDIMENSION out_rows_avail)
  154226. {
  154227. my_post_ptr post = (my_post_ptr) cinfo->post;
  154228. JDIMENSION old_next_row, num_rows;
  154229. if (post->next_row == 0) {
  154230. post->buffer = (*cinfo->mem->access_virt_sarray)
  154231. ((j_common_ptr) cinfo, post->whole_image,
  154232. post->starting_row, post->strip_height, TRUE);
  154233. }
  154234. old_next_row = post->next_row;
  154235. (*cinfo->upsample->upsample) (cinfo,
  154236. input_buf, in_row_group_ctr, in_row_groups_avail,
  154237. post->buffer, &post->next_row, post->strip_height);
  154238. if (post->next_row > old_next_row) {
  154239. num_rows = post->next_row - old_next_row;
  154240. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154241. (JSAMPARRAY) NULL, (int) num_rows);
  154242. *out_row_ctr += num_rows;
  154243. }
  154244. if (post->next_row >= post->strip_height) {
  154245. post->starting_row += post->strip_height;
  154246. post->next_row = 0;
  154247. }
  154248. }
  154249. METHODDEF(void)
  154250. post_process_2pass (j_decompress_ptr cinfo,
  154251. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154252. JDIMENSION in_row_groups_avail,
  154253. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154254. JDIMENSION out_rows_avail)
  154255. {
  154256. my_post_ptr post = (my_post_ptr) cinfo->post;
  154257. JDIMENSION num_rows, max_rows;
  154258. if (post->next_row == 0) {
  154259. post->buffer = (*cinfo->mem->access_virt_sarray)
  154260. ((j_common_ptr) cinfo, post->whole_image,
  154261. post->starting_row, post->strip_height, FALSE);
  154262. }
  154263. num_rows = post->strip_height - post->next_row; /* available in strip */
  154264. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154265. if (num_rows > max_rows)
  154266. num_rows = max_rows;
  154267. max_rows = cinfo->output_height - post->starting_row;
  154268. if (num_rows > max_rows)
  154269. num_rows = max_rows;
  154270. (*cinfo->cquantize->color_quantize) (cinfo,
  154271. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154272. (int) num_rows);
  154273. *out_row_ctr += num_rows;
  154274. post->next_row += num_rows;
  154275. if (post->next_row >= post->strip_height) {
  154276. post->starting_row += post->strip_height;
  154277. post->next_row = 0;
  154278. }
  154279. }
  154280. #endif /* QUANT_2PASS_SUPPORTED */
  154281. GLOBAL(void)
  154282. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154283. {
  154284. my_post_ptr post;
  154285. post = (my_post_ptr)
  154286. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154287. SIZEOF(my_post_controller));
  154288. cinfo->post = (struct jpeg_d_post_controller *) post;
  154289. post->pub.start_pass = start_pass_dpost;
  154290. post->whole_image = NULL; /* flag for no virtual arrays */
  154291. post->buffer = NULL; /* flag for no strip buffer */
  154292. if (cinfo->quantize_colors) {
  154293. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154294. if (need_full_buffer) {
  154295. #ifdef QUANT_2PASS_SUPPORTED
  154296. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154297. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154298. cinfo->output_width * cinfo->out_color_components,
  154299. (JDIMENSION) jround_up((long) cinfo->output_height,
  154300. (long) post->strip_height),
  154301. post->strip_height);
  154302. #else
  154303. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154304. #endif /* QUANT_2PASS_SUPPORTED */
  154305. } else {
  154306. post->buffer = (*cinfo->mem->alloc_sarray)
  154307. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154308. cinfo->output_width * cinfo->out_color_components,
  154309. post->strip_height);
  154310. }
  154311. }
  154312. }
  154313. /*** End of inlined file: jdpostct.c ***/
  154314. #undef FIX
  154315. /*** Start of inlined file: jdsample.c ***/
  154316. #define JPEG_INTERNALS
  154317. typedef JMETHOD(void, upsample1_ptr,
  154318. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154319. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154320. typedef struct {
  154321. struct jpeg_upsampler pub; /* public fields */
  154322. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154323. upsample1_ptr methods[MAX_COMPONENTS];
  154324. int next_row_out; /* counts rows emitted from color_buf */
  154325. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154326. int rowgroup_height[MAX_COMPONENTS];
  154327. UINT8 h_expand[MAX_COMPONENTS];
  154328. UINT8 v_expand[MAX_COMPONENTS];
  154329. } my_upsampler2;
  154330. typedef my_upsampler2 * my_upsample_ptr2;
  154331. METHODDEF(void)
  154332. start_pass_upsample (j_decompress_ptr cinfo)
  154333. {
  154334. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154335. upsample->next_row_out = cinfo->max_v_samp_factor;
  154336. upsample->rows_to_go = cinfo->output_height;
  154337. }
  154338. METHODDEF(void)
  154339. sep_upsample (j_decompress_ptr cinfo,
  154340. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154341. JDIMENSION in_row_groups_avail,
  154342. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154343. JDIMENSION out_rows_avail)
  154344. {
  154345. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154346. int ci;
  154347. jpeg_component_info * compptr;
  154348. JDIMENSION num_rows;
  154349. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154350. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154351. ci++, compptr++) {
  154352. (*upsample->methods[ci]) (cinfo, compptr,
  154353. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154354. upsample->color_buf + ci);
  154355. }
  154356. upsample->next_row_out = 0;
  154357. }
  154358. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154359. if (num_rows > upsample->rows_to_go)
  154360. num_rows = upsample->rows_to_go;
  154361. out_rows_avail -= *out_row_ctr;
  154362. if (num_rows > out_rows_avail)
  154363. num_rows = out_rows_avail;
  154364. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154365. (JDIMENSION) upsample->next_row_out,
  154366. output_buf + *out_row_ctr,
  154367. (int) num_rows);
  154368. *out_row_ctr += num_rows;
  154369. upsample->rows_to_go -= num_rows;
  154370. upsample->next_row_out += num_rows;
  154371. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154372. (*in_row_group_ctr)++;
  154373. }
  154374. METHODDEF(void)
  154375. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154376. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154377. {
  154378. *output_data_ptr = input_data;
  154379. }
  154380. METHODDEF(void)
  154381. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154382. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154383. {
  154384. *output_data_ptr = NULL; /* safety check */
  154385. }
  154386. METHODDEF(void)
  154387. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154388. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154389. {
  154390. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154391. JSAMPARRAY output_data = *output_data_ptr;
  154392. register JSAMPROW inptr, outptr;
  154393. register JSAMPLE invalue;
  154394. register int h;
  154395. JSAMPROW outend;
  154396. int h_expand, v_expand;
  154397. int inrow, outrow;
  154398. h_expand = upsample->h_expand[compptr->component_index];
  154399. v_expand = upsample->v_expand[compptr->component_index];
  154400. inrow = outrow = 0;
  154401. while (outrow < cinfo->max_v_samp_factor) {
  154402. inptr = input_data[inrow];
  154403. outptr = output_data[outrow];
  154404. outend = outptr + cinfo->output_width;
  154405. while (outptr < outend) {
  154406. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154407. for (h = h_expand; h > 0; h--) {
  154408. *outptr++ = invalue;
  154409. }
  154410. }
  154411. if (v_expand > 1) {
  154412. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154413. v_expand-1, cinfo->output_width);
  154414. }
  154415. inrow++;
  154416. outrow += v_expand;
  154417. }
  154418. }
  154419. METHODDEF(void)
  154420. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154421. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154422. {
  154423. JSAMPARRAY output_data = *output_data_ptr;
  154424. register JSAMPROW inptr, outptr;
  154425. register JSAMPLE invalue;
  154426. JSAMPROW outend;
  154427. int inrow;
  154428. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154429. inptr = input_data[inrow];
  154430. outptr = output_data[inrow];
  154431. outend = outptr + cinfo->output_width;
  154432. while (outptr < outend) {
  154433. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154434. *outptr++ = invalue;
  154435. *outptr++ = invalue;
  154436. }
  154437. }
  154438. }
  154439. METHODDEF(void)
  154440. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154441. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154442. {
  154443. JSAMPARRAY output_data = *output_data_ptr;
  154444. register JSAMPROW inptr, outptr;
  154445. register JSAMPLE invalue;
  154446. JSAMPROW outend;
  154447. int inrow, outrow;
  154448. inrow = outrow = 0;
  154449. while (outrow < cinfo->max_v_samp_factor) {
  154450. inptr = input_data[inrow];
  154451. outptr = output_data[outrow];
  154452. outend = outptr + cinfo->output_width;
  154453. while (outptr < outend) {
  154454. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154455. *outptr++ = invalue;
  154456. *outptr++ = invalue;
  154457. }
  154458. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154459. 1, cinfo->output_width);
  154460. inrow++;
  154461. outrow += 2;
  154462. }
  154463. }
  154464. METHODDEF(void)
  154465. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154466. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154467. {
  154468. JSAMPARRAY output_data = *output_data_ptr;
  154469. register JSAMPROW inptr, outptr;
  154470. register int invalue;
  154471. register JDIMENSION colctr;
  154472. int inrow;
  154473. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154474. inptr = input_data[inrow];
  154475. outptr = output_data[inrow];
  154476. invalue = GETJSAMPLE(*inptr++);
  154477. *outptr++ = (JSAMPLE) invalue;
  154478. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154479. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154480. invalue = GETJSAMPLE(*inptr++) * 3;
  154481. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154482. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154483. }
  154484. invalue = GETJSAMPLE(*inptr);
  154485. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154486. *outptr++ = (JSAMPLE) invalue;
  154487. }
  154488. }
  154489. METHODDEF(void)
  154490. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154491. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154492. {
  154493. JSAMPARRAY output_data = *output_data_ptr;
  154494. register JSAMPROW inptr0, inptr1, outptr;
  154495. #if BITS_IN_JSAMPLE == 8
  154496. register int thiscolsum, lastcolsum, nextcolsum;
  154497. #else
  154498. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154499. #endif
  154500. register JDIMENSION colctr;
  154501. int inrow, outrow, v;
  154502. inrow = outrow = 0;
  154503. while (outrow < cinfo->max_v_samp_factor) {
  154504. for (v = 0; v < 2; v++) {
  154505. inptr0 = input_data[inrow];
  154506. if (v == 0) /* next nearest is row above */
  154507. inptr1 = input_data[inrow-1];
  154508. else /* next nearest is row below */
  154509. inptr1 = input_data[inrow+1];
  154510. outptr = output_data[outrow++];
  154511. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154512. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154513. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154514. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154515. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154516. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154517. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154518. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154519. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154520. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154521. }
  154522. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154523. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154524. }
  154525. inrow++;
  154526. }
  154527. }
  154528. GLOBAL(void)
  154529. jinit_upsampler (j_decompress_ptr cinfo)
  154530. {
  154531. my_upsample_ptr2 upsample;
  154532. int ci;
  154533. jpeg_component_info * compptr;
  154534. boolean need_buffer, do_fancy;
  154535. int h_in_group, v_in_group, h_out_group, v_out_group;
  154536. upsample = (my_upsample_ptr2)
  154537. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154538. SIZEOF(my_upsampler2));
  154539. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154540. upsample->pub.start_pass = start_pass_upsample;
  154541. upsample->pub.upsample = sep_upsample;
  154542. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154543. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154544. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154545. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154546. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154547. ci++, compptr++) {
  154548. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154549. cinfo->min_DCT_scaled_size;
  154550. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154551. cinfo->min_DCT_scaled_size;
  154552. h_out_group = cinfo->max_h_samp_factor;
  154553. v_out_group = cinfo->max_v_samp_factor;
  154554. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154555. need_buffer = TRUE;
  154556. if (! compptr->component_needed) {
  154557. upsample->methods[ci] = noop_upsample;
  154558. need_buffer = FALSE;
  154559. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154560. upsample->methods[ci] = fullsize_upsample;
  154561. need_buffer = FALSE;
  154562. } else if (h_in_group * 2 == h_out_group &&
  154563. v_in_group == v_out_group) {
  154564. if (do_fancy && compptr->downsampled_width > 2)
  154565. upsample->methods[ci] = h2v1_fancy_upsample;
  154566. else
  154567. upsample->methods[ci] = h2v1_upsample;
  154568. } else if (h_in_group * 2 == h_out_group &&
  154569. v_in_group * 2 == v_out_group) {
  154570. if (do_fancy && compptr->downsampled_width > 2) {
  154571. upsample->methods[ci] = h2v2_fancy_upsample;
  154572. upsample->pub.need_context_rows = TRUE;
  154573. } else
  154574. upsample->methods[ci] = h2v2_upsample;
  154575. } else if ((h_out_group % h_in_group) == 0 &&
  154576. (v_out_group % v_in_group) == 0) {
  154577. upsample->methods[ci] = int_upsample;
  154578. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154579. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154580. } else
  154581. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154582. if (need_buffer) {
  154583. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154584. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154585. (JDIMENSION) jround_up((long) cinfo->output_width,
  154586. (long) cinfo->max_h_samp_factor),
  154587. (JDIMENSION) cinfo->max_v_samp_factor);
  154588. }
  154589. }
  154590. }
  154591. /*** End of inlined file: jdsample.c ***/
  154592. /*** Start of inlined file: jdtrans.c ***/
  154593. #define JPEG_INTERNALS
  154594. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154595. GLOBAL(jvirt_barray_ptr *)
  154596. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154597. {
  154598. if (cinfo->global_state == DSTATE_READY) {
  154599. transdecode_master_selection(cinfo);
  154600. cinfo->global_state = DSTATE_RDCOEFS;
  154601. }
  154602. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154603. for (;;) {
  154604. int retcode;
  154605. if (cinfo->progress != NULL)
  154606. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154607. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154608. if (retcode == JPEG_SUSPENDED)
  154609. return NULL;
  154610. if (retcode == JPEG_REACHED_EOI)
  154611. break;
  154612. if (cinfo->progress != NULL &&
  154613. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154614. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154615. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154616. }
  154617. }
  154618. }
  154619. cinfo->global_state = DSTATE_STOPPING;
  154620. }
  154621. if ((cinfo->global_state == DSTATE_STOPPING ||
  154622. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154623. return cinfo->coef->coef_arrays;
  154624. }
  154625. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154626. return NULL; /* keep compiler happy */
  154627. }
  154628. LOCAL(void)
  154629. transdecode_master_selection (j_decompress_ptr cinfo)
  154630. {
  154631. cinfo->buffered_image = TRUE;
  154632. if (cinfo->arith_code) {
  154633. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154634. } else {
  154635. if (cinfo->progressive_mode) {
  154636. #ifdef D_PROGRESSIVE_SUPPORTED
  154637. jinit_phuff_decoder(cinfo);
  154638. #else
  154639. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154640. #endif
  154641. } else
  154642. jinit_huff_decoder(cinfo);
  154643. }
  154644. jinit_d_coef_controller(cinfo, TRUE);
  154645. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154646. (*cinfo->inputctl->start_input_pass) (cinfo);
  154647. if (cinfo->progress != NULL) {
  154648. int nscans;
  154649. if (cinfo->progressive_mode) {
  154650. nscans = 2 + 3 * cinfo->num_components;
  154651. } else if (cinfo->inputctl->has_multiple_scans) {
  154652. nscans = cinfo->num_components;
  154653. } else {
  154654. nscans = 1;
  154655. }
  154656. cinfo->progress->pass_counter = 0L;
  154657. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154658. cinfo->progress->completed_passes = 0;
  154659. cinfo->progress->total_passes = 1;
  154660. }
  154661. }
  154662. /*** End of inlined file: jdtrans.c ***/
  154663. /*** Start of inlined file: jfdctflt.c ***/
  154664. #define JPEG_INTERNALS
  154665. #ifdef DCT_FLOAT_SUPPORTED
  154666. #if DCTSIZE != 8
  154667. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154668. #endif
  154669. GLOBAL(void)
  154670. jpeg_fdct_float (FAST_FLOAT * data)
  154671. {
  154672. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154673. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154674. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154675. FAST_FLOAT *dataptr;
  154676. int ctr;
  154677. dataptr = data;
  154678. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154679. tmp0 = dataptr[0] + dataptr[7];
  154680. tmp7 = dataptr[0] - dataptr[7];
  154681. tmp1 = dataptr[1] + dataptr[6];
  154682. tmp6 = dataptr[1] - dataptr[6];
  154683. tmp2 = dataptr[2] + dataptr[5];
  154684. tmp5 = dataptr[2] - dataptr[5];
  154685. tmp3 = dataptr[3] + dataptr[4];
  154686. tmp4 = dataptr[3] - dataptr[4];
  154687. tmp10 = tmp0 + tmp3; /* phase 2 */
  154688. tmp13 = tmp0 - tmp3;
  154689. tmp11 = tmp1 + tmp2;
  154690. tmp12 = tmp1 - tmp2;
  154691. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154692. dataptr[4] = tmp10 - tmp11;
  154693. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154694. dataptr[2] = tmp13 + z1; /* phase 5 */
  154695. dataptr[6] = tmp13 - z1;
  154696. tmp10 = tmp4 + tmp5; /* phase 2 */
  154697. tmp11 = tmp5 + tmp6;
  154698. tmp12 = tmp6 + tmp7;
  154699. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154700. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154701. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154702. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154703. z11 = tmp7 + z3; /* phase 5 */
  154704. z13 = tmp7 - z3;
  154705. dataptr[5] = z13 + z2; /* phase 6 */
  154706. dataptr[3] = z13 - z2;
  154707. dataptr[1] = z11 + z4;
  154708. dataptr[7] = z11 - z4;
  154709. dataptr += DCTSIZE; /* advance pointer to next row */
  154710. }
  154711. dataptr = data;
  154712. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154713. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154714. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154715. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154716. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154717. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154718. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154719. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154720. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154721. tmp10 = tmp0 + tmp3; /* phase 2 */
  154722. tmp13 = tmp0 - tmp3;
  154723. tmp11 = tmp1 + tmp2;
  154724. tmp12 = tmp1 - tmp2;
  154725. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154726. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154727. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154728. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154729. dataptr[DCTSIZE*6] = tmp13 - z1;
  154730. tmp10 = tmp4 + tmp5; /* phase 2 */
  154731. tmp11 = tmp5 + tmp6;
  154732. tmp12 = tmp6 + tmp7;
  154733. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154734. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154735. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154736. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154737. z11 = tmp7 + z3; /* phase 5 */
  154738. z13 = tmp7 - z3;
  154739. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  154740. dataptr[DCTSIZE*3] = z13 - z2;
  154741. dataptr[DCTSIZE*1] = z11 + z4;
  154742. dataptr[DCTSIZE*7] = z11 - z4;
  154743. dataptr++; /* advance pointer to next column */
  154744. }
  154745. }
  154746. #endif /* DCT_FLOAT_SUPPORTED */
  154747. /*** End of inlined file: jfdctflt.c ***/
  154748. /*** Start of inlined file: jfdctint.c ***/
  154749. #define JPEG_INTERNALS
  154750. #ifdef DCT_ISLOW_SUPPORTED
  154751. #if DCTSIZE != 8
  154752. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154753. #endif
  154754. #if BITS_IN_JSAMPLE == 8
  154755. #define CONST_BITS 13
  154756. #define PASS1_BITS 2
  154757. #else
  154758. #define CONST_BITS 13
  154759. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  154760. #endif
  154761. #if CONST_BITS == 13
  154762. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  154763. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  154764. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  154765. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  154766. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  154767. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  154768. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  154769. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  154770. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  154771. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  154772. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  154773. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  154774. #else
  154775. #define FIX_0_298631336 FIX(0.298631336)
  154776. #define FIX_0_390180644 FIX(0.390180644)
  154777. #define FIX_0_541196100 FIX(0.541196100)
  154778. #define FIX_0_765366865 FIX(0.765366865)
  154779. #define FIX_0_899976223 FIX(0.899976223)
  154780. #define FIX_1_175875602 FIX(1.175875602)
  154781. #define FIX_1_501321110 FIX(1.501321110)
  154782. #define FIX_1_847759065 FIX(1.847759065)
  154783. #define FIX_1_961570560 FIX(1.961570560)
  154784. #define FIX_2_053119869 FIX(2.053119869)
  154785. #define FIX_2_562915447 FIX(2.562915447)
  154786. #define FIX_3_072711026 FIX(3.072711026)
  154787. #endif
  154788. #if BITS_IN_JSAMPLE == 8
  154789. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  154790. #else
  154791. #define MULTIPLY(var,const) ((var) * (const))
  154792. #endif
  154793. GLOBAL(void)
  154794. jpeg_fdct_islow (DCTELEM * data)
  154795. {
  154796. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154797. INT32 tmp10, tmp11, tmp12, tmp13;
  154798. INT32 z1, z2, z3, z4, z5;
  154799. DCTELEM *dataptr;
  154800. int ctr;
  154801. SHIFT_TEMPS
  154802. dataptr = data;
  154803. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154804. tmp0 = dataptr[0] + dataptr[7];
  154805. tmp7 = dataptr[0] - dataptr[7];
  154806. tmp1 = dataptr[1] + dataptr[6];
  154807. tmp6 = dataptr[1] - dataptr[6];
  154808. tmp2 = dataptr[2] + dataptr[5];
  154809. tmp5 = dataptr[2] - dataptr[5];
  154810. tmp3 = dataptr[3] + dataptr[4];
  154811. tmp4 = dataptr[3] - dataptr[4];
  154812. tmp10 = tmp0 + tmp3;
  154813. tmp13 = tmp0 - tmp3;
  154814. tmp11 = tmp1 + tmp2;
  154815. tmp12 = tmp1 - tmp2;
  154816. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  154817. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  154818. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  154819. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  154820. CONST_BITS-PASS1_BITS);
  154821. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  154822. CONST_BITS-PASS1_BITS);
  154823. z1 = tmp4 + tmp7;
  154824. z2 = tmp5 + tmp6;
  154825. z3 = tmp4 + tmp6;
  154826. z4 = tmp5 + tmp7;
  154827. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  154828. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  154829. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  154830. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  154831. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  154832. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  154833. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  154834. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  154835. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  154836. z3 += z5;
  154837. z4 += z5;
  154838. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  154839. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  154840. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  154841. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  154842. dataptr += DCTSIZE; /* advance pointer to next row */
  154843. }
  154844. dataptr = data;
  154845. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154846. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154847. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154848. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154849. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154850. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154851. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154852. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154853. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154854. tmp10 = tmp0 + tmp3;
  154855. tmp13 = tmp0 - tmp3;
  154856. tmp11 = tmp1 + tmp2;
  154857. tmp12 = tmp1 - tmp2;
  154858. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  154859. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  154860. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  154861. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  154862. CONST_BITS+PASS1_BITS);
  154863. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  154864. CONST_BITS+PASS1_BITS);
  154865. z1 = tmp4 + tmp7;
  154866. z2 = tmp5 + tmp6;
  154867. z3 = tmp4 + tmp6;
  154868. z4 = tmp5 + tmp7;
  154869. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  154870. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  154871. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  154872. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  154873. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  154874. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  154875. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  154876. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  154877. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  154878. z3 += z5;
  154879. z4 += z5;
  154880. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  154881. CONST_BITS+PASS1_BITS);
  154882. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  154883. CONST_BITS+PASS1_BITS);
  154884. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  154885. CONST_BITS+PASS1_BITS);
  154886. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  154887. CONST_BITS+PASS1_BITS);
  154888. dataptr++; /* advance pointer to next column */
  154889. }
  154890. }
  154891. #endif /* DCT_ISLOW_SUPPORTED */
  154892. /*** End of inlined file: jfdctint.c ***/
  154893. #undef CONST_BITS
  154894. #undef MULTIPLY
  154895. #undef FIX_0_541196100
  154896. /*** Start of inlined file: jfdctfst.c ***/
  154897. #define JPEG_INTERNALS
  154898. #ifdef DCT_IFAST_SUPPORTED
  154899. #if DCTSIZE != 8
  154900. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154901. #endif
  154902. #define CONST_BITS 8
  154903. #if CONST_BITS == 8
  154904. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  154905. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  154906. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  154907. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  154908. #else
  154909. #define FIX_0_382683433 FIX(0.382683433)
  154910. #define FIX_0_541196100 FIX(0.541196100)
  154911. #define FIX_0_707106781 FIX(0.707106781)
  154912. #define FIX_1_306562965 FIX(1.306562965)
  154913. #endif
  154914. #ifndef USE_ACCURATE_ROUNDING
  154915. #undef DESCALE
  154916. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  154917. #endif
  154918. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  154919. GLOBAL(void)
  154920. jpeg_fdct_ifast (DCTELEM * data)
  154921. {
  154922. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154923. DCTELEM tmp10, tmp11, tmp12, tmp13;
  154924. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  154925. DCTELEM *dataptr;
  154926. int ctr;
  154927. SHIFT_TEMPS
  154928. dataptr = data;
  154929. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154930. tmp0 = dataptr[0] + dataptr[7];
  154931. tmp7 = dataptr[0] - dataptr[7];
  154932. tmp1 = dataptr[1] + dataptr[6];
  154933. tmp6 = dataptr[1] - dataptr[6];
  154934. tmp2 = dataptr[2] + dataptr[5];
  154935. tmp5 = dataptr[2] - dataptr[5];
  154936. tmp3 = dataptr[3] + dataptr[4];
  154937. tmp4 = dataptr[3] - dataptr[4];
  154938. tmp10 = tmp0 + tmp3; /* phase 2 */
  154939. tmp13 = tmp0 - tmp3;
  154940. tmp11 = tmp1 + tmp2;
  154941. tmp12 = tmp1 - tmp2;
  154942. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154943. dataptr[4] = tmp10 - tmp11;
  154944. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  154945. dataptr[2] = tmp13 + z1; /* phase 5 */
  154946. dataptr[6] = tmp13 - z1;
  154947. tmp10 = tmp4 + tmp5; /* phase 2 */
  154948. tmp11 = tmp5 + tmp6;
  154949. tmp12 = tmp6 + tmp7;
  154950. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  154951. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  154952. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  154953. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  154954. z11 = tmp7 + z3; /* phase 5 */
  154955. z13 = tmp7 - z3;
  154956. dataptr[5] = z13 + z2; /* phase 6 */
  154957. dataptr[3] = z13 - z2;
  154958. dataptr[1] = z11 + z4;
  154959. dataptr[7] = z11 - z4;
  154960. dataptr += DCTSIZE; /* advance pointer to next row */
  154961. }
  154962. dataptr = data;
  154963. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154964. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154965. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154966. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154967. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154968. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154969. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154970. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154971. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154972. tmp10 = tmp0 + tmp3; /* phase 2 */
  154973. tmp13 = tmp0 - tmp3;
  154974. tmp11 = tmp1 + tmp2;
  154975. tmp12 = tmp1 - tmp2;
  154976. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154977. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154978. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  154979. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154980. dataptr[DCTSIZE*6] = tmp13 - z1;
  154981. tmp10 = tmp4 + tmp5; /* phase 2 */
  154982. tmp11 = tmp5 + tmp6;
  154983. tmp12 = tmp6 + tmp7;
  154984. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  154985. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  154986. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  154987. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  154988. z11 = tmp7 + z3; /* phase 5 */
  154989. z13 = tmp7 - z3;
  154990. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  154991. dataptr[DCTSIZE*3] = z13 - z2;
  154992. dataptr[DCTSIZE*1] = z11 + z4;
  154993. dataptr[DCTSIZE*7] = z11 - z4;
  154994. dataptr++; /* advance pointer to next column */
  154995. }
  154996. }
  154997. #endif /* DCT_IFAST_SUPPORTED */
  154998. /*** End of inlined file: jfdctfst.c ***/
  154999. #undef FIX_0_541196100
  155000. /*** Start of inlined file: jidctflt.c ***/
  155001. #define JPEG_INTERNALS
  155002. #ifdef DCT_FLOAT_SUPPORTED
  155003. #if DCTSIZE != 8
  155004. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155005. #endif
  155006. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155007. GLOBAL(void)
  155008. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155009. JCOEFPTR coef_block,
  155010. JSAMPARRAY output_buf, JDIMENSION output_col)
  155011. {
  155012. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155013. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155014. FAST_FLOAT z5, z10, z11, z12, z13;
  155015. JCOEFPTR inptr;
  155016. FLOAT_MULT_TYPE * quantptr;
  155017. FAST_FLOAT * wsptr;
  155018. JSAMPROW outptr;
  155019. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155020. int ctr;
  155021. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155022. SHIFT_TEMPS
  155023. inptr = coef_block;
  155024. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155025. wsptr = workspace;
  155026. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155027. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155028. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155029. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155030. inptr[DCTSIZE*7] == 0) {
  155031. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155032. wsptr[DCTSIZE*0] = dcval;
  155033. wsptr[DCTSIZE*1] = dcval;
  155034. wsptr[DCTSIZE*2] = dcval;
  155035. wsptr[DCTSIZE*3] = dcval;
  155036. wsptr[DCTSIZE*4] = dcval;
  155037. wsptr[DCTSIZE*5] = dcval;
  155038. wsptr[DCTSIZE*6] = dcval;
  155039. wsptr[DCTSIZE*7] = dcval;
  155040. inptr++; /* advance pointers to next column */
  155041. quantptr++;
  155042. wsptr++;
  155043. continue;
  155044. }
  155045. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155046. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155047. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155048. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155049. tmp10 = tmp0 + tmp2; /* phase 3 */
  155050. tmp11 = tmp0 - tmp2;
  155051. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155052. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155053. tmp0 = tmp10 + tmp13; /* phase 2 */
  155054. tmp3 = tmp10 - tmp13;
  155055. tmp1 = tmp11 + tmp12;
  155056. tmp2 = tmp11 - tmp12;
  155057. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155058. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155059. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155060. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155061. z13 = tmp6 + tmp5; /* phase 6 */
  155062. z10 = tmp6 - tmp5;
  155063. z11 = tmp4 + tmp7;
  155064. z12 = tmp4 - tmp7;
  155065. tmp7 = z11 + z13; /* phase 5 */
  155066. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155067. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155068. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155069. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155070. tmp6 = tmp12 - tmp7; /* phase 2 */
  155071. tmp5 = tmp11 - tmp6;
  155072. tmp4 = tmp10 + tmp5;
  155073. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155074. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155075. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155076. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155077. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155078. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155079. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155080. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155081. inptr++; /* advance pointers to next column */
  155082. quantptr++;
  155083. wsptr++;
  155084. }
  155085. wsptr = workspace;
  155086. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155087. outptr = output_buf[ctr] + output_col;
  155088. tmp10 = wsptr[0] + wsptr[4];
  155089. tmp11 = wsptr[0] - wsptr[4];
  155090. tmp13 = wsptr[2] + wsptr[6];
  155091. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155092. tmp0 = tmp10 + tmp13;
  155093. tmp3 = tmp10 - tmp13;
  155094. tmp1 = tmp11 + tmp12;
  155095. tmp2 = tmp11 - tmp12;
  155096. z13 = wsptr[5] + wsptr[3];
  155097. z10 = wsptr[5] - wsptr[3];
  155098. z11 = wsptr[1] + wsptr[7];
  155099. z12 = wsptr[1] - wsptr[7];
  155100. tmp7 = z11 + z13;
  155101. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155102. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155103. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155104. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155105. tmp6 = tmp12 - tmp7;
  155106. tmp5 = tmp11 - tmp6;
  155107. tmp4 = tmp10 + tmp5;
  155108. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155109. & RANGE_MASK];
  155110. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155111. & RANGE_MASK];
  155112. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155113. & RANGE_MASK];
  155114. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155115. & RANGE_MASK];
  155116. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155117. & RANGE_MASK];
  155118. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155119. & RANGE_MASK];
  155120. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155121. & RANGE_MASK];
  155122. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155123. & RANGE_MASK];
  155124. wsptr += DCTSIZE; /* advance pointer to next row */
  155125. }
  155126. }
  155127. #endif /* DCT_FLOAT_SUPPORTED */
  155128. /*** End of inlined file: jidctflt.c ***/
  155129. #undef CONST_BITS
  155130. #undef FIX_1_847759065
  155131. #undef MULTIPLY
  155132. #undef DEQUANTIZE
  155133. #undef DESCALE
  155134. /*** Start of inlined file: jidctfst.c ***/
  155135. #define JPEG_INTERNALS
  155136. #ifdef DCT_IFAST_SUPPORTED
  155137. #if DCTSIZE != 8
  155138. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155139. #endif
  155140. #if BITS_IN_JSAMPLE == 8
  155141. #define CONST_BITS 8
  155142. #define PASS1_BITS 2
  155143. #else
  155144. #define CONST_BITS 8
  155145. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155146. #endif
  155147. #if CONST_BITS == 8
  155148. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155149. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155150. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155151. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155152. #else
  155153. #define FIX_1_082392200 FIX(1.082392200)
  155154. #define FIX_1_414213562 FIX(1.414213562)
  155155. #define FIX_1_847759065 FIX(1.847759065)
  155156. #define FIX_2_613125930 FIX(2.613125930)
  155157. #endif
  155158. #ifndef USE_ACCURATE_ROUNDING
  155159. #undef DESCALE
  155160. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155161. #endif
  155162. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155163. #if BITS_IN_JSAMPLE == 8
  155164. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155165. #else
  155166. #define DEQUANTIZE(coef,quantval) \
  155167. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155168. #endif
  155169. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155170. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155171. #if BITS_IN_JSAMPLE == 8
  155172. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155173. #else
  155174. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155175. #endif
  155176. #define IRIGHT_SHIFT(x,shft) \
  155177. ((ishift_temp = (x)) < 0 ? \
  155178. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155179. (ishift_temp >> (shft)))
  155180. #else
  155181. #define ISHIFT_TEMPS
  155182. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155183. #endif
  155184. #ifdef USE_ACCURATE_ROUNDING
  155185. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155186. #else
  155187. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155188. #endif
  155189. GLOBAL(void)
  155190. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155191. JCOEFPTR coef_block,
  155192. JSAMPARRAY output_buf, JDIMENSION output_col)
  155193. {
  155194. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155195. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155196. DCTELEM z5, z10, z11, z12, z13;
  155197. JCOEFPTR inptr;
  155198. IFAST_MULT_TYPE * quantptr;
  155199. int * wsptr;
  155200. JSAMPROW outptr;
  155201. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155202. int ctr;
  155203. int workspace[DCTSIZE2]; /* buffers data between passes */
  155204. SHIFT_TEMPS /* for DESCALE */
  155205. ISHIFT_TEMPS /* for IDESCALE */
  155206. inptr = coef_block;
  155207. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155208. wsptr = workspace;
  155209. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155210. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155211. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155212. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155213. inptr[DCTSIZE*7] == 0) {
  155214. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155215. wsptr[DCTSIZE*0] = dcval;
  155216. wsptr[DCTSIZE*1] = dcval;
  155217. wsptr[DCTSIZE*2] = dcval;
  155218. wsptr[DCTSIZE*3] = dcval;
  155219. wsptr[DCTSIZE*4] = dcval;
  155220. wsptr[DCTSIZE*5] = dcval;
  155221. wsptr[DCTSIZE*6] = dcval;
  155222. wsptr[DCTSIZE*7] = dcval;
  155223. inptr++; /* advance pointers to next column */
  155224. quantptr++;
  155225. wsptr++;
  155226. continue;
  155227. }
  155228. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155229. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155230. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155231. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155232. tmp10 = tmp0 + tmp2; /* phase 3 */
  155233. tmp11 = tmp0 - tmp2;
  155234. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155235. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155236. tmp0 = tmp10 + tmp13; /* phase 2 */
  155237. tmp3 = tmp10 - tmp13;
  155238. tmp1 = tmp11 + tmp12;
  155239. tmp2 = tmp11 - tmp12;
  155240. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155241. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155242. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155243. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155244. z13 = tmp6 + tmp5; /* phase 6 */
  155245. z10 = tmp6 - tmp5;
  155246. z11 = tmp4 + tmp7;
  155247. z12 = tmp4 - tmp7;
  155248. tmp7 = z11 + z13; /* phase 5 */
  155249. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155250. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155251. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155252. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155253. tmp6 = tmp12 - tmp7; /* phase 2 */
  155254. tmp5 = tmp11 - tmp6;
  155255. tmp4 = tmp10 + tmp5;
  155256. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155257. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155258. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155259. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155260. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155261. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155262. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155263. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155264. inptr++; /* advance pointers to next column */
  155265. quantptr++;
  155266. wsptr++;
  155267. }
  155268. wsptr = workspace;
  155269. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155270. outptr = output_buf[ctr] + output_col;
  155271. #ifndef NO_ZERO_ROW_TEST
  155272. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155273. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155274. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155275. & RANGE_MASK];
  155276. outptr[0] = dcval;
  155277. outptr[1] = dcval;
  155278. outptr[2] = dcval;
  155279. outptr[3] = dcval;
  155280. outptr[4] = dcval;
  155281. outptr[5] = dcval;
  155282. outptr[6] = dcval;
  155283. outptr[7] = dcval;
  155284. wsptr += DCTSIZE; /* advance pointer to next row */
  155285. continue;
  155286. }
  155287. #endif
  155288. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155289. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155290. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155291. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155292. - tmp13;
  155293. tmp0 = tmp10 + tmp13;
  155294. tmp3 = tmp10 - tmp13;
  155295. tmp1 = tmp11 + tmp12;
  155296. tmp2 = tmp11 - tmp12;
  155297. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155298. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155299. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155300. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155301. tmp7 = z11 + z13; /* phase 5 */
  155302. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155303. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155304. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155305. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155306. tmp6 = tmp12 - tmp7; /* phase 2 */
  155307. tmp5 = tmp11 - tmp6;
  155308. tmp4 = tmp10 + tmp5;
  155309. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155310. & RANGE_MASK];
  155311. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155312. & RANGE_MASK];
  155313. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155314. & RANGE_MASK];
  155315. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155316. & RANGE_MASK];
  155317. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155318. & RANGE_MASK];
  155319. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155320. & RANGE_MASK];
  155321. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155322. & RANGE_MASK];
  155323. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155324. & RANGE_MASK];
  155325. wsptr += DCTSIZE; /* advance pointer to next row */
  155326. }
  155327. }
  155328. #endif /* DCT_IFAST_SUPPORTED */
  155329. /*** End of inlined file: jidctfst.c ***/
  155330. #undef CONST_BITS
  155331. #undef FIX_1_847759065
  155332. #undef MULTIPLY
  155333. #undef DEQUANTIZE
  155334. /*** Start of inlined file: jidctint.c ***/
  155335. #define JPEG_INTERNALS
  155336. #ifdef DCT_ISLOW_SUPPORTED
  155337. #if DCTSIZE != 8
  155338. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155339. #endif
  155340. #if BITS_IN_JSAMPLE == 8
  155341. #define CONST_BITS 13
  155342. #define PASS1_BITS 2
  155343. #else
  155344. #define CONST_BITS 13
  155345. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155346. #endif
  155347. #if CONST_BITS == 13
  155348. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155349. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155350. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155351. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155352. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155353. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155354. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155355. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155356. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155357. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155358. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155359. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155360. #else
  155361. #define FIX_0_298631336 FIX(0.298631336)
  155362. #define FIX_0_390180644 FIX(0.390180644)
  155363. #define FIX_0_541196100 FIX(0.541196100)
  155364. #define FIX_0_765366865 FIX(0.765366865)
  155365. #define FIX_0_899976223 FIX(0.899976223)
  155366. #define FIX_1_175875602 FIX(1.175875602)
  155367. #define FIX_1_501321110 FIX(1.501321110)
  155368. #define FIX_1_847759065 FIX(1.847759065)
  155369. #define FIX_1_961570560 FIX(1.961570560)
  155370. #define FIX_2_053119869 FIX(2.053119869)
  155371. #define FIX_2_562915447 FIX(2.562915447)
  155372. #define FIX_3_072711026 FIX(3.072711026)
  155373. #endif
  155374. #if BITS_IN_JSAMPLE == 8
  155375. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155376. #else
  155377. #define MULTIPLY(var,const) ((var) * (const))
  155378. #endif
  155379. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155380. GLOBAL(void)
  155381. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155382. JCOEFPTR coef_block,
  155383. JSAMPARRAY output_buf, JDIMENSION output_col)
  155384. {
  155385. INT32 tmp0, tmp1, tmp2, tmp3;
  155386. INT32 tmp10, tmp11, tmp12, tmp13;
  155387. INT32 z1, z2, z3, z4, z5;
  155388. JCOEFPTR inptr;
  155389. ISLOW_MULT_TYPE * quantptr;
  155390. int * wsptr;
  155391. JSAMPROW outptr;
  155392. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155393. int ctr;
  155394. int workspace[DCTSIZE2]; /* buffers data between passes */
  155395. SHIFT_TEMPS
  155396. inptr = coef_block;
  155397. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155398. wsptr = workspace;
  155399. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155400. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155401. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155402. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155403. inptr[DCTSIZE*7] == 0) {
  155404. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155405. wsptr[DCTSIZE*0] = dcval;
  155406. wsptr[DCTSIZE*1] = dcval;
  155407. wsptr[DCTSIZE*2] = dcval;
  155408. wsptr[DCTSIZE*3] = dcval;
  155409. wsptr[DCTSIZE*4] = dcval;
  155410. wsptr[DCTSIZE*5] = dcval;
  155411. wsptr[DCTSIZE*6] = dcval;
  155412. wsptr[DCTSIZE*7] = dcval;
  155413. inptr++; /* advance pointers to next column */
  155414. quantptr++;
  155415. wsptr++;
  155416. continue;
  155417. }
  155418. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155419. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155420. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155421. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155422. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155423. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155424. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155425. tmp0 = (z2 + z3) << CONST_BITS;
  155426. tmp1 = (z2 - z3) << CONST_BITS;
  155427. tmp10 = tmp0 + tmp3;
  155428. tmp13 = tmp0 - tmp3;
  155429. tmp11 = tmp1 + tmp2;
  155430. tmp12 = tmp1 - tmp2;
  155431. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155432. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155433. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155434. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155435. z1 = tmp0 + tmp3;
  155436. z2 = tmp1 + tmp2;
  155437. z3 = tmp0 + tmp2;
  155438. z4 = tmp1 + tmp3;
  155439. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155440. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155441. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155442. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155443. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155444. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155445. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155446. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155447. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155448. z3 += z5;
  155449. z4 += z5;
  155450. tmp0 += z1 + z3;
  155451. tmp1 += z2 + z4;
  155452. tmp2 += z2 + z3;
  155453. tmp3 += z1 + z4;
  155454. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155455. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155456. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155457. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155458. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155459. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155460. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155461. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155462. inptr++; /* advance pointers to next column */
  155463. quantptr++;
  155464. wsptr++;
  155465. }
  155466. wsptr = workspace;
  155467. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155468. outptr = output_buf[ctr] + output_col;
  155469. #ifndef NO_ZERO_ROW_TEST
  155470. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155471. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155472. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155473. & RANGE_MASK];
  155474. outptr[0] = dcval;
  155475. outptr[1] = dcval;
  155476. outptr[2] = dcval;
  155477. outptr[3] = dcval;
  155478. outptr[4] = dcval;
  155479. outptr[5] = dcval;
  155480. outptr[6] = dcval;
  155481. outptr[7] = dcval;
  155482. wsptr += DCTSIZE; /* advance pointer to next row */
  155483. continue;
  155484. }
  155485. #endif
  155486. z2 = (INT32) wsptr[2];
  155487. z3 = (INT32) wsptr[6];
  155488. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155489. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155490. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155491. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155492. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155493. tmp10 = tmp0 + tmp3;
  155494. tmp13 = tmp0 - tmp3;
  155495. tmp11 = tmp1 + tmp2;
  155496. tmp12 = tmp1 - tmp2;
  155497. tmp0 = (INT32) wsptr[7];
  155498. tmp1 = (INT32) wsptr[5];
  155499. tmp2 = (INT32) wsptr[3];
  155500. tmp3 = (INT32) wsptr[1];
  155501. z1 = tmp0 + tmp3;
  155502. z2 = tmp1 + tmp2;
  155503. z3 = tmp0 + tmp2;
  155504. z4 = tmp1 + tmp3;
  155505. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155506. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155507. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155508. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155509. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155510. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155511. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155512. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155513. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155514. z3 += z5;
  155515. z4 += z5;
  155516. tmp0 += z1 + z3;
  155517. tmp1 += z2 + z4;
  155518. tmp2 += z2 + z3;
  155519. tmp3 += z1 + z4;
  155520. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155521. CONST_BITS+PASS1_BITS+3)
  155522. & RANGE_MASK];
  155523. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155524. CONST_BITS+PASS1_BITS+3)
  155525. & RANGE_MASK];
  155526. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155527. CONST_BITS+PASS1_BITS+3)
  155528. & RANGE_MASK];
  155529. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155530. CONST_BITS+PASS1_BITS+3)
  155531. & RANGE_MASK];
  155532. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155533. CONST_BITS+PASS1_BITS+3)
  155534. & RANGE_MASK];
  155535. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155536. CONST_BITS+PASS1_BITS+3)
  155537. & RANGE_MASK];
  155538. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155539. CONST_BITS+PASS1_BITS+3)
  155540. & RANGE_MASK];
  155541. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155542. CONST_BITS+PASS1_BITS+3)
  155543. & RANGE_MASK];
  155544. wsptr += DCTSIZE; /* advance pointer to next row */
  155545. }
  155546. }
  155547. #endif /* DCT_ISLOW_SUPPORTED */
  155548. /*** End of inlined file: jidctint.c ***/
  155549. /*** Start of inlined file: jidctred.c ***/
  155550. #define JPEG_INTERNALS
  155551. #ifdef IDCT_SCALING_SUPPORTED
  155552. #if DCTSIZE != 8
  155553. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155554. #endif
  155555. #if BITS_IN_JSAMPLE == 8
  155556. #define CONST_BITS 13
  155557. #define PASS1_BITS 2
  155558. #else
  155559. #define CONST_BITS 13
  155560. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155561. #endif
  155562. #if CONST_BITS == 13
  155563. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155564. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155565. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155566. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155567. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155568. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155569. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155570. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155571. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155572. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155573. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155574. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155575. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155576. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155577. #else
  155578. #define FIX_0_211164243 FIX(0.211164243)
  155579. #define FIX_0_509795579 FIX(0.509795579)
  155580. #define FIX_0_601344887 FIX(0.601344887)
  155581. #define FIX_0_720959822 FIX(0.720959822)
  155582. #define FIX_0_765366865 FIX(0.765366865)
  155583. #define FIX_0_850430095 FIX(0.850430095)
  155584. #define FIX_0_899976223 FIX(0.899976223)
  155585. #define FIX_1_061594337 FIX(1.061594337)
  155586. #define FIX_1_272758580 FIX(1.272758580)
  155587. #define FIX_1_451774981 FIX(1.451774981)
  155588. #define FIX_1_847759065 FIX(1.847759065)
  155589. #define FIX_2_172734803 FIX(2.172734803)
  155590. #define FIX_2_562915447 FIX(2.562915447)
  155591. #define FIX_3_624509785 FIX(3.624509785)
  155592. #endif
  155593. #if BITS_IN_JSAMPLE == 8
  155594. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155595. #else
  155596. #define MULTIPLY(var,const) ((var) * (const))
  155597. #endif
  155598. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155599. GLOBAL(void)
  155600. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155601. JCOEFPTR coef_block,
  155602. JSAMPARRAY output_buf, JDIMENSION output_col)
  155603. {
  155604. INT32 tmp0, tmp2, tmp10, tmp12;
  155605. INT32 z1, z2, z3, z4;
  155606. JCOEFPTR inptr;
  155607. ISLOW_MULT_TYPE * quantptr;
  155608. int * wsptr;
  155609. JSAMPROW outptr;
  155610. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155611. int ctr;
  155612. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155613. SHIFT_TEMPS
  155614. inptr = coef_block;
  155615. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155616. wsptr = workspace;
  155617. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155618. if (ctr == DCTSIZE-4)
  155619. continue;
  155620. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155621. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155622. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155623. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155624. wsptr[DCTSIZE*0] = dcval;
  155625. wsptr[DCTSIZE*1] = dcval;
  155626. wsptr[DCTSIZE*2] = dcval;
  155627. wsptr[DCTSIZE*3] = dcval;
  155628. continue;
  155629. }
  155630. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155631. tmp0 <<= (CONST_BITS+1);
  155632. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155633. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155634. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155635. tmp10 = tmp0 + tmp2;
  155636. tmp12 = tmp0 - tmp2;
  155637. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155638. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155639. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155640. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155641. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155642. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155643. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155644. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155645. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155646. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155647. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155648. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155649. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155650. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155651. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155652. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155653. }
  155654. wsptr = workspace;
  155655. for (ctr = 0; ctr < 4; ctr++) {
  155656. outptr = output_buf[ctr] + output_col;
  155657. #ifndef NO_ZERO_ROW_TEST
  155658. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155659. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155660. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155661. & RANGE_MASK];
  155662. outptr[0] = dcval;
  155663. outptr[1] = dcval;
  155664. outptr[2] = dcval;
  155665. outptr[3] = dcval;
  155666. wsptr += DCTSIZE; /* advance pointer to next row */
  155667. continue;
  155668. }
  155669. #endif
  155670. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155671. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155672. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155673. tmp10 = tmp0 + tmp2;
  155674. tmp12 = tmp0 - tmp2;
  155675. z1 = (INT32) wsptr[7];
  155676. z2 = (INT32) wsptr[5];
  155677. z3 = (INT32) wsptr[3];
  155678. z4 = (INT32) wsptr[1];
  155679. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155680. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155681. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155682. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155683. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155684. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155685. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155686. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155687. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155688. CONST_BITS+PASS1_BITS+3+1)
  155689. & RANGE_MASK];
  155690. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155691. CONST_BITS+PASS1_BITS+3+1)
  155692. & RANGE_MASK];
  155693. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155694. CONST_BITS+PASS1_BITS+3+1)
  155695. & RANGE_MASK];
  155696. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155697. CONST_BITS+PASS1_BITS+3+1)
  155698. & RANGE_MASK];
  155699. wsptr += DCTSIZE; /* advance pointer to next row */
  155700. }
  155701. }
  155702. GLOBAL(void)
  155703. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155704. JCOEFPTR coef_block,
  155705. JSAMPARRAY output_buf, JDIMENSION output_col)
  155706. {
  155707. INT32 tmp0, tmp10, z1;
  155708. JCOEFPTR inptr;
  155709. ISLOW_MULT_TYPE * quantptr;
  155710. int * wsptr;
  155711. JSAMPROW outptr;
  155712. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155713. int ctr;
  155714. int workspace[DCTSIZE*2]; /* buffers data between passes */
  155715. SHIFT_TEMPS
  155716. inptr = coef_block;
  155717. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155718. wsptr = workspace;
  155719. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155720. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  155721. continue;
  155722. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  155723. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  155724. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155725. wsptr[DCTSIZE*0] = dcval;
  155726. wsptr[DCTSIZE*1] = dcval;
  155727. continue;
  155728. }
  155729. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155730. tmp10 = z1 << (CONST_BITS+2);
  155731. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155732. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  155733. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155734. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  155735. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155736. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  155737. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155738. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155739. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  155740. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  155741. }
  155742. wsptr = workspace;
  155743. for (ctr = 0; ctr < 2; ctr++) {
  155744. outptr = output_buf[ctr] + output_col;
  155745. #ifndef NO_ZERO_ROW_TEST
  155746. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  155747. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155748. & RANGE_MASK];
  155749. outptr[0] = dcval;
  155750. outptr[1] = dcval;
  155751. wsptr += DCTSIZE; /* advance pointer to next row */
  155752. continue;
  155753. }
  155754. #endif
  155755. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  155756. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  155757. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  155758. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  155759. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155760. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  155761. CONST_BITS+PASS1_BITS+3+2)
  155762. & RANGE_MASK];
  155763. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  155764. CONST_BITS+PASS1_BITS+3+2)
  155765. & RANGE_MASK];
  155766. wsptr += DCTSIZE; /* advance pointer to next row */
  155767. }
  155768. }
  155769. GLOBAL(void)
  155770. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155771. JCOEFPTR coef_block,
  155772. JSAMPARRAY output_buf, JDIMENSION output_col)
  155773. {
  155774. int dcval;
  155775. ISLOW_MULT_TYPE * quantptr;
  155776. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155777. SHIFT_TEMPS
  155778. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155779. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  155780. dcval = (int) DESCALE((INT32) dcval, 3);
  155781. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  155782. }
  155783. #endif /* IDCT_SCALING_SUPPORTED */
  155784. /*** End of inlined file: jidctred.c ***/
  155785. /*** Start of inlined file: jmemmgr.c ***/
  155786. #define JPEG_INTERNALS
  155787. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  155788. /*** Start of inlined file: jmemsys.h ***/
  155789. #ifndef __jmemsys_h__
  155790. #define __jmemsys_h__
  155791. #ifdef NEED_SHORT_EXTERNAL_NAMES
  155792. #define jpeg_get_small jGetSmall
  155793. #define jpeg_free_small jFreeSmall
  155794. #define jpeg_get_large jGetLarge
  155795. #define jpeg_free_large jFreeLarge
  155796. #define jpeg_mem_available jMemAvail
  155797. #define jpeg_open_backing_store jOpenBackStore
  155798. #define jpeg_mem_init jMemInit
  155799. #define jpeg_mem_term jMemTerm
  155800. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  155801. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  155802. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  155803. size_t sizeofobject));
  155804. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  155805. size_t sizeofobject));
  155806. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  155807. size_t sizeofobject));
  155808. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  155809. #define MAX_ALLOC_CHUNK 1000000000L
  155810. #endif
  155811. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  155812. long min_bytes_needed,
  155813. long max_bytes_needed,
  155814. long already_allocated));
  155815. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  155816. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  155817. typedef unsigned short XMSH; /* type of extended-memory handles */
  155818. typedef unsigned short EMSH; /* type of expanded-memory handles */
  155819. typedef union {
  155820. short file_handle; /* DOS file handle if it's a temp file */
  155821. XMSH xms_handle; /* handle if it's a chunk of XMS */
  155822. EMSH ems_handle; /* handle if it's a chunk of EMS */
  155823. } handle_union;
  155824. #endif /* USE_MSDOS_MEMMGR */
  155825. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  155826. #include <Files.h>
  155827. #endif /* USE_MAC_MEMMGR */
  155828. //typedef struct backing_store_struct * backing_store_ptr;
  155829. typedef struct backing_store_struct {
  155830. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  155831. struct backing_store_struct *info,
  155832. void FAR * buffer_address,
  155833. long file_offset, long byte_count));
  155834. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  155835. struct backing_store_struct *info,
  155836. void FAR * buffer_address,
  155837. long file_offset, long byte_count));
  155838. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  155839. struct backing_store_struct *info));
  155840. #ifdef USE_MSDOS_MEMMGR
  155841. handle_union handle; /* reference to backing-store storage object */
  155842. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  155843. #else
  155844. #ifdef USE_MAC_MEMMGR
  155845. short temp_file; /* file reference number to temp file */
  155846. FSSpec tempSpec; /* the FSSpec for the temp file */
  155847. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  155848. #else
  155849. FILE * temp_file; /* stdio reference to temp file */
  155850. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  155851. #endif
  155852. #endif
  155853. } backing_store_info;
  155854. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  155855. struct backing_store_struct *info,
  155856. long total_bytes_needed));
  155857. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  155858. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  155859. #endif
  155860. /*** End of inlined file: jmemsys.h ***/
  155861. /* import the system-dependent declarations */
  155862. #ifndef NO_GETENV
  155863. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  155864. extern char * getenv JPP((const char * name));
  155865. #endif
  155866. #endif
  155867. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  155868. #define ALIGN_TYPE double
  155869. #endif
  155870. typedef union small_pool_struct * small_pool_ptr;
  155871. typedef union small_pool_struct {
  155872. struct {
  155873. small_pool_ptr next; /* next in list of pools */
  155874. size_t bytes_used; /* how many bytes already used within pool */
  155875. size_t bytes_left; /* bytes still available in this pool */
  155876. } hdr;
  155877. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  155878. } small_pool_hdr;
  155879. typedef union large_pool_struct FAR * large_pool_ptr;
  155880. typedef union large_pool_struct {
  155881. struct {
  155882. large_pool_ptr next; /* next in list of pools */
  155883. size_t bytes_used; /* how many bytes already used within pool */
  155884. size_t bytes_left; /* bytes still available in this pool */
  155885. } hdr;
  155886. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  155887. } large_pool_hdr;
  155888. typedef struct {
  155889. struct jpeg_memory_mgr pub; /* public fields */
  155890. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  155891. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  155892. jvirt_sarray_ptr virt_sarray_list;
  155893. jvirt_barray_ptr virt_barray_list;
  155894. long total_space_allocated;
  155895. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  155896. } my_memory_mgr;
  155897. typedef my_memory_mgr * my_mem_ptr;
  155898. struct jvirt_sarray_control {
  155899. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  155900. JDIMENSION rows_in_array; /* total virtual array height */
  155901. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  155902. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  155903. JDIMENSION rows_in_mem; /* height of memory buffer */
  155904. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  155905. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  155906. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  155907. boolean pre_zero; /* pre-zero mode requested? */
  155908. boolean dirty; /* do current buffer contents need written? */
  155909. boolean b_s_open; /* is backing-store data valid? */
  155910. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  155911. backing_store_info b_s_info; /* System-dependent control info */
  155912. };
  155913. struct jvirt_barray_control {
  155914. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  155915. JDIMENSION rows_in_array; /* total virtual array height */
  155916. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  155917. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  155918. JDIMENSION rows_in_mem; /* height of memory buffer */
  155919. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  155920. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  155921. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  155922. boolean pre_zero; /* pre-zero mode requested? */
  155923. boolean dirty; /* do current buffer contents need written? */
  155924. boolean b_s_open; /* is backing-store data valid? */
  155925. jvirt_barray_ptr next; /* link to next virtual barray control block */
  155926. backing_store_info b_s_info; /* System-dependent control info */
  155927. };
  155928. #ifdef MEM_STATS /* optional extra stuff for statistics */
  155929. LOCAL(void)
  155930. print_mem_stats (j_common_ptr cinfo, int pool_id)
  155931. {
  155932. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  155933. small_pool_ptr shdr_ptr;
  155934. large_pool_ptr lhdr_ptr;
  155935. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  155936. pool_id, mem->total_space_allocated);
  155937. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  155938. lhdr_ptr = lhdr_ptr->hdr.next) {
  155939. fprintf(stderr, " Large chunk used %ld\n",
  155940. (long) lhdr_ptr->hdr.bytes_used);
  155941. }
  155942. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  155943. shdr_ptr = shdr_ptr->hdr.next) {
  155944. fprintf(stderr, " Small chunk used %ld free %ld\n",
  155945. (long) shdr_ptr->hdr.bytes_used,
  155946. (long) shdr_ptr->hdr.bytes_left);
  155947. }
  155948. }
  155949. #endif /* MEM_STATS */
  155950. LOCAL(void)
  155951. out_of_memory (j_common_ptr cinfo, int which)
  155952. {
  155953. #ifdef MEM_STATS
  155954. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  155955. #endif
  155956. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  155957. }
  155958. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  155959. {
  155960. 1600, /* first PERMANENT pool */
  155961. 16000 /* first IMAGE pool */
  155962. };
  155963. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  155964. {
  155965. 0, /* additional PERMANENT pools */
  155966. 5000 /* additional IMAGE pools */
  155967. };
  155968. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  155969. METHODDEF(void *)
  155970. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  155971. {
  155972. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  155973. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  155974. char * data_ptr;
  155975. size_t odd_bytes, min_request, slop;
  155976. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  155977. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  155978. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  155979. if (odd_bytes > 0)
  155980. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  155981. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  155982. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  155983. prev_hdr_ptr = NULL;
  155984. hdr_ptr = mem->small_list[pool_id];
  155985. while (hdr_ptr != NULL) {
  155986. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  155987. break; /* found pool with enough space */
  155988. prev_hdr_ptr = hdr_ptr;
  155989. hdr_ptr = hdr_ptr->hdr.next;
  155990. }
  155991. if (hdr_ptr == NULL) {
  155992. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  155993. if (prev_hdr_ptr == NULL) /* first pool in class? */
  155994. slop = first_pool_slop[pool_id];
  155995. else
  155996. slop = extra_pool_slop[pool_id];
  155997. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  155998. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  155999. for (;;) {
  156000. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156001. if (hdr_ptr != NULL)
  156002. break;
  156003. slop /= 2;
  156004. if (slop < MIN_SLOP) /* give up when it gets real small */
  156005. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156006. }
  156007. mem->total_space_allocated += min_request + slop;
  156008. hdr_ptr->hdr.next = NULL;
  156009. hdr_ptr->hdr.bytes_used = 0;
  156010. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156011. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156012. mem->small_list[pool_id] = hdr_ptr;
  156013. else
  156014. prev_hdr_ptr->hdr.next = hdr_ptr;
  156015. }
  156016. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156017. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156018. hdr_ptr->hdr.bytes_used += sizeofobject;
  156019. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156020. return (void *) data_ptr;
  156021. }
  156022. METHODDEF(void FAR *)
  156023. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156024. {
  156025. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156026. large_pool_ptr hdr_ptr;
  156027. size_t odd_bytes;
  156028. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156029. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156030. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156031. if (odd_bytes > 0)
  156032. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156033. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156034. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156035. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156036. SIZEOF(large_pool_hdr));
  156037. if (hdr_ptr == NULL)
  156038. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156039. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156040. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156041. hdr_ptr->hdr.bytes_used = sizeofobject;
  156042. hdr_ptr->hdr.bytes_left = 0;
  156043. mem->large_list[pool_id] = hdr_ptr;
  156044. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156045. }
  156046. METHODDEF(JSAMPARRAY)
  156047. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156048. JDIMENSION samplesperrow, JDIMENSION numrows)
  156049. {
  156050. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156051. JSAMPARRAY result;
  156052. JSAMPROW workspace;
  156053. JDIMENSION rowsperchunk, currow, i;
  156054. long ltemp;
  156055. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156056. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156057. if (ltemp <= 0)
  156058. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156059. if (ltemp < (long) numrows)
  156060. rowsperchunk = (JDIMENSION) ltemp;
  156061. else
  156062. rowsperchunk = numrows;
  156063. mem->last_rowsperchunk = rowsperchunk;
  156064. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156065. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156066. currow = 0;
  156067. while (currow < numrows) {
  156068. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156069. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156070. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156071. * SIZEOF(JSAMPLE)));
  156072. for (i = rowsperchunk; i > 0; i--) {
  156073. result[currow++] = workspace;
  156074. workspace += samplesperrow;
  156075. }
  156076. }
  156077. return result;
  156078. }
  156079. METHODDEF(JBLOCKARRAY)
  156080. alloc_barray (j_common_ptr cinfo, int pool_id,
  156081. JDIMENSION blocksperrow, JDIMENSION numrows)
  156082. {
  156083. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156084. JBLOCKARRAY result;
  156085. JBLOCKROW workspace;
  156086. JDIMENSION rowsperchunk, currow, i;
  156087. long ltemp;
  156088. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156089. ((long) blocksperrow * SIZEOF(JBLOCK));
  156090. if (ltemp <= 0)
  156091. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156092. if (ltemp < (long) numrows)
  156093. rowsperchunk = (JDIMENSION) ltemp;
  156094. else
  156095. rowsperchunk = numrows;
  156096. mem->last_rowsperchunk = rowsperchunk;
  156097. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156098. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156099. currow = 0;
  156100. while (currow < numrows) {
  156101. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156102. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156103. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156104. * SIZEOF(JBLOCK)));
  156105. for (i = rowsperchunk; i > 0; i--) {
  156106. result[currow++] = workspace;
  156107. workspace += blocksperrow;
  156108. }
  156109. }
  156110. return result;
  156111. }
  156112. METHODDEF(jvirt_sarray_ptr)
  156113. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156114. JDIMENSION samplesperrow, JDIMENSION numrows,
  156115. JDIMENSION maxaccess)
  156116. {
  156117. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156118. jvirt_sarray_ptr result;
  156119. if (pool_id != JPOOL_IMAGE)
  156120. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156121. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156122. SIZEOF(struct jvirt_sarray_control));
  156123. result->mem_buffer = NULL; /* marks array not yet realized */
  156124. result->rows_in_array = numrows;
  156125. result->samplesperrow = samplesperrow;
  156126. result->maxaccess = maxaccess;
  156127. result->pre_zero = pre_zero;
  156128. result->b_s_open = FALSE; /* no associated backing-store object */
  156129. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156130. mem->virt_sarray_list = result;
  156131. return result;
  156132. }
  156133. METHODDEF(jvirt_barray_ptr)
  156134. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156135. JDIMENSION blocksperrow, JDIMENSION numrows,
  156136. JDIMENSION maxaccess)
  156137. {
  156138. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156139. jvirt_barray_ptr result;
  156140. if (pool_id != JPOOL_IMAGE)
  156141. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156142. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156143. SIZEOF(struct jvirt_barray_control));
  156144. result->mem_buffer = NULL; /* marks array not yet realized */
  156145. result->rows_in_array = numrows;
  156146. result->blocksperrow = blocksperrow;
  156147. result->maxaccess = maxaccess;
  156148. result->pre_zero = pre_zero;
  156149. result->b_s_open = FALSE; /* no associated backing-store object */
  156150. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156151. mem->virt_barray_list = result;
  156152. return result;
  156153. }
  156154. METHODDEF(void)
  156155. realize_virt_arrays (j_common_ptr cinfo)
  156156. {
  156157. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156158. long space_per_minheight, maximum_space, avail_mem;
  156159. long minheights, max_minheights;
  156160. jvirt_sarray_ptr sptr;
  156161. jvirt_barray_ptr bptr;
  156162. space_per_minheight = 0;
  156163. maximum_space = 0;
  156164. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156165. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156166. space_per_minheight += (long) sptr->maxaccess *
  156167. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156168. maximum_space += (long) sptr->rows_in_array *
  156169. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156170. }
  156171. }
  156172. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156173. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156174. space_per_minheight += (long) bptr->maxaccess *
  156175. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156176. maximum_space += (long) bptr->rows_in_array *
  156177. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156178. }
  156179. }
  156180. if (space_per_minheight <= 0)
  156181. return; /* no unrealized arrays, no work */
  156182. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156183. mem->total_space_allocated);
  156184. if (avail_mem >= maximum_space)
  156185. max_minheights = 1000000000L;
  156186. else {
  156187. max_minheights = avail_mem / space_per_minheight;
  156188. if (max_minheights <= 0)
  156189. max_minheights = 1;
  156190. }
  156191. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156192. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156193. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156194. if (minheights <= max_minheights) {
  156195. sptr->rows_in_mem = sptr->rows_in_array;
  156196. } else {
  156197. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156198. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156199. (long) sptr->rows_in_array *
  156200. (long) sptr->samplesperrow *
  156201. (long) SIZEOF(JSAMPLE));
  156202. sptr->b_s_open = TRUE;
  156203. }
  156204. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156205. sptr->samplesperrow, sptr->rows_in_mem);
  156206. sptr->rowsperchunk = mem->last_rowsperchunk;
  156207. sptr->cur_start_row = 0;
  156208. sptr->first_undef_row = 0;
  156209. sptr->dirty = FALSE;
  156210. }
  156211. }
  156212. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156213. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156214. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156215. if (minheights <= max_minheights) {
  156216. bptr->rows_in_mem = bptr->rows_in_array;
  156217. } else {
  156218. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156219. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156220. (long) bptr->rows_in_array *
  156221. (long) bptr->blocksperrow *
  156222. (long) SIZEOF(JBLOCK));
  156223. bptr->b_s_open = TRUE;
  156224. }
  156225. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156226. bptr->blocksperrow, bptr->rows_in_mem);
  156227. bptr->rowsperchunk = mem->last_rowsperchunk;
  156228. bptr->cur_start_row = 0;
  156229. bptr->first_undef_row = 0;
  156230. bptr->dirty = FALSE;
  156231. }
  156232. }
  156233. }
  156234. LOCAL(void)
  156235. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156236. {
  156237. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156238. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156239. file_offset = ptr->cur_start_row * bytesperrow;
  156240. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156241. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156242. thisrow = (long) ptr->cur_start_row + i;
  156243. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156244. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156245. if (rows <= 0) /* this chunk might be past end of file! */
  156246. break;
  156247. byte_count = rows * bytesperrow;
  156248. if (writing)
  156249. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156250. (void FAR *) ptr->mem_buffer[i],
  156251. file_offset, byte_count);
  156252. else
  156253. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156254. (void FAR *) ptr->mem_buffer[i],
  156255. file_offset, byte_count);
  156256. file_offset += byte_count;
  156257. }
  156258. }
  156259. LOCAL(void)
  156260. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156261. {
  156262. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156263. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156264. file_offset = ptr->cur_start_row * bytesperrow;
  156265. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156266. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156267. thisrow = (long) ptr->cur_start_row + i;
  156268. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156269. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156270. if (rows <= 0) /* this chunk might be past end of file! */
  156271. break;
  156272. byte_count = rows * bytesperrow;
  156273. if (writing)
  156274. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156275. (void FAR *) ptr->mem_buffer[i],
  156276. file_offset, byte_count);
  156277. else
  156278. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156279. (void FAR *) ptr->mem_buffer[i],
  156280. file_offset, byte_count);
  156281. file_offset += byte_count;
  156282. }
  156283. }
  156284. METHODDEF(JSAMPARRAY)
  156285. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156286. JDIMENSION start_row, JDIMENSION num_rows,
  156287. boolean writable)
  156288. {
  156289. JDIMENSION end_row = start_row + num_rows;
  156290. JDIMENSION undef_row;
  156291. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156292. ptr->mem_buffer == NULL)
  156293. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156294. if (start_row < ptr->cur_start_row ||
  156295. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156296. if (! ptr->b_s_open)
  156297. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156298. if (ptr->dirty) {
  156299. do_sarray_io(cinfo, ptr, TRUE);
  156300. ptr->dirty = FALSE;
  156301. }
  156302. if (start_row > ptr->cur_start_row) {
  156303. ptr->cur_start_row = start_row;
  156304. } else {
  156305. long ltemp;
  156306. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156307. if (ltemp < 0)
  156308. ltemp = 0; /* don't fall off front end of file */
  156309. ptr->cur_start_row = (JDIMENSION) ltemp;
  156310. }
  156311. do_sarray_io(cinfo, ptr, FALSE);
  156312. }
  156313. if (ptr->first_undef_row < end_row) {
  156314. if (ptr->first_undef_row < start_row) {
  156315. if (writable) /* writer skipped over a section of array */
  156316. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156317. undef_row = start_row; /* but reader is allowed to read ahead */
  156318. } else {
  156319. undef_row = ptr->first_undef_row;
  156320. }
  156321. if (writable)
  156322. ptr->first_undef_row = end_row;
  156323. if (ptr->pre_zero) {
  156324. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156325. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156326. end_row -= ptr->cur_start_row;
  156327. while (undef_row < end_row) {
  156328. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156329. undef_row++;
  156330. }
  156331. } else {
  156332. if (! writable) /* reader looking at undefined data */
  156333. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156334. }
  156335. }
  156336. if (writable)
  156337. ptr->dirty = TRUE;
  156338. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156339. }
  156340. METHODDEF(JBLOCKARRAY)
  156341. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156342. JDIMENSION start_row, JDIMENSION num_rows,
  156343. boolean writable)
  156344. {
  156345. JDIMENSION end_row = start_row + num_rows;
  156346. JDIMENSION undef_row;
  156347. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156348. ptr->mem_buffer == NULL)
  156349. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156350. if (start_row < ptr->cur_start_row ||
  156351. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156352. if (! ptr->b_s_open)
  156353. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156354. if (ptr->dirty) {
  156355. do_barray_io(cinfo, ptr, TRUE);
  156356. ptr->dirty = FALSE;
  156357. }
  156358. if (start_row > ptr->cur_start_row) {
  156359. ptr->cur_start_row = start_row;
  156360. } else {
  156361. long ltemp;
  156362. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156363. if (ltemp < 0)
  156364. ltemp = 0; /* don't fall off front end of file */
  156365. ptr->cur_start_row = (JDIMENSION) ltemp;
  156366. }
  156367. do_barray_io(cinfo, ptr, FALSE);
  156368. }
  156369. if (ptr->first_undef_row < end_row) {
  156370. if (ptr->first_undef_row < start_row) {
  156371. if (writable) /* writer skipped over a section of array */
  156372. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156373. undef_row = start_row; /* but reader is allowed to read ahead */
  156374. } else {
  156375. undef_row = ptr->first_undef_row;
  156376. }
  156377. if (writable)
  156378. ptr->first_undef_row = end_row;
  156379. if (ptr->pre_zero) {
  156380. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156381. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156382. end_row -= ptr->cur_start_row;
  156383. while (undef_row < end_row) {
  156384. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156385. undef_row++;
  156386. }
  156387. } else {
  156388. if (! writable) /* reader looking at undefined data */
  156389. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156390. }
  156391. }
  156392. if (writable)
  156393. ptr->dirty = TRUE;
  156394. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156395. }
  156396. METHODDEF(void)
  156397. free_pool (j_common_ptr cinfo, int pool_id)
  156398. {
  156399. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156400. small_pool_ptr shdr_ptr;
  156401. large_pool_ptr lhdr_ptr;
  156402. size_t space_freed;
  156403. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156404. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156405. #ifdef MEM_STATS
  156406. if (cinfo->err->trace_level > 1)
  156407. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156408. #endif
  156409. if (pool_id == JPOOL_IMAGE) {
  156410. jvirt_sarray_ptr sptr;
  156411. jvirt_barray_ptr bptr;
  156412. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156413. if (sptr->b_s_open) { /* there may be no backing store */
  156414. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156415. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156416. }
  156417. }
  156418. mem->virt_sarray_list = NULL;
  156419. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156420. if (bptr->b_s_open) { /* there may be no backing store */
  156421. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156422. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156423. }
  156424. }
  156425. mem->virt_barray_list = NULL;
  156426. }
  156427. lhdr_ptr = mem->large_list[pool_id];
  156428. mem->large_list[pool_id] = NULL;
  156429. while (lhdr_ptr != NULL) {
  156430. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156431. space_freed = lhdr_ptr->hdr.bytes_used +
  156432. lhdr_ptr->hdr.bytes_left +
  156433. SIZEOF(large_pool_hdr);
  156434. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156435. mem->total_space_allocated -= space_freed;
  156436. lhdr_ptr = next_lhdr_ptr;
  156437. }
  156438. shdr_ptr = mem->small_list[pool_id];
  156439. mem->small_list[pool_id] = NULL;
  156440. while (shdr_ptr != NULL) {
  156441. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156442. space_freed = shdr_ptr->hdr.bytes_used +
  156443. shdr_ptr->hdr.bytes_left +
  156444. SIZEOF(small_pool_hdr);
  156445. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156446. mem->total_space_allocated -= space_freed;
  156447. shdr_ptr = next_shdr_ptr;
  156448. }
  156449. }
  156450. METHODDEF(void)
  156451. self_destruct (j_common_ptr cinfo)
  156452. {
  156453. int pool;
  156454. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156455. free_pool(cinfo, pool);
  156456. }
  156457. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156458. cinfo->mem = NULL; /* ensures I will be called only once */
  156459. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156460. }
  156461. GLOBAL(void)
  156462. jinit_memory_mgr (j_common_ptr cinfo)
  156463. {
  156464. my_mem_ptr mem;
  156465. long max_to_use;
  156466. int pool;
  156467. size_t test_mac;
  156468. cinfo->mem = NULL; /* for safety if init fails */
  156469. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156470. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156471. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156472. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156473. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156474. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156475. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156476. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156477. if (mem == NULL) {
  156478. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156479. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156480. }
  156481. mem->pub.alloc_small = alloc_small;
  156482. mem->pub.alloc_large = alloc_large;
  156483. mem->pub.alloc_sarray = alloc_sarray;
  156484. mem->pub.alloc_barray = alloc_barray;
  156485. mem->pub.request_virt_sarray = request_virt_sarray;
  156486. mem->pub.request_virt_barray = request_virt_barray;
  156487. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156488. mem->pub.access_virt_sarray = access_virt_sarray;
  156489. mem->pub.access_virt_barray = access_virt_barray;
  156490. mem->pub.free_pool = free_pool;
  156491. mem->pub.self_destruct = self_destruct;
  156492. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156493. mem->pub.max_memory_to_use = max_to_use;
  156494. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156495. mem->small_list[pool] = NULL;
  156496. mem->large_list[pool] = NULL;
  156497. }
  156498. mem->virt_sarray_list = NULL;
  156499. mem->virt_barray_list = NULL;
  156500. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156501. cinfo->mem = & mem->pub;
  156502. #ifndef NO_GETENV
  156503. { char * memenv;
  156504. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156505. char ch = 'x';
  156506. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156507. if (ch == 'm' || ch == 'M')
  156508. max_to_use *= 1000L;
  156509. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156510. }
  156511. }
  156512. }
  156513. #endif
  156514. }
  156515. /*** End of inlined file: jmemmgr.c ***/
  156516. /*** Start of inlined file: jmemnobs.c ***/
  156517. #define JPEG_INTERNALS
  156518. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156519. extern void * malloc JPP((size_t size));
  156520. extern void free JPP((void *ptr));
  156521. #endif
  156522. GLOBAL(void *)
  156523. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156524. {
  156525. return (void *) malloc(sizeofobject);
  156526. }
  156527. GLOBAL(void)
  156528. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156529. {
  156530. free(object);
  156531. }
  156532. GLOBAL(void FAR *)
  156533. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156534. {
  156535. return (void FAR *) malloc(sizeofobject);
  156536. }
  156537. GLOBAL(void)
  156538. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156539. {
  156540. free(object);
  156541. }
  156542. GLOBAL(long)
  156543. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156544. long max_bytes_needed, long already_allocated)
  156545. {
  156546. return max_bytes_needed;
  156547. }
  156548. GLOBAL(void)
  156549. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156550. long total_bytes_needed)
  156551. {
  156552. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156553. }
  156554. GLOBAL(long)
  156555. jpeg_mem_init (j_common_ptr cinfo)
  156556. {
  156557. return 0; /* just set max_memory_to_use to 0 */
  156558. }
  156559. GLOBAL(void)
  156560. jpeg_mem_term (j_common_ptr cinfo)
  156561. {
  156562. }
  156563. /*** End of inlined file: jmemnobs.c ***/
  156564. /*** Start of inlined file: jquant1.c ***/
  156565. #define JPEG_INTERNALS
  156566. #ifdef QUANT_1PASS_SUPPORTED
  156567. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156568. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156569. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156570. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156571. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156572. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156573. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156574. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156575. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156576. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156577. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156578. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156579. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156580. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156581. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156582. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156583. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156584. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156585. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156586. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156587. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156588. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156589. };
  156590. #if BITS_IN_JSAMPLE == 8
  156591. typedef INT16 FSERROR; /* 16 bits should be enough */
  156592. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156593. #else
  156594. typedef INT32 FSERROR; /* may need more than 16 bits */
  156595. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156596. #endif
  156597. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156598. #define MAX_Q_COMPS 4 /* max components I can handle */
  156599. typedef struct {
  156600. struct jpeg_color_quantizer pub; /* public fields */
  156601. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156602. int sv_actual; /* number of entries in use */
  156603. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156604. boolean is_padded; /* is the colorindex padded for odither? */
  156605. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156606. int row_index; /* cur row's vertical index in dither matrix */
  156607. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156608. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156609. boolean on_odd_row; /* flag to remember which row we are on */
  156610. } my_cquantizer;
  156611. typedef my_cquantizer * my_cquantize_ptr;
  156612. LOCAL(int)
  156613. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156614. {
  156615. int nc = cinfo->out_color_components; /* number of color components */
  156616. int max_colors = cinfo->desired_number_of_colors;
  156617. int total_colors, iroot, i, j;
  156618. boolean changed;
  156619. long temp;
  156620. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156621. iroot = 1;
  156622. do {
  156623. iroot++;
  156624. temp = iroot; /* set temp = iroot ** nc */
  156625. for (i = 1; i < nc; i++)
  156626. temp *= iroot;
  156627. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156628. iroot--; /* now iroot = floor(root) */
  156629. if (iroot < 2)
  156630. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156631. total_colors = 1;
  156632. for (i = 0; i < nc; i++) {
  156633. Ncolors[i] = iroot;
  156634. total_colors *= iroot;
  156635. }
  156636. do {
  156637. changed = FALSE;
  156638. for (i = 0; i < nc; i++) {
  156639. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156640. temp = total_colors / Ncolors[j];
  156641. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156642. if (temp > (long) max_colors)
  156643. break; /* won't fit, done with this pass */
  156644. Ncolors[j]++; /* OK, apply the increment */
  156645. total_colors = (int) temp;
  156646. changed = TRUE;
  156647. }
  156648. } while (changed);
  156649. return total_colors;
  156650. }
  156651. LOCAL(int)
  156652. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156653. {
  156654. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156655. }
  156656. LOCAL(int)
  156657. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156658. {
  156659. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156660. }
  156661. LOCAL(void)
  156662. create_colormap (j_decompress_ptr cinfo)
  156663. {
  156664. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156665. JSAMPARRAY colormap; /* Created colormap */
  156666. int total_colors; /* Number of distinct output colors */
  156667. int i,j,k, nci, blksize, blkdist, ptr, val;
  156668. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156669. if (cinfo->out_color_components == 3)
  156670. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156671. total_colors, cquantize->Ncolors[0],
  156672. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156673. else
  156674. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156675. colormap = (*cinfo->mem->alloc_sarray)
  156676. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156677. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156678. blkdist = total_colors;
  156679. for (i = 0; i < cinfo->out_color_components; i++) {
  156680. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156681. blksize = blkdist / nci;
  156682. for (j = 0; j < nci; j++) {
  156683. val = output_value(cinfo, i, j, nci-1);
  156684. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156685. for (k = 0; k < blksize; k++)
  156686. colormap[i][ptr+k] = (JSAMPLE) val;
  156687. }
  156688. }
  156689. blkdist = blksize; /* blksize of this color is blkdist of next */
  156690. }
  156691. cquantize->sv_colormap = colormap;
  156692. cquantize->sv_actual = total_colors;
  156693. }
  156694. LOCAL(void)
  156695. create_colorindex (j_decompress_ptr cinfo)
  156696. {
  156697. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156698. JSAMPROW indexptr;
  156699. int i,j,k, nci, blksize, val, pad;
  156700. if (cinfo->dither_mode == JDITHER_ORDERED) {
  156701. pad = MAXJSAMPLE*2;
  156702. cquantize->is_padded = TRUE;
  156703. } else {
  156704. pad = 0;
  156705. cquantize->is_padded = FALSE;
  156706. }
  156707. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  156708. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156709. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  156710. (JDIMENSION) cinfo->out_color_components);
  156711. blksize = cquantize->sv_actual;
  156712. for (i = 0; i < cinfo->out_color_components; i++) {
  156713. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156714. blksize = blksize / nci;
  156715. if (pad)
  156716. cquantize->colorindex[i] += MAXJSAMPLE;
  156717. indexptr = cquantize->colorindex[i];
  156718. val = 0;
  156719. k = largest_input_value(cinfo, i, 0, nci-1);
  156720. for (j = 0; j <= MAXJSAMPLE; j++) {
  156721. while (j > k) /* advance val if past boundary */
  156722. k = largest_input_value(cinfo, i, ++val, nci-1);
  156723. indexptr[j] = (JSAMPLE) (val * blksize);
  156724. }
  156725. if (pad)
  156726. for (j = 1; j <= MAXJSAMPLE; j++) {
  156727. indexptr[-j] = indexptr[0];
  156728. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  156729. }
  156730. }
  156731. }
  156732. LOCAL(ODITHER_MATRIX_PTR)
  156733. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  156734. {
  156735. ODITHER_MATRIX_PTR odither;
  156736. int j,k;
  156737. INT32 num,den;
  156738. odither = (ODITHER_MATRIX_PTR)
  156739. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156740. SIZEOF(ODITHER_MATRIX));
  156741. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  156742. for (j = 0; j < ODITHER_SIZE; j++) {
  156743. for (k = 0; k < ODITHER_SIZE; k++) {
  156744. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  156745. * MAXJSAMPLE;
  156746. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  156747. }
  156748. }
  156749. return odither;
  156750. }
  156751. LOCAL(void)
  156752. create_odither_tables (j_decompress_ptr cinfo)
  156753. {
  156754. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156755. ODITHER_MATRIX_PTR odither;
  156756. int i, j, nci;
  156757. for (i = 0; i < cinfo->out_color_components; i++) {
  156758. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156759. odither = NULL; /* search for matching prior component */
  156760. for (j = 0; j < i; j++) {
  156761. if (nci == cquantize->Ncolors[j]) {
  156762. odither = cquantize->odither[j];
  156763. break;
  156764. }
  156765. }
  156766. if (odither == NULL) /* need a new table? */
  156767. odither = make_odither_array(cinfo, nci);
  156768. cquantize->odither[i] = odither;
  156769. }
  156770. }
  156771. METHODDEF(void)
  156772. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156773. JSAMPARRAY output_buf, int num_rows)
  156774. {
  156775. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156776. JSAMPARRAY colorindex = cquantize->colorindex;
  156777. register int pixcode, ci;
  156778. register JSAMPROW ptrin, ptrout;
  156779. int row;
  156780. JDIMENSION col;
  156781. JDIMENSION width = cinfo->output_width;
  156782. register int nc = cinfo->out_color_components;
  156783. for (row = 0; row < num_rows; row++) {
  156784. ptrin = input_buf[row];
  156785. ptrout = output_buf[row];
  156786. for (col = width; col > 0; col--) {
  156787. pixcode = 0;
  156788. for (ci = 0; ci < nc; ci++) {
  156789. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  156790. }
  156791. *ptrout++ = (JSAMPLE) pixcode;
  156792. }
  156793. }
  156794. }
  156795. METHODDEF(void)
  156796. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156797. JSAMPARRAY output_buf, int num_rows)
  156798. {
  156799. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156800. register int pixcode;
  156801. register JSAMPROW ptrin, ptrout;
  156802. JSAMPROW colorindex0 = cquantize->colorindex[0];
  156803. JSAMPROW colorindex1 = cquantize->colorindex[1];
  156804. JSAMPROW colorindex2 = cquantize->colorindex[2];
  156805. int row;
  156806. JDIMENSION col;
  156807. JDIMENSION width = cinfo->output_width;
  156808. for (row = 0; row < num_rows; row++) {
  156809. ptrin = input_buf[row];
  156810. ptrout = output_buf[row];
  156811. for (col = width; col > 0; col--) {
  156812. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  156813. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  156814. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  156815. *ptrout++ = (JSAMPLE) pixcode;
  156816. }
  156817. }
  156818. }
  156819. METHODDEF(void)
  156820. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156821. JSAMPARRAY output_buf, int num_rows)
  156822. {
  156823. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156824. register JSAMPROW input_ptr;
  156825. register JSAMPROW output_ptr;
  156826. JSAMPROW colorindex_ci;
  156827. int * dither; /* points to active row of dither matrix */
  156828. int row_index, col_index; /* current indexes into dither matrix */
  156829. int nc = cinfo->out_color_components;
  156830. int ci;
  156831. int row;
  156832. JDIMENSION col;
  156833. JDIMENSION width = cinfo->output_width;
  156834. for (row = 0; row < num_rows; row++) {
  156835. jzero_far((void FAR *) output_buf[row],
  156836. (size_t) (width * SIZEOF(JSAMPLE)));
  156837. row_index = cquantize->row_index;
  156838. for (ci = 0; ci < nc; ci++) {
  156839. input_ptr = input_buf[row] + ci;
  156840. output_ptr = output_buf[row];
  156841. colorindex_ci = cquantize->colorindex[ci];
  156842. dither = cquantize->odither[ci][row_index];
  156843. col_index = 0;
  156844. for (col = width; col > 0; col--) {
  156845. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  156846. input_ptr += nc;
  156847. output_ptr++;
  156848. col_index = (col_index + 1) & ODITHER_MASK;
  156849. }
  156850. }
  156851. row_index = (row_index + 1) & ODITHER_MASK;
  156852. cquantize->row_index = row_index;
  156853. }
  156854. }
  156855. METHODDEF(void)
  156856. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156857. JSAMPARRAY output_buf, int num_rows)
  156858. {
  156859. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156860. register int pixcode;
  156861. register JSAMPROW input_ptr;
  156862. register JSAMPROW output_ptr;
  156863. JSAMPROW colorindex0 = cquantize->colorindex[0];
  156864. JSAMPROW colorindex1 = cquantize->colorindex[1];
  156865. JSAMPROW colorindex2 = cquantize->colorindex[2];
  156866. int * dither0; /* points to active row of dither matrix */
  156867. int * dither1;
  156868. int * dither2;
  156869. int row_index, col_index; /* current indexes into dither matrix */
  156870. int row;
  156871. JDIMENSION col;
  156872. JDIMENSION width = cinfo->output_width;
  156873. for (row = 0; row < num_rows; row++) {
  156874. row_index = cquantize->row_index;
  156875. input_ptr = input_buf[row];
  156876. output_ptr = output_buf[row];
  156877. dither0 = cquantize->odither[0][row_index];
  156878. dither1 = cquantize->odither[1][row_index];
  156879. dither2 = cquantize->odither[2][row_index];
  156880. col_index = 0;
  156881. for (col = width; col > 0; col--) {
  156882. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  156883. dither0[col_index]]);
  156884. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  156885. dither1[col_index]]);
  156886. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  156887. dither2[col_index]]);
  156888. *output_ptr++ = (JSAMPLE) pixcode;
  156889. col_index = (col_index + 1) & ODITHER_MASK;
  156890. }
  156891. row_index = (row_index + 1) & ODITHER_MASK;
  156892. cquantize->row_index = row_index;
  156893. }
  156894. }
  156895. METHODDEF(void)
  156896. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156897. JSAMPARRAY output_buf, int num_rows)
  156898. {
  156899. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156900. register LOCFSERROR cur; /* current error or pixel value */
  156901. LOCFSERROR belowerr; /* error for pixel below cur */
  156902. LOCFSERROR bpreverr; /* error for below/prev col */
  156903. LOCFSERROR bnexterr; /* error for below/next col */
  156904. LOCFSERROR delta;
  156905. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  156906. register JSAMPROW input_ptr;
  156907. register JSAMPROW output_ptr;
  156908. JSAMPROW colorindex_ci;
  156909. JSAMPROW colormap_ci;
  156910. int pixcode;
  156911. int nc = cinfo->out_color_components;
  156912. int dir; /* 1 for left-to-right, -1 for right-to-left */
  156913. int dirnc; /* dir * nc */
  156914. int ci;
  156915. int row;
  156916. JDIMENSION col;
  156917. JDIMENSION width = cinfo->output_width;
  156918. JSAMPLE *range_limit = cinfo->sample_range_limit;
  156919. SHIFT_TEMPS
  156920. for (row = 0; row < num_rows; row++) {
  156921. jzero_far((void FAR *) output_buf[row],
  156922. (size_t) (width * SIZEOF(JSAMPLE)));
  156923. for (ci = 0; ci < nc; ci++) {
  156924. input_ptr = input_buf[row] + ci;
  156925. output_ptr = output_buf[row];
  156926. if (cquantize->on_odd_row) {
  156927. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  156928. output_ptr += width-1;
  156929. dir = -1;
  156930. dirnc = -nc;
  156931. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  156932. } else {
  156933. dir = 1;
  156934. dirnc = nc;
  156935. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  156936. }
  156937. colorindex_ci = cquantize->colorindex[ci];
  156938. colormap_ci = cquantize->sv_colormap[ci];
  156939. cur = 0;
  156940. belowerr = bpreverr = 0;
  156941. for (col = width; col > 0; col--) {
  156942. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  156943. cur += GETJSAMPLE(*input_ptr);
  156944. cur = GETJSAMPLE(range_limit[cur]);
  156945. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  156946. *output_ptr += (JSAMPLE) pixcode;
  156947. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  156948. bnexterr = cur;
  156949. delta = cur * 2;
  156950. cur += delta; /* form error * 3 */
  156951. errorptr[0] = (FSERROR) (bpreverr + cur);
  156952. cur += delta; /* form error * 5 */
  156953. bpreverr = belowerr + cur;
  156954. belowerr = bnexterr;
  156955. cur += delta; /* form error * 7 */
  156956. input_ptr += dirnc; /* advance input ptr to next column */
  156957. output_ptr += dir; /* advance output ptr to next column */
  156958. errorptr += dir; /* advance errorptr to current column */
  156959. }
  156960. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  156961. }
  156962. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  156963. }
  156964. }
  156965. LOCAL(void)
  156966. alloc_fs_workspace (j_decompress_ptr cinfo)
  156967. {
  156968. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156969. size_t arraysize;
  156970. int i;
  156971. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  156972. for (i = 0; i < cinfo->out_color_components; i++) {
  156973. cquantize->fserrors[i] = (FSERRPTR)
  156974. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  156975. }
  156976. }
  156977. METHODDEF(void)
  156978. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  156979. {
  156980. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156981. size_t arraysize;
  156982. int i;
  156983. cinfo->colormap = cquantize->sv_colormap;
  156984. cinfo->actual_number_of_colors = cquantize->sv_actual;
  156985. switch (cinfo->dither_mode) {
  156986. case JDITHER_NONE:
  156987. if (cinfo->out_color_components == 3)
  156988. cquantize->pub.color_quantize = color_quantize3;
  156989. else
  156990. cquantize->pub.color_quantize = color_quantize;
  156991. break;
  156992. case JDITHER_ORDERED:
  156993. if (cinfo->out_color_components == 3)
  156994. cquantize->pub.color_quantize = quantize3_ord_dither;
  156995. else
  156996. cquantize->pub.color_quantize = quantize_ord_dither;
  156997. cquantize->row_index = 0; /* initialize state for ordered dither */
  156998. if (! cquantize->is_padded)
  156999. create_colorindex(cinfo);
  157000. if (cquantize->odither[0] == NULL)
  157001. create_odither_tables(cinfo);
  157002. break;
  157003. case JDITHER_FS:
  157004. cquantize->pub.color_quantize = quantize_fs_dither;
  157005. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157006. if (cquantize->fserrors[0] == NULL)
  157007. alloc_fs_workspace(cinfo);
  157008. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157009. for (i = 0; i < cinfo->out_color_components; i++)
  157010. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157011. break;
  157012. default:
  157013. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157014. break;
  157015. }
  157016. }
  157017. METHODDEF(void)
  157018. finish_pass_1_quant (j_decompress_ptr cinfo)
  157019. {
  157020. }
  157021. METHODDEF(void)
  157022. new_color_map_1_quant (j_decompress_ptr cinfo)
  157023. {
  157024. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157025. }
  157026. GLOBAL(void)
  157027. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157028. {
  157029. my_cquantize_ptr cquantize;
  157030. cquantize = (my_cquantize_ptr)
  157031. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157032. SIZEOF(my_cquantizer));
  157033. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157034. cquantize->pub.start_pass = start_pass_1_quant;
  157035. cquantize->pub.finish_pass = finish_pass_1_quant;
  157036. cquantize->pub.new_color_map = new_color_map_1_quant;
  157037. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157038. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157039. if (cinfo->out_color_components > MAX_Q_COMPS)
  157040. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157041. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157042. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157043. create_colormap(cinfo);
  157044. create_colorindex(cinfo);
  157045. if (cinfo->dither_mode == JDITHER_FS)
  157046. alloc_fs_workspace(cinfo);
  157047. }
  157048. #endif /* QUANT_1PASS_SUPPORTED */
  157049. /*** End of inlined file: jquant1.c ***/
  157050. /*** Start of inlined file: jquant2.c ***/
  157051. #define JPEG_INTERNALS
  157052. #ifdef QUANT_2PASS_SUPPORTED
  157053. #define R_SCALE 2 /* scale R distances by this much */
  157054. #define G_SCALE 3 /* scale G distances by this much */
  157055. #define B_SCALE 1 /* and B by this much */
  157056. #if RGB_RED == 0
  157057. #define C0_SCALE R_SCALE
  157058. #endif
  157059. #if RGB_BLUE == 0
  157060. #define C0_SCALE B_SCALE
  157061. #endif
  157062. #if RGB_GREEN == 1
  157063. #define C1_SCALE G_SCALE
  157064. #endif
  157065. #if RGB_RED == 2
  157066. #define C2_SCALE R_SCALE
  157067. #endif
  157068. #if RGB_BLUE == 2
  157069. #define C2_SCALE B_SCALE
  157070. #endif
  157071. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157072. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157073. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157074. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157075. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157076. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157077. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157078. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157079. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157080. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157081. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157082. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157083. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157084. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157085. typedef hist2d * hist3d; /* type for top-level pointer */
  157086. #if BITS_IN_JSAMPLE == 8
  157087. typedef INT16 FSERROR; /* 16 bits should be enough */
  157088. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157089. #else
  157090. typedef INT32 FSERROR; /* may need more than 16 bits */
  157091. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157092. #endif
  157093. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157094. typedef struct {
  157095. struct jpeg_color_quantizer pub; /* public fields */
  157096. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157097. int desired; /* desired # of colors = size of colormap */
  157098. hist3d histogram; /* pointer to the histogram */
  157099. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157100. FSERRPTR fserrors; /* accumulated errors */
  157101. boolean on_odd_row; /* flag to remember which row we are on */
  157102. int * error_limiter; /* table for clamping the applied error */
  157103. } my_cquantizer2;
  157104. typedef my_cquantizer2 * my_cquantize_ptr2;
  157105. METHODDEF(void)
  157106. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157107. JSAMPARRAY output_buf, int num_rows)
  157108. {
  157109. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157110. register JSAMPROW ptr;
  157111. register histptr histp;
  157112. register hist3d histogram = cquantize->histogram;
  157113. int row;
  157114. JDIMENSION col;
  157115. JDIMENSION width = cinfo->output_width;
  157116. for (row = 0; row < num_rows; row++) {
  157117. ptr = input_buf[row];
  157118. for (col = width; col > 0; col--) {
  157119. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157120. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157121. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157122. if (++(*histp) <= 0)
  157123. (*histp)--;
  157124. ptr += 3;
  157125. }
  157126. }
  157127. }
  157128. typedef struct {
  157129. int c0min, c0max;
  157130. int c1min, c1max;
  157131. int c2min, c2max;
  157132. INT32 volume;
  157133. long colorcount;
  157134. } box;
  157135. typedef box * boxptr;
  157136. LOCAL(boxptr)
  157137. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157138. {
  157139. register boxptr boxp;
  157140. register int i;
  157141. register long maxc = 0;
  157142. boxptr which = NULL;
  157143. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157144. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157145. which = boxp;
  157146. maxc = boxp->colorcount;
  157147. }
  157148. }
  157149. return which;
  157150. }
  157151. LOCAL(boxptr)
  157152. find_biggest_volume (boxptr boxlist, int numboxes)
  157153. {
  157154. register boxptr boxp;
  157155. register int i;
  157156. register INT32 maxv = 0;
  157157. boxptr which = NULL;
  157158. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157159. if (boxp->volume > maxv) {
  157160. which = boxp;
  157161. maxv = boxp->volume;
  157162. }
  157163. }
  157164. return which;
  157165. }
  157166. LOCAL(void)
  157167. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157168. {
  157169. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157170. hist3d histogram = cquantize->histogram;
  157171. histptr histp;
  157172. int c0,c1,c2;
  157173. int c0min,c0max,c1min,c1max,c2min,c2max;
  157174. INT32 dist0,dist1,dist2;
  157175. long ccount;
  157176. c0min = boxp->c0min; c0max = boxp->c0max;
  157177. c1min = boxp->c1min; c1max = boxp->c1max;
  157178. c2min = boxp->c2min; c2max = boxp->c2max;
  157179. if (c0max > c0min)
  157180. for (c0 = c0min; c0 <= c0max; c0++)
  157181. for (c1 = c1min; c1 <= c1max; c1++) {
  157182. histp = & histogram[c0][c1][c2min];
  157183. for (c2 = c2min; c2 <= c2max; c2++)
  157184. if (*histp++ != 0) {
  157185. boxp->c0min = c0min = c0;
  157186. goto have_c0min;
  157187. }
  157188. }
  157189. have_c0min:
  157190. if (c0max > c0min)
  157191. for (c0 = c0max; c0 >= c0min; c0--)
  157192. for (c1 = c1min; c1 <= c1max; c1++) {
  157193. histp = & histogram[c0][c1][c2min];
  157194. for (c2 = c2min; c2 <= c2max; c2++)
  157195. if (*histp++ != 0) {
  157196. boxp->c0max = c0max = c0;
  157197. goto have_c0max;
  157198. }
  157199. }
  157200. have_c0max:
  157201. if (c1max > c1min)
  157202. for (c1 = c1min; c1 <= c1max; c1++)
  157203. for (c0 = c0min; c0 <= c0max; c0++) {
  157204. histp = & histogram[c0][c1][c2min];
  157205. for (c2 = c2min; c2 <= c2max; c2++)
  157206. if (*histp++ != 0) {
  157207. boxp->c1min = c1min = c1;
  157208. goto have_c1min;
  157209. }
  157210. }
  157211. have_c1min:
  157212. if (c1max > c1min)
  157213. for (c1 = c1max; c1 >= c1min; c1--)
  157214. for (c0 = c0min; c0 <= c0max; c0++) {
  157215. histp = & histogram[c0][c1][c2min];
  157216. for (c2 = c2min; c2 <= c2max; c2++)
  157217. if (*histp++ != 0) {
  157218. boxp->c1max = c1max = c1;
  157219. goto have_c1max;
  157220. }
  157221. }
  157222. have_c1max:
  157223. if (c2max > c2min)
  157224. for (c2 = c2min; c2 <= c2max; c2++)
  157225. for (c0 = c0min; c0 <= c0max; c0++) {
  157226. histp = & histogram[c0][c1min][c2];
  157227. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157228. if (*histp != 0) {
  157229. boxp->c2min = c2min = c2;
  157230. goto have_c2min;
  157231. }
  157232. }
  157233. have_c2min:
  157234. if (c2max > c2min)
  157235. for (c2 = c2max; c2 >= c2min; c2--)
  157236. for (c0 = c0min; c0 <= c0max; c0++) {
  157237. histp = & histogram[c0][c1min][c2];
  157238. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157239. if (*histp != 0) {
  157240. boxp->c2max = c2max = c2;
  157241. goto have_c2max;
  157242. }
  157243. }
  157244. have_c2max:
  157245. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157246. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157247. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157248. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157249. ccount = 0;
  157250. for (c0 = c0min; c0 <= c0max; c0++)
  157251. for (c1 = c1min; c1 <= c1max; c1++) {
  157252. histp = & histogram[c0][c1][c2min];
  157253. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157254. if (*histp != 0) {
  157255. ccount++;
  157256. }
  157257. }
  157258. boxp->colorcount = ccount;
  157259. }
  157260. LOCAL(int)
  157261. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157262. int desired_colors)
  157263. {
  157264. int n,lb;
  157265. int c0,c1,c2,cmax;
  157266. register boxptr b1,b2;
  157267. while (numboxes < desired_colors) {
  157268. if (numboxes*2 <= desired_colors) {
  157269. b1 = find_biggest_color_pop(boxlist, numboxes);
  157270. } else {
  157271. b1 = find_biggest_volume(boxlist, numboxes);
  157272. }
  157273. if (b1 == NULL) /* no splittable boxes left! */
  157274. break;
  157275. b2 = &boxlist[numboxes]; /* where new box will go */
  157276. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157277. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157278. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157279. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157280. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157281. #if RGB_RED == 0
  157282. cmax = c1; n = 1;
  157283. if (c0 > cmax) { cmax = c0; n = 0; }
  157284. if (c2 > cmax) { n = 2; }
  157285. #else
  157286. cmax = c1; n = 1;
  157287. if (c2 > cmax) { cmax = c2; n = 2; }
  157288. if (c0 > cmax) { n = 0; }
  157289. #endif
  157290. switch (n) {
  157291. case 0:
  157292. lb = (b1->c0max + b1->c0min) / 2;
  157293. b1->c0max = lb;
  157294. b2->c0min = lb+1;
  157295. break;
  157296. case 1:
  157297. lb = (b1->c1max + b1->c1min) / 2;
  157298. b1->c1max = lb;
  157299. b2->c1min = lb+1;
  157300. break;
  157301. case 2:
  157302. lb = (b1->c2max + b1->c2min) / 2;
  157303. b1->c2max = lb;
  157304. b2->c2min = lb+1;
  157305. break;
  157306. }
  157307. update_box(cinfo, b1);
  157308. update_box(cinfo, b2);
  157309. numboxes++;
  157310. }
  157311. return numboxes;
  157312. }
  157313. LOCAL(void)
  157314. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157315. {
  157316. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157317. hist3d histogram = cquantize->histogram;
  157318. histptr histp;
  157319. int c0,c1,c2;
  157320. int c0min,c0max,c1min,c1max,c2min,c2max;
  157321. long count;
  157322. long total = 0;
  157323. long c0total = 0;
  157324. long c1total = 0;
  157325. long c2total = 0;
  157326. c0min = boxp->c0min; c0max = boxp->c0max;
  157327. c1min = boxp->c1min; c1max = boxp->c1max;
  157328. c2min = boxp->c2min; c2max = boxp->c2max;
  157329. for (c0 = c0min; c0 <= c0max; c0++)
  157330. for (c1 = c1min; c1 <= c1max; c1++) {
  157331. histp = & histogram[c0][c1][c2min];
  157332. for (c2 = c2min; c2 <= c2max; c2++) {
  157333. if ((count = *histp++) != 0) {
  157334. total += count;
  157335. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157336. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157337. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157338. }
  157339. }
  157340. }
  157341. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157342. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157343. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157344. }
  157345. LOCAL(void)
  157346. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157347. {
  157348. boxptr boxlist;
  157349. int numboxes;
  157350. int i;
  157351. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157352. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157353. numboxes = 1;
  157354. boxlist[0].c0min = 0;
  157355. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157356. boxlist[0].c1min = 0;
  157357. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157358. boxlist[0].c2min = 0;
  157359. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157360. update_box(cinfo, & boxlist[0]);
  157361. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157362. for (i = 0; i < numboxes; i++)
  157363. compute_color(cinfo, & boxlist[i], i);
  157364. cinfo->actual_number_of_colors = numboxes;
  157365. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157366. }
  157367. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157368. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157369. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157370. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157371. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157372. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157373. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157374. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157375. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157376. LOCAL(int)
  157377. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157378. JSAMPLE colorlist[])
  157379. {
  157380. int numcolors = cinfo->actual_number_of_colors;
  157381. int maxc0, maxc1, maxc2;
  157382. int centerc0, centerc1, centerc2;
  157383. int i, x, ncolors;
  157384. INT32 minmaxdist, min_dist, max_dist, tdist;
  157385. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157386. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157387. centerc0 = (minc0 + maxc0) >> 1;
  157388. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157389. centerc1 = (minc1 + maxc1) >> 1;
  157390. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157391. centerc2 = (minc2 + maxc2) >> 1;
  157392. minmaxdist = 0x7FFFFFFFL;
  157393. for (i = 0; i < numcolors; i++) {
  157394. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157395. if (x < minc0) {
  157396. tdist = (x - minc0) * C0_SCALE;
  157397. min_dist = tdist*tdist;
  157398. tdist = (x - maxc0) * C0_SCALE;
  157399. max_dist = tdist*tdist;
  157400. } else if (x > maxc0) {
  157401. tdist = (x - maxc0) * C0_SCALE;
  157402. min_dist = tdist*tdist;
  157403. tdist = (x - minc0) * C0_SCALE;
  157404. max_dist = tdist*tdist;
  157405. } else {
  157406. min_dist = 0;
  157407. if (x <= centerc0) {
  157408. tdist = (x - maxc0) * C0_SCALE;
  157409. max_dist = tdist*tdist;
  157410. } else {
  157411. tdist = (x - minc0) * C0_SCALE;
  157412. max_dist = tdist*tdist;
  157413. }
  157414. }
  157415. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157416. if (x < minc1) {
  157417. tdist = (x - minc1) * C1_SCALE;
  157418. min_dist += tdist*tdist;
  157419. tdist = (x - maxc1) * C1_SCALE;
  157420. max_dist += tdist*tdist;
  157421. } else if (x > maxc1) {
  157422. tdist = (x - maxc1) * C1_SCALE;
  157423. min_dist += tdist*tdist;
  157424. tdist = (x - minc1) * C1_SCALE;
  157425. max_dist += tdist*tdist;
  157426. } else {
  157427. if (x <= centerc1) {
  157428. tdist = (x - maxc1) * C1_SCALE;
  157429. max_dist += tdist*tdist;
  157430. } else {
  157431. tdist = (x - minc1) * C1_SCALE;
  157432. max_dist += tdist*tdist;
  157433. }
  157434. }
  157435. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157436. if (x < minc2) {
  157437. tdist = (x - minc2) * C2_SCALE;
  157438. min_dist += tdist*tdist;
  157439. tdist = (x - maxc2) * C2_SCALE;
  157440. max_dist += tdist*tdist;
  157441. } else if (x > maxc2) {
  157442. tdist = (x - maxc2) * C2_SCALE;
  157443. min_dist += tdist*tdist;
  157444. tdist = (x - minc2) * C2_SCALE;
  157445. max_dist += tdist*tdist;
  157446. } else {
  157447. if (x <= centerc2) {
  157448. tdist = (x - maxc2) * C2_SCALE;
  157449. max_dist += tdist*tdist;
  157450. } else {
  157451. tdist = (x - minc2) * C2_SCALE;
  157452. max_dist += tdist*tdist;
  157453. }
  157454. }
  157455. mindist[i] = min_dist; /* save away the results */
  157456. if (max_dist < minmaxdist)
  157457. minmaxdist = max_dist;
  157458. }
  157459. ncolors = 0;
  157460. for (i = 0; i < numcolors; i++) {
  157461. if (mindist[i] <= minmaxdist)
  157462. colorlist[ncolors++] = (JSAMPLE) i;
  157463. }
  157464. return ncolors;
  157465. }
  157466. LOCAL(void)
  157467. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157468. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157469. {
  157470. int ic0, ic1, ic2;
  157471. int i, icolor;
  157472. register INT32 * bptr; /* pointer into bestdist[] array */
  157473. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157474. INT32 dist0, dist1; /* initial distance values */
  157475. register INT32 dist2; /* current distance in inner loop */
  157476. INT32 xx0, xx1; /* distance increments */
  157477. register INT32 xx2;
  157478. INT32 inc0, inc1, inc2; /* initial values for increments */
  157479. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157480. bptr = bestdist;
  157481. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157482. *bptr++ = 0x7FFFFFFFL;
  157483. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157484. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157485. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157486. for (i = 0; i < numcolors; i++) {
  157487. icolor = GETJSAMPLE(colorlist[i]);
  157488. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157489. dist0 = inc0*inc0;
  157490. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157491. dist0 += inc1*inc1;
  157492. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157493. dist0 += inc2*inc2;
  157494. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157495. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157496. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157497. bptr = bestdist;
  157498. cptr = bestcolor;
  157499. xx0 = inc0;
  157500. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157501. dist1 = dist0;
  157502. xx1 = inc1;
  157503. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157504. dist2 = dist1;
  157505. xx2 = inc2;
  157506. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157507. if (dist2 < *bptr) {
  157508. *bptr = dist2;
  157509. *cptr = (JSAMPLE) icolor;
  157510. }
  157511. dist2 += xx2;
  157512. xx2 += 2 * STEP_C2 * STEP_C2;
  157513. bptr++;
  157514. cptr++;
  157515. }
  157516. dist1 += xx1;
  157517. xx1 += 2 * STEP_C1 * STEP_C1;
  157518. }
  157519. dist0 += xx0;
  157520. xx0 += 2 * STEP_C0 * STEP_C0;
  157521. }
  157522. }
  157523. }
  157524. LOCAL(void)
  157525. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157526. {
  157527. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157528. hist3d histogram = cquantize->histogram;
  157529. int minc0, minc1, minc2; /* lower left corner of update box */
  157530. int ic0, ic1, ic2;
  157531. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157532. register histptr cachep; /* pointer into main cache array */
  157533. JSAMPLE colorlist[MAXNUMCOLORS];
  157534. int numcolors; /* number of candidate colors */
  157535. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157536. c0 >>= BOX_C0_LOG;
  157537. c1 >>= BOX_C1_LOG;
  157538. c2 >>= BOX_C2_LOG;
  157539. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157540. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157541. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157542. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157543. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157544. bestcolor);
  157545. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157546. c1 <<= BOX_C1_LOG;
  157547. c2 <<= BOX_C2_LOG;
  157548. cptr = bestcolor;
  157549. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157550. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157551. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157552. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157553. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157554. }
  157555. }
  157556. }
  157557. }
  157558. METHODDEF(void)
  157559. pass2_no_dither (j_decompress_ptr cinfo,
  157560. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157561. {
  157562. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157563. hist3d histogram = cquantize->histogram;
  157564. register JSAMPROW inptr, outptr;
  157565. register histptr cachep;
  157566. register int c0, c1, c2;
  157567. int row;
  157568. JDIMENSION col;
  157569. JDIMENSION width = cinfo->output_width;
  157570. for (row = 0; row < num_rows; row++) {
  157571. inptr = input_buf[row];
  157572. outptr = output_buf[row];
  157573. for (col = width; col > 0; col--) {
  157574. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157575. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157576. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157577. cachep = & histogram[c0][c1][c2];
  157578. if (*cachep == 0)
  157579. fill_inverse_cmap(cinfo, c0,c1,c2);
  157580. *outptr++ = (JSAMPLE) (*cachep - 1);
  157581. }
  157582. }
  157583. }
  157584. METHODDEF(void)
  157585. pass2_fs_dither (j_decompress_ptr cinfo,
  157586. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157587. {
  157588. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157589. hist3d histogram = cquantize->histogram;
  157590. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157591. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157592. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157593. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157594. JSAMPROW inptr; /* => current input pixel */
  157595. JSAMPROW outptr; /* => current output pixel */
  157596. histptr cachep;
  157597. int dir; /* +1 or -1 depending on direction */
  157598. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157599. int row;
  157600. JDIMENSION col;
  157601. JDIMENSION width = cinfo->output_width;
  157602. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157603. int *error_limit = cquantize->error_limiter;
  157604. JSAMPROW colormap0 = cinfo->colormap[0];
  157605. JSAMPROW colormap1 = cinfo->colormap[1];
  157606. JSAMPROW colormap2 = cinfo->colormap[2];
  157607. SHIFT_TEMPS
  157608. for (row = 0; row < num_rows; row++) {
  157609. inptr = input_buf[row];
  157610. outptr = output_buf[row];
  157611. if (cquantize->on_odd_row) {
  157612. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157613. outptr += width-1;
  157614. dir = -1;
  157615. dir3 = -3;
  157616. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157617. cquantize->on_odd_row = FALSE; /* flip for next time */
  157618. } else {
  157619. dir = 1;
  157620. dir3 = 3;
  157621. errorptr = cquantize->fserrors; /* => entry before first real column */
  157622. cquantize->on_odd_row = TRUE; /* flip for next time */
  157623. }
  157624. cur0 = cur1 = cur2 = 0;
  157625. belowerr0 = belowerr1 = belowerr2 = 0;
  157626. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157627. for (col = width; col > 0; col--) {
  157628. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157629. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157630. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157631. cur0 = error_limit[cur0];
  157632. cur1 = error_limit[cur1];
  157633. cur2 = error_limit[cur2];
  157634. cur0 += GETJSAMPLE(inptr[0]);
  157635. cur1 += GETJSAMPLE(inptr[1]);
  157636. cur2 += GETJSAMPLE(inptr[2]);
  157637. cur0 = GETJSAMPLE(range_limit[cur0]);
  157638. cur1 = GETJSAMPLE(range_limit[cur1]);
  157639. cur2 = GETJSAMPLE(range_limit[cur2]);
  157640. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157641. if (*cachep == 0)
  157642. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157643. { register int pixcode = *cachep - 1;
  157644. *outptr = (JSAMPLE) pixcode;
  157645. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157646. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157647. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157648. }
  157649. { register LOCFSERROR bnexterr, delta;
  157650. bnexterr = cur0; /* Process component 0 */
  157651. delta = cur0 * 2;
  157652. cur0 += delta; /* form error * 3 */
  157653. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157654. cur0 += delta; /* form error * 5 */
  157655. bpreverr0 = belowerr0 + cur0;
  157656. belowerr0 = bnexterr;
  157657. cur0 += delta; /* form error * 7 */
  157658. bnexterr = cur1; /* Process component 1 */
  157659. delta = cur1 * 2;
  157660. cur1 += delta; /* form error * 3 */
  157661. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157662. cur1 += delta; /* form error * 5 */
  157663. bpreverr1 = belowerr1 + cur1;
  157664. belowerr1 = bnexterr;
  157665. cur1 += delta; /* form error * 7 */
  157666. bnexterr = cur2; /* Process component 2 */
  157667. delta = cur2 * 2;
  157668. cur2 += delta; /* form error * 3 */
  157669. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157670. cur2 += delta; /* form error * 5 */
  157671. bpreverr2 = belowerr2 + cur2;
  157672. belowerr2 = bnexterr;
  157673. cur2 += delta; /* form error * 7 */
  157674. }
  157675. inptr += dir3; /* Advance pixel pointers to next column */
  157676. outptr += dir;
  157677. errorptr += dir3; /* advance errorptr to current column */
  157678. }
  157679. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157680. errorptr[1] = (FSERROR) bpreverr1;
  157681. errorptr[2] = (FSERROR) bpreverr2;
  157682. }
  157683. }
  157684. LOCAL(void)
  157685. init_error_limit (j_decompress_ptr cinfo)
  157686. {
  157687. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157688. int * table;
  157689. int in, out;
  157690. table = (int *) (*cinfo->mem->alloc_small)
  157691. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157692. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157693. cquantize->error_limiter = table;
  157694. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157695. out = 0;
  157696. for (in = 0; in < STEPSIZE; in++, out++) {
  157697. table[in] = out; table[-in] = -out;
  157698. }
  157699. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  157700. table[in] = out; table[-in] = -out;
  157701. }
  157702. for (; in <= MAXJSAMPLE; in++) {
  157703. table[in] = out; table[-in] = -out;
  157704. }
  157705. #undef STEPSIZE
  157706. }
  157707. METHODDEF(void)
  157708. finish_pass1 (j_decompress_ptr cinfo)
  157709. {
  157710. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157711. cinfo->colormap = cquantize->sv_colormap;
  157712. select_colors(cinfo, cquantize->desired);
  157713. cquantize->needs_zeroed = TRUE;
  157714. }
  157715. METHODDEF(void)
  157716. finish_pass2 (j_decompress_ptr cinfo)
  157717. {
  157718. }
  157719. METHODDEF(void)
  157720. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157721. {
  157722. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157723. hist3d histogram = cquantize->histogram;
  157724. int i;
  157725. if (cinfo->dither_mode != JDITHER_NONE)
  157726. cinfo->dither_mode = JDITHER_FS;
  157727. if (is_pre_scan) {
  157728. cquantize->pub.color_quantize = prescan_quantize;
  157729. cquantize->pub.finish_pass = finish_pass1;
  157730. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  157731. } else {
  157732. if (cinfo->dither_mode == JDITHER_FS)
  157733. cquantize->pub.color_quantize = pass2_fs_dither;
  157734. else
  157735. cquantize->pub.color_quantize = pass2_no_dither;
  157736. cquantize->pub.finish_pass = finish_pass2;
  157737. i = cinfo->actual_number_of_colors;
  157738. if (i < 1)
  157739. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  157740. if (i > MAXNUMCOLORS)
  157741. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157742. if (cinfo->dither_mode == JDITHER_FS) {
  157743. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  157744. (3 * SIZEOF(FSERROR)));
  157745. if (cquantize->fserrors == NULL)
  157746. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157747. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157748. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  157749. if (cquantize->error_limiter == NULL)
  157750. init_error_limit(cinfo);
  157751. cquantize->on_odd_row = FALSE;
  157752. }
  157753. }
  157754. if (cquantize->needs_zeroed) {
  157755. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157756. jzero_far((void FAR *) histogram[i],
  157757. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157758. }
  157759. cquantize->needs_zeroed = FALSE;
  157760. }
  157761. }
  157762. METHODDEF(void)
  157763. new_color_map_2_quant (j_decompress_ptr cinfo)
  157764. {
  157765. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157766. cquantize->needs_zeroed = TRUE;
  157767. }
  157768. GLOBAL(void)
  157769. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  157770. {
  157771. my_cquantize_ptr2 cquantize;
  157772. int i;
  157773. cquantize = (my_cquantize_ptr2)
  157774. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157775. SIZEOF(my_cquantizer2));
  157776. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157777. cquantize->pub.start_pass = start_pass_2_quant;
  157778. cquantize->pub.new_color_map = new_color_map_2_quant;
  157779. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  157780. cquantize->error_limiter = NULL;
  157781. if (cinfo->out_color_components != 3)
  157782. ERREXIT(cinfo, JERR_NOTIMPL);
  157783. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  157784. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  157785. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157786. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  157787. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157788. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157789. }
  157790. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  157791. if (cinfo->enable_2pass_quant) {
  157792. int desired = cinfo->desired_number_of_colors;
  157793. if (desired < 8)
  157794. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  157795. if (desired > MAXNUMCOLORS)
  157796. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157797. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  157798. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  157799. cquantize->desired = desired;
  157800. } else
  157801. cquantize->sv_colormap = NULL;
  157802. if (cinfo->dither_mode != JDITHER_NONE)
  157803. cinfo->dither_mode = JDITHER_FS;
  157804. if (cinfo->dither_mode == JDITHER_FS) {
  157805. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157806. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157807. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  157808. init_error_limit(cinfo);
  157809. }
  157810. }
  157811. #endif /* QUANT_2PASS_SUPPORTED */
  157812. /*** End of inlined file: jquant2.c ***/
  157813. /*** Start of inlined file: jutils.c ***/
  157814. #define JPEG_INTERNALS
  157815. #if 0 /* This table is not actually needed in v6a */
  157816. const int jpeg_zigzag_order[DCTSIZE2] = {
  157817. 0, 1, 5, 6, 14, 15, 27, 28,
  157818. 2, 4, 7, 13, 16, 26, 29, 42,
  157819. 3, 8, 12, 17, 25, 30, 41, 43,
  157820. 9, 11, 18, 24, 31, 40, 44, 53,
  157821. 10, 19, 23, 32, 39, 45, 52, 54,
  157822. 20, 22, 33, 38, 46, 51, 55, 60,
  157823. 21, 34, 37, 47, 50, 56, 59, 61,
  157824. 35, 36, 48, 49, 57, 58, 62, 63
  157825. };
  157826. #endif
  157827. const int jpeg_natural_order[DCTSIZE2+16] = {
  157828. 0, 1, 8, 16, 9, 2, 3, 10,
  157829. 17, 24, 32, 25, 18, 11, 4, 5,
  157830. 12, 19, 26, 33, 40, 48, 41, 34,
  157831. 27, 20, 13, 6, 7, 14, 21, 28,
  157832. 35, 42, 49, 56, 57, 50, 43, 36,
  157833. 29, 22, 15, 23, 30, 37, 44, 51,
  157834. 58, 59, 52, 45, 38, 31, 39, 46,
  157835. 53, 60, 61, 54, 47, 55, 62, 63,
  157836. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  157837. 63, 63, 63, 63, 63, 63, 63, 63
  157838. };
  157839. GLOBAL(long)
  157840. jdiv_round_up (long a, long b)
  157841. {
  157842. return (a + b - 1L) / b;
  157843. }
  157844. GLOBAL(long)
  157845. jround_up (long a, long b)
  157846. {
  157847. a += b - 1L;
  157848. return a - (a % b);
  157849. }
  157850. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  157851. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  157852. #define FMEMZERO(target,size) MEMZERO(target,size)
  157853. #else /* 80x86 case, define if we can */
  157854. #ifdef USE_FMEM
  157855. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  157856. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  157857. #endif
  157858. #endif
  157859. GLOBAL(void)
  157860. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  157861. JSAMPARRAY output_array, int dest_row,
  157862. int num_rows, JDIMENSION num_cols)
  157863. {
  157864. register JSAMPROW inptr, outptr;
  157865. #ifdef FMEMCOPY
  157866. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  157867. #else
  157868. register JDIMENSION count;
  157869. #endif
  157870. register int row;
  157871. input_array += source_row;
  157872. output_array += dest_row;
  157873. for (row = num_rows; row > 0; row--) {
  157874. inptr = *input_array++;
  157875. outptr = *output_array++;
  157876. #ifdef FMEMCOPY
  157877. FMEMCOPY(outptr, inptr, count);
  157878. #else
  157879. for (count = num_cols; count > 0; count--)
  157880. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  157881. #endif
  157882. }
  157883. }
  157884. GLOBAL(void)
  157885. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  157886. JDIMENSION num_blocks)
  157887. {
  157888. #ifdef FMEMCOPY
  157889. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  157890. #else
  157891. register JCOEFPTR inptr, outptr;
  157892. register long count;
  157893. inptr = (JCOEFPTR) input_row;
  157894. outptr = (JCOEFPTR) output_row;
  157895. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  157896. *outptr++ = *inptr++;
  157897. }
  157898. #endif
  157899. }
  157900. GLOBAL(void)
  157901. jzero_far (void FAR * target, size_t bytestozero)
  157902. {
  157903. #ifdef FMEMZERO
  157904. FMEMZERO(target, bytestozero);
  157905. #else
  157906. register char FAR * ptr = (char FAR *) target;
  157907. register size_t count;
  157908. for (count = bytestozero; count > 0; count--) {
  157909. *ptr++ = 0;
  157910. }
  157911. #endif
  157912. }
  157913. /*** End of inlined file: jutils.c ***/
  157914. /*** Start of inlined file: transupp.c ***/
  157915. #define JPEG_INTERNALS
  157916. /*** Start of inlined file: transupp.h ***/
  157917. #ifndef TRANSFORMS_SUPPORTED
  157918. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  157919. #endif
  157920. #ifdef NEED_SHORT_EXTERNAL_NAMES
  157921. #define jtransform_request_workspace jTrRequest
  157922. #define jtransform_adjust_parameters jTrAdjust
  157923. #define jtransform_execute_transformation jTrExec
  157924. #define jcopy_markers_setup jCMrkSetup
  157925. #define jcopy_markers_execute jCMrkExec
  157926. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  157927. typedef enum {
  157928. JXFORM_NONE, /* no transformation */
  157929. JXFORM_FLIP_H, /* horizontal flip */
  157930. JXFORM_FLIP_V, /* vertical flip */
  157931. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  157932. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  157933. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  157934. JXFORM_ROT_180, /* 180-degree rotation */
  157935. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  157936. } JXFORM_CODE;
  157937. typedef struct {
  157938. JXFORM_CODE transform; /* image transform operator */
  157939. boolean trim; /* if TRUE, trim partial MCUs as needed */
  157940. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  157941. int num_components; /* # of components in workspace */
  157942. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  157943. } jpeg_transform_info;
  157944. #if TRANSFORMS_SUPPORTED
  157945. EXTERN(void) jtransform_request_workspace
  157946. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  157947. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  157948. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  157949. jvirt_barray_ptr *src_coef_arrays,
  157950. jpeg_transform_info *info));
  157951. EXTERN(void) jtransform_execute_transformation
  157952. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  157953. jvirt_barray_ptr *src_coef_arrays,
  157954. jpeg_transform_info *info));
  157955. #endif /* TRANSFORMS_SUPPORTED */
  157956. typedef enum {
  157957. JCOPYOPT_NONE, /* copy no optional markers */
  157958. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  157959. JCOPYOPT_ALL /* copy all optional markers */
  157960. } JCOPY_OPTION;
  157961. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  157962. EXTERN(void) jcopy_markers_setup
  157963. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  157964. EXTERN(void) jcopy_markers_execute
  157965. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  157966. JCOPY_OPTION option));
  157967. /*** End of inlined file: transupp.h ***/
  157968. /* My own external interface */
  157969. #if TRANSFORMS_SUPPORTED
  157970. LOCAL(void)
  157971. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  157972. jvirt_barray_ptr *src_coef_arrays)
  157973. {
  157974. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  157975. int ci, k, offset_y;
  157976. JBLOCKARRAY buffer;
  157977. JCOEFPTR ptr1, ptr2;
  157978. JCOEF temp1, temp2;
  157979. jpeg_component_info *compptr;
  157980. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  157981. for (ci = 0; ci < dstinfo->num_components; ci++) {
  157982. compptr = dstinfo->comp_info + ci;
  157983. comp_width = MCU_cols * compptr->h_samp_factor;
  157984. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  157985. blk_y += compptr->v_samp_factor) {
  157986. buffer = (*srcinfo->mem->access_virt_barray)
  157987. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  157988. (JDIMENSION) compptr->v_samp_factor, TRUE);
  157989. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  157990. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  157991. ptr1 = buffer[offset_y][blk_x];
  157992. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  157993. for (k = 0; k < DCTSIZE2; k += 2) {
  157994. temp1 = *ptr1; /* swap even column */
  157995. temp2 = *ptr2;
  157996. *ptr1++ = temp2;
  157997. *ptr2++ = temp1;
  157998. temp1 = *ptr1; /* swap odd column with sign change */
  157999. temp2 = *ptr2;
  158000. *ptr1++ = -temp2;
  158001. *ptr2++ = -temp1;
  158002. }
  158003. }
  158004. }
  158005. }
  158006. }
  158007. }
  158008. LOCAL(void)
  158009. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158010. jvirt_barray_ptr *src_coef_arrays,
  158011. jvirt_barray_ptr *dst_coef_arrays)
  158012. {
  158013. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158014. int ci, i, j, offset_y;
  158015. JBLOCKARRAY src_buffer, dst_buffer;
  158016. JBLOCKROW src_row_ptr, dst_row_ptr;
  158017. JCOEFPTR src_ptr, dst_ptr;
  158018. jpeg_component_info *compptr;
  158019. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158020. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158021. compptr = dstinfo->comp_info + ci;
  158022. comp_height = MCU_rows * compptr->v_samp_factor;
  158023. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158024. dst_blk_y += compptr->v_samp_factor) {
  158025. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158026. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158027. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158028. if (dst_blk_y < comp_height) {
  158029. src_buffer = (*srcinfo->mem->access_virt_barray)
  158030. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158031. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158032. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158033. } else {
  158034. src_buffer = (*srcinfo->mem->access_virt_barray)
  158035. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158036. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158037. }
  158038. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158039. if (dst_blk_y < comp_height) {
  158040. dst_row_ptr = dst_buffer[offset_y];
  158041. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158042. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158043. dst_blk_x++) {
  158044. dst_ptr = dst_row_ptr[dst_blk_x];
  158045. src_ptr = src_row_ptr[dst_blk_x];
  158046. for (i = 0; i < DCTSIZE; i += 2) {
  158047. for (j = 0; j < DCTSIZE; j++)
  158048. *dst_ptr++ = *src_ptr++;
  158049. for (j = 0; j < DCTSIZE; j++)
  158050. *dst_ptr++ = - *src_ptr++;
  158051. }
  158052. }
  158053. } else {
  158054. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158055. compptr->width_in_blocks);
  158056. }
  158057. }
  158058. }
  158059. }
  158060. }
  158061. LOCAL(void)
  158062. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158063. jvirt_barray_ptr *src_coef_arrays,
  158064. jvirt_barray_ptr *dst_coef_arrays)
  158065. {
  158066. JDIMENSION dst_blk_x, dst_blk_y;
  158067. int ci, i, j, offset_x, offset_y;
  158068. JBLOCKARRAY src_buffer, dst_buffer;
  158069. JCOEFPTR src_ptr, dst_ptr;
  158070. jpeg_component_info *compptr;
  158071. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158072. compptr = dstinfo->comp_info + ci;
  158073. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158074. dst_blk_y += compptr->v_samp_factor) {
  158075. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158076. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158077. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158078. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158079. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158080. dst_blk_x += compptr->h_samp_factor) {
  158081. src_buffer = (*srcinfo->mem->access_virt_barray)
  158082. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158083. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158084. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158085. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158086. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158087. for (i = 0; i < DCTSIZE; i++)
  158088. for (j = 0; j < DCTSIZE; j++)
  158089. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158090. }
  158091. }
  158092. }
  158093. }
  158094. }
  158095. }
  158096. LOCAL(void)
  158097. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158098. jvirt_barray_ptr *src_coef_arrays,
  158099. jvirt_barray_ptr *dst_coef_arrays)
  158100. {
  158101. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158102. int ci, i, j, offset_x, offset_y;
  158103. JBLOCKARRAY src_buffer, dst_buffer;
  158104. JCOEFPTR src_ptr, dst_ptr;
  158105. jpeg_component_info *compptr;
  158106. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158107. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158108. compptr = dstinfo->comp_info + ci;
  158109. comp_width = MCU_cols * compptr->h_samp_factor;
  158110. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158111. dst_blk_y += compptr->v_samp_factor) {
  158112. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158113. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158114. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158115. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158116. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158117. dst_blk_x += compptr->h_samp_factor) {
  158118. src_buffer = (*srcinfo->mem->access_virt_barray)
  158119. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158120. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158121. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158122. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158123. if (dst_blk_x < comp_width) {
  158124. dst_ptr = dst_buffer[offset_y]
  158125. [comp_width - dst_blk_x - offset_x - 1];
  158126. for (i = 0; i < DCTSIZE; i++) {
  158127. for (j = 0; j < DCTSIZE; j++)
  158128. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158129. i++;
  158130. for (j = 0; j < DCTSIZE; j++)
  158131. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158132. }
  158133. } else {
  158134. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158135. for (i = 0; i < DCTSIZE; i++)
  158136. for (j = 0; j < DCTSIZE; j++)
  158137. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158138. }
  158139. }
  158140. }
  158141. }
  158142. }
  158143. }
  158144. }
  158145. LOCAL(void)
  158146. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158147. jvirt_barray_ptr *src_coef_arrays,
  158148. jvirt_barray_ptr *dst_coef_arrays)
  158149. {
  158150. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158151. int ci, i, j, offset_x, offset_y;
  158152. JBLOCKARRAY src_buffer, dst_buffer;
  158153. JCOEFPTR src_ptr, dst_ptr;
  158154. jpeg_component_info *compptr;
  158155. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158156. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158157. compptr = dstinfo->comp_info + ci;
  158158. comp_height = MCU_rows * compptr->v_samp_factor;
  158159. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158160. dst_blk_y += compptr->v_samp_factor) {
  158161. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158162. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158163. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158164. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158165. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158166. dst_blk_x += compptr->h_samp_factor) {
  158167. src_buffer = (*srcinfo->mem->access_virt_barray)
  158168. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158169. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158170. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158171. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158172. if (dst_blk_y < comp_height) {
  158173. src_ptr = src_buffer[offset_x]
  158174. [comp_height - dst_blk_y - offset_y - 1];
  158175. for (i = 0; i < DCTSIZE; i++) {
  158176. for (j = 0; j < DCTSIZE; j++) {
  158177. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158178. j++;
  158179. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158180. }
  158181. }
  158182. } else {
  158183. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158184. for (i = 0; i < DCTSIZE; i++)
  158185. for (j = 0; j < DCTSIZE; j++)
  158186. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158187. }
  158188. }
  158189. }
  158190. }
  158191. }
  158192. }
  158193. }
  158194. LOCAL(void)
  158195. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158196. jvirt_barray_ptr *src_coef_arrays,
  158197. jvirt_barray_ptr *dst_coef_arrays)
  158198. {
  158199. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158200. int ci, i, j, offset_y;
  158201. JBLOCKARRAY src_buffer, dst_buffer;
  158202. JBLOCKROW src_row_ptr, dst_row_ptr;
  158203. JCOEFPTR src_ptr, dst_ptr;
  158204. jpeg_component_info *compptr;
  158205. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158206. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158207. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158208. compptr = dstinfo->comp_info + ci;
  158209. comp_width = MCU_cols * compptr->h_samp_factor;
  158210. comp_height = MCU_rows * compptr->v_samp_factor;
  158211. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158212. dst_blk_y += compptr->v_samp_factor) {
  158213. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158214. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158215. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158216. if (dst_blk_y < comp_height) {
  158217. src_buffer = (*srcinfo->mem->access_virt_barray)
  158218. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158219. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158220. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158221. } else {
  158222. src_buffer = (*srcinfo->mem->access_virt_barray)
  158223. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158224. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158225. }
  158226. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158227. if (dst_blk_y < comp_height) {
  158228. dst_row_ptr = dst_buffer[offset_y];
  158229. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158230. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158231. dst_ptr = dst_row_ptr[dst_blk_x];
  158232. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158233. for (i = 0; i < DCTSIZE; i += 2) {
  158234. for (j = 0; j < DCTSIZE; j += 2) {
  158235. *dst_ptr++ = *src_ptr++;
  158236. *dst_ptr++ = - *src_ptr++;
  158237. }
  158238. for (j = 0; j < DCTSIZE; j += 2) {
  158239. *dst_ptr++ = - *src_ptr++;
  158240. *dst_ptr++ = *src_ptr++;
  158241. }
  158242. }
  158243. }
  158244. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158245. dst_ptr = dst_row_ptr[dst_blk_x];
  158246. src_ptr = src_row_ptr[dst_blk_x];
  158247. for (i = 0; i < DCTSIZE; i += 2) {
  158248. for (j = 0; j < DCTSIZE; j++)
  158249. *dst_ptr++ = *src_ptr++;
  158250. for (j = 0; j < DCTSIZE; j++)
  158251. *dst_ptr++ = - *src_ptr++;
  158252. }
  158253. }
  158254. } else {
  158255. dst_row_ptr = dst_buffer[offset_y];
  158256. src_row_ptr = src_buffer[offset_y];
  158257. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158258. dst_ptr = dst_row_ptr[dst_blk_x];
  158259. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158260. for (i = 0; i < DCTSIZE2; i += 2) {
  158261. *dst_ptr++ = *src_ptr++;
  158262. *dst_ptr++ = - *src_ptr++;
  158263. }
  158264. }
  158265. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158266. dst_ptr = dst_row_ptr[dst_blk_x];
  158267. src_ptr = src_row_ptr[dst_blk_x];
  158268. for (i = 0; i < DCTSIZE2; i++)
  158269. *dst_ptr++ = *src_ptr++;
  158270. }
  158271. }
  158272. }
  158273. }
  158274. }
  158275. }
  158276. LOCAL(void)
  158277. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158278. jvirt_barray_ptr *src_coef_arrays,
  158279. jvirt_barray_ptr *dst_coef_arrays)
  158280. {
  158281. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158282. int ci, i, j, offset_x, offset_y;
  158283. JBLOCKARRAY src_buffer, dst_buffer;
  158284. JCOEFPTR src_ptr, dst_ptr;
  158285. jpeg_component_info *compptr;
  158286. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158287. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158288. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158289. compptr = dstinfo->comp_info + ci;
  158290. comp_width = MCU_cols * compptr->h_samp_factor;
  158291. comp_height = MCU_rows * compptr->v_samp_factor;
  158292. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158293. dst_blk_y += compptr->v_samp_factor) {
  158294. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158295. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158296. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158297. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158298. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158299. dst_blk_x += compptr->h_samp_factor) {
  158300. src_buffer = (*srcinfo->mem->access_virt_barray)
  158301. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158302. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158303. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158304. if (dst_blk_y < comp_height) {
  158305. src_ptr = src_buffer[offset_x]
  158306. [comp_height - dst_blk_y - offset_y - 1];
  158307. if (dst_blk_x < comp_width) {
  158308. dst_ptr = dst_buffer[offset_y]
  158309. [comp_width - dst_blk_x - offset_x - 1];
  158310. for (i = 0; i < DCTSIZE; i++) {
  158311. for (j = 0; j < DCTSIZE; j++) {
  158312. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158313. j++;
  158314. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158315. }
  158316. i++;
  158317. for (j = 0; j < DCTSIZE; j++) {
  158318. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158319. j++;
  158320. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158321. }
  158322. }
  158323. } else {
  158324. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158325. for (i = 0; i < DCTSIZE; i++) {
  158326. for (j = 0; j < DCTSIZE; j++) {
  158327. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158328. j++;
  158329. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158330. }
  158331. }
  158332. }
  158333. } else {
  158334. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158335. if (dst_blk_x < comp_width) {
  158336. dst_ptr = dst_buffer[offset_y]
  158337. [comp_width - dst_blk_x - offset_x - 1];
  158338. for (i = 0; i < DCTSIZE; i++) {
  158339. for (j = 0; j < DCTSIZE; j++)
  158340. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158341. i++;
  158342. for (j = 0; j < DCTSIZE; j++)
  158343. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158344. }
  158345. } else {
  158346. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158347. for (i = 0; i < DCTSIZE; i++)
  158348. for (j = 0; j < DCTSIZE; j++)
  158349. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158350. }
  158351. }
  158352. }
  158353. }
  158354. }
  158355. }
  158356. }
  158357. }
  158358. GLOBAL(void)
  158359. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158360. jpeg_transform_info *info)
  158361. {
  158362. jvirt_barray_ptr *coef_arrays = NULL;
  158363. jpeg_component_info *compptr;
  158364. int ci;
  158365. if (info->force_grayscale &&
  158366. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158367. srcinfo->num_components == 3) {
  158368. info->num_components = 1;
  158369. } else {
  158370. info->num_components = srcinfo->num_components;
  158371. }
  158372. switch (info->transform) {
  158373. case JXFORM_NONE:
  158374. case JXFORM_FLIP_H:
  158375. break;
  158376. case JXFORM_FLIP_V:
  158377. case JXFORM_ROT_180:
  158378. coef_arrays = (jvirt_barray_ptr *)
  158379. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158380. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158381. for (ci = 0; ci < info->num_components; ci++) {
  158382. compptr = srcinfo->comp_info + ci;
  158383. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158384. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158385. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158386. (long) compptr->h_samp_factor),
  158387. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158388. (long) compptr->v_samp_factor),
  158389. (JDIMENSION) compptr->v_samp_factor);
  158390. }
  158391. break;
  158392. case JXFORM_TRANSPOSE:
  158393. case JXFORM_TRANSVERSE:
  158394. case JXFORM_ROT_90:
  158395. case JXFORM_ROT_270:
  158396. coef_arrays = (jvirt_barray_ptr *)
  158397. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158398. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158399. for (ci = 0; ci < info->num_components; ci++) {
  158400. compptr = srcinfo->comp_info + ci;
  158401. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158402. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158403. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158404. (long) compptr->v_samp_factor),
  158405. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158406. (long) compptr->h_samp_factor),
  158407. (JDIMENSION) compptr->h_samp_factor);
  158408. }
  158409. break;
  158410. }
  158411. info->workspace_coef_arrays = coef_arrays;
  158412. }
  158413. LOCAL(void)
  158414. transpose_critical_parameters (j_compress_ptr dstinfo)
  158415. {
  158416. int tblno, i, j, ci, itemp;
  158417. jpeg_component_info *compptr;
  158418. JQUANT_TBL *qtblptr;
  158419. JDIMENSION dtemp;
  158420. UINT16 qtemp;
  158421. dtemp = dstinfo->image_width;
  158422. dstinfo->image_width = dstinfo->image_height;
  158423. dstinfo->image_height = dtemp;
  158424. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158425. compptr = dstinfo->comp_info + ci;
  158426. itemp = compptr->h_samp_factor;
  158427. compptr->h_samp_factor = compptr->v_samp_factor;
  158428. compptr->v_samp_factor = itemp;
  158429. }
  158430. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158431. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158432. if (qtblptr != NULL) {
  158433. for (i = 0; i < DCTSIZE; i++) {
  158434. for (j = 0; j < i; j++) {
  158435. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158436. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158437. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158438. }
  158439. }
  158440. }
  158441. }
  158442. }
  158443. LOCAL(void)
  158444. trim_right_edge (j_compress_ptr dstinfo)
  158445. {
  158446. int ci, max_h_samp_factor;
  158447. JDIMENSION MCU_cols;
  158448. max_h_samp_factor = 1;
  158449. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158450. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158451. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158452. }
  158453. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158454. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158455. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158456. }
  158457. LOCAL(void)
  158458. trim_bottom_edge (j_compress_ptr dstinfo)
  158459. {
  158460. int ci, max_v_samp_factor;
  158461. JDIMENSION MCU_rows;
  158462. max_v_samp_factor = 1;
  158463. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158464. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158465. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158466. }
  158467. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158468. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158469. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158470. }
  158471. GLOBAL(jvirt_barray_ptr *)
  158472. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158473. j_compress_ptr dstinfo,
  158474. jvirt_barray_ptr *src_coef_arrays,
  158475. jpeg_transform_info *info)
  158476. {
  158477. if (info->force_grayscale) {
  158478. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158479. dstinfo->num_components == 3) ||
  158480. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158481. dstinfo->num_components == 1)) {
  158482. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158483. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158484. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158485. } else {
  158486. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158487. }
  158488. }
  158489. switch (info->transform) {
  158490. case JXFORM_NONE:
  158491. break;
  158492. case JXFORM_FLIP_H:
  158493. if (info->trim)
  158494. trim_right_edge(dstinfo);
  158495. break;
  158496. case JXFORM_FLIP_V:
  158497. if (info->trim)
  158498. trim_bottom_edge(dstinfo);
  158499. break;
  158500. case JXFORM_TRANSPOSE:
  158501. transpose_critical_parameters(dstinfo);
  158502. break;
  158503. case JXFORM_TRANSVERSE:
  158504. transpose_critical_parameters(dstinfo);
  158505. if (info->trim) {
  158506. trim_right_edge(dstinfo);
  158507. trim_bottom_edge(dstinfo);
  158508. }
  158509. break;
  158510. case JXFORM_ROT_90:
  158511. transpose_critical_parameters(dstinfo);
  158512. if (info->trim)
  158513. trim_right_edge(dstinfo);
  158514. break;
  158515. case JXFORM_ROT_180:
  158516. if (info->trim) {
  158517. trim_right_edge(dstinfo);
  158518. trim_bottom_edge(dstinfo);
  158519. }
  158520. break;
  158521. case JXFORM_ROT_270:
  158522. transpose_critical_parameters(dstinfo);
  158523. if (info->trim)
  158524. trim_bottom_edge(dstinfo);
  158525. break;
  158526. }
  158527. if (info->workspace_coef_arrays != NULL)
  158528. return info->workspace_coef_arrays;
  158529. return src_coef_arrays;
  158530. }
  158531. GLOBAL(void)
  158532. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158533. j_compress_ptr dstinfo,
  158534. jvirt_barray_ptr *src_coef_arrays,
  158535. jpeg_transform_info *info)
  158536. {
  158537. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158538. switch (info->transform) {
  158539. case JXFORM_NONE:
  158540. break;
  158541. case JXFORM_FLIP_H:
  158542. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158543. break;
  158544. case JXFORM_FLIP_V:
  158545. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158546. break;
  158547. case JXFORM_TRANSPOSE:
  158548. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158549. break;
  158550. case JXFORM_TRANSVERSE:
  158551. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158552. break;
  158553. case JXFORM_ROT_90:
  158554. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158555. break;
  158556. case JXFORM_ROT_180:
  158557. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158558. break;
  158559. case JXFORM_ROT_270:
  158560. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158561. break;
  158562. }
  158563. }
  158564. #endif /* TRANSFORMS_SUPPORTED */
  158565. GLOBAL(void)
  158566. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158567. {
  158568. #ifdef SAVE_MARKERS_SUPPORTED
  158569. int m;
  158570. if (option != JCOPYOPT_NONE) {
  158571. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158572. }
  158573. if (option == JCOPYOPT_ALL) {
  158574. for (m = 0; m < 16; m++)
  158575. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158576. }
  158577. #endif /* SAVE_MARKERS_SUPPORTED */
  158578. }
  158579. GLOBAL(void)
  158580. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158581. JCOPY_OPTION option)
  158582. {
  158583. jpeg_saved_marker_ptr marker;
  158584. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158585. if (dstinfo->write_JFIF_header &&
  158586. marker->marker == JPEG_APP0 &&
  158587. marker->data_length >= 5 &&
  158588. GETJOCTET(marker->data[0]) == 0x4A &&
  158589. GETJOCTET(marker->data[1]) == 0x46 &&
  158590. GETJOCTET(marker->data[2]) == 0x49 &&
  158591. GETJOCTET(marker->data[3]) == 0x46 &&
  158592. GETJOCTET(marker->data[4]) == 0)
  158593. continue; /* reject duplicate JFIF */
  158594. if (dstinfo->write_Adobe_marker &&
  158595. marker->marker == JPEG_APP0+14 &&
  158596. marker->data_length >= 5 &&
  158597. GETJOCTET(marker->data[0]) == 0x41 &&
  158598. GETJOCTET(marker->data[1]) == 0x64 &&
  158599. GETJOCTET(marker->data[2]) == 0x6F &&
  158600. GETJOCTET(marker->data[3]) == 0x62 &&
  158601. GETJOCTET(marker->data[4]) == 0x65)
  158602. continue; /* reject duplicate Adobe */
  158603. #ifdef NEED_FAR_POINTERS
  158604. {
  158605. unsigned int i;
  158606. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158607. for (i = 0; i < marker->data_length; i++)
  158608. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158609. }
  158610. #else
  158611. jpeg_write_marker(dstinfo, marker->marker,
  158612. marker->data, marker->data_length);
  158613. #endif
  158614. }
  158615. }
  158616. /*** End of inlined file: transupp.c ***/
  158617. }
  158618. #else
  158619. #define JPEG_INTERNALS
  158620. #undef FAR
  158621. #include <jpeglib.h>
  158622. #endif
  158623. }
  158624. #undef max
  158625. #undef min
  158626. #if JUCE_MSVC
  158627. #pragma warning (pop)
  158628. #endif
  158629. BEGIN_JUCE_NAMESPACE
  158630. namespace JPEGHelpers
  158631. {
  158632. using namespace jpeglibNamespace;
  158633. #if ! JUCE_MSVC
  158634. using jpeglibNamespace::boolean;
  158635. #endif
  158636. struct JPEGDecodingFailure {};
  158637. static void fatalErrorHandler (j_common_ptr)
  158638. {
  158639. throw JPEGDecodingFailure();
  158640. }
  158641. static void silentErrorCallback1 (j_common_ptr) {}
  158642. static void silentErrorCallback2 (j_common_ptr, int) {}
  158643. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158644. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158645. {
  158646. zerostruct (err);
  158647. err.error_exit = fatalErrorHandler;
  158648. err.emit_message = silentErrorCallback2;
  158649. err.output_message = silentErrorCallback1;
  158650. err.format_message = silentErrorCallback3;
  158651. err.reset_error_mgr = silentErrorCallback1;
  158652. }
  158653. static void dummyCallback1 (j_decompress_ptr)
  158654. {
  158655. }
  158656. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158657. {
  158658. decompStruct->src->next_input_byte += num;
  158659. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158660. decompStruct->src->bytes_in_buffer -= num;
  158661. }
  158662. static boolean jpegFill (j_decompress_ptr)
  158663. {
  158664. return 0;
  158665. }
  158666. static const int jpegBufferSize = 512;
  158667. struct JuceJpegDest : public jpeg_destination_mgr
  158668. {
  158669. OutputStream* output;
  158670. char* buffer;
  158671. };
  158672. static void jpegWriteInit (j_compress_ptr)
  158673. {
  158674. }
  158675. static void jpegWriteTerminate (j_compress_ptr cinfo)
  158676. {
  158677. JuceJpegDest* const dest = static_cast <JuceJpegDest*> (cinfo->dest);
  158678. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  158679. dest->output->write (dest->buffer, (int) numToWrite);
  158680. }
  158681. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  158682. {
  158683. JuceJpegDest* const dest = static_cast <JuceJpegDest*> (cinfo->dest);
  158684. const int numToWrite = jpegBufferSize;
  158685. dest->next_output_byte = reinterpret_cast <JOCTET*> (dest->buffer);
  158686. dest->free_in_buffer = jpegBufferSize;
  158687. return dest->output->write (dest->buffer, numToWrite);
  158688. }
  158689. }
  158690. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158691. {
  158692. using namespace jpeglibNamespace;
  158693. using namespace JPEGHelpers;
  158694. MemoryBlock mb;
  158695. in.readIntoMemoryBlock (mb);
  158696. Image* image = 0;
  158697. if (mb.getSize() > 16)
  158698. {
  158699. struct jpeg_decompress_struct jpegDecompStruct;
  158700. struct jpeg_error_mgr jerr;
  158701. setupSilentErrorHandler (jerr);
  158702. jpegDecompStruct.err = &jerr;
  158703. jpeg_create_decompress (&jpegDecompStruct);
  158704. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158705. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158706. jpegDecompStruct.src->init_source = dummyCallback1;
  158707. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158708. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158709. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158710. jpegDecompStruct.src->term_source = dummyCallback1;
  158711. jpegDecompStruct.src->next_input_byte = static_cast <const unsigned char*> (mb.getData());
  158712. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158713. try
  158714. {
  158715. jpeg_read_header (&jpegDecompStruct, TRUE);
  158716. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158717. const int width = jpegDecompStruct.output_width;
  158718. const int height = jpegDecompStruct.output_height;
  158719. jpegDecompStruct.out_color_space = JCS_RGB;
  158720. JSAMPARRAY buffer
  158721. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158722. JPOOL_IMAGE,
  158723. width * 3, 1);
  158724. if (jpeg_start_decompress (&jpegDecompStruct))
  158725. {
  158726. image = Image::createNativeImage (Image::RGB, width, height, false);
  158727. const bool hasAlphaChan = image->hasAlphaChannel();
  158728. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  158729. for (int y = 0; y < height; ++y)
  158730. {
  158731. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  158732. const uint8* src = *buffer;
  158733. uint8* dest = destData.getLinePointer (y);
  158734. if (hasAlphaChan)
  158735. {
  158736. for (int i = width; --i >= 0;)
  158737. {
  158738. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158739. ((PixelARGB*) dest)->premultiply();
  158740. dest += destData.pixelStride;
  158741. src += 3;
  158742. }
  158743. }
  158744. else
  158745. {
  158746. for (int i = width; --i >= 0;)
  158747. {
  158748. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158749. dest += destData.pixelStride;
  158750. src += 3;
  158751. }
  158752. }
  158753. }
  158754. jpeg_finish_decompress (&jpegDecompStruct);
  158755. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  158756. }
  158757. jpeg_destroy_decompress (&jpegDecompStruct);
  158758. }
  158759. catch (...)
  158760. {}
  158761. }
  158762. return image;
  158763. }
  158764. bool juce_writeJPEGImageToStream (const Image& image,
  158765. OutputStream& out,
  158766. float quality)
  158767. {
  158768. using namespace jpeglibNamespace;
  158769. using namespace JPEGHelpers;
  158770. if (image.hasAlphaChannel())
  158771. {
  158772. // this method could fill the background in white and still save the image..
  158773. jassertfalse
  158774. return true;
  158775. }
  158776. struct jpeg_compress_struct jpegCompStruct;
  158777. struct jpeg_error_mgr jerr;
  158778. setupSilentErrorHandler (jerr);
  158779. jpegCompStruct.err = &jerr;
  158780. jpeg_create_compress (&jpegCompStruct);
  158781. JuceJpegDest dest;
  158782. jpegCompStruct.dest = &dest;
  158783. dest.output = &out;
  158784. HeapBlock <char> tempBuffer (jpegBufferSize);
  158785. dest.buffer = tempBuffer;
  158786. dest.next_output_byte = (JOCTET*) dest.buffer;
  158787. dest.free_in_buffer = jpegBufferSize;
  158788. dest.init_destination = jpegWriteInit;
  158789. dest.empty_output_buffer = jpegWriteFlush;
  158790. dest.term_destination = jpegWriteTerminate;
  158791. jpegCompStruct.image_width = image.getWidth();
  158792. jpegCompStruct.image_height = image.getHeight();
  158793. jpegCompStruct.input_components = 3;
  158794. jpegCompStruct.in_color_space = JCS_RGB;
  158795. jpegCompStruct.write_JFIF_header = 1;
  158796. jpegCompStruct.X_density = 72;
  158797. jpegCompStruct.Y_density = 72;
  158798. jpeg_set_defaults (&jpegCompStruct);
  158799. jpegCompStruct.dct_method = JDCT_FLOAT;
  158800. jpegCompStruct.optimize_coding = 1;
  158801. //jpegCompStruct.smoothing_factor = 10;
  158802. if (quality < 0.0f)
  158803. quality = 0.85f;
  158804. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  158805. jpeg_start_compress (&jpegCompStruct, TRUE);
  158806. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  158807. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  158808. JPOOL_IMAGE, strideBytes, 1);
  158809. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  158810. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  158811. {
  158812. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  158813. uint8* dst = *buffer;
  158814. for (int i = jpegCompStruct.image_width; --i >= 0;)
  158815. {
  158816. *dst++ = ((const PixelRGB*) src)->getRed();
  158817. *dst++ = ((const PixelRGB*) src)->getGreen();
  158818. *dst++ = ((const PixelRGB*) src)->getBlue();
  158819. src += srcData.pixelStride;
  158820. }
  158821. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  158822. }
  158823. jpeg_finish_compress (&jpegCompStruct);
  158824. jpeg_destroy_compress (&jpegCompStruct);
  158825. out.flush();
  158826. return true;
  158827. }
  158828. END_JUCE_NAMESPACE
  158829. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  158830. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  158831. #ifdef _MSC_VER
  158832. #pragma warning (push)
  158833. #pragma warning (disable: 4390 4611)
  158834. #endif
  158835. namespace zlibNamespace
  158836. {
  158837. #if JUCE_INCLUDE_ZLIB_CODE
  158838. #undef OS_CODE
  158839. #undef fdopen
  158840. #undef OS_CODE
  158841. #else
  158842. #include <zlib.h>
  158843. #endif
  158844. }
  158845. namespace pnglibNamespace
  158846. {
  158847. using namespace zlibNamespace;
  158848. #if JUCE_INCLUDE_PNGLIB_CODE
  158849. #if _MSC_VER != 1310
  158850. using ::calloc; // (causes conflict in VS.NET 2003)
  158851. using ::malloc;
  158852. using ::free;
  158853. #endif
  158854. extern "C"
  158855. {
  158856. using ::abs;
  158857. #define PNG_INTERNAL
  158858. #define NO_DUMMY_DECL
  158859. #define PNG_SETJMP_NOT_SUPPORTED
  158860. /*** Start of inlined file: png.h ***/
  158861. #ifndef PNG_H
  158862. #define PNG_H
  158863. #define PNG_LIBPNG_VER_STRING "1.2.21"
  158864. #define PNG_HEADER_VERSION_STRING \
  158865. " libpng version 1.2.21 - October 4, 2007\n"
  158866. #define PNG_LIBPNG_VER_SONUM 0
  158867. #define PNG_LIBPNG_VER_DLLNUM 13
  158868. #define PNG_LIBPNG_VER_MAJOR 1
  158869. #define PNG_LIBPNG_VER_MINOR 2
  158870. #define PNG_LIBPNG_VER_RELEASE 21
  158871. #define PNG_LIBPNG_VER_BUILD 0
  158872. #define PNG_LIBPNG_BUILD_ALPHA 1
  158873. #define PNG_LIBPNG_BUILD_BETA 2
  158874. #define PNG_LIBPNG_BUILD_RC 3
  158875. #define PNG_LIBPNG_BUILD_STABLE 4
  158876. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  158877. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  158878. PNG_LIBPNG_BUILD_STABLE only */
  158879. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  158880. PNG_LIBPNG_BUILD_SPECIAL */
  158881. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  158882. PNG_LIBPNG_BUILD_PRIVATE */
  158883. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  158884. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  158885. #ifndef PNG_VERSION_INFO_ONLY
  158886. #endif
  158887. /*** Start of inlined file: pngconf.h ***/
  158888. #ifndef PNGCONF_H
  158889. #define PNGCONF_H
  158890. #define PNG_1_2_X
  158891. // These are some Juce config settings that should remove any unnecessary code bloat..
  158892. #define PNG_NO_STDIO 1
  158893. #define PNG_DEBUG 0
  158894. #define PNG_NO_WARNINGS 1
  158895. #define PNG_NO_ERROR_TEXT 1
  158896. #define PNG_NO_ERROR_NUMBERS 1
  158897. #define PNG_NO_USER_MEM 1
  158898. #define PNG_NO_READ_iCCP 1
  158899. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  158900. #define PNG_NO_READ_USER_CHUNKS 1
  158901. #define PNG_NO_READ_iTXt 1
  158902. #define PNG_NO_READ_sCAL 1
  158903. #define PNG_NO_READ_sPLT 1
  158904. #define png_error(a, b) png_err(a)
  158905. #define png_warning(a, b)
  158906. #define png_chunk_error(a, b) png_err(a)
  158907. #define png_chunk_warning(a, b)
  158908. #ifdef PNG_USER_CONFIG
  158909. # ifndef PNG_USER_PRIVATEBUILD
  158910. # define PNG_USER_PRIVATEBUILD
  158911. # endif
  158912. #include "pngusr.h"
  158913. #endif
  158914. #ifdef PNG_CONFIGURE_LIBPNG
  158915. #ifdef HAVE_CONFIG_H
  158916. #include "config.h"
  158917. #endif
  158918. #endif
  158919. #ifdef __STDC__
  158920. #ifdef SPECIALBUILD
  158921. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  158922. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  158923. #endif
  158924. #ifdef PRIVATEBUILD
  158925. # pragma message("PRIVATEBUILD is deprecated.\
  158926. Use PNG_USER_PRIVATEBUILD instead.")
  158927. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  158928. #endif
  158929. #endif /* __STDC__ */
  158930. #ifndef PNG_VERSION_INFO_ONLY
  158931. # define PNG_WARN_UNINITIALIZED_ROW 1
  158932. #ifndef PNG_ZBUF_SIZE
  158933. # define PNG_ZBUF_SIZE 8192
  158934. #endif
  158935. #ifndef PNG_NO_READ_SUPPORTED
  158936. # define PNG_READ_SUPPORTED
  158937. #endif
  158938. #ifndef PNG_NO_WRITE_SUPPORTED
  158939. # define PNG_WRITE_SUPPORTED
  158940. #endif
  158941. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  158942. # ifndef PNG_MNG_FEATURES_SUPPORTED
  158943. # define PNG_MNG_FEATURES_SUPPORTED
  158944. # endif
  158945. #endif
  158946. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  158947. # ifndef PNG_FLOATING_POINT_SUPPORTED
  158948. # define PNG_FLOATING_POINT_SUPPORTED
  158949. # endif
  158950. #endif
  158951. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  158952. # define PNG_MAX_MALLOC_64K
  158953. #endif
  158954. #if defined(__CYGWIN__)
  158955. # if defined(ALL_STATIC)
  158956. # if defined(PNG_BUILD_DLL)
  158957. # undef PNG_BUILD_DLL
  158958. # endif
  158959. # if defined(PNG_USE_DLL)
  158960. # undef PNG_USE_DLL
  158961. # endif
  158962. # if defined(PNG_DLL)
  158963. # undef PNG_DLL
  158964. # endif
  158965. # if !defined(PNG_STATIC)
  158966. # define PNG_STATIC
  158967. # endif
  158968. # else
  158969. # if defined (PNG_BUILD_DLL)
  158970. # if defined(PNG_STATIC)
  158971. # undef PNG_STATIC
  158972. # endif
  158973. # if defined(PNG_USE_DLL)
  158974. # undef PNG_USE_DLL
  158975. # endif
  158976. # if !defined(PNG_DLL)
  158977. # define PNG_DLL
  158978. # endif
  158979. # else
  158980. # if defined(PNG_STATIC)
  158981. # if defined(PNG_USE_DLL)
  158982. # undef PNG_USE_DLL
  158983. # endif
  158984. # if defined(PNG_DLL)
  158985. # undef PNG_DLL
  158986. # endif
  158987. # else
  158988. # if !defined(PNG_USE_DLL)
  158989. # define PNG_USE_DLL
  158990. # endif
  158991. # if !defined(PNG_DLL)
  158992. # define PNG_DLL
  158993. # endif
  158994. # endif
  158995. # endif
  158996. # endif
  158997. #endif
  158998. #if defined(_WIN32_WCE)
  158999. # include <windows.h>
  159000. # define PNG_NO_CONSOLE_IO
  159001. # ifdef PNG_DEBUG
  159002. # undef PNG_DEBUG
  159003. # endif
  159004. #endif
  159005. #ifdef PNG_BUILD_DLL
  159006. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159007. # ifndef PNG_NO_CONSOLE_IO
  159008. # define PNG_NO_CONSOLE_IO
  159009. # endif
  159010. # endif
  159011. #endif
  159012. # ifdef PNG_NO_STDIO
  159013. # ifndef PNG_NO_CONSOLE_IO
  159014. # define PNG_NO_CONSOLE_IO
  159015. # endif
  159016. # ifdef PNG_DEBUG
  159017. # if (PNG_DEBUG > 0)
  159018. # include <stdio.h>
  159019. # endif
  159020. # endif
  159021. # else
  159022. # if !defined(_WIN32_WCE)
  159023. # include <stdio.h>
  159024. # endif
  159025. # endif
  159026. #ifndef PNGARG
  159027. #ifdef OF /* zlib prototype munger */
  159028. # define PNGARG(arglist) OF(arglist)
  159029. #else
  159030. #ifdef _NO_PROTO
  159031. # define PNGARG(arglist) ()
  159032. # ifndef PNG_TYPECAST_NULL
  159033. # define PNG_TYPECAST_NULL
  159034. # endif
  159035. #else
  159036. # define PNGARG(arglist) arglist
  159037. #endif /* _NO_PROTO */
  159038. #endif /* OF */
  159039. #endif /* PNGARG */
  159040. #ifndef MACOS
  159041. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159042. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159043. # define MACOS
  159044. # endif
  159045. #endif
  159046. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159047. # include <sys/types.h>
  159048. #endif
  159049. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159050. # define PNG_SETJMP_SUPPORTED
  159051. #endif
  159052. #ifdef PNG_SETJMP_SUPPORTED
  159053. # ifdef __linux__
  159054. # ifdef _BSD_SOURCE
  159055. # define PNG_SAVE_BSD_SOURCE
  159056. # undef _BSD_SOURCE
  159057. # endif
  159058. # ifdef _SETJMP_H
  159059. __png.h__ already includes setjmp.h;
  159060. __dont__ include it again.;
  159061. # endif
  159062. # endif /* __linux__ */
  159063. # include <setjmp.h>
  159064. # ifdef __linux__
  159065. # ifdef PNG_SAVE_BSD_SOURCE
  159066. # define _BSD_SOURCE
  159067. # undef PNG_SAVE_BSD_SOURCE
  159068. # endif
  159069. # endif /* __linux__ */
  159070. #endif /* PNG_SETJMP_SUPPORTED */
  159071. #ifdef BSD
  159072. #if ! JUCE_MAC
  159073. # include <strings.h>
  159074. #endif
  159075. #else
  159076. # include <string.h>
  159077. #endif
  159078. #ifdef PNG_INTERNAL
  159079. #include <stdlib.h>
  159080. #define PNG_EXTERN
  159081. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159082. # if defined(MACOS)
  159083. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159084. # include <fp.h>
  159085. # endif
  159086. # else
  159087. # include <math.h>
  159088. # endif
  159089. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159090. # include <m68881.h>
  159091. # endif
  159092. #endif
  159093. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159094. # define PNG_ALWAYS_EXTERN
  159095. #endif
  159096. #if defined(__TURBOC__) && defined(__MSDOS__)
  159097. # include <mem.h>
  159098. # include <alloc.h>
  159099. #endif
  159100. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159101. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159102. # include <malloc.h>
  159103. #endif
  159104. #ifndef PNG_DITHER_RED_BITS
  159105. # define PNG_DITHER_RED_BITS 5
  159106. #endif
  159107. #ifndef PNG_DITHER_GREEN_BITS
  159108. # define PNG_DITHER_GREEN_BITS 5
  159109. #endif
  159110. #ifndef PNG_DITHER_BLUE_BITS
  159111. # define PNG_DITHER_BLUE_BITS 5
  159112. #endif
  159113. #ifndef PNG_MAX_GAMMA_8
  159114. # define PNG_MAX_GAMMA_8 11
  159115. #endif
  159116. #ifndef PNG_GAMMA_THRESHOLD
  159117. # define PNG_GAMMA_THRESHOLD 0.05
  159118. #endif
  159119. #endif /* PNG_INTERNAL */
  159120. #ifndef PNG_NO_CONST
  159121. # define PNG_CONST const
  159122. #else
  159123. # define PNG_CONST
  159124. #endif
  159125. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159126. # ifndef PNG_NO_iTXt_SUPPORTED
  159127. # define PNG_NO_iTXt_SUPPORTED
  159128. # endif
  159129. # ifndef PNG_NO_READ_iTXt
  159130. # define PNG_NO_READ_iTXt
  159131. # endif
  159132. # ifndef PNG_NO_WRITE_iTXt
  159133. # define PNG_NO_WRITE_iTXt
  159134. # endif
  159135. #endif
  159136. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159137. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159138. # define PNG_READ_iTXt
  159139. # endif
  159140. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159141. # define PNG_WRITE_iTXt
  159142. # endif
  159143. #endif
  159144. #ifdef PNG_LEGACY_SUPPORTED
  159145. # define PNG_NO_FREE_ME
  159146. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159147. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159148. # define PNG_NO_READ_USER_CHUNKS
  159149. # define PNG_NO_READ_iCCP
  159150. # define PNG_NO_WRITE_iCCP
  159151. # define PNG_NO_READ_iTXt
  159152. # define PNG_NO_WRITE_iTXt
  159153. # define PNG_NO_READ_sCAL
  159154. # define PNG_NO_WRITE_sCAL
  159155. # define PNG_NO_READ_sPLT
  159156. # define PNG_NO_WRITE_sPLT
  159157. # define PNG_NO_INFO_IMAGE
  159158. # define PNG_NO_READ_RGB_TO_GRAY
  159159. # define PNG_NO_READ_USER_TRANSFORM
  159160. # define PNG_NO_WRITE_USER_TRANSFORM
  159161. # define PNG_NO_USER_MEM
  159162. # define PNG_NO_READ_EMPTY_PLTE
  159163. # define PNG_NO_MNG_FEATURES
  159164. # define PNG_NO_FIXED_POINT_SUPPORTED
  159165. #endif
  159166. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159167. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159168. # define PNG_FIXED_POINT_SUPPORTED
  159169. #endif
  159170. #ifndef PNG_NO_FREE_ME
  159171. # define PNG_FREE_ME_SUPPORTED
  159172. #endif
  159173. #if defined(PNG_READ_SUPPORTED)
  159174. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159175. !defined(PNG_NO_READ_TRANSFORMS)
  159176. # define PNG_READ_TRANSFORMS_SUPPORTED
  159177. #endif
  159178. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159179. # ifndef PNG_NO_READ_EXPAND
  159180. # define PNG_READ_EXPAND_SUPPORTED
  159181. # endif
  159182. # ifndef PNG_NO_READ_SHIFT
  159183. # define PNG_READ_SHIFT_SUPPORTED
  159184. # endif
  159185. # ifndef PNG_NO_READ_PACK
  159186. # define PNG_READ_PACK_SUPPORTED
  159187. # endif
  159188. # ifndef PNG_NO_READ_BGR
  159189. # define PNG_READ_BGR_SUPPORTED
  159190. # endif
  159191. # ifndef PNG_NO_READ_SWAP
  159192. # define PNG_READ_SWAP_SUPPORTED
  159193. # endif
  159194. # ifndef PNG_NO_READ_PACKSWAP
  159195. # define PNG_READ_PACKSWAP_SUPPORTED
  159196. # endif
  159197. # ifndef PNG_NO_READ_INVERT
  159198. # define PNG_READ_INVERT_SUPPORTED
  159199. # endif
  159200. # ifndef PNG_NO_READ_DITHER
  159201. # define PNG_READ_DITHER_SUPPORTED
  159202. # endif
  159203. # ifndef PNG_NO_READ_BACKGROUND
  159204. # define PNG_READ_BACKGROUND_SUPPORTED
  159205. # endif
  159206. # ifndef PNG_NO_READ_16_TO_8
  159207. # define PNG_READ_16_TO_8_SUPPORTED
  159208. # endif
  159209. # ifndef PNG_NO_READ_FILLER
  159210. # define PNG_READ_FILLER_SUPPORTED
  159211. # endif
  159212. # ifndef PNG_NO_READ_GAMMA
  159213. # define PNG_READ_GAMMA_SUPPORTED
  159214. # endif
  159215. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159216. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159217. # endif
  159218. # ifndef PNG_NO_READ_SWAP_ALPHA
  159219. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159220. # endif
  159221. # ifndef PNG_NO_READ_INVERT_ALPHA
  159222. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159223. # endif
  159224. # ifndef PNG_NO_READ_STRIP_ALPHA
  159225. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159226. # endif
  159227. # ifndef PNG_NO_READ_USER_TRANSFORM
  159228. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159229. # endif
  159230. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159231. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159232. # endif
  159233. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159234. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159235. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159236. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159237. #endif /* about interlacing capability! You'll */
  159238. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159239. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159240. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159241. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159242. # endif
  159243. #endif
  159244. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159245. #ifndef PNG_NO_READ_EMPTY_PLTE
  159246. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159247. #endif
  159248. #endif
  159249. #endif /* PNG_READ_SUPPORTED */
  159250. #if defined(PNG_WRITE_SUPPORTED)
  159251. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159252. !defined(PNG_NO_WRITE_TRANSFORMS)
  159253. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159254. #endif
  159255. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159256. # ifndef PNG_NO_WRITE_SHIFT
  159257. # define PNG_WRITE_SHIFT_SUPPORTED
  159258. # endif
  159259. # ifndef PNG_NO_WRITE_PACK
  159260. # define PNG_WRITE_PACK_SUPPORTED
  159261. # endif
  159262. # ifndef PNG_NO_WRITE_BGR
  159263. # define PNG_WRITE_BGR_SUPPORTED
  159264. # endif
  159265. # ifndef PNG_NO_WRITE_SWAP
  159266. # define PNG_WRITE_SWAP_SUPPORTED
  159267. # endif
  159268. # ifndef PNG_NO_WRITE_PACKSWAP
  159269. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159270. # endif
  159271. # ifndef PNG_NO_WRITE_INVERT
  159272. # define PNG_WRITE_INVERT_SUPPORTED
  159273. # endif
  159274. # ifndef PNG_NO_WRITE_FILLER
  159275. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159276. # endif
  159277. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159278. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159279. # endif
  159280. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159281. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159282. # endif
  159283. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159284. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159285. # endif
  159286. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159287. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159288. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159289. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159290. encoders, but can cause trouble
  159291. if left undefined */
  159292. #endif
  159293. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159294. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159295. defined(PNG_FLOATING_POINT_SUPPORTED)
  159296. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159297. #endif
  159298. #ifndef PNG_NO_WRITE_FLUSH
  159299. # define PNG_WRITE_FLUSH_SUPPORTED
  159300. #endif
  159301. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159302. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159303. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159304. #endif
  159305. #endif
  159306. #endif /* PNG_WRITE_SUPPORTED */
  159307. #ifndef PNG_1_0_X
  159308. # ifndef PNG_NO_ERROR_NUMBERS
  159309. # define PNG_ERROR_NUMBERS_SUPPORTED
  159310. # endif
  159311. #endif /* PNG_1_0_X */
  159312. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159313. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159314. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159315. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159316. # endif
  159317. #endif
  159318. #ifndef PNG_NO_STDIO
  159319. # define PNG_TIME_RFC1123_SUPPORTED
  159320. #endif
  159321. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159322. # define PNG_EASY_ACCESS_SUPPORTED
  159323. #endif
  159324. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159325. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159326. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159327. # endif
  159328. #endif
  159329. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159330. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159331. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159332. # endif
  159333. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159334. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159335. # define PNG_NO_MMX_CODE
  159336. # endif
  159337. # endif
  159338. # if defined(__APPLE__)
  159339. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159340. # define PNG_NO_MMX_CODE
  159341. # endif
  159342. # endif
  159343. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159344. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159345. # define PNG_NO_MMX_CODE
  159346. # endif
  159347. # endif
  159348. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159349. # define PNG_MMX_CODE_SUPPORTED
  159350. # endif
  159351. #endif
  159352. #if !defined(PNG_1_0_X)
  159353. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159354. # define PNG_USER_MEM_SUPPORTED
  159355. #endif
  159356. #endif /* PNG_1_0_X */
  159357. #if !defined(PNG_1_0_X)
  159358. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159359. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159360. # define PNG_SET_USER_LIMITS_SUPPORTED
  159361. #endif
  159362. #endif
  159363. #endif /* PNG_1_0_X */
  159364. #ifndef PNG_USER_WIDTH_MAX
  159365. # define PNG_USER_WIDTH_MAX 1000000L
  159366. #endif
  159367. #ifndef PNG_USER_HEIGHT_MAX
  159368. # define PNG_USER_HEIGHT_MAX 1000000L
  159369. #endif
  159370. #if defined(PNG_READ_SUPPORTED) && \
  159371. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159372. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159373. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159374. #endif
  159375. #if defined(PNG_WRITE_SUPPORTED) && \
  159376. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159377. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159378. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159379. #endif
  159380. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159381. #ifdef PNG_NO_READ_TEXT
  159382. # define PNG_NO_READ_iTXt
  159383. # define PNG_NO_READ_tEXt
  159384. # define PNG_NO_READ_zTXt
  159385. #endif
  159386. #ifndef PNG_NO_READ_bKGD
  159387. # define PNG_READ_bKGD_SUPPORTED
  159388. # define PNG_bKGD_SUPPORTED
  159389. #endif
  159390. #ifndef PNG_NO_READ_cHRM
  159391. # define PNG_READ_cHRM_SUPPORTED
  159392. # define PNG_cHRM_SUPPORTED
  159393. #endif
  159394. #ifndef PNG_NO_READ_gAMA
  159395. # define PNG_READ_gAMA_SUPPORTED
  159396. # define PNG_gAMA_SUPPORTED
  159397. #endif
  159398. #ifndef PNG_NO_READ_hIST
  159399. # define PNG_READ_hIST_SUPPORTED
  159400. # define PNG_hIST_SUPPORTED
  159401. #endif
  159402. #ifndef PNG_NO_READ_iCCP
  159403. # define PNG_READ_iCCP_SUPPORTED
  159404. # define PNG_iCCP_SUPPORTED
  159405. #endif
  159406. #ifndef PNG_NO_READ_iTXt
  159407. # ifndef PNG_READ_iTXt_SUPPORTED
  159408. # define PNG_READ_iTXt_SUPPORTED
  159409. # endif
  159410. # ifndef PNG_iTXt_SUPPORTED
  159411. # define PNG_iTXt_SUPPORTED
  159412. # endif
  159413. #endif
  159414. #ifndef PNG_NO_READ_oFFs
  159415. # define PNG_READ_oFFs_SUPPORTED
  159416. # define PNG_oFFs_SUPPORTED
  159417. #endif
  159418. #ifndef PNG_NO_READ_pCAL
  159419. # define PNG_READ_pCAL_SUPPORTED
  159420. # define PNG_pCAL_SUPPORTED
  159421. #endif
  159422. #ifndef PNG_NO_READ_sCAL
  159423. # define PNG_READ_sCAL_SUPPORTED
  159424. # define PNG_sCAL_SUPPORTED
  159425. #endif
  159426. #ifndef PNG_NO_READ_pHYs
  159427. # define PNG_READ_pHYs_SUPPORTED
  159428. # define PNG_pHYs_SUPPORTED
  159429. #endif
  159430. #ifndef PNG_NO_READ_sBIT
  159431. # define PNG_READ_sBIT_SUPPORTED
  159432. # define PNG_sBIT_SUPPORTED
  159433. #endif
  159434. #ifndef PNG_NO_READ_sPLT
  159435. # define PNG_READ_sPLT_SUPPORTED
  159436. # define PNG_sPLT_SUPPORTED
  159437. #endif
  159438. #ifndef PNG_NO_READ_sRGB
  159439. # define PNG_READ_sRGB_SUPPORTED
  159440. # define PNG_sRGB_SUPPORTED
  159441. #endif
  159442. #ifndef PNG_NO_READ_tEXt
  159443. # define PNG_READ_tEXt_SUPPORTED
  159444. # define PNG_tEXt_SUPPORTED
  159445. #endif
  159446. #ifndef PNG_NO_READ_tIME
  159447. # define PNG_READ_tIME_SUPPORTED
  159448. # define PNG_tIME_SUPPORTED
  159449. #endif
  159450. #ifndef PNG_NO_READ_tRNS
  159451. # define PNG_READ_tRNS_SUPPORTED
  159452. # define PNG_tRNS_SUPPORTED
  159453. #endif
  159454. #ifndef PNG_NO_READ_zTXt
  159455. # define PNG_READ_zTXt_SUPPORTED
  159456. # define PNG_zTXt_SUPPORTED
  159457. #endif
  159458. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159459. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159460. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159461. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159462. # endif
  159463. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159464. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159465. # endif
  159466. #endif
  159467. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159468. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159469. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159470. # define PNG_USER_CHUNKS_SUPPORTED
  159471. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159472. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159473. # endif
  159474. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159475. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159476. # endif
  159477. #endif
  159478. #ifndef PNG_NO_READ_OPT_PLTE
  159479. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159480. #endif /* optional PLTE chunk in RGB and RGBA images */
  159481. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159482. defined(PNG_READ_zTXt_SUPPORTED)
  159483. # define PNG_READ_TEXT_SUPPORTED
  159484. # define PNG_TEXT_SUPPORTED
  159485. #endif
  159486. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159487. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159488. #ifdef PNG_NO_WRITE_TEXT
  159489. # define PNG_NO_WRITE_iTXt
  159490. # define PNG_NO_WRITE_tEXt
  159491. # define PNG_NO_WRITE_zTXt
  159492. #endif
  159493. #ifndef PNG_NO_WRITE_bKGD
  159494. # define PNG_WRITE_bKGD_SUPPORTED
  159495. # ifndef PNG_bKGD_SUPPORTED
  159496. # define PNG_bKGD_SUPPORTED
  159497. # endif
  159498. #endif
  159499. #ifndef PNG_NO_WRITE_cHRM
  159500. # define PNG_WRITE_cHRM_SUPPORTED
  159501. # ifndef PNG_cHRM_SUPPORTED
  159502. # define PNG_cHRM_SUPPORTED
  159503. # endif
  159504. #endif
  159505. #ifndef PNG_NO_WRITE_gAMA
  159506. # define PNG_WRITE_gAMA_SUPPORTED
  159507. # ifndef PNG_gAMA_SUPPORTED
  159508. # define PNG_gAMA_SUPPORTED
  159509. # endif
  159510. #endif
  159511. #ifndef PNG_NO_WRITE_hIST
  159512. # define PNG_WRITE_hIST_SUPPORTED
  159513. # ifndef PNG_hIST_SUPPORTED
  159514. # define PNG_hIST_SUPPORTED
  159515. # endif
  159516. #endif
  159517. #ifndef PNG_NO_WRITE_iCCP
  159518. # define PNG_WRITE_iCCP_SUPPORTED
  159519. # ifndef PNG_iCCP_SUPPORTED
  159520. # define PNG_iCCP_SUPPORTED
  159521. # endif
  159522. #endif
  159523. #ifndef PNG_NO_WRITE_iTXt
  159524. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159525. # define PNG_WRITE_iTXt_SUPPORTED
  159526. # endif
  159527. # ifndef PNG_iTXt_SUPPORTED
  159528. # define PNG_iTXt_SUPPORTED
  159529. # endif
  159530. #endif
  159531. #ifndef PNG_NO_WRITE_oFFs
  159532. # define PNG_WRITE_oFFs_SUPPORTED
  159533. # ifndef PNG_oFFs_SUPPORTED
  159534. # define PNG_oFFs_SUPPORTED
  159535. # endif
  159536. #endif
  159537. #ifndef PNG_NO_WRITE_pCAL
  159538. # define PNG_WRITE_pCAL_SUPPORTED
  159539. # ifndef PNG_pCAL_SUPPORTED
  159540. # define PNG_pCAL_SUPPORTED
  159541. # endif
  159542. #endif
  159543. #ifndef PNG_NO_WRITE_sCAL
  159544. # define PNG_WRITE_sCAL_SUPPORTED
  159545. # ifndef PNG_sCAL_SUPPORTED
  159546. # define PNG_sCAL_SUPPORTED
  159547. # endif
  159548. #endif
  159549. #ifndef PNG_NO_WRITE_pHYs
  159550. # define PNG_WRITE_pHYs_SUPPORTED
  159551. # ifndef PNG_pHYs_SUPPORTED
  159552. # define PNG_pHYs_SUPPORTED
  159553. # endif
  159554. #endif
  159555. #ifndef PNG_NO_WRITE_sBIT
  159556. # define PNG_WRITE_sBIT_SUPPORTED
  159557. # ifndef PNG_sBIT_SUPPORTED
  159558. # define PNG_sBIT_SUPPORTED
  159559. # endif
  159560. #endif
  159561. #ifndef PNG_NO_WRITE_sPLT
  159562. # define PNG_WRITE_sPLT_SUPPORTED
  159563. # ifndef PNG_sPLT_SUPPORTED
  159564. # define PNG_sPLT_SUPPORTED
  159565. # endif
  159566. #endif
  159567. #ifndef PNG_NO_WRITE_sRGB
  159568. # define PNG_WRITE_sRGB_SUPPORTED
  159569. # ifndef PNG_sRGB_SUPPORTED
  159570. # define PNG_sRGB_SUPPORTED
  159571. # endif
  159572. #endif
  159573. #ifndef PNG_NO_WRITE_tEXt
  159574. # define PNG_WRITE_tEXt_SUPPORTED
  159575. # ifndef PNG_tEXt_SUPPORTED
  159576. # define PNG_tEXt_SUPPORTED
  159577. # endif
  159578. #endif
  159579. #ifndef PNG_NO_WRITE_tIME
  159580. # define PNG_WRITE_tIME_SUPPORTED
  159581. # ifndef PNG_tIME_SUPPORTED
  159582. # define PNG_tIME_SUPPORTED
  159583. # endif
  159584. #endif
  159585. #ifndef PNG_NO_WRITE_tRNS
  159586. # define PNG_WRITE_tRNS_SUPPORTED
  159587. # ifndef PNG_tRNS_SUPPORTED
  159588. # define PNG_tRNS_SUPPORTED
  159589. # endif
  159590. #endif
  159591. #ifndef PNG_NO_WRITE_zTXt
  159592. # define PNG_WRITE_zTXt_SUPPORTED
  159593. # ifndef PNG_zTXt_SUPPORTED
  159594. # define PNG_zTXt_SUPPORTED
  159595. # endif
  159596. #endif
  159597. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159598. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159599. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159600. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159601. # endif
  159602. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159603. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159604. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159605. # endif
  159606. # endif
  159607. #endif
  159608. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159609. defined(PNG_WRITE_zTXt_SUPPORTED)
  159610. # define PNG_WRITE_TEXT_SUPPORTED
  159611. # ifndef PNG_TEXT_SUPPORTED
  159612. # define PNG_TEXT_SUPPORTED
  159613. # endif
  159614. #endif
  159615. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159616. #ifndef PNG_NO_INFO_IMAGE
  159617. # define PNG_INFO_IMAGE_SUPPORTED
  159618. #endif
  159619. #if defined(PNG_tIME_SUPPORTED)
  159620. # if !defined(_WIN32_WCE)
  159621. # include <time.h>
  159622. # endif
  159623. #endif
  159624. typedef unsigned long png_uint_32;
  159625. typedef long png_int_32;
  159626. typedef unsigned short png_uint_16;
  159627. typedef short png_int_16;
  159628. typedef unsigned char png_byte;
  159629. #ifdef PNG_SIZE_T
  159630. typedef PNG_SIZE_T png_size_t;
  159631. # define png_sizeof(x) png_convert_size(sizeof (x))
  159632. #else
  159633. typedef size_t png_size_t;
  159634. # define png_sizeof(x) sizeof (x)
  159635. #endif
  159636. #ifdef __BORLANDC__
  159637. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159638. # define LDATA 1
  159639. # else
  159640. # define LDATA 0
  159641. # endif
  159642. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159643. # define PNG_MAX_MALLOC_64K
  159644. # if (LDATA != 1)
  159645. # ifndef FAR
  159646. # define FAR __far
  159647. # endif
  159648. # define USE_FAR_KEYWORD
  159649. # endif /* LDATA != 1 */
  159650. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159651. #endif /* __BORLANDC__ */
  159652. #if defined(FAR)
  159653. # if defined(M_I86MM)
  159654. # define USE_FAR_KEYWORD
  159655. # define FARDATA FAR
  159656. # include <dos.h>
  159657. # endif
  159658. #endif
  159659. #ifndef FAR
  159660. # define FAR
  159661. #endif
  159662. #ifndef FARDATA
  159663. # define FARDATA
  159664. #endif
  159665. typedef png_int_32 png_fixed_point;
  159666. typedef void FAR * png_voidp;
  159667. typedef png_byte FAR * png_bytep;
  159668. typedef png_uint_32 FAR * png_uint_32p;
  159669. typedef png_int_32 FAR * png_int_32p;
  159670. typedef png_uint_16 FAR * png_uint_16p;
  159671. typedef png_int_16 FAR * png_int_16p;
  159672. typedef PNG_CONST char FAR * png_const_charp;
  159673. typedef char FAR * png_charp;
  159674. typedef png_fixed_point FAR * png_fixed_point_p;
  159675. #ifndef PNG_NO_STDIO
  159676. #if defined(_WIN32_WCE)
  159677. typedef HANDLE png_FILE_p;
  159678. #else
  159679. typedef FILE * png_FILE_p;
  159680. #endif
  159681. #endif
  159682. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159683. typedef double FAR * png_doublep;
  159684. #endif
  159685. typedef png_byte FAR * FAR * png_bytepp;
  159686. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159687. typedef png_int_32 FAR * FAR * png_int_32pp;
  159688. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159689. typedef png_int_16 FAR * FAR * png_int_16pp;
  159690. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159691. typedef char FAR * FAR * png_charpp;
  159692. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159693. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159694. typedef double FAR * FAR * png_doublepp;
  159695. #endif
  159696. typedef char FAR * FAR * FAR * png_charppp;
  159697. #if 0
  159698. typedef charf * png_zcharp;
  159699. typedef charf * FAR * png_zcharpp;
  159700. typedef z_stream FAR * png_zstreamp;
  159701. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159702. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159703. # define PNG_DLL
  159704. #endif
  159705. #if defined(__CYGWIN__)
  159706. # if !defined(PNG_STATIC)
  159707. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159708. # undef PNG_USE_GLOBAL_ARRAYS
  159709. # endif
  159710. # if !defined(PNG_USE_LOCAL_ARRAYS)
  159711. # define PNG_USE_LOCAL_ARRAYS
  159712. # endif
  159713. # else
  159714. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  159715. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159716. # undef PNG_USE_GLOBAL_ARRAYS
  159717. # endif
  159718. # endif
  159719. # endif
  159720. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159721. # define PNG_USE_LOCAL_ARRAYS
  159722. # endif
  159723. #endif
  159724. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159725. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  159726. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  159727. # define PNG_USE_LOCAL_ARRAYS
  159728. # else
  159729. # define PNG_USE_GLOBAL_ARRAYS
  159730. # endif
  159731. #endif
  159732. #if defined(__CYGWIN__)
  159733. # undef PNGAPI
  159734. # define PNGAPI __cdecl
  159735. # undef PNG_IMPEXP
  159736. # define PNG_IMPEXP
  159737. #endif
  159738. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  159739. # ifndef PNG_NO_MODULEDEF
  159740. # define PNG_NO_MODULEDEF
  159741. # endif
  159742. #endif
  159743. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  159744. # define PNG_IMPEXP
  159745. #endif
  159746. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  159747. (( defined(_Windows) || defined(_WINDOWS) || \
  159748. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  159749. # ifndef PNGAPI
  159750. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  159751. # define PNGAPI __cdecl
  159752. # else
  159753. # define PNGAPI _cdecl
  159754. # endif
  159755. # endif
  159756. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  159757. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  159758. # define PNG_IMPEXP
  159759. # endif
  159760. # if !defined(PNG_IMPEXP)
  159761. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159762. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  159763. # if defined(_MSC_VER) || defined(__BORLANDC__)
  159764. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  159765. # define PNG_EXPORT PNG_EXPORT_TYPE1
  159766. # else
  159767. # define PNG_EXPORT PNG_EXPORT_TYPE2
  159768. # if defined(PNG_BUILD_DLL)
  159769. # define PNG_IMPEXP __export
  159770. # else
  159771. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  159772. VC++ */
  159773. # endif /* Exists in Borland C++ for
  159774. C++ classes (== huge) */
  159775. # endif
  159776. # endif
  159777. # if !defined(PNG_IMPEXP)
  159778. # if defined(PNG_BUILD_DLL)
  159779. # define PNG_IMPEXP __declspec(dllexport)
  159780. # else
  159781. # define PNG_IMPEXP __declspec(dllimport)
  159782. # endif
  159783. # endif
  159784. # endif /* PNG_IMPEXP */
  159785. #else /* !(DLL || non-cygwin WINDOWS) */
  159786. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  159787. # ifndef PNGAPI
  159788. # define PNGAPI _System
  159789. # endif
  159790. # else
  159791. # if 0 /* ... other platforms, with other meanings */
  159792. # endif
  159793. # endif
  159794. #endif
  159795. #ifndef PNGAPI
  159796. # define PNGAPI
  159797. #endif
  159798. #ifndef PNG_IMPEXP
  159799. # define PNG_IMPEXP
  159800. #endif
  159801. #ifdef PNG_BUILDSYMS
  159802. # ifndef PNG_EXPORT
  159803. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  159804. # endif
  159805. # ifdef PNG_USE_GLOBAL_ARRAYS
  159806. # ifndef PNG_EXPORT_VAR
  159807. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  159808. # endif
  159809. # endif
  159810. #endif
  159811. #ifndef PNG_EXPORT
  159812. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159813. #endif
  159814. #ifdef PNG_USE_GLOBAL_ARRAYS
  159815. # ifndef PNG_EXPORT_VAR
  159816. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  159817. # endif
  159818. #endif
  159819. #ifndef PNG_ABORT
  159820. # define PNG_ABORT() abort()
  159821. #endif
  159822. #ifdef PNG_SETJMP_SUPPORTED
  159823. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  159824. #else
  159825. # define png_jmpbuf(png_ptr) \
  159826. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  159827. #endif
  159828. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  159829. # define CHECK 1
  159830. # define NOCHECK 0
  159831. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  159832. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  159833. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  159834. # define png_strcpy _fstrcpy
  159835. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  159836. # define png_strlen _fstrlen
  159837. # define png_memcmp _fmemcmp /* SJT: added */
  159838. # define png_memcpy _fmemcpy
  159839. # define png_memset _fmemset
  159840. #else /* use the usual functions */
  159841. # define CVT_PTR(ptr) (ptr)
  159842. # define CVT_PTR_NOCHECK(ptr) (ptr)
  159843. # ifndef PNG_NO_SNPRINTF
  159844. # ifdef _MSC_VER
  159845. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  159846. # define png_snprintf2 _snprintf
  159847. # define png_snprintf6 _snprintf
  159848. # else
  159849. # define png_snprintf snprintf /* Added to v 1.2.19 */
  159850. # define png_snprintf2 snprintf
  159851. # define png_snprintf6 snprintf
  159852. # endif
  159853. # else
  159854. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  159855. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  159856. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  159857. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  159858. # endif
  159859. # define png_strcpy strcpy
  159860. # define png_strncpy strncpy /* Added to v 1.2.6 */
  159861. # define png_strlen strlen
  159862. # define png_memcmp memcmp /* SJT: added */
  159863. # define png_memcpy memcpy
  159864. # define png_memset memset
  159865. #endif
  159866. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  159867. # undef PNG_ZBUF_SIZE
  159868. # define PNG_ZBUF_SIZE 65536L
  159869. #endif
  159870. #endif /* PNG_VERSION_INFO_ONLY */
  159871. #endif /* PNGCONF_H */
  159872. /*** End of inlined file: pngconf.h ***/
  159873. #ifdef _MSC_VER
  159874. #pragma warning (disable: 4996 4100)
  159875. #endif
  159876. #if defined(PNG_USER_PRIVATEBUILD)
  159877. # define PNG_LIBPNG_BUILD_TYPE \
  159878. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  159879. #else
  159880. # if defined(PNG_LIBPNG_SPECIALBUILD)
  159881. # define PNG_LIBPNG_BUILD_TYPE \
  159882. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  159883. # else
  159884. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  159885. # endif
  159886. #endif
  159887. #ifndef PNG_VERSION_INFO_ONLY
  159888. #ifdef __cplusplus
  159889. extern "C" {
  159890. #endif /* __cplusplus */
  159891. #ifndef PNG_NO_TYPECAST_NULL
  159892. #define int_p_NULL (int *)NULL
  159893. #define png_bytep_NULL (png_bytep)NULL
  159894. #define png_bytepp_NULL (png_bytepp)NULL
  159895. #define png_doublep_NULL (png_doublep)NULL
  159896. #define png_error_ptr_NULL (png_error_ptr)NULL
  159897. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  159898. #define png_free_ptr_NULL (png_free_ptr)NULL
  159899. #define png_infopp_NULL (png_infopp)NULL
  159900. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  159901. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  159902. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  159903. #define png_structp_NULL (png_structp)NULL
  159904. #define png_uint_16p_NULL (png_uint_16p)NULL
  159905. #define png_voidp_NULL (png_voidp)NULL
  159906. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  159907. #else
  159908. #define int_p_NULL NULL
  159909. #define png_bytep_NULL NULL
  159910. #define png_bytepp_NULL NULL
  159911. #define png_doublep_NULL NULL
  159912. #define png_error_ptr_NULL NULL
  159913. #define png_flush_ptr_NULL NULL
  159914. #define png_free_ptr_NULL NULL
  159915. #define png_infopp_NULL NULL
  159916. #define png_malloc_ptr_NULL NULL
  159917. #define png_read_status_ptr_NULL NULL
  159918. #define png_rw_ptr_NULL NULL
  159919. #define png_structp_NULL NULL
  159920. #define png_uint_16p_NULL NULL
  159921. #define png_voidp_NULL NULL
  159922. #define png_write_status_ptr_NULL NULL
  159923. #endif
  159924. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  159925. #ifdef PNG_USE_GLOBAL_ARRAYS
  159926. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  159927. #else
  159928. #define png_libpng_ver png_get_header_ver(NULL)
  159929. #endif
  159930. #ifdef PNG_USE_GLOBAL_ARRAYS
  159931. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  159932. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  159933. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  159934. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  159935. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  159936. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  159937. #endif
  159938. #endif /* PNG_NO_EXTERN */
  159939. typedef struct png_color_struct
  159940. {
  159941. png_byte red;
  159942. png_byte green;
  159943. png_byte blue;
  159944. } png_color;
  159945. typedef png_color FAR * png_colorp;
  159946. typedef png_color FAR * FAR * png_colorpp;
  159947. typedef struct png_color_16_struct
  159948. {
  159949. png_byte index; /* used for palette files */
  159950. png_uint_16 red; /* for use in red green blue files */
  159951. png_uint_16 green;
  159952. png_uint_16 blue;
  159953. png_uint_16 gray; /* for use in grayscale files */
  159954. } png_color_16;
  159955. typedef png_color_16 FAR * png_color_16p;
  159956. typedef png_color_16 FAR * FAR * png_color_16pp;
  159957. typedef struct png_color_8_struct
  159958. {
  159959. png_byte red; /* for use in red green blue files */
  159960. png_byte green;
  159961. png_byte blue;
  159962. png_byte gray; /* for use in grayscale files */
  159963. png_byte alpha; /* for alpha channel files */
  159964. } png_color_8;
  159965. typedef png_color_8 FAR * png_color_8p;
  159966. typedef png_color_8 FAR * FAR * png_color_8pp;
  159967. typedef struct png_sPLT_entry_struct
  159968. {
  159969. png_uint_16 red;
  159970. png_uint_16 green;
  159971. png_uint_16 blue;
  159972. png_uint_16 alpha;
  159973. png_uint_16 frequency;
  159974. } png_sPLT_entry;
  159975. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  159976. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  159977. typedef struct png_sPLT_struct
  159978. {
  159979. png_charp name; /* palette name */
  159980. png_byte depth; /* depth of palette samples */
  159981. png_sPLT_entryp entries; /* palette entries */
  159982. png_int_32 nentries; /* number of palette entries */
  159983. } png_sPLT_t;
  159984. typedef png_sPLT_t FAR * png_sPLT_tp;
  159985. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  159986. #ifdef PNG_TEXT_SUPPORTED
  159987. typedef struct png_text_struct
  159988. {
  159989. int compression; /* compression value:
  159990. -1: tEXt, none
  159991. 0: zTXt, deflate
  159992. 1: iTXt, none
  159993. 2: iTXt, deflate */
  159994. png_charp key; /* keyword, 1-79 character description of "text" */
  159995. png_charp text; /* comment, may be an empty string (ie "")
  159996. or a NULL pointer */
  159997. png_size_t text_length; /* length of the text string */
  159998. #ifdef PNG_iTXt_SUPPORTED
  159999. png_size_t itxt_length; /* length of the itxt string */
  160000. png_charp lang; /* language code, 0-79 characters
  160001. or a NULL pointer */
  160002. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160003. chars or a NULL pointer */
  160004. #endif
  160005. } png_text;
  160006. typedef png_text FAR * png_textp;
  160007. typedef png_text FAR * FAR * png_textpp;
  160008. #endif
  160009. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160010. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160011. #define PNG_TEXT_COMPRESSION_NONE -1
  160012. #define PNG_TEXT_COMPRESSION_zTXt 0
  160013. #define PNG_ITXT_COMPRESSION_NONE 1
  160014. #define PNG_ITXT_COMPRESSION_zTXt 2
  160015. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160016. typedef struct png_time_struct
  160017. {
  160018. png_uint_16 year; /* full year, as in, 1995 */
  160019. png_byte month; /* month of year, 1 - 12 */
  160020. png_byte day; /* day of month, 1 - 31 */
  160021. png_byte hour; /* hour of day, 0 - 23 */
  160022. png_byte minute; /* minute of hour, 0 - 59 */
  160023. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160024. } png_time;
  160025. typedef png_time FAR * png_timep;
  160026. typedef png_time FAR * FAR * png_timepp;
  160027. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160028. typedef struct png_unknown_chunk_t
  160029. {
  160030. png_byte name[5];
  160031. png_byte *data;
  160032. png_size_t size;
  160033. png_byte location; /* mode of operation at read time */
  160034. }
  160035. png_unknown_chunk;
  160036. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160037. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160038. #endif
  160039. typedef struct png_info_struct
  160040. {
  160041. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160042. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160043. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160044. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160045. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160046. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160047. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160048. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160049. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160050. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160051. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160052. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160053. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160054. png_byte pixel_depth; /* number of bits per pixel */
  160055. png_byte spare_byte; /* to align the data, and for future use */
  160056. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160057. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160058. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160059. #endif
  160060. #if defined(PNG_sRGB_SUPPORTED)
  160061. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160062. #endif
  160063. #if defined(PNG_TEXT_SUPPORTED)
  160064. int num_text; /* number of comments read/to write */
  160065. int max_text; /* current size of text array */
  160066. png_textp text; /* array of comments read/to write */
  160067. #endif /* PNG_TEXT_SUPPORTED */
  160068. #if defined(PNG_tIME_SUPPORTED)
  160069. png_time mod_time;
  160070. #endif
  160071. #if defined(PNG_sBIT_SUPPORTED)
  160072. png_color_8 sig_bit; /* significant bits in color channels */
  160073. #endif
  160074. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160075. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160076. png_bytep trans; /* transparent values for paletted image */
  160077. png_color_16 trans_values; /* transparent color for non-palette image */
  160078. #endif
  160079. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160080. png_color_16 background;
  160081. #endif
  160082. #if defined(PNG_oFFs_SUPPORTED)
  160083. png_int_32 x_offset; /* x offset on page */
  160084. png_int_32 y_offset; /* y offset on page */
  160085. png_byte offset_unit_type; /* offset units type */
  160086. #endif
  160087. #if defined(PNG_pHYs_SUPPORTED)
  160088. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160089. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160090. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160091. #endif
  160092. #if defined(PNG_hIST_SUPPORTED)
  160093. png_uint_16p hist;
  160094. #endif
  160095. #ifdef PNG_cHRM_SUPPORTED
  160096. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160097. float x_white;
  160098. float y_white;
  160099. float x_red;
  160100. float y_red;
  160101. float x_green;
  160102. float y_green;
  160103. float x_blue;
  160104. float y_blue;
  160105. #endif
  160106. #endif
  160107. #if defined(PNG_pCAL_SUPPORTED)
  160108. png_charp pcal_purpose; /* pCAL chunk description string */
  160109. png_int_32 pcal_X0; /* minimum value */
  160110. png_int_32 pcal_X1; /* maximum value */
  160111. png_charp pcal_units; /* Latin-1 string giving physical units */
  160112. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160113. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160114. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160115. #endif
  160116. #ifdef PNG_FREE_ME_SUPPORTED
  160117. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160118. #endif
  160119. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160120. png_unknown_chunkp unknown_chunks;
  160121. png_size_t unknown_chunks_num;
  160122. #endif
  160123. #if defined(PNG_iCCP_SUPPORTED)
  160124. png_charp iccp_name; /* profile name */
  160125. png_charp iccp_profile; /* International Color Consortium profile data */
  160126. png_uint_32 iccp_proflen; /* ICC profile data length */
  160127. png_byte iccp_compression; /* Always zero */
  160128. #endif
  160129. #if defined(PNG_sPLT_SUPPORTED)
  160130. png_sPLT_tp splt_palettes;
  160131. png_uint_32 splt_palettes_num;
  160132. #endif
  160133. #if defined(PNG_sCAL_SUPPORTED)
  160134. png_byte scal_unit; /* unit of physical scale */
  160135. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160136. double scal_pixel_width; /* width of one pixel */
  160137. double scal_pixel_height; /* height of one pixel */
  160138. #endif
  160139. #ifdef PNG_FIXED_POINT_SUPPORTED
  160140. png_charp scal_s_width; /* string containing height */
  160141. png_charp scal_s_height; /* string containing width */
  160142. #endif
  160143. #endif
  160144. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160145. png_bytepp row_pointers; /* the image bits */
  160146. #endif
  160147. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160148. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160149. #endif
  160150. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160151. png_fixed_point int_x_white;
  160152. png_fixed_point int_y_white;
  160153. png_fixed_point int_x_red;
  160154. png_fixed_point int_y_red;
  160155. png_fixed_point int_x_green;
  160156. png_fixed_point int_y_green;
  160157. png_fixed_point int_x_blue;
  160158. png_fixed_point int_y_blue;
  160159. #endif
  160160. } png_info;
  160161. typedef png_info FAR * png_infop;
  160162. typedef png_info FAR * FAR * png_infopp;
  160163. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160164. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160165. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160166. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160167. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160168. #endif
  160169. #define PNG_COLOR_MASK_PALETTE 1
  160170. #define PNG_COLOR_MASK_COLOR 2
  160171. #define PNG_COLOR_MASK_ALPHA 4
  160172. #define PNG_COLOR_TYPE_GRAY 0
  160173. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160174. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160175. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160176. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160177. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160178. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160179. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160180. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160181. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160182. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160183. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160184. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160185. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160186. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160187. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160188. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160189. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160190. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160191. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160192. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160193. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160194. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160195. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160196. #define PNG_SCALE_METER 1 /* meters per pixel */
  160197. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160198. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160199. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160200. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160201. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160202. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160203. #define PNG_sRGB_INTENT_RELATIVE 1
  160204. #define PNG_sRGB_INTENT_SATURATION 2
  160205. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160206. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160207. #define PNG_KEYWORD_MAX_LENGTH 79
  160208. #define PNG_MAX_PALETTE_LENGTH 256
  160209. #define PNG_INFO_gAMA 0x0001
  160210. #define PNG_INFO_sBIT 0x0002
  160211. #define PNG_INFO_cHRM 0x0004
  160212. #define PNG_INFO_PLTE 0x0008
  160213. #define PNG_INFO_tRNS 0x0010
  160214. #define PNG_INFO_bKGD 0x0020
  160215. #define PNG_INFO_hIST 0x0040
  160216. #define PNG_INFO_pHYs 0x0080
  160217. #define PNG_INFO_oFFs 0x0100
  160218. #define PNG_INFO_tIME 0x0200
  160219. #define PNG_INFO_pCAL 0x0400
  160220. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160221. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160222. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160223. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160224. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160225. typedef struct png_row_info_struct
  160226. {
  160227. png_uint_32 width; /* width of row */
  160228. png_uint_32 rowbytes; /* number of bytes in row */
  160229. png_byte color_type; /* color type of row */
  160230. png_byte bit_depth; /* bit depth of row */
  160231. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160232. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160233. } png_row_info;
  160234. typedef png_row_info FAR * png_row_infop;
  160235. typedef png_row_info FAR * FAR * png_row_infopp;
  160236. typedef struct png_struct_def png_struct;
  160237. typedef png_struct FAR * png_structp;
  160238. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160239. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160240. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160241. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160242. int));
  160243. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160244. int));
  160245. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160246. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160247. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160248. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160249. png_uint_32, int));
  160250. #endif
  160251. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160252. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160253. defined(PNG_LEGACY_SUPPORTED)
  160254. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160255. png_row_infop, png_bytep));
  160256. #endif
  160257. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160258. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160259. #endif
  160260. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160261. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160262. #endif
  160263. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160264. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160265. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160266. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160267. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160268. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160269. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160270. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160271. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160272. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160273. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160274. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160275. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160276. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160277. #define PNG_FLAG_MNG_FILTER_64 0x04
  160278. #define PNG_ALL_MNG_FEATURES 0x05
  160279. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160280. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160281. struct png_struct_def
  160282. {
  160283. #ifdef PNG_SETJMP_SUPPORTED
  160284. jmp_buf jmpbuf; /* used in png_error */
  160285. #endif
  160286. png_error_ptr error_fn; /* function for printing errors and aborting */
  160287. png_error_ptr warning_fn; /* function for printing warnings */
  160288. png_voidp error_ptr; /* user supplied struct for error functions */
  160289. png_rw_ptr write_data_fn; /* function for writing output data */
  160290. png_rw_ptr read_data_fn; /* function for reading input data */
  160291. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160292. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160293. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160294. #endif
  160295. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160296. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160297. #endif
  160298. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160299. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160300. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160301. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160302. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160303. png_byte user_transform_channels; /* channels in user transformed pixels */
  160304. #endif
  160305. #endif
  160306. png_uint_32 mode; /* tells us where we are in the PNG file */
  160307. png_uint_32 flags; /* flags indicating various things to libpng */
  160308. png_uint_32 transformations; /* which transformations to perform */
  160309. z_stream zstream; /* pointer to decompression structure (below) */
  160310. png_bytep zbuf; /* buffer for zlib */
  160311. png_size_t zbuf_size; /* size of zbuf */
  160312. int zlib_level; /* holds zlib compression level */
  160313. int zlib_method; /* holds zlib compression method */
  160314. int zlib_window_bits; /* holds zlib compression window bits */
  160315. int zlib_mem_level; /* holds zlib compression memory level */
  160316. int zlib_strategy; /* holds zlib compression strategy */
  160317. png_uint_32 width; /* width of image in pixels */
  160318. png_uint_32 height; /* height of image in pixels */
  160319. png_uint_32 num_rows; /* number of rows in current pass */
  160320. png_uint_32 usr_width; /* width of row at start of write */
  160321. png_uint_32 rowbytes; /* size of row in bytes */
  160322. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160323. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160324. png_uint_32 row_number; /* current row in interlace pass */
  160325. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160326. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160327. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160328. png_bytep up_row; /* buffer to save "up" row when filtering */
  160329. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160330. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160331. png_row_info row_info; /* used for transformation routines */
  160332. png_uint_32 idat_size; /* current IDAT size for read */
  160333. png_uint_32 crc; /* current chunk CRC value */
  160334. png_colorp palette; /* palette from the input file */
  160335. png_uint_16 num_palette; /* number of color entries in palette */
  160336. png_uint_16 num_trans; /* number of transparency values */
  160337. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160338. png_byte compression; /* file compression type (always 0) */
  160339. png_byte filter; /* file filter type (always 0) */
  160340. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160341. png_byte pass; /* current interlace pass (0 - 6) */
  160342. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160343. png_byte color_type; /* color type of file */
  160344. png_byte bit_depth; /* bit depth of file */
  160345. png_byte usr_bit_depth; /* bit depth of users row */
  160346. png_byte pixel_depth; /* number of bits per pixel */
  160347. png_byte channels; /* number of channels in file */
  160348. png_byte usr_channels; /* channels at start of write */
  160349. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160350. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160351. #ifdef PNG_LEGACY_SUPPORTED
  160352. png_byte filler; /* filler byte for pixel expansion */
  160353. #else
  160354. png_uint_16 filler; /* filler bytes for pixel expansion */
  160355. #endif
  160356. #endif
  160357. #if defined(PNG_bKGD_SUPPORTED)
  160358. png_byte background_gamma_type;
  160359. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160360. float background_gamma;
  160361. # endif
  160362. png_color_16 background; /* background color in screen gamma space */
  160363. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160364. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160365. #endif
  160366. #endif /* PNG_bKGD_SUPPORTED */
  160367. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160368. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160369. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160370. png_uint_32 flush_rows; /* number of rows written since last flush */
  160371. #endif
  160372. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160373. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160374. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160375. float gamma; /* file gamma value */
  160376. float screen_gamma; /* screen gamma value (display_exponent) */
  160377. #endif
  160378. #endif
  160379. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160380. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160381. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160382. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160383. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160384. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160385. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160386. #endif
  160387. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160388. png_color_8 sig_bit; /* significant bits in each available channel */
  160389. #endif
  160390. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160391. png_color_8 shift; /* shift for significant bit tranformation */
  160392. #endif
  160393. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160394. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160395. png_bytep trans; /* transparency values for paletted files */
  160396. png_color_16 trans_values; /* transparency values for non-paletted files */
  160397. #endif
  160398. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160399. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160400. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160401. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160402. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160403. png_progressive_end_ptr end_fn; /* called after image is complete */
  160404. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160405. png_bytep save_buffer; /* buffer for previously read data */
  160406. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160407. png_bytep current_buffer; /* buffer for recently used data */
  160408. png_uint_32 push_length; /* size of current input chunk */
  160409. png_uint_32 skip_length; /* bytes to skip in input data */
  160410. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160411. png_size_t save_buffer_max; /* total size of save_buffer */
  160412. png_size_t buffer_size; /* total amount of available input data */
  160413. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160414. int process_mode; /* what push library is currently doing */
  160415. int cur_palette; /* current push library palette index */
  160416. # if defined(PNG_TEXT_SUPPORTED)
  160417. png_size_t current_text_size; /* current size of text input data */
  160418. png_size_t current_text_left; /* how much text left to read in input */
  160419. png_charp current_text; /* current text chunk buffer */
  160420. png_charp current_text_ptr; /* current location in current_text */
  160421. # endif /* PNG_TEXT_SUPPORTED */
  160422. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160423. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160424. png_bytepp offset_table_ptr;
  160425. png_bytep offset_table;
  160426. png_uint_16 offset_table_number;
  160427. png_uint_16 offset_table_count;
  160428. png_uint_16 offset_table_count_free;
  160429. #endif
  160430. #if defined(PNG_READ_DITHER_SUPPORTED)
  160431. png_bytep palette_lookup; /* lookup table for dithering */
  160432. png_bytep dither_index; /* index translation for palette files */
  160433. #endif
  160434. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160435. png_uint_16p hist; /* histogram */
  160436. #endif
  160437. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160438. png_byte heuristic_method; /* heuristic for row filter selection */
  160439. png_byte num_prev_filters; /* number of weights for previous rows */
  160440. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160441. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160442. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160443. png_uint_16p filter_costs; /* relative filter calculation cost */
  160444. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160445. #endif
  160446. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160447. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160448. #endif
  160449. #ifdef PNG_FREE_ME_SUPPORTED
  160450. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160451. #endif
  160452. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160453. png_voidp user_chunk_ptr;
  160454. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160455. #endif
  160456. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160457. int num_chunk_list;
  160458. png_bytep chunk_list;
  160459. #endif
  160460. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160461. png_byte rgb_to_gray_status;
  160462. png_uint_16 rgb_to_gray_red_coeff;
  160463. png_uint_16 rgb_to_gray_green_coeff;
  160464. png_uint_16 rgb_to_gray_blue_coeff;
  160465. #endif
  160466. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160467. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160468. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160469. #ifdef PNG_1_0_X
  160470. png_byte mng_features_permitted;
  160471. #else
  160472. png_uint_32 mng_features_permitted;
  160473. #endif /* PNG_1_0_X */
  160474. #endif
  160475. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160476. png_fixed_point int_gamma;
  160477. #endif
  160478. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160479. png_byte filter_type;
  160480. #endif
  160481. #if defined(PNG_1_0_X)
  160482. png_uint_32 row_buf_size;
  160483. #endif
  160484. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160485. # if !defined(PNG_1_0_X)
  160486. # if defined(PNG_MMX_CODE_SUPPORTED)
  160487. png_byte mmx_bitdepth_threshold;
  160488. png_uint_32 mmx_rowbytes_threshold;
  160489. # endif
  160490. png_uint_32 asm_flags;
  160491. # endif
  160492. #endif
  160493. #ifdef PNG_USER_MEM_SUPPORTED
  160494. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160495. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160496. png_free_ptr free_fn; /* function for freeing memory */
  160497. #endif
  160498. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160499. #if defined(PNG_READ_DITHER_SUPPORTED)
  160500. png_bytep dither_sort; /* working sort array */
  160501. png_bytep index_to_palette; /* where the original index currently is */
  160502. png_bytep palette_to_index; /* which original index points to this */
  160503. #endif
  160504. png_byte compression_type;
  160505. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160506. png_uint_32 user_width_max;
  160507. png_uint_32 user_height_max;
  160508. #endif
  160509. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160510. png_unknown_chunk unknown_chunk;
  160511. #endif
  160512. };
  160513. typedef png_structp version_1_2_21;
  160514. typedef png_struct FAR * FAR * png_structpp;
  160515. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160516. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160517. int num_bytes));
  160518. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160519. png_size_t num_to_check));
  160520. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160521. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160522. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160523. png_error_ptr error_fn, png_error_ptr warn_fn));
  160524. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160525. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160526. png_error_ptr error_fn, png_error_ptr warn_fn));
  160527. #ifdef PNG_WRITE_SUPPORTED
  160528. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160529. PNGARG((png_structp png_ptr));
  160530. #endif
  160531. #ifdef PNG_WRITE_SUPPORTED
  160532. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160533. PNGARG((png_structp png_ptr, png_uint_32 size));
  160534. #endif
  160535. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160536. #ifdef PNG_USER_MEM_SUPPORTED
  160537. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160538. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160539. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160540. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160541. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160542. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160543. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160544. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160545. #endif
  160546. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160547. png_bytep chunk_name, png_bytep data, png_size_t length));
  160548. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160549. png_bytep chunk_name, png_uint_32 length));
  160550. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160551. png_bytep data, png_size_t length));
  160552. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160553. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160554. PNGARG((png_structp png_ptr));
  160555. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160556. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160557. #undef png_info_init
  160558. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160559. png_sizeof(png_info));
  160560. #endif
  160561. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160562. png_size_t png_info_struct_size));
  160563. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160564. png_infop info_ptr));
  160565. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160566. png_infop info_ptr));
  160567. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160568. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160569. png_infop info_ptr));
  160570. #endif
  160571. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160572. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160573. PNGARG((png_structp png_ptr, png_timep ptime));
  160574. #endif
  160575. #if !defined(_WIN32_WCE)
  160576. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160577. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160578. struct tm FAR * ttime));
  160579. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160580. time_t ttime));
  160581. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160582. #endif /* _WIN32_WCE */
  160583. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160584. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160585. #if !defined(PNG_1_0_X)
  160586. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160587. png_ptr));
  160588. #endif
  160589. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160590. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160591. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160592. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160593. #endif
  160594. #endif
  160595. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160596. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160597. #endif
  160598. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160599. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160600. #endif
  160601. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160602. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160603. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160604. int error_action, double red, double green ));
  160605. #endif
  160606. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160607. int error_action, png_fixed_point red, png_fixed_point green ));
  160608. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160609. png_ptr));
  160610. #endif
  160611. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160612. png_colorp palette));
  160613. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160614. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160615. #endif
  160616. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160617. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160618. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160619. #endif
  160620. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160621. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160622. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160623. #endif
  160624. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160625. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160626. png_uint_32 filler, int flags));
  160627. #define PNG_FILLER_BEFORE 0
  160628. #define PNG_FILLER_AFTER 1
  160629. #if !defined(PNG_1_0_X)
  160630. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160631. png_uint_32 filler, int flags));
  160632. #endif
  160633. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160634. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160635. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160636. #endif
  160637. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160638. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160639. #endif
  160640. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160641. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160642. #endif
  160643. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160644. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160645. png_color_8p true_bits));
  160646. #endif
  160647. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160648. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160649. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160650. #endif
  160651. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160652. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160653. #endif
  160654. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160655. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160656. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160657. png_color_16p background_color, int background_gamma_code,
  160658. int need_expand, double background_gamma));
  160659. #endif
  160660. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160661. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160662. #define PNG_BACKGROUND_GAMMA_FILE 2
  160663. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160664. #endif
  160665. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160666. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160667. #endif
  160668. #if defined(PNG_READ_DITHER_SUPPORTED)
  160669. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160670. png_colorp palette, int num_palette, int maximum_colors,
  160671. png_uint_16p histogram, int full_dither));
  160672. #endif
  160673. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160674. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160675. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160676. double screen_gamma, double default_file_gamma));
  160677. #endif
  160678. #endif
  160679. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160680. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160681. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160682. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160683. int empty_plte_permitted));
  160684. #endif
  160685. #endif
  160686. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160687. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160688. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160689. #endif
  160690. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160691. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160692. png_infop info_ptr));
  160693. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160694. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160695. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160696. #endif
  160697. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160698. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160699. png_bytep row,
  160700. png_bytep display_row));
  160701. #endif
  160702. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160703. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160704. png_bytepp image));
  160705. #endif
  160706. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  160707. png_bytep row));
  160708. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  160709. png_bytepp row, png_uint_32 num_rows));
  160710. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  160711. png_bytepp image));
  160712. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  160713. png_infop info_ptr));
  160714. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160715. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  160716. png_infop info_ptr));
  160717. #endif
  160718. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  160719. png_infopp info_ptr_ptr));
  160720. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  160721. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  160722. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  160723. png_infop end_info_ptr));
  160724. extern PNG_EXPORT(void,png_destroy_write_struct)
  160725. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  160726. extern void png_write_destroy PNGARG((png_structp png_ptr));
  160727. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  160728. int crit_action, int ancil_action));
  160729. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  160730. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  160731. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  160732. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  160733. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  160734. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  160735. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  160736. int filters));
  160737. #define PNG_NO_FILTERS 0x00
  160738. #define PNG_FILTER_NONE 0x08
  160739. #define PNG_FILTER_SUB 0x10
  160740. #define PNG_FILTER_UP 0x20
  160741. #define PNG_FILTER_AVG 0x40
  160742. #define PNG_FILTER_PAETH 0x80
  160743. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  160744. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  160745. #define PNG_FILTER_VALUE_NONE 0
  160746. #define PNG_FILTER_VALUE_SUB 1
  160747. #define PNG_FILTER_VALUE_UP 2
  160748. #define PNG_FILTER_VALUE_AVG 3
  160749. #define PNG_FILTER_VALUE_PAETH 4
  160750. #define PNG_FILTER_VALUE_LAST 5
  160751. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  160752. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160753. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  160754. int heuristic_method, int num_weights, png_doublep filter_weights,
  160755. png_doublep filter_costs));
  160756. #endif
  160757. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  160758. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  160759. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  160760. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  160761. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  160762. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  160763. int level));
  160764. extern PNG_EXPORT(void,png_set_compression_mem_level)
  160765. PNGARG((png_structp png_ptr, int mem_level));
  160766. extern PNG_EXPORT(void,png_set_compression_strategy)
  160767. PNGARG((png_structp png_ptr, int strategy));
  160768. extern PNG_EXPORT(void,png_set_compression_window_bits)
  160769. PNGARG((png_structp png_ptr, int window_bits));
  160770. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  160771. int method));
  160772. #if !defined(PNG_NO_STDIO)
  160773. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  160774. #endif
  160775. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  160776. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  160777. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  160778. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  160779. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  160780. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  160781. png_voidp io_ptr, png_rw_ptr read_data_fn));
  160782. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  160783. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  160784. png_read_status_ptr read_row_fn));
  160785. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  160786. png_write_status_ptr write_row_fn));
  160787. #ifdef PNG_USER_MEM_SUPPORTED
  160788. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  160789. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160790. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  160791. #endif
  160792. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160793. defined(PNG_LEGACY_SUPPORTED)
  160794. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  160795. png_ptr, png_user_transform_ptr read_user_transform_fn));
  160796. #endif
  160797. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160798. defined(PNG_LEGACY_SUPPORTED)
  160799. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  160800. png_ptr, png_user_transform_ptr write_user_transform_fn));
  160801. #endif
  160802. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160803. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160804. defined(PNG_LEGACY_SUPPORTED)
  160805. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  160806. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  160807. int user_transform_channels));
  160808. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  160809. PNGARG((png_structp png_ptr));
  160810. #endif
  160811. #ifdef PNG_USER_CHUNKS_SUPPORTED
  160812. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  160813. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  160814. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  160815. png_ptr));
  160816. #endif
  160817. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160818. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  160819. png_voidp progressive_ptr,
  160820. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  160821. png_progressive_end_ptr end_fn));
  160822. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  160823. PNGARG((png_structp png_ptr));
  160824. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  160825. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  160826. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  160827. png_bytep old_row, png_bytep new_row));
  160828. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160829. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  160830. png_uint_32 size));
  160831. #if defined(PNG_1_0_X)
  160832. # define png_malloc_warn png_malloc
  160833. #else
  160834. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  160835. png_uint_32 size));
  160836. #endif
  160837. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  160838. #if defined(PNG_1_0_X)
  160839. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  160840. uInt size));
  160841. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  160842. #endif
  160843. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  160844. png_infop info_ptr, png_uint_32 free_me, int num));
  160845. #ifdef PNG_FREE_ME_SUPPORTED
  160846. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  160847. png_infop info_ptr, int freer, png_uint_32 mask));
  160848. #endif
  160849. #define PNG_DESTROY_WILL_FREE_DATA 1
  160850. #define PNG_SET_WILL_FREE_DATA 1
  160851. #define PNG_USER_WILL_FREE_DATA 2
  160852. #define PNG_FREE_HIST 0x0008
  160853. #define PNG_FREE_ICCP 0x0010
  160854. #define PNG_FREE_SPLT 0x0020
  160855. #define PNG_FREE_ROWS 0x0040
  160856. #define PNG_FREE_PCAL 0x0080
  160857. #define PNG_FREE_SCAL 0x0100
  160858. #define PNG_FREE_UNKN 0x0200
  160859. #define PNG_FREE_LIST 0x0400
  160860. #define PNG_FREE_PLTE 0x1000
  160861. #define PNG_FREE_TRNS 0x2000
  160862. #define PNG_FREE_TEXT 0x4000
  160863. #define PNG_FREE_ALL 0x7fff
  160864. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  160865. #ifdef PNG_USER_MEM_SUPPORTED
  160866. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  160867. png_uint_32 size));
  160868. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  160869. png_voidp ptr));
  160870. #endif
  160871. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  160872. png_voidp s1, png_voidp s2, png_uint_32 size));
  160873. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  160874. png_voidp s1, int value, png_uint_32 size));
  160875. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  160876. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  160877. int check));
  160878. #endif /* USE_FAR_KEYWORD */
  160879. #ifndef PNG_NO_ERROR_TEXT
  160880. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  160881. png_const_charp error_message));
  160882. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  160883. png_const_charp error_message));
  160884. #else
  160885. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  160886. #endif
  160887. #ifndef PNG_NO_WARNINGS
  160888. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  160889. png_const_charp warning_message));
  160890. #ifdef PNG_READ_SUPPORTED
  160891. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  160892. png_const_charp warning_message));
  160893. #endif /* PNG_READ_SUPPORTED */
  160894. #endif /* PNG_NO_WARNINGS */
  160895. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  160896. png_infop info_ptr, png_uint_32 flag));
  160897. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  160898. png_infop info_ptr));
  160899. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160900. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  160901. png_infop info_ptr));
  160902. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  160903. png_infop info_ptr, png_bytepp row_pointers));
  160904. #endif
  160905. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  160906. png_infop info_ptr));
  160907. #ifdef PNG_EASY_ACCESS_SUPPORTED
  160908. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  160909. png_ptr, png_infop info_ptr));
  160910. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  160911. png_ptr, png_infop info_ptr));
  160912. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  160913. png_ptr, png_infop info_ptr));
  160914. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  160915. png_ptr, png_infop info_ptr));
  160916. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  160917. png_ptr, png_infop info_ptr));
  160918. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  160919. png_ptr, png_infop info_ptr));
  160920. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  160921. png_ptr, png_infop info_ptr));
  160922. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  160923. png_ptr, png_infop info_ptr));
  160924. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  160925. png_ptr, png_infop info_ptr));
  160926. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  160927. png_ptr, png_infop info_ptr));
  160928. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160929. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  160930. png_ptr, png_infop info_ptr));
  160931. #endif
  160932. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  160933. png_ptr, png_infop info_ptr));
  160934. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  160935. png_ptr, png_infop info_ptr));
  160936. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  160937. png_ptr, png_infop info_ptr));
  160938. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  160939. png_ptr, png_infop info_ptr));
  160940. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  160941. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  160942. png_infop info_ptr));
  160943. #if defined(PNG_bKGD_SUPPORTED)
  160944. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  160945. png_infop info_ptr, png_color_16p *background));
  160946. #endif
  160947. #if defined(PNG_bKGD_SUPPORTED)
  160948. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  160949. png_infop info_ptr, png_color_16p background));
  160950. #endif
  160951. #if defined(PNG_cHRM_SUPPORTED)
  160952. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160953. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  160954. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  160955. double *red_y, double *green_x, double *green_y, double *blue_x,
  160956. double *blue_y));
  160957. #endif
  160958. #ifdef PNG_FIXED_POINT_SUPPORTED
  160959. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  160960. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  160961. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  160962. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  160963. *int_blue_x, png_fixed_point *int_blue_y));
  160964. #endif
  160965. #endif
  160966. #if defined(PNG_cHRM_SUPPORTED)
  160967. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160968. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  160969. png_infop info_ptr, double white_x, double white_y, double red_x,
  160970. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  160971. #endif
  160972. #ifdef PNG_FIXED_POINT_SUPPORTED
  160973. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  160974. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  160975. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  160976. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  160977. png_fixed_point int_blue_y));
  160978. #endif
  160979. #endif
  160980. #if defined(PNG_gAMA_SUPPORTED)
  160981. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160982. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  160983. png_infop info_ptr, double *file_gamma));
  160984. #endif
  160985. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  160986. png_infop info_ptr, png_fixed_point *int_file_gamma));
  160987. #endif
  160988. #if defined(PNG_gAMA_SUPPORTED)
  160989. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160990. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  160991. png_infop info_ptr, double file_gamma));
  160992. #endif
  160993. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  160994. png_infop info_ptr, png_fixed_point int_file_gamma));
  160995. #endif
  160996. #if defined(PNG_hIST_SUPPORTED)
  160997. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  160998. png_infop info_ptr, png_uint_16p *hist));
  160999. #endif
  161000. #if defined(PNG_hIST_SUPPORTED)
  161001. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161002. png_infop info_ptr, png_uint_16p hist));
  161003. #endif
  161004. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161005. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161006. int *bit_depth, int *color_type, int *interlace_method,
  161007. int *compression_method, int *filter_method));
  161008. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161009. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161010. int color_type, int interlace_method, int compression_method,
  161011. int filter_method));
  161012. #if defined(PNG_oFFs_SUPPORTED)
  161013. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161014. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161015. int *unit_type));
  161016. #endif
  161017. #if defined(PNG_oFFs_SUPPORTED)
  161018. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161019. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161020. int unit_type));
  161021. #endif
  161022. #if defined(PNG_pCAL_SUPPORTED)
  161023. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161024. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161025. int *type, int *nparams, png_charp *units, png_charpp *params));
  161026. #endif
  161027. #if defined(PNG_pCAL_SUPPORTED)
  161028. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161029. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161030. int type, int nparams, png_charp units, png_charpp params));
  161031. #endif
  161032. #if defined(PNG_pHYs_SUPPORTED)
  161033. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161034. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161035. #endif
  161036. #if defined(PNG_pHYs_SUPPORTED)
  161037. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161038. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161039. #endif
  161040. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161041. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161042. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161043. png_infop info_ptr, png_colorp palette, int num_palette));
  161044. #if defined(PNG_sBIT_SUPPORTED)
  161045. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161046. png_infop info_ptr, png_color_8p *sig_bit));
  161047. #endif
  161048. #if defined(PNG_sBIT_SUPPORTED)
  161049. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161050. png_infop info_ptr, png_color_8p sig_bit));
  161051. #endif
  161052. #if defined(PNG_sRGB_SUPPORTED)
  161053. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161054. png_infop info_ptr, int *intent));
  161055. #endif
  161056. #if defined(PNG_sRGB_SUPPORTED)
  161057. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161058. png_infop info_ptr, int intent));
  161059. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161060. png_infop info_ptr, int intent));
  161061. #endif
  161062. #if defined(PNG_iCCP_SUPPORTED)
  161063. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161064. png_infop info_ptr, png_charpp name, int *compression_type,
  161065. png_charpp profile, png_uint_32 *proflen));
  161066. #endif
  161067. #if defined(PNG_iCCP_SUPPORTED)
  161068. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161069. png_infop info_ptr, png_charp name, int compression_type,
  161070. png_charp profile, png_uint_32 proflen));
  161071. #endif
  161072. #if defined(PNG_sPLT_SUPPORTED)
  161073. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161074. png_infop info_ptr, png_sPLT_tpp entries));
  161075. #endif
  161076. #if defined(PNG_sPLT_SUPPORTED)
  161077. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161078. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161079. #endif
  161080. #if defined(PNG_TEXT_SUPPORTED)
  161081. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161082. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161083. #endif
  161084. #if defined(PNG_TEXT_SUPPORTED)
  161085. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161086. png_infop info_ptr, png_textp text_ptr, int num_text));
  161087. #endif
  161088. #if defined(PNG_tIME_SUPPORTED)
  161089. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161090. png_infop info_ptr, png_timep *mod_time));
  161091. #endif
  161092. #if defined(PNG_tIME_SUPPORTED)
  161093. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161094. png_infop info_ptr, png_timep mod_time));
  161095. #endif
  161096. #if defined(PNG_tRNS_SUPPORTED)
  161097. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161098. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161099. png_color_16p *trans_values));
  161100. #endif
  161101. #if defined(PNG_tRNS_SUPPORTED)
  161102. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161103. png_infop info_ptr, png_bytep trans, int num_trans,
  161104. png_color_16p trans_values));
  161105. #endif
  161106. #if defined(PNG_tRNS_SUPPORTED)
  161107. #endif
  161108. #if defined(PNG_sCAL_SUPPORTED)
  161109. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161110. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161111. png_infop info_ptr, int *unit, double *width, double *height));
  161112. #else
  161113. #ifdef PNG_FIXED_POINT_SUPPORTED
  161114. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161115. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161116. #endif
  161117. #endif
  161118. #endif /* PNG_sCAL_SUPPORTED */
  161119. #if defined(PNG_sCAL_SUPPORTED)
  161120. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161121. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161122. png_infop info_ptr, int unit, double width, double height));
  161123. #else
  161124. #ifdef PNG_FIXED_POINT_SUPPORTED
  161125. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161126. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161127. #endif
  161128. #endif
  161129. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161130. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161131. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161132. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161133. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161134. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161135. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161136. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161137. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161138. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161139. #endif
  161140. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161141. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161142. chunk_name));
  161143. #endif
  161144. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161145. png_infop info_ptr, int mask));
  161146. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161147. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161148. png_infop info_ptr,
  161149. int transforms,
  161150. png_voidp params));
  161151. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161152. png_infop info_ptr,
  161153. int transforms,
  161154. png_voidp params));
  161155. #endif
  161156. #ifdef PNG_DEBUG
  161157. #if (PNG_DEBUG > 0)
  161158. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161159. #include <crtdbg.h>
  161160. #if (PNG_DEBUG > 1)
  161161. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161162. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161163. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161164. #endif
  161165. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161166. #ifndef PNG_DEBUG_FILE
  161167. #define PNG_DEBUG_FILE stderr
  161168. #endif /* PNG_DEBUG_FILE */
  161169. #if (PNG_DEBUG > 1)
  161170. #define png_debug(l,m) \
  161171. { \
  161172. int num_tabs=l; \
  161173. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161174. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161175. }
  161176. #define png_debug1(l,m,p1) \
  161177. { \
  161178. int num_tabs=l; \
  161179. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161180. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161181. }
  161182. #define png_debug2(l,m,p1,p2) \
  161183. { \
  161184. int num_tabs=l; \
  161185. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161186. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161187. }
  161188. #endif /* (PNG_DEBUG > 1) */
  161189. #endif /* _MSC_VER */
  161190. #endif /* (PNG_DEBUG > 0) */
  161191. #endif /* PNG_DEBUG */
  161192. #ifndef png_debug
  161193. #define png_debug(l, m)
  161194. #endif
  161195. #ifndef png_debug1
  161196. #define png_debug1(l, m, p1)
  161197. #endif
  161198. #ifndef png_debug2
  161199. #define png_debug2(l, m, p1, p2)
  161200. #endif
  161201. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161202. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161203. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161204. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161205. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161206. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161207. png_ptr, png_uint_32 mng_features_permitted));
  161208. #endif
  161209. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161210. #define PNG_HANDLE_CHUNK_NEVER 1
  161211. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161212. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161213. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161214. #if defined(PNG_MMX_CODE_SUPPORTED)
  161215. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161216. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161217. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161218. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161219. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161220. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161221. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161222. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161223. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161224. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161225. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161226. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161227. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161228. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161229. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161230. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161231. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161232. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161233. | PNG_MMX_READ_FLAGS \
  161234. | PNG_MMX_WRITE_FLAGS )
  161235. #define PNG_SELECT_READ 1
  161236. #define PNG_SELECT_WRITE 2
  161237. #endif /* PNG_MMX_CODE_SUPPORTED */
  161238. #if !defined(PNG_1_0_X)
  161239. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161240. PNGARG((int flag_select, int *compilerID));
  161241. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161242. PNGARG((int flag_select));
  161243. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161244. PNGARG((png_structp png_ptr));
  161245. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161246. PNGARG((png_structp png_ptr));
  161247. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161248. PNGARG((png_structp png_ptr));
  161249. extern PNG_EXPORT(void,png_set_asm_flags)
  161250. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161251. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161252. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161253. png_uint_32 mmx_rowbytes_threshold));
  161254. #endif /* PNG_1_0_X */
  161255. #if !defined(PNG_1_0_X)
  161256. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161257. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161258. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161259. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161260. png_ptr, png_uint_32 strip_mode));
  161261. #endif
  161262. #endif /* PNG_1_0_X */
  161263. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161264. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161265. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161266. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161267. png_ptr));
  161268. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161269. png_ptr));
  161270. #endif
  161271. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161272. # define png_composite(composite, fg, alpha, bg) \
  161273. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161274. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161275. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161276. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161277. # define png_composite_16(composite, fg, alpha, bg) \
  161278. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161279. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161280. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161281. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161282. #else /* standard method using integer division */
  161283. # define png_composite(composite, fg, alpha, bg) \
  161284. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161285. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161286. (png_uint_16)127) / 255)
  161287. # define png_composite_16(composite, fg, alpha, bg) \
  161288. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161289. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161290. (png_uint_32)32767) / (png_uint_32)65535L)
  161291. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161292. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161293. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161294. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161295. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161296. #else
  161297. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161298. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161299. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161300. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161301. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161302. PNGARG((png_structp png_ptr, png_bytep buf));
  161303. extern PNG_EXPORT(void,png_save_uint_32)
  161304. PNGARG((png_bytep buf, png_uint_32 i));
  161305. extern PNG_EXPORT(void,png_save_int_32)
  161306. PNGARG((png_bytep buf, png_int_32 i));
  161307. extern PNG_EXPORT(void,png_save_uint_16)
  161308. PNGARG((png_bytep buf, unsigned int i));
  161309. #define PNG_HAVE_IHDR 0x01
  161310. #define PNG_HAVE_PLTE 0x02
  161311. #define PNG_HAVE_IDAT 0x04
  161312. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161313. #define PNG_HAVE_IEND 0x10
  161314. #if defined(PNG_INTERNAL)
  161315. #define PNG_HAVE_gAMA 0x20
  161316. #define PNG_HAVE_cHRM 0x40
  161317. #define PNG_HAVE_sRGB 0x80
  161318. #define PNG_HAVE_CHUNK_HEADER 0x100
  161319. #define PNG_WROTE_tIME 0x200
  161320. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161321. #define PNG_BACKGROUND_IS_GRAY 0x800
  161322. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161323. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161324. #define PNG_BGR 0x0001
  161325. #define PNG_INTERLACE 0x0002
  161326. #define PNG_PACK 0x0004
  161327. #define PNG_SHIFT 0x0008
  161328. #define PNG_SWAP_BYTES 0x0010
  161329. #define PNG_INVERT_MONO 0x0020
  161330. #define PNG_DITHER 0x0040
  161331. #define PNG_BACKGROUND 0x0080
  161332. #define PNG_BACKGROUND_EXPAND 0x0100
  161333. #define PNG_16_TO_8 0x0400
  161334. #define PNG_RGBA 0x0800
  161335. #define PNG_EXPAND 0x1000
  161336. #define PNG_GAMMA 0x2000
  161337. #define PNG_GRAY_TO_RGB 0x4000
  161338. #define PNG_FILLER 0x8000L
  161339. #define PNG_PACKSWAP 0x10000L
  161340. #define PNG_SWAP_ALPHA 0x20000L
  161341. #define PNG_STRIP_ALPHA 0x40000L
  161342. #define PNG_INVERT_ALPHA 0x80000L
  161343. #define PNG_USER_TRANSFORM 0x100000L
  161344. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161345. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161346. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161347. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161348. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161349. #define PNG_STRUCT_PNG 0x0001
  161350. #define PNG_STRUCT_INFO 0x0002
  161351. #define PNG_WEIGHT_SHIFT 8
  161352. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161353. #define PNG_COST_SHIFT 3
  161354. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161355. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161356. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161357. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161358. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161359. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161360. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161361. #define PNG_FLAG_ROW_INIT 0x0040
  161362. #define PNG_FLAG_FILLER_AFTER 0x0080
  161363. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161364. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161365. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161366. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161367. #define PNG_FLAG_FREE_PLTE 0x1000
  161368. #define PNG_FLAG_FREE_TRNS 0x2000
  161369. #define PNG_FLAG_FREE_HIST 0x4000
  161370. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161371. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161372. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161373. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161374. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161375. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161376. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161377. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161378. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161379. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161380. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161381. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161382. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161383. PNG_FLAG_CRC_CRITICAL_MASK)
  161384. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161385. abs((int)((c1).green) - (int)((c2).green)) + \
  161386. abs((int)((c1).blue) - (int)((c2).blue)))
  161387. #define PNG_ROWBYTES(pixel_bits, width) \
  161388. ((pixel_bits) >= 8 ? \
  161389. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161390. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161391. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161392. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161393. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161394. #ifdef PNG_USE_GLOBAL_ARRAYS
  161395. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161396. #else
  161397. #endif
  161398. #endif /* PNG_NO_EXTERN */
  161399. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161400. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161401. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161402. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161403. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161404. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161405. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161406. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161407. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161408. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161409. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161410. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161411. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161412. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161413. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161414. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161415. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161416. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161417. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161418. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161419. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161420. #ifdef PNG_USE_GLOBAL_ARRAYS
  161421. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161422. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161423. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161424. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161425. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161426. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161427. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161428. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161429. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161430. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161431. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161432. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161433. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161434. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161435. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161436. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161437. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161438. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161439. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161440. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161441. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161442. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161443. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161444. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161445. #undef png_read_init
  161446. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161447. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161448. #endif
  161449. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161450. png_const_charp user_png_ver, png_size_t png_struct_size));
  161451. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161452. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161453. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161454. png_info_size));
  161455. #endif
  161456. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161457. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161458. #undef png_write_init
  161459. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161460. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161461. #endif
  161462. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161463. png_const_charp user_png_ver, png_size_t png_struct_size));
  161464. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161465. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161466. png_info_size));
  161467. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161468. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161469. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161470. malloc_fn, png_voidp mem_ptr));
  161471. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161472. png_free_ptr free_fn, png_voidp mem_ptr));
  161473. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161474. png_infop info_ptr));
  161475. #ifndef PNG_1_0_X
  161476. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161477. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161478. #ifdef PNG_SIZE_T
  161479. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161480. #endif
  161481. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161482. png_bytep data, png_size_t length));
  161483. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161484. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161485. png_bytep buffer, png_size_t length));
  161486. #endif
  161487. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161488. png_bytep data, png_size_t length));
  161489. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161490. #if !defined(PNG_NO_STDIO)
  161491. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161492. #endif
  161493. #endif
  161494. #else /* PNG_1_0_X */
  161495. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161496. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161497. png_bytep buffer, png_size_t length));
  161498. #endif
  161499. #endif /* PNG_1_0_X */
  161500. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161501. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161502. png_size_t length));
  161503. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161504. png_size_t length));
  161505. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161506. png_size_t length));
  161507. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161508. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161509. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161510. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161511. png_size_t prefix_length, png_size_t *data_length));
  161512. #endif
  161513. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161514. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161515. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161516. png_size_t length));
  161517. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161518. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161519. #endif
  161520. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161521. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161522. png_uint_32 height,
  161523. int bit_depth, int color_type, int compression_method, int filter_method,
  161524. int interlace_method));
  161525. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161526. png_uint_32 num_pal));
  161527. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161528. png_size_t length));
  161529. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161530. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161531. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161532. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161533. #endif
  161534. #ifdef PNG_FIXED_POINT_SUPPORTED
  161535. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161536. file_gamma));
  161537. #endif
  161538. #endif
  161539. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161540. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161541. int color_type));
  161542. #endif
  161543. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161544. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161545. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161546. double white_x, double white_y,
  161547. double red_x, double red_y, double green_x, double green_y,
  161548. double blue_x, double blue_y));
  161549. #endif
  161550. #ifdef PNG_FIXED_POINT_SUPPORTED
  161551. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161552. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161553. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161554. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161555. png_fixed_point int_blue_y));
  161556. #endif
  161557. #endif
  161558. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161559. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161560. int intent));
  161561. #endif
  161562. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161563. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161564. png_charp name, int compression_type,
  161565. png_charp profile, int proflen));
  161566. #endif
  161567. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161568. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161569. png_sPLT_tp palette));
  161570. #endif
  161571. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161572. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161573. png_color_16p values, int number, int color_type));
  161574. #endif
  161575. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161576. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161577. png_color_16p values, int color_type));
  161578. #endif
  161579. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161580. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161581. int num_hist));
  161582. #endif
  161583. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161584. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161585. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161586. png_charp key, png_charpp new_key));
  161587. #endif
  161588. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161589. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161590. png_charp text, png_size_t text_len));
  161591. #endif
  161592. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161593. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161594. png_charp text, png_size_t text_len, int compression));
  161595. #endif
  161596. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161597. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161598. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161599. png_charp text));
  161600. #endif
  161601. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161602. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161603. png_infop info_ptr, png_textp text_ptr, int num_text));
  161604. #endif
  161605. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161606. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161607. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161608. #endif
  161609. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161610. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161611. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161612. png_charp units, png_charpp params));
  161613. #endif
  161614. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161615. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161616. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161617. int unit_type));
  161618. #endif
  161619. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161620. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161621. png_timep mod_time));
  161622. #endif
  161623. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161624. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161625. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161626. int unit, double width, double height));
  161627. #else
  161628. #ifdef PNG_FIXED_POINT_SUPPORTED
  161629. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161630. int unit, png_charp width, png_charp height));
  161631. #endif
  161632. #endif
  161633. #endif
  161634. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161635. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161636. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161637. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161638. #endif
  161639. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161640. int mask));
  161641. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161642. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161643. #endif
  161644. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161645. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161646. png_bytep row, int pass));
  161647. #endif
  161648. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161649. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161650. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161651. png_row_infop row_info));
  161652. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161653. png_bytep filtered_row));
  161654. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161655. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161656. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161657. png_infop info_ptr));
  161658. #if defined(PNG_READ_FILLER_SUPPORTED)
  161659. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161660. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161661. #endif
  161662. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161663. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161664. png_bytep row));
  161665. #endif
  161666. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161667. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161668. png_bytep row));
  161669. #endif
  161670. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161671. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161672. png_bytep row));
  161673. #endif
  161674. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161675. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161676. png_bytep row));
  161677. #endif
  161678. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161679. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161680. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161681. png_bytep row, png_uint_32 flags));
  161682. #endif
  161683. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161684. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161685. #endif
  161686. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161687. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161688. #endif
  161689. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161690. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161691. row_info, png_bytep row));
  161692. #endif
  161693. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161694. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161695. png_bytep row));
  161696. #endif
  161697. #if defined(PNG_READ_PACK_SUPPORTED)
  161698. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161699. #endif
  161700. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161701. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161702. png_color_8p sig_bits));
  161703. #endif
  161704. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161705. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  161706. #endif
  161707. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161708. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  161709. #endif
  161710. #if defined(PNG_READ_DITHER_SUPPORTED)
  161711. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  161712. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  161713. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  161714. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  161715. png_colorp palette, int num_palette));
  161716. # endif
  161717. #endif
  161718. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161719. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  161720. #endif
  161721. #if defined(PNG_WRITE_PACK_SUPPORTED)
  161722. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  161723. png_bytep row, png_uint_32 bit_depth));
  161724. #endif
  161725. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  161726. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  161727. png_color_8p bit_depth));
  161728. #endif
  161729. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161730. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161731. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161732. png_color_16p trans_values, png_color_16p background,
  161733. png_color_16p background_1,
  161734. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  161735. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  161736. png_uint_16pp gamma_16_to_1, int gamma_shift));
  161737. #else
  161738. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161739. png_color_16p trans_values, png_color_16p background));
  161740. #endif
  161741. #endif
  161742. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161743. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  161744. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  161745. int gamma_shift));
  161746. #endif
  161747. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161748. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  161749. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  161750. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  161751. png_bytep row, png_color_16p trans_value));
  161752. #endif
  161753. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  161754. png_uint_32 length));
  161755. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  161756. png_uint_32 length));
  161757. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  161758. png_uint_32 length));
  161759. #if defined(PNG_READ_bKGD_SUPPORTED)
  161760. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  161761. png_uint_32 length));
  161762. #endif
  161763. #if defined(PNG_READ_cHRM_SUPPORTED)
  161764. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  161765. png_uint_32 length));
  161766. #endif
  161767. #if defined(PNG_READ_gAMA_SUPPORTED)
  161768. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  161769. png_uint_32 length));
  161770. #endif
  161771. #if defined(PNG_READ_hIST_SUPPORTED)
  161772. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  161773. png_uint_32 length));
  161774. #endif
  161775. #if defined(PNG_READ_iCCP_SUPPORTED)
  161776. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  161777. png_uint_32 length));
  161778. #endif /* PNG_READ_iCCP_SUPPORTED */
  161779. #if defined(PNG_READ_iTXt_SUPPORTED)
  161780. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161781. png_uint_32 length));
  161782. #endif
  161783. #if defined(PNG_READ_oFFs_SUPPORTED)
  161784. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161785. png_uint_32 length));
  161786. #endif
  161787. #if defined(PNG_READ_pCAL_SUPPORTED)
  161788. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161789. png_uint_32 length));
  161790. #endif
  161791. #if defined(PNG_READ_pHYs_SUPPORTED)
  161792. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161793. png_uint_32 length));
  161794. #endif
  161795. #if defined(PNG_READ_sBIT_SUPPORTED)
  161796. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  161797. png_uint_32 length));
  161798. #endif
  161799. #if defined(PNG_READ_sCAL_SUPPORTED)
  161800. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161801. png_uint_32 length));
  161802. #endif
  161803. #if defined(PNG_READ_sPLT_SUPPORTED)
  161804. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  161805. png_uint_32 length));
  161806. #endif /* PNG_READ_sPLT_SUPPORTED */
  161807. #if defined(PNG_READ_sRGB_SUPPORTED)
  161808. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  161809. png_uint_32 length));
  161810. #endif
  161811. #if defined(PNG_READ_tEXt_SUPPORTED)
  161812. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161813. png_uint_32 length));
  161814. #endif
  161815. #if defined(PNG_READ_tIME_SUPPORTED)
  161816. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  161817. png_uint_32 length));
  161818. #endif
  161819. #if defined(PNG_READ_tRNS_SUPPORTED)
  161820. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  161821. png_uint_32 length));
  161822. #endif
  161823. #if defined(PNG_READ_zTXt_SUPPORTED)
  161824. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161825. png_uint_32 length));
  161826. #endif
  161827. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  161828. png_infop info_ptr, png_uint_32 length));
  161829. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  161830. png_bytep chunk_name));
  161831. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  161832. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  161833. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  161834. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161835. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  161836. png_infop info_ptr));
  161837. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  161838. png_infop info_ptr));
  161839. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  161840. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  161841. png_uint_32 length));
  161842. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  161843. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  161844. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  161845. png_bytep buffer, png_size_t buffer_length));
  161846. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  161847. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  161848. png_bytep buffer, png_size_t buffer_length));
  161849. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  161850. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  161851. png_infop info_ptr, png_uint_32 length));
  161852. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  161853. png_infop info_ptr));
  161854. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  161855. png_infop info_ptr));
  161856. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  161857. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  161858. png_infop info_ptr));
  161859. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  161860. png_infop info_ptr));
  161861. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  161862. #if defined(PNG_READ_tEXt_SUPPORTED)
  161863. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  161864. png_infop info_ptr, png_uint_32 length));
  161865. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  161866. png_infop info_ptr));
  161867. #endif
  161868. #if defined(PNG_READ_zTXt_SUPPORTED)
  161869. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  161870. png_infop info_ptr, png_uint_32 length));
  161871. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  161872. png_infop info_ptr));
  161873. #endif
  161874. #if defined(PNG_READ_iTXt_SUPPORTED)
  161875. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  161876. png_infop info_ptr, png_uint_32 length));
  161877. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  161878. png_infop info_ptr));
  161879. #endif
  161880. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161881. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161882. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  161883. png_bytep row));
  161884. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  161885. png_bytep row));
  161886. #endif
  161887. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161888. #if defined(PNG_MMX_CODE_SUPPORTED)
  161889. /* PRIVATE */
  161890. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  161891. #endif
  161892. #endif
  161893. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  161894. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  161895. png_infop info_ptr));
  161896. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  161897. png_infop info_ptr));
  161898. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  161899. png_infop info_ptr));
  161900. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  161901. png_infop info_ptr));
  161902. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  161903. png_infop info_ptr));
  161904. #if defined(PNG_pHYs_SUPPORTED)
  161905. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  161906. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161907. #endif /* PNG_pHYs_SUPPORTED */
  161908. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  161909. #endif /* PNG_INTERNAL */
  161910. #ifdef __cplusplus
  161911. }
  161912. #endif
  161913. #endif /* PNG_VERSION_INFO_ONLY */
  161914. #endif /* PNG_H */
  161915. /*** End of inlined file: png.h ***/
  161916. #define PNG_NO_EXTERN
  161917. /*** Start of inlined file: png.c ***/
  161918. #define PNG_INTERNAL
  161919. #define PNG_NO_EXTERN
  161920. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  161921. #ifdef PNG_USE_GLOBAL_ARRAYS
  161922. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  161923. #ifdef PNG_READ_SUPPORTED
  161924. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  161925. #endif /* PNG_READ_SUPPORTED */
  161926. PNG_IHDR;
  161927. PNG_IDAT;
  161928. PNG_IEND;
  161929. PNG_PLTE;
  161930. PNG_bKGD;
  161931. PNG_cHRM;
  161932. PNG_gAMA;
  161933. PNG_hIST;
  161934. PNG_iCCP;
  161935. PNG_iTXt;
  161936. PNG_oFFs;
  161937. PNG_pCAL;
  161938. PNG_sCAL;
  161939. PNG_pHYs;
  161940. PNG_sBIT;
  161941. PNG_sPLT;
  161942. PNG_sRGB;
  161943. PNG_tEXt;
  161944. PNG_tIME;
  161945. PNG_tRNS;
  161946. PNG_zTXt;
  161947. #ifdef PNG_READ_SUPPORTED
  161948. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  161949. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  161950. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  161951. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  161952. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  161953. PNG_CONST int FARDATA png_pass_dsp_mask[]
  161954. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  161955. #endif /* PNG_READ_SUPPORTED */
  161956. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161957. #ifdef PNG_READ_SUPPORTED
  161958. void PNGAPI
  161959. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  161960. {
  161961. if(png_ptr == NULL) return;
  161962. png_debug(1, "in png_set_sig_bytes\n");
  161963. if (num_bytes > 8)
  161964. png_error(png_ptr, "Too many bytes for PNG signature.");
  161965. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  161966. }
  161967. int PNGAPI
  161968. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  161969. {
  161970. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  161971. if (num_to_check > 8)
  161972. num_to_check = 8;
  161973. else if (num_to_check < 1)
  161974. return (-1);
  161975. if (start > 7)
  161976. return (-1);
  161977. if (start + num_to_check > 8)
  161978. num_to_check = 8 - start;
  161979. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  161980. }
  161981. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  161982. int PNGAPI
  161983. png_check_sig(png_bytep sig, int num)
  161984. {
  161985. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  161986. }
  161987. #endif
  161988. #endif /* PNG_READ_SUPPORTED */
  161989. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  161990. #ifdef PNG_1_0_X
  161991. voidpf PNGAPI
  161992. #else
  161993. voidpf /* private */
  161994. #endif
  161995. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  161996. {
  161997. png_voidp ptr;
  161998. png_structp p=(png_structp)png_ptr;
  161999. png_uint_32 save_flags=p->flags;
  162000. png_uint_32 num_bytes;
  162001. if(png_ptr == NULL) return (NULL);
  162002. if (items > PNG_UINT_32_MAX/size)
  162003. {
  162004. png_warning (p, "Potential overflow in png_zalloc()");
  162005. return (NULL);
  162006. }
  162007. num_bytes = (png_uint_32)items * size;
  162008. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162009. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162010. p->flags=save_flags;
  162011. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162012. if (ptr == NULL)
  162013. return ((voidpf)ptr);
  162014. if (num_bytes > (png_uint_32)0x8000L)
  162015. {
  162016. png_memset(ptr, 0, (png_size_t)0x8000L);
  162017. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162018. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162019. }
  162020. else
  162021. {
  162022. png_memset(ptr, 0, (png_size_t)num_bytes);
  162023. }
  162024. #endif
  162025. return ((voidpf)ptr);
  162026. }
  162027. #ifdef PNG_1_0_X
  162028. void PNGAPI
  162029. #else
  162030. void /* private */
  162031. #endif
  162032. png_zfree(voidpf png_ptr, voidpf ptr)
  162033. {
  162034. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162035. }
  162036. void /* PRIVATE */
  162037. png_reset_crc(png_structp png_ptr)
  162038. {
  162039. png_ptr->crc = crc32(0, Z_NULL, 0);
  162040. }
  162041. void /* PRIVATE */
  162042. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162043. {
  162044. int need_crc = 1;
  162045. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162046. {
  162047. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162048. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162049. need_crc = 0;
  162050. }
  162051. else /* critical */
  162052. {
  162053. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162054. need_crc = 0;
  162055. }
  162056. if (need_crc)
  162057. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162058. }
  162059. png_infop PNGAPI
  162060. png_create_info_struct(png_structp png_ptr)
  162061. {
  162062. png_infop info_ptr;
  162063. png_debug(1, "in png_create_info_struct\n");
  162064. if(png_ptr == NULL) return (NULL);
  162065. #ifdef PNG_USER_MEM_SUPPORTED
  162066. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162067. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162068. #else
  162069. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162070. #endif
  162071. if (info_ptr != NULL)
  162072. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162073. return (info_ptr);
  162074. }
  162075. void PNGAPI
  162076. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162077. {
  162078. png_infop info_ptr = NULL;
  162079. if(png_ptr == NULL) return;
  162080. png_debug(1, "in png_destroy_info_struct\n");
  162081. if (info_ptr_ptr != NULL)
  162082. info_ptr = *info_ptr_ptr;
  162083. if (info_ptr != NULL)
  162084. {
  162085. png_info_destroy(png_ptr, info_ptr);
  162086. #ifdef PNG_USER_MEM_SUPPORTED
  162087. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162088. png_ptr->mem_ptr);
  162089. #else
  162090. png_destroy_struct((png_voidp)info_ptr);
  162091. #endif
  162092. *info_ptr_ptr = NULL;
  162093. }
  162094. }
  162095. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162096. #undef png_info_init
  162097. void PNGAPI
  162098. png_info_init(png_infop info_ptr)
  162099. {
  162100. png_info_init_3(&info_ptr, 0);
  162101. }
  162102. #endif
  162103. void PNGAPI
  162104. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162105. {
  162106. png_infop info_ptr = *ptr_ptr;
  162107. if(info_ptr == NULL) return;
  162108. png_debug(1, "in png_info_init_3\n");
  162109. if(png_sizeof(png_info) > png_info_struct_size)
  162110. {
  162111. png_destroy_struct(info_ptr);
  162112. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162113. *ptr_ptr = info_ptr;
  162114. }
  162115. png_memset(info_ptr, 0, png_sizeof (png_info));
  162116. }
  162117. #ifdef PNG_FREE_ME_SUPPORTED
  162118. void PNGAPI
  162119. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162120. int freer, png_uint_32 mask)
  162121. {
  162122. png_debug(1, "in png_data_freer\n");
  162123. if (png_ptr == NULL || info_ptr == NULL)
  162124. return;
  162125. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162126. info_ptr->free_me |= mask;
  162127. else if(freer == PNG_USER_WILL_FREE_DATA)
  162128. info_ptr->free_me &= ~mask;
  162129. else
  162130. png_warning(png_ptr,
  162131. "Unknown freer parameter in png_data_freer.");
  162132. }
  162133. #endif
  162134. void PNGAPI
  162135. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162136. int num)
  162137. {
  162138. png_debug(1, "in png_free_data\n");
  162139. if (png_ptr == NULL || info_ptr == NULL)
  162140. return;
  162141. #if defined(PNG_TEXT_SUPPORTED)
  162142. #ifdef PNG_FREE_ME_SUPPORTED
  162143. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162144. #else
  162145. if (mask & PNG_FREE_TEXT)
  162146. #endif
  162147. {
  162148. if (num != -1)
  162149. {
  162150. if (info_ptr->text && info_ptr->text[num].key)
  162151. {
  162152. png_free(png_ptr, info_ptr->text[num].key);
  162153. info_ptr->text[num].key = NULL;
  162154. }
  162155. }
  162156. else
  162157. {
  162158. int i;
  162159. for (i = 0; i < info_ptr->num_text; i++)
  162160. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162161. png_free(png_ptr, info_ptr->text);
  162162. info_ptr->text = NULL;
  162163. info_ptr->num_text=0;
  162164. }
  162165. }
  162166. #endif
  162167. #if defined(PNG_tRNS_SUPPORTED)
  162168. #ifdef PNG_FREE_ME_SUPPORTED
  162169. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162170. #else
  162171. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162172. #endif
  162173. {
  162174. png_free(png_ptr, info_ptr->trans);
  162175. info_ptr->valid &= ~PNG_INFO_tRNS;
  162176. #ifndef PNG_FREE_ME_SUPPORTED
  162177. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162178. #endif
  162179. info_ptr->trans = NULL;
  162180. }
  162181. #endif
  162182. #if defined(PNG_sCAL_SUPPORTED)
  162183. #ifdef PNG_FREE_ME_SUPPORTED
  162184. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162185. #else
  162186. if (mask & PNG_FREE_SCAL)
  162187. #endif
  162188. {
  162189. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162190. png_free(png_ptr, info_ptr->scal_s_width);
  162191. png_free(png_ptr, info_ptr->scal_s_height);
  162192. info_ptr->scal_s_width = NULL;
  162193. info_ptr->scal_s_height = NULL;
  162194. #endif
  162195. info_ptr->valid &= ~PNG_INFO_sCAL;
  162196. }
  162197. #endif
  162198. #if defined(PNG_pCAL_SUPPORTED)
  162199. #ifdef PNG_FREE_ME_SUPPORTED
  162200. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162201. #else
  162202. if (mask & PNG_FREE_PCAL)
  162203. #endif
  162204. {
  162205. png_free(png_ptr, info_ptr->pcal_purpose);
  162206. png_free(png_ptr, info_ptr->pcal_units);
  162207. info_ptr->pcal_purpose = NULL;
  162208. info_ptr->pcal_units = NULL;
  162209. if (info_ptr->pcal_params != NULL)
  162210. {
  162211. int i;
  162212. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162213. {
  162214. png_free(png_ptr, info_ptr->pcal_params[i]);
  162215. info_ptr->pcal_params[i]=NULL;
  162216. }
  162217. png_free(png_ptr, info_ptr->pcal_params);
  162218. info_ptr->pcal_params = NULL;
  162219. }
  162220. info_ptr->valid &= ~PNG_INFO_pCAL;
  162221. }
  162222. #endif
  162223. #if defined(PNG_iCCP_SUPPORTED)
  162224. #ifdef PNG_FREE_ME_SUPPORTED
  162225. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162226. #else
  162227. if (mask & PNG_FREE_ICCP)
  162228. #endif
  162229. {
  162230. png_free(png_ptr, info_ptr->iccp_name);
  162231. png_free(png_ptr, info_ptr->iccp_profile);
  162232. info_ptr->iccp_name = NULL;
  162233. info_ptr->iccp_profile = NULL;
  162234. info_ptr->valid &= ~PNG_INFO_iCCP;
  162235. }
  162236. #endif
  162237. #if defined(PNG_sPLT_SUPPORTED)
  162238. #ifdef PNG_FREE_ME_SUPPORTED
  162239. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162240. #else
  162241. if (mask & PNG_FREE_SPLT)
  162242. #endif
  162243. {
  162244. if (num != -1)
  162245. {
  162246. if(info_ptr->splt_palettes)
  162247. {
  162248. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162249. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162250. info_ptr->splt_palettes[num].name = NULL;
  162251. info_ptr->splt_palettes[num].entries = NULL;
  162252. }
  162253. }
  162254. else
  162255. {
  162256. if(info_ptr->splt_palettes_num)
  162257. {
  162258. int i;
  162259. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162260. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162261. png_free(png_ptr, info_ptr->splt_palettes);
  162262. info_ptr->splt_palettes = NULL;
  162263. info_ptr->splt_palettes_num = 0;
  162264. }
  162265. info_ptr->valid &= ~PNG_INFO_sPLT;
  162266. }
  162267. }
  162268. #endif
  162269. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162270. if(png_ptr->unknown_chunk.data)
  162271. {
  162272. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162273. png_ptr->unknown_chunk.data = NULL;
  162274. }
  162275. #ifdef PNG_FREE_ME_SUPPORTED
  162276. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162277. #else
  162278. if (mask & PNG_FREE_UNKN)
  162279. #endif
  162280. {
  162281. if (num != -1)
  162282. {
  162283. if(info_ptr->unknown_chunks)
  162284. {
  162285. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162286. info_ptr->unknown_chunks[num].data = NULL;
  162287. }
  162288. }
  162289. else
  162290. {
  162291. int i;
  162292. if(info_ptr->unknown_chunks_num)
  162293. {
  162294. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162295. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162296. png_free(png_ptr, info_ptr->unknown_chunks);
  162297. info_ptr->unknown_chunks = NULL;
  162298. info_ptr->unknown_chunks_num = 0;
  162299. }
  162300. }
  162301. }
  162302. #endif
  162303. #if defined(PNG_hIST_SUPPORTED)
  162304. #ifdef PNG_FREE_ME_SUPPORTED
  162305. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162306. #else
  162307. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162308. #endif
  162309. {
  162310. png_free(png_ptr, info_ptr->hist);
  162311. info_ptr->hist = NULL;
  162312. info_ptr->valid &= ~PNG_INFO_hIST;
  162313. #ifndef PNG_FREE_ME_SUPPORTED
  162314. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162315. #endif
  162316. }
  162317. #endif
  162318. #ifdef PNG_FREE_ME_SUPPORTED
  162319. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162320. #else
  162321. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162322. #endif
  162323. {
  162324. png_zfree(png_ptr, info_ptr->palette);
  162325. info_ptr->palette = NULL;
  162326. info_ptr->valid &= ~PNG_INFO_PLTE;
  162327. #ifndef PNG_FREE_ME_SUPPORTED
  162328. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162329. #endif
  162330. info_ptr->num_palette = 0;
  162331. }
  162332. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162333. #ifdef PNG_FREE_ME_SUPPORTED
  162334. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162335. #else
  162336. if (mask & PNG_FREE_ROWS)
  162337. #endif
  162338. {
  162339. if(info_ptr->row_pointers)
  162340. {
  162341. int row;
  162342. for (row = 0; row < (int)info_ptr->height; row++)
  162343. {
  162344. png_free(png_ptr, info_ptr->row_pointers[row]);
  162345. info_ptr->row_pointers[row]=NULL;
  162346. }
  162347. png_free(png_ptr, info_ptr->row_pointers);
  162348. info_ptr->row_pointers=NULL;
  162349. }
  162350. info_ptr->valid &= ~PNG_INFO_IDAT;
  162351. }
  162352. #endif
  162353. #ifdef PNG_FREE_ME_SUPPORTED
  162354. if(num == -1)
  162355. info_ptr->free_me &= ~mask;
  162356. else
  162357. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162358. #endif
  162359. }
  162360. void /* PRIVATE */
  162361. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162362. {
  162363. png_debug(1, "in png_info_destroy\n");
  162364. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162365. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162366. if (png_ptr->num_chunk_list)
  162367. {
  162368. png_free(png_ptr, png_ptr->chunk_list);
  162369. png_ptr->chunk_list=NULL;
  162370. png_ptr->num_chunk_list=0;
  162371. }
  162372. #endif
  162373. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162374. }
  162375. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162376. png_voidp PNGAPI
  162377. png_get_io_ptr(png_structp png_ptr)
  162378. {
  162379. if(png_ptr == NULL) return (NULL);
  162380. return (png_ptr->io_ptr);
  162381. }
  162382. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162383. #if !defined(PNG_NO_STDIO)
  162384. void PNGAPI
  162385. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162386. {
  162387. png_debug(1, "in png_init_io\n");
  162388. if(png_ptr == NULL) return;
  162389. png_ptr->io_ptr = (png_voidp)fp;
  162390. }
  162391. #endif
  162392. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162393. png_charp PNGAPI
  162394. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162395. {
  162396. static PNG_CONST char short_months[12][4] =
  162397. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162398. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162399. if(png_ptr == NULL) return (NULL);
  162400. if (png_ptr->time_buffer == NULL)
  162401. {
  162402. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162403. png_sizeof(char)));
  162404. }
  162405. #if defined(_WIN32_WCE)
  162406. {
  162407. wchar_t time_buf[29];
  162408. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162409. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162410. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162411. ptime->second % 61);
  162412. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162413. NULL, NULL);
  162414. }
  162415. #else
  162416. #ifdef USE_FAR_KEYWORD
  162417. {
  162418. char near_time_buf[29];
  162419. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162420. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162421. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162422. ptime->second % 61);
  162423. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162424. 29*png_sizeof(char));
  162425. }
  162426. #else
  162427. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162428. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162429. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162430. ptime->second % 61);
  162431. #endif
  162432. #endif /* _WIN32_WCE */
  162433. return ((png_charp)png_ptr->time_buffer);
  162434. }
  162435. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162436. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162437. png_charp PNGAPI
  162438. png_get_copyright(png_structp png_ptr)
  162439. {
  162440. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162441. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162442. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162443. Copyright (c) 1996-1997 Andreas Dilger\n\
  162444. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162445. }
  162446. png_charp PNGAPI
  162447. png_get_libpng_ver(png_structp png_ptr)
  162448. {
  162449. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162450. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162451. }
  162452. png_charp PNGAPI
  162453. png_get_header_ver(png_structp png_ptr)
  162454. {
  162455. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162456. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162457. }
  162458. png_charp PNGAPI
  162459. png_get_header_version(png_structp png_ptr)
  162460. {
  162461. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162462. return ((png_charp) PNG_HEADER_VERSION_STRING
  162463. #ifndef PNG_READ_SUPPORTED
  162464. " (NO READ SUPPORT)"
  162465. #endif
  162466. "\n");
  162467. }
  162468. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162469. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162470. int PNGAPI
  162471. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162472. {
  162473. int i;
  162474. png_bytep p;
  162475. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162476. return 0;
  162477. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162478. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162479. if (!png_memcmp(chunk_name, p, 4))
  162480. return ((int)*(p+4));
  162481. return 0;
  162482. }
  162483. #endif
  162484. int PNGAPI
  162485. png_reset_zstream(png_structp png_ptr)
  162486. {
  162487. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162488. return (inflateReset(&png_ptr->zstream));
  162489. }
  162490. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162491. png_uint_32 PNGAPI
  162492. png_access_version_number(void)
  162493. {
  162494. return((png_uint_32) PNG_LIBPNG_VER);
  162495. }
  162496. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162497. #if !defined(PNG_1_0_X)
  162498. int PNGAPI
  162499. png_mmx_support(void)
  162500. {
  162501. return -1;
  162502. }
  162503. #endif /* PNG_1_0_X */
  162504. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162505. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162506. #ifdef PNG_SIZE_T
  162507. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162508. png_size_t PNGAPI
  162509. png_convert_size(size_t size)
  162510. {
  162511. if (size > (png_size_t)-1)
  162512. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162513. return ((png_size_t)size);
  162514. }
  162515. #endif /* PNG_SIZE_T */
  162516. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162517. /*** End of inlined file: png.c ***/
  162518. /*** Start of inlined file: pngerror.c ***/
  162519. #define PNG_INTERNAL
  162520. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162521. static void /* PRIVATE */
  162522. png_default_error PNGARG((png_structp png_ptr,
  162523. png_const_charp error_message));
  162524. #ifndef PNG_NO_WARNINGS
  162525. static void /* PRIVATE */
  162526. png_default_warning PNGARG((png_structp png_ptr,
  162527. png_const_charp warning_message));
  162528. #endif /* PNG_NO_WARNINGS */
  162529. #ifndef PNG_NO_ERROR_TEXT
  162530. void PNGAPI
  162531. png_error(png_structp png_ptr, png_const_charp error_message)
  162532. {
  162533. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162534. char msg[16];
  162535. if (png_ptr != NULL)
  162536. {
  162537. if (png_ptr->flags&
  162538. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162539. {
  162540. if (*error_message == '#')
  162541. {
  162542. int offset;
  162543. for (offset=1; offset<15; offset++)
  162544. if (*(error_message+offset) == ' ')
  162545. break;
  162546. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162547. {
  162548. int i;
  162549. for (i=0; i<offset-1; i++)
  162550. msg[i]=error_message[i+1];
  162551. msg[i]='\0';
  162552. error_message=msg;
  162553. }
  162554. else
  162555. error_message+=offset;
  162556. }
  162557. else
  162558. {
  162559. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162560. {
  162561. msg[0]='0';
  162562. msg[1]='\0';
  162563. error_message=msg;
  162564. }
  162565. }
  162566. }
  162567. }
  162568. #endif
  162569. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162570. (*(png_ptr->error_fn))(png_ptr, error_message);
  162571. png_default_error(png_ptr, error_message);
  162572. }
  162573. #else
  162574. void PNGAPI
  162575. png_err(png_structp png_ptr)
  162576. {
  162577. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162578. (*(png_ptr->error_fn))(png_ptr, '\0');
  162579. png_default_error(png_ptr, '\0');
  162580. }
  162581. #endif /* PNG_NO_ERROR_TEXT */
  162582. #ifndef PNG_NO_WARNINGS
  162583. void PNGAPI
  162584. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162585. {
  162586. int offset = 0;
  162587. if (png_ptr != NULL)
  162588. {
  162589. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162590. if (png_ptr->flags&
  162591. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162592. #endif
  162593. {
  162594. if (*warning_message == '#')
  162595. {
  162596. for (offset=1; offset<15; offset++)
  162597. if (*(warning_message+offset) == ' ')
  162598. break;
  162599. }
  162600. }
  162601. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162602. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162603. }
  162604. else
  162605. png_default_warning(png_ptr, warning_message+offset);
  162606. }
  162607. #endif /* PNG_NO_WARNINGS */
  162608. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162609. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162610. static void /* PRIVATE */
  162611. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162612. error_message)
  162613. {
  162614. int iout = 0, iin = 0;
  162615. while (iin < 4)
  162616. {
  162617. int c = png_ptr->chunk_name[iin++];
  162618. if (isnonalpha(c))
  162619. {
  162620. buffer[iout++] = '[';
  162621. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162622. buffer[iout++] = png_digit[c & 0x0f];
  162623. buffer[iout++] = ']';
  162624. }
  162625. else
  162626. {
  162627. buffer[iout++] = (png_byte)c;
  162628. }
  162629. }
  162630. if (error_message == NULL)
  162631. buffer[iout] = 0;
  162632. else
  162633. {
  162634. buffer[iout++] = ':';
  162635. buffer[iout++] = ' ';
  162636. png_strncpy(buffer+iout, error_message, 63);
  162637. buffer[iout+63] = 0;
  162638. }
  162639. }
  162640. #ifdef PNG_READ_SUPPORTED
  162641. void PNGAPI
  162642. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162643. {
  162644. char msg[18+64];
  162645. if (png_ptr == NULL)
  162646. png_error(png_ptr, error_message);
  162647. else
  162648. {
  162649. png_format_buffer(png_ptr, msg, error_message);
  162650. png_error(png_ptr, msg);
  162651. }
  162652. }
  162653. #endif /* PNG_READ_SUPPORTED */
  162654. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162655. #ifndef PNG_NO_WARNINGS
  162656. void PNGAPI
  162657. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162658. {
  162659. char msg[18+64];
  162660. if (png_ptr == NULL)
  162661. png_warning(png_ptr, warning_message);
  162662. else
  162663. {
  162664. png_format_buffer(png_ptr, msg, warning_message);
  162665. png_warning(png_ptr, msg);
  162666. }
  162667. }
  162668. #endif /* PNG_NO_WARNINGS */
  162669. static void /* PRIVATE */
  162670. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162671. {
  162672. #ifndef PNG_NO_CONSOLE_IO
  162673. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162674. if (*error_message == '#')
  162675. {
  162676. int offset;
  162677. char error_number[16];
  162678. for (offset=0; offset<15; offset++)
  162679. {
  162680. error_number[offset] = *(error_message+offset+1);
  162681. if (*(error_message+offset) == ' ')
  162682. break;
  162683. }
  162684. if((offset > 1) && (offset < 15))
  162685. {
  162686. error_number[offset-1]='\0';
  162687. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162688. error_message+offset);
  162689. }
  162690. else
  162691. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162692. }
  162693. else
  162694. #endif
  162695. fprintf(stderr, "libpng error: %s\n", error_message);
  162696. #endif
  162697. #ifdef PNG_SETJMP_SUPPORTED
  162698. if (png_ptr)
  162699. {
  162700. # ifdef USE_FAR_KEYWORD
  162701. {
  162702. jmp_buf jmpbuf;
  162703. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162704. longjmp(jmpbuf, 1);
  162705. }
  162706. # else
  162707. longjmp(png_ptr->jmpbuf, 1);
  162708. # endif
  162709. }
  162710. #else
  162711. PNG_ABORT();
  162712. #endif
  162713. #ifdef PNG_NO_CONSOLE_IO
  162714. error_message = error_message; /* make compiler happy */
  162715. #endif
  162716. }
  162717. #ifndef PNG_NO_WARNINGS
  162718. static void /* PRIVATE */
  162719. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  162720. {
  162721. #ifndef PNG_NO_CONSOLE_IO
  162722. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162723. if (*warning_message == '#')
  162724. {
  162725. int offset;
  162726. char warning_number[16];
  162727. for (offset=0; offset<15; offset++)
  162728. {
  162729. warning_number[offset]=*(warning_message+offset+1);
  162730. if (*(warning_message+offset) == ' ')
  162731. break;
  162732. }
  162733. if((offset > 1) && (offset < 15))
  162734. {
  162735. warning_number[offset-1]='\0';
  162736. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  162737. warning_message+offset);
  162738. }
  162739. else
  162740. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162741. }
  162742. else
  162743. # endif
  162744. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162745. #else
  162746. warning_message = warning_message; /* make compiler happy */
  162747. #endif
  162748. png_ptr = png_ptr; /* make compiler happy */
  162749. }
  162750. #endif /* PNG_NO_WARNINGS */
  162751. void PNGAPI
  162752. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  162753. png_error_ptr error_fn, png_error_ptr warning_fn)
  162754. {
  162755. if (png_ptr == NULL)
  162756. return;
  162757. png_ptr->error_ptr = error_ptr;
  162758. png_ptr->error_fn = error_fn;
  162759. png_ptr->warning_fn = warning_fn;
  162760. }
  162761. png_voidp PNGAPI
  162762. png_get_error_ptr(png_structp png_ptr)
  162763. {
  162764. if (png_ptr == NULL)
  162765. return NULL;
  162766. return ((png_voidp)png_ptr->error_ptr);
  162767. }
  162768. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162769. void PNGAPI
  162770. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  162771. {
  162772. if(png_ptr != NULL)
  162773. {
  162774. png_ptr->flags &=
  162775. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  162776. }
  162777. }
  162778. #endif
  162779. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  162780. /*** End of inlined file: pngerror.c ***/
  162781. /*** Start of inlined file: pngget.c ***/
  162782. #define PNG_INTERNAL
  162783. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162784. png_uint_32 PNGAPI
  162785. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  162786. {
  162787. if (png_ptr != NULL && info_ptr != NULL)
  162788. return(info_ptr->valid & flag);
  162789. else
  162790. return(0);
  162791. }
  162792. png_uint_32 PNGAPI
  162793. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  162794. {
  162795. if (png_ptr != NULL && info_ptr != NULL)
  162796. return(info_ptr->rowbytes);
  162797. else
  162798. return(0);
  162799. }
  162800. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162801. png_bytepp PNGAPI
  162802. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  162803. {
  162804. if (png_ptr != NULL && info_ptr != NULL)
  162805. return(info_ptr->row_pointers);
  162806. else
  162807. return(0);
  162808. }
  162809. #endif
  162810. #ifdef PNG_EASY_ACCESS_SUPPORTED
  162811. png_uint_32 PNGAPI
  162812. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  162813. {
  162814. if (png_ptr != NULL && info_ptr != NULL)
  162815. {
  162816. return info_ptr->width;
  162817. }
  162818. return (0);
  162819. }
  162820. png_uint_32 PNGAPI
  162821. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  162822. {
  162823. if (png_ptr != NULL && info_ptr != NULL)
  162824. {
  162825. return info_ptr->height;
  162826. }
  162827. return (0);
  162828. }
  162829. png_byte PNGAPI
  162830. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  162831. {
  162832. if (png_ptr != NULL && info_ptr != NULL)
  162833. {
  162834. return info_ptr->bit_depth;
  162835. }
  162836. return (0);
  162837. }
  162838. png_byte PNGAPI
  162839. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  162840. {
  162841. if (png_ptr != NULL && info_ptr != NULL)
  162842. {
  162843. return info_ptr->color_type;
  162844. }
  162845. return (0);
  162846. }
  162847. png_byte PNGAPI
  162848. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  162849. {
  162850. if (png_ptr != NULL && info_ptr != NULL)
  162851. {
  162852. return info_ptr->filter_type;
  162853. }
  162854. return (0);
  162855. }
  162856. png_byte PNGAPI
  162857. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  162858. {
  162859. if (png_ptr != NULL && info_ptr != NULL)
  162860. {
  162861. return info_ptr->interlace_type;
  162862. }
  162863. return (0);
  162864. }
  162865. png_byte PNGAPI
  162866. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  162867. {
  162868. if (png_ptr != NULL && info_ptr != NULL)
  162869. {
  162870. return info_ptr->compression_type;
  162871. }
  162872. return (0);
  162873. }
  162874. png_uint_32 PNGAPI
  162875. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  162876. {
  162877. if (png_ptr != NULL && info_ptr != NULL)
  162878. #if defined(PNG_pHYs_SUPPORTED)
  162879. if (info_ptr->valid & PNG_INFO_pHYs)
  162880. {
  162881. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  162882. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  162883. return (0);
  162884. else return (info_ptr->x_pixels_per_unit);
  162885. }
  162886. #else
  162887. return (0);
  162888. #endif
  162889. return (0);
  162890. }
  162891. png_uint_32 PNGAPI
  162892. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  162893. {
  162894. if (png_ptr != NULL && info_ptr != NULL)
  162895. #if defined(PNG_pHYs_SUPPORTED)
  162896. if (info_ptr->valid & PNG_INFO_pHYs)
  162897. {
  162898. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  162899. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  162900. return (0);
  162901. else return (info_ptr->y_pixels_per_unit);
  162902. }
  162903. #else
  162904. return (0);
  162905. #endif
  162906. return (0);
  162907. }
  162908. png_uint_32 PNGAPI
  162909. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  162910. {
  162911. if (png_ptr != NULL && info_ptr != NULL)
  162912. #if defined(PNG_pHYs_SUPPORTED)
  162913. if (info_ptr->valid & PNG_INFO_pHYs)
  162914. {
  162915. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  162916. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  162917. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  162918. return (0);
  162919. else return (info_ptr->x_pixels_per_unit);
  162920. }
  162921. #else
  162922. return (0);
  162923. #endif
  162924. return (0);
  162925. }
  162926. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162927. float PNGAPI
  162928. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  162929. {
  162930. if (png_ptr != NULL && info_ptr != NULL)
  162931. #if defined(PNG_pHYs_SUPPORTED)
  162932. if (info_ptr->valid & PNG_INFO_pHYs)
  162933. {
  162934. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  162935. if (info_ptr->x_pixels_per_unit == 0)
  162936. return ((float)0.0);
  162937. else
  162938. return ((float)((float)info_ptr->y_pixels_per_unit
  162939. /(float)info_ptr->x_pixels_per_unit));
  162940. }
  162941. #else
  162942. return (0.0);
  162943. #endif
  162944. return ((float)0.0);
  162945. }
  162946. #endif
  162947. png_int_32 PNGAPI
  162948. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  162949. {
  162950. if (png_ptr != NULL && info_ptr != NULL)
  162951. #if defined(PNG_oFFs_SUPPORTED)
  162952. if (info_ptr->valid & PNG_INFO_oFFs)
  162953. {
  162954. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  162955. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  162956. return (0);
  162957. else return (info_ptr->x_offset);
  162958. }
  162959. #else
  162960. return (0);
  162961. #endif
  162962. return (0);
  162963. }
  162964. png_int_32 PNGAPI
  162965. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  162966. {
  162967. if (png_ptr != NULL && info_ptr != NULL)
  162968. #if defined(PNG_oFFs_SUPPORTED)
  162969. if (info_ptr->valid & PNG_INFO_oFFs)
  162970. {
  162971. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  162972. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  162973. return (0);
  162974. else return (info_ptr->y_offset);
  162975. }
  162976. #else
  162977. return (0);
  162978. #endif
  162979. return (0);
  162980. }
  162981. png_int_32 PNGAPI
  162982. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  162983. {
  162984. if (png_ptr != NULL && info_ptr != NULL)
  162985. #if defined(PNG_oFFs_SUPPORTED)
  162986. if (info_ptr->valid & PNG_INFO_oFFs)
  162987. {
  162988. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  162989. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  162990. return (0);
  162991. else return (info_ptr->x_offset);
  162992. }
  162993. #else
  162994. return (0);
  162995. #endif
  162996. return (0);
  162997. }
  162998. png_int_32 PNGAPI
  162999. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163000. {
  163001. if (png_ptr != NULL && info_ptr != NULL)
  163002. #if defined(PNG_oFFs_SUPPORTED)
  163003. if (info_ptr->valid & PNG_INFO_oFFs)
  163004. {
  163005. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163006. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163007. return (0);
  163008. else return (info_ptr->y_offset);
  163009. }
  163010. #else
  163011. return (0);
  163012. #endif
  163013. return (0);
  163014. }
  163015. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163016. png_uint_32 PNGAPI
  163017. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163018. {
  163019. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163020. *.0254 +.5));
  163021. }
  163022. png_uint_32 PNGAPI
  163023. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163024. {
  163025. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163026. *.0254 +.5));
  163027. }
  163028. png_uint_32 PNGAPI
  163029. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163030. {
  163031. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163032. *.0254 +.5));
  163033. }
  163034. float PNGAPI
  163035. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163036. {
  163037. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163038. *.00003937);
  163039. }
  163040. float PNGAPI
  163041. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163042. {
  163043. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163044. *.00003937);
  163045. }
  163046. #if defined(PNG_pHYs_SUPPORTED)
  163047. png_uint_32 PNGAPI
  163048. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163049. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163050. {
  163051. png_uint_32 retval = 0;
  163052. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163053. {
  163054. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163055. if (res_x != NULL)
  163056. {
  163057. *res_x = info_ptr->x_pixels_per_unit;
  163058. retval |= PNG_INFO_pHYs;
  163059. }
  163060. if (res_y != NULL)
  163061. {
  163062. *res_y = info_ptr->y_pixels_per_unit;
  163063. retval |= PNG_INFO_pHYs;
  163064. }
  163065. if (unit_type != NULL)
  163066. {
  163067. *unit_type = (int)info_ptr->phys_unit_type;
  163068. retval |= PNG_INFO_pHYs;
  163069. if(*unit_type == 1)
  163070. {
  163071. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163072. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163073. }
  163074. }
  163075. }
  163076. return (retval);
  163077. }
  163078. #endif /* PNG_pHYs_SUPPORTED */
  163079. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163080. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163081. png_byte PNGAPI
  163082. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163083. {
  163084. if (png_ptr != NULL && info_ptr != NULL)
  163085. return(info_ptr->channels);
  163086. else
  163087. return (0);
  163088. }
  163089. png_bytep PNGAPI
  163090. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163091. {
  163092. if (png_ptr != NULL && info_ptr != NULL)
  163093. return(info_ptr->signature);
  163094. else
  163095. return (NULL);
  163096. }
  163097. #if defined(PNG_bKGD_SUPPORTED)
  163098. png_uint_32 PNGAPI
  163099. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163100. png_color_16p *background)
  163101. {
  163102. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163103. && background != NULL)
  163104. {
  163105. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163106. *background = &(info_ptr->background);
  163107. return (PNG_INFO_bKGD);
  163108. }
  163109. return (0);
  163110. }
  163111. #endif
  163112. #if defined(PNG_cHRM_SUPPORTED)
  163113. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163114. png_uint_32 PNGAPI
  163115. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163116. double *white_x, double *white_y, double *red_x, double *red_y,
  163117. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163118. {
  163119. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163120. {
  163121. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163122. if (white_x != NULL)
  163123. *white_x = (double)info_ptr->x_white;
  163124. if (white_y != NULL)
  163125. *white_y = (double)info_ptr->y_white;
  163126. if (red_x != NULL)
  163127. *red_x = (double)info_ptr->x_red;
  163128. if (red_y != NULL)
  163129. *red_y = (double)info_ptr->y_red;
  163130. if (green_x != NULL)
  163131. *green_x = (double)info_ptr->x_green;
  163132. if (green_y != NULL)
  163133. *green_y = (double)info_ptr->y_green;
  163134. if (blue_x != NULL)
  163135. *blue_x = (double)info_ptr->x_blue;
  163136. if (blue_y != NULL)
  163137. *blue_y = (double)info_ptr->y_blue;
  163138. return (PNG_INFO_cHRM);
  163139. }
  163140. return (0);
  163141. }
  163142. #endif
  163143. #ifdef PNG_FIXED_POINT_SUPPORTED
  163144. png_uint_32 PNGAPI
  163145. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163146. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163147. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163148. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163149. {
  163150. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163151. {
  163152. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163153. if (white_x != NULL)
  163154. *white_x = info_ptr->int_x_white;
  163155. if (white_y != NULL)
  163156. *white_y = info_ptr->int_y_white;
  163157. if (red_x != NULL)
  163158. *red_x = info_ptr->int_x_red;
  163159. if (red_y != NULL)
  163160. *red_y = info_ptr->int_y_red;
  163161. if (green_x != NULL)
  163162. *green_x = info_ptr->int_x_green;
  163163. if (green_y != NULL)
  163164. *green_y = info_ptr->int_y_green;
  163165. if (blue_x != NULL)
  163166. *blue_x = info_ptr->int_x_blue;
  163167. if (blue_y != NULL)
  163168. *blue_y = info_ptr->int_y_blue;
  163169. return (PNG_INFO_cHRM);
  163170. }
  163171. return (0);
  163172. }
  163173. #endif
  163174. #endif
  163175. #if defined(PNG_gAMA_SUPPORTED)
  163176. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163177. png_uint_32 PNGAPI
  163178. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163179. {
  163180. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163181. && file_gamma != NULL)
  163182. {
  163183. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163184. *file_gamma = (double)info_ptr->gamma;
  163185. return (PNG_INFO_gAMA);
  163186. }
  163187. return (0);
  163188. }
  163189. #endif
  163190. #ifdef PNG_FIXED_POINT_SUPPORTED
  163191. png_uint_32 PNGAPI
  163192. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163193. png_fixed_point *int_file_gamma)
  163194. {
  163195. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163196. && int_file_gamma != NULL)
  163197. {
  163198. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163199. *int_file_gamma = info_ptr->int_gamma;
  163200. return (PNG_INFO_gAMA);
  163201. }
  163202. return (0);
  163203. }
  163204. #endif
  163205. #endif
  163206. #if defined(PNG_sRGB_SUPPORTED)
  163207. png_uint_32 PNGAPI
  163208. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163209. {
  163210. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163211. && file_srgb_intent != NULL)
  163212. {
  163213. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163214. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163215. return (PNG_INFO_sRGB);
  163216. }
  163217. return (0);
  163218. }
  163219. #endif
  163220. #if defined(PNG_iCCP_SUPPORTED)
  163221. png_uint_32 PNGAPI
  163222. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163223. png_charpp name, int *compression_type,
  163224. png_charpp profile, png_uint_32 *proflen)
  163225. {
  163226. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163227. && name != NULL && profile != NULL && proflen != NULL)
  163228. {
  163229. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163230. *name = info_ptr->iccp_name;
  163231. *profile = info_ptr->iccp_profile;
  163232. *proflen = (int)info_ptr->iccp_proflen;
  163233. *compression_type = (int)info_ptr->iccp_compression;
  163234. return (PNG_INFO_iCCP);
  163235. }
  163236. return (0);
  163237. }
  163238. #endif
  163239. #if defined(PNG_sPLT_SUPPORTED)
  163240. png_uint_32 PNGAPI
  163241. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163242. png_sPLT_tpp spalettes)
  163243. {
  163244. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163245. {
  163246. *spalettes = info_ptr->splt_palettes;
  163247. return ((png_uint_32)info_ptr->splt_palettes_num);
  163248. }
  163249. return (0);
  163250. }
  163251. #endif
  163252. #if defined(PNG_hIST_SUPPORTED)
  163253. png_uint_32 PNGAPI
  163254. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163255. {
  163256. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163257. && hist != NULL)
  163258. {
  163259. png_debug1(1, "in %s retrieval function\n", "hIST");
  163260. *hist = info_ptr->hist;
  163261. return (PNG_INFO_hIST);
  163262. }
  163263. return (0);
  163264. }
  163265. #endif
  163266. png_uint_32 PNGAPI
  163267. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163268. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163269. int *color_type, int *interlace_type, int *compression_type,
  163270. int *filter_type)
  163271. {
  163272. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163273. bit_depth != NULL && color_type != NULL)
  163274. {
  163275. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163276. *width = info_ptr->width;
  163277. *height = info_ptr->height;
  163278. *bit_depth = info_ptr->bit_depth;
  163279. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163280. png_error(png_ptr, "Invalid bit depth");
  163281. *color_type = info_ptr->color_type;
  163282. if (info_ptr->color_type > 6)
  163283. png_error(png_ptr, "Invalid color type");
  163284. if (compression_type != NULL)
  163285. *compression_type = info_ptr->compression_type;
  163286. if (filter_type != NULL)
  163287. *filter_type = info_ptr->filter_type;
  163288. if (interlace_type != NULL)
  163289. *interlace_type = info_ptr->interlace_type;
  163290. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163291. png_error(png_ptr, "Invalid image width");
  163292. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163293. png_error(png_ptr, "Invalid image height");
  163294. if (info_ptr->width > (PNG_UINT_32_MAX
  163295. >> 3) /* 8-byte RGBA pixels */
  163296. - 64 /* bigrowbuf hack */
  163297. - 1 /* filter byte */
  163298. - 7*8 /* rounding of width to multiple of 8 pixels */
  163299. - 8) /* extra max_pixel_depth pad */
  163300. {
  163301. png_warning(png_ptr,
  163302. "Width too large for libpng to process image data.");
  163303. }
  163304. return (1);
  163305. }
  163306. return (0);
  163307. }
  163308. #if defined(PNG_oFFs_SUPPORTED)
  163309. png_uint_32 PNGAPI
  163310. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163311. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163312. {
  163313. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163314. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163315. {
  163316. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163317. *offset_x = info_ptr->x_offset;
  163318. *offset_y = info_ptr->y_offset;
  163319. *unit_type = (int)info_ptr->offset_unit_type;
  163320. return (PNG_INFO_oFFs);
  163321. }
  163322. return (0);
  163323. }
  163324. #endif
  163325. #if defined(PNG_pCAL_SUPPORTED)
  163326. png_uint_32 PNGAPI
  163327. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163328. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163329. png_charp *units, png_charpp *params)
  163330. {
  163331. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163332. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163333. nparams != NULL && units != NULL && params != NULL)
  163334. {
  163335. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163336. *purpose = info_ptr->pcal_purpose;
  163337. *X0 = info_ptr->pcal_X0;
  163338. *X1 = info_ptr->pcal_X1;
  163339. *type = (int)info_ptr->pcal_type;
  163340. *nparams = (int)info_ptr->pcal_nparams;
  163341. *units = info_ptr->pcal_units;
  163342. *params = info_ptr->pcal_params;
  163343. return (PNG_INFO_pCAL);
  163344. }
  163345. return (0);
  163346. }
  163347. #endif
  163348. #if defined(PNG_sCAL_SUPPORTED)
  163349. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163350. png_uint_32 PNGAPI
  163351. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163352. int *unit, double *width, double *height)
  163353. {
  163354. if (png_ptr != NULL && info_ptr != NULL &&
  163355. (info_ptr->valid & PNG_INFO_sCAL))
  163356. {
  163357. *unit = info_ptr->scal_unit;
  163358. *width = info_ptr->scal_pixel_width;
  163359. *height = info_ptr->scal_pixel_height;
  163360. return (PNG_INFO_sCAL);
  163361. }
  163362. return(0);
  163363. }
  163364. #else
  163365. #ifdef PNG_FIXED_POINT_SUPPORTED
  163366. png_uint_32 PNGAPI
  163367. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163368. int *unit, png_charpp width, png_charpp height)
  163369. {
  163370. if (png_ptr != NULL && info_ptr != NULL &&
  163371. (info_ptr->valid & PNG_INFO_sCAL))
  163372. {
  163373. *unit = info_ptr->scal_unit;
  163374. *width = info_ptr->scal_s_width;
  163375. *height = info_ptr->scal_s_height;
  163376. return (PNG_INFO_sCAL);
  163377. }
  163378. return(0);
  163379. }
  163380. #endif
  163381. #endif
  163382. #endif
  163383. #if defined(PNG_pHYs_SUPPORTED)
  163384. png_uint_32 PNGAPI
  163385. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163386. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163387. {
  163388. png_uint_32 retval = 0;
  163389. if (png_ptr != NULL && info_ptr != NULL &&
  163390. (info_ptr->valid & PNG_INFO_pHYs))
  163391. {
  163392. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163393. if (res_x != NULL)
  163394. {
  163395. *res_x = info_ptr->x_pixels_per_unit;
  163396. retval |= PNG_INFO_pHYs;
  163397. }
  163398. if (res_y != NULL)
  163399. {
  163400. *res_y = info_ptr->y_pixels_per_unit;
  163401. retval |= PNG_INFO_pHYs;
  163402. }
  163403. if (unit_type != NULL)
  163404. {
  163405. *unit_type = (int)info_ptr->phys_unit_type;
  163406. retval |= PNG_INFO_pHYs;
  163407. }
  163408. }
  163409. return (retval);
  163410. }
  163411. #endif
  163412. png_uint_32 PNGAPI
  163413. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163414. int *num_palette)
  163415. {
  163416. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163417. && palette != NULL)
  163418. {
  163419. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163420. *palette = info_ptr->palette;
  163421. *num_palette = info_ptr->num_palette;
  163422. png_debug1(3, "num_palette = %d\n", *num_palette);
  163423. return (PNG_INFO_PLTE);
  163424. }
  163425. return (0);
  163426. }
  163427. #if defined(PNG_sBIT_SUPPORTED)
  163428. png_uint_32 PNGAPI
  163429. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163430. {
  163431. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163432. && sig_bit != NULL)
  163433. {
  163434. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163435. *sig_bit = &(info_ptr->sig_bit);
  163436. return (PNG_INFO_sBIT);
  163437. }
  163438. return (0);
  163439. }
  163440. #endif
  163441. #if defined(PNG_TEXT_SUPPORTED)
  163442. png_uint_32 PNGAPI
  163443. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163444. int *num_text)
  163445. {
  163446. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163447. {
  163448. png_debug1(1, "in %s retrieval function\n",
  163449. (png_ptr->chunk_name[0] == '\0' ? "text"
  163450. : (png_const_charp)png_ptr->chunk_name));
  163451. if (text_ptr != NULL)
  163452. *text_ptr = info_ptr->text;
  163453. if (num_text != NULL)
  163454. *num_text = info_ptr->num_text;
  163455. return ((png_uint_32)info_ptr->num_text);
  163456. }
  163457. if (num_text != NULL)
  163458. *num_text = 0;
  163459. return(0);
  163460. }
  163461. #endif
  163462. #if defined(PNG_tIME_SUPPORTED)
  163463. png_uint_32 PNGAPI
  163464. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163465. {
  163466. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163467. && mod_time != NULL)
  163468. {
  163469. png_debug1(1, "in %s retrieval function\n", "tIME");
  163470. *mod_time = &(info_ptr->mod_time);
  163471. return (PNG_INFO_tIME);
  163472. }
  163473. return (0);
  163474. }
  163475. #endif
  163476. #if defined(PNG_tRNS_SUPPORTED)
  163477. png_uint_32 PNGAPI
  163478. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163479. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163480. {
  163481. png_uint_32 retval = 0;
  163482. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163483. {
  163484. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163485. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163486. {
  163487. if (trans != NULL)
  163488. {
  163489. *trans = info_ptr->trans;
  163490. retval |= PNG_INFO_tRNS;
  163491. }
  163492. if (trans_values != NULL)
  163493. *trans_values = &(info_ptr->trans_values);
  163494. }
  163495. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163496. {
  163497. if (trans_values != NULL)
  163498. {
  163499. *trans_values = &(info_ptr->trans_values);
  163500. retval |= PNG_INFO_tRNS;
  163501. }
  163502. if(trans != NULL)
  163503. *trans = NULL;
  163504. }
  163505. if(num_trans != NULL)
  163506. {
  163507. *num_trans = info_ptr->num_trans;
  163508. retval |= PNG_INFO_tRNS;
  163509. }
  163510. }
  163511. return (retval);
  163512. }
  163513. #endif
  163514. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163515. png_uint_32 PNGAPI
  163516. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163517. png_unknown_chunkpp unknowns)
  163518. {
  163519. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163520. {
  163521. *unknowns = info_ptr->unknown_chunks;
  163522. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163523. }
  163524. return (0);
  163525. }
  163526. #endif
  163527. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163528. png_byte PNGAPI
  163529. png_get_rgb_to_gray_status (png_structp png_ptr)
  163530. {
  163531. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163532. }
  163533. #endif
  163534. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163535. png_voidp PNGAPI
  163536. png_get_user_chunk_ptr(png_structp png_ptr)
  163537. {
  163538. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163539. }
  163540. #endif
  163541. #ifdef PNG_WRITE_SUPPORTED
  163542. png_uint_32 PNGAPI
  163543. png_get_compression_buffer_size(png_structp png_ptr)
  163544. {
  163545. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163546. }
  163547. #endif
  163548. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163549. #ifndef PNG_1_0_X
  163550. png_uint_32 PNGAPI
  163551. png_get_asm_flags (png_structp png_ptr)
  163552. {
  163553. return (png_ptr? 0L: 0L);
  163554. }
  163555. png_uint_32 PNGAPI
  163556. png_get_asm_flagmask (int flag_select)
  163557. {
  163558. flag_select=flag_select;
  163559. return 0L;
  163560. }
  163561. png_uint_32 PNGAPI
  163562. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163563. {
  163564. flag_select=flag_select;
  163565. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163566. return 0L;
  163567. }
  163568. png_byte PNGAPI
  163569. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163570. {
  163571. return (png_ptr? 0: 0);
  163572. }
  163573. png_uint_32 PNGAPI
  163574. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163575. {
  163576. return (png_ptr? 0L: 0L);
  163577. }
  163578. #endif /* ?PNG_1_0_X */
  163579. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163580. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163581. png_uint_32 PNGAPI
  163582. png_get_user_width_max (png_structp png_ptr)
  163583. {
  163584. return (png_ptr? png_ptr->user_width_max : 0);
  163585. }
  163586. png_uint_32 PNGAPI
  163587. png_get_user_height_max (png_structp png_ptr)
  163588. {
  163589. return (png_ptr? png_ptr->user_height_max : 0);
  163590. }
  163591. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163592. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163593. /*** End of inlined file: pngget.c ***/
  163594. /*** Start of inlined file: pngmem.c ***/
  163595. #define PNG_INTERNAL
  163596. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163597. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163598. png_voidp /* PRIVATE */
  163599. png_create_struct(int type)
  163600. {
  163601. #ifdef PNG_USER_MEM_SUPPORTED
  163602. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163603. }
  163604. png_voidp /* PRIVATE */
  163605. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163606. {
  163607. #endif /* PNG_USER_MEM_SUPPORTED */
  163608. png_size_t size;
  163609. png_voidp struct_ptr;
  163610. if (type == PNG_STRUCT_INFO)
  163611. size = png_sizeof(png_info);
  163612. else if (type == PNG_STRUCT_PNG)
  163613. size = png_sizeof(png_struct);
  163614. else
  163615. return (png_get_copyright(NULL));
  163616. #ifdef PNG_USER_MEM_SUPPORTED
  163617. if(malloc_fn != NULL)
  163618. {
  163619. png_struct dummy_struct;
  163620. png_structp png_ptr = &dummy_struct;
  163621. png_ptr->mem_ptr=mem_ptr;
  163622. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163623. }
  163624. else
  163625. #endif /* PNG_USER_MEM_SUPPORTED */
  163626. struct_ptr = (png_voidp)farmalloc(size);
  163627. if (struct_ptr != NULL)
  163628. png_memset(struct_ptr, 0, size);
  163629. return (struct_ptr);
  163630. }
  163631. void /* PRIVATE */
  163632. png_destroy_struct(png_voidp struct_ptr)
  163633. {
  163634. #ifdef PNG_USER_MEM_SUPPORTED
  163635. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163636. }
  163637. void /* PRIVATE */
  163638. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163639. png_voidp mem_ptr)
  163640. {
  163641. #endif
  163642. if (struct_ptr != NULL)
  163643. {
  163644. #ifdef PNG_USER_MEM_SUPPORTED
  163645. if(free_fn != NULL)
  163646. {
  163647. png_struct dummy_struct;
  163648. png_structp png_ptr = &dummy_struct;
  163649. png_ptr->mem_ptr=mem_ptr;
  163650. (*(free_fn))(png_ptr, struct_ptr);
  163651. return;
  163652. }
  163653. #endif /* PNG_USER_MEM_SUPPORTED */
  163654. farfree (struct_ptr);
  163655. }
  163656. }
  163657. png_voidp PNGAPI
  163658. png_malloc(png_structp png_ptr, png_uint_32 size)
  163659. {
  163660. png_voidp ret;
  163661. if (png_ptr == NULL || size == 0)
  163662. return (NULL);
  163663. #ifdef PNG_USER_MEM_SUPPORTED
  163664. if(png_ptr->malloc_fn != NULL)
  163665. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163666. else
  163667. ret = (png_malloc_default(png_ptr, size));
  163668. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163669. png_error(png_ptr, "Out of memory!");
  163670. return (ret);
  163671. }
  163672. png_voidp PNGAPI
  163673. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163674. {
  163675. png_voidp ret;
  163676. #endif /* PNG_USER_MEM_SUPPORTED */
  163677. if (png_ptr == NULL || size == 0)
  163678. return (NULL);
  163679. #ifdef PNG_MAX_MALLOC_64K
  163680. if (size > (png_uint_32)65536L)
  163681. {
  163682. png_warning(png_ptr, "Cannot Allocate > 64K");
  163683. ret = NULL;
  163684. }
  163685. else
  163686. #endif
  163687. if (size != (size_t)size)
  163688. ret = NULL;
  163689. else if (size == (png_uint_32)65536L)
  163690. {
  163691. if (png_ptr->offset_table == NULL)
  163692. {
  163693. ret = farmalloc(size);
  163694. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163695. {
  163696. int num_blocks;
  163697. png_uint_32 total_size;
  163698. png_bytep table;
  163699. int i;
  163700. png_byte huge * hptr;
  163701. if (ret != NULL)
  163702. {
  163703. farfree(ret);
  163704. ret = NULL;
  163705. }
  163706. if(png_ptr->zlib_window_bits > 14)
  163707. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  163708. else
  163709. num_blocks = 1;
  163710. if (png_ptr->zlib_mem_level >= 7)
  163711. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  163712. else
  163713. num_blocks++;
  163714. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  163715. table = farmalloc(total_size);
  163716. if (table == NULL)
  163717. {
  163718. #ifndef PNG_USER_MEM_SUPPORTED
  163719. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163720. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  163721. else
  163722. png_warning(png_ptr, "Out Of Memory.");
  163723. #endif
  163724. return (NULL);
  163725. }
  163726. if ((png_size_t)table & 0xfff0)
  163727. {
  163728. #ifndef PNG_USER_MEM_SUPPORTED
  163729. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163730. png_error(png_ptr,
  163731. "Farmalloc didn't return normalized pointer");
  163732. else
  163733. png_warning(png_ptr,
  163734. "Farmalloc didn't return normalized pointer");
  163735. #endif
  163736. return (NULL);
  163737. }
  163738. png_ptr->offset_table = table;
  163739. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  163740. png_sizeof (png_bytep));
  163741. if (png_ptr->offset_table_ptr == NULL)
  163742. {
  163743. #ifndef PNG_USER_MEM_SUPPORTED
  163744. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163745. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  163746. else
  163747. png_warning(png_ptr, "Out Of memory.");
  163748. #endif
  163749. return (NULL);
  163750. }
  163751. hptr = (png_byte huge *)table;
  163752. if ((png_size_t)hptr & 0xf)
  163753. {
  163754. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  163755. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  163756. }
  163757. for (i = 0; i < num_blocks; i++)
  163758. {
  163759. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  163760. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  163761. }
  163762. png_ptr->offset_table_number = num_blocks;
  163763. png_ptr->offset_table_count = 0;
  163764. png_ptr->offset_table_count_free = 0;
  163765. }
  163766. }
  163767. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  163768. {
  163769. #ifndef PNG_USER_MEM_SUPPORTED
  163770. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163771. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  163772. else
  163773. png_warning(png_ptr, "Out of Memory.");
  163774. #endif
  163775. return (NULL);
  163776. }
  163777. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  163778. }
  163779. else
  163780. ret = farmalloc(size);
  163781. #ifndef PNG_USER_MEM_SUPPORTED
  163782. if (ret == NULL)
  163783. {
  163784. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163785. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163786. else
  163787. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163788. }
  163789. #endif
  163790. return (ret);
  163791. }
  163792. void PNGAPI
  163793. png_free(png_structp png_ptr, png_voidp ptr)
  163794. {
  163795. if (png_ptr == NULL || ptr == NULL)
  163796. return;
  163797. #ifdef PNG_USER_MEM_SUPPORTED
  163798. if (png_ptr->free_fn != NULL)
  163799. {
  163800. (*(png_ptr->free_fn))(png_ptr, ptr);
  163801. return;
  163802. }
  163803. else png_free_default(png_ptr, ptr);
  163804. }
  163805. void PNGAPI
  163806. png_free_default(png_structp png_ptr, png_voidp ptr)
  163807. {
  163808. #endif /* PNG_USER_MEM_SUPPORTED */
  163809. if(png_ptr == NULL) return;
  163810. if (png_ptr->offset_table != NULL)
  163811. {
  163812. int i;
  163813. for (i = 0; i < png_ptr->offset_table_count; i++)
  163814. {
  163815. if (ptr == png_ptr->offset_table_ptr[i])
  163816. {
  163817. ptr = NULL;
  163818. png_ptr->offset_table_count_free++;
  163819. break;
  163820. }
  163821. }
  163822. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  163823. {
  163824. farfree(png_ptr->offset_table);
  163825. farfree(png_ptr->offset_table_ptr);
  163826. png_ptr->offset_table = NULL;
  163827. png_ptr->offset_table_ptr = NULL;
  163828. }
  163829. }
  163830. if (ptr != NULL)
  163831. {
  163832. farfree(ptr);
  163833. }
  163834. }
  163835. #else /* Not the Borland DOS special memory handler */
  163836. png_voidp /* PRIVATE */
  163837. png_create_struct(int type)
  163838. {
  163839. #ifdef PNG_USER_MEM_SUPPORTED
  163840. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163841. }
  163842. png_voidp /* PRIVATE */
  163843. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163844. {
  163845. #endif /* PNG_USER_MEM_SUPPORTED */
  163846. png_size_t size;
  163847. png_voidp struct_ptr;
  163848. if (type == PNG_STRUCT_INFO)
  163849. size = png_sizeof(png_info);
  163850. else if (type == PNG_STRUCT_PNG)
  163851. size = png_sizeof(png_struct);
  163852. else
  163853. return (NULL);
  163854. #ifdef PNG_USER_MEM_SUPPORTED
  163855. if(malloc_fn != NULL)
  163856. {
  163857. png_struct dummy_struct;
  163858. png_structp png_ptr = &dummy_struct;
  163859. png_ptr->mem_ptr=mem_ptr;
  163860. struct_ptr = (*(malloc_fn))(png_ptr, size);
  163861. if (struct_ptr != NULL)
  163862. png_memset(struct_ptr, 0, size);
  163863. return (struct_ptr);
  163864. }
  163865. #endif /* PNG_USER_MEM_SUPPORTED */
  163866. #if defined(__TURBOC__) && !defined(__FLAT__)
  163867. struct_ptr = (png_voidp)farmalloc(size);
  163868. #else
  163869. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  163870. struct_ptr = (png_voidp)halloc(size,1);
  163871. # else
  163872. struct_ptr = (png_voidp)malloc(size);
  163873. # endif
  163874. #endif
  163875. if (struct_ptr != NULL)
  163876. png_memset(struct_ptr, 0, size);
  163877. return (struct_ptr);
  163878. }
  163879. void /* PRIVATE */
  163880. png_destroy_struct(png_voidp struct_ptr)
  163881. {
  163882. #ifdef PNG_USER_MEM_SUPPORTED
  163883. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163884. }
  163885. void /* PRIVATE */
  163886. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163887. png_voidp mem_ptr)
  163888. {
  163889. #endif /* PNG_USER_MEM_SUPPORTED */
  163890. if (struct_ptr != NULL)
  163891. {
  163892. #ifdef PNG_USER_MEM_SUPPORTED
  163893. if(free_fn != NULL)
  163894. {
  163895. png_struct dummy_struct;
  163896. png_structp png_ptr = &dummy_struct;
  163897. png_ptr->mem_ptr=mem_ptr;
  163898. (*(free_fn))(png_ptr, struct_ptr);
  163899. return;
  163900. }
  163901. #endif /* PNG_USER_MEM_SUPPORTED */
  163902. #if defined(__TURBOC__) && !defined(__FLAT__)
  163903. farfree(struct_ptr);
  163904. #else
  163905. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  163906. hfree(struct_ptr);
  163907. # else
  163908. free(struct_ptr);
  163909. # endif
  163910. #endif
  163911. }
  163912. }
  163913. png_voidp PNGAPI
  163914. png_malloc(png_structp png_ptr, png_uint_32 size)
  163915. {
  163916. png_voidp ret;
  163917. #ifdef PNG_USER_MEM_SUPPORTED
  163918. if (png_ptr == NULL || size == 0)
  163919. return (NULL);
  163920. if(png_ptr->malloc_fn != NULL)
  163921. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163922. else
  163923. ret = (png_malloc_default(png_ptr, size));
  163924. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163925. png_error(png_ptr, "Out of Memory!");
  163926. return (ret);
  163927. }
  163928. png_voidp PNGAPI
  163929. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163930. {
  163931. png_voidp ret;
  163932. #endif /* PNG_USER_MEM_SUPPORTED */
  163933. if (png_ptr == NULL || size == 0)
  163934. return (NULL);
  163935. #ifdef PNG_MAX_MALLOC_64K
  163936. if (size > (png_uint_32)65536L)
  163937. {
  163938. #ifndef PNG_USER_MEM_SUPPORTED
  163939. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163940. png_error(png_ptr, "Cannot Allocate > 64K");
  163941. else
  163942. #endif
  163943. return NULL;
  163944. }
  163945. #endif
  163946. #if defined(__TURBOC__) && !defined(__FLAT__)
  163947. if (size != (unsigned long)size)
  163948. ret = NULL;
  163949. else
  163950. ret = farmalloc(size);
  163951. #else
  163952. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  163953. if (size != (unsigned long)size)
  163954. ret = NULL;
  163955. else
  163956. ret = halloc(size, 1);
  163957. # else
  163958. if (size != (size_t)size)
  163959. ret = NULL;
  163960. else
  163961. ret = malloc((size_t)size);
  163962. # endif
  163963. #endif
  163964. #ifndef PNG_USER_MEM_SUPPORTED
  163965. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163966. png_error(png_ptr, "Out of Memory");
  163967. #endif
  163968. return (ret);
  163969. }
  163970. void PNGAPI
  163971. png_free(png_structp png_ptr, png_voidp ptr)
  163972. {
  163973. if (png_ptr == NULL || ptr == NULL)
  163974. return;
  163975. #ifdef PNG_USER_MEM_SUPPORTED
  163976. if (png_ptr->free_fn != NULL)
  163977. {
  163978. (*(png_ptr->free_fn))(png_ptr, ptr);
  163979. return;
  163980. }
  163981. else png_free_default(png_ptr, ptr);
  163982. }
  163983. void PNGAPI
  163984. png_free_default(png_structp png_ptr, png_voidp ptr)
  163985. {
  163986. if (png_ptr == NULL || ptr == NULL)
  163987. return;
  163988. #endif /* PNG_USER_MEM_SUPPORTED */
  163989. #if defined(__TURBOC__) && !defined(__FLAT__)
  163990. farfree(ptr);
  163991. #else
  163992. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  163993. hfree(ptr);
  163994. # else
  163995. free(ptr);
  163996. # endif
  163997. #endif
  163998. }
  163999. #endif /* Not Borland DOS special memory handler */
  164000. #if defined(PNG_1_0_X)
  164001. # define png_malloc_warn png_malloc
  164002. #else
  164003. png_voidp PNGAPI
  164004. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164005. {
  164006. png_voidp ptr;
  164007. png_uint_32 save_flags;
  164008. if(png_ptr == NULL) return (NULL);
  164009. save_flags=png_ptr->flags;
  164010. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164011. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164012. png_ptr->flags=save_flags;
  164013. return(ptr);
  164014. }
  164015. #endif
  164016. png_voidp PNGAPI
  164017. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164018. png_uint_32 length)
  164019. {
  164020. png_size_t size;
  164021. size = (png_size_t)length;
  164022. if ((png_uint_32)size != length)
  164023. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164024. return(png_memcpy (s1, s2, size));
  164025. }
  164026. png_voidp PNGAPI
  164027. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164028. png_uint_32 length)
  164029. {
  164030. png_size_t size;
  164031. size = (png_size_t)length;
  164032. if ((png_uint_32)size != length)
  164033. png_error(png_ptr,"Overflow in png_memset_check.");
  164034. return (png_memset (s1, value, size));
  164035. }
  164036. #ifdef PNG_USER_MEM_SUPPORTED
  164037. void PNGAPI
  164038. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164039. malloc_fn, png_free_ptr free_fn)
  164040. {
  164041. if(png_ptr != NULL) {
  164042. png_ptr->mem_ptr = mem_ptr;
  164043. png_ptr->malloc_fn = malloc_fn;
  164044. png_ptr->free_fn = free_fn;
  164045. }
  164046. }
  164047. png_voidp PNGAPI
  164048. png_get_mem_ptr(png_structp png_ptr)
  164049. {
  164050. if(png_ptr == NULL) return (NULL);
  164051. return ((png_voidp)png_ptr->mem_ptr);
  164052. }
  164053. #endif /* PNG_USER_MEM_SUPPORTED */
  164054. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164055. /*** End of inlined file: pngmem.c ***/
  164056. /*** Start of inlined file: pngread.c ***/
  164057. #define PNG_INTERNAL
  164058. #if defined(PNG_READ_SUPPORTED)
  164059. png_structp PNGAPI
  164060. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164061. png_error_ptr error_fn, png_error_ptr warn_fn)
  164062. {
  164063. #ifdef PNG_USER_MEM_SUPPORTED
  164064. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164065. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164066. }
  164067. png_structp PNGAPI
  164068. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164069. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164070. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164071. {
  164072. #endif /* PNG_USER_MEM_SUPPORTED */
  164073. png_structp png_ptr;
  164074. #ifdef PNG_SETJMP_SUPPORTED
  164075. #ifdef USE_FAR_KEYWORD
  164076. jmp_buf jmpbuf;
  164077. #endif
  164078. #endif
  164079. int i;
  164080. png_debug(1, "in png_create_read_struct\n");
  164081. #ifdef PNG_USER_MEM_SUPPORTED
  164082. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164083. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164084. #else
  164085. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164086. #endif
  164087. if (png_ptr == NULL)
  164088. return (NULL);
  164089. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164090. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164091. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164092. #endif
  164093. #ifdef PNG_SETJMP_SUPPORTED
  164094. #ifdef USE_FAR_KEYWORD
  164095. if (setjmp(jmpbuf))
  164096. #else
  164097. if (setjmp(png_ptr->jmpbuf))
  164098. #endif
  164099. {
  164100. png_free(png_ptr, png_ptr->zbuf);
  164101. png_ptr->zbuf=NULL;
  164102. #ifdef PNG_USER_MEM_SUPPORTED
  164103. png_destroy_struct_2((png_voidp)png_ptr,
  164104. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164105. #else
  164106. png_destroy_struct((png_voidp)png_ptr);
  164107. #endif
  164108. return (NULL);
  164109. }
  164110. #ifdef USE_FAR_KEYWORD
  164111. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164112. #endif
  164113. #endif
  164114. #ifdef PNG_USER_MEM_SUPPORTED
  164115. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164116. #endif
  164117. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164118. i=0;
  164119. do
  164120. {
  164121. if(user_png_ver[i] != png_libpng_ver[i])
  164122. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164123. } while (png_libpng_ver[i++]);
  164124. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164125. {
  164126. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164127. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164128. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164129. {
  164130. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164131. char msg[80];
  164132. if (user_png_ver)
  164133. {
  164134. png_snprintf(msg, 80,
  164135. "Application was compiled with png.h from libpng-%.20s",
  164136. user_png_ver);
  164137. png_warning(png_ptr, msg);
  164138. }
  164139. png_snprintf(msg, 80,
  164140. "Application is running with png.c from libpng-%.20s",
  164141. png_libpng_ver);
  164142. png_warning(png_ptr, msg);
  164143. #endif
  164144. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164145. png_ptr->flags=0;
  164146. #endif
  164147. png_error(png_ptr,
  164148. "Incompatible libpng version in application and library");
  164149. }
  164150. }
  164151. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164152. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164153. (png_uint_32)png_ptr->zbuf_size);
  164154. png_ptr->zstream.zalloc = png_zalloc;
  164155. png_ptr->zstream.zfree = png_zfree;
  164156. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164157. switch (inflateInit(&png_ptr->zstream))
  164158. {
  164159. case Z_OK: /* Do nothing */ break;
  164160. case Z_MEM_ERROR:
  164161. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164162. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164163. default: png_error(png_ptr, "Unknown zlib error");
  164164. }
  164165. png_ptr->zstream.next_out = png_ptr->zbuf;
  164166. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164167. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164168. #ifdef PNG_SETJMP_SUPPORTED
  164169. #ifdef USE_FAR_KEYWORD
  164170. if (setjmp(jmpbuf))
  164171. PNG_ABORT();
  164172. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164173. #else
  164174. if (setjmp(png_ptr->jmpbuf))
  164175. PNG_ABORT();
  164176. #endif
  164177. #endif
  164178. return (png_ptr);
  164179. }
  164180. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164181. #undef png_read_init
  164182. void PNGAPI
  164183. png_read_init(png_structp png_ptr)
  164184. {
  164185. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164186. }
  164187. void PNGAPI
  164188. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164189. png_size_t png_struct_size, png_size_t png_info_size)
  164190. {
  164191. if(png_ptr == NULL) return;
  164192. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164193. if(png_sizeof(png_struct) > png_struct_size ||
  164194. png_sizeof(png_info) > png_info_size)
  164195. {
  164196. char msg[80];
  164197. png_ptr->warning_fn=NULL;
  164198. if (user_png_ver)
  164199. {
  164200. png_snprintf(msg, 80,
  164201. "Application was compiled with png.h from libpng-%.20s",
  164202. user_png_ver);
  164203. png_warning(png_ptr, msg);
  164204. }
  164205. png_snprintf(msg, 80,
  164206. "Application is running with png.c from libpng-%.20s",
  164207. png_libpng_ver);
  164208. png_warning(png_ptr, msg);
  164209. }
  164210. #endif
  164211. if(png_sizeof(png_struct) > png_struct_size)
  164212. {
  164213. png_ptr->error_fn=NULL;
  164214. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164215. png_ptr->flags=0;
  164216. #endif
  164217. png_error(png_ptr,
  164218. "The png struct allocated by the application for reading is too small.");
  164219. }
  164220. if(png_sizeof(png_info) > png_info_size)
  164221. {
  164222. png_ptr->error_fn=NULL;
  164223. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164224. png_ptr->flags=0;
  164225. #endif
  164226. png_error(png_ptr,
  164227. "The info struct allocated by application for reading is too small.");
  164228. }
  164229. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164230. }
  164231. #endif /* PNG_1_0_X || PNG_1_2_X */
  164232. void PNGAPI
  164233. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164234. png_size_t png_struct_size)
  164235. {
  164236. #ifdef PNG_SETJMP_SUPPORTED
  164237. jmp_buf tmp_jmp; /* to save current jump buffer */
  164238. #endif
  164239. int i=0;
  164240. png_structp png_ptr=*ptr_ptr;
  164241. if(png_ptr == NULL) return;
  164242. do
  164243. {
  164244. if(user_png_ver[i] != png_libpng_ver[i])
  164245. {
  164246. #ifdef PNG_LEGACY_SUPPORTED
  164247. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164248. #else
  164249. png_ptr->warning_fn=NULL;
  164250. png_warning(png_ptr,
  164251. "Application uses deprecated png_read_init() and should be recompiled.");
  164252. break;
  164253. #endif
  164254. }
  164255. } while (png_libpng_ver[i++]);
  164256. png_debug(1, "in png_read_init_3\n");
  164257. #ifdef PNG_SETJMP_SUPPORTED
  164258. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164259. #endif
  164260. if(png_sizeof(png_struct) > png_struct_size)
  164261. {
  164262. png_destroy_struct(png_ptr);
  164263. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164264. png_ptr = *ptr_ptr;
  164265. }
  164266. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164267. #ifdef PNG_SETJMP_SUPPORTED
  164268. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164269. #endif
  164270. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164271. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164272. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164273. #endif
  164274. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164275. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164276. (png_uint_32)png_ptr->zbuf_size);
  164277. png_ptr->zstream.zalloc = png_zalloc;
  164278. png_ptr->zstream.zfree = png_zfree;
  164279. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164280. switch (inflateInit(&png_ptr->zstream))
  164281. {
  164282. case Z_OK: /* Do nothing */ break;
  164283. case Z_MEM_ERROR:
  164284. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164285. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164286. default: png_error(png_ptr, "Unknown zlib error");
  164287. }
  164288. png_ptr->zstream.next_out = png_ptr->zbuf;
  164289. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164290. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164291. }
  164292. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164293. void PNGAPI
  164294. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164295. {
  164296. if(png_ptr == NULL) return;
  164297. png_debug(1, "in png_read_info\n");
  164298. if (png_ptr->sig_bytes < 8)
  164299. {
  164300. png_size_t num_checked = png_ptr->sig_bytes,
  164301. num_to_check = 8 - num_checked;
  164302. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164303. png_ptr->sig_bytes = 8;
  164304. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164305. {
  164306. if (num_checked < 4 &&
  164307. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164308. png_error(png_ptr, "Not a PNG file");
  164309. else
  164310. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164311. }
  164312. if (num_checked < 3)
  164313. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164314. }
  164315. for(;;)
  164316. {
  164317. #ifdef PNG_USE_LOCAL_ARRAYS
  164318. PNG_CONST PNG_IHDR;
  164319. PNG_CONST PNG_IDAT;
  164320. PNG_CONST PNG_IEND;
  164321. PNG_CONST PNG_PLTE;
  164322. #if defined(PNG_READ_bKGD_SUPPORTED)
  164323. PNG_CONST PNG_bKGD;
  164324. #endif
  164325. #if defined(PNG_READ_cHRM_SUPPORTED)
  164326. PNG_CONST PNG_cHRM;
  164327. #endif
  164328. #if defined(PNG_READ_gAMA_SUPPORTED)
  164329. PNG_CONST PNG_gAMA;
  164330. #endif
  164331. #if defined(PNG_READ_hIST_SUPPORTED)
  164332. PNG_CONST PNG_hIST;
  164333. #endif
  164334. #if defined(PNG_READ_iCCP_SUPPORTED)
  164335. PNG_CONST PNG_iCCP;
  164336. #endif
  164337. #if defined(PNG_READ_iTXt_SUPPORTED)
  164338. PNG_CONST PNG_iTXt;
  164339. #endif
  164340. #if defined(PNG_READ_oFFs_SUPPORTED)
  164341. PNG_CONST PNG_oFFs;
  164342. #endif
  164343. #if defined(PNG_READ_pCAL_SUPPORTED)
  164344. PNG_CONST PNG_pCAL;
  164345. #endif
  164346. #if defined(PNG_READ_pHYs_SUPPORTED)
  164347. PNG_CONST PNG_pHYs;
  164348. #endif
  164349. #if defined(PNG_READ_sBIT_SUPPORTED)
  164350. PNG_CONST PNG_sBIT;
  164351. #endif
  164352. #if defined(PNG_READ_sCAL_SUPPORTED)
  164353. PNG_CONST PNG_sCAL;
  164354. #endif
  164355. #if defined(PNG_READ_sPLT_SUPPORTED)
  164356. PNG_CONST PNG_sPLT;
  164357. #endif
  164358. #if defined(PNG_READ_sRGB_SUPPORTED)
  164359. PNG_CONST PNG_sRGB;
  164360. #endif
  164361. #if defined(PNG_READ_tEXt_SUPPORTED)
  164362. PNG_CONST PNG_tEXt;
  164363. #endif
  164364. #if defined(PNG_READ_tIME_SUPPORTED)
  164365. PNG_CONST PNG_tIME;
  164366. #endif
  164367. #if defined(PNG_READ_tRNS_SUPPORTED)
  164368. PNG_CONST PNG_tRNS;
  164369. #endif
  164370. #if defined(PNG_READ_zTXt_SUPPORTED)
  164371. PNG_CONST PNG_zTXt;
  164372. #endif
  164373. #endif /* PNG_USE_LOCAL_ARRAYS */
  164374. png_byte chunk_length[4];
  164375. png_uint_32 length;
  164376. png_read_data(png_ptr, chunk_length, 4);
  164377. length = png_get_uint_31(png_ptr,chunk_length);
  164378. png_reset_crc(png_ptr);
  164379. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164380. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164381. length);
  164382. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164383. if(png_ptr->mode & PNG_AFTER_IDAT)
  164384. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164385. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164386. png_handle_IHDR(png_ptr, info_ptr, length);
  164387. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164388. png_handle_IEND(png_ptr, info_ptr, length);
  164389. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164390. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164391. {
  164392. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164393. png_ptr->mode |= PNG_HAVE_IDAT;
  164394. png_handle_unknown(png_ptr, info_ptr, length);
  164395. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164396. png_ptr->mode |= PNG_HAVE_PLTE;
  164397. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164398. {
  164399. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164400. png_error(png_ptr, "Missing IHDR before IDAT");
  164401. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164402. !(png_ptr->mode & PNG_HAVE_PLTE))
  164403. png_error(png_ptr, "Missing PLTE before IDAT");
  164404. break;
  164405. }
  164406. }
  164407. #endif
  164408. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164409. png_handle_PLTE(png_ptr, info_ptr, length);
  164410. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164411. {
  164412. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164413. png_error(png_ptr, "Missing IHDR before IDAT");
  164414. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164415. !(png_ptr->mode & PNG_HAVE_PLTE))
  164416. png_error(png_ptr, "Missing PLTE before IDAT");
  164417. png_ptr->idat_size = length;
  164418. png_ptr->mode |= PNG_HAVE_IDAT;
  164419. break;
  164420. }
  164421. #if defined(PNG_READ_bKGD_SUPPORTED)
  164422. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164423. png_handle_bKGD(png_ptr, info_ptr, length);
  164424. #endif
  164425. #if defined(PNG_READ_cHRM_SUPPORTED)
  164426. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164427. png_handle_cHRM(png_ptr, info_ptr, length);
  164428. #endif
  164429. #if defined(PNG_READ_gAMA_SUPPORTED)
  164430. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164431. png_handle_gAMA(png_ptr, info_ptr, length);
  164432. #endif
  164433. #if defined(PNG_READ_hIST_SUPPORTED)
  164434. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164435. png_handle_hIST(png_ptr, info_ptr, length);
  164436. #endif
  164437. #if defined(PNG_READ_oFFs_SUPPORTED)
  164438. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164439. png_handle_oFFs(png_ptr, info_ptr, length);
  164440. #endif
  164441. #if defined(PNG_READ_pCAL_SUPPORTED)
  164442. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164443. png_handle_pCAL(png_ptr, info_ptr, length);
  164444. #endif
  164445. #if defined(PNG_READ_sCAL_SUPPORTED)
  164446. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164447. png_handle_sCAL(png_ptr, info_ptr, length);
  164448. #endif
  164449. #if defined(PNG_READ_pHYs_SUPPORTED)
  164450. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164451. png_handle_pHYs(png_ptr, info_ptr, length);
  164452. #endif
  164453. #if defined(PNG_READ_sBIT_SUPPORTED)
  164454. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164455. png_handle_sBIT(png_ptr, info_ptr, length);
  164456. #endif
  164457. #if defined(PNG_READ_sRGB_SUPPORTED)
  164458. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164459. png_handle_sRGB(png_ptr, info_ptr, length);
  164460. #endif
  164461. #if defined(PNG_READ_iCCP_SUPPORTED)
  164462. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164463. png_handle_iCCP(png_ptr, info_ptr, length);
  164464. #endif
  164465. #if defined(PNG_READ_sPLT_SUPPORTED)
  164466. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164467. png_handle_sPLT(png_ptr, info_ptr, length);
  164468. #endif
  164469. #if defined(PNG_READ_tEXt_SUPPORTED)
  164470. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164471. png_handle_tEXt(png_ptr, info_ptr, length);
  164472. #endif
  164473. #if defined(PNG_READ_tIME_SUPPORTED)
  164474. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164475. png_handle_tIME(png_ptr, info_ptr, length);
  164476. #endif
  164477. #if defined(PNG_READ_tRNS_SUPPORTED)
  164478. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164479. png_handle_tRNS(png_ptr, info_ptr, length);
  164480. #endif
  164481. #if defined(PNG_READ_zTXt_SUPPORTED)
  164482. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164483. png_handle_zTXt(png_ptr, info_ptr, length);
  164484. #endif
  164485. #if defined(PNG_READ_iTXt_SUPPORTED)
  164486. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164487. png_handle_iTXt(png_ptr, info_ptr, length);
  164488. #endif
  164489. else
  164490. png_handle_unknown(png_ptr, info_ptr, length);
  164491. }
  164492. }
  164493. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164494. void PNGAPI
  164495. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164496. {
  164497. png_debug(1, "in png_read_update_info\n");
  164498. if(png_ptr == NULL) return;
  164499. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164500. png_read_start_row(png_ptr);
  164501. else
  164502. png_warning(png_ptr,
  164503. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164504. png_read_transform_info(png_ptr, info_ptr);
  164505. }
  164506. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164507. void PNGAPI
  164508. png_start_read_image(png_structp png_ptr)
  164509. {
  164510. png_debug(1, "in png_start_read_image\n");
  164511. if(png_ptr == NULL) return;
  164512. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164513. png_read_start_row(png_ptr);
  164514. }
  164515. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164516. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164517. void PNGAPI
  164518. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164519. {
  164520. #ifdef PNG_USE_LOCAL_ARRAYS
  164521. PNG_CONST PNG_IDAT;
  164522. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164523. 0xff};
  164524. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164525. #endif
  164526. int ret;
  164527. if(png_ptr == NULL) return;
  164528. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164529. png_ptr->row_number, png_ptr->pass);
  164530. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164531. png_read_start_row(png_ptr);
  164532. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164533. {
  164534. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164535. if (png_ptr->transformations & PNG_INVERT_MONO)
  164536. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164537. #endif
  164538. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164539. if (png_ptr->transformations & PNG_FILLER)
  164540. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164541. #endif
  164542. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164543. if (png_ptr->transformations & PNG_PACKSWAP)
  164544. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164545. #endif
  164546. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164547. if (png_ptr->transformations & PNG_PACK)
  164548. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164549. #endif
  164550. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164551. if (png_ptr->transformations & PNG_SHIFT)
  164552. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164553. #endif
  164554. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164555. if (png_ptr->transformations & PNG_BGR)
  164556. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164557. #endif
  164558. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164559. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164560. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164561. #endif
  164562. }
  164563. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164564. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164565. {
  164566. switch (png_ptr->pass)
  164567. {
  164568. case 0:
  164569. if (png_ptr->row_number & 0x07)
  164570. {
  164571. if (dsp_row != NULL)
  164572. png_combine_row(png_ptr, dsp_row,
  164573. png_pass_dsp_mask[png_ptr->pass]);
  164574. png_read_finish_row(png_ptr);
  164575. return;
  164576. }
  164577. break;
  164578. case 1:
  164579. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164580. {
  164581. if (dsp_row != NULL)
  164582. png_combine_row(png_ptr, dsp_row,
  164583. png_pass_dsp_mask[png_ptr->pass]);
  164584. png_read_finish_row(png_ptr);
  164585. return;
  164586. }
  164587. break;
  164588. case 2:
  164589. if ((png_ptr->row_number & 0x07) != 4)
  164590. {
  164591. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164592. png_combine_row(png_ptr, dsp_row,
  164593. png_pass_dsp_mask[png_ptr->pass]);
  164594. png_read_finish_row(png_ptr);
  164595. return;
  164596. }
  164597. break;
  164598. case 3:
  164599. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164600. {
  164601. if (dsp_row != NULL)
  164602. png_combine_row(png_ptr, dsp_row,
  164603. png_pass_dsp_mask[png_ptr->pass]);
  164604. png_read_finish_row(png_ptr);
  164605. return;
  164606. }
  164607. break;
  164608. case 4:
  164609. if ((png_ptr->row_number & 3) != 2)
  164610. {
  164611. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164612. png_combine_row(png_ptr, dsp_row,
  164613. png_pass_dsp_mask[png_ptr->pass]);
  164614. png_read_finish_row(png_ptr);
  164615. return;
  164616. }
  164617. break;
  164618. case 5:
  164619. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164620. {
  164621. if (dsp_row != NULL)
  164622. png_combine_row(png_ptr, dsp_row,
  164623. png_pass_dsp_mask[png_ptr->pass]);
  164624. png_read_finish_row(png_ptr);
  164625. return;
  164626. }
  164627. break;
  164628. case 6:
  164629. if (!(png_ptr->row_number & 1))
  164630. {
  164631. png_read_finish_row(png_ptr);
  164632. return;
  164633. }
  164634. break;
  164635. }
  164636. }
  164637. #endif
  164638. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164639. png_error(png_ptr, "Invalid attempt to read row data");
  164640. png_ptr->zstream.next_out = png_ptr->row_buf;
  164641. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164642. do
  164643. {
  164644. if (!(png_ptr->zstream.avail_in))
  164645. {
  164646. while (!png_ptr->idat_size)
  164647. {
  164648. png_byte chunk_length[4];
  164649. png_crc_finish(png_ptr, 0);
  164650. png_read_data(png_ptr, chunk_length, 4);
  164651. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164652. png_reset_crc(png_ptr);
  164653. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164654. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164655. png_error(png_ptr, "Not enough image data");
  164656. }
  164657. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164658. png_ptr->zstream.next_in = png_ptr->zbuf;
  164659. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164660. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164661. png_crc_read(png_ptr, png_ptr->zbuf,
  164662. (png_size_t)png_ptr->zstream.avail_in);
  164663. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164664. }
  164665. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164666. if (ret == Z_STREAM_END)
  164667. {
  164668. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164669. png_ptr->idat_size)
  164670. png_error(png_ptr, "Extra compressed data");
  164671. png_ptr->mode |= PNG_AFTER_IDAT;
  164672. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164673. break;
  164674. }
  164675. if (ret != Z_OK)
  164676. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164677. "Decompression error");
  164678. } while (png_ptr->zstream.avail_out);
  164679. png_ptr->row_info.color_type = png_ptr->color_type;
  164680. png_ptr->row_info.width = png_ptr->iwidth;
  164681. png_ptr->row_info.channels = png_ptr->channels;
  164682. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164683. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164684. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164685. png_ptr->row_info.width);
  164686. if(png_ptr->row_buf[0])
  164687. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164688. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164689. (int)(png_ptr->row_buf[0]));
  164690. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164691. png_ptr->rowbytes + 1);
  164692. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164693. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164694. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164695. {
  164696. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164697. }
  164698. #endif
  164699. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164700. png_do_read_transformations(png_ptr);
  164701. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164702. if (png_ptr->interlaced &&
  164703. (png_ptr->transformations & PNG_INTERLACE))
  164704. {
  164705. if (png_ptr->pass < 6)
  164706. png_do_read_interlace(png_ptr);
  164707. if (dsp_row != NULL)
  164708. png_combine_row(png_ptr, dsp_row,
  164709. png_pass_dsp_mask[png_ptr->pass]);
  164710. if (row != NULL)
  164711. png_combine_row(png_ptr, row,
  164712. png_pass_mask[png_ptr->pass]);
  164713. }
  164714. else
  164715. #endif
  164716. {
  164717. if (row != NULL)
  164718. png_combine_row(png_ptr, row, 0xff);
  164719. if (dsp_row != NULL)
  164720. png_combine_row(png_ptr, dsp_row, 0xff);
  164721. }
  164722. png_read_finish_row(png_ptr);
  164723. if (png_ptr->read_row_fn != NULL)
  164724. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  164725. }
  164726. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164727. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164728. void PNGAPI
  164729. png_read_rows(png_structp png_ptr, png_bytepp row,
  164730. png_bytepp display_row, png_uint_32 num_rows)
  164731. {
  164732. png_uint_32 i;
  164733. png_bytepp rp;
  164734. png_bytepp dp;
  164735. png_debug(1, "in png_read_rows\n");
  164736. if(png_ptr == NULL) return;
  164737. rp = row;
  164738. dp = display_row;
  164739. if (rp != NULL && dp != NULL)
  164740. for (i = 0; i < num_rows; i++)
  164741. {
  164742. png_bytep rptr = *rp++;
  164743. png_bytep dptr = *dp++;
  164744. png_read_row(png_ptr, rptr, dptr);
  164745. }
  164746. else if(rp != NULL)
  164747. for (i = 0; i < num_rows; i++)
  164748. {
  164749. png_bytep rptr = *rp;
  164750. png_read_row(png_ptr, rptr, png_bytep_NULL);
  164751. rp++;
  164752. }
  164753. else if(dp != NULL)
  164754. for (i = 0; i < num_rows; i++)
  164755. {
  164756. png_bytep dptr = *dp;
  164757. png_read_row(png_ptr, png_bytep_NULL, dptr);
  164758. dp++;
  164759. }
  164760. }
  164761. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164762. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164763. void PNGAPI
  164764. png_read_image(png_structp png_ptr, png_bytepp image)
  164765. {
  164766. png_uint_32 i,image_height;
  164767. int pass, j;
  164768. png_bytepp rp;
  164769. png_debug(1, "in png_read_image\n");
  164770. if(png_ptr == NULL) return;
  164771. #ifdef PNG_READ_INTERLACING_SUPPORTED
  164772. pass = png_set_interlace_handling(png_ptr);
  164773. #else
  164774. if (png_ptr->interlaced)
  164775. png_error(png_ptr,
  164776. "Cannot read interlaced image -- interlace handler disabled.");
  164777. pass = 1;
  164778. #endif
  164779. image_height=png_ptr->height;
  164780. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  164781. for (j = 0; j < pass; j++)
  164782. {
  164783. rp = image;
  164784. for (i = 0; i < image_height; i++)
  164785. {
  164786. png_read_row(png_ptr, *rp, png_bytep_NULL);
  164787. rp++;
  164788. }
  164789. }
  164790. }
  164791. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164792. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164793. void PNGAPI
  164794. png_read_end(png_structp png_ptr, png_infop info_ptr)
  164795. {
  164796. png_byte chunk_length[4];
  164797. png_uint_32 length;
  164798. png_debug(1, "in png_read_end\n");
  164799. if(png_ptr == NULL) return;
  164800. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  164801. do
  164802. {
  164803. #ifdef PNG_USE_LOCAL_ARRAYS
  164804. PNG_CONST PNG_IHDR;
  164805. PNG_CONST PNG_IDAT;
  164806. PNG_CONST PNG_IEND;
  164807. PNG_CONST PNG_PLTE;
  164808. #if defined(PNG_READ_bKGD_SUPPORTED)
  164809. PNG_CONST PNG_bKGD;
  164810. #endif
  164811. #if defined(PNG_READ_cHRM_SUPPORTED)
  164812. PNG_CONST PNG_cHRM;
  164813. #endif
  164814. #if defined(PNG_READ_gAMA_SUPPORTED)
  164815. PNG_CONST PNG_gAMA;
  164816. #endif
  164817. #if defined(PNG_READ_hIST_SUPPORTED)
  164818. PNG_CONST PNG_hIST;
  164819. #endif
  164820. #if defined(PNG_READ_iCCP_SUPPORTED)
  164821. PNG_CONST PNG_iCCP;
  164822. #endif
  164823. #if defined(PNG_READ_iTXt_SUPPORTED)
  164824. PNG_CONST PNG_iTXt;
  164825. #endif
  164826. #if defined(PNG_READ_oFFs_SUPPORTED)
  164827. PNG_CONST PNG_oFFs;
  164828. #endif
  164829. #if defined(PNG_READ_pCAL_SUPPORTED)
  164830. PNG_CONST PNG_pCAL;
  164831. #endif
  164832. #if defined(PNG_READ_pHYs_SUPPORTED)
  164833. PNG_CONST PNG_pHYs;
  164834. #endif
  164835. #if defined(PNG_READ_sBIT_SUPPORTED)
  164836. PNG_CONST PNG_sBIT;
  164837. #endif
  164838. #if defined(PNG_READ_sCAL_SUPPORTED)
  164839. PNG_CONST PNG_sCAL;
  164840. #endif
  164841. #if defined(PNG_READ_sPLT_SUPPORTED)
  164842. PNG_CONST PNG_sPLT;
  164843. #endif
  164844. #if defined(PNG_READ_sRGB_SUPPORTED)
  164845. PNG_CONST PNG_sRGB;
  164846. #endif
  164847. #if defined(PNG_READ_tEXt_SUPPORTED)
  164848. PNG_CONST PNG_tEXt;
  164849. #endif
  164850. #if defined(PNG_READ_tIME_SUPPORTED)
  164851. PNG_CONST PNG_tIME;
  164852. #endif
  164853. #if defined(PNG_READ_tRNS_SUPPORTED)
  164854. PNG_CONST PNG_tRNS;
  164855. #endif
  164856. #if defined(PNG_READ_zTXt_SUPPORTED)
  164857. PNG_CONST PNG_zTXt;
  164858. #endif
  164859. #endif /* PNG_USE_LOCAL_ARRAYS */
  164860. png_read_data(png_ptr, chunk_length, 4);
  164861. length = png_get_uint_31(png_ptr,chunk_length);
  164862. png_reset_crc(png_ptr);
  164863. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164864. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  164865. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164866. png_handle_IHDR(png_ptr, info_ptr, length);
  164867. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164868. png_handle_IEND(png_ptr, info_ptr, length);
  164869. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164870. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164871. {
  164872. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164873. {
  164874. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  164875. png_error(png_ptr, "Too many IDAT's found");
  164876. }
  164877. png_handle_unknown(png_ptr, info_ptr, length);
  164878. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164879. png_ptr->mode |= PNG_HAVE_PLTE;
  164880. }
  164881. #endif
  164882. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164883. {
  164884. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  164885. png_error(png_ptr, "Too many IDAT's found");
  164886. png_crc_finish(png_ptr, length);
  164887. }
  164888. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164889. png_handle_PLTE(png_ptr, info_ptr, length);
  164890. #if defined(PNG_READ_bKGD_SUPPORTED)
  164891. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164892. png_handle_bKGD(png_ptr, info_ptr, length);
  164893. #endif
  164894. #if defined(PNG_READ_cHRM_SUPPORTED)
  164895. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164896. png_handle_cHRM(png_ptr, info_ptr, length);
  164897. #endif
  164898. #if defined(PNG_READ_gAMA_SUPPORTED)
  164899. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164900. png_handle_gAMA(png_ptr, info_ptr, length);
  164901. #endif
  164902. #if defined(PNG_READ_hIST_SUPPORTED)
  164903. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164904. png_handle_hIST(png_ptr, info_ptr, length);
  164905. #endif
  164906. #if defined(PNG_READ_oFFs_SUPPORTED)
  164907. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164908. png_handle_oFFs(png_ptr, info_ptr, length);
  164909. #endif
  164910. #if defined(PNG_READ_pCAL_SUPPORTED)
  164911. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164912. png_handle_pCAL(png_ptr, info_ptr, length);
  164913. #endif
  164914. #if defined(PNG_READ_sCAL_SUPPORTED)
  164915. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164916. png_handle_sCAL(png_ptr, info_ptr, length);
  164917. #endif
  164918. #if defined(PNG_READ_pHYs_SUPPORTED)
  164919. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164920. png_handle_pHYs(png_ptr, info_ptr, length);
  164921. #endif
  164922. #if defined(PNG_READ_sBIT_SUPPORTED)
  164923. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164924. png_handle_sBIT(png_ptr, info_ptr, length);
  164925. #endif
  164926. #if defined(PNG_READ_sRGB_SUPPORTED)
  164927. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164928. png_handle_sRGB(png_ptr, info_ptr, length);
  164929. #endif
  164930. #if defined(PNG_READ_iCCP_SUPPORTED)
  164931. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164932. png_handle_iCCP(png_ptr, info_ptr, length);
  164933. #endif
  164934. #if defined(PNG_READ_sPLT_SUPPORTED)
  164935. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164936. png_handle_sPLT(png_ptr, info_ptr, length);
  164937. #endif
  164938. #if defined(PNG_READ_tEXt_SUPPORTED)
  164939. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164940. png_handle_tEXt(png_ptr, info_ptr, length);
  164941. #endif
  164942. #if defined(PNG_READ_tIME_SUPPORTED)
  164943. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164944. png_handle_tIME(png_ptr, info_ptr, length);
  164945. #endif
  164946. #if defined(PNG_READ_tRNS_SUPPORTED)
  164947. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164948. png_handle_tRNS(png_ptr, info_ptr, length);
  164949. #endif
  164950. #if defined(PNG_READ_zTXt_SUPPORTED)
  164951. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164952. png_handle_zTXt(png_ptr, info_ptr, length);
  164953. #endif
  164954. #if defined(PNG_READ_iTXt_SUPPORTED)
  164955. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164956. png_handle_iTXt(png_ptr, info_ptr, length);
  164957. #endif
  164958. else
  164959. png_handle_unknown(png_ptr, info_ptr, length);
  164960. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  164961. }
  164962. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164963. void PNGAPI
  164964. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  164965. png_infopp end_info_ptr_ptr)
  164966. {
  164967. png_structp png_ptr = NULL;
  164968. png_infop info_ptr = NULL, end_info_ptr = NULL;
  164969. #ifdef PNG_USER_MEM_SUPPORTED
  164970. png_free_ptr free_fn;
  164971. png_voidp mem_ptr;
  164972. #endif
  164973. png_debug(1, "in png_destroy_read_struct\n");
  164974. if (png_ptr_ptr != NULL)
  164975. png_ptr = *png_ptr_ptr;
  164976. if (info_ptr_ptr != NULL)
  164977. info_ptr = *info_ptr_ptr;
  164978. if (end_info_ptr_ptr != NULL)
  164979. end_info_ptr = *end_info_ptr_ptr;
  164980. #ifdef PNG_USER_MEM_SUPPORTED
  164981. free_fn = png_ptr->free_fn;
  164982. mem_ptr = png_ptr->mem_ptr;
  164983. #endif
  164984. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  164985. if (info_ptr != NULL)
  164986. {
  164987. #if defined(PNG_TEXT_SUPPORTED)
  164988. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  164989. #endif
  164990. #ifdef PNG_USER_MEM_SUPPORTED
  164991. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  164992. (png_voidp)mem_ptr);
  164993. #else
  164994. png_destroy_struct((png_voidp)info_ptr);
  164995. #endif
  164996. *info_ptr_ptr = NULL;
  164997. }
  164998. if (end_info_ptr != NULL)
  164999. {
  165000. #if defined(PNG_READ_TEXT_SUPPORTED)
  165001. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165002. #endif
  165003. #ifdef PNG_USER_MEM_SUPPORTED
  165004. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165005. (png_voidp)mem_ptr);
  165006. #else
  165007. png_destroy_struct((png_voidp)end_info_ptr);
  165008. #endif
  165009. *end_info_ptr_ptr = NULL;
  165010. }
  165011. if (png_ptr != NULL)
  165012. {
  165013. #ifdef PNG_USER_MEM_SUPPORTED
  165014. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165015. (png_voidp)mem_ptr);
  165016. #else
  165017. png_destroy_struct((png_voidp)png_ptr);
  165018. #endif
  165019. *png_ptr_ptr = NULL;
  165020. }
  165021. }
  165022. void /* PRIVATE */
  165023. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165024. {
  165025. #ifdef PNG_SETJMP_SUPPORTED
  165026. jmp_buf tmp_jmp;
  165027. #endif
  165028. png_error_ptr error_fn;
  165029. png_error_ptr warning_fn;
  165030. png_voidp error_ptr;
  165031. #ifdef PNG_USER_MEM_SUPPORTED
  165032. png_free_ptr free_fn;
  165033. #endif
  165034. png_debug(1, "in png_read_destroy\n");
  165035. if (info_ptr != NULL)
  165036. png_info_destroy(png_ptr, info_ptr);
  165037. if (end_info_ptr != NULL)
  165038. png_info_destroy(png_ptr, end_info_ptr);
  165039. png_free(png_ptr, png_ptr->zbuf);
  165040. png_free(png_ptr, png_ptr->big_row_buf);
  165041. png_free(png_ptr, png_ptr->prev_row);
  165042. #if defined(PNG_READ_DITHER_SUPPORTED)
  165043. png_free(png_ptr, png_ptr->palette_lookup);
  165044. png_free(png_ptr, png_ptr->dither_index);
  165045. #endif
  165046. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165047. png_free(png_ptr, png_ptr->gamma_table);
  165048. #endif
  165049. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165050. png_free(png_ptr, png_ptr->gamma_from_1);
  165051. png_free(png_ptr, png_ptr->gamma_to_1);
  165052. #endif
  165053. #ifdef PNG_FREE_ME_SUPPORTED
  165054. if (png_ptr->free_me & PNG_FREE_PLTE)
  165055. png_zfree(png_ptr, png_ptr->palette);
  165056. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165057. #else
  165058. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165059. png_zfree(png_ptr, png_ptr->palette);
  165060. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165061. #endif
  165062. #if defined(PNG_tRNS_SUPPORTED) || \
  165063. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165064. #ifdef PNG_FREE_ME_SUPPORTED
  165065. if (png_ptr->free_me & PNG_FREE_TRNS)
  165066. png_free(png_ptr, png_ptr->trans);
  165067. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165068. #else
  165069. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165070. png_free(png_ptr, png_ptr->trans);
  165071. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165072. #endif
  165073. #endif
  165074. #if defined(PNG_READ_hIST_SUPPORTED)
  165075. #ifdef PNG_FREE_ME_SUPPORTED
  165076. if (png_ptr->free_me & PNG_FREE_HIST)
  165077. png_free(png_ptr, png_ptr->hist);
  165078. png_ptr->free_me &= ~PNG_FREE_HIST;
  165079. #else
  165080. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165081. png_free(png_ptr, png_ptr->hist);
  165082. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165083. #endif
  165084. #endif
  165085. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165086. if (png_ptr->gamma_16_table != NULL)
  165087. {
  165088. int i;
  165089. int istop = (1 << (8 - png_ptr->gamma_shift));
  165090. for (i = 0; i < istop; i++)
  165091. {
  165092. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165093. }
  165094. png_free(png_ptr, png_ptr->gamma_16_table);
  165095. }
  165096. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165097. if (png_ptr->gamma_16_from_1 != NULL)
  165098. {
  165099. int i;
  165100. int istop = (1 << (8 - png_ptr->gamma_shift));
  165101. for (i = 0; i < istop; i++)
  165102. {
  165103. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165104. }
  165105. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165106. }
  165107. if (png_ptr->gamma_16_to_1 != NULL)
  165108. {
  165109. int i;
  165110. int istop = (1 << (8 - png_ptr->gamma_shift));
  165111. for (i = 0; i < istop; i++)
  165112. {
  165113. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165114. }
  165115. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165116. }
  165117. #endif
  165118. #endif
  165119. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165120. png_free(png_ptr, png_ptr->time_buffer);
  165121. #endif
  165122. inflateEnd(&png_ptr->zstream);
  165123. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165124. png_free(png_ptr, png_ptr->save_buffer);
  165125. #endif
  165126. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165127. #ifdef PNG_TEXT_SUPPORTED
  165128. png_free(png_ptr, png_ptr->current_text);
  165129. #endif /* PNG_TEXT_SUPPORTED */
  165130. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165131. #ifdef PNG_SETJMP_SUPPORTED
  165132. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165133. #endif
  165134. error_fn = png_ptr->error_fn;
  165135. warning_fn = png_ptr->warning_fn;
  165136. error_ptr = png_ptr->error_ptr;
  165137. #ifdef PNG_USER_MEM_SUPPORTED
  165138. free_fn = png_ptr->free_fn;
  165139. #endif
  165140. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165141. png_ptr->error_fn = error_fn;
  165142. png_ptr->warning_fn = warning_fn;
  165143. png_ptr->error_ptr = error_ptr;
  165144. #ifdef PNG_USER_MEM_SUPPORTED
  165145. png_ptr->free_fn = free_fn;
  165146. #endif
  165147. #ifdef PNG_SETJMP_SUPPORTED
  165148. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165149. #endif
  165150. }
  165151. void PNGAPI
  165152. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165153. {
  165154. if(png_ptr == NULL) return;
  165155. png_ptr->read_row_fn = read_row_fn;
  165156. }
  165157. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165158. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165159. void PNGAPI
  165160. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165161. int transforms,
  165162. voidp params)
  165163. {
  165164. int row;
  165165. if(png_ptr == NULL) return;
  165166. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165167. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165168. png_set_invert_alpha(png_ptr);
  165169. #endif
  165170. png_read_info(png_ptr, info_ptr);
  165171. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165172. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165173. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165174. if (transforms & PNG_TRANSFORM_STRIP_16)
  165175. png_set_strip_16(png_ptr);
  165176. #endif
  165177. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165178. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165179. png_set_strip_alpha(png_ptr);
  165180. #endif
  165181. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165182. if (transforms & PNG_TRANSFORM_PACKING)
  165183. png_set_packing(png_ptr);
  165184. #endif
  165185. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165186. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165187. png_set_packswap(png_ptr);
  165188. #endif
  165189. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165190. if (transforms & PNG_TRANSFORM_EXPAND)
  165191. if ((png_ptr->bit_depth < 8) ||
  165192. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165193. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165194. png_set_expand(png_ptr);
  165195. #endif
  165196. #if defined(PNG_READ_INVERT_SUPPORTED)
  165197. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165198. png_set_invert_mono(png_ptr);
  165199. #endif
  165200. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165201. if ((transforms & PNG_TRANSFORM_SHIFT)
  165202. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165203. {
  165204. png_color_8p sig_bit;
  165205. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165206. png_set_shift(png_ptr, sig_bit);
  165207. }
  165208. #endif
  165209. #if defined(PNG_READ_BGR_SUPPORTED)
  165210. if (transforms & PNG_TRANSFORM_BGR)
  165211. png_set_bgr(png_ptr);
  165212. #endif
  165213. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165214. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165215. png_set_swap_alpha(png_ptr);
  165216. #endif
  165217. #if defined(PNG_READ_SWAP_SUPPORTED)
  165218. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165219. png_set_swap(png_ptr);
  165220. #endif
  165221. png_read_update_info(png_ptr, info_ptr);
  165222. #ifdef PNG_FREE_ME_SUPPORTED
  165223. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165224. #endif
  165225. if(info_ptr->row_pointers == NULL)
  165226. {
  165227. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165228. info_ptr->height * png_sizeof(png_bytep));
  165229. #ifdef PNG_FREE_ME_SUPPORTED
  165230. info_ptr->free_me |= PNG_FREE_ROWS;
  165231. #endif
  165232. for (row = 0; row < (int)info_ptr->height; row++)
  165233. {
  165234. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165235. png_get_rowbytes(png_ptr, info_ptr));
  165236. }
  165237. }
  165238. png_read_image(png_ptr, info_ptr->row_pointers);
  165239. info_ptr->valid |= PNG_INFO_IDAT;
  165240. png_read_end(png_ptr, info_ptr);
  165241. transforms = transforms; /* quiet compiler warnings */
  165242. params = params;
  165243. }
  165244. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165245. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165246. #endif /* PNG_READ_SUPPORTED */
  165247. /*** End of inlined file: pngread.c ***/
  165248. /*** Start of inlined file: pngpread.c ***/
  165249. #define PNG_INTERNAL
  165250. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165251. #define PNG_READ_SIG_MODE 0
  165252. #define PNG_READ_CHUNK_MODE 1
  165253. #define PNG_READ_IDAT_MODE 2
  165254. #define PNG_SKIP_MODE 3
  165255. #define PNG_READ_tEXt_MODE 4
  165256. #define PNG_READ_zTXt_MODE 5
  165257. #define PNG_READ_DONE_MODE 6
  165258. #define PNG_READ_iTXt_MODE 7
  165259. #define PNG_ERROR_MODE 8
  165260. void PNGAPI
  165261. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165262. png_bytep buffer, png_size_t buffer_size)
  165263. {
  165264. if(png_ptr == NULL) return;
  165265. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165266. while (png_ptr->buffer_size)
  165267. {
  165268. png_process_some_data(png_ptr, info_ptr);
  165269. }
  165270. }
  165271. void /* PRIVATE */
  165272. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165273. {
  165274. if(png_ptr == NULL) return;
  165275. switch (png_ptr->process_mode)
  165276. {
  165277. case PNG_READ_SIG_MODE:
  165278. {
  165279. png_push_read_sig(png_ptr, info_ptr);
  165280. break;
  165281. }
  165282. case PNG_READ_CHUNK_MODE:
  165283. {
  165284. png_push_read_chunk(png_ptr, info_ptr);
  165285. break;
  165286. }
  165287. case PNG_READ_IDAT_MODE:
  165288. {
  165289. png_push_read_IDAT(png_ptr);
  165290. break;
  165291. }
  165292. #if defined(PNG_READ_tEXt_SUPPORTED)
  165293. case PNG_READ_tEXt_MODE:
  165294. {
  165295. png_push_read_tEXt(png_ptr, info_ptr);
  165296. break;
  165297. }
  165298. #endif
  165299. #if defined(PNG_READ_zTXt_SUPPORTED)
  165300. case PNG_READ_zTXt_MODE:
  165301. {
  165302. png_push_read_zTXt(png_ptr, info_ptr);
  165303. break;
  165304. }
  165305. #endif
  165306. #if defined(PNG_READ_iTXt_SUPPORTED)
  165307. case PNG_READ_iTXt_MODE:
  165308. {
  165309. png_push_read_iTXt(png_ptr, info_ptr);
  165310. break;
  165311. }
  165312. #endif
  165313. case PNG_SKIP_MODE:
  165314. {
  165315. png_push_crc_finish(png_ptr);
  165316. break;
  165317. }
  165318. default:
  165319. {
  165320. png_ptr->buffer_size = 0;
  165321. break;
  165322. }
  165323. }
  165324. }
  165325. void /* PRIVATE */
  165326. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165327. {
  165328. png_size_t num_checked = png_ptr->sig_bytes,
  165329. num_to_check = 8 - num_checked;
  165330. if (png_ptr->buffer_size < num_to_check)
  165331. {
  165332. num_to_check = png_ptr->buffer_size;
  165333. }
  165334. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165335. num_to_check);
  165336. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165337. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165338. {
  165339. if (num_checked < 4 &&
  165340. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165341. png_error(png_ptr, "Not a PNG file");
  165342. else
  165343. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165344. }
  165345. else
  165346. {
  165347. if (png_ptr->sig_bytes >= 8)
  165348. {
  165349. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165350. }
  165351. }
  165352. }
  165353. void /* PRIVATE */
  165354. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165355. {
  165356. #ifdef PNG_USE_LOCAL_ARRAYS
  165357. PNG_CONST PNG_IHDR;
  165358. PNG_CONST PNG_IDAT;
  165359. PNG_CONST PNG_IEND;
  165360. PNG_CONST PNG_PLTE;
  165361. #if defined(PNG_READ_bKGD_SUPPORTED)
  165362. PNG_CONST PNG_bKGD;
  165363. #endif
  165364. #if defined(PNG_READ_cHRM_SUPPORTED)
  165365. PNG_CONST PNG_cHRM;
  165366. #endif
  165367. #if defined(PNG_READ_gAMA_SUPPORTED)
  165368. PNG_CONST PNG_gAMA;
  165369. #endif
  165370. #if defined(PNG_READ_hIST_SUPPORTED)
  165371. PNG_CONST PNG_hIST;
  165372. #endif
  165373. #if defined(PNG_READ_iCCP_SUPPORTED)
  165374. PNG_CONST PNG_iCCP;
  165375. #endif
  165376. #if defined(PNG_READ_iTXt_SUPPORTED)
  165377. PNG_CONST PNG_iTXt;
  165378. #endif
  165379. #if defined(PNG_READ_oFFs_SUPPORTED)
  165380. PNG_CONST PNG_oFFs;
  165381. #endif
  165382. #if defined(PNG_READ_pCAL_SUPPORTED)
  165383. PNG_CONST PNG_pCAL;
  165384. #endif
  165385. #if defined(PNG_READ_pHYs_SUPPORTED)
  165386. PNG_CONST PNG_pHYs;
  165387. #endif
  165388. #if defined(PNG_READ_sBIT_SUPPORTED)
  165389. PNG_CONST PNG_sBIT;
  165390. #endif
  165391. #if defined(PNG_READ_sCAL_SUPPORTED)
  165392. PNG_CONST PNG_sCAL;
  165393. #endif
  165394. #if defined(PNG_READ_sRGB_SUPPORTED)
  165395. PNG_CONST PNG_sRGB;
  165396. #endif
  165397. #if defined(PNG_READ_sPLT_SUPPORTED)
  165398. PNG_CONST PNG_sPLT;
  165399. #endif
  165400. #if defined(PNG_READ_tEXt_SUPPORTED)
  165401. PNG_CONST PNG_tEXt;
  165402. #endif
  165403. #if defined(PNG_READ_tIME_SUPPORTED)
  165404. PNG_CONST PNG_tIME;
  165405. #endif
  165406. #if defined(PNG_READ_tRNS_SUPPORTED)
  165407. PNG_CONST PNG_tRNS;
  165408. #endif
  165409. #if defined(PNG_READ_zTXt_SUPPORTED)
  165410. PNG_CONST PNG_zTXt;
  165411. #endif
  165412. #endif /* PNG_USE_LOCAL_ARRAYS */
  165413. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165414. {
  165415. png_byte chunk_length[4];
  165416. if (png_ptr->buffer_size < 8)
  165417. {
  165418. png_push_save_buffer(png_ptr);
  165419. return;
  165420. }
  165421. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165422. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165423. png_reset_crc(png_ptr);
  165424. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165425. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165426. }
  165427. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165428. if(png_ptr->mode & PNG_AFTER_IDAT)
  165429. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165430. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165431. {
  165432. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165433. {
  165434. png_push_save_buffer(png_ptr);
  165435. return;
  165436. }
  165437. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165438. }
  165439. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165440. {
  165441. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165442. {
  165443. png_push_save_buffer(png_ptr);
  165444. return;
  165445. }
  165446. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165447. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165448. png_push_have_end(png_ptr, info_ptr);
  165449. }
  165450. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165451. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165452. {
  165453. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165454. {
  165455. png_push_save_buffer(png_ptr);
  165456. return;
  165457. }
  165458. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165459. png_ptr->mode |= PNG_HAVE_IDAT;
  165460. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165461. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165462. png_ptr->mode |= PNG_HAVE_PLTE;
  165463. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165464. {
  165465. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165466. png_error(png_ptr, "Missing IHDR before IDAT");
  165467. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165468. !(png_ptr->mode & PNG_HAVE_PLTE))
  165469. png_error(png_ptr, "Missing PLTE before IDAT");
  165470. }
  165471. }
  165472. #endif
  165473. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165474. {
  165475. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165476. {
  165477. png_push_save_buffer(png_ptr);
  165478. return;
  165479. }
  165480. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165481. }
  165482. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165483. {
  165484. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165485. png_error(png_ptr, "Missing IHDR before IDAT");
  165486. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165487. !(png_ptr->mode & PNG_HAVE_PLTE))
  165488. png_error(png_ptr, "Missing PLTE before IDAT");
  165489. if (png_ptr->mode & PNG_HAVE_IDAT)
  165490. {
  165491. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165492. if (png_ptr->push_length == 0)
  165493. return;
  165494. if (png_ptr->mode & PNG_AFTER_IDAT)
  165495. png_error(png_ptr, "Too many IDAT's found");
  165496. }
  165497. png_ptr->idat_size = png_ptr->push_length;
  165498. png_ptr->mode |= PNG_HAVE_IDAT;
  165499. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165500. png_push_have_info(png_ptr, info_ptr);
  165501. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165502. png_ptr->zstream.next_out = png_ptr->row_buf;
  165503. return;
  165504. }
  165505. #if defined(PNG_READ_gAMA_SUPPORTED)
  165506. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165507. {
  165508. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165509. {
  165510. png_push_save_buffer(png_ptr);
  165511. return;
  165512. }
  165513. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165514. }
  165515. #endif
  165516. #if defined(PNG_READ_sBIT_SUPPORTED)
  165517. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165518. {
  165519. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165520. {
  165521. png_push_save_buffer(png_ptr);
  165522. return;
  165523. }
  165524. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165525. }
  165526. #endif
  165527. #if defined(PNG_READ_cHRM_SUPPORTED)
  165528. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165529. {
  165530. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165531. {
  165532. png_push_save_buffer(png_ptr);
  165533. return;
  165534. }
  165535. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165536. }
  165537. #endif
  165538. #if defined(PNG_READ_sRGB_SUPPORTED)
  165539. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165540. {
  165541. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165542. {
  165543. png_push_save_buffer(png_ptr);
  165544. return;
  165545. }
  165546. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165547. }
  165548. #endif
  165549. #if defined(PNG_READ_iCCP_SUPPORTED)
  165550. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165551. {
  165552. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165553. {
  165554. png_push_save_buffer(png_ptr);
  165555. return;
  165556. }
  165557. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165558. }
  165559. #endif
  165560. #if defined(PNG_READ_sPLT_SUPPORTED)
  165561. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165562. {
  165563. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165564. {
  165565. png_push_save_buffer(png_ptr);
  165566. return;
  165567. }
  165568. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165569. }
  165570. #endif
  165571. #if defined(PNG_READ_tRNS_SUPPORTED)
  165572. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165573. {
  165574. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165575. {
  165576. png_push_save_buffer(png_ptr);
  165577. return;
  165578. }
  165579. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165580. }
  165581. #endif
  165582. #if defined(PNG_READ_bKGD_SUPPORTED)
  165583. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165584. {
  165585. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165586. {
  165587. png_push_save_buffer(png_ptr);
  165588. return;
  165589. }
  165590. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165591. }
  165592. #endif
  165593. #if defined(PNG_READ_hIST_SUPPORTED)
  165594. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165595. {
  165596. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165597. {
  165598. png_push_save_buffer(png_ptr);
  165599. return;
  165600. }
  165601. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165602. }
  165603. #endif
  165604. #if defined(PNG_READ_pHYs_SUPPORTED)
  165605. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165606. {
  165607. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165608. {
  165609. png_push_save_buffer(png_ptr);
  165610. return;
  165611. }
  165612. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165613. }
  165614. #endif
  165615. #if defined(PNG_READ_oFFs_SUPPORTED)
  165616. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165617. {
  165618. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165619. {
  165620. png_push_save_buffer(png_ptr);
  165621. return;
  165622. }
  165623. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165624. }
  165625. #endif
  165626. #if defined(PNG_READ_pCAL_SUPPORTED)
  165627. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165628. {
  165629. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165630. {
  165631. png_push_save_buffer(png_ptr);
  165632. return;
  165633. }
  165634. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165635. }
  165636. #endif
  165637. #if defined(PNG_READ_sCAL_SUPPORTED)
  165638. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165639. {
  165640. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165641. {
  165642. png_push_save_buffer(png_ptr);
  165643. return;
  165644. }
  165645. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165646. }
  165647. #endif
  165648. #if defined(PNG_READ_tIME_SUPPORTED)
  165649. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165650. {
  165651. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165652. {
  165653. png_push_save_buffer(png_ptr);
  165654. return;
  165655. }
  165656. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165657. }
  165658. #endif
  165659. #if defined(PNG_READ_tEXt_SUPPORTED)
  165660. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165661. {
  165662. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165663. {
  165664. png_push_save_buffer(png_ptr);
  165665. return;
  165666. }
  165667. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165668. }
  165669. #endif
  165670. #if defined(PNG_READ_zTXt_SUPPORTED)
  165671. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165672. {
  165673. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165674. {
  165675. png_push_save_buffer(png_ptr);
  165676. return;
  165677. }
  165678. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165679. }
  165680. #endif
  165681. #if defined(PNG_READ_iTXt_SUPPORTED)
  165682. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165683. {
  165684. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165685. {
  165686. png_push_save_buffer(png_ptr);
  165687. return;
  165688. }
  165689. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165690. }
  165691. #endif
  165692. else
  165693. {
  165694. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165695. {
  165696. png_push_save_buffer(png_ptr);
  165697. return;
  165698. }
  165699. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165700. }
  165701. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165702. }
  165703. void /* PRIVATE */
  165704. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165705. {
  165706. png_ptr->process_mode = PNG_SKIP_MODE;
  165707. png_ptr->skip_length = skip;
  165708. }
  165709. void /* PRIVATE */
  165710. png_push_crc_finish(png_structp png_ptr)
  165711. {
  165712. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  165713. {
  165714. png_size_t save_size;
  165715. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  165716. save_size = (png_size_t)png_ptr->skip_length;
  165717. else
  165718. save_size = png_ptr->save_buffer_size;
  165719. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165720. png_ptr->skip_length -= save_size;
  165721. png_ptr->buffer_size -= save_size;
  165722. png_ptr->save_buffer_size -= save_size;
  165723. png_ptr->save_buffer_ptr += save_size;
  165724. }
  165725. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  165726. {
  165727. png_size_t save_size;
  165728. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  165729. save_size = (png_size_t)png_ptr->skip_length;
  165730. else
  165731. save_size = png_ptr->current_buffer_size;
  165732. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165733. png_ptr->skip_length -= save_size;
  165734. png_ptr->buffer_size -= save_size;
  165735. png_ptr->current_buffer_size -= save_size;
  165736. png_ptr->current_buffer_ptr += save_size;
  165737. }
  165738. if (!png_ptr->skip_length)
  165739. {
  165740. if (png_ptr->buffer_size < 4)
  165741. {
  165742. png_push_save_buffer(png_ptr);
  165743. return;
  165744. }
  165745. png_crc_finish(png_ptr, 0);
  165746. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165747. }
  165748. }
  165749. void PNGAPI
  165750. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  165751. {
  165752. png_bytep ptr;
  165753. if(png_ptr == NULL) return;
  165754. ptr = buffer;
  165755. if (png_ptr->save_buffer_size)
  165756. {
  165757. png_size_t save_size;
  165758. if (length < png_ptr->save_buffer_size)
  165759. save_size = length;
  165760. else
  165761. save_size = png_ptr->save_buffer_size;
  165762. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  165763. length -= save_size;
  165764. ptr += save_size;
  165765. png_ptr->buffer_size -= save_size;
  165766. png_ptr->save_buffer_size -= save_size;
  165767. png_ptr->save_buffer_ptr += save_size;
  165768. }
  165769. if (length && png_ptr->current_buffer_size)
  165770. {
  165771. png_size_t save_size;
  165772. if (length < png_ptr->current_buffer_size)
  165773. save_size = length;
  165774. else
  165775. save_size = png_ptr->current_buffer_size;
  165776. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  165777. png_ptr->buffer_size -= save_size;
  165778. png_ptr->current_buffer_size -= save_size;
  165779. png_ptr->current_buffer_ptr += save_size;
  165780. }
  165781. }
  165782. void /* PRIVATE */
  165783. png_push_save_buffer(png_structp png_ptr)
  165784. {
  165785. if (png_ptr->save_buffer_size)
  165786. {
  165787. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  165788. {
  165789. png_size_t i,istop;
  165790. png_bytep sp;
  165791. png_bytep dp;
  165792. istop = png_ptr->save_buffer_size;
  165793. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  165794. i < istop; i++, sp++, dp++)
  165795. {
  165796. *dp = *sp;
  165797. }
  165798. }
  165799. }
  165800. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  165801. png_ptr->save_buffer_max)
  165802. {
  165803. png_size_t new_max;
  165804. png_bytep old_buffer;
  165805. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  165806. (png_ptr->current_buffer_size + 256))
  165807. {
  165808. png_error(png_ptr, "Potential overflow of save_buffer");
  165809. }
  165810. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  165811. old_buffer = png_ptr->save_buffer;
  165812. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  165813. (png_uint_32)new_max);
  165814. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  165815. png_free(png_ptr, old_buffer);
  165816. png_ptr->save_buffer_max = new_max;
  165817. }
  165818. if (png_ptr->current_buffer_size)
  165819. {
  165820. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  165821. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  165822. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  165823. png_ptr->current_buffer_size = 0;
  165824. }
  165825. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  165826. png_ptr->buffer_size = 0;
  165827. }
  165828. void /* PRIVATE */
  165829. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  165830. png_size_t buffer_length)
  165831. {
  165832. png_ptr->current_buffer = buffer;
  165833. png_ptr->current_buffer_size = buffer_length;
  165834. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  165835. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  165836. }
  165837. void /* PRIVATE */
  165838. png_push_read_IDAT(png_structp png_ptr)
  165839. {
  165840. #ifdef PNG_USE_LOCAL_ARRAYS
  165841. PNG_CONST PNG_IDAT;
  165842. #endif
  165843. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165844. {
  165845. png_byte chunk_length[4];
  165846. if (png_ptr->buffer_size < 8)
  165847. {
  165848. png_push_save_buffer(png_ptr);
  165849. return;
  165850. }
  165851. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165852. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165853. png_reset_crc(png_ptr);
  165854. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165855. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165856. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165857. {
  165858. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165859. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  165860. png_error(png_ptr, "Not enough compressed data");
  165861. return;
  165862. }
  165863. png_ptr->idat_size = png_ptr->push_length;
  165864. }
  165865. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  165866. {
  165867. png_size_t save_size;
  165868. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  165869. {
  165870. save_size = (png_size_t)png_ptr->idat_size;
  165871. if((png_uint_32)save_size != png_ptr->idat_size)
  165872. png_error(png_ptr, "save_size overflowed in pngpread");
  165873. }
  165874. else
  165875. save_size = png_ptr->save_buffer_size;
  165876. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165877. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  165878. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165879. png_ptr->idat_size -= save_size;
  165880. png_ptr->buffer_size -= save_size;
  165881. png_ptr->save_buffer_size -= save_size;
  165882. png_ptr->save_buffer_ptr += save_size;
  165883. }
  165884. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  165885. {
  165886. png_size_t save_size;
  165887. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  165888. {
  165889. save_size = (png_size_t)png_ptr->idat_size;
  165890. if((png_uint_32)save_size != png_ptr->idat_size)
  165891. png_error(png_ptr, "save_size overflowed in pngpread");
  165892. }
  165893. else
  165894. save_size = png_ptr->current_buffer_size;
  165895. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165896. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  165897. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165898. png_ptr->idat_size -= save_size;
  165899. png_ptr->buffer_size -= save_size;
  165900. png_ptr->current_buffer_size -= save_size;
  165901. png_ptr->current_buffer_ptr += save_size;
  165902. }
  165903. if (!png_ptr->idat_size)
  165904. {
  165905. if (png_ptr->buffer_size < 4)
  165906. {
  165907. png_push_save_buffer(png_ptr);
  165908. return;
  165909. }
  165910. png_crc_finish(png_ptr, 0);
  165911. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165912. png_ptr->mode |= PNG_AFTER_IDAT;
  165913. }
  165914. }
  165915. void /* PRIVATE */
  165916. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  165917. png_size_t buffer_length)
  165918. {
  165919. int ret;
  165920. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  165921. png_error(png_ptr, "Extra compression data");
  165922. png_ptr->zstream.next_in = buffer;
  165923. png_ptr->zstream.avail_in = (uInt)buffer_length;
  165924. for(;;)
  165925. {
  165926. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165927. if (ret != Z_OK)
  165928. {
  165929. if (ret == Z_STREAM_END)
  165930. {
  165931. if (png_ptr->zstream.avail_in)
  165932. png_error(png_ptr, "Extra compressed data");
  165933. if (!(png_ptr->zstream.avail_out))
  165934. {
  165935. png_push_process_row(png_ptr);
  165936. }
  165937. png_ptr->mode |= PNG_AFTER_IDAT;
  165938. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165939. break;
  165940. }
  165941. else if (ret == Z_BUF_ERROR)
  165942. break;
  165943. else
  165944. png_error(png_ptr, "Decompression Error");
  165945. }
  165946. if (!(png_ptr->zstream.avail_out))
  165947. {
  165948. if ((
  165949. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165950. png_ptr->interlaced && png_ptr->pass > 6) ||
  165951. (!png_ptr->interlaced &&
  165952. #endif
  165953. png_ptr->row_number == png_ptr->num_rows))
  165954. {
  165955. if (png_ptr->zstream.avail_in)
  165956. {
  165957. png_warning(png_ptr, "Too much data in IDAT chunks");
  165958. }
  165959. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165960. break;
  165961. }
  165962. png_push_process_row(png_ptr);
  165963. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165964. png_ptr->zstream.next_out = png_ptr->row_buf;
  165965. }
  165966. else
  165967. break;
  165968. }
  165969. }
  165970. void /* PRIVATE */
  165971. png_push_process_row(png_structp png_ptr)
  165972. {
  165973. png_ptr->row_info.color_type = png_ptr->color_type;
  165974. png_ptr->row_info.width = png_ptr->iwidth;
  165975. png_ptr->row_info.channels = png_ptr->channels;
  165976. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165977. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165978. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165979. png_ptr->row_info.width);
  165980. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165981. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165982. (int)(png_ptr->row_buf[0]));
  165983. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165984. png_ptr->rowbytes + 1);
  165985. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165986. png_do_read_transformations(png_ptr);
  165987. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165988. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165989. {
  165990. if (png_ptr->pass < 6)
  165991. png_do_read_interlace(png_ptr);
  165992. switch (png_ptr->pass)
  165993. {
  165994. case 0:
  165995. {
  165996. int i;
  165997. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  165998. {
  165999. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166000. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166001. }
  166002. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166003. {
  166004. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166005. {
  166006. png_push_have_row(png_ptr, png_bytep_NULL);
  166007. png_read_push_finish_row(png_ptr);
  166008. }
  166009. }
  166010. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166011. {
  166012. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166013. {
  166014. png_push_have_row(png_ptr, png_bytep_NULL);
  166015. png_read_push_finish_row(png_ptr);
  166016. }
  166017. }
  166018. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166019. {
  166020. png_push_have_row(png_ptr, png_bytep_NULL);
  166021. png_read_push_finish_row(png_ptr);
  166022. }
  166023. break;
  166024. }
  166025. case 1:
  166026. {
  166027. int i;
  166028. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166029. {
  166030. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166031. png_read_push_finish_row(png_ptr);
  166032. }
  166033. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166034. {
  166035. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166036. {
  166037. png_push_have_row(png_ptr, png_bytep_NULL);
  166038. png_read_push_finish_row(png_ptr);
  166039. }
  166040. }
  166041. break;
  166042. }
  166043. case 2:
  166044. {
  166045. int i;
  166046. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166047. {
  166048. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166049. png_read_push_finish_row(png_ptr);
  166050. }
  166051. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166052. {
  166053. png_push_have_row(png_ptr, png_bytep_NULL);
  166054. png_read_push_finish_row(png_ptr);
  166055. }
  166056. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166057. {
  166058. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166059. {
  166060. png_push_have_row(png_ptr, png_bytep_NULL);
  166061. png_read_push_finish_row(png_ptr);
  166062. }
  166063. }
  166064. break;
  166065. }
  166066. case 3:
  166067. {
  166068. int i;
  166069. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166070. {
  166071. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166072. png_read_push_finish_row(png_ptr);
  166073. }
  166074. if (png_ptr->pass == 4) /* skip top two generated rows */
  166075. {
  166076. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166077. {
  166078. png_push_have_row(png_ptr, png_bytep_NULL);
  166079. png_read_push_finish_row(png_ptr);
  166080. }
  166081. }
  166082. break;
  166083. }
  166084. case 4:
  166085. {
  166086. int i;
  166087. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166088. {
  166089. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166090. png_read_push_finish_row(png_ptr);
  166091. }
  166092. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166093. {
  166094. png_push_have_row(png_ptr, png_bytep_NULL);
  166095. png_read_push_finish_row(png_ptr);
  166096. }
  166097. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166098. {
  166099. png_push_have_row(png_ptr, png_bytep_NULL);
  166100. png_read_push_finish_row(png_ptr);
  166101. }
  166102. break;
  166103. }
  166104. case 5:
  166105. {
  166106. int i;
  166107. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166108. {
  166109. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166110. png_read_push_finish_row(png_ptr);
  166111. }
  166112. if (png_ptr->pass == 6) /* skip top generated row */
  166113. {
  166114. png_push_have_row(png_ptr, png_bytep_NULL);
  166115. png_read_push_finish_row(png_ptr);
  166116. }
  166117. break;
  166118. }
  166119. case 6:
  166120. {
  166121. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166122. png_read_push_finish_row(png_ptr);
  166123. if (png_ptr->pass != 6)
  166124. break;
  166125. png_push_have_row(png_ptr, png_bytep_NULL);
  166126. png_read_push_finish_row(png_ptr);
  166127. }
  166128. }
  166129. }
  166130. else
  166131. #endif
  166132. {
  166133. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166134. png_read_push_finish_row(png_ptr);
  166135. }
  166136. }
  166137. void /* PRIVATE */
  166138. png_read_push_finish_row(png_structp png_ptr)
  166139. {
  166140. #ifdef PNG_USE_LOCAL_ARRAYS
  166141. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166142. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166143. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166144. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166145. #endif
  166146. png_ptr->row_number++;
  166147. if (png_ptr->row_number < png_ptr->num_rows)
  166148. return;
  166149. if (png_ptr->interlaced)
  166150. {
  166151. png_ptr->row_number = 0;
  166152. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166153. png_ptr->rowbytes + 1);
  166154. do
  166155. {
  166156. png_ptr->pass++;
  166157. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166158. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166159. (png_ptr->pass == 5 && png_ptr->width < 2))
  166160. png_ptr->pass++;
  166161. if (png_ptr->pass > 7)
  166162. png_ptr->pass--;
  166163. if (png_ptr->pass >= 7)
  166164. break;
  166165. png_ptr->iwidth = (png_ptr->width +
  166166. png_pass_inc[png_ptr->pass] - 1 -
  166167. png_pass_start[png_ptr->pass]) /
  166168. png_pass_inc[png_ptr->pass];
  166169. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166170. png_ptr->iwidth) + 1;
  166171. if (png_ptr->transformations & PNG_INTERLACE)
  166172. break;
  166173. png_ptr->num_rows = (png_ptr->height +
  166174. png_pass_yinc[png_ptr->pass] - 1 -
  166175. png_pass_ystart[png_ptr->pass]) /
  166176. png_pass_yinc[png_ptr->pass];
  166177. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166178. }
  166179. }
  166180. #if defined(PNG_READ_tEXt_SUPPORTED)
  166181. void /* PRIVATE */
  166182. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166183. length)
  166184. {
  166185. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166186. {
  166187. png_error(png_ptr, "Out of place tEXt");
  166188. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166189. }
  166190. #ifdef PNG_MAX_MALLOC_64K
  166191. png_ptr->skip_length = 0; /* This may not be necessary */
  166192. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166193. {
  166194. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166195. png_ptr->skip_length = length - (png_uint_32)65535L;
  166196. length = (png_uint_32)65535L;
  166197. }
  166198. #endif
  166199. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166200. (png_uint_32)(length+1));
  166201. png_ptr->current_text[length] = '\0';
  166202. png_ptr->current_text_ptr = png_ptr->current_text;
  166203. png_ptr->current_text_size = (png_size_t)length;
  166204. png_ptr->current_text_left = (png_size_t)length;
  166205. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166206. }
  166207. void /* PRIVATE */
  166208. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166209. {
  166210. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166211. {
  166212. png_size_t text_size;
  166213. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166214. text_size = png_ptr->buffer_size;
  166215. else
  166216. text_size = png_ptr->current_text_left;
  166217. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166218. png_ptr->current_text_left -= text_size;
  166219. png_ptr->current_text_ptr += text_size;
  166220. }
  166221. if (!(png_ptr->current_text_left))
  166222. {
  166223. png_textp text_ptr;
  166224. png_charp text;
  166225. png_charp key;
  166226. int ret;
  166227. if (png_ptr->buffer_size < 4)
  166228. {
  166229. png_push_save_buffer(png_ptr);
  166230. return;
  166231. }
  166232. png_push_crc_finish(png_ptr);
  166233. #if defined(PNG_MAX_MALLOC_64K)
  166234. if (png_ptr->skip_length)
  166235. return;
  166236. #endif
  166237. key = png_ptr->current_text;
  166238. for (text = key; *text; text++)
  166239. ;
  166240. if (text < key + png_ptr->current_text_size)
  166241. text++;
  166242. text_ptr = (png_textp)png_malloc(png_ptr,
  166243. (png_uint_32)png_sizeof(png_text));
  166244. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166245. text_ptr->key = key;
  166246. #ifdef PNG_iTXt_SUPPORTED
  166247. text_ptr->lang = NULL;
  166248. text_ptr->lang_key = NULL;
  166249. #endif
  166250. text_ptr->text = text;
  166251. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166252. png_free(png_ptr, key);
  166253. png_free(png_ptr, text_ptr);
  166254. png_ptr->current_text = NULL;
  166255. if (ret)
  166256. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166257. }
  166258. }
  166259. #endif
  166260. #if defined(PNG_READ_zTXt_SUPPORTED)
  166261. void /* PRIVATE */
  166262. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166263. length)
  166264. {
  166265. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166266. {
  166267. png_error(png_ptr, "Out of place zTXt");
  166268. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166269. }
  166270. #ifdef PNG_MAX_MALLOC_64K
  166271. if (length > (png_uint_32)65535L)
  166272. {
  166273. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166274. png_push_crc_skip(png_ptr, length);
  166275. return;
  166276. }
  166277. #endif
  166278. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166279. (png_uint_32)(length+1));
  166280. png_ptr->current_text[length] = '\0';
  166281. png_ptr->current_text_ptr = png_ptr->current_text;
  166282. png_ptr->current_text_size = (png_size_t)length;
  166283. png_ptr->current_text_left = (png_size_t)length;
  166284. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166285. }
  166286. void /* PRIVATE */
  166287. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166288. {
  166289. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166290. {
  166291. png_size_t text_size;
  166292. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166293. text_size = png_ptr->buffer_size;
  166294. else
  166295. text_size = png_ptr->current_text_left;
  166296. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166297. png_ptr->current_text_left -= text_size;
  166298. png_ptr->current_text_ptr += text_size;
  166299. }
  166300. if (!(png_ptr->current_text_left))
  166301. {
  166302. png_textp text_ptr;
  166303. png_charp text;
  166304. png_charp key;
  166305. int ret;
  166306. png_size_t text_size, key_size;
  166307. if (png_ptr->buffer_size < 4)
  166308. {
  166309. png_push_save_buffer(png_ptr);
  166310. return;
  166311. }
  166312. png_push_crc_finish(png_ptr);
  166313. key = png_ptr->current_text;
  166314. for (text = key; *text; text++)
  166315. ;
  166316. if (text >= key + png_ptr->current_text_size)
  166317. {
  166318. png_ptr->current_text = NULL;
  166319. png_free(png_ptr, key);
  166320. return;
  166321. }
  166322. text++;
  166323. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166324. {
  166325. png_ptr->current_text = NULL;
  166326. png_free(png_ptr, key);
  166327. return;
  166328. }
  166329. text++;
  166330. png_ptr->zstream.next_in = (png_bytep )text;
  166331. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166332. (text - key));
  166333. png_ptr->zstream.next_out = png_ptr->zbuf;
  166334. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166335. key_size = text - key;
  166336. text_size = 0;
  166337. text = NULL;
  166338. ret = Z_STREAM_END;
  166339. while (png_ptr->zstream.avail_in)
  166340. {
  166341. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166342. if (ret != Z_OK && ret != Z_STREAM_END)
  166343. {
  166344. inflateReset(&png_ptr->zstream);
  166345. png_ptr->zstream.avail_in = 0;
  166346. png_ptr->current_text = NULL;
  166347. png_free(png_ptr, key);
  166348. png_free(png_ptr, text);
  166349. return;
  166350. }
  166351. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166352. {
  166353. if (text == NULL)
  166354. {
  166355. text = (png_charp)png_malloc(png_ptr,
  166356. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166357. + key_size + 1));
  166358. png_memcpy(text + key_size, png_ptr->zbuf,
  166359. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166360. png_memcpy(text, key, key_size);
  166361. text_size = key_size + png_ptr->zbuf_size -
  166362. png_ptr->zstream.avail_out;
  166363. *(text + text_size) = '\0';
  166364. }
  166365. else
  166366. {
  166367. png_charp tmp;
  166368. tmp = text;
  166369. text = (png_charp)png_malloc(png_ptr, text_size +
  166370. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166371. + 1));
  166372. png_memcpy(text, tmp, text_size);
  166373. png_free(png_ptr, tmp);
  166374. png_memcpy(text + text_size, png_ptr->zbuf,
  166375. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166376. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166377. *(text + text_size) = '\0';
  166378. }
  166379. if (ret != Z_STREAM_END)
  166380. {
  166381. png_ptr->zstream.next_out = png_ptr->zbuf;
  166382. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166383. }
  166384. }
  166385. else
  166386. {
  166387. break;
  166388. }
  166389. if (ret == Z_STREAM_END)
  166390. break;
  166391. }
  166392. inflateReset(&png_ptr->zstream);
  166393. png_ptr->zstream.avail_in = 0;
  166394. if (ret != Z_STREAM_END)
  166395. {
  166396. png_ptr->current_text = NULL;
  166397. png_free(png_ptr, key);
  166398. png_free(png_ptr, text);
  166399. return;
  166400. }
  166401. png_ptr->current_text = NULL;
  166402. png_free(png_ptr, key);
  166403. key = text;
  166404. text += key_size;
  166405. text_ptr = (png_textp)png_malloc(png_ptr,
  166406. (png_uint_32)png_sizeof(png_text));
  166407. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166408. text_ptr->key = key;
  166409. #ifdef PNG_iTXt_SUPPORTED
  166410. text_ptr->lang = NULL;
  166411. text_ptr->lang_key = NULL;
  166412. #endif
  166413. text_ptr->text = text;
  166414. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166415. png_free(png_ptr, key);
  166416. png_free(png_ptr, text_ptr);
  166417. if (ret)
  166418. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166419. }
  166420. }
  166421. #endif
  166422. #if defined(PNG_READ_iTXt_SUPPORTED)
  166423. void /* PRIVATE */
  166424. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166425. length)
  166426. {
  166427. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166428. {
  166429. png_error(png_ptr, "Out of place iTXt");
  166430. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166431. }
  166432. #ifdef PNG_MAX_MALLOC_64K
  166433. png_ptr->skip_length = 0; /* This may not be necessary */
  166434. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166435. {
  166436. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166437. png_ptr->skip_length = length - (png_uint_32)65535L;
  166438. length = (png_uint_32)65535L;
  166439. }
  166440. #endif
  166441. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166442. (png_uint_32)(length+1));
  166443. png_ptr->current_text[length] = '\0';
  166444. png_ptr->current_text_ptr = png_ptr->current_text;
  166445. png_ptr->current_text_size = (png_size_t)length;
  166446. png_ptr->current_text_left = (png_size_t)length;
  166447. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166448. }
  166449. void /* PRIVATE */
  166450. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166451. {
  166452. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166453. {
  166454. png_size_t text_size;
  166455. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166456. text_size = png_ptr->buffer_size;
  166457. else
  166458. text_size = png_ptr->current_text_left;
  166459. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166460. png_ptr->current_text_left -= text_size;
  166461. png_ptr->current_text_ptr += text_size;
  166462. }
  166463. if (!(png_ptr->current_text_left))
  166464. {
  166465. png_textp text_ptr;
  166466. png_charp key;
  166467. int comp_flag;
  166468. png_charp lang;
  166469. png_charp lang_key;
  166470. png_charp text;
  166471. int ret;
  166472. if (png_ptr->buffer_size < 4)
  166473. {
  166474. png_push_save_buffer(png_ptr);
  166475. return;
  166476. }
  166477. png_push_crc_finish(png_ptr);
  166478. #if defined(PNG_MAX_MALLOC_64K)
  166479. if (png_ptr->skip_length)
  166480. return;
  166481. #endif
  166482. key = png_ptr->current_text;
  166483. for (lang = key; *lang; lang++)
  166484. ;
  166485. if (lang < key + png_ptr->current_text_size - 3)
  166486. lang++;
  166487. comp_flag = *lang++;
  166488. lang++; /* skip comp_type, always zero */
  166489. for (lang_key = lang; *lang_key; lang_key++)
  166490. ;
  166491. lang_key++; /* skip NUL separator */
  166492. text=lang_key;
  166493. if (lang_key < key + png_ptr->current_text_size - 1)
  166494. {
  166495. for (; *text; text++)
  166496. ;
  166497. }
  166498. if (text < key + png_ptr->current_text_size)
  166499. text++;
  166500. text_ptr = (png_textp)png_malloc(png_ptr,
  166501. (png_uint_32)png_sizeof(png_text));
  166502. text_ptr->compression = comp_flag + 2;
  166503. text_ptr->key = key;
  166504. text_ptr->lang = lang;
  166505. text_ptr->lang_key = lang_key;
  166506. text_ptr->text = text;
  166507. text_ptr->text_length = 0;
  166508. text_ptr->itxt_length = png_strlen(text);
  166509. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166510. png_ptr->current_text = NULL;
  166511. png_free(png_ptr, text_ptr);
  166512. if (ret)
  166513. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166514. }
  166515. }
  166516. #endif
  166517. void /* PRIVATE */
  166518. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166519. length)
  166520. {
  166521. png_uint_32 skip=0;
  166522. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166523. if (!(png_ptr->chunk_name[0] & 0x20))
  166524. {
  166525. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166526. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166527. PNG_HANDLE_CHUNK_ALWAYS
  166528. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166529. && png_ptr->read_user_chunk_fn == NULL
  166530. #endif
  166531. )
  166532. #endif
  166533. png_chunk_error(png_ptr, "unknown critical chunk");
  166534. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166535. }
  166536. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166537. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166538. {
  166539. #ifdef PNG_MAX_MALLOC_64K
  166540. if (length > (png_uint_32)65535L)
  166541. {
  166542. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166543. skip = length - (png_uint_32)65535L;
  166544. length = (png_uint_32)65535L;
  166545. }
  166546. #endif
  166547. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166548. (png_charp)png_ptr->chunk_name, 5);
  166549. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166550. png_ptr->unknown_chunk.size = (png_size_t)length;
  166551. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166552. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166553. if(png_ptr->read_user_chunk_fn != NULL)
  166554. {
  166555. int ret;
  166556. ret = (*(png_ptr->read_user_chunk_fn))
  166557. (png_ptr, &png_ptr->unknown_chunk);
  166558. if (ret < 0)
  166559. png_chunk_error(png_ptr, "error in user chunk");
  166560. if (ret == 0)
  166561. {
  166562. if (!(png_ptr->chunk_name[0] & 0x20))
  166563. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166564. PNG_HANDLE_CHUNK_ALWAYS)
  166565. png_chunk_error(png_ptr, "unknown critical chunk");
  166566. png_set_unknown_chunks(png_ptr, info_ptr,
  166567. &png_ptr->unknown_chunk, 1);
  166568. }
  166569. }
  166570. #else
  166571. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166572. #endif
  166573. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166574. png_ptr->unknown_chunk.data = NULL;
  166575. }
  166576. else
  166577. #endif
  166578. skip=length;
  166579. png_push_crc_skip(png_ptr, skip);
  166580. }
  166581. void /* PRIVATE */
  166582. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166583. {
  166584. if (png_ptr->info_fn != NULL)
  166585. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166586. }
  166587. void /* PRIVATE */
  166588. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166589. {
  166590. if (png_ptr->end_fn != NULL)
  166591. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166592. }
  166593. void /* PRIVATE */
  166594. png_push_have_row(png_structp png_ptr, png_bytep row)
  166595. {
  166596. if (png_ptr->row_fn != NULL)
  166597. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166598. (int)png_ptr->pass);
  166599. }
  166600. void PNGAPI
  166601. png_progressive_combine_row (png_structp png_ptr,
  166602. png_bytep old_row, png_bytep new_row)
  166603. {
  166604. #ifdef PNG_USE_LOCAL_ARRAYS
  166605. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166606. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166607. #endif
  166608. if(png_ptr == NULL) return;
  166609. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166610. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166611. }
  166612. void PNGAPI
  166613. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166614. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166615. png_progressive_end_ptr end_fn)
  166616. {
  166617. if(png_ptr == NULL) return;
  166618. png_ptr->info_fn = info_fn;
  166619. png_ptr->row_fn = row_fn;
  166620. png_ptr->end_fn = end_fn;
  166621. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166622. }
  166623. png_voidp PNGAPI
  166624. png_get_progressive_ptr(png_structp png_ptr)
  166625. {
  166626. if(png_ptr == NULL) return (NULL);
  166627. return png_ptr->io_ptr;
  166628. }
  166629. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166630. /*** End of inlined file: pngpread.c ***/
  166631. /*** Start of inlined file: pngrio.c ***/
  166632. #define PNG_INTERNAL
  166633. #if defined(PNG_READ_SUPPORTED)
  166634. void /* PRIVATE */
  166635. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166636. {
  166637. png_debug1(4,"reading %d bytes\n", (int)length);
  166638. if (png_ptr->read_data_fn != NULL)
  166639. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166640. else
  166641. png_error(png_ptr, "Call to NULL read function");
  166642. }
  166643. #if !defined(PNG_NO_STDIO)
  166644. #ifndef USE_FAR_KEYWORD
  166645. void PNGAPI
  166646. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166647. {
  166648. png_size_t check;
  166649. if(png_ptr == NULL) return;
  166650. #if defined(_WIN32_WCE)
  166651. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166652. check = 0;
  166653. #else
  166654. check = (png_size_t)fread(data, (png_size_t)1, length,
  166655. (png_FILE_p)png_ptr->io_ptr);
  166656. #endif
  166657. if (check != length)
  166658. png_error(png_ptr, "Read Error");
  166659. }
  166660. #else
  166661. #define NEAR_BUF_SIZE 1024
  166662. #define MIN(a,b) (a <= b ? a : b)
  166663. static void PNGAPI
  166664. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166665. {
  166666. int check;
  166667. png_byte *n_data;
  166668. png_FILE_p io_ptr;
  166669. if(png_ptr == NULL) return;
  166670. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166671. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166672. if ((png_bytep)n_data == data)
  166673. {
  166674. #if defined(_WIN32_WCE)
  166675. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166676. check = 0;
  166677. #else
  166678. check = fread(n_data, 1, length, io_ptr);
  166679. #endif
  166680. }
  166681. else
  166682. {
  166683. png_byte buf[NEAR_BUF_SIZE];
  166684. png_size_t read, remaining, err;
  166685. check = 0;
  166686. remaining = length;
  166687. do
  166688. {
  166689. read = MIN(NEAR_BUF_SIZE, remaining);
  166690. #if defined(_WIN32_WCE)
  166691. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166692. err = 0;
  166693. #else
  166694. err = fread(buf, (png_size_t)1, read, io_ptr);
  166695. #endif
  166696. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166697. if(err != read)
  166698. break;
  166699. else
  166700. check += err;
  166701. data += read;
  166702. remaining -= read;
  166703. }
  166704. while (remaining != 0);
  166705. }
  166706. if ((png_uint_32)check != (png_uint_32)length)
  166707. png_error(png_ptr, "read Error");
  166708. }
  166709. #endif
  166710. #endif
  166711. void PNGAPI
  166712. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  166713. png_rw_ptr read_data_fn)
  166714. {
  166715. if(png_ptr == NULL) return;
  166716. png_ptr->io_ptr = io_ptr;
  166717. #if !defined(PNG_NO_STDIO)
  166718. if (read_data_fn != NULL)
  166719. png_ptr->read_data_fn = read_data_fn;
  166720. else
  166721. png_ptr->read_data_fn = png_default_read_data;
  166722. #else
  166723. png_ptr->read_data_fn = read_data_fn;
  166724. #endif
  166725. if (png_ptr->write_data_fn != NULL)
  166726. {
  166727. png_ptr->write_data_fn = NULL;
  166728. png_warning(png_ptr,
  166729. "It's an error to set both read_data_fn and write_data_fn in the ");
  166730. png_warning(png_ptr,
  166731. "same structure. Resetting write_data_fn to NULL.");
  166732. }
  166733. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  166734. png_ptr->output_flush_fn = NULL;
  166735. #endif
  166736. }
  166737. #endif /* PNG_READ_SUPPORTED */
  166738. /*** End of inlined file: pngrio.c ***/
  166739. /*** Start of inlined file: pngrtran.c ***/
  166740. #define PNG_INTERNAL
  166741. #if defined(PNG_READ_SUPPORTED)
  166742. void PNGAPI
  166743. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  166744. {
  166745. png_debug(1, "in png_set_crc_action\n");
  166746. if(png_ptr == NULL) return;
  166747. switch (crit_action)
  166748. {
  166749. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166750. break;
  166751. case PNG_CRC_WARN_USE: /* warn/use data */
  166752. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166753. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  166754. break;
  166755. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166756. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166757. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  166758. PNG_FLAG_CRC_CRITICAL_IGNORE;
  166759. break;
  166760. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  166761. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  166762. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166763. case PNG_CRC_DEFAULT:
  166764. default:
  166765. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166766. break;
  166767. }
  166768. switch (ancil_action)
  166769. {
  166770. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166771. break;
  166772. case PNG_CRC_WARN_USE: /* warn/use data */
  166773. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166774. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  166775. break;
  166776. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166777. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166778. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  166779. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166780. break;
  166781. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166782. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166783. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166784. break;
  166785. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  166786. case PNG_CRC_DEFAULT:
  166787. default:
  166788. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166789. break;
  166790. }
  166791. }
  166792. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  166793. defined(PNG_FLOATING_POINT_SUPPORTED)
  166794. void PNGAPI
  166795. png_set_background(png_structp png_ptr,
  166796. png_color_16p background_color, int background_gamma_code,
  166797. int need_expand, double background_gamma)
  166798. {
  166799. png_debug(1, "in png_set_background\n");
  166800. if(png_ptr == NULL) return;
  166801. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  166802. {
  166803. png_warning(png_ptr, "Application must supply a known background gamma");
  166804. return;
  166805. }
  166806. png_ptr->transformations |= PNG_BACKGROUND;
  166807. png_memcpy(&(png_ptr->background), background_color,
  166808. png_sizeof(png_color_16));
  166809. png_ptr->background_gamma = (float)background_gamma;
  166810. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  166811. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  166812. }
  166813. #endif
  166814. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  166815. void PNGAPI
  166816. png_set_strip_16(png_structp png_ptr)
  166817. {
  166818. png_debug(1, "in png_set_strip_16\n");
  166819. if(png_ptr == NULL) return;
  166820. png_ptr->transformations |= PNG_16_TO_8;
  166821. }
  166822. #endif
  166823. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  166824. void PNGAPI
  166825. png_set_strip_alpha(png_structp png_ptr)
  166826. {
  166827. png_debug(1, "in png_set_strip_alpha\n");
  166828. if(png_ptr == NULL) return;
  166829. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  166830. }
  166831. #endif
  166832. #if defined(PNG_READ_DITHER_SUPPORTED)
  166833. typedef struct png_dsort_struct
  166834. {
  166835. struct png_dsort_struct FAR * next;
  166836. png_byte left;
  166837. png_byte right;
  166838. } png_dsort;
  166839. typedef png_dsort FAR * png_dsortp;
  166840. typedef png_dsort FAR * FAR * png_dsortpp;
  166841. void PNGAPI
  166842. png_set_dither(png_structp png_ptr, png_colorp palette,
  166843. int num_palette, int maximum_colors, png_uint_16p histogram,
  166844. int full_dither)
  166845. {
  166846. png_debug(1, "in png_set_dither\n");
  166847. if(png_ptr == NULL) return;
  166848. png_ptr->transformations |= PNG_DITHER;
  166849. if (!full_dither)
  166850. {
  166851. int i;
  166852. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  166853. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166854. for (i = 0; i < num_palette; i++)
  166855. png_ptr->dither_index[i] = (png_byte)i;
  166856. }
  166857. if (num_palette > maximum_colors)
  166858. {
  166859. if (histogram != NULL)
  166860. {
  166861. int i;
  166862. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  166863. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166864. for (i = 0; i < num_palette; i++)
  166865. png_ptr->dither_sort[i] = (png_byte)i;
  166866. for (i = num_palette - 1; i >= maximum_colors; i--)
  166867. {
  166868. int done; /* to stop early if the list is pre-sorted */
  166869. int j;
  166870. done = 1;
  166871. for (j = 0; j < i; j++)
  166872. {
  166873. if (histogram[png_ptr->dither_sort[j]]
  166874. < histogram[png_ptr->dither_sort[j + 1]])
  166875. {
  166876. png_byte t;
  166877. t = png_ptr->dither_sort[j];
  166878. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  166879. png_ptr->dither_sort[j + 1] = t;
  166880. done = 0;
  166881. }
  166882. }
  166883. if (done)
  166884. break;
  166885. }
  166886. if (full_dither)
  166887. {
  166888. int j = num_palette;
  166889. for (i = 0; i < maximum_colors; i++)
  166890. {
  166891. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  166892. {
  166893. do
  166894. j--;
  166895. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  166896. palette[i] = palette[j];
  166897. }
  166898. }
  166899. }
  166900. else
  166901. {
  166902. int j = num_palette;
  166903. for (i = 0; i < maximum_colors; i++)
  166904. {
  166905. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  166906. {
  166907. png_color tmp_color;
  166908. do
  166909. j--;
  166910. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  166911. tmp_color = palette[j];
  166912. palette[j] = palette[i];
  166913. palette[i] = tmp_color;
  166914. png_ptr->dither_index[j] = (png_byte)i;
  166915. png_ptr->dither_index[i] = (png_byte)j;
  166916. }
  166917. }
  166918. for (i = 0; i < num_palette; i++)
  166919. {
  166920. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  166921. {
  166922. int min_d, k, min_k, d_index;
  166923. d_index = png_ptr->dither_index[i];
  166924. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  166925. for (k = 1, min_k = 0; k < maximum_colors; k++)
  166926. {
  166927. int d;
  166928. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  166929. if (d < min_d)
  166930. {
  166931. min_d = d;
  166932. min_k = k;
  166933. }
  166934. }
  166935. png_ptr->dither_index[i] = (png_byte)min_k;
  166936. }
  166937. }
  166938. }
  166939. png_free(png_ptr, png_ptr->dither_sort);
  166940. png_ptr->dither_sort=NULL;
  166941. }
  166942. else
  166943. {
  166944. int i;
  166945. int max_d;
  166946. int num_new_palette;
  166947. png_dsortp t;
  166948. png_dsortpp hash;
  166949. t=NULL;
  166950. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  166951. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166952. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  166953. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166954. for (i = 0; i < num_palette; i++)
  166955. {
  166956. png_ptr->index_to_palette[i] = (png_byte)i;
  166957. png_ptr->palette_to_index[i] = (png_byte)i;
  166958. }
  166959. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  166960. png_sizeof (png_dsortp)));
  166961. for (i = 0; i < 769; i++)
  166962. hash[i] = NULL;
  166963. num_new_palette = num_palette;
  166964. max_d = 96;
  166965. while (num_new_palette > maximum_colors)
  166966. {
  166967. for (i = 0; i < num_new_palette - 1; i++)
  166968. {
  166969. int j;
  166970. for (j = i + 1; j < num_new_palette; j++)
  166971. {
  166972. int d;
  166973. d = PNG_COLOR_DIST(palette[i], palette[j]);
  166974. if (d <= max_d)
  166975. {
  166976. t = (png_dsortp)png_malloc_warn(png_ptr,
  166977. (png_uint_32)(png_sizeof(png_dsort)));
  166978. if (t == NULL)
  166979. break;
  166980. t->next = hash[d];
  166981. t->left = (png_byte)i;
  166982. t->right = (png_byte)j;
  166983. hash[d] = t;
  166984. }
  166985. }
  166986. if (t == NULL)
  166987. break;
  166988. }
  166989. if (t != NULL)
  166990. for (i = 0; i <= max_d; i++)
  166991. {
  166992. if (hash[i] != NULL)
  166993. {
  166994. png_dsortp p;
  166995. for (p = hash[i]; p; p = p->next)
  166996. {
  166997. if ((int)png_ptr->index_to_palette[p->left]
  166998. < num_new_palette &&
  166999. (int)png_ptr->index_to_palette[p->right]
  167000. < num_new_palette)
  167001. {
  167002. int j, next_j;
  167003. if (num_new_palette & 0x01)
  167004. {
  167005. j = p->left;
  167006. next_j = p->right;
  167007. }
  167008. else
  167009. {
  167010. j = p->right;
  167011. next_j = p->left;
  167012. }
  167013. num_new_palette--;
  167014. palette[png_ptr->index_to_palette[j]]
  167015. = palette[num_new_palette];
  167016. if (!full_dither)
  167017. {
  167018. int k;
  167019. for (k = 0; k < num_palette; k++)
  167020. {
  167021. if (png_ptr->dither_index[k] ==
  167022. png_ptr->index_to_palette[j])
  167023. png_ptr->dither_index[k] =
  167024. png_ptr->index_to_palette[next_j];
  167025. if ((int)png_ptr->dither_index[k] ==
  167026. num_new_palette)
  167027. png_ptr->dither_index[k] =
  167028. png_ptr->index_to_palette[j];
  167029. }
  167030. }
  167031. png_ptr->index_to_palette[png_ptr->palette_to_index
  167032. [num_new_palette]] = png_ptr->index_to_palette[j];
  167033. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167034. = png_ptr->palette_to_index[num_new_palette];
  167035. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167036. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167037. }
  167038. if (num_new_palette <= maximum_colors)
  167039. break;
  167040. }
  167041. if (num_new_palette <= maximum_colors)
  167042. break;
  167043. }
  167044. }
  167045. for (i = 0; i < 769; i++)
  167046. {
  167047. if (hash[i] != NULL)
  167048. {
  167049. png_dsortp p = hash[i];
  167050. while (p)
  167051. {
  167052. t = p->next;
  167053. png_free(png_ptr, p);
  167054. p = t;
  167055. }
  167056. }
  167057. hash[i] = 0;
  167058. }
  167059. max_d += 96;
  167060. }
  167061. png_free(png_ptr, hash);
  167062. png_free(png_ptr, png_ptr->palette_to_index);
  167063. png_free(png_ptr, png_ptr->index_to_palette);
  167064. png_ptr->palette_to_index=NULL;
  167065. png_ptr->index_to_palette=NULL;
  167066. }
  167067. num_palette = maximum_colors;
  167068. }
  167069. if (png_ptr->palette == NULL)
  167070. {
  167071. png_ptr->palette = palette;
  167072. }
  167073. png_ptr->num_palette = (png_uint_16)num_palette;
  167074. if (full_dither)
  167075. {
  167076. int i;
  167077. png_bytep distance;
  167078. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167079. PNG_DITHER_BLUE_BITS;
  167080. int num_red = (1 << PNG_DITHER_RED_BITS);
  167081. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167082. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167083. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167084. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167085. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167086. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167087. png_sizeof (png_byte));
  167088. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167089. png_sizeof(png_byte)));
  167090. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167091. for (i = 0; i < num_palette; i++)
  167092. {
  167093. int ir, ig, ib;
  167094. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167095. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167096. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167097. for (ir = 0; ir < num_red; ir++)
  167098. {
  167099. int dr = ((ir > r) ? ir - r : r - ir);
  167100. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167101. for (ig = 0; ig < num_green; ig++)
  167102. {
  167103. int dg = ((ig > g) ? ig - g : g - ig);
  167104. int dt = dr + dg;
  167105. int dm = ((dr > dg) ? dr : dg);
  167106. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167107. for (ib = 0; ib < num_blue; ib++)
  167108. {
  167109. int d_index = index_g | ib;
  167110. int db = ((ib > b) ? ib - b : b - ib);
  167111. int dmax = ((dm > db) ? dm : db);
  167112. int d = dmax + dt + db;
  167113. if (d < (int)distance[d_index])
  167114. {
  167115. distance[d_index] = (png_byte)d;
  167116. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167117. }
  167118. }
  167119. }
  167120. }
  167121. }
  167122. png_free(png_ptr, distance);
  167123. }
  167124. }
  167125. #endif
  167126. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167127. void PNGAPI
  167128. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167129. {
  167130. png_debug(1, "in png_set_gamma\n");
  167131. if(png_ptr == NULL) return;
  167132. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167133. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167134. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167135. png_ptr->transformations |= PNG_GAMMA;
  167136. png_ptr->gamma = (float)file_gamma;
  167137. png_ptr->screen_gamma = (float)scrn_gamma;
  167138. }
  167139. #endif
  167140. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167141. void PNGAPI
  167142. png_set_expand(png_structp png_ptr)
  167143. {
  167144. png_debug(1, "in png_set_expand\n");
  167145. if(png_ptr == NULL) return;
  167146. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167147. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167148. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167149. #endif
  167150. }
  167151. void PNGAPI
  167152. png_set_palette_to_rgb(png_structp png_ptr)
  167153. {
  167154. png_debug(1, "in png_set_palette_to_rgb\n");
  167155. if(png_ptr == NULL) return;
  167156. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167157. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167158. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167159. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167160. #endif
  167161. }
  167162. #if !defined(PNG_1_0_X)
  167163. void PNGAPI
  167164. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167165. {
  167166. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167167. if(png_ptr == NULL) return;
  167168. png_ptr->transformations |= PNG_EXPAND;
  167169. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167170. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167171. #endif
  167172. }
  167173. #endif
  167174. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167175. void PNGAPI
  167176. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167177. {
  167178. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167179. if(png_ptr == NULL) return;
  167180. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167181. }
  167182. #endif
  167183. void PNGAPI
  167184. png_set_tRNS_to_alpha(png_structp png_ptr)
  167185. {
  167186. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167187. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167188. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167189. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167190. #endif
  167191. }
  167192. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167193. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167194. void PNGAPI
  167195. png_set_gray_to_rgb(png_structp png_ptr)
  167196. {
  167197. png_debug(1, "in png_set_gray_to_rgb\n");
  167198. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167199. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167200. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167201. #endif
  167202. }
  167203. #endif
  167204. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167205. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167206. void PNGAPI
  167207. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167208. double green)
  167209. {
  167210. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167211. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167212. if(png_ptr == NULL) return;
  167213. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167214. }
  167215. #endif
  167216. void PNGAPI
  167217. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167218. png_fixed_point red, png_fixed_point green)
  167219. {
  167220. png_debug(1, "in png_set_rgb_to_gray\n");
  167221. if(png_ptr == NULL) return;
  167222. switch(error_action)
  167223. {
  167224. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167225. break;
  167226. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167227. break;
  167228. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167229. }
  167230. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167231. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167232. png_ptr->transformations |= PNG_EXPAND;
  167233. #else
  167234. {
  167235. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167236. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167237. }
  167238. #endif
  167239. {
  167240. png_uint_16 red_int, green_int;
  167241. if(red < 0 || green < 0)
  167242. {
  167243. red_int = 6968; /* .212671 * 32768 + .5 */
  167244. green_int = 23434; /* .715160 * 32768 + .5 */
  167245. }
  167246. else if(red + green < 100000L)
  167247. {
  167248. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167249. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167250. }
  167251. else
  167252. {
  167253. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167254. red_int = 6968;
  167255. green_int = 23434;
  167256. }
  167257. png_ptr->rgb_to_gray_red_coeff = red_int;
  167258. png_ptr->rgb_to_gray_green_coeff = green_int;
  167259. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167260. }
  167261. }
  167262. #endif
  167263. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167264. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167265. defined(PNG_LEGACY_SUPPORTED)
  167266. void PNGAPI
  167267. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167268. read_user_transform_fn)
  167269. {
  167270. png_debug(1, "in png_set_read_user_transform_fn\n");
  167271. if(png_ptr == NULL) return;
  167272. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167273. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167274. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167275. #endif
  167276. #ifdef PNG_LEGACY_SUPPORTED
  167277. if(read_user_transform_fn)
  167278. png_warning(png_ptr,
  167279. "This version of libpng does not support user transforms");
  167280. #endif
  167281. }
  167282. #endif
  167283. void /* PRIVATE */
  167284. png_init_read_transformations(png_structp png_ptr)
  167285. {
  167286. png_debug(1, "in png_init_read_transformations\n");
  167287. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167288. if(png_ptr != NULL)
  167289. #endif
  167290. {
  167291. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167292. || defined(PNG_READ_GAMMA_SUPPORTED)
  167293. int color_type = png_ptr->color_type;
  167294. #endif
  167295. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167296. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167297. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167298. !(color_type & PNG_COLOR_MASK_COLOR))
  167299. {
  167300. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167301. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167302. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167303. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167304. png_ptr->background.red == png_ptr->background.green &&
  167305. png_ptr->background.red == png_ptr->background.blue)
  167306. {
  167307. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167308. png_ptr->background.gray = png_ptr->background.red;
  167309. }
  167310. #endif
  167311. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167312. (png_ptr->transformations & PNG_EXPAND))
  167313. {
  167314. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167315. {
  167316. switch (png_ptr->bit_depth)
  167317. {
  167318. case 1:
  167319. png_ptr->background.gray *= (png_uint_16)0xff;
  167320. png_ptr->background.red = png_ptr->background.green
  167321. = png_ptr->background.blue = png_ptr->background.gray;
  167322. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167323. {
  167324. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167325. png_ptr->trans_values.red = png_ptr->trans_values.green
  167326. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167327. }
  167328. break;
  167329. case 2:
  167330. png_ptr->background.gray *= (png_uint_16)0x55;
  167331. png_ptr->background.red = png_ptr->background.green
  167332. = png_ptr->background.blue = png_ptr->background.gray;
  167333. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167334. {
  167335. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167336. png_ptr->trans_values.red = png_ptr->trans_values.green
  167337. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167338. }
  167339. break;
  167340. case 4:
  167341. png_ptr->background.gray *= (png_uint_16)0x11;
  167342. png_ptr->background.red = png_ptr->background.green
  167343. = png_ptr->background.blue = png_ptr->background.gray;
  167344. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167345. {
  167346. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167347. png_ptr->trans_values.red = png_ptr->trans_values.green
  167348. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167349. }
  167350. break;
  167351. case 8:
  167352. case 16:
  167353. png_ptr->background.red = png_ptr->background.green
  167354. = png_ptr->background.blue = png_ptr->background.gray;
  167355. break;
  167356. }
  167357. }
  167358. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167359. {
  167360. png_ptr->background.red =
  167361. png_ptr->palette[png_ptr->background.index].red;
  167362. png_ptr->background.green =
  167363. png_ptr->palette[png_ptr->background.index].green;
  167364. png_ptr->background.blue =
  167365. png_ptr->palette[png_ptr->background.index].blue;
  167366. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167367. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167368. {
  167369. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167370. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167371. #endif
  167372. {
  167373. int i,istop;
  167374. istop=(int)png_ptr->num_trans;
  167375. for (i=0; i<istop; i++)
  167376. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167377. }
  167378. }
  167379. #endif
  167380. }
  167381. }
  167382. #endif
  167383. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167384. png_ptr->background_1 = png_ptr->background;
  167385. #endif
  167386. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167387. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167388. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167389. < PNG_GAMMA_THRESHOLD))
  167390. {
  167391. int i,k;
  167392. k=0;
  167393. for (i=0; i<png_ptr->num_trans; i++)
  167394. {
  167395. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167396. k=1; /* partial transparency is present */
  167397. }
  167398. if (k == 0)
  167399. png_ptr->transformations &= (~PNG_GAMMA);
  167400. }
  167401. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167402. png_ptr->gamma != 0.0)
  167403. {
  167404. png_build_gamma_table(png_ptr);
  167405. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167406. if (png_ptr->transformations & PNG_BACKGROUND)
  167407. {
  167408. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167409. {
  167410. png_color back, back_1;
  167411. png_colorp palette = png_ptr->palette;
  167412. int num_palette = png_ptr->num_palette;
  167413. int i;
  167414. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167415. {
  167416. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167417. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167418. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167419. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167420. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167421. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167422. }
  167423. else
  167424. {
  167425. double g, gs;
  167426. switch (png_ptr->background_gamma_type)
  167427. {
  167428. case PNG_BACKGROUND_GAMMA_SCREEN:
  167429. g = (png_ptr->screen_gamma);
  167430. gs = 1.0;
  167431. break;
  167432. case PNG_BACKGROUND_GAMMA_FILE:
  167433. g = 1.0 / (png_ptr->gamma);
  167434. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167435. break;
  167436. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167437. g = 1.0 / (png_ptr->background_gamma);
  167438. gs = 1.0 / (png_ptr->background_gamma *
  167439. png_ptr->screen_gamma);
  167440. break;
  167441. default:
  167442. g = 1.0; /* back_1 */
  167443. gs = 1.0; /* back */
  167444. }
  167445. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167446. {
  167447. back.red = (png_byte)png_ptr->background.red;
  167448. back.green = (png_byte)png_ptr->background.green;
  167449. back.blue = (png_byte)png_ptr->background.blue;
  167450. }
  167451. else
  167452. {
  167453. back.red = (png_byte)(pow(
  167454. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167455. back.green = (png_byte)(pow(
  167456. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167457. back.blue = (png_byte)(pow(
  167458. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167459. }
  167460. back_1.red = (png_byte)(pow(
  167461. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167462. back_1.green = (png_byte)(pow(
  167463. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167464. back_1.blue = (png_byte)(pow(
  167465. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167466. }
  167467. for (i = 0; i < num_palette; i++)
  167468. {
  167469. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167470. {
  167471. if (png_ptr->trans[i] == 0)
  167472. {
  167473. palette[i] = back;
  167474. }
  167475. else /* if (png_ptr->trans[i] != 0xff) */
  167476. {
  167477. png_byte v, w;
  167478. v = png_ptr->gamma_to_1[palette[i].red];
  167479. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167480. palette[i].red = png_ptr->gamma_from_1[w];
  167481. v = png_ptr->gamma_to_1[palette[i].green];
  167482. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167483. palette[i].green = png_ptr->gamma_from_1[w];
  167484. v = png_ptr->gamma_to_1[palette[i].blue];
  167485. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167486. palette[i].blue = png_ptr->gamma_from_1[w];
  167487. }
  167488. }
  167489. else
  167490. {
  167491. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167492. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167493. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167494. }
  167495. }
  167496. }
  167497. else
  167498. {
  167499. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167500. double g = 1.0;
  167501. double gs = 1.0;
  167502. switch (png_ptr->background_gamma_type)
  167503. {
  167504. case PNG_BACKGROUND_GAMMA_SCREEN:
  167505. g = (png_ptr->screen_gamma);
  167506. gs = 1.0;
  167507. break;
  167508. case PNG_BACKGROUND_GAMMA_FILE:
  167509. g = 1.0 / (png_ptr->gamma);
  167510. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167511. break;
  167512. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167513. g = 1.0 / (png_ptr->background_gamma);
  167514. gs = 1.0 / (png_ptr->background_gamma *
  167515. png_ptr->screen_gamma);
  167516. break;
  167517. }
  167518. png_ptr->background_1.gray = (png_uint_16)(pow(
  167519. (double)png_ptr->background.gray / m, g) * m + .5);
  167520. png_ptr->background.gray = (png_uint_16)(pow(
  167521. (double)png_ptr->background.gray / m, gs) * m + .5);
  167522. if ((png_ptr->background.red != png_ptr->background.green) ||
  167523. (png_ptr->background.red != png_ptr->background.blue) ||
  167524. (png_ptr->background.red != png_ptr->background.gray))
  167525. {
  167526. png_ptr->background_1.red = (png_uint_16)(pow(
  167527. (double)png_ptr->background.red / m, g) * m + .5);
  167528. png_ptr->background_1.green = (png_uint_16)(pow(
  167529. (double)png_ptr->background.green / m, g) * m + .5);
  167530. png_ptr->background_1.blue = (png_uint_16)(pow(
  167531. (double)png_ptr->background.blue / m, g) * m + .5);
  167532. png_ptr->background.red = (png_uint_16)(pow(
  167533. (double)png_ptr->background.red / m, gs) * m + .5);
  167534. png_ptr->background.green = (png_uint_16)(pow(
  167535. (double)png_ptr->background.green / m, gs) * m + .5);
  167536. png_ptr->background.blue = (png_uint_16)(pow(
  167537. (double)png_ptr->background.blue / m, gs) * m + .5);
  167538. }
  167539. else
  167540. {
  167541. png_ptr->background_1.red = png_ptr->background_1.green
  167542. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167543. png_ptr->background.red = png_ptr->background.green
  167544. = png_ptr->background.blue = png_ptr->background.gray;
  167545. }
  167546. }
  167547. }
  167548. else
  167549. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167550. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167551. {
  167552. png_colorp palette = png_ptr->palette;
  167553. int num_palette = png_ptr->num_palette;
  167554. int i;
  167555. for (i = 0; i < num_palette; i++)
  167556. {
  167557. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167558. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167559. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167560. }
  167561. }
  167562. }
  167563. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167564. else
  167565. #endif
  167566. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167567. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167568. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167569. (color_type == PNG_COLOR_TYPE_PALETTE))
  167570. {
  167571. int i;
  167572. int istop = (int)png_ptr->num_trans;
  167573. png_color back;
  167574. png_colorp palette = png_ptr->palette;
  167575. back.red = (png_byte)png_ptr->background.red;
  167576. back.green = (png_byte)png_ptr->background.green;
  167577. back.blue = (png_byte)png_ptr->background.blue;
  167578. for (i = 0; i < istop; i++)
  167579. {
  167580. if (png_ptr->trans[i] == 0)
  167581. {
  167582. palette[i] = back;
  167583. }
  167584. else if (png_ptr->trans[i] != 0xff)
  167585. {
  167586. png_composite(palette[i].red, palette[i].red,
  167587. png_ptr->trans[i], back.red);
  167588. png_composite(palette[i].green, palette[i].green,
  167589. png_ptr->trans[i], back.green);
  167590. png_composite(palette[i].blue, palette[i].blue,
  167591. png_ptr->trans[i], back.blue);
  167592. }
  167593. }
  167594. }
  167595. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167596. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167597. if ((png_ptr->transformations & PNG_SHIFT) &&
  167598. (color_type == PNG_COLOR_TYPE_PALETTE))
  167599. {
  167600. png_uint_16 i;
  167601. png_uint_16 istop = png_ptr->num_palette;
  167602. int sr = 8 - png_ptr->sig_bit.red;
  167603. int sg = 8 - png_ptr->sig_bit.green;
  167604. int sb = 8 - png_ptr->sig_bit.blue;
  167605. if (sr < 0 || sr > 8)
  167606. sr = 0;
  167607. if (sg < 0 || sg > 8)
  167608. sg = 0;
  167609. if (sb < 0 || sb > 8)
  167610. sb = 0;
  167611. for (i = 0; i < istop; i++)
  167612. {
  167613. png_ptr->palette[i].red >>= sr;
  167614. png_ptr->palette[i].green >>= sg;
  167615. png_ptr->palette[i].blue >>= sb;
  167616. }
  167617. }
  167618. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167619. }
  167620. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167621. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167622. if(png_ptr)
  167623. return;
  167624. #endif
  167625. }
  167626. void /* PRIVATE */
  167627. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167628. {
  167629. png_debug(1, "in png_read_transform_info\n");
  167630. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167631. if (png_ptr->transformations & PNG_EXPAND)
  167632. {
  167633. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167634. {
  167635. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167636. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167637. else
  167638. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167639. info_ptr->bit_depth = 8;
  167640. info_ptr->num_trans = 0;
  167641. }
  167642. else
  167643. {
  167644. if (png_ptr->num_trans)
  167645. {
  167646. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167647. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167648. else
  167649. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167650. }
  167651. if (info_ptr->bit_depth < 8)
  167652. info_ptr->bit_depth = 8;
  167653. info_ptr->num_trans = 0;
  167654. }
  167655. }
  167656. #endif
  167657. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167658. if (png_ptr->transformations & PNG_BACKGROUND)
  167659. {
  167660. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167661. info_ptr->num_trans = 0;
  167662. info_ptr->background = png_ptr->background;
  167663. }
  167664. #endif
  167665. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167666. if (png_ptr->transformations & PNG_GAMMA)
  167667. {
  167668. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167669. info_ptr->gamma = png_ptr->gamma;
  167670. #endif
  167671. #ifdef PNG_FIXED_POINT_SUPPORTED
  167672. info_ptr->int_gamma = png_ptr->int_gamma;
  167673. #endif
  167674. }
  167675. #endif
  167676. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167677. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167678. info_ptr->bit_depth = 8;
  167679. #endif
  167680. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167681. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167682. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167683. #endif
  167684. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167685. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167686. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167687. #endif
  167688. #if defined(PNG_READ_DITHER_SUPPORTED)
  167689. if (png_ptr->transformations & PNG_DITHER)
  167690. {
  167691. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167692. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167693. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167694. {
  167695. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167696. }
  167697. }
  167698. #endif
  167699. #if defined(PNG_READ_PACK_SUPPORTED)
  167700. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167701. info_ptr->bit_depth = 8;
  167702. #endif
  167703. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167704. info_ptr->channels = 1;
  167705. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  167706. info_ptr->channels = 3;
  167707. else
  167708. info_ptr->channels = 1;
  167709. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167710. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167711. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167712. #endif
  167713. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  167714. info_ptr->channels++;
  167715. #if defined(PNG_READ_FILLER_SUPPORTED)
  167716. if ((png_ptr->transformations & PNG_FILLER) &&
  167717. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167718. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  167719. {
  167720. info_ptr->channels++;
  167721. #if !defined(PNG_1_0_X)
  167722. if (png_ptr->transformations & PNG_ADD_ALPHA)
  167723. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167724. #endif
  167725. }
  167726. #endif
  167727. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  167728. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167729. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  167730. {
  167731. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  167732. info_ptr->bit_depth = png_ptr->user_transform_depth;
  167733. if(info_ptr->channels < png_ptr->user_transform_channels)
  167734. info_ptr->channels = png_ptr->user_transform_channels;
  167735. }
  167736. #endif
  167737. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  167738. info_ptr->bit_depth);
  167739. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  167740. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  167741. if(png_ptr)
  167742. return;
  167743. #endif
  167744. }
  167745. void /* PRIVATE */
  167746. png_do_read_transformations(png_structp png_ptr)
  167747. {
  167748. png_debug(1, "in png_do_read_transformations\n");
  167749. if (png_ptr->row_buf == NULL)
  167750. {
  167751. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  167752. char msg[50];
  167753. png_snprintf2(msg, 50,
  167754. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  167755. png_ptr->pass);
  167756. png_error(png_ptr, msg);
  167757. #else
  167758. png_error(png_ptr, "NULL row buffer");
  167759. #endif
  167760. }
  167761. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167762. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  167763. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  167764. png_error(png_ptr, "Uninitialized row");
  167765. #else
  167766. png_warning(png_ptr, "Uninitialized row");
  167767. #endif
  167768. #endif
  167769. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167770. if (png_ptr->transformations & PNG_EXPAND)
  167771. {
  167772. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  167773. {
  167774. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167775. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  167776. }
  167777. else
  167778. {
  167779. if (png_ptr->num_trans &&
  167780. (png_ptr->transformations & PNG_EXPAND_tRNS))
  167781. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167782. &(png_ptr->trans_values));
  167783. else
  167784. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167785. NULL);
  167786. }
  167787. }
  167788. #endif
  167789. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167790. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167791. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167792. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  167793. #endif
  167794. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167795. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167796. {
  167797. int rgb_error =
  167798. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  167799. if(rgb_error)
  167800. {
  167801. png_ptr->rgb_to_gray_status=1;
  167802. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  167803. PNG_RGB_TO_GRAY_WARN)
  167804. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  167805. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  167806. PNG_RGB_TO_GRAY_ERR)
  167807. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  167808. }
  167809. }
  167810. #endif
  167811. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167812. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167813. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  167814. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167815. #endif
  167816. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167817. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167818. ((png_ptr->num_trans != 0 ) ||
  167819. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  167820. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167821. &(png_ptr->trans_values), &(png_ptr->background)
  167822. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167823. , &(png_ptr->background_1),
  167824. png_ptr->gamma_table, png_ptr->gamma_from_1,
  167825. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  167826. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  167827. png_ptr->gamma_shift
  167828. #endif
  167829. );
  167830. #endif
  167831. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167832. if ((png_ptr->transformations & PNG_GAMMA) &&
  167833. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167834. !((png_ptr->transformations & PNG_BACKGROUND) &&
  167835. ((png_ptr->num_trans != 0) ||
  167836. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  167837. #endif
  167838. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  167839. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167840. png_ptr->gamma_table, png_ptr->gamma_16_table,
  167841. png_ptr->gamma_shift);
  167842. #endif
  167843. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167844. if (png_ptr->transformations & PNG_16_TO_8)
  167845. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167846. #endif
  167847. #if defined(PNG_READ_DITHER_SUPPORTED)
  167848. if (png_ptr->transformations & PNG_DITHER)
  167849. {
  167850. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  167851. png_ptr->palette_lookup, png_ptr->dither_index);
  167852. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  167853. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  167854. }
  167855. #endif
  167856. #if defined(PNG_READ_INVERT_SUPPORTED)
  167857. if (png_ptr->transformations & PNG_INVERT_MONO)
  167858. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167859. #endif
  167860. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167861. if (png_ptr->transformations & PNG_SHIFT)
  167862. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167863. &(png_ptr->shift));
  167864. #endif
  167865. #if defined(PNG_READ_PACK_SUPPORTED)
  167866. if (png_ptr->transformations & PNG_PACK)
  167867. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167868. #endif
  167869. #if defined(PNG_READ_BGR_SUPPORTED)
  167870. if (png_ptr->transformations & PNG_BGR)
  167871. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167872. #endif
  167873. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  167874. if (png_ptr->transformations & PNG_PACKSWAP)
  167875. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167876. #endif
  167877. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167878. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167879. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  167880. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167881. #endif
  167882. #if defined(PNG_READ_FILLER_SUPPORTED)
  167883. if (png_ptr->transformations & PNG_FILLER)
  167884. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167885. (png_uint_32)png_ptr->filler, png_ptr->flags);
  167886. #endif
  167887. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167888. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167889. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167890. #endif
  167891. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  167892. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  167893. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167894. #endif
  167895. #if defined(PNG_READ_SWAP_SUPPORTED)
  167896. if (png_ptr->transformations & PNG_SWAP_BYTES)
  167897. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167898. #endif
  167899. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167900. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  167901. {
  167902. if(png_ptr->read_user_transform_fn != NULL)
  167903. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  167904. (png_ptr, /* png_ptr */
  167905. &(png_ptr->row_info), /* row_info: */
  167906. png_ptr->row_buf + 1); /* start of pixel data for row */
  167907. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  167908. if(png_ptr->user_transform_depth)
  167909. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  167910. if(png_ptr->user_transform_channels)
  167911. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  167912. #endif
  167913. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  167914. png_ptr->row_info.channels);
  167915. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  167916. png_ptr->row_info.width);
  167917. }
  167918. #endif
  167919. }
  167920. #if defined(PNG_READ_PACK_SUPPORTED)
  167921. void /* PRIVATE */
  167922. png_do_unpack(png_row_infop row_info, png_bytep row)
  167923. {
  167924. png_debug(1, "in png_do_unpack\n");
  167925. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167926. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  167927. #else
  167928. if (row_info->bit_depth < 8)
  167929. #endif
  167930. {
  167931. png_uint_32 i;
  167932. png_uint_32 row_width=row_info->width;
  167933. switch (row_info->bit_depth)
  167934. {
  167935. case 1:
  167936. {
  167937. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  167938. png_bytep dp = row + (png_size_t)row_width - 1;
  167939. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  167940. for (i = 0; i < row_width; i++)
  167941. {
  167942. *dp = (png_byte)((*sp >> shift) & 0x01);
  167943. if (shift == 7)
  167944. {
  167945. shift = 0;
  167946. sp--;
  167947. }
  167948. else
  167949. shift++;
  167950. dp--;
  167951. }
  167952. break;
  167953. }
  167954. case 2:
  167955. {
  167956. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  167957. png_bytep dp = row + (png_size_t)row_width - 1;
  167958. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  167959. for (i = 0; i < row_width; i++)
  167960. {
  167961. *dp = (png_byte)((*sp >> shift) & 0x03);
  167962. if (shift == 6)
  167963. {
  167964. shift = 0;
  167965. sp--;
  167966. }
  167967. else
  167968. shift += 2;
  167969. dp--;
  167970. }
  167971. break;
  167972. }
  167973. case 4:
  167974. {
  167975. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  167976. png_bytep dp = row + (png_size_t)row_width - 1;
  167977. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  167978. for (i = 0; i < row_width; i++)
  167979. {
  167980. *dp = (png_byte)((*sp >> shift) & 0x0f);
  167981. if (shift == 4)
  167982. {
  167983. shift = 0;
  167984. sp--;
  167985. }
  167986. else
  167987. shift = 4;
  167988. dp--;
  167989. }
  167990. break;
  167991. }
  167992. }
  167993. row_info->bit_depth = 8;
  167994. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  167995. row_info->rowbytes = row_width * row_info->channels;
  167996. }
  167997. }
  167998. #endif
  167999. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168000. void /* PRIVATE */
  168001. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168002. {
  168003. png_debug(1, "in png_do_unshift\n");
  168004. if (
  168005. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168006. row != NULL && row_info != NULL && sig_bits != NULL &&
  168007. #endif
  168008. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168009. {
  168010. int shift[4];
  168011. int channels = 0;
  168012. int c;
  168013. png_uint_16 value = 0;
  168014. png_uint_32 row_width = row_info->width;
  168015. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168016. {
  168017. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168018. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168019. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168020. }
  168021. else
  168022. {
  168023. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168024. }
  168025. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168026. {
  168027. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168028. }
  168029. for (c = 0; c < channels; c++)
  168030. {
  168031. if (shift[c] <= 0)
  168032. shift[c] = 0;
  168033. else
  168034. value = 1;
  168035. }
  168036. if (!value)
  168037. return;
  168038. switch (row_info->bit_depth)
  168039. {
  168040. case 2:
  168041. {
  168042. png_bytep bp;
  168043. png_uint_32 i;
  168044. png_uint_32 istop = row_info->rowbytes;
  168045. for (bp = row, i = 0; i < istop; i++)
  168046. {
  168047. *bp >>= 1;
  168048. *bp++ &= 0x55;
  168049. }
  168050. break;
  168051. }
  168052. case 4:
  168053. {
  168054. png_bytep bp = row;
  168055. png_uint_32 i;
  168056. png_uint_32 istop = row_info->rowbytes;
  168057. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168058. (png_byte)((int)0xf >> shift[0]));
  168059. for (i = 0; i < istop; i++)
  168060. {
  168061. *bp >>= shift[0];
  168062. *bp++ &= mask;
  168063. }
  168064. break;
  168065. }
  168066. case 8:
  168067. {
  168068. png_bytep bp = row;
  168069. png_uint_32 i;
  168070. png_uint_32 istop = row_width * channels;
  168071. for (i = 0; i < istop; i++)
  168072. {
  168073. *bp++ >>= shift[i%channels];
  168074. }
  168075. break;
  168076. }
  168077. case 16:
  168078. {
  168079. png_bytep bp = row;
  168080. png_uint_32 i;
  168081. png_uint_32 istop = channels * row_width;
  168082. for (i = 0; i < istop; i++)
  168083. {
  168084. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168085. value >>= shift[i%channels];
  168086. *bp++ = (png_byte)(value >> 8);
  168087. *bp++ = (png_byte)(value & 0xff);
  168088. }
  168089. break;
  168090. }
  168091. }
  168092. }
  168093. }
  168094. #endif
  168095. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168096. void /* PRIVATE */
  168097. png_do_chop(png_row_infop row_info, png_bytep row)
  168098. {
  168099. png_debug(1, "in png_do_chop\n");
  168100. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168101. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168102. #else
  168103. if (row_info->bit_depth == 16)
  168104. #endif
  168105. {
  168106. png_bytep sp = row;
  168107. png_bytep dp = row;
  168108. png_uint_32 i;
  168109. png_uint_32 istop = row_info->width * row_info->channels;
  168110. for (i = 0; i<istop; i++, sp += 2, dp++)
  168111. {
  168112. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168113. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168114. #else
  168115. *dp = *sp;
  168116. #endif
  168117. }
  168118. row_info->bit_depth = 8;
  168119. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168120. row_info->rowbytes = row_info->width * row_info->channels;
  168121. }
  168122. }
  168123. #endif
  168124. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168125. void /* PRIVATE */
  168126. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168127. {
  168128. png_debug(1, "in png_do_read_swap_alpha\n");
  168129. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168130. if (row != NULL && row_info != NULL)
  168131. #endif
  168132. {
  168133. png_uint_32 row_width = row_info->width;
  168134. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168135. {
  168136. if (row_info->bit_depth == 8)
  168137. {
  168138. png_bytep sp = row + row_info->rowbytes;
  168139. png_bytep dp = sp;
  168140. png_byte save;
  168141. png_uint_32 i;
  168142. for (i = 0; i < row_width; i++)
  168143. {
  168144. save = *(--sp);
  168145. *(--dp) = *(--sp);
  168146. *(--dp) = *(--sp);
  168147. *(--dp) = *(--sp);
  168148. *(--dp) = save;
  168149. }
  168150. }
  168151. else
  168152. {
  168153. png_bytep sp = row + row_info->rowbytes;
  168154. png_bytep dp = sp;
  168155. png_byte save[2];
  168156. png_uint_32 i;
  168157. for (i = 0; i < row_width; i++)
  168158. {
  168159. save[0] = *(--sp);
  168160. save[1] = *(--sp);
  168161. *(--dp) = *(--sp);
  168162. *(--dp) = *(--sp);
  168163. *(--dp) = *(--sp);
  168164. *(--dp) = *(--sp);
  168165. *(--dp) = *(--sp);
  168166. *(--dp) = *(--sp);
  168167. *(--dp) = save[0];
  168168. *(--dp) = save[1];
  168169. }
  168170. }
  168171. }
  168172. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168173. {
  168174. if (row_info->bit_depth == 8)
  168175. {
  168176. png_bytep sp = row + row_info->rowbytes;
  168177. png_bytep dp = sp;
  168178. png_byte save;
  168179. png_uint_32 i;
  168180. for (i = 0; i < row_width; i++)
  168181. {
  168182. save = *(--sp);
  168183. *(--dp) = *(--sp);
  168184. *(--dp) = save;
  168185. }
  168186. }
  168187. else
  168188. {
  168189. png_bytep sp = row + row_info->rowbytes;
  168190. png_bytep dp = sp;
  168191. png_byte save[2];
  168192. png_uint_32 i;
  168193. for (i = 0; i < row_width; i++)
  168194. {
  168195. save[0] = *(--sp);
  168196. save[1] = *(--sp);
  168197. *(--dp) = *(--sp);
  168198. *(--dp) = *(--sp);
  168199. *(--dp) = save[0];
  168200. *(--dp) = save[1];
  168201. }
  168202. }
  168203. }
  168204. }
  168205. }
  168206. #endif
  168207. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168208. void /* PRIVATE */
  168209. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168210. {
  168211. png_debug(1, "in png_do_read_invert_alpha\n");
  168212. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168213. if (row != NULL && row_info != NULL)
  168214. #endif
  168215. {
  168216. png_uint_32 row_width = row_info->width;
  168217. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168218. {
  168219. if (row_info->bit_depth == 8)
  168220. {
  168221. png_bytep sp = row + row_info->rowbytes;
  168222. png_bytep dp = sp;
  168223. png_uint_32 i;
  168224. for (i = 0; i < row_width; i++)
  168225. {
  168226. *(--dp) = (png_byte)(255 - *(--sp));
  168227. sp-=3;
  168228. dp=sp;
  168229. }
  168230. }
  168231. else
  168232. {
  168233. png_bytep sp = row + row_info->rowbytes;
  168234. png_bytep dp = sp;
  168235. png_uint_32 i;
  168236. for (i = 0; i < row_width; i++)
  168237. {
  168238. *(--dp) = (png_byte)(255 - *(--sp));
  168239. *(--dp) = (png_byte)(255 - *(--sp));
  168240. sp-=6;
  168241. dp=sp;
  168242. }
  168243. }
  168244. }
  168245. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168246. {
  168247. if (row_info->bit_depth == 8)
  168248. {
  168249. png_bytep sp = row + row_info->rowbytes;
  168250. png_bytep dp = sp;
  168251. png_uint_32 i;
  168252. for (i = 0; i < row_width; i++)
  168253. {
  168254. *(--dp) = (png_byte)(255 - *(--sp));
  168255. *(--dp) = *(--sp);
  168256. }
  168257. }
  168258. else
  168259. {
  168260. png_bytep sp = row + row_info->rowbytes;
  168261. png_bytep dp = sp;
  168262. png_uint_32 i;
  168263. for (i = 0; i < row_width; i++)
  168264. {
  168265. *(--dp) = (png_byte)(255 - *(--sp));
  168266. *(--dp) = (png_byte)(255 - *(--sp));
  168267. sp-=2;
  168268. dp=sp;
  168269. }
  168270. }
  168271. }
  168272. }
  168273. }
  168274. #endif
  168275. #if defined(PNG_READ_FILLER_SUPPORTED)
  168276. void /* PRIVATE */
  168277. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168278. png_uint_32 filler, png_uint_32 flags)
  168279. {
  168280. png_uint_32 i;
  168281. png_uint_32 row_width = row_info->width;
  168282. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168283. png_byte lo_filler = (png_byte)(filler & 0xff);
  168284. png_debug(1, "in png_do_read_filler\n");
  168285. if (
  168286. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168287. row != NULL && row_info != NULL &&
  168288. #endif
  168289. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168290. {
  168291. if(row_info->bit_depth == 8)
  168292. {
  168293. if (flags & PNG_FLAG_FILLER_AFTER)
  168294. {
  168295. png_bytep sp = row + (png_size_t)row_width;
  168296. png_bytep dp = sp + (png_size_t)row_width;
  168297. for (i = 1; i < row_width; i++)
  168298. {
  168299. *(--dp) = lo_filler;
  168300. *(--dp) = *(--sp);
  168301. }
  168302. *(--dp) = lo_filler;
  168303. row_info->channels = 2;
  168304. row_info->pixel_depth = 16;
  168305. row_info->rowbytes = row_width * 2;
  168306. }
  168307. else
  168308. {
  168309. png_bytep sp = row + (png_size_t)row_width;
  168310. png_bytep dp = sp + (png_size_t)row_width;
  168311. for (i = 0; i < row_width; i++)
  168312. {
  168313. *(--dp) = *(--sp);
  168314. *(--dp) = lo_filler;
  168315. }
  168316. row_info->channels = 2;
  168317. row_info->pixel_depth = 16;
  168318. row_info->rowbytes = row_width * 2;
  168319. }
  168320. }
  168321. else if(row_info->bit_depth == 16)
  168322. {
  168323. if (flags & PNG_FLAG_FILLER_AFTER)
  168324. {
  168325. png_bytep sp = row + (png_size_t)row_width * 2;
  168326. png_bytep dp = sp + (png_size_t)row_width * 2;
  168327. for (i = 1; i < row_width; i++)
  168328. {
  168329. *(--dp) = hi_filler;
  168330. *(--dp) = lo_filler;
  168331. *(--dp) = *(--sp);
  168332. *(--dp) = *(--sp);
  168333. }
  168334. *(--dp) = hi_filler;
  168335. *(--dp) = lo_filler;
  168336. row_info->channels = 2;
  168337. row_info->pixel_depth = 32;
  168338. row_info->rowbytes = row_width * 4;
  168339. }
  168340. else
  168341. {
  168342. png_bytep sp = row + (png_size_t)row_width * 2;
  168343. png_bytep dp = sp + (png_size_t)row_width * 2;
  168344. for (i = 0; i < row_width; i++)
  168345. {
  168346. *(--dp) = *(--sp);
  168347. *(--dp) = *(--sp);
  168348. *(--dp) = hi_filler;
  168349. *(--dp) = lo_filler;
  168350. }
  168351. row_info->channels = 2;
  168352. row_info->pixel_depth = 32;
  168353. row_info->rowbytes = row_width * 4;
  168354. }
  168355. }
  168356. } /* COLOR_TYPE == GRAY */
  168357. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168358. {
  168359. if(row_info->bit_depth == 8)
  168360. {
  168361. if (flags & PNG_FLAG_FILLER_AFTER)
  168362. {
  168363. png_bytep sp = row + (png_size_t)row_width * 3;
  168364. png_bytep dp = sp + (png_size_t)row_width;
  168365. for (i = 1; i < row_width; i++)
  168366. {
  168367. *(--dp) = lo_filler;
  168368. *(--dp) = *(--sp);
  168369. *(--dp) = *(--sp);
  168370. *(--dp) = *(--sp);
  168371. }
  168372. *(--dp) = lo_filler;
  168373. row_info->channels = 4;
  168374. row_info->pixel_depth = 32;
  168375. row_info->rowbytes = row_width * 4;
  168376. }
  168377. else
  168378. {
  168379. png_bytep sp = row + (png_size_t)row_width * 3;
  168380. png_bytep dp = sp + (png_size_t)row_width;
  168381. for (i = 0; i < row_width; i++)
  168382. {
  168383. *(--dp) = *(--sp);
  168384. *(--dp) = *(--sp);
  168385. *(--dp) = *(--sp);
  168386. *(--dp) = lo_filler;
  168387. }
  168388. row_info->channels = 4;
  168389. row_info->pixel_depth = 32;
  168390. row_info->rowbytes = row_width * 4;
  168391. }
  168392. }
  168393. else if(row_info->bit_depth == 16)
  168394. {
  168395. if (flags & PNG_FLAG_FILLER_AFTER)
  168396. {
  168397. png_bytep sp = row + (png_size_t)row_width * 6;
  168398. png_bytep dp = sp + (png_size_t)row_width * 2;
  168399. for (i = 1; i < row_width; i++)
  168400. {
  168401. *(--dp) = hi_filler;
  168402. *(--dp) = lo_filler;
  168403. *(--dp) = *(--sp);
  168404. *(--dp) = *(--sp);
  168405. *(--dp) = *(--sp);
  168406. *(--dp) = *(--sp);
  168407. *(--dp) = *(--sp);
  168408. *(--dp) = *(--sp);
  168409. }
  168410. *(--dp) = hi_filler;
  168411. *(--dp) = lo_filler;
  168412. row_info->channels = 4;
  168413. row_info->pixel_depth = 64;
  168414. row_info->rowbytes = row_width * 8;
  168415. }
  168416. else
  168417. {
  168418. png_bytep sp = row + (png_size_t)row_width * 6;
  168419. png_bytep dp = sp + (png_size_t)row_width * 2;
  168420. for (i = 0; i < row_width; i++)
  168421. {
  168422. *(--dp) = *(--sp);
  168423. *(--dp) = *(--sp);
  168424. *(--dp) = *(--sp);
  168425. *(--dp) = *(--sp);
  168426. *(--dp) = *(--sp);
  168427. *(--dp) = *(--sp);
  168428. *(--dp) = hi_filler;
  168429. *(--dp) = lo_filler;
  168430. }
  168431. row_info->channels = 4;
  168432. row_info->pixel_depth = 64;
  168433. row_info->rowbytes = row_width * 8;
  168434. }
  168435. }
  168436. } /* COLOR_TYPE == RGB */
  168437. }
  168438. #endif
  168439. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168440. void /* PRIVATE */
  168441. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168442. {
  168443. png_uint_32 i;
  168444. png_uint_32 row_width = row_info->width;
  168445. png_debug(1, "in png_do_gray_to_rgb\n");
  168446. if (row_info->bit_depth >= 8 &&
  168447. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168448. row != NULL && row_info != NULL &&
  168449. #endif
  168450. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168451. {
  168452. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168453. {
  168454. if (row_info->bit_depth == 8)
  168455. {
  168456. png_bytep sp = row + (png_size_t)row_width - 1;
  168457. png_bytep dp = sp + (png_size_t)row_width * 2;
  168458. for (i = 0; i < row_width; i++)
  168459. {
  168460. *(dp--) = *sp;
  168461. *(dp--) = *sp;
  168462. *(dp--) = *(sp--);
  168463. }
  168464. }
  168465. else
  168466. {
  168467. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168468. png_bytep dp = sp + (png_size_t)row_width * 4;
  168469. for (i = 0; i < row_width; i++)
  168470. {
  168471. *(dp--) = *sp;
  168472. *(dp--) = *(sp - 1);
  168473. *(dp--) = *sp;
  168474. *(dp--) = *(sp - 1);
  168475. *(dp--) = *(sp--);
  168476. *(dp--) = *(sp--);
  168477. }
  168478. }
  168479. }
  168480. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168481. {
  168482. if (row_info->bit_depth == 8)
  168483. {
  168484. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168485. png_bytep dp = sp + (png_size_t)row_width * 2;
  168486. for (i = 0; i < row_width; i++)
  168487. {
  168488. *(dp--) = *(sp--);
  168489. *(dp--) = *sp;
  168490. *(dp--) = *sp;
  168491. *(dp--) = *(sp--);
  168492. }
  168493. }
  168494. else
  168495. {
  168496. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168497. png_bytep dp = sp + (png_size_t)row_width * 4;
  168498. for (i = 0; i < row_width; i++)
  168499. {
  168500. *(dp--) = *(sp--);
  168501. *(dp--) = *(sp--);
  168502. *(dp--) = *sp;
  168503. *(dp--) = *(sp - 1);
  168504. *(dp--) = *sp;
  168505. *(dp--) = *(sp - 1);
  168506. *(dp--) = *(sp--);
  168507. *(dp--) = *(sp--);
  168508. }
  168509. }
  168510. }
  168511. row_info->channels += (png_byte)2;
  168512. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168513. row_info->pixel_depth = (png_byte)(row_info->channels *
  168514. row_info->bit_depth);
  168515. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168516. }
  168517. }
  168518. #endif
  168519. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168520. int /* PRIVATE */
  168521. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168522. {
  168523. png_uint_32 i;
  168524. png_uint_32 row_width = row_info->width;
  168525. int rgb_error = 0;
  168526. png_debug(1, "in png_do_rgb_to_gray\n");
  168527. if (
  168528. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168529. row != NULL && row_info != NULL &&
  168530. #endif
  168531. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168532. {
  168533. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168534. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168535. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168536. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168537. {
  168538. if (row_info->bit_depth == 8)
  168539. {
  168540. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168541. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168542. {
  168543. png_bytep sp = row;
  168544. png_bytep dp = row;
  168545. for (i = 0; i < row_width; i++)
  168546. {
  168547. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168548. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168549. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168550. if(red != green || red != blue)
  168551. {
  168552. rgb_error |= 1;
  168553. *(dp++) = png_ptr->gamma_from_1[
  168554. (rc*red+gc*green+bc*blue)>>15];
  168555. }
  168556. else
  168557. *(dp++) = *(sp-1);
  168558. }
  168559. }
  168560. else
  168561. #endif
  168562. {
  168563. png_bytep sp = row;
  168564. png_bytep dp = row;
  168565. for (i = 0; i < row_width; i++)
  168566. {
  168567. png_byte red = *(sp++);
  168568. png_byte green = *(sp++);
  168569. png_byte blue = *(sp++);
  168570. if(red != green || red != blue)
  168571. {
  168572. rgb_error |= 1;
  168573. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168574. }
  168575. else
  168576. *(dp++) = *(sp-1);
  168577. }
  168578. }
  168579. }
  168580. else /* RGB bit_depth == 16 */
  168581. {
  168582. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168583. if (png_ptr->gamma_16_to_1 != NULL &&
  168584. png_ptr->gamma_16_from_1 != NULL)
  168585. {
  168586. png_bytep sp = row;
  168587. png_bytep dp = row;
  168588. for (i = 0; i < row_width; i++)
  168589. {
  168590. png_uint_16 red, green, blue, w;
  168591. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168592. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168593. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168594. if(red == green && red == blue)
  168595. w = red;
  168596. else
  168597. {
  168598. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168599. png_ptr->gamma_shift][red>>8];
  168600. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168601. png_ptr->gamma_shift][green>>8];
  168602. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168603. png_ptr->gamma_shift][blue>>8];
  168604. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168605. + bc*blue_1)>>15);
  168606. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168607. png_ptr->gamma_shift][gray16 >> 8];
  168608. rgb_error |= 1;
  168609. }
  168610. *(dp++) = (png_byte)((w>>8) & 0xff);
  168611. *(dp++) = (png_byte)(w & 0xff);
  168612. }
  168613. }
  168614. else
  168615. #endif
  168616. {
  168617. png_bytep sp = row;
  168618. png_bytep dp = row;
  168619. for (i = 0; i < row_width; i++)
  168620. {
  168621. png_uint_16 red, green, blue, gray16;
  168622. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168623. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168624. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168625. if(red != green || red != blue)
  168626. rgb_error |= 1;
  168627. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168628. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168629. *(dp++) = (png_byte)(gray16 & 0xff);
  168630. }
  168631. }
  168632. }
  168633. }
  168634. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168635. {
  168636. if (row_info->bit_depth == 8)
  168637. {
  168638. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168639. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168640. {
  168641. png_bytep sp = row;
  168642. png_bytep dp = row;
  168643. for (i = 0; i < row_width; i++)
  168644. {
  168645. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168646. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168647. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168648. if(red != green || red != blue)
  168649. rgb_error |= 1;
  168650. *(dp++) = png_ptr->gamma_from_1
  168651. [(rc*red + gc*green + bc*blue)>>15];
  168652. *(dp++) = *(sp++); /* alpha */
  168653. }
  168654. }
  168655. else
  168656. #endif
  168657. {
  168658. png_bytep sp = row;
  168659. png_bytep dp = row;
  168660. for (i = 0; i < row_width; i++)
  168661. {
  168662. png_byte red = *(sp++);
  168663. png_byte green = *(sp++);
  168664. png_byte blue = *(sp++);
  168665. if(red != green || red != blue)
  168666. rgb_error |= 1;
  168667. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168668. *(dp++) = *(sp++); /* alpha */
  168669. }
  168670. }
  168671. }
  168672. else /* RGBA bit_depth == 16 */
  168673. {
  168674. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168675. if (png_ptr->gamma_16_to_1 != NULL &&
  168676. png_ptr->gamma_16_from_1 != NULL)
  168677. {
  168678. png_bytep sp = row;
  168679. png_bytep dp = row;
  168680. for (i = 0; i < row_width; i++)
  168681. {
  168682. png_uint_16 red, green, blue, w;
  168683. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168684. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168685. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168686. if(red == green && red == blue)
  168687. w = red;
  168688. else
  168689. {
  168690. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168691. png_ptr->gamma_shift][red>>8];
  168692. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168693. png_ptr->gamma_shift][green>>8];
  168694. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168695. png_ptr->gamma_shift][blue>>8];
  168696. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168697. + gc * green_1 + bc * blue_1)>>15);
  168698. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168699. png_ptr->gamma_shift][gray16 >> 8];
  168700. rgb_error |= 1;
  168701. }
  168702. *(dp++) = (png_byte)((w>>8) & 0xff);
  168703. *(dp++) = (png_byte)(w & 0xff);
  168704. *(dp++) = *(sp++); /* alpha */
  168705. *(dp++) = *(sp++);
  168706. }
  168707. }
  168708. else
  168709. #endif
  168710. {
  168711. png_bytep sp = row;
  168712. png_bytep dp = row;
  168713. for (i = 0; i < row_width; i++)
  168714. {
  168715. png_uint_16 red, green, blue, gray16;
  168716. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168717. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168718. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168719. if(red != green || red != blue)
  168720. rgb_error |= 1;
  168721. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168722. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168723. *(dp++) = (png_byte)(gray16 & 0xff);
  168724. *(dp++) = *(sp++); /* alpha */
  168725. *(dp++) = *(sp++);
  168726. }
  168727. }
  168728. }
  168729. }
  168730. row_info->channels -= (png_byte)2;
  168731. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  168732. row_info->pixel_depth = (png_byte)(row_info->channels *
  168733. row_info->bit_depth);
  168734. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168735. }
  168736. return rgb_error;
  168737. }
  168738. #endif
  168739. void PNGAPI
  168740. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  168741. {
  168742. int num_palette;
  168743. int color_inc;
  168744. int i;
  168745. int v;
  168746. png_debug(1, "in png_do_build_grayscale_palette\n");
  168747. if (palette == NULL)
  168748. return;
  168749. switch (bit_depth)
  168750. {
  168751. case 1:
  168752. num_palette = 2;
  168753. color_inc = 0xff;
  168754. break;
  168755. case 2:
  168756. num_palette = 4;
  168757. color_inc = 0x55;
  168758. break;
  168759. case 4:
  168760. num_palette = 16;
  168761. color_inc = 0x11;
  168762. break;
  168763. case 8:
  168764. num_palette = 256;
  168765. color_inc = 1;
  168766. break;
  168767. default:
  168768. num_palette = 0;
  168769. color_inc = 0;
  168770. break;
  168771. }
  168772. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  168773. {
  168774. palette[i].red = (png_byte)v;
  168775. palette[i].green = (png_byte)v;
  168776. palette[i].blue = (png_byte)v;
  168777. }
  168778. }
  168779. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  168780. void /* PRIVATE */
  168781. png_correct_palette(png_structp png_ptr, png_colorp palette,
  168782. int num_palette)
  168783. {
  168784. png_debug(1, "in png_correct_palette\n");
  168785. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  168786. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168787. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  168788. {
  168789. png_color back, back_1;
  168790. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168791. {
  168792. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168793. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168794. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168795. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168796. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168797. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168798. }
  168799. else
  168800. {
  168801. double g;
  168802. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  168803. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  168804. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  168805. {
  168806. back.red = png_ptr->background.red;
  168807. back.green = png_ptr->background.green;
  168808. back.blue = png_ptr->background.blue;
  168809. }
  168810. else
  168811. {
  168812. back.red =
  168813. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  168814. 255.0 + 0.5);
  168815. back.green =
  168816. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  168817. 255.0 + 0.5);
  168818. back.blue =
  168819. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  168820. 255.0 + 0.5);
  168821. }
  168822. g = 1.0 / png_ptr->background_gamma;
  168823. back_1.red =
  168824. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  168825. 255.0 + 0.5);
  168826. back_1.green =
  168827. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  168828. 255.0 + 0.5);
  168829. back_1.blue =
  168830. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  168831. 255.0 + 0.5);
  168832. }
  168833. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168834. {
  168835. png_uint_32 i;
  168836. for (i = 0; i < (png_uint_32)num_palette; i++)
  168837. {
  168838. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  168839. {
  168840. palette[i] = back;
  168841. }
  168842. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168843. {
  168844. png_byte v, w;
  168845. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  168846. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168847. palette[i].red = png_ptr->gamma_from_1[w];
  168848. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  168849. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168850. palette[i].green = png_ptr->gamma_from_1[w];
  168851. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  168852. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168853. palette[i].blue = png_ptr->gamma_from_1[w];
  168854. }
  168855. else
  168856. {
  168857. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168858. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168859. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168860. }
  168861. }
  168862. }
  168863. else
  168864. {
  168865. int i;
  168866. for (i = 0; i < num_palette; i++)
  168867. {
  168868. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  168869. {
  168870. palette[i] = back;
  168871. }
  168872. else
  168873. {
  168874. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168875. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168876. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168877. }
  168878. }
  168879. }
  168880. }
  168881. else
  168882. #endif
  168883. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168884. if (png_ptr->transformations & PNG_GAMMA)
  168885. {
  168886. int i;
  168887. for (i = 0; i < num_palette; i++)
  168888. {
  168889. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168890. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168891. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168892. }
  168893. }
  168894. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168895. else
  168896. #endif
  168897. #endif
  168898. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168899. if (png_ptr->transformations & PNG_BACKGROUND)
  168900. {
  168901. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168902. {
  168903. png_color back;
  168904. back.red = (png_byte)png_ptr->background.red;
  168905. back.green = (png_byte)png_ptr->background.green;
  168906. back.blue = (png_byte)png_ptr->background.blue;
  168907. for (i = 0; i < (int)png_ptr->num_trans; i++)
  168908. {
  168909. if (png_ptr->trans[i] == 0)
  168910. {
  168911. palette[i].red = back.red;
  168912. palette[i].green = back.green;
  168913. palette[i].blue = back.blue;
  168914. }
  168915. else if (png_ptr->trans[i] != 0xff)
  168916. {
  168917. png_composite(palette[i].red, png_ptr->palette[i].red,
  168918. png_ptr->trans[i], back.red);
  168919. png_composite(palette[i].green, png_ptr->palette[i].green,
  168920. png_ptr->trans[i], back.green);
  168921. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  168922. png_ptr->trans[i], back.blue);
  168923. }
  168924. }
  168925. }
  168926. else /* assume grayscale palette (what else could it be?) */
  168927. {
  168928. int i;
  168929. for (i = 0; i < num_palette; i++)
  168930. {
  168931. if (i == (png_byte)png_ptr->trans_values.gray)
  168932. {
  168933. palette[i].red = (png_byte)png_ptr->background.red;
  168934. palette[i].green = (png_byte)png_ptr->background.green;
  168935. palette[i].blue = (png_byte)png_ptr->background.blue;
  168936. }
  168937. }
  168938. }
  168939. }
  168940. #endif
  168941. }
  168942. #endif
  168943. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168944. void /* PRIVATE */
  168945. png_do_background(png_row_infop row_info, png_bytep row,
  168946. png_color_16p trans_values, png_color_16p background
  168947. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168948. , png_color_16p background_1,
  168949. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  168950. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  168951. png_uint_16pp gamma_16_to_1, int gamma_shift
  168952. #endif
  168953. )
  168954. {
  168955. png_bytep sp, dp;
  168956. png_uint_32 i;
  168957. png_uint_32 row_width=row_info->width;
  168958. int shift;
  168959. png_debug(1, "in png_do_background\n");
  168960. if (background != NULL &&
  168961. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168962. row != NULL && row_info != NULL &&
  168963. #endif
  168964. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  168965. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  168966. {
  168967. switch (row_info->color_type)
  168968. {
  168969. case PNG_COLOR_TYPE_GRAY:
  168970. {
  168971. switch (row_info->bit_depth)
  168972. {
  168973. case 1:
  168974. {
  168975. sp = row;
  168976. shift = 7;
  168977. for (i = 0; i < row_width; i++)
  168978. {
  168979. if ((png_uint_16)((*sp >> shift) & 0x01)
  168980. == trans_values->gray)
  168981. {
  168982. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  168983. *sp |= (png_byte)(background->gray << shift);
  168984. }
  168985. if (!shift)
  168986. {
  168987. shift = 7;
  168988. sp++;
  168989. }
  168990. else
  168991. shift--;
  168992. }
  168993. break;
  168994. }
  168995. case 2:
  168996. {
  168997. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168998. if (gamma_table != NULL)
  168999. {
  169000. sp = row;
  169001. shift = 6;
  169002. for (i = 0; i < row_width; i++)
  169003. {
  169004. if ((png_uint_16)((*sp >> shift) & 0x03)
  169005. == trans_values->gray)
  169006. {
  169007. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169008. *sp |= (png_byte)(background->gray << shift);
  169009. }
  169010. else
  169011. {
  169012. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169013. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169014. (p << 4) | (p << 6)] >> 6) & 0x03);
  169015. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169016. *sp |= (png_byte)(g << shift);
  169017. }
  169018. if (!shift)
  169019. {
  169020. shift = 6;
  169021. sp++;
  169022. }
  169023. else
  169024. shift -= 2;
  169025. }
  169026. }
  169027. else
  169028. #endif
  169029. {
  169030. sp = row;
  169031. shift = 6;
  169032. for (i = 0; i < row_width; i++)
  169033. {
  169034. if ((png_uint_16)((*sp >> shift) & 0x03)
  169035. == trans_values->gray)
  169036. {
  169037. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169038. *sp |= (png_byte)(background->gray << shift);
  169039. }
  169040. if (!shift)
  169041. {
  169042. shift = 6;
  169043. sp++;
  169044. }
  169045. else
  169046. shift -= 2;
  169047. }
  169048. }
  169049. break;
  169050. }
  169051. case 4:
  169052. {
  169053. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169054. if (gamma_table != NULL)
  169055. {
  169056. sp = row;
  169057. shift = 4;
  169058. for (i = 0; i < row_width; i++)
  169059. {
  169060. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169061. == trans_values->gray)
  169062. {
  169063. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169064. *sp |= (png_byte)(background->gray << shift);
  169065. }
  169066. else
  169067. {
  169068. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169069. png_byte g = (png_byte)((gamma_table[p |
  169070. (p << 4)] >> 4) & 0x0f);
  169071. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169072. *sp |= (png_byte)(g << shift);
  169073. }
  169074. if (!shift)
  169075. {
  169076. shift = 4;
  169077. sp++;
  169078. }
  169079. else
  169080. shift -= 4;
  169081. }
  169082. }
  169083. else
  169084. #endif
  169085. {
  169086. sp = row;
  169087. shift = 4;
  169088. for (i = 0; i < row_width; i++)
  169089. {
  169090. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169091. == trans_values->gray)
  169092. {
  169093. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169094. *sp |= (png_byte)(background->gray << shift);
  169095. }
  169096. if (!shift)
  169097. {
  169098. shift = 4;
  169099. sp++;
  169100. }
  169101. else
  169102. shift -= 4;
  169103. }
  169104. }
  169105. break;
  169106. }
  169107. case 8:
  169108. {
  169109. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169110. if (gamma_table != NULL)
  169111. {
  169112. sp = row;
  169113. for (i = 0; i < row_width; i++, sp++)
  169114. {
  169115. if (*sp == trans_values->gray)
  169116. {
  169117. *sp = (png_byte)background->gray;
  169118. }
  169119. else
  169120. {
  169121. *sp = gamma_table[*sp];
  169122. }
  169123. }
  169124. }
  169125. else
  169126. #endif
  169127. {
  169128. sp = row;
  169129. for (i = 0; i < row_width; i++, sp++)
  169130. {
  169131. if (*sp == trans_values->gray)
  169132. {
  169133. *sp = (png_byte)background->gray;
  169134. }
  169135. }
  169136. }
  169137. break;
  169138. }
  169139. case 16:
  169140. {
  169141. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169142. if (gamma_16 != NULL)
  169143. {
  169144. sp = row;
  169145. for (i = 0; i < row_width; i++, sp += 2)
  169146. {
  169147. png_uint_16 v;
  169148. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169149. if (v == trans_values->gray)
  169150. {
  169151. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169152. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169153. }
  169154. else
  169155. {
  169156. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169157. *sp = (png_byte)((v >> 8) & 0xff);
  169158. *(sp + 1) = (png_byte)(v & 0xff);
  169159. }
  169160. }
  169161. }
  169162. else
  169163. #endif
  169164. {
  169165. sp = row;
  169166. for (i = 0; i < row_width; i++, sp += 2)
  169167. {
  169168. png_uint_16 v;
  169169. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169170. if (v == trans_values->gray)
  169171. {
  169172. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169173. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169174. }
  169175. }
  169176. }
  169177. break;
  169178. }
  169179. }
  169180. break;
  169181. }
  169182. case PNG_COLOR_TYPE_RGB:
  169183. {
  169184. if (row_info->bit_depth == 8)
  169185. {
  169186. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169187. if (gamma_table != NULL)
  169188. {
  169189. sp = row;
  169190. for (i = 0; i < row_width; i++, sp += 3)
  169191. {
  169192. if (*sp == trans_values->red &&
  169193. *(sp + 1) == trans_values->green &&
  169194. *(sp + 2) == trans_values->blue)
  169195. {
  169196. *sp = (png_byte)background->red;
  169197. *(sp + 1) = (png_byte)background->green;
  169198. *(sp + 2) = (png_byte)background->blue;
  169199. }
  169200. else
  169201. {
  169202. *sp = gamma_table[*sp];
  169203. *(sp + 1) = gamma_table[*(sp + 1)];
  169204. *(sp + 2) = gamma_table[*(sp + 2)];
  169205. }
  169206. }
  169207. }
  169208. else
  169209. #endif
  169210. {
  169211. sp = row;
  169212. for (i = 0; i < row_width; i++, sp += 3)
  169213. {
  169214. if (*sp == trans_values->red &&
  169215. *(sp + 1) == trans_values->green &&
  169216. *(sp + 2) == trans_values->blue)
  169217. {
  169218. *sp = (png_byte)background->red;
  169219. *(sp + 1) = (png_byte)background->green;
  169220. *(sp + 2) = (png_byte)background->blue;
  169221. }
  169222. }
  169223. }
  169224. }
  169225. else /* if (row_info->bit_depth == 16) */
  169226. {
  169227. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169228. if (gamma_16 != NULL)
  169229. {
  169230. sp = row;
  169231. for (i = 0; i < row_width; i++, sp += 6)
  169232. {
  169233. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169234. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169235. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169236. if (r == trans_values->red && g == trans_values->green &&
  169237. b == trans_values->blue)
  169238. {
  169239. *sp = (png_byte)((background->red >> 8) & 0xff);
  169240. *(sp + 1) = (png_byte)(background->red & 0xff);
  169241. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169242. *(sp + 3) = (png_byte)(background->green & 0xff);
  169243. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169244. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169245. }
  169246. else
  169247. {
  169248. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169249. *sp = (png_byte)((v >> 8) & 0xff);
  169250. *(sp + 1) = (png_byte)(v & 0xff);
  169251. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169252. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169253. *(sp + 3) = (png_byte)(v & 0xff);
  169254. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169255. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169256. *(sp + 5) = (png_byte)(v & 0xff);
  169257. }
  169258. }
  169259. }
  169260. else
  169261. #endif
  169262. {
  169263. sp = row;
  169264. for (i = 0; i < row_width; i++, sp += 6)
  169265. {
  169266. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169267. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169268. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169269. if (r == trans_values->red && g == trans_values->green &&
  169270. b == trans_values->blue)
  169271. {
  169272. *sp = (png_byte)((background->red >> 8) & 0xff);
  169273. *(sp + 1) = (png_byte)(background->red & 0xff);
  169274. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169275. *(sp + 3) = (png_byte)(background->green & 0xff);
  169276. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169277. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169278. }
  169279. }
  169280. }
  169281. }
  169282. break;
  169283. }
  169284. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169285. {
  169286. if (row_info->bit_depth == 8)
  169287. {
  169288. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169289. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169290. gamma_table != NULL)
  169291. {
  169292. sp = row;
  169293. dp = row;
  169294. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169295. {
  169296. png_uint_16 a = *(sp + 1);
  169297. if (a == 0xff)
  169298. {
  169299. *dp = gamma_table[*sp];
  169300. }
  169301. else if (a == 0)
  169302. {
  169303. *dp = (png_byte)background->gray;
  169304. }
  169305. else
  169306. {
  169307. png_byte v, w;
  169308. v = gamma_to_1[*sp];
  169309. png_composite(w, v, a, background_1->gray);
  169310. *dp = gamma_from_1[w];
  169311. }
  169312. }
  169313. }
  169314. else
  169315. #endif
  169316. {
  169317. sp = row;
  169318. dp = row;
  169319. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169320. {
  169321. png_byte a = *(sp + 1);
  169322. if (a == 0xff)
  169323. {
  169324. *dp = *sp;
  169325. }
  169326. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169327. else if (a == 0)
  169328. {
  169329. *dp = (png_byte)background->gray;
  169330. }
  169331. else
  169332. {
  169333. png_composite(*dp, *sp, a, background_1->gray);
  169334. }
  169335. #else
  169336. *dp = (png_byte)background->gray;
  169337. #endif
  169338. }
  169339. }
  169340. }
  169341. else /* if (png_ptr->bit_depth == 16) */
  169342. {
  169343. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169344. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169345. gamma_16_to_1 != NULL)
  169346. {
  169347. sp = row;
  169348. dp = row;
  169349. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169350. {
  169351. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169352. if (a == (png_uint_16)0xffff)
  169353. {
  169354. png_uint_16 v;
  169355. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169356. *dp = (png_byte)((v >> 8) & 0xff);
  169357. *(dp + 1) = (png_byte)(v & 0xff);
  169358. }
  169359. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169360. else if (a == 0)
  169361. #else
  169362. else
  169363. #endif
  169364. {
  169365. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169366. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169367. }
  169368. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169369. else
  169370. {
  169371. png_uint_16 g, v, w;
  169372. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169373. png_composite_16(v, g, a, background_1->gray);
  169374. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169375. *dp = (png_byte)((w >> 8) & 0xff);
  169376. *(dp + 1) = (png_byte)(w & 0xff);
  169377. }
  169378. #endif
  169379. }
  169380. }
  169381. else
  169382. #endif
  169383. {
  169384. sp = row;
  169385. dp = row;
  169386. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169387. {
  169388. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169389. if (a == (png_uint_16)0xffff)
  169390. {
  169391. png_memcpy(dp, sp, 2);
  169392. }
  169393. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169394. else if (a == 0)
  169395. #else
  169396. else
  169397. #endif
  169398. {
  169399. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169400. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169401. }
  169402. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169403. else
  169404. {
  169405. png_uint_16 g, v;
  169406. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169407. png_composite_16(v, g, a, background_1->gray);
  169408. *dp = (png_byte)((v >> 8) & 0xff);
  169409. *(dp + 1) = (png_byte)(v & 0xff);
  169410. }
  169411. #endif
  169412. }
  169413. }
  169414. }
  169415. break;
  169416. }
  169417. case PNG_COLOR_TYPE_RGB_ALPHA:
  169418. {
  169419. if (row_info->bit_depth == 8)
  169420. {
  169421. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169422. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169423. gamma_table != NULL)
  169424. {
  169425. sp = row;
  169426. dp = row;
  169427. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169428. {
  169429. png_byte a = *(sp + 3);
  169430. if (a == 0xff)
  169431. {
  169432. *dp = gamma_table[*sp];
  169433. *(dp + 1) = gamma_table[*(sp + 1)];
  169434. *(dp + 2) = gamma_table[*(sp + 2)];
  169435. }
  169436. else if (a == 0)
  169437. {
  169438. *dp = (png_byte)background->red;
  169439. *(dp + 1) = (png_byte)background->green;
  169440. *(dp + 2) = (png_byte)background->blue;
  169441. }
  169442. else
  169443. {
  169444. png_byte v, w;
  169445. v = gamma_to_1[*sp];
  169446. png_composite(w, v, a, background_1->red);
  169447. *dp = gamma_from_1[w];
  169448. v = gamma_to_1[*(sp + 1)];
  169449. png_composite(w, v, a, background_1->green);
  169450. *(dp + 1) = gamma_from_1[w];
  169451. v = gamma_to_1[*(sp + 2)];
  169452. png_composite(w, v, a, background_1->blue);
  169453. *(dp + 2) = gamma_from_1[w];
  169454. }
  169455. }
  169456. }
  169457. else
  169458. #endif
  169459. {
  169460. sp = row;
  169461. dp = row;
  169462. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169463. {
  169464. png_byte a = *(sp + 3);
  169465. if (a == 0xff)
  169466. {
  169467. *dp = *sp;
  169468. *(dp + 1) = *(sp + 1);
  169469. *(dp + 2) = *(sp + 2);
  169470. }
  169471. else if (a == 0)
  169472. {
  169473. *dp = (png_byte)background->red;
  169474. *(dp + 1) = (png_byte)background->green;
  169475. *(dp + 2) = (png_byte)background->blue;
  169476. }
  169477. else
  169478. {
  169479. png_composite(*dp, *sp, a, background->red);
  169480. png_composite(*(dp + 1), *(sp + 1), a,
  169481. background->green);
  169482. png_composite(*(dp + 2), *(sp + 2), a,
  169483. background->blue);
  169484. }
  169485. }
  169486. }
  169487. }
  169488. else /* if (row_info->bit_depth == 16) */
  169489. {
  169490. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169491. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169492. gamma_16_to_1 != NULL)
  169493. {
  169494. sp = row;
  169495. dp = row;
  169496. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169497. {
  169498. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169499. << 8) + (png_uint_16)(*(sp + 7)));
  169500. if (a == (png_uint_16)0xffff)
  169501. {
  169502. png_uint_16 v;
  169503. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169504. *dp = (png_byte)((v >> 8) & 0xff);
  169505. *(dp + 1) = (png_byte)(v & 0xff);
  169506. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169507. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169508. *(dp + 3) = (png_byte)(v & 0xff);
  169509. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169510. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169511. *(dp + 5) = (png_byte)(v & 0xff);
  169512. }
  169513. else if (a == 0)
  169514. {
  169515. *dp = (png_byte)((background->red >> 8) & 0xff);
  169516. *(dp + 1) = (png_byte)(background->red & 0xff);
  169517. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169518. *(dp + 3) = (png_byte)(background->green & 0xff);
  169519. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169520. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169521. }
  169522. else
  169523. {
  169524. png_uint_16 v, w, x;
  169525. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169526. png_composite_16(w, v, a, background_1->red);
  169527. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169528. *dp = (png_byte)((x >> 8) & 0xff);
  169529. *(dp + 1) = (png_byte)(x & 0xff);
  169530. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169531. png_composite_16(w, v, a, background_1->green);
  169532. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169533. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169534. *(dp + 3) = (png_byte)(x & 0xff);
  169535. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169536. png_composite_16(w, v, a, background_1->blue);
  169537. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169538. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169539. *(dp + 5) = (png_byte)(x & 0xff);
  169540. }
  169541. }
  169542. }
  169543. else
  169544. #endif
  169545. {
  169546. sp = row;
  169547. dp = row;
  169548. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169549. {
  169550. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169551. << 8) + (png_uint_16)(*(sp + 7)));
  169552. if (a == (png_uint_16)0xffff)
  169553. {
  169554. png_memcpy(dp, sp, 6);
  169555. }
  169556. else if (a == 0)
  169557. {
  169558. *dp = (png_byte)((background->red >> 8) & 0xff);
  169559. *(dp + 1) = (png_byte)(background->red & 0xff);
  169560. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169561. *(dp + 3) = (png_byte)(background->green & 0xff);
  169562. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169563. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169564. }
  169565. else
  169566. {
  169567. png_uint_16 v;
  169568. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169569. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169570. + *(sp + 3));
  169571. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169572. + *(sp + 5));
  169573. png_composite_16(v, r, a, background->red);
  169574. *dp = (png_byte)((v >> 8) & 0xff);
  169575. *(dp + 1) = (png_byte)(v & 0xff);
  169576. png_composite_16(v, g, a, background->green);
  169577. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169578. *(dp + 3) = (png_byte)(v & 0xff);
  169579. png_composite_16(v, b, a, background->blue);
  169580. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169581. *(dp + 5) = (png_byte)(v & 0xff);
  169582. }
  169583. }
  169584. }
  169585. }
  169586. break;
  169587. }
  169588. }
  169589. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169590. {
  169591. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169592. row_info->channels--;
  169593. row_info->pixel_depth = (png_byte)(row_info->channels *
  169594. row_info->bit_depth);
  169595. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169596. }
  169597. }
  169598. }
  169599. #endif
  169600. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169601. void /* PRIVATE */
  169602. png_do_gamma(png_row_infop row_info, png_bytep row,
  169603. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169604. int gamma_shift)
  169605. {
  169606. png_bytep sp;
  169607. png_uint_32 i;
  169608. png_uint_32 row_width=row_info->width;
  169609. png_debug(1, "in png_do_gamma\n");
  169610. if (
  169611. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169612. row != NULL && row_info != NULL &&
  169613. #endif
  169614. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169615. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169616. {
  169617. switch (row_info->color_type)
  169618. {
  169619. case PNG_COLOR_TYPE_RGB:
  169620. {
  169621. if (row_info->bit_depth == 8)
  169622. {
  169623. sp = row;
  169624. for (i = 0; i < row_width; i++)
  169625. {
  169626. *sp = gamma_table[*sp];
  169627. sp++;
  169628. *sp = gamma_table[*sp];
  169629. sp++;
  169630. *sp = gamma_table[*sp];
  169631. sp++;
  169632. }
  169633. }
  169634. else /* if (row_info->bit_depth == 16) */
  169635. {
  169636. sp = row;
  169637. for (i = 0; i < row_width; i++)
  169638. {
  169639. png_uint_16 v;
  169640. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169641. *sp = (png_byte)((v >> 8) & 0xff);
  169642. *(sp + 1) = (png_byte)(v & 0xff);
  169643. sp += 2;
  169644. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169645. *sp = (png_byte)((v >> 8) & 0xff);
  169646. *(sp + 1) = (png_byte)(v & 0xff);
  169647. sp += 2;
  169648. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169649. *sp = (png_byte)((v >> 8) & 0xff);
  169650. *(sp + 1) = (png_byte)(v & 0xff);
  169651. sp += 2;
  169652. }
  169653. }
  169654. break;
  169655. }
  169656. case PNG_COLOR_TYPE_RGB_ALPHA:
  169657. {
  169658. if (row_info->bit_depth == 8)
  169659. {
  169660. sp = row;
  169661. for (i = 0; i < row_width; i++)
  169662. {
  169663. *sp = gamma_table[*sp];
  169664. sp++;
  169665. *sp = gamma_table[*sp];
  169666. sp++;
  169667. *sp = gamma_table[*sp];
  169668. sp++;
  169669. sp++;
  169670. }
  169671. }
  169672. else /* if (row_info->bit_depth == 16) */
  169673. {
  169674. sp = row;
  169675. for (i = 0; i < row_width; i++)
  169676. {
  169677. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169678. *sp = (png_byte)((v >> 8) & 0xff);
  169679. *(sp + 1) = (png_byte)(v & 0xff);
  169680. sp += 2;
  169681. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169682. *sp = (png_byte)((v >> 8) & 0xff);
  169683. *(sp + 1) = (png_byte)(v & 0xff);
  169684. sp += 2;
  169685. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169686. *sp = (png_byte)((v >> 8) & 0xff);
  169687. *(sp + 1) = (png_byte)(v & 0xff);
  169688. sp += 4;
  169689. }
  169690. }
  169691. break;
  169692. }
  169693. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169694. {
  169695. if (row_info->bit_depth == 8)
  169696. {
  169697. sp = row;
  169698. for (i = 0; i < row_width; i++)
  169699. {
  169700. *sp = gamma_table[*sp];
  169701. sp += 2;
  169702. }
  169703. }
  169704. else /* if (row_info->bit_depth == 16) */
  169705. {
  169706. sp = row;
  169707. for (i = 0; i < row_width; i++)
  169708. {
  169709. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169710. *sp = (png_byte)((v >> 8) & 0xff);
  169711. *(sp + 1) = (png_byte)(v & 0xff);
  169712. sp += 4;
  169713. }
  169714. }
  169715. break;
  169716. }
  169717. case PNG_COLOR_TYPE_GRAY:
  169718. {
  169719. if (row_info->bit_depth == 2)
  169720. {
  169721. sp = row;
  169722. for (i = 0; i < row_width; i += 4)
  169723. {
  169724. int a = *sp & 0xc0;
  169725. int b = *sp & 0x30;
  169726. int c = *sp & 0x0c;
  169727. int d = *sp & 0x03;
  169728. *sp = (png_byte)(
  169729. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  169730. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  169731. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  169732. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  169733. sp++;
  169734. }
  169735. }
  169736. if (row_info->bit_depth == 4)
  169737. {
  169738. sp = row;
  169739. for (i = 0; i < row_width; i += 2)
  169740. {
  169741. int msb = *sp & 0xf0;
  169742. int lsb = *sp & 0x0f;
  169743. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  169744. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  169745. sp++;
  169746. }
  169747. }
  169748. else if (row_info->bit_depth == 8)
  169749. {
  169750. sp = row;
  169751. for (i = 0; i < row_width; i++)
  169752. {
  169753. *sp = gamma_table[*sp];
  169754. sp++;
  169755. }
  169756. }
  169757. else if (row_info->bit_depth == 16)
  169758. {
  169759. sp = row;
  169760. for (i = 0; i < row_width; i++)
  169761. {
  169762. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169763. *sp = (png_byte)((v >> 8) & 0xff);
  169764. *(sp + 1) = (png_byte)(v & 0xff);
  169765. sp += 2;
  169766. }
  169767. }
  169768. break;
  169769. }
  169770. }
  169771. }
  169772. }
  169773. #endif
  169774. #if defined(PNG_READ_EXPAND_SUPPORTED)
  169775. void /* PRIVATE */
  169776. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  169777. png_colorp palette, png_bytep trans, int num_trans)
  169778. {
  169779. int shift, value;
  169780. png_bytep sp, dp;
  169781. png_uint_32 i;
  169782. png_uint_32 row_width=row_info->width;
  169783. png_debug(1, "in png_do_expand_palette\n");
  169784. if (
  169785. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169786. row != NULL && row_info != NULL &&
  169787. #endif
  169788. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  169789. {
  169790. if (row_info->bit_depth < 8)
  169791. {
  169792. switch (row_info->bit_depth)
  169793. {
  169794. case 1:
  169795. {
  169796. sp = row + (png_size_t)((row_width - 1) >> 3);
  169797. dp = row + (png_size_t)row_width - 1;
  169798. shift = 7 - (int)((row_width + 7) & 0x07);
  169799. for (i = 0; i < row_width; i++)
  169800. {
  169801. if ((*sp >> shift) & 0x01)
  169802. *dp = 1;
  169803. else
  169804. *dp = 0;
  169805. if (shift == 7)
  169806. {
  169807. shift = 0;
  169808. sp--;
  169809. }
  169810. else
  169811. shift++;
  169812. dp--;
  169813. }
  169814. break;
  169815. }
  169816. case 2:
  169817. {
  169818. sp = row + (png_size_t)((row_width - 1) >> 2);
  169819. dp = row + (png_size_t)row_width - 1;
  169820. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  169821. for (i = 0; i < row_width; i++)
  169822. {
  169823. value = (*sp >> shift) & 0x03;
  169824. *dp = (png_byte)value;
  169825. if (shift == 6)
  169826. {
  169827. shift = 0;
  169828. sp--;
  169829. }
  169830. else
  169831. shift += 2;
  169832. dp--;
  169833. }
  169834. break;
  169835. }
  169836. case 4:
  169837. {
  169838. sp = row + (png_size_t)((row_width - 1) >> 1);
  169839. dp = row + (png_size_t)row_width - 1;
  169840. shift = (int)((row_width & 0x01) << 2);
  169841. for (i = 0; i < row_width; i++)
  169842. {
  169843. value = (*sp >> shift) & 0x0f;
  169844. *dp = (png_byte)value;
  169845. if (shift == 4)
  169846. {
  169847. shift = 0;
  169848. sp--;
  169849. }
  169850. else
  169851. shift += 4;
  169852. dp--;
  169853. }
  169854. break;
  169855. }
  169856. }
  169857. row_info->bit_depth = 8;
  169858. row_info->pixel_depth = 8;
  169859. row_info->rowbytes = row_width;
  169860. }
  169861. switch (row_info->bit_depth)
  169862. {
  169863. case 8:
  169864. {
  169865. if (trans != NULL)
  169866. {
  169867. sp = row + (png_size_t)row_width - 1;
  169868. dp = row + (png_size_t)(row_width << 2) - 1;
  169869. for (i = 0; i < row_width; i++)
  169870. {
  169871. if ((int)(*sp) >= num_trans)
  169872. *dp-- = 0xff;
  169873. else
  169874. *dp-- = trans[*sp];
  169875. *dp-- = palette[*sp].blue;
  169876. *dp-- = palette[*sp].green;
  169877. *dp-- = palette[*sp].red;
  169878. sp--;
  169879. }
  169880. row_info->bit_depth = 8;
  169881. row_info->pixel_depth = 32;
  169882. row_info->rowbytes = row_width * 4;
  169883. row_info->color_type = 6;
  169884. row_info->channels = 4;
  169885. }
  169886. else
  169887. {
  169888. sp = row + (png_size_t)row_width - 1;
  169889. dp = row + (png_size_t)(row_width * 3) - 1;
  169890. for (i = 0; i < row_width; i++)
  169891. {
  169892. *dp-- = palette[*sp].blue;
  169893. *dp-- = palette[*sp].green;
  169894. *dp-- = palette[*sp].red;
  169895. sp--;
  169896. }
  169897. row_info->bit_depth = 8;
  169898. row_info->pixel_depth = 24;
  169899. row_info->rowbytes = row_width * 3;
  169900. row_info->color_type = 2;
  169901. row_info->channels = 3;
  169902. }
  169903. break;
  169904. }
  169905. }
  169906. }
  169907. }
  169908. void /* PRIVATE */
  169909. png_do_expand(png_row_infop row_info, png_bytep row,
  169910. png_color_16p trans_value)
  169911. {
  169912. int shift, value;
  169913. png_bytep sp, dp;
  169914. png_uint_32 i;
  169915. png_uint_32 row_width=row_info->width;
  169916. png_debug(1, "in png_do_expand\n");
  169917. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169918. if (row != NULL && row_info != NULL)
  169919. #endif
  169920. {
  169921. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169922. {
  169923. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  169924. if (row_info->bit_depth < 8)
  169925. {
  169926. switch (row_info->bit_depth)
  169927. {
  169928. case 1:
  169929. {
  169930. gray = (png_uint_16)((gray&0x01)*0xff);
  169931. sp = row + (png_size_t)((row_width - 1) >> 3);
  169932. dp = row + (png_size_t)row_width - 1;
  169933. shift = 7 - (int)((row_width + 7) & 0x07);
  169934. for (i = 0; i < row_width; i++)
  169935. {
  169936. if ((*sp >> shift) & 0x01)
  169937. *dp = 0xff;
  169938. else
  169939. *dp = 0;
  169940. if (shift == 7)
  169941. {
  169942. shift = 0;
  169943. sp--;
  169944. }
  169945. else
  169946. shift++;
  169947. dp--;
  169948. }
  169949. break;
  169950. }
  169951. case 2:
  169952. {
  169953. gray = (png_uint_16)((gray&0x03)*0x55);
  169954. sp = row + (png_size_t)((row_width - 1) >> 2);
  169955. dp = row + (png_size_t)row_width - 1;
  169956. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  169957. for (i = 0; i < row_width; i++)
  169958. {
  169959. value = (*sp >> shift) & 0x03;
  169960. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  169961. (value << 6));
  169962. if (shift == 6)
  169963. {
  169964. shift = 0;
  169965. sp--;
  169966. }
  169967. else
  169968. shift += 2;
  169969. dp--;
  169970. }
  169971. break;
  169972. }
  169973. case 4:
  169974. {
  169975. gray = (png_uint_16)((gray&0x0f)*0x11);
  169976. sp = row + (png_size_t)((row_width - 1) >> 1);
  169977. dp = row + (png_size_t)row_width - 1;
  169978. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  169979. for (i = 0; i < row_width; i++)
  169980. {
  169981. value = (*sp >> shift) & 0x0f;
  169982. *dp = (png_byte)(value | (value << 4));
  169983. if (shift == 4)
  169984. {
  169985. shift = 0;
  169986. sp--;
  169987. }
  169988. else
  169989. shift = 4;
  169990. dp--;
  169991. }
  169992. break;
  169993. }
  169994. }
  169995. row_info->bit_depth = 8;
  169996. row_info->pixel_depth = 8;
  169997. row_info->rowbytes = row_width;
  169998. }
  169999. if (trans_value != NULL)
  170000. {
  170001. if (row_info->bit_depth == 8)
  170002. {
  170003. gray = gray & 0xff;
  170004. sp = row + (png_size_t)row_width - 1;
  170005. dp = row + (png_size_t)(row_width << 1) - 1;
  170006. for (i = 0; i < row_width; i++)
  170007. {
  170008. if (*sp == gray)
  170009. *dp-- = 0;
  170010. else
  170011. *dp-- = 0xff;
  170012. *dp-- = *sp--;
  170013. }
  170014. }
  170015. else if (row_info->bit_depth == 16)
  170016. {
  170017. png_byte gray_high = (gray >> 8) & 0xff;
  170018. png_byte gray_low = gray & 0xff;
  170019. sp = row + row_info->rowbytes - 1;
  170020. dp = row + (row_info->rowbytes << 1) - 1;
  170021. for (i = 0; i < row_width; i++)
  170022. {
  170023. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170024. {
  170025. *dp-- = 0;
  170026. *dp-- = 0;
  170027. }
  170028. else
  170029. {
  170030. *dp-- = 0xff;
  170031. *dp-- = 0xff;
  170032. }
  170033. *dp-- = *sp--;
  170034. *dp-- = *sp--;
  170035. }
  170036. }
  170037. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170038. row_info->channels = 2;
  170039. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170040. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170041. row_width);
  170042. }
  170043. }
  170044. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170045. {
  170046. if (row_info->bit_depth == 8)
  170047. {
  170048. png_byte red = trans_value->red & 0xff;
  170049. png_byte green = trans_value->green & 0xff;
  170050. png_byte blue = trans_value->blue & 0xff;
  170051. sp = row + (png_size_t)row_info->rowbytes - 1;
  170052. dp = row + (png_size_t)(row_width << 2) - 1;
  170053. for (i = 0; i < row_width; i++)
  170054. {
  170055. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170056. *dp-- = 0;
  170057. else
  170058. *dp-- = 0xff;
  170059. *dp-- = *sp--;
  170060. *dp-- = *sp--;
  170061. *dp-- = *sp--;
  170062. }
  170063. }
  170064. else if (row_info->bit_depth == 16)
  170065. {
  170066. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170067. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170068. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170069. png_byte red_low = trans_value->red & 0xff;
  170070. png_byte green_low = trans_value->green & 0xff;
  170071. png_byte blue_low = trans_value->blue & 0xff;
  170072. sp = row + row_info->rowbytes - 1;
  170073. dp = row + (png_size_t)(row_width << 3) - 1;
  170074. for (i = 0; i < row_width; i++)
  170075. {
  170076. if (*(sp - 5) == red_high &&
  170077. *(sp - 4) == red_low &&
  170078. *(sp - 3) == green_high &&
  170079. *(sp - 2) == green_low &&
  170080. *(sp - 1) == blue_high &&
  170081. *(sp ) == blue_low)
  170082. {
  170083. *dp-- = 0;
  170084. *dp-- = 0;
  170085. }
  170086. else
  170087. {
  170088. *dp-- = 0xff;
  170089. *dp-- = 0xff;
  170090. }
  170091. *dp-- = *sp--;
  170092. *dp-- = *sp--;
  170093. *dp-- = *sp--;
  170094. *dp-- = *sp--;
  170095. *dp-- = *sp--;
  170096. *dp-- = *sp--;
  170097. }
  170098. }
  170099. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170100. row_info->channels = 4;
  170101. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170102. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170103. }
  170104. }
  170105. }
  170106. #endif
  170107. #if defined(PNG_READ_DITHER_SUPPORTED)
  170108. void /* PRIVATE */
  170109. png_do_dither(png_row_infop row_info, png_bytep row,
  170110. png_bytep palette_lookup, png_bytep dither_lookup)
  170111. {
  170112. png_bytep sp, dp;
  170113. png_uint_32 i;
  170114. png_uint_32 row_width=row_info->width;
  170115. png_debug(1, "in png_do_dither\n");
  170116. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170117. if (row != NULL && row_info != NULL)
  170118. #endif
  170119. {
  170120. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170121. palette_lookup && row_info->bit_depth == 8)
  170122. {
  170123. int r, g, b, p;
  170124. sp = row;
  170125. dp = row;
  170126. for (i = 0; i < row_width; i++)
  170127. {
  170128. r = *sp++;
  170129. g = *sp++;
  170130. b = *sp++;
  170131. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170132. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170133. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170134. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170135. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170136. (PNG_DITHER_BLUE_BITS)) |
  170137. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170138. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170139. *dp++ = palette_lookup[p];
  170140. }
  170141. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170142. row_info->channels = 1;
  170143. row_info->pixel_depth = row_info->bit_depth;
  170144. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170145. }
  170146. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170147. palette_lookup != NULL && row_info->bit_depth == 8)
  170148. {
  170149. int r, g, b, p;
  170150. sp = row;
  170151. dp = row;
  170152. for (i = 0; i < row_width; i++)
  170153. {
  170154. r = *sp++;
  170155. g = *sp++;
  170156. b = *sp++;
  170157. sp++;
  170158. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170159. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170160. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170161. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170162. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170163. (PNG_DITHER_BLUE_BITS)) |
  170164. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170165. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170166. *dp++ = palette_lookup[p];
  170167. }
  170168. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170169. row_info->channels = 1;
  170170. row_info->pixel_depth = row_info->bit_depth;
  170171. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170172. }
  170173. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170174. dither_lookup && row_info->bit_depth == 8)
  170175. {
  170176. sp = row;
  170177. for (i = 0; i < row_width; i++, sp++)
  170178. {
  170179. *sp = dither_lookup[*sp];
  170180. }
  170181. }
  170182. }
  170183. }
  170184. #endif
  170185. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170186. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170187. static PNG_CONST int png_gamma_shift[] =
  170188. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170189. void /* PRIVATE */
  170190. png_build_gamma_table(png_structp png_ptr)
  170191. {
  170192. png_debug(1, "in png_build_gamma_table\n");
  170193. if (png_ptr->bit_depth <= 8)
  170194. {
  170195. int i;
  170196. double g;
  170197. if (png_ptr->screen_gamma > .000001)
  170198. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170199. else
  170200. g = 1.0;
  170201. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170202. (png_uint_32)256);
  170203. for (i = 0; i < 256; i++)
  170204. {
  170205. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170206. g) * 255.0 + .5);
  170207. }
  170208. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170209. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170210. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170211. {
  170212. g = 1.0 / (png_ptr->gamma);
  170213. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170214. (png_uint_32)256);
  170215. for (i = 0; i < 256; i++)
  170216. {
  170217. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170218. g) * 255.0 + .5);
  170219. }
  170220. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170221. (png_uint_32)256);
  170222. if(png_ptr->screen_gamma > 0.000001)
  170223. g = 1.0 / png_ptr->screen_gamma;
  170224. else
  170225. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170226. for (i = 0; i < 256; i++)
  170227. {
  170228. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170229. g) * 255.0 + .5);
  170230. }
  170231. }
  170232. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170233. }
  170234. else
  170235. {
  170236. double g;
  170237. int i, j, shift, num;
  170238. int sig_bit;
  170239. png_uint_32 ig;
  170240. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170241. {
  170242. sig_bit = (int)png_ptr->sig_bit.red;
  170243. if ((int)png_ptr->sig_bit.green > sig_bit)
  170244. sig_bit = png_ptr->sig_bit.green;
  170245. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170246. sig_bit = png_ptr->sig_bit.blue;
  170247. }
  170248. else
  170249. {
  170250. sig_bit = (int)png_ptr->sig_bit.gray;
  170251. }
  170252. if (sig_bit > 0)
  170253. shift = 16 - sig_bit;
  170254. else
  170255. shift = 0;
  170256. if (png_ptr->transformations & PNG_16_TO_8)
  170257. {
  170258. if (shift < (16 - PNG_MAX_GAMMA_8))
  170259. shift = (16 - PNG_MAX_GAMMA_8);
  170260. }
  170261. if (shift > 8)
  170262. shift = 8;
  170263. if (shift < 0)
  170264. shift = 0;
  170265. png_ptr->gamma_shift = (png_byte)shift;
  170266. num = (1 << (8 - shift));
  170267. if (png_ptr->screen_gamma > .000001)
  170268. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170269. else
  170270. g = 1.0;
  170271. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170272. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170273. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170274. {
  170275. double fin, fout;
  170276. png_uint_32 last, max;
  170277. for (i = 0; i < num; i++)
  170278. {
  170279. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170280. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170281. }
  170282. g = 1.0 / g;
  170283. last = 0;
  170284. for (i = 0; i < 256; i++)
  170285. {
  170286. fout = ((double)i + 0.5) / 256.0;
  170287. fin = pow(fout, g);
  170288. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170289. while (last <= max)
  170290. {
  170291. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170292. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170293. (png_uint_16)i | ((png_uint_16)i << 8));
  170294. last++;
  170295. }
  170296. }
  170297. while (last < ((png_uint_32)num << 8))
  170298. {
  170299. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170300. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170301. last++;
  170302. }
  170303. }
  170304. else
  170305. {
  170306. for (i = 0; i < num; i++)
  170307. {
  170308. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170309. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170310. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170311. for (j = 0; j < 256; j++)
  170312. {
  170313. png_ptr->gamma_16_table[i][j] =
  170314. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170315. 65535.0, g) * 65535.0 + .5);
  170316. }
  170317. }
  170318. }
  170319. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170320. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170321. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170322. {
  170323. g = 1.0 / (png_ptr->gamma);
  170324. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170325. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170326. for (i = 0; i < num; i++)
  170327. {
  170328. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170329. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170330. ig = (((png_uint_32)i *
  170331. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170332. for (j = 0; j < 256; j++)
  170333. {
  170334. png_ptr->gamma_16_to_1[i][j] =
  170335. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170336. 65535.0, g) * 65535.0 + .5);
  170337. }
  170338. }
  170339. if(png_ptr->screen_gamma > 0.000001)
  170340. g = 1.0 / png_ptr->screen_gamma;
  170341. else
  170342. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170343. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170344. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170345. for (i = 0; i < num; i++)
  170346. {
  170347. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170348. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170349. ig = (((png_uint_32)i *
  170350. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170351. for (j = 0; j < 256; j++)
  170352. {
  170353. png_ptr->gamma_16_from_1[i][j] =
  170354. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170355. 65535.0, g) * 65535.0 + .5);
  170356. }
  170357. }
  170358. }
  170359. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170360. }
  170361. }
  170362. #endif
  170363. #endif
  170364. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170365. void /* PRIVATE */
  170366. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170367. {
  170368. png_debug(1, "in png_do_read_intrapixel\n");
  170369. if (
  170370. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170371. row != NULL && row_info != NULL &&
  170372. #endif
  170373. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170374. {
  170375. int bytes_per_pixel;
  170376. png_uint_32 row_width = row_info->width;
  170377. if (row_info->bit_depth == 8)
  170378. {
  170379. png_bytep rp;
  170380. png_uint_32 i;
  170381. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170382. bytes_per_pixel = 3;
  170383. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170384. bytes_per_pixel = 4;
  170385. else
  170386. return;
  170387. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170388. {
  170389. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170390. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170391. }
  170392. }
  170393. else if (row_info->bit_depth == 16)
  170394. {
  170395. png_bytep rp;
  170396. png_uint_32 i;
  170397. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170398. bytes_per_pixel = 6;
  170399. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170400. bytes_per_pixel = 8;
  170401. else
  170402. return;
  170403. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170404. {
  170405. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170406. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170407. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170408. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170409. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170410. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170411. *(rp+1) = (png_byte)(red & 0xff);
  170412. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170413. *(rp+5) = (png_byte)(blue & 0xff);
  170414. }
  170415. }
  170416. }
  170417. }
  170418. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170419. #endif /* PNG_READ_SUPPORTED */
  170420. /*** End of inlined file: pngrtran.c ***/
  170421. /*** Start of inlined file: pngrutil.c ***/
  170422. #define PNG_INTERNAL
  170423. #if defined(PNG_READ_SUPPORTED)
  170424. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170425. # define WIN32_WCE_OLD
  170426. #endif
  170427. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170428. # if defined(WIN32_WCE_OLD)
  170429. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170430. {
  170431. double result = 0;
  170432. int len;
  170433. wchar_t *str, *end;
  170434. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170435. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170436. if ( NULL != str )
  170437. {
  170438. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170439. result = wcstod(str, &end);
  170440. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170441. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170442. png_free(png_ptr, str);
  170443. }
  170444. return result;
  170445. }
  170446. # else
  170447. # define png_strtod(p,a,b) strtod(a,b)
  170448. # endif
  170449. #endif
  170450. png_uint_32 PNGAPI
  170451. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170452. {
  170453. png_uint_32 i = png_get_uint_32(buf);
  170454. if (i > PNG_UINT_31_MAX)
  170455. png_error(png_ptr, "PNG unsigned integer out of range.");
  170456. return (i);
  170457. }
  170458. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170459. png_uint_32 PNGAPI
  170460. png_get_uint_32(png_bytep buf)
  170461. {
  170462. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170463. ((png_uint_32)(*(buf + 1)) << 16) +
  170464. ((png_uint_32)(*(buf + 2)) << 8) +
  170465. (png_uint_32)(*(buf + 3));
  170466. return (i);
  170467. }
  170468. png_int_32 PNGAPI
  170469. png_get_int_32(png_bytep buf)
  170470. {
  170471. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170472. ((png_int_32)(*(buf + 1)) << 16) +
  170473. ((png_int_32)(*(buf + 2)) << 8) +
  170474. (png_int_32)(*(buf + 3));
  170475. return (i);
  170476. }
  170477. png_uint_16 PNGAPI
  170478. png_get_uint_16(png_bytep buf)
  170479. {
  170480. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170481. (png_uint_16)(*(buf + 1)));
  170482. return (i);
  170483. }
  170484. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170485. void /* PRIVATE */
  170486. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170487. {
  170488. if(png_ptr == NULL) return;
  170489. png_read_data(png_ptr, buf, length);
  170490. png_calculate_crc(png_ptr, buf, length);
  170491. }
  170492. int /* PRIVATE */
  170493. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170494. {
  170495. png_size_t i;
  170496. png_size_t istop = png_ptr->zbuf_size;
  170497. for (i = (png_size_t)skip; i > istop; i -= istop)
  170498. {
  170499. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170500. }
  170501. if (i)
  170502. {
  170503. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170504. }
  170505. if (png_crc_error(png_ptr))
  170506. {
  170507. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170508. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170509. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170510. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170511. {
  170512. png_chunk_warning(png_ptr, "CRC error");
  170513. }
  170514. else
  170515. {
  170516. png_chunk_error(png_ptr, "CRC error");
  170517. }
  170518. return (1);
  170519. }
  170520. return (0);
  170521. }
  170522. int /* PRIVATE */
  170523. png_crc_error(png_structp png_ptr)
  170524. {
  170525. png_byte crc_bytes[4];
  170526. png_uint_32 crc;
  170527. int need_crc = 1;
  170528. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170529. {
  170530. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170531. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170532. need_crc = 0;
  170533. }
  170534. else /* critical */
  170535. {
  170536. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170537. need_crc = 0;
  170538. }
  170539. png_read_data(png_ptr, crc_bytes, 4);
  170540. if (need_crc)
  170541. {
  170542. crc = png_get_uint_32(crc_bytes);
  170543. return ((int)(crc != png_ptr->crc));
  170544. }
  170545. else
  170546. return (0);
  170547. }
  170548. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170549. defined(PNG_READ_iCCP_SUPPORTED)
  170550. png_charp /* PRIVATE */
  170551. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170552. png_charp chunkdata, png_size_t chunklength,
  170553. png_size_t prefix_size, png_size_t *newlength)
  170554. {
  170555. static PNG_CONST char msg[] = "Error decoding compressed text";
  170556. png_charp text;
  170557. png_size_t text_size;
  170558. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170559. {
  170560. int ret = Z_OK;
  170561. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170562. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170563. png_ptr->zstream.next_out = png_ptr->zbuf;
  170564. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170565. text_size = 0;
  170566. text = NULL;
  170567. while (png_ptr->zstream.avail_in)
  170568. {
  170569. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170570. if (ret != Z_OK && ret != Z_STREAM_END)
  170571. {
  170572. if (png_ptr->zstream.msg != NULL)
  170573. png_warning(png_ptr, png_ptr->zstream.msg);
  170574. else
  170575. png_warning(png_ptr, msg);
  170576. inflateReset(&png_ptr->zstream);
  170577. png_ptr->zstream.avail_in = 0;
  170578. if (text == NULL)
  170579. {
  170580. text_size = prefix_size + png_sizeof(msg) + 1;
  170581. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170582. if (text == NULL)
  170583. {
  170584. png_free(png_ptr,chunkdata);
  170585. png_error(png_ptr,"Not enough memory to decompress chunk");
  170586. }
  170587. png_memcpy(text, chunkdata, prefix_size);
  170588. }
  170589. text[text_size - 1] = 0x00;
  170590. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170591. text_size = png_sizeof(msg) > text_size ? text_size :
  170592. png_sizeof(msg);
  170593. png_memcpy(text + prefix_size, msg, text_size + 1);
  170594. break;
  170595. }
  170596. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170597. {
  170598. if (text == NULL)
  170599. {
  170600. text_size = prefix_size +
  170601. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170602. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170603. if (text == NULL)
  170604. {
  170605. png_free(png_ptr,chunkdata);
  170606. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170607. }
  170608. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170609. text_size - prefix_size);
  170610. png_memcpy(text, chunkdata, prefix_size);
  170611. *(text + text_size) = 0x00;
  170612. }
  170613. else
  170614. {
  170615. png_charp tmp;
  170616. tmp = text;
  170617. text = (png_charp)png_malloc_warn(png_ptr,
  170618. (png_uint_32)(text_size +
  170619. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170620. if (text == NULL)
  170621. {
  170622. png_free(png_ptr, tmp);
  170623. png_free(png_ptr, chunkdata);
  170624. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170625. }
  170626. png_memcpy(text, tmp, text_size);
  170627. png_free(png_ptr, tmp);
  170628. png_memcpy(text + text_size, png_ptr->zbuf,
  170629. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170630. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170631. *(text + text_size) = 0x00;
  170632. }
  170633. if (ret == Z_STREAM_END)
  170634. break;
  170635. else
  170636. {
  170637. png_ptr->zstream.next_out = png_ptr->zbuf;
  170638. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170639. }
  170640. }
  170641. }
  170642. if (ret != Z_STREAM_END)
  170643. {
  170644. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170645. char umsg[52];
  170646. if (ret == Z_BUF_ERROR)
  170647. png_snprintf(umsg, 52,
  170648. "Buffer error in compressed datastream in %s chunk",
  170649. png_ptr->chunk_name);
  170650. else if (ret == Z_DATA_ERROR)
  170651. png_snprintf(umsg, 52,
  170652. "Data error in compressed datastream in %s chunk",
  170653. png_ptr->chunk_name);
  170654. else
  170655. png_snprintf(umsg, 52,
  170656. "Incomplete compressed datastream in %s chunk",
  170657. png_ptr->chunk_name);
  170658. png_warning(png_ptr, umsg);
  170659. #else
  170660. png_warning(png_ptr,
  170661. "Incomplete compressed datastream in chunk other than IDAT");
  170662. #endif
  170663. text_size=prefix_size;
  170664. if (text == NULL)
  170665. {
  170666. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170667. if (text == NULL)
  170668. {
  170669. png_free(png_ptr, chunkdata);
  170670. png_error(png_ptr,"Not enough memory for text.");
  170671. }
  170672. png_memcpy(text, chunkdata, prefix_size);
  170673. }
  170674. *(text + text_size) = 0x00;
  170675. }
  170676. inflateReset(&png_ptr->zstream);
  170677. png_ptr->zstream.avail_in = 0;
  170678. png_free(png_ptr, chunkdata);
  170679. chunkdata = text;
  170680. *newlength=text_size;
  170681. }
  170682. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170683. {
  170684. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170685. char umsg[50];
  170686. png_snprintf(umsg, 50,
  170687. "Unknown zTXt compression type %d", comp_type);
  170688. png_warning(png_ptr, umsg);
  170689. #else
  170690. png_warning(png_ptr, "Unknown zTXt compression type");
  170691. #endif
  170692. *(chunkdata + prefix_size) = 0x00;
  170693. *newlength=prefix_size;
  170694. }
  170695. return chunkdata;
  170696. }
  170697. #endif
  170698. void /* PRIVATE */
  170699. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170700. {
  170701. png_byte buf[13];
  170702. png_uint_32 width, height;
  170703. int bit_depth, color_type, compression_type, filter_type;
  170704. int interlace_type;
  170705. png_debug(1, "in png_handle_IHDR\n");
  170706. if (png_ptr->mode & PNG_HAVE_IHDR)
  170707. png_error(png_ptr, "Out of place IHDR");
  170708. if (length != 13)
  170709. png_error(png_ptr, "Invalid IHDR chunk");
  170710. png_ptr->mode |= PNG_HAVE_IHDR;
  170711. png_crc_read(png_ptr, buf, 13);
  170712. png_crc_finish(png_ptr, 0);
  170713. width = png_get_uint_31(png_ptr, buf);
  170714. height = png_get_uint_31(png_ptr, buf + 4);
  170715. bit_depth = buf[8];
  170716. color_type = buf[9];
  170717. compression_type = buf[10];
  170718. filter_type = buf[11];
  170719. interlace_type = buf[12];
  170720. png_ptr->width = width;
  170721. png_ptr->height = height;
  170722. png_ptr->bit_depth = (png_byte)bit_depth;
  170723. png_ptr->interlaced = (png_byte)interlace_type;
  170724. png_ptr->color_type = (png_byte)color_type;
  170725. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170726. png_ptr->filter_type = (png_byte)filter_type;
  170727. #endif
  170728. png_ptr->compression_type = (png_byte)compression_type;
  170729. switch (png_ptr->color_type)
  170730. {
  170731. case PNG_COLOR_TYPE_GRAY:
  170732. case PNG_COLOR_TYPE_PALETTE:
  170733. png_ptr->channels = 1;
  170734. break;
  170735. case PNG_COLOR_TYPE_RGB:
  170736. png_ptr->channels = 3;
  170737. break;
  170738. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170739. png_ptr->channels = 2;
  170740. break;
  170741. case PNG_COLOR_TYPE_RGB_ALPHA:
  170742. png_ptr->channels = 4;
  170743. break;
  170744. }
  170745. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  170746. png_ptr->channels);
  170747. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  170748. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  170749. png_debug1(3,"channels = %d\n", png_ptr->channels);
  170750. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  170751. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  170752. color_type, interlace_type, compression_type, filter_type);
  170753. }
  170754. void /* PRIVATE */
  170755. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170756. {
  170757. png_color palette[PNG_MAX_PALETTE_LENGTH];
  170758. int num, i;
  170759. #ifndef PNG_NO_POINTER_INDEXING
  170760. png_colorp pal_ptr;
  170761. #endif
  170762. png_debug(1, "in png_handle_PLTE\n");
  170763. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170764. png_error(png_ptr, "Missing IHDR before PLTE");
  170765. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170766. {
  170767. png_warning(png_ptr, "Invalid PLTE after IDAT");
  170768. png_crc_finish(png_ptr, length);
  170769. return;
  170770. }
  170771. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170772. png_error(png_ptr, "Duplicate PLTE chunk");
  170773. png_ptr->mode |= PNG_HAVE_PLTE;
  170774. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  170775. {
  170776. png_warning(png_ptr,
  170777. "Ignoring PLTE chunk in grayscale PNG");
  170778. png_crc_finish(png_ptr, length);
  170779. return;
  170780. }
  170781. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170782. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170783. {
  170784. png_crc_finish(png_ptr, length);
  170785. return;
  170786. }
  170787. #endif
  170788. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  170789. {
  170790. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170791. {
  170792. png_warning(png_ptr, "Invalid palette chunk");
  170793. png_crc_finish(png_ptr, length);
  170794. return;
  170795. }
  170796. else
  170797. {
  170798. png_error(png_ptr, "Invalid palette chunk");
  170799. }
  170800. }
  170801. num = (int)length / 3;
  170802. #ifndef PNG_NO_POINTER_INDEXING
  170803. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  170804. {
  170805. png_byte buf[3];
  170806. png_crc_read(png_ptr, buf, 3);
  170807. pal_ptr->red = buf[0];
  170808. pal_ptr->green = buf[1];
  170809. pal_ptr->blue = buf[2];
  170810. }
  170811. #else
  170812. for (i = 0; i < num; i++)
  170813. {
  170814. png_byte buf[3];
  170815. png_crc_read(png_ptr, buf, 3);
  170816. palette[i].red = buf[0];
  170817. palette[i].green = buf[1];
  170818. palette[i].blue = buf[2];
  170819. }
  170820. #endif
  170821. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170822. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  170823. #endif
  170824. {
  170825. png_crc_finish(png_ptr, 0);
  170826. }
  170827. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170828. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  170829. {
  170830. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  170831. {
  170832. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  170833. {
  170834. png_chunk_error(png_ptr, "CRC error");
  170835. }
  170836. else
  170837. {
  170838. png_chunk_warning(png_ptr, "CRC error");
  170839. return;
  170840. }
  170841. }
  170842. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170843. {
  170844. png_chunk_warning(png_ptr, "CRC error");
  170845. }
  170846. }
  170847. #endif
  170848. png_set_PLTE(png_ptr, info_ptr, palette, num);
  170849. #if defined(PNG_READ_tRNS_SUPPORTED)
  170850. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  170851. {
  170852. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  170853. {
  170854. if (png_ptr->num_trans > (png_uint_16)num)
  170855. {
  170856. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  170857. png_ptr->num_trans = (png_uint_16)num;
  170858. }
  170859. if (info_ptr->num_trans > (png_uint_16)num)
  170860. {
  170861. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  170862. info_ptr->num_trans = (png_uint_16)num;
  170863. }
  170864. }
  170865. }
  170866. #endif
  170867. }
  170868. void /* PRIVATE */
  170869. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170870. {
  170871. png_debug(1, "in png_handle_IEND\n");
  170872. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  170873. {
  170874. png_error(png_ptr, "No image in file");
  170875. }
  170876. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  170877. if (length != 0)
  170878. {
  170879. png_warning(png_ptr, "Incorrect IEND chunk length");
  170880. }
  170881. png_crc_finish(png_ptr, length);
  170882. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  170883. }
  170884. #if defined(PNG_READ_gAMA_SUPPORTED)
  170885. void /* PRIVATE */
  170886. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170887. {
  170888. png_fixed_point igamma;
  170889. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170890. float file_gamma;
  170891. #endif
  170892. png_byte buf[4];
  170893. png_debug(1, "in png_handle_gAMA\n");
  170894. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170895. png_error(png_ptr, "Missing IHDR before gAMA");
  170896. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170897. {
  170898. png_warning(png_ptr, "Invalid gAMA after IDAT");
  170899. png_crc_finish(png_ptr, length);
  170900. return;
  170901. }
  170902. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170903. png_warning(png_ptr, "Out of place gAMA chunk");
  170904. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  170905. #if defined(PNG_READ_sRGB_SUPPORTED)
  170906. && !(info_ptr->valid & PNG_INFO_sRGB)
  170907. #endif
  170908. )
  170909. {
  170910. png_warning(png_ptr, "Duplicate gAMA chunk");
  170911. png_crc_finish(png_ptr, length);
  170912. return;
  170913. }
  170914. if (length != 4)
  170915. {
  170916. png_warning(png_ptr, "Incorrect gAMA chunk length");
  170917. png_crc_finish(png_ptr, length);
  170918. return;
  170919. }
  170920. png_crc_read(png_ptr, buf, 4);
  170921. if (png_crc_finish(png_ptr, 0))
  170922. return;
  170923. igamma = (png_fixed_point)png_get_uint_32(buf);
  170924. if (igamma == 0)
  170925. {
  170926. png_warning(png_ptr,
  170927. "Ignoring gAMA chunk with gamma=0");
  170928. return;
  170929. }
  170930. #if defined(PNG_READ_sRGB_SUPPORTED)
  170931. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  170932. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  170933. {
  170934. png_warning(png_ptr,
  170935. "Ignoring incorrect gAMA value when sRGB is also present");
  170936. #ifndef PNG_NO_CONSOLE_IO
  170937. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  170938. #endif
  170939. return;
  170940. }
  170941. #endif /* PNG_READ_sRGB_SUPPORTED */
  170942. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170943. file_gamma = (float)igamma / (float)100000.0;
  170944. # ifdef PNG_READ_GAMMA_SUPPORTED
  170945. png_ptr->gamma = file_gamma;
  170946. # endif
  170947. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  170948. #endif
  170949. #ifdef PNG_FIXED_POINT_SUPPORTED
  170950. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  170951. #endif
  170952. }
  170953. #endif
  170954. #if defined(PNG_READ_sBIT_SUPPORTED)
  170955. void /* PRIVATE */
  170956. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170957. {
  170958. png_size_t truelen;
  170959. png_byte buf[4];
  170960. png_debug(1, "in png_handle_sBIT\n");
  170961. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  170962. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170963. png_error(png_ptr, "Missing IHDR before sBIT");
  170964. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170965. {
  170966. png_warning(png_ptr, "Invalid sBIT after IDAT");
  170967. png_crc_finish(png_ptr, length);
  170968. return;
  170969. }
  170970. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170971. {
  170972. png_warning(png_ptr, "Out of place sBIT chunk");
  170973. }
  170974. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  170975. {
  170976. png_warning(png_ptr, "Duplicate sBIT chunk");
  170977. png_crc_finish(png_ptr, length);
  170978. return;
  170979. }
  170980. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  170981. truelen = 3;
  170982. else
  170983. truelen = (png_size_t)png_ptr->channels;
  170984. if (length != truelen || length > 4)
  170985. {
  170986. png_warning(png_ptr, "Incorrect sBIT chunk length");
  170987. png_crc_finish(png_ptr, length);
  170988. return;
  170989. }
  170990. png_crc_read(png_ptr, buf, truelen);
  170991. if (png_crc_finish(png_ptr, 0))
  170992. return;
  170993. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170994. {
  170995. png_ptr->sig_bit.red = buf[0];
  170996. png_ptr->sig_bit.green = buf[1];
  170997. png_ptr->sig_bit.blue = buf[2];
  170998. png_ptr->sig_bit.alpha = buf[3];
  170999. }
  171000. else
  171001. {
  171002. png_ptr->sig_bit.gray = buf[0];
  171003. png_ptr->sig_bit.red = buf[0];
  171004. png_ptr->sig_bit.green = buf[0];
  171005. png_ptr->sig_bit.blue = buf[0];
  171006. png_ptr->sig_bit.alpha = buf[1];
  171007. }
  171008. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171009. }
  171010. #endif
  171011. #if defined(PNG_READ_cHRM_SUPPORTED)
  171012. void /* PRIVATE */
  171013. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171014. {
  171015. png_byte buf[4];
  171016. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171017. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171018. #endif
  171019. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171020. int_y_green, int_x_blue, int_y_blue;
  171021. png_uint_32 uint_x, uint_y;
  171022. png_debug(1, "in png_handle_cHRM\n");
  171023. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171024. png_error(png_ptr, "Missing IHDR before cHRM");
  171025. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171026. {
  171027. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171028. png_crc_finish(png_ptr, length);
  171029. return;
  171030. }
  171031. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171032. png_warning(png_ptr, "Missing PLTE before cHRM");
  171033. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171034. #if defined(PNG_READ_sRGB_SUPPORTED)
  171035. && !(info_ptr->valid & PNG_INFO_sRGB)
  171036. #endif
  171037. )
  171038. {
  171039. png_warning(png_ptr, "Duplicate cHRM chunk");
  171040. png_crc_finish(png_ptr, length);
  171041. return;
  171042. }
  171043. if (length != 32)
  171044. {
  171045. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171046. png_crc_finish(png_ptr, length);
  171047. return;
  171048. }
  171049. png_crc_read(png_ptr, buf, 4);
  171050. uint_x = png_get_uint_32(buf);
  171051. png_crc_read(png_ptr, buf, 4);
  171052. uint_y = png_get_uint_32(buf);
  171053. if (uint_x > 80000L || uint_y > 80000L ||
  171054. uint_x + uint_y > 100000L)
  171055. {
  171056. png_warning(png_ptr, "Invalid cHRM white point");
  171057. png_crc_finish(png_ptr, 24);
  171058. return;
  171059. }
  171060. int_x_white = (png_fixed_point)uint_x;
  171061. int_y_white = (png_fixed_point)uint_y;
  171062. png_crc_read(png_ptr, buf, 4);
  171063. uint_x = png_get_uint_32(buf);
  171064. png_crc_read(png_ptr, buf, 4);
  171065. uint_y = png_get_uint_32(buf);
  171066. if (uint_x + uint_y > 100000L)
  171067. {
  171068. png_warning(png_ptr, "Invalid cHRM red point");
  171069. png_crc_finish(png_ptr, 16);
  171070. return;
  171071. }
  171072. int_x_red = (png_fixed_point)uint_x;
  171073. int_y_red = (png_fixed_point)uint_y;
  171074. png_crc_read(png_ptr, buf, 4);
  171075. uint_x = png_get_uint_32(buf);
  171076. png_crc_read(png_ptr, buf, 4);
  171077. uint_y = png_get_uint_32(buf);
  171078. if (uint_x + uint_y > 100000L)
  171079. {
  171080. png_warning(png_ptr, "Invalid cHRM green point");
  171081. png_crc_finish(png_ptr, 8);
  171082. return;
  171083. }
  171084. int_x_green = (png_fixed_point)uint_x;
  171085. int_y_green = (png_fixed_point)uint_y;
  171086. png_crc_read(png_ptr, buf, 4);
  171087. uint_x = png_get_uint_32(buf);
  171088. png_crc_read(png_ptr, buf, 4);
  171089. uint_y = png_get_uint_32(buf);
  171090. if (uint_x + uint_y > 100000L)
  171091. {
  171092. png_warning(png_ptr, "Invalid cHRM blue point");
  171093. png_crc_finish(png_ptr, 0);
  171094. return;
  171095. }
  171096. int_x_blue = (png_fixed_point)uint_x;
  171097. int_y_blue = (png_fixed_point)uint_y;
  171098. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171099. white_x = (float)int_x_white / (float)100000.0;
  171100. white_y = (float)int_y_white / (float)100000.0;
  171101. red_x = (float)int_x_red / (float)100000.0;
  171102. red_y = (float)int_y_red / (float)100000.0;
  171103. green_x = (float)int_x_green / (float)100000.0;
  171104. green_y = (float)int_y_green / (float)100000.0;
  171105. blue_x = (float)int_x_blue / (float)100000.0;
  171106. blue_y = (float)int_y_blue / (float)100000.0;
  171107. #endif
  171108. #if defined(PNG_READ_sRGB_SUPPORTED)
  171109. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171110. {
  171111. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171112. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171113. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171114. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171115. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171116. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171117. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171118. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171119. {
  171120. png_warning(png_ptr,
  171121. "Ignoring incorrect cHRM value when sRGB is also present");
  171122. #ifndef PNG_NO_CONSOLE_IO
  171123. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171124. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171125. white_x, white_y, red_x, red_y);
  171126. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171127. green_x, green_y, blue_x, blue_y);
  171128. #else
  171129. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171130. int_x_white, int_y_white, int_x_red, int_y_red);
  171131. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171132. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171133. #endif
  171134. #endif /* PNG_NO_CONSOLE_IO */
  171135. }
  171136. png_crc_finish(png_ptr, 0);
  171137. return;
  171138. }
  171139. #endif /* PNG_READ_sRGB_SUPPORTED */
  171140. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171141. png_set_cHRM(png_ptr, info_ptr,
  171142. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171143. #endif
  171144. #ifdef PNG_FIXED_POINT_SUPPORTED
  171145. png_set_cHRM_fixed(png_ptr, info_ptr,
  171146. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171147. int_y_green, int_x_blue, int_y_blue);
  171148. #endif
  171149. if (png_crc_finish(png_ptr, 0))
  171150. return;
  171151. }
  171152. #endif
  171153. #if defined(PNG_READ_sRGB_SUPPORTED)
  171154. void /* PRIVATE */
  171155. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171156. {
  171157. int intent;
  171158. png_byte buf[1];
  171159. png_debug(1, "in png_handle_sRGB\n");
  171160. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171161. png_error(png_ptr, "Missing IHDR before sRGB");
  171162. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171163. {
  171164. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171165. png_crc_finish(png_ptr, length);
  171166. return;
  171167. }
  171168. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171169. png_warning(png_ptr, "Out of place sRGB chunk");
  171170. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171171. {
  171172. png_warning(png_ptr, "Duplicate sRGB chunk");
  171173. png_crc_finish(png_ptr, length);
  171174. return;
  171175. }
  171176. if (length != 1)
  171177. {
  171178. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171179. png_crc_finish(png_ptr, length);
  171180. return;
  171181. }
  171182. png_crc_read(png_ptr, buf, 1);
  171183. if (png_crc_finish(png_ptr, 0))
  171184. return;
  171185. intent = buf[0];
  171186. if (intent >= PNG_sRGB_INTENT_LAST)
  171187. {
  171188. png_warning(png_ptr, "Unknown sRGB intent");
  171189. return;
  171190. }
  171191. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171192. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171193. {
  171194. png_fixed_point igamma;
  171195. #ifdef PNG_FIXED_POINT_SUPPORTED
  171196. igamma=info_ptr->int_gamma;
  171197. #else
  171198. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171199. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171200. # endif
  171201. #endif
  171202. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171203. {
  171204. png_warning(png_ptr,
  171205. "Ignoring incorrect gAMA value when sRGB is also present");
  171206. #ifndef PNG_NO_CONSOLE_IO
  171207. # ifdef PNG_FIXED_POINT_SUPPORTED
  171208. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171209. # else
  171210. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171211. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171212. # endif
  171213. # endif
  171214. #endif
  171215. }
  171216. }
  171217. #endif /* PNG_READ_gAMA_SUPPORTED */
  171218. #ifdef PNG_READ_cHRM_SUPPORTED
  171219. #ifdef PNG_FIXED_POINT_SUPPORTED
  171220. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171221. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171222. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171223. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171224. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171225. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171226. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171227. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171228. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171229. {
  171230. png_warning(png_ptr,
  171231. "Ignoring incorrect cHRM value when sRGB is also present");
  171232. }
  171233. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171234. #endif /* PNG_READ_cHRM_SUPPORTED */
  171235. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171236. }
  171237. #endif /* PNG_READ_sRGB_SUPPORTED */
  171238. #if defined(PNG_READ_iCCP_SUPPORTED)
  171239. void /* PRIVATE */
  171240. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171241. {
  171242. png_charp chunkdata;
  171243. png_byte compression_type;
  171244. png_bytep pC;
  171245. png_charp profile;
  171246. png_uint_32 skip = 0;
  171247. png_uint_32 profile_size, profile_length;
  171248. png_size_t slength, prefix_length, data_length;
  171249. png_debug(1, "in png_handle_iCCP\n");
  171250. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171251. png_error(png_ptr, "Missing IHDR before iCCP");
  171252. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171253. {
  171254. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171255. png_crc_finish(png_ptr, length);
  171256. return;
  171257. }
  171258. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171259. png_warning(png_ptr, "Out of place iCCP chunk");
  171260. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171261. {
  171262. png_warning(png_ptr, "Duplicate iCCP chunk");
  171263. png_crc_finish(png_ptr, length);
  171264. return;
  171265. }
  171266. #ifdef PNG_MAX_MALLOC_64K
  171267. if (length > (png_uint_32)65535L)
  171268. {
  171269. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171270. skip = length - (png_uint_32)65535L;
  171271. length = (png_uint_32)65535L;
  171272. }
  171273. #endif
  171274. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171275. slength = (png_size_t)length;
  171276. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171277. if (png_crc_finish(png_ptr, skip))
  171278. {
  171279. png_free(png_ptr, chunkdata);
  171280. return;
  171281. }
  171282. chunkdata[slength] = 0x00;
  171283. for (profile = chunkdata; *profile; profile++)
  171284. ;
  171285. ++profile;
  171286. if ( profile >= chunkdata + slength - 1)
  171287. {
  171288. png_free(png_ptr, chunkdata);
  171289. png_warning(png_ptr, "Malformed iCCP chunk");
  171290. return;
  171291. }
  171292. compression_type = *profile++;
  171293. if (compression_type)
  171294. {
  171295. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171296. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171297. wrote nonzero) */
  171298. }
  171299. prefix_length = profile - chunkdata;
  171300. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171301. slength, prefix_length, &data_length);
  171302. profile_length = data_length - prefix_length;
  171303. if ( prefix_length > data_length || profile_length < 4)
  171304. {
  171305. png_free(png_ptr, chunkdata);
  171306. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171307. return;
  171308. }
  171309. pC = (png_bytep)(chunkdata+prefix_length);
  171310. profile_size = ((*(pC ))<<24) |
  171311. ((*(pC+1))<<16) |
  171312. ((*(pC+2))<< 8) |
  171313. ((*(pC+3)) );
  171314. if(profile_size < profile_length)
  171315. profile_length = profile_size;
  171316. if(profile_size > profile_length)
  171317. {
  171318. png_free(png_ptr, chunkdata);
  171319. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171320. return;
  171321. }
  171322. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171323. chunkdata + prefix_length, profile_length);
  171324. png_free(png_ptr, chunkdata);
  171325. }
  171326. #endif /* PNG_READ_iCCP_SUPPORTED */
  171327. #if defined(PNG_READ_sPLT_SUPPORTED)
  171328. void /* PRIVATE */
  171329. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171330. {
  171331. png_bytep chunkdata;
  171332. png_bytep entry_start;
  171333. png_sPLT_t new_palette;
  171334. #ifdef PNG_NO_POINTER_INDEXING
  171335. png_sPLT_entryp pp;
  171336. #endif
  171337. int data_length, entry_size, i;
  171338. png_uint_32 skip = 0;
  171339. png_size_t slength;
  171340. png_debug(1, "in png_handle_sPLT\n");
  171341. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171342. png_error(png_ptr, "Missing IHDR before sPLT");
  171343. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171344. {
  171345. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171346. png_crc_finish(png_ptr, length);
  171347. return;
  171348. }
  171349. #ifdef PNG_MAX_MALLOC_64K
  171350. if (length > (png_uint_32)65535L)
  171351. {
  171352. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171353. skip = length - (png_uint_32)65535L;
  171354. length = (png_uint_32)65535L;
  171355. }
  171356. #endif
  171357. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171358. slength = (png_size_t)length;
  171359. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171360. if (png_crc_finish(png_ptr, skip))
  171361. {
  171362. png_free(png_ptr, chunkdata);
  171363. return;
  171364. }
  171365. chunkdata[slength] = 0x00;
  171366. for (entry_start = chunkdata; *entry_start; entry_start++)
  171367. ;
  171368. ++entry_start;
  171369. if (entry_start > chunkdata + slength - 2)
  171370. {
  171371. png_free(png_ptr, chunkdata);
  171372. png_warning(png_ptr, "malformed sPLT chunk");
  171373. return;
  171374. }
  171375. new_palette.depth = *entry_start++;
  171376. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171377. data_length = (slength - (entry_start - chunkdata));
  171378. if (data_length % entry_size)
  171379. {
  171380. png_free(png_ptr, chunkdata);
  171381. png_warning(png_ptr, "sPLT chunk has bad length");
  171382. return;
  171383. }
  171384. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171385. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171386. png_sizeof(png_sPLT_entry)))
  171387. {
  171388. png_warning(png_ptr, "sPLT chunk too long");
  171389. return;
  171390. }
  171391. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171392. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171393. if (new_palette.entries == NULL)
  171394. {
  171395. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171396. return;
  171397. }
  171398. #ifndef PNG_NO_POINTER_INDEXING
  171399. for (i = 0; i < new_palette.nentries; i++)
  171400. {
  171401. png_sPLT_entryp pp = new_palette.entries + i;
  171402. if (new_palette.depth == 8)
  171403. {
  171404. pp->red = *entry_start++;
  171405. pp->green = *entry_start++;
  171406. pp->blue = *entry_start++;
  171407. pp->alpha = *entry_start++;
  171408. }
  171409. else
  171410. {
  171411. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171412. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171413. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171414. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171415. }
  171416. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171417. }
  171418. #else
  171419. pp = new_palette.entries;
  171420. for (i = 0; i < new_palette.nentries; i++)
  171421. {
  171422. if (new_palette.depth == 8)
  171423. {
  171424. pp[i].red = *entry_start++;
  171425. pp[i].green = *entry_start++;
  171426. pp[i].blue = *entry_start++;
  171427. pp[i].alpha = *entry_start++;
  171428. }
  171429. else
  171430. {
  171431. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171432. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171433. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171434. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171435. }
  171436. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171437. }
  171438. #endif
  171439. new_palette.name = (png_charp)chunkdata;
  171440. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171441. png_free(png_ptr, chunkdata);
  171442. png_free(png_ptr, new_palette.entries);
  171443. }
  171444. #endif /* PNG_READ_sPLT_SUPPORTED */
  171445. #if defined(PNG_READ_tRNS_SUPPORTED)
  171446. void /* PRIVATE */
  171447. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171448. {
  171449. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171450. int bit_mask;
  171451. png_debug(1, "in png_handle_tRNS\n");
  171452. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171453. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171454. png_error(png_ptr, "Missing IHDR before tRNS");
  171455. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171456. {
  171457. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171458. png_crc_finish(png_ptr, length);
  171459. return;
  171460. }
  171461. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171462. {
  171463. png_warning(png_ptr, "Duplicate tRNS chunk");
  171464. png_crc_finish(png_ptr, length);
  171465. return;
  171466. }
  171467. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171468. {
  171469. png_byte buf[2];
  171470. if (length != 2)
  171471. {
  171472. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171473. png_crc_finish(png_ptr, length);
  171474. return;
  171475. }
  171476. png_crc_read(png_ptr, buf, 2);
  171477. png_ptr->num_trans = 1;
  171478. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171479. }
  171480. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171481. {
  171482. png_byte buf[6];
  171483. if (length != 6)
  171484. {
  171485. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171486. png_crc_finish(png_ptr, length);
  171487. return;
  171488. }
  171489. png_crc_read(png_ptr, buf, (png_size_t)length);
  171490. png_ptr->num_trans = 1;
  171491. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171492. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171493. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171494. }
  171495. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171496. {
  171497. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171498. {
  171499. png_warning(png_ptr, "Missing PLTE before tRNS");
  171500. }
  171501. if (length > (png_uint_32)png_ptr->num_palette ||
  171502. length > PNG_MAX_PALETTE_LENGTH)
  171503. {
  171504. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171505. png_crc_finish(png_ptr, length);
  171506. return;
  171507. }
  171508. if (length == 0)
  171509. {
  171510. png_warning(png_ptr, "Zero length tRNS chunk");
  171511. png_crc_finish(png_ptr, length);
  171512. return;
  171513. }
  171514. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171515. png_ptr->num_trans = (png_uint_16)length;
  171516. }
  171517. else
  171518. {
  171519. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171520. png_crc_finish(png_ptr, length);
  171521. return;
  171522. }
  171523. if (png_crc_finish(png_ptr, 0))
  171524. {
  171525. png_ptr->num_trans = 0;
  171526. return;
  171527. }
  171528. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171529. &(png_ptr->trans_values));
  171530. }
  171531. #endif
  171532. #if defined(PNG_READ_bKGD_SUPPORTED)
  171533. void /* PRIVATE */
  171534. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171535. {
  171536. png_size_t truelen;
  171537. png_byte buf[6];
  171538. png_debug(1, "in png_handle_bKGD\n");
  171539. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171540. png_error(png_ptr, "Missing IHDR before bKGD");
  171541. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171542. {
  171543. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171544. png_crc_finish(png_ptr, length);
  171545. return;
  171546. }
  171547. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171548. !(png_ptr->mode & PNG_HAVE_PLTE))
  171549. {
  171550. png_warning(png_ptr, "Missing PLTE before bKGD");
  171551. png_crc_finish(png_ptr, length);
  171552. return;
  171553. }
  171554. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171555. {
  171556. png_warning(png_ptr, "Duplicate bKGD chunk");
  171557. png_crc_finish(png_ptr, length);
  171558. return;
  171559. }
  171560. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171561. truelen = 1;
  171562. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171563. truelen = 6;
  171564. else
  171565. truelen = 2;
  171566. if (length != truelen)
  171567. {
  171568. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171569. png_crc_finish(png_ptr, length);
  171570. return;
  171571. }
  171572. png_crc_read(png_ptr, buf, truelen);
  171573. if (png_crc_finish(png_ptr, 0))
  171574. return;
  171575. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171576. {
  171577. png_ptr->background.index = buf[0];
  171578. if(info_ptr->num_palette)
  171579. {
  171580. if(buf[0] > info_ptr->num_palette)
  171581. {
  171582. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171583. return;
  171584. }
  171585. png_ptr->background.red =
  171586. (png_uint_16)png_ptr->palette[buf[0]].red;
  171587. png_ptr->background.green =
  171588. (png_uint_16)png_ptr->palette[buf[0]].green;
  171589. png_ptr->background.blue =
  171590. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171591. }
  171592. }
  171593. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171594. {
  171595. png_ptr->background.red =
  171596. png_ptr->background.green =
  171597. png_ptr->background.blue =
  171598. png_ptr->background.gray = png_get_uint_16(buf);
  171599. }
  171600. else
  171601. {
  171602. png_ptr->background.red = png_get_uint_16(buf);
  171603. png_ptr->background.green = png_get_uint_16(buf + 2);
  171604. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171605. }
  171606. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171607. }
  171608. #endif
  171609. #if defined(PNG_READ_hIST_SUPPORTED)
  171610. void /* PRIVATE */
  171611. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171612. {
  171613. unsigned int num, i;
  171614. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171615. png_debug(1, "in png_handle_hIST\n");
  171616. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171617. png_error(png_ptr, "Missing IHDR before hIST");
  171618. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171619. {
  171620. png_warning(png_ptr, "Invalid hIST after IDAT");
  171621. png_crc_finish(png_ptr, length);
  171622. return;
  171623. }
  171624. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171625. {
  171626. png_warning(png_ptr, "Missing PLTE before hIST");
  171627. png_crc_finish(png_ptr, length);
  171628. return;
  171629. }
  171630. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171631. {
  171632. png_warning(png_ptr, "Duplicate hIST chunk");
  171633. png_crc_finish(png_ptr, length);
  171634. return;
  171635. }
  171636. num = length / 2 ;
  171637. if (num != (unsigned int) png_ptr->num_palette || num >
  171638. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171639. {
  171640. png_warning(png_ptr, "Incorrect hIST chunk length");
  171641. png_crc_finish(png_ptr, length);
  171642. return;
  171643. }
  171644. for (i = 0; i < num; i++)
  171645. {
  171646. png_byte buf[2];
  171647. png_crc_read(png_ptr, buf, 2);
  171648. readbuf[i] = png_get_uint_16(buf);
  171649. }
  171650. if (png_crc_finish(png_ptr, 0))
  171651. return;
  171652. png_set_hIST(png_ptr, info_ptr, readbuf);
  171653. }
  171654. #endif
  171655. #if defined(PNG_READ_pHYs_SUPPORTED)
  171656. void /* PRIVATE */
  171657. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171658. {
  171659. png_byte buf[9];
  171660. png_uint_32 res_x, res_y;
  171661. int unit_type;
  171662. png_debug(1, "in png_handle_pHYs\n");
  171663. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171664. png_error(png_ptr, "Missing IHDR before pHYs");
  171665. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171666. {
  171667. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171668. png_crc_finish(png_ptr, length);
  171669. return;
  171670. }
  171671. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171672. {
  171673. png_warning(png_ptr, "Duplicate pHYs chunk");
  171674. png_crc_finish(png_ptr, length);
  171675. return;
  171676. }
  171677. if (length != 9)
  171678. {
  171679. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171680. png_crc_finish(png_ptr, length);
  171681. return;
  171682. }
  171683. png_crc_read(png_ptr, buf, 9);
  171684. if (png_crc_finish(png_ptr, 0))
  171685. return;
  171686. res_x = png_get_uint_32(buf);
  171687. res_y = png_get_uint_32(buf + 4);
  171688. unit_type = buf[8];
  171689. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171690. }
  171691. #endif
  171692. #if defined(PNG_READ_oFFs_SUPPORTED)
  171693. void /* PRIVATE */
  171694. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171695. {
  171696. png_byte buf[9];
  171697. png_int_32 offset_x, offset_y;
  171698. int unit_type;
  171699. png_debug(1, "in png_handle_oFFs\n");
  171700. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171701. png_error(png_ptr, "Missing IHDR before oFFs");
  171702. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171703. {
  171704. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171705. png_crc_finish(png_ptr, length);
  171706. return;
  171707. }
  171708. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  171709. {
  171710. png_warning(png_ptr, "Duplicate oFFs chunk");
  171711. png_crc_finish(png_ptr, length);
  171712. return;
  171713. }
  171714. if (length != 9)
  171715. {
  171716. png_warning(png_ptr, "Incorrect oFFs chunk length");
  171717. png_crc_finish(png_ptr, length);
  171718. return;
  171719. }
  171720. png_crc_read(png_ptr, buf, 9);
  171721. if (png_crc_finish(png_ptr, 0))
  171722. return;
  171723. offset_x = png_get_int_32(buf);
  171724. offset_y = png_get_int_32(buf + 4);
  171725. unit_type = buf[8];
  171726. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  171727. }
  171728. #endif
  171729. #if defined(PNG_READ_pCAL_SUPPORTED)
  171730. void /* PRIVATE */
  171731. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171732. {
  171733. png_charp purpose;
  171734. png_int_32 X0, X1;
  171735. png_byte type, nparams;
  171736. png_charp buf, units, endptr;
  171737. png_charpp params;
  171738. png_size_t slength;
  171739. int i;
  171740. png_debug(1, "in png_handle_pCAL\n");
  171741. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171742. png_error(png_ptr, "Missing IHDR before pCAL");
  171743. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171744. {
  171745. png_warning(png_ptr, "Invalid pCAL after IDAT");
  171746. png_crc_finish(png_ptr, length);
  171747. return;
  171748. }
  171749. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  171750. {
  171751. png_warning(png_ptr, "Duplicate pCAL chunk");
  171752. png_crc_finish(png_ptr, length);
  171753. return;
  171754. }
  171755. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  171756. length + 1);
  171757. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171758. if (purpose == NULL)
  171759. {
  171760. png_warning(png_ptr, "No memory for pCAL purpose.");
  171761. return;
  171762. }
  171763. slength = (png_size_t)length;
  171764. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  171765. if (png_crc_finish(png_ptr, 0))
  171766. {
  171767. png_free(png_ptr, purpose);
  171768. return;
  171769. }
  171770. purpose[slength] = 0x00; /* null terminate the last string */
  171771. png_debug(3, "Finding end of pCAL purpose string\n");
  171772. for (buf = purpose; *buf; buf++)
  171773. ;
  171774. endptr = purpose + slength;
  171775. if (endptr <= buf + 12)
  171776. {
  171777. png_warning(png_ptr, "Invalid pCAL data");
  171778. png_free(png_ptr, purpose);
  171779. return;
  171780. }
  171781. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  171782. X0 = png_get_int_32((png_bytep)buf+1);
  171783. X1 = png_get_int_32((png_bytep)buf+5);
  171784. type = buf[9];
  171785. nparams = buf[10];
  171786. units = buf + 11;
  171787. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  171788. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  171789. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  171790. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  171791. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  171792. {
  171793. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  171794. png_free(png_ptr, purpose);
  171795. return;
  171796. }
  171797. else if (type >= PNG_EQUATION_LAST)
  171798. {
  171799. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  171800. }
  171801. for (buf = units; *buf; buf++)
  171802. ;
  171803. png_debug(3, "Allocating pCAL parameters array\n");
  171804. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  171805. *png_sizeof(png_charp))) ;
  171806. if (params == NULL)
  171807. {
  171808. png_free(png_ptr, purpose);
  171809. png_warning(png_ptr, "No memory for pCAL params.");
  171810. return;
  171811. }
  171812. for (i = 0; i < (int)nparams; i++)
  171813. {
  171814. buf++; /* Skip the null string terminator from previous parameter. */
  171815. png_debug1(3, "Reading pCAL parameter %d\n", i);
  171816. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  171817. ;
  171818. if (buf > endptr)
  171819. {
  171820. png_warning(png_ptr, "Invalid pCAL data");
  171821. png_free(png_ptr, purpose);
  171822. png_free(png_ptr, params);
  171823. return;
  171824. }
  171825. }
  171826. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  171827. units, params);
  171828. png_free(png_ptr, purpose);
  171829. png_free(png_ptr, params);
  171830. }
  171831. #endif
  171832. #if defined(PNG_READ_sCAL_SUPPORTED)
  171833. void /* PRIVATE */
  171834. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171835. {
  171836. png_charp buffer, ep;
  171837. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171838. double width, height;
  171839. png_charp vp;
  171840. #else
  171841. #ifdef PNG_FIXED_POINT_SUPPORTED
  171842. png_charp swidth, sheight;
  171843. #endif
  171844. #endif
  171845. png_size_t slength;
  171846. png_debug(1, "in png_handle_sCAL\n");
  171847. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171848. png_error(png_ptr, "Missing IHDR before sCAL");
  171849. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171850. {
  171851. png_warning(png_ptr, "Invalid sCAL after IDAT");
  171852. png_crc_finish(png_ptr, length);
  171853. return;
  171854. }
  171855. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  171856. {
  171857. png_warning(png_ptr, "Duplicate sCAL chunk");
  171858. png_crc_finish(png_ptr, length);
  171859. return;
  171860. }
  171861. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  171862. length + 1);
  171863. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171864. if (buffer == NULL)
  171865. {
  171866. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  171867. return;
  171868. }
  171869. slength = (png_size_t)length;
  171870. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  171871. if (png_crc_finish(png_ptr, 0))
  171872. {
  171873. png_free(png_ptr, buffer);
  171874. return;
  171875. }
  171876. buffer[slength] = 0x00; /* null terminate the last string */
  171877. ep = buffer + 1; /* skip unit byte */
  171878. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171879. width = png_strtod(png_ptr, ep, &vp);
  171880. if (*vp)
  171881. {
  171882. png_warning(png_ptr, "malformed width string in sCAL chunk");
  171883. return;
  171884. }
  171885. #else
  171886. #ifdef PNG_FIXED_POINT_SUPPORTED
  171887. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  171888. if (swidth == NULL)
  171889. {
  171890. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  171891. return;
  171892. }
  171893. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  171894. #endif
  171895. #endif
  171896. for (ep = buffer; *ep; ep++)
  171897. ;
  171898. ep++;
  171899. if (buffer + slength < ep)
  171900. {
  171901. png_warning(png_ptr, "Truncated sCAL chunk");
  171902. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  171903. !defined(PNG_FLOATING_POINT_SUPPORTED)
  171904. png_free(png_ptr, swidth);
  171905. #endif
  171906. png_free(png_ptr, buffer);
  171907. return;
  171908. }
  171909. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171910. height = png_strtod(png_ptr, ep, &vp);
  171911. if (*vp)
  171912. {
  171913. png_warning(png_ptr, "malformed height string in sCAL chunk");
  171914. return;
  171915. }
  171916. #else
  171917. #ifdef PNG_FIXED_POINT_SUPPORTED
  171918. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  171919. if (swidth == NULL)
  171920. {
  171921. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  171922. return;
  171923. }
  171924. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  171925. #endif
  171926. #endif
  171927. if (buffer + slength < ep
  171928. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171929. || width <= 0. || height <= 0.
  171930. #endif
  171931. )
  171932. {
  171933. png_warning(png_ptr, "Invalid sCAL data");
  171934. png_free(png_ptr, buffer);
  171935. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  171936. png_free(png_ptr, swidth);
  171937. png_free(png_ptr, sheight);
  171938. #endif
  171939. return;
  171940. }
  171941. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171942. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  171943. #else
  171944. #ifdef PNG_FIXED_POINT_SUPPORTED
  171945. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  171946. #endif
  171947. #endif
  171948. png_free(png_ptr, buffer);
  171949. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  171950. png_free(png_ptr, swidth);
  171951. png_free(png_ptr, sheight);
  171952. #endif
  171953. }
  171954. #endif
  171955. #if defined(PNG_READ_tIME_SUPPORTED)
  171956. void /* PRIVATE */
  171957. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171958. {
  171959. png_byte buf[7];
  171960. png_time mod_time;
  171961. png_debug(1, "in png_handle_tIME\n");
  171962. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171963. png_error(png_ptr, "Out of place tIME chunk");
  171964. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  171965. {
  171966. png_warning(png_ptr, "Duplicate tIME chunk");
  171967. png_crc_finish(png_ptr, length);
  171968. return;
  171969. }
  171970. if (png_ptr->mode & PNG_HAVE_IDAT)
  171971. png_ptr->mode |= PNG_AFTER_IDAT;
  171972. if (length != 7)
  171973. {
  171974. png_warning(png_ptr, "Incorrect tIME chunk length");
  171975. png_crc_finish(png_ptr, length);
  171976. return;
  171977. }
  171978. png_crc_read(png_ptr, buf, 7);
  171979. if (png_crc_finish(png_ptr, 0))
  171980. return;
  171981. mod_time.second = buf[6];
  171982. mod_time.minute = buf[5];
  171983. mod_time.hour = buf[4];
  171984. mod_time.day = buf[3];
  171985. mod_time.month = buf[2];
  171986. mod_time.year = png_get_uint_16(buf);
  171987. png_set_tIME(png_ptr, info_ptr, &mod_time);
  171988. }
  171989. #endif
  171990. #if defined(PNG_READ_tEXt_SUPPORTED)
  171991. void /* PRIVATE */
  171992. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171993. {
  171994. png_textp text_ptr;
  171995. png_charp key;
  171996. png_charp text;
  171997. png_uint_32 skip = 0;
  171998. png_size_t slength;
  171999. int ret;
  172000. png_debug(1, "in png_handle_tEXt\n");
  172001. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172002. png_error(png_ptr, "Missing IHDR before tEXt");
  172003. if (png_ptr->mode & PNG_HAVE_IDAT)
  172004. png_ptr->mode |= PNG_AFTER_IDAT;
  172005. #ifdef PNG_MAX_MALLOC_64K
  172006. if (length > (png_uint_32)65535L)
  172007. {
  172008. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172009. skip = length - (png_uint_32)65535L;
  172010. length = (png_uint_32)65535L;
  172011. }
  172012. #endif
  172013. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172014. if (key == NULL)
  172015. {
  172016. png_warning(png_ptr, "No memory to process text chunk.");
  172017. return;
  172018. }
  172019. slength = (png_size_t)length;
  172020. png_crc_read(png_ptr, (png_bytep)key, slength);
  172021. if (png_crc_finish(png_ptr, skip))
  172022. {
  172023. png_free(png_ptr, key);
  172024. return;
  172025. }
  172026. key[slength] = 0x00;
  172027. for (text = key; *text; text++)
  172028. ;
  172029. if (text != key + slength)
  172030. text++;
  172031. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172032. (png_uint_32)png_sizeof(png_text));
  172033. if (text_ptr == NULL)
  172034. {
  172035. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172036. png_free(png_ptr, key);
  172037. return;
  172038. }
  172039. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172040. text_ptr->key = key;
  172041. #ifdef PNG_iTXt_SUPPORTED
  172042. text_ptr->lang = NULL;
  172043. text_ptr->lang_key = NULL;
  172044. text_ptr->itxt_length = 0;
  172045. #endif
  172046. text_ptr->text = text;
  172047. text_ptr->text_length = png_strlen(text);
  172048. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172049. png_free(png_ptr, key);
  172050. png_free(png_ptr, text_ptr);
  172051. if (ret)
  172052. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172053. }
  172054. #endif
  172055. #if defined(PNG_READ_zTXt_SUPPORTED)
  172056. void /* PRIVATE */
  172057. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172058. {
  172059. png_textp text_ptr;
  172060. png_charp chunkdata;
  172061. png_charp text;
  172062. int comp_type;
  172063. int ret;
  172064. png_size_t slength, prefix_len, data_len;
  172065. png_debug(1, "in png_handle_zTXt\n");
  172066. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172067. png_error(png_ptr, "Missing IHDR before zTXt");
  172068. if (png_ptr->mode & PNG_HAVE_IDAT)
  172069. png_ptr->mode |= PNG_AFTER_IDAT;
  172070. #ifdef PNG_MAX_MALLOC_64K
  172071. if (length > (png_uint_32)65535L)
  172072. {
  172073. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172074. png_crc_finish(png_ptr, length);
  172075. return;
  172076. }
  172077. #endif
  172078. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172079. if (chunkdata == NULL)
  172080. {
  172081. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172082. return;
  172083. }
  172084. slength = (png_size_t)length;
  172085. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172086. if (png_crc_finish(png_ptr, 0))
  172087. {
  172088. png_free(png_ptr, chunkdata);
  172089. return;
  172090. }
  172091. chunkdata[slength] = 0x00;
  172092. for (text = chunkdata; *text; text++)
  172093. ;
  172094. if (text >= chunkdata + slength - 2)
  172095. {
  172096. png_warning(png_ptr, "Truncated zTXt chunk");
  172097. png_free(png_ptr, chunkdata);
  172098. return;
  172099. }
  172100. else
  172101. {
  172102. comp_type = *(++text);
  172103. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172104. {
  172105. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172106. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172107. }
  172108. text++; /* skip the compression_method byte */
  172109. }
  172110. prefix_len = text - chunkdata;
  172111. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172112. (png_size_t)length, prefix_len, &data_len);
  172113. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172114. (png_uint_32)png_sizeof(png_text));
  172115. if (text_ptr == NULL)
  172116. {
  172117. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172118. png_free(png_ptr, chunkdata);
  172119. return;
  172120. }
  172121. text_ptr->compression = comp_type;
  172122. text_ptr->key = chunkdata;
  172123. #ifdef PNG_iTXt_SUPPORTED
  172124. text_ptr->lang = NULL;
  172125. text_ptr->lang_key = NULL;
  172126. text_ptr->itxt_length = 0;
  172127. #endif
  172128. text_ptr->text = chunkdata + prefix_len;
  172129. text_ptr->text_length = data_len;
  172130. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172131. png_free(png_ptr, text_ptr);
  172132. png_free(png_ptr, chunkdata);
  172133. if (ret)
  172134. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172135. }
  172136. #endif
  172137. #if defined(PNG_READ_iTXt_SUPPORTED)
  172138. void /* PRIVATE */
  172139. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172140. {
  172141. png_textp text_ptr;
  172142. png_charp chunkdata;
  172143. png_charp key, lang, text, lang_key;
  172144. int comp_flag;
  172145. int comp_type = 0;
  172146. int ret;
  172147. png_size_t slength, prefix_len, data_len;
  172148. png_debug(1, "in png_handle_iTXt\n");
  172149. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172150. png_error(png_ptr, "Missing IHDR before iTXt");
  172151. if (png_ptr->mode & PNG_HAVE_IDAT)
  172152. png_ptr->mode |= PNG_AFTER_IDAT;
  172153. #ifdef PNG_MAX_MALLOC_64K
  172154. if (length > (png_uint_32)65535L)
  172155. {
  172156. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172157. png_crc_finish(png_ptr, length);
  172158. return;
  172159. }
  172160. #endif
  172161. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172162. if (chunkdata == NULL)
  172163. {
  172164. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172165. return;
  172166. }
  172167. slength = (png_size_t)length;
  172168. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172169. if (png_crc_finish(png_ptr, 0))
  172170. {
  172171. png_free(png_ptr, chunkdata);
  172172. return;
  172173. }
  172174. chunkdata[slength] = 0x00;
  172175. for (lang = chunkdata; *lang; lang++)
  172176. ;
  172177. lang++; /* skip NUL separator */
  172178. if (lang >= chunkdata + slength - 3)
  172179. {
  172180. png_warning(png_ptr, "Truncated iTXt chunk");
  172181. png_free(png_ptr, chunkdata);
  172182. return;
  172183. }
  172184. else
  172185. {
  172186. comp_flag = *lang++;
  172187. comp_type = *lang++;
  172188. }
  172189. for (lang_key = lang; *lang_key; lang_key++)
  172190. ;
  172191. lang_key++; /* skip NUL separator */
  172192. if (lang_key >= chunkdata + slength)
  172193. {
  172194. png_warning(png_ptr, "Truncated iTXt chunk");
  172195. png_free(png_ptr, chunkdata);
  172196. return;
  172197. }
  172198. for (text = lang_key; *text; text++)
  172199. ;
  172200. text++; /* skip NUL separator */
  172201. if (text >= chunkdata + slength)
  172202. {
  172203. png_warning(png_ptr, "Malformed iTXt chunk");
  172204. png_free(png_ptr, chunkdata);
  172205. return;
  172206. }
  172207. prefix_len = text - chunkdata;
  172208. key=chunkdata;
  172209. if (comp_flag)
  172210. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172211. (size_t)length, prefix_len, &data_len);
  172212. else
  172213. data_len=png_strlen(chunkdata + prefix_len);
  172214. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172215. (png_uint_32)png_sizeof(png_text));
  172216. if (text_ptr == NULL)
  172217. {
  172218. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172219. png_free(png_ptr, chunkdata);
  172220. return;
  172221. }
  172222. text_ptr->compression = (int)comp_flag + 1;
  172223. text_ptr->lang_key = chunkdata+(lang_key-key);
  172224. text_ptr->lang = chunkdata+(lang-key);
  172225. text_ptr->itxt_length = data_len;
  172226. text_ptr->text_length = 0;
  172227. text_ptr->key = chunkdata;
  172228. text_ptr->text = chunkdata + prefix_len;
  172229. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172230. png_free(png_ptr, text_ptr);
  172231. png_free(png_ptr, chunkdata);
  172232. if (ret)
  172233. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172234. }
  172235. #endif
  172236. void /* PRIVATE */
  172237. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172238. {
  172239. png_uint_32 skip = 0;
  172240. png_debug(1, "in png_handle_unknown\n");
  172241. if (png_ptr->mode & PNG_HAVE_IDAT)
  172242. {
  172243. #ifdef PNG_USE_LOCAL_ARRAYS
  172244. PNG_CONST PNG_IDAT;
  172245. #endif
  172246. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172247. png_ptr->mode |= PNG_AFTER_IDAT;
  172248. }
  172249. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172250. if (!(png_ptr->chunk_name[0] & 0x20))
  172251. {
  172252. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172253. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172254. PNG_HANDLE_CHUNK_ALWAYS
  172255. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172256. && png_ptr->read_user_chunk_fn == NULL
  172257. #endif
  172258. )
  172259. #endif
  172260. png_chunk_error(png_ptr, "unknown critical chunk");
  172261. }
  172262. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172263. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172264. (png_ptr->read_user_chunk_fn != NULL))
  172265. {
  172266. #ifdef PNG_MAX_MALLOC_64K
  172267. if (length > (png_uint_32)65535L)
  172268. {
  172269. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172270. skip = length - (png_uint_32)65535L;
  172271. length = (png_uint_32)65535L;
  172272. }
  172273. #endif
  172274. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172275. (png_charp)png_ptr->chunk_name, 5);
  172276. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172277. png_ptr->unknown_chunk.size = (png_size_t)length;
  172278. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172279. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172280. if(png_ptr->read_user_chunk_fn != NULL)
  172281. {
  172282. int ret;
  172283. ret = (*(png_ptr->read_user_chunk_fn))
  172284. (png_ptr, &png_ptr->unknown_chunk);
  172285. if (ret < 0)
  172286. png_chunk_error(png_ptr, "error in user chunk");
  172287. if (ret == 0)
  172288. {
  172289. if (!(png_ptr->chunk_name[0] & 0x20))
  172290. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172291. PNG_HANDLE_CHUNK_ALWAYS)
  172292. png_chunk_error(png_ptr, "unknown critical chunk");
  172293. png_set_unknown_chunks(png_ptr, info_ptr,
  172294. &png_ptr->unknown_chunk, 1);
  172295. }
  172296. }
  172297. #else
  172298. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172299. #endif
  172300. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172301. png_ptr->unknown_chunk.data = NULL;
  172302. }
  172303. else
  172304. #endif
  172305. skip = length;
  172306. png_crc_finish(png_ptr, skip);
  172307. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172308. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172309. #endif
  172310. }
  172311. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172312. void /* PRIVATE */
  172313. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172314. {
  172315. png_debug(1, "in png_check_chunk_name\n");
  172316. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172317. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172318. {
  172319. png_chunk_error(png_ptr, "invalid chunk type");
  172320. }
  172321. }
  172322. void /* PRIVATE */
  172323. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172324. {
  172325. png_debug(1,"in png_combine_row\n");
  172326. if (mask == 0xff)
  172327. {
  172328. png_memcpy(row, png_ptr->row_buf + 1,
  172329. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172330. }
  172331. else
  172332. {
  172333. switch (png_ptr->row_info.pixel_depth)
  172334. {
  172335. case 1:
  172336. {
  172337. png_bytep sp = png_ptr->row_buf + 1;
  172338. png_bytep dp = row;
  172339. int s_inc, s_start, s_end;
  172340. int m = 0x80;
  172341. int shift;
  172342. png_uint_32 i;
  172343. png_uint_32 row_width = png_ptr->width;
  172344. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172345. if (png_ptr->transformations & PNG_PACKSWAP)
  172346. {
  172347. s_start = 0;
  172348. s_end = 7;
  172349. s_inc = 1;
  172350. }
  172351. else
  172352. #endif
  172353. {
  172354. s_start = 7;
  172355. s_end = 0;
  172356. s_inc = -1;
  172357. }
  172358. shift = s_start;
  172359. for (i = 0; i < row_width; i++)
  172360. {
  172361. if (m & mask)
  172362. {
  172363. int value;
  172364. value = (*sp >> shift) & 0x01;
  172365. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172366. *dp |= (png_byte)(value << shift);
  172367. }
  172368. if (shift == s_end)
  172369. {
  172370. shift = s_start;
  172371. sp++;
  172372. dp++;
  172373. }
  172374. else
  172375. shift += s_inc;
  172376. if (m == 1)
  172377. m = 0x80;
  172378. else
  172379. m >>= 1;
  172380. }
  172381. break;
  172382. }
  172383. case 2:
  172384. {
  172385. png_bytep sp = png_ptr->row_buf + 1;
  172386. png_bytep dp = row;
  172387. int s_start, s_end, s_inc;
  172388. int m = 0x80;
  172389. int shift;
  172390. png_uint_32 i;
  172391. png_uint_32 row_width = png_ptr->width;
  172392. int value;
  172393. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172394. if (png_ptr->transformations & PNG_PACKSWAP)
  172395. {
  172396. s_start = 0;
  172397. s_end = 6;
  172398. s_inc = 2;
  172399. }
  172400. else
  172401. #endif
  172402. {
  172403. s_start = 6;
  172404. s_end = 0;
  172405. s_inc = -2;
  172406. }
  172407. shift = s_start;
  172408. for (i = 0; i < row_width; i++)
  172409. {
  172410. if (m & mask)
  172411. {
  172412. value = (*sp >> shift) & 0x03;
  172413. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172414. *dp |= (png_byte)(value << shift);
  172415. }
  172416. if (shift == s_end)
  172417. {
  172418. shift = s_start;
  172419. sp++;
  172420. dp++;
  172421. }
  172422. else
  172423. shift += s_inc;
  172424. if (m == 1)
  172425. m = 0x80;
  172426. else
  172427. m >>= 1;
  172428. }
  172429. break;
  172430. }
  172431. case 4:
  172432. {
  172433. png_bytep sp = png_ptr->row_buf + 1;
  172434. png_bytep dp = row;
  172435. int s_start, s_end, s_inc;
  172436. int m = 0x80;
  172437. int shift;
  172438. png_uint_32 i;
  172439. png_uint_32 row_width = png_ptr->width;
  172440. int value;
  172441. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172442. if (png_ptr->transformations & PNG_PACKSWAP)
  172443. {
  172444. s_start = 0;
  172445. s_end = 4;
  172446. s_inc = 4;
  172447. }
  172448. else
  172449. #endif
  172450. {
  172451. s_start = 4;
  172452. s_end = 0;
  172453. s_inc = -4;
  172454. }
  172455. shift = s_start;
  172456. for (i = 0; i < row_width; i++)
  172457. {
  172458. if (m & mask)
  172459. {
  172460. value = (*sp >> shift) & 0xf;
  172461. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172462. *dp |= (png_byte)(value << shift);
  172463. }
  172464. if (shift == s_end)
  172465. {
  172466. shift = s_start;
  172467. sp++;
  172468. dp++;
  172469. }
  172470. else
  172471. shift += s_inc;
  172472. if (m == 1)
  172473. m = 0x80;
  172474. else
  172475. m >>= 1;
  172476. }
  172477. break;
  172478. }
  172479. default:
  172480. {
  172481. png_bytep sp = png_ptr->row_buf + 1;
  172482. png_bytep dp = row;
  172483. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172484. png_uint_32 i;
  172485. png_uint_32 row_width = png_ptr->width;
  172486. png_byte m = 0x80;
  172487. for (i = 0; i < row_width; i++)
  172488. {
  172489. if (m & mask)
  172490. {
  172491. png_memcpy(dp, sp, pixel_bytes);
  172492. }
  172493. sp += pixel_bytes;
  172494. dp += pixel_bytes;
  172495. if (m == 1)
  172496. m = 0x80;
  172497. else
  172498. m >>= 1;
  172499. }
  172500. break;
  172501. }
  172502. }
  172503. }
  172504. }
  172505. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172506. void /* PRIVATE */
  172507. png_do_read_interlace(png_structp png_ptr)
  172508. {
  172509. png_row_infop row_info = &(png_ptr->row_info);
  172510. png_bytep row = png_ptr->row_buf + 1;
  172511. int pass = png_ptr->pass;
  172512. png_uint_32 transformations = png_ptr->transformations;
  172513. #ifdef PNG_USE_LOCAL_ARRAYS
  172514. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172515. #endif
  172516. png_debug(1,"in png_do_read_interlace\n");
  172517. if (row != NULL && row_info != NULL)
  172518. {
  172519. png_uint_32 final_width;
  172520. final_width = row_info->width * png_pass_inc[pass];
  172521. switch (row_info->pixel_depth)
  172522. {
  172523. case 1:
  172524. {
  172525. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172526. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172527. int sshift, dshift;
  172528. int s_start, s_end, s_inc;
  172529. int jstop = png_pass_inc[pass];
  172530. png_byte v;
  172531. png_uint_32 i;
  172532. int j;
  172533. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172534. if (transformations & PNG_PACKSWAP)
  172535. {
  172536. sshift = (int)((row_info->width + 7) & 0x07);
  172537. dshift = (int)((final_width + 7) & 0x07);
  172538. s_start = 7;
  172539. s_end = 0;
  172540. s_inc = -1;
  172541. }
  172542. else
  172543. #endif
  172544. {
  172545. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172546. dshift = 7 - (int)((final_width + 7) & 0x07);
  172547. s_start = 0;
  172548. s_end = 7;
  172549. s_inc = 1;
  172550. }
  172551. for (i = 0; i < row_info->width; i++)
  172552. {
  172553. v = (png_byte)((*sp >> sshift) & 0x01);
  172554. for (j = 0; j < jstop; j++)
  172555. {
  172556. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172557. *dp |= (png_byte)(v << dshift);
  172558. if (dshift == s_end)
  172559. {
  172560. dshift = s_start;
  172561. dp--;
  172562. }
  172563. else
  172564. dshift += s_inc;
  172565. }
  172566. if (sshift == s_end)
  172567. {
  172568. sshift = s_start;
  172569. sp--;
  172570. }
  172571. else
  172572. sshift += s_inc;
  172573. }
  172574. break;
  172575. }
  172576. case 2:
  172577. {
  172578. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172579. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172580. int sshift, dshift;
  172581. int s_start, s_end, s_inc;
  172582. int jstop = png_pass_inc[pass];
  172583. png_uint_32 i;
  172584. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172585. if (transformations & PNG_PACKSWAP)
  172586. {
  172587. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172588. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172589. s_start = 6;
  172590. s_end = 0;
  172591. s_inc = -2;
  172592. }
  172593. else
  172594. #endif
  172595. {
  172596. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172597. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172598. s_start = 0;
  172599. s_end = 6;
  172600. s_inc = 2;
  172601. }
  172602. for (i = 0; i < row_info->width; i++)
  172603. {
  172604. png_byte v;
  172605. int j;
  172606. v = (png_byte)((*sp >> sshift) & 0x03);
  172607. for (j = 0; j < jstop; j++)
  172608. {
  172609. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172610. *dp |= (png_byte)(v << dshift);
  172611. if (dshift == s_end)
  172612. {
  172613. dshift = s_start;
  172614. dp--;
  172615. }
  172616. else
  172617. dshift += s_inc;
  172618. }
  172619. if (sshift == s_end)
  172620. {
  172621. sshift = s_start;
  172622. sp--;
  172623. }
  172624. else
  172625. sshift += s_inc;
  172626. }
  172627. break;
  172628. }
  172629. case 4:
  172630. {
  172631. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172632. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172633. int sshift, dshift;
  172634. int s_start, s_end, s_inc;
  172635. png_uint_32 i;
  172636. int jstop = png_pass_inc[pass];
  172637. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172638. if (transformations & PNG_PACKSWAP)
  172639. {
  172640. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172641. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172642. s_start = 4;
  172643. s_end = 0;
  172644. s_inc = -4;
  172645. }
  172646. else
  172647. #endif
  172648. {
  172649. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172650. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172651. s_start = 0;
  172652. s_end = 4;
  172653. s_inc = 4;
  172654. }
  172655. for (i = 0; i < row_info->width; i++)
  172656. {
  172657. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172658. int j;
  172659. for (j = 0; j < jstop; j++)
  172660. {
  172661. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172662. *dp |= (png_byte)(v << dshift);
  172663. if (dshift == s_end)
  172664. {
  172665. dshift = s_start;
  172666. dp--;
  172667. }
  172668. else
  172669. dshift += s_inc;
  172670. }
  172671. if (sshift == s_end)
  172672. {
  172673. sshift = s_start;
  172674. sp--;
  172675. }
  172676. else
  172677. sshift += s_inc;
  172678. }
  172679. break;
  172680. }
  172681. default:
  172682. {
  172683. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172684. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172685. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172686. int jstop = png_pass_inc[pass];
  172687. png_uint_32 i;
  172688. for (i = 0; i < row_info->width; i++)
  172689. {
  172690. png_byte v[8];
  172691. int j;
  172692. png_memcpy(v, sp, pixel_bytes);
  172693. for (j = 0; j < jstop; j++)
  172694. {
  172695. png_memcpy(dp, v, pixel_bytes);
  172696. dp -= pixel_bytes;
  172697. }
  172698. sp -= pixel_bytes;
  172699. }
  172700. break;
  172701. }
  172702. }
  172703. row_info->width = final_width;
  172704. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172705. }
  172706. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  172707. transformations = transformations; /* silence compiler warning */
  172708. #endif
  172709. }
  172710. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  172711. void /* PRIVATE */
  172712. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  172713. png_bytep prev_row, int filter)
  172714. {
  172715. png_debug(1, "in png_read_filter_row\n");
  172716. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  172717. switch (filter)
  172718. {
  172719. case PNG_FILTER_VALUE_NONE:
  172720. break;
  172721. case PNG_FILTER_VALUE_SUB:
  172722. {
  172723. png_uint_32 i;
  172724. png_uint_32 istop = row_info->rowbytes;
  172725. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172726. png_bytep rp = row + bpp;
  172727. png_bytep lp = row;
  172728. for (i = bpp; i < istop; i++)
  172729. {
  172730. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  172731. rp++;
  172732. }
  172733. break;
  172734. }
  172735. case PNG_FILTER_VALUE_UP:
  172736. {
  172737. png_uint_32 i;
  172738. png_uint_32 istop = row_info->rowbytes;
  172739. png_bytep rp = row;
  172740. png_bytep pp = prev_row;
  172741. for (i = 0; i < istop; i++)
  172742. {
  172743. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172744. rp++;
  172745. }
  172746. break;
  172747. }
  172748. case PNG_FILTER_VALUE_AVG:
  172749. {
  172750. png_uint_32 i;
  172751. png_bytep rp = row;
  172752. png_bytep pp = prev_row;
  172753. png_bytep lp = row;
  172754. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172755. png_uint_32 istop = row_info->rowbytes - bpp;
  172756. for (i = 0; i < bpp; i++)
  172757. {
  172758. *rp = (png_byte)(((int)(*rp) +
  172759. ((int)(*pp++) / 2 )) & 0xff);
  172760. rp++;
  172761. }
  172762. for (i = 0; i < istop; i++)
  172763. {
  172764. *rp = (png_byte)(((int)(*rp) +
  172765. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  172766. rp++;
  172767. }
  172768. break;
  172769. }
  172770. case PNG_FILTER_VALUE_PAETH:
  172771. {
  172772. png_uint_32 i;
  172773. png_bytep rp = row;
  172774. png_bytep pp = prev_row;
  172775. png_bytep lp = row;
  172776. png_bytep cp = prev_row;
  172777. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172778. png_uint_32 istop=row_info->rowbytes - bpp;
  172779. for (i = 0; i < bpp; i++)
  172780. {
  172781. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172782. rp++;
  172783. }
  172784. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  172785. {
  172786. int a, b, c, pa, pb, pc, p;
  172787. a = *lp++;
  172788. b = *pp++;
  172789. c = *cp++;
  172790. p = b - c;
  172791. pc = a - c;
  172792. #ifdef PNG_USE_ABS
  172793. pa = abs(p);
  172794. pb = abs(pc);
  172795. pc = abs(p + pc);
  172796. #else
  172797. pa = p < 0 ? -p : p;
  172798. pb = pc < 0 ? -pc : pc;
  172799. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  172800. #endif
  172801. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  172802. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  172803. rp++;
  172804. }
  172805. break;
  172806. }
  172807. default:
  172808. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  172809. *row=0;
  172810. break;
  172811. }
  172812. }
  172813. void /* PRIVATE */
  172814. png_read_finish_row(png_structp png_ptr)
  172815. {
  172816. #ifdef PNG_USE_LOCAL_ARRAYS
  172817. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  172818. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172819. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  172820. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  172821. #endif
  172822. png_debug(1, "in png_read_finish_row\n");
  172823. png_ptr->row_number++;
  172824. if (png_ptr->row_number < png_ptr->num_rows)
  172825. return;
  172826. if (png_ptr->interlaced)
  172827. {
  172828. png_ptr->row_number = 0;
  172829. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  172830. png_ptr->rowbytes + 1);
  172831. do
  172832. {
  172833. png_ptr->pass++;
  172834. if (png_ptr->pass >= 7)
  172835. break;
  172836. png_ptr->iwidth = (png_ptr->width +
  172837. png_pass_inc[png_ptr->pass] - 1 -
  172838. png_pass_start[png_ptr->pass]) /
  172839. png_pass_inc[png_ptr->pass];
  172840. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  172841. png_ptr->iwidth) + 1;
  172842. if (!(png_ptr->transformations & PNG_INTERLACE))
  172843. {
  172844. png_ptr->num_rows = (png_ptr->height +
  172845. png_pass_yinc[png_ptr->pass] - 1 -
  172846. png_pass_ystart[png_ptr->pass]) /
  172847. png_pass_yinc[png_ptr->pass];
  172848. if (!(png_ptr->num_rows))
  172849. continue;
  172850. }
  172851. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  172852. break;
  172853. } while (png_ptr->iwidth == 0);
  172854. if (png_ptr->pass < 7)
  172855. return;
  172856. }
  172857. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  172858. {
  172859. #ifdef PNG_USE_LOCAL_ARRAYS
  172860. PNG_CONST PNG_IDAT;
  172861. #endif
  172862. char extra;
  172863. int ret;
  172864. png_ptr->zstream.next_out = (Bytef *)&extra;
  172865. png_ptr->zstream.avail_out = (uInt)1;
  172866. for(;;)
  172867. {
  172868. if (!(png_ptr->zstream.avail_in))
  172869. {
  172870. while (!png_ptr->idat_size)
  172871. {
  172872. png_byte chunk_length[4];
  172873. png_crc_finish(png_ptr, 0);
  172874. png_read_data(png_ptr, chunk_length, 4);
  172875. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  172876. png_reset_crc(png_ptr);
  172877. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  172878. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  172879. png_error(png_ptr, "Not enough image data");
  172880. }
  172881. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  172882. png_ptr->zstream.next_in = png_ptr->zbuf;
  172883. if (png_ptr->zbuf_size > png_ptr->idat_size)
  172884. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  172885. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  172886. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  172887. }
  172888. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  172889. if (ret == Z_STREAM_END)
  172890. {
  172891. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  172892. png_ptr->idat_size)
  172893. png_warning(png_ptr, "Extra compressed data");
  172894. png_ptr->mode |= PNG_AFTER_IDAT;
  172895. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  172896. break;
  172897. }
  172898. if (ret != Z_OK)
  172899. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  172900. "Decompression Error");
  172901. if (!(png_ptr->zstream.avail_out))
  172902. {
  172903. png_warning(png_ptr, "Extra compressed data.");
  172904. png_ptr->mode |= PNG_AFTER_IDAT;
  172905. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  172906. break;
  172907. }
  172908. }
  172909. png_ptr->zstream.avail_out = 0;
  172910. }
  172911. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  172912. png_warning(png_ptr, "Extra compression data");
  172913. inflateReset(&png_ptr->zstream);
  172914. png_ptr->mode |= PNG_AFTER_IDAT;
  172915. }
  172916. void /* PRIVATE */
  172917. png_read_start_row(png_structp png_ptr)
  172918. {
  172919. #ifdef PNG_USE_LOCAL_ARRAYS
  172920. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  172921. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172922. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  172923. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  172924. #endif
  172925. int max_pixel_depth;
  172926. png_uint_32 row_bytes;
  172927. png_debug(1, "in png_read_start_row\n");
  172928. png_ptr->zstream.avail_in = 0;
  172929. png_init_read_transformations(png_ptr);
  172930. if (png_ptr->interlaced)
  172931. {
  172932. if (!(png_ptr->transformations & PNG_INTERLACE))
  172933. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  172934. png_pass_ystart[0]) / png_pass_yinc[0];
  172935. else
  172936. png_ptr->num_rows = png_ptr->height;
  172937. png_ptr->iwidth = (png_ptr->width +
  172938. png_pass_inc[png_ptr->pass] - 1 -
  172939. png_pass_start[png_ptr->pass]) /
  172940. png_pass_inc[png_ptr->pass];
  172941. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  172942. png_ptr->irowbytes = (png_size_t)row_bytes;
  172943. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  172944. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  172945. }
  172946. else
  172947. {
  172948. png_ptr->num_rows = png_ptr->height;
  172949. png_ptr->iwidth = png_ptr->width;
  172950. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  172951. }
  172952. max_pixel_depth = png_ptr->pixel_depth;
  172953. #if defined(PNG_READ_PACK_SUPPORTED)
  172954. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  172955. max_pixel_depth = 8;
  172956. #endif
  172957. #if defined(PNG_READ_EXPAND_SUPPORTED)
  172958. if (png_ptr->transformations & PNG_EXPAND)
  172959. {
  172960. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172961. {
  172962. if (png_ptr->num_trans)
  172963. max_pixel_depth = 32;
  172964. else
  172965. max_pixel_depth = 24;
  172966. }
  172967. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172968. {
  172969. if (max_pixel_depth < 8)
  172970. max_pixel_depth = 8;
  172971. if (png_ptr->num_trans)
  172972. max_pixel_depth *= 2;
  172973. }
  172974. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172975. {
  172976. if (png_ptr->num_trans)
  172977. {
  172978. max_pixel_depth *= 4;
  172979. max_pixel_depth /= 3;
  172980. }
  172981. }
  172982. }
  172983. #endif
  172984. #if defined(PNG_READ_FILLER_SUPPORTED)
  172985. if (png_ptr->transformations & (PNG_FILLER))
  172986. {
  172987. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172988. max_pixel_depth = 32;
  172989. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172990. {
  172991. if (max_pixel_depth <= 8)
  172992. max_pixel_depth = 16;
  172993. else
  172994. max_pixel_depth = 32;
  172995. }
  172996. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172997. {
  172998. if (max_pixel_depth <= 32)
  172999. max_pixel_depth = 32;
  173000. else
  173001. max_pixel_depth = 64;
  173002. }
  173003. }
  173004. #endif
  173005. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173006. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173007. {
  173008. if (
  173009. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173010. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173011. #endif
  173012. #if defined(PNG_READ_FILLER_SUPPORTED)
  173013. (png_ptr->transformations & (PNG_FILLER)) ||
  173014. #endif
  173015. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173016. {
  173017. if (max_pixel_depth <= 16)
  173018. max_pixel_depth = 32;
  173019. else
  173020. max_pixel_depth = 64;
  173021. }
  173022. else
  173023. {
  173024. if (max_pixel_depth <= 8)
  173025. {
  173026. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173027. max_pixel_depth = 32;
  173028. else
  173029. max_pixel_depth = 24;
  173030. }
  173031. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173032. max_pixel_depth = 64;
  173033. else
  173034. max_pixel_depth = 48;
  173035. }
  173036. }
  173037. #endif
  173038. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173039. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173040. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173041. {
  173042. int user_pixel_depth=png_ptr->user_transform_depth*
  173043. png_ptr->user_transform_channels;
  173044. if(user_pixel_depth > max_pixel_depth)
  173045. max_pixel_depth=user_pixel_depth;
  173046. }
  173047. #endif
  173048. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173049. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173050. 1 + ((max_pixel_depth + 7) >> 3);
  173051. #ifdef PNG_MAX_MALLOC_64K
  173052. if (row_bytes > (png_uint_32)65536L)
  173053. png_error(png_ptr, "This image requires a row greater than 64KB");
  173054. #endif
  173055. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173056. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173057. #ifdef PNG_MAX_MALLOC_64K
  173058. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173059. png_error(png_ptr, "This image requires a row greater than 64KB");
  173060. #endif
  173061. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173062. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173063. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173064. png_ptr->rowbytes + 1));
  173065. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173066. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173067. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173068. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173069. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173070. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173071. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173072. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173073. }
  173074. #endif /* PNG_READ_SUPPORTED */
  173075. /*** End of inlined file: pngrutil.c ***/
  173076. /*** Start of inlined file: pngset.c ***/
  173077. #define PNG_INTERNAL
  173078. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173079. #if defined(PNG_bKGD_SUPPORTED)
  173080. void PNGAPI
  173081. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173082. {
  173083. png_debug1(1, "in %s storage function\n", "bKGD");
  173084. if (png_ptr == NULL || info_ptr == NULL)
  173085. return;
  173086. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173087. info_ptr->valid |= PNG_INFO_bKGD;
  173088. }
  173089. #endif
  173090. #if defined(PNG_cHRM_SUPPORTED)
  173091. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173092. void PNGAPI
  173093. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173094. double white_x, double white_y, double red_x, double red_y,
  173095. double green_x, double green_y, double blue_x, double blue_y)
  173096. {
  173097. png_debug1(1, "in %s storage function\n", "cHRM");
  173098. if (png_ptr == NULL || info_ptr == NULL)
  173099. return;
  173100. if (white_x < 0.0 || white_y < 0.0 ||
  173101. red_x < 0.0 || red_y < 0.0 ||
  173102. green_x < 0.0 || green_y < 0.0 ||
  173103. blue_x < 0.0 || blue_y < 0.0)
  173104. {
  173105. png_warning(png_ptr,
  173106. "Ignoring attempt to set negative chromaticity value");
  173107. return;
  173108. }
  173109. if (white_x > 21474.83 || white_y > 21474.83 ||
  173110. red_x > 21474.83 || red_y > 21474.83 ||
  173111. green_x > 21474.83 || green_y > 21474.83 ||
  173112. blue_x > 21474.83 || blue_y > 21474.83)
  173113. {
  173114. png_warning(png_ptr,
  173115. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173116. return;
  173117. }
  173118. info_ptr->x_white = (float)white_x;
  173119. info_ptr->y_white = (float)white_y;
  173120. info_ptr->x_red = (float)red_x;
  173121. info_ptr->y_red = (float)red_y;
  173122. info_ptr->x_green = (float)green_x;
  173123. info_ptr->y_green = (float)green_y;
  173124. info_ptr->x_blue = (float)blue_x;
  173125. info_ptr->y_blue = (float)blue_y;
  173126. #ifdef PNG_FIXED_POINT_SUPPORTED
  173127. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173128. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173129. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173130. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173131. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173132. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173133. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173134. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173135. #endif
  173136. info_ptr->valid |= PNG_INFO_cHRM;
  173137. }
  173138. #endif
  173139. #ifdef PNG_FIXED_POINT_SUPPORTED
  173140. void PNGAPI
  173141. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173142. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173143. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173144. png_fixed_point blue_x, png_fixed_point blue_y)
  173145. {
  173146. png_debug1(1, "in %s storage function\n", "cHRM");
  173147. if (png_ptr == NULL || info_ptr == NULL)
  173148. return;
  173149. if (white_x < 0 || white_y < 0 ||
  173150. red_x < 0 || red_y < 0 ||
  173151. green_x < 0 || green_y < 0 ||
  173152. blue_x < 0 || blue_y < 0)
  173153. {
  173154. png_warning(png_ptr,
  173155. "Ignoring attempt to set negative chromaticity value");
  173156. return;
  173157. }
  173158. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173159. if (white_x > (double) PNG_UINT_31_MAX ||
  173160. white_y > (double) PNG_UINT_31_MAX ||
  173161. red_x > (double) PNG_UINT_31_MAX ||
  173162. red_y > (double) PNG_UINT_31_MAX ||
  173163. green_x > (double) PNG_UINT_31_MAX ||
  173164. green_y > (double) PNG_UINT_31_MAX ||
  173165. blue_x > (double) PNG_UINT_31_MAX ||
  173166. blue_y > (double) PNG_UINT_31_MAX)
  173167. #else
  173168. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173169. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173170. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173171. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173172. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173173. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173174. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173175. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173176. #endif
  173177. {
  173178. png_warning(png_ptr,
  173179. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173180. return;
  173181. }
  173182. info_ptr->int_x_white = white_x;
  173183. info_ptr->int_y_white = white_y;
  173184. info_ptr->int_x_red = red_x;
  173185. info_ptr->int_y_red = red_y;
  173186. info_ptr->int_x_green = green_x;
  173187. info_ptr->int_y_green = green_y;
  173188. info_ptr->int_x_blue = blue_x;
  173189. info_ptr->int_y_blue = blue_y;
  173190. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173191. info_ptr->x_white = (float)(white_x/100000.);
  173192. info_ptr->y_white = (float)(white_y/100000.);
  173193. info_ptr->x_red = (float)( red_x/100000.);
  173194. info_ptr->y_red = (float)( red_y/100000.);
  173195. info_ptr->x_green = (float)(green_x/100000.);
  173196. info_ptr->y_green = (float)(green_y/100000.);
  173197. info_ptr->x_blue = (float)( blue_x/100000.);
  173198. info_ptr->y_blue = (float)( blue_y/100000.);
  173199. #endif
  173200. info_ptr->valid |= PNG_INFO_cHRM;
  173201. }
  173202. #endif
  173203. #endif
  173204. #if defined(PNG_gAMA_SUPPORTED)
  173205. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173206. void PNGAPI
  173207. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173208. {
  173209. double gamma;
  173210. png_debug1(1, "in %s storage function\n", "gAMA");
  173211. if (png_ptr == NULL || info_ptr == NULL)
  173212. return;
  173213. if (file_gamma > 21474.83)
  173214. {
  173215. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173216. gamma=21474.83;
  173217. }
  173218. else
  173219. gamma=file_gamma;
  173220. info_ptr->gamma = (float)gamma;
  173221. #ifdef PNG_FIXED_POINT_SUPPORTED
  173222. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173223. #endif
  173224. info_ptr->valid |= PNG_INFO_gAMA;
  173225. if(gamma == 0.0)
  173226. png_warning(png_ptr, "Setting gamma=0");
  173227. }
  173228. #endif
  173229. void PNGAPI
  173230. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173231. int_gamma)
  173232. {
  173233. png_fixed_point gamma;
  173234. png_debug1(1, "in %s storage function\n", "gAMA");
  173235. if (png_ptr == NULL || info_ptr == NULL)
  173236. return;
  173237. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173238. {
  173239. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173240. gamma=PNG_UINT_31_MAX;
  173241. }
  173242. else
  173243. {
  173244. if (int_gamma < 0)
  173245. {
  173246. png_warning(png_ptr, "Setting negative gamma to zero");
  173247. gamma=0;
  173248. }
  173249. else
  173250. gamma=int_gamma;
  173251. }
  173252. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173253. info_ptr->gamma = (float)(gamma/100000.);
  173254. #endif
  173255. #ifdef PNG_FIXED_POINT_SUPPORTED
  173256. info_ptr->int_gamma = gamma;
  173257. #endif
  173258. info_ptr->valid |= PNG_INFO_gAMA;
  173259. if(gamma == 0)
  173260. png_warning(png_ptr, "Setting gamma=0");
  173261. }
  173262. #endif
  173263. #if defined(PNG_hIST_SUPPORTED)
  173264. void PNGAPI
  173265. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173266. {
  173267. int i;
  173268. png_debug1(1, "in %s storage function\n", "hIST");
  173269. if (png_ptr == NULL || info_ptr == NULL)
  173270. return;
  173271. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173272. > PNG_MAX_PALETTE_LENGTH)
  173273. {
  173274. png_warning(png_ptr,
  173275. "Invalid palette size, hIST allocation skipped.");
  173276. return;
  173277. }
  173278. #ifdef PNG_FREE_ME_SUPPORTED
  173279. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173280. #endif
  173281. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173282. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173283. if (png_ptr->hist == NULL)
  173284. {
  173285. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173286. return;
  173287. }
  173288. for (i = 0; i < info_ptr->num_palette; i++)
  173289. png_ptr->hist[i] = hist[i];
  173290. info_ptr->hist = png_ptr->hist;
  173291. info_ptr->valid |= PNG_INFO_hIST;
  173292. #ifdef PNG_FREE_ME_SUPPORTED
  173293. info_ptr->free_me |= PNG_FREE_HIST;
  173294. #else
  173295. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173296. #endif
  173297. }
  173298. #endif
  173299. void PNGAPI
  173300. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173301. png_uint_32 width, png_uint_32 height, int bit_depth,
  173302. int color_type, int interlace_type, int compression_type,
  173303. int filter_type)
  173304. {
  173305. png_debug1(1, "in %s storage function\n", "IHDR");
  173306. if (png_ptr == NULL || info_ptr == NULL)
  173307. return;
  173308. if (width == 0 || height == 0)
  173309. png_error(png_ptr, "Image width or height is zero in IHDR");
  173310. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173311. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173312. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173313. #else
  173314. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173315. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173316. #endif
  173317. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173318. png_error(png_ptr, "Invalid image size in IHDR");
  173319. if ( width > (PNG_UINT_32_MAX
  173320. >> 3) /* 8-byte RGBA pixels */
  173321. - 64 /* bigrowbuf hack */
  173322. - 1 /* filter byte */
  173323. - 7*8 /* rounding of width to multiple of 8 pixels */
  173324. - 8) /* extra max_pixel_depth pad */
  173325. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173326. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173327. bit_depth != 8 && bit_depth != 16)
  173328. png_error(png_ptr, "Invalid bit depth in IHDR");
  173329. if (color_type < 0 || color_type == 1 ||
  173330. color_type == 5 || color_type > 6)
  173331. png_error(png_ptr, "Invalid color type in IHDR");
  173332. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173333. ((color_type == PNG_COLOR_TYPE_RGB ||
  173334. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173335. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173336. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173337. if (interlace_type >= PNG_INTERLACE_LAST)
  173338. png_error(png_ptr, "Unknown interlace method in IHDR");
  173339. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173340. png_error(png_ptr, "Unknown compression method in IHDR");
  173341. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173342. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173343. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173344. if(filter_type != PNG_FILTER_TYPE_BASE)
  173345. {
  173346. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173347. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173348. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173349. (color_type == PNG_COLOR_TYPE_RGB ||
  173350. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173351. png_error(png_ptr, "Unknown filter method in IHDR");
  173352. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173353. png_warning(png_ptr, "Invalid filter method in IHDR");
  173354. }
  173355. #else
  173356. if(filter_type != PNG_FILTER_TYPE_BASE)
  173357. png_error(png_ptr, "Unknown filter method in IHDR");
  173358. #endif
  173359. info_ptr->width = width;
  173360. info_ptr->height = height;
  173361. info_ptr->bit_depth = (png_byte)bit_depth;
  173362. info_ptr->color_type =(png_byte) color_type;
  173363. info_ptr->compression_type = (png_byte)compression_type;
  173364. info_ptr->filter_type = (png_byte)filter_type;
  173365. info_ptr->interlace_type = (png_byte)interlace_type;
  173366. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173367. info_ptr->channels = 1;
  173368. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173369. info_ptr->channels = 3;
  173370. else
  173371. info_ptr->channels = 1;
  173372. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173373. info_ptr->channels++;
  173374. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173375. if (width > (PNG_UINT_32_MAX
  173376. >> 3) /* 8-byte RGBA pixels */
  173377. - 64 /* bigrowbuf hack */
  173378. - 1 /* filter byte */
  173379. - 7*8 /* rounding of width to multiple of 8 pixels */
  173380. - 8) /* extra max_pixel_depth pad */
  173381. info_ptr->rowbytes = (png_size_t)0;
  173382. else
  173383. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173384. }
  173385. #if defined(PNG_oFFs_SUPPORTED)
  173386. void PNGAPI
  173387. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173388. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173389. {
  173390. png_debug1(1, "in %s storage function\n", "oFFs");
  173391. if (png_ptr == NULL || info_ptr == NULL)
  173392. return;
  173393. info_ptr->x_offset = offset_x;
  173394. info_ptr->y_offset = offset_y;
  173395. info_ptr->offset_unit_type = (png_byte)unit_type;
  173396. info_ptr->valid |= PNG_INFO_oFFs;
  173397. }
  173398. #endif
  173399. #if defined(PNG_pCAL_SUPPORTED)
  173400. void PNGAPI
  173401. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173402. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173403. png_charp units, png_charpp params)
  173404. {
  173405. png_uint_32 length;
  173406. int i;
  173407. png_debug1(1, "in %s storage function\n", "pCAL");
  173408. if (png_ptr == NULL || info_ptr == NULL)
  173409. return;
  173410. length = png_strlen(purpose) + 1;
  173411. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173412. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173413. if (info_ptr->pcal_purpose == NULL)
  173414. {
  173415. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173416. return;
  173417. }
  173418. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173419. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173420. info_ptr->pcal_X0 = X0;
  173421. info_ptr->pcal_X1 = X1;
  173422. info_ptr->pcal_type = (png_byte)type;
  173423. info_ptr->pcal_nparams = (png_byte)nparams;
  173424. length = png_strlen(units) + 1;
  173425. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173426. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173427. if (info_ptr->pcal_units == NULL)
  173428. {
  173429. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173430. return;
  173431. }
  173432. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173433. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173434. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173435. if (info_ptr->pcal_params == NULL)
  173436. {
  173437. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173438. return;
  173439. }
  173440. info_ptr->pcal_params[nparams] = NULL;
  173441. for (i = 0; i < nparams; i++)
  173442. {
  173443. length = png_strlen(params[i]) + 1;
  173444. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173445. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173446. if (info_ptr->pcal_params[i] == NULL)
  173447. {
  173448. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173449. return;
  173450. }
  173451. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173452. }
  173453. info_ptr->valid |= PNG_INFO_pCAL;
  173454. #ifdef PNG_FREE_ME_SUPPORTED
  173455. info_ptr->free_me |= PNG_FREE_PCAL;
  173456. #endif
  173457. }
  173458. #endif
  173459. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173460. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173461. void PNGAPI
  173462. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173463. int unit, double width, double height)
  173464. {
  173465. png_debug1(1, "in %s storage function\n", "sCAL");
  173466. if (png_ptr == NULL || info_ptr == NULL)
  173467. return;
  173468. info_ptr->scal_unit = (png_byte)unit;
  173469. info_ptr->scal_pixel_width = width;
  173470. info_ptr->scal_pixel_height = height;
  173471. info_ptr->valid |= PNG_INFO_sCAL;
  173472. }
  173473. #else
  173474. #ifdef PNG_FIXED_POINT_SUPPORTED
  173475. void PNGAPI
  173476. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173477. int unit, png_charp swidth, png_charp sheight)
  173478. {
  173479. png_uint_32 length;
  173480. png_debug1(1, "in %s storage function\n", "sCAL");
  173481. if (png_ptr == NULL || info_ptr == NULL)
  173482. return;
  173483. info_ptr->scal_unit = (png_byte)unit;
  173484. length = png_strlen(swidth) + 1;
  173485. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173486. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173487. if (info_ptr->scal_s_width == NULL)
  173488. {
  173489. png_warning(png_ptr,
  173490. "Memory allocation failed while processing sCAL.");
  173491. }
  173492. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173493. length = png_strlen(sheight) + 1;
  173494. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173495. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173496. if (info_ptr->scal_s_height == NULL)
  173497. {
  173498. png_free (png_ptr, info_ptr->scal_s_width);
  173499. png_warning(png_ptr,
  173500. "Memory allocation failed while processing sCAL.");
  173501. }
  173502. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173503. info_ptr->valid |= PNG_INFO_sCAL;
  173504. #ifdef PNG_FREE_ME_SUPPORTED
  173505. info_ptr->free_me |= PNG_FREE_SCAL;
  173506. #endif
  173507. }
  173508. #endif
  173509. #endif
  173510. #endif
  173511. #if defined(PNG_pHYs_SUPPORTED)
  173512. void PNGAPI
  173513. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173514. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173515. {
  173516. png_debug1(1, "in %s storage function\n", "pHYs");
  173517. if (png_ptr == NULL || info_ptr == NULL)
  173518. return;
  173519. info_ptr->x_pixels_per_unit = res_x;
  173520. info_ptr->y_pixels_per_unit = res_y;
  173521. info_ptr->phys_unit_type = (png_byte)unit_type;
  173522. info_ptr->valid |= PNG_INFO_pHYs;
  173523. }
  173524. #endif
  173525. void PNGAPI
  173526. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173527. png_colorp palette, int num_palette)
  173528. {
  173529. png_debug1(1, "in %s storage function\n", "PLTE");
  173530. if (png_ptr == NULL || info_ptr == NULL)
  173531. return;
  173532. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173533. {
  173534. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173535. png_error(png_ptr, "Invalid palette length");
  173536. else
  173537. {
  173538. png_warning(png_ptr, "Invalid palette length");
  173539. return;
  173540. }
  173541. }
  173542. #ifdef PNG_FREE_ME_SUPPORTED
  173543. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173544. #endif
  173545. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173546. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173547. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173548. png_sizeof(png_color));
  173549. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173550. info_ptr->palette = png_ptr->palette;
  173551. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173552. #ifdef PNG_FREE_ME_SUPPORTED
  173553. info_ptr->free_me |= PNG_FREE_PLTE;
  173554. #else
  173555. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173556. #endif
  173557. info_ptr->valid |= PNG_INFO_PLTE;
  173558. }
  173559. #if defined(PNG_sBIT_SUPPORTED)
  173560. void PNGAPI
  173561. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173562. png_color_8p sig_bit)
  173563. {
  173564. png_debug1(1, "in %s storage function\n", "sBIT");
  173565. if (png_ptr == NULL || info_ptr == NULL)
  173566. return;
  173567. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173568. info_ptr->valid |= PNG_INFO_sBIT;
  173569. }
  173570. #endif
  173571. #if defined(PNG_sRGB_SUPPORTED)
  173572. void PNGAPI
  173573. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173574. {
  173575. png_debug1(1, "in %s storage function\n", "sRGB");
  173576. if (png_ptr == NULL || info_ptr == NULL)
  173577. return;
  173578. info_ptr->srgb_intent = (png_byte)intent;
  173579. info_ptr->valid |= PNG_INFO_sRGB;
  173580. }
  173581. void PNGAPI
  173582. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173583. int intent)
  173584. {
  173585. #if defined(PNG_gAMA_SUPPORTED)
  173586. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173587. float file_gamma;
  173588. #endif
  173589. #ifdef PNG_FIXED_POINT_SUPPORTED
  173590. png_fixed_point int_file_gamma;
  173591. #endif
  173592. #endif
  173593. #if defined(PNG_cHRM_SUPPORTED)
  173594. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173595. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173596. #endif
  173597. #ifdef PNG_FIXED_POINT_SUPPORTED
  173598. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173599. int_green_y, int_blue_x, int_blue_y;
  173600. #endif
  173601. #endif
  173602. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173603. if (png_ptr == NULL || info_ptr == NULL)
  173604. return;
  173605. png_set_sRGB(png_ptr, info_ptr, intent);
  173606. #if defined(PNG_gAMA_SUPPORTED)
  173607. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173608. file_gamma = (float).45455;
  173609. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173610. #endif
  173611. #ifdef PNG_FIXED_POINT_SUPPORTED
  173612. int_file_gamma = 45455L;
  173613. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173614. #endif
  173615. #endif
  173616. #if defined(PNG_cHRM_SUPPORTED)
  173617. #ifdef PNG_FIXED_POINT_SUPPORTED
  173618. int_white_x = 31270L;
  173619. int_white_y = 32900L;
  173620. int_red_x = 64000L;
  173621. int_red_y = 33000L;
  173622. int_green_x = 30000L;
  173623. int_green_y = 60000L;
  173624. int_blue_x = 15000L;
  173625. int_blue_y = 6000L;
  173626. png_set_cHRM_fixed(png_ptr, info_ptr,
  173627. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173628. int_blue_x, int_blue_y);
  173629. #endif
  173630. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173631. white_x = (float).3127;
  173632. white_y = (float).3290;
  173633. red_x = (float).64;
  173634. red_y = (float).33;
  173635. green_x = (float).30;
  173636. green_y = (float).60;
  173637. blue_x = (float).15;
  173638. blue_y = (float).06;
  173639. png_set_cHRM(png_ptr, info_ptr,
  173640. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173641. #endif
  173642. #endif
  173643. }
  173644. #endif
  173645. #if defined(PNG_iCCP_SUPPORTED)
  173646. void PNGAPI
  173647. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173648. png_charp name, int compression_type,
  173649. png_charp profile, png_uint_32 proflen)
  173650. {
  173651. png_charp new_iccp_name;
  173652. png_charp new_iccp_profile;
  173653. png_debug1(1, "in %s storage function\n", "iCCP");
  173654. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173655. return;
  173656. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173657. if (new_iccp_name == NULL)
  173658. {
  173659. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173660. return;
  173661. }
  173662. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173663. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173664. if (new_iccp_profile == NULL)
  173665. {
  173666. png_free (png_ptr, new_iccp_name);
  173667. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173668. return;
  173669. }
  173670. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173671. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173672. info_ptr->iccp_proflen = proflen;
  173673. info_ptr->iccp_name = new_iccp_name;
  173674. info_ptr->iccp_profile = new_iccp_profile;
  173675. info_ptr->iccp_compression = (png_byte)compression_type;
  173676. #ifdef PNG_FREE_ME_SUPPORTED
  173677. info_ptr->free_me |= PNG_FREE_ICCP;
  173678. #endif
  173679. info_ptr->valid |= PNG_INFO_iCCP;
  173680. }
  173681. #endif
  173682. #if defined(PNG_TEXT_SUPPORTED)
  173683. void PNGAPI
  173684. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173685. int num_text)
  173686. {
  173687. int ret;
  173688. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173689. if (ret)
  173690. png_error(png_ptr, "Insufficient memory to store text");
  173691. }
  173692. int /* PRIVATE */
  173693. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173694. int num_text)
  173695. {
  173696. int i;
  173697. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173698. "text" : (png_const_charp)png_ptr->chunk_name));
  173699. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173700. return(0);
  173701. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173702. {
  173703. if (info_ptr->text != NULL)
  173704. {
  173705. png_textp old_text;
  173706. int old_max;
  173707. old_max = info_ptr->max_text;
  173708. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  173709. old_text = info_ptr->text;
  173710. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173711. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173712. if (info_ptr->text == NULL)
  173713. {
  173714. png_free(png_ptr, old_text);
  173715. return(1);
  173716. }
  173717. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  173718. png_sizeof(png_text)));
  173719. png_free(png_ptr, old_text);
  173720. }
  173721. else
  173722. {
  173723. info_ptr->max_text = num_text + 8;
  173724. info_ptr->num_text = 0;
  173725. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173726. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173727. if (info_ptr->text == NULL)
  173728. return(1);
  173729. #ifdef PNG_FREE_ME_SUPPORTED
  173730. info_ptr->free_me |= PNG_FREE_TEXT;
  173731. #endif
  173732. }
  173733. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  173734. info_ptr->max_text);
  173735. }
  173736. for (i = 0; i < num_text; i++)
  173737. {
  173738. png_size_t text_length,key_len;
  173739. png_size_t lang_len,lang_key_len;
  173740. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  173741. if (text_ptr[i].key == NULL)
  173742. continue;
  173743. key_len = png_strlen(text_ptr[i].key);
  173744. if(text_ptr[i].compression <= 0)
  173745. {
  173746. lang_len = 0;
  173747. lang_key_len = 0;
  173748. }
  173749. else
  173750. #ifdef PNG_iTXt_SUPPORTED
  173751. {
  173752. if (text_ptr[i].lang != NULL)
  173753. lang_len = png_strlen(text_ptr[i].lang);
  173754. else
  173755. lang_len = 0;
  173756. if (text_ptr[i].lang_key != NULL)
  173757. lang_key_len = png_strlen(text_ptr[i].lang_key);
  173758. else
  173759. lang_key_len = 0;
  173760. }
  173761. #else
  173762. {
  173763. png_warning(png_ptr, "iTXt chunk not supported.");
  173764. continue;
  173765. }
  173766. #endif
  173767. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  173768. {
  173769. text_length = 0;
  173770. #ifdef PNG_iTXt_SUPPORTED
  173771. if(text_ptr[i].compression > 0)
  173772. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  173773. else
  173774. #endif
  173775. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  173776. }
  173777. else
  173778. {
  173779. text_length = png_strlen(text_ptr[i].text);
  173780. textp->compression = text_ptr[i].compression;
  173781. }
  173782. textp->key = (png_charp)png_malloc_warn(png_ptr,
  173783. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  173784. if (textp->key == NULL)
  173785. return(1);
  173786. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  173787. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  173788. (int)textp->key);
  173789. png_memcpy(textp->key, text_ptr[i].key,
  173790. (png_size_t)(key_len));
  173791. *(textp->key+key_len) = '\0';
  173792. #ifdef PNG_iTXt_SUPPORTED
  173793. if (text_ptr[i].compression > 0)
  173794. {
  173795. textp->lang=textp->key + key_len + 1;
  173796. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  173797. *(textp->lang+lang_len) = '\0';
  173798. textp->lang_key=textp->lang + lang_len + 1;
  173799. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  173800. *(textp->lang_key+lang_key_len) = '\0';
  173801. textp->text=textp->lang_key + lang_key_len + 1;
  173802. }
  173803. else
  173804. #endif
  173805. {
  173806. #ifdef PNG_iTXt_SUPPORTED
  173807. textp->lang=NULL;
  173808. textp->lang_key=NULL;
  173809. #endif
  173810. textp->text=textp->key + key_len + 1;
  173811. }
  173812. if(text_length)
  173813. png_memcpy(textp->text, text_ptr[i].text,
  173814. (png_size_t)(text_length));
  173815. *(textp->text+text_length) = '\0';
  173816. #ifdef PNG_iTXt_SUPPORTED
  173817. if(textp->compression > 0)
  173818. {
  173819. textp->text_length = 0;
  173820. textp->itxt_length = text_length;
  173821. }
  173822. else
  173823. #endif
  173824. {
  173825. textp->text_length = text_length;
  173826. #ifdef PNG_iTXt_SUPPORTED
  173827. textp->itxt_length = 0;
  173828. #endif
  173829. }
  173830. info_ptr->num_text++;
  173831. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  173832. }
  173833. return(0);
  173834. }
  173835. #endif
  173836. #if defined(PNG_tIME_SUPPORTED)
  173837. void PNGAPI
  173838. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  173839. {
  173840. png_debug1(1, "in %s storage function\n", "tIME");
  173841. if (png_ptr == NULL || info_ptr == NULL ||
  173842. (png_ptr->mode & PNG_WROTE_tIME))
  173843. return;
  173844. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  173845. info_ptr->valid |= PNG_INFO_tIME;
  173846. }
  173847. #endif
  173848. #if defined(PNG_tRNS_SUPPORTED)
  173849. void PNGAPI
  173850. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  173851. png_bytep trans, int num_trans, png_color_16p trans_values)
  173852. {
  173853. png_debug1(1, "in %s storage function\n", "tRNS");
  173854. if (png_ptr == NULL || info_ptr == NULL)
  173855. return;
  173856. if (trans != NULL)
  173857. {
  173858. #ifdef PNG_FREE_ME_SUPPORTED
  173859. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  173860. #endif
  173861. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  173862. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  173863. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  173864. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  173865. #ifdef PNG_FREE_ME_SUPPORTED
  173866. info_ptr->free_me |= PNG_FREE_TRNS;
  173867. #else
  173868. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  173869. #endif
  173870. }
  173871. if (trans_values != NULL)
  173872. {
  173873. png_memcpy(&(info_ptr->trans_values), trans_values,
  173874. png_sizeof(png_color_16));
  173875. if (num_trans == 0)
  173876. num_trans = 1;
  173877. }
  173878. info_ptr->num_trans = (png_uint_16)num_trans;
  173879. info_ptr->valid |= PNG_INFO_tRNS;
  173880. }
  173881. #endif
  173882. #if defined(PNG_sPLT_SUPPORTED)
  173883. void PNGAPI
  173884. png_set_sPLT(png_structp png_ptr,
  173885. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  173886. {
  173887. png_sPLT_tp np;
  173888. int i;
  173889. if (png_ptr == NULL || info_ptr == NULL)
  173890. return;
  173891. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  173892. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  173893. if (np == NULL)
  173894. {
  173895. png_warning(png_ptr, "No memory for sPLT palettes.");
  173896. return;
  173897. }
  173898. png_memcpy(np, info_ptr->splt_palettes,
  173899. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  173900. png_free(png_ptr, info_ptr->splt_palettes);
  173901. info_ptr->splt_palettes=NULL;
  173902. for (i = 0; i < nentries; i++)
  173903. {
  173904. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  173905. png_sPLT_tp from = entries + i;
  173906. to->name = (png_charp)png_malloc_warn(png_ptr,
  173907. png_strlen(from->name) + 1);
  173908. if (to->name == NULL)
  173909. {
  173910. png_warning(png_ptr,
  173911. "Out of memory while processing sPLT chunk");
  173912. }
  173913. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  173914. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  173915. from->nentries * png_sizeof(png_sPLT_entry));
  173916. png_memcpy(to->entries, from->entries,
  173917. from->nentries * png_sizeof(png_sPLT_entry));
  173918. if (to->entries == NULL)
  173919. {
  173920. png_warning(png_ptr,
  173921. "Out of memory while processing sPLT chunk");
  173922. png_free(png_ptr,to->name);
  173923. to->name = NULL;
  173924. }
  173925. to->nentries = from->nentries;
  173926. to->depth = from->depth;
  173927. }
  173928. info_ptr->splt_palettes = np;
  173929. info_ptr->splt_palettes_num += nentries;
  173930. info_ptr->valid |= PNG_INFO_sPLT;
  173931. #ifdef PNG_FREE_ME_SUPPORTED
  173932. info_ptr->free_me |= PNG_FREE_SPLT;
  173933. #endif
  173934. }
  173935. #endif /* PNG_sPLT_SUPPORTED */
  173936. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  173937. void PNGAPI
  173938. png_set_unknown_chunks(png_structp png_ptr,
  173939. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  173940. {
  173941. png_unknown_chunkp np;
  173942. int i;
  173943. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  173944. return;
  173945. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  173946. (info_ptr->unknown_chunks_num + num_unknowns) *
  173947. png_sizeof(png_unknown_chunk));
  173948. if (np == NULL)
  173949. {
  173950. png_warning(png_ptr,
  173951. "Out of memory while processing unknown chunk.");
  173952. return;
  173953. }
  173954. png_memcpy(np, info_ptr->unknown_chunks,
  173955. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  173956. png_free(png_ptr, info_ptr->unknown_chunks);
  173957. info_ptr->unknown_chunks=NULL;
  173958. for (i = 0; i < num_unknowns; i++)
  173959. {
  173960. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  173961. png_unknown_chunkp from = unknowns + i;
  173962. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  173963. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  173964. if (to->data == NULL)
  173965. {
  173966. png_warning(png_ptr,
  173967. "Out of memory while processing unknown chunk.");
  173968. }
  173969. else
  173970. {
  173971. png_memcpy(to->data, from->data, from->size);
  173972. to->size = from->size;
  173973. to->location = (png_byte)(png_ptr->mode & 0xff);
  173974. }
  173975. }
  173976. info_ptr->unknown_chunks = np;
  173977. info_ptr->unknown_chunks_num += num_unknowns;
  173978. #ifdef PNG_FREE_ME_SUPPORTED
  173979. info_ptr->free_me |= PNG_FREE_UNKN;
  173980. #endif
  173981. }
  173982. void PNGAPI
  173983. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  173984. int chunk, int location)
  173985. {
  173986. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  173987. (int)info_ptr->unknown_chunks_num)
  173988. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  173989. }
  173990. #endif
  173991. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  173992. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  173993. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  173994. void PNGAPI
  173995. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  173996. {
  173997. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  173998. if (png_ptr == NULL)
  173999. return;
  174000. png_ptr->mng_features_permitted = (png_byte)
  174001. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174002. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174003. }
  174004. #endif
  174005. #endif
  174006. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174007. png_uint_32 PNGAPI
  174008. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174009. {
  174010. png_debug(1, "in png_permit_mng_features\n");
  174011. if (png_ptr == NULL)
  174012. return (png_uint_32)0;
  174013. png_ptr->mng_features_permitted =
  174014. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174015. return (png_uint_32)png_ptr->mng_features_permitted;
  174016. }
  174017. #endif
  174018. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174019. void PNGAPI
  174020. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174021. chunk_list, int num_chunks)
  174022. {
  174023. png_bytep new_list, p;
  174024. int i, old_num_chunks;
  174025. if (png_ptr == NULL)
  174026. return;
  174027. if (num_chunks == 0)
  174028. {
  174029. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174030. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174031. else
  174032. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174033. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174034. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174035. else
  174036. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174037. return;
  174038. }
  174039. if (chunk_list == NULL)
  174040. return;
  174041. old_num_chunks=png_ptr->num_chunk_list;
  174042. new_list=(png_bytep)png_malloc(png_ptr,
  174043. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174044. if(png_ptr->chunk_list != NULL)
  174045. {
  174046. png_memcpy(new_list, png_ptr->chunk_list,
  174047. (png_size_t)(5*old_num_chunks));
  174048. png_free(png_ptr, png_ptr->chunk_list);
  174049. png_ptr->chunk_list=NULL;
  174050. }
  174051. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174052. (png_size_t)(5*num_chunks));
  174053. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174054. *p=(png_byte)keep;
  174055. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174056. png_ptr->chunk_list=new_list;
  174057. #ifdef PNG_FREE_ME_SUPPORTED
  174058. png_ptr->free_me |= PNG_FREE_LIST;
  174059. #endif
  174060. }
  174061. #endif
  174062. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174063. void PNGAPI
  174064. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174065. png_user_chunk_ptr read_user_chunk_fn)
  174066. {
  174067. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174068. if (png_ptr == NULL)
  174069. return;
  174070. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174071. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174072. }
  174073. #endif
  174074. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174075. void PNGAPI
  174076. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174077. {
  174078. png_debug1(1, "in %s storage function\n", "rows");
  174079. if (png_ptr == NULL || info_ptr == NULL)
  174080. return;
  174081. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174082. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174083. info_ptr->row_pointers = row_pointers;
  174084. if(row_pointers)
  174085. info_ptr->valid |= PNG_INFO_IDAT;
  174086. }
  174087. #endif
  174088. #ifdef PNG_WRITE_SUPPORTED
  174089. void PNGAPI
  174090. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174091. {
  174092. if (png_ptr == NULL)
  174093. return;
  174094. if(png_ptr->zbuf)
  174095. png_free(png_ptr, png_ptr->zbuf);
  174096. png_ptr->zbuf_size = (png_size_t)size;
  174097. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174098. png_ptr->zstream.next_out = png_ptr->zbuf;
  174099. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174100. }
  174101. #endif
  174102. void PNGAPI
  174103. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174104. {
  174105. if (png_ptr && info_ptr)
  174106. info_ptr->valid &= ~(mask);
  174107. }
  174108. #ifndef PNG_1_0_X
  174109. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174110. void PNGAPI
  174111. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174112. {
  174113. if (png_ptr != NULL)
  174114. png_ptr->asm_flags = 0;
  174115. }
  174116. void PNGAPI
  174117. png_set_mmx_thresholds (png_structp png_ptr,
  174118. png_byte mmx_bitdepth_threshold,
  174119. png_uint_32 mmx_rowbytes_threshold)
  174120. {
  174121. if (png_ptr == NULL)
  174122. return;
  174123. }
  174124. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174125. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174126. void PNGAPI
  174127. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174128. png_uint_32 user_height_max)
  174129. {
  174130. if(png_ptr == NULL) return;
  174131. png_ptr->user_width_max = user_width_max;
  174132. png_ptr->user_height_max = user_height_max;
  174133. }
  174134. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174135. #endif /* ?PNG_1_0_X */
  174136. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174137. /*** End of inlined file: pngset.c ***/
  174138. /*** Start of inlined file: pngtrans.c ***/
  174139. #define PNG_INTERNAL
  174140. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174141. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174142. void PNGAPI
  174143. png_set_bgr(png_structp png_ptr)
  174144. {
  174145. png_debug(1, "in png_set_bgr\n");
  174146. if(png_ptr == NULL) return;
  174147. png_ptr->transformations |= PNG_BGR;
  174148. }
  174149. #endif
  174150. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174151. void PNGAPI
  174152. png_set_swap(png_structp png_ptr)
  174153. {
  174154. png_debug(1, "in png_set_swap\n");
  174155. if(png_ptr == NULL) return;
  174156. if (png_ptr->bit_depth == 16)
  174157. png_ptr->transformations |= PNG_SWAP_BYTES;
  174158. }
  174159. #endif
  174160. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174161. void PNGAPI
  174162. png_set_packing(png_structp png_ptr)
  174163. {
  174164. png_debug(1, "in png_set_packing\n");
  174165. if(png_ptr == NULL) return;
  174166. if (png_ptr->bit_depth < 8)
  174167. {
  174168. png_ptr->transformations |= PNG_PACK;
  174169. png_ptr->usr_bit_depth = 8;
  174170. }
  174171. }
  174172. #endif
  174173. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174174. void PNGAPI
  174175. png_set_packswap(png_structp png_ptr)
  174176. {
  174177. png_debug(1, "in png_set_packswap\n");
  174178. if(png_ptr == NULL) return;
  174179. if (png_ptr->bit_depth < 8)
  174180. png_ptr->transformations |= PNG_PACKSWAP;
  174181. }
  174182. #endif
  174183. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174184. void PNGAPI
  174185. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174186. {
  174187. png_debug(1, "in png_set_shift\n");
  174188. if(png_ptr == NULL) return;
  174189. png_ptr->transformations |= PNG_SHIFT;
  174190. png_ptr->shift = *true_bits;
  174191. }
  174192. #endif
  174193. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174194. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174195. int PNGAPI
  174196. png_set_interlace_handling(png_structp png_ptr)
  174197. {
  174198. png_debug(1, "in png_set_interlace handling\n");
  174199. if (png_ptr && png_ptr->interlaced)
  174200. {
  174201. png_ptr->transformations |= PNG_INTERLACE;
  174202. return (7);
  174203. }
  174204. return (1);
  174205. }
  174206. #endif
  174207. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174208. void PNGAPI
  174209. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174210. {
  174211. png_debug(1, "in png_set_filler\n");
  174212. if(png_ptr == NULL) return;
  174213. png_ptr->transformations |= PNG_FILLER;
  174214. png_ptr->filler = (png_byte)filler;
  174215. if (filler_loc == PNG_FILLER_AFTER)
  174216. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174217. else
  174218. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174219. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174220. {
  174221. png_ptr->usr_channels = 4;
  174222. }
  174223. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174224. {
  174225. png_ptr->usr_channels = 2;
  174226. }
  174227. }
  174228. #if !defined(PNG_1_0_X)
  174229. void PNGAPI
  174230. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174231. {
  174232. png_debug(1, "in png_set_add_alpha\n");
  174233. if(png_ptr == NULL) return;
  174234. png_set_filler(png_ptr, filler, filler_loc);
  174235. png_ptr->transformations |= PNG_ADD_ALPHA;
  174236. }
  174237. #endif
  174238. #endif
  174239. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174240. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174241. void PNGAPI
  174242. png_set_swap_alpha(png_structp png_ptr)
  174243. {
  174244. png_debug(1, "in png_set_swap_alpha\n");
  174245. if(png_ptr == NULL) return;
  174246. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174247. }
  174248. #endif
  174249. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174250. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174251. void PNGAPI
  174252. png_set_invert_alpha(png_structp png_ptr)
  174253. {
  174254. png_debug(1, "in png_set_invert_alpha\n");
  174255. if(png_ptr == NULL) return;
  174256. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174257. }
  174258. #endif
  174259. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174260. void PNGAPI
  174261. png_set_invert_mono(png_structp png_ptr)
  174262. {
  174263. png_debug(1, "in png_set_invert_mono\n");
  174264. if(png_ptr == NULL) return;
  174265. png_ptr->transformations |= PNG_INVERT_MONO;
  174266. }
  174267. void /* PRIVATE */
  174268. png_do_invert(png_row_infop row_info, png_bytep row)
  174269. {
  174270. png_debug(1, "in png_do_invert\n");
  174271. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174272. if (row == NULL || row_info == NULL)
  174273. return;
  174274. #endif
  174275. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174276. {
  174277. png_bytep rp = row;
  174278. png_uint_32 i;
  174279. png_uint_32 istop = row_info->rowbytes;
  174280. for (i = 0; i < istop; i++)
  174281. {
  174282. *rp = (png_byte)(~(*rp));
  174283. rp++;
  174284. }
  174285. }
  174286. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174287. row_info->bit_depth == 8)
  174288. {
  174289. png_bytep rp = row;
  174290. png_uint_32 i;
  174291. png_uint_32 istop = row_info->rowbytes;
  174292. for (i = 0; i < istop; i+=2)
  174293. {
  174294. *rp = (png_byte)(~(*rp));
  174295. rp+=2;
  174296. }
  174297. }
  174298. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174299. row_info->bit_depth == 16)
  174300. {
  174301. png_bytep rp = row;
  174302. png_uint_32 i;
  174303. png_uint_32 istop = row_info->rowbytes;
  174304. for (i = 0; i < istop; i+=4)
  174305. {
  174306. *rp = (png_byte)(~(*rp));
  174307. *(rp+1) = (png_byte)(~(*(rp+1)));
  174308. rp+=4;
  174309. }
  174310. }
  174311. }
  174312. #endif
  174313. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174314. void /* PRIVATE */
  174315. png_do_swap(png_row_infop row_info, png_bytep row)
  174316. {
  174317. png_debug(1, "in png_do_swap\n");
  174318. if (
  174319. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174320. row != NULL && row_info != NULL &&
  174321. #endif
  174322. row_info->bit_depth == 16)
  174323. {
  174324. png_bytep rp = row;
  174325. png_uint_32 i;
  174326. png_uint_32 istop= row_info->width * row_info->channels;
  174327. for (i = 0; i < istop; i++, rp += 2)
  174328. {
  174329. png_byte t = *rp;
  174330. *rp = *(rp + 1);
  174331. *(rp + 1) = t;
  174332. }
  174333. }
  174334. }
  174335. #endif
  174336. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174337. static PNG_CONST png_byte onebppswaptable[256] = {
  174338. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174339. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174340. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174341. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174342. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174343. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174344. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174345. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174346. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174347. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174348. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174349. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174350. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174351. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174352. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174353. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174354. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174355. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174356. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174357. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174358. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174359. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174360. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174361. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174362. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174363. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174364. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174365. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174366. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174367. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174368. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174369. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174370. };
  174371. static PNG_CONST png_byte twobppswaptable[256] = {
  174372. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174373. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174374. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174375. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174376. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174377. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174378. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174379. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174380. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174381. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174382. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174383. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174384. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174385. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174386. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174387. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174388. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174389. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174390. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174391. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174392. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174393. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174394. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174395. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174396. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174397. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174398. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174399. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174400. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174401. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174402. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174403. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174404. };
  174405. static PNG_CONST png_byte fourbppswaptable[256] = {
  174406. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174407. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174408. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174409. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174410. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174411. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174412. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174413. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174414. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174415. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174416. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174417. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174418. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174419. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174420. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174421. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174422. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174423. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174424. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174425. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174426. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174427. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174428. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174429. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174430. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174431. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174432. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174433. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174434. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174435. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174436. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174437. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174438. };
  174439. void /* PRIVATE */
  174440. png_do_packswap(png_row_infop row_info, png_bytep row)
  174441. {
  174442. png_debug(1, "in png_do_packswap\n");
  174443. if (
  174444. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174445. row != NULL && row_info != NULL &&
  174446. #endif
  174447. row_info->bit_depth < 8)
  174448. {
  174449. png_bytep rp, end, table;
  174450. end = row + row_info->rowbytes;
  174451. if (row_info->bit_depth == 1)
  174452. table = (png_bytep)onebppswaptable;
  174453. else if (row_info->bit_depth == 2)
  174454. table = (png_bytep)twobppswaptable;
  174455. else if (row_info->bit_depth == 4)
  174456. table = (png_bytep)fourbppswaptable;
  174457. else
  174458. return;
  174459. for (rp = row; rp < end; rp++)
  174460. *rp = table[*rp];
  174461. }
  174462. }
  174463. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174464. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174465. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174466. void /* PRIVATE */
  174467. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174468. {
  174469. png_debug(1, "in png_do_strip_filler\n");
  174470. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174471. if (row != NULL && row_info != NULL)
  174472. #endif
  174473. {
  174474. png_bytep sp=row;
  174475. png_bytep dp=row;
  174476. png_uint_32 row_width=row_info->width;
  174477. png_uint_32 i;
  174478. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174479. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174480. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174481. row_info->channels == 4)
  174482. {
  174483. if (row_info->bit_depth == 8)
  174484. {
  174485. if (flags & PNG_FLAG_FILLER_AFTER)
  174486. {
  174487. dp+=3; sp+=4;
  174488. for (i = 1; i < row_width; i++)
  174489. {
  174490. *dp++ = *sp++;
  174491. *dp++ = *sp++;
  174492. *dp++ = *sp++;
  174493. sp++;
  174494. }
  174495. }
  174496. else
  174497. {
  174498. for (i = 0; i < row_width; i++)
  174499. {
  174500. sp++;
  174501. *dp++ = *sp++;
  174502. *dp++ = *sp++;
  174503. *dp++ = *sp++;
  174504. }
  174505. }
  174506. row_info->pixel_depth = 24;
  174507. row_info->rowbytes = row_width * 3;
  174508. }
  174509. else /* if (row_info->bit_depth == 16) */
  174510. {
  174511. if (flags & PNG_FLAG_FILLER_AFTER)
  174512. {
  174513. sp += 8; dp += 6;
  174514. for (i = 1; i < row_width; i++)
  174515. {
  174516. *dp++ = *sp++;
  174517. *dp++ = *sp++;
  174518. *dp++ = *sp++;
  174519. *dp++ = *sp++;
  174520. *dp++ = *sp++;
  174521. *dp++ = *sp++;
  174522. sp += 2;
  174523. }
  174524. }
  174525. else
  174526. {
  174527. for (i = 0; i < row_width; i++)
  174528. {
  174529. sp+=2;
  174530. *dp++ = *sp++;
  174531. *dp++ = *sp++;
  174532. *dp++ = *sp++;
  174533. *dp++ = *sp++;
  174534. *dp++ = *sp++;
  174535. *dp++ = *sp++;
  174536. }
  174537. }
  174538. row_info->pixel_depth = 48;
  174539. row_info->rowbytes = row_width * 6;
  174540. }
  174541. row_info->channels = 3;
  174542. }
  174543. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174544. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174545. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174546. row_info->channels == 2)
  174547. {
  174548. if (row_info->bit_depth == 8)
  174549. {
  174550. if (flags & PNG_FLAG_FILLER_AFTER)
  174551. {
  174552. for (i = 0; i < row_width; i++)
  174553. {
  174554. *dp++ = *sp++;
  174555. sp++;
  174556. }
  174557. }
  174558. else
  174559. {
  174560. for (i = 0; i < row_width; i++)
  174561. {
  174562. sp++;
  174563. *dp++ = *sp++;
  174564. }
  174565. }
  174566. row_info->pixel_depth = 8;
  174567. row_info->rowbytes = row_width;
  174568. }
  174569. else /* if (row_info->bit_depth == 16) */
  174570. {
  174571. if (flags & PNG_FLAG_FILLER_AFTER)
  174572. {
  174573. sp += 4; dp += 2;
  174574. for (i = 1; i < row_width; i++)
  174575. {
  174576. *dp++ = *sp++;
  174577. *dp++ = *sp++;
  174578. sp += 2;
  174579. }
  174580. }
  174581. else
  174582. {
  174583. for (i = 0; i < row_width; i++)
  174584. {
  174585. sp += 2;
  174586. *dp++ = *sp++;
  174587. *dp++ = *sp++;
  174588. }
  174589. }
  174590. row_info->pixel_depth = 16;
  174591. row_info->rowbytes = row_width * 2;
  174592. }
  174593. row_info->channels = 1;
  174594. }
  174595. if (flags & PNG_FLAG_STRIP_ALPHA)
  174596. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174597. }
  174598. }
  174599. #endif
  174600. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174601. void /* PRIVATE */
  174602. png_do_bgr(png_row_infop row_info, png_bytep row)
  174603. {
  174604. png_debug(1, "in png_do_bgr\n");
  174605. if (
  174606. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174607. row != NULL && row_info != NULL &&
  174608. #endif
  174609. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174610. {
  174611. png_uint_32 row_width = row_info->width;
  174612. if (row_info->bit_depth == 8)
  174613. {
  174614. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174615. {
  174616. png_bytep rp;
  174617. png_uint_32 i;
  174618. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174619. {
  174620. png_byte save = *rp;
  174621. *rp = *(rp + 2);
  174622. *(rp + 2) = save;
  174623. }
  174624. }
  174625. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174626. {
  174627. png_bytep rp;
  174628. png_uint_32 i;
  174629. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174630. {
  174631. png_byte save = *rp;
  174632. *rp = *(rp + 2);
  174633. *(rp + 2) = save;
  174634. }
  174635. }
  174636. }
  174637. else if (row_info->bit_depth == 16)
  174638. {
  174639. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174640. {
  174641. png_bytep rp;
  174642. png_uint_32 i;
  174643. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174644. {
  174645. png_byte save = *rp;
  174646. *rp = *(rp + 4);
  174647. *(rp + 4) = save;
  174648. save = *(rp + 1);
  174649. *(rp + 1) = *(rp + 5);
  174650. *(rp + 5) = save;
  174651. }
  174652. }
  174653. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174654. {
  174655. png_bytep rp;
  174656. png_uint_32 i;
  174657. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174658. {
  174659. png_byte save = *rp;
  174660. *rp = *(rp + 4);
  174661. *(rp + 4) = save;
  174662. save = *(rp + 1);
  174663. *(rp + 1) = *(rp + 5);
  174664. *(rp + 5) = save;
  174665. }
  174666. }
  174667. }
  174668. }
  174669. }
  174670. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174671. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174672. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174673. defined(PNG_LEGACY_SUPPORTED)
  174674. void PNGAPI
  174675. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174676. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174677. {
  174678. png_debug(1, "in png_set_user_transform_info\n");
  174679. if(png_ptr == NULL) return;
  174680. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174681. png_ptr->user_transform_ptr = user_transform_ptr;
  174682. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174683. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174684. #else
  174685. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174686. png_warning(png_ptr,
  174687. "This version of libpng does not support user transform info");
  174688. #endif
  174689. }
  174690. #endif
  174691. png_voidp PNGAPI
  174692. png_get_user_transform_ptr(png_structp png_ptr)
  174693. {
  174694. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174695. if (png_ptr == NULL) return (NULL);
  174696. return ((png_voidp)png_ptr->user_transform_ptr);
  174697. #else
  174698. return (NULL);
  174699. #endif
  174700. }
  174701. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174702. /*** End of inlined file: pngtrans.c ***/
  174703. /*** Start of inlined file: pngwio.c ***/
  174704. #define PNG_INTERNAL
  174705. #ifdef PNG_WRITE_SUPPORTED
  174706. void /* PRIVATE */
  174707. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174708. {
  174709. if (png_ptr->write_data_fn != NULL )
  174710. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  174711. else
  174712. png_error(png_ptr, "Call to NULL write function");
  174713. }
  174714. #if !defined(PNG_NO_STDIO)
  174715. #ifndef USE_FAR_KEYWORD
  174716. void PNGAPI
  174717. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174718. {
  174719. png_uint_32 check;
  174720. if(png_ptr == NULL) return;
  174721. #if defined(_WIN32_WCE)
  174722. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  174723. check = 0;
  174724. #else
  174725. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  174726. #endif
  174727. if (check != length)
  174728. png_error(png_ptr, "Write Error");
  174729. }
  174730. #else
  174731. #define NEAR_BUF_SIZE 1024
  174732. #define MIN(a,b) (a <= b ? a : b)
  174733. void PNGAPI
  174734. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174735. {
  174736. png_uint_32 check;
  174737. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  174738. png_FILE_p io_ptr;
  174739. if(png_ptr == NULL) return;
  174740. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  174741. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  174742. if ((png_bytep)near_data == data)
  174743. {
  174744. #if defined(_WIN32_WCE)
  174745. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  174746. check = 0;
  174747. #else
  174748. check = fwrite(near_data, 1, length, io_ptr);
  174749. #endif
  174750. }
  174751. else
  174752. {
  174753. png_byte buf[NEAR_BUF_SIZE];
  174754. png_size_t written, remaining, err;
  174755. check = 0;
  174756. remaining = length;
  174757. do
  174758. {
  174759. written = MIN(NEAR_BUF_SIZE, remaining);
  174760. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  174761. #if defined(_WIN32_WCE)
  174762. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  174763. err = 0;
  174764. #else
  174765. err = fwrite(buf, 1, written, io_ptr);
  174766. #endif
  174767. if (err != written)
  174768. break;
  174769. else
  174770. check += err;
  174771. data += written;
  174772. remaining -= written;
  174773. }
  174774. while (remaining != 0);
  174775. }
  174776. if (check != length)
  174777. png_error(png_ptr, "Write Error");
  174778. }
  174779. #endif
  174780. #endif
  174781. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174782. void /* PRIVATE */
  174783. png_flush(png_structp png_ptr)
  174784. {
  174785. if (png_ptr->output_flush_fn != NULL)
  174786. (*(png_ptr->output_flush_fn))(png_ptr);
  174787. }
  174788. #if !defined(PNG_NO_STDIO)
  174789. void PNGAPI
  174790. png_default_flush(png_structp png_ptr)
  174791. {
  174792. #if !defined(_WIN32_WCE)
  174793. png_FILE_p io_ptr;
  174794. #endif
  174795. if(png_ptr == NULL) return;
  174796. #if !defined(_WIN32_WCE)
  174797. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  174798. if (io_ptr != NULL)
  174799. fflush(io_ptr);
  174800. #endif
  174801. }
  174802. #endif
  174803. #endif
  174804. void PNGAPI
  174805. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  174806. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  174807. {
  174808. if(png_ptr == NULL) return;
  174809. png_ptr->io_ptr = io_ptr;
  174810. #if !defined(PNG_NO_STDIO)
  174811. if (write_data_fn != NULL)
  174812. png_ptr->write_data_fn = write_data_fn;
  174813. else
  174814. png_ptr->write_data_fn = png_default_write_data;
  174815. #else
  174816. png_ptr->write_data_fn = write_data_fn;
  174817. #endif
  174818. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174819. #if !defined(PNG_NO_STDIO)
  174820. if (output_flush_fn != NULL)
  174821. png_ptr->output_flush_fn = output_flush_fn;
  174822. else
  174823. png_ptr->output_flush_fn = png_default_flush;
  174824. #else
  174825. png_ptr->output_flush_fn = output_flush_fn;
  174826. #endif
  174827. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  174828. if (png_ptr->read_data_fn != NULL)
  174829. {
  174830. png_ptr->read_data_fn = NULL;
  174831. png_warning(png_ptr,
  174832. "Attempted to set both read_data_fn and write_data_fn in");
  174833. png_warning(png_ptr,
  174834. "the same structure. Resetting read_data_fn to NULL.");
  174835. }
  174836. }
  174837. #if defined(USE_FAR_KEYWORD)
  174838. #if defined(_MSC_VER)
  174839. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  174840. {
  174841. void *near_ptr;
  174842. void FAR *far_ptr;
  174843. FP_OFF(near_ptr) = FP_OFF(ptr);
  174844. far_ptr = (void FAR *)near_ptr;
  174845. if(check != 0)
  174846. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  174847. png_error(png_ptr,"segment lost in conversion");
  174848. return(near_ptr);
  174849. }
  174850. # else
  174851. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  174852. {
  174853. void *near_ptr;
  174854. void FAR *far_ptr;
  174855. near_ptr = (void FAR *)ptr;
  174856. far_ptr = (void FAR *)near_ptr;
  174857. if(check != 0)
  174858. if(far_ptr != ptr)
  174859. png_error(png_ptr,"segment lost in conversion");
  174860. return(near_ptr);
  174861. }
  174862. # endif
  174863. # endif
  174864. #endif /* PNG_WRITE_SUPPORTED */
  174865. /*** End of inlined file: pngwio.c ***/
  174866. /*** Start of inlined file: pngwrite.c ***/
  174867. #define PNG_INTERNAL
  174868. #ifdef PNG_WRITE_SUPPORTED
  174869. void PNGAPI
  174870. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  174871. {
  174872. png_debug(1, "in png_write_info_before_PLTE\n");
  174873. if (png_ptr == NULL || info_ptr == NULL)
  174874. return;
  174875. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  174876. {
  174877. png_write_sig(png_ptr); /* write PNG signature */
  174878. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174879. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  174880. {
  174881. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  174882. png_ptr->mng_features_permitted=0;
  174883. }
  174884. #endif
  174885. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  174886. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  174887. info_ptr->filter_type,
  174888. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174889. info_ptr->interlace_type);
  174890. #else
  174891. 0);
  174892. #endif
  174893. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  174894. if (info_ptr->valid & PNG_INFO_gAMA)
  174895. {
  174896. # ifdef PNG_FLOATING_POINT_SUPPORTED
  174897. png_write_gAMA(png_ptr, info_ptr->gamma);
  174898. #else
  174899. #ifdef PNG_FIXED_POINT_SUPPORTED
  174900. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  174901. # endif
  174902. #endif
  174903. }
  174904. #endif
  174905. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  174906. if (info_ptr->valid & PNG_INFO_sRGB)
  174907. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  174908. #endif
  174909. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  174910. if (info_ptr->valid & PNG_INFO_iCCP)
  174911. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  174912. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  174913. #endif
  174914. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  174915. if (info_ptr->valid & PNG_INFO_sBIT)
  174916. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  174917. #endif
  174918. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  174919. if (info_ptr->valid & PNG_INFO_cHRM)
  174920. {
  174921. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174922. png_write_cHRM(png_ptr,
  174923. info_ptr->x_white, info_ptr->y_white,
  174924. info_ptr->x_red, info_ptr->y_red,
  174925. info_ptr->x_green, info_ptr->y_green,
  174926. info_ptr->x_blue, info_ptr->y_blue);
  174927. #else
  174928. # ifdef PNG_FIXED_POINT_SUPPORTED
  174929. png_write_cHRM_fixed(png_ptr,
  174930. info_ptr->int_x_white, info_ptr->int_y_white,
  174931. info_ptr->int_x_red, info_ptr->int_y_red,
  174932. info_ptr->int_x_green, info_ptr->int_y_green,
  174933. info_ptr->int_x_blue, info_ptr->int_y_blue);
  174934. # endif
  174935. #endif
  174936. }
  174937. #endif
  174938. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  174939. if (info_ptr->unknown_chunks_num)
  174940. {
  174941. png_unknown_chunk *up;
  174942. png_debug(5, "writing extra chunks\n");
  174943. for (up = info_ptr->unknown_chunks;
  174944. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  174945. up++)
  174946. {
  174947. int keep=png_handle_as_unknown(png_ptr, up->name);
  174948. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  174949. up->location && !(up->location & PNG_HAVE_PLTE) &&
  174950. !(up->location & PNG_HAVE_IDAT) &&
  174951. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  174952. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  174953. {
  174954. png_write_chunk(png_ptr, up->name, up->data, up->size);
  174955. }
  174956. }
  174957. }
  174958. #endif
  174959. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  174960. }
  174961. }
  174962. void PNGAPI
  174963. png_write_info(png_structp png_ptr, png_infop info_ptr)
  174964. {
  174965. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  174966. int i;
  174967. #endif
  174968. png_debug(1, "in png_write_info\n");
  174969. if (png_ptr == NULL || info_ptr == NULL)
  174970. return;
  174971. png_write_info_before_PLTE(png_ptr, info_ptr);
  174972. if (info_ptr->valid & PNG_INFO_PLTE)
  174973. png_write_PLTE(png_ptr, info_ptr->palette,
  174974. (png_uint_32)info_ptr->num_palette);
  174975. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174976. png_error(png_ptr, "Valid palette required for paletted images");
  174977. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  174978. if (info_ptr->valid & PNG_INFO_tRNS)
  174979. {
  174980. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174981. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  174982. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174983. {
  174984. int j;
  174985. for (j=0; j<(int)info_ptr->num_trans; j++)
  174986. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  174987. }
  174988. #endif
  174989. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  174990. info_ptr->num_trans, info_ptr->color_type);
  174991. }
  174992. #endif
  174993. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  174994. if (info_ptr->valid & PNG_INFO_bKGD)
  174995. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  174996. #endif
  174997. #if defined(PNG_WRITE_hIST_SUPPORTED)
  174998. if (info_ptr->valid & PNG_INFO_hIST)
  174999. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175000. #endif
  175001. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175002. if (info_ptr->valid & PNG_INFO_oFFs)
  175003. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175004. info_ptr->offset_unit_type);
  175005. #endif
  175006. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175007. if (info_ptr->valid & PNG_INFO_pCAL)
  175008. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175009. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175010. info_ptr->pcal_units, info_ptr->pcal_params);
  175011. #endif
  175012. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175013. if (info_ptr->valid & PNG_INFO_sCAL)
  175014. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175015. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175016. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175017. #else
  175018. #ifdef PNG_FIXED_POINT_SUPPORTED
  175019. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175020. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175021. #else
  175022. png_warning(png_ptr,
  175023. "png_write_sCAL not supported; sCAL chunk not written.");
  175024. #endif
  175025. #endif
  175026. #endif
  175027. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175028. if (info_ptr->valid & PNG_INFO_pHYs)
  175029. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175030. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175031. #endif
  175032. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175033. if (info_ptr->valid & PNG_INFO_tIME)
  175034. {
  175035. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175036. png_ptr->mode |= PNG_WROTE_tIME;
  175037. }
  175038. #endif
  175039. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175040. if (info_ptr->valid & PNG_INFO_sPLT)
  175041. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175042. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175043. #endif
  175044. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175045. for (i = 0; i < info_ptr->num_text; i++)
  175046. {
  175047. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175048. info_ptr->text[i].compression);
  175049. if (info_ptr->text[i].compression > 0)
  175050. {
  175051. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175052. png_write_iTXt(png_ptr,
  175053. info_ptr->text[i].compression,
  175054. info_ptr->text[i].key,
  175055. info_ptr->text[i].lang,
  175056. info_ptr->text[i].lang_key,
  175057. info_ptr->text[i].text);
  175058. #else
  175059. png_warning(png_ptr, "Unable to write international text");
  175060. #endif
  175061. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175062. }
  175063. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175064. {
  175065. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175066. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175067. info_ptr->text[i].text, 0,
  175068. info_ptr->text[i].compression);
  175069. #else
  175070. png_warning(png_ptr, "Unable to write compressed text");
  175071. #endif
  175072. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175073. }
  175074. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175075. {
  175076. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175077. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175078. info_ptr->text[i].text,
  175079. 0);
  175080. #else
  175081. png_warning(png_ptr, "Unable to write uncompressed text");
  175082. #endif
  175083. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175084. }
  175085. }
  175086. #endif
  175087. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175088. if (info_ptr->unknown_chunks_num)
  175089. {
  175090. png_unknown_chunk *up;
  175091. png_debug(5, "writing extra chunks\n");
  175092. for (up = info_ptr->unknown_chunks;
  175093. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175094. up++)
  175095. {
  175096. int keep=png_handle_as_unknown(png_ptr, up->name);
  175097. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175098. up->location && (up->location & PNG_HAVE_PLTE) &&
  175099. !(up->location & PNG_HAVE_IDAT) &&
  175100. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175101. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175102. {
  175103. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175104. }
  175105. }
  175106. }
  175107. #endif
  175108. }
  175109. void PNGAPI
  175110. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175111. {
  175112. png_debug(1, "in png_write_end\n");
  175113. if (png_ptr == NULL)
  175114. return;
  175115. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175116. png_error(png_ptr, "No IDATs written into file");
  175117. if (info_ptr != NULL)
  175118. {
  175119. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175120. int i; /* local index variable */
  175121. #endif
  175122. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175123. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175124. !(png_ptr->mode & PNG_WROTE_tIME))
  175125. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175126. #endif
  175127. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175128. for (i = 0; i < info_ptr->num_text; i++)
  175129. {
  175130. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175131. info_ptr->text[i].compression);
  175132. if (info_ptr->text[i].compression > 0)
  175133. {
  175134. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175135. png_write_iTXt(png_ptr,
  175136. info_ptr->text[i].compression,
  175137. info_ptr->text[i].key,
  175138. info_ptr->text[i].lang,
  175139. info_ptr->text[i].lang_key,
  175140. info_ptr->text[i].text);
  175141. #else
  175142. png_warning(png_ptr, "Unable to write international text");
  175143. #endif
  175144. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175145. }
  175146. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175147. {
  175148. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175149. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175150. info_ptr->text[i].text, 0,
  175151. info_ptr->text[i].compression);
  175152. #else
  175153. png_warning(png_ptr, "Unable to write compressed text");
  175154. #endif
  175155. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175156. }
  175157. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175158. {
  175159. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175160. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175161. info_ptr->text[i].text, 0);
  175162. #else
  175163. png_warning(png_ptr, "Unable to write uncompressed text");
  175164. #endif
  175165. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175166. }
  175167. }
  175168. #endif
  175169. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175170. if (info_ptr->unknown_chunks_num)
  175171. {
  175172. png_unknown_chunk *up;
  175173. png_debug(5, "writing extra chunks\n");
  175174. for (up = info_ptr->unknown_chunks;
  175175. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175176. up++)
  175177. {
  175178. int keep=png_handle_as_unknown(png_ptr, up->name);
  175179. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175180. up->location && (up->location & PNG_AFTER_IDAT) &&
  175181. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175182. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175183. {
  175184. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175185. }
  175186. }
  175187. }
  175188. #endif
  175189. }
  175190. png_ptr->mode |= PNG_AFTER_IDAT;
  175191. png_write_IEND(png_ptr);
  175192. }
  175193. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175194. #if !defined(_WIN32_WCE)
  175195. void PNGAPI
  175196. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175197. {
  175198. png_debug(1, "in png_convert_from_struct_tm\n");
  175199. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175200. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175201. ptime->day = (png_byte)ttime->tm_mday;
  175202. ptime->hour = (png_byte)ttime->tm_hour;
  175203. ptime->minute = (png_byte)ttime->tm_min;
  175204. ptime->second = (png_byte)ttime->tm_sec;
  175205. }
  175206. void PNGAPI
  175207. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175208. {
  175209. struct tm *tbuf;
  175210. png_debug(1, "in png_convert_from_time_t\n");
  175211. tbuf = gmtime(&ttime);
  175212. png_convert_from_struct_tm(ptime, tbuf);
  175213. }
  175214. #endif
  175215. #endif
  175216. png_structp PNGAPI
  175217. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175218. png_error_ptr error_fn, png_error_ptr warn_fn)
  175219. {
  175220. #ifdef PNG_USER_MEM_SUPPORTED
  175221. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175222. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175223. }
  175224. png_structp PNGAPI
  175225. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175226. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175227. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175228. {
  175229. #endif /* PNG_USER_MEM_SUPPORTED */
  175230. png_structp png_ptr;
  175231. #ifdef PNG_SETJMP_SUPPORTED
  175232. #ifdef USE_FAR_KEYWORD
  175233. jmp_buf jmpbuf;
  175234. #endif
  175235. #endif
  175236. int i;
  175237. png_debug(1, "in png_create_write_struct\n");
  175238. #ifdef PNG_USER_MEM_SUPPORTED
  175239. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175240. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175241. #else
  175242. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175243. #endif /* PNG_USER_MEM_SUPPORTED */
  175244. if (png_ptr == NULL)
  175245. return (NULL);
  175246. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175247. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175248. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175249. #endif
  175250. #ifdef PNG_SETJMP_SUPPORTED
  175251. #ifdef USE_FAR_KEYWORD
  175252. if (setjmp(jmpbuf))
  175253. #else
  175254. if (setjmp(png_ptr->jmpbuf))
  175255. #endif
  175256. {
  175257. png_free(png_ptr, png_ptr->zbuf);
  175258. png_ptr->zbuf=NULL;
  175259. png_destroy_struct(png_ptr);
  175260. return (NULL);
  175261. }
  175262. #ifdef USE_FAR_KEYWORD
  175263. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175264. #endif
  175265. #endif
  175266. #ifdef PNG_USER_MEM_SUPPORTED
  175267. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175268. #endif /* PNG_USER_MEM_SUPPORTED */
  175269. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175270. i=0;
  175271. do
  175272. {
  175273. if(user_png_ver[i] != png_libpng_ver[i])
  175274. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175275. } while (png_libpng_ver[i++]);
  175276. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175277. {
  175278. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175279. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175280. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175281. {
  175282. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175283. char msg[80];
  175284. if (user_png_ver)
  175285. {
  175286. png_snprintf(msg, 80,
  175287. "Application was compiled with png.h from libpng-%.20s",
  175288. user_png_ver);
  175289. png_warning(png_ptr, msg);
  175290. }
  175291. png_snprintf(msg, 80,
  175292. "Application is running with png.c from libpng-%.20s",
  175293. png_libpng_ver);
  175294. png_warning(png_ptr, msg);
  175295. #endif
  175296. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175297. png_ptr->flags=0;
  175298. #endif
  175299. png_error(png_ptr,
  175300. "Incompatible libpng version in application and library");
  175301. }
  175302. }
  175303. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175304. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175305. (png_uint_32)png_ptr->zbuf_size);
  175306. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175307. png_flush_ptr_NULL);
  175308. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175309. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175310. 1, png_doublep_NULL, png_doublep_NULL);
  175311. #endif
  175312. #ifdef PNG_SETJMP_SUPPORTED
  175313. #ifdef USE_FAR_KEYWORD
  175314. if (setjmp(jmpbuf))
  175315. PNG_ABORT();
  175316. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175317. #else
  175318. if (setjmp(png_ptr->jmpbuf))
  175319. PNG_ABORT();
  175320. #endif
  175321. #endif
  175322. return (png_ptr);
  175323. }
  175324. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175325. #undef png_write_init
  175326. void PNGAPI
  175327. png_write_init(png_structp png_ptr)
  175328. {
  175329. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175330. }
  175331. void PNGAPI
  175332. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175333. png_size_t png_struct_size, png_size_t png_info_size)
  175334. {
  175335. if(png_ptr == NULL) return;
  175336. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175337. if(png_sizeof(png_struct) > png_struct_size ||
  175338. png_sizeof(png_info) > png_info_size)
  175339. {
  175340. char msg[80];
  175341. png_ptr->warning_fn=NULL;
  175342. if (user_png_ver)
  175343. {
  175344. png_snprintf(msg, 80,
  175345. "Application was compiled with png.h from libpng-%.20s",
  175346. user_png_ver);
  175347. png_warning(png_ptr, msg);
  175348. }
  175349. png_snprintf(msg, 80,
  175350. "Application is running with png.c from libpng-%.20s",
  175351. png_libpng_ver);
  175352. png_warning(png_ptr, msg);
  175353. }
  175354. #endif
  175355. if(png_sizeof(png_struct) > png_struct_size)
  175356. {
  175357. png_ptr->error_fn=NULL;
  175358. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175359. png_ptr->flags=0;
  175360. #endif
  175361. png_error(png_ptr,
  175362. "The png struct allocated by the application for writing is too small.");
  175363. }
  175364. if(png_sizeof(png_info) > png_info_size)
  175365. {
  175366. png_ptr->error_fn=NULL;
  175367. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175368. png_ptr->flags=0;
  175369. #endif
  175370. png_error(png_ptr,
  175371. "The info struct allocated by the application for writing is too small.");
  175372. }
  175373. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175374. }
  175375. #endif /* PNG_1_0_X || PNG_1_2_X */
  175376. void PNGAPI
  175377. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175378. png_size_t png_struct_size)
  175379. {
  175380. png_structp png_ptr=*ptr_ptr;
  175381. #ifdef PNG_SETJMP_SUPPORTED
  175382. jmp_buf tmp_jmp; /* to save current jump buffer */
  175383. #endif
  175384. int i = 0;
  175385. if (png_ptr == NULL)
  175386. return;
  175387. do
  175388. {
  175389. if (user_png_ver[i] != png_libpng_ver[i])
  175390. {
  175391. #ifdef PNG_LEGACY_SUPPORTED
  175392. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175393. #else
  175394. png_ptr->warning_fn=NULL;
  175395. png_warning(png_ptr,
  175396. "Application uses deprecated png_write_init() and should be recompiled.");
  175397. break;
  175398. #endif
  175399. }
  175400. } while (png_libpng_ver[i++]);
  175401. png_debug(1, "in png_write_init_3\n");
  175402. #ifdef PNG_SETJMP_SUPPORTED
  175403. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175404. #endif
  175405. if (png_sizeof(png_struct) > png_struct_size)
  175406. {
  175407. png_destroy_struct(png_ptr);
  175408. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175409. *ptr_ptr = png_ptr;
  175410. }
  175411. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175412. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175413. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175414. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175415. #endif
  175416. #ifdef PNG_SETJMP_SUPPORTED
  175417. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175418. #endif
  175419. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175420. png_flush_ptr_NULL);
  175421. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175422. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175423. (png_uint_32)png_ptr->zbuf_size);
  175424. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175425. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175426. 1, png_doublep_NULL, png_doublep_NULL);
  175427. #endif
  175428. }
  175429. void PNGAPI
  175430. png_write_rows(png_structp png_ptr, png_bytepp row,
  175431. png_uint_32 num_rows)
  175432. {
  175433. png_uint_32 i; /* row counter */
  175434. png_bytepp rp; /* row pointer */
  175435. png_debug(1, "in png_write_rows\n");
  175436. if (png_ptr == NULL)
  175437. return;
  175438. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175439. {
  175440. png_write_row(png_ptr, *rp);
  175441. }
  175442. }
  175443. void PNGAPI
  175444. png_write_image(png_structp png_ptr, png_bytepp image)
  175445. {
  175446. png_uint_32 i; /* row index */
  175447. int pass, num_pass; /* pass variables */
  175448. png_bytepp rp; /* points to current row */
  175449. if (png_ptr == NULL)
  175450. return;
  175451. png_debug(1, "in png_write_image\n");
  175452. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175453. num_pass = png_set_interlace_handling(png_ptr);
  175454. #else
  175455. num_pass = 1;
  175456. #endif
  175457. for (pass = 0; pass < num_pass; pass++)
  175458. {
  175459. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175460. {
  175461. png_write_row(png_ptr, *rp);
  175462. }
  175463. }
  175464. }
  175465. void PNGAPI
  175466. png_write_row(png_structp png_ptr, png_bytep row)
  175467. {
  175468. if (png_ptr == NULL)
  175469. return;
  175470. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175471. png_ptr->row_number, png_ptr->pass);
  175472. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175473. {
  175474. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175475. png_error(png_ptr,
  175476. "png_write_info was never called before png_write_row.");
  175477. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175478. if (png_ptr->transformations & PNG_INVERT_MONO)
  175479. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175480. #endif
  175481. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175482. if (png_ptr->transformations & PNG_FILLER)
  175483. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175484. #endif
  175485. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175486. if (png_ptr->transformations & PNG_PACKSWAP)
  175487. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175488. #endif
  175489. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175490. if (png_ptr->transformations & PNG_PACK)
  175491. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175492. #endif
  175493. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175494. if (png_ptr->transformations & PNG_SHIFT)
  175495. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175496. #endif
  175497. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175498. if (png_ptr->transformations & PNG_BGR)
  175499. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175500. #endif
  175501. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175502. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175503. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175504. #endif
  175505. png_write_start_row(png_ptr);
  175506. }
  175507. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175508. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175509. {
  175510. switch (png_ptr->pass)
  175511. {
  175512. case 0:
  175513. if (png_ptr->row_number & 0x07)
  175514. {
  175515. png_write_finish_row(png_ptr);
  175516. return;
  175517. }
  175518. break;
  175519. case 1:
  175520. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175521. {
  175522. png_write_finish_row(png_ptr);
  175523. return;
  175524. }
  175525. break;
  175526. case 2:
  175527. if ((png_ptr->row_number & 0x07) != 4)
  175528. {
  175529. png_write_finish_row(png_ptr);
  175530. return;
  175531. }
  175532. break;
  175533. case 3:
  175534. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175535. {
  175536. png_write_finish_row(png_ptr);
  175537. return;
  175538. }
  175539. break;
  175540. case 4:
  175541. if ((png_ptr->row_number & 0x03) != 2)
  175542. {
  175543. png_write_finish_row(png_ptr);
  175544. return;
  175545. }
  175546. break;
  175547. case 5:
  175548. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175549. {
  175550. png_write_finish_row(png_ptr);
  175551. return;
  175552. }
  175553. break;
  175554. case 6:
  175555. if (!(png_ptr->row_number & 0x01))
  175556. {
  175557. png_write_finish_row(png_ptr);
  175558. return;
  175559. }
  175560. break;
  175561. }
  175562. }
  175563. #endif
  175564. png_ptr->row_info.color_type = png_ptr->color_type;
  175565. png_ptr->row_info.width = png_ptr->usr_width;
  175566. png_ptr->row_info.channels = png_ptr->usr_channels;
  175567. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175568. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175569. png_ptr->row_info.channels);
  175570. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175571. png_ptr->row_info.width);
  175572. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175573. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175574. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175575. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175576. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175577. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175578. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175579. png_ptr->row_info.rowbytes);
  175580. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175581. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175582. (png_ptr->transformations & PNG_INTERLACE))
  175583. {
  175584. png_do_write_interlace(&(png_ptr->row_info),
  175585. png_ptr->row_buf + 1, png_ptr->pass);
  175586. if (!(png_ptr->row_info.width))
  175587. {
  175588. png_write_finish_row(png_ptr);
  175589. return;
  175590. }
  175591. }
  175592. #endif
  175593. if (png_ptr->transformations)
  175594. png_do_write_transformations(png_ptr);
  175595. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175596. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175597. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175598. {
  175599. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175600. }
  175601. #endif
  175602. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175603. if (png_ptr->write_row_fn != NULL)
  175604. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175605. }
  175606. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175607. void PNGAPI
  175608. png_set_flush(png_structp png_ptr, int nrows)
  175609. {
  175610. png_debug(1, "in png_set_flush\n");
  175611. if (png_ptr == NULL)
  175612. return;
  175613. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175614. }
  175615. void PNGAPI
  175616. png_write_flush(png_structp png_ptr)
  175617. {
  175618. int wrote_IDAT;
  175619. png_debug(1, "in png_write_flush\n");
  175620. if (png_ptr == NULL)
  175621. return;
  175622. if (png_ptr->row_number >= png_ptr->num_rows)
  175623. return;
  175624. do
  175625. {
  175626. int ret;
  175627. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175628. wrote_IDAT = 0;
  175629. if (ret != Z_OK)
  175630. {
  175631. if (png_ptr->zstream.msg != NULL)
  175632. png_error(png_ptr, png_ptr->zstream.msg);
  175633. else
  175634. png_error(png_ptr, "zlib error");
  175635. }
  175636. if (!(png_ptr->zstream.avail_out))
  175637. {
  175638. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175639. png_ptr->zbuf_size);
  175640. png_ptr->zstream.next_out = png_ptr->zbuf;
  175641. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175642. wrote_IDAT = 1;
  175643. }
  175644. } while(wrote_IDAT == 1);
  175645. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175646. {
  175647. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175648. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175649. png_ptr->zstream.next_out = png_ptr->zbuf;
  175650. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175651. }
  175652. png_ptr->flush_rows = 0;
  175653. png_flush(png_ptr);
  175654. }
  175655. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175656. void PNGAPI
  175657. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175658. {
  175659. png_structp png_ptr = NULL;
  175660. png_infop info_ptr = NULL;
  175661. #ifdef PNG_USER_MEM_SUPPORTED
  175662. png_free_ptr free_fn = NULL;
  175663. png_voidp mem_ptr = NULL;
  175664. #endif
  175665. png_debug(1, "in png_destroy_write_struct\n");
  175666. if (png_ptr_ptr != NULL)
  175667. {
  175668. png_ptr = *png_ptr_ptr;
  175669. #ifdef PNG_USER_MEM_SUPPORTED
  175670. free_fn = png_ptr->free_fn;
  175671. mem_ptr = png_ptr->mem_ptr;
  175672. #endif
  175673. }
  175674. if (info_ptr_ptr != NULL)
  175675. info_ptr = *info_ptr_ptr;
  175676. if (info_ptr != NULL)
  175677. {
  175678. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175679. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175680. if (png_ptr->num_chunk_list)
  175681. {
  175682. png_free(png_ptr, png_ptr->chunk_list);
  175683. png_ptr->chunk_list=NULL;
  175684. png_ptr->num_chunk_list=0;
  175685. }
  175686. #endif
  175687. #ifdef PNG_USER_MEM_SUPPORTED
  175688. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175689. (png_voidp)mem_ptr);
  175690. #else
  175691. png_destroy_struct((png_voidp)info_ptr);
  175692. #endif
  175693. *info_ptr_ptr = NULL;
  175694. }
  175695. if (png_ptr != NULL)
  175696. {
  175697. png_write_destroy(png_ptr);
  175698. #ifdef PNG_USER_MEM_SUPPORTED
  175699. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175700. (png_voidp)mem_ptr);
  175701. #else
  175702. png_destroy_struct((png_voidp)png_ptr);
  175703. #endif
  175704. *png_ptr_ptr = NULL;
  175705. }
  175706. }
  175707. void /* PRIVATE */
  175708. png_write_destroy(png_structp png_ptr)
  175709. {
  175710. #ifdef PNG_SETJMP_SUPPORTED
  175711. jmp_buf tmp_jmp; /* save jump buffer */
  175712. #endif
  175713. png_error_ptr error_fn;
  175714. png_error_ptr warning_fn;
  175715. png_voidp error_ptr;
  175716. #ifdef PNG_USER_MEM_SUPPORTED
  175717. png_free_ptr free_fn;
  175718. #endif
  175719. png_debug(1, "in png_write_destroy\n");
  175720. deflateEnd(&png_ptr->zstream);
  175721. png_free(png_ptr, png_ptr->zbuf);
  175722. png_free(png_ptr, png_ptr->row_buf);
  175723. png_free(png_ptr, png_ptr->prev_row);
  175724. png_free(png_ptr, png_ptr->sub_row);
  175725. png_free(png_ptr, png_ptr->up_row);
  175726. png_free(png_ptr, png_ptr->avg_row);
  175727. png_free(png_ptr, png_ptr->paeth_row);
  175728. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  175729. png_free(png_ptr, png_ptr->time_buffer);
  175730. #endif
  175731. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175732. png_free(png_ptr, png_ptr->prev_filters);
  175733. png_free(png_ptr, png_ptr->filter_weights);
  175734. png_free(png_ptr, png_ptr->inv_filter_weights);
  175735. png_free(png_ptr, png_ptr->filter_costs);
  175736. png_free(png_ptr, png_ptr->inv_filter_costs);
  175737. #endif
  175738. #ifdef PNG_SETJMP_SUPPORTED
  175739. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175740. #endif
  175741. error_fn = png_ptr->error_fn;
  175742. warning_fn = png_ptr->warning_fn;
  175743. error_ptr = png_ptr->error_ptr;
  175744. #ifdef PNG_USER_MEM_SUPPORTED
  175745. free_fn = png_ptr->free_fn;
  175746. #endif
  175747. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175748. png_ptr->error_fn = error_fn;
  175749. png_ptr->warning_fn = warning_fn;
  175750. png_ptr->error_ptr = error_ptr;
  175751. #ifdef PNG_USER_MEM_SUPPORTED
  175752. png_ptr->free_fn = free_fn;
  175753. #endif
  175754. #ifdef PNG_SETJMP_SUPPORTED
  175755. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175756. #endif
  175757. }
  175758. void PNGAPI
  175759. png_set_filter(png_structp png_ptr, int method, int filters)
  175760. {
  175761. png_debug(1, "in png_set_filter\n");
  175762. if (png_ptr == NULL)
  175763. return;
  175764. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175765. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175766. (method == PNG_INTRAPIXEL_DIFFERENCING))
  175767. method = PNG_FILTER_TYPE_BASE;
  175768. #endif
  175769. if (method == PNG_FILTER_TYPE_BASE)
  175770. {
  175771. switch (filters & (PNG_ALL_FILTERS | 0x07))
  175772. {
  175773. #ifndef PNG_NO_WRITE_FILTER
  175774. case 5:
  175775. case 6:
  175776. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  175777. #endif /* PNG_NO_WRITE_FILTER */
  175778. case PNG_FILTER_VALUE_NONE:
  175779. png_ptr->do_filter=PNG_FILTER_NONE; break;
  175780. #ifndef PNG_NO_WRITE_FILTER
  175781. case PNG_FILTER_VALUE_SUB:
  175782. png_ptr->do_filter=PNG_FILTER_SUB; break;
  175783. case PNG_FILTER_VALUE_UP:
  175784. png_ptr->do_filter=PNG_FILTER_UP; break;
  175785. case PNG_FILTER_VALUE_AVG:
  175786. png_ptr->do_filter=PNG_FILTER_AVG; break;
  175787. case PNG_FILTER_VALUE_PAETH:
  175788. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  175789. default: png_ptr->do_filter = (png_byte)filters; break;
  175790. #else
  175791. default: png_warning(png_ptr, "Unknown row filter for method 0");
  175792. #endif /* PNG_NO_WRITE_FILTER */
  175793. }
  175794. if (png_ptr->row_buf != NULL)
  175795. {
  175796. #ifndef PNG_NO_WRITE_FILTER
  175797. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  175798. {
  175799. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  175800. (png_ptr->rowbytes + 1));
  175801. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  175802. }
  175803. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  175804. {
  175805. if (png_ptr->prev_row == NULL)
  175806. {
  175807. png_warning(png_ptr, "Can't add Up filter after starting");
  175808. png_ptr->do_filter &= ~PNG_FILTER_UP;
  175809. }
  175810. else
  175811. {
  175812. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  175813. (png_ptr->rowbytes + 1));
  175814. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  175815. }
  175816. }
  175817. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  175818. {
  175819. if (png_ptr->prev_row == NULL)
  175820. {
  175821. png_warning(png_ptr, "Can't add Average filter after starting");
  175822. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  175823. }
  175824. else
  175825. {
  175826. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  175827. (png_ptr->rowbytes + 1));
  175828. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  175829. }
  175830. }
  175831. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  175832. png_ptr->paeth_row == NULL)
  175833. {
  175834. if (png_ptr->prev_row == NULL)
  175835. {
  175836. png_warning(png_ptr, "Can't add Paeth filter after starting");
  175837. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  175838. }
  175839. else
  175840. {
  175841. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  175842. (png_ptr->rowbytes + 1));
  175843. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  175844. }
  175845. }
  175846. if (png_ptr->do_filter == PNG_NO_FILTERS)
  175847. #endif /* PNG_NO_WRITE_FILTER */
  175848. png_ptr->do_filter = PNG_FILTER_NONE;
  175849. }
  175850. }
  175851. else
  175852. png_error(png_ptr, "Unknown custom filter method");
  175853. }
  175854. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  175855. void PNGAPI
  175856. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  175857. int num_weights, png_doublep filter_weights,
  175858. png_doublep filter_costs)
  175859. {
  175860. int i;
  175861. png_debug(1, "in png_set_filter_heuristics\n");
  175862. if (png_ptr == NULL)
  175863. return;
  175864. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  175865. {
  175866. png_warning(png_ptr, "Unknown filter heuristic method");
  175867. return;
  175868. }
  175869. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  175870. {
  175871. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  175872. }
  175873. if (num_weights < 0 || filter_weights == NULL ||
  175874. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  175875. {
  175876. num_weights = 0;
  175877. }
  175878. png_ptr->num_prev_filters = (png_byte)num_weights;
  175879. png_ptr->heuristic_method = (png_byte)heuristic_method;
  175880. if (num_weights > 0)
  175881. {
  175882. if (png_ptr->prev_filters == NULL)
  175883. {
  175884. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  175885. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  175886. for (i = 0; i < num_weights; i++)
  175887. {
  175888. png_ptr->prev_filters[i] = 255;
  175889. }
  175890. }
  175891. if (png_ptr->filter_weights == NULL)
  175892. {
  175893. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  175894. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  175895. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  175896. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  175897. for (i = 0; i < num_weights; i++)
  175898. {
  175899. png_ptr->inv_filter_weights[i] =
  175900. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  175901. }
  175902. }
  175903. for (i = 0; i < num_weights; i++)
  175904. {
  175905. if (filter_weights[i] < 0.0)
  175906. {
  175907. png_ptr->inv_filter_weights[i] =
  175908. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  175909. }
  175910. else
  175911. {
  175912. png_ptr->inv_filter_weights[i] =
  175913. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  175914. png_ptr->filter_weights[i] =
  175915. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  175916. }
  175917. }
  175918. }
  175919. if (png_ptr->filter_costs == NULL)
  175920. {
  175921. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  175922. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  175923. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  175924. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  175925. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  175926. {
  175927. png_ptr->inv_filter_costs[i] =
  175928. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  175929. }
  175930. }
  175931. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  175932. {
  175933. if (filter_costs == NULL || filter_costs[i] < 0.0)
  175934. {
  175935. png_ptr->inv_filter_costs[i] =
  175936. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  175937. }
  175938. else if (filter_costs[i] >= 1.0)
  175939. {
  175940. png_ptr->inv_filter_costs[i] =
  175941. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  175942. png_ptr->filter_costs[i] =
  175943. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  175944. }
  175945. }
  175946. }
  175947. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  175948. void PNGAPI
  175949. png_set_compression_level(png_structp png_ptr, int level)
  175950. {
  175951. png_debug(1, "in png_set_compression_level\n");
  175952. if (png_ptr == NULL)
  175953. return;
  175954. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  175955. png_ptr->zlib_level = level;
  175956. }
  175957. void PNGAPI
  175958. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  175959. {
  175960. png_debug(1, "in png_set_compression_mem_level\n");
  175961. if (png_ptr == NULL)
  175962. return;
  175963. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  175964. png_ptr->zlib_mem_level = mem_level;
  175965. }
  175966. void PNGAPI
  175967. png_set_compression_strategy(png_structp png_ptr, int strategy)
  175968. {
  175969. png_debug(1, "in png_set_compression_strategy\n");
  175970. if (png_ptr == NULL)
  175971. return;
  175972. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  175973. png_ptr->zlib_strategy = strategy;
  175974. }
  175975. void PNGAPI
  175976. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  175977. {
  175978. if (png_ptr == NULL)
  175979. return;
  175980. if (window_bits > 15)
  175981. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  175982. else if (window_bits < 8)
  175983. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  175984. #ifndef WBITS_8_OK
  175985. if (window_bits == 8)
  175986. {
  175987. png_warning(png_ptr, "Compression window is being reset to 512");
  175988. window_bits=9;
  175989. }
  175990. #endif
  175991. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  175992. png_ptr->zlib_window_bits = window_bits;
  175993. }
  175994. void PNGAPI
  175995. png_set_compression_method(png_structp png_ptr, int method)
  175996. {
  175997. png_debug(1, "in png_set_compression_method\n");
  175998. if (png_ptr == NULL)
  175999. return;
  176000. if (method != 8)
  176001. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176002. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176003. png_ptr->zlib_method = method;
  176004. }
  176005. void PNGAPI
  176006. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176007. {
  176008. if (png_ptr == NULL)
  176009. return;
  176010. png_ptr->write_row_fn = write_row_fn;
  176011. }
  176012. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176013. void PNGAPI
  176014. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176015. write_user_transform_fn)
  176016. {
  176017. png_debug(1, "in png_set_write_user_transform_fn\n");
  176018. if (png_ptr == NULL)
  176019. return;
  176020. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176021. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176022. }
  176023. #endif
  176024. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176025. void PNGAPI
  176026. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176027. int transforms, voidp params)
  176028. {
  176029. if (png_ptr == NULL || info_ptr == NULL)
  176030. return;
  176031. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176032. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176033. png_set_invert_alpha(png_ptr);
  176034. #endif
  176035. png_write_info(png_ptr, info_ptr);
  176036. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176037. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176038. png_set_invert_mono(png_ptr);
  176039. #endif
  176040. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176041. if ((transforms & PNG_TRANSFORM_SHIFT)
  176042. && (info_ptr->valid & PNG_INFO_sBIT))
  176043. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176044. #endif
  176045. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176046. if (transforms & PNG_TRANSFORM_PACKING)
  176047. png_set_packing(png_ptr);
  176048. #endif
  176049. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176050. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176051. png_set_swap_alpha(png_ptr);
  176052. #endif
  176053. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176054. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176055. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176056. #endif
  176057. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176058. if (transforms & PNG_TRANSFORM_BGR)
  176059. png_set_bgr(png_ptr);
  176060. #endif
  176061. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176062. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176063. png_set_swap(png_ptr);
  176064. #endif
  176065. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176066. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176067. png_set_packswap(png_ptr);
  176068. #endif
  176069. if (info_ptr->valid & PNG_INFO_IDAT)
  176070. png_write_image(png_ptr, info_ptr->row_pointers);
  176071. png_write_end(png_ptr, info_ptr);
  176072. transforms = transforms; /* quiet compiler warnings */
  176073. params = params;
  176074. }
  176075. #endif
  176076. #endif /* PNG_WRITE_SUPPORTED */
  176077. /*** End of inlined file: pngwrite.c ***/
  176078. /*** Start of inlined file: pngwtran.c ***/
  176079. #define PNG_INTERNAL
  176080. #ifdef PNG_WRITE_SUPPORTED
  176081. void /* PRIVATE */
  176082. png_do_write_transformations(png_structp png_ptr)
  176083. {
  176084. png_debug(1, "in png_do_write_transformations\n");
  176085. if (png_ptr == NULL)
  176086. return;
  176087. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176088. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176089. if(png_ptr->write_user_transform_fn != NULL)
  176090. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176091. (png_ptr, /* png_ptr */
  176092. &(png_ptr->row_info), /* row_info: */
  176093. png_ptr->row_buf + 1); /* start of pixel data for row */
  176094. #endif
  176095. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176096. if (png_ptr->transformations & PNG_FILLER)
  176097. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176098. png_ptr->flags);
  176099. #endif
  176100. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176101. if (png_ptr->transformations & PNG_PACKSWAP)
  176102. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176103. #endif
  176104. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176105. if (png_ptr->transformations & PNG_PACK)
  176106. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176107. (png_uint_32)png_ptr->bit_depth);
  176108. #endif
  176109. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176110. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176111. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176112. #endif
  176113. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176114. if (png_ptr->transformations & PNG_SHIFT)
  176115. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176116. &(png_ptr->shift));
  176117. #endif
  176118. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176119. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176120. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176121. #endif
  176122. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176123. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176124. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176125. #endif
  176126. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176127. if (png_ptr->transformations & PNG_BGR)
  176128. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176129. #endif
  176130. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176131. if (png_ptr->transformations & PNG_INVERT_MONO)
  176132. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176133. #endif
  176134. }
  176135. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176136. void /* PRIVATE */
  176137. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176138. {
  176139. png_debug(1, "in png_do_pack\n");
  176140. if (row_info->bit_depth == 8 &&
  176141. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176142. row != NULL && row_info != NULL &&
  176143. #endif
  176144. row_info->channels == 1)
  176145. {
  176146. switch ((int)bit_depth)
  176147. {
  176148. case 1:
  176149. {
  176150. png_bytep sp, dp;
  176151. int mask, v;
  176152. png_uint_32 i;
  176153. png_uint_32 row_width = row_info->width;
  176154. sp = row;
  176155. dp = row;
  176156. mask = 0x80;
  176157. v = 0;
  176158. for (i = 0; i < row_width; i++)
  176159. {
  176160. if (*sp != 0)
  176161. v |= mask;
  176162. sp++;
  176163. if (mask > 1)
  176164. mask >>= 1;
  176165. else
  176166. {
  176167. mask = 0x80;
  176168. *dp = (png_byte)v;
  176169. dp++;
  176170. v = 0;
  176171. }
  176172. }
  176173. if (mask != 0x80)
  176174. *dp = (png_byte)v;
  176175. break;
  176176. }
  176177. case 2:
  176178. {
  176179. png_bytep sp, dp;
  176180. int shift, v;
  176181. png_uint_32 i;
  176182. png_uint_32 row_width = row_info->width;
  176183. sp = row;
  176184. dp = row;
  176185. shift = 6;
  176186. v = 0;
  176187. for (i = 0; i < row_width; i++)
  176188. {
  176189. png_byte value;
  176190. value = (png_byte)(*sp & 0x03);
  176191. v |= (value << shift);
  176192. if (shift == 0)
  176193. {
  176194. shift = 6;
  176195. *dp = (png_byte)v;
  176196. dp++;
  176197. v = 0;
  176198. }
  176199. else
  176200. shift -= 2;
  176201. sp++;
  176202. }
  176203. if (shift != 6)
  176204. *dp = (png_byte)v;
  176205. break;
  176206. }
  176207. case 4:
  176208. {
  176209. png_bytep sp, dp;
  176210. int shift, v;
  176211. png_uint_32 i;
  176212. png_uint_32 row_width = row_info->width;
  176213. sp = row;
  176214. dp = row;
  176215. shift = 4;
  176216. v = 0;
  176217. for (i = 0; i < row_width; i++)
  176218. {
  176219. png_byte value;
  176220. value = (png_byte)(*sp & 0x0f);
  176221. v |= (value << shift);
  176222. if (shift == 0)
  176223. {
  176224. shift = 4;
  176225. *dp = (png_byte)v;
  176226. dp++;
  176227. v = 0;
  176228. }
  176229. else
  176230. shift -= 4;
  176231. sp++;
  176232. }
  176233. if (shift != 4)
  176234. *dp = (png_byte)v;
  176235. break;
  176236. }
  176237. }
  176238. row_info->bit_depth = (png_byte)bit_depth;
  176239. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176240. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176241. row_info->width);
  176242. }
  176243. }
  176244. #endif
  176245. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176246. void /* PRIVATE */
  176247. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176248. {
  176249. png_debug(1, "in png_do_shift\n");
  176250. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176251. if (row != NULL && row_info != NULL &&
  176252. #else
  176253. if (
  176254. #endif
  176255. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176256. {
  176257. int shift_start[4], shift_dec[4];
  176258. int channels = 0;
  176259. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176260. {
  176261. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176262. shift_dec[channels] = bit_depth->red;
  176263. channels++;
  176264. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176265. shift_dec[channels] = bit_depth->green;
  176266. channels++;
  176267. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176268. shift_dec[channels] = bit_depth->blue;
  176269. channels++;
  176270. }
  176271. else
  176272. {
  176273. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176274. shift_dec[channels] = bit_depth->gray;
  176275. channels++;
  176276. }
  176277. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176278. {
  176279. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176280. shift_dec[channels] = bit_depth->alpha;
  176281. channels++;
  176282. }
  176283. if (row_info->bit_depth < 8)
  176284. {
  176285. png_bytep bp = row;
  176286. png_uint_32 i;
  176287. png_byte mask;
  176288. png_uint_32 row_bytes = row_info->rowbytes;
  176289. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176290. mask = 0x55;
  176291. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176292. mask = 0x11;
  176293. else
  176294. mask = 0xff;
  176295. for (i = 0; i < row_bytes; i++, bp++)
  176296. {
  176297. png_uint_16 v;
  176298. int j;
  176299. v = *bp;
  176300. *bp = 0;
  176301. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176302. {
  176303. if (j > 0)
  176304. *bp |= (png_byte)((v << j) & 0xff);
  176305. else
  176306. *bp |= (png_byte)((v >> (-j)) & mask);
  176307. }
  176308. }
  176309. }
  176310. else if (row_info->bit_depth == 8)
  176311. {
  176312. png_bytep bp = row;
  176313. png_uint_32 i;
  176314. png_uint_32 istop = channels * row_info->width;
  176315. for (i = 0; i < istop; i++, bp++)
  176316. {
  176317. png_uint_16 v;
  176318. int j;
  176319. int c = (int)(i%channels);
  176320. v = *bp;
  176321. *bp = 0;
  176322. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176323. {
  176324. if (j > 0)
  176325. *bp |= (png_byte)((v << j) & 0xff);
  176326. else
  176327. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176328. }
  176329. }
  176330. }
  176331. else
  176332. {
  176333. png_bytep bp;
  176334. png_uint_32 i;
  176335. png_uint_32 istop = channels * row_info->width;
  176336. for (bp = row, i = 0; i < istop; i++)
  176337. {
  176338. int c = (int)(i%channels);
  176339. png_uint_16 value, v;
  176340. int j;
  176341. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176342. value = 0;
  176343. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176344. {
  176345. if (j > 0)
  176346. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176347. else
  176348. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176349. }
  176350. *bp++ = (png_byte)(value >> 8);
  176351. *bp++ = (png_byte)(value & 0xff);
  176352. }
  176353. }
  176354. }
  176355. }
  176356. #endif
  176357. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176358. void /* PRIVATE */
  176359. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176360. {
  176361. png_debug(1, "in png_do_write_swap_alpha\n");
  176362. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176363. if (row != NULL && row_info != NULL)
  176364. #endif
  176365. {
  176366. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176367. {
  176368. if (row_info->bit_depth == 8)
  176369. {
  176370. png_bytep sp, dp;
  176371. png_uint_32 i;
  176372. png_uint_32 row_width = row_info->width;
  176373. for (i = 0, sp = dp = row; i < row_width; i++)
  176374. {
  176375. png_byte save = *(sp++);
  176376. *(dp++) = *(sp++);
  176377. *(dp++) = *(sp++);
  176378. *(dp++) = *(sp++);
  176379. *(dp++) = save;
  176380. }
  176381. }
  176382. else
  176383. {
  176384. png_bytep sp, dp;
  176385. png_uint_32 i;
  176386. png_uint_32 row_width = row_info->width;
  176387. for (i = 0, sp = dp = row; i < row_width; i++)
  176388. {
  176389. png_byte save[2];
  176390. save[0] = *(sp++);
  176391. save[1] = *(sp++);
  176392. *(dp++) = *(sp++);
  176393. *(dp++) = *(sp++);
  176394. *(dp++) = *(sp++);
  176395. *(dp++) = *(sp++);
  176396. *(dp++) = *(sp++);
  176397. *(dp++) = *(sp++);
  176398. *(dp++) = save[0];
  176399. *(dp++) = save[1];
  176400. }
  176401. }
  176402. }
  176403. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176404. {
  176405. if (row_info->bit_depth == 8)
  176406. {
  176407. png_bytep sp, dp;
  176408. png_uint_32 i;
  176409. png_uint_32 row_width = row_info->width;
  176410. for (i = 0, sp = dp = row; i < row_width; i++)
  176411. {
  176412. png_byte save = *(sp++);
  176413. *(dp++) = *(sp++);
  176414. *(dp++) = save;
  176415. }
  176416. }
  176417. else
  176418. {
  176419. png_bytep sp, dp;
  176420. png_uint_32 i;
  176421. png_uint_32 row_width = row_info->width;
  176422. for (i = 0, sp = dp = row; i < row_width; i++)
  176423. {
  176424. png_byte save[2];
  176425. save[0] = *(sp++);
  176426. save[1] = *(sp++);
  176427. *(dp++) = *(sp++);
  176428. *(dp++) = *(sp++);
  176429. *(dp++) = save[0];
  176430. *(dp++) = save[1];
  176431. }
  176432. }
  176433. }
  176434. }
  176435. }
  176436. #endif
  176437. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176438. void /* PRIVATE */
  176439. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176440. {
  176441. png_debug(1, "in png_do_write_invert_alpha\n");
  176442. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176443. if (row != NULL && row_info != NULL)
  176444. #endif
  176445. {
  176446. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176447. {
  176448. if (row_info->bit_depth == 8)
  176449. {
  176450. png_bytep sp, dp;
  176451. png_uint_32 i;
  176452. png_uint_32 row_width = row_info->width;
  176453. for (i = 0, sp = dp = row; i < row_width; i++)
  176454. {
  176455. sp+=3; dp = sp;
  176456. *(dp++) = (png_byte)(255 - *(sp++));
  176457. }
  176458. }
  176459. else
  176460. {
  176461. png_bytep sp, dp;
  176462. png_uint_32 i;
  176463. png_uint_32 row_width = row_info->width;
  176464. for (i = 0, sp = dp = row; i < row_width; i++)
  176465. {
  176466. sp+=6; dp = sp;
  176467. *(dp++) = (png_byte)(255 - *(sp++));
  176468. *(dp++) = (png_byte)(255 - *(sp++));
  176469. }
  176470. }
  176471. }
  176472. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176473. {
  176474. if (row_info->bit_depth == 8)
  176475. {
  176476. png_bytep sp, dp;
  176477. png_uint_32 i;
  176478. png_uint_32 row_width = row_info->width;
  176479. for (i = 0, sp = dp = row; i < row_width; i++)
  176480. {
  176481. *(dp++) = *(sp++);
  176482. *(dp++) = (png_byte)(255 - *(sp++));
  176483. }
  176484. }
  176485. else
  176486. {
  176487. png_bytep sp, dp;
  176488. png_uint_32 i;
  176489. png_uint_32 row_width = row_info->width;
  176490. for (i = 0, sp = dp = row; i < row_width; i++)
  176491. {
  176492. sp+=2; dp = sp;
  176493. *(dp++) = (png_byte)(255 - *(sp++));
  176494. *(dp++) = (png_byte)(255 - *(sp++));
  176495. }
  176496. }
  176497. }
  176498. }
  176499. }
  176500. #endif
  176501. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176502. void /* PRIVATE */
  176503. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176504. {
  176505. png_debug(1, "in png_do_write_intrapixel\n");
  176506. if (
  176507. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176508. row != NULL && row_info != NULL &&
  176509. #endif
  176510. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176511. {
  176512. int bytes_per_pixel;
  176513. png_uint_32 row_width = row_info->width;
  176514. if (row_info->bit_depth == 8)
  176515. {
  176516. png_bytep rp;
  176517. png_uint_32 i;
  176518. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176519. bytes_per_pixel = 3;
  176520. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176521. bytes_per_pixel = 4;
  176522. else
  176523. return;
  176524. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176525. {
  176526. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176527. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176528. }
  176529. }
  176530. else if (row_info->bit_depth == 16)
  176531. {
  176532. png_bytep rp;
  176533. png_uint_32 i;
  176534. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176535. bytes_per_pixel = 6;
  176536. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176537. bytes_per_pixel = 8;
  176538. else
  176539. return;
  176540. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176541. {
  176542. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176543. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176544. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176545. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176546. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176547. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176548. *(rp+1) = (png_byte)(red & 0xff);
  176549. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176550. *(rp+5) = (png_byte)(blue & 0xff);
  176551. }
  176552. }
  176553. }
  176554. }
  176555. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176556. #endif /* PNG_WRITE_SUPPORTED */
  176557. /*** End of inlined file: pngwtran.c ***/
  176558. /*** Start of inlined file: pngwutil.c ***/
  176559. #define PNG_INTERNAL
  176560. #ifdef PNG_WRITE_SUPPORTED
  176561. void PNGAPI
  176562. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176563. {
  176564. buf[0] = (png_byte)((i >> 24) & 0xff);
  176565. buf[1] = (png_byte)((i >> 16) & 0xff);
  176566. buf[2] = (png_byte)((i >> 8) & 0xff);
  176567. buf[3] = (png_byte)(i & 0xff);
  176568. }
  176569. void PNGAPI
  176570. png_save_int_32(png_bytep buf, png_int_32 i)
  176571. {
  176572. buf[0] = (png_byte)((i >> 24) & 0xff);
  176573. buf[1] = (png_byte)((i >> 16) & 0xff);
  176574. buf[2] = (png_byte)((i >> 8) & 0xff);
  176575. buf[3] = (png_byte)(i & 0xff);
  176576. }
  176577. void PNGAPI
  176578. png_save_uint_16(png_bytep buf, unsigned int i)
  176579. {
  176580. buf[0] = (png_byte)((i >> 8) & 0xff);
  176581. buf[1] = (png_byte)(i & 0xff);
  176582. }
  176583. void PNGAPI
  176584. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176585. png_bytep data, png_size_t length)
  176586. {
  176587. if(png_ptr == NULL) return;
  176588. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176589. png_write_chunk_data(png_ptr, data, length);
  176590. png_write_chunk_end(png_ptr);
  176591. }
  176592. void PNGAPI
  176593. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176594. png_uint_32 length)
  176595. {
  176596. png_byte buf[4];
  176597. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176598. if(png_ptr == NULL) return;
  176599. png_save_uint_32(buf, length);
  176600. png_write_data(png_ptr, buf, (png_size_t)4);
  176601. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176602. png_reset_crc(png_ptr);
  176603. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176604. }
  176605. void PNGAPI
  176606. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176607. {
  176608. if(png_ptr == NULL) return;
  176609. if (data != NULL && length > 0)
  176610. {
  176611. png_calculate_crc(png_ptr, data, length);
  176612. png_write_data(png_ptr, data, length);
  176613. }
  176614. }
  176615. void PNGAPI
  176616. png_write_chunk_end(png_structp png_ptr)
  176617. {
  176618. png_byte buf[4];
  176619. if(png_ptr == NULL) return;
  176620. png_save_uint_32(buf, png_ptr->crc);
  176621. png_write_data(png_ptr, buf, (png_size_t)4);
  176622. }
  176623. void /* PRIVATE */
  176624. png_write_sig(png_structp png_ptr)
  176625. {
  176626. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176627. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176628. (png_size_t)8 - png_ptr->sig_bytes);
  176629. if(png_ptr->sig_bytes < 3)
  176630. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176631. }
  176632. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176633. typedef struct
  176634. {
  176635. char *input; /* the uncompressed input data */
  176636. int input_len; /* its length */
  176637. int num_output_ptr; /* number of output pointers used */
  176638. int max_output_ptr; /* size of output_ptr */
  176639. png_charpp output_ptr; /* array of pointers to output */
  176640. } compression_state;
  176641. static int /* PRIVATE */
  176642. png_text_compress(png_structp png_ptr,
  176643. png_charp text, png_size_t text_len, int compression,
  176644. compression_state *comp)
  176645. {
  176646. int ret;
  176647. comp->num_output_ptr = 0;
  176648. comp->max_output_ptr = 0;
  176649. comp->output_ptr = NULL;
  176650. comp->input = NULL;
  176651. comp->input_len = 0;
  176652. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176653. {
  176654. comp->input = text;
  176655. comp->input_len = text_len;
  176656. return((int)text_len);
  176657. }
  176658. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176659. {
  176660. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176661. char msg[50];
  176662. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176663. png_warning(png_ptr, msg);
  176664. #else
  176665. png_warning(png_ptr, "Unknown compression type");
  176666. #endif
  176667. }
  176668. png_ptr->zstream.avail_in = (uInt)text_len;
  176669. png_ptr->zstream.next_in = (Bytef *)text;
  176670. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176671. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176672. do
  176673. {
  176674. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176675. if (ret != Z_OK)
  176676. {
  176677. if (png_ptr->zstream.msg != NULL)
  176678. png_error(png_ptr, png_ptr->zstream.msg);
  176679. else
  176680. png_error(png_ptr, "zlib error");
  176681. }
  176682. if (!(png_ptr->zstream.avail_out))
  176683. {
  176684. if (comp->num_output_ptr >= comp->max_output_ptr)
  176685. {
  176686. int old_max;
  176687. old_max = comp->max_output_ptr;
  176688. comp->max_output_ptr = comp->num_output_ptr + 4;
  176689. if (comp->output_ptr != NULL)
  176690. {
  176691. png_charpp old_ptr;
  176692. old_ptr = comp->output_ptr;
  176693. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176694. (png_uint_32)(comp->max_output_ptr *
  176695. png_sizeof (png_charpp)));
  176696. png_memcpy(comp->output_ptr, old_ptr, old_max
  176697. * png_sizeof (png_charp));
  176698. png_free(png_ptr, old_ptr);
  176699. }
  176700. else
  176701. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176702. (png_uint_32)(comp->max_output_ptr *
  176703. png_sizeof (png_charp)));
  176704. }
  176705. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  176706. (png_uint_32)png_ptr->zbuf_size);
  176707. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176708. png_ptr->zbuf_size);
  176709. comp->num_output_ptr++;
  176710. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176711. png_ptr->zstream.next_out = png_ptr->zbuf;
  176712. }
  176713. } while (png_ptr->zstream.avail_in);
  176714. do
  176715. {
  176716. ret = deflate(&png_ptr->zstream, Z_FINISH);
  176717. if (ret == Z_OK)
  176718. {
  176719. if (!(png_ptr->zstream.avail_out))
  176720. {
  176721. if (comp->num_output_ptr >= comp->max_output_ptr)
  176722. {
  176723. int old_max;
  176724. old_max = comp->max_output_ptr;
  176725. comp->max_output_ptr = comp->num_output_ptr + 4;
  176726. if (comp->output_ptr != NULL)
  176727. {
  176728. png_charpp old_ptr;
  176729. old_ptr = comp->output_ptr;
  176730. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176731. (png_uint_32)(comp->max_output_ptr *
  176732. png_sizeof (png_charpp)));
  176733. png_memcpy(comp->output_ptr, old_ptr,
  176734. old_max * png_sizeof (png_charp));
  176735. png_free(png_ptr, old_ptr);
  176736. }
  176737. else
  176738. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176739. (png_uint_32)(comp->max_output_ptr *
  176740. png_sizeof (png_charp)));
  176741. }
  176742. comp->output_ptr[comp->num_output_ptr] =
  176743. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  176744. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176745. png_ptr->zbuf_size);
  176746. comp->num_output_ptr++;
  176747. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176748. png_ptr->zstream.next_out = png_ptr->zbuf;
  176749. }
  176750. }
  176751. else if (ret != Z_STREAM_END)
  176752. {
  176753. if (png_ptr->zstream.msg != NULL)
  176754. png_error(png_ptr, png_ptr->zstream.msg);
  176755. else
  176756. png_error(png_ptr, "zlib error");
  176757. }
  176758. } while (ret != Z_STREAM_END);
  176759. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  176760. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  176761. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  176762. return((int)text_len);
  176763. }
  176764. static void /* PRIVATE */
  176765. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  176766. {
  176767. int i;
  176768. if (comp->input)
  176769. {
  176770. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  176771. (png_size_t)comp->input_len);
  176772. return;
  176773. }
  176774. for (i = 0; i < comp->num_output_ptr; i++)
  176775. {
  176776. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  176777. png_ptr->zbuf_size);
  176778. png_free(png_ptr, comp->output_ptr[i]);
  176779. comp->output_ptr[i]=NULL;
  176780. }
  176781. if (comp->max_output_ptr != 0)
  176782. png_free(png_ptr, comp->output_ptr);
  176783. comp->output_ptr=NULL;
  176784. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  176785. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  176786. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176787. deflateReset(&png_ptr->zstream);
  176788. png_ptr->zstream.data_type = Z_BINARY;
  176789. }
  176790. #endif
  176791. void /* PRIVATE */
  176792. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  176793. int bit_depth, int color_type, int compression_type, int filter_type,
  176794. int interlace_type)
  176795. {
  176796. #ifdef PNG_USE_LOCAL_ARRAYS
  176797. PNG_IHDR;
  176798. #endif
  176799. png_byte buf[13]; /* buffer to store the IHDR info */
  176800. png_debug(1, "in png_write_IHDR\n");
  176801. switch (color_type)
  176802. {
  176803. case PNG_COLOR_TYPE_GRAY:
  176804. switch (bit_depth)
  176805. {
  176806. case 1:
  176807. case 2:
  176808. case 4:
  176809. case 8:
  176810. case 16: png_ptr->channels = 1; break;
  176811. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  176812. }
  176813. break;
  176814. case PNG_COLOR_TYPE_RGB:
  176815. if (bit_depth != 8 && bit_depth != 16)
  176816. png_error(png_ptr, "Invalid bit depth for RGB image");
  176817. png_ptr->channels = 3;
  176818. break;
  176819. case PNG_COLOR_TYPE_PALETTE:
  176820. switch (bit_depth)
  176821. {
  176822. case 1:
  176823. case 2:
  176824. case 4:
  176825. case 8: png_ptr->channels = 1; break;
  176826. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  176827. }
  176828. break;
  176829. case PNG_COLOR_TYPE_GRAY_ALPHA:
  176830. if (bit_depth != 8 && bit_depth != 16)
  176831. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  176832. png_ptr->channels = 2;
  176833. break;
  176834. case PNG_COLOR_TYPE_RGB_ALPHA:
  176835. if (bit_depth != 8 && bit_depth != 16)
  176836. png_error(png_ptr, "Invalid bit depth for RGBA image");
  176837. png_ptr->channels = 4;
  176838. break;
  176839. default:
  176840. png_error(png_ptr, "Invalid image color type specified");
  176841. }
  176842. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  176843. {
  176844. png_warning(png_ptr, "Invalid compression type specified");
  176845. compression_type = PNG_COMPRESSION_TYPE_BASE;
  176846. }
  176847. if (
  176848. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176849. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176850. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  176851. (color_type == PNG_COLOR_TYPE_RGB ||
  176852. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  176853. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  176854. #endif
  176855. filter_type != PNG_FILTER_TYPE_BASE)
  176856. {
  176857. png_warning(png_ptr, "Invalid filter type specified");
  176858. filter_type = PNG_FILTER_TYPE_BASE;
  176859. }
  176860. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  176861. if (interlace_type != PNG_INTERLACE_NONE &&
  176862. interlace_type != PNG_INTERLACE_ADAM7)
  176863. {
  176864. png_warning(png_ptr, "Invalid interlace type specified");
  176865. interlace_type = PNG_INTERLACE_ADAM7;
  176866. }
  176867. #else
  176868. interlace_type=PNG_INTERLACE_NONE;
  176869. #endif
  176870. png_ptr->bit_depth = (png_byte)bit_depth;
  176871. png_ptr->color_type = (png_byte)color_type;
  176872. png_ptr->interlaced = (png_byte)interlace_type;
  176873. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176874. png_ptr->filter_type = (png_byte)filter_type;
  176875. #endif
  176876. png_ptr->compression_type = (png_byte)compression_type;
  176877. png_ptr->width = width;
  176878. png_ptr->height = height;
  176879. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  176880. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  176881. png_ptr->usr_width = png_ptr->width;
  176882. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  176883. png_ptr->usr_channels = png_ptr->channels;
  176884. png_save_uint_32(buf, width);
  176885. png_save_uint_32(buf + 4, height);
  176886. buf[8] = (png_byte)bit_depth;
  176887. buf[9] = (png_byte)color_type;
  176888. buf[10] = (png_byte)compression_type;
  176889. buf[11] = (png_byte)filter_type;
  176890. buf[12] = (png_byte)interlace_type;
  176891. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  176892. png_ptr->zstream.zalloc = png_zalloc;
  176893. png_ptr->zstream.zfree = png_zfree;
  176894. png_ptr->zstream.opaque = (voidpf)png_ptr;
  176895. if (!(png_ptr->do_filter))
  176896. {
  176897. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  176898. png_ptr->bit_depth < 8)
  176899. png_ptr->do_filter = PNG_FILTER_NONE;
  176900. else
  176901. png_ptr->do_filter = PNG_ALL_FILTERS;
  176902. }
  176903. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  176904. {
  176905. if (png_ptr->do_filter != PNG_FILTER_NONE)
  176906. png_ptr->zlib_strategy = Z_FILTERED;
  176907. else
  176908. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  176909. }
  176910. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  176911. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  176912. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  176913. png_ptr->zlib_mem_level = 8;
  176914. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  176915. png_ptr->zlib_window_bits = 15;
  176916. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  176917. png_ptr->zlib_method = 8;
  176918. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  176919. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  176920. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  176921. png_error(png_ptr, "zlib failed to initialize compressor");
  176922. png_ptr->zstream.next_out = png_ptr->zbuf;
  176923. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176924. png_ptr->zstream.data_type = Z_BINARY;
  176925. png_ptr->mode = PNG_HAVE_IHDR;
  176926. }
  176927. void /* PRIVATE */
  176928. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  176929. {
  176930. #ifdef PNG_USE_LOCAL_ARRAYS
  176931. PNG_PLTE;
  176932. #endif
  176933. png_uint_32 i;
  176934. png_colorp pal_ptr;
  176935. png_byte buf[3];
  176936. png_debug(1, "in png_write_PLTE\n");
  176937. if ((
  176938. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176939. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  176940. #endif
  176941. num_pal == 0) || num_pal > 256)
  176942. {
  176943. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  176944. {
  176945. png_error(png_ptr, "Invalid number of colors in palette");
  176946. }
  176947. else
  176948. {
  176949. png_warning(png_ptr, "Invalid number of colors in palette");
  176950. return;
  176951. }
  176952. }
  176953. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  176954. {
  176955. png_warning(png_ptr,
  176956. "Ignoring request to write a PLTE chunk in grayscale PNG");
  176957. return;
  176958. }
  176959. png_ptr->num_palette = (png_uint_16)num_pal;
  176960. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  176961. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  176962. #ifndef PNG_NO_POINTER_INDEXING
  176963. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  176964. {
  176965. buf[0] = pal_ptr->red;
  176966. buf[1] = pal_ptr->green;
  176967. buf[2] = pal_ptr->blue;
  176968. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  176969. }
  176970. #else
  176971. pal_ptr=palette;
  176972. for (i = 0; i < num_pal; i++)
  176973. {
  176974. buf[0] = pal_ptr[i].red;
  176975. buf[1] = pal_ptr[i].green;
  176976. buf[2] = pal_ptr[i].blue;
  176977. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  176978. }
  176979. #endif
  176980. png_write_chunk_end(png_ptr);
  176981. png_ptr->mode |= PNG_HAVE_PLTE;
  176982. }
  176983. void /* PRIVATE */
  176984. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  176985. {
  176986. #ifdef PNG_USE_LOCAL_ARRAYS
  176987. PNG_IDAT;
  176988. #endif
  176989. png_debug(1, "in png_write_IDAT\n");
  176990. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  176991. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  176992. {
  176993. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  176994. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  176995. {
  176996. if (length >= 2 &&
  176997. png_ptr->height < 16384 && png_ptr->width < 16384)
  176998. {
  176999. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177000. ((png_ptr->width *
  177001. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177002. unsigned int z_cinfo = z_cmf >> 4;
  177003. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177004. while (uncompressed_idat_size <= half_z_window_size &&
  177005. half_z_window_size >= 256)
  177006. {
  177007. z_cinfo--;
  177008. half_z_window_size >>= 1;
  177009. }
  177010. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177011. if (data[0] != (png_byte)z_cmf)
  177012. {
  177013. data[0] = (png_byte)z_cmf;
  177014. data[1] &= 0xe0;
  177015. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177016. }
  177017. }
  177018. }
  177019. else
  177020. png_error(png_ptr,
  177021. "Invalid zlib compression method or flags in IDAT");
  177022. }
  177023. png_write_chunk(png_ptr, png_IDAT, data, length);
  177024. png_ptr->mode |= PNG_HAVE_IDAT;
  177025. }
  177026. void /* PRIVATE */
  177027. png_write_IEND(png_structp png_ptr)
  177028. {
  177029. #ifdef PNG_USE_LOCAL_ARRAYS
  177030. PNG_IEND;
  177031. #endif
  177032. png_debug(1, "in png_write_IEND\n");
  177033. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177034. (png_size_t)0);
  177035. png_ptr->mode |= PNG_HAVE_IEND;
  177036. }
  177037. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177038. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177039. void /* PRIVATE */
  177040. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177041. {
  177042. #ifdef PNG_USE_LOCAL_ARRAYS
  177043. PNG_gAMA;
  177044. #endif
  177045. png_uint_32 igamma;
  177046. png_byte buf[4];
  177047. png_debug(1, "in png_write_gAMA\n");
  177048. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177049. png_save_uint_32(buf, igamma);
  177050. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177051. }
  177052. #endif
  177053. #ifdef PNG_FIXED_POINT_SUPPORTED
  177054. void /* PRIVATE */
  177055. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177056. {
  177057. #ifdef PNG_USE_LOCAL_ARRAYS
  177058. PNG_gAMA;
  177059. #endif
  177060. png_byte buf[4];
  177061. png_debug(1, "in png_write_gAMA\n");
  177062. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177063. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177064. }
  177065. #endif
  177066. #endif
  177067. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177068. void /* PRIVATE */
  177069. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177070. {
  177071. #ifdef PNG_USE_LOCAL_ARRAYS
  177072. PNG_sRGB;
  177073. #endif
  177074. png_byte buf[1];
  177075. png_debug(1, "in png_write_sRGB\n");
  177076. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177077. png_warning(png_ptr,
  177078. "Invalid sRGB rendering intent specified");
  177079. buf[0]=(png_byte)srgb_intent;
  177080. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177081. }
  177082. #endif
  177083. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177084. void /* PRIVATE */
  177085. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177086. png_charp profile, int profile_len)
  177087. {
  177088. #ifdef PNG_USE_LOCAL_ARRAYS
  177089. PNG_iCCP;
  177090. #endif
  177091. png_size_t name_len;
  177092. png_charp new_name;
  177093. compression_state comp;
  177094. int embedded_profile_len = 0;
  177095. png_debug(1, "in png_write_iCCP\n");
  177096. comp.num_output_ptr = 0;
  177097. comp.max_output_ptr = 0;
  177098. comp.output_ptr = NULL;
  177099. comp.input = NULL;
  177100. comp.input_len = 0;
  177101. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177102. &new_name)) == 0)
  177103. {
  177104. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177105. return;
  177106. }
  177107. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177108. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177109. if (profile == NULL)
  177110. profile_len = 0;
  177111. if (profile_len > 3)
  177112. embedded_profile_len =
  177113. ((*( (png_bytep)profile ))<<24) |
  177114. ((*( (png_bytep)profile+1))<<16) |
  177115. ((*( (png_bytep)profile+2))<< 8) |
  177116. ((*( (png_bytep)profile+3)) );
  177117. if (profile_len < embedded_profile_len)
  177118. {
  177119. png_warning(png_ptr,
  177120. "Embedded profile length too large in iCCP chunk");
  177121. return;
  177122. }
  177123. if (profile_len > embedded_profile_len)
  177124. {
  177125. png_warning(png_ptr,
  177126. "Truncating profile to actual length in iCCP chunk");
  177127. profile_len = embedded_profile_len;
  177128. }
  177129. if (profile_len)
  177130. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177131. PNG_COMPRESSION_TYPE_BASE, &comp);
  177132. png_write_chunk_start(png_ptr, png_iCCP,
  177133. (png_uint_32)name_len+profile_len+2);
  177134. new_name[name_len+1]=0x00;
  177135. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177136. if (profile_len)
  177137. png_write_compressed_data_out(png_ptr, &comp);
  177138. png_write_chunk_end(png_ptr);
  177139. png_free(png_ptr, new_name);
  177140. }
  177141. #endif
  177142. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177143. void /* PRIVATE */
  177144. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177145. {
  177146. #ifdef PNG_USE_LOCAL_ARRAYS
  177147. PNG_sPLT;
  177148. #endif
  177149. png_size_t name_len;
  177150. png_charp new_name;
  177151. png_byte entrybuf[10];
  177152. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177153. int palette_size = entry_size * spalette->nentries;
  177154. png_sPLT_entryp ep;
  177155. #ifdef PNG_NO_POINTER_INDEXING
  177156. int i;
  177157. #endif
  177158. png_debug(1, "in png_write_sPLT\n");
  177159. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177160. spalette->name, &new_name))==0)
  177161. {
  177162. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177163. return;
  177164. }
  177165. png_write_chunk_start(png_ptr, png_sPLT,
  177166. (png_uint_32)(name_len + 2 + palette_size));
  177167. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177168. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177169. #ifndef PNG_NO_POINTER_INDEXING
  177170. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177171. {
  177172. if (spalette->depth == 8)
  177173. {
  177174. entrybuf[0] = (png_byte)ep->red;
  177175. entrybuf[1] = (png_byte)ep->green;
  177176. entrybuf[2] = (png_byte)ep->blue;
  177177. entrybuf[3] = (png_byte)ep->alpha;
  177178. png_save_uint_16(entrybuf + 4, ep->frequency);
  177179. }
  177180. else
  177181. {
  177182. png_save_uint_16(entrybuf + 0, ep->red);
  177183. png_save_uint_16(entrybuf + 2, ep->green);
  177184. png_save_uint_16(entrybuf + 4, ep->blue);
  177185. png_save_uint_16(entrybuf + 6, ep->alpha);
  177186. png_save_uint_16(entrybuf + 8, ep->frequency);
  177187. }
  177188. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177189. }
  177190. #else
  177191. ep=spalette->entries;
  177192. for (i=0; i>spalette->nentries; i++)
  177193. {
  177194. if (spalette->depth == 8)
  177195. {
  177196. entrybuf[0] = (png_byte)ep[i].red;
  177197. entrybuf[1] = (png_byte)ep[i].green;
  177198. entrybuf[2] = (png_byte)ep[i].blue;
  177199. entrybuf[3] = (png_byte)ep[i].alpha;
  177200. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177201. }
  177202. else
  177203. {
  177204. png_save_uint_16(entrybuf + 0, ep[i].red);
  177205. png_save_uint_16(entrybuf + 2, ep[i].green);
  177206. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177207. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177208. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177209. }
  177210. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177211. }
  177212. #endif
  177213. png_write_chunk_end(png_ptr);
  177214. png_free(png_ptr, new_name);
  177215. }
  177216. #endif
  177217. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177218. void /* PRIVATE */
  177219. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177220. {
  177221. #ifdef PNG_USE_LOCAL_ARRAYS
  177222. PNG_sBIT;
  177223. #endif
  177224. png_byte buf[4];
  177225. png_size_t size;
  177226. png_debug(1, "in png_write_sBIT\n");
  177227. if (color_type & PNG_COLOR_MASK_COLOR)
  177228. {
  177229. png_byte maxbits;
  177230. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177231. png_ptr->usr_bit_depth);
  177232. if (sbit->red == 0 || sbit->red > maxbits ||
  177233. sbit->green == 0 || sbit->green > maxbits ||
  177234. sbit->blue == 0 || sbit->blue > maxbits)
  177235. {
  177236. png_warning(png_ptr, "Invalid sBIT depth specified");
  177237. return;
  177238. }
  177239. buf[0] = sbit->red;
  177240. buf[1] = sbit->green;
  177241. buf[2] = sbit->blue;
  177242. size = 3;
  177243. }
  177244. else
  177245. {
  177246. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177247. {
  177248. png_warning(png_ptr, "Invalid sBIT depth specified");
  177249. return;
  177250. }
  177251. buf[0] = sbit->gray;
  177252. size = 1;
  177253. }
  177254. if (color_type & PNG_COLOR_MASK_ALPHA)
  177255. {
  177256. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177257. {
  177258. png_warning(png_ptr, "Invalid sBIT depth specified");
  177259. return;
  177260. }
  177261. buf[size++] = sbit->alpha;
  177262. }
  177263. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177264. }
  177265. #endif
  177266. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177267. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177268. void /* PRIVATE */
  177269. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177270. double red_x, double red_y, double green_x, double green_y,
  177271. double blue_x, double blue_y)
  177272. {
  177273. #ifdef PNG_USE_LOCAL_ARRAYS
  177274. PNG_cHRM;
  177275. #endif
  177276. png_byte buf[32];
  177277. png_uint_32 itemp;
  177278. png_debug(1, "in png_write_cHRM\n");
  177279. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177280. white_x + white_y > 1.0)
  177281. {
  177282. png_warning(png_ptr, "Invalid cHRM white point specified");
  177283. #if !defined(PNG_NO_CONSOLE_IO)
  177284. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177285. #endif
  177286. return;
  177287. }
  177288. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177289. png_save_uint_32(buf, itemp);
  177290. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177291. png_save_uint_32(buf + 4, itemp);
  177292. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177293. {
  177294. png_warning(png_ptr, "Invalid cHRM red point specified");
  177295. return;
  177296. }
  177297. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177298. png_save_uint_32(buf + 8, itemp);
  177299. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177300. png_save_uint_32(buf + 12, itemp);
  177301. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177302. {
  177303. png_warning(png_ptr, "Invalid cHRM green point specified");
  177304. return;
  177305. }
  177306. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177307. png_save_uint_32(buf + 16, itemp);
  177308. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177309. png_save_uint_32(buf + 20, itemp);
  177310. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177311. {
  177312. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177313. return;
  177314. }
  177315. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177316. png_save_uint_32(buf + 24, itemp);
  177317. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177318. png_save_uint_32(buf + 28, itemp);
  177319. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177320. }
  177321. #endif
  177322. #ifdef PNG_FIXED_POINT_SUPPORTED
  177323. void /* PRIVATE */
  177324. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177325. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177326. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177327. png_fixed_point blue_y)
  177328. {
  177329. #ifdef PNG_USE_LOCAL_ARRAYS
  177330. PNG_cHRM;
  177331. #endif
  177332. png_byte buf[32];
  177333. png_debug(1, "in png_write_cHRM\n");
  177334. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177335. {
  177336. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177337. #if !defined(PNG_NO_CONSOLE_IO)
  177338. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177339. #endif
  177340. return;
  177341. }
  177342. png_save_uint_32(buf, (png_uint_32)white_x);
  177343. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177344. if (red_x + red_y > 100000L)
  177345. {
  177346. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177347. return;
  177348. }
  177349. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177350. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177351. if (green_x + green_y > 100000L)
  177352. {
  177353. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177354. return;
  177355. }
  177356. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177357. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177358. if (blue_x + blue_y > 100000L)
  177359. {
  177360. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177361. return;
  177362. }
  177363. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177364. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177365. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177366. }
  177367. #endif
  177368. #endif
  177369. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177370. void /* PRIVATE */
  177371. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177372. int num_trans, int color_type)
  177373. {
  177374. #ifdef PNG_USE_LOCAL_ARRAYS
  177375. PNG_tRNS;
  177376. #endif
  177377. png_byte buf[6];
  177378. png_debug(1, "in png_write_tRNS\n");
  177379. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177380. {
  177381. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177382. {
  177383. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177384. return;
  177385. }
  177386. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177387. }
  177388. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177389. {
  177390. if(tran->gray >= (1 << png_ptr->bit_depth))
  177391. {
  177392. png_warning(png_ptr,
  177393. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177394. return;
  177395. }
  177396. png_save_uint_16(buf, tran->gray);
  177397. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177398. }
  177399. else if (color_type == PNG_COLOR_TYPE_RGB)
  177400. {
  177401. png_save_uint_16(buf, tran->red);
  177402. png_save_uint_16(buf + 2, tran->green);
  177403. png_save_uint_16(buf + 4, tran->blue);
  177404. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177405. {
  177406. png_warning(png_ptr,
  177407. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177408. return;
  177409. }
  177410. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177411. }
  177412. else
  177413. {
  177414. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177415. }
  177416. }
  177417. #endif
  177418. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177419. void /* PRIVATE */
  177420. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177421. {
  177422. #ifdef PNG_USE_LOCAL_ARRAYS
  177423. PNG_bKGD;
  177424. #endif
  177425. png_byte buf[6];
  177426. png_debug(1, "in png_write_bKGD\n");
  177427. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177428. {
  177429. if (
  177430. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177431. (png_ptr->num_palette ||
  177432. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177433. #endif
  177434. back->index > png_ptr->num_palette)
  177435. {
  177436. png_warning(png_ptr, "Invalid background palette index");
  177437. return;
  177438. }
  177439. buf[0] = back->index;
  177440. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177441. }
  177442. else if (color_type & PNG_COLOR_MASK_COLOR)
  177443. {
  177444. png_save_uint_16(buf, back->red);
  177445. png_save_uint_16(buf + 2, back->green);
  177446. png_save_uint_16(buf + 4, back->blue);
  177447. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177448. {
  177449. png_warning(png_ptr,
  177450. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177451. return;
  177452. }
  177453. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177454. }
  177455. else
  177456. {
  177457. if(back->gray >= (1 << png_ptr->bit_depth))
  177458. {
  177459. png_warning(png_ptr,
  177460. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177461. return;
  177462. }
  177463. png_save_uint_16(buf, back->gray);
  177464. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177465. }
  177466. }
  177467. #endif
  177468. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177469. void /* PRIVATE */
  177470. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177471. {
  177472. #ifdef PNG_USE_LOCAL_ARRAYS
  177473. PNG_hIST;
  177474. #endif
  177475. int i;
  177476. png_byte buf[3];
  177477. png_debug(1, "in png_write_hIST\n");
  177478. if (num_hist > (int)png_ptr->num_palette)
  177479. {
  177480. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177481. png_ptr->num_palette);
  177482. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177483. return;
  177484. }
  177485. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177486. for (i = 0; i < num_hist; i++)
  177487. {
  177488. png_save_uint_16(buf, hist[i]);
  177489. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177490. }
  177491. png_write_chunk_end(png_ptr);
  177492. }
  177493. #endif
  177494. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177495. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177496. png_size_t /* PRIVATE */
  177497. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177498. {
  177499. png_size_t key_len;
  177500. png_charp kp, dp;
  177501. int kflag;
  177502. int kwarn=0;
  177503. png_debug(1, "in png_check_keyword\n");
  177504. *new_key = NULL;
  177505. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177506. {
  177507. png_warning(png_ptr, "zero length keyword");
  177508. return ((png_size_t)0);
  177509. }
  177510. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177511. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177512. if (*new_key == NULL)
  177513. {
  177514. png_warning(png_ptr, "Out of memory while procesing keyword");
  177515. return ((png_size_t)0);
  177516. }
  177517. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177518. {
  177519. if ((png_byte)*kp < 0x20 ||
  177520. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177521. {
  177522. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177523. char msg[40];
  177524. png_snprintf(msg, 40,
  177525. "invalid keyword character 0x%02X", (png_byte)*kp);
  177526. png_warning(png_ptr, msg);
  177527. #else
  177528. png_warning(png_ptr, "invalid character in keyword");
  177529. #endif
  177530. *dp = ' ';
  177531. }
  177532. else
  177533. {
  177534. *dp = *kp;
  177535. }
  177536. }
  177537. *dp = '\0';
  177538. kp = *new_key + key_len - 1;
  177539. if (*kp == ' ')
  177540. {
  177541. png_warning(png_ptr, "trailing spaces removed from keyword");
  177542. while (*kp == ' ')
  177543. {
  177544. *(kp--) = '\0';
  177545. key_len--;
  177546. }
  177547. }
  177548. kp = *new_key;
  177549. if (*kp == ' ')
  177550. {
  177551. png_warning(png_ptr, "leading spaces removed from keyword");
  177552. while (*kp == ' ')
  177553. {
  177554. kp++;
  177555. key_len--;
  177556. }
  177557. }
  177558. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177559. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177560. {
  177561. if (*kp == ' ' && kflag == 0)
  177562. {
  177563. *(dp++) = *kp;
  177564. kflag = 1;
  177565. }
  177566. else if (*kp == ' ')
  177567. {
  177568. key_len--;
  177569. kwarn=1;
  177570. }
  177571. else
  177572. {
  177573. *(dp++) = *kp;
  177574. kflag = 0;
  177575. }
  177576. }
  177577. *dp = '\0';
  177578. if(kwarn)
  177579. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177580. if (key_len == 0)
  177581. {
  177582. png_free(png_ptr, *new_key);
  177583. *new_key=NULL;
  177584. png_warning(png_ptr, "Zero length keyword");
  177585. }
  177586. if (key_len > 79)
  177587. {
  177588. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177589. new_key[79] = '\0';
  177590. key_len = 79;
  177591. }
  177592. return (key_len);
  177593. }
  177594. #endif
  177595. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177596. void /* PRIVATE */
  177597. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177598. png_size_t text_len)
  177599. {
  177600. #ifdef PNG_USE_LOCAL_ARRAYS
  177601. PNG_tEXt;
  177602. #endif
  177603. png_size_t key_len;
  177604. png_charp new_key;
  177605. png_debug(1, "in png_write_tEXt\n");
  177606. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177607. {
  177608. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177609. return;
  177610. }
  177611. if (text == NULL || *text == '\0')
  177612. text_len = 0;
  177613. else
  177614. text_len = png_strlen(text);
  177615. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177616. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177617. if (text_len)
  177618. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177619. png_write_chunk_end(png_ptr);
  177620. png_free(png_ptr, new_key);
  177621. }
  177622. #endif
  177623. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177624. void /* PRIVATE */
  177625. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177626. png_size_t text_len, int compression)
  177627. {
  177628. #ifdef PNG_USE_LOCAL_ARRAYS
  177629. PNG_zTXt;
  177630. #endif
  177631. png_size_t key_len;
  177632. char buf[1];
  177633. png_charp new_key;
  177634. compression_state comp;
  177635. png_debug(1, "in png_write_zTXt\n");
  177636. comp.num_output_ptr = 0;
  177637. comp.max_output_ptr = 0;
  177638. comp.output_ptr = NULL;
  177639. comp.input = NULL;
  177640. comp.input_len = 0;
  177641. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177642. {
  177643. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177644. return;
  177645. }
  177646. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177647. {
  177648. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177649. png_free(png_ptr, new_key);
  177650. return;
  177651. }
  177652. text_len = png_strlen(text);
  177653. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177654. &comp);
  177655. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177656. (key_len+text_len+2));
  177657. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177658. png_free(png_ptr, new_key);
  177659. buf[0] = (png_byte)compression;
  177660. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177661. png_write_compressed_data_out(png_ptr, &comp);
  177662. png_write_chunk_end(png_ptr);
  177663. }
  177664. #endif
  177665. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177666. void /* PRIVATE */
  177667. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177668. png_charp lang, png_charp lang_key, png_charp text)
  177669. {
  177670. #ifdef PNG_USE_LOCAL_ARRAYS
  177671. PNG_iTXt;
  177672. #endif
  177673. png_size_t lang_len, key_len, lang_key_len, text_len;
  177674. png_charp new_lang, new_key;
  177675. png_byte cbuf[2];
  177676. compression_state comp;
  177677. png_debug(1, "in png_write_iTXt\n");
  177678. comp.num_output_ptr = 0;
  177679. comp.max_output_ptr = 0;
  177680. comp.output_ptr = NULL;
  177681. comp.input = NULL;
  177682. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177683. {
  177684. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177685. return;
  177686. }
  177687. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177688. {
  177689. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177690. new_lang = NULL;
  177691. lang_len = 0;
  177692. }
  177693. if (lang_key == NULL)
  177694. lang_key_len = 0;
  177695. else
  177696. lang_key_len = png_strlen(lang_key);
  177697. if (text == NULL)
  177698. text_len = 0;
  177699. else
  177700. text_len = png_strlen(text);
  177701. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177702. &comp);
  177703. png_write_chunk_start(png_ptr, png_iTXt,
  177704. (png_uint_32)(
  177705. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  177706. + key_len
  177707. + lang_len
  177708. + lang_key_len
  177709. + text_len));
  177710. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177711. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  177712. compression == PNG_TEXT_COMPRESSION_NONE)
  177713. cbuf[0] = 0;
  177714. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  177715. cbuf[0] = 1;
  177716. cbuf[1] = 0;
  177717. png_write_chunk_data(png_ptr, cbuf, 2);
  177718. cbuf[0] = 0;
  177719. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  177720. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  177721. png_write_compressed_data_out(png_ptr, &comp);
  177722. png_write_chunk_end(png_ptr);
  177723. png_free(png_ptr, new_key);
  177724. if (new_lang)
  177725. png_free(png_ptr, new_lang);
  177726. }
  177727. #endif
  177728. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  177729. void /* PRIVATE */
  177730. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  177731. int unit_type)
  177732. {
  177733. #ifdef PNG_USE_LOCAL_ARRAYS
  177734. PNG_oFFs;
  177735. #endif
  177736. png_byte buf[9];
  177737. png_debug(1, "in png_write_oFFs\n");
  177738. if (unit_type >= PNG_OFFSET_LAST)
  177739. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  177740. png_save_int_32(buf, x_offset);
  177741. png_save_int_32(buf + 4, y_offset);
  177742. buf[8] = (png_byte)unit_type;
  177743. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  177744. }
  177745. #endif
  177746. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  177747. void /* PRIVATE */
  177748. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  177749. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  177750. {
  177751. #ifdef PNG_USE_LOCAL_ARRAYS
  177752. PNG_pCAL;
  177753. #endif
  177754. png_size_t purpose_len, units_len, total_len;
  177755. png_uint_32p params_len;
  177756. png_byte buf[10];
  177757. png_charp new_purpose;
  177758. int i;
  177759. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  177760. if (type >= PNG_EQUATION_LAST)
  177761. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  177762. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  177763. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  177764. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  177765. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  177766. total_len = purpose_len + units_len + 10;
  177767. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  177768. *png_sizeof(png_uint_32)));
  177769. for (i = 0; i < nparams; i++)
  177770. {
  177771. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  177772. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  177773. total_len += (png_size_t)params_len[i];
  177774. }
  177775. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  177776. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  177777. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  177778. png_save_int_32(buf, X0);
  177779. png_save_int_32(buf + 4, X1);
  177780. buf[8] = (png_byte)type;
  177781. buf[9] = (png_byte)nparams;
  177782. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  177783. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  177784. png_free(png_ptr, new_purpose);
  177785. for (i = 0; i < nparams; i++)
  177786. {
  177787. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  177788. (png_size_t)params_len[i]);
  177789. }
  177790. png_free(png_ptr, params_len);
  177791. png_write_chunk_end(png_ptr);
  177792. }
  177793. #endif
  177794. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  177795. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  177796. void /* PRIVATE */
  177797. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  177798. {
  177799. #ifdef PNG_USE_LOCAL_ARRAYS
  177800. PNG_sCAL;
  177801. #endif
  177802. char buf[64];
  177803. png_size_t total_len;
  177804. png_debug(1, "in png_write_sCAL\n");
  177805. buf[0] = (char)unit;
  177806. #if defined(_WIN32_WCE)
  177807. {
  177808. wchar_t wc_buf[32];
  177809. size_t wc_len;
  177810. swprintf(wc_buf, TEXT("%12.12e"), width);
  177811. wc_len = wcslen(wc_buf);
  177812. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  177813. total_len = wc_len + 2;
  177814. swprintf(wc_buf, TEXT("%12.12e"), height);
  177815. wc_len = wcslen(wc_buf);
  177816. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  177817. NULL, NULL);
  177818. total_len += wc_len;
  177819. }
  177820. #else
  177821. png_snprintf(buf + 1, 63, "%12.12e", width);
  177822. total_len = 1 + png_strlen(buf + 1) + 1;
  177823. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  177824. total_len += png_strlen(buf + total_len);
  177825. #endif
  177826. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  177827. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  177828. }
  177829. #else
  177830. #ifdef PNG_FIXED_POINT_SUPPORTED
  177831. void /* PRIVATE */
  177832. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  177833. png_charp height)
  177834. {
  177835. #ifdef PNG_USE_LOCAL_ARRAYS
  177836. PNG_sCAL;
  177837. #endif
  177838. png_byte buf[64];
  177839. png_size_t wlen, hlen, total_len;
  177840. png_debug(1, "in png_write_sCAL_s\n");
  177841. wlen = png_strlen(width);
  177842. hlen = png_strlen(height);
  177843. total_len = wlen + hlen + 2;
  177844. if (total_len > 64)
  177845. {
  177846. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  177847. return;
  177848. }
  177849. buf[0] = (png_byte)unit;
  177850. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  177851. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  177852. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  177853. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  177854. }
  177855. #endif
  177856. #endif
  177857. #endif
  177858. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  177859. void /* PRIVATE */
  177860. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  177861. png_uint_32 y_pixels_per_unit,
  177862. int unit_type)
  177863. {
  177864. #ifdef PNG_USE_LOCAL_ARRAYS
  177865. PNG_pHYs;
  177866. #endif
  177867. png_byte buf[9];
  177868. png_debug(1, "in png_write_pHYs\n");
  177869. if (unit_type >= PNG_RESOLUTION_LAST)
  177870. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  177871. png_save_uint_32(buf, x_pixels_per_unit);
  177872. png_save_uint_32(buf + 4, y_pixels_per_unit);
  177873. buf[8] = (png_byte)unit_type;
  177874. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  177875. }
  177876. #endif
  177877. #if defined(PNG_WRITE_tIME_SUPPORTED)
  177878. void /* PRIVATE */
  177879. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  177880. {
  177881. #ifdef PNG_USE_LOCAL_ARRAYS
  177882. PNG_tIME;
  177883. #endif
  177884. png_byte buf[7];
  177885. png_debug(1, "in png_write_tIME\n");
  177886. if (mod_time->month > 12 || mod_time->month < 1 ||
  177887. mod_time->day > 31 || mod_time->day < 1 ||
  177888. mod_time->hour > 23 || mod_time->second > 60)
  177889. {
  177890. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  177891. return;
  177892. }
  177893. png_save_uint_16(buf, mod_time->year);
  177894. buf[2] = mod_time->month;
  177895. buf[3] = mod_time->day;
  177896. buf[4] = mod_time->hour;
  177897. buf[5] = mod_time->minute;
  177898. buf[6] = mod_time->second;
  177899. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  177900. }
  177901. #endif
  177902. void /* PRIVATE */
  177903. png_write_start_row(png_structp png_ptr)
  177904. {
  177905. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177906. #ifdef PNG_USE_LOCAL_ARRAYS
  177907. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  177908. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  177909. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  177910. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  177911. #endif
  177912. #endif
  177913. png_size_t buf_size;
  177914. png_debug(1, "in png_write_start_row\n");
  177915. buf_size = (png_size_t)(PNG_ROWBYTES(
  177916. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  177917. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  177918. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  177919. #ifndef PNG_NO_WRITE_FILTERING
  177920. if (png_ptr->do_filter & PNG_FILTER_SUB)
  177921. {
  177922. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  177923. (png_ptr->rowbytes + 1));
  177924. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  177925. }
  177926. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  177927. {
  177928. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  177929. png_memset(png_ptr->prev_row, 0, buf_size);
  177930. if (png_ptr->do_filter & PNG_FILTER_UP)
  177931. {
  177932. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  177933. (png_ptr->rowbytes + 1));
  177934. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  177935. }
  177936. if (png_ptr->do_filter & PNG_FILTER_AVG)
  177937. {
  177938. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  177939. (png_ptr->rowbytes + 1));
  177940. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  177941. }
  177942. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  177943. {
  177944. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  177945. (png_ptr->rowbytes + 1));
  177946. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  177947. }
  177948. #endif /* PNG_NO_WRITE_FILTERING */
  177949. }
  177950. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177951. if (png_ptr->interlaced)
  177952. {
  177953. if (!(png_ptr->transformations & PNG_INTERLACE))
  177954. {
  177955. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  177956. png_pass_ystart[0]) / png_pass_yinc[0];
  177957. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  177958. png_pass_start[0]) / png_pass_inc[0];
  177959. }
  177960. else
  177961. {
  177962. png_ptr->num_rows = png_ptr->height;
  177963. png_ptr->usr_width = png_ptr->width;
  177964. }
  177965. }
  177966. else
  177967. #endif
  177968. {
  177969. png_ptr->num_rows = png_ptr->height;
  177970. png_ptr->usr_width = png_ptr->width;
  177971. }
  177972. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177973. png_ptr->zstream.next_out = png_ptr->zbuf;
  177974. }
  177975. void /* PRIVATE */
  177976. png_write_finish_row(png_structp png_ptr)
  177977. {
  177978. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177979. #ifdef PNG_USE_LOCAL_ARRAYS
  177980. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  177981. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  177982. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  177983. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  177984. #endif
  177985. #endif
  177986. int ret;
  177987. png_debug(1, "in png_write_finish_row\n");
  177988. png_ptr->row_number++;
  177989. if (png_ptr->row_number < png_ptr->num_rows)
  177990. return;
  177991. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177992. if (png_ptr->interlaced)
  177993. {
  177994. png_ptr->row_number = 0;
  177995. if (png_ptr->transformations & PNG_INTERLACE)
  177996. {
  177997. png_ptr->pass++;
  177998. }
  177999. else
  178000. {
  178001. do
  178002. {
  178003. png_ptr->pass++;
  178004. if (png_ptr->pass >= 7)
  178005. break;
  178006. png_ptr->usr_width = (png_ptr->width +
  178007. png_pass_inc[png_ptr->pass] - 1 -
  178008. png_pass_start[png_ptr->pass]) /
  178009. png_pass_inc[png_ptr->pass];
  178010. png_ptr->num_rows = (png_ptr->height +
  178011. png_pass_yinc[png_ptr->pass] - 1 -
  178012. png_pass_ystart[png_ptr->pass]) /
  178013. png_pass_yinc[png_ptr->pass];
  178014. if (png_ptr->transformations & PNG_INTERLACE)
  178015. break;
  178016. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178017. }
  178018. if (png_ptr->pass < 7)
  178019. {
  178020. if (png_ptr->prev_row != NULL)
  178021. png_memset(png_ptr->prev_row, 0,
  178022. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178023. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178024. return;
  178025. }
  178026. }
  178027. #endif
  178028. do
  178029. {
  178030. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178031. if (ret == Z_OK)
  178032. {
  178033. if (!(png_ptr->zstream.avail_out))
  178034. {
  178035. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178036. png_ptr->zstream.next_out = png_ptr->zbuf;
  178037. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178038. }
  178039. }
  178040. else if (ret != Z_STREAM_END)
  178041. {
  178042. if (png_ptr->zstream.msg != NULL)
  178043. png_error(png_ptr, png_ptr->zstream.msg);
  178044. else
  178045. png_error(png_ptr, "zlib error");
  178046. }
  178047. } while (ret != Z_STREAM_END);
  178048. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178049. {
  178050. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178051. png_ptr->zstream.avail_out);
  178052. }
  178053. deflateReset(&png_ptr->zstream);
  178054. png_ptr->zstream.data_type = Z_BINARY;
  178055. }
  178056. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178057. void /* PRIVATE */
  178058. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178059. {
  178060. #ifdef PNG_USE_LOCAL_ARRAYS
  178061. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178062. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178063. #endif
  178064. png_debug(1, "in png_do_write_interlace\n");
  178065. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178066. if (row != NULL && row_info != NULL && pass < 6)
  178067. #else
  178068. if (pass < 6)
  178069. #endif
  178070. {
  178071. switch (row_info->pixel_depth)
  178072. {
  178073. case 1:
  178074. {
  178075. png_bytep sp;
  178076. png_bytep dp;
  178077. int shift;
  178078. int d;
  178079. int value;
  178080. png_uint_32 i;
  178081. png_uint_32 row_width = row_info->width;
  178082. dp = row;
  178083. d = 0;
  178084. shift = 7;
  178085. for (i = png_pass_start[pass]; i < row_width;
  178086. i += png_pass_inc[pass])
  178087. {
  178088. sp = row + (png_size_t)(i >> 3);
  178089. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178090. d |= (value << shift);
  178091. if (shift == 0)
  178092. {
  178093. shift = 7;
  178094. *dp++ = (png_byte)d;
  178095. d = 0;
  178096. }
  178097. else
  178098. shift--;
  178099. }
  178100. if (shift != 7)
  178101. *dp = (png_byte)d;
  178102. break;
  178103. }
  178104. case 2:
  178105. {
  178106. png_bytep sp;
  178107. png_bytep dp;
  178108. int shift;
  178109. int d;
  178110. int value;
  178111. png_uint_32 i;
  178112. png_uint_32 row_width = row_info->width;
  178113. dp = row;
  178114. shift = 6;
  178115. d = 0;
  178116. for (i = png_pass_start[pass]; i < row_width;
  178117. i += png_pass_inc[pass])
  178118. {
  178119. sp = row + (png_size_t)(i >> 2);
  178120. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178121. d |= (value << shift);
  178122. if (shift == 0)
  178123. {
  178124. shift = 6;
  178125. *dp++ = (png_byte)d;
  178126. d = 0;
  178127. }
  178128. else
  178129. shift -= 2;
  178130. }
  178131. if (shift != 6)
  178132. *dp = (png_byte)d;
  178133. break;
  178134. }
  178135. case 4:
  178136. {
  178137. png_bytep sp;
  178138. png_bytep dp;
  178139. int shift;
  178140. int d;
  178141. int value;
  178142. png_uint_32 i;
  178143. png_uint_32 row_width = row_info->width;
  178144. dp = row;
  178145. shift = 4;
  178146. d = 0;
  178147. for (i = png_pass_start[pass]; i < row_width;
  178148. i += png_pass_inc[pass])
  178149. {
  178150. sp = row + (png_size_t)(i >> 1);
  178151. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178152. d |= (value << shift);
  178153. if (shift == 0)
  178154. {
  178155. shift = 4;
  178156. *dp++ = (png_byte)d;
  178157. d = 0;
  178158. }
  178159. else
  178160. shift -= 4;
  178161. }
  178162. if (shift != 4)
  178163. *dp = (png_byte)d;
  178164. break;
  178165. }
  178166. default:
  178167. {
  178168. png_bytep sp;
  178169. png_bytep dp;
  178170. png_uint_32 i;
  178171. png_uint_32 row_width = row_info->width;
  178172. png_size_t pixel_bytes;
  178173. dp = row;
  178174. pixel_bytes = (row_info->pixel_depth >> 3);
  178175. for (i = png_pass_start[pass]; i < row_width;
  178176. i += png_pass_inc[pass])
  178177. {
  178178. sp = row + (png_size_t)i * pixel_bytes;
  178179. if (dp != sp)
  178180. png_memcpy(dp, sp, pixel_bytes);
  178181. dp += pixel_bytes;
  178182. }
  178183. break;
  178184. }
  178185. }
  178186. row_info->width = (row_info->width +
  178187. png_pass_inc[pass] - 1 -
  178188. png_pass_start[pass]) /
  178189. png_pass_inc[pass];
  178190. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178191. row_info->width);
  178192. }
  178193. }
  178194. #endif
  178195. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178196. #define PNG_HISHIFT 10
  178197. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178198. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178199. void /* PRIVATE */
  178200. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178201. {
  178202. png_bytep best_row;
  178203. #ifndef PNG_NO_WRITE_FILTER
  178204. png_bytep prev_row, row_buf;
  178205. png_uint_32 mins, bpp;
  178206. png_byte filter_to_do = png_ptr->do_filter;
  178207. png_uint_32 row_bytes = row_info->rowbytes;
  178208. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178209. int num_p_filters = (int)png_ptr->num_prev_filters;
  178210. #endif
  178211. png_debug(1, "in png_write_find_filter\n");
  178212. bpp = (row_info->pixel_depth + 7) >> 3;
  178213. prev_row = png_ptr->prev_row;
  178214. #endif
  178215. best_row = png_ptr->row_buf;
  178216. #ifndef PNG_NO_WRITE_FILTER
  178217. row_buf = best_row;
  178218. mins = PNG_MAXSUM;
  178219. if ((filter_to_do & PNG_FILTER_NONE) &&
  178220. filter_to_do != PNG_FILTER_NONE)
  178221. {
  178222. png_bytep rp;
  178223. png_uint_32 sum = 0;
  178224. png_uint_32 i;
  178225. int v;
  178226. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178227. {
  178228. v = *rp;
  178229. sum += (v < 128) ? v : 256 - v;
  178230. }
  178231. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178232. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178233. {
  178234. png_uint_32 sumhi, sumlo;
  178235. int j;
  178236. sumlo = sum & PNG_LOMASK;
  178237. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178238. for (j = 0; j < num_p_filters; j++)
  178239. {
  178240. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178241. {
  178242. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178243. PNG_WEIGHT_SHIFT;
  178244. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178245. PNG_WEIGHT_SHIFT;
  178246. }
  178247. }
  178248. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178249. PNG_COST_SHIFT;
  178250. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178251. PNG_COST_SHIFT;
  178252. if (sumhi > PNG_HIMASK)
  178253. sum = PNG_MAXSUM;
  178254. else
  178255. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178256. }
  178257. #endif
  178258. mins = sum;
  178259. }
  178260. if (filter_to_do == PNG_FILTER_SUB)
  178261. {
  178262. png_bytep rp, lp, dp;
  178263. png_uint_32 i;
  178264. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178265. i++, rp++, dp++)
  178266. {
  178267. *dp = *rp;
  178268. }
  178269. for (lp = row_buf + 1; i < row_bytes;
  178270. i++, rp++, lp++, dp++)
  178271. {
  178272. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178273. }
  178274. best_row = png_ptr->sub_row;
  178275. }
  178276. else if (filter_to_do & PNG_FILTER_SUB)
  178277. {
  178278. png_bytep rp, dp, lp;
  178279. png_uint_32 sum = 0, lmins = mins;
  178280. png_uint_32 i;
  178281. int v;
  178282. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178283. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178284. {
  178285. int j;
  178286. png_uint_32 lmhi, lmlo;
  178287. lmlo = lmins & PNG_LOMASK;
  178288. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178289. for (j = 0; j < num_p_filters; j++)
  178290. {
  178291. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178292. {
  178293. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178294. PNG_WEIGHT_SHIFT;
  178295. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178296. PNG_WEIGHT_SHIFT;
  178297. }
  178298. }
  178299. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178300. PNG_COST_SHIFT;
  178301. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178302. PNG_COST_SHIFT;
  178303. if (lmhi > PNG_HIMASK)
  178304. lmins = PNG_MAXSUM;
  178305. else
  178306. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178307. }
  178308. #endif
  178309. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178310. i++, rp++, dp++)
  178311. {
  178312. v = *dp = *rp;
  178313. sum += (v < 128) ? v : 256 - v;
  178314. }
  178315. for (lp = row_buf + 1; i < row_bytes;
  178316. i++, rp++, lp++, dp++)
  178317. {
  178318. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178319. sum += (v < 128) ? v : 256 - v;
  178320. if (sum > lmins) /* We are already worse, don't continue. */
  178321. break;
  178322. }
  178323. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178324. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178325. {
  178326. int j;
  178327. png_uint_32 sumhi, sumlo;
  178328. sumlo = sum & PNG_LOMASK;
  178329. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178330. for (j = 0; j < num_p_filters; j++)
  178331. {
  178332. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178333. {
  178334. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178335. PNG_WEIGHT_SHIFT;
  178336. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178337. PNG_WEIGHT_SHIFT;
  178338. }
  178339. }
  178340. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178341. PNG_COST_SHIFT;
  178342. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178343. PNG_COST_SHIFT;
  178344. if (sumhi > PNG_HIMASK)
  178345. sum = PNG_MAXSUM;
  178346. else
  178347. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178348. }
  178349. #endif
  178350. if (sum < mins)
  178351. {
  178352. mins = sum;
  178353. best_row = png_ptr->sub_row;
  178354. }
  178355. }
  178356. if (filter_to_do == PNG_FILTER_UP)
  178357. {
  178358. png_bytep rp, dp, pp;
  178359. png_uint_32 i;
  178360. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178361. pp = prev_row + 1; i < row_bytes;
  178362. i++, rp++, pp++, dp++)
  178363. {
  178364. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178365. }
  178366. best_row = png_ptr->up_row;
  178367. }
  178368. else if (filter_to_do & PNG_FILTER_UP)
  178369. {
  178370. png_bytep rp, dp, pp;
  178371. png_uint_32 sum = 0, lmins = mins;
  178372. png_uint_32 i;
  178373. int v;
  178374. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178375. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178376. {
  178377. int j;
  178378. png_uint_32 lmhi, lmlo;
  178379. lmlo = lmins & PNG_LOMASK;
  178380. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178381. for (j = 0; j < num_p_filters; j++)
  178382. {
  178383. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178384. {
  178385. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178386. PNG_WEIGHT_SHIFT;
  178387. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178388. PNG_WEIGHT_SHIFT;
  178389. }
  178390. }
  178391. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178392. PNG_COST_SHIFT;
  178393. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178394. PNG_COST_SHIFT;
  178395. if (lmhi > PNG_HIMASK)
  178396. lmins = PNG_MAXSUM;
  178397. else
  178398. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178399. }
  178400. #endif
  178401. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178402. pp = prev_row + 1; i < row_bytes; i++)
  178403. {
  178404. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178405. sum += (v < 128) ? v : 256 - v;
  178406. if (sum > lmins) /* We are already worse, don't continue. */
  178407. break;
  178408. }
  178409. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178410. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178411. {
  178412. int j;
  178413. png_uint_32 sumhi, sumlo;
  178414. sumlo = sum & PNG_LOMASK;
  178415. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178416. for (j = 0; j < num_p_filters; j++)
  178417. {
  178418. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178419. {
  178420. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178421. PNG_WEIGHT_SHIFT;
  178422. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178423. PNG_WEIGHT_SHIFT;
  178424. }
  178425. }
  178426. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178427. PNG_COST_SHIFT;
  178428. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178429. PNG_COST_SHIFT;
  178430. if (sumhi > PNG_HIMASK)
  178431. sum = PNG_MAXSUM;
  178432. else
  178433. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178434. }
  178435. #endif
  178436. if (sum < mins)
  178437. {
  178438. mins = sum;
  178439. best_row = png_ptr->up_row;
  178440. }
  178441. }
  178442. if (filter_to_do == PNG_FILTER_AVG)
  178443. {
  178444. png_bytep rp, dp, pp, lp;
  178445. png_uint_32 i;
  178446. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178447. pp = prev_row + 1; i < bpp; i++)
  178448. {
  178449. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178450. }
  178451. for (lp = row_buf + 1; i < row_bytes; i++)
  178452. {
  178453. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178454. & 0xff);
  178455. }
  178456. best_row = png_ptr->avg_row;
  178457. }
  178458. else if (filter_to_do & PNG_FILTER_AVG)
  178459. {
  178460. png_bytep rp, dp, pp, lp;
  178461. png_uint_32 sum = 0, lmins = mins;
  178462. png_uint_32 i;
  178463. int v;
  178464. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178465. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178466. {
  178467. int j;
  178468. png_uint_32 lmhi, lmlo;
  178469. lmlo = lmins & PNG_LOMASK;
  178470. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178471. for (j = 0; j < num_p_filters; j++)
  178472. {
  178473. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178474. {
  178475. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178476. PNG_WEIGHT_SHIFT;
  178477. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178478. PNG_WEIGHT_SHIFT;
  178479. }
  178480. }
  178481. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178482. PNG_COST_SHIFT;
  178483. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178484. PNG_COST_SHIFT;
  178485. if (lmhi > PNG_HIMASK)
  178486. lmins = PNG_MAXSUM;
  178487. else
  178488. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178489. }
  178490. #endif
  178491. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178492. pp = prev_row + 1; i < bpp; i++)
  178493. {
  178494. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178495. sum += (v < 128) ? v : 256 - v;
  178496. }
  178497. for (lp = row_buf + 1; i < row_bytes; i++)
  178498. {
  178499. v = *dp++ =
  178500. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178501. sum += (v < 128) ? v : 256 - v;
  178502. if (sum > lmins) /* We are already worse, don't continue. */
  178503. break;
  178504. }
  178505. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178506. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178507. {
  178508. int j;
  178509. png_uint_32 sumhi, sumlo;
  178510. sumlo = sum & PNG_LOMASK;
  178511. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178512. for (j = 0; j < num_p_filters; j++)
  178513. {
  178514. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178515. {
  178516. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178517. PNG_WEIGHT_SHIFT;
  178518. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178519. PNG_WEIGHT_SHIFT;
  178520. }
  178521. }
  178522. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178523. PNG_COST_SHIFT;
  178524. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178525. PNG_COST_SHIFT;
  178526. if (sumhi > PNG_HIMASK)
  178527. sum = PNG_MAXSUM;
  178528. else
  178529. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178530. }
  178531. #endif
  178532. if (sum < mins)
  178533. {
  178534. mins = sum;
  178535. best_row = png_ptr->avg_row;
  178536. }
  178537. }
  178538. if (filter_to_do == PNG_FILTER_PAETH)
  178539. {
  178540. png_bytep rp, dp, pp, cp, lp;
  178541. png_uint_32 i;
  178542. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178543. pp = prev_row + 1; i < bpp; i++)
  178544. {
  178545. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178546. }
  178547. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178548. {
  178549. int a, b, c, pa, pb, pc, p;
  178550. b = *pp++;
  178551. c = *cp++;
  178552. a = *lp++;
  178553. p = b - c;
  178554. pc = a - c;
  178555. #ifdef PNG_USE_ABS
  178556. pa = abs(p);
  178557. pb = abs(pc);
  178558. pc = abs(p + pc);
  178559. #else
  178560. pa = p < 0 ? -p : p;
  178561. pb = pc < 0 ? -pc : pc;
  178562. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178563. #endif
  178564. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178565. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178566. }
  178567. best_row = png_ptr->paeth_row;
  178568. }
  178569. else if (filter_to_do & PNG_FILTER_PAETH)
  178570. {
  178571. png_bytep rp, dp, pp, cp, lp;
  178572. png_uint_32 sum = 0, lmins = mins;
  178573. png_uint_32 i;
  178574. int v;
  178575. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178576. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178577. {
  178578. int j;
  178579. png_uint_32 lmhi, lmlo;
  178580. lmlo = lmins & PNG_LOMASK;
  178581. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178582. for (j = 0; j < num_p_filters; j++)
  178583. {
  178584. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178585. {
  178586. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178587. PNG_WEIGHT_SHIFT;
  178588. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178589. PNG_WEIGHT_SHIFT;
  178590. }
  178591. }
  178592. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178593. PNG_COST_SHIFT;
  178594. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178595. PNG_COST_SHIFT;
  178596. if (lmhi > PNG_HIMASK)
  178597. lmins = PNG_MAXSUM;
  178598. else
  178599. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178600. }
  178601. #endif
  178602. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178603. pp = prev_row + 1; i < bpp; i++)
  178604. {
  178605. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178606. sum += (v < 128) ? v : 256 - v;
  178607. }
  178608. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178609. {
  178610. int a, b, c, pa, pb, pc, p;
  178611. b = *pp++;
  178612. c = *cp++;
  178613. a = *lp++;
  178614. #ifndef PNG_SLOW_PAETH
  178615. p = b - c;
  178616. pc = a - c;
  178617. #ifdef PNG_USE_ABS
  178618. pa = abs(p);
  178619. pb = abs(pc);
  178620. pc = abs(p + pc);
  178621. #else
  178622. pa = p < 0 ? -p : p;
  178623. pb = pc < 0 ? -pc : pc;
  178624. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178625. #endif
  178626. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178627. #else /* PNG_SLOW_PAETH */
  178628. p = a + b - c;
  178629. pa = abs(p - a);
  178630. pb = abs(p - b);
  178631. pc = abs(p - c);
  178632. if (pa <= pb && pa <= pc)
  178633. p = a;
  178634. else if (pb <= pc)
  178635. p = b;
  178636. else
  178637. p = c;
  178638. #endif /* PNG_SLOW_PAETH */
  178639. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178640. sum += (v < 128) ? v : 256 - v;
  178641. if (sum > lmins) /* We are already worse, don't continue. */
  178642. break;
  178643. }
  178644. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178645. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178646. {
  178647. int j;
  178648. png_uint_32 sumhi, sumlo;
  178649. sumlo = sum & PNG_LOMASK;
  178650. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178651. for (j = 0; j < num_p_filters; j++)
  178652. {
  178653. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178654. {
  178655. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178656. PNG_WEIGHT_SHIFT;
  178657. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178658. PNG_WEIGHT_SHIFT;
  178659. }
  178660. }
  178661. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178662. PNG_COST_SHIFT;
  178663. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178664. PNG_COST_SHIFT;
  178665. if (sumhi > PNG_HIMASK)
  178666. sum = PNG_MAXSUM;
  178667. else
  178668. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178669. }
  178670. #endif
  178671. if (sum < mins)
  178672. {
  178673. best_row = png_ptr->paeth_row;
  178674. }
  178675. }
  178676. #endif /* PNG_NO_WRITE_FILTER */
  178677. png_write_filtered_row(png_ptr, best_row);
  178678. #ifndef PNG_NO_WRITE_FILTER
  178679. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178680. if (png_ptr->num_prev_filters > 0)
  178681. {
  178682. int j;
  178683. for (j = 1; j < num_p_filters; j++)
  178684. {
  178685. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178686. }
  178687. png_ptr->prev_filters[j] = best_row[0];
  178688. }
  178689. #endif
  178690. #endif /* PNG_NO_WRITE_FILTER */
  178691. }
  178692. void /* PRIVATE */
  178693. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178694. {
  178695. png_debug(1, "in png_write_filtered_row\n");
  178696. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178697. png_ptr->zstream.next_in = filtered_row;
  178698. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178699. do
  178700. {
  178701. int ret; /* return of zlib */
  178702. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178703. if (ret != Z_OK)
  178704. {
  178705. if (png_ptr->zstream.msg != NULL)
  178706. png_error(png_ptr, png_ptr->zstream.msg);
  178707. else
  178708. png_error(png_ptr, "zlib error");
  178709. }
  178710. if (!(png_ptr->zstream.avail_out))
  178711. {
  178712. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178713. png_ptr->zstream.next_out = png_ptr->zbuf;
  178714. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178715. }
  178716. } while (png_ptr->zstream.avail_in);
  178717. if (png_ptr->prev_row != NULL)
  178718. {
  178719. png_bytep tptr;
  178720. tptr = png_ptr->prev_row;
  178721. png_ptr->prev_row = png_ptr->row_buf;
  178722. png_ptr->row_buf = tptr;
  178723. }
  178724. png_write_finish_row(png_ptr);
  178725. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  178726. png_ptr->flush_rows++;
  178727. if (png_ptr->flush_dist > 0 &&
  178728. png_ptr->flush_rows >= png_ptr->flush_dist)
  178729. {
  178730. png_write_flush(png_ptr);
  178731. }
  178732. #endif
  178733. }
  178734. #endif /* PNG_WRITE_SUPPORTED */
  178735. /*** End of inlined file: pngwutil.c ***/
  178736. }
  178737. #else
  178738. #define PNG_INTERNAL
  178739. #define PNG_SETJMP_NOT_SUPPORTED
  178740. #include <png.h>
  178741. #include <pngconf.h>
  178742. #endif
  178743. }
  178744. #undef max
  178745. #undef min
  178746. #ifdef _MSC_VER
  178747. #pragma warning (pop)
  178748. #endif
  178749. BEGIN_JUCE_NAMESPACE
  178750. using ::calloc;
  178751. using ::malloc;
  178752. using ::free;
  178753. namespace PNGHelpers
  178754. {
  178755. using namespace pnglibNamespace;
  178756. static void readCallback (png_structp png, png_bytep data, png_size_t length)
  178757. {
  178758. static_cast<InputStream*> (png_get_io_ptr (png))->read (data, (int) length);
  178759. }
  178760. static void writeDataCallback (png_structp png, png_bytep data, png_size_t length)
  178761. {
  178762. static_cast<OutputStream*> (png_get_io_ptr (png))->write (data, (int) length);
  178763. }
  178764. struct PNGErrorStruct {};
  178765. static void errorCallback (png_structp, png_const_charp)
  178766. {
  178767. throw PNGErrorStruct();
  178768. }
  178769. }
  178770. Image* juce_loadPNGImageFromStream (InputStream& in)
  178771. {
  178772. using namespace pnglibNamespace;
  178773. Image* image = 0;
  178774. png_structp pngReadStruct;
  178775. png_infop pngInfoStruct;
  178776. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178777. if (pngReadStruct != 0)
  178778. {
  178779. pngInfoStruct = png_create_info_struct (pngReadStruct);
  178780. if (pngInfoStruct == 0)
  178781. {
  178782. png_destroy_read_struct (&pngReadStruct, 0, 0);
  178783. return 0;
  178784. }
  178785. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  178786. // read the header..
  178787. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  178788. png_uint_32 width, height;
  178789. int bitDepth, colorType, interlaceType;
  178790. png_read_info (pngReadStruct, pngInfoStruct);
  178791. png_get_IHDR (pngReadStruct, pngInfoStruct,
  178792. &width, &height,
  178793. &bitDepth, &colorType,
  178794. &interlaceType, 0, 0);
  178795. if (bitDepth == 16)
  178796. png_set_strip_16 (pngReadStruct);
  178797. if (colorType == PNG_COLOR_TYPE_PALETTE)
  178798. png_set_expand (pngReadStruct);
  178799. if (bitDepth < 8)
  178800. png_set_expand (pngReadStruct);
  178801. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  178802. png_set_expand (pngReadStruct);
  178803. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  178804. png_set_gray_to_rgb (pngReadStruct);
  178805. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  178806. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  178807. || pngInfoStruct->num_trans > 0;
  178808. // Load the image into a temp buffer in the pnglib format..
  178809. HeapBlock <uint8> tempBuffer (height * (width << 2));
  178810. {
  178811. HeapBlock <png_bytep> rows (height);
  178812. for (int y = (int) height; --y >= 0;)
  178813. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  178814. png_read_image (pngReadStruct, rows);
  178815. png_read_end (pngReadStruct, pngInfoStruct);
  178816. }
  178817. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  178818. // now convert the data to a juce image format..
  178819. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  178820. (int) width, (int) height, hasAlphaChan);
  178821. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  178822. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  178823. uint8* srcRow = tempBuffer;
  178824. uint8* destRow = destData.data;
  178825. for (int y = 0; y < (int) height; ++y)
  178826. {
  178827. const uint8* src = srcRow;
  178828. srcRow += (width << 2);
  178829. uint8* dest = destRow;
  178830. destRow += destData.lineStride;
  178831. if (hasAlphaChan)
  178832. {
  178833. for (int i = (int) width; --i >= 0;)
  178834. {
  178835. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  178836. ((PixelARGB*) dest)->premultiply();
  178837. dest += destData.pixelStride;
  178838. src += 4;
  178839. }
  178840. }
  178841. else
  178842. {
  178843. for (int i = (int) width; --i >= 0;)
  178844. {
  178845. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  178846. dest += destData.pixelStride;
  178847. src += 4;
  178848. }
  178849. }
  178850. }
  178851. }
  178852. return image;
  178853. }
  178854. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  178855. {
  178856. using namespace pnglibNamespace;
  178857. const int width = image.getWidth();
  178858. const int height = image.getHeight();
  178859. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178860. if (pngWriteStruct == 0)
  178861. return false;
  178862. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  178863. if (pngInfoStruct == 0)
  178864. {
  178865. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  178866. return false;
  178867. }
  178868. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  178869. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  178870. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  178871. : PNG_COLOR_TYPE_RGB,
  178872. PNG_INTERLACE_NONE,
  178873. PNG_COMPRESSION_TYPE_BASE,
  178874. PNG_FILTER_TYPE_BASE);
  178875. HeapBlock <uint8> rowData (width * 4);
  178876. png_color_8 sig_bit;
  178877. sig_bit.red = 8;
  178878. sig_bit.green = 8;
  178879. sig_bit.blue = 8;
  178880. sig_bit.alpha = 8;
  178881. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  178882. png_write_info (pngWriteStruct, pngInfoStruct);
  178883. png_set_shift (pngWriteStruct, &sig_bit);
  178884. png_set_packing (pngWriteStruct);
  178885. const Image::BitmapData srcData (image, 0, 0, width, height);
  178886. for (int y = 0; y < height; ++y)
  178887. {
  178888. uint8* dst = rowData;
  178889. const uint8* src = srcData.getLinePointer (y);
  178890. if (image.hasAlphaChannel())
  178891. {
  178892. for (int i = width; --i >= 0;)
  178893. {
  178894. PixelARGB p (*(const PixelARGB*) src);
  178895. p.unpremultiply();
  178896. *dst++ = p.getRed();
  178897. *dst++ = p.getGreen();
  178898. *dst++ = p.getBlue();
  178899. *dst++ = p.getAlpha();
  178900. src += srcData.pixelStride;
  178901. }
  178902. }
  178903. else
  178904. {
  178905. for (int i = width; --i >= 0;)
  178906. {
  178907. *dst++ = ((const PixelRGB*) src)->getRed();
  178908. *dst++ = ((const PixelRGB*) src)->getGreen();
  178909. *dst++ = ((const PixelRGB*) src)->getBlue();
  178910. src += srcData.pixelStride;
  178911. }
  178912. }
  178913. png_write_rows (pngWriteStruct, &rowData, 1);
  178914. }
  178915. png_write_end (pngWriteStruct, pngInfoStruct);
  178916. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  178917. out.flush();
  178918. return true;
  178919. }
  178920. END_JUCE_NAMESPACE
  178921. /*** End of inlined file: juce_PNGLoader.cpp ***/
  178922. #endif
  178923. //==============================================================================
  178924. #if JUCE_BUILD_NATIVE
  178925. #if JUCE_WINDOWS
  178926. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  178927. #if JUCE_WINDOWS
  178928. BEGIN_JUCE_NAMESPACE
  178929. #define JUCE_INCLUDED_FILE 1
  178930. // Now include the actual code files..
  178931. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  178932. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  178933. // compiled on its own).
  178934. #if JUCE_INCLUDED_FILE
  178935. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  178936. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  178937. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  178938. #ifndef DOXYGEN
  178939. // use with DynamicLibraryLoader to simplify importing functions
  178940. //
  178941. // functionName: function to import
  178942. // localFunctionName: name you want to use to actually call it (must be different)
  178943. // returnType: the return type
  178944. // object: the DynamicLibraryLoader to use
  178945. // params: list of params (bracketed)
  178946. //
  178947. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  178948. typedef returnType (WINAPI *type##localFunctionName) params; \
  178949. type##localFunctionName localFunctionName \
  178950. = (type##localFunctionName)object.findProcAddress (#functionName);
  178951. // loads and unloads a DLL automatically
  178952. class JUCE_API DynamicLibraryLoader
  178953. {
  178954. public:
  178955. DynamicLibraryLoader (const String& name);
  178956. ~DynamicLibraryLoader();
  178957. void* findProcAddress (const String& functionName);
  178958. private:
  178959. void* libHandle;
  178960. };
  178961. #endif
  178962. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  178963. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  178964. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  178965. {
  178966. libHandle = LoadLibrary (name);
  178967. }
  178968. DynamicLibraryLoader::~DynamicLibraryLoader()
  178969. {
  178970. FreeLibrary ((HMODULE) libHandle);
  178971. }
  178972. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  178973. {
  178974. return GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  178975. }
  178976. #endif
  178977. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  178978. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  178979. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  178980. // compiled on its own).
  178981. #if JUCE_INCLUDED_FILE
  178982. extern void juce_initialiseThreadEvents();
  178983. void Logger::outputDebugString (const String& text) throw()
  178984. {
  178985. OutputDebugString (text + "\n");
  178986. }
  178987. static int64 hiResTicksPerSecond;
  178988. static double hiResTicksScaleFactor;
  178989. #if JUCE_USE_INTRINSICS
  178990. // CPU info functions using intrinsics...
  178991. #pragma intrinsic (__cpuid)
  178992. #pragma intrinsic (__rdtsc)
  178993. const String SystemStats::getCpuVendor() throw()
  178994. {
  178995. int info [4];
  178996. __cpuid (info, 0);
  178997. char v [12];
  178998. memcpy (v, info + 1, 4);
  178999. memcpy (v + 4, info + 3, 4);
  179000. memcpy (v + 8, info + 2, 4);
  179001. return String (v, 12);
  179002. }
  179003. #else
  179004. // CPU info functions using old fashioned inline asm...
  179005. static void juce_getCpuVendor (char* const v)
  179006. {
  179007. int vendor[4];
  179008. zeromem (vendor, 16);
  179009. #ifdef JUCE_64BIT
  179010. #else
  179011. #ifndef __MINGW32__
  179012. __try
  179013. #endif
  179014. {
  179015. #if JUCE_GCC
  179016. unsigned int dummy = 0;
  179017. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179018. #else
  179019. __asm
  179020. {
  179021. mov eax, 0
  179022. cpuid
  179023. mov [vendor], ebx
  179024. mov [vendor + 4], edx
  179025. mov [vendor + 8], ecx
  179026. }
  179027. #endif
  179028. }
  179029. #ifndef __MINGW32__
  179030. __except (EXCEPTION_EXECUTE_HANDLER)
  179031. {
  179032. *v = 0;
  179033. }
  179034. #endif
  179035. #endif
  179036. memcpy (v, vendor, 16);
  179037. }
  179038. const String SystemStats::getCpuVendor() throw()
  179039. {
  179040. char v [16];
  179041. juce_getCpuVendor (v);
  179042. return String (v, 16);
  179043. }
  179044. #endif
  179045. struct CPUFlags
  179046. {
  179047. bool hasMMX : 1;
  179048. bool hasSSE : 1;
  179049. bool hasSSE2 : 1;
  179050. bool has3DNow : 1;
  179051. };
  179052. static CPUFlags cpuFlags;
  179053. bool SystemStats::hasMMX() throw()
  179054. {
  179055. return cpuFlags.hasMMX;
  179056. }
  179057. bool SystemStats::hasSSE() throw()
  179058. {
  179059. return cpuFlags.hasSSE;
  179060. }
  179061. bool SystemStats::hasSSE2() throw()
  179062. {
  179063. return cpuFlags.hasSSE2;
  179064. }
  179065. bool SystemStats::has3DNow() throw()
  179066. {
  179067. return cpuFlags.has3DNow;
  179068. }
  179069. void SystemStats::initialiseStats() throw()
  179070. {
  179071. juce_initialiseThreadEvents();
  179072. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179073. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179074. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179075. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179076. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179077. #else
  179078. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179079. #endif
  179080. LARGE_INTEGER f;
  179081. QueryPerformanceFrequency (&f);
  179082. hiResTicksPerSecond = f.QuadPart;
  179083. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179084. String s (SystemStats::getJUCEVersion());
  179085. #ifdef JUCE_DEBUG
  179086. const MMRESULT res = timeBeginPeriod (1);
  179087. jassert (res == TIMERR_NOERROR);
  179088. #else
  179089. timeBeginPeriod (1);
  179090. #endif
  179091. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179092. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179093. #endif
  179094. }
  179095. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179096. {
  179097. OSVERSIONINFO info;
  179098. info.dwOSVersionInfoSize = sizeof (info);
  179099. GetVersionEx (&info);
  179100. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179101. {
  179102. switch (info.dwMajorVersion)
  179103. {
  179104. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179105. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179106. default: jassertfalse; break; // !! not a supported OS!
  179107. }
  179108. }
  179109. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179110. {
  179111. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179112. return Win98;
  179113. }
  179114. return UnknownOS;
  179115. }
  179116. const String SystemStats::getOperatingSystemName() throw()
  179117. {
  179118. const char* name = "Unknown OS";
  179119. switch (getOperatingSystemType())
  179120. {
  179121. case Windows7: name = "Windows 7"; break;
  179122. case WinVista: name = "Windows Vista"; break;
  179123. case WinXP: name = "Windows XP"; break;
  179124. case Win2000: name = "Windows 2000"; break;
  179125. case Win98: name = "Windows 98"; break;
  179126. default: jassertfalse; break; // !! new type of OS?
  179127. }
  179128. return name;
  179129. }
  179130. bool SystemStats::isOperatingSystem64Bit() throw()
  179131. {
  179132. #ifdef _WIN64
  179133. return true;
  179134. #else
  179135. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179136. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179137. BOOL isWow64 = FALSE;
  179138. return (fnIsWow64Process != 0)
  179139. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179140. && (isWow64 != FALSE);
  179141. #endif
  179142. }
  179143. int SystemStats::getMemorySizeInMegabytes() throw()
  179144. {
  179145. MEMORYSTATUSEX mem;
  179146. mem.dwLength = sizeof (mem);
  179147. GlobalMemoryStatusEx (&mem);
  179148. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179149. }
  179150. int SystemStats::getNumCpus() throw()
  179151. {
  179152. SYSTEM_INFO systemInfo;
  179153. GetSystemInfo (&systemInfo);
  179154. return systemInfo.dwNumberOfProcessors;
  179155. }
  179156. uint32 juce_millisecondsSinceStartup() throw()
  179157. {
  179158. return (uint32) GetTickCount();
  179159. }
  179160. int64 Time::getHighResolutionTicks() throw()
  179161. {
  179162. LARGE_INTEGER ticks;
  179163. QueryPerformanceCounter (&ticks);
  179164. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179165. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179166. // fix for a very obscure PCI hardware bug that can make the counter
  179167. // sometimes jump forwards by a few seconds..
  179168. static int64 hiResTicksOffset = 0;
  179169. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179170. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179171. hiResTicksOffset = newOffset;
  179172. return ticks.QuadPart + hiResTicksOffset;
  179173. }
  179174. double Time::getMillisecondCounterHiRes() throw()
  179175. {
  179176. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179177. }
  179178. int64 Time::getHighResolutionTicksPerSecond() throw()
  179179. {
  179180. return hiResTicksPerSecond;
  179181. }
  179182. int64 SystemStats::getClockCycleCounter() throw()
  179183. {
  179184. #if JUCE_USE_INTRINSICS
  179185. // MS intrinsics version...
  179186. return __rdtsc();
  179187. #elif JUCE_GCC
  179188. // GNU inline asm version...
  179189. unsigned int hi = 0, lo = 0;
  179190. __asm__ __volatile__ (
  179191. "xor %%eax, %%eax \n\
  179192. xor %%edx, %%edx \n\
  179193. rdtsc \n\
  179194. movl %%eax, %[lo] \n\
  179195. movl %%edx, %[hi]"
  179196. :
  179197. : [hi] "m" (hi),
  179198. [lo] "m" (lo)
  179199. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179200. return (int64) ((((uint64) hi) << 32) | lo);
  179201. #else
  179202. // MSVC inline asm version...
  179203. unsigned int hi = 0, lo = 0;
  179204. __asm
  179205. {
  179206. xor eax, eax
  179207. xor edx, edx
  179208. rdtsc
  179209. mov lo, eax
  179210. mov hi, edx
  179211. }
  179212. return (int64) ((((uint64) hi) << 32) | lo);
  179213. #endif
  179214. }
  179215. int SystemStats::getCpuSpeedInMegaherz() throw()
  179216. {
  179217. const int64 cycles = SystemStats::getClockCycleCounter();
  179218. const uint32 millis = Time::getMillisecondCounter();
  179219. int lastResult = 0;
  179220. for (;;)
  179221. {
  179222. int n = 1000000;
  179223. while (--n > 0) {}
  179224. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179225. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179226. if (millisElapsed > 80)
  179227. {
  179228. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179229. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179230. return newResult;
  179231. lastResult = newResult;
  179232. }
  179233. }
  179234. }
  179235. bool Time::setSystemTimeToThisTime() const throw()
  179236. {
  179237. SYSTEMTIME st;
  179238. st.wDayOfWeek = 0;
  179239. st.wYear = (WORD) getYear();
  179240. st.wMonth = (WORD) (getMonth() + 1);
  179241. st.wDay = (WORD) getDayOfMonth();
  179242. st.wHour = (WORD) getHours();
  179243. st.wMinute = (WORD) getMinutes();
  179244. st.wSecond = (WORD) getSeconds();
  179245. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179246. // do this twice because of daylight saving conversion problems - the
  179247. // first one sets it up, the second one kicks it in.
  179248. return SetLocalTime (&st) != 0
  179249. && SetLocalTime (&st) != 0;
  179250. }
  179251. int SystemStats::getPageSize() throw()
  179252. {
  179253. SYSTEM_INFO systemInfo;
  179254. GetSystemInfo (&systemInfo);
  179255. return systemInfo.dwPageSize;
  179256. }
  179257. const String SystemStats::getLogonName()
  179258. {
  179259. TCHAR text [256];
  179260. DWORD len = numElementsInArray (text) - 2;
  179261. zerostruct (text);
  179262. GetUserName (text, &len);
  179263. return String (text, len);
  179264. }
  179265. const String SystemStats::getFullUserName()
  179266. {
  179267. return getLogonName();
  179268. }
  179269. #endif
  179270. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179271. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179272. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179273. // compiled on its own).
  179274. #if JUCE_INCLUDED_FILE
  179275. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179276. extern HWND juce_messageWindowHandle;
  179277. #endif
  179278. #if ! JUCE_USE_INTRINSICS
  179279. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179280. // older ones we have to actually call the ops as win32 functions..
  179281. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179282. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179283. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179284. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179285. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179286. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179287. #endif
  179288. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179289. CriticalSection::CriticalSection() throw()
  179290. {
  179291. // (just to check the MS haven't changed this structure and broken things...)
  179292. #if _MSC_VER >= 1400
  179293. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179294. #else
  179295. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179296. #endif
  179297. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179298. }
  179299. CriticalSection::~CriticalSection() throw()
  179300. {
  179301. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179302. }
  179303. void CriticalSection::enter() const throw()
  179304. {
  179305. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179306. }
  179307. bool CriticalSection::tryEnter() const throw()
  179308. {
  179309. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179310. }
  179311. void CriticalSection::exit() const throw()
  179312. {
  179313. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179314. }
  179315. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  179316. : internal (CreateEvent (0, manualReset ? TRUE : FALSE, FALSE, 0))
  179317. {
  179318. }
  179319. WaitableEvent::~WaitableEvent() throw()
  179320. {
  179321. CloseHandle (internal);
  179322. }
  179323. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179324. {
  179325. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179326. }
  179327. void WaitableEvent::signal() const throw()
  179328. {
  179329. SetEvent (internal);
  179330. }
  179331. void WaitableEvent::reset() const throw()
  179332. {
  179333. ResetEvent (internal);
  179334. }
  179335. void JUCE_API juce_threadEntryPoint (void*);
  179336. static unsigned int __stdcall threadEntryProc (void* userData)
  179337. {
  179338. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179339. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179340. GetCurrentThreadId(), TRUE);
  179341. #endif
  179342. juce_threadEntryPoint (userData);
  179343. _endthreadex (0);
  179344. return 0;
  179345. }
  179346. void juce_CloseThreadHandle (void* handle)
  179347. {
  179348. CloseHandle ((HANDLE) handle);
  179349. }
  179350. void* juce_createThread (void* userData)
  179351. {
  179352. unsigned int threadId;
  179353. return (void*) _beginthreadex (0, 0,
  179354. &threadEntryProc,
  179355. userData,
  179356. 0, &threadId);
  179357. }
  179358. void juce_killThread (void* handle)
  179359. {
  179360. if (handle != 0)
  179361. {
  179362. #ifdef JUCE_DEBUG
  179363. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179364. #endif
  179365. TerminateThread (handle, 0);
  179366. }
  179367. }
  179368. void juce_setCurrentThreadName (const String& name)
  179369. {
  179370. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179371. struct
  179372. {
  179373. DWORD dwType;
  179374. LPCSTR szName;
  179375. DWORD dwThreadID;
  179376. DWORD dwFlags;
  179377. } info;
  179378. info.dwType = 0x1000;
  179379. info.szName = name.toCString();
  179380. info.dwThreadID = GetCurrentThreadId();
  179381. info.dwFlags = 0;
  179382. __try
  179383. {
  179384. RaiseException (0x406d1388 /*MS_VC_EXCEPTION*/, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179385. }
  179386. __except (EXCEPTION_CONTINUE_EXECUTION)
  179387. {}
  179388. #else
  179389. (void) name;
  179390. #endif
  179391. }
  179392. Thread::ThreadID Thread::getCurrentThreadId()
  179393. {
  179394. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179395. }
  179396. // priority 1 to 10 where 5=normal, 1=low
  179397. bool juce_setThreadPriority (void* threadHandle, int priority)
  179398. {
  179399. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179400. if (priority < 1)
  179401. pri = THREAD_PRIORITY_IDLE;
  179402. else if (priority < 2)
  179403. pri = THREAD_PRIORITY_LOWEST;
  179404. else if (priority < 5)
  179405. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179406. else if (priority < 7)
  179407. pri = THREAD_PRIORITY_NORMAL;
  179408. else if (priority < 9)
  179409. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179410. else if (priority < 10)
  179411. pri = THREAD_PRIORITY_HIGHEST;
  179412. if (threadHandle == 0)
  179413. threadHandle = GetCurrentThread();
  179414. return SetThreadPriority (threadHandle, pri) != FALSE;
  179415. }
  179416. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179417. {
  179418. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179419. }
  179420. static HANDLE sleepEvent = 0;
  179421. void juce_initialiseThreadEvents()
  179422. {
  179423. if (sleepEvent == 0)
  179424. #ifdef JUCE_DEBUG
  179425. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179426. #else
  179427. sleepEvent = CreateEvent (0, 0, 0, 0);
  179428. #endif
  179429. }
  179430. void Thread::yield()
  179431. {
  179432. Sleep (0);
  179433. }
  179434. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179435. {
  179436. if (millisecs >= 10)
  179437. {
  179438. Sleep (millisecs);
  179439. }
  179440. else
  179441. {
  179442. jassert (sleepEvent != 0);
  179443. // unlike Sleep() this is guaranteed to return to the current thread after
  179444. // the time expires, so we'll use this for short waits, which are more likely
  179445. // to need to be accurate
  179446. WaitForSingleObject (sleepEvent, millisecs);
  179447. }
  179448. }
  179449. static int lastProcessPriority = -1;
  179450. // called by WindowDriver because Windows does wierd things to process priority
  179451. // when you swap apps, and this forces an update when the app is brought to the front.
  179452. void juce_repeatLastProcessPriority()
  179453. {
  179454. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179455. {
  179456. DWORD p;
  179457. switch (lastProcessPriority)
  179458. {
  179459. case Process::LowPriority: p = IDLE_PRIORITY_CLASS; break;
  179460. case Process::NormalPriority: p = NORMAL_PRIORITY_CLASS; break;
  179461. case Process::HighPriority: p = HIGH_PRIORITY_CLASS; break;
  179462. case Process::RealtimePriority: p = REALTIME_PRIORITY_CLASS; break;
  179463. default: jassertfalse; return; // bad priority value
  179464. }
  179465. SetPriorityClass (GetCurrentProcess(), p);
  179466. }
  179467. }
  179468. void Process::setPriority (ProcessPriority prior)
  179469. {
  179470. if (lastProcessPriority != (int) prior)
  179471. {
  179472. lastProcessPriority = (int) prior;
  179473. juce_repeatLastProcessPriority();
  179474. }
  179475. }
  179476. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179477. {
  179478. return IsDebuggerPresent() != FALSE;
  179479. }
  179480. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179481. {
  179482. return juce_isRunningUnderDebugger();
  179483. }
  179484. void Process::raisePrivilege()
  179485. {
  179486. jassertfalse // xxx not implemented
  179487. }
  179488. void Process::lowerPrivilege()
  179489. {
  179490. jassertfalse // xxx not implemented
  179491. }
  179492. void Process::terminate()
  179493. {
  179494. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179495. _CrtDumpMemoryLeaks();
  179496. #endif
  179497. // bullet in the head in case there's a problem shutting down..
  179498. ExitProcess (0);
  179499. }
  179500. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179501. {
  179502. void* result = 0;
  179503. JUCE_TRY
  179504. {
  179505. result = LoadLibrary (name);
  179506. }
  179507. JUCE_CATCH_ALL
  179508. return result;
  179509. }
  179510. void PlatformUtilities::freeDynamicLibrary (void* h)
  179511. {
  179512. JUCE_TRY
  179513. {
  179514. if (h != 0)
  179515. FreeLibrary ((HMODULE) h);
  179516. }
  179517. JUCE_CATCH_ALL
  179518. }
  179519. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179520. {
  179521. return (h != 0) ? GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179522. }
  179523. class InterProcessLock::Pimpl
  179524. {
  179525. public:
  179526. Pimpl (const String& name, const int timeOutMillisecs)
  179527. : handle (0), refCount (1)
  179528. {
  179529. handle = CreateMutex (0, TRUE, "Global\\" + name.replaceCharacter ('\\','/'));
  179530. if (handle != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179531. {
  179532. if (timeOutMillisecs == 0)
  179533. {
  179534. close();
  179535. return;
  179536. }
  179537. switch (WaitForSingleObject (handle, timeOutMillisecs < 0 ? INFINITE : timeOutMillisecs))
  179538. {
  179539. case WAIT_OBJECT_0:
  179540. case WAIT_ABANDONED:
  179541. break;
  179542. case WAIT_TIMEOUT:
  179543. default:
  179544. close();
  179545. break;
  179546. }
  179547. }
  179548. }
  179549. ~Pimpl()
  179550. {
  179551. close();
  179552. }
  179553. void close()
  179554. {
  179555. if (handle != 0)
  179556. {
  179557. ReleaseMutex (handle);
  179558. CloseHandle (handle);
  179559. handle = 0;
  179560. }
  179561. }
  179562. HANDLE handle;
  179563. int refCount;
  179564. };
  179565. InterProcessLock::InterProcessLock (const String& name_)
  179566. : name (name_)
  179567. {
  179568. }
  179569. InterProcessLock::~InterProcessLock()
  179570. {
  179571. }
  179572. bool InterProcessLock::enter (const int timeOutMillisecs)
  179573. {
  179574. const ScopedLock sl (lock);
  179575. if (pimpl == 0)
  179576. {
  179577. pimpl = new Pimpl (name, timeOutMillisecs);
  179578. if (pimpl->handle == 0)
  179579. pimpl = 0;
  179580. }
  179581. else
  179582. {
  179583. pimpl->refCount++;
  179584. }
  179585. return pimpl != 0;
  179586. }
  179587. void InterProcessLock::exit()
  179588. {
  179589. const ScopedLock sl (lock);
  179590. // Trying to release the lock too many times!
  179591. jassert (pimpl != 0);
  179592. if (pimpl != 0 && --(pimpl->refCount) == 0)
  179593. pimpl = 0;
  179594. }
  179595. #endif
  179596. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179597. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179598. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179599. // compiled on its own).
  179600. #if JUCE_INCLUDED_FILE
  179601. #ifndef CSIDL_MYMUSIC
  179602. #define CSIDL_MYMUSIC 0x000d
  179603. #endif
  179604. #ifndef CSIDL_MYVIDEO
  179605. #define CSIDL_MYVIDEO 0x000e
  179606. #endif
  179607. #ifndef INVALID_FILE_ATTRIBUTES
  179608. #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
  179609. #endif
  179610. const juce_wchar File::separator = '\\';
  179611. const String File::separatorString ("\\");
  179612. bool File::exists() const
  179613. {
  179614. return fullPath.isNotEmpty()
  179615. && GetFileAttributes (fullPath) != INVALID_FILE_ATTRIBUTES;
  179616. }
  179617. bool File::existsAsFile() const
  179618. {
  179619. return fullPath.isNotEmpty()
  179620. && (GetFileAttributes (fullPath) & FILE_ATTRIBUTE_DIRECTORY) == 0;
  179621. }
  179622. bool File::isDirectory() const
  179623. {
  179624. const DWORD attr = GetFileAttributes (fullPath);
  179625. return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES);
  179626. }
  179627. bool File::hasWriteAccess() const
  179628. {
  179629. if (exists())
  179630. return (GetFileAttributes (fullPath) & FILE_ATTRIBUTE_READONLY) == 0;
  179631. // on windows, it seems that even read-only directories can still be written into,
  179632. // so checking the parent directory's permissions would return the wrong result..
  179633. return true;
  179634. }
  179635. bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const
  179636. {
  179637. DWORD attr = GetFileAttributes (fullPath);
  179638. if (attr == INVALID_FILE_ATTRIBUTES)
  179639. return false;
  179640. if (shouldBeReadOnly == ((attr & FILE_ATTRIBUTE_READONLY) != 0))
  179641. return true;
  179642. if (shouldBeReadOnly)
  179643. attr |= FILE_ATTRIBUTE_READONLY;
  179644. else
  179645. attr &= ~FILE_ATTRIBUTE_READONLY;
  179646. return SetFileAttributes (fullPath, attr) != FALSE;
  179647. }
  179648. bool File::isHidden() const
  179649. {
  179650. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179651. }
  179652. bool File::deleteFile() const
  179653. {
  179654. if (! exists())
  179655. return true;
  179656. else if (isDirectory())
  179657. return RemoveDirectory (fullPath) != 0;
  179658. else
  179659. return DeleteFile (fullPath) != 0;
  179660. }
  179661. bool File::moveToTrash() const
  179662. {
  179663. if (! exists())
  179664. return true;
  179665. SHFILEOPSTRUCT fos;
  179666. zerostruct (fos);
  179667. // The string we pass in must be double null terminated..
  179668. String doubleNullTermPath (getFullPathName() + " ");
  179669. TCHAR* const p = const_cast <TCHAR*> (static_cast <const TCHAR*> (doubleNullTermPath));
  179670. p [getFullPathName().length()] = 0;
  179671. fos.wFunc = FO_DELETE;
  179672. fos.pFrom = p;
  179673. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179674. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179675. return SHFileOperation (&fos) == 0;
  179676. }
  179677. bool File::copyInternal (const File& dest) const
  179678. {
  179679. return CopyFile (fullPath, dest.getFullPathName(), false) != 0;
  179680. }
  179681. bool File::moveInternal (const File& dest) const
  179682. {
  179683. return MoveFile (fullPath, dest.getFullPathName()) != 0;
  179684. }
  179685. void File::createDirectoryInternal (const String& fileName) const
  179686. {
  179687. CreateDirectory (fileName, 0);
  179688. }
  179689. // return 0 if not possible
  179690. void* juce_fileOpen (const File& file, bool forWriting)
  179691. {
  179692. HANDLE h;
  179693. if (forWriting)
  179694. {
  179695. h = CreateFile (file.getFullPathName(), GENERIC_WRITE, FILE_SHARE_READ, 0,
  179696. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179697. if (h != INVALID_HANDLE_VALUE)
  179698. SetFilePointer (h, 0, 0, FILE_END);
  179699. else
  179700. h = 0;
  179701. }
  179702. else
  179703. {
  179704. h = CreateFile (file.getFullPathName(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179705. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179706. if (h == INVALID_HANDLE_VALUE)
  179707. h = 0;
  179708. }
  179709. return h;
  179710. }
  179711. void juce_fileClose (void* handle)
  179712. {
  179713. CloseHandle (handle);
  179714. }
  179715. int juce_fileRead (void* handle, void* buffer, int size)
  179716. {
  179717. DWORD num = 0;
  179718. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179719. return (int) num;
  179720. }
  179721. int juce_fileWrite (void* handle, const void* buffer, int size)
  179722. {
  179723. DWORD num;
  179724. WriteFile ((HANDLE) handle, buffer, size, &num, 0);
  179725. return (int) num;
  179726. }
  179727. int64 juce_fileSetPosition (void* handle, int64 pos)
  179728. {
  179729. LARGE_INTEGER li;
  179730. li.QuadPart = pos;
  179731. li.LowPart = SetFilePointer ((HANDLE) handle, li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails)
  179732. return li.QuadPart;
  179733. }
  179734. int64 FileOutputStream::getPositionInternal() const
  179735. {
  179736. if (fileHandle == 0)
  179737. return -1;
  179738. LARGE_INTEGER li;
  179739. li.QuadPart = 0;
  179740. li.LowPart = SetFilePointer ((HANDLE) fileHandle, 0, &li.HighPart, FILE_CURRENT); // (returns -1 if it fails)
  179741. return jmax ((int64) 0, li.QuadPart);
  179742. }
  179743. void FileOutputStream::flushInternal()
  179744. {
  179745. if (fileHandle != 0)
  179746. FlushFileBuffers ((HANDLE) fileHandle);
  179747. }
  179748. int64 File::getSize() const
  179749. {
  179750. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179751. if (GetFileAttributesEx (fullPath, GetFileExInfoStandard, &attributes))
  179752. return (((int64) attributes.nFileSizeHigh) << 32) | attributes.nFileSizeLow;
  179753. return 0;
  179754. }
  179755. static int64 fileTimeToTime (const FILETIME* const ft)
  179756. {
  179757. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME)); // tell me if this fails!
  179758. return (reinterpret_cast<const ULARGE_INTEGER*> (ft)->QuadPart - literal64bit (116444736000000000)) / 10000;
  179759. }
  179760. static void timeToFileTime (const int64 time, FILETIME* const ft)
  179761. {
  179762. reinterpret_cast<ULARGE_INTEGER*> (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000);
  179763. }
  179764. void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const
  179765. {
  179766. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179767. if (GetFileAttributesEx (fullPath, GetFileExInfoStandard, &attributes))
  179768. {
  179769. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  179770. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  179771. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  179772. }
  179773. else
  179774. {
  179775. creationTime = accessTime = modificationTime = 0;
  179776. }
  179777. }
  179778. bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const
  179779. {
  179780. void* const h = juce_fileOpen (fullPath, true);
  179781. bool ok = false;
  179782. if (h != 0)
  179783. {
  179784. FILETIME m, a, c;
  179785. timeToFileTime (modificationTime, &m);
  179786. timeToFileTime (accessTime, &a);
  179787. timeToFileTime (creationTime, &c);
  179788. ok = SetFileTime ((HANDLE) h,
  179789. creationTime > 0 ? &c : 0,
  179790. accessTime > 0 ? &a : 0,
  179791. modificationTime > 0 ? &m : 0) != 0;
  179792. juce_fileClose (h);
  179793. }
  179794. return ok;
  179795. }
  179796. void File::findFileSystemRoots (Array<File>& destArray)
  179797. {
  179798. TCHAR buffer [2048];
  179799. buffer[0] = 0;
  179800. buffer[1] = 0;
  179801. GetLogicalDriveStrings (2048, buffer);
  179802. const TCHAR* n = buffer;
  179803. StringArray roots;
  179804. while (*n != 0)
  179805. {
  179806. roots.add (String (n));
  179807. while (*n++ != 0)
  179808. {}
  179809. }
  179810. roots.sort (true);
  179811. for (int i = 0; i < roots.size(); ++i)
  179812. destArray.add (roots [i]);
  179813. }
  179814. static const String getDriveFromPath (const String& path)
  179815. {
  179816. if (path.isNotEmpty() && path[1] == ':')
  179817. return path.substring (0, 2) + '\\';
  179818. return path;
  179819. }
  179820. const String File::getVolumeLabel() const
  179821. {
  179822. TCHAR dest[64];
  179823. if (! GetVolumeInformation (getDriveFromPath (getFullPathName()), dest,
  179824. numElementsInArray (dest), 0, 0, 0, 0, 0))
  179825. dest[0] = 0;
  179826. return dest;
  179827. }
  179828. int File::getVolumeSerialNumber() const
  179829. {
  179830. TCHAR dest[64];
  179831. DWORD serialNum;
  179832. if (! GetVolumeInformation (getDriveFromPath (getFullPathName()), dest,
  179833. numElementsInArray (dest), &serialNum, 0, 0, 0, 0))
  179834. return 0;
  179835. return (int) serialNum;
  179836. }
  179837. static int64 getDiskSpaceInfo (const String& path, const bool total)
  179838. {
  179839. ULARGE_INTEGER spc, tot, totFree;
  179840. if (GetDiskFreeSpaceEx (getDriveFromPath (path), &spc, &tot, &totFree))
  179841. return total ? (int64) tot.QuadPart
  179842. : (int64) spc.QuadPart;
  179843. return 0;
  179844. }
  179845. int64 File::getBytesFreeOnVolume() const
  179846. {
  179847. return getDiskSpaceInfo (getFullPathName(), false);
  179848. }
  179849. int64 File::getVolumeTotalSize() const
  179850. {
  179851. return getDiskSpaceInfo (getFullPathName(), true);
  179852. }
  179853. static unsigned int getWindowsDriveType (const String& path)
  179854. {
  179855. return GetDriveType (getDriveFromPath (path));
  179856. }
  179857. bool File::isOnCDRomDrive() const
  179858. {
  179859. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  179860. }
  179861. bool File::isOnHardDisk() const
  179862. {
  179863. if (fullPath.isEmpty())
  179864. return false;
  179865. const unsigned int n = getWindowsDriveType (getFullPathName());
  179866. if (fullPath.toLowerCase()[0] <= 'b' && fullPath[1] == ':')
  179867. return n != DRIVE_REMOVABLE;
  179868. else
  179869. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  179870. }
  179871. bool File::isOnRemovableDrive() const
  179872. {
  179873. if (fullPath.isEmpty())
  179874. return false;
  179875. const unsigned int n = getWindowsDriveType (getFullPathName());
  179876. return n == DRIVE_CDROM
  179877. || n == DRIVE_REMOTE
  179878. || n == DRIVE_REMOVABLE
  179879. || n == DRIVE_RAMDISK;
  179880. }
  179881. static const File juce_getSpecialFolderPath (int type)
  179882. {
  179883. WCHAR path [MAX_PATH + 256];
  179884. if (SHGetSpecialFolderPath (0, path, type, FALSE))
  179885. return File (String (path));
  179886. return File::nonexistent;
  179887. }
  179888. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  179889. {
  179890. int csidlType = 0;
  179891. switch (type)
  179892. {
  179893. case userHomeDirectory: csidlType = CSIDL_PROFILE; break;
  179894. case userDocumentsDirectory: csidlType = CSIDL_PERSONAL; break;
  179895. case userDesktopDirectory: csidlType = CSIDL_DESKTOP; break;
  179896. case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break;
  179897. case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break;
  179898. case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break;
  179899. case userMusicDirectory: csidlType = CSIDL_MYMUSIC; break;
  179900. case userMoviesDirectory: csidlType = CSIDL_MYVIDEO; break;
  179901. case tempDirectory:
  179902. {
  179903. WCHAR dest [2048];
  179904. dest[0] = 0;
  179905. GetTempPath (numElementsInArray (dest), dest);
  179906. return File (String (dest));
  179907. }
  179908. case invokedExecutableFile:
  179909. case currentExecutableFile:
  179910. case currentApplicationFile:
  179911. {
  179912. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  179913. WCHAR dest [MAX_PATH + 256];
  179914. dest[0] = 0;
  179915. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  179916. return File (String (dest));
  179917. }
  179918. break;
  179919. default:
  179920. jassertfalse // unknown type?
  179921. return File::nonexistent;
  179922. }
  179923. return juce_getSpecialFolderPath (csidlType);
  179924. }
  179925. const File File::getCurrentWorkingDirectory()
  179926. {
  179927. WCHAR dest [MAX_PATH + 256];
  179928. dest[0] = 0;
  179929. GetCurrentDirectory (numElementsInArray (dest), dest);
  179930. return File (String (dest));
  179931. }
  179932. bool File::setAsCurrentWorkingDirectory() const
  179933. {
  179934. return SetCurrentDirectory (getFullPathName()) != FALSE;
  179935. }
  179936. const String File::getVersion() const
  179937. {
  179938. String result;
  179939. DWORD handle = 0;
  179940. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  179941. HeapBlock<char> buffer;
  179942. buffer.calloc (bufferSize);
  179943. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  179944. {
  179945. VS_FIXEDFILEINFO* vffi;
  179946. UINT len = 0;
  179947. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  179948. {
  179949. result << (int) HIWORD (vffi->dwFileVersionMS) << '.'
  179950. << (int) LOWORD (vffi->dwFileVersionMS) << '.'
  179951. << (int) HIWORD (vffi->dwFileVersionLS) << '.'
  179952. << (int) LOWORD (vffi->dwFileVersionLS);
  179953. }
  179954. }
  179955. return result;
  179956. }
  179957. const File File::getLinkedTarget() const
  179958. {
  179959. File result (*this);
  179960. String p (getFullPathName());
  179961. if (! exists())
  179962. p += ".lnk";
  179963. else if (getFileExtension() != ".lnk")
  179964. return result;
  179965. ComSmartPtr <IShellLink> shellLink;
  179966. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink)))
  179967. {
  179968. ComSmartPtr <IPersistFile> persistFile;
  179969. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  179970. {
  179971. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  179972. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  179973. {
  179974. WIN32_FIND_DATA winFindData;
  179975. WCHAR resolvedPath [MAX_PATH];
  179976. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  179977. result = File (resolvedPath);
  179978. }
  179979. }
  179980. }
  179981. return result;
  179982. }
  179983. class DirectoryIterator::NativeIterator::Pimpl
  179984. {
  179985. public:
  179986. Pimpl (const File& directory, const String& wildCard)
  179987. : directoryWithWildCard (File::addTrailingSeparator (directory.getFullPathName()) + wildCard),
  179988. handle (INVALID_HANDLE_VALUE)
  179989. {
  179990. }
  179991. ~Pimpl()
  179992. {
  179993. if (handle != INVALID_HANDLE_VALUE)
  179994. FindClose (handle);
  179995. }
  179996. bool next (String& filenameFound,
  179997. bool* const isDir, bool* const isHidden, int64* const fileSize,
  179998. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  179999. {
  180000. WIN32_FIND_DATA findData;
  180001. if (handle == INVALID_HANDLE_VALUE)
  180002. {
  180003. handle = FindFirstFile (directoryWithWildCard, &findData);
  180004. if (handle == INVALID_HANDLE_VALUE)
  180005. return false;
  180006. }
  180007. else
  180008. {
  180009. if (FindNextFile (handle, &findData) == 0)
  180010. return false;
  180011. }
  180012. filenameFound = findData.cFileName;
  180013. if (isDir != 0) *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180014. if (isHidden != 0) *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180015. if (fileSize != 0) *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180016. if (modTime != 0) *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180017. if (creationTime != 0) *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180018. if (isReadOnly != 0) *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180019. return true;
  180020. }
  180021. juce_UseDebuggingNewOperator
  180022. private:
  180023. const String directoryWithWildCard;
  180024. HANDLE handle;
  180025. Pimpl (const Pimpl&);
  180026. Pimpl& operator= (const Pimpl&);
  180027. };
  180028. DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard)
  180029. : pimpl (new DirectoryIterator::NativeIterator::Pimpl (directory, wildCard))
  180030. {
  180031. }
  180032. DirectoryIterator::NativeIterator::~NativeIterator()
  180033. {
  180034. }
  180035. bool DirectoryIterator::NativeIterator::next (String& filenameFound,
  180036. bool* const isDir, bool* const isHidden, int64* const fileSize,
  180037. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  180038. {
  180039. return pimpl->next (filenameFound, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  180040. }
  180041. bool PlatformUtilities::openDocument (const String& fileName, const String& parameters)
  180042. {
  180043. HINSTANCE hInstance = 0;
  180044. JUCE_TRY
  180045. {
  180046. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180047. }
  180048. JUCE_CATCH_ALL
  180049. return hInstance > (HINSTANCE) 32;
  180050. }
  180051. void File::revealToUser() const
  180052. {
  180053. if (isDirectory())
  180054. startAsProcess();
  180055. else if (getParentDirectory().exists())
  180056. getParentDirectory().startAsProcess();
  180057. }
  180058. class NamedPipeInternal
  180059. {
  180060. public:
  180061. NamedPipeInternal (const String& file, const bool isPipe_)
  180062. : pipeH (0),
  180063. cancelEvent (0),
  180064. connected (false),
  180065. isPipe (isPipe_)
  180066. {
  180067. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180068. pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180069. PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
  180070. : CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
  180071. OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
  180072. }
  180073. ~NamedPipeInternal()
  180074. {
  180075. disconnectPipe();
  180076. if (pipeH != 0)
  180077. CloseHandle (pipeH);
  180078. CloseHandle (cancelEvent);
  180079. }
  180080. bool connect (const int timeOutMs)
  180081. {
  180082. if (! isPipe)
  180083. return true;
  180084. if (! connected)
  180085. {
  180086. OVERLAPPED over;
  180087. zerostruct (over);
  180088. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180089. if (ConnectNamedPipe (pipeH, &over))
  180090. {
  180091. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180092. }
  180093. else
  180094. {
  180095. const int err = GetLastError();
  180096. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180097. {
  180098. HANDLE handles[] = { over.hEvent, cancelEvent };
  180099. if (WaitForMultipleObjects (2, handles, FALSE,
  180100. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180101. connected = true;
  180102. }
  180103. else if (err == ERROR_PIPE_CONNECTED)
  180104. {
  180105. connected = true;
  180106. }
  180107. }
  180108. CloseHandle (over.hEvent);
  180109. }
  180110. return connected;
  180111. }
  180112. void disconnectPipe()
  180113. {
  180114. if (connected)
  180115. {
  180116. DisconnectNamedPipe (pipeH);
  180117. connected = false;
  180118. }
  180119. }
  180120. HANDLE pipeH;
  180121. HANDLE cancelEvent;
  180122. bool connected, isPipe;
  180123. };
  180124. void NamedPipe::close()
  180125. {
  180126. cancelPendingReads();
  180127. const ScopedLock sl (lock);
  180128. delete static_cast<NamedPipeInternal*> (internal);
  180129. internal = 0;
  180130. }
  180131. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180132. {
  180133. close();
  180134. ScopedPointer<NamedPipeInternal> intern (new NamedPipeInternal ("\\\\.\\pipe\\" + pipeName, createPipe));
  180135. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180136. {
  180137. internal = intern.release();
  180138. return true;
  180139. }
  180140. return false;
  180141. }
  180142. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180143. {
  180144. const ScopedLock sl (lock);
  180145. int bytesRead = -1;
  180146. bool waitAgain = true;
  180147. while (waitAgain && internal != 0)
  180148. {
  180149. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180150. waitAgain = false;
  180151. if (! intern->connect (timeOutMilliseconds))
  180152. break;
  180153. if (maxBytesToRead <= 0)
  180154. return 0;
  180155. OVERLAPPED over;
  180156. zerostruct (over);
  180157. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180158. unsigned long numRead;
  180159. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180160. {
  180161. bytesRead = (int) numRead;
  180162. }
  180163. else if (GetLastError() == ERROR_IO_PENDING)
  180164. {
  180165. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180166. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180167. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180168. : INFINITE);
  180169. if (waitResult != WAIT_OBJECT_0)
  180170. {
  180171. // if the operation timed out, let's cancel it...
  180172. CancelIo (intern->pipeH);
  180173. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180174. }
  180175. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180176. {
  180177. bytesRead = (int) numRead;
  180178. }
  180179. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180180. {
  180181. intern->disconnectPipe();
  180182. waitAgain = true;
  180183. }
  180184. }
  180185. else
  180186. {
  180187. waitAgain = internal != 0;
  180188. Sleep (5);
  180189. }
  180190. CloseHandle (over.hEvent);
  180191. }
  180192. return bytesRead;
  180193. }
  180194. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180195. {
  180196. int bytesWritten = -1;
  180197. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180198. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180199. {
  180200. if (numBytesToWrite <= 0)
  180201. return 0;
  180202. OVERLAPPED over;
  180203. zerostruct (over);
  180204. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180205. unsigned long numWritten;
  180206. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180207. {
  180208. bytesWritten = (int) numWritten;
  180209. }
  180210. else if (GetLastError() == ERROR_IO_PENDING)
  180211. {
  180212. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180213. DWORD waitResult;
  180214. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180215. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180216. : INFINITE);
  180217. if (waitResult != WAIT_OBJECT_0)
  180218. {
  180219. CancelIo (intern->pipeH);
  180220. WaitForSingleObject (over.hEvent, INFINITE);
  180221. }
  180222. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180223. {
  180224. bytesWritten = (int) numWritten;
  180225. }
  180226. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180227. {
  180228. intern->disconnectPipe();
  180229. }
  180230. }
  180231. CloseHandle (over.hEvent);
  180232. }
  180233. return bytesWritten;
  180234. }
  180235. void NamedPipe::cancelPendingReads()
  180236. {
  180237. if (internal != 0)
  180238. SetEvent (static_cast<NamedPipeInternal*> (internal)->cancelEvent);
  180239. }
  180240. #endif
  180241. /*** End of inlined file: juce_win32_Files.cpp ***/
  180242. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180243. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180244. // compiled on its own).
  180245. #if JUCE_INCLUDED_FILE
  180246. #ifndef INTERNET_FLAG_NEED_FILE
  180247. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180248. #endif
  180249. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180250. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180251. #endif
  180252. struct ConnectionAndRequestStruct
  180253. {
  180254. HINTERNET connection, request;
  180255. };
  180256. static HINTERNET sessionHandle = 0;
  180257. #ifndef WORKAROUND_TIMEOUT_BUG
  180258. //#define WORKAROUND_TIMEOUT_BUG 1
  180259. #endif
  180260. #if WORKAROUND_TIMEOUT_BUG
  180261. // Required because of a Microsoft bug in setting a timeout
  180262. class InternetConnectThread : public Thread
  180263. {
  180264. public:
  180265. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180266. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180267. {
  180268. startThread();
  180269. }
  180270. ~InternetConnectThread()
  180271. {
  180272. stopThread (60000);
  180273. }
  180274. void run()
  180275. {
  180276. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180277. uc.nPort, _T(""), _T(""),
  180278. isFtp ? INTERNET_SERVICE_FTP
  180279. : INTERNET_SERVICE_HTTP,
  180280. 0, 0);
  180281. notify();
  180282. }
  180283. juce_UseDebuggingNewOperator
  180284. private:
  180285. URL_COMPONENTS& uc;
  180286. HINTERNET& connection;
  180287. const bool isFtp;
  180288. InternetConnectThread (const InternetConnectThread&);
  180289. InternetConnectThread& operator= (const InternetConnectThread&);
  180290. };
  180291. #endif
  180292. void* juce_openInternetFile (const String& url,
  180293. const String& headers,
  180294. const MemoryBlock& postData,
  180295. const bool isPost,
  180296. URL::OpenStreamProgressCallback* callback,
  180297. void* callbackContext,
  180298. int timeOutMs)
  180299. {
  180300. if (sessionHandle == 0)
  180301. sessionHandle = InternetOpen (_T("juce"),
  180302. INTERNET_OPEN_TYPE_PRECONFIG,
  180303. 0, 0, 0);
  180304. if (sessionHandle != 0)
  180305. {
  180306. // break up the url..
  180307. TCHAR file[1024], server[1024];
  180308. URL_COMPONENTS uc;
  180309. zerostruct (uc);
  180310. uc.dwStructSize = sizeof (uc);
  180311. uc.dwUrlPathLength = sizeof (file);
  180312. uc.dwHostNameLength = sizeof (server);
  180313. uc.lpszUrlPath = file;
  180314. uc.lpszHostName = server;
  180315. if (InternetCrackUrl (url, 0, 0, &uc))
  180316. {
  180317. int disable = 1;
  180318. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180319. if (timeOutMs == 0)
  180320. timeOutMs = 30000;
  180321. else if (timeOutMs < 0)
  180322. timeOutMs = -1;
  180323. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180324. const bool isFtp = url.startsWithIgnoreCase ("ftp:");
  180325. #if WORKAROUND_TIMEOUT_BUG
  180326. HINTERNET connection = 0;
  180327. {
  180328. InternetConnectThread connectThread (uc, connection, isFtp);
  180329. connectThread.wait (timeOutMs);
  180330. if (connection == 0)
  180331. {
  180332. InternetCloseHandle (sessionHandle);
  180333. sessionHandle = 0;
  180334. }
  180335. }
  180336. #else
  180337. HINTERNET connection = InternetConnect (sessionHandle,
  180338. uc.lpszHostName,
  180339. uc.nPort,
  180340. _T(""), _T(""),
  180341. isFtp ? INTERNET_SERVICE_FTP
  180342. : INTERNET_SERVICE_HTTP,
  180343. 0, 0);
  180344. #endif
  180345. if (connection != 0)
  180346. {
  180347. if (isFtp)
  180348. {
  180349. HINTERNET request = FtpOpenFile (connection,
  180350. uc.lpszUrlPath,
  180351. GENERIC_READ,
  180352. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180353. 0);
  180354. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180355. result->connection = connection;
  180356. result->request = request;
  180357. return result;
  180358. }
  180359. else
  180360. {
  180361. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180362. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180363. if (url.startsWithIgnoreCase ("https:"))
  180364. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180365. // IE7 seems to automatically work out when it's https)
  180366. HINTERNET request = HttpOpenRequest (connection,
  180367. isPost ? _T("POST")
  180368. : _T("GET"),
  180369. uc.lpszUrlPath,
  180370. 0, 0, mimeTypes, flags, 0);
  180371. if (request != 0)
  180372. {
  180373. INTERNET_BUFFERS buffers;
  180374. zerostruct (buffers);
  180375. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180376. buffers.lpcszHeader = (LPCTSTR) headers;
  180377. buffers.dwHeadersLength = headers.length();
  180378. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180379. ConnectionAndRequestStruct* result = 0;
  180380. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180381. {
  180382. int bytesSent = 0;
  180383. for (;;)
  180384. {
  180385. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180386. DWORD bytesDone = 0;
  180387. if (bytesToDo > 0
  180388. && ! InternetWriteFile (request,
  180389. static_cast <const char*> (postData.getData()) + bytesSent,
  180390. bytesToDo, &bytesDone))
  180391. {
  180392. break;
  180393. }
  180394. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180395. {
  180396. result = new ConnectionAndRequestStruct();
  180397. result->connection = connection;
  180398. result->request = request;
  180399. HttpEndRequest (request, 0, 0, 0);
  180400. return result;
  180401. }
  180402. bytesSent += bytesDone;
  180403. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180404. break;
  180405. }
  180406. }
  180407. InternetCloseHandle (request);
  180408. }
  180409. InternetCloseHandle (connection);
  180410. }
  180411. }
  180412. }
  180413. }
  180414. return 0;
  180415. }
  180416. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180417. {
  180418. DWORD bytesRead = 0;
  180419. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180420. if (crs != 0)
  180421. InternetReadFile (crs->request,
  180422. buffer, bytesToRead,
  180423. &bytesRead);
  180424. return bytesRead;
  180425. }
  180426. int juce_seekInInternetFile (void* handle, int newPosition)
  180427. {
  180428. if (handle != 0)
  180429. {
  180430. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180431. return InternetSetFilePointer (crs->request, newPosition, 0, FILE_BEGIN, 0);
  180432. }
  180433. else
  180434. {
  180435. return -1;
  180436. }
  180437. }
  180438. int64 juce_getInternetFileContentLength (void* handle)
  180439. {
  180440. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180441. if (crs != 0)
  180442. {
  180443. DWORD index = 0, result = 0, size = sizeof (result);
  180444. if (HttpQueryInfo (crs->request, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180445. &result, &size, &index))
  180446. {
  180447. return (int64) result;
  180448. }
  180449. }
  180450. return -1;
  180451. }
  180452. void juce_closeInternetFile (void* handle)
  180453. {
  180454. if (handle != 0)
  180455. {
  180456. ScopedPointer <ConnectionAndRequestStruct> crs (static_cast <ConnectionAndRequestStruct*> (handle));
  180457. InternetCloseHandle (crs->request);
  180458. InternetCloseHandle (crs->connection);
  180459. }
  180460. }
  180461. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180462. {
  180463. int numFound = 0;
  180464. DynamicLibraryLoader dll ("iphlpapi.dll");
  180465. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180466. if (getAdaptersInfo != 0)
  180467. {
  180468. ULONG len = sizeof (IP_ADAPTER_INFO);
  180469. MemoryBlock mb;
  180470. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180471. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180472. {
  180473. mb.setSize (len);
  180474. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180475. }
  180476. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180477. {
  180478. PIP_ADAPTER_INFO adapter = adapterInfo;
  180479. while (adapter != 0)
  180480. {
  180481. int64 mac = 0;
  180482. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180483. mac = (mac << 8) | adapter->Address[i];
  180484. if (littleEndian)
  180485. mac = (int64) ByteOrder::swap ((uint64) mac);
  180486. if (numFound < maxNum && mac != 0)
  180487. addresses [numFound++] = mac;
  180488. adapter = adapter->Next;
  180489. }
  180490. }
  180491. }
  180492. return numFound;
  180493. }
  180494. struct ASTAT
  180495. {
  180496. ADAPTER_STATUS adapt;
  180497. NAME_BUFFER NameBuff [30];
  180498. };
  180499. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180500. {
  180501. int numFound = 0;
  180502. DynamicLibraryLoader dll ("netapi32.dll");
  180503. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180504. if (NetbiosCall != 0)
  180505. {
  180506. NCB ncb;
  180507. zerostruct (ncb);
  180508. ASTAT astat;
  180509. zerostruct (astat);
  180510. LANA_ENUM enums;
  180511. zerostruct (enums);
  180512. ncb.ncb_command = NCBENUM;
  180513. ncb.ncb_buffer = (unsigned char*) &enums;
  180514. ncb.ncb_length = sizeof (LANA_ENUM);
  180515. NetbiosCall (&ncb);
  180516. for (int i = 0; i < enums.length; ++i)
  180517. {
  180518. zerostruct (ncb);
  180519. ncb.ncb_command = NCBRESET;
  180520. ncb.ncb_lana_num = enums.lana[i];
  180521. if (NetbiosCall (&ncb) == 0)
  180522. {
  180523. zerostruct (ncb);
  180524. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180525. ncb.ncb_command = NCBASTAT;
  180526. ncb.ncb_lana_num = enums.lana[i];
  180527. ncb.ncb_buffer = (unsigned char*) &astat;
  180528. ncb.ncb_length = sizeof (ASTAT);
  180529. if (NetbiosCall (&ncb) == 0)
  180530. {
  180531. if (astat.adapt.adapter_type == 0xfe)
  180532. {
  180533. uint64 mac = 0;
  180534. for (int i = 6; --i >= 0;)
  180535. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180536. if (numFound < maxNum && mac != 0)
  180537. addresses [numFound++] = mac;
  180538. }
  180539. }
  180540. }
  180541. }
  180542. }
  180543. return numFound;
  180544. }
  180545. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180546. {
  180547. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180548. if (numFound == 0)
  180549. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180550. return numFound;
  180551. }
  180552. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180553. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180554. const String& emailSubject,
  180555. const String& bodyText,
  180556. const StringArray& filesToAttach)
  180557. {
  180558. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180559. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180560. bool ok = false;
  180561. if (mapiSendMail != 0)
  180562. {
  180563. MapiMessage message;
  180564. zerostruct (message);
  180565. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180566. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180567. MapiRecipDesc recip;
  180568. zerostruct (recip);
  180569. recip.ulRecipClass = MAPI_TO;
  180570. String targetEmailAddress_ (targetEmailAddress);
  180571. if (targetEmailAddress_.isEmpty())
  180572. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180573. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180574. message.nRecipCount = 1;
  180575. message.lpRecips = &recip;
  180576. HeapBlock <MapiFileDesc> files;
  180577. files.calloc (filesToAttach.size());
  180578. message.nFileCount = filesToAttach.size();
  180579. message.lpFiles = files;
  180580. for (int i = 0; i < filesToAttach.size(); ++i)
  180581. {
  180582. files[i].nPosition = (ULONG) -1;
  180583. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180584. }
  180585. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180586. }
  180587. FreeLibrary (h);
  180588. return ok;
  180589. }
  180590. #endif
  180591. /*** End of inlined file: juce_win32_Network.cpp ***/
  180592. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180593. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180594. // compiled on its own).
  180595. #if JUCE_INCLUDED_FILE
  180596. static HKEY findKeyForPath (String name,
  180597. const bool createForWriting,
  180598. String& valueName)
  180599. {
  180600. HKEY rootKey = 0;
  180601. if (name.startsWithIgnoreCase ("HKEY_CURRENT_USER\\"))
  180602. rootKey = HKEY_CURRENT_USER;
  180603. else if (name.startsWithIgnoreCase ("HKEY_LOCAL_MACHINE\\"))
  180604. rootKey = HKEY_LOCAL_MACHINE;
  180605. else if (name.startsWithIgnoreCase ("HKEY_CLASSES_ROOT\\"))
  180606. rootKey = HKEY_CLASSES_ROOT;
  180607. if (rootKey != 0)
  180608. {
  180609. name = name.substring (name.indexOfChar ('\\') + 1);
  180610. const int lastSlash = name.lastIndexOfChar ('\\');
  180611. valueName = name.substring (lastSlash + 1);
  180612. name = name.substring (0, lastSlash);
  180613. HKEY key;
  180614. DWORD result;
  180615. if (createForWriting)
  180616. {
  180617. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180618. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180619. return key;
  180620. }
  180621. else
  180622. {
  180623. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180624. return key;
  180625. }
  180626. }
  180627. return 0;
  180628. }
  180629. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180630. const String& defaultValue)
  180631. {
  180632. String valueName, result (defaultValue);
  180633. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180634. if (k != 0)
  180635. {
  180636. WCHAR buffer [2048];
  180637. unsigned long bufferSize = sizeof (buffer);
  180638. DWORD type = REG_SZ;
  180639. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180640. {
  180641. if (type == REG_SZ)
  180642. result = buffer;
  180643. else if (type == REG_DWORD)
  180644. result = String ((int) *(DWORD*) buffer);
  180645. }
  180646. RegCloseKey (k);
  180647. }
  180648. return result;
  180649. }
  180650. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180651. const String& value)
  180652. {
  180653. String valueName;
  180654. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180655. if (k != 0)
  180656. {
  180657. RegSetValueEx (k, valueName, 0, REG_SZ,
  180658. (const BYTE*) (const WCHAR*) value,
  180659. sizeof (WCHAR) * (value.length() + 1));
  180660. RegCloseKey (k);
  180661. }
  180662. }
  180663. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  180664. {
  180665. bool exists = false;
  180666. String valueName;
  180667. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180668. if (k != 0)
  180669. {
  180670. unsigned char buffer [2048];
  180671. unsigned long bufferSize = sizeof (buffer);
  180672. DWORD type = 0;
  180673. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  180674. exists = true;
  180675. RegCloseKey (k);
  180676. }
  180677. return exists;
  180678. }
  180679. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  180680. {
  180681. String valueName;
  180682. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180683. if (k != 0)
  180684. {
  180685. RegDeleteValue (k, valueName);
  180686. RegCloseKey (k);
  180687. }
  180688. }
  180689. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  180690. {
  180691. String valueName;
  180692. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  180693. if (k != 0)
  180694. {
  180695. RegDeleteKey (k, valueName);
  180696. RegCloseKey (k);
  180697. }
  180698. }
  180699. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  180700. const String& symbolicDescription,
  180701. const String& fullDescription,
  180702. const File& targetExecutable,
  180703. int iconResourceNumber)
  180704. {
  180705. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  180706. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  180707. if (iconResourceNumber != 0)
  180708. setRegistryValue (key + "\\DefaultIcon\\",
  180709. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  180710. setRegistryValue (key + "\\", fullDescription);
  180711. setRegistryValue (key + "\\shell\\open\\command\\",
  180712. targetExecutable.getFullPathName() + " %1");
  180713. }
  180714. bool juce_IsRunningInWine()
  180715. {
  180716. HKEY key;
  180717. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  180718. {
  180719. RegCloseKey (key);
  180720. return true;
  180721. }
  180722. return false;
  180723. }
  180724. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  180725. {
  180726. String s (::GetCommandLineW());
  180727. StringArray tokens;
  180728. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  180729. return tokens.joinIntoString (" ", 1);
  180730. }
  180731. static void* currentModuleHandle = 0;
  180732. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  180733. {
  180734. if (currentModuleHandle == 0)
  180735. currentModuleHandle = GetModuleHandle (0);
  180736. return currentModuleHandle;
  180737. }
  180738. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  180739. {
  180740. currentModuleHandle = newHandle;
  180741. }
  180742. void PlatformUtilities::fpuReset()
  180743. {
  180744. #if JUCE_MSVC
  180745. _clearfp();
  180746. #endif
  180747. }
  180748. void PlatformUtilities::beep()
  180749. {
  180750. MessageBeep (MB_OK);
  180751. }
  180752. #endif
  180753. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  180754. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180755. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  180756. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180757. // compiled on its own).
  180758. #if JUCE_INCLUDED_FILE
  180759. static const unsigned int specialId = WM_APP + 0x4400;
  180760. static const unsigned int broadcastId = WM_APP + 0x4403;
  180761. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  180762. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  180763. HWND juce_messageWindowHandle = 0;
  180764. extern long improbableWindowNumber; // defined in windowing.cpp
  180765. #ifndef WM_APPCOMMAND
  180766. #define WM_APPCOMMAND 0x0319
  180767. #endif
  180768. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  180769. const UINT message,
  180770. const WPARAM wParam,
  180771. const LPARAM lParam) throw()
  180772. {
  180773. JUCE_TRY
  180774. {
  180775. if (h == juce_messageWindowHandle)
  180776. {
  180777. if (message == specialCallbackId)
  180778. {
  180779. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  180780. return (LRESULT) (*func) ((void*) lParam);
  180781. }
  180782. else if (message == specialId)
  180783. {
  180784. // these are trapped early in the dispatch call, but must also be checked
  180785. // here in case there are windows modal dialog boxes doing their own
  180786. // dispatch loop and not calling our version
  180787. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  180788. return 0;
  180789. }
  180790. else if (message == broadcastId)
  180791. {
  180792. const ScopedPointer <String> messageString ((String*) lParam);
  180793. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  180794. return 0;
  180795. }
  180796. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  180797. {
  180798. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  180799. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  180800. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  180801. return 0;
  180802. }
  180803. }
  180804. }
  180805. JUCE_CATCH_EXCEPTION
  180806. return DefWindowProc (h, message, wParam, lParam);
  180807. }
  180808. static bool isEventBlockedByModalComps (MSG& m)
  180809. {
  180810. if (Component::getNumCurrentlyModalComponents() == 0
  180811. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  180812. return false;
  180813. switch (m.message)
  180814. {
  180815. case WM_MOUSEMOVE:
  180816. case WM_NCMOUSEMOVE:
  180817. case 0x020A: /* WM_MOUSEWHEEL */
  180818. case 0x020E: /* WM_MOUSEHWHEEL */
  180819. case WM_KEYUP:
  180820. case WM_SYSKEYUP:
  180821. case WM_CHAR:
  180822. case WM_APPCOMMAND:
  180823. case WM_LBUTTONUP:
  180824. case WM_MBUTTONUP:
  180825. case WM_RBUTTONUP:
  180826. case WM_MOUSEACTIVATE:
  180827. case WM_NCMOUSEHOVER:
  180828. case WM_MOUSEHOVER:
  180829. return true;
  180830. case WM_NCLBUTTONDOWN:
  180831. case WM_NCLBUTTONDBLCLK:
  180832. case WM_NCRBUTTONDOWN:
  180833. case WM_NCRBUTTONDBLCLK:
  180834. case WM_NCMBUTTONDOWN:
  180835. case WM_NCMBUTTONDBLCLK:
  180836. case WM_LBUTTONDOWN:
  180837. case WM_LBUTTONDBLCLK:
  180838. case WM_MBUTTONDOWN:
  180839. case WM_MBUTTONDBLCLK:
  180840. case WM_RBUTTONDOWN:
  180841. case WM_RBUTTONDBLCLK:
  180842. case WM_KEYDOWN:
  180843. case WM_SYSKEYDOWN:
  180844. {
  180845. Component* const modal = Component::getCurrentlyModalComponent (0);
  180846. if (modal != 0)
  180847. modal->inputAttemptWhenModal();
  180848. return true;
  180849. }
  180850. default:
  180851. break;
  180852. }
  180853. return false;
  180854. }
  180855. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  180856. {
  180857. MSG m;
  180858. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  180859. return false;
  180860. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  180861. {
  180862. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  180863. {
  180864. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  180865. }
  180866. else if (m.message == WM_QUIT)
  180867. {
  180868. if (JUCEApplication::getInstance())
  180869. JUCEApplication::getInstance()->systemRequestedQuit();
  180870. }
  180871. else if (! isEventBlockedByModalComps (m))
  180872. {
  180873. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  180874. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  180875. {
  180876. // if it's someone else's window being clicked on, and the focus is
  180877. // currently on a juce window, pass the kb focus over..
  180878. HWND currentFocus = GetFocus();
  180879. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  180880. SetFocus (m.hwnd);
  180881. }
  180882. TranslateMessage (&m);
  180883. DispatchMessage (&m);
  180884. }
  180885. }
  180886. return true;
  180887. }
  180888. bool juce_postMessageToSystemQueue (void* message)
  180889. {
  180890. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  180891. }
  180892. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  180893. void* userData)
  180894. {
  180895. if (MessageManager::getInstance()->isThisTheMessageThread())
  180896. {
  180897. return (*callback) (userData);
  180898. }
  180899. else
  180900. {
  180901. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  180902. // deadlock because the message manager is blocked from running, and can't
  180903. // call your function..
  180904. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  180905. return (void*) SendMessage (juce_messageWindowHandle,
  180906. specialCallbackId,
  180907. (WPARAM) callback,
  180908. (LPARAM) userData);
  180909. }
  180910. }
  180911. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  180912. {
  180913. if (hwnd != juce_messageWindowHandle)
  180914. reinterpret_cast <VoidArray*> (lParam)->add ((void*) hwnd);
  180915. return TRUE;
  180916. }
  180917. void MessageManager::broadcastMessage (const String& value) throw()
  180918. {
  180919. VoidArray windows;
  180920. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  180921. const String localCopy (value);
  180922. COPYDATASTRUCT data;
  180923. data.dwData = broadcastId;
  180924. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  180925. data.lpData = (void*) static_cast <const juce_wchar*> (localCopy);
  180926. for (int i = windows.size(); --i >= 0;)
  180927. {
  180928. HWND hwnd = (HWND) windows.getUnchecked(i);
  180929. TCHAR windowName [64]; // no need to read longer strings than this
  180930. GetWindowText (hwnd, windowName, 64);
  180931. windowName [63] = 0;
  180932. if (String (windowName) == String (messageWindowName))
  180933. {
  180934. DWORD_PTR result;
  180935. SendMessageTimeout (hwnd, WM_COPYDATA,
  180936. (WPARAM) juce_messageWindowHandle,
  180937. (LPARAM) &data,
  180938. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  180939. 8000,
  180940. &result);
  180941. }
  180942. }
  180943. }
  180944. static const String getMessageWindowClassName()
  180945. {
  180946. // this name has to be different for each app/dll instance because otherwise
  180947. // poor old Win32 can get a bit confused (even despite it not being a process-global
  180948. // window class).
  180949. static int number = 0;
  180950. if (number == 0)
  180951. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  180952. return "JUCEcs_" + String (number);
  180953. }
  180954. void MessageManager::doPlatformSpecificInitialisation()
  180955. {
  180956. OleInitialize (0);
  180957. const String className (getMessageWindowClassName());
  180958. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180959. WNDCLASSEX wc;
  180960. zerostruct (wc);
  180961. wc.cbSize = sizeof (wc);
  180962. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  180963. wc.cbWndExtra = 4;
  180964. wc.hInstance = hmod;
  180965. wc.lpszClassName = className;
  180966. RegisterClassEx (&wc);
  180967. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  180968. messageWindowName,
  180969. 0, 0, 0, 0, 0, 0, 0,
  180970. hmod, 0);
  180971. }
  180972. void MessageManager::doPlatformSpecificShutdown()
  180973. {
  180974. DestroyWindow (juce_messageWindowHandle);
  180975. UnregisterClass (getMessageWindowClassName(), 0);
  180976. OleUninitialize();
  180977. }
  180978. #endif
  180979. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  180980. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  180981. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180982. // compiled on its own).
  180983. #if JUCE_INCLUDED_FILE
  180984. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  180985. // these are in the windows SDK, but need to be repeated here for GCC..
  180986. #ifndef GET_APPCOMMAND_LPARAM
  180987. #define FAPPCOMMAND_MASK 0xF000
  180988. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  180989. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  180990. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  180991. #define APPCOMMAND_MEDIA_STOP 13
  180992. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  180993. #define WM_APPCOMMAND 0x0319
  180994. #endif
  180995. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  180996. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  180997. extern bool juce_IsRunningInWine();
  180998. #ifndef ULW_ALPHA
  180999. #define ULW_ALPHA 0x00000002
  181000. #endif
  181001. #ifndef AC_SRC_ALPHA
  181002. #define AC_SRC_ALPHA 0x01
  181003. #endif
  181004. static HPALETTE palette = 0;
  181005. static bool createPaletteIfNeeded = true;
  181006. static bool shouldDeactivateTitleBar = true;
  181007. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181008. #define WM_TRAYNOTIFY WM_USER + 100
  181009. using ::abs;
  181010. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181011. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181012. bool Desktop::canUseSemiTransparentWindows() throw()
  181013. {
  181014. if (updateLayeredWindow == 0)
  181015. {
  181016. if (! juce_IsRunningInWine())
  181017. {
  181018. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181019. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181020. }
  181021. }
  181022. return updateLayeredWindow != 0;
  181023. }
  181024. const int extendedKeyModifier = 0x10000;
  181025. const int KeyPress::spaceKey = VK_SPACE;
  181026. const int KeyPress::returnKey = VK_RETURN;
  181027. const int KeyPress::escapeKey = VK_ESCAPE;
  181028. const int KeyPress::backspaceKey = VK_BACK;
  181029. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181030. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181031. const int KeyPress::tabKey = VK_TAB;
  181032. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181033. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181034. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181035. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181036. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181037. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181038. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181039. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181040. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181041. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181042. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181043. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181044. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181045. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181046. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181047. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181048. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181049. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181050. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181051. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181052. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181053. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181054. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181055. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181056. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181057. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181058. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181059. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181060. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181061. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181062. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181063. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181064. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181065. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181066. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181067. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181068. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181069. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181070. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181071. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181072. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181073. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181074. const int KeyPress::playKey = 0x30000;
  181075. const int KeyPress::stopKey = 0x30001;
  181076. const int KeyPress::fastForwardKey = 0x30002;
  181077. const int KeyPress::rewindKey = 0x30003;
  181078. class WindowsBitmapImage : public Image
  181079. {
  181080. public:
  181081. HBITMAP hBitmap;
  181082. BITMAPV4HEADER bitmapInfo;
  181083. HDC hdc;
  181084. unsigned char* bitmapData;
  181085. WindowsBitmapImage (const PixelFormat format_,
  181086. const int w, const int h, const bool clearImage)
  181087. : Image (format_, w, h)
  181088. {
  181089. jassert (format_ == RGB || format_ == ARGB);
  181090. pixelStride = (format_ == RGB) ? 3 : 4;
  181091. zerostruct (bitmapInfo);
  181092. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181093. bitmapInfo.bV4Width = w;
  181094. bitmapInfo.bV4Height = h;
  181095. bitmapInfo.bV4Planes = 1;
  181096. bitmapInfo.bV4CSType = 1;
  181097. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181098. if (format_ == ARGB)
  181099. {
  181100. bitmapInfo.bV4AlphaMask = 0xff000000;
  181101. bitmapInfo.bV4RedMask = 0xff0000;
  181102. bitmapInfo.bV4GreenMask = 0xff00;
  181103. bitmapInfo.bV4BlueMask = 0xff;
  181104. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181105. }
  181106. else
  181107. {
  181108. bitmapInfo.bV4V4Compression = BI_RGB;
  181109. }
  181110. lineStride = -((w * pixelStride + 3) & ~3);
  181111. HDC dc = GetDC (0);
  181112. hdc = CreateCompatibleDC (dc);
  181113. ReleaseDC (0, dc);
  181114. SetMapMode (hdc, MM_TEXT);
  181115. hBitmap = CreateDIBSection (hdc,
  181116. (BITMAPINFO*) &(bitmapInfo),
  181117. DIB_RGB_COLORS,
  181118. (void**) &bitmapData,
  181119. 0, 0);
  181120. SelectObject (hdc, hBitmap);
  181121. if (format_ == ARGB && clearImage)
  181122. zeromem (bitmapData, abs (h * lineStride));
  181123. imageData = bitmapData - (lineStride * (h - 1));
  181124. }
  181125. ~WindowsBitmapImage()
  181126. {
  181127. DeleteDC (hdc);
  181128. DeleteObject (hBitmap);
  181129. }
  181130. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181131. const int x, const int y,
  181132. const RectangleList& maskedRegion) throw()
  181133. {
  181134. static HDRAWDIB hdd = 0;
  181135. static bool needToCreateDrawDib = true;
  181136. if (needToCreateDrawDib)
  181137. {
  181138. needToCreateDrawDib = false;
  181139. HDC dc = GetDC (0);
  181140. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181141. ReleaseDC (0, dc);
  181142. // only open if we're not palettised
  181143. if (n > 8)
  181144. hdd = DrawDibOpen();
  181145. }
  181146. if (createPaletteIfNeeded)
  181147. {
  181148. HDC dc = GetDC (0);
  181149. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181150. ReleaseDC (0, dc);
  181151. if (n <= 8)
  181152. palette = CreateHalftonePalette (dc);
  181153. createPaletteIfNeeded = false;
  181154. }
  181155. if (palette != 0)
  181156. {
  181157. SelectPalette (dc, palette, FALSE);
  181158. RealizePalette (dc);
  181159. SetStretchBltMode (dc, HALFTONE);
  181160. }
  181161. SetMapMode (dc, MM_TEXT);
  181162. if (transparent)
  181163. {
  181164. POINT p, pos;
  181165. SIZE size;
  181166. RECT windowBounds;
  181167. GetWindowRect (hwnd, &windowBounds);
  181168. p.x = -x;
  181169. p.y = -y;
  181170. pos.x = windowBounds.left;
  181171. pos.y = windowBounds.top;
  181172. size.cx = windowBounds.right - windowBounds.left;
  181173. size.cy = windowBounds.bottom - windowBounds.top;
  181174. BLENDFUNCTION bf;
  181175. bf.AlphaFormat = AC_SRC_ALPHA;
  181176. bf.BlendFlags = 0;
  181177. bf.BlendOp = AC_SRC_OVER;
  181178. bf.SourceConstantAlpha = 0xff;
  181179. if (! maskedRegion.isEmpty())
  181180. {
  181181. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181182. {
  181183. const Rectangle<int>& r = *i.getRectangle();
  181184. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181185. }
  181186. }
  181187. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181188. }
  181189. else
  181190. {
  181191. int savedDC = 0;
  181192. if (! maskedRegion.isEmpty())
  181193. {
  181194. savedDC = SaveDC (dc);
  181195. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181196. {
  181197. const Rectangle<int>& r = *i.getRectangle();
  181198. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181199. }
  181200. }
  181201. const int w = getWidth();
  181202. const int h = getHeight();
  181203. if (hdd == 0)
  181204. {
  181205. StretchDIBits (dc,
  181206. x, y, w, h,
  181207. 0, 0, w, h,
  181208. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181209. DIB_RGB_COLORS, SRCCOPY);
  181210. }
  181211. else
  181212. {
  181213. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181214. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181215. 0, 0, w, h, 0);
  181216. }
  181217. if (! maskedRegion.isEmpty())
  181218. RestoreDC (dc, savedDC);
  181219. }
  181220. }
  181221. juce_UseDebuggingNewOperator
  181222. private:
  181223. WindowsBitmapImage (const WindowsBitmapImage&);
  181224. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181225. };
  181226. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181227. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  181228. {
  181229. SHORT k = (SHORT) keyCode;
  181230. if ((keyCode & extendedKeyModifier) == 0
  181231. && (k >= (SHORT) 'a' && k <= (SHORT) 'z'))
  181232. k += (SHORT) 'A' - (SHORT) 'a';
  181233. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181234. (SHORT) '+', VK_OEM_PLUS,
  181235. (SHORT) '-', VK_OEM_MINUS,
  181236. (SHORT) '.', VK_OEM_PERIOD,
  181237. (SHORT) ';', VK_OEM_1,
  181238. (SHORT) ':', VK_OEM_1,
  181239. (SHORT) '/', VK_OEM_2,
  181240. (SHORT) '?', VK_OEM_2,
  181241. (SHORT) '[', VK_OEM_4,
  181242. (SHORT) ']', VK_OEM_6 };
  181243. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181244. if (k == translatedValues [i])
  181245. k = translatedValues [i + 1];
  181246. return (GetKeyState (k) & 0x8000) != 0;
  181247. }
  181248. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181249. {
  181250. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181251. return callback (userData);
  181252. else
  181253. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181254. }
  181255. class Win32ComponentPeer : public ComponentPeer
  181256. {
  181257. public:
  181258. Win32ComponentPeer (Component* const component,
  181259. const int windowStyleFlags)
  181260. : ComponentPeer (component, windowStyleFlags),
  181261. dontRepaint (false),
  181262. fullScreen (false),
  181263. isDragging (false),
  181264. isMouseOver (false),
  181265. hasCreatedCaret (false),
  181266. currentWindowIcon (0),
  181267. taskBarIcon (0),
  181268. dropTarget (0)
  181269. {
  181270. callFunctionIfNotLocked (&createWindowCallback, this);
  181271. setTitle (component->getName());
  181272. if ((windowStyleFlags & windowHasDropShadow) != 0
  181273. && Desktop::canUseSemiTransparentWindows())
  181274. {
  181275. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181276. if (shadower != 0)
  181277. shadower->setOwner (component);
  181278. }
  181279. else
  181280. {
  181281. shadower = 0;
  181282. }
  181283. }
  181284. ~Win32ComponentPeer()
  181285. {
  181286. setTaskBarIcon (0);
  181287. deleteAndZero (shadower);
  181288. // do this before the next bit to avoid messages arriving for this window
  181289. // before it's destroyed
  181290. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181291. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181292. if (currentWindowIcon != 0)
  181293. DestroyIcon (currentWindowIcon);
  181294. if (dropTarget != 0)
  181295. {
  181296. dropTarget->Release();
  181297. dropTarget = 0;
  181298. }
  181299. }
  181300. void* getNativeHandle() const
  181301. {
  181302. return hwnd;
  181303. }
  181304. void setVisible (bool shouldBeVisible)
  181305. {
  181306. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181307. if (shouldBeVisible)
  181308. InvalidateRect (hwnd, 0, 0);
  181309. else
  181310. lastPaintTime = 0;
  181311. }
  181312. void setTitle (const String& title)
  181313. {
  181314. SetWindowText (hwnd, title);
  181315. }
  181316. void setPosition (int x, int y)
  181317. {
  181318. offsetWithinParent (x, y);
  181319. SetWindowPos (hwnd, 0,
  181320. x - windowBorder.getLeft(),
  181321. y - windowBorder.getTop(),
  181322. 0, 0,
  181323. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181324. }
  181325. void repaintNowIfTransparent()
  181326. {
  181327. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181328. handlePaintMessage();
  181329. }
  181330. void updateBorderSize()
  181331. {
  181332. WINDOWINFO info;
  181333. info.cbSize = sizeof (info);
  181334. if (GetWindowInfo (hwnd, &info))
  181335. {
  181336. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181337. info.rcClient.left - info.rcWindow.left,
  181338. info.rcWindow.bottom - info.rcClient.bottom,
  181339. info.rcWindow.right - info.rcClient.right);
  181340. }
  181341. }
  181342. void setSize (int w, int h)
  181343. {
  181344. SetWindowPos (hwnd, 0, 0, 0,
  181345. w + windowBorder.getLeftAndRight(),
  181346. h + windowBorder.getTopAndBottom(),
  181347. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181348. updateBorderSize();
  181349. repaintNowIfTransparent();
  181350. }
  181351. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  181352. {
  181353. fullScreen = isNowFullScreen;
  181354. offsetWithinParent (x, y);
  181355. SetWindowPos (hwnd, 0,
  181356. x - windowBorder.getLeft(),
  181357. y - windowBorder.getTop(),
  181358. w + windowBorder.getLeftAndRight(),
  181359. h + windowBorder.getTopAndBottom(),
  181360. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181361. updateBorderSize();
  181362. repaintNowIfTransparent();
  181363. }
  181364. const Rectangle<int> getBounds() const
  181365. {
  181366. RECT r;
  181367. GetWindowRect (hwnd, &r);
  181368. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181369. HWND parentH = GetParent (hwnd);
  181370. if (parentH != 0)
  181371. {
  181372. GetWindowRect (parentH, &r);
  181373. bounds.translate (-r.left, -r.top);
  181374. }
  181375. return windowBorder.subtractedFrom (bounds);
  181376. }
  181377. const Point<int> getScreenPosition() const
  181378. {
  181379. RECT r;
  181380. GetWindowRect (hwnd, &r);
  181381. return Point<int> (r.left + windowBorder.getLeft(),
  181382. r.top + windowBorder.getTop());
  181383. }
  181384. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181385. {
  181386. return relativePosition + getScreenPosition();
  181387. }
  181388. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181389. {
  181390. return screenPosition - getScreenPosition();
  181391. }
  181392. void setMinimised (bool shouldBeMinimised)
  181393. {
  181394. if (shouldBeMinimised != isMinimised())
  181395. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181396. }
  181397. bool isMinimised() const
  181398. {
  181399. WINDOWPLACEMENT wp;
  181400. wp.length = sizeof (WINDOWPLACEMENT);
  181401. GetWindowPlacement (hwnd, &wp);
  181402. return wp.showCmd == SW_SHOWMINIMIZED;
  181403. }
  181404. void setFullScreen (bool shouldBeFullScreen)
  181405. {
  181406. setMinimised (false);
  181407. if (fullScreen != shouldBeFullScreen)
  181408. {
  181409. fullScreen = shouldBeFullScreen;
  181410. const Component::SafePointer<Component> deletionChecker (component);
  181411. if (! fullScreen)
  181412. {
  181413. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181414. if (hasTitleBar())
  181415. ShowWindow (hwnd, SW_SHOWNORMAL);
  181416. if (! boundsCopy.isEmpty())
  181417. {
  181418. setBounds (boundsCopy.getX(),
  181419. boundsCopy.getY(),
  181420. boundsCopy.getWidth(),
  181421. boundsCopy.getHeight(),
  181422. false);
  181423. }
  181424. }
  181425. else
  181426. {
  181427. if (hasTitleBar())
  181428. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181429. else
  181430. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181431. }
  181432. if (deletionChecker != 0)
  181433. handleMovedOrResized();
  181434. }
  181435. }
  181436. bool isFullScreen() const
  181437. {
  181438. if (! hasTitleBar())
  181439. return fullScreen;
  181440. WINDOWPLACEMENT wp;
  181441. wp.length = sizeof (wp);
  181442. GetWindowPlacement (hwnd, &wp);
  181443. return wp.showCmd == SW_SHOWMAXIMIZED;
  181444. }
  181445. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181446. {
  181447. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181448. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181449. return false;
  181450. RECT r;
  181451. GetWindowRect (hwnd, &r);
  181452. POINT p;
  181453. p.x = position.getX() + r.left + windowBorder.getLeft();
  181454. p.y = position.getY() + r.top + windowBorder.getTop();
  181455. HWND w = WindowFromPoint (p);
  181456. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181457. }
  181458. const BorderSize getFrameSize() const
  181459. {
  181460. return windowBorder;
  181461. }
  181462. bool setAlwaysOnTop (bool alwaysOnTop)
  181463. {
  181464. const bool oldDeactivate = shouldDeactivateTitleBar;
  181465. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181466. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181467. 0, 0, 0, 0,
  181468. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181469. shouldDeactivateTitleBar = oldDeactivate;
  181470. if (shadower != 0)
  181471. shadower->componentBroughtToFront (*component);
  181472. return true;
  181473. }
  181474. void toFront (bool makeActive)
  181475. {
  181476. setMinimised (false);
  181477. const bool oldDeactivate = shouldDeactivateTitleBar;
  181478. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181479. callFunctionIfNotLocked (makeActive ? &toFrontCallback1 : &toFrontCallback2, hwnd);
  181480. shouldDeactivateTitleBar = oldDeactivate;
  181481. if (! makeActive)
  181482. {
  181483. // in this case a broughttofront call won't have occured, so do it now..
  181484. handleBroughtToFront();
  181485. }
  181486. }
  181487. void toBehind (ComponentPeer* other)
  181488. {
  181489. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181490. jassert (otherPeer != 0); // wrong type of window?
  181491. if (otherPeer != 0)
  181492. {
  181493. setMinimised (false);
  181494. // must be careful not to try to put a topmost window behind a normal one, or win32
  181495. // promotes the normal one to be topmost!
  181496. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181497. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181498. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181499. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181500. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181501. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181502. }
  181503. }
  181504. bool isFocused() const
  181505. {
  181506. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181507. }
  181508. void grabFocus()
  181509. {
  181510. const bool oldDeactivate = shouldDeactivateTitleBar;
  181511. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181512. callFunctionIfNotLocked (&setFocusCallback, hwnd);
  181513. shouldDeactivateTitleBar = oldDeactivate;
  181514. }
  181515. void textInputRequired (const Point<int>&)
  181516. {
  181517. if (! hasCreatedCaret)
  181518. {
  181519. hasCreatedCaret = true;
  181520. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181521. }
  181522. ShowCaret (hwnd);
  181523. SetCaretPos (0, 0);
  181524. }
  181525. void repaint (int x, int y, int w, int h)
  181526. {
  181527. const RECT r = { x, y, x + w, y + h };
  181528. InvalidateRect (hwnd, &r, FALSE);
  181529. }
  181530. void performAnyPendingRepaintsNow()
  181531. {
  181532. MSG m;
  181533. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181534. DispatchMessage (&m);
  181535. }
  181536. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181537. {
  181538. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181539. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181540. return 0;
  181541. }
  181542. void setTaskBarIcon (const Image* const image)
  181543. {
  181544. if (image != 0)
  181545. {
  181546. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181547. if (taskBarIcon == 0)
  181548. {
  181549. taskBarIcon = new NOTIFYICONDATA();
  181550. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181551. taskBarIcon->hWnd = (HWND) hwnd;
  181552. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181553. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181554. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181555. taskBarIcon->hIcon = hicon;
  181556. taskBarIcon->szTip[0] = 0;
  181557. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181558. }
  181559. else
  181560. {
  181561. HICON oldIcon = taskBarIcon->hIcon;
  181562. taskBarIcon->hIcon = hicon;
  181563. taskBarIcon->uFlags = NIF_ICON;
  181564. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181565. DestroyIcon (oldIcon);
  181566. }
  181567. DestroyIcon (hicon);
  181568. }
  181569. else if (taskBarIcon != 0)
  181570. {
  181571. taskBarIcon->uFlags = 0;
  181572. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181573. DestroyIcon (taskBarIcon->hIcon);
  181574. deleteAndZero (taskBarIcon);
  181575. }
  181576. }
  181577. void setTaskBarIconToolTip (const String& toolTip) const
  181578. {
  181579. if (taskBarIcon != 0)
  181580. {
  181581. taskBarIcon->uFlags = NIF_TIP;
  181582. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181583. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181584. }
  181585. }
  181586. bool isInside (HWND h) const
  181587. {
  181588. return GetAncestor (hwnd, GA_ROOT) == h;
  181589. }
  181590. static void updateKeyModifiers() throw()
  181591. {
  181592. int keyMods = 0;
  181593. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181594. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181595. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181596. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181597. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181598. }
  181599. static void updateModifiersFromWParam (const WPARAM wParam)
  181600. {
  181601. int mouseMods = 0;
  181602. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181603. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181604. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181605. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181606. updateKeyModifiers();
  181607. }
  181608. static int64 getMouseEventTime()
  181609. {
  181610. static int64 eventTimeOffset = 0;
  181611. static DWORD lastMessageTime = 0;
  181612. const DWORD thisMessageTime = GetMessageTime();
  181613. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181614. {
  181615. lastMessageTime = thisMessageTime;
  181616. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181617. }
  181618. return eventTimeOffset + thisMessageTime;
  181619. }
  181620. juce_UseDebuggingNewOperator
  181621. bool dontRepaint;
  181622. static ModifierKeys currentModifiers;
  181623. static ModifierKeys modifiersAtLastCallback;
  181624. private:
  181625. HWND hwnd;
  181626. DropShadower* shadower;
  181627. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181628. BorderSize windowBorder;
  181629. HICON currentWindowIcon;
  181630. NOTIFYICONDATA* taskBarIcon;
  181631. IDropTarget* dropTarget;
  181632. class TemporaryImage : public Timer
  181633. {
  181634. public:
  181635. TemporaryImage() {}
  181636. ~TemporaryImage() {}
  181637. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181638. {
  181639. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181640. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181641. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181642. startTimer (3000);
  181643. return image;
  181644. }
  181645. void timerCallback()
  181646. {
  181647. stopTimer();
  181648. image = 0;
  181649. }
  181650. private:
  181651. ScopedPointer <WindowsBitmapImage> image;
  181652. TemporaryImage (const TemporaryImage&);
  181653. TemporaryImage& operator= (const TemporaryImage&);
  181654. };
  181655. TemporaryImage offscreenImageGenerator;
  181656. class WindowClassHolder : public DeletedAtShutdown
  181657. {
  181658. public:
  181659. WindowClassHolder()
  181660. : windowClassName ("JUCE_")
  181661. {
  181662. // this name has to be different for each app/dll instance because otherwise
  181663. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181664. // window class).
  181665. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  181666. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181667. TCHAR moduleFile [1024];
  181668. moduleFile[0] = 0;
  181669. GetModuleFileName (moduleHandle, moduleFile, 1024);
  181670. WORD iconNum = 0;
  181671. WNDCLASSEX wcex;
  181672. wcex.cbSize = sizeof (wcex);
  181673. wcex.style = CS_OWNDC;
  181674. wcex.lpfnWndProc = (WNDPROC) windowProc;
  181675. wcex.lpszClassName = windowClassName;
  181676. wcex.cbClsExtra = 0;
  181677. wcex.cbWndExtra = 32;
  181678. wcex.hInstance = moduleHandle;
  181679. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181680. iconNum = 1;
  181681. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181682. wcex.hCursor = 0;
  181683. wcex.hbrBackground = 0;
  181684. wcex.lpszMenuName = 0;
  181685. RegisterClassEx (&wcex);
  181686. }
  181687. ~WindowClassHolder()
  181688. {
  181689. if (ComponentPeer::getNumPeers() == 0)
  181690. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  181691. clearSingletonInstance();
  181692. }
  181693. String windowClassName;
  181694. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  181695. };
  181696. static void* createWindowCallback (void* userData)
  181697. {
  181698. static_cast <Win32ComponentPeer*> (userData)->createWindow();
  181699. return 0;
  181700. }
  181701. void createWindow()
  181702. {
  181703. DWORD exstyle = WS_EX_ACCEPTFILES;
  181704. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  181705. if (hasTitleBar())
  181706. {
  181707. type |= WS_OVERLAPPED;
  181708. exstyle |= WS_EX_APPWINDOW;
  181709. if ((styleFlags & windowHasCloseButton) != 0)
  181710. {
  181711. type |= WS_SYSMENU;
  181712. }
  181713. else
  181714. {
  181715. // annoyingly, windows won't let you have a min/max button without a close button
  181716. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  181717. }
  181718. if ((styleFlags & windowIsResizable) != 0)
  181719. type |= WS_THICKFRAME;
  181720. }
  181721. else
  181722. {
  181723. type |= WS_POPUP | WS_SYSMENU;
  181724. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  181725. exstyle |= WS_EX_TOOLWINDOW;
  181726. else
  181727. exstyle |= WS_EX_APPWINDOW;
  181728. }
  181729. if ((styleFlags & windowHasMinimiseButton) != 0)
  181730. type |= WS_MINIMIZEBOX;
  181731. if ((styleFlags & windowHasMaximiseButton) != 0)
  181732. type |= WS_MAXIMIZEBOX;
  181733. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  181734. exstyle |= WS_EX_TRANSPARENT;
  181735. if ((styleFlags & windowIsSemiTransparent) != 0
  181736. && Desktop::canUseSemiTransparentWindows())
  181737. exstyle |= WS_EX_LAYERED;
  181738. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  181739. if (hwnd != 0)
  181740. {
  181741. SetWindowLongPtr (hwnd, 0, 0);
  181742. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  181743. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  181744. if (dropTarget == 0)
  181745. dropTarget = new JuceDropTarget (this);
  181746. RegisterDragDrop (hwnd, dropTarget);
  181747. updateBorderSize();
  181748. // Calling this function here is (for some reason) necessary to make Windows
  181749. // correctly enable the menu items that we specify in the wm_initmenu message.
  181750. GetSystemMenu (hwnd, false);
  181751. }
  181752. else
  181753. {
  181754. jassertfalse
  181755. }
  181756. }
  181757. static void* destroyWindowCallback (void* handle)
  181758. {
  181759. RevokeDragDrop ((HWND) handle);
  181760. DestroyWindow ((HWND) handle);
  181761. return 0;
  181762. }
  181763. static void* toFrontCallback1 (void* h)
  181764. {
  181765. SetForegroundWindow ((HWND) h);
  181766. return 0;
  181767. }
  181768. static void* toFrontCallback2 (void* h)
  181769. {
  181770. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181771. return 0;
  181772. }
  181773. static void* setFocusCallback (void* h)
  181774. {
  181775. SetFocus ((HWND) h);
  181776. return 0;
  181777. }
  181778. static void* getFocusCallback (void*)
  181779. {
  181780. return GetFocus();
  181781. }
  181782. void offsetWithinParent (int& x, int& y) const
  181783. {
  181784. if (isTransparent())
  181785. {
  181786. HWND parentHwnd = GetParent (hwnd);
  181787. if (parentHwnd != 0)
  181788. {
  181789. RECT parentRect;
  181790. GetWindowRect (parentHwnd, &parentRect);
  181791. x += parentRect.left;
  181792. y += parentRect.top;
  181793. }
  181794. }
  181795. }
  181796. bool isTransparent() const
  181797. {
  181798. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  181799. }
  181800. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  181801. void setIcon (const Image& newIcon)
  181802. {
  181803. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  181804. if (hicon != 0)
  181805. {
  181806. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  181807. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  181808. if (currentWindowIcon != 0)
  181809. DestroyIcon (currentWindowIcon);
  181810. currentWindowIcon = hicon;
  181811. }
  181812. }
  181813. void handlePaintMessage()
  181814. {
  181815. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  181816. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  181817. PAINTSTRUCT paintStruct;
  181818. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  181819. // message and become re-entrant, but that's OK
  181820. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  181821. // corrupt the image it's using to paint into, so do a check here.
  181822. static bool reentrant = false;
  181823. if (reentrant)
  181824. {
  181825. DeleteObject (rgn);
  181826. EndPaint (hwnd, &paintStruct);
  181827. return;
  181828. }
  181829. reentrant = true;
  181830. // this is the rectangle to update..
  181831. int x = paintStruct.rcPaint.left;
  181832. int y = paintStruct.rcPaint.top;
  181833. int w = paintStruct.rcPaint.right - x;
  181834. int h = paintStruct.rcPaint.bottom - y;
  181835. const bool transparent = isTransparent();
  181836. if (transparent)
  181837. {
  181838. // it's not possible to have a transparent window with a title bar at the moment!
  181839. jassert (! hasTitleBar());
  181840. RECT r;
  181841. GetWindowRect (hwnd, &r);
  181842. x = y = 0;
  181843. w = r.right - r.left;
  181844. h = r.bottom - r.top;
  181845. }
  181846. if (w > 0 && h > 0)
  181847. {
  181848. clearMaskedRegion();
  181849. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  181850. RectangleList contextClip;
  181851. bool needToPaintAll = true;
  181852. if (regionType == COMPLEXREGION && ! transparent)
  181853. {
  181854. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  181855. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  181856. DeleteObject (clipRgn);
  181857. char rgnData [8192];
  181858. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  181859. if (res > 0 && res <= sizeof (rgnData))
  181860. {
  181861. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  181862. if (hdr->iType == RDH_RECTANGLES
  181863. && hdr->rcBound.right - hdr->rcBound.left >= w
  181864. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  181865. {
  181866. needToPaintAll = false;
  181867. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  181868. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  181869. while (--num >= 0)
  181870. {
  181871. // (need to move this one pixel to the left because of a win32 bug)
  181872. const int cx = jmax (x, (int) rects->left - 1);
  181873. const int cy = rects->top;
  181874. const int cw = rects->right - cx;
  181875. const int ch = rects->bottom - rects->top;
  181876. if (cx + cw - x <= w && cy + ch - y <= h)
  181877. {
  181878. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  181879. }
  181880. else
  181881. {
  181882. needToPaintAll = true;
  181883. break;
  181884. }
  181885. ++rects;
  181886. }
  181887. }
  181888. }
  181889. }
  181890. if (needToPaintAll)
  181891. {
  181892. contextClip.clear();
  181893. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  181894. }
  181895. if (transparent)
  181896. {
  181897. RectangleList::Iterator i (contextClip);
  181898. while (i.next())
  181899. {
  181900. const Rectangle<int>& r = *i.getRectangle();
  181901. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  181902. }
  181903. }
  181904. // if the component's not opaque, this won't draw properly unless the platform can support this
  181905. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  181906. updateCurrentModifiers();
  181907. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  181908. context.clipToRectangleList (contextClip);
  181909. context.setOrigin (-x, -y);
  181910. handlePaint (context);
  181911. if (! dontRepaint)
  181912. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  181913. }
  181914. DeleteObject (rgn);
  181915. EndPaint (hwnd, &paintStruct);
  181916. reentrant = false;
  181917. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  181918. _fpreset(); // because some graphics cards can unmask FP exceptions
  181919. #endif
  181920. lastPaintTime = Time::getMillisecondCounter();
  181921. }
  181922. void doMouseEvent (const Point<int>& position)
  181923. {
  181924. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  181925. }
  181926. void doMouseMove (const Point<int>& position)
  181927. {
  181928. if (! isMouseOver)
  181929. {
  181930. isMouseOver = true;
  181931. updateKeyModifiers();
  181932. TRACKMOUSEEVENT tme;
  181933. tme.cbSize = sizeof (tme);
  181934. tme.dwFlags = TME_LEAVE;
  181935. tme.hwndTrack = hwnd;
  181936. tme.dwHoverTime = 0;
  181937. if (! TrackMouseEvent (&tme))
  181938. jassertfalse;
  181939. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  181940. }
  181941. else if (! isDragging)
  181942. {
  181943. if (! contains (position, false))
  181944. return;
  181945. }
  181946. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  181947. static uint32 lastMouseTime = 0;
  181948. const uint32 now = Time::getMillisecondCounter();
  181949. const int maxMouseMovesPerSecond = 60;
  181950. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  181951. {
  181952. lastMouseTime = now;
  181953. doMouseEvent (position);
  181954. }
  181955. }
  181956. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  181957. {
  181958. if (GetCapture() != hwnd)
  181959. SetCapture (hwnd);
  181960. doMouseMove (position);
  181961. updateModifiersFromWParam (wParam);
  181962. isDragging = true;
  181963. doMouseEvent (position);
  181964. }
  181965. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  181966. {
  181967. updateModifiersFromWParam (wParam);
  181968. isDragging = false;
  181969. // release the mouse capture if the user has released all buttons
  181970. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  181971. ReleaseCapture();
  181972. doMouseEvent (position);
  181973. }
  181974. void doCaptureChanged()
  181975. {
  181976. if (isDragging)
  181977. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  181978. }
  181979. void doMouseExit()
  181980. {
  181981. isMouseOver = false;
  181982. doMouseEvent (getCurrentMousePos());
  181983. }
  181984. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  181985. {
  181986. updateKeyModifiers();
  181987. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  181988. handleMouseWheel (0, position, getMouseEventTime(),
  181989. isVertical ? 0.0f : amount,
  181990. isVertical ? amount : 0.0f);
  181991. }
  181992. void sendModifierKeyChangeIfNeeded()
  181993. {
  181994. if (modifiersAtLastCallback != currentModifiers)
  181995. {
  181996. modifiersAtLastCallback = currentModifiers;
  181997. handleModifierKeysChange();
  181998. }
  181999. }
  182000. bool doKeyUp (const WPARAM key)
  182001. {
  182002. updateKeyModifiers();
  182003. switch (key)
  182004. {
  182005. case VK_SHIFT:
  182006. case VK_CONTROL:
  182007. case VK_MENU:
  182008. case VK_CAPITAL:
  182009. case VK_LWIN:
  182010. case VK_RWIN:
  182011. case VK_APPS:
  182012. case VK_NUMLOCK:
  182013. case VK_SCROLL:
  182014. case VK_LSHIFT:
  182015. case VK_RSHIFT:
  182016. case VK_LCONTROL:
  182017. case VK_LMENU:
  182018. case VK_RCONTROL:
  182019. case VK_RMENU:
  182020. sendModifierKeyChangeIfNeeded();
  182021. }
  182022. return handleKeyUpOrDown (false)
  182023. || Component::getCurrentlyModalComponent() != 0;
  182024. }
  182025. bool doKeyDown (const WPARAM key)
  182026. {
  182027. updateKeyModifiers();
  182028. bool used = false;
  182029. switch (key)
  182030. {
  182031. case VK_SHIFT:
  182032. case VK_LSHIFT:
  182033. case VK_RSHIFT:
  182034. case VK_CONTROL:
  182035. case VK_LCONTROL:
  182036. case VK_RCONTROL:
  182037. case VK_MENU:
  182038. case VK_LMENU:
  182039. case VK_RMENU:
  182040. case VK_LWIN:
  182041. case VK_RWIN:
  182042. case VK_CAPITAL:
  182043. case VK_NUMLOCK:
  182044. case VK_SCROLL:
  182045. case VK_APPS:
  182046. sendModifierKeyChangeIfNeeded();
  182047. break;
  182048. case VK_LEFT:
  182049. case VK_RIGHT:
  182050. case VK_UP:
  182051. case VK_DOWN:
  182052. case VK_PRIOR:
  182053. case VK_NEXT:
  182054. case VK_HOME:
  182055. case VK_END:
  182056. case VK_DELETE:
  182057. case VK_INSERT:
  182058. case VK_F1:
  182059. case VK_F2:
  182060. case VK_F3:
  182061. case VK_F4:
  182062. case VK_F5:
  182063. case VK_F6:
  182064. case VK_F7:
  182065. case VK_F8:
  182066. case VK_F9:
  182067. case VK_F10:
  182068. case VK_F11:
  182069. case VK_F12:
  182070. case VK_F13:
  182071. case VK_F14:
  182072. case VK_F15:
  182073. case VK_F16:
  182074. used = handleKeyUpOrDown (true);
  182075. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182076. break;
  182077. case VK_ADD:
  182078. case VK_SUBTRACT:
  182079. case VK_MULTIPLY:
  182080. case VK_DIVIDE:
  182081. case VK_SEPARATOR:
  182082. case VK_DECIMAL:
  182083. used = handleKeyUpOrDown (true);
  182084. break;
  182085. default:
  182086. used = handleKeyUpOrDown (true);
  182087. {
  182088. MSG msg;
  182089. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182090. {
  182091. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182092. // manually generate the key-press event that matches this key-down.
  182093. const UINT keyChar = MapVirtualKey (key, 2);
  182094. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182095. }
  182096. }
  182097. break;
  182098. }
  182099. if (Component::getCurrentlyModalComponent() != 0)
  182100. used = true;
  182101. return used;
  182102. }
  182103. bool doKeyChar (int key, const LPARAM flags)
  182104. {
  182105. updateKeyModifiers();
  182106. juce_wchar textChar = (juce_wchar) key;
  182107. const int virtualScanCode = (flags >> 16) & 0xff;
  182108. if (key >= '0' && key <= '9')
  182109. {
  182110. switch (virtualScanCode) // check for a numeric keypad scan-code
  182111. {
  182112. case 0x52:
  182113. case 0x4f:
  182114. case 0x50:
  182115. case 0x51:
  182116. case 0x4b:
  182117. case 0x4c:
  182118. case 0x4d:
  182119. case 0x47:
  182120. case 0x48:
  182121. case 0x49:
  182122. key = (key - '0') + KeyPress::numberPad0;
  182123. break;
  182124. default:
  182125. break;
  182126. }
  182127. }
  182128. else
  182129. {
  182130. // convert the scan code to an unmodified character code..
  182131. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182132. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182133. keyChar = LOWORD (keyChar);
  182134. if (keyChar != 0)
  182135. key = (int) keyChar;
  182136. // avoid sending junk text characters for some control-key combinations
  182137. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182138. textChar = 0;
  182139. }
  182140. return handleKeyPress (key, textChar);
  182141. }
  182142. bool doAppCommand (const LPARAM lParam)
  182143. {
  182144. int key = 0;
  182145. switch (GET_APPCOMMAND_LPARAM (lParam))
  182146. {
  182147. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182148. key = KeyPress::playKey;
  182149. break;
  182150. case APPCOMMAND_MEDIA_STOP:
  182151. key = KeyPress::stopKey;
  182152. break;
  182153. case APPCOMMAND_MEDIA_NEXTTRACK:
  182154. key = KeyPress::fastForwardKey;
  182155. break;
  182156. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182157. key = KeyPress::rewindKey;
  182158. break;
  182159. }
  182160. if (key != 0)
  182161. {
  182162. updateKeyModifiers();
  182163. if (hwnd == GetActiveWindow())
  182164. {
  182165. handleKeyPress (key, 0);
  182166. return true;
  182167. }
  182168. }
  182169. return false;
  182170. }
  182171. class JuceDropTarget : public ComBaseClassHelper <IDropTarget>
  182172. {
  182173. public:
  182174. JuceDropTarget (Win32ComponentPeer* const owner_)
  182175. : owner (owner_)
  182176. {
  182177. }
  182178. ~JuceDropTarget() {}
  182179. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182180. {
  182181. updateFileList (pDataObject);
  182182. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182183. *pdwEffect = DROPEFFECT_COPY;
  182184. return S_OK;
  182185. }
  182186. HRESULT __stdcall DragLeave()
  182187. {
  182188. owner->handleFileDragExit (files);
  182189. return S_OK;
  182190. }
  182191. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182192. {
  182193. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182194. *pdwEffect = DROPEFFECT_COPY;
  182195. return S_OK;
  182196. }
  182197. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182198. {
  182199. updateFileList (pDataObject);
  182200. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182201. *pdwEffect = DROPEFFECT_COPY;
  182202. return S_OK;
  182203. }
  182204. private:
  182205. Win32ComponentPeer* const owner;
  182206. StringArray files;
  182207. void updateFileList (IDataObject* const pDataObject)
  182208. {
  182209. files.clear();
  182210. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182211. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182212. if (pDataObject->GetData (&format, &medium) == S_OK)
  182213. {
  182214. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182215. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182216. unsigned int i = 0;
  182217. if (pDropFiles->fWide)
  182218. {
  182219. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182220. for (;;)
  182221. {
  182222. unsigned int len = 0;
  182223. while (i + len < totalLen && fname [i + len] != 0)
  182224. ++len;
  182225. if (len == 0)
  182226. break;
  182227. files.add (String (fname + i, len));
  182228. i += len + 1;
  182229. }
  182230. }
  182231. else
  182232. {
  182233. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182234. for (;;)
  182235. {
  182236. unsigned int len = 0;
  182237. while (i + len < totalLen && fname [i + len] != 0)
  182238. ++len;
  182239. if (len == 0)
  182240. break;
  182241. files.add (String (fname + i, len));
  182242. i += len + 1;
  182243. }
  182244. }
  182245. GlobalUnlock (medium.hGlobal);
  182246. }
  182247. }
  182248. JuceDropTarget (const JuceDropTarget&);
  182249. JuceDropTarget& operator= (const JuceDropTarget&);
  182250. };
  182251. void doSettingChange()
  182252. {
  182253. Desktop::getInstance().refreshMonitorSizes();
  182254. if (fullScreen && ! isMinimised())
  182255. {
  182256. const Rectangle<int> r (component->getParentMonitorArea());
  182257. SetWindowPos (hwnd, 0,
  182258. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182259. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182260. }
  182261. }
  182262. public:
  182263. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182264. {
  182265. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182266. if (peer != 0)
  182267. return peer->peerWindowProc (h, message, wParam, lParam);
  182268. return DefWindowProcW (h, message, wParam, lParam);
  182269. }
  182270. private:
  182271. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182272. {
  182273. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182274. }
  182275. const Point<int> getCurrentMousePos() throw()
  182276. {
  182277. RECT wr;
  182278. GetWindowRect (hwnd, &wr);
  182279. const DWORD mp = GetMessagePos();
  182280. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182281. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182282. }
  182283. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182284. {
  182285. if (isValidPeer (this))
  182286. {
  182287. switch (message)
  182288. {
  182289. case WM_NCHITTEST:
  182290. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182291. return HTTRANSPARENT;
  182292. if (hasTitleBar())
  182293. break;
  182294. return HTCLIENT;
  182295. case WM_PAINT:
  182296. handlePaintMessage();
  182297. return 0;
  182298. case WM_NCPAINT:
  182299. if (wParam != 1)
  182300. handlePaintMessage();
  182301. if (hasTitleBar())
  182302. break;
  182303. return 0;
  182304. case WM_ERASEBKGND:
  182305. case WM_NCCALCSIZE:
  182306. if (hasTitleBar())
  182307. break;
  182308. return 1;
  182309. case WM_MOUSEMOVE:
  182310. doMouseMove (getPointFromLParam (lParam));
  182311. return 0;
  182312. case WM_MOUSELEAVE:
  182313. doMouseExit();
  182314. return 0;
  182315. case WM_LBUTTONDOWN:
  182316. case WM_MBUTTONDOWN:
  182317. case WM_RBUTTONDOWN:
  182318. doMouseDown (getPointFromLParam (lParam), wParam);
  182319. return 0;
  182320. case WM_LBUTTONUP:
  182321. case WM_MBUTTONUP:
  182322. case WM_RBUTTONUP:
  182323. doMouseUp (getPointFromLParam (lParam), wParam);
  182324. return 0;
  182325. case WM_CAPTURECHANGED:
  182326. doCaptureChanged();
  182327. return 0;
  182328. case WM_NCMOUSEMOVE:
  182329. if (hasTitleBar())
  182330. break;
  182331. return 0;
  182332. case 0x020A: /* WM_MOUSEWHEEL */
  182333. doMouseWheel (getCurrentMousePos(), wParam, true);
  182334. return 0;
  182335. case 0x020E: /* WM_MOUSEHWHEEL */
  182336. doMouseWheel (getCurrentMousePos(), wParam, false);
  182337. return 0;
  182338. case WM_WINDOWPOSCHANGING:
  182339. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182340. {
  182341. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182342. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182343. {
  182344. if (constrainer != 0)
  182345. {
  182346. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182347. component->getY() - windowBorder.getTop(),
  182348. component->getWidth() + windowBorder.getLeftAndRight(),
  182349. component->getHeight() + windowBorder.getTopAndBottom());
  182350. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182351. constrainer->checkBounds (pos, current,
  182352. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182353. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182354. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182355. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182356. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182357. wp->x = pos.getX();
  182358. wp->y = pos.getY();
  182359. wp->cx = pos.getWidth();
  182360. wp->cy = pos.getHeight();
  182361. }
  182362. }
  182363. }
  182364. return 0;
  182365. case WM_WINDOWPOSCHANGED:
  182366. handleMovedOrResized();
  182367. if (dontRepaint)
  182368. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182369. return 0;
  182370. case WM_KEYDOWN:
  182371. case WM_SYSKEYDOWN:
  182372. if (doKeyDown (wParam))
  182373. return 0;
  182374. break;
  182375. case WM_KEYUP:
  182376. case WM_SYSKEYUP:
  182377. if (doKeyUp (wParam))
  182378. return 0;
  182379. break;
  182380. case WM_CHAR:
  182381. if (doKeyChar ((int) wParam, lParam))
  182382. return 0;
  182383. break;
  182384. case WM_APPCOMMAND:
  182385. if (doAppCommand (lParam))
  182386. return TRUE;
  182387. break;
  182388. case WM_SETFOCUS:
  182389. updateKeyModifiers();
  182390. handleFocusGain();
  182391. break;
  182392. case WM_KILLFOCUS:
  182393. if (hasCreatedCaret)
  182394. {
  182395. hasCreatedCaret = false;
  182396. DestroyCaret();
  182397. }
  182398. handleFocusLoss();
  182399. break;
  182400. case WM_ACTIVATEAPP:
  182401. // Windows does weird things to process priority when you swap apps,
  182402. // so this forces an update when the app is brought to the front
  182403. if (wParam != FALSE)
  182404. juce_repeatLastProcessPriority();
  182405. else
  182406. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182407. juce_CheckCurrentlyFocusedTopLevelWindow();
  182408. modifiersAtLastCallback = -1;
  182409. return 0;
  182410. case WM_ACTIVATE:
  182411. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182412. {
  182413. modifiersAtLastCallback = -1;
  182414. updateKeyModifiers();
  182415. if (isMinimised())
  182416. {
  182417. component->repaint();
  182418. handleMovedOrResized();
  182419. if (! ComponentPeer::isValidPeer (this))
  182420. return 0;
  182421. }
  182422. if (LOWORD (wParam) == WA_CLICKACTIVE
  182423. && component->isCurrentlyBlockedByAnotherModalComponent())
  182424. {
  182425. const Point<int> mousePos (component->getMouseXYRelative());
  182426. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182427. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182428. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182429. return 0;
  182430. }
  182431. handleBroughtToFront();
  182432. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182433. Component::getCurrentlyModalComponent()->toFront (true);
  182434. return 0;
  182435. }
  182436. break;
  182437. case WM_NCACTIVATE:
  182438. // while a temporary window is being shown, prevent Windows from deactivating the
  182439. // title bars of our main windows.
  182440. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182441. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182442. break;
  182443. case WM_MOUSEACTIVATE:
  182444. if (! component->getMouseClickGrabsKeyboardFocus())
  182445. return MA_NOACTIVATE;
  182446. break;
  182447. case WM_SHOWWINDOW:
  182448. if (wParam != 0)
  182449. handleBroughtToFront();
  182450. break;
  182451. case WM_CLOSE:
  182452. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182453. handleUserClosingWindow();
  182454. return 0;
  182455. case WM_QUERYENDSESSION:
  182456. if (JUCEApplication::getInstance() != 0)
  182457. {
  182458. JUCEApplication::getInstance()->systemRequestedQuit();
  182459. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182460. }
  182461. return TRUE;
  182462. case WM_TRAYNOTIFY:
  182463. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182464. {
  182465. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182466. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182467. {
  182468. Component* const current = Component::getCurrentlyModalComponent();
  182469. if (current != 0)
  182470. current->inputAttemptWhenModal();
  182471. }
  182472. }
  182473. else
  182474. {
  182475. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182476. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182477. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182478. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182479. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182480. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182481. eventMods = eventMods.withoutMouseButtons();
  182482. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182483. Point<int>(), eventMods, component, getMouseEventTime(),
  182484. Point<int>(), getMouseEventTime(), 1, false);
  182485. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182486. {
  182487. SetFocus (hwnd);
  182488. SetForegroundWindow (hwnd);
  182489. component->mouseDown (e);
  182490. }
  182491. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182492. {
  182493. component->mouseUp (e);
  182494. }
  182495. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182496. {
  182497. component->mouseDoubleClick (e);
  182498. }
  182499. else if (lParam == WM_MOUSEMOVE)
  182500. {
  182501. component->mouseMove (e);
  182502. }
  182503. }
  182504. break;
  182505. case WM_SYNCPAINT:
  182506. return 0;
  182507. case WM_PALETTECHANGED:
  182508. InvalidateRect (h, 0, 0);
  182509. break;
  182510. case WM_DISPLAYCHANGE:
  182511. InvalidateRect (h, 0, 0);
  182512. createPaletteIfNeeded = true;
  182513. // intentional fall-through...
  182514. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182515. doSettingChange();
  182516. break;
  182517. case WM_INITMENU:
  182518. if (! hasTitleBar())
  182519. {
  182520. if (isFullScreen())
  182521. {
  182522. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182523. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182524. }
  182525. else if (! isMinimised())
  182526. {
  182527. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182528. }
  182529. }
  182530. break;
  182531. case WM_SYSCOMMAND:
  182532. switch (wParam & 0xfff0)
  182533. {
  182534. case SC_CLOSE:
  182535. if (sendInputAttemptWhenModalMessage())
  182536. return 0;
  182537. if (hasTitleBar())
  182538. {
  182539. PostMessage (h, WM_CLOSE, 0, 0);
  182540. return 0;
  182541. }
  182542. break;
  182543. case SC_KEYMENU:
  182544. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182545. // obscure situations that can arise if a modal loop is started from an alt-key
  182546. // keypress).
  182547. if (hasTitleBar() && h == GetCapture())
  182548. ReleaseCapture();
  182549. break;
  182550. case SC_MAXIMIZE:
  182551. if (sendInputAttemptWhenModalMessage())
  182552. return 0;
  182553. setFullScreen (true);
  182554. return 0;
  182555. case SC_MINIMIZE:
  182556. if (sendInputAttemptWhenModalMessage())
  182557. return 0;
  182558. if (! hasTitleBar())
  182559. {
  182560. setMinimised (true);
  182561. return 0;
  182562. }
  182563. break;
  182564. case SC_RESTORE:
  182565. if (sendInputAttemptWhenModalMessage())
  182566. return 0;
  182567. if (hasTitleBar())
  182568. {
  182569. if (isFullScreen())
  182570. {
  182571. setFullScreen (false);
  182572. return 0;
  182573. }
  182574. }
  182575. else
  182576. {
  182577. if (isMinimised())
  182578. setMinimised (false);
  182579. else if (isFullScreen())
  182580. setFullScreen (false);
  182581. return 0;
  182582. }
  182583. break;
  182584. }
  182585. break;
  182586. case WM_NCLBUTTONDOWN:
  182587. case WM_NCRBUTTONDOWN:
  182588. case WM_NCMBUTTONDOWN:
  182589. sendInputAttemptWhenModalMessage();
  182590. break;
  182591. //case WM_IME_STARTCOMPOSITION;
  182592. // return 0;
  182593. case WM_GETDLGCODE:
  182594. return DLGC_WANTALLKEYS;
  182595. default:
  182596. break;
  182597. }
  182598. }
  182599. return DefWindowProcW (h, message, wParam, lParam);
  182600. }
  182601. bool sendInputAttemptWhenModalMessage()
  182602. {
  182603. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182604. {
  182605. Component* const current = Component::getCurrentlyModalComponent();
  182606. if (current != 0)
  182607. current->inputAttemptWhenModal();
  182608. return true;
  182609. }
  182610. return false;
  182611. }
  182612. Win32ComponentPeer (const Win32ComponentPeer&);
  182613. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182614. };
  182615. ModifierKeys Win32ComponentPeer::currentModifiers;
  182616. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182617. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182618. {
  182619. return new Win32ComponentPeer (this, styleFlags);
  182620. }
  182621. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182622. void ModifierKeys::updateCurrentModifiers() throw()
  182623. {
  182624. currentModifiers = Win32ComponentPeer::currentModifiers;
  182625. }
  182626. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182627. {
  182628. Win32ComponentPeer::updateKeyModifiers();
  182629. int keyMods = 0;
  182630. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182631. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182632. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182633. Win32ComponentPeer::currentModifiers
  182634. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182635. return Win32ComponentPeer::currentModifiers;
  182636. }
  182637. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  182638. {
  182639. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182640. if (wp != 0)
  182641. wp->setTaskBarIcon (&newImage);
  182642. }
  182643. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  182644. {
  182645. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182646. if (wp != 0)
  182647. wp->setTaskBarIconToolTip (tooltip);
  182648. }
  182649. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  182650. {
  182651. DWORD val = GetWindowLong (h, styleType);
  182652. if (bitIsSet)
  182653. val |= feature;
  182654. else
  182655. val &= ~feature;
  182656. SetWindowLongPtr (h, styleType, val);
  182657. SetWindowPos (h, 0, 0, 0, 0, 0,
  182658. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  182659. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  182660. }
  182661. bool Process::isForegroundProcess()
  182662. {
  182663. HWND fg = GetForegroundWindow();
  182664. if (fg == 0)
  182665. return true;
  182666. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  182667. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  182668. // have to see if any of our windows are children of the foreground window
  182669. fg = GetAncestor (fg, GA_ROOT);
  182670. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  182671. {
  182672. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  182673. if (wp != 0 && wp->isInside (fg))
  182674. return true;
  182675. }
  182676. return false;
  182677. }
  182678. bool AlertWindow::showNativeDialogBox (const String& title,
  182679. const String& bodyText,
  182680. bool isOkCancel)
  182681. {
  182682. return MessageBox (0, bodyText, title,
  182683. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  182684. : MB_OK)) == IDOK;
  182685. }
  182686. void Desktop::createMouseInputSources()
  182687. {
  182688. mouseSources.add (new MouseInputSource (0, true));
  182689. }
  182690. const Point<int> Desktop::getMousePosition()
  182691. {
  182692. POINT mousePos;
  182693. GetCursorPos (&mousePos);
  182694. return Point<int> (mousePos.x, mousePos.y);
  182695. }
  182696. void Desktop::setMousePosition (const Point<int>& newPosition)
  182697. {
  182698. SetCursorPos (newPosition.getX(), newPosition.getY());
  182699. }
  182700. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  182701. {
  182702. return new Image (format, imageWidth, imageHeight, clearImage);
  182703. }
  182704. class ScreenSaverDefeater : public Timer,
  182705. public DeletedAtShutdown
  182706. {
  182707. public:
  182708. ScreenSaverDefeater() throw()
  182709. {
  182710. startTimer (10000);
  182711. timerCallback();
  182712. }
  182713. ~ScreenSaverDefeater() {}
  182714. void timerCallback()
  182715. {
  182716. if (Process::isForegroundProcess())
  182717. {
  182718. // simulate a shift key getting pressed..
  182719. INPUT input[2];
  182720. input[0].type = INPUT_KEYBOARD;
  182721. input[0].ki.wVk = VK_SHIFT;
  182722. input[0].ki.dwFlags = 0;
  182723. input[0].ki.dwExtraInfo = 0;
  182724. input[1].type = INPUT_KEYBOARD;
  182725. input[1].ki.wVk = VK_SHIFT;
  182726. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  182727. input[1].ki.dwExtraInfo = 0;
  182728. SendInput (2, input, sizeof (INPUT));
  182729. }
  182730. }
  182731. };
  182732. static ScreenSaverDefeater* screenSaverDefeater = 0;
  182733. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  182734. {
  182735. if (isEnabled)
  182736. {
  182737. deleteAndZero (screenSaverDefeater);
  182738. }
  182739. else if (screenSaverDefeater == 0)
  182740. {
  182741. screenSaverDefeater = new ScreenSaverDefeater();
  182742. }
  182743. }
  182744. bool Desktop::isScreenSaverEnabled() throw()
  182745. {
  182746. return screenSaverDefeater == 0;
  182747. }
  182748. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  182749. {
  182750. if (enableOrDisable)
  182751. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  182752. }
  182753. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  182754. {
  182755. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  182756. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  182757. return TRUE;
  182758. }
  182759. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  182760. {
  182761. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  182762. // make sure the first in the list is the main monitor
  182763. for (int i = 1; i < monitorCoords.size(); ++i)
  182764. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  182765. monitorCoords.swap (i, 0);
  182766. if (monitorCoords.size() == 0)
  182767. {
  182768. RECT r;
  182769. GetWindowRect (GetDesktopWindow(), &r);
  182770. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  182771. }
  182772. if (clipToWorkArea)
  182773. {
  182774. // clip the main monitor to the active non-taskbar area
  182775. RECT r;
  182776. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  182777. Rectangle<int>& screen = monitorCoords.getReference (0);
  182778. screen.setPosition (jmax (screen.getX(), (int) r.left),
  182779. jmax (screen.getY(), (int) r.top));
  182780. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  182781. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  182782. }
  182783. }
  182784. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  182785. {
  182786. Image* im = 0;
  182787. if (bitmap != 0)
  182788. {
  182789. BITMAP bm;
  182790. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  182791. && bm.bmWidth > 0 && bm.bmHeight > 0)
  182792. {
  182793. HDC tempDC = GetDC (0);
  182794. HDC dc = CreateCompatibleDC (tempDC);
  182795. ReleaseDC (0, tempDC);
  182796. SelectObject (dc, bitmap);
  182797. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  182798. for (int y = bm.bmHeight; --y >= 0;)
  182799. {
  182800. for (int x = bm.bmWidth; --x >= 0;)
  182801. {
  182802. COLORREF col = GetPixel (dc, x, y);
  182803. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  182804. (uint8) GetGValue (col),
  182805. (uint8) GetBValue (col)));
  182806. }
  182807. }
  182808. DeleteDC (dc);
  182809. }
  182810. }
  182811. return im;
  182812. }
  182813. static Image* createImageFromHICON (HICON icon) throw()
  182814. {
  182815. ICONINFO info;
  182816. if (GetIconInfo (icon, &info))
  182817. {
  182818. ScopedPointer<Image> mask (createImageFromHBITMAP (info.hbmMask));
  182819. if (mask == 0)
  182820. return 0;
  182821. ScopedPointer<Image> image (createImageFromHBITMAP (info.hbmColor));
  182822. if (image == 0)
  182823. return mask.release();
  182824. for (int y = image->getHeight(); --y >= 0;)
  182825. {
  182826. for (int x = image->getWidth(); --x >= 0;)
  182827. {
  182828. const float brightness = mask->getPixelAt (x, y).getBrightness();
  182829. if (brightness > 0.0f)
  182830. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  182831. }
  182832. }
  182833. return image.release();
  182834. }
  182835. return 0;
  182836. }
  182837. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  182838. {
  182839. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  182840. ICONINFO info;
  182841. info.fIcon = isIcon;
  182842. info.xHotspot = hotspotX;
  182843. info.yHotspot = hotspotY;
  182844. info.hbmMask = mask;
  182845. HICON hi = 0;
  182846. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  182847. {
  182848. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  182849. Graphics g (bitmap);
  182850. g.drawImageAt (&image, 0, 0);
  182851. info.hbmColor = bitmap.hBitmap;
  182852. hi = CreateIconIndirect (&info);
  182853. }
  182854. else
  182855. {
  182856. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  182857. HDC colDC = CreateCompatibleDC (GetDC (0));
  182858. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  182859. SelectObject (colDC, colour);
  182860. SelectObject (alphaDC, mask);
  182861. for (int y = image.getHeight(); --y >= 0;)
  182862. {
  182863. for (int x = image.getWidth(); --x >= 0;)
  182864. {
  182865. const Colour c (image.getPixelAt (x, y));
  182866. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  182867. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  182868. }
  182869. }
  182870. DeleteDC (colDC);
  182871. DeleteDC (alphaDC);
  182872. info.hbmColor = colour;
  182873. hi = CreateIconIndirect (&info);
  182874. DeleteObject (colour);
  182875. }
  182876. DeleteObject (mask);
  182877. return hi;
  182878. }
  182879. Image* juce_createIconForFile (const File& file)
  182880. {
  182881. Image* image = 0;
  182882. WCHAR filename [1024];
  182883. file.getFullPathName().copyToUnicode (filename, 1023);
  182884. WORD iconNum = 0;
  182885. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  182886. filename, &iconNum);
  182887. if (icon != 0)
  182888. {
  182889. image = createImageFromHICON (icon);
  182890. DestroyIcon (icon);
  182891. }
  182892. return image;
  182893. }
  182894. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  182895. {
  182896. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  182897. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  182898. const Image* im = &image;
  182899. Image* newIm = 0;
  182900. if (image.getWidth() > maxW || image.getHeight() > maxH)
  182901. {
  182902. im = newIm = image.createCopy (maxW, maxH);
  182903. hotspotX = (hotspotX * maxW) / image.getWidth();
  182904. hotspotY = (hotspotY * maxH) / image.getHeight();
  182905. }
  182906. void* cursorH = 0;
  182907. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  182908. if (os == SystemStats::WinXP)
  182909. {
  182910. cursorH = createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  182911. }
  182912. else
  182913. {
  182914. const int stride = (maxW + 7) >> 3;
  182915. HeapBlock <uint8> andPlane, xorPlane;
  182916. andPlane.calloc (stride * maxH);
  182917. xorPlane.calloc (stride * maxH);
  182918. int index = 0;
  182919. for (int y = 0; y < maxH; ++y)
  182920. {
  182921. for (int x = 0; x < maxW; ++x)
  182922. {
  182923. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  182924. const Colour pixelColour (im->getPixelAt (x, y));
  182925. if (pixelColour.getAlpha() < 127)
  182926. andPlane [index + (x >> 3)] |= bit;
  182927. else if (pixelColour.getBrightness() >= 0.5f)
  182928. xorPlane [index + (x >> 3)] |= bit;
  182929. }
  182930. index += stride;
  182931. }
  182932. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  182933. }
  182934. delete newIm;
  182935. return cursorH;
  182936. }
  182937. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  182938. {
  182939. if (cursorHandle != 0 && ! isStandard)
  182940. DestroyCursor ((HCURSOR) cursorHandle);
  182941. }
  182942. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  182943. {
  182944. LPCTSTR cursorName = IDC_ARROW;
  182945. switch (type)
  182946. {
  182947. case MouseCursor::NormalCursor:
  182948. cursorName = IDC_ARROW;
  182949. break;
  182950. case MouseCursor::NoCursor:
  182951. return 0;
  182952. case MouseCursor::DraggingHandCursor:
  182953. {
  182954. static void* dragHandCursor = 0;
  182955. if (dragHandCursor == 0)
  182956. {
  182957. static const unsigned char dragHandData[] =
  182958. { 71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  182959. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, 132,117,151,116,132,146,248,60,209,138,
  182960. 98,22,203,114,34,236,37,52,77,217,247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  182961. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  182962. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  182963. }
  182964. return dragHandCursor;
  182965. }
  182966. case MouseCursor::WaitCursor:
  182967. cursorName = IDC_WAIT;
  182968. break;
  182969. case MouseCursor::IBeamCursor:
  182970. cursorName = IDC_IBEAM;
  182971. break;
  182972. case MouseCursor::PointingHandCursor:
  182973. cursorName = MAKEINTRESOURCE(32649);
  182974. break;
  182975. case MouseCursor::LeftRightResizeCursor:
  182976. case MouseCursor::LeftEdgeResizeCursor:
  182977. case MouseCursor::RightEdgeResizeCursor:
  182978. cursorName = IDC_SIZEWE;
  182979. break;
  182980. case MouseCursor::UpDownResizeCursor:
  182981. case MouseCursor::TopEdgeResizeCursor:
  182982. case MouseCursor::BottomEdgeResizeCursor:
  182983. cursorName = IDC_SIZENS;
  182984. break;
  182985. case MouseCursor::TopLeftCornerResizeCursor:
  182986. case MouseCursor::BottomRightCornerResizeCursor:
  182987. cursorName = IDC_SIZENWSE;
  182988. break;
  182989. case MouseCursor::TopRightCornerResizeCursor:
  182990. case MouseCursor::BottomLeftCornerResizeCursor:
  182991. cursorName = IDC_SIZENESW;
  182992. break;
  182993. case MouseCursor::UpDownLeftRightResizeCursor:
  182994. cursorName = IDC_SIZEALL;
  182995. break;
  182996. case MouseCursor::CrosshairCursor:
  182997. cursorName = IDC_CROSS;
  182998. break;
  182999. case MouseCursor::CopyingCursor:
  183000. // can't seem to find one of these in the win32 list..
  183001. break;
  183002. }
  183003. HCURSOR cursorH = LoadCursor (0, cursorName);
  183004. if (cursorH == 0)
  183005. cursorH = LoadCursor (0, IDC_ARROW);
  183006. return cursorH;
  183007. }
  183008. void MouseCursor::showInWindow (ComponentPeer*) const
  183009. {
  183010. SetCursor ((HCURSOR) getHandle());
  183011. }
  183012. void MouseCursor::showInAllWindows() const
  183013. {
  183014. showInWindow (0);
  183015. }
  183016. class JuceDropSource : public ComBaseClassHelper <IDropSource>
  183017. {
  183018. public:
  183019. JuceDropSource() {}
  183020. ~JuceDropSource() {}
  183021. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183022. {
  183023. if (escapePressed)
  183024. return DRAGDROP_S_CANCEL;
  183025. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183026. return DRAGDROP_S_DROP;
  183027. return S_OK;
  183028. }
  183029. HRESULT __stdcall GiveFeedback (DWORD)
  183030. {
  183031. return DRAGDROP_S_USEDEFAULTCURSORS;
  183032. }
  183033. };
  183034. class JuceEnumFormatEtc : public ComBaseClassHelper <IEnumFORMATETC>
  183035. {
  183036. public:
  183037. JuceEnumFormatEtc (const FORMATETC* const format_)
  183038. : format (format_),
  183039. index (0)
  183040. {
  183041. }
  183042. ~JuceEnumFormatEtc() {}
  183043. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183044. {
  183045. if (result == 0)
  183046. return E_POINTER;
  183047. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183048. newOne->index = index;
  183049. *result = newOne;
  183050. return S_OK;
  183051. }
  183052. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183053. {
  183054. if (pceltFetched != 0)
  183055. *pceltFetched = 0;
  183056. else if (celt != 1)
  183057. return S_FALSE;
  183058. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183059. {
  183060. copyFormatEtc (lpFormatEtc [0], *format);
  183061. ++index;
  183062. if (pceltFetched != 0)
  183063. *pceltFetched = 1;
  183064. return S_OK;
  183065. }
  183066. return S_FALSE;
  183067. }
  183068. HRESULT __stdcall Skip (ULONG celt)
  183069. {
  183070. if (index + (int) celt >= 1)
  183071. return S_FALSE;
  183072. index += celt;
  183073. return S_OK;
  183074. }
  183075. HRESULT __stdcall Reset()
  183076. {
  183077. index = 0;
  183078. return S_OK;
  183079. }
  183080. private:
  183081. const FORMATETC* const format;
  183082. int index;
  183083. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183084. {
  183085. dest = source;
  183086. if (source.ptd != 0)
  183087. {
  183088. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183089. *(dest.ptd) = *(source.ptd);
  183090. }
  183091. }
  183092. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183093. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183094. };
  183095. class JuceDataObject : public ComBaseClassHelper <IDataObject>
  183096. {
  183097. JuceDropSource* const dropSource;
  183098. const FORMATETC* const format;
  183099. const STGMEDIUM* const medium;
  183100. JuceDataObject (const JuceDataObject&);
  183101. JuceDataObject& operator= (const JuceDataObject&);
  183102. public:
  183103. JuceDataObject (JuceDropSource* const dropSource_,
  183104. const FORMATETC* const format_,
  183105. const STGMEDIUM* const medium_)
  183106. : dropSource (dropSource_),
  183107. format (format_),
  183108. medium (medium_)
  183109. {
  183110. }
  183111. virtual ~JuceDataObject()
  183112. {
  183113. jassert (refCount == 0);
  183114. }
  183115. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183116. {
  183117. if ((pFormatEtc->tymed & format->tymed) != 0
  183118. && pFormatEtc->cfFormat == format->cfFormat
  183119. && pFormatEtc->dwAspect == format->dwAspect)
  183120. {
  183121. pMedium->tymed = format->tymed;
  183122. pMedium->pUnkForRelease = 0;
  183123. if (format->tymed == TYMED_HGLOBAL)
  183124. {
  183125. const SIZE_T len = GlobalSize (medium->hGlobal);
  183126. void* const src = GlobalLock (medium->hGlobal);
  183127. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183128. memcpy (dst, src, len);
  183129. GlobalUnlock (medium->hGlobal);
  183130. pMedium->hGlobal = dst;
  183131. return S_OK;
  183132. }
  183133. }
  183134. return DV_E_FORMATETC;
  183135. }
  183136. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183137. {
  183138. if (f == 0)
  183139. return E_INVALIDARG;
  183140. if (f->tymed == format->tymed
  183141. && f->cfFormat == format->cfFormat
  183142. && f->dwAspect == format->dwAspect)
  183143. return S_OK;
  183144. return DV_E_FORMATETC;
  183145. }
  183146. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183147. {
  183148. pFormatEtcOut->ptd = 0;
  183149. return E_NOTIMPL;
  183150. }
  183151. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183152. {
  183153. if (result == 0)
  183154. return E_POINTER;
  183155. if (direction == DATADIR_GET)
  183156. {
  183157. *result = new JuceEnumFormatEtc (format);
  183158. return S_OK;
  183159. }
  183160. *result = 0;
  183161. return E_NOTIMPL;
  183162. }
  183163. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183164. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183165. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183166. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183167. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183168. };
  183169. static HDROP createHDrop (const StringArray& fileNames) throw()
  183170. {
  183171. int totalChars = 0;
  183172. for (int i = fileNames.size(); --i >= 0;)
  183173. totalChars += fileNames[i].length() + 1;
  183174. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183175. sizeof (DROPFILES)
  183176. + sizeof (WCHAR) * (totalChars + 2));
  183177. if (hDrop != 0)
  183178. {
  183179. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183180. pDropFiles->pFiles = sizeof (DROPFILES);
  183181. pDropFiles->fWide = true;
  183182. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183183. for (int i = 0; i < fileNames.size(); ++i)
  183184. {
  183185. fileNames[i].copyToUnicode (fname, 2048);
  183186. fname += fileNames[i].length() + 1;
  183187. }
  183188. *fname = 0;
  183189. GlobalUnlock (hDrop);
  183190. }
  183191. return hDrop;
  183192. }
  183193. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183194. {
  183195. JuceDropSource* const source = new JuceDropSource();
  183196. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183197. DWORD effect;
  183198. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183199. data->Release();
  183200. source->Release();
  183201. return res == DRAGDROP_S_DROP;
  183202. }
  183203. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183204. {
  183205. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183206. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183207. medium.hGlobal = createHDrop (files);
  183208. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183209. : DROPEFFECT_COPY);
  183210. }
  183211. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183212. {
  183213. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183214. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183215. const int numChars = text.length();
  183216. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183217. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (medium.hGlobal));
  183218. text.copyToUnicode (data, numChars + 1);
  183219. format.cfFormat = CF_UNICODETEXT;
  183220. GlobalUnlock (medium.hGlobal);
  183221. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183222. }
  183223. #endif
  183224. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183225. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183226. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183227. // compiled on its own).
  183228. #if JUCE_INCLUDED_FILE
  183229. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183230. NEWTEXTMETRICEXW*,
  183231. int type,
  183232. LPARAM lParam)
  183233. {
  183234. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183235. {
  183236. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183237. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters ("@"));
  183238. }
  183239. return 1;
  183240. }
  183241. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183242. NEWTEXTMETRICEXW*,
  183243. int type,
  183244. LPARAM lParam)
  183245. {
  183246. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183247. {
  183248. LOGFONTW lf;
  183249. zerostruct (lf);
  183250. lf.lfWeight = FW_DONTCARE;
  183251. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183252. lf.lfQuality = DEFAULT_QUALITY;
  183253. lf.lfCharSet = DEFAULT_CHARSET;
  183254. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183255. lf.lfPitchAndFamily = FF_DONTCARE;
  183256. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183257. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183258. HDC dc = CreateCompatibleDC (0);
  183259. EnumFontFamiliesEx (dc, &lf,
  183260. (FONTENUMPROCW) &wfontEnum2,
  183261. lParam, 0);
  183262. DeleteDC (dc);
  183263. }
  183264. return 1;
  183265. }
  183266. const StringArray Font::findAllTypefaceNames()
  183267. {
  183268. StringArray results;
  183269. HDC dc = CreateCompatibleDC (0);
  183270. {
  183271. LOGFONTW lf;
  183272. zerostruct (lf);
  183273. lf.lfWeight = FW_DONTCARE;
  183274. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183275. lf.lfQuality = DEFAULT_QUALITY;
  183276. lf.lfCharSet = DEFAULT_CHARSET;
  183277. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183278. lf.lfPitchAndFamily = FF_DONTCARE;
  183279. lf.lfFaceName[0] = 0;
  183280. EnumFontFamiliesEx (dc, &lf,
  183281. (FONTENUMPROCW) &wfontEnum1,
  183282. (LPARAM) &results, 0);
  183283. }
  183284. DeleteDC (dc);
  183285. results.sort (true);
  183286. return results;
  183287. }
  183288. extern bool juce_IsRunningInWine();
  183289. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  183290. {
  183291. if (juce_IsRunningInWine())
  183292. {
  183293. // If we're running in Wine, then use fonts that might be available on Linux..
  183294. defaultSans = "Bitstream Vera Sans";
  183295. defaultSerif = "Bitstream Vera Serif";
  183296. defaultFixed = "Bitstream Vera Sans Mono";
  183297. }
  183298. else
  183299. {
  183300. defaultSans = "Verdana";
  183301. defaultSerif = "Times";
  183302. defaultFixed = "Lucida Console";
  183303. }
  183304. }
  183305. class FontDCHolder : private DeletedAtShutdown
  183306. {
  183307. public:
  183308. FontDCHolder() throw()
  183309. : dc (0), numKPs (0), size (0),
  183310. bold (false), italic (false)
  183311. {
  183312. }
  183313. ~FontDCHolder() throw()
  183314. {
  183315. if (dc != 0)
  183316. {
  183317. DeleteDC (dc);
  183318. DeleteObject (fontH);
  183319. }
  183320. clearSingletonInstance();
  183321. }
  183322. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183323. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183324. {
  183325. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183326. {
  183327. fontName = fontName_;
  183328. bold = bold_;
  183329. italic = italic_;
  183330. size = size_;
  183331. if (dc != 0)
  183332. {
  183333. DeleteDC (dc);
  183334. DeleteObject (fontH);
  183335. kps.free();
  183336. }
  183337. fontH = 0;
  183338. dc = CreateCompatibleDC (0);
  183339. SetMapperFlags (dc, 0);
  183340. SetMapMode (dc, MM_TEXT);
  183341. LOGFONTW lfw;
  183342. zerostruct (lfw);
  183343. lfw.lfCharSet = DEFAULT_CHARSET;
  183344. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183345. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183346. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183347. lfw.lfQuality = PROOF_QUALITY;
  183348. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183349. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183350. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183351. lfw.lfHeight = size > 0 ? size : -256;
  183352. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183353. if (standardSizedFont != 0)
  183354. {
  183355. if (SelectObject (dc, standardSizedFont) != 0)
  183356. {
  183357. fontH = standardSizedFont;
  183358. if (size == 0)
  183359. {
  183360. OUTLINETEXTMETRIC otm;
  183361. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183362. {
  183363. lfw.lfHeight = -(int) otm.otmEMSquare;
  183364. fontH = CreateFontIndirect (&lfw);
  183365. SelectObject (dc, fontH);
  183366. DeleteObject (standardSizedFont);
  183367. }
  183368. }
  183369. }
  183370. else
  183371. {
  183372. jassertfalse
  183373. }
  183374. }
  183375. else
  183376. {
  183377. jassertfalse
  183378. }
  183379. }
  183380. return dc;
  183381. }
  183382. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183383. {
  183384. if (kps == 0)
  183385. {
  183386. numKPs = GetKerningPairs (dc, 0, 0);
  183387. kps.calloc (numKPs);
  183388. GetKerningPairs (dc, numKPs, kps);
  183389. }
  183390. numKPs_ = numKPs;
  183391. return kps;
  183392. }
  183393. private:
  183394. HFONT fontH;
  183395. HDC dc;
  183396. String fontName;
  183397. HeapBlock <KERNINGPAIR> kps;
  183398. int numKPs, size;
  183399. bool bold, italic;
  183400. FontDCHolder (const FontDCHolder&);
  183401. FontDCHolder& operator= (const FontDCHolder&);
  183402. };
  183403. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183404. class WindowsTypeface : public CustomTypeface
  183405. {
  183406. public:
  183407. WindowsTypeface (const Font& font)
  183408. {
  183409. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183410. font.isBold(), font.isItalic(), 0);
  183411. TEXTMETRIC tm;
  183412. tm.tmAscent = tm.tmHeight = 1;
  183413. tm.tmDefaultChar = 0;
  183414. GetTextMetrics (dc, &tm);
  183415. setCharacteristics (font.getTypefaceName(),
  183416. tm.tmAscent / (float) tm.tmHeight,
  183417. font.isBold(), font.isItalic(),
  183418. tm.tmDefaultChar);
  183419. }
  183420. bool loadGlyphIfPossible (juce_wchar character)
  183421. {
  183422. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183423. GLYPHMETRICS gm;
  183424. {
  183425. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183426. WORD index = 0;
  183427. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183428. && index == 0xffff)
  183429. {
  183430. return false;
  183431. }
  183432. }
  183433. Path glyphPath;
  183434. TEXTMETRIC tm;
  183435. if (! GetTextMetrics (dc, &tm))
  183436. {
  183437. addGlyph (character, glyphPath, 0);
  183438. return true;
  183439. }
  183440. const float height = (float) tm.tmHeight;
  183441. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183442. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183443. &gm, 0, 0, &identityMatrix);
  183444. if (bufSize > 0)
  183445. {
  183446. HeapBlock<char> data (bufSize);
  183447. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183448. bufSize, data, &identityMatrix);
  183449. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183450. const float scaleX = 1.0f / height;
  183451. const float scaleY = -1.0f / height;
  183452. while ((char*) pheader < data + bufSize)
  183453. {
  183454. float x = scaleX * pheader->pfxStart.x.value;
  183455. float y = scaleY * pheader->pfxStart.y.value;
  183456. glyphPath.startNewSubPath (x, y);
  183457. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183458. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183459. while ((const char*) curve < curveEnd)
  183460. {
  183461. if (curve->wType == TT_PRIM_LINE)
  183462. {
  183463. for (int i = 0; i < curve->cpfx; ++i)
  183464. {
  183465. x = scaleX * curve->apfx[i].x.value;
  183466. y = scaleY * curve->apfx[i].y.value;
  183467. glyphPath.lineTo (x, y);
  183468. }
  183469. }
  183470. else if (curve->wType == TT_PRIM_QSPLINE)
  183471. {
  183472. for (int i = 0; i < curve->cpfx - 1; ++i)
  183473. {
  183474. const float x2 = scaleX * curve->apfx[i].x.value;
  183475. const float y2 = scaleY * curve->apfx[i].y.value;
  183476. float x3, y3;
  183477. if (i < curve->cpfx - 2)
  183478. {
  183479. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183480. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183481. }
  183482. else
  183483. {
  183484. x3 = scaleX * curve->apfx[i + 1].x.value;
  183485. y3 = scaleY * curve->apfx[i + 1].y.value;
  183486. }
  183487. glyphPath.quadraticTo (x2, y2, x3, y3);
  183488. x = x3;
  183489. y = y3;
  183490. }
  183491. }
  183492. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183493. }
  183494. pheader = (const TTPOLYGONHEADER*) curve;
  183495. glyphPath.closeSubPath();
  183496. }
  183497. }
  183498. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183499. int numKPs;
  183500. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183501. for (int i = 0; i < numKPs; ++i)
  183502. {
  183503. if (kps[i].wFirst == character)
  183504. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183505. kps[i].iKernAmount / height);
  183506. }
  183507. return true;
  183508. }
  183509. };
  183510. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183511. {
  183512. return new WindowsTypeface (font);
  183513. }
  183514. #endif
  183515. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183516. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183517. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183518. // compiled on its own).
  183519. #if JUCE_INCLUDED_FILE
  183520. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183521. namespace FileChooserHelpers
  183522. {
  183523. static const void* defaultDirPath = 0;
  183524. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183525. static Component* currentExtraFileWin = 0;
  183526. static bool areThereAnyAlwaysOnTopWindows()
  183527. {
  183528. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183529. {
  183530. Component* c = Desktop::getInstance().getComponent (i);
  183531. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183532. return true;
  183533. }
  183534. return false;
  183535. }
  183536. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183537. {
  183538. if (msg == BFFM_INITIALIZED)
  183539. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183540. else if (msg == BFFM_VALIDATEFAILEDW)
  183541. returnedString = (LPCWSTR) lParam;
  183542. else if (msg == BFFM_VALIDATEFAILEDA)
  183543. returnedString = (const char*) lParam;
  183544. return 0;
  183545. }
  183546. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183547. {
  183548. if (currentExtraFileWin != 0)
  183549. {
  183550. if (uiMsg == WM_INITDIALOG)
  183551. {
  183552. HWND dialogH = GetParent (hdlg);
  183553. jassert (dialogH != 0);
  183554. if (dialogH == 0)
  183555. dialogH = hdlg;
  183556. RECT r, cr;
  183557. GetWindowRect (dialogH, &r);
  183558. GetClientRect (dialogH, &cr);
  183559. SetWindowPos (dialogH, 0,
  183560. r.left, r.top,
  183561. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183562. jmax (150, (int) (r.bottom - r.top)),
  183563. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183564. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183565. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183566. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183567. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183568. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183569. }
  183570. else if (uiMsg == WM_NOTIFY)
  183571. {
  183572. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183573. if (ofn->hdr.code == CDN_SELCHANGE)
  183574. {
  183575. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183576. if (comp != 0)
  183577. {
  183578. TCHAR path [MAX_PATH * 2];
  183579. path[0] = 0;
  183580. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  183581. const String fn ((const WCHAR*) path);
  183582. comp->selectedFileChanged (File (fn));
  183583. }
  183584. }
  183585. }
  183586. }
  183587. return 0;
  183588. }
  183589. class FPComponentHolder : public Component
  183590. {
  183591. public:
  183592. FPComponentHolder()
  183593. {
  183594. setVisible (true);
  183595. setOpaque (true);
  183596. }
  183597. ~FPComponentHolder()
  183598. {
  183599. }
  183600. void paint (Graphics& g)
  183601. {
  183602. g.fillAll (Colours::lightgrey);
  183603. }
  183604. private:
  183605. FPComponentHolder (const FPComponentHolder&);
  183606. FPComponentHolder& operator= (const FPComponentHolder&);
  183607. };
  183608. }
  183609. void FileChooser::showPlatformDialog (Array<File>& results,
  183610. const String& title,
  183611. const File& currentFileOrDirectory,
  183612. const String& filter,
  183613. bool selectsDirectory,
  183614. bool /*selectsFiles*/,
  183615. bool isSaveDialogue,
  183616. bool warnAboutOverwritingExistingFiles,
  183617. bool selectMultipleFiles,
  183618. FilePreviewComponent* extraInfoComponent)
  183619. {
  183620. using namespace FileChooserHelpers;
  183621. const int numCharsAvailable = 32768;
  183622. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  183623. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  183624. int fnameIdx = 0;
  183625. JUCE_TRY
  183626. {
  183627. // use a modal window as the parent for this dialog box
  183628. // to block input from other app windows
  183629. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  183630. Component w (String::empty);
  183631. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  183632. mainMon.getY() + mainMon.getHeight() / 4,
  183633. 0, 0);
  183634. w.setOpaque (true);
  183635. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  183636. w.addToDesktop (0);
  183637. if (extraInfoComponent == 0)
  183638. w.enterModalState();
  183639. String initialDir;
  183640. if (currentFileOrDirectory.isDirectory())
  183641. {
  183642. initialDir = currentFileOrDirectory.getFullPathName();
  183643. }
  183644. else
  183645. {
  183646. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  183647. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  183648. }
  183649. if (currentExtraFileWin->isValidComponent())
  183650. {
  183651. jassertfalse
  183652. return;
  183653. }
  183654. if (selectsDirectory)
  183655. {
  183656. LPITEMIDLIST list = 0;
  183657. filenameSpace.fillWith (0);
  183658. {
  183659. BROWSEINFO bi;
  183660. zerostruct (bi);
  183661. bi.hwndOwner = (HWND) w.getWindowHandle();
  183662. bi.pszDisplayName = fname;
  183663. bi.lpszTitle = title;
  183664. bi.lpfn = browseCallbackProc;
  183665. #ifdef BIF_USENEWUI
  183666. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  183667. #else
  183668. bi.ulFlags = 0x50;
  183669. #endif
  183670. defaultDirPath = (const WCHAR*) initialDir;
  183671. list = SHBrowseForFolder (&bi);
  183672. if (! SHGetPathFromIDListW (list, fname))
  183673. {
  183674. fname[0] = 0;
  183675. returnedString = String::empty;
  183676. }
  183677. }
  183678. LPMALLOC al;
  183679. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  183680. al->Free (list);
  183681. defaultDirPath = 0;
  183682. if (returnedString.isNotEmpty())
  183683. {
  183684. const String stringFName (fname);
  183685. results.add (File (stringFName).getSiblingFile (returnedString));
  183686. returnedString = String::empty;
  183687. return;
  183688. }
  183689. }
  183690. else
  183691. {
  183692. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  183693. if (warnAboutOverwritingExistingFiles)
  183694. flags |= OFN_OVERWRITEPROMPT;
  183695. if (selectMultipleFiles)
  183696. flags |= OFN_ALLOWMULTISELECT;
  183697. if (extraInfoComponent != 0)
  183698. {
  183699. flags |= OFN_ENABLEHOOK;
  183700. currentExtraFileWin = new FPComponentHolder();
  183701. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  183702. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  183703. extraInfoComponent->getHeight());
  183704. currentExtraFileWin->addToDesktop (0);
  183705. currentExtraFileWin->enterModalState();
  183706. }
  183707. {
  183708. WCHAR filters [1024];
  183709. zeromem (filters, sizeof (filters));
  183710. filter.copyToUnicode (filters, 1024);
  183711. filter.copyToUnicode (filters + filter.length() + 1,
  183712. 1022 - filter.length());
  183713. OPENFILENAMEW of;
  183714. zerostruct (of);
  183715. #ifdef OPENFILENAME_SIZE_VERSION_400W
  183716. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  183717. #else
  183718. of.lStructSize = sizeof (of);
  183719. #endif
  183720. of.hwndOwner = (HWND) w.getWindowHandle();
  183721. of.lpstrFilter = filters;
  183722. of.nFilterIndex = 1;
  183723. of.lpstrFile = fname;
  183724. of.nMaxFile = numCharsAvailable;
  183725. of.lpstrInitialDir = initialDir;
  183726. of.lpstrTitle = title;
  183727. of.Flags = flags;
  183728. if (extraInfoComponent != 0)
  183729. of.lpfnHook = &openCallback;
  183730. if (isSaveDialogue)
  183731. {
  183732. if (! GetSaveFileName (&of))
  183733. fname[0] = 0;
  183734. else
  183735. fnameIdx = of.nFileOffset;
  183736. }
  183737. else
  183738. {
  183739. if (! GetOpenFileName (&of))
  183740. fname[0] = 0;
  183741. else
  183742. fnameIdx = of.nFileOffset;
  183743. }
  183744. }
  183745. }
  183746. }
  183747. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  183748. catch (...)
  183749. {
  183750. fname[0] = 0;
  183751. }
  183752. #endif
  183753. deleteAndZero (currentExtraFileWin);
  183754. const WCHAR* const files = fname;
  183755. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  183756. {
  183757. const WCHAR* filename = files + fnameIdx;
  183758. while (*filename != 0)
  183759. {
  183760. const String filepath (String (files) + "\\" + String (filename));
  183761. results.add (File (filepath));
  183762. filename += CharacterFunctions::length (filename) + 1;
  183763. }
  183764. }
  183765. else if (files[0] != 0)
  183766. {
  183767. results.add (File (files));
  183768. }
  183769. }
  183770. #endif
  183771. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  183772. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  183773. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183774. // compiled on its own).
  183775. #if JUCE_INCLUDED_FILE
  183776. void SystemClipboard::copyTextToClipboard (const String& text)
  183777. {
  183778. if (OpenClipboard (0) != 0)
  183779. {
  183780. if (EmptyClipboard() != 0)
  183781. {
  183782. const int len = text.length();
  183783. if (len > 0)
  183784. {
  183785. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  183786. (len + 1) * sizeof (wchar_t));
  183787. if (bufH != 0)
  183788. {
  183789. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (bufH));
  183790. text.copyToUnicode (data, len);
  183791. GlobalUnlock (bufH);
  183792. SetClipboardData (CF_UNICODETEXT, bufH);
  183793. }
  183794. }
  183795. }
  183796. CloseClipboard();
  183797. }
  183798. }
  183799. const String SystemClipboard::getTextFromClipboard()
  183800. {
  183801. String result;
  183802. if (OpenClipboard (0) != 0)
  183803. {
  183804. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  183805. if (bufH != 0)
  183806. {
  183807. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  183808. if (data != 0)
  183809. {
  183810. result = String (data, (int) (GlobalSize (bufH) / sizeof (wchar_t)));
  183811. GlobalUnlock (bufH);
  183812. }
  183813. }
  183814. CloseClipboard();
  183815. }
  183816. return result;
  183817. }
  183818. #endif
  183819. /*** End of inlined file: juce_win32_Misc.cpp ***/
  183820. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  183821. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183822. // compiled on its own).
  183823. #if JUCE_INCLUDED_FILE
  183824. namespace ActiveXHelpers
  183825. {
  183826. class JuceIStorage : public ComBaseClassHelper <IStorage>
  183827. {
  183828. public:
  183829. JuceIStorage() {}
  183830. ~JuceIStorage() {}
  183831. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  183832. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  183833. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  183834. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  183835. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  183836. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  183837. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  183838. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  183839. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  183840. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  183841. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  183842. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  183843. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  183844. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  183845. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  183846. juce_UseDebuggingNewOperator
  183847. };
  183848. class JuceOleInPlaceFrame : public ComBaseClassHelper <IOleInPlaceFrame>
  183849. {
  183850. HWND window;
  183851. public:
  183852. JuceOleInPlaceFrame (HWND window_) : window (window_) {}
  183853. ~JuceOleInPlaceFrame() {}
  183854. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  183855. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  183856. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  183857. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  183858. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  183859. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  183860. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  183861. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  183862. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  183863. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  183864. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  183865. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  183866. juce_UseDebuggingNewOperator
  183867. };
  183868. class JuceIOleInPlaceSite : public ComBaseClassHelper <IOleInPlaceSite>
  183869. {
  183870. HWND window;
  183871. JuceOleInPlaceFrame* frame;
  183872. public:
  183873. JuceIOleInPlaceSite (HWND window_)
  183874. : window (window_),
  183875. frame (new JuceOleInPlaceFrame (window))
  183876. {}
  183877. ~JuceIOleInPlaceSite()
  183878. {
  183879. frame->Release();
  183880. }
  183881. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  183882. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  183883. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  183884. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  183885. HRESULT __stdcall OnUIActivate() { return S_OK; }
  183886. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  183887. {
  183888. *lplpFrame = frame;
  183889. *lplpDoc = 0;
  183890. lpFrameInfo->fMDIApp = FALSE;
  183891. lpFrameInfo->hwndFrame = window;
  183892. lpFrameInfo->haccel = 0;
  183893. lpFrameInfo->cAccelEntries = 0;
  183894. return S_OK;
  183895. }
  183896. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  183897. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  183898. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  183899. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  183900. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  183901. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  183902. juce_UseDebuggingNewOperator
  183903. };
  183904. class JuceIOleClientSite : public ComBaseClassHelper <IOleClientSite>
  183905. {
  183906. JuceIOleInPlaceSite* inplaceSite;
  183907. public:
  183908. JuceIOleClientSite (HWND window)
  183909. : inplaceSite (new JuceIOleInPlaceSite (window))
  183910. {}
  183911. ~JuceIOleClientSite()
  183912. {
  183913. inplaceSite->Release();
  183914. }
  183915. HRESULT __stdcall QueryInterface (REFIID type, void __RPC_FAR* __RPC_FAR* result)
  183916. {
  183917. if (type == IID_IOleInPlaceSite)
  183918. {
  183919. inplaceSite->AddRef();
  183920. *result = static_cast <IOleInPlaceSite*> (inplaceSite);
  183921. return S_OK;
  183922. }
  183923. return ComBaseClassHelper <IOleClientSite>::QueryInterface (type, result);
  183924. }
  183925. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  183926. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  183927. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  183928. HRESULT __stdcall ShowObject() { return S_OK; }
  183929. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  183930. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  183931. juce_UseDebuggingNewOperator
  183932. };
  183933. static VoidArray activeXComps;
  183934. static HWND getHWND (const ActiveXControlComponent* const component)
  183935. {
  183936. HWND hwnd = 0;
  183937. const IID iid = IID_IOleWindow;
  183938. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  183939. if (window != 0)
  183940. {
  183941. window->GetWindow (&hwnd);
  183942. window->Release();
  183943. }
  183944. return hwnd;
  183945. }
  183946. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  183947. {
  183948. RECT activeXRect, peerRect;
  183949. GetWindowRect (hwnd, &activeXRect);
  183950. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  183951. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  183952. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  183953. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  183954. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  183955. switch (message)
  183956. {
  183957. case WM_MOUSEMOVE:
  183958. case WM_LBUTTONDOWN:
  183959. case WM_MBUTTONDOWN:
  183960. case WM_RBUTTONDOWN:
  183961. case WM_LBUTTONUP:
  183962. case WM_MBUTTONUP:
  183963. case WM_RBUTTONUP:
  183964. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  183965. break;
  183966. default:
  183967. break;
  183968. }
  183969. }
  183970. }
  183971. class ActiveXControlComponent::Pimpl : public ComponentMovementWatcher
  183972. {
  183973. ActiveXControlComponent* const owner;
  183974. bool wasShowing;
  183975. public:
  183976. HWND controlHWND;
  183977. IStorage* storage;
  183978. IOleClientSite* clientSite;
  183979. IOleObject* control;
  183980. Pimpl (HWND hwnd, ActiveXControlComponent* const owner_)
  183981. : ComponentMovementWatcher (owner_),
  183982. owner (owner_),
  183983. wasShowing (owner_ != 0 && owner_->isShowing()),
  183984. controlHWND (0),
  183985. storage (new ActiveXHelpers::JuceIStorage()),
  183986. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  183987. control (0)
  183988. {
  183989. }
  183990. ~Pimpl()
  183991. {
  183992. if (control != 0)
  183993. {
  183994. control->Close (OLECLOSE_NOSAVE);
  183995. control->Release();
  183996. }
  183997. clientSite->Release();
  183998. storage->Release();
  183999. }
  184000. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184001. {
  184002. Component* const topComp = owner->getTopLevelComponent();
  184003. if (topComp->getPeer() != 0)
  184004. {
  184005. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184006. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184007. }
  184008. }
  184009. void componentPeerChanged()
  184010. {
  184011. const bool isShowingNow = owner->isShowing();
  184012. if (wasShowing != isShowingNow)
  184013. {
  184014. wasShowing = isShowingNow;
  184015. owner->setControlVisible (isShowingNow);
  184016. }
  184017. componentMovedOrResized (true, true);
  184018. }
  184019. void componentVisibilityChanged (Component&)
  184020. {
  184021. componentPeerChanged();
  184022. }
  184023. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184024. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184025. {
  184026. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184027. {
  184028. const ActiveXControlComponent* const ax
  184029. = static_cast <const ActiveXControlComponent*> (ActiveXHelpers::activeXComps.getUnchecked(i));
  184030. if (ax->control != 0 && ax->control->controlHWND == hwnd)
  184031. {
  184032. switch (message)
  184033. {
  184034. case WM_MOUSEMOVE:
  184035. case WM_LBUTTONDOWN:
  184036. case WM_MBUTTONDOWN:
  184037. case WM_RBUTTONDOWN:
  184038. case WM_LBUTTONUP:
  184039. case WM_MBUTTONUP:
  184040. case WM_RBUTTONUP:
  184041. case WM_LBUTTONDBLCLK:
  184042. case WM_MBUTTONDBLCLK:
  184043. case WM_RBUTTONDBLCLK:
  184044. if (ax->isShowing())
  184045. {
  184046. ComponentPeer* const peer = ax->getPeer();
  184047. if (peer != 0)
  184048. {
  184049. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184050. if (! ax->areMouseEventsAllowed())
  184051. return 0;
  184052. }
  184053. }
  184054. break;
  184055. default:
  184056. break;
  184057. }
  184058. return CallWindowProc ((WNDPROC) ax->originalWndProc, hwnd, message, wParam, lParam);
  184059. }
  184060. }
  184061. return DefWindowProc (hwnd, message, wParam, lParam);
  184062. }
  184063. };
  184064. ActiveXControlComponent::ActiveXControlComponent()
  184065. : originalWndProc (0),
  184066. mouseEventsAllowed (true)
  184067. {
  184068. ActiveXHelpers::activeXComps.add (this);
  184069. }
  184070. ActiveXControlComponent::~ActiveXControlComponent()
  184071. {
  184072. deleteControl();
  184073. ActiveXHelpers::activeXComps.removeValue (this);
  184074. }
  184075. void ActiveXControlComponent::paint (Graphics& g)
  184076. {
  184077. if (control == 0)
  184078. g.fillAll (Colours::lightgrey);
  184079. }
  184080. bool ActiveXControlComponent::createControl (const void* controlIID)
  184081. {
  184082. deleteControl();
  184083. ComponentPeer* const peer = getPeer();
  184084. // the component must have already been added to a real window when you call this!
  184085. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184086. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184087. {
  184088. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184089. HWND hwnd = (HWND) peer->getNativeHandle();
  184090. ScopedPointer<Pimpl> newControl (new Pimpl (hwnd, this));
  184091. HRESULT hr;
  184092. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184093. newControl->clientSite, newControl->storage,
  184094. (void**) &(newControl->control))) == S_OK)
  184095. {
  184096. newControl->control->SetHostNames (L"Juce", 0);
  184097. if (OleSetContainedObject (newControl->control, TRUE) == S_OK)
  184098. {
  184099. RECT rect;
  184100. rect.left = pos.getX();
  184101. rect.top = pos.getY();
  184102. rect.right = pos.getX() + getWidth();
  184103. rect.bottom = pos.getY() + getHeight();
  184104. if (newControl->control->DoVerb (OLEIVERB_SHOW, 0, newControl->clientSite, 0, hwnd, &rect) == S_OK)
  184105. {
  184106. control = newControl;
  184107. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184108. control->controlHWND = ActiveXHelpers::getHWND (this);
  184109. if (control->controlHWND != 0)
  184110. {
  184111. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) control->controlHWND, GWLP_WNDPROC);
  184112. SetWindowLongPtr ((HWND) control->controlHWND, GWLP_WNDPROC, (LONG_PTR) Pimpl::activeXHookWndProc);
  184113. }
  184114. return true;
  184115. }
  184116. }
  184117. }
  184118. }
  184119. return false;
  184120. }
  184121. void ActiveXControlComponent::deleteControl()
  184122. {
  184123. control = 0;
  184124. originalWndProc = 0;
  184125. }
  184126. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184127. {
  184128. void* result = 0;
  184129. if (control != 0 && control->control != 0
  184130. && SUCCEEDED (control->control->QueryInterface (*(const IID*) iid, &result)))
  184131. return result;
  184132. return 0;
  184133. }
  184134. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184135. {
  184136. if (control->controlHWND != 0)
  184137. MoveWindow (control->controlHWND, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184138. }
  184139. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184140. {
  184141. if (control->controlHWND != 0)
  184142. ShowWindow (control->controlHWND, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184143. }
  184144. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184145. {
  184146. mouseEventsAllowed = eventsCanReachControl;
  184147. }
  184148. #endif
  184149. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184150. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184151. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184152. // compiled on its own).
  184153. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184154. using namespace QTOLibrary;
  184155. using namespace QTOControlLib;
  184156. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184157. static bool isQTAvailable = false;
  184158. class QuickTimeMovieComponent::Pimpl
  184159. {
  184160. public:
  184161. Pimpl() : dataHandle (0)
  184162. {
  184163. }
  184164. ~Pimpl()
  184165. {
  184166. clearHandle();
  184167. }
  184168. void clearHandle()
  184169. {
  184170. if (dataHandle != 0)
  184171. {
  184172. DisposeHandle (dataHandle);
  184173. dataHandle = 0;
  184174. }
  184175. }
  184176. IQTControlPtr qtControl;
  184177. IQTMoviePtr qtMovie;
  184178. Handle dataHandle;
  184179. };
  184180. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184181. : movieLoaded (false),
  184182. controllerVisible (true)
  184183. {
  184184. pimpl = new Pimpl();
  184185. setMouseEventsAllowed (false);
  184186. }
  184187. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184188. {
  184189. closeMovie();
  184190. pimpl->qtControl = 0;
  184191. deleteControl();
  184192. pimpl = 0;
  184193. }
  184194. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184195. {
  184196. if (! isQTAvailable)
  184197. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184198. return isQTAvailable;
  184199. }
  184200. void QuickTimeMovieComponent::createControlIfNeeded()
  184201. {
  184202. if (isShowing() && ! isControlCreated())
  184203. {
  184204. const IID qtIID = __uuidof (QTControl);
  184205. if (createControl (&qtIID))
  184206. {
  184207. const IID qtInterfaceIID = __uuidof (IQTControl);
  184208. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184209. if (pimpl->qtControl != 0)
  184210. {
  184211. pimpl->qtControl->Release(); // it has one ref too many at this point
  184212. pimpl->qtControl->QuickTimeInitialize();
  184213. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184214. if (movieFile != File::nonexistent)
  184215. loadMovie (movieFile, controllerVisible);
  184216. }
  184217. }
  184218. }
  184219. }
  184220. bool QuickTimeMovieComponent::isControlCreated() const
  184221. {
  184222. return isControlOpen();
  184223. }
  184224. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184225. const bool isControllerVisible)
  184226. {
  184227. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184228. movieFile = File::nonexistent;
  184229. movieLoaded = false;
  184230. pimpl->qtMovie = 0;
  184231. controllerVisible = isControllerVisible;
  184232. createControlIfNeeded();
  184233. if (isControlCreated())
  184234. {
  184235. if (pimpl->qtControl != 0)
  184236. {
  184237. pimpl->qtControl->Put_MovieHandle (0);
  184238. pimpl->clearHandle();
  184239. Movie movie;
  184240. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184241. {
  184242. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184243. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184244. if (pimpl->qtMovie != 0)
  184245. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184246. : qtMovieControllerTypeNone);
  184247. }
  184248. if (movie == 0)
  184249. pimpl->clearHandle();
  184250. }
  184251. movieLoaded = (pimpl->qtMovie != 0);
  184252. }
  184253. else
  184254. {
  184255. // You're trying to open a movie when the control hasn't yet been created, probably because
  184256. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184257. jassertfalse
  184258. }
  184259. return movieLoaded;
  184260. }
  184261. void QuickTimeMovieComponent::closeMovie()
  184262. {
  184263. stop();
  184264. movieFile = File::nonexistent;
  184265. movieLoaded = false;
  184266. pimpl->qtMovie = 0;
  184267. if (pimpl->qtControl != 0)
  184268. pimpl->qtControl->Put_MovieHandle (0);
  184269. pimpl->clearHandle();
  184270. }
  184271. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184272. {
  184273. return movieFile;
  184274. }
  184275. bool QuickTimeMovieComponent::isMovieOpen() const
  184276. {
  184277. return movieLoaded;
  184278. }
  184279. double QuickTimeMovieComponent::getMovieDuration() const
  184280. {
  184281. if (pimpl->qtMovie != 0)
  184282. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184283. return 0.0;
  184284. }
  184285. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184286. {
  184287. if (pimpl->qtMovie != 0)
  184288. {
  184289. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184290. width = r.right - r.left;
  184291. height = r.bottom - r.top;
  184292. }
  184293. else
  184294. {
  184295. width = height = 0;
  184296. }
  184297. }
  184298. void QuickTimeMovieComponent::play()
  184299. {
  184300. if (pimpl->qtMovie != 0)
  184301. pimpl->qtMovie->Play();
  184302. }
  184303. void QuickTimeMovieComponent::stop()
  184304. {
  184305. if (pimpl->qtMovie != 0)
  184306. pimpl->qtMovie->Stop();
  184307. }
  184308. bool QuickTimeMovieComponent::isPlaying() const
  184309. {
  184310. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184311. }
  184312. void QuickTimeMovieComponent::setPosition (const double seconds)
  184313. {
  184314. if (pimpl->qtMovie != 0)
  184315. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184316. }
  184317. double QuickTimeMovieComponent::getPosition() const
  184318. {
  184319. if (pimpl->qtMovie != 0)
  184320. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184321. return 0.0;
  184322. }
  184323. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184324. {
  184325. if (pimpl->qtMovie != 0)
  184326. pimpl->qtMovie->PutRate (newSpeed);
  184327. }
  184328. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184329. {
  184330. if (pimpl->qtMovie != 0)
  184331. {
  184332. pimpl->qtMovie->PutAudioVolume (newVolume);
  184333. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184334. }
  184335. }
  184336. float QuickTimeMovieComponent::getMovieVolume() const
  184337. {
  184338. if (pimpl->qtMovie != 0)
  184339. return pimpl->qtMovie->GetAudioVolume();
  184340. return 0.0f;
  184341. }
  184342. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184343. {
  184344. if (pimpl->qtMovie != 0)
  184345. pimpl->qtMovie->PutLoop (shouldLoop);
  184346. }
  184347. bool QuickTimeMovieComponent::isLooping() const
  184348. {
  184349. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184350. }
  184351. bool QuickTimeMovieComponent::isControllerVisible() const
  184352. {
  184353. return controllerVisible;
  184354. }
  184355. void QuickTimeMovieComponent::parentHierarchyChanged()
  184356. {
  184357. createControlIfNeeded();
  184358. QTCompBaseClass::parentHierarchyChanged();
  184359. }
  184360. void QuickTimeMovieComponent::visibilityChanged()
  184361. {
  184362. createControlIfNeeded();
  184363. QTCompBaseClass::visibilityChanged();
  184364. }
  184365. void QuickTimeMovieComponent::paint (Graphics& g)
  184366. {
  184367. if (! isControlCreated())
  184368. g.fillAll (Colours::black);
  184369. }
  184370. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184371. {
  184372. Handle dataRef = 0;
  184373. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184374. if (err == noErr)
  184375. {
  184376. Str255 suffix;
  184377. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184378. StringPtr name = suffix;
  184379. err = PtrAndHand (name, dataRef, name[0] + 1);
  184380. if (err == noErr)
  184381. {
  184382. long atoms[3];
  184383. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184384. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184385. atoms[2] = EndianU32_NtoB (MovieFileType);
  184386. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184387. if (err == noErr)
  184388. return dataRef;
  184389. }
  184390. DisposeHandle (dataRef);
  184391. }
  184392. return 0;
  184393. }
  184394. static CFStringRef juceStringToCFString (const String& s)
  184395. {
  184396. const int len = s.length();
  184397. const juce_wchar* const t = s;
  184398. HeapBlock <UniChar> temp (len + 2);
  184399. for (int i = 0; i <= len; ++i)
  184400. temp[i] = t[i];
  184401. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184402. }
  184403. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184404. {
  184405. Boolean trueBool = true;
  184406. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184407. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184408. props[prop].propValueSize = sizeof (trueBool);
  184409. props[prop].propValueAddress = &trueBool;
  184410. ++prop;
  184411. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184412. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184413. props[prop].propValueSize = sizeof (trueBool);
  184414. props[prop].propValueAddress = &trueBool;
  184415. ++prop;
  184416. Boolean isActive = true;
  184417. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184418. props[prop].propID = kQTNewMoviePropertyID_Active;
  184419. props[prop].propValueSize = sizeof (isActive);
  184420. props[prop].propValueAddress = &isActive;
  184421. ++prop;
  184422. MacSetPort (0);
  184423. jassert (prop <= 5);
  184424. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184425. return err == noErr;
  184426. }
  184427. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184428. {
  184429. if (input == 0)
  184430. return false;
  184431. dataHandle = 0;
  184432. bool ok = false;
  184433. QTNewMoviePropertyElement props[5];
  184434. zeromem (props, sizeof (props));
  184435. int prop = 0;
  184436. DataReferenceRecord dr;
  184437. props[prop].propClass = kQTPropertyClass_DataLocation;
  184438. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184439. props[prop].propValueSize = sizeof (dr);
  184440. props[prop].propValueAddress = &dr;
  184441. ++prop;
  184442. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184443. if (fin != 0)
  184444. {
  184445. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184446. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184447. &dr.dataRef, &dr.dataRefType);
  184448. ok = openMovie (props, prop, movie);
  184449. DisposeHandle (dr.dataRef);
  184450. CFRelease (filePath);
  184451. }
  184452. else
  184453. {
  184454. // sanity-check because this currently needs to load the whole stream into memory..
  184455. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184456. dataHandle = NewHandle ((Size) input->getTotalLength());
  184457. HLock (dataHandle);
  184458. // read the entire stream into memory - this is a pain, but can't get it to work
  184459. // properly using a custom callback to supply the data.
  184460. input->read (*dataHandle, (int) input->getTotalLength());
  184461. HUnlock (dataHandle);
  184462. // different types to get QT to try. (We should really be a bit smarter here by
  184463. // working out in advance which one the stream contains, rather than just trying
  184464. // each one)
  184465. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184466. "\04.avi", "\04.m4a" };
  184467. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184468. {
  184469. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184470. dr.dataRefType = HandleDataHandlerSubType;
  184471. ok = openMovie (props, prop, movie);
  184472. DisposeHandle (dr.dataRef);
  184473. }
  184474. }
  184475. return ok;
  184476. }
  184477. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184478. const bool isControllerVisible)
  184479. {
  184480. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184481. movieFile = movieFile_;
  184482. return ok;
  184483. }
  184484. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184485. const bool isControllerVisible)
  184486. {
  184487. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184488. }
  184489. void QuickTimeMovieComponent::goToStart()
  184490. {
  184491. setPosition (0.0);
  184492. }
  184493. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184494. const RectanglePlacement& placement)
  184495. {
  184496. int normalWidth, normalHeight;
  184497. getMovieNormalSize (normalWidth, normalHeight);
  184498. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  184499. {
  184500. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  184501. placement.applyTo (x, y, w, h,
  184502. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  184503. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  184504. if (w > 0 && h > 0)
  184505. {
  184506. setBounds (roundToInt (x), roundToInt (y),
  184507. roundToInt (w), roundToInt (h));
  184508. }
  184509. }
  184510. else
  184511. {
  184512. setBounds (spaceToFitWithin);
  184513. }
  184514. }
  184515. #endif
  184516. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184517. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184518. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184519. // compiled on its own).
  184520. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  184521. class WebBrowserComponentInternal : public ActiveXControlComponent
  184522. {
  184523. public:
  184524. WebBrowserComponentInternal()
  184525. : browser (0),
  184526. connectionPoint (0),
  184527. adviseCookie (0)
  184528. {
  184529. }
  184530. ~WebBrowserComponentInternal()
  184531. {
  184532. if (connectionPoint != 0)
  184533. connectionPoint->Unadvise (adviseCookie);
  184534. if (browser != 0)
  184535. browser->Release();
  184536. }
  184537. void createBrowser()
  184538. {
  184539. createControl (&CLSID_WebBrowser);
  184540. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  184541. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  184542. if (connectionPointContainer != 0)
  184543. {
  184544. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  184545. &connectionPoint);
  184546. if (connectionPoint != 0)
  184547. {
  184548. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  184549. jassert (owner != 0);
  184550. EventHandler* handler = new EventHandler (owner);
  184551. connectionPoint->Advise (handler, &adviseCookie);
  184552. handler->Release();
  184553. }
  184554. }
  184555. }
  184556. void goToURL (const String& url,
  184557. const StringArray* headers,
  184558. const MemoryBlock* postData)
  184559. {
  184560. if (browser != 0)
  184561. {
  184562. LPSAFEARRAY sa = 0;
  184563. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  184564. VariantInit (&flags);
  184565. VariantInit (&frame);
  184566. VariantInit (&postDataVar);
  184567. VariantInit (&headersVar);
  184568. if (headers != 0)
  184569. {
  184570. V_VT (&headersVar) = VT_BSTR;
  184571. V_BSTR (&headersVar) = SysAllocString ((const OLECHAR*) headers->joinIntoString ("\r\n"));
  184572. }
  184573. if (postData != 0 && postData->getSize() > 0)
  184574. {
  184575. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  184576. if (sa != 0)
  184577. {
  184578. void* data = 0;
  184579. SafeArrayAccessData (sa, &data);
  184580. jassert (data != 0);
  184581. if (data != 0)
  184582. {
  184583. postData->copyTo (data, 0, postData->getSize());
  184584. SafeArrayUnaccessData (sa);
  184585. VARIANT postDataVar2;
  184586. VariantInit (&postDataVar2);
  184587. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  184588. V_ARRAY (&postDataVar2) = sa;
  184589. postDataVar = postDataVar2;
  184590. }
  184591. }
  184592. }
  184593. browser->Navigate ((BSTR) (const OLECHAR*) url,
  184594. &flags, &frame,
  184595. &postDataVar, &headersVar);
  184596. if (sa != 0)
  184597. SafeArrayDestroy (sa);
  184598. VariantClear (&flags);
  184599. VariantClear (&frame);
  184600. VariantClear (&postDataVar);
  184601. VariantClear (&headersVar);
  184602. }
  184603. }
  184604. IWebBrowser2* browser;
  184605. juce_UseDebuggingNewOperator
  184606. private:
  184607. IConnectionPoint* connectionPoint;
  184608. DWORD adviseCookie;
  184609. class EventHandler : public ComBaseClassHelper <IDispatch>,
  184610. public ComponentMovementWatcher
  184611. {
  184612. public:
  184613. EventHandler (WebBrowserComponent* owner_)
  184614. : ComponentMovementWatcher (owner_),
  184615. owner (owner_)
  184616. {
  184617. }
  184618. ~EventHandler()
  184619. {
  184620. }
  184621. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  184622. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  184623. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  184624. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  184625. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  184626. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  184627. UINT __RPC_FAR* /*puArgErr*/)
  184628. {
  184629. switch (dispIdMember)
  184630. {
  184631. case DISPID_BEFORENAVIGATE2:
  184632. {
  184633. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  184634. String url;
  184635. if ((vurl->vt & VT_BYREF) != 0)
  184636. url = *vurl->pbstrVal;
  184637. else
  184638. url = vurl->bstrVal;
  184639. *pDispParams->rgvarg->pboolVal
  184640. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  184641. : VARIANT_TRUE;
  184642. return S_OK;
  184643. }
  184644. default:
  184645. break;
  184646. }
  184647. return E_NOTIMPL;
  184648. }
  184649. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  184650. void componentPeerChanged() {}
  184651. void componentVisibilityChanged (Component&)
  184652. {
  184653. owner->visibilityChanged();
  184654. }
  184655. juce_UseDebuggingNewOperator
  184656. private:
  184657. WebBrowserComponent* const owner;
  184658. EventHandler (const EventHandler&);
  184659. EventHandler& operator= (const EventHandler&);
  184660. };
  184661. };
  184662. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  184663. : browser (0),
  184664. blankPageShown (false),
  184665. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  184666. {
  184667. setOpaque (true);
  184668. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  184669. }
  184670. WebBrowserComponent::~WebBrowserComponent()
  184671. {
  184672. delete browser;
  184673. }
  184674. void WebBrowserComponent::goToURL (const String& url,
  184675. const StringArray* headers,
  184676. const MemoryBlock* postData)
  184677. {
  184678. lastURL = url;
  184679. lastHeaders.clear();
  184680. if (headers != 0)
  184681. lastHeaders = *headers;
  184682. lastPostData.setSize (0);
  184683. if (postData != 0)
  184684. lastPostData = *postData;
  184685. blankPageShown = false;
  184686. browser->goToURL (url, headers, postData);
  184687. }
  184688. void WebBrowserComponent::stop()
  184689. {
  184690. if (browser->browser != 0)
  184691. browser->browser->Stop();
  184692. }
  184693. void WebBrowserComponent::goBack()
  184694. {
  184695. lastURL = String::empty;
  184696. blankPageShown = false;
  184697. if (browser->browser != 0)
  184698. browser->browser->GoBack();
  184699. }
  184700. void WebBrowserComponent::goForward()
  184701. {
  184702. lastURL = String::empty;
  184703. if (browser->browser != 0)
  184704. browser->browser->GoForward();
  184705. }
  184706. void WebBrowserComponent::refresh()
  184707. {
  184708. if (browser->browser != 0)
  184709. browser->browser->Refresh();
  184710. }
  184711. void WebBrowserComponent::paint (Graphics& g)
  184712. {
  184713. if (browser->browser == 0)
  184714. g.fillAll (Colours::white);
  184715. }
  184716. void WebBrowserComponent::checkWindowAssociation()
  184717. {
  184718. if (isShowing())
  184719. {
  184720. if (browser->browser == 0 && getPeer() != 0)
  184721. {
  184722. browser->createBrowser();
  184723. reloadLastURL();
  184724. }
  184725. else
  184726. {
  184727. if (blankPageShown)
  184728. goBack();
  184729. }
  184730. }
  184731. else
  184732. {
  184733. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  184734. {
  184735. // when the component becomes invisible, some stuff like flash
  184736. // carries on playing audio, so we need to force it onto a blank
  184737. // page to avoid this..
  184738. blankPageShown = true;
  184739. browser->goToURL ("about:blank", 0, 0);
  184740. }
  184741. }
  184742. }
  184743. void WebBrowserComponent::reloadLastURL()
  184744. {
  184745. if (lastURL.isNotEmpty())
  184746. {
  184747. goToURL (lastURL, &lastHeaders, &lastPostData);
  184748. lastURL = String::empty;
  184749. }
  184750. }
  184751. void WebBrowserComponent::parentHierarchyChanged()
  184752. {
  184753. checkWindowAssociation();
  184754. }
  184755. void WebBrowserComponent::resized()
  184756. {
  184757. browser->setSize (getWidth(), getHeight());
  184758. }
  184759. void WebBrowserComponent::visibilityChanged()
  184760. {
  184761. checkWindowAssociation();
  184762. }
  184763. bool WebBrowserComponent::pageAboutToLoad (const String&)
  184764. {
  184765. return true;
  184766. }
  184767. #endif
  184768. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184769. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  184770. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184771. // compiled on its own).
  184772. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  184773. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  184774. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  184775. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  184776. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  184777. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  184778. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  184779. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  184780. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  184781. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  184782. #define WGL_ACCELERATION_ARB 0x2003
  184783. #define WGL_SWAP_METHOD_ARB 0x2007
  184784. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  184785. #define WGL_PIXEL_TYPE_ARB 0x2013
  184786. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  184787. #define WGL_COLOR_BITS_ARB 0x2014
  184788. #define WGL_RED_BITS_ARB 0x2015
  184789. #define WGL_GREEN_BITS_ARB 0x2017
  184790. #define WGL_BLUE_BITS_ARB 0x2019
  184791. #define WGL_ALPHA_BITS_ARB 0x201B
  184792. #define WGL_DEPTH_BITS_ARB 0x2022
  184793. #define WGL_STENCIL_BITS_ARB 0x2023
  184794. #define WGL_FULL_ACCELERATION_ARB 0x2027
  184795. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  184796. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  184797. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  184798. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  184799. #define WGL_STEREO_ARB 0x2012
  184800. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  184801. #define WGL_SAMPLES_ARB 0x2042
  184802. #define WGL_TYPE_RGBA_ARB 0x202B
  184803. static void getWglExtensions (HDC dc, StringArray& result) throw()
  184804. {
  184805. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  184806. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  184807. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  184808. else
  184809. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  184810. }
  184811. class WindowedGLContext : public OpenGLContext
  184812. {
  184813. public:
  184814. WindowedGLContext (Component* const component_,
  184815. HGLRC contextToShareWith,
  184816. const OpenGLPixelFormat& pixelFormat)
  184817. : renderContext (0),
  184818. nativeWindow (0),
  184819. dc (0),
  184820. component (component_)
  184821. {
  184822. jassert (component != 0);
  184823. createNativeWindow();
  184824. // Use a default pixel format that should be supported everywhere
  184825. PIXELFORMATDESCRIPTOR pfd;
  184826. zerostruct (pfd);
  184827. pfd.nSize = sizeof (pfd);
  184828. pfd.nVersion = 1;
  184829. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  184830. pfd.iPixelType = PFD_TYPE_RGBA;
  184831. pfd.cColorBits = 24;
  184832. pfd.cDepthBits = 16;
  184833. const int format = ChoosePixelFormat (dc, &pfd);
  184834. if (format != 0)
  184835. SetPixelFormat (dc, format, &pfd);
  184836. renderContext = wglCreateContext (dc);
  184837. makeActive();
  184838. setPixelFormat (pixelFormat);
  184839. if (contextToShareWith != 0 && renderContext != 0)
  184840. wglShareLists (contextToShareWith, renderContext);
  184841. }
  184842. ~WindowedGLContext()
  184843. {
  184844. makeInactive();
  184845. wglDeleteContext (renderContext);
  184846. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  184847. delete nativeWindow;
  184848. }
  184849. bool makeActive() const throw()
  184850. {
  184851. jassert (renderContext != 0);
  184852. return wglMakeCurrent (dc, renderContext) != 0;
  184853. }
  184854. bool makeInactive() const throw()
  184855. {
  184856. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  184857. }
  184858. bool isActive() const throw()
  184859. {
  184860. return wglGetCurrentContext() == renderContext;
  184861. }
  184862. const OpenGLPixelFormat getPixelFormat() const
  184863. {
  184864. OpenGLPixelFormat pf;
  184865. makeActive();
  184866. StringArray availableExtensions;
  184867. getWglExtensions (dc, availableExtensions);
  184868. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  184869. return pf;
  184870. }
  184871. void* getRawContext() const throw()
  184872. {
  184873. return renderContext;
  184874. }
  184875. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  184876. {
  184877. makeActive();
  184878. PIXELFORMATDESCRIPTOR pfd;
  184879. zerostruct (pfd);
  184880. pfd.nSize = sizeof (pfd);
  184881. pfd.nVersion = 1;
  184882. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  184883. pfd.iPixelType = PFD_TYPE_RGBA;
  184884. pfd.iLayerType = PFD_MAIN_PLANE;
  184885. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  184886. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  184887. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  184888. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  184889. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  184890. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  184891. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  184892. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  184893. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  184894. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  184895. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  184896. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  184897. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  184898. int format = 0;
  184899. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  184900. StringArray availableExtensions;
  184901. getWglExtensions (dc, availableExtensions);
  184902. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  184903. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  184904. {
  184905. int attributes[64];
  184906. int n = 0;
  184907. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  184908. attributes[n++] = GL_TRUE;
  184909. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  184910. attributes[n++] = GL_TRUE;
  184911. attributes[n++] = WGL_ACCELERATION_ARB;
  184912. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  184913. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  184914. attributes[n++] = GL_TRUE;
  184915. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  184916. attributes[n++] = WGL_TYPE_RGBA_ARB;
  184917. attributes[n++] = WGL_COLOR_BITS_ARB;
  184918. attributes[n++] = pfd.cColorBits;
  184919. attributes[n++] = WGL_RED_BITS_ARB;
  184920. attributes[n++] = pixelFormat.redBits;
  184921. attributes[n++] = WGL_GREEN_BITS_ARB;
  184922. attributes[n++] = pixelFormat.greenBits;
  184923. attributes[n++] = WGL_BLUE_BITS_ARB;
  184924. attributes[n++] = pixelFormat.blueBits;
  184925. attributes[n++] = WGL_ALPHA_BITS_ARB;
  184926. attributes[n++] = pixelFormat.alphaBits;
  184927. attributes[n++] = WGL_DEPTH_BITS_ARB;
  184928. attributes[n++] = pixelFormat.depthBufferBits;
  184929. if (pixelFormat.stencilBufferBits > 0)
  184930. {
  184931. attributes[n++] = WGL_STENCIL_BITS_ARB;
  184932. attributes[n++] = pixelFormat.stencilBufferBits;
  184933. }
  184934. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  184935. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  184936. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  184937. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  184938. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  184939. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  184940. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  184941. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  184942. if (availableExtensions.contains ("WGL_ARB_multisample")
  184943. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  184944. {
  184945. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  184946. attributes[n++] = 1;
  184947. attributes[n++] = WGL_SAMPLES_ARB;
  184948. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  184949. }
  184950. attributes[n++] = 0;
  184951. UINT formatsCount;
  184952. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  184953. (void) ok;
  184954. jassert (ok);
  184955. }
  184956. else
  184957. {
  184958. format = ChoosePixelFormat (dc, &pfd);
  184959. }
  184960. if (format != 0)
  184961. {
  184962. makeInactive();
  184963. // win32 can't change the pixel format of a window, so need to delete the
  184964. // old one and create a new one..
  184965. jassert (nativeWindow != 0);
  184966. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  184967. delete nativeWindow;
  184968. createNativeWindow();
  184969. if (SetPixelFormat (dc, format, &pfd))
  184970. {
  184971. wglDeleteContext (renderContext);
  184972. renderContext = wglCreateContext (dc);
  184973. jassert (renderContext != 0);
  184974. return renderContext != 0;
  184975. }
  184976. }
  184977. return false;
  184978. }
  184979. void updateWindowPosition (int x, int y, int w, int h, int)
  184980. {
  184981. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  184982. x, y, w, h,
  184983. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  184984. }
  184985. void repaint()
  184986. {
  184987. const Rectangle<int> bounds (nativeWindow->getBounds());
  184988. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  184989. }
  184990. void swapBuffers()
  184991. {
  184992. SwapBuffers (dc);
  184993. }
  184994. bool setSwapInterval (int numFramesPerSwap)
  184995. {
  184996. makeActive();
  184997. StringArray availableExtensions;
  184998. getWglExtensions (dc, availableExtensions);
  184999. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185000. return availableExtensions.contains ("WGL_EXT_swap_control")
  185001. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185002. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185003. }
  185004. int getSwapInterval() const
  185005. {
  185006. makeActive();
  185007. StringArray availableExtensions;
  185008. getWglExtensions (dc, availableExtensions);
  185009. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185010. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185011. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185012. return wglGetSwapIntervalEXT();
  185013. return 0;
  185014. }
  185015. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185016. {
  185017. jassert (isActive());
  185018. StringArray availableExtensions;
  185019. getWglExtensions (dc, availableExtensions);
  185020. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185021. int numTypes = 0;
  185022. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185023. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185024. {
  185025. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185026. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185027. jassertfalse
  185028. }
  185029. else
  185030. {
  185031. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185032. }
  185033. OpenGLPixelFormat pf;
  185034. for (int i = 0; i < numTypes; ++i)
  185035. {
  185036. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185037. {
  185038. bool alreadyListed = false;
  185039. for (int j = results.size(); --j >= 0;)
  185040. if (pf == *results.getUnchecked(j))
  185041. alreadyListed = true;
  185042. if (! alreadyListed)
  185043. results.add (new OpenGLPixelFormat (pf));
  185044. }
  185045. }
  185046. }
  185047. void* getNativeWindowHandle() const
  185048. {
  185049. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185050. }
  185051. juce_UseDebuggingNewOperator
  185052. HGLRC renderContext;
  185053. private:
  185054. Win32ComponentPeer* nativeWindow;
  185055. Component* const component;
  185056. HDC dc;
  185057. void createNativeWindow()
  185058. {
  185059. nativeWindow = new Win32ComponentPeer (component, 0);
  185060. nativeWindow->dontRepaint = true;
  185061. nativeWindow->setVisible (true);
  185062. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185063. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185064. if (peer != 0)
  185065. {
  185066. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185067. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185068. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185069. }
  185070. dc = GetDC (hwnd);
  185071. }
  185072. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185073. OpenGLPixelFormat& result,
  185074. const StringArray& availableExtensions) const throw()
  185075. {
  185076. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185077. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185078. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185079. {
  185080. int attributes[32];
  185081. int numAttributes = 0;
  185082. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185083. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185084. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185085. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185086. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185087. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185088. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185089. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185090. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185091. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185092. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185093. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185094. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185095. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185096. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185097. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185098. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185099. int values[32];
  185100. zeromem (values, sizeof (values));
  185101. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185102. {
  185103. int n = 0;
  185104. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185105. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185106. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185107. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185108. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185109. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185110. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185111. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185112. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185113. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185114. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185115. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185116. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185117. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185118. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185119. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185120. return isValidFormat;
  185121. }
  185122. else
  185123. {
  185124. jassertfalse
  185125. }
  185126. }
  185127. else
  185128. {
  185129. PIXELFORMATDESCRIPTOR pfd;
  185130. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185131. {
  185132. result.redBits = pfd.cRedBits;
  185133. result.greenBits = pfd.cGreenBits;
  185134. result.blueBits = pfd.cBlueBits;
  185135. result.alphaBits = pfd.cAlphaBits;
  185136. result.depthBufferBits = pfd.cDepthBits;
  185137. result.stencilBufferBits = pfd.cStencilBits;
  185138. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185139. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185140. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185141. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185142. result.fullSceneAntiAliasingNumSamples = 0;
  185143. return true;
  185144. }
  185145. else
  185146. {
  185147. jassertfalse
  185148. }
  185149. }
  185150. return false;
  185151. }
  185152. WindowedGLContext (const WindowedGLContext&);
  185153. WindowedGLContext& operator= (const WindowedGLContext&);
  185154. };
  185155. OpenGLContext* OpenGLComponent::createContext()
  185156. {
  185157. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this,
  185158. contextToShareListsWith != 0 ? (HGLRC) contextToShareListsWith->getRawContext() : 0,
  185159. preferredPixelFormat));
  185160. return (c->renderContext != 0) ? c.release() : 0;
  185161. }
  185162. void* OpenGLComponent::getNativeWindowHandle() const
  185163. {
  185164. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle() : 0;
  185165. }
  185166. void juce_glViewport (const int w, const int h)
  185167. {
  185168. glViewport (0, 0, w, h);
  185169. }
  185170. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185171. OwnedArray <OpenGLPixelFormat>& results)
  185172. {
  185173. Component tempComp;
  185174. {
  185175. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185176. wc.makeActive();
  185177. wc.findAlternativeOpenGLPixelFormats (results);
  185178. }
  185179. }
  185180. #endif
  185181. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185182. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185183. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185184. // compiled on its own).
  185185. #if JUCE_INCLUDED_FILE
  185186. #if JUCE_USE_CDREADER
  185187. namespace CDReaderHelpers
  185188. {
  185189. //***************************************************************************
  185190. // %%% TARGET STATUS VALUES %%%
  185191. //***************************************************************************
  185192. #define STATUS_GOOD 0x00 // Status Good
  185193. #define STATUS_CHKCOND 0x02 // Check Condition
  185194. #define STATUS_CONDMET 0x04 // Condition Met
  185195. #define STATUS_BUSY 0x08 // Busy
  185196. #define STATUS_INTERM 0x10 // Intermediate
  185197. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185198. #define STATUS_RESCONF 0x18 // Reservation conflict
  185199. #define STATUS_COMTERM 0x22 // Command Terminated
  185200. #define STATUS_QFULL 0x28 // Queue full
  185201. //***************************************************************************
  185202. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185203. //***************************************************************************
  185204. #define MAXLUN 7 // Maximum Logical Unit Id
  185205. #define MAXTARG 7 // Maximum Target Id
  185206. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185207. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185208. //***************************************************************************
  185209. // %%% Commands for all Device Types %%%
  185210. //***************************************************************************
  185211. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185212. #define SCSI_COMPARE 0x39 // Compare (O)
  185213. #define SCSI_COPY 0x18 // Copy (O)
  185214. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185215. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185216. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185217. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185218. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185219. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185220. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185221. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185222. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185223. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185224. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185225. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185226. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185227. //***************************************************************************
  185228. // %%% Commands Unique to Direct Access Devices %%%
  185229. //***************************************************************************
  185230. #define SCSI_COMPARE 0x39 // Compare (O)
  185231. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185232. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185233. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185234. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185235. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185236. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185237. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185238. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185239. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185240. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185241. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185242. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185243. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185244. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185245. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185246. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185247. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185248. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185249. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185250. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185251. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185252. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185253. #define SCSI_VERIFY 0x2F // Verify (O)
  185254. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185255. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185256. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185257. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185258. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185259. //***************************************************************************
  185260. // %%% Commands Unique to Sequential Access Devices %%%
  185261. //***************************************************************************
  185262. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185263. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185264. #define SCSI_LOCATE 0x2B // Locate (O)
  185265. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185266. #define SCSI_READ_POS 0x34 // Read Position (O)
  185267. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185268. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185269. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185270. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185271. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185272. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185273. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185274. //***************************************************************************
  185275. // %%% Commands Unique to Printer Devices %%%
  185276. //***************************************************************************
  185277. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185278. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185279. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185280. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185281. //***************************************************************************
  185282. // %%% Commands Unique to Processor Devices %%%
  185283. //***************************************************************************
  185284. #define SCSI_RECEIVE 0x08 // Receive (O)
  185285. #define SCSI_SEND 0x0A // Send (O)
  185286. //***************************************************************************
  185287. // %%% Commands Unique to Write-Once Devices %%%
  185288. //***************************************************************************
  185289. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185290. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185291. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185292. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185293. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185294. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185295. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185296. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185297. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185298. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185299. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185300. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185301. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185302. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185303. //***************************************************************************
  185304. // %%% Commands Unique to CD-ROM Devices %%%
  185305. //***************************************************************************
  185306. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185307. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185308. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185309. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185310. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185311. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185312. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185313. #define SCSI_READHEADER 0x44 // Read Header (O)
  185314. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185315. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185316. //***************************************************************************
  185317. // %%% Commands Unique to Scanner Devices %%%
  185318. //***************************************************************************
  185319. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185320. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185321. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185322. #define SCSI_SCAN 0x1B // Scan (O)
  185323. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185324. //***************************************************************************
  185325. // %%% Commands Unique to Optical Memory Devices %%%
  185326. //***************************************************************************
  185327. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185328. //***************************************************************************
  185329. // %%% Commands Unique to Medium Changer Devices %%%
  185330. //***************************************************************************
  185331. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185332. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185333. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185334. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185335. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185336. //***************************************************************************
  185337. // %%% Commands Unique to Communication Devices %%%
  185338. //***************************************************************************
  185339. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185340. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185341. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185342. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185343. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185344. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185345. //***************************************************************************
  185346. // %%% Request Sense Data Format %%%
  185347. //***************************************************************************
  185348. typedef struct {
  185349. BYTE ErrorCode; // Error Code (70H or 71H)
  185350. BYTE SegmentNum; // Number of current segment descriptor
  185351. BYTE SenseKey; // Sense Key(See bit definitions too)
  185352. BYTE InfoByte0; // Information MSB
  185353. BYTE InfoByte1; // Information MID
  185354. BYTE InfoByte2; // Information MID
  185355. BYTE InfoByte3; // Information LSB
  185356. BYTE AddSenLen; // Additional Sense Length
  185357. BYTE ComSpecInf0; // Command Specific Information MSB
  185358. BYTE ComSpecInf1; // Command Specific Information MID
  185359. BYTE ComSpecInf2; // Command Specific Information MID
  185360. BYTE ComSpecInf3; // Command Specific Information LSB
  185361. BYTE AddSenseCode; // Additional Sense Code
  185362. BYTE AddSenQual; // Additional Sense Code Qualifier
  185363. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185364. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185365. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185366. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185367. BYTE AddSenseBytes; // Additional Sense Bytes
  185368. } SENSE_DATA_FMT;
  185369. //***************************************************************************
  185370. // %%% REQUEST SENSE ERROR CODE %%%
  185371. //***************************************************************************
  185372. #define SERROR_CURRENT 0x70 // Current Errors
  185373. #define SERROR_DEFERED 0x71 // Deferred Errors
  185374. //***************************************************************************
  185375. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185376. //***************************************************************************
  185377. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185378. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185379. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185380. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185381. //***************************************************************************
  185382. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185383. //***************************************************************************
  185384. #define KEY_NOSENSE 0x00 // No Sense
  185385. #define KEY_RECERROR 0x01 // Recovered Error
  185386. #define KEY_NOTREADY 0x02 // Not Ready
  185387. #define KEY_MEDIUMERR 0x03 // Medium Error
  185388. #define KEY_HARDERROR 0x04 // Hardware Error
  185389. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185390. #define KEY_UNITATT 0x06 // Unit Attention
  185391. #define KEY_DATAPROT 0x07 // Data Protect
  185392. #define KEY_BLANKCHK 0x08 // Blank Check
  185393. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185394. #define KEY_COPYABORT 0x0A // Copy Abort
  185395. #define KEY_EQUAL 0x0C // Equal (Search)
  185396. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185397. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185398. #define KEY_RESERVED 0x0F // Reserved
  185399. //***************************************************************************
  185400. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185401. //***************************************************************************
  185402. #define DTYPE_DASD 0x00 // Disk Device
  185403. #define DTYPE_SEQD 0x01 // Tape Device
  185404. #define DTYPE_PRNT 0x02 // Printer
  185405. #define DTYPE_PROC 0x03 // Processor
  185406. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185407. #define DTYPE_CROM 0x05 // CD-ROM device
  185408. #define DTYPE_SCAN 0x06 // Scanner device
  185409. #define DTYPE_OPTI 0x07 // Optical memory device
  185410. #define DTYPE_JUKE 0x08 // Medium Changer device
  185411. #define DTYPE_COMM 0x09 // Communications device
  185412. #define DTYPE_RESL 0x0A // Reserved (low)
  185413. #define DTYPE_RESH 0x1E // Reserved (high)
  185414. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185415. //***************************************************************************
  185416. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185417. //***************************************************************************
  185418. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185419. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185420. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185421. #define ANSI_RESLO 0x3 // Reserved (low)
  185422. #define ANSI_RESHI 0x7 // Reserved (high)
  185423. typedef struct
  185424. {
  185425. USHORT Length;
  185426. UCHAR ScsiStatus;
  185427. UCHAR PathId;
  185428. UCHAR TargetId;
  185429. UCHAR Lun;
  185430. UCHAR CdbLength;
  185431. UCHAR SenseInfoLength;
  185432. UCHAR DataIn;
  185433. ULONG DataTransferLength;
  185434. ULONG TimeOutValue;
  185435. ULONG DataBufferOffset;
  185436. ULONG SenseInfoOffset;
  185437. UCHAR Cdb[16];
  185438. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185439. typedef struct
  185440. {
  185441. USHORT Length;
  185442. UCHAR ScsiStatus;
  185443. UCHAR PathId;
  185444. UCHAR TargetId;
  185445. UCHAR Lun;
  185446. UCHAR CdbLength;
  185447. UCHAR SenseInfoLength;
  185448. UCHAR DataIn;
  185449. ULONG DataTransferLength;
  185450. ULONG TimeOutValue;
  185451. PVOID DataBuffer;
  185452. ULONG SenseInfoOffset;
  185453. UCHAR Cdb[16];
  185454. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185455. typedef struct
  185456. {
  185457. SCSI_PASS_THROUGH_DIRECT spt;
  185458. ULONG Filler;
  185459. UCHAR ucSenseBuf[32];
  185460. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185461. typedef struct
  185462. {
  185463. ULONG Length;
  185464. UCHAR PortNumber;
  185465. UCHAR PathId;
  185466. UCHAR TargetId;
  185467. UCHAR Lun;
  185468. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185469. #define METHOD_BUFFERED 0
  185470. #define METHOD_IN_DIRECT 1
  185471. #define METHOD_OUT_DIRECT 2
  185472. #define METHOD_NEITHER 3
  185473. #define FILE_ANY_ACCESS 0
  185474. #ifndef FILE_READ_ACCESS
  185475. #define FILE_READ_ACCESS (0x0001)
  185476. #endif
  185477. #ifndef FILE_WRITE_ACCESS
  185478. #define FILE_WRITE_ACCESS (0x0002)
  185479. #endif
  185480. #define IOCTL_SCSI_BASE 0x00000004
  185481. #define SCSI_IOCTL_DATA_OUT 0
  185482. #define SCSI_IOCTL_DATA_IN 1
  185483. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  185484. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  185485. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  185486. )
  185487. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185488. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  185489. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185490. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  185491. #define SENSE_LEN 14
  185492. #define SRB_DIR_SCSI 0x00
  185493. #define SRB_POSTING 0x01
  185494. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  185495. #define SRB_DIR_IN 0x08
  185496. #define SRB_DIR_OUT 0x10
  185497. #define SRB_EVENT_NOTIFY 0x40
  185498. #define RESIDUAL_COUNT_SUPPORTED 0x02
  185499. #define MAX_SRB_TIMEOUT 1080001u
  185500. #define DEFAULT_SRB_TIMEOUT 1080001u
  185501. #define SC_HA_INQUIRY 0x00
  185502. #define SC_GET_DEV_TYPE 0x01
  185503. #define SC_EXEC_SCSI_CMD 0x02
  185504. #define SC_ABORT_SRB 0x03
  185505. #define SC_RESET_DEV 0x04
  185506. #define SC_SET_HA_PARMS 0x05
  185507. #define SC_GET_DISK_INFO 0x06
  185508. #define SC_RESCAN_SCSI_BUS 0x07
  185509. #define SC_GETSET_TIMEOUTS 0x08
  185510. #define SS_PENDING 0x00
  185511. #define SS_COMP 0x01
  185512. #define SS_ABORTED 0x02
  185513. #define SS_ABORT_FAIL 0x03
  185514. #define SS_ERR 0x04
  185515. #define SS_INVALID_CMD 0x80
  185516. #define SS_INVALID_HA 0x81
  185517. #define SS_NO_DEVICE 0x82
  185518. #define SS_INVALID_SRB 0xE0
  185519. #define SS_OLD_MANAGER 0xE1
  185520. #define SS_BUFFER_ALIGN 0xE1
  185521. #define SS_ILLEGAL_MODE 0xE2
  185522. #define SS_NO_ASPI 0xE3
  185523. #define SS_FAILED_INIT 0xE4
  185524. #define SS_ASPI_IS_BUSY 0xE5
  185525. #define SS_BUFFER_TO_BIG 0xE6
  185526. #define SS_BUFFER_TOO_BIG 0xE6
  185527. #define SS_MISMATCHED_COMPONENTS 0xE7
  185528. #define SS_NO_ADAPTERS 0xE8
  185529. #define SS_INSUFFICIENT_RESOURCES 0xE9
  185530. #define SS_ASPI_IS_SHUTDOWN 0xEA
  185531. #define SS_BAD_INSTALL 0xEB
  185532. #define HASTAT_OK 0x00
  185533. #define HASTAT_SEL_TO 0x11
  185534. #define HASTAT_DO_DU 0x12
  185535. #define HASTAT_BUS_FREE 0x13
  185536. #define HASTAT_PHASE_ERR 0x14
  185537. #define HASTAT_TIMEOUT 0x09
  185538. #define HASTAT_COMMAND_TIMEOUT 0x0B
  185539. #define HASTAT_MESSAGE_REJECT 0x0D
  185540. #define HASTAT_BUS_RESET 0x0E
  185541. #define HASTAT_PARITY_ERROR 0x0F
  185542. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  185543. #define PACKED
  185544. #pragma pack(1)
  185545. typedef struct
  185546. {
  185547. BYTE SRB_Cmd;
  185548. BYTE SRB_Status;
  185549. BYTE SRB_HaID;
  185550. BYTE SRB_Flags;
  185551. DWORD SRB_Hdr_Rsvd;
  185552. BYTE HA_Count;
  185553. BYTE HA_SCSI_ID;
  185554. BYTE HA_ManagerId[16];
  185555. BYTE HA_Identifier[16];
  185556. BYTE HA_Unique[16];
  185557. WORD HA_Rsvd1;
  185558. BYTE pad[20];
  185559. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  185560. typedef struct
  185561. {
  185562. BYTE SRB_Cmd;
  185563. BYTE SRB_Status;
  185564. BYTE SRB_HaID;
  185565. BYTE SRB_Flags;
  185566. DWORD SRB_Hdr_Rsvd;
  185567. BYTE SRB_Target;
  185568. BYTE SRB_Lun;
  185569. BYTE SRB_DeviceType;
  185570. BYTE SRB_Rsvd1;
  185571. BYTE pad[68];
  185572. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  185573. typedef struct
  185574. {
  185575. BYTE SRB_Cmd;
  185576. BYTE SRB_Status;
  185577. BYTE SRB_HaID;
  185578. BYTE SRB_Flags;
  185579. DWORD SRB_Hdr_Rsvd;
  185580. BYTE SRB_Target;
  185581. BYTE SRB_Lun;
  185582. WORD SRB_Rsvd1;
  185583. DWORD SRB_BufLen;
  185584. BYTE FAR *SRB_BufPointer;
  185585. BYTE SRB_SenseLen;
  185586. BYTE SRB_CDBLen;
  185587. BYTE SRB_HaStat;
  185588. BYTE SRB_TargStat;
  185589. VOID FAR *SRB_PostProc;
  185590. BYTE SRB_Rsvd2[20];
  185591. BYTE CDBByte[16];
  185592. BYTE SenseArea[SENSE_LEN+2];
  185593. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  185594. typedef struct
  185595. {
  185596. BYTE SRB_Cmd;
  185597. BYTE SRB_Status;
  185598. BYTE SRB_HaId;
  185599. BYTE SRB_Flags;
  185600. DWORD SRB_Hdr_Rsvd;
  185601. } PACKED SRB, *PSRB, FAR *LPSRB;
  185602. #pragma pack()
  185603. struct CDDeviceInfo
  185604. {
  185605. char vendor[9];
  185606. char productId[17];
  185607. char rev[5];
  185608. char vendorSpec[21];
  185609. BYTE ha;
  185610. BYTE tgt;
  185611. BYTE lun;
  185612. char scsiDriveLetter; // will be 0 if not using scsi
  185613. };
  185614. class CDReadBuffer
  185615. {
  185616. public:
  185617. int startFrame;
  185618. int numFrames;
  185619. int dataStartOffset;
  185620. int dataLength;
  185621. BYTE* buffer;
  185622. int bufferSize;
  185623. int index;
  185624. bool wantsIndex;
  185625. CDReadBuffer (const int numberOfFrames)
  185626. : startFrame (0),
  185627. numFrames (0),
  185628. dataStartOffset (0),
  185629. dataLength (0),
  185630. index (0),
  185631. wantsIndex (false)
  185632. {
  185633. bufferSize = 2352 * numberOfFrames;
  185634. buffer = (BYTE*) juce_malloc (bufferSize);
  185635. }
  185636. ~CDReadBuffer()
  185637. {
  185638. juce_free (buffer);
  185639. }
  185640. bool isZero() const
  185641. {
  185642. BYTE* p = buffer + dataStartOffset;
  185643. for (int i = dataLength; --i >= 0;)
  185644. if (*p++ != 0)
  185645. return false;
  185646. return true;
  185647. }
  185648. };
  185649. class CDDeviceHandle;
  185650. class CDController
  185651. {
  185652. public:
  185653. CDController();
  185654. virtual ~CDController();
  185655. virtual bool read (CDReadBuffer* t) = 0;
  185656. virtual void shutDown();
  185657. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  185658. int getLastIndex();
  185659. public:
  185660. bool initialised;
  185661. CDDeviceHandle* deviceInfo;
  185662. int framesToCheck, framesOverlap;
  185663. void prepare (SRB_ExecSCSICmd& s);
  185664. void perform (SRB_ExecSCSICmd& s);
  185665. void setPaused (bool paused);
  185666. };
  185667. #pragma pack(1)
  185668. struct TOCTRACK
  185669. {
  185670. BYTE rsvd;
  185671. BYTE ADR;
  185672. BYTE trackNumber;
  185673. BYTE rsvd2;
  185674. BYTE addr[4];
  185675. };
  185676. struct TOC
  185677. {
  185678. WORD tocLen;
  185679. BYTE firstTrack;
  185680. BYTE lastTrack;
  185681. TOCTRACK tracks[100];
  185682. };
  185683. #pragma pack()
  185684. enum
  185685. {
  185686. READTYPE_ANY = 0,
  185687. READTYPE_ATAPI1 = 1,
  185688. READTYPE_ATAPI2 = 2,
  185689. READTYPE_READ6 = 3,
  185690. READTYPE_READ10 = 4,
  185691. READTYPE_READ_D8 = 5,
  185692. READTYPE_READ_D4 = 6,
  185693. READTYPE_READ_D4_1 = 7,
  185694. READTYPE_READ10_2 = 8
  185695. };
  185696. class CDDeviceHandle
  185697. {
  185698. public:
  185699. CDDeviceHandle (const CDDeviceInfo* const device)
  185700. : scsiHandle (0),
  185701. readType (READTYPE_ANY),
  185702. controller (0)
  185703. {
  185704. memcpy (&info, device, sizeof (info));
  185705. }
  185706. ~CDDeviceHandle()
  185707. {
  185708. if (controller != 0)
  185709. {
  185710. controller->shutDown();
  185711. controller = 0;
  185712. }
  185713. if (scsiHandle != 0)
  185714. CloseHandle (scsiHandle);
  185715. }
  185716. bool readTOC (TOC* lpToc, bool useMSF);
  185717. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  185718. void openDrawer (bool shouldBeOpen);
  185719. CDDeviceInfo info;
  185720. HANDLE scsiHandle;
  185721. BYTE readType;
  185722. private:
  185723. ScopedPointer<CDController> controller;
  185724. bool testController (const int readType,
  185725. CDController* const newController,
  185726. CDReadBuffer* const bufferToUse);
  185727. };
  185728. DWORD (*fGetASPI32SupportInfo)(void);
  185729. DWORD (*fSendASPI32Command)(LPSRB);
  185730. static HINSTANCE winAspiLib = 0;
  185731. static bool usingScsi = false;
  185732. static bool initialised = false;
  185733. static bool InitialiseCDRipper()
  185734. {
  185735. if (! initialised)
  185736. {
  185737. initialised = true;
  185738. OSVERSIONINFO info;
  185739. info.dwOSVersionInfoSize = sizeof (info);
  185740. GetVersionEx (&info);
  185741. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  185742. if (! usingScsi)
  185743. {
  185744. fGetASPI32SupportInfo = 0;
  185745. fSendASPI32Command = 0;
  185746. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  185747. if (winAspiLib != 0)
  185748. {
  185749. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  185750. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  185751. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  185752. return false;
  185753. }
  185754. else
  185755. {
  185756. usingScsi = true;
  185757. }
  185758. }
  185759. }
  185760. return true;
  185761. }
  185762. static void DeinitialiseCDRipper()
  185763. {
  185764. if (winAspiLib != 0)
  185765. {
  185766. fGetASPI32SupportInfo = 0;
  185767. fSendASPI32Command = 0;
  185768. FreeLibrary (winAspiLib);
  185769. winAspiLib = 0;
  185770. }
  185771. initialised = false;
  185772. }
  185773. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  185774. {
  185775. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  185776. OSVERSIONINFO info;
  185777. info.dwOSVersionInfoSize = sizeof (info);
  185778. GetVersionEx (&info);
  185779. DWORD flags = GENERIC_READ;
  185780. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  185781. flags = GENERIC_READ | GENERIC_WRITE;
  185782. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  185783. if (h == INVALID_HANDLE_VALUE)
  185784. {
  185785. flags ^= GENERIC_WRITE;
  185786. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  185787. }
  185788. return h;
  185789. }
  185790. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  185791. const char driveLetter,
  185792. HANDLE& deviceHandle,
  185793. const bool retryOnFailure = true)
  185794. {
  185795. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  185796. zerostruct (s);
  185797. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  185798. s.spt.CdbLength = srb->SRB_CDBLen;
  185799. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  185800. ? SCSI_IOCTL_DATA_IN
  185801. : ((srb->SRB_Flags & SRB_DIR_OUT)
  185802. ? SCSI_IOCTL_DATA_OUT
  185803. : SCSI_IOCTL_DATA_UNSPECIFIED));
  185804. s.spt.DataTransferLength = srb->SRB_BufLen;
  185805. s.spt.TimeOutValue = 5;
  185806. s.spt.DataBuffer = srb->SRB_BufPointer;
  185807. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  185808. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  185809. srb->SRB_Status = SS_ERR;
  185810. srb->SRB_TargStat = 0x0004;
  185811. DWORD bytesReturned = 0;
  185812. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  185813. &s, sizeof (s),
  185814. &s, sizeof (s),
  185815. &bytesReturned, 0) != 0)
  185816. {
  185817. srb->SRB_Status = SS_COMP;
  185818. }
  185819. else if (retryOnFailure)
  185820. {
  185821. const DWORD error = GetLastError();
  185822. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  185823. {
  185824. if (error != ERROR_INVALID_HANDLE)
  185825. CloseHandle (deviceHandle);
  185826. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  185827. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  185828. }
  185829. }
  185830. return srb->SRB_Status;
  185831. }
  185832. // Controller types..
  185833. class ControllerType1 : public CDController
  185834. {
  185835. public:
  185836. ControllerType1() {}
  185837. ~ControllerType1() {}
  185838. bool read (CDReadBuffer* rb)
  185839. {
  185840. if (rb->numFrames * 2352 > rb->bufferSize)
  185841. return false;
  185842. SRB_ExecSCSICmd s;
  185843. prepare (s);
  185844. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  185845. s.SRB_BufLen = rb->bufferSize;
  185846. s.SRB_BufPointer = rb->buffer;
  185847. s.SRB_CDBLen = 12;
  185848. s.CDBByte[0] = 0xBE;
  185849. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  185850. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  185851. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  185852. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  185853. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  185854. perform (s);
  185855. if (s.SRB_Status != SS_COMP)
  185856. return false;
  185857. rb->dataLength = rb->numFrames * 2352;
  185858. rb->dataStartOffset = 0;
  185859. return true;
  185860. }
  185861. };
  185862. class ControllerType2 : public CDController
  185863. {
  185864. public:
  185865. ControllerType2() {}
  185866. ~ControllerType2() {}
  185867. void shutDown()
  185868. {
  185869. if (initialised)
  185870. {
  185871. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  185872. SRB_ExecSCSICmd s;
  185873. prepare (s);
  185874. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  185875. s.SRB_BufLen = 0x0C;
  185876. s.SRB_BufPointer = bufPointer;
  185877. s.SRB_CDBLen = 6;
  185878. s.CDBByte[0] = 0x15;
  185879. s.CDBByte[4] = 0x0C;
  185880. perform (s);
  185881. }
  185882. }
  185883. bool init()
  185884. {
  185885. SRB_ExecSCSICmd s;
  185886. s.SRB_Status = SS_ERR;
  185887. if (deviceInfo->readType == READTYPE_READ10_2)
  185888. {
  185889. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  185890. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  185891. for (int i = 0; i < 2; ++i)
  185892. {
  185893. prepare (s);
  185894. s.SRB_Flags = SRB_EVENT_NOTIFY;
  185895. s.SRB_BufLen = 0x14;
  185896. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  185897. s.SRB_CDBLen = 6;
  185898. s.CDBByte[0] = 0x15;
  185899. s.CDBByte[1] = 0x10;
  185900. s.CDBByte[4] = 0x14;
  185901. perform (s);
  185902. if (s.SRB_Status != SS_COMP)
  185903. return false;
  185904. }
  185905. }
  185906. else
  185907. {
  185908. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  185909. prepare (s);
  185910. s.SRB_Flags = SRB_EVENT_NOTIFY;
  185911. s.SRB_BufLen = 0x0C;
  185912. s.SRB_BufPointer = bufPointer;
  185913. s.SRB_CDBLen = 6;
  185914. s.CDBByte[0] = 0x15;
  185915. s.CDBByte[4] = 0x0C;
  185916. perform (s);
  185917. }
  185918. return s.SRB_Status == SS_COMP;
  185919. }
  185920. bool read (CDReadBuffer* rb)
  185921. {
  185922. if (rb->numFrames * 2352 > rb->bufferSize)
  185923. return false;
  185924. if (!initialised)
  185925. {
  185926. initialised = init();
  185927. if (!initialised)
  185928. return false;
  185929. }
  185930. SRB_ExecSCSICmd s;
  185931. prepare (s);
  185932. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  185933. s.SRB_BufLen = rb->bufferSize;
  185934. s.SRB_BufPointer = rb->buffer;
  185935. s.SRB_CDBLen = 10;
  185936. s.CDBByte[0] = 0x28;
  185937. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  185938. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  185939. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  185940. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  185941. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  185942. perform (s);
  185943. if (s.SRB_Status != SS_COMP)
  185944. return false;
  185945. rb->dataLength = rb->numFrames * 2352;
  185946. rb->dataStartOffset = 0;
  185947. return true;
  185948. }
  185949. };
  185950. class ControllerType3 : public CDController
  185951. {
  185952. public:
  185953. ControllerType3() {}
  185954. ~ControllerType3() {}
  185955. bool read (CDReadBuffer* rb)
  185956. {
  185957. if (rb->numFrames * 2352 > rb->bufferSize)
  185958. return false;
  185959. if (!initialised)
  185960. {
  185961. setPaused (false);
  185962. initialised = true;
  185963. }
  185964. SRB_ExecSCSICmd s;
  185965. prepare (s);
  185966. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  185967. s.SRB_BufLen = rb->numFrames * 2352;
  185968. s.SRB_BufPointer = rb->buffer;
  185969. s.SRB_CDBLen = 12;
  185970. s.CDBByte[0] = 0xD8;
  185971. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  185972. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  185973. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  185974. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  185975. perform (s);
  185976. if (s.SRB_Status != SS_COMP)
  185977. return false;
  185978. rb->dataLength = rb->numFrames * 2352;
  185979. rb->dataStartOffset = 0;
  185980. return true;
  185981. }
  185982. };
  185983. class ControllerType4 : public CDController
  185984. {
  185985. public:
  185986. ControllerType4() {}
  185987. ~ControllerType4() {}
  185988. bool selectD4Mode()
  185989. {
  185990. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  185991. SRB_ExecSCSICmd s;
  185992. prepare (s);
  185993. s.SRB_Flags = SRB_EVENT_NOTIFY;
  185994. s.SRB_CDBLen = 6;
  185995. s.SRB_BufLen = 12;
  185996. s.SRB_BufPointer = bufPointer;
  185997. s.CDBByte[0] = 0x15;
  185998. s.CDBByte[1] = 0x10;
  185999. s.CDBByte[4] = 0x08;
  186000. perform (s);
  186001. return s.SRB_Status == SS_COMP;
  186002. }
  186003. bool read (CDReadBuffer* rb)
  186004. {
  186005. if (rb->numFrames * 2352 > rb->bufferSize)
  186006. return false;
  186007. if (!initialised)
  186008. {
  186009. setPaused (true);
  186010. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186011. selectD4Mode();
  186012. initialised = true;
  186013. }
  186014. SRB_ExecSCSICmd s;
  186015. prepare (s);
  186016. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186017. s.SRB_BufLen = rb->bufferSize;
  186018. s.SRB_BufPointer = rb->buffer;
  186019. s.SRB_CDBLen = 10;
  186020. s.CDBByte[0] = 0xD4;
  186021. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186022. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186023. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186024. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186025. perform (s);
  186026. if (s.SRB_Status != SS_COMP)
  186027. return false;
  186028. rb->dataLength = rb->numFrames * 2352;
  186029. rb->dataStartOffset = 0;
  186030. return true;
  186031. }
  186032. };
  186033. CDController::CDController() : initialised (false)
  186034. {
  186035. }
  186036. CDController::~CDController()
  186037. {
  186038. }
  186039. void CDController::prepare (SRB_ExecSCSICmd& s)
  186040. {
  186041. zerostruct (s);
  186042. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186043. s.SRB_HaID = deviceInfo->info.ha;
  186044. s.SRB_Target = deviceInfo->info.tgt;
  186045. s.SRB_Lun = deviceInfo->info.lun;
  186046. s.SRB_SenseLen = SENSE_LEN;
  186047. }
  186048. void CDController::perform (SRB_ExecSCSICmd& s)
  186049. {
  186050. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186051. s.SRB_PostProc = event;
  186052. ResetEvent (event);
  186053. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186054. deviceInfo->info.scsiDriveLetter,
  186055. deviceInfo->scsiHandle)
  186056. : fSendASPI32Command ((LPSRB)&s);
  186057. if (status == SS_PENDING)
  186058. WaitForSingleObject (event, 4000);
  186059. CloseHandle (event);
  186060. }
  186061. void CDController::setPaused (bool paused)
  186062. {
  186063. SRB_ExecSCSICmd s;
  186064. prepare (s);
  186065. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186066. s.SRB_CDBLen = 10;
  186067. s.CDBByte[0] = 0x4B;
  186068. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186069. perform (s);
  186070. }
  186071. void CDController::shutDown()
  186072. {
  186073. }
  186074. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186075. {
  186076. if (overlapBuffer != 0)
  186077. {
  186078. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186079. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186080. if (doJitter
  186081. && overlapBuffer->startFrame > 0
  186082. && overlapBuffer->numFrames > 0
  186083. && overlapBuffer->dataLength > 0)
  186084. {
  186085. const int numFrames = rb->numFrames;
  186086. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186087. {
  186088. rb->startFrame -= framesOverlap;
  186089. if (framesToCheck < framesOverlap
  186090. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186091. rb->numFrames += framesOverlap;
  186092. }
  186093. else
  186094. {
  186095. overlapBuffer->dataLength = 0;
  186096. overlapBuffer->startFrame = 0;
  186097. overlapBuffer->numFrames = 0;
  186098. }
  186099. }
  186100. if (! read (rb))
  186101. return false;
  186102. if (doJitter)
  186103. {
  186104. const int checkLen = framesToCheck * 2352;
  186105. const int maxToCheck = rb->dataLength - checkLen;
  186106. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186107. return true;
  186108. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186109. bool found = false;
  186110. for (int i = 0; i < maxToCheck; ++i)
  186111. {
  186112. if (memcmp (p, rb->buffer + i, checkLen) == 0)
  186113. {
  186114. i += checkLen;
  186115. rb->dataStartOffset = i;
  186116. rb->dataLength -= i;
  186117. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186118. found = true;
  186119. break;
  186120. }
  186121. }
  186122. rb->numFrames = rb->dataLength / 2352;
  186123. rb->dataLength = 2352 * rb->numFrames;
  186124. if (!found)
  186125. return false;
  186126. }
  186127. if (canDoJitter)
  186128. {
  186129. memcpy (overlapBuffer->buffer,
  186130. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186131. 2352 * framesToCheck);
  186132. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186133. overlapBuffer->numFrames = framesToCheck;
  186134. overlapBuffer->dataLength = 2352 * framesToCheck;
  186135. overlapBuffer->dataStartOffset = 0;
  186136. }
  186137. else
  186138. {
  186139. overlapBuffer->startFrame = 0;
  186140. overlapBuffer->numFrames = 0;
  186141. overlapBuffer->dataLength = 0;
  186142. }
  186143. return true;
  186144. }
  186145. else
  186146. {
  186147. return read (rb);
  186148. }
  186149. }
  186150. int CDController::getLastIndex()
  186151. {
  186152. char qdata[100];
  186153. SRB_ExecSCSICmd s;
  186154. prepare (s);
  186155. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186156. s.SRB_BufLen = sizeof (qdata);
  186157. s.SRB_BufPointer = (BYTE*)qdata;
  186158. s.SRB_CDBLen = 12;
  186159. s.CDBByte[0] = 0x42;
  186160. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186161. s.CDBByte[2] = 64;
  186162. s.CDBByte[3] = 1; // get current position
  186163. s.CDBByte[7] = 0;
  186164. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186165. perform (s);
  186166. if (s.SRB_Status == SS_COMP)
  186167. return qdata[7];
  186168. return 0;
  186169. }
  186170. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186171. {
  186172. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186173. SRB_ExecSCSICmd s;
  186174. zerostruct (s);
  186175. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186176. s.SRB_HaID = info.ha;
  186177. s.SRB_Target = info.tgt;
  186178. s.SRB_Lun = info.lun;
  186179. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186180. s.SRB_BufLen = 0x324;
  186181. s.SRB_BufPointer = (BYTE*)lpToc;
  186182. s.SRB_SenseLen = 0x0E;
  186183. s.SRB_CDBLen = 0x0A;
  186184. s.SRB_PostProc = event;
  186185. s.CDBByte[0] = 0x43;
  186186. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186187. s.CDBByte[7] = 0x03;
  186188. s.CDBByte[8] = 0x24;
  186189. ResetEvent (event);
  186190. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186191. : fSendASPI32Command ((LPSRB)&s);
  186192. if (status == SS_PENDING)
  186193. WaitForSingleObject (event, 4000);
  186194. CloseHandle (event);
  186195. return (s.SRB_Status == SS_COMP);
  186196. }
  186197. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186198. CDReadBuffer* const overlapBuffer)
  186199. {
  186200. if (controller == 0)
  186201. {
  186202. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186203. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186204. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186205. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186206. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186207. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186208. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186209. }
  186210. buffer->index = 0;
  186211. if ((controller != 0)
  186212. && controller->readAudio (buffer, overlapBuffer))
  186213. {
  186214. if (buffer->wantsIndex)
  186215. buffer->index = controller->getLastIndex();
  186216. return true;
  186217. }
  186218. return false;
  186219. }
  186220. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186221. {
  186222. if (shouldBeOpen)
  186223. {
  186224. if (controller != 0)
  186225. {
  186226. controller->shutDown();
  186227. controller = 0;
  186228. }
  186229. if (scsiHandle != 0)
  186230. {
  186231. CloseHandle (scsiHandle);
  186232. scsiHandle = 0;
  186233. }
  186234. }
  186235. SRB_ExecSCSICmd s;
  186236. zerostruct (s);
  186237. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186238. s.SRB_HaID = info.ha;
  186239. s.SRB_Target = info.tgt;
  186240. s.SRB_Lun = info.lun;
  186241. s.SRB_SenseLen = SENSE_LEN;
  186242. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186243. s.SRB_BufLen = 0;
  186244. s.SRB_BufPointer = 0;
  186245. s.SRB_CDBLen = 12;
  186246. s.CDBByte[0] = 0x1b;
  186247. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186248. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186249. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186250. s.SRB_PostProc = event;
  186251. ResetEvent (event);
  186252. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186253. : fSendASPI32Command ((LPSRB)&s);
  186254. if (status == SS_PENDING)
  186255. WaitForSingleObject (event, 4000);
  186256. CloseHandle (event);
  186257. }
  186258. bool CDDeviceHandle::testController (const int type,
  186259. CDController* const newController,
  186260. CDReadBuffer* const rb)
  186261. {
  186262. controller = newController;
  186263. readType = (BYTE)type;
  186264. controller->deviceInfo = this;
  186265. controller->framesToCheck = 1;
  186266. controller->framesOverlap = 3;
  186267. bool passed = false;
  186268. memset (rb->buffer, 0xcd, rb->bufferSize);
  186269. if (controller->read (rb))
  186270. {
  186271. passed = true;
  186272. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186273. int wrong = 0;
  186274. for (int i = rb->dataLength / 4; --i >= 0;)
  186275. {
  186276. if (*p++ == (int) 0xcdcdcdcd)
  186277. {
  186278. if (++wrong == 4)
  186279. {
  186280. passed = false;
  186281. break;
  186282. }
  186283. }
  186284. else
  186285. {
  186286. wrong = 0;
  186287. }
  186288. }
  186289. }
  186290. if (! passed)
  186291. {
  186292. controller->shutDown();
  186293. controller = 0;
  186294. }
  186295. return passed;
  186296. }
  186297. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186298. {
  186299. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186300. const int bufSize = 128;
  186301. BYTE buffer[bufSize];
  186302. zeromem (buffer, bufSize);
  186303. SRB_ExecSCSICmd s;
  186304. zerostruct (s);
  186305. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186306. s.SRB_HaID = ha;
  186307. s.SRB_Target = tgt;
  186308. s.SRB_Lun = lun;
  186309. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186310. s.SRB_BufLen = bufSize;
  186311. s.SRB_BufPointer = buffer;
  186312. s.SRB_SenseLen = SENSE_LEN;
  186313. s.SRB_CDBLen = 6;
  186314. s.SRB_PostProc = event;
  186315. s.CDBByte[0] = SCSI_INQUIRY;
  186316. s.CDBByte[4] = 100;
  186317. ResetEvent (event);
  186318. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186319. WaitForSingleObject (event, 4000);
  186320. CloseHandle (event);
  186321. if (s.SRB_Status == SS_COMP)
  186322. {
  186323. memcpy (dev->vendor, &buffer[8], 8);
  186324. memcpy (dev->productId, &buffer[16], 16);
  186325. memcpy (dev->rev, &buffer[32], 4);
  186326. memcpy (dev->vendorSpec, &buffer[36], 20);
  186327. }
  186328. }
  186329. static int FindCDDevices (CDDeviceInfo* const list,
  186330. int maxItems)
  186331. {
  186332. int count = 0;
  186333. if (usingScsi)
  186334. {
  186335. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186336. {
  186337. TCHAR drivePath[8];
  186338. drivePath[0] = driveLetter;
  186339. drivePath[1] = ':';
  186340. drivePath[2] = '\\';
  186341. drivePath[3] = 0;
  186342. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186343. {
  186344. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186345. if (h != INVALID_HANDLE_VALUE)
  186346. {
  186347. BYTE buffer[100], passThroughStruct[1024];
  186348. zeromem (buffer, sizeof (buffer));
  186349. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186350. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186351. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186352. p->spt.CdbLength = 6;
  186353. p->spt.SenseInfoLength = 24;
  186354. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186355. p->spt.DataTransferLength = 100;
  186356. p->spt.TimeOutValue = 2;
  186357. p->spt.DataBuffer = buffer;
  186358. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186359. p->spt.Cdb[0] = 0x12;
  186360. p->spt.Cdb[4] = 100;
  186361. DWORD bytesReturned = 0;
  186362. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186363. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186364. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186365. &bytesReturned, 0) != 0)
  186366. {
  186367. zeromem (&list[count], sizeof (CDDeviceInfo));
  186368. list[count].scsiDriveLetter = driveLetter;
  186369. memcpy (list[count].vendor, &buffer[8], 8);
  186370. memcpy (list[count].productId, &buffer[16], 16);
  186371. memcpy (list[count].rev, &buffer[32], 4);
  186372. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186373. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186374. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186375. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186376. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186377. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186378. &bytesReturned, 0) != 0)
  186379. {
  186380. list[count].ha = scsiAddr->PortNumber;
  186381. list[count].tgt = scsiAddr->TargetId;
  186382. list[count].lun = scsiAddr->Lun;
  186383. ++count;
  186384. }
  186385. }
  186386. CloseHandle (h);
  186387. }
  186388. }
  186389. }
  186390. }
  186391. else
  186392. {
  186393. const DWORD d = fGetASPI32SupportInfo();
  186394. BYTE status = HIBYTE (LOWORD (d));
  186395. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186396. return 0;
  186397. const int numAdapters = LOBYTE (LOWORD (d));
  186398. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186399. {
  186400. SRB_HAInquiry s;
  186401. zerostruct (s);
  186402. s.SRB_Cmd = SC_HA_INQUIRY;
  186403. s.SRB_HaID = ha;
  186404. fSendASPI32Command ((LPSRB)&s);
  186405. if (s.SRB_Status == SS_COMP)
  186406. {
  186407. maxItems = (int)s.HA_Unique[3];
  186408. if (maxItems == 0)
  186409. maxItems = 8;
  186410. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186411. {
  186412. for (BYTE lun = 0; lun < 8; ++lun)
  186413. {
  186414. SRB_GDEVBlock sb;
  186415. zerostruct (sb);
  186416. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186417. sb.SRB_HaID = ha;
  186418. sb.SRB_Target = tgt;
  186419. sb.SRB_Lun = lun;
  186420. fSendASPI32Command ((LPSRB) &sb);
  186421. if (sb.SRB_Status == SS_COMP
  186422. && sb.SRB_DeviceType == DTYPE_CROM)
  186423. {
  186424. zeromem (&list[count], sizeof (CDDeviceInfo));
  186425. list[count].ha = ha;
  186426. list[count].tgt = tgt;
  186427. list[count].lun = lun;
  186428. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186429. ++count;
  186430. }
  186431. }
  186432. }
  186433. }
  186434. }
  186435. }
  186436. return count;
  186437. }
  186438. static int ripperUsers = 0;
  186439. static bool initialisedOk = false;
  186440. class DeinitialiseTimer : private Timer,
  186441. private DeletedAtShutdown
  186442. {
  186443. DeinitialiseTimer (const DeinitialiseTimer&);
  186444. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186445. public:
  186446. DeinitialiseTimer()
  186447. {
  186448. startTimer (4000);
  186449. }
  186450. ~DeinitialiseTimer()
  186451. {
  186452. if (--ripperUsers == 0)
  186453. DeinitialiseCDRipper();
  186454. }
  186455. void timerCallback()
  186456. {
  186457. delete this;
  186458. }
  186459. juce_UseDebuggingNewOperator
  186460. };
  186461. static void incUserCount()
  186462. {
  186463. if (ripperUsers++ == 0)
  186464. initialisedOk = InitialiseCDRipper();
  186465. }
  186466. static void decUserCount()
  186467. {
  186468. new DeinitialiseTimer();
  186469. }
  186470. struct CDDeviceWrapper
  186471. {
  186472. ScopedPointer<CDDeviceHandle> cdH;
  186473. ScopedPointer<CDReadBuffer> overlapBuffer;
  186474. bool jitter;
  186475. };
  186476. static int getAddressOf (const TOCTRACK* const t)
  186477. {
  186478. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  186479. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  186480. }
  186481. static int getMSFAddressOf (const TOCTRACK* const t)
  186482. {
  186483. return 60 * t->addr[1] + t->addr[2];
  186484. }
  186485. static const int samplesPerFrame = 44100 / 75;
  186486. static const int bytesPerFrame = samplesPerFrame * 4;
  186487. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  186488. {
  186489. SRB_GDEVBlock s;
  186490. zerostruct (s);
  186491. s.SRB_Cmd = SC_GET_DEV_TYPE;
  186492. s.SRB_HaID = device->ha;
  186493. s.SRB_Target = device->tgt;
  186494. s.SRB_Lun = device->lun;
  186495. if (usingScsi)
  186496. {
  186497. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  186498. if (h != INVALID_HANDLE_VALUE)
  186499. {
  186500. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  186501. cdh->scsiHandle = h;
  186502. return cdh;
  186503. }
  186504. }
  186505. else
  186506. {
  186507. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  186508. && s.SRB_DeviceType == DTYPE_CROM)
  186509. {
  186510. return new CDDeviceHandle (device);
  186511. }
  186512. }
  186513. return 0;
  186514. }
  186515. }
  186516. const StringArray AudioCDReader::getAvailableCDNames()
  186517. {
  186518. using namespace CDReaderHelpers;
  186519. StringArray results;
  186520. incUserCount();
  186521. if (initialisedOk)
  186522. {
  186523. CDDeviceInfo list[8];
  186524. const int num = FindCDDevices (list, 8);
  186525. decUserCount();
  186526. for (int i = 0; i < num; ++i)
  186527. {
  186528. String s;
  186529. if (list[i].scsiDriveLetter > 0)
  186530. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << ": ";
  186531. s << String (list[i].vendor).trim()
  186532. << ' ' << String (list[i].productId).trim()
  186533. << ' ' << String (list[i].rev).trim();
  186534. results.add (s);
  186535. }
  186536. }
  186537. return results;
  186538. }
  186539. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  186540. {
  186541. using namespace CDReaderHelpers;
  186542. incUserCount();
  186543. if (initialisedOk)
  186544. {
  186545. CDDeviceInfo list[8];
  186546. const int num = FindCDDevices (list, 8);
  186547. if (((unsigned int) deviceIndex) < (unsigned int) num)
  186548. {
  186549. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  186550. if (handle != 0)
  186551. {
  186552. CDDeviceWrapper* const d = new CDDeviceWrapper();
  186553. d->cdH = handle;
  186554. d->overlapBuffer = new CDReadBuffer(3);
  186555. return new AudioCDReader (d);
  186556. }
  186557. }
  186558. }
  186559. decUserCount();
  186560. return 0;
  186561. }
  186562. AudioCDReader::AudioCDReader (void* handle_)
  186563. : AudioFormatReader (0, "CD Audio"),
  186564. handle (handle_),
  186565. indexingEnabled (false),
  186566. lastIndex (0),
  186567. firstFrameInBuffer (0),
  186568. samplesInBuffer (0)
  186569. {
  186570. using namespace CDReaderHelpers;
  186571. jassert (handle_ != 0);
  186572. refreshTrackLengths();
  186573. sampleRate = 44100.0;
  186574. bitsPerSample = 16;
  186575. lengthInSamples = getPositionOfTrackStart (numTracks);
  186576. numChannels = 2;
  186577. usesFloatingPointData = false;
  186578. buffer.setSize (4 * bytesPerFrame, true);
  186579. }
  186580. AudioCDReader::~AudioCDReader()
  186581. {
  186582. using namespace CDReaderHelpers;
  186583. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186584. delete device;
  186585. decUserCount();
  186586. }
  186587. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  186588. int64 startSampleInFile, int numSamples)
  186589. {
  186590. using namespace CDReaderHelpers;
  186591. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186592. bool ok = true;
  186593. while (numSamples > 0)
  186594. {
  186595. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  186596. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  186597. if (startSampleInFile >= bufferStartSample
  186598. && startSampleInFile < bufferEndSample)
  186599. {
  186600. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  186601. int* const l = destSamples[0] + startOffsetInDestBuffer;
  186602. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186603. const short* src = (const short*) buffer.getData();
  186604. src += 2 * (startSampleInFile - bufferStartSample);
  186605. for (int i = 0; i < toDo; ++i)
  186606. {
  186607. l[i] = src [i << 1] << 16;
  186608. if (r != 0)
  186609. r[i] = src [(i << 1) + 1] << 16;
  186610. }
  186611. startOffsetInDestBuffer += toDo;
  186612. startSampleInFile += toDo;
  186613. numSamples -= toDo;
  186614. }
  186615. else
  186616. {
  186617. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  186618. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  186619. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  186620. {
  186621. device->overlapBuffer->dataLength = 0;
  186622. device->overlapBuffer->startFrame = 0;
  186623. device->overlapBuffer->numFrames = 0;
  186624. device->jitter = false;
  186625. }
  186626. firstFrameInBuffer = frameNeeded;
  186627. lastIndex = 0;
  186628. CDReadBuffer readBuffer (framesInBuffer + 4);
  186629. readBuffer.wantsIndex = indexingEnabled;
  186630. int i;
  186631. for (i = 5; --i >= 0;)
  186632. {
  186633. readBuffer.startFrame = frameNeeded;
  186634. readBuffer.numFrames = framesInBuffer;
  186635. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  186636. break;
  186637. else
  186638. device->overlapBuffer->dataLength = 0;
  186639. }
  186640. if (i >= 0)
  186641. {
  186642. memcpy ((char*) buffer.getData(),
  186643. readBuffer.buffer + readBuffer.dataStartOffset,
  186644. readBuffer.dataLength);
  186645. samplesInBuffer = readBuffer.dataLength >> 2;
  186646. lastIndex = readBuffer.index;
  186647. }
  186648. else
  186649. {
  186650. int* l = destSamples[0] + startOffsetInDestBuffer;
  186651. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186652. while (--numSamples >= 0)
  186653. {
  186654. *l++ = 0;
  186655. if (r != 0)
  186656. *r++ = 0;
  186657. }
  186658. // sometimes the read fails for just the very last couple of blocks, so
  186659. // we'll ignore and errors in the last half-second of the disk..
  186660. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  186661. break;
  186662. }
  186663. }
  186664. }
  186665. return ok;
  186666. }
  186667. bool AudioCDReader::isCDStillPresent() const
  186668. {
  186669. using namespace CDReaderHelpers;
  186670. TOC toc;
  186671. zerostruct (toc);
  186672. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  186673. }
  186674. int AudioCDReader::getNumTracks() const
  186675. {
  186676. return numTracks;
  186677. }
  186678. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  186679. {
  186680. using namespace CDReaderHelpers;
  186681. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  186682. : 0;
  186683. }
  186684. void AudioCDReader::refreshTrackLengths()
  186685. {
  186686. using namespace CDReaderHelpers;
  186687. zeromem (trackStarts, sizeof (trackStarts));
  186688. zeromem (audioTracks, sizeof (audioTracks));
  186689. TOC toc;
  186690. zerostruct (toc);
  186691. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  186692. {
  186693. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  186694. for (int i = 0; i <= numTracks; ++i)
  186695. {
  186696. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  186697. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  186698. }
  186699. }
  186700. else
  186701. {
  186702. numTracks = 0;
  186703. }
  186704. }
  186705. bool AudioCDReader::isTrackAudio (int trackNum) const
  186706. {
  186707. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  186708. : false;
  186709. }
  186710. void AudioCDReader::enableIndexScanning (bool b)
  186711. {
  186712. indexingEnabled = b;
  186713. }
  186714. int AudioCDReader::getLastIndex() const
  186715. {
  186716. return lastIndex;
  186717. }
  186718. const int framesPerIndexRead = 4;
  186719. int AudioCDReader::getIndexAt (int samplePos)
  186720. {
  186721. using namespace CDReaderHelpers;
  186722. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186723. const int frameNeeded = samplePos / samplesPerFrame;
  186724. device->overlapBuffer->dataLength = 0;
  186725. device->overlapBuffer->startFrame = 0;
  186726. device->overlapBuffer->numFrames = 0;
  186727. device->jitter = false;
  186728. firstFrameInBuffer = 0;
  186729. lastIndex = 0;
  186730. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  186731. readBuffer.wantsIndex = true;
  186732. int i;
  186733. for (i = 5; --i >= 0;)
  186734. {
  186735. readBuffer.startFrame = frameNeeded;
  186736. readBuffer.numFrames = framesPerIndexRead;
  186737. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  186738. break;
  186739. }
  186740. if (i >= 0)
  186741. return readBuffer.index;
  186742. return -1;
  186743. }
  186744. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  186745. {
  186746. using namespace CDReaderHelpers;
  186747. Array <int> indexes;
  186748. const int trackStart = getPositionOfTrackStart (trackNumber);
  186749. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  186750. bool needToScan = true;
  186751. if (trackEnd - trackStart > 20 * 44100)
  186752. {
  186753. // check the end of the track for indexes before scanning the whole thing
  186754. needToScan = false;
  186755. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  186756. bool seenAnIndex = false;
  186757. while (pos <= trackEnd - samplesPerFrame)
  186758. {
  186759. const int index = getIndexAt (pos);
  186760. if (index == 0)
  186761. {
  186762. // lead-out, so skip back a bit if we've not found any indexes yet..
  186763. if (seenAnIndex)
  186764. break;
  186765. pos -= 44100 * 5;
  186766. if (pos < trackStart)
  186767. break;
  186768. }
  186769. else
  186770. {
  186771. if (index > 0)
  186772. seenAnIndex = true;
  186773. if (index > 1)
  186774. {
  186775. needToScan = true;
  186776. break;
  186777. }
  186778. pos += samplesPerFrame * framesPerIndexRead;
  186779. }
  186780. }
  186781. }
  186782. if (needToScan)
  186783. {
  186784. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186785. int pos = trackStart;
  186786. int last = -1;
  186787. while (pos < trackEnd - samplesPerFrame * 10)
  186788. {
  186789. const int frameNeeded = pos / samplesPerFrame;
  186790. device->overlapBuffer->dataLength = 0;
  186791. device->overlapBuffer->startFrame = 0;
  186792. device->overlapBuffer->numFrames = 0;
  186793. device->jitter = false;
  186794. firstFrameInBuffer = 0;
  186795. CDReadBuffer readBuffer (4);
  186796. readBuffer.wantsIndex = true;
  186797. int i;
  186798. for (i = 5; --i >= 0;)
  186799. {
  186800. readBuffer.startFrame = frameNeeded;
  186801. readBuffer.numFrames = framesPerIndexRead;
  186802. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  186803. break;
  186804. }
  186805. if (i < 0)
  186806. break;
  186807. if (readBuffer.index > last && readBuffer.index > 1)
  186808. {
  186809. last = readBuffer.index;
  186810. indexes.add (pos);
  186811. }
  186812. pos += samplesPerFrame * framesPerIndexRead;
  186813. }
  186814. indexes.removeValue (trackStart);
  186815. }
  186816. return indexes;
  186817. }
  186818. int AudioCDReader::getCDDBId()
  186819. {
  186820. using namespace CDReaderHelpers;
  186821. refreshTrackLengths();
  186822. if (numTracks > 0)
  186823. {
  186824. TOC toc;
  186825. zerostruct (toc);
  186826. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  186827. {
  186828. int n = 0;
  186829. for (int i = numTracks; --i >= 0;)
  186830. {
  186831. int j = getMSFAddressOf (&toc.tracks[i]);
  186832. while (j > 0)
  186833. {
  186834. n += (j % 10);
  186835. j /= 10;
  186836. }
  186837. }
  186838. if (n != 0)
  186839. {
  186840. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  186841. - getMSFAddressOf (&toc.tracks[0]);
  186842. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  186843. }
  186844. }
  186845. }
  186846. return 0;
  186847. }
  186848. void AudioCDReader::ejectDisk()
  186849. {
  186850. using namespace CDReaderHelpers;
  186851. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  186852. }
  186853. #endif
  186854. #if JUCE_USE_CDBURNER
  186855. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  186856. {
  186857. CoInitialize (0);
  186858. IDiscMaster* dm;
  186859. IDiscRecorder* result = 0;
  186860. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  186861. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  186862. IID_IDiscMaster,
  186863. (void**) &dm)))
  186864. {
  186865. if (SUCCEEDED (dm->Open()))
  186866. {
  186867. IEnumDiscRecorders* drEnum = 0;
  186868. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  186869. {
  186870. IDiscRecorder* dr = 0;
  186871. DWORD dummy;
  186872. int index = 0;
  186873. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  186874. {
  186875. if (indexToOpen == index)
  186876. {
  186877. result = dr;
  186878. break;
  186879. }
  186880. else if (list != 0)
  186881. {
  186882. BSTR path;
  186883. if (SUCCEEDED (dr->GetPath (&path)))
  186884. list->add ((const WCHAR*) path);
  186885. }
  186886. ++index;
  186887. dr->Release();
  186888. }
  186889. drEnum->Release();
  186890. }
  186891. if (master == 0)
  186892. dm->Close();
  186893. }
  186894. if (master != 0)
  186895. *master = dm;
  186896. else
  186897. dm->Release();
  186898. }
  186899. return result;
  186900. }
  186901. class AudioCDBurner::Pimpl : public ComBaseClassHelper <IDiscMasterProgressEvents>,
  186902. public Timer
  186903. {
  186904. public:
  186905. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  186906. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  186907. listener (0), progress (0), shouldCancel (false)
  186908. {
  186909. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  186910. jassert (SUCCEEDED (hr));
  186911. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  186912. //jassert (SUCCEEDED (hr));
  186913. lastState = getDiskState();
  186914. startTimer (2000);
  186915. }
  186916. ~Pimpl() {}
  186917. void releaseObjects()
  186918. {
  186919. discRecorder->Close();
  186920. if (redbook != 0)
  186921. redbook->Release();
  186922. discRecorder->Release();
  186923. discMaster->Release();
  186924. Release();
  186925. }
  186926. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  186927. {
  186928. if (listener != 0 && ! shouldCancel)
  186929. shouldCancel = listener->audioCDBurnProgress (progress);
  186930. *pbCancel = shouldCancel;
  186931. return S_OK;
  186932. }
  186933. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  186934. {
  186935. progress = nCompleted / (float) nTotal;
  186936. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  186937. return E_NOTIMPL;
  186938. }
  186939. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  186940. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  186941. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  186942. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  186943. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  186944. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  186945. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  186946. class ScopedDiscOpener
  186947. {
  186948. public:
  186949. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  186950. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  186951. private:
  186952. Pimpl& pimpl;
  186953. ScopedDiscOpener (const ScopedDiscOpener&);
  186954. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  186955. };
  186956. DiskState getDiskState()
  186957. {
  186958. const ScopedDiscOpener opener (*this);
  186959. long type, flags;
  186960. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  186961. if (FAILED (hr))
  186962. return unknown;
  186963. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  186964. return writableDiskPresent;
  186965. if (type == 0)
  186966. return noDisc;
  186967. else
  186968. return readOnlyDiskPresent;
  186969. }
  186970. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  186971. {
  186972. ComSmartPtr<IPropertyStorage> prop;
  186973. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  186974. return defaultReturn;
  186975. PROPSPEC iPropSpec;
  186976. iPropSpec.ulKind = PRSPEC_LPWSTR;
  186977. iPropSpec.lpwstr = name;
  186978. PROPVARIANT iPropVariant;
  186979. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  186980. ? defaultReturn : (int) iPropVariant.lVal;
  186981. }
  186982. bool setIntProperty (const LPOLESTR name, const int value) const
  186983. {
  186984. ComSmartPtr<IPropertyStorage> prop;
  186985. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  186986. return false;
  186987. PROPSPEC iPropSpec;
  186988. iPropSpec.ulKind = PRSPEC_LPWSTR;
  186989. iPropSpec.lpwstr = name;
  186990. PROPVARIANT iPropVariant;
  186991. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  186992. return false;
  186993. iPropVariant.lVal = (long) value;
  186994. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  186995. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  186996. }
  186997. void timerCallback()
  186998. {
  186999. const DiskState state = getDiskState();
  187000. if (state != lastState)
  187001. {
  187002. lastState = state;
  187003. owner.sendChangeMessage (&owner);
  187004. }
  187005. }
  187006. AudioCDBurner& owner;
  187007. DiskState lastState;
  187008. IDiscMaster* discMaster;
  187009. IDiscRecorder* discRecorder;
  187010. IRedbookDiscMaster* redbook;
  187011. AudioCDBurner::BurnProgressListener* listener;
  187012. float progress;
  187013. bool shouldCancel;
  187014. };
  187015. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187016. {
  187017. IDiscMaster* discMaster = 0;
  187018. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187019. if (discRecorder != 0)
  187020. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187021. }
  187022. AudioCDBurner::~AudioCDBurner()
  187023. {
  187024. if (pimpl != 0)
  187025. pimpl.release()->releaseObjects();
  187026. }
  187027. const StringArray AudioCDBurner::findAvailableDevices()
  187028. {
  187029. StringArray devs;
  187030. enumCDBurners (&devs, -1, 0);
  187031. return devs;
  187032. }
  187033. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187034. {
  187035. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187036. if (b->pimpl == 0)
  187037. b = 0;
  187038. return b.release();
  187039. }
  187040. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187041. {
  187042. return pimpl->getDiskState();
  187043. }
  187044. bool AudioCDBurner::isDiskPresent() const
  187045. {
  187046. return getDiskState() == writableDiskPresent;
  187047. }
  187048. bool AudioCDBurner::openTray()
  187049. {
  187050. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187051. return SUCCEEDED (pimpl->discRecorder->Eject());
  187052. }
  187053. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187054. {
  187055. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187056. DiskState oldState = getDiskState();
  187057. DiskState newState = oldState;
  187058. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187059. {
  187060. newState = getDiskState();
  187061. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187062. }
  187063. return newState;
  187064. }
  187065. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187066. {
  187067. Array<int> results;
  187068. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187069. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187070. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187071. if (speeds[i] <= maxSpeed)
  187072. results.add (speeds[i]);
  187073. results.addIfNotAlreadyThere (maxSpeed);
  187074. return results;
  187075. }
  187076. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187077. {
  187078. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187079. return false;
  187080. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187081. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187082. }
  187083. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187084. {
  187085. long blocksFree = 0;
  187086. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187087. return blocksFree;
  187088. }
  187089. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187090. bool performFakeBurnForTesting, int writeSpeed)
  187091. {
  187092. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187093. pimpl->listener = listener;
  187094. pimpl->progress = 0;
  187095. pimpl->shouldCancel = false;
  187096. UINT_PTR cookie;
  187097. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187098. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187099. ejectDiscAfterwards);
  187100. String error;
  187101. if (hr != S_OK)
  187102. {
  187103. const char* e = "Couldn't open or write to the CD device";
  187104. if (hr == IMAPI_E_USERABORT)
  187105. e = "User cancelled the write operation";
  187106. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187107. e = "No Disk present";
  187108. error = e;
  187109. }
  187110. pimpl->discMaster->ProgressUnadvise (cookie);
  187111. pimpl->listener = 0;
  187112. return error;
  187113. }
  187114. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187115. {
  187116. if (audioSource == 0)
  187117. return false;
  187118. ScopedPointer<AudioSource> source (audioSource);
  187119. long bytesPerBlock;
  187120. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187121. const int samplesPerBlock = bytesPerBlock / 4;
  187122. bool ok = true;
  187123. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187124. HeapBlock <byte> buffer (bytesPerBlock);
  187125. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187126. int samplesDone = 0;
  187127. source->prepareToPlay (samplesPerBlock, 44100.0);
  187128. while (ok)
  187129. {
  187130. {
  187131. AudioSourceChannelInfo info;
  187132. info.buffer = &sourceBuffer;
  187133. info.numSamples = samplesPerBlock;
  187134. info.startSample = 0;
  187135. sourceBuffer.clear();
  187136. source->getNextAudioBlock (info);
  187137. }
  187138. zeromem (buffer, bytesPerBlock);
  187139. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187140. buffer, samplesPerBlock, 4);
  187141. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187142. buffer + 2, samplesPerBlock, 4);
  187143. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187144. if (FAILED (hr))
  187145. ok = false;
  187146. samplesDone += samplesPerBlock;
  187147. if (samplesDone >= numSamples)
  187148. break;
  187149. }
  187150. hr = pimpl->redbook->CloseAudioTrack();
  187151. return ok && hr == S_OK;
  187152. }
  187153. #endif
  187154. #endif
  187155. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187156. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187157. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187158. // compiled on its own).
  187159. #if JUCE_INCLUDED_FILE
  187160. using ::free;
  187161. namespace MidiConstants
  187162. {
  187163. static const int midiBufferSize = 1024 * 10;
  187164. static const int numInHeaders = 32;
  187165. static const int inBufferSize = 256;
  187166. }
  187167. class MidiInThread : public Thread
  187168. {
  187169. public:
  187170. MidiInThread (MidiInput* const input_,
  187171. MidiInputCallback* const callback_)
  187172. : Thread ("Juce Midi"),
  187173. hIn (0),
  187174. input (input_),
  187175. callback (callback_),
  187176. isStarted (false),
  187177. startTime (0),
  187178. pendingLength(0)
  187179. {
  187180. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187181. {
  187182. zeromem (&hdr[i], sizeof (MIDIHDR));
  187183. hdr[i].lpData = inData[i];
  187184. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187185. }
  187186. };
  187187. ~MidiInThread()
  187188. {
  187189. stop();
  187190. if (hIn != 0)
  187191. {
  187192. int count = 5;
  187193. while (--count >= 0)
  187194. {
  187195. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187196. break;
  187197. Sleep (20);
  187198. }
  187199. }
  187200. }
  187201. void handle (const uint32 message, const uint32 timeStamp) throw()
  187202. {
  187203. const int byte = message & 0xff;
  187204. if (byte < 0x80)
  187205. return;
  187206. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187207. const double time = timeStampToTime (timeStamp);
  187208. {
  187209. const ScopedLock sl (lock);
  187210. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187211. {
  187212. char* const p = pending + pendingLength;
  187213. *(double*) p = time;
  187214. *(uint32*) (p + 8) = numBytes;
  187215. *(uint32*) (p + 12) = message;
  187216. pendingLength += 12 + numBytes;
  187217. }
  187218. else
  187219. {
  187220. jassertfalse // midi buffer overflow! You might need to increase the size..
  187221. }
  187222. }
  187223. notify();
  187224. }
  187225. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187226. {
  187227. const int num = hdr->dwBytesRecorded;
  187228. if (num > 0)
  187229. {
  187230. const double time = timeStampToTime (timeStamp);
  187231. {
  187232. const ScopedLock sl (lock);
  187233. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187234. {
  187235. char* const p = pending + pendingLength;
  187236. *(double*) p = time;
  187237. *(uint32*) (p + 8) = num;
  187238. memcpy (p + 12, hdr->lpData, num);
  187239. pendingLength += 12 + num;
  187240. }
  187241. else
  187242. {
  187243. jassertfalse // midi buffer overflow! You might need to increase the size..
  187244. }
  187245. }
  187246. notify();
  187247. }
  187248. }
  187249. void writeBlock (const int i) throw()
  187250. {
  187251. hdr[i].dwBytesRecorded = 0;
  187252. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187253. jassert (res == MMSYSERR_NOERROR);
  187254. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187255. jassert (res == MMSYSERR_NOERROR);
  187256. }
  187257. void run()
  187258. {
  187259. MemoryBlock pendingCopy (64);
  187260. while (! threadShouldExit())
  187261. {
  187262. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187263. {
  187264. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187265. {
  187266. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187267. (void) res;
  187268. jassert (res == MMSYSERR_NOERROR);
  187269. writeBlock (i);
  187270. }
  187271. }
  187272. int len;
  187273. {
  187274. const ScopedLock sl (lock);
  187275. len = pendingLength;
  187276. if (len > 0)
  187277. {
  187278. pendingCopy.ensureSize (len);
  187279. pendingCopy.copyFrom (pending, 0, len);
  187280. pendingLength = 0;
  187281. }
  187282. }
  187283. //xxx needs to figure out if blocks are broken up or not
  187284. if (len == 0)
  187285. {
  187286. wait (500);
  187287. }
  187288. else
  187289. {
  187290. const char* p = (const char*) pendingCopy.getData();
  187291. while (len > 0)
  187292. {
  187293. const double time = *(const double*) p;
  187294. const int messageLen = *(const int*) (p + 8);
  187295. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187296. callback->handleIncomingMidiMessage (input, message);
  187297. p += 12 + messageLen;
  187298. len -= 12 + messageLen;
  187299. }
  187300. }
  187301. }
  187302. }
  187303. void start() throw()
  187304. {
  187305. jassert (hIn != 0);
  187306. if (hIn != 0 && ! isStarted)
  187307. {
  187308. stop();
  187309. activeMidiThreads.addIfNotAlreadyThere (this);
  187310. int i;
  187311. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187312. writeBlock (i);
  187313. startTime = Time::getMillisecondCounter();
  187314. MMRESULT res = midiInStart (hIn);
  187315. jassert (res == MMSYSERR_NOERROR);
  187316. if (res == MMSYSERR_NOERROR)
  187317. {
  187318. isStarted = true;
  187319. pendingLength = 0;
  187320. startThread (6);
  187321. }
  187322. }
  187323. }
  187324. void stop() throw()
  187325. {
  187326. if (isStarted)
  187327. {
  187328. stopThread (5000);
  187329. midiInReset (hIn);
  187330. midiInStop (hIn);
  187331. activeMidiThreads.removeValue (this);
  187332. { const ScopedLock sl (lock); }
  187333. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187334. {
  187335. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187336. {
  187337. int c = 10;
  187338. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187339. Sleep (20);
  187340. jassert (c >= 0);
  187341. }
  187342. }
  187343. isStarted = false;
  187344. pendingLength = 0;
  187345. }
  187346. }
  187347. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187348. {
  187349. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187350. if (thread != 0 && activeMidiThreads.contains (thread))
  187351. {
  187352. if (uMsg == MIM_DATA)
  187353. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187354. else if (uMsg == MIM_LONGDATA)
  187355. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187356. }
  187357. }
  187358. juce_UseDebuggingNewOperator
  187359. HMIDIIN hIn;
  187360. private:
  187361. static Array <void*, CriticalSection> activeMidiThreads;
  187362. MidiInput* input;
  187363. MidiInputCallback* callback;
  187364. bool isStarted;
  187365. uint32 startTime;
  187366. CriticalSection lock;
  187367. MIDIHDR hdr [MidiConstants::numInHeaders];
  187368. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187369. int pendingLength;
  187370. char pending [MidiConstants::midiBufferSize];
  187371. double timeStampToTime (uint32 timeStamp) throw()
  187372. {
  187373. timeStamp += startTime;
  187374. const uint32 now = Time::getMillisecondCounter();
  187375. if (timeStamp > now)
  187376. {
  187377. if (timeStamp > now + 2)
  187378. --startTime;
  187379. timeStamp = now;
  187380. }
  187381. return 0.001 * timeStamp;
  187382. }
  187383. MidiInThread (const MidiInThread&);
  187384. MidiInThread& operator= (const MidiInThread&);
  187385. };
  187386. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187387. const StringArray MidiInput::getDevices()
  187388. {
  187389. StringArray s;
  187390. const int num = midiInGetNumDevs();
  187391. for (int i = 0; i < num; ++i)
  187392. {
  187393. MIDIINCAPS mc;
  187394. zerostruct (mc);
  187395. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187396. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187397. }
  187398. return s;
  187399. }
  187400. int MidiInput::getDefaultDeviceIndex()
  187401. {
  187402. return 0;
  187403. }
  187404. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187405. {
  187406. if (callback == 0)
  187407. return 0;
  187408. UINT deviceId = MIDI_MAPPER;
  187409. int n = 0;
  187410. String name;
  187411. const int num = midiInGetNumDevs();
  187412. for (int i = 0; i < num; ++i)
  187413. {
  187414. MIDIINCAPS mc;
  187415. zerostruct (mc);
  187416. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187417. {
  187418. if (index == n)
  187419. {
  187420. deviceId = i;
  187421. name = String (mc.szPname, sizeof (mc.szPname));
  187422. break;
  187423. }
  187424. ++n;
  187425. }
  187426. }
  187427. ScopedPointer <MidiInput> in (new MidiInput (name));
  187428. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187429. HMIDIIN h;
  187430. HRESULT err = midiInOpen (&h, deviceId,
  187431. (DWORD_PTR) &MidiInThread::midiInCallback,
  187432. (DWORD_PTR) (MidiInThread*) thread,
  187433. CALLBACK_FUNCTION);
  187434. if (err == MMSYSERR_NOERROR)
  187435. {
  187436. thread->hIn = h;
  187437. in->internal = thread.release();
  187438. return in.release();
  187439. }
  187440. return 0;
  187441. }
  187442. MidiInput::MidiInput (const String& name_)
  187443. : name (name_),
  187444. internal (0)
  187445. {
  187446. }
  187447. MidiInput::~MidiInput()
  187448. {
  187449. delete static_cast <MidiInThread*> (internal);
  187450. }
  187451. void MidiInput::start()
  187452. {
  187453. static_cast <MidiInThread*> (internal)->start();
  187454. }
  187455. void MidiInput::stop()
  187456. {
  187457. static_cast <MidiInThread*> (internal)->stop();
  187458. }
  187459. struct MidiOutHandle
  187460. {
  187461. int refCount;
  187462. UINT deviceId;
  187463. HMIDIOUT handle;
  187464. static Array<MidiOutHandle*> activeHandles;
  187465. juce_UseDebuggingNewOperator
  187466. };
  187467. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  187468. const StringArray MidiOutput::getDevices()
  187469. {
  187470. StringArray s;
  187471. const int num = midiOutGetNumDevs();
  187472. for (int i = 0; i < num; ++i)
  187473. {
  187474. MIDIOUTCAPS mc;
  187475. zerostruct (mc);
  187476. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187477. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187478. }
  187479. return s;
  187480. }
  187481. int MidiOutput::getDefaultDeviceIndex()
  187482. {
  187483. const int num = midiOutGetNumDevs();
  187484. int n = 0;
  187485. for (int i = 0; i < num; ++i)
  187486. {
  187487. MIDIOUTCAPS mc;
  187488. zerostruct (mc);
  187489. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187490. {
  187491. if ((mc.wTechnology & MOD_MAPPER) != 0)
  187492. return n;
  187493. ++n;
  187494. }
  187495. }
  187496. return 0;
  187497. }
  187498. MidiOutput* MidiOutput::openDevice (int index)
  187499. {
  187500. UINT deviceId = MIDI_MAPPER;
  187501. const int num = midiOutGetNumDevs();
  187502. int i, n = 0;
  187503. for (i = 0; i < num; ++i)
  187504. {
  187505. MIDIOUTCAPS mc;
  187506. zerostruct (mc);
  187507. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187508. {
  187509. // use the microsoft sw synth as a default - best not to allow deviceId
  187510. // to be MIDI_MAPPER, or else device sharing breaks
  187511. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase ("microsoft"))
  187512. deviceId = i;
  187513. if (index == n)
  187514. {
  187515. deviceId = i;
  187516. break;
  187517. }
  187518. ++n;
  187519. }
  187520. }
  187521. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  187522. {
  187523. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  187524. if (han != 0 && han->deviceId == deviceId)
  187525. {
  187526. han->refCount++;
  187527. MidiOutput* const out = new MidiOutput();
  187528. out->internal = han;
  187529. return out;
  187530. }
  187531. }
  187532. for (i = 4; --i >= 0;)
  187533. {
  187534. HMIDIOUT h = 0;
  187535. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  187536. if (res == MMSYSERR_NOERROR)
  187537. {
  187538. MidiOutHandle* const han = new MidiOutHandle();
  187539. han->deviceId = deviceId;
  187540. han->refCount = 1;
  187541. han->handle = h;
  187542. MidiOutHandle::activeHandles.add (han);
  187543. MidiOutput* const out = new MidiOutput();
  187544. out->internal = han;
  187545. return out;
  187546. }
  187547. else if (res == MMSYSERR_ALLOCATED)
  187548. {
  187549. Sleep (100);
  187550. }
  187551. else
  187552. {
  187553. break;
  187554. }
  187555. }
  187556. return 0;
  187557. }
  187558. MidiOutput::~MidiOutput()
  187559. {
  187560. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  187561. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  187562. {
  187563. midiOutClose (h->handle);
  187564. MidiOutHandle::activeHandles.removeValue (h);
  187565. delete h;
  187566. }
  187567. }
  187568. void MidiOutput::reset()
  187569. {
  187570. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  187571. midiOutReset (h->handle);
  187572. }
  187573. bool MidiOutput::getVolume (float& leftVol,
  187574. float& rightVol)
  187575. {
  187576. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187577. DWORD n;
  187578. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  187579. {
  187580. const unsigned short* const nn = (const unsigned short*) &n;
  187581. rightVol = nn[0] / (float) 0xffff;
  187582. leftVol = nn[1] / (float) 0xffff;
  187583. return true;
  187584. }
  187585. else
  187586. {
  187587. rightVol = leftVol = 1.0f;
  187588. return false;
  187589. }
  187590. }
  187591. void MidiOutput::setVolume (float leftVol,
  187592. float rightVol)
  187593. {
  187594. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  187595. DWORD n;
  187596. unsigned short* const nn = (unsigned short*) &n;
  187597. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  187598. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  187599. midiOutSetVolume (handle->handle, n);
  187600. }
  187601. void MidiOutput::sendMessageNow (const MidiMessage& message)
  187602. {
  187603. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187604. if (message.getRawDataSize() > 3
  187605. || message.isSysEx())
  187606. {
  187607. MIDIHDR h;
  187608. zerostruct (h);
  187609. h.lpData = (char*) message.getRawData();
  187610. h.dwBufferLength = message.getRawDataSize();
  187611. h.dwBytesRecorded = message.getRawDataSize();
  187612. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  187613. {
  187614. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  187615. if (res == MMSYSERR_NOERROR)
  187616. {
  187617. while ((h.dwFlags & MHDR_DONE) == 0)
  187618. Sleep (1);
  187619. int count = 500; // 1 sec timeout
  187620. while (--count >= 0)
  187621. {
  187622. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  187623. if (res == MIDIERR_STILLPLAYING)
  187624. Sleep (2);
  187625. else
  187626. break;
  187627. }
  187628. }
  187629. }
  187630. }
  187631. else
  187632. {
  187633. midiOutShortMsg (handle->handle,
  187634. *(unsigned int*) message.getRawData());
  187635. }
  187636. }
  187637. #endif
  187638. /*** End of inlined file: juce_win32_Midi.cpp ***/
  187639. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  187640. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187641. // compiled on its own).
  187642. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  187643. #undef WINDOWS
  187644. // #define ASIO_DEBUGGING
  187645. #ifdef ASIO_DEBUGGING
  187646. #define log(a) { Logger::writeToLog (a); DBG (a) }
  187647. #else
  187648. #define log(a) {}
  187649. #endif
  187650. #ifdef ASIO_DEBUGGING
  187651. static void logError (const String& context, long error)
  187652. {
  187653. String err ("unknown error");
  187654. if (error == ASE_NotPresent)
  187655. err = "Not Present";
  187656. else if (error == ASE_HWMalfunction)
  187657. err = "Hardware Malfunction";
  187658. else if (error == ASE_InvalidParameter)
  187659. err = "Invalid Parameter";
  187660. else if (error == ASE_InvalidMode)
  187661. err = "Invalid Mode";
  187662. else if (error == ASE_SPNotAdvancing)
  187663. err = "Sample position not advancing";
  187664. else if (error == ASE_NoClock)
  187665. err = "No Clock";
  187666. else if (error == ASE_NoMemory)
  187667. err = "Out of memory";
  187668. log ("!!error: " + context + " - " + err);
  187669. }
  187670. #else
  187671. #define logError(a, b) {}
  187672. #endif
  187673. class ASIOAudioIODevice;
  187674. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  187675. static const int maxASIOChannels = 160;
  187676. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  187677. private Timer
  187678. {
  187679. public:
  187680. Component ourWindow;
  187681. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  187682. const String& optionalDllForDirectLoading_)
  187683. : AudioIODevice (name_, "ASIO"),
  187684. asioObject (0),
  187685. classId (classId_),
  187686. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  187687. currentBitDepth (16),
  187688. currentSampleRate (0),
  187689. isOpen_ (false),
  187690. isStarted (false),
  187691. postOutput (true),
  187692. insideControlPanelModalLoop (false),
  187693. shouldUsePreferredSize (false)
  187694. {
  187695. name = name_;
  187696. ourWindow.addToDesktop (0);
  187697. windowHandle = ourWindow.getWindowHandle();
  187698. jassert (currentASIODev [slotNumber] == 0);
  187699. currentASIODev [slotNumber] = this;
  187700. openDevice();
  187701. }
  187702. ~ASIOAudioIODevice()
  187703. {
  187704. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  187705. if (currentASIODev[i] == this)
  187706. currentASIODev[i] = 0;
  187707. close();
  187708. log ("ASIO - exiting");
  187709. removeCurrentDriver();
  187710. }
  187711. void updateSampleRates()
  187712. {
  187713. // find a list of sample rates..
  187714. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  187715. sampleRates.clear();
  187716. if (asioObject != 0)
  187717. {
  187718. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  187719. {
  187720. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  187721. if (err == 0)
  187722. {
  187723. sampleRates.add ((int) possibleSampleRates[index]);
  187724. log ("rate: " + String ((int) possibleSampleRates[index]));
  187725. }
  187726. else if (err != ASE_NoClock)
  187727. {
  187728. logError ("CanSampleRate", err);
  187729. }
  187730. }
  187731. if (sampleRates.size() == 0)
  187732. {
  187733. double cr = 0;
  187734. const long err = asioObject->getSampleRate (&cr);
  187735. log ("No sample rates supported - current rate: " + String ((int) cr));
  187736. if (err == 0)
  187737. sampleRates.add ((int) cr);
  187738. }
  187739. }
  187740. }
  187741. const StringArray getOutputChannelNames()
  187742. {
  187743. return outputChannelNames;
  187744. }
  187745. const StringArray getInputChannelNames()
  187746. {
  187747. return inputChannelNames;
  187748. }
  187749. int getNumSampleRates()
  187750. {
  187751. return sampleRates.size();
  187752. }
  187753. double getSampleRate (int index)
  187754. {
  187755. return sampleRates [index];
  187756. }
  187757. int getNumBufferSizesAvailable()
  187758. {
  187759. return bufferSizes.size();
  187760. }
  187761. int getBufferSizeSamples (int index)
  187762. {
  187763. return bufferSizes [index];
  187764. }
  187765. int getDefaultBufferSize()
  187766. {
  187767. return preferredSize;
  187768. }
  187769. const String open (const BigInteger& inputChannels,
  187770. const BigInteger& outputChannels,
  187771. double sr,
  187772. int bufferSizeSamples)
  187773. {
  187774. close();
  187775. currentCallback = 0;
  187776. if (bufferSizeSamples <= 0)
  187777. shouldUsePreferredSize = true;
  187778. if (asioObject == 0 || ! isASIOOpen)
  187779. {
  187780. log ("Warning: device not open");
  187781. const String err (openDevice());
  187782. if (asioObject == 0 || ! isASIOOpen)
  187783. return err;
  187784. }
  187785. isStarted = false;
  187786. bufferIndex = -1;
  187787. long err = 0;
  187788. long newPreferredSize = 0;
  187789. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  187790. minSize = 0;
  187791. maxSize = 0;
  187792. newPreferredSize = 0;
  187793. granularity = 0;
  187794. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  187795. {
  187796. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  187797. shouldUsePreferredSize = true;
  187798. preferredSize = newPreferredSize;
  187799. }
  187800. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  187801. // dynamic changes to the buffer size...
  187802. shouldUsePreferredSize = shouldUsePreferredSize
  187803. || getName().containsIgnoreCase ("Digidesign");
  187804. if (shouldUsePreferredSize)
  187805. {
  187806. log ("Using preferred size for buffer..");
  187807. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  187808. {
  187809. bufferSizeSamples = preferredSize;
  187810. }
  187811. else
  187812. {
  187813. bufferSizeSamples = 1024;
  187814. logError ("GetBufferSize1", err);
  187815. }
  187816. shouldUsePreferredSize = false;
  187817. }
  187818. int sampleRate = roundDoubleToInt (sr);
  187819. currentSampleRate = sampleRate;
  187820. currentBlockSizeSamples = bufferSizeSamples;
  187821. currentChansOut.clear();
  187822. currentChansIn.clear();
  187823. zeromem (inBuffers, sizeof (inBuffers));
  187824. zeromem (outBuffers, sizeof (outBuffers));
  187825. updateSampleRates();
  187826. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  187827. sampleRate = sampleRates[0];
  187828. jassert (sampleRate != 0);
  187829. if (sampleRate == 0)
  187830. sampleRate = 44100;
  187831. long numSources = 32;
  187832. ASIOClockSource clocks[32];
  187833. zeromem (clocks, sizeof (clocks));
  187834. asioObject->getClockSources (clocks, &numSources);
  187835. bool isSourceSet = false;
  187836. // careful not to remove this loop because it does more than just logging!
  187837. int i;
  187838. for (i = 0; i < numSources; ++i)
  187839. {
  187840. String s ("clock: ");
  187841. s += clocks[i].name;
  187842. if (clocks[i].isCurrentSource)
  187843. {
  187844. isSourceSet = true;
  187845. s << " (cur)";
  187846. }
  187847. log (s);
  187848. }
  187849. if (numSources > 1 && ! isSourceSet)
  187850. {
  187851. log ("setting clock source");
  187852. asioObject->setClockSource (clocks[0].index);
  187853. Thread::sleep (20);
  187854. }
  187855. else
  187856. {
  187857. if (numSources == 0)
  187858. {
  187859. log ("ASIO - no clock sources!");
  187860. }
  187861. }
  187862. double cr = 0;
  187863. err = asioObject->getSampleRate (&cr);
  187864. if (err == 0)
  187865. {
  187866. currentSampleRate = cr;
  187867. }
  187868. else
  187869. {
  187870. logError ("GetSampleRate", err);
  187871. currentSampleRate = 0;
  187872. }
  187873. error = String::empty;
  187874. needToReset = false;
  187875. isReSync = false;
  187876. err = 0;
  187877. bool buffersCreated = false;
  187878. if (currentSampleRate != sampleRate)
  187879. {
  187880. log ("ASIO samplerate: " + String (currentSampleRate) + " to " + String (sampleRate));
  187881. err = asioObject->setSampleRate (sampleRate);
  187882. if (err == ASE_NoClock && numSources > 0)
  187883. {
  187884. log ("trying to set a clock source..");
  187885. Thread::sleep (10);
  187886. err = asioObject->setClockSource (clocks[0].index);
  187887. if (err != 0)
  187888. {
  187889. logError ("SetClock", err);
  187890. }
  187891. Thread::sleep (10);
  187892. err = asioObject->setSampleRate (sampleRate);
  187893. }
  187894. }
  187895. if (err == 0)
  187896. {
  187897. currentSampleRate = sampleRate;
  187898. if (needToReset)
  187899. {
  187900. if (isReSync)
  187901. {
  187902. log ("Resync request");
  187903. }
  187904. log ("! Resetting ASIO after sample rate change");
  187905. removeCurrentDriver();
  187906. loadDriver();
  187907. const String error (initDriver());
  187908. if (error.isNotEmpty())
  187909. {
  187910. log ("ASIOInit: " + error);
  187911. }
  187912. needToReset = false;
  187913. isReSync = false;
  187914. }
  187915. numActiveInputChans = 0;
  187916. numActiveOutputChans = 0;
  187917. ASIOBufferInfo* info = bufferInfos;
  187918. int i;
  187919. for (i = 0; i < totalNumInputChans; ++i)
  187920. {
  187921. if (inputChannels[i])
  187922. {
  187923. currentChansIn.setBit (i);
  187924. info->isInput = 1;
  187925. info->channelNum = i;
  187926. info->buffers[0] = info->buffers[1] = 0;
  187927. ++info;
  187928. ++numActiveInputChans;
  187929. }
  187930. }
  187931. for (i = 0; i < totalNumOutputChans; ++i)
  187932. {
  187933. if (outputChannels[i])
  187934. {
  187935. currentChansOut.setBit (i);
  187936. info->isInput = 0;
  187937. info->channelNum = i;
  187938. info->buffers[0] = info->buffers[1] = 0;
  187939. ++info;
  187940. ++numActiveOutputChans;
  187941. }
  187942. }
  187943. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  187944. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  187945. if (currentASIODev[0] == this)
  187946. {
  187947. callbacks.bufferSwitch = &bufferSwitchCallback0;
  187948. callbacks.asioMessage = &asioMessagesCallback0;
  187949. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  187950. }
  187951. else if (currentASIODev[1] == this)
  187952. {
  187953. callbacks.bufferSwitch = &bufferSwitchCallback1;
  187954. callbacks.asioMessage = &asioMessagesCallback1;
  187955. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  187956. }
  187957. else if (currentASIODev[2] == this)
  187958. {
  187959. callbacks.bufferSwitch = &bufferSwitchCallback2;
  187960. callbacks.asioMessage = &asioMessagesCallback2;
  187961. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  187962. }
  187963. else
  187964. {
  187965. jassertfalse
  187966. }
  187967. log ("disposing buffers");
  187968. err = asioObject->disposeBuffers();
  187969. log ("creating buffers: " + String (totalBuffers) + ", " + String (currentBlockSizeSamples));
  187970. err = asioObject->createBuffers (bufferInfos,
  187971. totalBuffers,
  187972. currentBlockSizeSamples,
  187973. &callbacks);
  187974. if (err != 0)
  187975. {
  187976. currentBlockSizeSamples = preferredSize;
  187977. logError ("create buffers 2", err);
  187978. asioObject->disposeBuffers();
  187979. err = asioObject->createBuffers (bufferInfos,
  187980. totalBuffers,
  187981. currentBlockSizeSamples,
  187982. &callbacks);
  187983. }
  187984. if (err == 0)
  187985. {
  187986. buffersCreated = true;
  187987. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  187988. int n = 0;
  187989. Array <int> types;
  187990. currentBitDepth = 16;
  187991. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  187992. {
  187993. if (inputChannels[i])
  187994. {
  187995. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  187996. ASIOChannelInfo channelInfo;
  187997. zerostruct (channelInfo);
  187998. channelInfo.channel = i;
  187999. channelInfo.isInput = 1;
  188000. asioObject->getChannelInfo (&channelInfo);
  188001. types.addIfNotAlreadyThere (channelInfo.type);
  188002. typeToFormatParameters (channelInfo.type,
  188003. inputChannelBitDepths[n],
  188004. inputChannelBytesPerSample[n],
  188005. inputChannelIsFloat[n],
  188006. inputChannelLittleEndian[n]);
  188007. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188008. ++n;
  188009. }
  188010. }
  188011. jassert (numActiveInputChans == n);
  188012. n = 0;
  188013. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188014. {
  188015. if (outputChannels[i])
  188016. {
  188017. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188018. ASIOChannelInfo channelInfo;
  188019. zerostruct (channelInfo);
  188020. channelInfo.channel = i;
  188021. channelInfo.isInput = 0;
  188022. asioObject->getChannelInfo (&channelInfo);
  188023. types.addIfNotAlreadyThere (channelInfo.type);
  188024. typeToFormatParameters (channelInfo.type,
  188025. outputChannelBitDepths[n],
  188026. outputChannelBytesPerSample[n],
  188027. outputChannelIsFloat[n],
  188028. outputChannelLittleEndian[n]);
  188029. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188030. ++n;
  188031. }
  188032. }
  188033. jassert (numActiveOutputChans == n);
  188034. for (i = types.size(); --i >= 0;)
  188035. {
  188036. log ("channel format: " + String (types[i]));
  188037. }
  188038. jassert (n <= totalBuffers);
  188039. for (i = 0; i < numActiveOutputChans; ++i)
  188040. {
  188041. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188042. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188043. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188044. {
  188045. log ("!! Null buffers");
  188046. }
  188047. else
  188048. {
  188049. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188050. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188051. }
  188052. }
  188053. inputLatency = outputLatency = 0;
  188054. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188055. {
  188056. log ("ASIO - no latencies");
  188057. }
  188058. else
  188059. {
  188060. log ("ASIO latencies: " + String ((int) outputLatency) + ", " + String ((int) inputLatency));
  188061. }
  188062. isOpen_ = true;
  188063. log ("starting ASIO");
  188064. calledback = false;
  188065. err = asioObject->start();
  188066. if (err != 0)
  188067. {
  188068. isOpen_ = false;
  188069. log ("ASIO - stop on failure");
  188070. Thread::sleep (10);
  188071. asioObject->stop();
  188072. error = "Can't start device";
  188073. Thread::sleep (10);
  188074. }
  188075. else
  188076. {
  188077. int count = 300;
  188078. while (--count > 0 && ! calledback)
  188079. Thread::sleep (10);
  188080. isStarted = true;
  188081. if (! calledback)
  188082. {
  188083. error = "Device didn't start correctly";
  188084. log ("ASIO didn't callback - stopping..");
  188085. asioObject->stop();
  188086. }
  188087. }
  188088. }
  188089. else
  188090. {
  188091. error = "Can't create i/o buffers";
  188092. }
  188093. }
  188094. else
  188095. {
  188096. error = "Can't set sample rate: ";
  188097. error << sampleRate;
  188098. }
  188099. if (error.isNotEmpty())
  188100. {
  188101. logError (error, err);
  188102. if (asioObject != 0 && buffersCreated)
  188103. asioObject->disposeBuffers();
  188104. Thread::sleep (20);
  188105. isStarted = false;
  188106. isOpen_ = false;
  188107. close();
  188108. }
  188109. needToReset = false;
  188110. isReSync = false;
  188111. return error;
  188112. }
  188113. void close()
  188114. {
  188115. error = String::empty;
  188116. stopTimer();
  188117. stop();
  188118. if (isASIOOpen && isOpen_)
  188119. {
  188120. const ScopedLock sl (callbackLock);
  188121. isOpen_ = false;
  188122. isStarted = false;
  188123. needToReset = false;
  188124. isReSync = false;
  188125. log ("ASIO - stopping");
  188126. if (asioObject != 0)
  188127. {
  188128. Thread::sleep (20);
  188129. asioObject->stop();
  188130. Thread::sleep (10);
  188131. asioObject->disposeBuffers();
  188132. }
  188133. Thread::sleep (10);
  188134. }
  188135. }
  188136. bool isOpen()
  188137. {
  188138. return isOpen_ || insideControlPanelModalLoop;
  188139. }
  188140. int getCurrentBufferSizeSamples()
  188141. {
  188142. return currentBlockSizeSamples;
  188143. }
  188144. double getCurrentSampleRate()
  188145. {
  188146. return currentSampleRate;
  188147. }
  188148. const BigInteger getActiveOutputChannels() const
  188149. {
  188150. return currentChansOut;
  188151. }
  188152. const BigInteger getActiveInputChannels() const
  188153. {
  188154. return currentChansIn;
  188155. }
  188156. int getCurrentBitDepth()
  188157. {
  188158. return currentBitDepth;
  188159. }
  188160. int getOutputLatencyInSamples()
  188161. {
  188162. return outputLatency + currentBlockSizeSamples / 4;
  188163. }
  188164. int getInputLatencyInSamples()
  188165. {
  188166. return inputLatency + currentBlockSizeSamples / 4;
  188167. }
  188168. void start (AudioIODeviceCallback* callback)
  188169. {
  188170. if (callback != 0)
  188171. {
  188172. callback->audioDeviceAboutToStart (this);
  188173. const ScopedLock sl (callbackLock);
  188174. currentCallback = callback;
  188175. }
  188176. }
  188177. void stop()
  188178. {
  188179. AudioIODeviceCallback* const lastCallback = currentCallback;
  188180. {
  188181. const ScopedLock sl (callbackLock);
  188182. currentCallback = 0;
  188183. }
  188184. if (lastCallback != 0)
  188185. lastCallback->audioDeviceStopped();
  188186. }
  188187. bool isPlaying()
  188188. {
  188189. return isASIOOpen && (currentCallback != 0);
  188190. }
  188191. const String getLastError()
  188192. {
  188193. return error;
  188194. }
  188195. bool hasControlPanel() const
  188196. {
  188197. return true;
  188198. }
  188199. bool showControlPanel()
  188200. {
  188201. log ("ASIO - showing control panel");
  188202. Component modalWindow (String::empty);
  188203. modalWindow.setOpaque (true);
  188204. modalWindow.addToDesktop (0);
  188205. modalWindow.enterModalState();
  188206. bool done = false;
  188207. JUCE_TRY
  188208. {
  188209. // are there are devices that need to be closed before showing their control panel?
  188210. // close();
  188211. insideControlPanelModalLoop = true;
  188212. const uint32 started = Time::getMillisecondCounter();
  188213. if (asioObject != 0)
  188214. {
  188215. asioObject->controlPanel();
  188216. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188217. log ("spent: " + String (spent));
  188218. if (spent > 300)
  188219. {
  188220. shouldUsePreferredSize = true;
  188221. done = true;
  188222. }
  188223. }
  188224. }
  188225. JUCE_CATCH_ALL
  188226. insideControlPanelModalLoop = false;
  188227. return done;
  188228. }
  188229. void resetRequest() throw()
  188230. {
  188231. needToReset = true;
  188232. }
  188233. void resyncRequest() throw()
  188234. {
  188235. needToReset = true;
  188236. isReSync = true;
  188237. }
  188238. void timerCallback()
  188239. {
  188240. if (! insideControlPanelModalLoop)
  188241. {
  188242. stopTimer();
  188243. // used to cause a reset
  188244. log ("! ASIO restart request!");
  188245. if (isOpen_)
  188246. {
  188247. AudioIODeviceCallback* const oldCallback = currentCallback;
  188248. close();
  188249. open (BigInteger (currentChansIn), BigInteger (currentChansOut),
  188250. currentSampleRate, currentBlockSizeSamples);
  188251. if (oldCallback != 0)
  188252. start (oldCallback);
  188253. }
  188254. }
  188255. else
  188256. {
  188257. startTimer (100);
  188258. }
  188259. }
  188260. juce_UseDebuggingNewOperator
  188261. private:
  188262. IASIO* volatile asioObject;
  188263. ASIOCallbacks callbacks;
  188264. void* windowHandle;
  188265. CLSID classId;
  188266. const String optionalDllForDirectLoading;
  188267. String error;
  188268. long totalNumInputChans, totalNumOutputChans;
  188269. StringArray inputChannelNames, outputChannelNames;
  188270. Array<int> sampleRates, bufferSizes;
  188271. long inputLatency, outputLatency;
  188272. long minSize, maxSize, preferredSize, granularity;
  188273. int volatile currentBlockSizeSamples;
  188274. int volatile currentBitDepth;
  188275. double volatile currentSampleRate;
  188276. BigInteger currentChansOut, currentChansIn;
  188277. AudioIODeviceCallback* volatile currentCallback;
  188278. CriticalSection callbackLock;
  188279. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188280. float* inBuffers [maxASIOChannels];
  188281. float* outBuffers [maxASIOChannels];
  188282. int inputChannelBitDepths [maxASIOChannels];
  188283. int outputChannelBitDepths [maxASIOChannels];
  188284. int inputChannelBytesPerSample [maxASIOChannels];
  188285. int outputChannelBytesPerSample [maxASIOChannels];
  188286. bool inputChannelIsFloat [maxASIOChannels];
  188287. bool outputChannelIsFloat [maxASIOChannels];
  188288. bool inputChannelLittleEndian [maxASIOChannels];
  188289. bool outputChannelLittleEndian [maxASIOChannels];
  188290. WaitableEvent event1;
  188291. HeapBlock <float> tempBuffer;
  188292. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188293. bool isOpen_, isStarted;
  188294. bool volatile isASIOOpen;
  188295. bool volatile calledback;
  188296. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188297. bool volatile insideControlPanelModalLoop;
  188298. bool volatile shouldUsePreferredSize;
  188299. void removeCurrentDriver()
  188300. {
  188301. if (asioObject != 0)
  188302. {
  188303. asioObject->Release();
  188304. asioObject = 0;
  188305. }
  188306. }
  188307. bool loadDriver()
  188308. {
  188309. removeCurrentDriver();
  188310. JUCE_TRY
  188311. {
  188312. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188313. classId, (void**) &asioObject) == S_OK)
  188314. {
  188315. return true;
  188316. }
  188317. // If a class isn't registered but we have a path for it, we can fallback to
  188318. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188319. if (optionalDllForDirectLoading.isNotEmpty())
  188320. {
  188321. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188322. if (h != 0)
  188323. {
  188324. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188325. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188326. if (dllGetClassObject != 0)
  188327. {
  188328. IClassFactory* classFactory = 0;
  188329. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188330. if (classFactory != 0)
  188331. {
  188332. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188333. classFactory->Release();
  188334. }
  188335. return asioObject != 0;
  188336. }
  188337. }
  188338. }
  188339. }
  188340. JUCE_CATCH_ALL
  188341. asioObject = 0;
  188342. return false;
  188343. }
  188344. const String initDriver()
  188345. {
  188346. if (asioObject != 0)
  188347. {
  188348. char buffer [256];
  188349. zeromem (buffer, sizeof (buffer));
  188350. if (! asioObject->init (windowHandle))
  188351. {
  188352. asioObject->getErrorMessage (buffer);
  188353. return String (buffer, sizeof (buffer) - 1);
  188354. }
  188355. // just in case any daft drivers expect this to be called..
  188356. asioObject->getDriverName (buffer);
  188357. return String::empty;
  188358. }
  188359. return "No Driver";
  188360. }
  188361. const String openDevice()
  188362. {
  188363. // use this in case the driver starts opening dialog boxes..
  188364. Component modalWindow (String::empty);
  188365. modalWindow.setOpaque (true);
  188366. modalWindow.addToDesktop (0);
  188367. modalWindow.enterModalState();
  188368. // open the device and get its info..
  188369. log ("opening ASIO device: " + getName());
  188370. needToReset = false;
  188371. isReSync = false;
  188372. outputChannelNames.clear();
  188373. inputChannelNames.clear();
  188374. bufferSizes.clear();
  188375. sampleRates.clear();
  188376. isASIOOpen = false;
  188377. isOpen_ = false;
  188378. totalNumInputChans = 0;
  188379. totalNumOutputChans = 0;
  188380. numActiveInputChans = 0;
  188381. numActiveOutputChans = 0;
  188382. currentCallback = 0;
  188383. error = String::empty;
  188384. if (getName().isEmpty())
  188385. return error;
  188386. long err = 0;
  188387. if (loadDriver())
  188388. {
  188389. if ((error = initDriver()).isEmpty())
  188390. {
  188391. numActiveInputChans = 0;
  188392. numActiveOutputChans = 0;
  188393. totalNumInputChans = 0;
  188394. totalNumOutputChans = 0;
  188395. if (asioObject != 0
  188396. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188397. {
  188398. log (String ((int) totalNumInputChans) + " in, " + String ((int) totalNumOutputChans) + " out");
  188399. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188400. {
  188401. // find a list of buffer sizes..
  188402. log (String ((int) minSize) + " " + String ((int) maxSize) + " " + String ((int) preferredSize) + " " + String ((int) granularity));
  188403. if (granularity >= 0)
  188404. {
  188405. granularity = jmax (1, (int) granularity);
  188406. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188407. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188408. }
  188409. else if (granularity < 0)
  188410. {
  188411. for (int i = 0; i < 18; ++i)
  188412. {
  188413. const int s = (1 << i);
  188414. if (s >= minSize && s <= maxSize)
  188415. bufferSizes.add (s);
  188416. }
  188417. }
  188418. if (! bufferSizes.contains (preferredSize))
  188419. bufferSizes.insert (0, preferredSize);
  188420. double currentRate = 0;
  188421. asioObject->getSampleRate (&currentRate);
  188422. if (currentRate <= 0.0 || currentRate > 192001.0)
  188423. {
  188424. log ("setting sample rate");
  188425. err = asioObject->setSampleRate (44100.0);
  188426. if (err != 0)
  188427. {
  188428. logError ("setting sample rate", err);
  188429. }
  188430. asioObject->getSampleRate (&currentRate);
  188431. }
  188432. currentSampleRate = currentRate;
  188433. postOutput = (asioObject->outputReady() == 0);
  188434. if (postOutput)
  188435. {
  188436. log ("ASIO outputReady = ok");
  188437. }
  188438. updateSampleRates();
  188439. // ..because cubase does it at this point
  188440. inputLatency = outputLatency = 0;
  188441. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188442. {
  188443. log ("ASIO - no latencies");
  188444. }
  188445. log ("latencies: " + String ((int) inputLatency) + ", " + String ((int) outputLatency));
  188446. // create some dummy buffers now.. because cubase does..
  188447. numActiveInputChans = 0;
  188448. numActiveOutputChans = 0;
  188449. ASIOBufferInfo* info = bufferInfos;
  188450. int i, numChans = 0;
  188451. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188452. {
  188453. info->isInput = 1;
  188454. info->channelNum = i;
  188455. info->buffers[0] = info->buffers[1] = 0;
  188456. ++info;
  188457. ++numChans;
  188458. }
  188459. const int outputBufferIndex = numChans;
  188460. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  188461. {
  188462. info->isInput = 0;
  188463. info->channelNum = i;
  188464. info->buffers[0] = info->buffers[1] = 0;
  188465. ++info;
  188466. ++numChans;
  188467. }
  188468. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188469. if (currentASIODev[0] == this)
  188470. {
  188471. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188472. callbacks.asioMessage = &asioMessagesCallback0;
  188473. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188474. }
  188475. else if (currentASIODev[1] == this)
  188476. {
  188477. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188478. callbacks.asioMessage = &asioMessagesCallback1;
  188479. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188480. }
  188481. else if (currentASIODev[2] == this)
  188482. {
  188483. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188484. callbacks.asioMessage = &asioMessagesCallback2;
  188485. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188486. }
  188487. else
  188488. {
  188489. jassertfalse
  188490. }
  188491. log ("creating buffers (dummy): " + String (numChans) + ", " + String ((int) preferredSize));
  188492. if (preferredSize > 0)
  188493. {
  188494. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  188495. if (err != 0)
  188496. {
  188497. logError ("dummy buffers", err);
  188498. }
  188499. }
  188500. long newInps = 0, newOuts = 0;
  188501. asioObject->getChannels (&newInps, &newOuts);
  188502. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  188503. {
  188504. totalNumInputChans = newInps;
  188505. totalNumOutputChans = newOuts;
  188506. log (String ((int) totalNumInputChans) + " in; " + String ((int) totalNumOutputChans) + " out");
  188507. }
  188508. updateSampleRates();
  188509. ASIOChannelInfo channelInfo;
  188510. channelInfo.type = 0;
  188511. for (i = 0; i < totalNumInputChans; ++i)
  188512. {
  188513. zerostruct (channelInfo);
  188514. channelInfo.channel = i;
  188515. channelInfo.isInput = 1;
  188516. asioObject->getChannelInfo (&channelInfo);
  188517. inputChannelNames.add (String (channelInfo.name));
  188518. }
  188519. for (i = 0; i < totalNumOutputChans; ++i)
  188520. {
  188521. zerostruct (channelInfo);
  188522. channelInfo.channel = i;
  188523. channelInfo.isInput = 0;
  188524. asioObject->getChannelInfo (&channelInfo);
  188525. outputChannelNames.add (String (channelInfo.name));
  188526. typeToFormatParameters (channelInfo.type,
  188527. outputChannelBitDepths[i],
  188528. outputChannelBytesPerSample[i],
  188529. outputChannelIsFloat[i],
  188530. outputChannelLittleEndian[i]);
  188531. if (i < 2)
  188532. {
  188533. // clear the channels that are used with the dummy stuff
  188534. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  188535. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  188536. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  188537. }
  188538. }
  188539. outputChannelNames.trim();
  188540. inputChannelNames.trim();
  188541. outputChannelNames.appendNumbersToDuplicates (false, true);
  188542. inputChannelNames.appendNumbersToDuplicates (false, true);
  188543. // start and stop because cubase does it..
  188544. asioObject->getLatencies (&inputLatency, &outputLatency);
  188545. if ((err = asioObject->start()) != 0)
  188546. {
  188547. // ignore an error here, as it might start later after setting other stuff up
  188548. logError ("ASIO start", err);
  188549. }
  188550. Thread::sleep (100);
  188551. asioObject->stop();
  188552. }
  188553. else
  188554. {
  188555. error = "Can't detect buffer sizes";
  188556. }
  188557. }
  188558. else
  188559. {
  188560. error = "Can't detect asio channels";
  188561. }
  188562. }
  188563. }
  188564. else
  188565. {
  188566. error = "No such device";
  188567. }
  188568. if (error.isNotEmpty())
  188569. {
  188570. logError (error, err);
  188571. if (asioObject != 0)
  188572. asioObject->disposeBuffers();
  188573. removeCurrentDriver();
  188574. isASIOOpen = false;
  188575. }
  188576. else
  188577. {
  188578. isASIOOpen = true;
  188579. log ("ASIO device open");
  188580. }
  188581. isOpen_ = false;
  188582. needToReset = false;
  188583. isReSync = false;
  188584. return error;
  188585. }
  188586. void callback (const long index) throw()
  188587. {
  188588. if (isStarted)
  188589. {
  188590. bufferIndex = index;
  188591. processBuffer();
  188592. }
  188593. else
  188594. {
  188595. if (postOutput && (asioObject != 0))
  188596. asioObject->outputReady();
  188597. }
  188598. calledback = true;
  188599. }
  188600. void processBuffer() throw()
  188601. {
  188602. const ASIOBufferInfo* const infos = bufferInfos;
  188603. const int bi = bufferIndex;
  188604. const ScopedLock sl (callbackLock);
  188605. if (needToReset)
  188606. {
  188607. needToReset = false;
  188608. if (isReSync)
  188609. {
  188610. log ("! ASIO resync");
  188611. isReSync = false;
  188612. }
  188613. else
  188614. {
  188615. startTimer (20);
  188616. }
  188617. }
  188618. if (bi >= 0)
  188619. {
  188620. const int samps = currentBlockSizeSamples;
  188621. if (currentCallback != 0)
  188622. {
  188623. int i;
  188624. for (i = 0; i < numActiveInputChans; ++i)
  188625. {
  188626. float* const dst = inBuffers[i];
  188627. jassert (dst != 0);
  188628. const char* const src = (const char*) (infos[i].buffers[bi]);
  188629. if (inputChannelIsFloat[i])
  188630. {
  188631. memcpy (dst, src, samps * sizeof (float));
  188632. }
  188633. else
  188634. {
  188635. jassert (dst == tempBuffer + (samps * i));
  188636. switch (inputChannelBitDepths[i])
  188637. {
  188638. case 16:
  188639. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  188640. samps, inputChannelLittleEndian[i]);
  188641. break;
  188642. case 24:
  188643. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  188644. samps, inputChannelLittleEndian[i]);
  188645. break;
  188646. case 32:
  188647. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  188648. samps, inputChannelLittleEndian[i]);
  188649. break;
  188650. case 64:
  188651. jassertfalse
  188652. break;
  188653. }
  188654. }
  188655. }
  188656. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  188657. numActiveInputChans,
  188658. outBuffers,
  188659. numActiveOutputChans,
  188660. samps);
  188661. for (i = 0; i < numActiveOutputChans; ++i)
  188662. {
  188663. float* const src = outBuffers[i];
  188664. jassert (src != 0);
  188665. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  188666. if (outputChannelIsFloat[i])
  188667. {
  188668. memcpy (dst, src, samps * sizeof (float));
  188669. }
  188670. else
  188671. {
  188672. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  188673. switch (outputChannelBitDepths[i])
  188674. {
  188675. case 16:
  188676. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  188677. samps, outputChannelLittleEndian[i]);
  188678. break;
  188679. case 24:
  188680. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  188681. samps, outputChannelLittleEndian[i]);
  188682. break;
  188683. case 32:
  188684. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  188685. samps, outputChannelLittleEndian[i]);
  188686. break;
  188687. case 64:
  188688. jassertfalse
  188689. break;
  188690. }
  188691. }
  188692. }
  188693. }
  188694. else
  188695. {
  188696. for (int i = 0; i < numActiveOutputChans; ++i)
  188697. {
  188698. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  188699. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  188700. }
  188701. }
  188702. }
  188703. if (postOutput)
  188704. asioObject->outputReady();
  188705. }
  188706. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  188707. {
  188708. if (currentASIODev[0] != 0)
  188709. currentASIODev[0]->callback (index);
  188710. return 0;
  188711. }
  188712. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  188713. {
  188714. if (currentASIODev[1] != 0)
  188715. currentASIODev[1]->callback (index);
  188716. return 0;
  188717. }
  188718. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  188719. {
  188720. if (currentASIODev[2] != 0)
  188721. currentASIODev[2]->callback (index);
  188722. return 0;
  188723. }
  188724. static void bufferSwitchCallback0 (long index, long) throw()
  188725. {
  188726. if (currentASIODev[0] != 0)
  188727. currentASIODev[0]->callback (index);
  188728. }
  188729. static void bufferSwitchCallback1 (long index, long) throw()
  188730. {
  188731. if (currentASIODev[1] != 0)
  188732. currentASIODev[1]->callback (index);
  188733. }
  188734. static void bufferSwitchCallback2 (long index, long) throw()
  188735. {
  188736. if (currentASIODev[2] != 0)
  188737. currentASIODev[2]->callback (index);
  188738. }
  188739. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  188740. {
  188741. return asioMessagesCallback (selector, value, 0);
  188742. }
  188743. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  188744. {
  188745. return asioMessagesCallback (selector, value, 1);
  188746. }
  188747. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  188748. {
  188749. return asioMessagesCallback (selector, value, 2);
  188750. }
  188751. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  188752. {
  188753. switch (selector)
  188754. {
  188755. case kAsioSelectorSupported:
  188756. if (value == kAsioResetRequest
  188757. || value == kAsioEngineVersion
  188758. || value == kAsioResyncRequest
  188759. || value == kAsioLatenciesChanged
  188760. || value == kAsioSupportsInputMonitor)
  188761. return 1;
  188762. break;
  188763. case kAsioBufferSizeChange:
  188764. break;
  188765. case kAsioResetRequest:
  188766. if (currentASIODev[deviceIndex] != 0)
  188767. currentASIODev[deviceIndex]->resetRequest();
  188768. return 1;
  188769. case kAsioResyncRequest:
  188770. if (currentASIODev[deviceIndex] != 0)
  188771. currentASIODev[deviceIndex]->resyncRequest();
  188772. return 1;
  188773. case kAsioLatenciesChanged:
  188774. return 1;
  188775. case kAsioEngineVersion:
  188776. return 2;
  188777. case kAsioSupportsTimeInfo:
  188778. case kAsioSupportsTimeCode:
  188779. return 0;
  188780. }
  188781. return 0;
  188782. }
  188783. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  188784. {
  188785. }
  188786. static void convertInt16ToFloat (const char* src,
  188787. float* dest,
  188788. const int srcStrideBytes,
  188789. int numSamples,
  188790. const bool littleEndian) throw()
  188791. {
  188792. const double g = 1.0 / 32768.0;
  188793. if (littleEndian)
  188794. {
  188795. while (--numSamples >= 0)
  188796. {
  188797. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  188798. src += srcStrideBytes;
  188799. }
  188800. }
  188801. else
  188802. {
  188803. while (--numSamples >= 0)
  188804. {
  188805. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  188806. src += srcStrideBytes;
  188807. }
  188808. }
  188809. }
  188810. static void convertFloatToInt16 (const float* src,
  188811. char* dest,
  188812. const int dstStrideBytes,
  188813. int numSamples,
  188814. const bool littleEndian) throw()
  188815. {
  188816. const double maxVal = (double) 0x7fff;
  188817. if (littleEndian)
  188818. {
  188819. while (--numSamples >= 0)
  188820. {
  188821. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  188822. dest += dstStrideBytes;
  188823. }
  188824. }
  188825. else
  188826. {
  188827. while (--numSamples >= 0)
  188828. {
  188829. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  188830. dest += dstStrideBytes;
  188831. }
  188832. }
  188833. }
  188834. static void convertInt24ToFloat (const char* src,
  188835. float* dest,
  188836. const int srcStrideBytes,
  188837. int numSamples,
  188838. const bool littleEndian) throw()
  188839. {
  188840. const double g = 1.0 / 0x7fffff;
  188841. if (littleEndian)
  188842. {
  188843. while (--numSamples >= 0)
  188844. {
  188845. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  188846. src += srcStrideBytes;
  188847. }
  188848. }
  188849. else
  188850. {
  188851. while (--numSamples >= 0)
  188852. {
  188853. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  188854. src += srcStrideBytes;
  188855. }
  188856. }
  188857. }
  188858. static void convertFloatToInt24 (const float* src,
  188859. char* dest,
  188860. const int dstStrideBytes,
  188861. int numSamples,
  188862. const bool littleEndian) throw()
  188863. {
  188864. const double maxVal = (double) 0x7fffff;
  188865. if (littleEndian)
  188866. {
  188867. while (--numSamples >= 0)
  188868. {
  188869. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  188870. dest += dstStrideBytes;
  188871. }
  188872. }
  188873. else
  188874. {
  188875. while (--numSamples >= 0)
  188876. {
  188877. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  188878. dest += dstStrideBytes;
  188879. }
  188880. }
  188881. }
  188882. static void convertInt32ToFloat (const char* src,
  188883. float* dest,
  188884. const int srcStrideBytes,
  188885. int numSamples,
  188886. const bool littleEndian) throw()
  188887. {
  188888. const double g = 1.0 / 0x7fffffff;
  188889. if (littleEndian)
  188890. {
  188891. while (--numSamples >= 0)
  188892. {
  188893. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  188894. src += srcStrideBytes;
  188895. }
  188896. }
  188897. else
  188898. {
  188899. while (--numSamples >= 0)
  188900. {
  188901. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  188902. src += srcStrideBytes;
  188903. }
  188904. }
  188905. }
  188906. static void convertFloatToInt32 (const float* src,
  188907. char* dest,
  188908. const int dstStrideBytes,
  188909. int numSamples,
  188910. const bool littleEndian) throw()
  188911. {
  188912. const double maxVal = (double) 0x7fffffff;
  188913. if (littleEndian)
  188914. {
  188915. while (--numSamples >= 0)
  188916. {
  188917. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  188918. dest += dstStrideBytes;
  188919. }
  188920. }
  188921. else
  188922. {
  188923. while (--numSamples >= 0)
  188924. {
  188925. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  188926. dest += dstStrideBytes;
  188927. }
  188928. }
  188929. }
  188930. static void typeToFormatParameters (const long type,
  188931. int& bitDepth,
  188932. int& byteStride,
  188933. bool& formatIsFloat,
  188934. bool& littleEndian) throw()
  188935. {
  188936. bitDepth = 0;
  188937. littleEndian = false;
  188938. formatIsFloat = false;
  188939. switch (type)
  188940. {
  188941. case ASIOSTInt16MSB:
  188942. case ASIOSTInt16LSB:
  188943. case ASIOSTInt32MSB16:
  188944. case ASIOSTInt32LSB16:
  188945. bitDepth = 16; break;
  188946. case ASIOSTFloat32MSB:
  188947. case ASIOSTFloat32LSB:
  188948. formatIsFloat = true;
  188949. bitDepth = 32; break;
  188950. case ASIOSTInt32MSB:
  188951. case ASIOSTInt32LSB:
  188952. bitDepth = 32; break;
  188953. case ASIOSTInt24MSB:
  188954. case ASIOSTInt24LSB:
  188955. case ASIOSTInt32MSB24:
  188956. case ASIOSTInt32LSB24:
  188957. case ASIOSTInt32MSB18:
  188958. case ASIOSTInt32MSB20:
  188959. case ASIOSTInt32LSB18:
  188960. case ASIOSTInt32LSB20:
  188961. bitDepth = 24; break;
  188962. case ASIOSTFloat64MSB:
  188963. case ASIOSTFloat64LSB:
  188964. default:
  188965. bitDepth = 64;
  188966. break;
  188967. }
  188968. switch (type)
  188969. {
  188970. case ASIOSTInt16MSB:
  188971. case ASIOSTInt32MSB16:
  188972. case ASIOSTFloat32MSB:
  188973. case ASIOSTFloat64MSB:
  188974. case ASIOSTInt32MSB:
  188975. case ASIOSTInt32MSB18:
  188976. case ASIOSTInt32MSB20:
  188977. case ASIOSTInt32MSB24:
  188978. case ASIOSTInt24MSB:
  188979. littleEndian = false; break;
  188980. case ASIOSTInt16LSB:
  188981. case ASIOSTInt32LSB16:
  188982. case ASIOSTFloat32LSB:
  188983. case ASIOSTFloat64LSB:
  188984. case ASIOSTInt32LSB:
  188985. case ASIOSTInt32LSB18:
  188986. case ASIOSTInt32LSB20:
  188987. case ASIOSTInt32LSB24:
  188988. case ASIOSTInt24LSB:
  188989. littleEndian = true; break;
  188990. default:
  188991. break;
  188992. }
  188993. switch (type)
  188994. {
  188995. case ASIOSTInt16LSB:
  188996. case ASIOSTInt16MSB:
  188997. byteStride = 2; break;
  188998. case ASIOSTInt24LSB:
  188999. case ASIOSTInt24MSB:
  189000. byteStride = 3; break;
  189001. case ASIOSTInt32MSB16:
  189002. case ASIOSTInt32LSB16:
  189003. case ASIOSTInt32MSB:
  189004. case ASIOSTInt32MSB18:
  189005. case ASIOSTInt32MSB20:
  189006. case ASIOSTInt32MSB24:
  189007. case ASIOSTInt32LSB:
  189008. case ASIOSTInt32LSB18:
  189009. case ASIOSTInt32LSB20:
  189010. case ASIOSTInt32LSB24:
  189011. case ASIOSTFloat32LSB:
  189012. case ASIOSTFloat32MSB:
  189013. byteStride = 4; break;
  189014. case ASIOSTFloat64MSB:
  189015. case ASIOSTFloat64LSB:
  189016. byteStride = 8; break;
  189017. default:
  189018. break;
  189019. }
  189020. }
  189021. };
  189022. class ASIOAudioIODeviceType : public AudioIODeviceType
  189023. {
  189024. public:
  189025. ASIOAudioIODeviceType()
  189026. : AudioIODeviceType ("ASIO"),
  189027. hasScanned (false)
  189028. {
  189029. CoInitialize (0);
  189030. }
  189031. ~ASIOAudioIODeviceType()
  189032. {
  189033. }
  189034. void scanForDevices()
  189035. {
  189036. hasScanned = true;
  189037. deviceNames.clear();
  189038. classIds.clear();
  189039. HKEY hk = 0;
  189040. int index = 0;
  189041. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189042. {
  189043. for (;;)
  189044. {
  189045. char name [256];
  189046. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189047. {
  189048. addDriverInfo (name, hk);
  189049. }
  189050. else
  189051. {
  189052. break;
  189053. }
  189054. }
  189055. RegCloseKey (hk);
  189056. }
  189057. }
  189058. const StringArray getDeviceNames (bool /*wantInputNames*/) const
  189059. {
  189060. jassert (hasScanned); // need to call scanForDevices() before doing this
  189061. return deviceNames;
  189062. }
  189063. int getDefaultDeviceIndex (bool) const
  189064. {
  189065. jassert (hasScanned); // need to call scanForDevices() before doing this
  189066. for (int i = deviceNames.size(); --i >= 0;)
  189067. if (deviceNames[i].containsIgnoreCase ("asio4all"))
  189068. return i; // asio4all is a safe choice for a default..
  189069. #if JUCE_DEBUG
  189070. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase ("digidesign"))
  189071. return 1; // (the digi m-box driver crashes the app when you run
  189072. // it in the debugger, which can be a bit annoying)
  189073. #endif
  189074. return 0;
  189075. }
  189076. static int findFreeSlot()
  189077. {
  189078. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189079. if (currentASIODev[i] == 0)
  189080. return i;
  189081. jassertfalse; // unfortunately you can only have a finite number
  189082. // of ASIO devices open at the same time..
  189083. return -1;
  189084. }
  189085. int getIndexOfDevice (AudioIODevice* d, bool /*asInput*/) const
  189086. {
  189087. jassert (hasScanned); // need to call scanForDevices() before doing this
  189088. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189089. }
  189090. bool hasSeparateInputsAndOutputs() const { return false; }
  189091. AudioIODevice* createDevice (const String& outputDeviceName,
  189092. const String& inputDeviceName)
  189093. {
  189094. // ASIO can't open two different devices for input and output - they must be the same one.
  189095. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189096. jassert (hasScanned); // need to call scanForDevices() before doing this
  189097. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189098. : inputDeviceName);
  189099. if (index >= 0)
  189100. {
  189101. const int freeSlot = findFreeSlot();
  189102. if (freeSlot >= 0)
  189103. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189104. }
  189105. return 0;
  189106. }
  189107. juce_UseDebuggingNewOperator
  189108. private:
  189109. StringArray deviceNames;
  189110. OwnedArray <CLSID> classIds;
  189111. bool hasScanned;
  189112. static bool checkClassIsOk (const String& classId)
  189113. {
  189114. HKEY hk = 0;
  189115. bool ok = false;
  189116. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189117. {
  189118. int index = 0;
  189119. for (;;)
  189120. {
  189121. WCHAR buf [512];
  189122. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189123. {
  189124. if (classId.equalsIgnoreCase (buf))
  189125. {
  189126. HKEY subKey, pathKey;
  189127. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189128. {
  189129. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189130. {
  189131. WCHAR pathName [1024];
  189132. DWORD dtype = REG_SZ;
  189133. DWORD dsize = sizeof (pathName);
  189134. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189135. ok = File (pathName).exists();
  189136. RegCloseKey (pathKey);
  189137. }
  189138. RegCloseKey (subKey);
  189139. }
  189140. break;
  189141. }
  189142. }
  189143. else
  189144. {
  189145. break;
  189146. }
  189147. }
  189148. RegCloseKey (hk);
  189149. }
  189150. return ok;
  189151. }
  189152. void addDriverInfo (const String& keyName, HKEY hk)
  189153. {
  189154. HKEY subKey;
  189155. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189156. {
  189157. WCHAR buf [256];
  189158. zerostruct (buf);
  189159. DWORD dtype = REG_SZ;
  189160. DWORD dsize = sizeof (buf);
  189161. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189162. {
  189163. if (dsize > 0 && checkClassIsOk (buf))
  189164. {
  189165. CLSID classId;
  189166. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189167. {
  189168. dtype = REG_SZ;
  189169. dsize = sizeof (buf);
  189170. String deviceName;
  189171. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189172. deviceName = buf;
  189173. else
  189174. deviceName = keyName;
  189175. log ("found " + deviceName);
  189176. deviceNames.add (deviceName);
  189177. classIds.add (new CLSID (classId));
  189178. }
  189179. }
  189180. RegCloseKey (subKey);
  189181. }
  189182. }
  189183. }
  189184. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189185. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189186. };
  189187. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189188. {
  189189. return new ASIOAudioIODeviceType();
  189190. }
  189191. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189192. void* guid,
  189193. const String& optionalDllForDirectLoading)
  189194. {
  189195. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189196. if (freeSlot < 0)
  189197. return 0;
  189198. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189199. }
  189200. #undef log
  189201. #endif
  189202. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189203. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189204. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189205. // compiled on its own).
  189206. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189207. END_JUCE_NAMESPACE
  189208. extern "C"
  189209. {
  189210. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189211. typedef struct typeDSBUFFERDESC
  189212. {
  189213. DWORD dwSize;
  189214. DWORD dwFlags;
  189215. DWORD dwBufferBytes;
  189216. DWORD dwReserved;
  189217. LPWAVEFORMATEX lpwfxFormat;
  189218. GUID guid3DAlgorithm;
  189219. } DSBUFFERDESC;
  189220. struct IDirectSoundBuffer;
  189221. #undef INTERFACE
  189222. #define INTERFACE IDirectSound
  189223. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189224. {
  189225. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189226. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189227. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189228. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189229. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189230. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189231. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189232. STDMETHOD(Compact) (THIS) PURE;
  189233. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189234. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189235. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189236. };
  189237. #undef INTERFACE
  189238. #define INTERFACE IDirectSoundBuffer
  189239. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189240. {
  189241. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189242. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189243. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189244. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189245. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189246. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189247. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189248. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189249. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189250. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189251. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189252. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189253. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189254. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189255. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189256. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189257. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189258. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189259. STDMETHOD(Stop) (THIS) PURE;
  189260. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189261. STDMETHOD(Restore) (THIS) PURE;
  189262. };
  189263. typedef struct typeDSCBUFFERDESC
  189264. {
  189265. DWORD dwSize;
  189266. DWORD dwFlags;
  189267. DWORD dwBufferBytes;
  189268. DWORD dwReserved;
  189269. LPWAVEFORMATEX lpwfxFormat;
  189270. } DSCBUFFERDESC;
  189271. struct IDirectSoundCaptureBuffer;
  189272. #undef INTERFACE
  189273. #define INTERFACE IDirectSoundCapture
  189274. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189275. {
  189276. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189277. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189278. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189279. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189280. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189281. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189282. };
  189283. #undef INTERFACE
  189284. #define INTERFACE IDirectSoundCaptureBuffer
  189285. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189286. {
  189287. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189288. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189289. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189290. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189291. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189292. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189293. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189294. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189295. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189296. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189297. STDMETHOD(Stop) (THIS) PURE;
  189298. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189299. };
  189300. };
  189301. BEGIN_JUCE_NAMESPACE
  189302. static const String getDSErrorMessage (HRESULT hr)
  189303. {
  189304. const char* result = 0;
  189305. switch (hr)
  189306. {
  189307. case MAKE_HRESULT(1, 0x878, 10):
  189308. result = "Device already allocated";
  189309. break;
  189310. case MAKE_HRESULT(1, 0x878, 30):
  189311. result = "Control unavailable";
  189312. break;
  189313. case E_INVALIDARG:
  189314. result = "Invalid parameter";
  189315. break;
  189316. case MAKE_HRESULT(1, 0x878, 50):
  189317. result = "Invalid call";
  189318. break;
  189319. case E_FAIL:
  189320. result = "Generic error";
  189321. break;
  189322. case MAKE_HRESULT(1, 0x878, 70):
  189323. result = "Priority level error";
  189324. break;
  189325. case E_OUTOFMEMORY:
  189326. result = "Out of memory";
  189327. break;
  189328. case MAKE_HRESULT(1, 0x878, 100):
  189329. result = "Bad format";
  189330. break;
  189331. case E_NOTIMPL:
  189332. result = "Unsupported function";
  189333. break;
  189334. case MAKE_HRESULT(1, 0x878, 120):
  189335. result = "No driver";
  189336. break;
  189337. case MAKE_HRESULT(1, 0x878, 130):
  189338. result = "Already initialised";
  189339. break;
  189340. case CLASS_E_NOAGGREGATION:
  189341. result = "No aggregation";
  189342. break;
  189343. case MAKE_HRESULT(1, 0x878, 150):
  189344. result = "Buffer lost";
  189345. break;
  189346. case MAKE_HRESULT(1, 0x878, 160):
  189347. result = "Another app has priority";
  189348. break;
  189349. case MAKE_HRESULT(1, 0x878, 170):
  189350. result = "Uninitialised";
  189351. break;
  189352. case E_NOINTERFACE:
  189353. result = "No interface";
  189354. break;
  189355. case S_OK:
  189356. result = "No error";
  189357. break;
  189358. default:
  189359. return "Unknown error: " + String ((int) hr);
  189360. }
  189361. return result;
  189362. }
  189363. #define DS_DEBUGGING 1
  189364. #ifdef DS_DEBUGGING
  189365. #define CATCH JUCE_CATCH_EXCEPTION
  189366. #undef log
  189367. #define log(a) Logger::writeToLog(a);
  189368. #undef logError
  189369. #define logError(a) logDSError(a, __LINE__);
  189370. static void logDSError (HRESULT hr, int lineNum)
  189371. {
  189372. if (hr != S_OK)
  189373. {
  189374. String error ("DS error at line ");
  189375. error << lineNum << " - " << getDSErrorMessage (hr);
  189376. log (error);
  189377. }
  189378. }
  189379. #else
  189380. #define CATCH JUCE_CATCH_ALL
  189381. #define log(a)
  189382. #define logError(a)
  189383. #endif
  189384. #define DSOUND_FUNCTION(functionName, params) \
  189385. typedef HRESULT (WINAPI *type##functionName) params; \
  189386. static type##functionName ds##functionName = 0;
  189387. #define DSOUND_FUNCTION_LOAD(functionName) \
  189388. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189389. jassert (ds##functionName != 0);
  189390. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189391. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189392. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189393. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189394. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189395. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189396. static void initialiseDSoundFunctions()
  189397. {
  189398. if (dsDirectSoundCreate == 0)
  189399. {
  189400. HMODULE h = LoadLibraryA ("dsound.dll");
  189401. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189402. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189403. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189404. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189405. }
  189406. }
  189407. class DSoundInternalOutChannel
  189408. {
  189409. String name;
  189410. LPGUID guid;
  189411. int sampleRate, bufferSizeSamples;
  189412. float* leftBuffer;
  189413. float* rightBuffer;
  189414. IDirectSound* pDirectSound;
  189415. IDirectSoundBuffer* pOutputBuffer;
  189416. DWORD writeOffset;
  189417. int totalBytesPerBuffer;
  189418. int bytesPerBuffer;
  189419. unsigned int lastPlayCursor;
  189420. public:
  189421. int bitDepth;
  189422. bool doneFlag;
  189423. DSoundInternalOutChannel (const String& name_,
  189424. LPGUID guid_,
  189425. int rate,
  189426. int bufferSize,
  189427. float* left,
  189428. float* right)
  189429. : name (name_),
  189430. guid (guid_),
  189431. sampleRate (rate),
  189432. bufferSizeSamples (bufferSize),
  189433. leftBuffer (left),
  189434. rightBuffer (right),
  189435. pDirectSound (0),
  189436. pOutputBuffer (0),
  189437. bitDepth (16)
  189438. {
  189439. }
  189440. ~DSoundInternalOutChannel()
  189441. {
  189442. close();
  189443. }
  189444. void close()
  189445. {
  189446. HRESULT hr;
  189447. if (pOutputBuffer != 0)
  189448. {
  189449. JUCE_TRY
  189450. {
  189451. log ("closing dsound out: " + name);
  189452. hr = pOutputBuffer->Stop();
  189453. logError (hr);
  189454. }
  189455. CATCH
  189456. JUCE_TRY
  189457. {
  189458. hr = pOutputBuffer->Release();
  189459. logError (hr);
  189460. }
  189461. CATCH
  189462. pOutputBuffer = 0;
  189463. }
  189464. if (pDirectSound != 0)
  189465. {
  189466. JUCE_TRY
  189467. {
  189468. hr = pDirectSound->Release();
  189469. logError (hr);
  189470. }
  189471. CATCH
  189472. pDirectSound = 0;
  189473. }
  189474. }
  189475. const String open()
  189476. {
  189477. log ("opening dsound out device: " + name + " rate=" + String (sampleRate)
  189478. + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  189479. pDirectSound = 0;
  189480. pOutputBuffer = 0;
  189481. writeOffset = 0;
  189482. String error;
  189483. HRESULT hr = E_NOINTERFACE;
  189484. if (dsDirectSoundCreate != 0)
  189485. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  189486. if (hr == S_OK)
  189487. {
  189488. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  189489. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  189490. const int numChannels = 2;
  189491. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  189492. logError (hr);
  189493. if (hr == S_OK)
  189494. {
  189495. IDirectSoundBuffer* pPrimaryBuffer;
  189496. DSBUFFERDESC primaryDesc;
  189497. zerostruct (primaryDesc);
  189498. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189499. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  189500. primaryDesc.dwBufferBytes = 0;
  189501. primaryDesc.lpwfxFormat = 0;
  189502. log ("opening dsound out step 2");
  189503. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  189504. logError (hr);
  189505. if (hr == S_OK)
  189506. {
  189507. WAVEFORMATEX wfFormat;
  189508. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  189509. wfFormat.nChannels = (unsigned short) numChannels;
  189510. wfFormat.nSamplesPerSec = sampleRate;
  189511. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  189512. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  189513. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  189514. wfFormat.cbSize = 0;
  189515. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  189516. logError (hr);
  189517. if (hr == S_OK)
  189518. {
  189519. DSBUFFERDESC secondaryDesc;
  189520. zerostruct (secondaryDesc);
  189521. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189522. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  189523. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  189524. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  189525. secondaryDesc.lpwfxFormat = &wfFormat;
  189526. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  189527. logError (hr);
  189528. if (hr == S_OK)
  189529. {
  189530. log ("opening dsound out step 3");
  189531. DWORD dwDataLen;
  189532. unsigned char* pDSBuffData;
  189533. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  189534. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  189535. logError (hr);
  189536. if (hr == S_OK)
  189537. {
  189538. zeromem (pDSBuffData, dwDataLen);
  189539. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  189540. if (hr == S_OK)
  189541. {
  189542. hr = pOutputBuffer->SetCurrentPosition (0);
  189543. if (hr == S_OK)
  189544. {
  189545. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  189546. if (hr == S_OK)
  189547. return String::empty;
  189548. }
  189549. }
  189550. }
  189551. }
  189552. }
  189553. }
  189554. }
  189555. }
  189556. error = getDSErrorMessage (hr);
  189557. close();
  189558. return error;
  189559. }
  189560. void synchronisePosition()
  189561. {
  189562. if (pOutputBuffer != 0)
  189563. {
  189564. DWORD playCursor;
  189565. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  189566. }
  189567. }
  189568. bool service()
  189569. {
  189570. if (pOutputBuffer == 0)
  189571. return true;
  189572. DWORD playCursor, writeCursor;
  189573. for (;;)
  189574. {
  189575. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  189576. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189577. {
  189578. pOutputBuffer->Restore();
  189579. continue;
  189580. }
  189581. if (hr == S_OK)
  189582. break;
  189583. logError (hr);
  189584. jassertfalse
  189585. return true;
  189586. }
  189587. int playWriteGap = writeCursor - playCursor;
  189588. if (playWriteGap < 0)
  189589. playWriteGap += totalBytesPerBuffer;
  189590. int bytesEmpty = playCursor - writeOffset;
  189591. if (bytesEmpty < 0)
  189592. bytesEmpty += totalBytesPerBuffer;
  189593. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  189594. {
  189595. writeOffset = writeCursor;
  189596. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  189597. }
  189598. if (bytesEmpty >= bytesPerBuffer)
  189599. {
  189600. LPBYTE lpbuf1 = 0;
  189601. LPBYTE lpbuf2 = 0;
  189602. DWORD dwSize1 = 0;
  189603. DWORD dwSize2 = 0;
  189604. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  189605. bytesPerBuffer,
  189606. (void**) &lpbuf1, &dwSize1,
  189607. (void**) &lpbuf2, &dwSize2, 0);
  189608. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189609. {
  189610. pOutputBuffer->Restore();
  189611. hr = pOutputBuffer->Lock (writeOffset,
  189612. bytesPerBuffer,
  189613. (void**) &lpbuf1, &dwSize1,
  189614. (void**) &lpbuf2, &dwSize2, 0);
  189615. }
  189616. if (hr == S_OK)
  189617. {
  189618. if (bitDepth == 16)
  189619. {
  189620. const float gainL = 32767.0f;
  189621. const float gainR = 32767.0f;
  189622. int* dest = (int*)lpbuf1;
  189623. const float* left = leftBuffer;
  189624. const float* right = rightBuffer;
  189625. int samples1 = dwSize1 >> 2;
  189626. int samples2 = dwSize2 >> 2;
  189627. if (left == 0)
  189628. {
  189629. while (--samples1 >= 0)
  189630. {
  189631. int r = roundToInt (gainR * *right++);
  189632. if (r < -32768)
  189633. r = -32768;
  189634. else if (r > 32767)
  189635. r = 32767;
  189636. *dest++ = (r << 16);
  189637. }
  189638. dest = (int*)lpbuf2;
  189639. while (--samples2 >= 0)
  189640. {
  189641. int r = roundToInt (gainR * *right++);
  189642. if (r < -32768)
  189643. r = -32768;
  189644. else if (r > 32767)
  189645. r = 32767;
  189646. *dest++ = (r << 16);
  189647. }
  189648. }
  189649. else if (right == 0)
  189650. {
  189651. while (--samples1 >= 0)
  189652. {
  189653. int l = roundToInt (gainL * *left++);
  189654. if (l < -32768)
  189655. l = -32768;
  189656. else if (l > 32767)
  189657. l = 32767;
  189658. l &= 0xffff;
  189659. *dest++ = l;
  189660. }
  189661. dest = (int*)lpbuf2;
  189662. while (--samples2 >= 0)
  189663. {
  189664. int l = roundToInt (gainL * *left++);
  189665. if (l < -32768)
  189666. l = -32768;
  189667. else if (l > 32767)
  189668. l = 32767;
  189669. l &= 0xffff;
  189670. *dest++ = l;
  189671. }
  189672. }
  189673. else
  189674. {
  189675. while (--samples1 >= 0)
  189676. {
  189677. int l = roundToInt (gainL * *left++);
  189678. if (l < -32768)
  189679. l = -32768;
  189680. else if (l > 32767)
  189681. l = 32767;
  189682. l &= 0xffff;
  189683. int r = roundToInt (gainR * *right++);
  189684. if (r < -32768)
  189685. r = -32768;
  189686. else if (r > 32767)
  189687. r = 32767;
  189688. *dest++ = (r << 16) | l;
  189689. }
  189690. dest = (int*)lpbuf2;
  189691. while (--samples2 >= 0)
  189692. {
  189693. int l = roundToInt (gainL * *left++);
  189694. if (l < -32768)
  189695. l = -32768;
  189696. else if (l > 32767)
  189697. l = 32767;
  189698. l &= 0xffff;
  189699. int r = roundToInt (gainR * *right++);
  189700. if (r < -32768)
  189701. r = -32768;
  189702. else if (r > 32767)
  189703. r = 32767;
  189704. *dest++ = (r << 16) | l;
  189705. }
  189706. }
  189707. }
  189708. else
  189709. {
  189710. jassertfalse
  189711. }
  189712. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  189713. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  189714. }
  189715. else
  189716. {
  189717. jassertfalse
  189718. logError (hr);
  189719. }
  189720. bytesEmpty -= bytesPerBuffer;
  189721. return true;
  189722. }
  189723. else
  189724. {
  189725. return false;
  189726. }
  189727. }
  189728. };
  189729. struct DSoundInternalInChannel
  189730. {
  189731. String name;
  189732. LPGUID guid;
  189733. int sampleRate, bufferSizeSamples;
  189734. float* leftBuffer;
  189735. float* rightBuffer;
  189736. IDirectSound* pDirectSound;
  189737. IDirectSoundCapture* pDirectSoundCapture;
  189738. IDirectSoundCaptureBuffer* pInputBuffer;
  189739. public:
  189740. unsigned int readOffset;
  189741. int bytesPerBuffer, totalBytesPerBuffer;
  189742. int bitDepth;
  189743. bool doneFlag;
  189744. DSoundInternalInChannel (const String& name_,
  189745. LPGUID guid_,
  189746. int rate,
  189747. int bufferSize,
  189748. float* left,
  189749. float* right)
  189750. : name (name_),
  189751. guid (guid_),
  189752. sampleRate (rate),
  189753. bufferSizeSamples (bufferSize),
  189754. leftBuffer (left),
  189755. rightBuffer (right),
  189756. pDirectSound (0),
  189757. pDirectSoundCapture (0),
  189758. pInputBuffer (0),
  189759. bitDepth (16)
  189760. {
  189761. }
  189762. ~DSoundInternalInChannel()
  189763. {
  189764. close();
  189765. }
  189766. void close()
  189767. {
  189768. HRESULT hr;
  189769. if (pInputBuffer != 0)
  189770. {
  189771. JUCE_TRY
  189772. {
  189773. log ("closing dsound in: " + name);
  189774. hr = pInputBuffer->Stop();
  189775. logError (hr);
  189776. }
  189777. CATCH
  189778. JUCE_TRY
  189779. {
  189780. hr = pInputBuffer->Release();
  189781. logError (hr);
  189782. }
  189783. CATCH
  189784. pInputBuffer = 0;
  189785. }
  189786. if (pDirectSoundCapture != 0)
  189787. {
  189788. JUCE_TRY
  189789. {
  189790. hr = pDirectSoundCapture->Release();
  189791. logError (hr);
  189792. }
  189793. CATCH
  189794. pDirectSoundCapture = 0;
  189795. }
  189796. if (pDirectSound != 0)
  189797. {
  189798. JUCE_TRY
  189799. {
  189800. hr = pDirectSound->Release();
  189801. logError (hr);
  189802. }
  189803. CATCH
  189804. pDirectSound = 0;
  189805. }
  189806. }
  189807. const String open()
  189808. {
  189809. log ("opening dsound in device: " + name
  189810. + " rate=" + String (sampleRate) + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  189811. pDirectSound = 0;
  189812. pDirectSoundCapture = 0;
  189813. pInputBuffer = 0;
  189814. readOffset = 0;
  189815. totalBytesPerBuffer = 0;
  189816. String error;
  189817. HRESULT hr = E_NOINTERFACE;
  189818. if (dsDirectSoundCaptureCreate != 0)
  189819. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  189820. logError (hr);
  189821. if (hr == S_OK)
  189822. {
  189823. const int numChannels = 2;
  189824. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  189825. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  189826. WAVEFORMATEX wfFormat;
  189827. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  189828. wfFormat.nChannels = (unsigned short)numChannels;
  189829. wfFormat.nSamplesPerSec = sampleRate;
  189830. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  189831. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  189832. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  189833. wfFormat.cbSize = 0;
  189834. DSCBUFFERDESC captureDesc;
  189835. zerostruct (captureDesc);
  189836. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  189837. captureDesc.dwFlags = 0;
  189838. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  189839. captureDesc.lpwfxFormat = &wfFormat;
  189840. log ("opening dsound in step 2");
  189841. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  189842. logError (hr);
  189843. if (hr == S_OK)
  189844. {
  189845. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  189846. logError (hr);
  189847. if (hr == S_OK)
  189848. return String::empty;
  189849. }
  189850. }
  189851. error = getDSErrorMessage (hr);
  189852. close();
  189853. return error;
  189854. }
  189855. void synchronisePosition()
  189856. {
  189857. if (pInputBuffer != 0)
  189858. {
  189859. DWORD capturePos;
  189860. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  189861. }
  189862. }
  189863. bool service()
  189864. {
  189865. if (pInputBuffer == 0)
  189866. return true;
  189867. DWORD capturePos, readPos;
  189868. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  189869. logError (hr);
  189870. if (hr != S_OK)
  189871. return true;
  189872. int bytesFilled = readPos - readOffset;
  189873. if (bytesFilled < 0)
  189874. bytesFilled += totalBytesPerBuffer;
  189875. if (bytesFilled >= bytesPerBuffer)
  189876. {
  189877. LPBYTE lpbuf1 = 0;
  189878. LPBYTE lpbuf2 = 0;
  189879. DWORD dwsize1 = 0;
  189880. DWORD dwsize2 = 0;
  189881. HRESULT hr = pInputBuffer->Lock (readOffset,
  189882. bytesPerBuffer,
  189883. (void**) &lpbuf1, &dwsize1,
  189884. (void**) &lpbuf2, &dwsize2, 0);
  189885. if (hr == S_OK)
  189886. {
  189887. if (bitDepth == 16)
  189888. {
  189889. const float g = 1.0f / 32768.0f;
  189890. float* destL = leftBuffer;
  189891. float* destR = rightBuffer;
  189892. int samples1 = dwsize1 >> 2;
  189893. int samples2 = dwsize2 >> 2;
  189894. const short* src = (const short*)lpbuf1;
  189895. if (destL == 0)
  189896. {
  189897. while (--samples1 >= 0)
  189898. {
  189899. ++src;
  189900. *destR++ = *src++ * g;
  189901. }
  189902. src = (const short*)lpbuf2;
  189903. while (--samples2 >= 0)
  189904. {
  189905. ++src;
  189906. *destR++ = *src++ * g;
  189907. }
  189908. }
  189909. else if (destR == 0)
  189910. {
  189911. while (--samples1 >= 0)
  189912. {
  189913. *destL++ = *src++ * g;
  189914. ++src;
  189915. }
  189916. src = (const short*)lpbuf2;
  189917. while (--samples2 >= 0)
  189918. {
  189919. *destL++ = *src++ * g;
  189920. ++src;
  189921. }
  189922. }
  189923. else
  189924. {
  189925. while (--samples1 >= 0)
  189926. {
  189927. *destL++ = *src++ * g;
  189928. *destR++ = *src++ * g;
  189929. }
  189930. src = (const short*)lpbuf2;
  189931. while (--samples2 >= 0)
  189932. {
  189933. *destL++ = *src++ * g;
  189934. *destR++ = *src++ * g;
  189935. }
  189936. }
  189937. }
  189938. else
  189939. {
  189940. jassertfalse
  189941. }
  189942. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  189943. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  189944. }
  189945. else
  189946. {
  189947. logError (hr);
  189948. jassertfalse
  189949. }
  189950. bytesFilled -= bytesPerBuffer;
  189951. return true;
  189952. }
  189953. else
  189954. {
  189955. return false;
  189956. }
  189957. }
  189958. };
  189959. class DSoundAudioIODevice : public AudioIODevice,
  189960. public Thread
  189961. {
  189962. public:
  189963. DSoundAudioIODevice (const String& deviceName,
  189964. const int outputDeviceIndex_,
  189965. const int inputDeviceIndex_)
  189966. : AudioIODevice (deviceName, "DirectSound"),
  189967. Thread ("Juce DSound"),
  189968. isOpen_ (false),
  189969. isStarted (false),
  189970. outputDeviceIndex (outputDeviceIndex_),
  189971. inputDeviceIndex (inputDeviceIndex_),
  189972. numInputBuffers (0),
  189973. numOutputBuffers (0),
  189974. totalSamplesOut (0),
  189975. sampleRate (0.0),
  189976. inputBuffers (0),
  189977. outputBuffers (0),
  189978. callback (0),
  189979. bufferSizeSamples (0)
  189980. {
  189981. if (outputDeviceIndex_ >= 0)
  189982. {
  189983. outChannels.add (TRANS("Left"));
  189984. outChannels.add (TRANS("Right"));
  189985. }
  189986. if (inputDeviceIndex_ >= 0)
  189987. {
  189988. inChannels.add (TRANS("Left"));
  189989. inChannels.add (TRANS("Right"));
  189990. }
  189991. }
  189992. ~DSoundAudioIODevice()
  189993. {
  189994. close();
  189995. }
  189996. const StringArray getOutputChannelNames()
  189997. {
  189998. return outChannels;
  189999. }
  190000. const StringArray getInputChannelNames()
  190001. {
  190002. return inChannels;
  190003. }
  190004. int getNumSampleRates()
  190005. {
  190006. return 4;
  190007. }
  190008. double getSampleRate (int index)
  190009. {
  190010. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190011. return samps [jlimit (0, 3, index)];
  190012. }
  190013. int getNumBufferSizesAvailable()
  190014. {
  190015. return 50;
  190016. }
  190017. int getBufferSizeSamples (int index)
  190018. {
  190019. int n = 64;
  190020. for (int i = 0; i < index; ++i)
  190021. n += (n < 512) ? 32
  190022. : ((n < 1024) ? 64
  190023. : ((n < 2048) ? 128 : 256));
  190024. return n;
  190025. }
  190026. int getDefaultBufferSize()
  190027. {
  190028. return 2560;
  190029. }
  190030. const String open (const BigInteger& inputChannels,
  190031. const BigInteger& outputChannels,
  190032. double sampleRate,
  190033. int bufferSizeSamples)
  190034. {
  190035. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190036. isOpen_ = lastError.isEmpty();
  190037. return lastError;
  190038. }
  190039. void close()
  190040. {
  190041. stop();
  190042. if (isOpen_)
  190043. {
  190044. closeDevice();
  190045. isOpen_ = false;
  190046. }
  190047. }
  190048. bool isOpen()
  190049. {
  190050. return isOpen_ && isThreadRunning();
  190051. }
  190052. int getCurrentBufferSizeSamples()
  190053. {
  190054. return bufferSizeSamples;
  190055. }
  190056. double getCurrentSampleRate()
  190057. {
  190058. return sampleRate;
  190059. }
  190060. int getCurrentBitDepth()
  190061. {
  190062. int i, bits = 256;
  190063. for (i = inChans.size(); --i >= 0;)
  190064. bits = jmin (bits, inChans[i]->bitDepth);
  190065. for (i = outChans.size(); --i >= 0;)
  190066. bits = jmin (bits, outChans[i]->bitDepth);
  190067. if (bits > 32)
  190068. bits = 16;
  190069. return bits;
  190070. }
  190071. const BigInteger getActiveOutputChannels() const
  190072. {
  190073. return enabledOutputs;
  190074. }
  190075. const BigInteger getActiveInputChannels() const
  190076. {
  190077. return enabledInputs;
  190078. }
  190079. int getOutputLatencyInSamples()
  190080. {
  190081. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190082. }
  190083. int getInputLatencyInSamples()
  190084. {
  190085. return getOutputLatencyInSamples();
  190086. }
  190087. void start (AudioIODeviceCallback* call)
  190088. {
  190089. if (isOpen_ && call != 0 && ! isStarted)
  190090. {
  190091. if (! isThreadRunning())
  190092. {
  190093. // something gone wrong and the thread's stopped..
  190094. isOpen_ = false;
  190095. return;
  190096. }
  190097. call->audioDeviceAboutToStart (this);
  190098. const ScopedLock sl (startStopLock);
  190099. callback = call;
  190100. isStarted = true;
  190101. }
  190102. }
  190103. void stop()
  190104. {
  190105. if (isStarted)
  190106. {
  190107. AudioIODeviceCallback* const callbackLocal = callback;
  190108. {
  190109. const ScopedLock sl (startStopLock);
  190110. isStarted = false;
  190111. }
  190112. if (callbackLocal != 0)
  190113. callbackLocal->audioDeviceStopped();
  190114. }
  190115. }
  190116. bool isPlaying()
  190117. {
  190118. return isStarted && isOpen_ && isThreadRunning();
  190119. }
  190120. const String getLastError()
  190121. {
  190122. return lastError;
  190123. }
  190124. juce_UseDebuggingNewOperator
  190125. StringArray inChannels, outChannels;
  190126. int outputDeviceIndex, inputDeviceIndex;
  190127. private:
  190128. bool isOpen_;
  190129. bool isStarted;
  190130. String lastError;
  190131. OwnedArray <DSoundInternalInChannel> inChans;
  190132. OwnedArray <DSoundInternalOutChannel> outChans;
  190133. WaitableEvent startEvent;
  190134. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190135. int volatile totalSamplesOut;
  190136. int64 volatile lastBlockTime;
  190137. double sampleRate;
  190138. BigInteger enabledInputs, enabledOutputs;
  190139. HeapBlock <float*> inputBuffers, outputBuffers;
  190140. AudioIODeviceCallback* callback;
  190141. CriticalSection startStopLock;
  190142. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190143. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190144. const String openDevice (const BigInteger& inputChannels,
  190145. const BigInteger& outputChannels,
  190146. double sampleRate_,
  190147. int bufferSizeSamples_);
  190148. void closeDevice()
  190149. {
  190150. isStarted = false;
  190151. stopThread (5000);
  190152. inChans.clear();
  190153. outChans.clear();
  190154. int i;
  190155. for (i = 0; i < numInputBuffers; ++i)
  190156. juce_free (inputBuffers[i]);
  190157. inputBuffers.free();
  190158. numInputBuffers = 0;
  190159. for (i = 0; i < numOutputBuffers; ++i)
  190160. juce_free (outputBuffers[i]);
  190161. outputBuffers.free();
  190162. numOutputBuffers = 0;
  190163. }
  190164. void resync()
  190165. {
  190166. if (! threadShouldExit())
  190167. {
  190168. sleep (5);
  190169. int i;
  190170. for (i = 0; i < outChans.size(); ++i)
  190171. outChans.getUnchecked(i)->synchronisePosition();
  190172. for (i = 0; i < inChans.size(); ++i)
  190173. inChans.getUnchecked(i)->synchronisePosition();
  190174. }
  190175. }
  190176. public:
  190177. void run()
  190178. {
  190179. while (! threadShouldExit())
  190180. {
  190181. if (wait (100))
  190182. break;
  190183. }
  190184. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190185. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190186. while (! threadShouldExit())
  190187. {
  190188. int numToDo = 0;
  190189. uint32 startTime = Time::getMillisecondCounter();
  190190. int i;
  190191. for (i = inChans.size(); --i >= 0;)
  190192. {
  190193. inChans.getUnchecked(i)->doneFlag = false;
  190194. ++numToDo;
  190195. }
  190196. for (i = outChans.size(); --i >= 0;)
  190197. {
  190198. outChans.getUnchecked(i)->doneFlag = false;
  190199. ++numToDo;
  190200. }
  190201. if (numToDo > 0)
  190202. {
  190203. const int maxCount = 3;
  190204. int count = maxCount;
  190205. for (;;)
  190206. {
  190207. for (i = inChans.size(); --i >= 0;)
  190208. {
  190209. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190210. if ((! in->doneFlag) && in->service())
  190211. {
  190212. in->doneFlag = true;
  190213. --numToDo;
  190214. }
  190215. }
  190216. for (i = outChans.size(); --i >= 0;)
  190217. {
  190218. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190219. if ((! out->doneFlag) && out->service())
  190220. {
  190221. out->doneFlag = true;
  190222. --numToDo;
  190223. }
  190224. }
  190225. if (numToDo <= 0)
  190226. break;
  190227. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190228. {
  190229. resync();
  190230. break;
  190231. }
  190232. if (--count <= 0)
  190233. {
  190234. Sleep (1);
  190235. count = maxCount;
  190236. }
  190237. if (threadShouldExit())
  190238. return;
  190239. }
  190240. }
  190241. else
  190242. {
  190243. sleep (1);
  190244. }
  190245. const ScopedLock sl (startStopLock);
  190246. if (isStarted)
  190247. {
  190248. JUCE_TRY
  190249. {
  190250. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190251. numInputBuffers,
  190252. outputBuffers,
  190253. numOutputBuffers,
  190254. bufferSizeSamples);
  190255. }
  190256. JUCE_CATCH_EXCEPTION
  190257. totalSamplesOut += bufferSizeSamples;
  190258. }
  190259. else
  190260. {
  190261. for (i = 0; i < numOutputBuffers; ++i)
  190262. if (outputBuffers[i] != 0)
  190263. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190264. totalSamplesOut = 0;
  190265. sleep (1);
  190266. }
  190267. }
  190268. }
  190269. };
  190270. class DSoundAudioIODeviceType : public AudioIODeviceType
  190271. {
  190272. public:
  190273. DSoundAudioIODeviceType()
  190274. : AudioIODeviceType ("DirectSound"),
  190275. hasScanned (false)
  190276. {
  190277. initialiseDSoundFunctions();
  190278. }
  190279. ~DSoundAudioIODeviceType()
  190280. {
  190281. }
  190282. void scanForDevices()
  190283. {
  190284. hasScanned = true;
  190285. outputDeviceNames.clear();
  190286. outputGuids.clear();
  190287. inputDeviceNames.clear();
  190288. inputGuids.clear();
  190289. if (dsDirectSoundEnumerateW != 0)
  190290. {
  190291. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190292. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190293. }
  190294. }
  190295. const StringArray getDeviceNames (bool wantInputNames) const
  190296. {
  190297. jassert (hasScanned); // need to call scanForDevices() before doing this
  190298. return wantInputNames ? inputDeviceNames
  190299. : outputDeviceNames;
  190300. }
  190301. int getDefaultDeviceIndex (bool /*forInput*/) const
  190302. {
  190303. jassert (hasScanned); // need to call scanForDevices() before doing this
  190304. return 0;
  190305. }
  190306. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  190307. {
  190308. jassert (hasScanned); // need to call scanForDevices() before doing this
  190309. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190310. if (d == 0)
  190311. return -1;
  190312. return asInput ? d->inputDeviceIndex
  190313. : d->outputDeviceIndex;
  190314. }
  190315. bool hasSeparateInputsAndOutputs() const { return true; }
  190316. AudioIODevice* createDevice (const String& outputDeviceName,
  190317. const String& inputDeviceName)
  190318. {
  190319. jassert (hasScanned); // need to call scanForDevices() before doing this
  190320. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190321. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190322. if (outputIndex >= 0 || inputIndex >= 0)
  190323. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190324. : inputDeviceName,
  190325. outputIndex, inputIndex);
  190326. return 0;
  190327. }
  190328. juce_UseDebuggingNewOperator
  190329. StringArray outputDeviceNames;
  190330. OwnedArray <GUID> outputGuids;
  190331. StringArray inputDeviceNames;
  190332. OwnedArray <GUID> inputGuids;
  190333. private:
  190334. bool hasScanned;
  190335. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190336. {
  190337. desc = desc.trim();
  190338. if (desc.isNotEmpty())
  190339. {
  190340. const String origDesc (desc);
  190341. int n = 2;
  190342. while (outputDeviceNames.contains (desc))
  190343. desc = origDesc + " (" + String (n++) + ")";
  190344. outputDeviceNames.add (desc);
  190345. if (lpGUID != 0)
  190346. outputGuids.add (new GUID (*lpGUID));
  190347. else
  190348. outputGuids.add (0);
  190349. }
  190350. return TRUE;
  190351. }
  190352. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190353. {
  190354. return ((DSoundAudioIODeviceType*) object)
  190355. ->outputEnumProc (lpGUID, String (description));
  190356. }
  190357. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190358. {
  190359. return ((DSoundAudioIODeviceType*) object)
  190360. ->outputEnumProc (lpGUID, String (description));
  190361. }
  190362. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190363. {
  190364. desc = desc.trim();
  190365. if (desc.isNotEmpty())
  190366. {
  190367. const String origDesc (desc);
  190368. int n = 2;
  190369. while (inputDeviceNames.contains (desc))
  190370. desc = origDesc + " (" + String (n++) + ")";
  190371. inputDeviceNames.add (desc);
  190372. if (lpGUID != 0)
  190373. inputGuids.add (new GUID (*lpGUID));
  190374. else
  190375. inputGuids.add (0);
  190376. }
  190377. return TRUE;
  190378. }
  190379. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190380. {
  190381. return ((DSoundAudioIODeviceType*) object)
  190382. ->inputEnumProc (lpGUID, String (description));
  190383. }
  190384. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190385. {
  190386. return ((DSoundAudioIODeviceType*) object)
  190387. ->inputEnumProc (lpGUID, String (description));
  190388. }
  190389. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190390. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190391. };
  190392. const String DSoundAudioIODevice::openDevice (const BigInteger& inputChannels,
  190393. const BigInteger& outputChannels,
  190394. double sampleRate_,
  190395. int bufferSizeSamples_)
  190396. {
  190397. closeDevice();
  190398. totalSamplesOut = 0;
  190399. sampleRate = sampleRate_;
  190400. if (bufferSizeSamples_ <= 0)
  190401. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190402. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190403. DSoundAudioIODeviceType dlh;
  190404. dlh.scanForDevices();
  190405. enabledInputs = inputChannels;
  190406. enabledInputs.setRange (inChannels.size(),
  190407. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190408. false);
  190409. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190410. inputBuffers.calloc (numInputBuffers + 2);
  190411. int i, numIns = 0;
  190412. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190413. {
  190414. float* left = 0;
  190415. float* right = 0;
  190416. if (enabledInputs[i])
  190417. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190418. if (enabledInputs[i + 1])
  190419. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190420. if (left != 0 || right != 0)
  190421. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190422. dlh.inputGuids [inputDeviceIndex],
  190423. (int) sampleRate, bufferSizeSamples,
  190424. left, right));
  190425. }
  190426. enabledOutputs = outputChannels;
  190427. enabledOutputs.setRange (outChannels.size(),
  190428. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190429. false);
  190430. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190431. outputBuffers.calloc (numOutputBuffers + 2);
  190432. int numOuts = 0;
  190433. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190434. {
  190435. float* left = 0;
  190436. float* right = 0;
  190437. if (enabledOutputs[i])
  190438. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190439. if (enabledOutputs[i + 1])
  190440. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190441. if (left != 0 || right != 0)
  190442. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190443. dlh.outputGuids [outputDeviceIndex],
  190444. (int) sampleRate, bufferSizeSamples,
  190445. left, right));
  190446. }
  190447. String error;
  190448. // boost our priority while opening the devices to try to get better sync between them
  190449. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190450. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190451. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  190452. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  190453. for (i = 0; i < outChans.size(); ++i)
  190454. {
  190455. error = outChans[i]->open();
  190456. if (error.isNotEmpty())
  190457. {
  190458. error = "Error opening " + dlh.outputDeviceNames[i] + ": \"" + error + "\"";
  190459. break;
  190460. }
  190461. }
  190462. if (error.isEmpty())
  190463. {
  190464. for (i = 0; i < inChans.size(); ++i)
  190465. {
  190466. error = inChans[i]->open();
  190467. if (error.isNotEmpty())
  190468. {
  190469. error = "Error opening " + dlh.inputDeviceNames[i] + ": \"" + error + "\"";
  190470. break;
  190471. }
  190472. }
  190473. }
  190474. if (error.isEmpty())
  190475. {
  190476. totalSamplesOut = 0;
  190477. for (i = 0; i < outChans.size(); ++i)
  190478. outChans.getUnchecked(i)->synchronisePosition();
  190479. for (i = 0; i < inChans.size(); ++i)
  190480. inChans.getUnchecked(i)->synchronisePosition();
  190481. startThread (9);
  190482. sleep (10);
  190483. notify();
  190484. }
  190485. else
  190486. {
  190487. log (error);
  190488. }
  190489. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  190490. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  190491. return error;
  190492. }
  190493. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  190494. {
  190495. return new DSoundAudioIODeviceType();
  190496. }
  190497. #undef log
  190498. #endif
  190499. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  190500. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  190501. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190502. // compiled on its own).
  190503. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  190504. #if 1
  190505. const String getAudioErrorDesc (HRESULT hr)
  190506. {
  190507. const char* e = 0;
  190508. switch (hr)
  190509. {
  190510. case E_POINTER: e = "E_POINTER"; break;
  190511. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  190512. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  190513. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  190514. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  190515. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  190516. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  190517. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  190518. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  190519. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  190520. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  190521. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  190522. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  190523. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  190524. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  190525. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  190526. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  190527. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  190528. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  190529. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  190530. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  190531. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  190532. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  190533. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  190534. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  190535. default: return String::toHexString ((int) hr);
  190536. }
  190537. return e;
  190538. }
  190539. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  190540. #define OK(a) wasapi_checkResult(a)
  190541. static bool wasapi_checkResult (HRESULT hr)
  190542. {
  190543. logFailure (hr);
  190544. return SUCCEEDED (hr);
  190545. }
  190546. #else
  190547. #define logFailure(hr) {}
  190548. #define OK(a) SUCCEEDED(a)
  190549. #endif
  190550. static const String wasapi_getDeviceID (IMMDevice* const device)
  190551. {
  190552. String s;
  190553. WCHAR* deviceId = 0;
  190554. if (OK (device->GetId (&deviceId)))
  190555. {
  190556. s = String (deviceId);
  190557. CoTaskMemFree (deviceId);
  190558. }
  190559. return s;
  190560. }
  190561. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  190562. {
  190563. EDataFlow flow = eRender;
  190564. ComSmartPtr <IMMEndpoint> endPoint;
  190565. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  190566. (void) OK (endPoint->GetDataFlow (&flow));
  190567. return flow;
  190568. }
  190569. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  190570. {
  190571. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  190572. }
  190573. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  190574. {
  190575. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  190576. : sizeof (WAVEFORMATEX));
  190577. }
  190578. class WASAPIDeviceBase
  190579. {
  190580. public:
  190581. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  190582. : device (device_),
  190583. sampleRate (0),
  190584. numChannels (0),
  190585. actualNumChannels (0),
  190586. defaultSampleRate (0),
  190587. minBufferSize (0),
  190588. defaultBufferSize (0),
  190589. latencySamples (0),
  190590. useExclusiveMode (useExclusiveMode_)
  190591. {
  190592. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  190593. ComSmartPtr <IAudioClient> tempClient (createClient());
  190594. if (tempClient == 0)
  190595. return;
  190596. REFERENCE_TIME defaultPeriod, minPeriod;
  190597. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  190598. return;
  190599. WAVEFORMATEX* mixFormat = 0;
  190600. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  190601. return;
  190602. WAVEFORMATEXTENSIBLE format;
  190603. wasapi_copyWavFormat (format, mixFormat);
  190604. CoTaskMemFree (mixFormat);
  190605. actualNumChannels = numChannels = format.Format.nChannels;
  190606. defaultSampleRate = format.Format.nSamplesPerSec;
  190607. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  190608. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  190609. rates.addUsingDefaultSort (defaultSampleRate);
  190610. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190611. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  190612. {
  190613. if (ratesToTest[i] == defaultSampleRate)
  190614. continue;
  190615. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  190616. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  190617. (WAVEFORMATEX*) &format, 0)))
  190618. if (! rates.contains (ratesToTest[i]))
  190619. rates.addUsingDefaultSort (ratesToTest[i]);
  190620. }
  190621. }
  190622. ~WASAPIDeviceBase()
  190623. {
  190624. device = 0;
  190625. CloseHandle (clientEvent);
  190626. }
  190627. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  190628. bool openClient (const double newSampleRate, const BigInteger& newChannels)
  190629. {
  190630. sampleRate = newSampleRate;
  190631. channels = newChannels;
  190632. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  190633. numChannels = channels.getHighestBit() + 1;
  190634. if (numChannels == 0)
  190635. return true;
  190636. client = createClient();
  190637. if (client != 0
  190638. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  190639. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  190640. {
  190641. channelMaps.clear();
  190642. for (int i = 0; i <= channels.getHighestBit(); ++i)
  190643. if (channels[i])
  190644. channelMaps.add (i);
  190645. REFERENCE_TIME latency;
  190646. if (OK (client->GetStreamLatency (&latency)))
  190647. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  190648. (void) OK (client->GetBufferSize (&actualBufferSize));
  190649. return OK (client->SetEventHandle (clientEvent));
  190650. }
  190651. return false;
  190652. }
  190653. void closeClient()
  190654. {
  190655. if (client != 0)
  190656. client->Stop();
  190657. client = 0;
  190658. ResetEvent (clientEvent);
  190659. }
  190660. ComSmartPtr <IMMDevice> device;
  190661. ComSmartPtr <IAudioClient> client;
  190662. double sampleRate, defaultSampleRate;
  190663. int numChannels, actualNumChannels;
  190664. int minBufferSize, defaultBufferSize, latencySamples;
  190665. const bool useExclusiveMode;
  190666. Array <double> rates;
  190667. HANDLE clientEvent;
  190668. BigInteger channels;
  190669. AudioDataConverters::DataFormat dataFormat;
  190670. Array <int> channelMaps;
  190671. UINT32 actualBufferSize;
  190672. int bytesPerSample;
  190673. private:
  190674. const ComSmartPtr <IAudioClient> createClient()
  190675. {
  190676. ComSmartPtr <IAudioClient> client;
  190677. if (device != 0)
  190678. {
  190679. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  190680. logFailure (hr);
  190681. }
  190682. return client;
  190683. }
  190684. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  190685. {
  190686. WAVEFORMATEXTENSIBLE format;
  190687. zerostruct (format);
  190688. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  190689. {
  190690. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  190691. }
  190692. else
  190693. {
  190694. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  190695. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  190696. }
  190697. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  190698. format.Format.nChannels = (WORD) numChannels;
  190699. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  190700. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  190701. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  190702. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  190703. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  190704. switch (numChannels)
  190705. {
  190706. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  190707. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  190708. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  190709. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  190710. case 8: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_FRONT_LEFT_OF_CENTER | SPEAKER_FRONT_RIGHT_OF_CENTER; break;
  190711. default: break;
  190712. }
  190713. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  190714. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  190715. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  190716. logFailure (hr);
  190717. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  190718. {
  190719. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  190720. hr = S_OK;
  190721. }
  190722. CoTaskMemFree (nearestFormat);
  190723. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  190724. if (useExclusiveMode)
  190725. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  190726. GUID session;
  190727. if (hr == S_OK
  190728. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  190729. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  190730. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  190731. {
  190732. actualNumChannels = format.Format.nChannels;
  190733. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  190734. bytesPerSample = format.Format.wBitsPerSample / 8;
  190735. dataFormat = isFloat ? AudioDataConverters::float32LE
  190736. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  190737. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  190738. : AudioDataConverters::int16LE)));
  190739. return true;
  190740. }
  190741. return false;
  190742. }
  190743. WASAPIDeviceBase (const WASAPIDeviceBase&);
  190744. WASAPIDeviceBase& operator= (const WASAPIDeviceBase&);
  190745. };
  190746. class WASAPIInputDevice : public WASAPIDeviceBase
  190747. {
  190748. public:
  190749. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  190750. : WASAPIDeviceBase (device_, useExclusiveMode_),
  190751. reservoir (1, 1)
  190752. {
  190753. }
  190754. ~WASAPIInputDevice()
  190755. {
  190756. close();
  190757. }
  190758. bool open (const double newSampleRate, const BigInteger& newChannels)
  190759. {
  190760. reservoirSize = 0;
  190761. reservoirCapacity = 16384;
  190762. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  190763. return openClient (newSampleRate, newChannels)
  190764. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  190765. }
  190766. void close()
  190767. {
  190768. closeClient();
  190769. captureClient = 0;
  190770. reservoir.setSize (0);
  190771. }
  190772. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  190773. {
  190774. if (numChannels <= 0)
  190775. return;
  190776. int offset = 0;
  190777. while (bufferSize > 0)
  190778. {
  190779. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  190780. {
  190781. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  190782. for (int i = 0; i < numDestBuffers; ++i)
  190783. {
  190784. float* const dest = destBuffers[i] + offset;
  190785. const int srcChan = channelMaps.getUnchecked(i);
  190786. switch (dataFormat)
  190787. {
  190788. case AudioDataConverters::float32LE:
  190789. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  190790. break;
  190791. case AudioDataConverters::int32LE:
  190792. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  190793. break;
  190794. case AudioDataConverters::int24LE:
  190795. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  190796. break;
  190797. case AudioDataConverters::int16LE:
  190798. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  190799. break;
  190800. default: jassertfalse; break;
  190801. }
  190802. }
  190803. bufferSize -= samplesToDo;
  190804. offset += samplesToDo;
  190805. reservoirSize -= samplesToDo;
  190806. }
  190807. else
  190808. {
  190809. UINT32 packetLength = 0;
  190810. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  190811. break;
  190812. if (packetLength == 0)
  190813. {
  190814. if (thread.threadShouldExit())
  190815. break;
  190816. Thread::sleep (1);
  190817. continue;
  190818. }
  190819. uint8* inputData = 0;
  190820. UINT32 numSamplesAvailable;
  190821. DWORD flags;
  190822. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  190823. {
  190824. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  190825. for (int i = 0; i < numDestBuffers; ++i)
  190826. {
  190827. float* const dest = destBuffers[i] + offset;
  190828. const int srcChan = channelMaps.getUnchecked(i);
  190829. switch (dataFormat)
  190830. {
  190831. case AudioDataConverters::float32LE:
  190832. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  190833. break;
  190834. case AudioDataConverters::int32LE:
  190835. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  190836. break;
  190837. case AudioDataConverters::int24LE:
  190838. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  190839. break;
  190840. case AudioDataConverters::int16LE:
  190841. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  190842. break;
  190843. default: jassertfalse; break;
  190844. }
  190845. }
  190846. bufferSize -= samplesToDo;
  190847. offset += samplesToDo;
  190848. if (samplesToDo < (int) numSamplesAvailable)
  190849. {
  190850. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  190851. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  190852. bytesPerSample * actualNumChannels * reservoirSize);
  190853. }
  190854. captureClient->ReleaseBuffer (numSamplesAvailable);
  190855. }
  190856. }
  190857. }
  190858. }
  190859. ComSmartPtr <IAudioCaptureClient> captureClient;
  190860. MemoryBlock reservoir;
  190861. int reservoirSize, reservoirCapacity;
  190862. private:
  190863. WASAPIInputDevice (const WASAPIInputDevice&);
  190864. WASAPIInputDevice& operator= (const WASAPIInputDevice&);
  190865. };
  190866. class WASAPIOutputDevice : public WASAPIDeviceBase
  190867. {
  190868. public:
  190869. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  190870. : WASAPIDeviceBase (device_, useExclusiveMode_)
  190871. {
  190872. }
  190873. ~WASAPIOutputDevice()
  190874. {
  190875. close();
  190876. }
  190877. bool open (const double newSampleRate, const BigInteger& newChannels)
  190878. {
  190879. return openClient (newSampleRate, newChannels)
  190880. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  190881. }
  190882. void close()
  190883. {
  190884. closeClient();
  190885. renderClient = 0;
  190886. }
  190887. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  190888. {
  190889. if (numChannels <= 0)
  190890. return;
  190891. int offset = 0;
  190892. while (bufferSize > 0)
  190893. {
  190894. UINT32 padding = 0;
  190895. if (! OK (client->GetCurrentPadding (&padding)))
  190896. return;
  190897. int samplesToDo = useExclusiveMode ? bufferSize
  190898. : jmin ((int) (actualBufferSize - padding), bufferSize);
  190899. if (samplesToDo <= 0)
  190900. {
  190901. if (thread.threadShouldExit())
  190902. break;
  190903. Thread::sleep (0);
  190904. continue;
  190905. }
  190906. uint8* outputData = 0;
  190907. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  190908. {
  190909. for (int i = 0; i < numSrcBuffers; ++i)
  190910. {
  190911. const float* const source = srcBuffers[i] + offset;
  190912. const int destChan = channelMaps.getUnchecked(i);
  190913. switch (dataFormat)
  190914. {
  190915. case AudioDataConverters::float32LE:
  190916. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  190917. break;
  190918. case AudioDataConverters::int32LE:
  190919. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  190920. break;
  190921. case AudioDataConverters::int24LE:
  190922. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  190923. break;
  190924. case AudioDataConverters::int16LE:
  190925. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  190926. break;
  190927. default: jassertfalse; break;
  190928. }
  190929. }
  190930. renderClient->ReleaseBuffer (samplesToDo, 0);
  190931. offset += samplesToDo;
  190932. bufferSize -= samplesToDo;
  190933. }
  190934. }
  190935. }
  190936. ComSmartPtr <IAudioRenderClient> renderClient;
  190937. private:
  190938. WASAPIOutputDevice (const WASAPIOutputDevice&);
  190939. WASAPIOutputDevice& operator= (const WASAPIOutputDevice&);
  190940. };
  190941. class WASAPIAudioIODevice : public AudioIODevice,
  190942. public Thread
  190943. {
  190944. public:
  190945. WASAPIAudioIODevice (const String& deviceName,
  190946. const String& outputDeviceId_,
  190947. const String& inputDeviceId_,
  190948. const bool useExclusiveMode_)
  190949. : AudioIODevice (deviceName, "Windows Audio"),
  190950. Thread ("Juce WASAPI"),
  190951. isOpen_ (false),
  190952. isStarted (false),
  190953. outputDevice (0),
  190954. outputDeviceId (outputDeviceId_),
  190955. inputDevice (0),
  190956. inputDeviceId (inputDeviceId_),
  190957. useExclusiveMode (useExclusiveMode_),
  190958. currentBufferSizeSamples (0),
  190959. currentSampleRate (0),
  190960. callback (0)
  190961. {
  190962. }
  190963. ~WASAPIAudioIODevice()
  190964. {
  190965. close();
  190966. deleteAndZero (inputDevice);
  190967. deleteAndZero (outputDevice);
  190968. }
  190969. bool initialise()
  190970. {
  190971. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  190972. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  190973. latencyIn = latencyOut = 0;
  190974. Array <double> ratesIn, ratesOut;
  190975. if (createDevices())
  190976. {
  190977. jassert (inputDevice != 0 || outputDevice != 0);
  190978. if (inputDevice != 0 && outputDevice != 0)
  190979. {
  190980. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  190981. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  190982. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  190983. sampleRates = inputDevice->rates;
  190984. sampleRates.removeValuesNotIn (outputDevice->rates);
  190985. }
  190986. else
  190987. {
  190988. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  190989. defaultSampleRate = d->defaultSampleRate;
  190990. minBufferSize = d->minBufferSize;
  190991. defaultBufferSize = d->defaultBufferSize;
  190992. sampleRates = d->rates;
  190993. }
  190994. bufferSizes.addUsingDefaultSort (defaultBufferSize);
  190995. if (minBufferSize != defaultBufferSize)
  190996. bufferSizes.addUsingDefaultSort (minBufferSize);
  190997. int n = 64;
  190998. for (int i = 0; i < 40; ++i)
  190999. {
  191000. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191001. bufferSizes.addUsingDefaultSort (n);
  191002. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191003. }
  191004. return true;
  191005. }
  191006. return false;
  191007. }
  191008. const StringArray getOutputChannelNames()
  191009. {
  191010. StringArray outChannels;
  191011. if (outputDevice != 0)
  191012. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191013. outChannels.add ("Output channel " + String (i));
  191014. return outChannels;
  191015. }
  191016. const StringArray getInputChannelNames()
  191017. {
  191018. StringArray inChannels;
  191019. if (inputDevice != 0)
  191020. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191021. inChannels.add ("Input channel " + String (i));
  191022. return inChannels;
  191023. }
  191024. int getNumSampleRates() { return sampleRates.size(); }
  191025. double getSampleRate (int index) { return sampleRates [index]; }
  191026. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191027. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191028. int getDefaultBufferSize() { return defaultBufferSize; }
  191029. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191030. double getCurrentSampleRate() { return currentSampleRate; }
  191031. int getCurrentBitDepth() { return 32; }
  191032. int getOutputLatencyInSamples() { return latencyOut; }
  191033. int getInputLatencyInSamples() { return latencyIn; }
  191034. const BigInteger getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BigInteger(); }
  191035. const BigInteger getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BigInteger(); }
  191036. const String getLastError() { return lastError; }
  191037. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  191038. double sampleRate, int bufferSizeSamples)
  191039. {
  191040. close();
  191041. lastError = String::empty;
  191042. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191043. {
  191044. lastError = "The input and output devices don't share a common sample rate!";
  191045. return lastError;
  191046. }
  191047. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191048. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191049. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191050. {
  191051. lastError = "Couldn't open the input device!";
  191052. return lastError;
  191053. }
  191054. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191055. {
  191056. close();
  191057. lastError = "Couldn't open the output device!";
  191058. return lastError;
  191059. }
  191060. if (inputDevice != 0)
  191061. ResetEvent (inputDevice->clientEvent);
  191062. if (outputDevice != 0)
  191063. ResetEvent (outputDevice->clientEvent);
  191064. startThread (8);
  191065. Thread::sleep (5);
  191066. if (inputDevice != 0 && inputDevice->client != 0)
  191067. {
  191068. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191069. HRESULT hr = inputDevice->client->Start();
  191070. logFailure (hr); //xxx handle this
  191071. }
  191072. if (outputDevice != 0 && outputDevice->client != 0)
  191073. {
  191074. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191075. HRESULT hr = outputDevice->client->Start();
  191076. logFailure (hr); //xxx handle this
  191077. }
  191078. isOpen_ = true;
  191079. return lastError;
  191080. }
  191081. void close()
  191082. {
  191083. stop();
  191084. if (inputDevice != 0)
  191085. SetEvent (inputDevice->clientEvent);
  191086. if (outputDevice != 0)
  191087. SetEvent (outputDevice->clientEvent);
  191088. stopThread (5000);
  191089. if (inputDevice != 0)
  191090. inputDevice->close();
  191091. if (outputDevice != 0)
  191092. outputDevice->close();
  191093. isOpen_ = false;
  191094. }
  191095. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191096. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191097. void start (AudioIODeviceCallback* call)
  191098. {
  191099. if (isOpen_ && call != 0 && ! isStarted)
  191100. {
  191101. if (! isThreadRunning())
  191102. {
  191103. // something's gone wrong and the thread's stopped..
  191104. isOpen_ = false;
  191105. return;
  191106. }
  191107. call->audioDeviceAboutToStart (this);
  191108. const ScopedLock sl (startStopLock);
  191109. callback = call;
  191110. isStarted = true;
  191111. }
  191112. }
  191113. void stop()
  191114. {
  191115. if (isStarted)
  191116. {
  191117. AudioIODeviceCallback* const callbackLocal = callback;
  191118. {
  191119. const ScopedLock sl (startStopLock);
  191120. isStarted = false;
  191121. }
  191122. if (callbackLocal != 0)
  191123. callbackLocal->audioDeviceStopped();
  191124. }
  191125. }
  191126. void setMMThreadPriority()
  191127. {
  191128. DynamicLibraryLoader dll ("avrt.dll");
  191129. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191130. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191131. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191132. {
  191133. DWORD dummy = 0;
  191134. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191135. if (h != 0)
  191136. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191137. }
  191138. }
  191139. void run()
  191140. {
  191141. setMMThreadPriority();
  191142. const int bufferSize = currentBufferSizeSamples;
  191143. HANDLE events[2];
  191144. int numEvents = 0;
  191145. if (inputDevice != 0)
  191146. events [numEvents++] = inputDevice->clientEvent;
  191147. if (outputDevice != 0)
  191148. events [numEvents++] = outputDevice->clientEvent;
  191149. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191150. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191151. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191152. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191153. float** const inputBuffers = ins.getArrayOfChannels();
  191154. float** const outputBuffers = outs.getArrayOfChannels();
  191155. ins.clear();
  191156. while (! threadShouldExit())
  191157. {
  191158. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191159. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191160. if (result == WAIT_TIMEOUT)
  191161. continue;
  191162. if (threadShouldExit())
  191163. break;
  191164. if (inputDevice != 0)
  191165. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191166. // Make the callback..
  191167. {
  191168. const ScopedLock sl (startStopLock);
  191169. if (isStarted)
  191170. {
  191171. JUCE_TRY
  191172. {
  191173. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191174. numInputBuffers,
  191175. outputBuffers,
  191176. numOutputBuffers,
  191177. bufferSize);
  191178. }
  191179. JUCE_CATCH_EXCEPTION
  191180. }
  191181. else
  191182. {
  191183. outs.clear();
  191184. }
  191185. }
  191186. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191187. continue;
  191188. if (outputDevice != 0)
  191189. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191190. }
  191191. }
  191192. juce_UseDebuggingNewOperator
  191193. String outputDeviceId, inputDeviceId;
  191194. String lastError;
  191195. private:
  191196. // Device stats...
  191197. WASAPIInputDevice* inputDevice;
  191198. WASAPIOutputDevice* outputDevice;
  191199. const bool useExclusiveMode;
  191200. double defaultSampleRate;
  191201. int minBufferSize, defaultBufferSize;
  191202. int latencyIn, latencyOut;
  191203. Array <double> sampleRates;
  191204. Array <int> bufferSizes;
  191205. // Active state...
  191206. bool isOpen_, isStarted;
  191207. int currentBufferSizeSamples;
  191208. double currentSampleRate;
  191209. AudioIODeviceCallback* callback;
  191210. CriticalSection startStopLock;
  191211. bool createDevices()
  191212. {
  191213. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191214. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator))))
  191215. return false;
  191216. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191217. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191218. return false;
  191219. UINT32 numDevices = 0;
  191220. if (! OK (deviceCollection->GetCount (&numDevices)))
  191221. return false;
  191222. for (UINT32 i = 0; i < numDevices; ++i)
  191223. {
  191224. ComSmartPtr <IMMDevice> device;
  191225. if (! OK (deviceCollection->Item (i, &device)))
  191226. continue;
  191227. const String deviceId (wasapi_getDeviceID (device));
  191228. if (deviceId.isEmpty())
  191229. continue;
  191230. const EDataFlow flow = wasapi_getDataFlow (device);
  191231. if (deviceId == inputDeviceId && flow == eCapture)
  191232. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191233. else if (deviceId == outputDeviceId && flow == eRender)
  191234. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191235. }
  191236. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191237. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191238. }
  191239. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191240. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191241. };
  191242. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191243. {
  191244. public:
  191245. WASAPIAudioIODeviceType()
  191246. : AudioIODeviceType ("Windows Audio"),
  191247. hasScanned (false)
  191248. {
  191249. }
  191250. ~WASAPIAudioIODeviceType()
  191251. {
  191252. }
  191253. void scanForDevices()
  191254. {
  191255. hasScanned = true;
  191256. outputDeviceNames.clear();
  191257. inputDeviceNames.clear();
  191258. outputDeviceIds.clear();
  191259. inputDeviceIds.clear();
  191260. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191261. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator))))
  191262. return;
  191263. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191264. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191265. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191266. UINT32 numDevices = 0;
  191267. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191268. && OK (deviceCollection->GetCount (&numDevices))))
  191269. return;
  191270. for (UINT32 i = 0; i < numDevices; ++i)
  191271. {
  191272. ComSmartPtr <IMMDevice> device;
  191273. if (! OK (deviceCollection->Item (i, &device)))
  191274. continue;
  191275. const String deviceId (wasapi_getDeviceID (device));
  191276. DWORD state = 0;
  191277. if (! OK (device->GetState (&state)))
  191278. continue;
  191279. if (state != DEVICE_STATE_ACTIVE)
  191280. continue;
  191281. String name;
  191282. {
  191283. ComSmartPtr <IPropertyStore> properties;
  191284. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191285. continue;
  191286. PROPVARIANT value;
  191287. PropVariantInit (&value);
  191288. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191289. name = value.pwszVal;
  191290. PropVariantClear (&value);
  191291. }
  191292. const EDataFlow flow = wasapi_getDataFlow (device);
  191293. if (flow == eRender)
  191294. {
  191295. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191296. outputDeviceIds.insert (index, deviceId);
  191297. outputDeviceNames.insert (index, name);
  191298. }
  191299. else if (flow == eCapture)
  191300. {
  191301. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191302. inputDeviceIds.insert (index, deviceId);
  191303. inputDeviceNames.insert (index, name);
  191304. }
  191305. }
  191306. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191307. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191308. }
  191309. const StringArray getDeviceNames (bool wantInputNames) const
  191310. {
  191311. jassert (hasScanned); // need to call scanForDevices() before doing this
  191312. return wantInputNames ? inputDeviceNames
  191313. : outputDeviceNames;
  191314. }
  191315. int getDefaultDeviceIndex (bool /*forInput*/) const
  191316. {
  191317. jassert (hasScanned); // need to call scanForDevices() before doing this
  191318. return 0;
  191319. }
  191320. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  191321. {
  191322. jassert (hasScanned); // need to call scanForDevices() before doing this
  191323. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191324. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191325. : outputDeviceIds.indexOf (d->outputDeviceId));
  191326. }
  191327. bool hasSeparateInputsAndOutputs() const { return true; }
  191328. AudioIODevice* createDevice (const String& outputDeviceName,
  191329. const String& inputDeviceName)
  191330. {
  191331. jassert (hasScanned); // need to call scanForDevices() before doing this
  191332. const bool useExclusiveMode = false;
  191333. ScopedPointer<WASAPIAudioIODevice> device;
  191334. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191335. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191336. if (outputIndex >= 0 || inputIndex >= 0)
  191337. {
  191338. device = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191339. : inputDeviceName,
  191340. outputDeviceIds [outputIndex],
  191341. inputDeviceIds [inputIndex],
  191342. useExclusiveMode);
  191343. if (! device->initialise())
  191344. device = 0;
  191345. }
  191346. return device.release();
  191347. }
  191348. juce_UseDebuggingNewOperator
  191349. StringArray outputDeviceNames, outputDeviceIds;
  191350. StringArray inputDeviceNames, inputDeviceIds;
  191351. private:
  191352. bool hasScanned;
  191353. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191354. {
  191355. String s;
  191356. IMMDevice* dev = 0;
  191357. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191358. eMultimedia, &dev)))
  191359. {
  191360. WCHAR* deviceId = 0;
  191361. if (OK (dev->GetId (&deviceId)))
  191362. {
  191363. s = String (deviceId);
  191364. CoTaskMemFree (deviceId);
  191365. }
  191366. dev->Release();
  191367. }
  191368. return s;
  191369. }
  191370. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191371. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191372. };
  191373. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191374. {
  191375. return new WASAPIAudioIODeviceType();
  191376. }
  191377. #undef logFailure
  191378. #undef OK
  191379. #endif
  191380. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191381. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191382. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191383. // compiled on its own).
  191384. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191385. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191386. {
  191387. public:
  191388. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191389. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191390. const ComSmartPtr <IBaseFilter>& filter_,
  191391. int minWidth, int minHeight,
  191392. int maxWidth, int maxHeight)
  191393. : owner (owner_),
  191394. captureGraphBuilder (captureGraphBuilder_),
  191395. filter (filter_),
  191396. ok (false),
  191397. imageNeedsFlipping (false),
  191398. width (0),
  191399. height (0),
  191400. activeUsers (0),
  191401. recordNextFrameTime (false),
  191402. activeImage (0),
  191403. loadingImage (0)
  191404. {
  191405. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph);
  191406. if (FAILED (hr))
  191407. return;
  191408. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191409. if (FAILED (hr))
  191410. return;
  191411. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191412. if (FAILED (hr))
  191413. return;
  191414. {
  191415. ComSmartPtr <IAMStreamConfig> streamConfig;
  191416. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191417. IID_IAMStreamConfig, (void**) &streamConfig);
  191418. if (streamConfig != 0)
  191419. {
  191420. getVideoSizes (streamConfig);
  191421. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191422. return;
  191423. }
  191424. }
  191425. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191426. if (FAILED (hr))
  191427. return;
  191428. hr = smartTee.CoCreateInstance (CLSID_SmartTee);
  191429. if (FAILED (hr))
  191430. return;
  191431. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191432. if (FAILED (hr))
  191433. return;
  191434. if (! connectFilters (filter, smartTee))
  191435. return;
  191436. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191437. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber);
  191438. if (FAILED (hr))
  191439. return;
  191440. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191441. if (FAILED (hr))
  191442. return;
  191443. AM_MEDIA_TYPE mt;
  191444. zerostruct (mt);
  191445. mt.majortype = MEDIATYPE_Video;
  191446. mt.subtype = MEDIASUBTYPE_RGB24;
  191447. mt.formattype = FORMAT_VideoInfo;
  191448. sampleGrabber->SetMediaType (&mt);
  191449. callback = new GrabberCallback (*this);
  191450. sampleGrabber->SetCallback (callback, 1);
  191451. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191452. if (FAILED (hr))
  191453. return;
  191454. ComSmartPtr <IPin> grabberInputPin;
  191455. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  191456. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  191457. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  191458. return;
  191459. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  191460. if (FAILED (hr))
  191461. return;
  191462. zerostruct (mt);
  191463. hr = sampleGrabber->GetConnectedMediaType (&mt);
  191464. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  191465. width = pVih->bmiHeader.biWidth;
  191466. height = pVih->bmiHeader.biHeight;
  191467. ComSmartPtr <IBaseFilter> nullFilter;
  191468. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer);
  191469. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  191470. if (connectFilters (sampleGrabberBase, nullFilter)
  191471. && addGraphToRot())
  191472. {
  191473. activeImage = new Image (Image::RGB, width, height, true);
  191474. loadingImage = new Image (Image::RGB, width, height, true);
  191475. ok = true;
  191476. }
  191477. }
  191478. ~DShowCameraDeviceInteral()
  191479. {
  191480. if (mediaControl != 0)
  191481. mediaControl->Stop();
  191482. removeGraphFromRot();
  191483. for (int i = viewerComps.size(); --i >= 0;)
  191484. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  191485. callback = 0;
  191486. graphBuilder = 0;
  191487. sampleGrabber = 0;
  191488. mediaControl = 0;
  191489. filter = 0;
  191490. captureGraphBuilder = 0;
  191491. smartTee = 0;
  191492. smartTeePreviewOutputPin = 0;
  191493. smartTeeCaptureOutputPin = 0;
  191494. asfWriter = 0;
  191495. delete activeImage;
  191496. delete loadingImage;
  191497. }
  191498. void addUser()
  191499. {
  191500. if (ok && activeUsers++ == 0)
  191501. mediaControl->Run();
  191502. }
  191503. void removeUser()
  191504. {
  191505. if (ok && --activeUsers == 0)
  191506. mediaControl->Stop();
  191507. }
  191508. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  191509. {
  191510. if (recordNextFrameTime)
  191511. {
  191512. const double defaultCameraLatency = 0.1;
  191513. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  191514. recordNextFrameTime = false;
  191515. ComSmartPtr <IPin> pin;
  191516. if (getPin (filter, PINDIR_OUTPUT, &pin))
  191517. {
  191518. ComSmartPtr <IAMPushSource> pushSource;
  191519. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  191520. if (pushSource != 0)
  191521. {
  191522. REFERENCE_TIME latency = 0;
  191523. hr = pushSource->GetLatency (&latency);
  191524. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  191525. }
  191526. }
  191527. }
  191528. {
  191529. const int lineStride = width * 3;
  191530. const ScopedLock sl (imageSwapLock);
  191531. {
  191532. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  191533. for (int i = 0; i < height; ++i)
  191534. memcpy (destData.getLinePointer ((height - 1) - i),
  191535. buffer + lineStride * i,
  191536. lineStride);
  191537. }
  191538. imageNeedsFlipping = true;
  191539. }
  191540. if (listeners.size() > 0)
  191541. callListeners (*loadingImage);
  191542. sendChangeMessage (this);
  191543. }
  191544. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  191545. {
  191546. if (imageNeedsFlipping)
  191547. {
  191548. const ScopedLock sl (imageSwapLock);
  191549. swapVariables (loadingImage, activeImage);
  191550. imageNeedsFlipping = false;
  191551. }
  191552. RectanglePlacement rp (RectanglePlacement::centred);
  191553. double dx = 0, dy = 0, dw = width, dh = height;
  191554. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  191555. const int rx = roundToInt (dx), ry = roundToInt (dy);
  191556. const int rw = roundToInt (dw), rh = roundToInt (dh);
  191557. g.saveState();
  191558. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  191559. g.fillAll (Colours::black);
  191560. g.restoreState();
  191561. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  191562. }
  191563. bool createFileCaptureFilter (const File& file)
  191564. {
  191565. removeFileCaptureFilter();
  191566. file.deleteFile();
  191567. mediaControl->Stop();
  191568. firstRecordedTime = Time();
  191569. recordNextFrameTime = true;
  191570. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter);
  191571. if (SUCCEEDED (hr))
  191572. {
  191573. ComSmartPtr <IFileSinkFilter> fileSink;
  191574. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  191575. if (SUCCEEDED (hr))
  191576. {
  191577. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  191578. if (SUCCEEDED (hr))
  191579. {
  191580. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  191581. if (SUCCEEDED (hr))
  191582. {
  191583. ComSmartPtr <IConfigAsfWriter> asfConfig;
  191584. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  191585. asfConfig->SetIndexMode (true);
  191586. ComSmartPtr <IWMProfileManager> profileManager;
  191587. hr = WMCreateProfileManager (&profileManager);
  191588. // This gibberish is the DirectShow profile for a video-only wmv file.
  191589. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  191590. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  191591. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  191592. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  191593. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  191594. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  191595. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  191596. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  191597. prof = prof.replace ("$WIDTH", String (width))
  191598. .replace ("$HEIGHT", String (height));
  191599. ComSmartPtr <IWMProfile> currentProfile;
  191600. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  191601. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  191602. if (SUCCEEDED (hr))
  191603. {
  191604. ComSmartPtr <IPin> asfWriterInputPin;
  191605. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  191606. {
  191607. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  191608. if (SUCCEEDED (hr)
  191609. && ok && activeUsers > 0
  191610. && SUCCEEDED (mediaControl->Run()))
  191611. {
  191612. return true;
  191613. }
  191614. }
  191615. }
  191616. }
  191617. }
  191618. }
  191619. }
  191620. removeFileCaptureFilter();
  191621. if (ok && activeUsers > 0)
  191622. mediaControl->Run();
  191623. return false;
  191624. }
  191625. void removeFileCaptureFilter()
  191626. {
  191627. mediaControl->Stop();
  191628. if (asfWriter != 0)
  191629. {
  191630. graphBuilder->RemoveFilter (asfWriter);
  191631. asfWriter = 0;
  191632. }
  191633. if (ok && activeUsers > 0)
  191634. mediaControl->Run();
  191635. }
  191636. void addListener (CameraImageListener* listenerToAdd)
  191637. {
  191638. const ScopedLock sl (listenerLock);
  191639. if (listeners.size() == 0)
  191640. addUser();
  191641. listeners.addIfNotAlreadyThere (listenerToAdd);
  191642. }
  191643. void removeListener (CameraImageListener* listenerToRemove)
  191644. {
  191645. const ScopedLock sl (listenerLock);
  191646. listeners.removeValue (listenerToRemove);
  191647. if (listeners.size() == 0)
  191648. removeUser();
  191649. }
  191650. void callListeners (Image& image)
  191651. {
  191652. const ScopedLock sl (listenerLock);
  191653. for (int i = listeners.size(); --i >= 0;)
  191654. {
  191655. CameraImageListener* l = (CameraImageListener*) listeners[i];
  191656. if (l != 0)
  191657. l->imageReceived (image);
  191658. }
  191659. }
  191660. class DShowCaptureViewerComp : public Component,
  191661. public ChangeListener
  191662. {
  191663. public:
  191664. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  191665. : owner (owner_)
  191666. {
  191667. setOpaque (true);
  191668. owner->addChangeListener (this);
  191669. owner->addUser();
  191670. owner->viewerComps.add (this);
  191671. setSize (owner_->width, owner_->height);
  191672. }
  191673. ~DShowCaptureViewerComp()
  191674. {
  191675. if (owner != 0)
  191676. {
  191677. owner->viewerComps.removeValue (this);
  191678. owner->removeUser();
  191679. owner->removeChangeListener (this);
  191680. }
  191681. }
  191682. void ownerDeleted()
  191683. {
  191684. owner = 0;
  191685. }
  191686. void paint (Graphics& g)
  191687. {
  191688. g.setColour (Colours::black);
  191689. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  191690. if (owner != 0)
  191691. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  191692. else
  191693. g.fillAll (Colours::black);
  191694. }
  191695. void changeListenerCallback (void*)
  191696. {
  191697. repaint();
  191698. }
  191699. private:
  191700. DShowCameraDeviceInteral* owner;
  191701. };
  191702. bool ok;
  191703. int width, height;
  191704. Time firstRecordedTime;
  191705. VoidArray viewerComps;
  191706. private:
  191707. CameraDevice* const owner;
  191708. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  191709. ComSmartPtr <IBaseFilter> filter;
  191710. ComSmartPtr <IBaseFilter> smartTee;
  191711. ComSmartPtr <IGraphBuilder> graphBuilder;
  191712. ComSmartPtr <ISampleGrabber> sampleGrabber;
  191713. ComSmartPtr <IMediaControl> mediaControl;
  191714. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  191715. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  191716. ComSmartPtr <IBaseFilter> asfWriter;
  191717. int activeUsers;
  191718. Array <int> widths, heights;
  191719. DWORD graphRegistrationID;
  191720. CriticalSection imageSwapLock;
  191721. bool imageNeedsFlipping;
  191722. Image* loadingImage;
  191723. Image* activeImage;
  191724. bool recordNextFrameTime;
  191725. void getVideoSizes (IAMStreamConfig* const streamConfig)
  191726. {
  191727. widths.clear();
  191728. heights.clear();
  191729. int count = 0, size = 0;
  191730. streamConfig->GetNumberOfCapabilities (&count, &size);
  191731. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  191732. {
  191733. for (int i = 0; i < count; ++i)
  191734. {
  191735. VIDEO_STREAM_CONFIG_CAPS scc;
  191736. AM_MEDIA_TYPE* config;
  191737. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  191738. if (SUCCEEDED (hr))
  191739. {
  191740. const int w = scc.InputSize.cx;
  191741. const int h = scc.InputSize.cy;
  191742. bool duplicate = false;
  191743. for (int j = widths.size(); --j >= 0;)
  191744. {
  191745. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  191746. {
  191747. duplicate = true;
  191748. break;
  191749. }
  191750. }
  191751. if (! duplicate)
  191752. {
  191753. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  191754. widths.add (w);
  191755. heights.add (h);
  191756. }
  191757. deleteMediaType (config);
  191758. }
  191759. }
  191760. }
  191761. }
  191762. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  191763. const int minWidth, const int minHeight,
  191764. const int maxWidth, const int maxHeight)
  191765. {
  191766. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  191767. streamConfig->GetNumberOfCapabilities (&count, &size);
  191768. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  191769. {
  191770. AM_MEDIA_TYPE* config;
  191771. VIDEO_STREAM_CONFIG_CAPS scc;
  191772. for (int i = 0; i < count; ++i)
  191773. {
  191774. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  191775. if (SUCCEEDED (hr))
  191776. {
  191777. if (scc.InputSize.cx >= minWidth
  191778. && scc.InputSize.cy >= minHeight
  191779. && scc.InputSize.cx <= maxWidth
  191780. && scc.InputSize.cy <= maxHeight)
  191781. {
  191782. int area = scc.InputSize.cx * scc.InputSize.cy;
  191783. if (area > bestArea)
  191784. {
  191785. bestIndex = i;
  191786. bestArea = area;
  191787. }
  191788. }
  191789. deleteMediaType (config);
  191790. }
  191791. }
  191792. if (bestIndex >= 0)
  191793. {
  191794. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  191795. hr = streamConfig->SetFormat (config);
  191796. deleteMediaType (config);
  191797. return SUCCEEDED (hr);
  191798. }
  191799. }
  191800. return false;
  191801. }
  191802. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  191803. {
  191804. ComSmartPtr <IEnumPins> enumerator;
  191805. ComSmartPtr <IPin> pin;
  191806. filter->EnumPins (&enumerator);
  191807. while (enumerator->Next (1, &pin, 0) == S_OK)
  191808. {
  191809. PIN_DIRECTION dir;
  191810. pin->QueryDirection (&dir);
  191811. if (wantedDirection == dir)
  191812. {
  191813. PIN_INFO info;
  191814. zerostruct (info);
  191815. pin->QueryPinInfo (&info);
  191816. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  191817. {
  191818. pin.p->AddRef();
  191819. *result = pin;
  191820. return true;
  191821. }
  191822. }
  191823. }
  191824. return false;
  191825. }
  191826. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  191827. {
  191828. ComSmartPtr <IPin> in, out;
  191829. return getPin (first, PINDIR_OUTPUT, &out)
  191830. && getPin (second, PINDIR_INPUT, &in)
  191831. && SUCCEEDED (graphBuilder->Connect (out, in));
  191832. }
  191833. bool addGraphToRot()
  191834. {
  191835. ComSmartPtr <IRunningObjectTable> rot;
  191836. if (FAILED (GetRunningObjectTable (0, &rot)))
  191837. return false;
  191838. ComSmartPtr <IMoniker> moniker;
  191839. WCHAR buffer[128];
  191840. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  191841. if (FAILED (hr))
  191842. return false;
  191843. graphRegistrationID = 0;
  191844. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  191845. }
  191846. void removeGraphFromRot()
  191847. {
  191848. ComSmartPtr <IRunningObjectTable> rot;
  191849. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  191850. rot->Revoke (graphRegistrationID);
  191851. }
  191852. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  191853. {
  191854. if (pmt->cbFormat != 0)
  191855. CoTaskMemFree ((PVOID) pmt->pbFormat);
  191856. if (pmt->pUnk != 0)
  191857. pmt->pUnk->Release();
  191858. CoTaskMemFree (pmt);
  191859. }
  191860. class GrabberCallback : public ComBaseClassHelper <ISampleGrabberCB>
  191861. {
  191862. public:
  191863. GrabberCallback (DShowCameraDeviceInteral& owner_)
  191864. : owner (owner_)
  191865. {
  191866. }
  191867. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  191868. {
  191869. return E_FAIL;
  191870. }
  191871. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  191872. {
  191873. owner.handleFrame (time, buffer, bufferSize);
  191874. return S_OK;
  191875. }
  191876. private:
  191877. DShowCameraDeviceInteral& owner;
  191878. GrabberCallback (const GrabberCallback&);
  191879. GrabberCallback& operator= (const GrabberCallback&);
  191880. };
  191881. ComSmartPtr <GrabberCallback> callback;
  191882. VoidArray listeners;
  191883. CriticalSection listenerLock;
  191884. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  191885. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  191886. };
  191887. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  191888. : name (name_)
  191889. {
  191890. isRecording = false;
  191891. }
  191892. CameraDevice::~CameraDevice()
  191893. {
  191894. stopRecording();
  191895. delete static_cast <DShowCameraDeviceInteral*> (internal);
  191896. internal = 0;
  191897. }
  191898. Component* CameraDevice::createViewerComponent()
  191899. {
  191900. return new DShowCameraDeviceInteral::DShowCaptureViewerComp (static_cast <DShowCameraDeviceInteral*> (internal));
  191901. }
  191902. const String CameraDevice::getFileExtension()
  191903. {
  191904. return ".wmv";
  191905. }
  191906. void CameraDevice::startRecordingToFile (const File& file, int quality)
  191907. {
  191908. stopRecording();
  191909. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  191910. d->addUser();
  191911. isRecording = d->createFileCaptureFilter (file);
  191912. }
  191913. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  191914. {
  191915. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  191916. return d->firstRecordedTime;
  191917. }
  191918. void CameraDevice::stopRecording()
  191919. {
  191920. if (isRecording)
  191921. {
  191922. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  191923. d->removeFileCaptureFilter();
  191924. d->removeUser();
  191925. isRecording = false;
  191926. }
  191927. }
  191928. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  191929. {
  191930. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  191931. if (listenerToAdd != 0)
  191932. d->addListener (listenerToAdd);
  191933. }
  191934. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  191935. {
  191936. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  191937. if (listenerToRemove != 0)
  191938. d->removeListener (listenerToRemove);
  191939. }
  191940. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  191941. const int deviceIndexToOpen,
  191942. String& name)
  191943. {
  191944. int index = 0;
  191945. ComSmartPtr <IBaseFilter> result;
  191946. ComSmartPtr <ICreateDevEnum> pDevEnum;
  191947. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum);
  191948. if (SUCCEEDED (hr))
  191949. {
  191950. ComSmartPtr <IEnumMoniker> enumerator;
  191951. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  191952. if (SUCCEEDED (hr) && enumerator != 0)
  191953. {
  191954. ComSmartPtr <IBaseFilter> captureFilter;
  191955. ComSmartPtr <IMoniker> moniker;
  191956. ULONG fetched;
  191957. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  191958. {
  191959. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  191960. if (SUCCEEDED (hr))
  191961. {
  191962. ComSmartPtr <IPropertyBag> propertyBag;
  191963. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  191964. if (SUCCEEDED (hr))
  191965. {
  191966. VARIANT var;
  191967. var.vt = VT_BSTR;
  191968. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  191969. propertyBag = 0;
  191970. if (SUCCEEDED (hr))
  191971. {
  191972. if (names != 0)
  191973. names->add (var.bstrVal);
  191974. if (index == deviceIndexToOpen)
  191975. {
  191976. name = var.bstrVal;
  191977. result = captureFilter;
  191978. captureFilter = 0;
  191979. break;
  191980. }
  191981. ++index;
  191982. }
  191983. moniker = 0;
  191984. }
  191985. captureFilter = 0;
  191986. }
  191987. }
  191988. }
  191989. }
  191990. return result;
  191991. }
  191992. const StringArray CameraDevice::getAvailableDevices()
  191993. {
  191994. StringArray devs;
  191995. String dummy;
  191996. enumerateCameras (&devs, -1, dummy);
  191997. return devs;
  191998. }
  191999. CameraDevice* CameraDevice::openDevice (int index,
  192000. int minWidth, int minHeight,
  192001. int maxWidth, int maxHeight)
  192002. {
  192003. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192004. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2);
  192005. if (SUCCEEDED (hr))
  192006. {
  192007. String name;
  192008. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192009. if (filter != 0)
  192010. {
  192011. ScopedPointer <CameraDevice> cam (new CameraDevice (name, index));
  192012. DShowCameraDeviceInteral* const intern
  192013. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192014. minWidth, minHeight, maxWidth, maxHeight);
  192015. cam->internal = intern;
  192016. if (intern->ok)
  192017. return cam.release();
  192018. }
  192019. }
  192020. return 0;
  192021. }
  192022. #endif
  192023. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192024. #endif
  192025. // Auto-link the other win32 libs that are needed by library calls..
  192026. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192027. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192028. // Auto-links to various win32 libs that are needed by library calls..
  192029. #pragma comment(lib, "kernel32.lib")
  192030. #pragma comment(lib, "user32.lib")
  192031. #pragma comment(lib, "shell32.lib")
  192032. #pragma comment(lib, "gdi32.lib")
  192033. #pragma comment(lib, "vfw32.lib")
  192034. #pragma comment(lib, "comdlg32.lib")
  192035. #pragma comment(lib, "winmm.lib")
  192036. #pragma comment(lib, "wininet.lib")
  192037. #pragma comment(lib, "ole32.lib")
  192038. #pragma comment(lib, "oleaut32.lib")
  192039. #pragma comment(lib, "advapi32.lib")
  192040. #pragma comment(lib, "ws2_32.lib")
  192041. #pragma comment(lib, "comsupp.lib")
  192042. #pragma comment(lib, "version.lib")
  192043. #if JUCE_OPENGL
  192044. #pragma comment(lib, "OpenGL32.Lib")
  192045. #pragma comment(lib, "GlU32.Lib")
  192046. #endif
  192047. #if JUCE_QUICKTIME
  192048. #pragma comment (lib, "QTMLClient.lib")
  192049. #endif
  192050. #if JUCE_USE_CAMERA
  192051. #pragma comment (lib, "Strmiids.lib")
  192052. #pragma comment (lib, "wmvcore.lib")
  192053. #endif
  192054. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192055. #endif
  192056. END_JUCE_NAMESPACE
  192057. #endif
  192058. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192059. #endif
  192060. #if JUCE_LINUX
  192061. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192062. #if JUCE_LINUX
  192063. BEGIN_JUCE_NAMESPACE
  192064. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192065. #define SUPPORT_AFFINITIES 1
  192066. #endif
  192067. #define JUCE_INCLUDED_FILE 1
  192068. // Now include the actual code files..
  192069. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192070. CriticalSection::CriticalSection() throw()
  192071. {
  192072. pthread_mutexattr_t atts;
  192073. pthread_mutexattr_init (&atts);
  192074. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192075. pthread_mutex_init (&internal, &atts);
  192076. }
  192077. CriticalSection::~CriticalSection() throw()
  192078. {
  192079. pthread_mutex_destroy (&internal);
  192080. }
  192081. void CriticalSection::enter() const throw()
  192082. {
  192083. pthread_mutex_lock (&internal);
  192084. }
  192085. bool CriticalSection::tryEnter() const throw()
  192086. {
  192087. return pthread_mutex_trylock (&internal) == 0;
  192088. }
  192089. void CriticalSection::exit() const throw()
  192090. {
  192091. pthread_mutex_unlock (&internal);
  192092. }
  192093. class WaitableEventImpl
  192094. {
  192095. public:
  192096. WaitableEventImpl (const bool manualReset_)
  192097. : triggered (false),
  192098. manualReset (manualReset_)
  192099. {
  192100. pthread_cond_init (&condition, 0);
  192101. pthread_mutex_init (&mutex, 0);
  192102. }
  192103. ~WaitableEventImpl()
  192104. {
  192105. pthread_cond_destroy (&condition);
  192106. pthread_mutex_destroy (&mutex);
  192107. }
  192108. bool wait (const int timeOutMillisecs) throw()
  192109. {
  192110. pthread_mutex_lock (&mutex);
  192111. if (! triggered)
  192112. {
  192113. if (timeOutMillisecs < 0)
  192114. {
  192115. do
  192116. {
  192117. pthread_cond_wait (&condition, &mutex);
  192118. }
  192119. while (! triggered);
  192120. }
  192121. else
  192122. {
  192123. struct timeval now;
  192124. gettimeofday (&now, 0);
  192125. struct timespec time;
  192126. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  192127. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192128. if (time.tv_nsec >= 1000000000)
  192129. {
  192130. time.tv_nsec -= 1000000000;
  192131. time.tv_sec++;
  192132. }
  192133. do
  192134. {
  192135. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  192136. {
  192137. pthread_mutex_unlock (&mutex);
  192138. return false;
  192139. }
  192140. }
  192141. while (! triggered);
  192142. }
  192143. }
  192144. if (! manualReset)
  192145. triggered = false;
  192146. pthread_mutex_unlock (&mutex);
  192147. return true;
  192148. }
  192149. void signal() throw()
  192150. {
  192151. pthread_mutex_lock (&mutex);
  192152. triggered = true;
  192153. pthread_cond_broadcast (&condition);
  192154. pthread_mutex_unlock (&mutex);
  192155. }
  192156. void reset() throw()
  192157. {
  192158. pthread_mutex_lock (&mutex);
  192159. triggered = false;
  192160. pthread_mutex_unlock (&mutex);
  192161. }
  192162. private:
  192163. pthread_cond_t condition;
  192164. pthread_mutex_t mutex;
  192165. bool triggered;
  192166. const bool manualReset;
  192167. WaitableEventImpl (const WaitableEventImpl&);
  192168. WaitableEventImpl& operator= (const WaitableEventImpl&);
  192169. };
  192170. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  192171. : internal (new WaitableEventImpl (manualReset))
  192172. {
  192173. }
  192174. WaitableEvent::~WaitableEvent() throw()
  192175. {
  192176. delete static_cast <WaitableEventImpl*> (internal);
  192177. }
  192178. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192179. {
  192180. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  192181. }
  192182. void WaitableEvent::signal() const throw()
  192183. {
  192184. static_cast <WaitableEventImpl*> (internal)->signal();
  192185. }
  192186. void WaitableEvent::reset() const throw()
  192187. {
  192188. static_cast <WaitableEventImpl*> (internal)->reset();
  192189. }
  192190. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192191. {
  192192. struct timespec time;
  192193. time.tv_sec = millisecs / 1000;
  192194. time.tv_nsec = (millisecs % 1000) * 1000000;
  192195. nanosleep (&time, 0);
  192196. }
  192197. const juce_wchar File::separator = '/';
  192198. const String File::separatorString ("/");
  192199. const File File::getCurrentWorkingDirectory()
  192200. {
  192201. HeapBlock<char> heapBuffer;
  192202. char localBuffer [1024];
  192203. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192204. int bufferSize = 4096;
  192205. while (cwd == 0 && errno == ERANGE)
  192206. {
  192207. heapBuffer.malloc (bufferSize);
  192208. cwd = getcwd (heapBuffer, bufferSize - 1);
  192209. bufferSize += 1024;
  192210. }
  192211. return File (String::fromUTF8 (cwd));
  192212. }
  192213. bool File::setAsCurrentWorkingDirectory() const
  192214. {
  192215. return chdir (getFullPathName().toUTF8()) == 0;
  192216. }
  192217. static bool juce_stat (const String& fileName, struct stat& info)
  192218. {
  192219. return fileName.isNotEmpty()
  192220. && (stat (fileName.toUTF8(), &info) == 0);
  192221. }
  192222. bool File::isDirectory() const
  192223. {
  192224. struct stat info;
  192225. return fullPath.isEmpty()
  192226. || (juce_stat (fullPath, info) && ((info.st_mode & S_IFDIR) != 0));
  192227. }
  192228. bool File::exists() const
  192229. {
  192230. return fullPath.isNotEmpty()
  192231. && access (fullPath.toUTF8(), F_OK) == 0;
  192232. }
  192233. bool File::existsAsFile() const
  192234. {
  192235. return exists() && ! isDirectory();
  192236. }
  192237. int64 File::getSize() const
  192238. {
  192239. struct stat info;
  192240. return juce_stat (fullPath, info) ? info.st_size : 0;
  192241. }
  192242. bool File::hasWriteAccess() const
  192243. {
  192244. if (exists())
  192245. return access (fullPath.toUTF8(), W_OK) == 0;
  192246. if ((! isDirectory()) && fullPath.containsChar (separator))
  192247. return getParentDirectory().hasWriteAccess();
  192248. return false;
  192249. }
  192250. bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const
  192251. {
  192252. struct stat info;
  192253. const int res = stat (fullPath.toUTF8(), &info);
  192254. if (res != 0)
  192255. return false;
  192256. info.st_mode &= 0777; // Just permissions
  192257. if (shouldBeReadOnly)
  192258. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  192259. else
  192260. // Give everybody write permission?
  192261. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  192262. return chmod (fullPath.toUTF8(), info.st_mode) == 0;
  192263. }
  192264. void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const
  192265. {
  192266. modificationTime = 0;
  192267. accessTime = 0;
  192268. creationTime = 0;
  192269. struct stat info;
  192270. const int res = stat (fullPath.toUTF8(), &info);
  192271. if (res == 0)
  192272. {
  192273. modificationTime = (int64) info.st_mtime * 1000;
  192274. accessTime = (int64) info.st_atime * 1000;
  192275. creationTime = (int64) info.st_ctime * 1000;
  192276. }
  192277. }
  192278. bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const
  192279. {
  192280. struct utimbuf times;
  192281. times.actime = (time_t) (accessTime / 1000);
  192282. times.modtime = (time_t) (modificationTime / 1000);
  192283. return utime (fullPath.toUTF8(), &times) == 0;
  192284. }
  192285. bool File::deleteFile() const
  192286. {
  192287. if (! exists())
  192288. return true;
  192289. else if (isDirectory())
  192290. return rmdir (fullPath.toUTF8()) == 0;
  192291. else
  192292. return remove (fullPath.toUTF8()) == 0;
  192293. }
  192294. bool File::moveInternal (const File& dest) const
  192295. {
  192296. if (rename (fullPath.toUTF8(), dest.getFullPathName().toUTF8()) == 0)
  192297. return true;
  192298. if (hasWriteAccess() && copyInternal (dest))
  192299. {
  192300. if (deleteFile())
  192301. return true;
  192302. dest.deleteFile();
  192303. }
  192304. return false;
  192305. }
  192306. void File::createDirectoryInternal (const String& fileName) const
  192307. {
  192308. mkdir (fileName.toUTF8(), 0777);
  192309. }
  192310. void* juce_fileOpen (const File& file, bool forWriting)
  192311. {
  192312. int flags = O_RDONLY;
  192313. if (forWriting)
  192314. {
  192315. if (file.exists())
  192316. {
  192317. const int f = open (file.getFullPathName().toUTF8(), O_RDWR, 00644);
  192318. if (f != -1)
  192319. lseek (f, 0, SEEK_END);
  192320. return (void*) f;
  192321. }
  192322. else
  192323. {
  192324. flags = O_RDWR + O_CREAT;
  192325. }
  192326. }
  192327. return (void*) open (file.getFullPathName().toUTF8(), flags, 00644);
  192328. }
  192329. void juce_fileClose (void* handle)
  192330. {
  192331. if (handle != 0)
  192332. close ((int) (pointer_sized_int) handle);
  192333. }
  192334. int juce_fileRead (void* handle, void* buffer, int size)
  192335. {
  192336. if (handle != 0)
  192337. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  192338. return 0;
  192339. }
  192340. int juce_fileWrite (void* handle, const void* buffer, int size)
  192341. {
  192342. if (handle != 0)
  192343. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192344. return 0;
  192345. }
  192346. int64 juce_fileSetPosition (void* handle, int64 pos)
  192347. {
  192348. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192349. return pos;
  192350. return -1;
  192351. }
  192352. int64 FileOutputStream::getPositionInternal() const
  192353. {
  192354. if (fileHandle != 0)
  192355. return lseek ((int) (pointer_sized_int) fileHandle, 0, SEEK_CUR);
  192356. return -1;
  192357. }
  192358. void FileOutputStream::flushInternal()
  192359. {
  192360. if (fileHandle != 0)
  192361. fsync ((int) (pointer_sized_int) fileHandle);
  192362. }
  192363. const File juce_getExecutableFile()
  192364. {
  192365. Dl_info exeInfo;
  192366. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192367. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  192368. }
  192369. // if this file doesn't exist, find a parent of it that does..
  192370. static bool juce_doStatFS (File f, struct statfs& result)
  192371. {
  192372. for (int i = 5; --i >= 0;)
  192373. {
  192374. if (f.exists())
  192375. break;
  192376. f = f.getParentDirectory();
  192377. }
  192378. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192379. }
  192380. int64 File::getBytesFreeOnVolume() const
  192381. {
  192382. struct statfs buf;
  192383. if (juce_doStatFS (*this, buf))
  192384. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192385. return 0;
  192386. }
  192387. int64 File::getVolumeTotalSize() const
  192388. {
  192389. struct statfs buf;
  192390. if (juce_doStatFS (*this, buf))
  192391. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192392. return 0;
  192393. }
  192394. const String File::getVolumeLabel() const
  192395. {
  192396. #if JUCE_MAC
  192397. struct VolAttrBuf
  192398. {
  192399. u_int32_t length;
  192400. attrreference_t mountPointRef;
  192401. char mountPointSpace [MAXPATHLEN];
  192402. } attrBuf;
  192403. struct attrlist attrList;
  192404. zerostruct (attrList);
  192405. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192406. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192407. File f (*this);
  192408. for (;;)
  192409. {
  192410. if (getattrlist (f.getFullPathName().toUTF8(), &attrList, &attrBuf, sizeof (attrBuf), 0) == 0)
  192411. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192412. (int) attrBuf.mountPointRef.attr_length);
  192413. const File parent (f.getParentDirectory());
  192414. if (f == parent)
  192415. break;
  192416. f = parent;
  192417. }
  192418. #endif
  192419. return String::empty;
  192420. }
  192421. int File::getVolumeSerialNumber() const
  192422. {
  192423. return 0; // xxx
  192424. }
  192425. void juce_runSystemCommand (const String& command)
  192426. {
  192427. int result = system (command.toUTF8());
  192428. (void) result;
  192429. }
  192430. const String juce_getOutputFromCommand (const String& command)
  192431. {
  192432. // slight bodge here, as we just pipe the output into a temp file and read it...
  192433. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192434. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192435. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192436. String result (tempFile.loadFileAsString());
  192437. tempFile.deleteFile();
  192438. return result;
  192439. }
  192440. class InterProcessLock::Pimpl
  192441. {
  192442. public:
  192443. Pimpl (const String& name, const int timeOutMillisecs)
  192444. : handle (0), refCount (1)
  192445. {
  192446. #if JUCE_MAC
  192447. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192448. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  192449. #else
  192450. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192451. #endif
  192452. temp.create();
  192453. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192454. if (handle != 0)
  192455. {
  192456. struct flock fl;
  192457. zerostruct (fl);
  192458. fl.l_whence = SEEK_SET;
  192459. fl.l_type = F_WRLCK;
  192460. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192461. for (;;)
  192462. {
  192463. const int result = fcntl (handle, F_SETLK, &fl);
  192464. if (result >= 0)
  192465. return;
  192466. if (errno != EINTR)
  192467. {
  192468. if (timeOutMillisecs == 0
  192469. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192470. break;
  192471. Thread::sleep (10);
  192472. }
  192473. }
  192474. }
  192475. closeFile();
  192476. }
  192477. ~Pimpl()
  192478. {
  192479. closeFile();
  192480. }
  192481. void closeFile()
  192482. {
  192483. if (handle != 0)
  192484. {
  192485. struct flock fl;
  192486. zerostruct (fl);
  192487. fl.l_whence = SEEK_SET;
  192488. fl.l_type = F_UNLCK;
  192489. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  192490. {}
  192491. close (handle);
  192492. handle = 0;
  192493. }
  192494. }
  192495. int handle, refCount;
  192496. };
  192497. InterProcessLock::InterProcessLock (const String& name_)
  192498. : name (name_)
  192499. {
  192500. }
  192501. InterProcessLock::~InterProcessLock()
  192502. {
  192503. }
  192504. bool InterProcessLock::enter (const int timeOutMillisecs)
  192505. {
  192506. const ScopedLock sl (lock);
  192507. if (pimpl == 0)
  192508. {
  192509. pimpl = new Pimpl (name, timeOutMillisecs);
  192510. if (pimpl->handle == 0)
  192511. pimpl = 0;
  192512. }
  192513. else
  192514. {
  192515. pimpl->refCount++;
  192516. }
  192517. return pimpl != 0;
  192518. }
  192519. void InterProcessLock::exit()
  192520. {
  192521. const ScopedLock sl (lock);
  192522. // Trying to release the lock too many times!
  192523. jassert (pimpl != 0);
  192524. if (pimpl != 0 && --(pimpl->refCount) == 0)
  192525. pimpl = 0;
  192526. }
  192527. /*** End of inlined file: juce_posix_SharedCode.h ***/
  192528. /*** Start of inlined file: juce_linux_Files.cpp ***/
  192529. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  192530. // compiled on its own).
  192531. #if JUCE_INCLUDED_FILE
  192532. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  192533. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  192534. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  192535. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  192536. bool File::copyInternal (const File& dest) const
  192537. {
  192538. FileInputStream in (*this);
  192539. if (dest.deleteFile())
  192540. {
  192541. {
  192542. FileOutputStream out (dest);
  192543. if (out.failedToOpen())
  192544. return false;
  192545. if (out.writeFromInputStream (in, -1) == getSize())
  192546. return true;
  192547. }
  192548. dest.deleteFile();
  192549. }
  192550. return false;
  192551. }
  192552. void File::findFileSystemRoots (Array<File>& destArray)
  192553. {
  192554. destArray.add (File ("/"));
  192555. }
  192556. bool File::isOnCDRomDrive() const
  192557. {
  192558. struct statfs buf;
  192559. return statfs (getFullPathName().toUTF8(), &buf) == 0
  192560. && buf.f_type == U_ISOFS_SUPER_MAGIC;
  192561. }
  192562. bool File::isOnHardDisk() const
  192563. {
  192564. struct statfs buf;
  192565. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192566. {
  192567. switch (buf.f_type)
  192568. {
  192569. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  192570. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  192571. case U_NFS_SUPER_MAGIC: // Network NFS
  192572. case U_SMB_SUPER_MAGIC: // Network Samba
  192573. return false;
  192574. default:
  192575. // Assume anything else is a hard-disk (but note it could
  192576. // be a RAM disk. There isn't a good way of determining
  192577. // this for sure)
  192578. return true;
  192579. }
  192580. }
  192581. // Assume so if this fails for some reason
  192582. return true;
  192583. }
  192584. bool File::isOnRemovableDrive() const
  192585. {
  192586. jassertfalse // xxx not implemented for linux!
  192587. return false;
  192588. }
  192589. bool File::isHidden() const
  192590. {
  192591. return getFileName().startsWithChar ('.');
  192592. }
  192593. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  192594. const File File::getSpecialLocation (const SpecialLocationType type)
  192595. {
  192596. switch (type)
  192597. {
  192598. case userHomeDirectory:
  192599. {
  192600. const char* homeDir = getenv ("HOME");
  192601. if (homeDir == 0)
  192602. {
  192603. struct passwd* const pw = getpwuid (getuid());
  192604. if (pw != 0)
  192605. homeDir = pw->pw_dir;
  192606. }
  192607. return File (String::fromUTF8 (homeDir));
  192608. }
  192609. case userDocumentsDirectory:
  192610. case userMusicDirectory:
  192611. case userMoviesDirectory:
  192612. case userApplicationDataDirectory:
  192613. return File ("~");
  192614. case userDesktopDirectory:
  192615. return File ("~/Desktop");
  192616. case commonApplicationDataDirectory:
  192617. return File ("/var");
  192618. case globalApplicationsDirectory:
  192619. return File ("/usr");
  192620. case tempDirectory:
  192621. {
  192622. File tmp ("/var/tmp");
  192623. if (! tmp.isDirectory())
  192624. {
  192625. tmp = "/tmp";
  192626. if (! tmp.isDirectory())
  192627. tmp = File::getCurrentWorkingDirectory();
  192628. }
  192629. return tmp;
  192630. }
  192631. case invokedExecutableFile:
  192632. if (juce_Argv0 != 0)
  192633. return File (String::fromUTF8 (juce_Argv0));
  192634. // deliberate fall-through...
  192635. case currentExecutableFile:
  192636. case currentApplicationFile:
  192637. return juce_getExecutableFile();
  192638. default:
  192639. jassertfalse // unknown type?
  192640. break;
  192641. }
  192642. return File::nonexistent;
  192643. }
  192644. const String File::getVersion() const
  192645. {
  192646. return String::empty; // xxx not yet implemented
  192647. }
  192648. const File File::getLinkedTarget() const
  192649. {
  192650. char buffer [4096];
  192651. size_t numChars = readlink (getFullPathName().toUTF8(),
  192652. buffer, sizeof (buffer));
  192653. if (numChars > 0 && numChars <= sizeof (buffer))
  192654. return File (String::fromUTF8 (buffer, (int) numChars));
  192655. return *this;
  192656. }
  192657. bool File::moveToTrash() const
  192658. {
  192659. if (! exists())
  192660. return true;
  192661. File trashCan ("~/.Trash");
  192662. if (! trashCan.isDirectory())
  192663. trashCan = "~/.local/share/Trash/files";
  192664. if (! trashCan.isDirectory())
  192665. return false;
  192666. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  192667. getFileExtension()));
  192668. }
  192669. class DirectoryIterator::NativeIterator::Pimpl
  192670. {
  192671. public:
  192672. Pimpl (const File& directory, const String& wildCard_)
  192673. : parentDir (File::addTrailingSeparator (directory.getFullPathName())),
  192674. wildCard (wildCard_),
  192675. dir (opendir (directory.getFullPathName().toUTF8()))
  192676. {
  192677. if (wildCard == "*.*")
  192678. wildCard = "*";
  192679. wildcardUTF8 = wildCard.toUTF8();
  192680. }
  192681. ~Pimpl()
  192682. {
  192683. if (dir != 0)
  192684. closedir (dir);
  192685. }
  192686. bool next (String& filenameFound,
  192687. bool* const isDir, bool* const isHidden, int64* const fileSize,
  192688. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  192689. {
  192690. if (dir == 0)
  192691. return false;
  192692. for (;;)
  192693. {
  192694. struct dirent* const de = readdir (dir);
  192695. if (de == 0)
  192696. return false;
  192697. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  192698. {
  192699. filenameFound = String::fromUTF8 (de->d_name);
  192700. const String path (parentDir + filenameFound);
  192701. if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0)
  192702. {
  192703. struct stat info;
  192704. const bool statOk = juce_stat (path, info);
  192705. if (isDir != 0) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  192706. if (fileSize != 0) *fileSize = statOk ? info.st_size : 0;
  192707. if (modTime != 0) *modTime = statOk ? (int64) info.st_mtime * 1000 : 0;
  192708. if (creationTime != 0) *creationTime = statOk ? (int64) info.st_ctime * 1000 : 0;
  192709. }
  192710. if (isHidden != 0)
  192711. *isHidden = filenameFound.startsWithChar ('.');
  192712. if (isReadOnly != 0)
  192713. *isReadOnly = access (path.toUTF8(), W_OK) != 0;
  192714. return true;
  192715. }
  192716. }
  192717. }
  192718. private:
  192719. String parentDir, wildCard;
  192720. const char* wildcardUTF8;
  192721. DIR* dir;
  192722. Pimpl (const Pimpl&);
  192723. Pimpl& operator= (const Pimpl&);
  192724. };
  192725. DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard)
  192726. : pimpl (new DirectoryIterator::NativeIterator::Pimpl (directory, wildCard))
  192727. {
  192728. }
  192729. DirectoryIterator::NativeIterator::~NativeIterator()
  192730. {
  192731. }
  192732. bool DirectoryIterator::NativeIterator::next (String& filenameFound,
  192733. bool* const isDir, bool* const isHidden, int64* const fileSize,
  192734. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  192735. {
  192736. return pimpl->next (filenameFound, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  192737. }
  192738. bool PlatformUtilities::openDocument (const String& fileName, const String& parameters)
  192739. {
  192740. String cmdString (fileName.replace (" ", "\\ ",false));
  192741. cmdString << " " << parameters;
  192742. if (URL::isProbablyAWebsiteURL (fileName)
  192743. || cmdString.startsWithIgnoreCase ("file:")
  192744. || URL::isProbablyAnEmailAddress (fileName))
  192745. {
  192746. // create a command that tries to launch a bunch of likely browsers
  192747. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  192748. StringArray cmdLines;
  192749. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  192750. cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());
  192751. cmdString = cmdLines.joinIntoString (" || ");
  192752. }
  192753. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
  192754. const int cpid = fork();
  192755. if (cpid == 0)
  192756. {
  192757. setsid();
  192758. // Child process
  192759. execve (argv[0], (char**) argv, environ);
  192760. exit (0);
  192761. }
  192762. return cpid >= 0;
  192763. }
  192764. void File::revealToUser() const
  192765. {
  192766. if (isDirectory())
  192767. startAsProcess();
  192768. else if (getParentDirectory().exists())
  192769. getParentDirectory().startAsProcess();
  192770. }
  192771. #endif
  192772. /*** End of inlined file: juce_linux_Files.cpp ***/
  192773. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  192774. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  192775. // compiled on its own).
  192776. #if JUCE_INCLUDED_FILE
  192777. struct NamedPipeInternal
  192778. {
  192779. String pipeInName, pipeOutName;
  192780. int pipeIn, pipeOut;
  192781. bool volatile createdPipe, blocked, stopReadOperation;
  192782. static void signalHandler (int) {}
  192783. };
  192784. void NamedPipe::cancelPendingReads()
  192785. {
  192786. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  192787. {
  192788. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  192789. intern->stopReadOperation = true;
  192790. char buffer [1] = { 0 };
  192791. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  192792. (void) bytesWritten;
  192793. int timeout = 2000;
  192794. while (intern->blocked && --timeout >= 0)
  192795. Thread::sleep (2);
  192796. intern->stopReadOperation = false;
  192797. }
  192798. }
  192799. void NamedPipe::close()
  192800. {
  192801. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  192802. if (intern != 0)
  192803. {
  192804. internal = 0;
  192805. if (intern->pipeIn != -1)
  192806. ::close (intern->pipeIn);
  192807. if (intern->pipeOut != -1)
  192808. ::close (intern->pipeOut);
  192809. if (intern->createdPipe)
  192810. {
  192811. unlink (intern->pipeInName.toUTF8());
  192812. unlink (intern->pipeOutName.toUTF8());
  192813. }
  192814. delete intern;
  192815. }
  192816. }
  192817. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  192818. {
  192819. close();
  192820. NamedPipeInternal* const intern = new NamedPipeInternal();
  192821. internal = intern;
  192822. intern->createdPipe = createPipe;
  192823. intern->blocked = false;
  192824. intern->stopReadOperation = false;
  192825. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  192826. siginterrupt (SIGPIPE, 1);
  192827. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  192828. intern->pipeInName = pipePath + "_in";
  192829. intern->pipeOutName = pipePath + "_out";
  192830. intern->pipeIn = -1;
  192831. intern->pipeOut = -1;
  192832. if (createPipe)
  192833. {
  192834. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  192835. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  192836. {
  192837. delete intern;
  192838. internal = 0;
  192839. return false;
  192840. }
  192841. }
  192842. return true;
  192843. }
  192844. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  192845. {
  192846. int bytesRead = -1;
  192847. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  192848. if (intern != 0)
  192849. {
  192850. intern->blocked = true;
  192851. if (intern->pipeIn == -1)
  192852. {
  192853. if (intern->createdPipe)
  192854. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  192855. else
  192856. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  192857. if (intern->pipeIn == -1)
  192858. {
  192859. intern->blocked = false;
  192860. return -1;
  192861. }
  192862. }
  192863. bytesRead = 0;
  192864. char* p = (char*) destBuffer;
  192865. while (bytesRead < maxBytesToRead)
  192866. {
  192867. const int bytesThisTime = maxBytesToRead - bytesRead;
  192868. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  192869. if (numRead <= 0 || intern->stopReadOperation)
  192870. {
  192871. bytesRead = -1;
  192872. break;
  192873. }
  192874. bytesRead += numRead;
  192875. p += bytesRead;
  192876. }
  192877. intern->blocked = false;
  192878. }
  192879. return bytesRead;
  192880. }
  192881. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  192882. {
  192883. int bytesWritten = -1;
  192884. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  192885. if (intern != 0)
  192886. {
  192887. if (intern->pipeOut == -1)
  192888. {
  192889. if (intern->createdPipe)
  192890. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  192891. else
  192892. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  192893. if (intern->pipeOut == -1)
  192894. {
  192895. return -1;
  192896. }
  192897. }
  192898. const char* p = (const char*) sourceBuffer;
  192899. bytesWritten = 0;
  192900. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  192901. while (bytesWritten < numBytesToWrite
  192902. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  192903. {
  192904. const int bytesThisTime = numBytesToWrite - bytesWritten;
  192905. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  192906. if (numWritten <= 0)
  192907. {
  192908. bytesWritten = -1;
  192909. break;
  192910. }
  192911. bytesWritten += numWritten;
  192912. p += bytesWritten;
  192913. }
  192914. }
  192915. return bytesWritten;
  192916. }
  192917. #endif
  192918. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  192919. /*** Start of inlined file: juce_linux_Network.cpp ***/
  192920. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  192921. // compiled on its own).
  192922. #if JUCE_INCLUDED_FILE
  192923. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  192924. {
  192925. int numResults = 0;
  192926. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  192927. if (s != -1)
  192928. {
  192929. char buf [1024];
  192930. struct ifconf ifc;
  192931. ifc.ifc_len = sizeof (buf);
  192932. ifc.ifc_buf = buf;
  192933. ioctl (s, SIOCGIFCONF, &ifc);
  192934. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  192935. {
  192936. struct ifreq ifr;
  192937. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  192938. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  192939. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  192940. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  192941. && numResults < maxNum)
  192942. {
  192943. int64 a = 0;
  192944. for (int j = 6; --j >= 0;)
  192945. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  192946. *addresses++ = a;
  192947. ++numResults;
  192948. }
  192949. }
  192950. close (s);
  192951. }
  192952. return numResults;
  192953. }
  192954. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  192955. const String& emailSubject,
  192956. const String& bodyText,
  192957. const StringArray& filesToAttach)
  192958. {
  192959. jassertfalse // xxx todo
  192960. return false;
  192961. }
  192962. class JUCE_HTTPSocketStream
  192963. {
  192964. public:
  192965. JUCE_HTTPSocketStream()
  192966. : readPosition (0),
  192967. socketHandle (-1),
  192968. levelsOfRedirection (0),
  192969. timeoutSeconds (15)
  192970. {
  192971. }
  192972. ~JUCE_HTTPSocketStream()
  192973. {
  192974. closeSocket();
  192975. }
  192976. bool open (const String& url,
  192977. const String& headers,
  192978. const MemoryBlock& postData,
  192979. const bool isPost,
  192980. URL::OpenStreamProgressCallback* callback,
  192981. void* callbackContext,
  192982. int timeOutMs)
  192983. {
  192984. closeSocket();
  192985. uint32 timeOutTime = Time::getMillisecondCounter();
  192986. if (timeOutMs == 0)
  192987. timeOutTime += 60000;
  192988. else if (timeOutMs < 0)
  192989. timeOutTime = 0xffffffff;
  192990. else
  192991. timeOutTime += timeOutMs;
  192992. String hostName, hostPath;
  192993. int hostPort;
  192994. if (! decomposeURL (url, hostName, hostPath, hostPort))
  192995. return false;
  192996. const struct hostent* host = 0;
  192997. int port = 0;
  192998. String proxyName, proxyPath;
  192999. int proxyPort = 0;
  193000. String proxyURL (getenv ("http_proxy"));
  193001. if (proxyURL.startsWithIgnoreCase ("http://"))
  193002. {
  193003. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193004. return false;
  193005. host = gethostbyname (proxyName.toUTF8());
  193006. port = proxyPort;
  193007. }
  193008. else
  193009. {
  193010. host = gethostbyname (hostName.toUTF8());
  193011. port = hostPort;
  193012. }
  193013. if (host == 0)
  193014. return false;
  193015. struct sockaddr_in address;
  193016. zerostruct (address);
  193017. memcpy (&address.sin_addr, host->h_addr, host->h_length);
  193018. address.sin_family = host->h_addrtype;
  193019. address.sin_port = htons (port);
  193020. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193021. if (socketHandle == -1)
  193022. return false;
  193023. int receiveBufferSize = 16384;
  193024. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193025. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193026. #if JUCE_MAC
  193027. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193028. #endif
  193029. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193030. {
  193031. closeSocket();
  193032. return false;
  193033. }
  193034. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193035. proxyName, proxyPort,
  193036. hostPath, url,
  193037. headers, postData,
  193038. isPost));
  193039. size_t totalHeaderSent = 0;
  193040. while (totalHeaderSent < requestHeader.getSize())
  193041. {
  193042. if (Time::getMillisecondCounter() > timeOutTime)
  193043. {
  193044. closeSocket();
  193045. return false;
  193046. }
  193047. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193048. if (send (socketHandle,
  193049. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193050. numToSend, 0)
  193051. != numToSend)
  193052. {
  193053. closeSocket();
  193054. return false;
  193055. }
  193056. totalHeaderSent += numToSend;
  193057. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193058. {
  193059. closeSocket();
  193060. return false;
  193061. }
  193062. }
  193063. const String responseHeader (readResponse (timeOutTime));
  193064. if (responseHeader.isNotEmpty())
  193065. {
  193066. //DBG (responseHeader);
  193067. StringArray lines;
  193068. lines.addLines (responseHeader);
  193069. const int statusCode = responseHeader.fromFirstOccurrenceOf (" ", false, false)
  193070. .substring (0, 3).getIntValue();
  193071. //int contentLength = findHeaderItem (lines, "Content-Length:").getIntValue();
  193072. //bool isChunked = findHeaderItem (lines, "Transfer-Encoding:").equalsIgnoreCase ("chunked");
  193073. String location (findHeaderItem (lines, "Location:"));
  193074. if (statusCode >= 300 && statusCode < 400
  193075. && location.isNotEmpty())
  193076. {
  193077. if (! location.startsWithIgnoreCase ("http://"))
  193078. location = "http://" + location;
  193079. if (levelsOfRedirection++ < 3)
  193080. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193081. }
  193082. else
  193083. {
  193084. levelsOfRedirection = 0;
  193085. return true;
  193086. }
  193087. }
  193088. closeSocket();
  193089. return false;
  193090. }
  193091. int read (void* buffer, int bytesToRead)
  193092. {
  193093. fd_set readbits;
  193094. FD_ZERO (&readbits);
  193095. FD_SET (socketHandle, &readbits);
  193096. struct timeval tv;
  193097. tv.tv_sec = timeoutSeconds;
  193098. tv.tv_usec = 0;
  193099. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193100. return 0; // (timeout)
  193101. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193102. readPosition += bytesRead;
  193103. return bytesRead;
  193104. }
  193105. int readPosition;
  193106. juce_UseDebuggingNewOperator
  193107. private:
  193108. int socketHandle, levelsOfRedirection;
  193109. const int timeoutSeconds;
  193110. void closeSocket()
  193111. {
  193112. if (socketHandle >= 0)
  193113. close (socketHandle);
  193114. socketHandle = -1;
  193115. }
  193116. const MemoryBlock createRequestHeader (const String& hostName,
  193117. const int hostPort,
  193118. const String& proxyName,
  193119. const int proxyPort,
  193120. const String& hostPath,
  193121. const String& originalURL,
  193122. const String& headers,
  193123. const MemoryBlock& postData,
  193124. const bool isPost)
  193125. {
  193126. String header (isPost ? "POST " : "GET ");
  193127. if (proxyName.isEmpty())
  193128. {
  193129. header << hostPath << " HTTP/1.0\r\nHost: "
  193130. << hostName << ':' << hostPort;
  193131. }
  193132. else
  193133. {
  193134. header << originalURL << " HTTP/1.0\r\nHost: "
  193135. << proxyName << ':' << proxyPort;
  193136. }
  193137. header << "\r\nUser-Agent: JUCE/"
  193138. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193139. << "\r\nConnection: Close\r\nContent-Length: "
  193140. << postData.getSize() << "\r\n"
  193141. << headers << "\r\n";
  193142. MemoryBlock mb;
  193143. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193144. mb.append (postData.getData(), postData.getSize());
  193145. return mb;
  193146. }
  193147. const String readResponse (const uint32 timeOutTime)
  193148. {
  193149. int bytesRead = 0, numConsecutiveLFs = 0;
  193150. MemoryBlock buffer (1024, true);
  193151. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193152. && Time::getMillisecondCounter() <= timeOutTime)
  193153. {
  193154. fd_set readbits;
  193155. FD_ZERO (&readbits);
  193156. FD_SET (socketHandle, &readbits);
  193157. struct timeval tv;
  193158. tv.tv_sec = timeoutSeconds;
  193159. tv.tv_usec = 0;
  193160. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193161. return String::empty; // (timeout)
  193162. buffer.ensureSize (bytesRead + 8, true);
  193163. char* const dest = (char*) buffer.getData() + bytesRead;
  193164. if (recv (socketHandle, dest, 1, 0) == -1)
  193165. return String::empty;
  193166. const char lastByte = *dest;
  193167. ++bytesRead;
  193168. if (lastByte == '\n')
  193169. ++numConsecutiveLFs;
  193170. else if (lastByte != '\r')
  193171. numConsecutiveLFs = 0;
  193172. }
  193173. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193174. if (header.startsWithIgnoreCase ("HTTP/"))
  193175. return header.trimEnd();
  193176. return String::empty;
  193177. }
  193178. static bool decomposeURL (const String& url,
  193179. String& host, String& path, int& port)
  193180. {
  193181. if (! url.startsWithIgnoreCase ("http://"))
  193182. return false;
  193183. const int nextSlash = url.indexOfChar (7, '/');
  193184. int nextColon = url.indexOfChar (7, ':');
  193185. if (nextColon > nextSlash && nextSlash > 0)
  193186. nextColon = -1;
  193187. if (nextColon >= 0)
  193188. {
  193189. host = url.substring (7, nextColon);
  193190. if (nextSlash >= 0)
  193191. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193192. else
  193193. port = url.substring (nextColon + 1).getIntValue();
  193194. }
  193195. else
  193196. {
  193197. port = 80;
  193198. if (nextSlash >= 0)
  193199. host = url.substring (7, nextSlash);
  193200. else
  193201. host = url.substring (7);
  193202. }
  193203. if (nextSlash >= 0)
  193204. path = url.substring (nextSlash);
  193205. else
  193206. path = "/";
  193207. return true;
  193208. }
  193209. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193210. {
  193211. for (int i = 0; i < lines.size(); ++i)
  193212. if (lines[i].startsWithIgnoreCase (itemName))
  193213. return lines[i].substring (itemName.length()).trim();
  193214. return String::empty;
  193215. }
  193216. };
  193217. void* juce_openInternetFile (const String& url,
  193218. const String& headers,
  193219. const MemoryBlock& postData,
  193220. const bool isPost,
  193221. URL::OpenStreamProgressCallback* callback,
  193222. void* callbackContext,
  193223. int timeOutMs)
  193224. {
  193225. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193226. if (s->open (url, headers, postData, isPost,
  193227. callback, callbackContext, timeOutMs))
  193228. return s;
  193229. delete s;
  193230. return 0;
  193231. }
  193232. void juce_closeInternetFile (void* handle)
  193233. {
  193234. delete static_cast <JUCE_HTTPSocketStream*> (handle);
  193235. }
  193236. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193237. {
  193238. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193239. if (s != 0)
  193240. return s->read (buffer, bytesToRead);
  193241. return 0;
  193242. }
  193243. int64 juce_getInternetFileContentLength (void* handle)
  193244. {
  193245. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193246. if (s != 0)
  193247. {
  193248. //xxx todo
  193249. jassertfalse
  193250. }
  193251. return -1;
  193252. }
  193253. int juce_seekInInternetFile (void* handle, int newPosition)
  193254. {
  193255. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193256. if (s != 0)
  193257. return s->readPosition;
  193258. return 0;
  193259. }
  193260. #endif
  193261. /*** End of inlined file: juce_linux_Network.cpp ***/
  193262. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193263. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193264. // compiled on its own).
  193265. #if JUCE_INCLUDED_FILE
  193266. void Logger::outputDebugString (const String& text) throw()
  193267. {
  193268. std::cerr << text << std::endl;
  193269. }
  193270. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193271. {
  193272. return Linux;
  193273. }
  193274. const String SystemStats::getOperatingSystemName() throw()
  193275. {
  193276. return "Linux";
  193277. }
  193278. bool SystemStats::isOperatingSystem64Bit() throw()
  193279. {
  193280. #if JUCE_64BIT
  193281. return true;
  193282. #else
  193283. //xxx not sure how to find this out?..
  193284. return false;
  193285. #endif
  193286. }
  193287. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193288. {
  193289. String info;
  193290. char buf [256];
  193291. FILE* f = fopen ("/proc/cpuinfo", "r");
  193292. while (f != 0 && fgets (buf, sizeof(buf), f))
  193293. {
  193294. if (strncmp (buf, key, strlen (key)) == 0)
  193295. {
  193296. char* p = buf;
  193297. while (*p && *p != '\n')
  193298. ++p;
  193299. if (*p != 0)
  193300. *p = 0;
  193301. p = buf;
  193302. while (*p != 0 && *p != ':')
  193303. ++p;
  193304. if (*p != 0 && *(p + 1) != 0)
  193305. info = p + 2;
  193306. if (! lastOne)
  193307. break;
  193308. }
  193309. }
  193310. fclose (f);
  193311. return info;
  193312. }
  193313. bool SystemStats::hasMMX() throw()
  193314. {
  193315. return getCpuInfo ("flags").contains ("mmx");
  193316. }
  193317. bool SystemStats::hasSSE() throw()
  193318. {
  193319. return getCpuInfo ("flags").contains ("sse");
  193320. }
  193321. bool SystemStats::hasSSE2() throw()
  193322. {
  193323. return getCpuInfo ("flags").contains ("sse2");
  193324. }
  193325. bool SystemStats::has3DNow() throw()
  193326. {
  193327. return getCpuInfo ("flags").contains ("3dnow");
  193328. }
  193329. const String SystemStats::getCpuVendor() throw()
  193330. {
  193331. return getCpuInfo ("vendor_id");
  193332. }
  193333. int SystemStats::getCpuSpeedInMegaherz() throw()
  193334. {
  193335. const String speed (getCpuInfo ("cpu MHz"));
  193336. return (int) (speed.getFloatValue() + 0.5f);
  193337. }
  193338. int SystemStats::getMemorySizeInMegabytes() throw()
  193339. {
  193340. struct sysinfo sysi;
  193341. if (sysinfo (&sysi) == 0)
  193342. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193343. return 0;
  193344. }
  193345. uint32 juce_millisecondsSinceStartup() throw()
  193346. {
  193347. static unsigned int calibrate = 0;
  193348. static bool calibrated = false;
  193349. timeval t;
  193350. unsigned int ret = 0;
  193351. if (! gettimeofday (&t, 0))
  193352. {
  193353. if (! calibrated)
  193354. {
  193355. struct sysinfo sysi;
  193356. if (sysinfo (&sysi) == 0)
  193357. // Safe to assume system was not brought up earlier than 1970!
  193358. calibrate = t.tv_sec - sysi.uptime;
  193359. calibrated = true;
  193360. }
  193361. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193362. }
  193363. return ret;
  193364. }
  193365. double Time::getMillisecondCounterHiRes() throw()
  193366. {
  193367. return getHighResolutionTicks() * 0.001;
  193368. }
  193369. int64 Time::getHighResolutionTicks() throw()
  193370. {
  193371. timeval t;
  193372. if (gettimeofday (&t, 0))
  193373. return 0;
  193374. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193375. }
  193376. int64 Time::getHighResolutionTicksPerSecond() throw()
  193377. {
  193378. // Microseconds
  193379. return 1000000;
  193380. }
  193381. bool Time::setSystemTimeToThisTime() const throw()
  193382. {
  193383. timeval t;
  193384. t.tv_sec = millisSinceEpoch % 1000000;
  193385. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193386. return settimeofday (&t, NULL) ? false : true;
  193387. }
  193388. int SystemStats::getPageSize() throw()
  193389. {
  193390. static int systemPageSize = 0;
  193391. if (systemPageSize == 0)
  193392. systemPageSize = sysconf (_SC_PAGESIZE);
  193393. return systemPageSize;
  193394. }
  193395. int SystemStats::getNumCpus() throw()
  193396. {
  193397. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193398. return lastCpu + 1;
  193399. }
  193400. const String SystemStats::getLogonName()
  193401. {
  193402. const char* user = getenv ("USER");
  193403. if (user == 0)
  193404. {
  193405. struct passwd* const pw = getpwuid (getuid());
  193406. if (pw != 0)
  193407. user = pw->pw_name;
  193408. }
  193409. return String::fromUTF8 (user);
  193410. }
  193411. const String SystemStats::getFullUserName()
  193412. {
  193413. return getLogonName();
  193414. }
  193415. void SystemStats::initialiseStats() throw()
  193416. {
  193417. // Process starts off as root when running suid
  193418. Process::lowerPrivilege();
  193419. String s (SystemStats::getJUCEVersion());
  193420. }
  193421. void PlatformUtilities::fpuReset()
  193422. {
  193423. }
  193424. #endif
  193425. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193426. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193427. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193428. // compiled on its own).
  193429. #if JUCE_INCLUDED_FILE
  193430. void JUCE_API juce_threadEntryPoint (void*);
  193431. void* threadEntryProc (void* value)
  193432. {
  193433. // New threads start off as root when running suid
  193434. Process::lowerPrivilege();
  193435. juce_threadEntryPoint (value);
  193436. return 0;
  193437. }
  193438. void* juce_createThread (void* userData)
  193439. {
  193440. pthread_t handle = 0;
  193441. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  193442. {
  193443. pthread_detach (handle);
  193444. return (void*) handle;
  193445. }
  193446. return 0;
  193447. }
  193448. void juce_killThread (void* handle)
  193449. {
  193450. if (handle != 0)
  193451. pthread_cancel ((pthread_t)handle);
  193452. }
  193453. void juce_setCurrentThreadName (const String& /*name*/)
  193454. {
  193455. }
  193456. Thread::ThreadID Thread::getCurrentThreadId()
  193457. {
  193458. return (ThreadID) pthread_self();
  193459. }
  193460. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  193461. // priority of the current thread
  193462. bool juce_setThreadPriority (void* handle, int priority)
  193463. {
  193464. struct sched_param param;
  193465. int policy, maxp, minp, pri;
  193466. if (handle == 0)
  193467. handle = (void*) pthread_self();
  193468. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  193469. && policy != SCHED_OTHER)
  193470. {
  193471. minp = sched_get_priority_min(policy);
  193472. maxp = sched_get_priority_max(policy);
  193473. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  193474. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  193475. // Realtime process priority
  193476. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  193477. else
  193478. // High process priority
  193479. param.__sched_priority = minp + pri;
  193480. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  193481. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  193482. }
  193483. return false;
  193484. }
  193485. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  193486. {
  193487. #if SUPPORT_AFFINITIES
  193488. cpu_set_t affinity;
  193489. CPU_ZERO (&affinity);
  193490. for (int i = 0; i < 32; ++i)
  193491. if ((affinityMask & (1 << i)) != 0)
  193492. CPU_SET (i, &affinity);
  193493. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  193494. sched_yield();
  193495. #else
  193496. /* affinities aren't supported because either the appropriate header files weren't found,
  193497. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  193498. */
  193499. jassertfalse
  193500. #endif
  193501. }
  193502. void Thread::yield()
  193503. {
  193504. sched_yield();
  193505. }
  193506. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  193507. void Process::setPriority (ProcessPriority prior)
  193508. {
  193509. struct sched_param param;
  193510. int policy, maxp, minp;
  193511. const int p = (int) prior;
  193512. if (p <= 1)
  193513. policy = SCHED_OTHER;
  193514. else
  193515. policy = SCHED_RR;
  193516. minp = sched_get_priority_min (policy);
  193517. maxp = sched_get_priority_max (policy);
  193518. if (p < 2)
  193519. param.__sched_priority = 0;
  193520. else if (p == 2 )
  193521. // Set to middle of lower realtime priority range
  193522. param.__sched_priority = minp + (maxp - minp) / 4;
  193523. else
  193524. // Set to middle of higher realtime priority range
  193525. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  193526. pthread_setschedparam (pthread_self(), policy, &param);
  193527. }
  193528. void Process::terminate()
  193529. {
  193530. exit (0);
  193531. }
  193532. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  193533. {
  193534. static char testResult = 0;
  193535. if (testResult == 0)
  193536. {
  193537. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  193538. if (testResult >= 0)
  193539. {
  193540. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  193541. testResult = 1;
  193542. }
  193543. }
  193544. return testResult < 0;
  193545. }
  193546. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  193547. {
  193548. return juce_isRunningUnderDebugger();
  193549. }
  193550. void Process::raisePrivilege()
  193551. {
  193552. // If running suid root, change effective user
  193553. // to root
  193554. if (geteuid() != 0 && getuid() == 0)
  193555. {
  193556. setreuid (geteuid(), getuid());
  193557. setregid (getegid(), getgid());
  193558. }
  193559. }
  193560. void Process::lowerPrivilege()
  193561. {
  193562. // If runing suid root, change effective user
  193563. // back to real user
  193564. if (geteuid() == 0 && getuid() != 0)
  193565. {
  193566. setreuid (geteuid(), getuid());
  193567. setregid (getegid(), getgid());
  193568. }
  193569. }
  193570. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  193571. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  193572. {
  193573. return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  193574. }
  193575. void PlatformUtilities::freeDynamicLibrary (void* handle)
  193576. {
  193577. dlclose(handle);
  193578. }
  193579. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  193580. {
  193581. return dlsym (libraryHandle, procedureName.toCString());
  193582. }
  193583. #endif
  193584. #endif
  193585. /*** End of inlined file: juce_linux_Threads.cpp ***/
  193586. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  193587. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  193588. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193589. // compiled on its own).
  193590. #if JUCE_INCLUDED_FILE
  193591. #ifdef JUCE_DEBUG
  193592. #define JUCE_DEBUG_XERRORS 1
  193593. #endif
  193594. extern Display* display;
  193595. extern Window juce_messageWindowHandle;
  193596. static String localClipboardContent;
  193597. static Atom atom_UTF8_STRING;
  193598. static Atom atom_CLIPBOARD;
  193599. static Atom atom_TARGETS;
  193600. static void initSelectionAtoms()
  193601. {
  193602. static bool isInitialised = false;
  193603. if (! isInitialised)
  193604. {
  193605. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  193606. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  193607. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  193608. }
  193609. }
  193610. // Read the content of a window property as either a locale-dependent string or an utf8 string
  193611. // works only for strings shorter than 1000000 bytes
  193612. static String juce_readWindowProperty (Window window, Atom prop,
  193613. Atom fmt, // XA_STRING or UTF8_STRING
  193614. bool deleteAfterReading)
  193615. {
  193616. String returnData;
  193617. char* clipData;
  193618. Atom actualType;
  193619. int actualFormat;
  193620. unsigned long numItems, bytesLeft;
  193621. if (XGetWindowProperty (display, window, prop,
  193622. 0L /* offset */, 1000000 /* length (max) */, False,
  193623. AnyPropertyType /* format */,
  193624. &actualType, &actualFormat, &numItems, &bytesLeft,
  193625. (unsigned char**) &clipData) == Success)
  193626. {
  193627. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  193628. {
  193629. returnData = String::fromUTF8 (clipData, numItems);
  193630. }
  193631. else if (actualType == XA_STRING && actualFormat == 8)
  193632. {
  193633. returnData = String (clipData, numItems);
  193634. }
  193635. if (clipData != 0)
  193636. XFree (clipData);
  193637. jassert (bytesLeft == 0 || numItems == 1000000);
  193638. }
  193639. if (deleteAfterReading)
  193640. XDeleteProperty (display, window, prop);
  193641. return returnData;
  193642. }
  193643. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  193644. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  193645. {
  193646. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  193647. // The selection owner will be asked to set the JUCE_SEL property on the
  193648. // juce_messageWindowHandle with the selection content
  193649. XConvertSelection (display, selection, requested_format, property_name,
  193650. juce_messageWindowHandle, CurrentTime);
  193651. int timeoutMs = 200; // will wait at most for 200 ms
  193652. do
  193653. {
  193654. XEvent event;
  193655. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  193656. {
  193657. if (event.xselection.property == property_name)
  193658. {
  193659. jassert (event.xselection.requestor == juce_messageWindowHandle);
  193660. selection_content = juce_readWindowProperty (event.xselection.requestor,
  193661. event.xselection.property,
  193662. requested_format, true);
  193663. return true;
  193664. }
  193665. else
  193666. {
  193667. return false; // the format we asked for was denied.. (event.xselection.property == None)
  193668. }
  193669. }
  193670. // not very elegant.. we could do a select() or something like that...
  193671. // however clipboard content requesting is inherently slow on x11, it
  193672. // often takes 50ms or more so...
  193673. Thread::sleep (4);
  193674. timeoutMs -= 4;
  193675. }
  193676. while (timeoutMs > 0);
  193677. DBG("timeout for juce_requestSelectionContent");
  193678. return false;
  193679. }
  193680. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  193681. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  193682. {
  193683. initSelectionAtoms();
  193684. // the selection content is sent to the target window as a window property
  193685. XSelectionEvent reply;
  193686. reply.type = SelectionNotify;
  193687. reply.display = evt.display;
  193688. reply.requestor = evt.requestor;
  193689. reply.selection = evt.selection;
  193690. reply.target = evt.target;
  193691. reply.property = None; // == "fail"
  193692. reply.time = evt.time;
  193693. HeapBlock <char> data;
  193694. int propertyFormat = 0, numDataItems = 0;
  193695. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  193696. {
  193697. if (evt.target == XA_STRING)
  193698. {
  193699. // format data according to system locale
  193700. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  193701. data.calloc (numDataItems + 1);
  193702. localClipboardContent.copyToCString (data, numDataItems);
  193703. propertyFormat = 8; // bits/item
  193704. }
  193705. else if (evt.target == atom_UTF8_STRING)
  193706. {
  193707. // translate to utf8
  193708. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  193709. data.calloc (numDataItems + 1);
  193710. localClipboardContent.copyToUTF8 (data, numDataItems);
  193711. propertyFormat = 8; // bits/item
  193712. }
  193713. else if (evt.target == atom_TARGETS)
  193714. {
  193715. // another application wants to know what we are able to send
  193716. numDataItems = 2;
  193717. propertyFormat = 32; // atoms are 32-bit
  193718. data.calloc (numDataItems * 4);
  193719. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  193720. atoms[0] = atom_UTF8_STRING;
  193721. atoms[1] = XA_STRING;
  193722. }
  193723. }
  193724. else
  193725. {
  193726. DBG ("requested unsupported clipboard");
  193727. }
  193728. if (data != 0)
  193729. {
  193730. const int maxReasonableSelectionSize = 1000000;
  193731. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  193732. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  193733. {
  193734. XChangeProperty (evt.display, evt.requestor,
  193735. evt.property, evt.target,
  193736. propertyFormat /* 8 or 32 */, PropModeReplace,
  193737. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  193738. reply.property = evt.property; // " == success"
  193739. }
  193740. }
  193741. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  193742. }
  193743. void SystemClipboard::copyTextToClipboard (const String& clipText)
  193744. {
  193745. initSelectionAtoms();
  193746. localClipboardContent = clipText;
  193747. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  193748. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  193749. }
  193750. const String SystemClipboard::getTextFromClipboard()
  193751. {
  193752. initSelectionAtoms();
  193753. String content;
  193754. Atom selection = XA_PRIMARY;
  193755. Window selectionOwner = None;
  193756. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  193757. {
  193758. selection = atom_CLIPBOARD;
  193759. selectionOwner = XGetSelectionOwner (display, selection);
  193760. }
  193761. if (selectionOwner != None)
  193762. {
  193763. if (selectionOwner == juce_messageWindowHandle)
  193764. {
  193765. content = localClipboardContent;
  193766. }
  193767. else
  193768. {
  193769. // first try: we want an utf8 string
  193770. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  193771. if (! ok)
  193772. {
  193773. // second chance, ask for a good old locale-dependent string ..
  193774. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  193775. }
  193776. }
  193777. }
  193778. return content;
  193779. }
  193780. #endif
  193781. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  193782. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  193783. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193784. // compiled on its own).
  193785. #if JUCE_INCLUDED_FILE
  193786. #ifdef JUCE_DEBUG
  193787. #define JUCE_DEBUG_XERRORS 1
  193788. #endif
  193789. Display* display = 0; // This is also referenced from WindowDriver.cpp
  193790. Window juce_messageWindowHandle = None;
  193791. XContext improbableNumber; // This is referenced from Windowing.cpp
  193792. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  193793. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  193794. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  193795. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  193796. class InternalMessageQueue
  193797. {
  193798. public:
  193799. InternalMessageQueue()
  193800. : bytesInSocket (0)
  193801. {
  193802. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  193803. (void) ret; jassert (ret == 0);
  193804. //setNonBlocking (fd[0]);
  193805. //setNonBlocking (fd[1]);
  193806. }
  193807. ~InternalMessageQueue()
  193808. {
  193809. close (fd[0]);
  193810. close (fd[1]);
  193811. }
  193812. void postMessage (Message* msg)
  193813. {
  193814. const int maxBytesInSocketQueue = 128;
  193815. ScopedLock sl (lock);
  193816. queue.add (msg);
  193817. if (bytesInSocket < maxBytesInSocketQueue)
  193818. {
  193819. ++bytesInSocket;
  193820. ScopedUnlock ul (lock);
  193821. const unsigned char x = 0xff;
  193822. size_t bytesWritten = write (fd[0], &x, 1);
  193823. (void) bytesWritten;
  193824. }
  193825. }
  193826. bool isEmpty() const
  193827. {
  193828. ScopedLock sl (lock);
  193829. return queue.size() == 0;
  193830. }
  193831. Message* popNextMessage()
  193832. {
  193833. ScopedLock sl (lock);
  193834. if (bytesInSocket > 0)
  193835. {
  193836. --bytesInSocket;
  193837. ScopedUnlock ul (lock);
  193838. unsigned char x;
  193839. size_t numBytes = read (fd[1], &x, 1);
  193840. (void) numBytes;
  193841. }
  193842. Message* m = queue[0];
  193843. queue.remove (0, false /* deleteObject */);
  193844. return m;
  193845. }
  193846. int getWaitHandle() const { return fd[1]; }
  193847. private:
  193848. CriticalSection lock;
  193849. OwnedArray <Message> queue;
  193850. int fd[2];
  193851. int bytesInSocket;
  193852. static bool setNonBlocking (int handle)
  193853. {
  193854. int socketFlags = fcntl (handle, F_GETFL, 0);
  193855. if (socketFlags == -1)
  193856. return false;
  193857. socketFlags |= O_NONBLOCK;
  193858. return fcntl (handle, F_SETFL, socketFlags) == 0;
  193859. }
  193860. };
  193861. struct MessageThreadFuncCall
  193862. {
  193863. enum { uniqueID = 0x73774623 };
  193864. MessageCallbackFunction* func;
  193865. void* parameter;
  193866. void* result;
  193867. CriticalSection lock;
  193868. WaitableEvent event;
  193869. };
  193870. static InternalMessageQueue* juce_internalMessageQueue = 0;
  193871. // error handling in X11
  193872. static bool errorOccurred = false;
  193873. static bool keyboardBreakOccurred = false;
  193874. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  193875. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  193876. // Usually happens when client-server connection is broken
  193877. static int ioErrorHandler (Display* display)
  193878. {
  193879. DBG ("ERROR: connection to X server broken.. terminating.");
  193880. errorOccurred = true;
  193881. if (JUCEApplication::getInstance() != 0)
  193882. Process::terminate();
  193883. return 0;
  193884. }
  193885. // A protocol error has occurred
  193886. static int errorHandler (Display* display, XErrorEvent* event)
  193887. {
  193888. #ifdef JUCE_DEBUG_XERRORS
  193889. char errorStr[64] = { 0 };
  193890. char requestStr[64] = { 0 };
  193891. XGetErrorText (display, event->error_code, errorStr, 64);
  193892. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  193893. "Unknown", requestStr, 64);
  193894. DBG ("ERROR: X returned " + String (errorStr) + " for operation " + String (requestStr));
  193895. #endif
  193896. return 0;
  193897. }
  193898. // Breakin from keyboard
  193899. static void signalHandler (int sig)
  193900. {
  193901. if (sig == SIGINT)
  193902. {
  193903. keyboardBreakOccurred = true;
  193904. return;
  193905. }
  193906. static bool reentrant = false;
  193907. if (! reentrant)
  193908. {
  193909. reentrant = true;
  193910. // Illegal instruction
  193911. fflush (stdout);
  193912. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  193913. errorOccurred = true;
  193914. if (JUCEApplication::getInstance() != 0)
  193915. Process::terminate();
  193916. }
  193917. else
  193918. {
  193919. if (JUCEApplication::getInstance() != 0)
  193920. exit(0);
  193921. }
  193922. }
  193923. void MessageManager::doPlatformSpecificInitialisation()
  193924. {
  193925. // Initialise xlib for multiple thread support
  193926. static bool initThreadCalled = false;
  193927. if (! initThreadCalled)
  193928. {
  193929. if (! XInitThreads())
  193930. {
  193931. // This is fatal! Print error and closedown
  193932. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  193933. if (JUCEApplication::getInstance() != 0)
  193934. Process::terminate();
  193935. return;
  193936. }
  193937. initThreadCalled = true;
  193938. }
  193939. // This is called if the client/server connection is broken
  193940. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  193941. // This is called if a protocol error occurs
  193942. oldErrorHandler = XSetErrorHandler (errorHandler);
  193943. // Install signal handler for break-in
  193944. struct sigaction saction;
  193945. sigset_t maskSet;
  193946. sigemptyset (&maskSet);
  193947. saction.sa_handler = signalHandler;
  193948. saction.sa_mask = maskSet;
  193949. saction.sa_flags = 0;
  193950. sigaction (SIGINT, &saction, NULL);
  193951. #ifndef _DEBUG
  193952. // Setup signal handlers for various fatal errors
  193953. sigaction (SIGILL, &saction, NULL);
  193954. sigaction (SIGBUS, &saction, NULL);
  193955. sigaction (SIGFPE, &saction, NULL);
  193956. sigaction (SIGSEGV, &saction, NULL);
  193957. sigaction (SIGSYS, &saction, NULL);
  193958. #endif
  193959. // Create the internal message queue
  193960. juce_internalMessageQueue = new InternalMessageQueue();
  193961. // Try to connect to a display
  193962. String displayName (getenv ("DISPLAY"));
  193963. if (displayName.isEmpty())
  193964. displayName = ":0.0";
  193965. display = XOpenDisplay (displayName.toCString());
  193966. if (display == 0)
  193967. {
  193968. // This is not fatal! we can run headless.
  193969. return;
  193970. }
  193971. // Get defaults for various properties
  193972. int screen = DefaultScreen (display);
  193973. Window root = RootWindow (display, screen);
  193974. Visual* visual = DefaultVisual (display, screen);
  193975. // Create a context to store user data associated with Windows we
  193976. // create in WindowDriver
  193977. improbableNumber = XUniqueContext();
  193978. // We're only interested in client messages for this window
  193979. // which are always sent
  193980. XSetWindowAttributes swa;
  193981. swa.event_mask = NoEventMask;
  193982. // Create our message window (this will never be mapped)
  193983. juce_messageWindowHandle = XCreateWindow (display, root,
  193984. 0, 0, 1, 1, 0, 0, InputOnly,
  193985. visual, CWEventMask, &swa);
  193986. }
  193987. void MessageManager::doPlatformSpecificShutdown()
  193988. {
  193989. deleteAndZero (juce_internalMessageQueue);
  193990. if (display != 0 && ! errorOccurred)
  193991. {
  193992. XDestroyWindow (display, juce_messageWindowHandle);
  193993. XCloseDisplay (display);
  193994. // reset pointers
  193995. juce_messageWindowHandle = 0;
  193996. display = 0;
  193997. // Restore original error handlers
  193998. XSetIOErrorHandler (oldIOErrorHandler);
  193999. oldIOErrorHandler = 0;
  194000. XSetErrorHandler (oldErrorHandler);
  194001. oldErrorHandler = 0;
  194002. }
  194003. }
  194004. bool juce_postMessageToSystemQueue (void* message)
  194005. {
  194006. if (errorOccurred)
  194007. return false;
  194008. juce_internalMessageQueue->postMessage ((Message*) message);
  194009. return true;
  194010. }
  194011. void MessageManager::broadcastMessage (const String& value) throw()
  194012. {
  194013. }
  194014. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194015. void* parameter)
  194016. {
  194017. if (errorOccurred)
  194018. return 0;
  194019. if (! isThisTheMessageThread())
  194020. {
  194021. MessageThreadFuncCall messageCallContext;
  194022. messageCallContext.func = func;
  194023. messageCallContext.parameter = parameter;
  194024. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194025. 0, 0, &messageCallContext));
  194026. // Wait for it to complete before continuing
  194027. messageCallContext.event.wait();
  194028. return messageCallContext.result;
  194029. }
  194030. else
  194031. {
  194032. // Just call the function directly
  194033. return func (parameter);
  194034. }
  194035. }
  194036. // Wait for an event (either XEvent, or an internal Message)
  194037. static bool juce_sleepUntilEvent (const int timeoutMs)
  194038. {
  194039. if (! juce_internalMessageQueue->isEmpty())
  194040. return true;
  194041. if (display != 0)
  194042. {
  194043. ScopedXLock xlock;
  194044. if (XPending (display))
  194045. return true;
  194046. }
  194047. struct timeval tv;
  194048. tv.tv_sec = 0;
  194049. tv.tv_usec = timeoutMs * 1000;
  194050. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194051. int fdmax = fd0;
  194052. fd_set readset;
  194053. FD_ZERO (&readset);
  194054. FD_SET (fd0, &readset);
  194055. if (display != 0)
  194056. {
  194057. ScopedXLock xlock;
  194058. int fd1 = XConnectionNumber (display);
  194059. FD_SET (fd1, &readset);
  194060. fdmax = jmax (fd0, fd1);
  194061. }
  194062. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194063. return (ret > 0); // ret <= 0 if error or timeout
  194064. }
  194065. // Handle next XEvent (if any)
  194066. static bool juce_dispatchNextXEvent()
  194067. {
  194068. if (display == 0)
  194069. return false;
  194070. XEvent evt;
  194071. {
  194072. ScopedXLock xlock;
  194073. if (! XPending (display))
  194074. return false;
  194075. XNextEvent (display, &evt);
  194076. }
  194077. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194078. {
  194079. juce_handleSelectionRequest (evt.xselectionrequest);
  194080. }
  194081. else if (evt.xany.window != juce_messageWindowHandle)
  194082. {
  194083. juce_windowMessageReceive (&evt);
  194084. }
  194085. return true;
  194086. }
  194087. // Handle next internal Message (if any)
  194088. static bool juce_dispatchNextInternalMessage()
  194089. {
  194090. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194091. if (msg == 0)
  194092. return false;
  194093. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194094. {
  194095. // Handle callback message
  194096. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194097. call->result = (*(call->func)) (call->parameter);
  194098. call->event.signal();
  194099. }
  194100. else
  194101. {
  194102. // Handle "normal" messages
  194103. MessageManager::getInstance()->deliverMessage (msg.release());
  194104. }
  194105. return true;
  194106. }
  194107. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194108. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194109. {
  194110. for (;;)
  194111. {
  194112. if (errorOccurred)
  194113. break;
  194114. if (keyboardBreakOccurred)
  194115. {
  194116. errorOccurred = true;
  194117. if (JUCEApplication::getInstance() != 0)
  194118. Process::terminate();
  194119. break;
  194120. }
  194121. static int totalEventCount = 0;
  194122. ++totalEventCount;
  194123. // The purpose here is to give either priority to XEvents or
  194124. // to internal messages This is necessary to keep a "good"
  194125. // behaviour when the cpu is overloaded
  194126. if (totalEventCount & 1)
  194127. {
  194128. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194129. return true;
  194130. }
  194131. else
  194132. {
  194133. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194134. return true;
  194135. }
  194136. if (returnIfNoPendingMessages) // early exit
  194137. break;
  194138. // the timeout is to be on the safe side, but it does not seem to be useful
  194139. juce_sleepUntilEvent (2000);
  194140. }
  194141. return false;
  194142. }
  194143. #endif
  194144. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194145. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194146. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194147. // compiled on its own).
  194148. #if JUCE_INCLUDED_FILE
  194149. class FreeTypeFontFace
  194150. {
  194151. public:
  194152. enum FontStyle
  194153. {
  194154. Plain = 0,
  194155. Bold = 1,
  194156. Italic = 2
  194157. };
  194158. struct FontNameIndex
  194159. {
  194160. String fileName;
  194161. int faceIndex;
  194162. };
  194163. FreeTypeFontFace (const String& familyName)
  194164. : hasSerif (false),
  194165. monospaced (false)
  194166. {
  194167. family = familyName;
  194168. }
  194169. void setFileName (const String& name, const int faceIndex, FontStyle style)
  194170. {
  194171. if (names [(int) style].fileName.isEmpty())
  194172. {
  194173. names [(int) style].fileName = name;
  194174. names [(int) style].faceIndex = faceIndex;
  194175. }
  194176. }
  194177. const String& getFamilyName() const throw() { return family; }
  194178. const String& getFileName (const int style, int& faceIndex) const throw()
  194179. {
  194180. faceIndex = names[style].faceIndex;
  194181. return names[style].fileName;
  194182. }
  194183. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194184. bool getMonospaced() const throw() { return monospaced; }
  194185. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194186. bool getSerif() const throw() { return hasSerif; }
  194187. private:
  194188. String family;
  194189. FontNameIndex names[4];
  194190. bool hasSerif, monospaced;
  194191. };
  194192. class FreeTypeInterface : public DeletedAtShutdown
  194193. {
  194194. public:
  194195. FreeTypeInterface()
  194196. : ftLib (0),
  194197. lastFace (0),
  194198. lastBold (false),
  194199. lastItalic (false)
  194200. {
  194201. if (FT_Init_FreeType (&ftLib) != 0)
  194202. {
  194203. ftLib = 0;
  194204. DBG ("Failed to initialize FreeType");
  194205. }
  194206. StringArray fontDirs;
  194207. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194208. fontDirs.removeEmptyStrings (true);
  194209. if (fontDirs.size() == 0)
  194210. {
  194211. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194212. const ScopedPointer<XmlElement> fontsInfo (fontsConfig.getDocumentElement());
  194213. if (fontsInfo != 0)
  194214. {
  194215. forEachXmlChildElementWithTagName (*fontsInfo, e, "dir")
  194216. {
  194217. fontDirs.add (e->getAllSubText().trim());
  194218. }
  194219. }
  194220. }
  194221. if (fontDirs.size() == 0)
  194222. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194223. for (int i = 0; i < fontDirs.size(); ++i)
  194224. enumerateFaces (fontDirs[i]);
  194225. }
  194226. ~FreeTypeInterface()
  194227. {
  194228. if (lastFace != 0)
  194229. FT_Done_Face (lastFace);
  194230. if (ftLib != 0)
  194231. FT_Done_FreeType (ftLib);
  194232. clearSingletonInstance();
  194233. }
  194234. FreeTypeFontFace* findOrCreate (const String& familyName, const bool create = false)
  194235. {
  194236. for (int i = 0; i < faces.size(); i++)
  194237. if (faces[i]->getFamilyName() == familyName)
  194238. return faces[i];
  194239. if (! create)
  194240. return NULL;
  194241. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194242. faces.add (newFace);
  194243. return newFace;
  194244. }
  194245. // Enumerate all font faces available in a given directory
  194246. void enumerateFaces (const String& path)
  194247. {
  194248. File dirPath (path);
  194249. if (path.isEmpty() || ! dirPath.isDirectory())
  194250. return;
  194251. DirectoryIterator di (dirPath, true);
  194252. while (di.next())
  194253. {
  194254. File possible (di.getFile());
  194255. if (possible.hasFileExtension ("ttf")
  194256. || possible.hasFileExtension ("pfb")
  194257. || possible.hasFileExtension ("pcf"))
  194258. {
  194259. FT_Face face;
  194260. int faceIndex = 0;
  194261. int numFaces = 0;
  194262. do
  194263. {
  194264. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194265. faceIndex, &face) == 0)
  194266. {
  194267. if (faceIndex == 0)
  194268. numFaces = face->num_faces;
  194269. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194270. {
  194271. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194272. int style = (int) FreeTypeFontFace::Plain;
  194273. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194274. style |= (int) FreeTypeFontFace::Bold;
  194275. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194276. style |= (int) FreeTypeFontFace::Italic;
  194277. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194278. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194279. // Surely there must be a better way to do this?
  194280. const String name (face->family_name);
  194281. newFace->setSerif (! (name.containsIgnoreCase ("Sans")
  194282. || name.containsIgnoreCase ("Verdana")
  194283. || name.containsIgnoreCase ("Arial")));
  194284. }
  194285. FT_Done_Face (face);
  194286. }
  194287. ++faceIndex;
  194288. }
  194289. while (faceIndex < numFaces);
  194290. }
  194291. }
  194292. }
  194293. // Create a FreeType face object for a given font
  194294. FT_Face createFT_Face (const String& fontName, const bool bold, const bool italic)
  194295. {
  194296. FT_Face face = 0;
  194297. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194298. {
  194299. face = lastFace;
  194300. }
  194301. else
  194302. {
  194303. if (lastFace != 0)
  194304. {
  194305. FT_Done_Face (lastFace);
  194306. lastFace = 0;
  194307. }
  194308. lastFontName = fontName;
  194309. lastBold = bold;
  194310. lastItalic = italic;
  194311. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194312. if (ftFace != 0)
  194313. {
  194314. int style = (int) FreeTypeFontFace::Plain;
  194315. if (bold)
  194316. style |= (int) FreeTypeFontFace::Bold;
  194317. if (italic)
  194318. style |= (int) FreeTypeFontFace::Italic;
  194319. int faceIndex;
  194320. String fileName (ftFace->getFileName (style, faceIndex));
  194321. if (fileName.isEmpty())
  194322. {
  194323. style ^= (int) FreeTypeFontFace::Bold;
  194324. fileName = ftFace->getFileName (style, faceIndex);
  194325. if (fileName.isEmpty())
  194326. {
  194327. style ^= (int) FreeTypeFontFace::Bold;
  194328. style ^= (int) FreeTypeFontFace::Italic;
  194329. fileName = ftFace->getFileName (style, faceIndex);
  194330. if (! fileName.length())
  194331. {
  194332. style ^= (int) FreeTypeFontFace::Bold;
  194333. fileName = ftFace->getFileName (style, faceIndex);
  194334. }
  194335. }
  194336. }
  194337. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194338. {
  194339. face = lastFace;
  194340. // If there isn't a unicode charmap then select the first one.
  194341. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194342. FT_Set_Charmap (face, face->charmaps[0]);
  194343. }
  194344. }
  194345. }
  194346. return face;
  194347. }
  194348. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character)
  194349. {
  194350. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194351. const float height = (float) (face->ascender - face->descender);
  194352. const float scaleX = 1.0f / height;
  194353. const float scaleY = -1.0f / height;
  194354. Path destShape;
  194355. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194356. || face->glyph->format != ft_glyph_format_outline)
  194357. {
  194358. return false;
  194359. }
  194360. const FT_Outline* const outline = &face->glyph->outline;
  194361. const short* const contours = outline->contours;
  194362. const char* const tags = outline->tags;
  194363. FT_Vector* const points = outline->points;
  194364. for (int c = 0; c < outline->n_contours; c++)
  194365. {
  194366. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194367. const int endPoint = contours[c];
  194368. for (int p = startPoint; p <= endPoint; p++)
  194369. {
  194370. const float x = scaleX * points[p].x;
  194371. const float y = scaleY * points[p].y;
  194372. if (p == startPoint)
  194373. {
  194374. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194375. {
  194376. float x2 = scaleX * points [endPoint].x;
  194377. float y2 = scaleY * points [endPoint].y;
  194378. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194379. {
  194380. x2 = (x + x2) * 0.5f;
  194381. y2 = (y + y2) * 0.5f;
  194382. }
  194383. destShape.startNewSubPath (x2, y2);
  194384. }
  194385. else
  194386. {
  194387. destShape.startNewSubPath (x, y);
  194388. }
  194389. }
  194390. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194391. {
  194392. if (p != startPoint)
  194393. destShape.lineTo (x, y);
  194394. }
  194395. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194396. {
  194397. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194398. float x2 = scaleX * points [nextIndex].x;
  194399. float y2 = scaleY * points [nextIndex].y;
  194400. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194401. {
  194402. x2 = (x + x2) * 0.5f;
  194403. y2 = (y + y2) * 0.5f;
  194404. }
  194405. else
  194406. {
  194407. ++p;
  194408. }
  194409. destShape.quadraticTo (x, y, x2, y2);
  194410. }
  194411. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194412. {
  194413. if (p >= endPoint)
  194414. return false;
  194415. const int next1 = p + 1;
  194416. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194417. const float x2 = scaleX * points [next1].x;
  194418. const float y2 = scaleY * points [next1].y;
  194419. const float x3 = scaleX * points [next2].x;
  194420. const float y3 = scaleY * points [next2].y;
  194421. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194422. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194423. return false;
  194424. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194425. p += 2;
  194426. }
  194427. }
  194428. destShape.closeSubPath();
  194429. }
  194430. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  194431. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  194432. addKerning (face, dest, character, glyphIndex);
  194433. return true;
  194434. }
  194435. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex)
  194436. {
  194437. const float height = (float) (face->ascender - face->descender);
  194438. uint32 rightGlyphIndex;
  194439. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  194440. while (rightGlyphIndex != 0)
  194441. {
  194442. FT_Vector kerning;
  194443. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  194444. {
  194445. if (kerning.x != 0)
  194446. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  194447. }
  194448. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  194449. }
  194450. }
  194451. // Add a glyph to a font
  194452. bool addGlyphToFont (const uint32 character, const String& fontName,
  194453. bool bold, bool italic, CustomTypeface& dest)
  194454. {
  194455. FT_Face face = createFT_Face (fontName, bold, italic);
  194456. return face != 0 && addGlyph (face, dest, character);
  194457. }
  194458. void getFamilyNames (StringArray& familyNames) const
  194459. {
  194460. for (int i = 0; i < faces.size(); i++)
  194461. familyNames.add (faces[i]->getFamilyName());
  194462. }
  194463. void getMonospacedNames (StringArray& monoSpaced) const
  194464. {
  194465. for (int i = 0; i < faces.size(); i++)
  194466. if (faces[i]->getMonospaced())
  194467. monoSpaced.add (faces[i]->getFamilyName());
  194468. }
  194469. void getSerifNames (StringArray& serif) const
  194470. {
  194471. for (int i = 0; i < faces.size(); i++)
  194472. if (faces[i]->getSerif())
  194473. serif.add (faces[i]->getFamilyName());
  194474. }
  194475. void getSansSerifNames (StringArray& sansSerif) const
  194476. {
  194477. for (int i = 0; i < faces.size(); i++)
  194478. if (! faces[i]->getSerif())
  194479. sansSerif.add (faces[i]->getFamilyName());
  194480. }
  194481. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  194482. private:
  194483. FT_Library ftLib;
  194484. FT_Face lastFace;
  194485. String lastFontName;
  194486. bool lastBold, lastItalic;
  194487. OwnedArray<FreeTypeFontFace> faces;
  194488. };
  194489. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  194490. class FreetypeTypeface : public CustomTypeface
  194491. {
  194492. public:
  194493. FreetypeTypeface (const Font& font)
  194494. {
  194495. FT_Face face = FreeTypeInterface::getInstance()
  194496. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  194497. if (face == 0)
  194498. {
  194499. #ifdef JUCE_DEBUG
  194500. String msg ("Failed to create typeface: ");
  194501. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  194502. DBG (msg);
  194503. #endif
  194504. }
  194505. else
  194506. {
  194507. setCharacteristics (font.getTypefaceName(),
  194508. face->ascender / (float) (face->ascender - face->descender),
  194509. font.isBold(), font.isItalic(),
  194510. L' ');
  194511. }
  194512. }
  194513. bool loadGlyphIfPossible (juce_wchar character)
  194514. {
  194515. return FreeTypeInterface::getInstance()
  194516. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  194517. }
  194518. };
  194519. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  194520. {
  194521. return new FreetypeTypeface (font);
  194522. }
  194523. const StringArray Font::findAllTypefaceNames()
  194524. {
  194525. StringArray s;
  194526. FreeTypeInterface::getInstance()->getFamilyNames (s);
  194527. s.sort (true);
  194528. return s;
  194529. }
  194530. static const String pickBestFont (const StringArray& names,
  194531. const char* const choicesString)
  194532. {
  194533. StringArray choices;
  194534. choices.addTokens (String (choicesString), ",", String::empty);
  194535. choices.trim();
  194536. choices.removeEmptyStrings();
  194537. int i, j;
  194538. for (j = 0; j < choices.size(); ++j)
  194539. if (names.contains (choices[j], true))
  194540. return choices[j];
  194541. for (j = 0; j < choices.size(); ++j)
  194542. for (i = 0; i < names.size(); i++)
  194543. if (names[i].startsWithIgnoreCase (choices[j]))
  194544. return names[i];
  194545. for (j = 0; j < choices.size(); ++j)
  194546. for (i = 0; i < names.size(); i++)
  194547. if (names[i].containsIgnoreCase (choices[j]))
  194548. return names[i];
  194549. return names[0];
  194550. }
  194551. static const String linux_getDefaultSansSerifFontName()
  194552. {
  194553. StringArray allFonts;
  194554. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  194555. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  194556. }
  194557. static const String linux_getDefaultSerifFontName()
  194558. {
  194559. StringArray allFonts;
  194560. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  194561. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  194562. }
  194563. static const String linux_getDefaultMonospacedFontName()
  194564. {
  194565. StringArray allFonts;
  194566. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  194567. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  194568. }
  194569. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  194570. {
  194571. defaultSans = linux_getDefaultSansSerifFontName();
  194572. defaultSerif = linux_getDefaultSerifFontName();
  194573. defaultFixed = linux_getDefaultMonospacedFontName();
  194574. }
  194575. #endif
  194576. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  194577. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  194578. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194579. // compiled on its own).
  194580. #if JUCE_INCLUDED_FILE
  194581. // These are defined in juce_linux_Messaging.cpp
  194582. extern Display* display;
  194583. extern XContext improbableNumber;
  194584. namespace Atoms
  194585. {
  194586. enum ProtocolItems
  194587. {
  194588. TAKE_FOCUS = 0,
  194589. DELETE_WINDOW = 1,
  194590. PING = 2
  194591. };
  194592. static Atom Protocols, ProtocolList[3], ChangeState, State,
  194593. ActiveWin, Pid, WindowType, WindowState,
  194594. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  194595. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  194596. XdndActionDescription, XdndActionCopy,
  194597. allowedActions[5],
  194598. allowedMimeTypes[2];
  194599. const unsigned long DndVersion = 3;
  194600. static void initialiseAtoms()
  194601. {
  194602. static bool atomsInitialised = false;
  194603. if (! atomsInitialised)
  194604. {
  194605. atomsInitialised = true;
  194606. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  194607. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  194608. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  194609. ProtocolList [PING] = XInternAtom (display, "_NET_WM_PING", True);
  194610. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  194611. State = XInternAtom (display, "WM_STATE", True);
  194612. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  194613. Pid = XInternAtom (display, "_NET_WM_PID", False);
  194614. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  194615. WindowState = XInternAtom (display, "_NET_WM_STATE", True);
  194616. XdndAware = XInternAtom (display, "XdndAware", False);
  194617. XdndEnter = XInternAtom (display, "XdndEnter", False);
  194618. XdndLeave = XInternAtom (display, "XdndLeave", False);
  194619. XdndPosition = XInternAtom (display, "XdndPosition", False);
  194620. XdndStatus = XInternAtom (display, "XdndStatus", False);
  194621. XdndDrop = XInternAtom (display, "XdndDrop", False);
  194622. XdndFinished = XInternAtom (display, "XdndFinished", False);
  194623. XdndSelection = XInternAtom (display, "XdndSelection", False);
  194624. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  194625. XdndActionList = XInternAtom (display, "XdndActionList", False);
  194626. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  194627. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  194628. allowedMimeTypes[0] = XInternAtom (display, "text/plain", False);
  194629. allowedMimeTypes[1] = XInternAtom (display, "text/uri-list", False);
  194630. allowedActions[0] = XInternAtom (display, "XdndActionMove", False);
  194631. allowedActions[1] = XdndActionCopy;
  194632. allowedActions[2] = XInternAtom (display, "XdndActionLink", False);
  194633. allowedActions[3] = XInternAtom (display, "XdndActionAsk", False);
  194634. allowedActions[4] = XInternAtom (display, "XdndActionPrivate", False);
  194635. }
  194636. }
  194637. }
  194638. namespace Keys
  194639. {
  194640. enum MouseButtons
  194641. {
  194642. NoButton = 0,
  194643. LeftButton = 1,
  194644. MiddleButton = 2,
  194645. RightButton = 3,
  194646. WheelUp = 4,
  194647. WheelDown = 5
  194648. };
  194649. static int AltMask = 0;
  194650. static int NumLockMask = 0;
  194651. static bool numLock = false;
  194652. static bool capsLock = false;
  194653. static char keyStates [32];
  194654. static const int extendedKeyModifier = 0x10000000;
  194655. }
  194656. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  194657. {
  194658. int keysym;
  194659. if (keyCode & Keys::extendedKeyModifier)
  194660. {
  194661. keysym = 0xff00 | (keyCode & 0xff);
  194662. }
  194663. else
  194664. {
  194665. keysym = keyCode;
  194666. if (keysym == (XK_Tab & 0xff)
  194667. || keysym == (XK_Return & 0xff)
  194668. || keysym == (XK_Escape & 0xff)
  194669. || keysym == (XK_BackSpace & 0xff))
  194670. {
  194671. keysym |= 0xff00;
  194672. }
  194673. }
  194674. ScopedXLock xlock;
  194675. const int keycode = XKeysymToKeycode (display, keysym);
  194676. const int keybyte = keycode >> 3;
  194677. const int keybit = (1 << (keycode & 7));
  194678. return (Keys::keyStates [keybyte] & keybit) != 0;
  194679. }
  194680. #if JUCE_USE_XSHM
  194681. namespace XSHMHelpers
  194682. {
  194683. static int trappedErrorCode = 0;
  194684. extern "C" int errorTrapHandler (Display*, XErrorEvent* err)
  194685. {
  194686. trappedErrorCode = err->error_code;
  194687. return 0;
  194688. }
  194689. static bool isShmAvailable() throw()
  194690. {
  194691. static bool isChecked = false;
  194692. static bool isAvailable = false;
  194693. if (! isChecked)
  194694. {
  194695. isChecked = true;
  194696. int major, minor;
  194697. Bool pixmaps;
  194698. ScopedXLock xlock;
  194699. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  194700. {
  194701. trappedErrorCode = 0;
  194702. XErrorHandler oldHandler = XSetErrorHandler (errorTrapHandler);
  194703. XShmSegmentInfo segmentInfo;
  194704. zerostruct (segmentInfo);
  194705. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  194706. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  194707. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  194708. xImage->bytes_per_line * xImage->height,
  194709. IPC_CREAT | 0777)) >= 0)
  194710. {
  194711. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  194712. if (segmentInfo.shmaddr != (void*) -1)
  194713. {
  194714. segmentInfo.readOnly = False;
  194715. xImage->data = segmentInfo.shmaddr;
  194716. XSync (display, False);
  194717. if (XShmAttach (display, &segmentInfo) != 0)
  194718. {
  194719. XSync (display, False);
  194720. XShmDetach (display, &segmentInfo);
  194721. isAvailable = true;
  194722. }
  194723. }
  194724. XFlush (display);
  194725. XDestroyImage (xImage);
  194726. shmdt (segmentInfo.shmaddr);
  194727. }
  194728. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  194729. XSetErrorHandler (oldHandler);
  194730. if (trappedErrorCode != 0)
  194731. isAvailable = false;
  194732. }
  194733. }
  194734. return isAvailable;
  194735. }
  194736. }
  194737. #endif
  194738. #if JUCE_USE_XRENDER
  194739. namespace XRender
  194740. {
  194741. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  194742. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  194743. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  194744. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  194745. static tXRenderQueryVersion xRenderQueryVersion = 0;
  194746. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  194747. static tXRenderFindFormat xRenderFindFormat = 0;
  194748. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  194749. static bool isAvailable()
  194750. {
  194751. static bool hasLoaded = false;
  194752. if (! hasLoaded)
  194753. {
  194754. ScopedXLock xlock;
  194755. hasLoaded = true;
  194756. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  194757. if (h != 0)
  194758. {
  194759. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  194760. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  194761. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  194762. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  194763. }
  194764. if (xRenderQueryVersion != 0
  194765. && xRenderFindStandardFormat != 0
  194766. && xRenderFindFormat != 0
  194767. && xRenderFindVisualFormat != 0)
  194768. {
  194769. int major, minor;
  194770. if (xRenderQueryVersion (display, &major, &minor))
  194771. return true;
  194772. }
  194773. xRenderQueryVersion = 0;
  194774. }
  194775. return xRenderQueryVersion != 0;
  194776. }
  194777. static XRenderPictFormat* findPictureFormat()
  194778. {
  194779. ScopedXLock xlock;
  194780. XRenderPictFormat* pictFormat = 0;
  194781. if (isAvailable())
  194782. {
  194783. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  194784. if (pictFormat == 0)
  194785. {
  194786. XRenderPictFormat desiredFormat;
  194787. desiredFormat.type = PictTypeDirect;
  194788. desiredFormat.depth = 32;
  194789. desiredFormat.direct.alphaMask = 0xff;
  194790. desiredFormat.direct.redMask = 0xff;
  194791. desiredFormat.direct.greenMask = 0xff;
  194792. desiredFormat.direct.blueMask = 0xff;
  194793. desiredFormat.direct.alpha = 24;
  194794. desiredFormat.direct.red = 16;
  194795. desiredFormat.direct.green = 8;
  194796. desiredFormat.direct.blue = 0;
  194797. pictFormat = xRenderFindFormat (display,
  194798. PictFormatType | PictFormatDepth
  194799. | PictFormatRedMask | PictFormatRed
  194800. | PictFormatGreenMask | PictFormatGreen
  194801. | PictFormatBlueMask | PictFormatBlue
  194802. | PictFormatAlphaMask | PictFormatAlpha,
  194803. &desiredFormat,
  194804. 0);
  194805. }
  194806. }
  194807. return pictFormat;
  194808. }
  194809. }
  194810. #endif
  194811. namespace Visuals
  194812. {
  194813. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  194814. {
  194815. ScopedXLock xlock;
  194816. Visual* visual = 0;
  194817. int numVisuals = 0;
  194818. long desiredMask = VisualNoMask;
  194819. XVisualInfo desiredVisual;
  194820. desiredVisual.screen = DefaultScreen (display);
  194821. desiredVisual.depth = desiredDepth;
  194822. desiredMask = VisualScreenMask | VisualDepthMask;
  194823. if (desiredDepth == 32)
  194824. {
  194825. desiredVisual.c_class = TrueColor;
  194826. desiredVisual.red_mask = 0x00FF0000;
  194827. desiredVisual.green_mask = 0x0000FF00;
  194828. desiredVisual.blue_mask = 0x000000FF;
  194829. desiredVisual.bits_per_rgb = 8;
  194830. desiredMask |= VisualClassMask;
  194831. desiredMask |= VisualRedMaskMask;
  194832. desiredMask |= VisualGreenMaskMask;
  194833. desiredMask |= VisualBlueMaskMask;
  194834. desiredMask |= VisualBitsPerRGBMask;
  194835. }
  194836. XVisualInfo* xvinfos = XGetVisualInfo (display,
  194837. desiredMask,
  194838. &desiredVisual,
  194839. &numVisuals);
  194840. if (xvinfos != 0)
  194841. {
  194842. for (int i = 0; i < numVisuals; i++)
  194843. {
  194844. if (xvinfos[i].depth == desiredDepth)
  194845. {
  194846. visual = xvinfos[i].visual;
  194847. break;
  194848. }
  194849. }
  194850. XFree (xvinfos);
  194851. }
  194852. return visual;
  194853. }
  194854. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  194855. {
  194856. Visual* visual = 0;
  194857. if (desiredDepth == 32)
  194858. {
  194859. #if JUCE_USE_XSHM
  194860. if (XSHMHelpers::isShmAvailable())
  194861. {
  194862. #if JUCE_USE_XRENDER
  194863. if (XRender::isAvailable())
  194864. {
  194865. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  194866. if (pictFormat != 0)
  194867. {
  194868. int numVisuals = 0;
  194869. XVisualInfo desiredVisual;
  194870. desiredVisual.screen = DefaultScreen (display);
  194871. desiredVisual.depth = 32;
  194872. desiredVisual.bits_per_rgb = 8;
  194873. XVisualInfo* xvinfos = XGetVisualInfo (display,
  194874. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  194875. &desiredVisual, &numVisuals);
  194876. if (xvinfos != 0)
  194877. {
  194878. for (int i = 0; i < numVisuals; ++i)
  194879. {
  194880. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  194881. if (pictVisualFormat != 0
  194882. && pictVisualFormat->type == PictTypeDirect
  194883. && pictVisualFormat->direct.alphaMask)
  194884. {
  194885. visual = xvinfos[i].visual;
  194886. matchedDepth = 32;
  194887. break;
  194888. }
  194889. }
  194890. XFree (xvinfos);
  194891. }
  194892. }
  194893. }
  194894. #endif
  194895. if (visual == 0)
  194896. {
  194897. visual = findVisualWithDepth (32);
  194898. if (visual != 0)
  194899. matchedDepth = 32;
  194900. }
  194901. }
  194902. #endif
  194903. }
  194904. if (visual == 0 && desiredDepth >= 24)
  194905. {
  194906. visual = findVisualWithDepth (24);
  194907. if (visual != 0)
  194908. matchedDepth = 24;
  194909. }
  194910. if (visual == 0 && desiredDepth >= 16)
  194911. {
  194912. visual = findVisualWithDepth (16);
  194913. if (visual != 0)
  194914. matchedDepth = 16;
  194915. }
  194916. return visual;
  194917. }
  194918. }
  194919. class XBitmapImage : public Image
  194920. {
  194921. public:
  194922. XBitmapImage (const PixelFormat format_, const int w, const int h,
  194923. const bool clearImage, const int imageDepth_, Visual* visual)
  194924. : Image (format_, w, h),
  194925. imageDepth (imageDepth_),
  194926. gc (None)
  194927. {
  194928. jassert (format_ == RGB || format_ == ARGB);
  194929. pixelStride = (format_ == RGB) ? 3 : 4;
  194930. lineStride = ((w * pixelStride + 3) & ~3);
  194931. ScopedXLock xlock;
  194932. #if JUCE_USE_XSHM
  194933. usingXShm = false;
  194934. if ((imageDepth > 16) && XSHMHelpers::isShmAvailable())
  194935. {
  194936. zerostruct (segmentInfo);
  194937. segmentInfo.shmid = -1;
  194938. segmentInfo.shmaddr = (char *) -1;
  194939. segmentInfo.readOnly = False;
  194940. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  194941. if (xImage != 0)
  194942. {
  194943. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  194944. xImage->bytes_per_line * xImage->height,
  194945. IPC_CREAT | 0777)) >= 0)
  194946. {
  194947. if (segmentInfo.shmid != -1)
  194948. {
  194949. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  194950. if (segmentInfo.shmaddr != (void*) -1)
  194951. {
  194952. segmentInfo.readOnly = False;
  194953. xImage->data = segmentInfo.shmaddr;
  194954. imageData = (uint8*) segmentInfo.shmaddr;
  194955. if (XShmAttach (display, &segmentInfo) != 0)
  194956. {
  194957. usingXShm = true;
  194958. }
  194959. else
  194960. {
  194961. jassertfalse
  194962. }
  194963. }
  194964. else
  194965. {
  194966. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  194967. }
  194968. }
  194969. }
  194970. }
  194971. }
  194972. if (! usingXShm)
  194973. #endif
  194974. {
  194975. imageDataAllocated.malloc (lineStride * h);
  194976. imageData = imageDataAllocated;
  194977. if (format_ == ARGB && clearImage)
  194978. zeromem (imageData, h * lineStride);
  194979. xImage = (XImage*) juce_calloc (sizeof (XImage));
  194980. xImage->width = w;
  194981. xImage->height = h;
  194982. xImage->xoffset = 0;
  194983. xImage->format = ZPixmap;
  194984. xImage->data = (char*) imageData;
  194985. xImage->byte_order = ImageByteOrder (display);
  194986. xImage->bitmap_unit = BitmapUnit (display);
  194987. xImage->bitmap_bit_order = BitmapBitOrder (display);
  194988. xImage->bitmap_pad = 32;
  194989. xImage->depth = pixelStride * 8;
  194990. xImage->bytes_per_line = lineStride;
  194991. xImage->bits_per_pixel = pixelStride * 8;
  194992. xImage->red_mask = 0x00FF0000;
  194993. xImage->green_mask = 0x0000FF00;
  194994. xImage->blue_mask = 0x000000FF;
  194995. if (imageDepth == 16)
  194996. {
  194997. const int pixelStride = 2;
  194998. const int lineStride = ((w * pixelStride + 3) & ~3);
  194999. imageData16Bit.malloc (lineStride * h);
  195000. xImage->data = imageData16Bit;
  195001. xImage->bitmap_pad = 16;
  195002. xImage->depth = pixelStride * 8;
  195003. xImage->bytes_per_line = lineStride;
  195004. xImage->bits_per_pixel = pixelStride * 8;
  195005. xImage->red_mask = visual->red_mask;
  195006. xImage->green_mask = visual->green_mask;
  195007. xImage->blue_mask = visual->blue_mask;
  195008. }
  195009. if (! XInitImage (xImage))
  195010. {
  195011. jassertfalse
  195012. }
  195013. }
  195014. }
  195015. ~XBitmapImage()
  195016. {
  195017. ScopedXLock xlock;
  195018. if (gc != None)
  195019. XFreeGC (display, gc);
  195020. #if JUCE_USE_XSHM
  195021. if (usingXShm)
  195022. {
  195023. XShmDetach (display, &segmentInfo);
  195024. XFlush (display);
  195025. XDestroyImage (xImage);
  195026. shmdt (segmentInfo.shmaddr);
  195027. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195028. }
  195029. else
  195030. #endif
  195031. {
  195032. xImage->data = 0;
  195033. XDestroyImage (xImage);
  195034. }
  195035. }
  195036. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195037. {
  195038. ScopedXLock xlock;
  195039. if (gc == None)
  195040. {
  195041. XGCValues gcvalues;
  195042. gcvalues.foreground = None;
  195043. gcvalues.background = None;
  195044. gcvalues.function = GXcopy;
  195045. gcvalues.plane_mask = AllPlanes;
  195046. gcvalues.clip_mask = None;
  195047. gcvalues.graphics_exposures = False;
  195048. gc = XCreateGC (display, window,
  195049. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195050. &gcvalues);
  195051. }
  195052. if (imageDepth == 16)
  195053. {
  195054. const uint32 rMask = xImage->red_mask;
  195055. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195056. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195057. const uint32 gMask = xImage->green_mask;
  195058. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195059. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195060. const uint32 bMask = xImage->blue_mask;
  195061. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195062. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195063. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195064. for (int y = sy; y < sy + dh; ++y)
  195065. {
  195066. const uint8* p = srcData.getPixelPointer (sx, y);
  195067. for (int x = sx; x < sx + dw; ++x)
  195068. {
  195069. const PixelRGB* const pixel = (const PixelRGB*) p;
  195070. p += srcData.pixelStride;
  195071. XPutPixel (xImage, x, y,
  195072. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195073. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195074. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195075. }
  195076. }
  195077. }
  195078. // blit results to screen.
  195079. #if JUCE_USE_XSHM
  195080. if (usingXShm)
  195081. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195082. else
  195083. #endif
  195084. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195085. }
  195086. juce_UseDebuggingNewOperator
  195087. private:
  195088. XImage* xImage;
  195089. const int imageDepth;
  195090. HeapBlock <char> imageData16Bit;
  195091. GC gc;
  195092. #if JUCE_USE_XSHM
  195093. XShmSegmentInfo segmentInfo;
  195094. bool usingXShm;
  195095. #endif
  195096. static int getShiftNeeded (const uint32 mask) throw()
  195097. {
  195098. for (int i = 32; --i >= 0;)
  195099. if (((mask >> i) & 1) != 0)
  195100. return i - 7;
  195101. jassertfalse
  195102. return 0;
  195103. }
  195104. };
  195105. class LinuxComponentPeer : public ComponentPeer
  195106. {
  195107. public:
  195108. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195109. : ComponentPeer (component, windowStyleFlags),
  195110. windowH (0),
  195111. parentWindow (0),
  195112. wx (0),
  195113. wy (0),
  195114. ww (0),
  195115. wh (0),
  195116. fullScreen (false),
  195117. mapped (false),
  195118. visual (0),
  195119. depth (0)
  195120. {
  195121. // it's dangerous to create a window on a thread other than the message thread..
  195122. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195123. repainter = new LinuxRepaintManager (this);
  195124. createWindow();
  195125. setTitle (component->getName());
  195126. }
  195127. ~LinuxComponentPeer()
  195128. {
  195129. // it's dangerous to delete a window on a thread other than the message thread..
  195130. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195131. deleteIconPixmaps();
  195132. destroyWindow();
  195133. windowH = 0;
  195134. }
  195135. void* getNativeHandle() const
  195136. {
  195137. return (void*) windowH;
  195138. }
  195139. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195140. {
  195141. XPointer peer = 0;
  195142. ScopedXLock xlock;
  195143. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195144. {
  195145. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195146. peer = 0;
  195147. }
  195148. return (LinuxComponentPeer*) peer;
  195149. }
  195150. void setVisible (bool shouldBeVisible)
  195151. {
  195152. ScopedXLock xlock;
  195153. if (shouldBeVisible)
  195154. XMapWindow (display, windowH);
  195155. else
  195156. XUnmapWindow (display, windowH);
  195157. }
  195158. void setTitle (const String& title)
  195159. {
  195160. setWindowTitle (windowH, title);
  195161. }
  195162. void setPosition (int x, int y)
  195163. {
  195164. setBounds (x, y, ww, wh, false);
  195165. }
  195166. void setSize (int w, int h)
  195167. {
  195168. setBounds (wx, wy, w, h, false);
  195169. }
  195170. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  195171. {
  195172. fullScreen = isNowFullScreen;
  195173. if (windowH != 0)
  195174. {
  195175. Component::SafePointer<Component> deletionChecker (component);
  195176. wx = x;
  195177. wy = y;
  195178. ww = jmax (1, w);
  195179. wh = jmax (1, h);
  195180. ScopedXLock xlock;
  195181. // Make sure the Window manager does what we want
  195182. XSizeHints* hints = XAllocSizeHints();
  195183. hints->flags = USSize | USPosition;
  195184. hints->width = ww;
  195185. hints->height = wh;
  195186. hints->x = wx;
  195187. hints->y = wy;
  195188. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195189. {
  195190. hints->min_width = hints->max_width = hints->width;
  195191. hints->min_height = hints->max_height = hints->height;
  195192. hints->flags |= PMinSize | PMaxSize;
  195193. }
  195194. XSetWMNormalHints (display, windowH, hints);
  195195. XFree (hints);
  195196. XMoveResizeWindow (display, windowH,
  195197. wx - windowBorder.getLeft(),
  195198. wy - windowBorder.getTop(), ww, wh);
  195199. if (deletionChecker != 0)
  195200. {
  195201. updateBorderSize();
  195202. handleMovedOrResized();
  195203. }
  195204. }
  195205. }
  195206. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195207. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195208. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195209. {
  195210. return relativePosition + getScreenPosition();
  195211. }
  195212. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195213. {
  195214. return screenPosition - getScreenPosition();
  195215. }
  195216. void setMinimised (bool shouldBeMinimised)
  195217. {
  195218. if (shouldBeMinimised)
  195219. {
  195220. Window root = RootWindow (display, DefaultScreen (display));
  195221. XClientMessageEvent clientMsg;
  195222. clientMsg.display = display;
  195223. clientMsg.window = windowH;
  195224. clientMsg.type = ClientMessage;
  195225. clientMsg.format = 32;
  195226. clientMsg.message_type = Atoms::ChangeState;
  195227. clientMsg.data.l[0] = IconicState;
  195228. ScopedXLock xlock;
  195229. XSendEvent (display, root, false,
  195230. SubstructureRedirectMask | SubstructureNotifyMask,
  195231. (XEvent*) &clientMsg);
  195232. }
  195233. else
  195234. {
  195235. setVisible (true);
  195236. }
  195237. }
  195238. bool isMinimised() const
  195239. {
  195240. bool minimised = false;
  195241. unsigned char* stateProp;
  195242. unsigned long nitems, bytesLeft;
  195243. Atom actualType;
  195244. int actualFormat;
  195245. ScopedXLock xlock;
  195246. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195247. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195248. &stateProp) == Success
  195249. && actualType == Atoms::State
  195250. && actualFormat == 32
  195251. && nitems > 0)
  195252. {
  195253. if (((unsigned long*) stateProp)[0] == IconicState)
  195254. minimised = true;
  195255. XFree (stateProp);
  195256. }
  195257. return minimised;
  195258. }
  195259. void setFullScreen (const bool shouldBeFullScreen)
  195260. {
  195261. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195262. setMinimised (false);
  195263. if (fullScreen != shouldBeFullScreen)
  195264. {
  195265. if (shouldBeFullScreen)
  195266. r = Desktop::getInstance().getMainMonitorArea();
  195267. if (! r.isEmpty())
  195268. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195269. getComponent()->repaint();
  195270. }
  195271. }
  195272. bool isFullScreen() const
  195273. {
  195274. return fullScreen;
  195275. }
  195276. bool isChildWindowOf (Window possibleParent) const
  195277. {
  195278. Window* windowList = 0;
  195279. uint32 windowListSize = 0;
  195280. Window parent, root;
  195281. ScopedXLock xlock;
  195282. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195283. {
  195284. if (windowList != 0)
  195285. XFree (windowList);
  195286. return parent == possibleParent;
  195287. }
  195288. return false;
  195289. }
  195290. bool isFrontWindow() const
  195291. {
  195292. Window* windowList = 0;
  195293. uint32 windowListSize = 0;
  195294. bool result = false;
  195295. ScopedXLock xlock;
  195296. Window parent, root = RootWindow (display, DefaultScreen (display));
  195297. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195298. {
  195299. for (int i = windowListSize; --i >= 0;)
  195300. {
  195301. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195302. if (peer != 0)
  195303. {
  195304. result = (peer == this);
  195305. break;
  195306. }
  195307. }
  195308. }
  195309. if (windowList != 0)
  195310. XFree (windowList);
  195311. return result;
  195312. }
  195313. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195314. {
  195315. int x = position.getX();
  195316. int y = position.getY();
  195317. if (((unsigned int) x) >= (unsigned int) ww
  195318. || ((unsigned int) y) >= (unsigned int) wh)
  195319. return false;
  195320. bool inFront = false;
  195321. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195322. {
  195323. Component* const c = Desktop::getInstance().getComponent (i);
  195324. if (inFront)
  195325. {
  195326. if (c->contains (x + wx - c->getScreenX(),
  195327. y + wy - c->getScreenY()))
  195328. {
  195329. return false;
  195330. }
  195331. }
  195332. else if (c == getComponent())
  195333. {
  195334. inFront = true;
  195335. }
  195336. }
  195337. if (trueIfInAChildWindow)
  195338. return true;
  195339. ::Window root, child;
  195340. unsigned int bw, depth;
  195341. int wx, wy, w, h;
  195342. ScopedXLock xlock;
  195343. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195344. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195345. &bw, &depth))
  195346. {
  195347. return false;
  195348. }
  195349. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195350. return false;
  195351. return child == None;
  195352. }
  195353. const BorderSize getFrameSize() const
  195354. {
  195355. return BorderSize();
  195356. }
  195357. bool setAlwaysOnTop (bool alwaysOnTop)
  195358. {
  195359. if (windowH != 0)
  195360. {
  195361. const bool wasVisible = component->isVisible();
  195362. if (wasVisible)
  195363. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195364. {
  195365. ScopedXLock xlock;
  195366. XSetWindowAttributes swa;
  195367. swa.override_redirect = alwaysOnTop ? True : False;
  195368. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195369. }
  195370. if (wasVisible)
  195371. setVisible (true);
  195372. }
  195373. return true;
  195374. }
  195375. void toFront (bool makeActive)
  195376. {
  195377. if (makeActive)
  195378. {
  195379. setVisible (true);
  195380. grabFocus();
  195381. }
  195382. XEvent ev;
  195383. ev.xclient.type = ClientMessage;
  195384. ev.xclient.serial = 0;
  195385. ev.xclient.send_event = True;
  195386. ev.xclient.message_type = Atoms::ActiveWin;
  195387. ev.xclient.window = windowH;
  195388. ev.xclient.format = 32;
  195389. ev.xclient.data.l[0] = 2;
  195390. ev.xclient.data.l[1] = CurrentTime;
  195391. ev.xclient.data.l[2] = 0;
  195392. ev.xclient.data.l[3] = 0;
  195393. ev.xclient.data.l[4] = 0;
  195394. {
  195395. ScopedXLock xlock;
  195396. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195397. False,
  195398. SubstructureRedirectMask | SubstructureNotifyMask,
  195399. &ev);
  195400. XWindowAttributes attr;
  195401. XGetWindowAttributes (display, windowH, &attr);
  195402. if (attr.override_redirect)
  195403. XRaiseWindow (display, windowH);
  195404. XSync (display, False);
  195405. }
  195406. handleBroughtToFront();
  195407. }
  195408. void toBehind (ComponentPeer* other)
  195409. {
  195410. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  195411. jassert (otherPeer != 0); // wrong type of window?
  195412. if (otherPeer != 0)
  195413. {
  195414. setMinimised (false);
  195415. Window newStack[] = { otherPeer->windowH, windowH };
  195416. ScopedXLock xlock;
  195417. XRestackWindows (display, newStack, 2);
  195418. }
  195419. }
  195420. bool isFocused() const
  195421. {
  195422. int revert;
  195423. Window focusedWindow = 0;
  195424. ScopedXLock xlock;
  195425. XGetInputFocus (display, &focusedWindow, &revert);
  195426. return focusedWindow == windowH;
  195427. }
  195428. void grabFocus()
  195429. {
  195430. XWindowAttributes atts;
  195431. ScopedXLock xlock;
  195432. if (windowH != 0
  195433. && XGetWindowAttributes (display, windowH, &atts)
  195434. && atts.map_state == IsViewable
  195435. && ! isFocused())
  195436. {
  195437. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  195438. isActiveApplication = true;
  195439. }
  195440. }
  195441. void textInputRequired (const Point<int>&)
  195442. {
  195443. }
  195444. void repaint (int x, int y, int w, int h)
  195445. {
  195446. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  195447. 0, 0,
  195448. getComponent()->getWidth(),
  195449. getComponent()->getHeight()))
  195450. {
  195451. repainter->repaint (x, y, w, h);
  195452. }
  195453. }
  195454. void performAnyPendingRepaintsNow()
  195455. {
  195456. repainter->performAnyPendingRepaintsNow();
  195457. }
  195458. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195459. {
  195460. ScopedXLock xlock;
  195461. const int width = image.getWidth();
  195462. const int height = image.getHeight();
  195463. HeapBlock <char> colour (width * height);
  195464. int index = 0;
  195465. for (int y = 0; y < height; ++y)
  195466. for (int x = 0; x < width; ++x)
  195467. colour[index++] = static_cast<char> (image.getPixelAt (x, y).getARGB());
  195468. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195469. 0, colour.getData(),
  195470. width, height, 32, 0);
  195471. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195472. width, height, 24);
  195473. GC gc = XCreateGC (display, pixmap, 0, 0);
  195474. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195475. XFreeGC (display, gc);
  195476. return pixmap;
  195477. }
  195478. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195479. {
  195480. ScopedXLock xlock;
  195481. const int width = image.getWidth();
  195482. const int height = image.getHeight();
  195483. const int stride = (width + 7) >> 3;
  195484. HeapBlock <char> mask;
  195485. mask.calloc (stride * height);
  195486. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195487. for (int y = 0; y < height; ++y)
  195488. {
  195489. for (int x = 0; x < width; ++x)
  195490. {
  195491. const char bit = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195492. const int offset = y * stride + (x >> 3);
  195493. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195494. mask[offset] |= bit;
  195495. }
  195496. }
  195497. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195498. mask.getData(), width, height, 1, 0, 1);
  195499. }
  195500. void setIcon (const Image& newIcon)
  195501. {
  195502. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  195503. HeapBlock <unsigned long> data (dataSize);
  195504. int index = 0;
  195505. data[index++] = newIcon.getWidth();
  195506. data[index++] = newIcon.getHeight();
  195507. for (int y = 0; y < newIcon.getHeight(); ++y)
  195508. for (int x = 0; x < newIcon.getWidth(); ++x)
  195509. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  195510. ScopedXLock xlock;
  195511. XChangeProperty (display, windowH,
  195512. XInternAtom (display, "_NET_WM_ICON", False),
  195513. XA_CARDINAL, 32, PropModeReplace,
  195514. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  195515. deleteIconPixmaps();
  195516. XWMHints* wmHints = XGetWMHints (display, windowH);
  195517. if (wmHints == 0)
  195518. wmHints = XAllocWMHints();
  195519. wmHints->flags |= IconPixmapHint | IconMaskHint;
  195520. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  195521. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  195522. XSetWMHints (display, windowH, wmHints);
  195523. XFree (wmHints);
  195524. XSync (display, False);
  195525. }
  195526. void deleteIconPixmaps()
  195527. {
  195528. ScopedXLock xlock;
  195529. XWMHints* wmHints = XGetWMHints (display, windowH);
  195530. if (wmHints != 0)
  195531. {
  195532. if ((wmHints->flags & IconPixmapHint) != 0)
  195533. {
  195534. wmHints->flags &= ~IconPixmapHint;
  195535. XFreePixmap (display, wmHints->icon_pixmap);
  195536. }
  195537. if ((wmHints->flags & IconMaskHint) != 0)
  195538. {
  195539. wmHints->flags &= ~IconMaskHint;
  195540. XFreePixmap (display, wmHints->icon_mask);
  195541. }
  195542. XSetWMHints (display, windowH, wmHints);
  195543. XFree (wmHints);
  195544. }
  195545. }
  195546. void handleWindowMessage (XEvent* event)
  195547. {
  195548. switch (event->xany.type)
  195549. {
  195550. case 2: // 'KeyPress'
  195551. {
  195552. ScopedXLock xlock;
  195553. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  195554. updateKeyStates (keyEvent->keycode, true);
  195555. char utf8 [64];
  195556. zeromem (utf8, sizeof (utf8));
  195557. KeySym sym;
  195558. {
  195559. const char* oldLocale = ::setlocale (LC_ALL, 0);
  195560. ::setlocale (LC_ALL, "");
  195561. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  195562. ::setlocale (LC_ALL, oldLocale);
  195563. }
  195564. const juce_wchar unicodeChar = String::fromUTF8 (utf8, sizeof (utf8) - 1) [0];
  195565. int keyCode = (int) unicodeChar;
  195566. if (keyCode < 0x20)
  195567. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  195568. const ModifierKeys oldMods (currentModifiers);
  195569. bool keyPressed = false;
  195570. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  195571. if ((sym & 0xff00) == 0xff00)
  195572. {
  195573. // Translate keypad
  195574. if (sym == XK_KP_Divide)
  195575. keyCode = XK_slash;
  195576. else if (sym == XK_KP_Multiply)
  195577. keyCode = XK_asterisk;
  195578. else if (sym == XK_KP_Subtract)
  195579. keyCode = XK_hyphen;
  195580. else if (sym == XK_KP_Add)
  195581. keyCode = XK_plus;
  195582. else if (sym == XK_KP_Enter)
  195583. keyCode = XK_Return;
  195584. else if (sym == XK_KP_Decimal)
  195585. keyCode = Keys::numLock ? XK_period : XK_Delete;
  195586. else if (sym == XK_KP_0)
  195587. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  195588. else if (sym == XK_KP_1)
  195589. keyCode = Keys::numLock ? XK_1 : XK_End;
  195590. else if (sym == XK_KP_2)
  195591. keyCode = Keys::numLock ? XK_2 : XK_Down;
  195592. else if (sym == XK_KP_3)
  195593. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  195594. else if (sym == XK_KP_4)
  195595. keyCode = Keys::numLock ? XK_4 : XK_Left;
  195596. else if (sym == XK_KP_5)
  195597. keyCode = XK_5;
  195598. else if (sym == XK_KP_6)
  195599. keyCode = Keys::numLock ? XK_6 : XK_Right;
  195600. else if (sym == XK_KP_7)
  195601. keyCode = Keys::numLock ? XK_7 : XK_Home;
  195602. else if (sym == XK_KP_8)
  195603. keyCode = Keys::numLock ? XK_8 : XK_Up;
  195604. else if (sym == XK_KP_9)
  195605. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  195606. switch (sym)
  195607. {
  195608. case XK_Left:
  195609. case XK_Right:
  195610. case XK_Up:
  195611. case XK_Down:
  195612. case XK_Page_Up:
  195613. case XK_Page_Down:
  195614. case XK_End:
  195615. case XK_Home:
  195616. case XK_Delete:
  195617. case XK_Insert:
  195618. keyPressed = true;
  195619. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  195620. break;
  195621. case XK_Tab:
  195622. case XK_Return:
  195623. case XK_Escape:
  195624. case XK_BackSpace:
  195625. keyPressed = true;
  195626. keyCode &= 0xff;
  195627. break;
  195628. default:
  195629. {
  195630. if (sym >= XK_F1 && sym <= XK_F16)
  195631. {
  195632. keyPressed = true;
  195633. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  195634. }
  195635. break;
  195636. }
  195637. }
  195638. }
  195639. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  195640. keyPressed = true;
  195641. if (oldMods != currentModifiers)
  195642. handleModifierKeysChange();
  195643. if (keyDownChange)
  195644. handleKeyUpOrDown (true);
  195645. if (keyPressed)
  195646. handleKeyPress (keyCode, unicodeChar);
  195647. break;
  195648. }
  195649. case KeyRelease:
  195650. {
  195651. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  195652. updateKeyStates (keyEvent->keycode, false);
  195653. ScopedXLock xlock;
  195654. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  195655. const ModifierKeys oldMods (currentModifiers);
  195656. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  195657. if (oldMods != currentModifiers)
  195658. handleModifierKeysChange();
  195659. if (keyDownChange)
  195660. handleKeyUpOrDown (false);
  195661. break;
  195662. }
  195663. case ButtonPress:
  195664. {
  195665. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  195666. updateKeyModifiers (buttonPressEvent->state);
  195667. bool buttonMsg = false;
  195668. const int map = pointerMap [buttonPressEvent->button - Button1];
  195669. if (map == Keys::WheelUp || map == Keys::WheelDown)
  195670. {
  195671. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  195672. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  195673. }
  195674. if (map == Keys::LeftButton)
  195675. {
  195676. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  195677. buttonMsg = true;
  195678. }
  195679. else if (map == Keys::RightButton)
  195680. {
  195681. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  195682. buttonMsg = true;
  195683. }
  195684. else if (map == Keys::MiddleButton)
  195685. {
  195686. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  195687. buttonMsg = true;
  195688. }
  195689. if (buttonMsg)
  195690. {
  195691. toFront (true);
  195692. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  195693. getEventTime (buttonPressEvent->time));
  195694. }
  195695. clearLastMousePos();
  195696. break;
  195697. }
  195698. case ButtonRelease:
  195699. {
  195700. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  195701. updateKeyModifiers (buttonRelEvent->state);
  195702. const int map = pointerMap [buttonRelEvent->button - Button1];
  195703. if (map == Keys::LeftButton)
  195704. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  195705. else if (map == Keys::RightButton)
  195706. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  195707. else if (map == Keys::MiddleButton)
  195708. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  195709. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  195710. getEventTime (buttonRelEvent->time));
  195711. clearLastMousePos();
  195712. break;
  195713. }
  195714. case MotionNotify:
  195715. {
  195716. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  195717. updateKeyModifiers (movedEvent->state);
  195718. const Point<int> mousePos (Desktop::getMousePosition());
  195719. if (lastMousePos != mousePos)
  195720. {
  195721. lastMousePos = mousePos;
  195722. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  195723. {
  195724. Window wRoot = 0, wParent = 0;
  195725. {
  195726. ScopedXLock xlock;
  195727. unsigned int numChildren;
  195728. Window* wChild = 0;
  195729. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  195730. }
  195731. if (wParent != 0
  195732. && wParent != windowH
  195733. && wParent != wRoot)
  195734. {
  195735. parentWindow = wParent;
  195736. updateBounds();
  195737. }
  195738. else
  195739. {
  195740. parentWindow = 0;
  195741. }
  195742. }
  195743. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  195744. }
  195745. break;
  195746. }
  195747. case EnterNotify:
  195748. {
  195749. clearLastMousePos();
  195750. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  195751. if (! currentModifiers.isAnyMouseButtonDown())
  195752. {
  195753. updateKeyModifiers (enterEvent->state);
  195754. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  195755. }
  195756. break;
  195757. }
  195758. case LeaveNotify:
  195759. {
  195760. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  195761. // Suppress the normal leave if we've got a pointer grab, or if
  195762. // it's a bogus one caused by clicking a mouse button when running
  195763. // in a Window manager
  195764. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  195765. || leaveEvent->mode == NotifyUngrab)
  195766. {
  195767. updateKeyModifiers (leaveEvent->state);
  195768. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  195769. }
  195770. break;
  195771. }
  195772. case FocusIn:
  195773. {
  195774. isActiveApplication = true;
  195775. if (isFocused())
  195776. handleFocusGain();
  195777. break;
  195778. }
  195779. case FocusOut:
  195780. {
  195781. isActiveApplication = false;
  195782. if (! isFocused())
  195783. handleFocusLoss();
  195784. break;
  195785. }
  195786. case Expose:
  195787. {
  195788. // Batch together all pending expose events
  195789. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  195790. XEvent nextEvent;
  195791. ScopedXLock xlock;
  195792. if (exposeEvent->window != windowH)
  195793. {
  195794. Window child;
  195795. XTranslateCoordinates (display, exposeEvent->window, windowH,
  195796. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  195797. &child);
  195798. }
  195799. repaint (exposeEvent->x, exposeEvent->y,
  195800. exposeEvent->width, exposeEvent->height);
  195801. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  195802. {
  195803. XPeekEvent (display, (XEvent*) &nextEvent);
  195804. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  195805. break;
  195806. XNextEvent (display, (XEvent*) &nextEvent);
  195807. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  195808. repaint (nextExposeEvent->x, nextExposeEvent->y,
  195809. nextExposeEvent->width, nextExposeEvent->height);
  195810. }
  195811. break;
  195812. }
  195813. case CirculateNotify:
  195814. case CreateNotify:
  195815. case DestroyNotify:
  195816. // Think we can ignore these
  195817. break;
  195818. case ConfigureNotify:
  195819. {
  195820. updateBounds();
  195821. updateBorderSize();
  195822. handleMovedOrResized();
  195823. // if the native title bar is dragged, need to tell any active menus, etc.
  195824. if ((styleFlags & windowHasTitleBar) != 0
  195825. && component->isCurrentlyBlockedByAnotherModalComponent())
  195826. {
  195827. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  195828. if (currentModalComp != 0)
  195829. currentModalComp->inputAttemptWhenModal();
  195830. }
  195831. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  195832. if (confEvent->window == windowH
  195833. && confEvent->above != 0
  195834. && isFrontWindow())
  195835. {
  195836. handleBroughtToFront();
  195837. }
  195838. break;
  195839. }
  195840. case ReparentNotify:
  195841. {
  195842. parentWindow = 0;
  195843. Window wRoot = 0;
  195844. Window* wChild = 0;
  195845. unsigned int numChildren;
  195846. {
  195847. ScopedXLock xlock;
  195848. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  195849. }
  195850. if (parentWindow == windowH || parentWindow == wRoot)
  195851. parentWindow = 0;
  195852. updateBounds();
  195853. updateBorderSize();
  195854. handleMovedOrResized();
  195855. break;
  195856. }
  195857. case GravityNotify:
  195858. {
  195859. updateBounds();
  195860. updateBorderSize();
  195861. handleMovedOrResized();
  195862. break;
  195863. }
  195864. case MapNotify:
  195865. mapped = true;
  195866. handleBroughtToFront();
  195867. break;
  195868. case UnmapNotify:
  195869. mapped = false;
  195870. break;
  195871. case MappingNotify:
  195872. {
  195873. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  195874. if (mappingEvent->request != MappingPointer)
  195875. {
  195876. // Deal with modifier/keyboard mapping
  195877. ScopedXLock xlock;
  195878. XRefreshKeyboardMapping (mappingEvent);
  195879. updateModifierMappings();
  195880. }
  195881. break;
  195882. }
  195883. case ClientMessage:
  195884. {
  195885. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  195886. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  195887. {
  195888. const Atom atom = (Atom) clientMsg->data.l[0];
  195889. if (atom == Atoms::ProtocolList [Atoms::PING])
  195890. {
  195891. Window root = RootWindow (display, DefaultScreen (display));
  195892. event->xclient.window = root;
  195893. XSendEvent (display, root, False, NoEventMask, event);
  195894. XFlush (display);
  195895. }
  195896. else if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  195897. {
  195898. XWindowAttributes atts;
  195899. ScopedXLock xlock;
  195900. if (clientMsg->window != 0
  195901. && XGetWindowAttributes (display, clientMsg->window, &atts))
  195902. {
  195903. if (atts.map_state == IsViewable)
  195904. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  195905. }
  195906. }
  195907. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  195908. {
  195909. handleUserClosingWindow();
  195910. }
  195911. }
  195912. else if (clientMsg->message_type == Atoms::XdndEnter)
  195913. {
  195914. handleDragAndDropEnter (clientMsg);
  195915. }
  195916. else if (clientMsg->message_type == Atoms::XdndLeave)
  195917. {
  195918. resetDragAndDrop();
  195919. }
  195920. else if (clientMsg->message_type == Atoms::XdndPosition)
  195921. {
  195922. handleDragAndDropPosition (clientMsg);
  195923. }
  195924. else if (clientMsg->message_type == Atoms::XdndDrop)
  195925. {
  195926. handleDragAndDropDrop (clientMsg);
  195927. }
  195928. else if (clientMsg->message_type == Atoms::XdndStatus)
  195929. {
  195930. handleDragAndDropStatus (clientMsg);
  195931. }
  195932. else if (clientMsg->message_type == Atoms::XdndFinished)
  195933. {
  195934. resetDragAndDrop();
  195935. }
  195936. break;
  195937. }
  195938. case SelectionNotify:
  195939. handleDragAndDropSelection (event);
  195940. break;
  195941. case SelectionClear:
  195942. case SelectionRequest:
  195943. break;
  195944. default:
  195945. #if JUCE_USE_XSHM
  195946. {
  195947. ScopedXLock xlock;
  195948. if (event->xany.type == XShmGetEventBase (display))
  195949. repainter->notifyPaintCompleted();
  195950. }
  195951. #endif
  195952. break;
  195953. }
  195954. }
  195955. void showMouseCursor (Cursor cursor) throw()
  195956. {
  195957. ScopedXLock xlock;
  195958. XDefineCursor (display, windowH, cursor);
  195959. }
  195960. void setTaskBarIcon (const Image& image)
  195961. {
  195962. ScopedXLock xlock;
  195963. taskbarImage = image.createCopy();
  195964. Screen* const screen = XDefaultScreenOfDisplay (display);
  195965. const int screenNumber = XScreenNumberOfScreen (screen);
  195966. String screenAtom ("_NET_SYSTEM_TRAY_S");
  195967. screenAtom << screenNumber;
  195968. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  195969. XGrabServer (display);
  195970. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  195971. if (managerWin != None)
  195972. XSelectInput (display, managerWin, StructureNotifyMask);
  195973. XUngrabServer (display);
  195974. XFlush (display);
  195975. if (managerWin != None)
  195976. {
  195977. XEvent ev;
  195978. zerostruct (ev);
  195979. ev.xclient.type = ClientMessage;
  195980. ev.xclient.window = managerWin;
  195981. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  195982. ev.xclient.format = 32;
  195983. ev.xclient.data.l[0] = CurrentTime;
  195984. ev.xclient.data.l[1] = 0 /*SYSTEM_TRAY_REQUEST_DOCK*/;
  195985. ev.xclient.data.l[2] = windowH;
  195986. ev.xclient.data.l[3] = 0;
  195987. ev.xclient.data.l[4] = 0;
  195988. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  195989. XSync (display, False);
  195990. }
  195991. // For older KDE's ...
  195992. long atomData = 1;
  195993. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  195994. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  195995. // For more recent KDE's...
  195996. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  195997. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  195998. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  195999. XSizeHints* hints = XAllocSizeHints();
  196000. hints->flags = PMinSize;
  196001. hints->min_width = 22;
  196002. hints->min_height = 22;
  196003. XSetWMNormalHints (display, windowH, hints);
  196004. XFree (hints);
  196005. }
  196006. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196007. juce_UseDebuggingNewOperator
  196008. bool dontRepaint;
  196009. static ModifierKeys currentModifiers;
  196010. static bool isActiveApplication;
  196011. private:
  196012. class LinuxRepaintManager : public Timer
  196013. {
  196014. public:
  196015. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196016. : peer (peer_),
  196017. lastTimeImageUsed (0)
  196018. {
  196019. #if JUCE_USE_XSHM
  196020. shmCompletedDrawing = true;
  196021. useARGBImagesForRendering = XSHMHelpers::isShmAvailable();
  196022. if (useARGBImagesForRendering)
  196023. {
  196024. ScopedXLock xlock;
  196025. XShmSegmentInfo segmentinfo;
  196026. XImage* const testImage
  196027. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196028. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196029. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196030. XDestroyImage (testImage);
  196031. }
  196032. #endif
  196033. }
  196034. ~LinuxRepaintManager()
  196035. {
  196036. }
  196037. void timerCallback()
  196038. {
  196039. #if JUCE_USE_XSHM
  196040. if (! shmCompletedDrawing)
  196041. return;
  196042. #endif
  196043. if (! regionsNeedingRepaint.isEmpty())
  196044. {
  196045. stopTimer();
  196046. performAnyPendingRepaintsNow();
  196047. }
  196048. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196049. {
  196050. stopTimer();
  196051. image = 0;
  196052. }
  196053. }
  196054. void repaint (int x, int y, int w, int h)
  196055. {
  196056. if (! isTimerRunning())
  196057. startTimer (repaintTimerPeriod);
  196058. regionsNeedingRepaint.add (x, y, w, h);
  196059. }
  196060. void performAnyPendingRepaintsNow()
  196061. {
  196062. #if JUCE_USE_XSHM
  196063. if (! shmCompletedDrawing)
  196064. {
  196065. startTimer (repaintTimerPeriod);
  196066. return;
  196067. }
  196068. #endif
  196069. peer->clearMaskedRegion();
  196070. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196071. regionsNeedingRepaint.clear();
  196072. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196073. if (! totalArea.isEmpty())
  196074. {
  196075. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196076. || image->getHeight() < totalArea.getHeight())
  196077. {
  196078. #if JUCE_USE_XSHM
  196079. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196080. : Image::RGB,
  196081. #else
  196082. image = new XBitmapImage (Image::RGB,
  196083. #endif
  196084. (totalArea.getWidth() + 31) & ~31,
  196085. (totalArea.getHeight() + 31) & ~31,
  196086. false,
  196087. peer->depth,
  196088. peer->visual);
  196089. }
  196090. startTimer (repaintTimerPeriod);
  196091. LowLevelGraphicsSoftwareRenderer context (*image);
  196092. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196093. if (context.clipToRectangleList (originalRepaintRegion))
  196094. {
  196095. if (peer->depth == 32)
  196096. {
  196097. RectangleList::Iterator i (originalRepaintRegion);
  196098. while (i.next())
  196099. {
  196100. const Rectangle<int>& r = *i.getRectangle();
  196101. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196102. }
  196103. }
  196104. peer->handlePaint (context);
  196105. }
  196106. if (! peer->maskedRegion.isEmpty())
  196107. originalRepaintRegion.subtract (peer->maskedRegion);
  196108. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196109. {
  196110. #if JUCE_USE_XSHM
  196111. shmCompletedDrawing = false;
  196112. #endif
  196113. const Rectangle<int>& r = *i.getRectangle();
  196114. image->blitToWindow (peer->windowH,
  196115. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196116. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196117. }
  196118. }
  196119. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196120. startTimer (repaintTimerPeriod);
  196121. }
  196122. #if JUCE_USE_XSHM
  196123. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196124. #endif
  196125. private:
  196126. enum { repaintTimerPeriod = 1000 / 100 };
  196127. LinuxComponentPeer* const peer;
  196128. ScopedPointer <XBitmapImage> image;
  196129. uint32 lastTimeImageUsed;
  196130. RectangleList regionsNeedingRepaint;
  196131. #if JUCE_USE_XSHM
  196132. bool useARGBImagesForRendering, shmCompletedDrawing;
  196133. #endif
  196134. LinuxRepaintManager (const LinuxRepaintManager&);
  196135. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196136. };
  196137. ScopedPointer <LinuxRepaintManager> repainter;
  196138. friend class LinuxRepaintManager;
  196139. Window windowH, parentWindow;
  196140. int wx, wy, ww, wh;
  196141. ScopedPointer<Image> taskbarImage;
  196142. bool fullScreen, mapped;
  196143. Visual* visual;
  196144. int depth;
  196145. BorderSize windowBorder;
  196146. struct MotifWmHints
  196147. {
  196148. unsigned long flags;
  196149. unsigned long functions;
  196150. unsigned long decorations;
  196151. long input_mode;
  196152. unsigned long status;
  196153. };
  196154. static void updateKeyStates (const int keycode, const bool press) throw()
  196155. {
  196156. const int keybyte = keycode >> 3;
  196157. const int keybit = (1 << (keycode & 7));
  196158. if (press)
  196159. Keys::keyStates [keybyte] |= keybit;
  196160. else
  196161. Keys::keyStates [keybyte] &= ~keybit;
  196162. }
  196163. static void updateKeyModifiers (const int status) throw()
  196164. {
  196165. int keyMods = 0;
  196166. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196167. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196168. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196169. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196170. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196171. Keys::capsLock = ((status & LockMask) != 0);
  196172. }
  196173. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196174. {
  196175. int modifier = 0;
  196176. bool isModifier = true;
  196177. switch (sym)
  196178. {
  196179. case XK_Shift_L:
  196180. case XK_Shift_R:
  196181. modifier = ModifierKeys::shiftModifier;
  196182. break;
  196183. case XK_Control_L:
  196184. case XK_Control_R:
  196185. modifier = ModifierKeys::ctrlModifier;
  196186. break;
  196187. case XK_Alt_L:
  196188. case XK_Alt_R:
  196189. modifier = ModifierKeys::altModifier;
  196190. break;
  196191. case XK_Num_Lock:
  196192. if (press)
  196193. Keys::numLock = ! Keys::numLock;
  196194. break;
  196195. case XK_Caps_Lock:
  196196. if (press)
  196197. Keys::capsLock = ! Keys::capsLock;
  196198. break;
  196199. case XK_Scroll_Lock:
  196200. break;
  196201. default:
  196202. isModifier = false;
  196203. break;
  196204. }
  196205. if (modifier != 0)
  196206. {
  196207. if (press)
  196208. currentModifiers = currentModifiers.withFlags (modifier);
  196209. else
  196210. currentModifiers = currentModifiers.withoutFlags (modifier);
  196211. }
  196212. return isModifier;
  196213. }
  196214. // Alt and Num lock are not defined by standard X
  196215. // modifier constants: check what they're mapped to
  196216. static void updateModifierMappings() throw()
  196217. {
  196218. ScopedXLock xlock;
  196219. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196220. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196221. Keys::AltMask = 0;
  196222. Keys::NumLockMask = 0;
  196223. XModifierKeymap* mapping = XGetModifierMapping (display);
  196224. if (mapping)
  196225. {
  196226. for (int i = 0; i < 8; i++)
  196227. {
  196228. if (mapping->modifiermap [i << 1] == altLeftCode)
  196229. Keys::AltMask = 1 << i;
  196230. else if (mapping->modifiermap [i << 1] == numLockCode)
  196231. Keys::NumLockMask = 1 << i;
  196232. }
  196233. XFreeModifiermap (mapping);
  196234. }
  196235. }
  196236. void removeWindowDecorations (Window wndH)
  196237. {
  196238. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196239. if (hints != None)
  196240. {
  196241. MotifWmHints motifHints;
  196242. zerostruct (motifHints);
  196243. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196244. motifHints.decorations = 0;
  196245. ScopedXLock xlock;
  196246. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196247. (unsigned char*) &motifHints, 4);
  196248. }
  196249. hints = XInternAtom (display, "_WIN_HINTS", True);
  196250. if (hints != None)
  196251. {
  196252. long gnomeHints = 0;
  196253. ScopedXLock xlock;
  196254. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196255. (unsigned char*) &gnomeHints, 1);
  196256. }
  196257. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196258. if (hints != None)
  196259. {
  196260. long kwmHints = 2; /*KDE_tinyDecoration*/
  196261. ScopedXLock xlock;
  196262. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196263. (unsigned char*) &kwmHints, 1);
  196264. }
  196265. }
  196266. void addWindowButtons (Window wndH)
  196267. {
  196268. ScopedXLock xlock;
  196269. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196270. if (hints != None)
  196271. {
  196272. MotifWmHints motifHints;
  196273. zerostruct (motifHints);
  196274. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196275. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196276. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196277. if ((styleFlags & windowHasCloseButton) != 0)
  196278. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196279. if ((styleFlags & windowHasMinimiseButton) != 0)
  196280. {
  196281. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196282. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196283. }
  196284. if ((styleFlags & windowHasMaximiseButton) != 0)
  196285. {
  196286. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196287. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196288. }
  196289. if ((styleFlags & windowIsResizable) != 0)
  196290. {
  196291. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196292. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196293. }
  196294. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196295. }
  196296. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196297. if (hints != None)
  196298. {
  196299. int netHints [6];
  196300. int num = 0;
  196301. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196302. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196303. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196304. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196305. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196306. (unsigned char*) &netHints, num);
  196307. }
  196308. }
  196309. void setWindowType (Window wndH)
  196310. {
  196311. int netHints [2];
  196312. int numHints = 0;
  196313. if ((styleFlags & windowIsTemporary) != 0
  196314. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196315. {
  196316. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196317. }
  196318. else
  196319. {
  196320. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196321. }
  196322. if (netHints [numHints] != 0)
  196323. ++numHints;
  196324. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196325. if (netHints [numHints] != 0)
  196326. ++numHints;
  196327. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196328. (unsigned char*) &netHints, numHints);
  196329. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196330. {
  196331. Atom skipTaskbar = XInternAtom (display, "_NET_WM_STATE_SKIP_TASKBAR", False);
  196332. XChangeProperty (display, wndH, Atoms::WindowState, XA_ATOM, 32, PropModeReplace,
  196333. (unsigned char*) &skipTaskbar, 1);
  196334. }
  196335. }
  196336. void createWindow()
  196337. {
  196338. ScopedXLock xlock;
  196339. Atoms::initialiseAtoms();
  196340. resetDragAndDrop();
  196341. // Get defaults for various properties
  196342. const int screen = DefaultScreen (display);
  196343. Window root = RootWindow (display, screen);
  196344. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196345. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196346. if (visual == 0)
  196347. {
  196348. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196349. Process::terminate();
  196350. }
  196351. // Create and install a colormap suitable fr our visual
  196352. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196353. XInstallColormap (display, colormap);
  196354. // Set up the window attributes
  196355. XSetWindowAttributes swa;
  196356. swa.border_pixel = 0;
  196357. swa.background_pixmap = None;
  196358. swa.colormap = colormap;
  196359. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196360. swa.event_mask = getAllEventsMask();
  196361. Window wndH = XCreateWindow (display, root,
  196362. 0, 0, 1, 1,
  196363. 0, depth, InputOutput, visual,
  196364. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196365. &swa);
  196366. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196367. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196368. GrabModeAsync, GrabModeAsync, None, None);
  196369. // Set the window context to identify the window handle object
  196370. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196371. {
  196372. // Failed
  196373. jassertfalse
  196374. Logger::outputDebugString ("Failed to create context information for window.\n");
  196375. XDestroyWindow (display, wndH);
  196376. wndH = 0;
  196377. }
  196378. // Set window manager hints
  196379. XWMHints* wmHints = XAllocWMHints();
  196380. wmHints->flags = InputHint | StateHint;
  196381. wmHints->input = True; // Locally active input model
  196382. wmHints->initial_state = NormalState;
  196383. XSetWMHints (display, wndH, wmHints);
  196384. XFree (wmHints);
  196385. // Set the window type
  196386. setWindowType (wndH);
  196387. // Define decoration
  196388. if ((styleFlags & windowHasTitleBar) == 0)
  196389. removeWindowDecorations (wndH);
  196390. else
  196391. addWindowButtons (wndH);
  196392. // Set window name
  196393. setWindowTitle (wndH, getComponent()->getName());
  196394. // Associate the PID, allowing to be shut down when something goes wrong
  196395. unsigned long pid = getpid();
  196396. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196397. (unsigned char*) &pid, 1);
  196398. // Set window manager protocols
  196399. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196400. (unsigned char*) Atoms::ProtocolList, 2);
  196401. // Set drag and drop flags
  196402. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196403. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196404. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196405. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196406. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196407. (const unsigned char*) "", 0);
  196408. unsigned long dndVersion = Atoms::DndVersion;
  196409. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196410. (const unsigned char*) &dndVersion, 1);
  196411. // Initialise the pointer and keyboard mapping
  196412. // This is not the same as the logical pointer mapping the X server uses:
  196413. // we don't mess with this.
  196414. static bool mappingInitialised = false;
  196415. if (! mappingInitialised)
  196416. {
  196417. mappingInitialised = true;
  196418. const int numButtons = XGetPointerMapping (display, 0, 0);
  196419. if (numButtons == 2)
  196420. {
  196421. pointerMap[0] = Keys::LeftButton;
  196422. pointerMap[1] = Keys::RightButton;
  196423. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  196424. }
  196425. else if (numButtons >= 3)
  196426. {
  196427. pointerMap[0] = Keys::LeftButton;
  196428. pointerMap[1] = Keys::MiddleButton;
  196429. pointerMap[2] = Keys::RightButton;
  196430. if (numButtons >= 5)
  196431. {
  196432. pointerMap[3] = Keys::WheelUp;
  196433. pointerMap[4] = Keys::WheelDown;
  196434. }
  196435. }
  196436. updateModifierMappings();
  196437. }
  196438. windowH = wndH;
  196439. }
  196440. void destroyWindow()
  196441. {
  196442. ScopedXLock xlock;
  196443. XPointer handlePointer;
  196444. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  196445. XDeleteContext (display, (XID) windowH, improbableNumber);
  196446. XDestroyWindow (display, windowH);
  196447. // Wait for it to complete and then remove any events for this
  196448. // window from the event queue.
  196449. XSync (display, false);
  196450. XEvent event;
  196451. while (XCheckWindowEvent (display, windowH, getAllEventsMask(), &event) == True)
  196452. {}
  196453. }
  196454. static int getAllEventsMask() throw()
  196455. {
  196456. return NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  196457. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  196458. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  196459. }
  196460. static int64 getEventTime (::Time t)
  196461. {
  196462. static int64 eventTimeOffset = 0x12345678;
  196463. const int64 thisMessageTime = t;
  196464. if (eventTimeOffset == 0x12345678)
  196465. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  196466. return eventTimeOffset + thisMessageTime;
  196467. }
  196468. static void setWindowTitle (Window xwin, const String& title)
  196469. {
  196470. XTextProperty nameProperty;
  196471. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  196472. ScopedXLock xlock;
  196473. if (XStringListToTextProperty (strings, 1, &nameProperty))
  196474. {
  196475. XSetWMName (display, xwin, &nameProperty);
  196476. XSetWMIconName (display, xwin, &nameProperty);
  196477. XFree (nameProperty.value);
  196478. }
  196479. }
  196480. void updateBorderSize()
  196481. {
  196482. if ((styleFlags & windowHasTitleBar) == 0)
  196483. {
  196484. windowBorder = BorderSize (0);
  196485. }
  196486. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  196487. {
  196488. ScopedXLock xlock;
  196489. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  196490. if (hints != None)
  196491. {
  196492. unsigned char* data = 0;
  196493. unsigned long nitems, bytesLeft;
  196494. Atom actualType;
  196495. int actualFormat;
  196496. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  196497. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  196498. &data) == Success)
  196499. {
  196500. const unsigned long* const sizes = (const unsigned long*) data;
  196501. if (actualFormat == 32)
  196502. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  196503. (int) sizes[3], (int) sizes[1]);
  196504. XFree (data);
  196505. }
  196506. }
  196507. }
  196508. }
  196509. void updateBounds()
  196510. {
  196511. jassert (windowH != 0);
  196512. if (windowH != 0)
  196513. {
  196514. Window root, child;
  196515. unsigned int bw, depth;
  196516. ScopedXLock xlock;
  196517. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196518. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  196519. &bw, &depth))
  196520. {
  196521. wx = wy = ww = wh = 0;
  196522. }
  196523. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  196524. {
  196525. wx = wy = 0;
  196526. }
  196527. }
  196528. }
  196529. void resetDragAndDrop()
  196530. {
  196531. dragAndDropFiles.clear();
  196532. lastDropPos = Point<int> (-1, -1);
  196533. dragAndDropCurrentMimeType = 0;
  196534. dragAndDropSourceWindow = 0;
  196535. srcMimeTypeAtomList.clear();
  196536. }
  196537. void sendDragAndDropMessage (XClientMessageEvent& msg)
  196538. {
  196539. msg.type = ClientMessage;
  196540. msg.display = display;
  196541. msg.window = dragAndDropSourceWindow;
  196542. msg.format = 32;
  196543. msg.data.l[0] = windowH;
  196544. ScopedXLock xlock;
  196545. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  196546. }
  196547. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  196548. {
  196549. XClientMessageEvent msg;
  196550. zerostruct (msg);
  196551. msg.message_type = Atoms::XdndStatus;
  196552. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  196553. msg.data.l[4] = dropAction;
  196554. sendDragAndDropMessage (msg);
  196555. }
  196556. void sendDragAndDropLeave()
  196557. {
  196558. XClientMessageEvent msg;
  196559. zerostruct (msg);
  196560. msg.message_type = Atoms::XdndLeave;
  196561. sendDragAndDropMessage (msg);
  196562. }
  196563. void sendDragAndDropFinish()
  196564. {
  196565. XClientMessageEvent msg;
  196566. zerostruct (msg);
  196567. msg.message_type = Atoms::XdndFinished;
  196568. sendDragAndDropMessage (msg);
  196569. }
  196570. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  196571. {
  196572. if ((clientMsg->data.l[1] & 1) == 0)
  196573. {
  196574. sendDragAndDropLeave();
  196575. if (dragAndDropFiles.size() > 0)
  196576. handleFileDragExit (dragAndDropFiles);
  196577. dragAndDropFiles.clear();
  196578. }
  196579. }
  196580. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  196581. {
  196582. if (dragAndDropSourceWindow == 0)
  196583. return;
  196584. dragAndDropSourceWindow = clientMsg->data.l[0];
  196585. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  196586. (int) clientMsg->data.l[2] & 0xffff);
  196587. dropPos -= getScreenPosition();
  196588. if (lastDropPos != dropPos)
  196589. {
  196590. lastDropPos = dropPos;
  196591. dragAndDropTimestamp = clientMsg->data.l[3];
  196592. Atom targetAction = Atoms::XdndActionCopy;
  196593. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  196594. {
  196595. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  196596. {
  196597. targetAction = Atoms::allowedActions[i];
  196598. break;
  196599. }
  196600. }
  196601. sendDragAndDropStatus (true, targetAction);
  196602. if (dragAndDropFiles.size() == 0)
  196603. updateDraggedFileList (clientMsg);
  196604. if (dragAndDropFiles.size() > 0)
  196605. handleFileDragMove (dragAndDropFiles, dropPos);
  196606. }
  196607. }
  196608. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  196609. {
  196610. if (dragAndDropFiles.size() == 0)
  196611. updateDraggedFileList (clientMsg);
  196612. const StringArray files (dragAndDropFiles);
  196613. const Point<int> lastPos (lastDropPos);
  196614. sendDragAndDropFinish();
  196615. resetDragAndDrop();
  196616. if (files.size() > 0)
  196617. handleFileDragDrop (files, lastPos);
  196618. }
  196619. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  196620. {
  196621. dragAndDropFiles.clear();
  196622. srcMimeTypeAtomList.clear();
  196623. dragAndDropCurrentMimeType = 0;
  196624. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  196625. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  196626. {
  196627. dragAndDropSourceWindow = 0;
  196628. return;
  196629. }
  196630. dragAndDropSourceWindow = clientMsg->data.l[0];
  196631. if ((clientMsg->data.l[1] & 1) != 0)
  196632. {
  196633. Atom actual;
  196634. int format;
  196635. unsigned long count = 0, remaining = 0;
  196636. unsigned char* data = 0;
  196637. ScopedXLock xlock;
  196638. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  196639. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  196640. &count, &remaining, &data);
  196641. if (data != 0)
  196642. {
  196643. if (actual == XA_ATOM && format == 32 && count != 0)
  196644. {
  196645. const unsigned long* const types = (const unsigned long*) data;
  196646. for (unsigned int i = 0; i < count; ++i)
  196647. if (types[i] != None)
  196648. srcMimeTypeAtomList.add (types[i]);
  196649. }
  196650. XFree (data);
  196651. }
  196652. }
  196653. if (srcMimeTypeAtomList.size() == 0)
  196654. {
  196655. for (int i = 2; i < 5; ++i)
  196656. if (clientMsg->data.l[i] != None)
  196657. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  196658. if (srcMimeTypeAtomList.size() == 0)
  196659. {
  196660. dragAndDropSourceWindow = 0;
  196661. return;
  196662. }
  196663. }
  196664. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  196665. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  196666. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  196667. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  196668. handleDragAndDropPosition (clientMsg);
  196669. }
  196670. void handleDragAndDropSelection (const XEvent* const evt)
  196671. {
  196672. dragAndDropFiles.clear();
  196673. if (evt->xselection.property != 0)
  196674. {
  196675. StringArray lines;
  196676. {
  196677. MemoryBlock dropData;
  196678. for (;;)
  196679. {
  196680. Atom actual;
  196681. uint8* data = 0;
  196682. unsigned long count = 0, remaining = 0;
  196683. int format = 0;
  196684. ScopedXLock xlock;
  196685. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  196686. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  196687. &format, &count, &remaining, &data) == Success)
  196688. {
  196689. dropData.append (data, count * format / 8);
  196690. XFree (data);
  196691. if (remaining == 0)
  196692. break;
  196693. }
  196694. else
  196695. {
  196696. XFree (data);
  196697. break;
  196698. }
  196699. }
  196700. lines.addLines (dropData.toString());
  196701. }
  196702. for (int i = 0; i < lines.size(); ++i)
  196703. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf ("file://", false, true)));
  196704. dragAndDropFiles.trim();
  196705. dragAndDropFiles.removeEmptyStrings();
  196706. }
  196707. }
  196708. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  196709. {
  196710. dragAndDropFiles.clear();
  196711. if (dragAndDropSourceWindow != None
  196712. && dragAndDropCurrentMimeType != 0)
  196713. {
  196714. dragAndDropTimestamp = clientMsg->data.l[2];
  196715. ScopedXLock xlock;
  196716. XConvertSelection (display,
  196717. Atoms::XdndSelection,
  196718. dragAndDropCurrentMimeType,
  196719. XInternAtom (display, "JXSelectionWindowProperty", 0),
  196720. windowH,
  196721. dragAndDropTimestamp);
  196722. }
  196723. }
  196724. StringArray dragAndDropFiles;
  196725. int dragAndDropTimestamp;
  196726. Point<int> lastDropPos;
  196727. Atom dragAndDropCurrentMimeType;
  196728. Window dragAndDropSourceWindow;
  196729. Array <Atom> srcMimeTypeAtomList;
  196730. static int pointerMap[5];
  196731. static Point<int> lastMousePos;
  196732. static void clearLastMousePos() throw()
  196733. {
  196734. lastMousePos = Point<int> (0x100000, 0x100000);
  196735. }
  196736. };
  196737. ModifierKeys LinuxComponentPeer::currentModifiers;
  196738. bool LinuxComponentPeer::isActiveApplication = false;
  196739. int LinuxComponentPeer::pointerMap[5];
  196740. Point<int> LinuxComponentPeer::lastMousePos;
  196741. bool Process::isForegroundProcess()
  196742. {
  196743. return LinuxComponentPeer::isActiveApplication;
  196744. }
  196745. void ModifierKeys::updateCurrentModifiers() throw()
  196746. {
  196747. currentModifiers = LinuxComponentPeer::currentModifiers;
  196748. }
  196749. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  196750. {
  196751. Window root, child;
  196752. int x, y, winx, winy;
  196753. unsigned int mask;
  196754. int mouseMods = 0;
  196755. ScopedXLock xlock;
  196756. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  196757. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  196758. {
  196759. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  196760. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  196761. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  196762. }
  196763. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  196764. return LinuxComponentPeer::currentModifiers;
  196765. }
  196766. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  196767. {
  196768. if (enableOrDisable)
  196769. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  196770. }
  196771. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  196772. {
  196773. return new LinuxComponentPeer (this, styleFlags);
  196774. }
  196775. // (this callback is hooked up in the messaging code)
  196776. void juce_windowMessageReceive (XEvent* event)
  196777. {
  196778. if (event->xany.window != None)
  196779. {
  196780. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  196781. if (ComponentPeer::isValidPeer (peer))
  196782. peer->handleWindowMessage (event);
  196783. }
  196784. else
  196785. {
  196786. switch (event->xany.type)
  196787. {
  196788. case KeymapNotify:
  196789. {
  196790. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  196791. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  196792. break;
  196793. }
  196794. default:
  196795. break;
  196796. }
  196797. }
  196798. }
  196799. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  196800. {
  196801. if (display == 0)
  196802. return;
  196803. #if JUCE_USE_XINERAMA
  196804. int major_opcode, first_event, first_error;
  196805. ScopedXLock xlock;
  196806. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  196807. {
  196808. typedef Bool (*tXineramaIsActive) (Display*);
  196809. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  196810. static tXineramaIsActive xXineramaIsActive = 0;
  196811. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  196812. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  196813. {
  196814. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  196815. if (h != 0)
  196816. {
  196817. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  196818. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  196819. }
  196820. }
  196821. if (xXineramaIsActive != 0
  196822. && xXineramaQueryScreens != 0
  196823. && xXineramaIsActive (display))
  196824. {
  196825. int numMonitors = 0;
  196826. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  196827. if (screens != 0)
  196828. {
  196829. for (int i = numMonitors; --i >= 0;)
  196830. {
  196831. int index = screens[i].screen_number;
  196832. if (index >= 0)
  196833. {
  196834. while (monitorCoords.size() < index)
  196835. monitorCoords.add (Rectangle<int>());
  196836. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  196837. screens[i].y_org,
  196838. screens[i].width,
  196839. screens[i].height));
  196840. }
  196841. }
  196842. XFree (screens);
  196843. }
  196844. }
  196845. }
  196846. if (monitorCoords.size() == 0)
  196847. #endif
  196848. {
  196849. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  196850. if (hints != None)
  196851. {
  196852. const int numMonitors = ScreenCount (display);
  196853. for (int i = 0; i < numMonitors; ++i)
  196854. {
  196855. Window root = RootWindow (display, i);
  196856. unsigned long nitems, bytesLeft;
  196857. Atom actualType;
  196858. int actualFormat;
  196859. unsigned char* data = 0;
  196860. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  196861. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  196862. &data) == Success)
  196863. {
  196864. const long* const position = (const long*) data;
  196865. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  196866. monitorCoords.add (Rectangle<int> (position[0], position[1],
  196867. position[2], position[3]));
  196868. XFree (data);
  196869. }
  196870. }
  196871. }
  196872. if (monitorCoords.size() == 0)
  196873. {
  196874. monitorCoords.add (Rectangle<int> (0, 0,
  196875. DisplayWidth (display, DefaultScreen (display)),
  196876. DisplayHeight (display, DefaultScreen (display))));
  196877. }
  196878. }
  196879. }
  196880. void Desktop::createMouseInputSources()
  196881. {
  196882. mouseSources.add (new MouseInputSource (0, true));
  196883. }
  196884. bool Desktop::canUseSemiTransparentWindows() throw()
  196885. {
  196886. int matchedDepth = 0;
  196887. const int desiredDepth = 32;
  196888. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  196889. && (matchedDepth == desiredDepth);
  196890. }
  196891. const Point<int> Desktop::getMousePosition()
  196892. {
  196893. Window root, child;
  196894. int x, y, winx, winy;
  196895. unsigned int mask;
  196896. ScopedXLock xlock;
  196897. if (XQueryPointer (display,
  196898. RootWindow (display, DefaultScreen (display)),
  196899. &root, &child,
  196900. &x, &y, &winx, &winy, &mask) == False)
  196901. {
  196902. // Pointer not on the default screen
  196903. x = y = -1;
  196904. }
  196905. return Point<int> (x, y);
  196906. }
  196907. void Desktop::setMousePosition (const Point<int>& newPosition)
  196908. {
  196909. ScopedXLock xlock;
  196910. Window root = RootWindow (display, DefaultScreen (display));
  196911. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  196912. }
  196913. static bool screenSaverAllowed = true;
  196914. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  196915. {
  196916. if (screenSaverAllowed != isEnabled)
  196917. {
  196918. screenSaverAllowed = isEnabled;
  196919. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  196920. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  196921. if (xScreenSaverSuspend == 0)
  196922. {
  196923. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  196924. if (h != 0)
  196925. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  196926. }
  196927. ScopedXLock xlock;
  196928. if (xScreenSaverSuspend != 0)
  196929. xScreenSaverSuspend (display, ! isEnabled);
  196930. }
  196931. }
  196932. bool Desktop::isScreenSaverEnabled() throw()
  196933. {
  196934. return screenSaverAllowed;
  196935. }
  196936. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  196937. {
  196938. ScopedXLock xlock;
  196939. const unsigned int imageW = image.getWidth();
  196940. const unsigned int imageH = image.getHeight();
  196941. #if JUCE_USE_XCURSOR
  196942. {
  196943. typedef XcursorBool (*tXcursorSupportsARGB) (Display*);
  196944. typedef XcursorImage* (*tXcursorImageCreate) (int, int);
  196945. typedef void (*tXcursorImageDestroy) (XcursorImage*);
  196946. typedef Cursor (*tXcursorImageLoadCursor) (Display*, const XcursorImage*);
  196947. static tXcursorSupportsARGB xXcursorSupportsARGB = 0;
  196948. static tXcursorImageCreate xXcursorImageCreate = 0;
  196949. static tXcursorImageDestroy xXcursorImageDestroy = 0;
  196950. static tXcursorImageLoadCursor xXcursorImageLoadCursor = 0;
  196951. static bool hasBeenLoaded = false;
  196952. if (! hasBeenLoaded)
  196953. {
  196954. hasBeenLoaded = true;
  196955. void* h = dlopen ("libXcursor.so", RTLD_GLOBAL | RTLD_NOW);
  196956. if (h != 0)
  196957. {
  196958. xXcursorSupportsARGB = (tXcursorSupportsARGB) dlsym (h, "XcursorSupportsARGB");
  196959. xXcursorImageCreate = (tXcursorImageCreate) dlsym (h, "XcursorImageCreate");
  196960. xXcursorImageLoadCursor = (tXcursorImageLoadCursor) dlsym (h, "XcursorImageLoadCursor");
  196961. xXcursorImageDestroy = (tXcursorImageDestroy) dlsym (h, "XcursorImageDestroy");
  196962. if (xXcursorSupportsARGB == 0 || xXcursorImageCreate == 0
  196963. || xXcursorImageLoadCursor == 0 || xXcursorImageDestroy == 0
  196964. || ! xXcursorSupportsARGB (display))
  196965. xXcursorSupportsARGB = 0;
  196966. }
  196967. }
  196968. if (xXcursorSupportsARGB != 0)
  196969. {
  196970. XcursorImage* xcImage = xXcursorImageCreate (imageW, imageH);
  196971. if (xcImage != 0)
  196972. {
  196973. xcImage->xhot = hotspotX;
  196974. xcImage->yhot = hotspotY;
  196975. XcursorPixel* dest = xcImage->pixels;
  196976. for (int y = 0; y < (int) imageH; ++y)
  196977. for (int x = 0; x < (int) imageW; ++x)
  196978. *dest++ = image.getPixelAt (x, y).getARGB();
  196979. void* result = (void*) xXcursorImageLoadCursor (display, xcImage);
  196980. xXcursorImageDestroy (xcImage);
  196981. if (result != 0)
  196982. return result;
  196983. }
  196984. }
  196985. }
  196986. #endif
  196987. Window root = RootWindow (display, DefaultScreen (display));
  196988. unsigned int cursorW, cursorH;
  196989. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  196990. return 0;
  196991. Image im (Image::ARGB, cursorW, cursorH, true);
  196992. {
  196993. Graphics g (im);
  196994. if (imageW > cursorW || imageH > cursorH)
  196995. {
  196996. hotspotX = (hotspotX * cursorW) / imageW;
  196997. hotspotY = (hotspotY * cursorH) / imageH;
  196998. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  196999. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197000. false);
  197001. }
  197002. else
  197003. {
  197004. g.drawImageAt (&image, 0, 0);
  197005. }
  197006. }
  197007. const int stride = (cursorW + 7) >> 3;
  197008. HeapBlock <char> maskPlane, sourcePlane;
  197009. maskPlane.calloc (stride * cursorH);
  197010. sourcePlane.calloc (stride * cursorH);
  197011. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197012. for (int y = cursorH; --y >= 0;)
  197013. {
  197014. for (int x = cursorW; --x >= 0;)
  197015. {
  197016. const char mask = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197017. const int offset = y * stride + (x >> 3);
  197018. const Colour c (im.getPixelAt (x, y));
  197019. if (c.getAlpha() >= 128)
  197020. maskPlane[offset] |= mask;
  197021. if (c.getBrightness() >= 0.5f)
  197022. sourcePlane[offset] |= mask;
  197023. }
  197024. }
  197025. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, sourcePlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197026. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, maskPlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197027. XColor white, black;
  197028. black.red = black.green = black.blue = 0;
  197029. white.red = white.green = white.blue = 0xffff;
  197030. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197031. XFreePixmap (display, sourcePixmap);
  197032. XFreePixmap (display, maskPixmap);
  197033. return result;
  197034. }
  197035. void juce_deleteMouseCursor (void* const cursorHandle, const bool)
  197036. {
  197037. ScopedXLock xlock;
  197038. if (cursorHandle != 0)
  197039. XFreeCursor (display, (Cursor) cursorHandle);
  197040. }
  197041. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  197042. {
  197043. unsigned int shape;
  197044. switch (type)
  197045. {
  197046. case MouseCursor::NoCursor:
  197047. {
  197048. const Image im (Image::ARGB, 16, 16, true);
  197049. return juce_createMouseCursorFromImage (im, 0, 0);
  197050. }
  197051. case MouseCursor::NormalCursor:
  197052. return (void*) None; // Use parent cursor
  197053. case MouseCursor::DraggingHandCursor:
  197054. {
  197055. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197056. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197057. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197058. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197059. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197060. const int dragHandDataSize = 99;
  197061. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (dragHandData, dragHandDataSize));
  197062. return juce_createMouseCursorFromImage (*im, 8, 7);
  197063. }
  197064. case MouseCursor::CopyingCursor:
  197065. {
  197066. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197067. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197068. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197069. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197070. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197071. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197072. const int copyCursorSize = 119;
  197073. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (copyCursorData, copyCursorSize));
  197074. return juce_createMouseCursorFromImage (*im, 1, 3);
  197075. }
  197076. case MouseCursor::WaitCursor:
  197077. shape = XC_watch;
  197078. break;
  197079. case MouseCursor::IBeamCursor:
  197080. shape = XC_xterm;
  197081. break;
  197082. case MouseCursor::PointingHandCursor:
  197083. shape = XC_hand2;
  197084. break;
  197085. case MouseCursor::LeftRightResizeCursor:
  197086. shape = XC_sb_h_double_arrow;
  197087. break;
  197088. case MouseCursor::UpDownResizeCursor:
  197089. shape = XC_sb_v_double_arrow;
  197090. break;
  197091. case MouseCursor::UpDownLeftRightResizeCursor:
  197092. shape = XC_fleur;
  197093. break;
  197094. case MouseCursor::TopEdgeResizeCursor:
  197095. shape = XC_top_side;
  197096. break;
  197097. case MouseCursor::BottomEdgeResizeCursor:
  197098. shape = XC_bottom_side;
  197099. break;
  197100. case MouseCursor::LeftEdgeResizeCursor:
  197101. shape = XC_left_side;
  197102. break;
  197103. case MouseCursor::RightEdgeResizeCursor:
  197104. shape = XC_right_side;
  197105. break;
  197106. case MouseCursor::TopLeftCornerResizeCursor:
  197107. shape = XC_top_left_corner;
  197108. break;
  197109. case MouseCursor::TopRightCornerResizeCursor:
  197110. shape = XC_top_right_corner;
  197111. break;
  197112. case MouseCursor::BottomLeftCornerResizeCursor:
  197113. shape = XC_bottom_left_corner;
  197114. break;
  197115. case MouseCursor::BottomRightCornerResizeCursor:
  197116. shape = XC_bottom_right_corner;
  197117. break;
  197118. case MouseCursor::CrosshairCursor:
  197119. shape = XC_crosshair;
  197120. break;
  197121. default:
  197122. return (void*) None; // Use parent cursor
  197123. }
  197124. ScopedXLock xlock;
  197125. return (void*) XCreateFontCursor (display, shape);
  197126. }
  197127. void MouseCursor::showInWindow (ComponentPeer* peer) const
  197128. {
  197129. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197130. if (lp != 0)
  197131. lp->showMouseCursor ((Cursor) getHandle());
  197132. }
  197133. void MouseCursor::showInAllWindows() const
  197134. {
  197135. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197136. showInWindow (ComponentPeer::getPeer (i));
  197137. }
  197138. Image* juce_createIconForFile (const File& file)
  197139. {
  197140. return 0;
  197141. }
  197142. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197143. {
  197144. return new Image (format, imageWidth, imageHeight, clearImage);
  197145. }
  197146. #if JUCE_OPENGL
  197147. class WindowedGLContext : public OpenGLContext
  197148. {
  197149. public:
  197150. WindowedGLContext (Component* const component,
  197151. const OpenGLPixelFormat& pixelFormat_,
  197152. GLXContext sharedContext)
  197153. : renderContext (0),
  197154. embeddedWindow (0),
  197155. pixelFormat (pixelFormat_)
  197156. {
  197157. jassert (component != 0);
  197158. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197159. if (peer == 0)
  197160. return;
  197161. ScopedXLock xlock;
  197162. XSync (display, False);
  197163. GLint attribs [64];
  197164. int n = 0;
  197165. attribs[n++] = GLX_RGBA;
  197166. attribs[n++] = GLX_DOUBLEBUFFER;
  197167. attribs[n++] = GLX_RED_SIZE;
  197168. attribs[n++] = pixelFormat.redBits;
  197169. attribs[n++] = GLX_GREEN_SIZE;
  197170. attribs[n++] = pixelFormat.greenBits;
  197171. attribs[n++] = GLX_BLUE_SIZE;
  197172. attribs[n++] = pixelFormat.blueBits;
  197173. attribs[n++] = GLX_ALPHA_SIZE;
  197174. attribs[n++] = pixelFormat.alphaBits;
  197175. attribs[n++] = GLX_DEPTH_SIZE;
  197176. attribs[n++] = pixelFormat.depthBufferBits;
  197177. attribs[n++] = GLX_STENCIL_SIZE;
  197178. attribs[n++] = pixelFormat.stencilBufferBits;
  197179. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197180. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197181. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197182. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197183. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197184. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197185. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197186. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197187. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197188. attribs[n++] = None;
  197189. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197190. if (bestVisual == 0)
  197191. return;
  197192. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197193. Window windowH = (Window) peer->getNativeHandle();
  197194. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197195. XSetWindowAttributes swa;
  197196. swa.colormap = colourMap;
  197197. swa.border_pixel = 0;
  197198. swa.event_mask = ExposureMask | StructureNotifyMask;
  197199. embeddedWindow = XCreateWindow (display, windowH,
  197200. 0, 0, 1, 1, 0,
  197201. bestVisual->depth,
  197202. InputOutput,
  197203. bestVisual->visual,
  197204. CWBorderPixel | CWColormap | CWEventMask,
  197205. &swa);
  197206. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197207. XMapWindow (display, embeddedWindow);
  197208. XFreeColormap (display, colourMap);
  197209. XFree (bestVisual);
  197210. XSync (display, False);
  197211. }
  197212. ~WindowedGLContext()
  197213. {
  197214. makeInactive();
  197215. ScopedXLock xlock;
  197216. glXDestroyContext (display, renderContext);
  197217. XUnmapWindow (display, embeddedWindow);
  197218. XDestroyWindow (display, embeddedWindow);
  197219. }
  197220. bool makeActive() const throw()
  197221. {
  197222. jassert (renderContext != 0);
  197223. ScopedXLock xlock;
  197224. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197225. && XSync (display, False);
  197226. }
  197227. bool makeInactive() const throw()
  197228. {
  197229. ScopedXLock xlock;
  197230. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197231. }
  197232. bool isActive() const throw()
  197233. {
  197234. ScopedXLock xlock;
  197235. return glXGetCurrentContext() == renderContext;
  197236. }
  197237. const OpenGLPixelFormat getPixelFormat() const
  197238. {
  197239. return pixelFormat;
  197240. }
  197241. void* getRawContext() const throw()
  197242. {
  197243. return renderContext;
  197244. }
  197245. void updateWindowPosition (int x, int y, int w, int h, int)
  197246. {
  197247. ScopedXLock xlock;
  197248. XMoveResizeWindow (display, embeddedWindow,
  197249. x, y, jmax (1, w), jmax (1, h));
  197250. }
  197251. void swapBuffers()
  197252. {
  197253. ScopedXLock xlock;
  197254. glXSwapBuffers (display, embeddedWindow);
  197255. }
  197256. bool setSwapInterval (const int numFramesPerSwap)
  197257. {
  197258. // xxx needs doing..
  197259. return false;
  197260. }
  197261. int getSwapInterval() const
  197262. {
  197263. // xxx needs doing..
  197264. return 0;
  197265. }
  197266. void repaint()
  197267. {
  197268. }
  197269. juce_UseDebuggingNewOperator
  197270. GLXContext renderContext;
  197271. private:
  197272. Window embeddedWindow;
  197273. OpenGLPixelFormat pixelFormat;
  197274. WindowedGLContext (const WindowedGLContext&);
  197275. WindowedGLContext& operator= (const WindowedGLContext&);
  197276. };
  197277. OpenGLContext* OpenGLComponent::createContext()
  197278. {
  197279. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  197280. contextToShareListsWith != 0 ? (GLXContext) contextToShareListsWith->getRawContext() : 0));
  197281. return (c->renderContext != 0) ? c.release() : 0;
  197282. }
  197283. void juce_glViewport (const int w, const int h)
  197284. {
  197285. glViewport (0, 0, w, h);
  197286. }
  197287. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197288. OwnedArray <OpenGLPixelFormat>& results)
  197289. {
  197290. results.add (new OpenGLPixelFormat()); // xxx
  197291. }
  197292. #endif
  197293. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197294. {
  197295. jassertfalse // not implemented!
  197296. return false;
  197297. }
  197298. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197299. {
  197300. jassertfalse // not implemented!
  197301. return false;
  197302. }
  197303. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197304. {
  197305. if (! isOnDesktop ())
  197306. addToDesktop (0);
  197307. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197308. if (wp != 0)
  197309. {
  197310. wp->setTaskBarIcon (newImage);
  197311. setVisible (true);
  197312. toFront (false);
  197313. repaint();
  197314. }
  197315. }
  197316. void SystemTrayIconComponent::paint (Graphics& g)
  197317. {
  197318. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197319. if (wp != 0)
  197320. {
  197321. const Image* const image = wp->getTaskbarIcon();
  197322. if (image != 0)
  197323. {
  197324. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197325. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197326. false);
  197327. }
  197328. }
  197329. }
  197330. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197331. {
  197332. // xxx not yet implemented!
  197333. }
  197334. void PlatformUtilities::beep()
  197335. {
  197336. std::cout << "\a" << std::flush;
  197337. }
  197338. bool AlertWindow::showNativeDialogBox (const String& title,
  197339. const String& bodyText,
  197340. bool isOkCancel)
  197341. {
  197342. // use a non-native one for the time being..
  197343. if (isOkCancel)
  197344. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197345. else
  197346. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197347. return true;
  197348. }
  197349. const int KeyPress::spaceKey = XK_space & 0xff;
  197350. const int KeyPress::returnKey = XK_Return & 0xff;
  197351. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197352. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197353. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197354. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197355. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197356. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197357. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197358. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197359. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197360. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197361. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197362. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197363. const int KeyPress::tabKey = XK_Tab & 0xff;
  197364. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197365. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197366. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197367. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197368. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197369. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197370. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197371. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197372. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197373. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197374. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197375. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197376. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197377. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197378. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197379. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197380. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197381. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197382. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197383. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197384. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197385. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197386. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197387. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197388. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197389. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197390. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197391. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197392. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197393. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197394. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197395. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197396. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197397. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197398. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197399. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197400. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197401. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197402. #endif
  197403. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197404. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197405. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197406. // compiled on its own).
  197407. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197408. static const int maxNumChans = 64;
  197409. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197410. {
  197411. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197412. snd_pcm_hw_params_t* hwParams;
  197413. snd_pcm_hw_params_alloca (&hwParams);
  197414. for (int i = 0; ratesToTry[i] != 0; ++i)
  197415. {
  197416. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197417. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197418. {
  197419. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197420. }
  197421. }
  197422. }
  197423. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197424. {
  197425. snd_pcm_hw_params_t *params;
  197426. snd_pcm_hw_params_alloca (&params);
  197427. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197428. {
  197429. snd_pcm_hw_params_get_channels_min (params, minChans);
  197430. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197431. }
  197432. }
  197433. static void getDeviceProperties (const String& deviceID,
  197434. unsigned int& minChansOut,
  197435. unsigned int& maxChansOut,
  197436. unsigned int& minChansIn,
  197437. unsigned int& maxChansIn,
  197438. Array <int>& rates)
  197439. {
  197440. if (deviceID.isEmpty())
  197441. return;
  197442. snd_ctl_t* handle;
  197443. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (",", false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197444. {
  197445. snd_pcm_info_t* info;
  197446. snd_pcm_info_alloca (&info);
  197447. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197448. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (",", false, false).getIntValue());
  197449. snd_pcm_info_set_subdevice (info, 0);
  197450. if (snd_ctl_pcm_info (handle, info) >= 0)
  197451. {
  197452. snd_pcm_t* pcmHandle;
  197453. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197454. {
  197455. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197456. getDeviceSampleRates (pcmHandle, rates);
  197457. snd_pcm_close (pcmHandle);
  197458. }
  197459. }
  197460. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197461. if (snd_ctl_pcm_info (handle, info) >= 0)
  197462. {
  197463. snd_pcm_t* pcmHandle;
  197464. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197465. {
  197466. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197467. if (rates.size() == 0)
  197468. getDeviceSampleRates (pcmHandle, rates);
  197469. snd_pcm_close (pcmHandle);
  197470. }
  197471. }
  197472. snd_ctl_close (handle);
  197473. }
  197474. }
  197475. class ALSADevice
  197476. {
  197477. public:
  197478. ALSADevice (const String& deviceID,
  197479. const bool forInput)
  197480. : handle (0),
  197481. bitDepth (16),
  197482. numChannelsRunning (0),
  197483. isInput (forInput),
  197484. sampleFormat (AudioDataConverters::int16LE)
  197485. {
  197486. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  197487. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  197488. SND_PCM_ASYNC));
  197489. }
  197490. ~ALSADevice()
  197491. {
  197492. if (handle != 0)
  197493. snd_pcm_close (handle);
  197494. }
  197495. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  197496. {
  197497. if (handle == 0)
  197498. return false;
  197499. snd_pcm_hw_params_t* hwParams;
  197500. snd_pcm_hw_params_alloca (&hwParams);
  197501. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  197502. return false;
  197503. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  197504. isInterleaved = false;
  197505. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  197506. isInterleaved = true;
  197507. else
  197508. {
  197509. jassertfalse
  197510. return false;
  197511. }
  197512. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  197513. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  197514. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  197515. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  197516. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  197517. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  197518. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  197519. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  197520. bitDepth = 0;
  197521. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  197522. {
  197523. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  197524. {
  197525. bitDepth = formatsToTry [i + 1];
  197526. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  197527. break;
  197528. }
  197529. }
  197530. if (bitDepth == 0)
  197531. {
  197532. error = "device doesn't support a compatible PCM format";
  197533. DBG ("ALSA error: " + error + "\n");
  197534. return false;
  197535. }
  197536. int dir = 0;
  197537. unsigned int periods = 4;
  197538. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  197539. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  197540. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  197541. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  197542. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  197543. || failed (snd_pcm_hw_params (handle, hwParams)))
  197544. {
  197545. return false;
  197546. }
  197547. snd_pcm_sw_params_t* swParams;
  197548. snd_pcm_sw_params_alloca (&swParams);
  197549. snd_pcm_uframes_t boundary;
  197550. if (failed (snd_pcm_sw_params_current (handle, swParams))
  197551. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  197552. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  197553. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  197554. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  197555. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  197556. || failed (snd_pcm_sw_params (handle, swParams)))
  197557. {
  197558. return false;
  197559. }
  197560. numChannelsRunning = numChannels;
  197561. return true;
  197562. }
  197563. bool write (float** const data, const int numSamples)
  197564. {
  197565. if (isInterleaved)
  197566. {
  197567. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197568. float* interleaved = static_cast <float*> (scratch.getData());
  197569. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  197570. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  197571. snd_pcm_sframes_t num = snd_pcm_writei (handle, interleaved, numSamples);
  197572. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  197573. return false;
  197574. }
  197575. else
  197576. {
  197577. for (int i = 0; i < numChannelsRunning; ++i)
  197578. if (data[i] != 0)
  197579. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  197580. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  197581. if (failed (num))
  197582. {
  197583. if (num == -EPIPE)
  197584. {
  197585. if (failed (snd_pcm_prepare (handle)))
  197586. return false;
  197587. }
  197588. else if (num != -ESTRPIPE)
  197589. return false;
  197590. }
  197591. }
  197592. return true;
  197593. }
  197594. bool read (float** const data, const int numSamples)
  197595. {
  197596. if (isInterleaved)
  197597. {
  197598. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197599. float* interleaved = static_cast <float*> (scratch.getData());
  197600. snd_pcm_sframes_t num = snd_pcm_readi (handle, interleaved, numSamples);
  197601. if (failed (num))
  197602. {
  197603. if (num == -EPIPE)
  197604. {
  197605. if (failed (snd_pcm_prepare (handle)))
  197606. return false;
  197607. }
  197608. else if (num != -ESTRPIPE)
  197609. return false;
  197610. }
  197611. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  197612. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  197613. }
  197614. else
  197615. {
  197616. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  197617. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  197618. return false;
  197619. for (int i = 0; i < numChannelsRunning; ++i)
  197620. if (data[i] != 0)
  197621. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  197622. }
  197623. return true;
  197624. }
  197625. juce_UseDebuggingNewOperator
  197626. snd_pcm_t* handle;
  197627. String error;
  197628. int bitDepth, numChannelsRunning;
  197629. private:
  197630. const bool isInput;
  197631. bool isInterleaved;
  197632. MemoryBlock scratch;
  197633. AudioDataConverters::DataFormat sampleFormat;
  197634. bool failed (const int errorNum)
  197635. {
  197636. if (errorNum >= 0)
  197637. return false;
  197638. error = snd_strerror (errorNum);
  197639. DBG ("ALSA error: " + error + "\n");
  197640. return true;
  197641. }
  197642. };
  197643. class ALSAThread : public Thread
  197644. {
  197645. public:
  197646. ALSAThread (const String& inputId_,
  197647. const String& outputId_)
  197648. : Thread ("Juce ALSA"),
  197649. sampleRate (0),
  197650. bufferSize (0),
  197651. callback (0),
  197652. inputId (inputId_),
  197653. outputId (outputId_),
  197654. outputDevice (0),
  197655. inputDevice (0),
  197656. numCallbacks (0),
  197657. totalNumInputChannels (0),
  197658. totalNumOutputChannels (0)
  197659. {
  197660. zeromem (outputChannelData, sizeof (outputChannelData));
  197661. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  197662. zeromem (inputChannelData, sizeof (inputChannelData));
  197663. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  197664. initialiseRatesAndChannels();
  197665. }
  197666. ~ALSAThread()
  197667. {
  197668. close();
  197669. }
  197670. void open (BigInteger inputChannels,
  197671. BigInteger outputChannels,
  197672. const double sampleRate_,
  197673. const int bufferSize_)
  197674. {
  197675. close();
  197676. error = String::empty;
  197677. sampleRate = sampleRate_;
  197678. bufferSize = bufferSize_;
  197679. currentInputChans.clear();
  197680. currentOutputChans.clear();
  197681. if (inputChannels.getHighestBit() >= 0)
  197682. {
  197683. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  197684. {
  197685. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  197686. if (inputChannels[i])
  197687. {
  197688. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  197689. currentInputChans.setBit (i);
  197690. }
  197691. }
  197692. }
  197693. if (outputChannels.getHighestBit() >= 0)
  197694. {
  197695. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  197696. {
  197697. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  197698. if (outputChannels[i])
  197699. {
  197700. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  197701. currentOutputChans.setBit (i);
  197702. }
  197703. }
  197704. }
  197705. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  197706. {
  197707. outputDevice = new ALSADevice (outputId, false);
  197708. if (outputDevice->error.isNotEmpty())
  197709. {
  197710. error = outputDevice->error;
  197711. deleteAndZero (outputDevice);
  197712. return;
  197713. }
  197714. currentOutputChans.setRange (0, minChansOut, true);
  197715. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  197716. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  197717. bufferSize))
  197718. {
  197719. error = outputDevice->error;
  197720. deleteAndZero (outputDevice);
  197721. return;
  197722. }
  197723. }
  197724. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  197725. {
  197726. inputDevice = new ALSADevice (inputId, true);
  197727. if (inputDevice->error.isNotEmpty())
  197728. {
  197729. error = inputDevice->error;
  197730. deleteAndZero (inputDevice);
  197731. return;
  197732. }
  197733. currentInputChans.setRange (0, minChansIn, true);
  197734. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  197735. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  197736. bufferSize))
  197737. {
  197738. error = inputDevice->error;
  197739. deleteAndZero (inputDevice);
  197740. return;
  197741. }
  197742. }
  197743. if (outputDevice == 0 && inputDevice == 0)
  197744. {
  197745. error = "no channels";
  197746. return;
  197747. }
  197748. if (outputDevice != 0 && inputDevice != 0)
  197749. {
  197750. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  197751. }
  197752. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  197753. return;
  197754. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  197755. return;
  197756. startThread (9);
  197757. int count = 1000;
  197758. while (numCallbacks == 0)
  197759. {
  197760. sleep (5);
  197761. if (--count < 0 || ! isThreadRunning())
  197762. {
  197763. error = "device didn't start";
  197764. break;
  197765. }
  197766. }
  197767. }
  197768. void close()
  197769. {
  197770. stopThread (6000);
  197771. deleteAndZero (inputDevice);
  197772. deleteAndZero (outputDevice);
  197773. for (int i = 0; i < maxNumChans; ++i)
  197774. {
  197775. juce_free (inputChannelData [i]);
  197776. juce_free (outputChannelData [i]);
  197777. }
  197778. zeromem (outputChannelData, sizeof (outputChannelData));
  197779. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  197780. zeromem (inputChannelData, sizeof (inputChannelData));
  197781. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  197782. totalNumOutputChannels = 0;
  197783. totalNumInputChannels = 0;
  197784. numCallbacks = 0;
  197785. }
  197786. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  197787. {
  197788. const ScopedLock sl (callbackLock);
  197789. callback = newCallback;
  197790. }
  197791. void run()
  197792. {
  197793. while (! threadShouldExit())
  197794. {
  197795. if (inputDevice != 0)
  197796. {
  197797. if (! inputDevice->read (inputChannelData, bufferSize))
  197798. {
  197799. DBG ("ALSA: read failure");
  197800. break;
  197801. }
  197802. }
  197803. if (threadShouldExit())
  197804. break;
  197805. {
  197806. const ScopedLock sl (callbackLock);
  197807. ++numCallbacks;
  197808. if (callback != 0)
  197809. {
  197810. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  197811. totalNumInputChannels,
  197812. outputChannelDataForCallback,
  197813. totalNumOutputChannels,
  197814. bufferSize);
  197815. }
  197816. else
  197817. {
  197818. for (int i = 0; i < totalNumOutputChannels; ++i)
  197819. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  197820. }
  197821. }
  197822. if (outputDevice != 0)
  197823. {
  197824. failed (snd_pcm_wait (outputDevice->handle, 2000));
  197825. if (threadShouldExit())
  197826. break;
  197827. failed (snd_pcm_avail_update (outputDevice->handle));
  197828. if (! outputDevice->write (outputChannelData, bufferSize))
  197829. {
  197830. DBG ("ALSA: write failure");
  197831. break;
  197832. }
  197833. }
  197834. }
  197835. }
  197836. int getBitDepth() const throw()
  197837. {
  197838. if (outputDevice != 0)
  197839. return outputDevice->bitDepth;
  197840. if (inputDevice != 0)
  197841. return inputDevice->bitDepth;
  197842. return 16;
  197843. }
  197844. juce_UseDebuggingNewOperator
  197845. String error;
  197846. double sampleRate;
  197847. int bufferSize;
  197848. BigInteger currentInputChans, currentOutputChans;
  197849. Array <int> sampleRates;
  197850. StringArray channelNamesOut, channelNamesIn;
  197851. AudioIODeviceCallback* callback;
  197852. private:
  197853. const String inputId, outputId;
  197854. ALSADevice* outputDevice;
  197855. ALSADevice* inputDevice;
  197856. int numCallbacks;
  197857. CriticalSection callbackLock;
  197858. float* outputChannelData [maxNumChans];
  197859. float* outputChannelDataForCallback [maxNumChans];
  197860. int totalNumInputChannels;
  197861. float* inputChannelData [maxNumChans];
  197862. float* inputChannelDataForCallback [maxNumChans];
  197863. int totalNumOutputChannels;
  197864. unsigned int minChansOut, maxChansOut;
  197865. unsigned int minChansIn, maxChansIn;
  197866. bool failed (const int errorNum) throw()
  197867. {
  197868. if (errorNum >= 0)
  197869. return false;
  197870. error = snd_strerror (errorNum);
  197871. DBG ("ALSA error: " + error + "\n");
  197872. return true;
  197873. }
  197874. void initialiseRatesAndChannels() throw()
  197875. {
  197876. sampleRates.clear();
  197877. channelNamesOut.clear();
  197878. channelNamesIn.clear();
  197879. minChansOut = 0;
  197880. maxChansOut = 0;
  197881. minChansIn = 0;
  197882. maxChansIn = 0;
  197883. unsigned int dummy = 0;
  197884. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  197885. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  197886. unsigned int i;
  197887. for (i = 0; i < maxChansOut; ++i)
  197888. channelNamesOut.add ("channel " + String ((int) i + 1));
  197889. for (i = 0; i < maxChansIn; ++i)
  197890. channelNamesIn.add ("channel " + String ((int) i + 1));
  197891. }
  197892. };
  197893. class ALSAAudioIODevice : public AudioIODevice
  197894. {
  197895. public:
  197896. ALSAAudioIODevice (const String& deviceName,
  197897. const String& inputId_,
  197898. const String& outputId_)
  197899. : AudioIODevice (deviceName, "ALSA"),
  197900. inputId (inputId_),
  197901. outputId (outputId_),
  197902. isOpen_ (false),
  197903. isStarted (false),
  197904. internal (new ALSAThread (inputId_, outputId_))
  197905. {
  197906. }
  197907. ~ALSAAudioIODevice()
  197908. {
  197909. }
  197910. const StringArray getOutputChannelNames()
  197911. {
  197912. return internal->channelNamesOut;
  197913. }
  197914. const StringArray getInputChannelNames()
  197915. {
  197916. return internal->channelNamesIn;
  197917. }
  197918. int getNumSampleRates()
  197919. {
  197920. return internal->sampleRates.size();
  197921. }
  197922. double getSampleRate (int index)
  197923. {
  197924. return internal->sampleRates [index];
  197925. }
  197926. int getNumBufferSizesAvailable()
  197927. {
  197928. return 50;
  197929. }
  197930. int getBufferSizeSamples (int index)
  197931. {
  197932. int n = 16;
  197933. for (int i = 0; i < index; ++i)
  197934. n += n < 64 ? 16
  197935. : (n < 512 ? 32
  197936. : (n < 1024 ? 64
  197937. : (n < 2048 ? 128 : 256)));
  197938. return n;
  197939. }
  197940. int getDefaultBufferSize()
  197941. {
  197942. return 512;
  197943. }
  197944. const String open (const BigInteger& inputChannels,
  197945. const BigInteger& outputChannels,
  197946. double sampleRate,
  197947. int bufferSizeSamples)
  197948. {
  197949. close();
  197950. if (bufferSizeSamples <= 0)
  197951. bufferSizeSamples = getDefaultBufferSize();
  197952. if (sampleRate <= 0)
  197953. {
  197954. for (int i = 0; i < getNumSampleRates(); ++i)
  197955. {
  197956. if (getSampleRate (i) >= 44100)
  197957. {
  197958. sampleRate = getSampleRate (i);
  197959. break;
  197960. }
  197961. }
  197962. }
  197963. internal->open (inputChannels, outputChannels,
  197964. sampleRate, bufferSizeSamples);
  197965. isOpen_ = internal->error.isEmpty();
  197966. return internal->error;
  197967. }
  197968. void close()
  197969. {
  197970. stop();
  197971. internal->close();
  197972. isOpen_ = false;
  197973. }
  197974. bool isOpen()
  197975. {
  197976. return isOpen_;
  197977. }
  197978. int getCurrentBufferSizeSamples()
  197979. {
  197980. return internal->bufferSize;
  197981. }
  197982. double getCurrentSampleRate()
  197983. {
  197984. return internal->sampleRate;
  197985. }
  197986. int getCurrentBitDepth()
  197987. {
  197988. return internal->getBitDepth();
  197989. }
  197990. const BigInteger getActiveOutputChannels() const
  197991. {
  197992. return internal->currentOutputChans;
  197993. }
  197994. const BigInteger getActiveInputChannels() const
  197995. {
  197996. return internal->currentInputChans;
  197997. }
  197998. int getOutputLatencyInSamples()
  197999. {
  198000. return 0;
  198001. }
  198002. int getInputLatencyInSamples()
  198003. {
  198004. return 0;
  198005. }
  198006. void start (AudioIODeviceCallback* callback)
  198007. {
  198008. if (! isOpen_)
  198009. callback = 0;
  198010. internal->setCallback (callback);
  198011. if (callback != 0)
  198012. callback->audioDeviceAboutToStart (this);
  198013. isStarted = (callback != 0);
  198014. }
  198015. void stop()
  198016. {
  198017. AudioIODeviceCallback* const oldCallback = internal->callback;
  198018. start (0);
  198019. if (oldCallback != 0)
  198020. oldCallback->audioDeviceStopped();
  198021. }
  198022. bool isPlaying()
  198023. {
  198024. return isStarted && internal->error.isEmpty();
  198025. }
  198026. const String getLastError()
  198027. {
  198028. return internal->error;
  198029. }
  198030. String inputId, outputId;
  198031. private:
  198032. bool isOpen_, isStarted;
  198033. ScopedPointer<ALSAThread> internal;
  198034. };
  198035. class ALSAAudioIODeviceType : public AudioIODeviceType
  198036. {
  198037. public:
  198038. ALSAAudioIODeviceType()
  198039. : AudioIODeviceType ("ALSA"),
  198040. hasScanned (false)
  198041. {
  198042. }
  198043. ~ALSAAudioIODeviceType()
  198044. {
  198045. }
  198046. void scanForDevices()
  198047. {
  198048. if (hasScanned)
  198049. return;
  198050. hasScanned = true;
  198051. inputNames.clear();
  198052. inputIds.clear();
  198053. outputNames.clear();
  198054. outputIds.clear();
  198055. snd_ctl_t* handle;
  198056. snd_ctl_card_info_t* info;
  198057. snd_ctl_card_info_alloca (&info);
  198058. int cardNum = -1;
  198059. while (outputIds.size() + inputIds.size() <= 32)
  198060. {
  198061. snd_card_next (&cardNum);
  198062. if (cardNum < 0)
  198063. break;
  198064. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198065. {
  198066. if (snd_ctl_card_info (handle, info) >= 0)
  198067. {
  198068. String cardId (snd_ctl_card_info_get_id (info));
  198069. if (cardId.removeCharacters ("0123456789").isEmpty())
  198070. cardId = String (cardNum);
  198071. int device = -1;
  198072. for (;;)
  198073. {
  198074. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198075. break;
  198076. String id, name;
  198077. id << "hw:" << cardId << ',' << device;
  198078. bool isInput, isOutput;
  198079. if (testDevice (id, isInput, isOutput))
  198080. {
  198081. name << snd_ctl_card_info_get_name (info);
  198082. if (name.isEmpty())
  198083. name = id;
  198084. if (isInput)
  198085. {
  198086. inputNames.add (name);
  198087. inputIds.add (id);
  198088. }
  198089. if (isOutput)
  198090. {
  198091. outputNames.add (name);
  198092. outputIds.add (id);
  198093. }
  198094. }
  198095. }
  198096. }
  198097. snd_ctl_close (handle);
  198098. }
  198099. }
  198100. inputNames.appendNumbersToDuplicates (false, true);
  198101. outputNames.appendNumbersToDuplicates (false, true);
  198102. }
  198103. const StringArray getDeviceNames (bool wantInputNames) const
  198104. {
  198105. jassert (hasScanned); // need to call scanForDevices() before doing this
  198106. return wantInputNames ? inputNames : outputNames;
  198107. }
  198108. int getDefaultDeviceIndex (bool forInput) const
  198109. {
  198110. jassert (hasScanned); // need to call scanForDevices() before doing this
  198111. return 0;
  198112. }
  198113. bool hasSeparateInputsAndOutputs() const { return true; }
  198114. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198115. {
  198116. jassert (hasScanned); // need to call scanForDevices() before doing this
  198117. ALSAAudioIODevice* d = dynamic_cast <ALSAAudioIODevice*> (device);
  198118. if (d == 0)
  198119. return -1;
  198120. return asInput ? inputIds.indexOf (d->inputId)
  198121. : outputIds.indexOf (d->outputId);
  198122. }
  198123. AudioIODevice* createDevice (const String& outputDeviceName,
  198124. const String& inputDeviceName)
  198125. {
  198126. jassert (hasScanned); // need to call scanForDevices() before doing this
  198127. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198128. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198129. String deviceName (outputIndex >= 0 ? outputDeviceName
  198130. : inputDeviceName);
  198131. if (inputIndex >= 0 || outputIndex >= 0)
  198132. return new ALSAAudioIODevice (deviceName,
  198133. inputIds [inputIndex],
  198134. outputIds [outputIndex]);
  198135. return 0;
  198136. }
  198137. juce_UseDebuggingNewOperator
  198138. private:
  198139. StringArray inputNames, outputNames, inputIds, outputIds;
  198140. bool hasScanned;
  198141. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198142. {
  198143. unsigned int minChansOut = 0, maxChansOut = 0;
  198144. unsigned int minChansIn = 0, maxChansIn = 0;
  198145. Array <int> rates;
  198146. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198147. DBG ("ALSA device: " + id
  198148. + " outs=" + String ((int) minChansOut) + "-" + String ((int) maxChansOut)
  198149. + " ins=" + String ((int) minChansIn) + "-" + String ((int) maxChansIn)
  198150. + " rates=" + String (rates.size()));
  198151. isInput = maxChansIn > 0;
  198152. isOutput = maxChansOut > 0;
  198153. return (isInput || isOutput) && rates.size() > 0;
  198154. }
  198155. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198156. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198157. };
  198158. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198159. {
  198160. return new ALSAAudioIODeviceType();
  198161. }
  198162. #endif
  198163. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198164. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198165. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198166. // compiled on its own).
  198167. #ifdef JUCE_INCLUDED_FILE
  198168. #if JUCE_JACK
  198169. static void* juce_libjack_handle = 0;
  198170. void* juce_load_jack_function (const char* const name)
  198171. {
  198172. if (juce_libjack_handle == 0)
  198173. return 0;
  198174. return dlsym (juce_libjack_handle, name);
  198175. }
  198176. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198177. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198178. return_type fn_name argument_types { \
  198179. static fn_name##_ptr_t fn = 0; \
  198180. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198181. if (fn) return (*fn)arguments; \
  198182. else return 0; \
  198183. }
  198184. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198185. typedef void (*fn_name##_ptr_t)argument_types; \
  198186. void fn_name argument_types { \
  198187. static fn_name##_ptr_t fn = 0; \
  198188. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198189. if (fn) (*fn)arguments; \
  198190. }
  198191. JUCE_DECL_JACK_FUNCTION (jack_client_t*, jack_client_open, (const char* client_name, jack_options_t options, jack_status_t* status), (client_name, options, status));
  198192. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198193. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198194. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198195. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198196. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198197. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198198. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198199. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198200. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_register, (jack_client_t* client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size), (client, port_name, port_type, flags, buffer_size));
  198201. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198202. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198203. JUCE_DECL_JACK_FUNCTION (const char**, jack_get_ports, (jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags), (client, port_name_pattern, type_name_pattern, flags));
  198204. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198205. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198206. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198207. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198208. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198209. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198210. #if JUCE_DEBUG
  198211. #define JACK_LOGGING_ENABLED 1
  198212. #endif
  198213. #if JACK_LOGGING_ENABLED
  198214. static void jack_Log (const String& s)
  198215. {
  198216. std::cerr << s << std::endl;
  198217. }
  198218. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198219. {
  198220. if (status & JackServerFailed || status & JackServerError)
  198221. jack_Log ("Unable to connect to JACK server");
  198222. if (status & JackVersionError)
  198223. jack_Log ("Client's protocol version does not match");
  198224. if (status & JackInvalidOption)
  198225. jack_Log ("The operation contained an invalid or unsupported option");
  198226. if (status & JackNameNotUnique)
  198227. jack_Log ("The desired client name was not unique");
  198228. if (status & JackNoSuchClient)
  198229. jack_Log ("Requested client does not exist");
  198230. if (status & JackInitFailure)
  198231. jack_Log ("Unable to initialize client");
  198232. }
  198233. #else
  198234. #define dumpJackErrorMessage(a) {}
  198235. #define jack_Log(...) {}
  198236. #endif
  198237. #ifndef JUCE_JACK_CLIENT_NAME
  198238. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198239. #endif
  198240. class JackAudioIODevice : public AudioIODevice
  198241. {
  198242. public:
  198243. JackAudioIODevice (const String& deviceName,
  198244. const String& inputId_,
  198245. const String& outputId_)
  198246. : AudioIODevice (deviceName, "JACK"),
  198247. inputId (inputId_),
  198248. outputId (outputId_),
  198249. isOpen_ (false),
  198250. callback (0),
  198251. totalNumberOfInputChannels (0),
  198252. totalNumberOfOutputChannels (0)
  198253. {
  198254. jassert (deviceName.isNotEmpty());
  198255. jack_status_t status;
  198256. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198257. if (client == 0)
  198258. {
  198259. dumpJackErrorMessage (status);
  198260. }
  198261. else
  198262. {
  198263. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198264. // open input ports
  198265. const StringArray inputChannels (getInputChannelNames());
  198266. for (int i = 0; i < inputChannels.size(); i++)
  198267. {
  198268. String inputName;
  198269. inputName << "in_" << ++totalNumberOfInputChannels;
  198270. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198271. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198272. }
  198273. // open output ports
  198274. const StringArray outputChannels (getOutputChannelNames());
  198275. for (int i = 0; i < outputChannels.size (); i++)
  198276. {
  198277. String outputName;
  198278. outputName << "out_" << ++totalNumberOfOutputChannels;
  198279. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198280. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198281. }
  198282. inChans.calloc (totalNumberOfInputChannels + 2);
  198283. outChans.calloc (totalNumberOfOutputChannels + 2);
  198284. }
  198285. }
  198286. ~JackAudioIODevice()
  198287. {
  198288. close();
  198289. if (client != 0)
  198290. {
  198291. JUCE_NAMESPACE::jack_client_close (client);
  198292. client = 0;
  198293. }
  198294. }
  198295. const StringArray getChannelNames (bool forInput) const
  198296. {
  198297. StringArray names;
  198298. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198299. forInput ? JackPortIsInput : JackPortIsOutput);
  198300. if (ports != 0)
  198301. {
  198302. int j = 0;
  198303. while (ports[j] != 0)
  198304. {
  198305. const String portName (ports [j++]);
  198306. if (portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198307. names.add (portName.fromFirstOccurrenceOf (":", false, false));
  198308. }
  198309. free (ports);
  198310. }
  198311. return names;
  198312. }
  198313. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198314. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198315. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198316. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198317. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198318. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198319. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198320. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  198321. double sampleRate, int bufferSizeSamples)
  198322. {
  198323. if (client == 0)
  198324. {
  198325. lastError = "No JACK client running";
  198326. return lastError;
  198327. }
  198328. lastError = String::empty;
  198329. close();
  198330. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198331. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198332. JUCE_NAMESPACE::jack_activate (client);
  198333. isOpen_ = true;
  198334. if (! inputChannels.isZero())
  198335. {
  198336. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198337. if (ports != 0)
  198338. {
  198339. const int numInputChannels = inputChannels.getHighestBit() + 1;
  198340. for (int i = 0; i < numInputChannels; ++i)
  198341. {
  198342. const String portName (ports[i]);
  198343. if (inputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198344. {
  198345. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198346. if (error != 0)
  198347. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198348. }
  198349. }
  198350. free (ports);
  198351. }
  198352. }
  198353. if (! outputChannels.isZero())
  198354. {
  198355. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198356. if (ports != 0)
  198357. {
  198358. const int numOutputChannels = outputChannels.getHighestBit() + 1;
  198359. for (int i = 0; i < numOutputChannels; ++i)
  198360. {
  198361. const String portName (ports[i]);
  198362. if (outputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198363. {
  198364. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198365. if (error != 0)
  198366. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198367. }
  198368. }
  198369. free (ports);
  198370. }
  198371. }
  198372. return lastError;
  198373. }
  198374. void close()
  198375. {
  198376. stop();
  198377. if (client != 0)
  198378. {
  198379. JUCE_NAMESPACE::jack_deactivate (client);
  198380. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198381. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198382. }
  198383. isOpen_ = false;
  198384. }
  198385. void start (AudioIODeviceCallback* newCallback)
  198386. {
  198387. if (isOpen_ && newCallback != callback)
  198388. {
  198389. if (newCallback != 0)
  198390. newCallback->audioDeviceAboutToStart (this);
  198391. AudioIODeviceCallback* const oldCallback = callback;
  198392. {
  198393. const ScopedLock sl (callbackLock);
  198394. callback = newCallback;
  198395. }
  198396. if (oldCallback != 0)
  198397. oldCallback->audioDeviceStopped();
  198398. }
  198399. }
  198400. void stop()
  198401. {
  198402. start (0);
  198403. }
  198404. bool isOpen() { return isOpen_; }
  198405. bool isPlaying() { return callback != 0; }
  198406. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198407. double getCurrentSampleRate() { return getSampleRate (0); }
  198408. int getCurrentBitDepth() { return 32; }
  198409. const String getLastError() { return lastError; }
  198410. const BigInteger getActiveOutputChannels() const
  198411. {
  198412. BigInteger outputBits;
  198413. for (int i = 0; i < outputPorts.size(); i++)
  198414. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198415. outputBits.setBit (i);
  198416. return outputBits;
  198417. }
  198418. const BigInteger getActiveInputChannels() const
  198419. {
  198420. BigInteger inputBits;
  198421. for (int i = 0; i < inputPorts.size(); i++)
  198422. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198423. inputBits.setBit (i);
  198424. return inputBits;
  198425. }
  198426. int getOutputLatencyInSamples()
  198427. {
  198428. int latency = 0;
  198429. for (int i = 0; i < outputPorts.size(); i++)
  198430. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198431. return latency;
  198432. }
  198433. int getInputLatencyInSamples()
  198434. {
  198435. int latency = 0;
  198436. for (int i = 0; i < inputPorts.size(); i++)
  198437. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198438. return latency;
  198439. }
  198440. String inputId, outputId;
  198441. private:
  198442. void process (const int numSamples)
  198443. {
  198444. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198445. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198446. {
  198447. jack_default_audio_sample_t* in
  198448. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198449. if (in != 0)
  198450. inChans [numActiveInChans++] = (float*) in;
  198451. }
  198452. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198453. {
  198454. jack_default_audio_sample_t* out
  198455. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198456. if (out != 0)
  198457. outChans [numActiveOutChans++] = (float*) out;
  198458. }
  198459. const ScopedLock sl (callbackLock);
  198460. if (callback != 0)
  198461. {
  198462. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198463. outChans, numActiveOutChans, numSamples);
  198464. }
  198465. else
  198466. {
  198467. for (i = 0; i < numActiveOutChans; ++i)
  198468. zeromem (outChans[i], sizeof (float) * numSamples);
  198469. }
  198470. }
  198471. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  198472. {
  198473. if (callbackArgument != 0)
  198474. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  198475. return 0;
  198476. }
  198477. static void threadInitCallback (void* callbackArgument)
  198478. {
  198479. jack_Log ("JackAudioIODevice::initialise");
  198480. }
  198481. static void shutdownCallback (void* callbackArgument)
  198482. {
  198483. jack_Log ("JackAudioIODevice::shutdown");
  198484. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  198485. if (device != 0)
  198486. {
  198487. device->client = 0;
  198488. device->close();
  198489. }
  198490. }
  198491. static void errorCallback (const char* msg)
  198492. {
  198493. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  198494. }
  198495. bool isOpen_;
  198496. jack_client_t* client;
  198497. String lastError;
  198498. AudioIODeviceCallback* callback;
  198499. CriticalSection callbackLock;
  198500. HeapBlock <float*> inChans, outChans;
  198501. int totalNumberOfInputChannels;
  198502. int totalNumberOfOutputChannels;
  198503. VoidArray inputPorts, outputPorts;
  198504. };
  198505. class JackAudioIODeviceType : public AudioIODeviceType
  198506. {
  198507. public:
  198508. JackAudioIODeviceType()
  198509. : AudioIODeviceType ("JACK"),
  198510. hasScanned (false)
  198511. {
  198512. }
  198513. ~JackAudioIODeviceType()
  198514. {
  198515. }
  198516. void scanForDevices()
  198517. {
  198518. hasScanned = true;
  198519. inputNames.clear();
  198520. inputIds.clear();
  198521. outputNames.clear();
  198522. outputIds.clear();
  198523. if (juce_libjack_handle == 0)
  198524. {
  198525. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  198526. if (juce_libjack_handle == 0)
  198527. return;
  198528. }
  198529. // open a dummy client
  198530. jack_status_t status;
  198531. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  198532. if (client == 0)
  198533. {
  198534. dumpJackErrorMessage (status);
  198535. }
  198536. else
  198537. {
  198538. // scan for output devices
  198539. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198540. if (ports != 0)
  198541. {
  198542. int j = 0;
  198543. while (ports[j] != 0)
  198544. {
  198545. String clientName (ports[j]);
  198546. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198547. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198548. && ! inputNames.contains (clientName))
  198549. {
  198550. inputNames.add (clientName);
  198551. inputIds.add (ports [j]);
  198552. }
  198553. ++j;
  198554. }
  198555. free (ports);
  198556. }
  198557. // scan for input devices
  198558. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198559. if (ports != 0)
  198560. {
  198561. int j = 0;
  198562. while (ports[j] != 0)
  198563. {
  198564. String clientName (ports[j]);
  198565. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198566. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198567. && ! outputNames.contains (clientName))
  198568. {
  198569. outputNames.add (clientName);
  198570. outputIds.add (ports [j]);
  198571. }
  198572. ++j;
  198573. }
  198574. free (ports);
  198575. }
  198576. JUCE_NAMESPACE::jack_client_close (client);
  198577. }
  198578. }
  198579. const StringArray getDeviceNames (bool wantInputNames) const
  198580. {
  198581. jassert (hasScanned); // need to call scanForDevices() before doing this
  198582. return wantInputNames ? inputNames : outputNames;
  198583. }
  198584. int getDefaultDeviceIndex (bool forInput) const
  198585. {
  198586. jassert (hasScanned); // need to call scanForDevices() before doing this
  198587. return 0;
  198588. }
  198589. bool hasSeparateInputsAndOutputs() const { return true; }
  198590. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198591. {
  198592. jassert (hasScanned); // need to call scanForDevices() before doing this
  198593. JackAudioIODevice* d = dynamic_cast <JackAudioIODevice*> (device);
  198594. if (d == 0)
  198595. return -1;
  198596. return asInput ? inputIds.indexOf (d->inputId)
  198597. : outputIds.indexOf (d->outputId);
  198598. }
  198599. AudioIODevice* createDevice (const String& outputDeviceName,
  198600. const String& inputDeviceName)
  198601. {
  198602. jassert (hasScanned); // need to call scanForDevices() before doing this
  198603. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198604. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198605. if (inputIndex >= 0 || outputIndex >= 0)
  198606. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  198607. : inputDeviceName,
  198608. inputIds [inputIndex],
  198609. outputIds [outputIndex]);
  198610. return 0;
  198611. }
  198612. juce_UseDebuggingNewOperator
  198613. private:
  198614. StringArray inputNames, outputNames, inputIds, outputIds;
  198615. bool hasScanned;
  198616. JackAudioIODeviceType (const JackAudioIODeviceType&);
  198617. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  198618. };
  198619. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  198620. {
  198621. return new JackAudioIODeviceType();
  198622. }
  198623. #else // if JACK is turned off..
  198624. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  198625. #endif
  198626. #endif
  198627. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  198628. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  198629. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198630. // compiled on its own).
  198631. #if JUCE_INCLUDED_FILE
  198632. #if JUCE_ALSA
  198633. static snd_seq_t* iterateDevices (const bool forInput,
  198634. StringArray& deviceNamesFound,
  198635. const int deviceIndexToOpen)
  198636. {
  198637. snd_seq_t* returnedHandle = 0;
  198638. snd_seq_t* seqHandle;
  198639. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  198640. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  198641. {
  198642. snd_seq_system_info_t* systemInfo;
  198643. snd_seq_client_info_t* clientInfo;
  198644. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  198645. {
  198646. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  198647. && snd_seq_client_info_malloc (&clientInfo) == 0)
  198648. {
  198649. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  198650. while (--numClients >= 0 && returnedHandle == 0)
  198651. {
  198652. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  198653. {
  198654. snd_seq_port_info_t* portInfo;
  198655. if (snd_seq_port_info_malloc (&portInfo) == 0)
  198656. {
  198657. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  198658. const int client = snd_seq_client_info_get_client (clientInfo);
  198659. snd_seq_port_info_set_client (portInfo, client);
  198660. snd_seq_port_info_set_port (portInfo, -1);
  198661. while (--numPorts >= 0)
  198662. {
  198663. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  198664. && (snd_seq_port_info_get_capability (portInfo)
  198665. & (forInput ? SND_SEQ_PORT_CAP_READ
  198666. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  198667. {
  198668. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  198669. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  198670. {
  198671. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  198672. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  198673. if (sourcePort != -1)
  198674. {
  198675. snd_seq_set_client_name (seqHandle,
  198676. forInput ? "Juce Midi Input"
  198677. : "Juce Midi Output");
  198678. const int portId
  198679. = snd_seq_create_simple_port (seqHandle,
  198680. forInput ? "Juce Midi In Port"
  198681. : "Juce Midi Out Port",
  198682. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  198683. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  198684. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  198685. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  198686. returnedHandle = seqHandle;
  198687. }
  198688. }
  198689. }
  198690. }
  198691. snd_seq_port_info_free (portInfo);
  198692. }
  198693. }
  198694. }
  198695. snd_seq_client_info_free (clientInfo);
  198696. }
  198697. snd_seq_system_info_free (systemInfo);
  198698. }
  198699. if (returnedHandle == 0)
  198700. snd_seq_close (seqHandle);
  198701. }
  198702. deviceNamesFound.appendNumbersToDuplicates (true, true);
  198703. return returnedHandle;
  198704. }
  198705. static snd_seq_t* createDevice (const bool forInput,
  198706. const String& deviceNameToOpen)
  198707. {
  198708. snd_seq_t* seqHandle = 0;
  198709. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  198710. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  198711. {
  198712. snd_seq_set_client_name (seqHandle,
  198713. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  198714. const int portId
  198715. = snd_seq_create_simple_port (seqHandle,
  198716. forInput ? "in"
  198717. : "out",
  198718. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  198719. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  198720. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  198721. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  198722. if (portId < 0)
  198723. {
  198724. snd_seq_close (seqHandle);
  198725. seqHandle = 0;
  198726. }
  198727. }
  198728. return seqHandle;
  198729. }
  198730. class MidiOutputDevice
  198731. {
  198732. public:
  198733. MidiOutputDevice (MidiOutput* const midiOutput_,
  198734. snd_seq_t* const seqHandle_)
  198735. :
  198736. midiOutput (midiOutput_),
  198737. seqHandle (seqHandle_),
  198738. maxEventSize (16 * 1024)
  198739. {
  198740. jassert (seqHandle != 0 && midiOutput != 0);
  198741. snd_midi_event_new (maxEventSize, &midiParser);
  198742. }
  198743. ~MidiOutputDevice()
  198744. {
  198745. snd_midi_event_free (midiParser);
  198746. snd_seq_close (seqHandle);
  198747. }
  198748. void sendMessageNow (const MidiMessage& message)
  198749. {
  198750. if (message.getRawDataSize() > maxEventSize)
  198751. {
  198752. maxEventSize = message.getRawDataSize();
  198753. snd_midi_event_free (midiParser);
  198754. snd_midi_event_new (maxEventSize, &midiParser);
  198755. }
  198756. snd_seq_event_t event;
  198757. snd_seq_ev_clear (&event);
  198758. snd_midi_event_encode (midiParser,
  198759. message.getRawData(),
  198760. message.getRawDataSize(),
  198761. &event);
  198762. snd_midi_event_reset_encode (midiParser);
  198763. snd_seq_ev_set_source (&event, 0);
  198764. snd_seq_ev_set_subs (&event);
  198765. snd_seq_ev_set_direct (&event);
  198766. snd_seq_event_output (seqHandle, &event);
  198767. snd_seq_drain_output (seqHandle);
  198768. }
  198769. juce_UseDebuggingNewOperator
  198770. private:
  198771. MidiOutput* const midiOutput;
  198772. snd_seq_t* const seqHandle;
  198773. snd_midi_event_t* midiParser;
  198774. int maxEventSize;
  198775. };
  198776. const StringArray MidiOutput::getDevices()
  198777. {
  198778. StringArray devices;
  198779. iterateDevices (false, devices, -1);
  198780. return devices;
  198781. }
  198782. int MidiOutput::getDefaultDeviceIndex()
  198783. {
  198784. return 0;
  198785. }
  198786. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  198787. {
  198788. MidiOutput* newDevice = 0;
  198789. StringArray devices;
  198790. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  198791. if (handle != 0)
  198792. {
  198793. newDevice = new MidiOutput();
  198794. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  198795. }
  198796. return newDevice;
  198797. }
  198798. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  198799. {
  198800. MidiOutput* newDevice = 0;
  198801. snd_seq_t* const handle = createDevice (false, deviceName);
  198802. if (handle != 0)
  198803. {
  198804. newDevice = new MidiOutput();
  198805. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  198806. }
  198807. return newDevice;
  198808. }
  198809. MidiOutput::~MidiOutput()
  198810. {
  198811. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  198812. delete device;
  198813. }
  198814. void MidiOutput::reset()
  198815. {
  198816. }
  198817. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  198818. {
  198819. return false;
  198820. }
  198821. void MidiOutput::setVolume (float leftVol, float rightVol)
  198822. {
  198823. }
  198824. void MidiOutput::sendMessageNow (const MidiMessage& message)
  198825. {
  198826. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  198827. }
  198828. class MidiInputThread : public Thread
  198829. {
  198830. public:
  198831. MidiInputThread (MidiInput* const midiInput_,
  198832. snd_seq_t* const seqHandle_,
  198833. MidiInputCallback* const callback_)
  198834. : Thread ("Juce MIDI Input"),
  198835. midiInput (midiInput_),
  198836. seqHandle (seqHandle_),
  198837. callback (callback_)
  198838. {
  198839. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  198840. }
  198841. ~MidiInputThread()
  198842. {
  198843. snd_seq_close (seqHandle);
  198844. }
  198845. void run()
  198846. {
  198847. const int maxEventSize = 16 * 1024;
  198848. snd_midi_event_t* midiParser;
  198849. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  198850. {
  198851. HeapBlock <uint8> buffer (maxEventSize);
  198852. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  198853. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  198854. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  198855. while (! threadShouldExit())
  198856. {
  198857. if (poll (pfd, numPfds, 500) > 0)
  198858. {
  198859. snd_seq_event_t* inputEvent = 0;
  198860. snd_seq_nonblock (seqHandle, 1);
  198861. do
  198862. {
  198863. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  198864. {
  198865. // xxx what about SYSEXes that are too big for the buffer?
  198866. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  198867. snd_midi_event_reset_decode (midiParser);
  198868. if (numBytes > 0)
  198869. {
  198870. const MidiMessage message ((const uint8*) buffer,
  198871. numBytes,
  198872. Time::getMillisecondCounter() * 0.001);
  198873. callback->handleIncomingMidiMessage (midiInput, message);
  198874. }
  198875. snd_seq_free_event (inputEvent);
  198876. }
  198877. }
  198878. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  198879. snd_seq_free_event (inputEvent);
  198880. }
  198881. }
  198882. snd_midi_event_free (midiParser);
  198883. }
  198884. };
  198885. juce_UseDebuggingNewOperator
  198886. private:
  198887. MidiInput* const midiInput;
  198888. snd_seq_t* const seqHandle;
  198889. MidiInputCallback* const callback;
  198890. };
  198891. MidiInput::MidiInput (const String& name_)
  198892. : name (name_),
  198893. internal (0)
  198894. {
  198895. }
  198896. MidiInput::~MidiInput()
  198897. {
  198898. stop();
  198899. MidiInputThread* const thread = (MidiInputThread*) internal;
  198900. delete thread;
  198901. }
  198902. void MidiInput::start()
  198903. {
  198904. ((MidiInputThread*) internal)->startThread();
  198905. }
  198906. void MidiInput::stop()
  198907. {
  198908. ((MidiInputThread*) internal)->stopThread (3000);
  198909. }
  198910. int MidiInput::getDefaultDeviceIndex()
  198911. {
  198912. return 0;
  198913. }
  198914. const StringArray MidiInput::getDevices()
  198915. {
  198916. StringArray devices;
  198917. iterateDevices (true, devices, -1);
  198918. return devices;
  198919. }
  198920. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  198921. {
  198922. MidiInput* newDevice = 0;
  198923. StringArray devices;
  198924. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  198925. if (handle != 0)
  198926. {
  198927. newDevice = new MidiInput (devices [deviceIndex]);
  198928. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  198929. }
  198930. return newDevice;
  198931. }
  198932. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  198933. {
  198934. MidiInput* newDevice = 0;
  198935. snd_seq_t* const handle = createDevice (true, deviceName);
  198936. if (handle != 0)
  198937. {
  198938. newDevice = new MidiInput (deviceName);
  198939. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  198940. }
  198941. return newDevice;
  198942. }
  198943. #else
  198944. // (These are just stub functions if ALSA is unavailable...)
  198945. const StringArray MidiOutput::getDevices() { return StringArray(); }
  198946. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  198947. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  198948. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  198949. MidiOutput::~MidiOutput() {}
  198950. void MidiOutput::reset() {}
  198951. bool MidiOutput::getVolume (float&, float&) { return false; }
  198952. void MidiOutput::setVolume (float, float) {}
  198953. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  198954. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  198955. MidiInput::~MidiInput() {}
  198956. void MidiInput::start() {}
  198957. void MidiInput::stop() {}
  198958. int MidiInput::getDefaultDeviceIndex() { return 0; }
  198959. const StringArray MidiInput::getDevices() { return StringArray(); }
  198960. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  198961. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  198962. #endif
  198963. #endif
  198964. /*** End of inlined file: juce_linux_Midi.cpp ***/
  198965. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  198966. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198967. // compiled on its own).
  198968. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  198969. AudioCDReader::AudioCDReader()
  198970. : AudioFormatReader (0, "CD Audio")
  198971. {
  198972. }
  198973. const StringArray AudioCDReader::getAvailableCDNames()
  198974. {
  198975. StringArray names;
  198976. return names;
  198977. }
  198978. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  198979. {
  198980. return 0;
  198981. }
  198982. AudioCDReader::~AudioCDReader()
  198983. {
  198984. }
  198985. void AudioCDReader::refreshTrackLengths()
  198986. {
  198987. }
  198988. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  198989. int64 startSampleInFile, int numSamples)
  198990. {
  198991. return false;
  198992. }
  198993. bool AudioCDReader::isCDStillPresent() const
  198994. {
  198995. return false;
  198996. }
  198997. int AudioCDReader::getNumTracks() const
  198998. {
  198999. return 0;
  199000. }
  199001. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199002. {
  199003. return 0;
  199004. }
  199005. bool AudioCDReader::isTrackAudio (int trackNum) const
  199006. {
  199007. return false;
  199008. }
  199009. void AudioCDReader::enableIndexScanning (bool b)
  199010. {
  199011. }
  199012. int AudioCDReader::getLastIndex() const
  199013. {
  199014. return 0;
  199015. }
  199016. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199017. {
  199018. return Array<int>();
  199019. }
  199020. int AudioCDReader::getCDDBId()
  199021. {
  199022. return 0;
  199023. }
  199024. #endif
  199025. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199026. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199027. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199028. // compiled on its own).
  199029. #if JUCE_INCLUDED_FILE
  199030. void FileChooser::showPlatformDialog (Array<File>& results,
  199031. const String& title,
  199032. const File& file,
  199033. const String& filters,
  199034. bool isDirectory,
  199035. bool selectsFiles,
  199036. bool isSave,
  199037. bool warnAboutOverwritingExistingFiles,
  199038. bool selectMultipleFiles,
  199039. FilePreviewComponent* previewComponent)
  199040. {
  199041. const String separator (":");
  199042. String command ("zenity --file-selection");
  199043. if (title.isNotEmpty())
  199044. command << " --title=\"" << title << "\"";
  199045. if (file != File::nonexistent)
  199046. command << " --filename=\"" << file.getFullPathName () << "\"";
  199047. if (isDirectory)
  199048. command << " --directory";
  199049. if (isSave)
  199050. command << " --save";
  199051. if (selectMultipleFiles)
  199052. command << " --multiple --separator=\"" << separator << "\"";
  199053. command << " 2>&1";
  199054. MemoryOutputStream result;
  199055. int status = -1;
  199056. FILE* stream = popen (command.toUTF8(), "r");
  199057. if (stream != 0)
  199058. {
  199059. for (;;)
  199060. {
  199061. char buffer [1024];
  199062. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199063. if (bytesRead <= 0)
  199064. break;
  199065. result.write (buffer, bytesRead);
  199066. }
  199067. status = pclose (stream);
  199068. }
  199069. if (status == 0)
  199070. {
  199071. StringArray tokens;
  199072. if (selectMultipleFiles)
  199073. tokens.addTokens (result.toUTF8(), separator, String::empty);
  199074. else
  199075. tokens.add (result.toUTF8());
  199076. for (int i = 0; i < tokens.size(); i++)
  199077. results.add (File (tokens[i]));
  199078. return;
  199079. }
  199080. //xxx ain't got one!
  199081. jassertfalse
  199082. }
  199083. #endif
  199084. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199085. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199086. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199087. // compiled on its own).
  199088. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199089. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199090. : browser (0),
  199091. blankPageShown (false),
  199092. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199093. {
  199094. setOpaque (true);
  199095. }
  199096. WebBrowserComponent::~WebBrowserComponent()
  199097. {
  199098. }
  199099. void WebBrowserComponent::goToURL (const String& url,
  199100. const StringArray* headers,
  199101. const MemoryBlock* postData)
  199102. {
  199103. lastURL = url;
  199104. lastHeaders.clear();
  199105. if (headers != 0)
  199106. lastHeaders = *headers;
  199107. lastPostData.setSize (0);
  199108. if (postData != 0)
  199109. lastPostData = *postData;
  199110. blankPageShown = false;
  199111. }
  199112. void WebBrowserComponent::stop()
  199113. {
  199114. }
  199115. void WebBrowserComponent::goBack()
  199116. {
  199117. lastURL = String::empty;
  199118. blankPageShown = false;
  199119. }
  199120. void WebBrowserComponent::goForward()
  199121. {
  199122. lastURL = String::empty;
  199123. }
  199124. void WebBrowserComponent::refresh()
  199125. {
  199126. }
  199127. void WebBrowserComponent::paint (Graphics& g)
  199128. {
  199129. g.fillAll (Colours::white);
  199130. }
  199131. void WebBrowserComponent::checkWindowAssociation()
  199132. {
  199133. }
  199134. void WebBrowserComponent::reloadLastURL()
  199135. {
  199136. if (lastURL.isNotEmpty())
  199137. {
  199138. goToURL (lastURL, &lastHeaders, &lastPostData);
  199139. lastURL = String::empty;
  199140. }
  199141. }
  199142. void WebBrowserComponent::parentHierarchyChanged()
  199143. {
  199144. checkWindowAssociation();
  199145. }
  199146. void WebBrowserComponent::resized()
  199147. {
  199148. }
  199149. void WebBrowserComponent::visibilityChanged()
  199150. {
  199151. checkWindowAssociation();
  199152. }
  199153. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199154. {
  199155. return true;
  199156. }
  199157. #endif
  199158. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199159. #endif
  199160. END_JUCE_NAMESPACE
  199161. #endif
  199162. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199163. #endif
  199164. #if JUCE_MAC || JUCE_IPHONE
  199165. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199166. #if JUCE_MAC || JUCE_IPHONE
  199167. BEGIN_JUCE_NAMESPACE
  199168. #undef Point
  199169. #define JUCE_INCLUDED_FILE 1
  199170. // Now include the actual code files..
  199171. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199172. #ifndef JUCE_ObjCExtraSuffix
  199173. #define JUCE_ObjCExtraSuffix 3
  199174. #endif
  199175. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199176. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199177. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199178. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199179. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199180. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199181. // compiled on its own).
  199182. #if JUCE_INCLUDED_FILE
  199183. static const String nsStringToJuce (NSString* s)
  199184. {
  199185. return String::fromUTF8 ([s UTF8String]);
  199186. }
  199187. static NSString* juceStringToNS (const String& s)
  199188. {
  199189. return [NSString stringWithUTF8String: s.toUTF8()];
  199190. }
  199191. static const String convertUTF16ToString (const UniChar* utf16)
  199192. {
  199193. String s;
  199194. while (*utf16 != 0)
  199195. s += (juce_wchar) *utf16++;
  199196. return s;
  199197. }
  199198. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199199. {
  199200. String result;
  199201. if (cfString != 0)
  199202. {
  199203. CFRange range = { 0, CFStringGetLength (cfString) };
  199204. HeapBlock <UniChar> u (range.length + 1);
  199205. CFStringGetCharacters (cfString, range, u);
  199206. u[range.length] = 0;
  199207. result = convertUTF16ToString (u);
  199208. }
  199209. return result;
  199210. }
  199211. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199212. {
  199213. const int len = s.length();
  199214. HeapBlock <UniChar> temp (len + 2);
  199215. for (int i = 0; i <= len; ++i)
  199216. temp[i] = s[i];
  199217. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199218. }
  199219. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199220. {
  199221. #if JUCE_IPHONE
  199222. const ScopedAutoReleasePool pool;
  199223. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199224. #else
  199225. UnicodeMapping map;
  199226. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199227. kUnicodeNoSubset,
  199228. kTextEncodingDefaultFormat);
  199229. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199230. kUnicodeCanonicalCompVariant,
  199231. kTextEncodingDefaultFormat);
  199232. map.mappingVersion = kUnicodeUseLatestMapping;
  199233. UnicodeToTextInfo conversionInfo = 0;
  199234. String result;
  199235. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199236. {
  199237. const int len = s.length();
  199238. HeapBlock <UniChar> tempIn, tempOut;
  199239. tempIn.calloc (len + 2);
  199240. tempOut.calloc (len + 2);
  199241. for (int i = 0; i <= len; ++i)
  199242. tempIn[i] = s[i];
  199243. ByteCount bytesRead = 0;
  199244. ByteCount outputBufferSize = 0;
  199245. if (ConvertFromUnicodeToText (conversionInfo,
  199246. len * sizeof (UniChar), tempIn,
  199247. kUnicodeDefaultDirectionMask,
  199248. 0, 0, 0, 0,
  199249. len * sizeof (UniChar), &bytesRead,
  199250. &outputBufferSize, tempOut) == noErr)
  199251. {
  199252. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199253. juce_wchar* t = result;
  199254. unsigned int i;
  199255. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199256. t[i] = (juce_wchar) tempOut[i];
  199257. t[i] = 0;
  199258. }
  199259. DisposeUnicodeToTextInfo (&conversionInfo);
  199260. }
  199261. return result;
  199262. #endif
  199263. }
  199264. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199265. void SystemClipboard::copyTextToClipboard (const String& text)
  199266. {
  199267. #if JUCE_IPHONE
  199268. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199269. forPasteboardType: @"public.text"];
  199270. #else
  199271. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199272. owner: nil];
  199273. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199274. forType: NSStringPboardType];
  199275. #endif
  199276. }
  199277. const String SystemClipboard::getTextFromClipboard()
  199278. {
  199279. #if JUCE_IPHONE
  199280. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199281. #else
  199282. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199283. #endif
  199284. return text == 0 ? String::empty
  199285. : nsStringToJuce (text);
  199286. }
  199287. #endif
  199288. #endif
  199289. /*** End of inlined file: juce_mac_Strings.mm ***/
  199290. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199291. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199292. // compiled on its own).
  199293. #if JUCE_INCLUDED_FILE
  199294. namespace SystemStatsHelpers
  199295. {
  199296. static int64 highResTimerFrequency = 0;
  199297. static double highResTimerToMillisecRatio = 0;
  199298. #if JUCE_INTEL
  199299. static void juce_getCpuVendor (char* const v) throw()
  199300. {
  199301. int vendor[4];
  199302. zerostruct (vendor);
  199303. int dummy = 0;
  199304. asm ("mov %%ebx, %%esi \n\t"
  199305. "cpuid \n\t"
  199306. "xchg %%esi, %%ebx"
  199307. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199308. memcpy (v, vendor, 16);
  199309. }
  199310. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199311. {
  199312. unsigned int cpu = 0;
  199313. unsigned int ext = 0;
  199314. unsigned int family = 0;
  199315. unsigned int dummy = 0;
  199316. asm ("mov %%ebx, %%esi \n\t"
  199317. "cpuid \n\t"
  199318. "xchg %%esi, %%ebx"
  199319. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199320. familyModel = family;
  199321. extFeatures = ext;
  199322. return cpu;
  199323. }
  199324. struct CPUFlags
  199325. {
  199326. bool hasMMX : 1;
  199327. bool hasSSE : 1;
  199328. bool hasSSE2 : 1;
  199329. bool has3DNow : 1;
  199330. };
  199331. static CPUFlags cpuFlags;
  199332. #endif
  199333. }
  199334. void SystemStats::initialiseStats() throw()
  199335. {
  199336. using namespace SystemStatsHelpers;
  199337. static bool initialised = false;
  199338. if (! initialised)
  199339. {
  199340. initialised = true;
  199341. #if JUCE_MAC
  199342. // extremely annoying: adding this line stops the apple menu items from working. Of
  199343. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199344. // any events.
  199345. //NSApplicationLoad();
  199346. [NSApplication sharedApplication];
  199347. #endif
  199348. #if JUCE_INTEL
  199349. {
  199350. unsigned int familyModel, extFeatures;
  199351. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199352. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199353. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199354. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199355. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199356. }
  199357. #endif
  199358. mach_timebase_info_data_t timebase;
  199359. (void) mach_timebase_info (&timebase);
  199360. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199361. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199362. String s (SystemStats::getJUCEVersion());
  199363. rlimit lim;
  199364. getrlimit (RLIMIT_NOFILE, &lim);
  199365. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199366. setrlimit (RLIMIT_NOFILE, &lim);
  199367. }
  199368. }
  199369. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199370. {
  199371. return MacOSX;
  199372. }
  199373. const String SystemStats::getOperatingSystemName() throw()
  199374. {
  199375. return "Mac OS X";
  199376. }
  199377. bool SystemStats::isOperatingSystem64Bit() throw()
  199378. {
  199379. #if JUCE_64BIT
  199380. return true;
  199381. #else
  199382. //xxx not sure how to find this out?..
  199383. return false;
  199384. #endif
  199385. }
  199386. int SystemStats::getMemorySizeInMegabytes() throw()
  199387. {
  199388. uint64 mem = 0;
  199389. size_t memSize = sizeof (mem);
  199390. int mib[] = { CTL_HW, HW_MEMSIZE };
  199391. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199392. return (int) (mem / (1024 * 1024));
  199393. }
  199394. bool SystemStats::hasMMX() throw()
  199395. {
  199396. #if JUCE_INTEL
  199397. return SystemStatsHelpers::cpuFlags.hasMMX;
  199398. #else
  199399. return false;
  199400. #endif
  199401. }
  199402. bool SystemStats::hasSSE() throw()
  199403. {
  199404. #if JUCE_INTEL
  199405. return SystemStatsHelpers::cpuFlags.hasSSE;
  199406. #else
  199407. return false;
  199408. #endif
  199409. }
  199410. bool SystemStats::hasSSE2() throw()
  199411. {
  199412. #if JUCE_INTEL
  199413. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199414. #else
  199415. return false;
  199416. #endif
  199417. }
  199418. bool SystemStats::has3DNow() throw()
  199419. {
  199420. #if JUCE_INTEL
  199421. return SystemStatsHelpers::cpuFlags.has3DNow;
  199422. #else
  199423. return false;
  199424. #endif
  199425. }
  199426. const String SystemStats::getCpuVendor() throw()
  199427. {
  199428. #if JUCE_INTEL
  199429. char v [16];
  199430. SystemStatsHelpers::juce_getCpuVendor (v);
  199431. return String (v, 16);
  199432. #else
  199433. return String::empty;
  199434. #endif
  199435. }
  199436. int SystemStats::getCpuSpeedInMegaherz() throw()
  199437. {
  199438. uint64 speedHz = 0;
  199439. size_t speedSize = sizeof (speedHz);
  199440. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199441. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199442. #if JUCE_BIG_ENDIAN
  199443. if (speedSize == 4)
  199444. speedHz >>= 32;
  199445. #endif
  199446. return (int) (speedHz / 1000000);
  199447. }
  199448. int SystemStats::getNumCpus() throw()
  199449. {
  199450. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199451. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199452. #else
  199453. return MPProcessors();
  199454. #endif
  199455. }
  199456. const String SystemStats::getLogonName()
  199457. {
  199458. return nsStringToJuce (NSUserName());
  199459. }
  199460. const String SystemStats::getFullUserName()
  199461. {
  199462. return nsStringToJuce (NSFullUserName());
  199463. }
  199464. uint32 juce_millisecondsSinceStartup() throw()
  199465. {
  199466. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  199467. }
  199468. double Time::getMillisecondCounterHiRes() throw()
  199469. {
  199470. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  199471. }
  199472. int64 Time::getHighResolutionTicks() throw()
  199473. {
  199474. return (int64) mach_absolute_time();
  199475. }
  199476. int64 Time::getHighResolutionTicksPerSecond() throw()
  199477. {
  199478. return SystemStatsHelpers::highResTimerFrequency;
  199479. }
  199480. int64 SystemStats::getClockCycleCounter() throw()
  199481. {
  199482. return (int64) mach_absolute_time();
  199483. }
  199484. bool Time::setSystemTimeToThisTime() const throw()
  199485. {
  199486. jassertfalse
  199487. return false;
  199488. }
  199489. int SystemStats::getPageSize() throw()
  199490. {
  199491. return (int) NSPageSize();
  199492. }
  199493. void PlatformUtilities::fpuReset()
  199494. {
  199495. }
  199496. #endif
  199497. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  199498. /*** Start of inlined file: juce_mac_Network.mm ***/
  199499. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199500. // compiled on its own).
  199501. #if JUCE_INCLUDED_FILE
  199502. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  199503. {
  199504. #ifndef IFT_ETHER
  199505. #define IFT_ETHER 6
  199506. #endif
  199507. ifaddrs* addrs = 0;
  199508. int numResults = 0;
  199509. if (getifaddrs (&addrs) == 0)
  199510. {
  199511. const ifaddrs* cursor = addrs;
  199512. while (cursor != 0 && numResults < maxNum)
  199513. {
  199514. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  199515. if (sto->ss_family == AF_LINK)
  199516. {
  199517. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  199518. if (sadd->sdl_type == IFT_ETHER)
  199519. {
  199520. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  199521. uint64 a = 0;
  199522. for (int i = 6; --i >= 0;)
  199523. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  199524. *addresses++ = (int64) a;
  199525. ++numResults;
  199526. }
  199527. }
  199528. cursor = cursor->ifa_next;
  199529. }
  199530. freeifaddrs (addrs);
  199531. }
  199532. return numResults;
  199533. }
  199534. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  199535. const String& emailSubject,
  199536. const String& bodyText,
  199537. const StringArray& filesToAttach)
  199538. {
  199539. #if JUCE_IPHONE
  199540. //xxx probably need to use MFMailComposeViewController
  199541. jassertfalse
  199542. return false;
  199543. #else
  199544. const ScopedAutoReleasePool pool;
  199545. String script;
  199546. script << "tell application \"Mail\"\r\n"
  199547. "set newMessage to make new outgoing message with properties {subject:\""
  199548. << emailSubject.replace ("\"", "\\\"")
  199549. << "\", content:\""
  199550. << bodyText.replace ("\"", "\\\"")
  199551. << "\" & return & return}\r\n"
  199552. "tell newMessage\r\n"
  199553. "set visible to true\r\n"
  199554. "set sender to \"sdfsdfsdfewf\"\r\n"
  199555. "make new to recipient at end of to recipients with properties {address:\""
  199556. << targetEmailAddress
  199557. << "\"}\r\n";
  199558. for (int i = 0; i < filesToAttach.size(); ++i)
  199559. {
  199560. script << "tell content\r\n"
  199561. "make new attachment with properties {file name:\""
  199562. << filesToAttach[i].replace ("\"", "\\\"")
  199563. << "\"} at after the last paragraph\r\n"
  199564. "end tell\r\n";
  199565. }
  199566. script << "end tell\r\n"
  199567. "end tell\r\n";
  199568. NSAppleScript* s = [[NSAppleScript alloc]
  199569. initWithSource: juceStringToNS (script)];
  199570. NSDictionary* error = 0;
  199571. const bool ok = [s executeAndReturnError: &error] != nil;
  199572. [s release];
  199573. return ok;
  199574. #endif
  199575. }
  199576. END_JUCE_NAMESPACE
  199577. using namespace JUCE_NAMESPACE;
  199578. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  199579. @interface JuceURLConnection : NSObject
  199580. {
  199581. @public
  199582. NSURLRequest* request;
  199583. NSURLConnection* connection;
  199584. NSMutableData* data;
  199585. Thread* runLoopThread;
  199586. bool initialised, hasFailed, hasFinished;
  199587. int position;
  199588. int64 contentLength;
  199589. NSLock* dataLock;
  199590. }
  199591. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  199592. - (void) dealloc;
  199593. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  199594. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  199595. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  199596. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  199597. - (BOOL) isOpen;
  199598. - (int) read: (char*) dest numBytes: (int) num;
  199599. - (int) readPosition;
  199600. - (void) stop;
  199601. - (void) createConnection;
  199602. @end
  199603. class JuceURLConnectionMessageThread : public Thread
  199604. {
  199605. JuceURLConnection* owner;
  199606. public:
  199607. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  199608. : Thread ("http connection"),
  199609. owner (owner_)
  199610. {
  199611. }
  199612. ~JuceURLConnectionMessageThread()
  199613. {
  199614. stopThread (10000);
  199615. }
  199616. void run()
  199617. {
  199618. [owner createConnection];
  199619. while (! threadShouldExit())
  199620. {
  199621. const ScopedAutoReleasePool pool;
  199622. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  199623. }
  199624. }
  199625. };
  199626. @implementation JuceURLConnection
  199627. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  199628. withCallback: (URL::OpenStreamProgressCallback*) callback
  199629. withContext: (void*) context;
  199630. {
  199631. [super init];
  199632. request = req;
  199633. [request retain];
  199634. data = [[NSMutableData data] retain];
  199635. dataLock = [[NSLock alloc] init];
  199636. connection = 0;
  199637. initialised = false;
  199638. hasFailed = false;
  199639. hasFinished = false;
  199640. contentLength = -1;
  199641. runLoopThread = new JuceURLConnectionMessageThread (self);
  199642. runLoopThread->startThread();
  199643. while (runLoopThread->isThreadRunning() && ! initialised)
  199644. {
  199645. if (callback != 0)
  199646. callback (context, -1, (int) [[request HTTPBody] length]);
  199647. Thread::sleep (1);
  199648. }
  199649. return self;
  199650. }
  199651. - (void) dealloc
  199652. {
  199653. [self stop];
  199654. deleteAndZero (runLoopThread);
  199655. [connection release];
  199656. [data release];
  199657. [dataLock release];
  199658. [request release];
  199659. [super dealloc];
  199660. }
  199661. - (void) createConnection
  199662. {
  199663. connection = [[NSURLConnection alloc] initWithRequest: request
  199664. delegate: [self retain]];
  199665. if (connection == nil)
  199666. runLoopThread->signalThreadShouldExit();
  199667. }
  199668. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  199669. {
  199670. [dataLock lock];
  199671. [data setLength: 0];
  199672. [dataLock unlock];
  199673. initialised = true;
  199674. contentLength = [response expectedContentLength];
  199675. }
  199676. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  199677. {
  199678. DBG (nsStringToJuce ([error description]));
  199679. hasFailed = true;
  199680. initialised = true;
  199681. if (runLoopThread != 0)
  199682. runLoopThread->signalThreadShouldExit();
  199683. }
  199684. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  199685. {
  199686. [dataLock lock];
  199687. [data appendData: newData];
  199688. [dataLock unlock];
  199689. initialised = true;
  199690. }
  199691. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  199692. {
  199693. hasFinished = true;
  199694. initialised = true;
  199695. if (runLoopThread != 0)
  199696. runLoopThread->signalThreadShouldExit();
  199697. }
  199698. - (BOOL) isOpen
  199699. {
  199700. return connection != 0 && ! hasFailed;
  199701. }
  199702. - (int) readPosition
  199703. {
  199704. return position;
  199705. }
  199706. - (int) read: (char*) dest numBytes: (int) numNeeded
  199707. {
  199708. int numDone = 0;
  199709. while (numNeeded > 0)
  199710. {
  199711. int available = jmin (numNeeded, (int) [data length]);
  199712. if (available > 0)
  199713. {
  199714. [dataLock lock];
  199715. [data getBytes: dest length: available];
  199716. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  199717. [dataLock unlock];
  199718. numDone += available;
  199719. numNeeded -= available;
  199720. dest += available;
  199721. }
  199722. else
  199723. {
  199724. if (hasFailed || hasFinished)
  199725. break;
  199726. Thread::sleep (1);
  199727. }
  199728. }
  199729. position += numDone;
  199730. return numDone;
  199731. }
  199732. - (void) stop
  199733. {
  199734. [connection cancel];
  199735. if (runLoopThread != 0)
  199736. runLoopThread->stopThread (10000);
  199737. }
  199738. @end
  199739. BEGIN_JUCE_NAMESPACE
  199740. void* juce_openInternetFile (const String& url,
  199741. const String& headers,
  199742. const MemoryBlock& postData,
  199743. const bool isPost,
  199744. URL::OpenStreamProgressCallback* callback,
  199745. void* callbackContext,
  199746. int timeOutMs)
  199747. {
  199748. const ScopedAutoReleasePool pool;
  199749. NSMutableURLRequest* req = [NSMutableURLRequest
  199750. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  199751. cachePolicy: NSURLRequestUseProtocolCachePolicy
  199752. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  199753. if (req == nil)
  199754. return 0;
  199755. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  199756. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  199757. StringArray headerLines;
  199758. headerLines.addLines (headers);
  199759. headerLines.removeEmptyStrings (true);
  199760. for (int i = 0; i < headerLines.size(); ++i)
  199761. {
  199762. const String key (headerLines[i].upToFirstOccurrenceOf (":", false, false).trim());
  199763. const String value (headerLines[i].fromFirstOccurrenceOf (":", false, false).trim());
  199764. if (key.isNotEmpty() && value.isNotEmpty())
  199765. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  199766. }
  199767. if (isPost && postData.getSize() > 0)
  199768. {
  199769. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  199770. length: postData.getSize()]];
  199771. }
  199772. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  199773. withCallback: callback
  199774. withContext: callbackContext];
  199775. if ([s isOpen])
  199776. return s;
  199777. [s release];
  199778. return 0;
  199779. }
  199780. void juce_closeInternetFile (void* handle)
  199781. {
  199782. JuceURLConnection* const s = (JuceURLConnection*) handle;
  199783. if (s != 0)
  199784. {
  199785. const ScopedAutoReleasePool pool;
  199786. [s stop];
  199787. [s release];
  199788. }
  199789. }
  199790. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  199791. {
  199792. JuceURLConnection* const s = (JuceURLConnection*) handle;
  199793. if (s != 0)
  199794. {
  199795. const ScopedAutoReleasePool pool;
  199796. return [s read: (char*) buffer numBytes: bytesToRead];
  199797. }
  199798. return 0;
  199799. }
  199800. int64 juce_getInternetFileContentLength (void* handle)
  199801. {
  199802. JuceURLConnection* const s = (JuceURLConnection*) handle;
  199803. if (s != 0)
  199804. return s->contentLength;
  199805. return -1;
  199806. }
  199807. int juce_seekInInternetFile (void* handle, int newPosition)
  199808. {
  199809. JuceURLConnection* const s = (JuceURLConnection*) handle;
  199810. if (s != 0)
  199811. return [s readPosition];
  199812. return 0;
  199813. }
  199814. #endif
  199815. /*** End of inlined file: juce_mac_Network.mm ***/
  199816. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  199817. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199818. // compiled on its own).
  199819. #if JUCE_INCLUDED_FILE
  199820. struct NamedPipeInternal
  199821. {
  199822. String pipeInName, pipeOutName;
  199823. int pipeIn, pipeOut;
  199824. bool volatile createdPipe, blocked, stopReadOperation;
  199825. static void signalHandler (int) {}
  199826. };
  199827. void NamedPipe::cancelPendingReads()
  199828. {
  199829. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  199830. {
  199831. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  199832. intern->stopReadOperation = true;
  199833. char buffer [1] = { 0 };
  199834. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  199835. (void) bytesWritten;
  199836. int timeout = 2000;
  199837. while (intern->blocked && --timeout >= 0)
  199838. Thread::sleep (2);
  199839. intern->stopReadOperation = false;
  199840. }
  199841. }
  199842. void NamedPipe::close()
  199843. {
  199844. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  199845. if (intern != 0)
  199846. {
  199847. internal = 0;
  199848. if (intern->pipeIn != -1)
  199849. ::close (intern->pipeIn);
  199850. if (intern->pipeOut != -1)
  199851. ::close (intern->pipeOut);
  199852. if (intern->createdPipe)
  199853. {
  199854. unlink (intern->pipeInName.toUTF8());
  199855. unlink (intern->pipeOutName.toUTF8());
  199856. }
  199857. delete intern;
  199858. }
  199859. }
  199860. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  199861. {
  199862. close();
  199863. NamedPipeInternal* const intern = new NamedPipeInternal();
  199864. internal = intern;
  199865. intern->createdPipe = createPipe;
  199866. intern->blocked = false;
  199867. intern->stopReadOperation = false;
  199868. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  199869. siginterrupt (SIGPIPE, 1);
  199870. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  199871. intern->pipeInName = pipePath + "_in";
  199872. intern->pipeOutName = pipePath + "_out";
  199873. intern->pipeIn = -1;
  199874. intern->pipeOut = -1;
  199875. if (createPipe)
  199876. {
  199877. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  199878. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  199879. {
  199880. delete intern;
  199881. internal = 0;
  199882. return false;
  199883. }
  199884. }
  199885. return true;
  199886. }
  199887. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  199888. {
  199889. int bytesRead = -1;
  199890. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  199891. if (intern != 0)
  199892. {
  199893. intern->blocked = true;
  199894. if (intern->pipeIn == -1)
  199895. {
  199896. if (intern->createdPipe)
  199897. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  199898. else
  199899. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  199900. if (intern->pipeIn == -1)
  199901. {
  199902. intern->blocked = false;
  199903. return -1;
  199904. }
  199905. }
  199906. bytesRead = 0;
  199907. char* p = (char*) destBuffer;
  199908. while (bytesRead < maxBytesToRead)
  199909. {
  199910. const int bytesThisTime = maxBytesToRead - bytesRead;
  199911. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  199912. if (numRead <= 0 || intern->stopReadOperation)
  199913. {
  199914. bytesRead = -1;
  199915. break;
  199916. }
  199917. bytesRead += numRead;
  199918. p += bytesRead;
  199919. }
  199920. intern->blocked = false;
  199921. }
  199922. return bytesRead;
  199923. }
  199924. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  199925. {
  199926. int bytesWritten = -1;
  199927. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  199928. if (intern != 0)
  199929. {
  199930. if (intern->pipeOut == -1)
  199931. {
  199932. if (intern->createdPipe)
  199933. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  199934. else
  199935. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  199936. if (intern->pipeOut == -1)
  199937. {
  199938. return -1;
  199939. }
  199940. }
  199941. const char* p = (const char*) sourceBuffer;
  199942. bytesWritten = 0;
  199943. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  199944. while (bytesWritten < numBytesToWrite
  199945. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  199946. {
  199947. const int bytesThisTime = numBytesToWrite - bytesWritten;
  199948. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  199949. if (numWritten <= 0)
  199950. {
  199951. bytesWritten = -1;
  199952. break;
  199953. }
  199954. bytesWritten += numWritten;
  199955. p += bytesWritten;
  199956. }
  199957. }
  199958. return bytesWritten;
  199959. }
  199960. #endif
  199961. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  199962. /*** Start of inlined file: juce_mac_Threads.mm ***/
  199963. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199964. // compiled on its own).
  199965. #if JUCE_INCLUDED_FILE
  199966. void JUCE_API juce_threadEntryPoint (void*);
  199967. void* threadEntryProc (void* userData)
  199968. {
  199969. const ScopedAutoReleasePool pool;
  199970. juce_threadEntryPoint (userData);
  199971. return 0;
  199972. }
  199973. void* juce_createThread (void* userData)
  199974. {
  199975. pthread_t handle = 0;
  199976. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  199977. {
  199978. pthread_detach (handle);
  199979. return (void*) handle;
  199980. }
  199981. return 0;
  199982. }
  199983. void juce_killThread (void* handle)
  199984. {
  199985. if (handle != 0)
  199986. pthread_cancel ((pthread_t) handle);
  199987. }
  199988. void juce_setCurrentThreadName (const String& /*name*/)
  199989. {
  199990. }
  199991. bool juce_setThreadPriority (void* handle, int priority)
  199992. {
  199993. if (handle == 0)
  199994. handle = (void*) pthread_self();
  199995. struct sched_param param;
  199996. int policy;
  199997. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  199998. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  199999. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200000. }
  200001. Thread::ThreadID Thread::getCurrentThreadId()
  200002. {
  200003. return static_cast <ThreadID> (pthread_self());
  200004. }
  200005. void Thread::yield()
  200006. {
  200007. sched_yield();
  200008. }
  200009. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200010. {
  200011. // xxx
  200012. jassertfalse
  200013. }
  200014. bool Process::isForegroundProcess()
  200015. {
  200016. #if JUCE_MAC
  200017. return [NSApp isActive];
  200018. #else
  200019. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200020. #endif
  200021. }
  200022. void Process::raisePrivilege()
  200023. {
  200024. jassertfalse
  200025. }
  200026. void Process::lowerPrivilege()
  200027. {
  200028. jassertfalse
  200029. }
  200030. void Process::terminate()
  200031. {
  200032. exit (0);
  200033. }
  200034. void Process::setPriority (ProcessPriority p)
  200035. {
  200036. // xxx
  200037. }
  200038. #endif
  200039. /*** End of inlined file: juce_mac_Threads.mm ***/
  200040. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200041. CriticalSection::CriticalSection() throw()
  200042. {
  200043. pthread_mutexattr_t atts;
  200044. pthread_mutexattr_init (&atts);
  200045. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200046. pthread_mutex_init (&internal, &atts);
  200047. }
  200048. CriticalSection::~CriticalSection() throw()
  200049. {
  200050. pthread_mutex_destroy (&internal);
  200051. }
  200052. void CriticalSection::enter() const throw()
  200053. {
  200054. pthread_mutex_lock (&internal);
  200055. }
  200056. bool CriticalSection::tryEnter() const throw()
  200057. {
  200058. return pthread_mutex_trylock (&internal) == 0;
  200059. }
  200060. void CriticalSection::exit() const throw()
  200061. {
  200062. pthread_mutex_unlock (&internal);
  200063. }
  200064. class WaitableEventImpl
  200065. {
  200066. public:
  200067. WaitableEventImpl (const bool manualReset_)
  200068. : triggered (false),
  200069. manualReset (manualReset_)
  200070. {
  200071. pthread_cond_init (&condition, 0);
  200072. pthread_mutex_init (&mutex, 0);
  200073. }
  200074. ~WaitableEventImpl()
  200075. {
  200076. pthread_cond_destroy (&condition);
  200077. pthread_mutex_destroy (&mutex);
  200078. }
  200079. bool wait (const int timeOutMillisecs) throw()
  200080. {
  200081. pthread_mutex_lock (&mutex);
  200082. if (! triggered)
  200083. {
  200084. if (timeOutMillisecs < 0)
  200085. {
  200086. do
  200087. {
  200088. pthread_cond_wait (&condition, &mutex);
  200089. }
  200090. while (! triggered);
  200091. }
  200092. else
  200093. {
  200094. struct timeval now;
  200095. gettimeofday (&now, 0);
  200096. struct timespec time;
  200097. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  200098. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200099. if (time.tv_nsec >= 1000000000)
  200100. {
  200101. time.tv_nsec -= 1000000000;
  200102. time.tv_sec++;
  200103. }
  200104. do
  200105. {
  200106. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  200107. {
  200108. pthread_mutex_unlock (&mutex);
  200109. return false;
  200110. }
  200111. }
  200112. while (! triggered);
  200113. }
  200114. }
  200115. if (! manualReset)
  200116. triggered = false;
  200117. pthread_mutex_unlock (&mutex);
  200118. return true;
  200119. }
  200120. void signal() throw()
  200121. {
  200122. pthread_mutex_lock (&mutex);
  200123. triggered = true;
  200124. pthread_cond_broadcast (&condition);
  200125. pthread_mutex_unlock (&mutex);
  200126. }
  200127. void reset() throw()
  200128. {
  200129. pthread_mutex_lock (&mutex);
  200130. triggered = false;
  200131. pthread_mutex_unlock (&mutex);
  200132. }
  200133. private:
  200134. pthread_cond_t condition;
  200135. pthread_mutex_t mutex;
  200136. bool triggered;
  200137. const bool manualReset;
  200138. WaitableEventImpl (const WaitableEventImpl&);
  200139. WaitableEventImpl& operator= (const WaitableEventImpl&);
  200140. };
  200141. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  200142. : internal (new WaitableEventImpl (manualReset))
  200143. {
  200144. }
  200145. WaitableEvent::~WaitableEvent() throw()
  200146. {
  200147. delete static_cast <WaitableEventImpl*> (internal);
  200148. }
  200149. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200150. {
  200151. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  200152. }
  200153. void WaitableEvent::signal() const throw()
  200154. {
  200155. static_cast <WaitableEventImpl*> (internal)->signal();
  200156. }
  200157. void WaitableEvent::reset() const throw()
  200158. {
  200159. static_cast <WaitableEventImpl*> (internal)->reset();
  200160. }
  200161. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200162. {
  200163. struct timespec time;
  200164. time.tv_sec = millisecs / 1000;
  200165. time.tv_nsec = (millisecs % 1000) * 1000000;
  200166. nanosleep (&time, 0);
  200167. }
  200168. const juce_wchar File::separator = '/';
  200169. const String File::separatorString ("/");
  200170. const File File::getCurrentWorkingDirectory()
  200171. {
  200172. HeapBlock<char> heapBuffer;
  200173. char localBuffer [1024];
  200174. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200175. int bufferSize = 4096;
  200176. while (cwd == 0 && errno == ERANGE)
  200177. {
  200178. heapBuffer.malloc (bufferSize);
  200179. cwd = getcwd (heapBuffer, bufferSize - 1);
  200180. bufferSize += 1024;
  200181. }
  200182. return File (String::fromUTF8 (cwd));
  200183. }
  200184. bool File::setAsCurrentWorkingDirectory() const
  200185. {
  200186. return chdir (getFullPathName().toUTF8()) == 0;
  200187. }
  200188. static bool juce_stat (const String& fileName, struct stat& info)
  200189. {
  200190. return fileName.isNotEmpty()
  200191. && (stat (fileName.toUTF8(), &info) == 0);
  200192. }
  200193. bool File::isDirectory() const
  200194. {
  200195. struct stat info;
  200196. return fullPath.isEmpty()
  200197. || (juce_stat (fullPath, info) && ((info.st_mode & S_IFDIR) != 0));
  200198. }
  200199. bool File::exists() const
  200200. {
  200201. return fullPath.isNotEmpty()
  200202. && access (fullPath.toUTF8(), F_OK) == 0;
  200203. }
  200204. bool File::existsAsFile() const
  200205. {
  200206. return exists() && ! isDirectory();
  200207. }
  200208. int64 File::getSize() const
  200209. {
  200210. struct stat info;
  200211. return juce_stat (fullPath, info) ? info.st_size : 0;
  200212. }
  200213. bool File::hasWriteAccess() const
  200214. {
  200215. if (exists())
  200216. return access (fullPath.toUTF8(), W_OK) == 0;
  200217. if ((! isDirectory()) && fullPath.containsChar (separator))
  200218. return getParentDirectory().hasWriteAccess();
  200219. return false;
  200220. }
  200221. bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const
  200222. {
  200223. struct stat info;
  200224. const int res = stat (fullPath.toUTF8(), &info);
  200225. if (res != 0)
  200226. return false;
  200227. info.st_mode &= 0777; // Just permissions
  200228. if (shouldBeReadOnly)
  200229. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  200230. else
  200231. // Give everybody write permission?
  200232. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  200233. return chmod (fullPath.toUTF8(), info.st_mode) == 0;
  200234. }
  200235. void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const
  200236. {
  200237. modificationTime = 0;
  200238. accessTime = 0;
  200239. creationTime = 0;
  200240. struct stat info;
  200241. const int res = stat (fullPath.toUTF8(), &info);
  200242. if (res == 0)
  200243. {
  200244. modificationTime = (int64) info.st_mtime * 1000;
  200245. accessTime = (int64) info.st_atime * 1000;
  200246. creationTime = (int64) info.st_ctime * 1000;
  200247. }
  200248. }
  200249. bool File::setFileTimesInternal (int64 modificationTime, int64 accessTime, int64 creationTime) const
  200250. {
  200251. struct utimbuf times;
  200252. times.actime = (time_t) (accessTime / 1000);
  200253. times.modtime = (time_t) (modificationTime / 1000);
  200254. return utime (fullPath.toUTF8(), &times) == 0;
  200255. }
  200256. bool File::deleteFile() const
  200257. {
  200258. if (! exists())
  200259. return true;
  200260. else if (isDirectory())
  200261. return rmdir (fullPath.toUTF8()) == 0;
  200262. else
  200263. return remove (fullPath.toUTF8()) == 0;
  200264. }
  200265. bool File::moveInternal (const File& dest) const
  200266. {
  200267. if (rename (fullPath.toUTF8(), dest.getFullPathName().toUTF8()) == 0)
  200268. return true;
  200269. if (hasWriteAccess() && copyInternal (dest))
  200270. {
  200271. if (deleteFile())
  200272. return true;
  200273. dest.deleteFile();
  200274. }
  200275. return false;
  200276. }
  200277. void File::createDirectoryInternal (const String& fileName) const
  200278. {
  200279. mkdir (fileName.toUTF8(), 0777);
  200280. }
  200281. void* juce_fileOpen (const File& file, bool forWriting)
  200282. {
  200283. int flags = O_RDONLY;
  200284. if (forWriting)
  200285. {
  200286. if (file.exists())
  200287. {
  200288. const int f = open (file.getFullPathName().toUTF8(), O_RDWR, 00644);
  200289. if (f != -1)
  200290. lseek (f, 0, SEEK_END);
  200291. return (void*) f;
  200292. }
  200293. else
  200294. {
  200295. flags = O_RDWR + O_CREAT;
  200296. }
  200297. }
  200298. return (void*) open (file.getFullPathName().toUTF8(), flags, 00644);
  200299. }
  200300. void juce_fileClose (void* handle)
  200301. {
  200302. if (handle != 0)
  200303. close ((int) (pointer_sized_int) handle);
  200304. }
  200305. int juce_fileRead (void* handle, void* buffer, int size)
  200306. {
  200307. if (handle != 0)
  200308. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  200309. return 0;
  200310. }
  200311. int juce_fileWrite (void* handle, const void* buffer, int size)
  200312. {
  200313. if (handle != 0)
  200314. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200315. return 0;
  200316. }
  200317. int64 juce_fileSetPosition (void* handle, int64 pos)
  200318. {
  200319. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200320. return pos;
  200321. return -1;
  200322. }
  200323. int64 FileOutputStream::getPositionInternal() const
  200324. {
  200325. if (fileHandle != 0)
  200326. return lseek ((int) (pointer_sized_int) fileHandle, 0, SEEK_CUR);
  200327. return -1;
  200328. }
  200329. void FileOutputStream::flushInternal()
  200330. {
  200331. if (fileHandle != 0)
  200332. fsync ((int) (pointer_sized_int) fileHandle);
  200333. }
  200334. const File juce_getExecutableFile()
  200335. {
  200336. Dl_info exeInfo;
  200337. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200338. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  200339. }
  200340. // if this file doesn't exist, find a parent of it that does..
  200341. static bool juce_doStatFS (File f, struct statfs& result)
  200342. {
  200343. for (int i = 5; --i >= 0;)
  200344. {
  200345. if (f.exists())
  200346. break;
  200347. f = f.getParentDirectory();
  200348. }
  200349. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200350. }
  200351. int64 File::getBytesFreeOnVolume() const
  200352. {
  200353. struct statfs buf;
  200354. if (juce_doStatFS (*this, buf))
  200355. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200356. return 0;
  200357. }
  200358. int64 File::getVolumeTotalSize() const
  200359. {
  200360. struct statfs buf;
  200361. if (juce_doStatFS (*this, buf))
  200362. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200363. return 0;
  200364. }
  200365. const String File::getVolumeLabel() const
  200366. {
  200367. #if JUCE_MAC
  200368. struct VolAttrBuf
  200369. {
  200370. u_int32_t length;
  200371. attrreference_t mountPointRef;
  200372. char mountPointSpace [MAXPATHLEN];
  200373. } attrBuf;
  200374. struct attrlist attrList;
  200375. zerostruct (attrList);
  200376. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200377. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200378. File f (*this);
  200379. for (;;)
  200380. {
  200381. if (getattrlist (f.getFullPathName().toUTF8(), &attrList, &attrBuf, sizeof (attrBuf), 0) == 0)
  200382. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200383. (int) attrBuf.mountPointRef.attr_length);
  200384. const File parent (f.getParentDirectory());
  200385. if (f == parent)
  200386. break;
  200387. f = parent;
  200388. }
  200389. #endif
  200390. return String::empty;
  200391. }
  200392. int File::getVolumeSerialNumber() const
  200393. {
  200394. return 0; // xxx
  200395. }
  200396. void juce_runSystemCommand (const String& command)
  200397. {
  200398. int result = system (command.toUTF8());
  200399. (void) result;
  200400. }
  200401. const String juce_getOutputFromCommand (const String& command)
  200402. {
  200403. // slight bodge here, as we just pipe the output into a temp file and read it...
  200404. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200405. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200406. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200407. String result (tempFile.loadFileAsString());
  200408. tempFile.deleteFile();
  200409. return result;
  200410. }
  200411. class InterProcessLock::Pimpl
  200412. {
  200413. public:
  200414. Pimpl (const String& name, const int timeOutMillisecs)
  200415. : handle (0), refCount (1)
  200416. {
  200417. #if JUCE_MAC
  200418. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200419. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  200420. #else
  200421. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200422. #endif
  200423. temp.create();
  200424. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200425. if (handle != 0)
  200426. {
  200427. struct flock fl;
  200428. zerostruct (fl);
  200429. fl.l_whence = SEEK_SET;
  200430. fl.l_type = F_WRLCK;
  200431. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200432. for (;;)
  200433. {
  200434. const int result = fcntl (handle, F_SETLK, &fl);
  200435. if (result >= 0)
  200436. return;
  200437. if (errno != EINTR)
  200438. {
  200439. if (timeOutMillisecs == 0
  200440. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200441. break;
  200442. Thread::sleep (10);
  200443. }
  200444. }
  200445. }
  200446. closeFile();
  200447. }
  200448. ~Pimpl()
  200449. {
  200450. closeFile();
  200451. }
  200452. void closeFile()
  200453. {
  200454. if (handle != 0)
  200455. {
  200456. struct flock fl;
  200457. zerostruct (fl);
  200458. fl.l_whence = SEEK_SET;
  200459. fl.l_type = F_UNLCK;
  200460. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  200461. {}
  200462. close (handle);
  200463. handle = 0;
  200464. }
  200465. }
  200466. int handle, refCount;
  200467. };
  200468. InterProcessLock::InterProcessLock (const String& name_)
  200469. : name (name_)
  200470. {
  200471. }
  200472. InterProcessLock::~InterProcessLock()
  200473. {
  200474. }
  200475. bool InterProcessLock::enter (const int timeOutMillisecs)
  200476. {
  200477. const ScopedLock sl (lock);
  200478. if (pimpl == 0)
  200479. {
  200480. pimpl = new Pimpl (name, timeOutMillisecs);
  200481. if (pimpl->handle == 0)
  200482. pimpl = 0;
  200483. }
  200484. else
  200485. {
  200486. pimpl->refCount++;
  200487. }
  200488. return pimpl != 0;
  200489. }
  200490. void InterProcessLock::exit()
  200491. {
  200492. const ScopedLock sl (lock);
  200493. // Trying to release the lock too many times!
  200494. jassert (pimpl != 0);
  200495. if (pimpl != 0 && --(pimpl->refCount) == 0)
  200496. pimpl = 0;
  200497. }
  200498. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200499. /*** Start of inlined file: juce_mac_Files.mm ***/
  200500. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200501. // compiled on its own).
  200502. #if JUCE_INCLUDED_FILE
  200503. bool File::copyInternal (const File& dest) const
  200504. {
  200505. const ScopedAutoReleasePool pool;
  200506. NSFileManager* fm = [NSFileManager defaultManager];
  200507. return [fm fileExistsAtPath: juceStringToNS (fullPath)]
  200508. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  200509. && [fm copyItemAtPath: juceStringToNS (fullPath)
  200510. toPath: juceStringToNS (dest.getFullPathName())
  200511. error: nil];
  200512. #else
  200513. && [fm copyPath: juceStringToNS (fullPath)
  200514. toPath: juceStringToNS (dest.getFullPathName())
  200515. handler: nil];
  200516. #endif
  200517. }
  200518. void File::findFileSystemRoots (Array<File>& destArray)
  200519. {
  200520. destArray.add (File ("/"));
  200521. }
  200522. static bool isFileOnDriveType (const File& f, const char** types)
  200523. {
  200524. struct statfs buf;
  200525. if (juce_doStatFS (f, buf))
  200526. {
  200527. const String type (buf.f_fstypename);
  200528. while (*types != 0)
  200529. if (type.equalsIgnoreCase (*types++))
  200530. return true;
  200531. }
  200532. return false;
  200533. }
  200534. bool File::isOnCDRomDrive() const
  200535. {
  200536. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  200537. return isFileOnDriveType (*this, (const char**) cdTypes);
  200538. }
  200539. bool File::isOnHardDisk() const
  200540. {
  200541. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  200542. return ! (isOnCDRomDrive() || isFileOnDriveType (*this, (const char**) nonHDTypes));
  200543. }
  200544. bool File::isOnRemovableDrive() const
  200545. {
  200546. #if JUCE_IPHONE
  200547. return false; // xxx is this possible?
  200548. #else
  200549. const ScopedAutoReleasePool pool;
  200550. BOOL removable = false;
  200551. [[NSWorkspace sharedWorkspace]
  200552. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  200553. isRemovable: &removable
  200554. isWritable: nil
  200555. isUnmountable: nil
  200556. description: nil
  200557. type: nil];
  200558. return removable;
  200559. #endif
  200560. }
  200561. static bool juce_isHiddenFile (const String& path)
  200562. {
  200563. #if JUCE_IPHONE
  200564. return File (path).getFileName().startsWithChar ('.');
  200565. #else
  200566. FSRef ref;
  200567. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  200568. return false;
  200569. FSCatalogInfo info;
  200570. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  200571. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  200572. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200573. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200574. #endif
  200575. }
  200576. bool File::isHidden() const
  200577. {
  200578. return juce_isHiddenFile (getFullPathName());
  200579. }
  200580. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  200581. const File File::getSpecialLocation (const SpecialLocationType type)
  200582. {
  200583. const ScopedAutoReleasePool pool;
  200584. String resultPath;
  200585. switch (type)
  200586. {
  200587. case userHomeDirectory:
  200588. resultPath = nsStringToJuce (NSHomeDirectory());
  200589. break;
  200590. case userDocumentsDirectory:
  200591. resultPath = "~/Documents";
  200592. break;
  200593. case userDesktopDirectory:
  200594. resultPath = "~/Desktop";
  200595. break;
  200596. case userApplicationDataDirectory:
  200597. resultPath = "~/Library";
  200598. break;
  200599. case commonApplicationDataDirectory:
  200600. resultPath = "/Library";
  200601. break;
  200602. case globalApplicationsDirectory:
  200603. resultPath = "/Applications";
  200604. break;
  200605. case userMusicDirectory:
  200606. resultPath = "~/Music";
  200607. break;
  200608. case userMoviesDirectory:
  200609. resultPath = "~/Movies";
  200610. break;
  200611. case tempDirectory:
  200612. {
  200613. File tmp ("~/Library/Caches/" + juce_getExecutableFile().getFileNameWithoutExtension());
  200614. tmp.createDirectory();
  200615. return tmp.getFullPathName();
  200616. }
  200617. case invokedExecutableFile:
  200618. if (juce_Argv0 != 0)
  200619. return File (String::fromUTF8 (juce_Argv0));
  200620. // deliberate fall-through...
  200621. case currentExecutableFile:
  200622. return juce_getExecutableFile();
  200623. case currentApplicationFile:
  200624. {
  200625. const File exe (juce_getExecutableFile());
  200626. const File parent (exe.getParentDirectory());
  200627. return parent.getFullPathName().endsWithIgnoreCase ("Contents/MacOS")
  200628. ? parent.getParentDirectory().getParentDirectory()
  200629. : exe;
  200630. }
  200631. default:
  200632. jassertfalse // unknown type?
  200633. break;
  200634. }
  200635. if (resultPath.isNotEmpty())
  200636. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  200637. return File::nonexistent;
  200638. }
  200639. const String File::getVersion() const
  200640. {
  200641. const ScopedAutoReleasePool pool;
  200642. String result;
  200643. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  200644. if (bundle != 0)
  200645. {
  200646. NSDictionary* info = [bundle infoDictionary];
  200647. if (info != 0)
  200648. {
  200649. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  200650. if (name != nil)
  200651. result = nsStringToJuce (name);
  200652. }
  200653. }
  200654. return result;
  200655. }
  200656. const File File::getLinkedTarget() const
  200657. {
  200658. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  200659. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  200660. #else
  200661. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  200662. #endif
  200663. if (dest != nil)
  200664. return File (nsStringToJuce (dest));
  200665. return *this;
  200666. }
  200667. bool File::moveToTrash() const
  200668. {
  200669. if (! exists())
  200670. return true;
  200671. #if JUCE_IPHONE
  200672. return deleteFile(); //xxx is there a trashcan on the iPhone?
  200673. #else
  200674. const ScopedAutoReleasePool pool;
  200675. NSString* p = juceStringToNS (getFullPathName());
  200676. return [[NSWorkspace sharedWorkspace]
  200677. performFileOperation: NSWorkspaceRecycleOperation
  200678. source: [p stringByDeletingLastPathComponent]
  200679. destination: @""
  200680. files: [NSArray arrayWithObject: [p lastPathComponent]]
  200681. tag: nil ];
  200682. #endif
  200683. }
  200684. class DirectoryIterator::NativeIterator::Pimpl
  200685. {
  200686. public:
  200687. Pimpl (const File& directory, const String& wildCard_)
  200688. : parentDir (File::addTrailingSeparator (directory.getFullPathName())),
  200689. wildCard (wildCard_),
  200690. enumerator (0)
  200691. {
  200692. ScopedAutoReleasePool pool;
  200693. enumerator = [[[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory.getFullPathName())] retain];
  200694. wildcardUTF8 = wildCard.toUTF8();
  200695. }
  200696. ~Pimpl()
  200697. {
  200698. [enumerator release];
  200699. }
  200700. bool next (String& filenameFound,
  200701. bool* const isDir, bool* const isHidden, int64* const fileSize,
  200702. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  200703. {
  200704. ScopedAutoReleasePool pool;
  200705. for (;;)
  200706. {
  200707. NSString* file;
  200708. if (enumerator == 0 || (file = [enumerator nextObject]) == 0)
  200709. return false;
  200710. [enumerator skipDescendents];
  200711. filenameFound = nsStringToJuce (file);
  200712. if (fnmatch (wildcardUTF8, filenameFound.toUTF8(), FNM_CASEFOLD) != 0)
  200713. continue;
  200714. const String path (parentDir + filenameFound);
  200715. if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0)
  200716. {
  200717. struct stat info;
  200718. const bool statOk = juce_stat (path, info);
  200719. if (isDir != 0) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  200720. if (fileSize != 0) *fileSize = statOk ? info.st_size : 0;
  200721. if (modTime != 0) *modTime = statOk ? (int64) info.st_mtime * 1000 : 0;
  200722. if (creationTime != 0) *creationTime = statOk ? (int64) info.st_ctime * 1000 : 0;
  200723. }
  200724. if (isHidden != 0)
  200725. *isHidden = juce_isHiddenFile (path);
  200726. if (isReadOnly != 0)
  200727. *isReadOnly = access (path.toUTF8(), W_OK) != 0;
  200728. return true;
  200729. }
  200730. }
  200731. private:
  200732. String parentDir, wildCard;
  200733. const char* wildcardUTF8;
  200734. NSDirectoryEnumerator* enumerator;
  200735. Pimpl (const Pimpl&);
  200736. Pimpl& operator= (const Pimpl&);
  200737. };
  200738. DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard)
  200739. : pimpl (new DirectoryIterator::NativeIterator::Pimpl (directory, wildCard))
  200740. {
  200741. }
  200742. DirectoryIterator::NativeIterator::~NativeIterator()
  200743. {
  200744. }
  200745. bool DirectoryIterator::NativeIterator::next (String& filenameFound,
  200746. bool* const isDir, bool* const isHidden, int64* const fileSize,
  200747. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  200748. {
  200749. return pimpl->next (filenameFound, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  200750. }
  200751. bool juce_launchExecutable (const String& pathAndArguments)
  200752. {
  200753. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  200754. const int cpid = fork();
  200755. if (cpid == 0)
  200756. {
  200757. // Child process
  200758. if (execve (argv[0], (char**) argv, 0) < 0)
  200759. exit (0);
  200760. }
  200761. else
  200762. {
  200763. if (cpid < 0)
  200764. return false;
  200765. }
  200766. return true;
  200767. }
  200768. bool PlatformUtilities::openDocument (const String& fileName, const String& parameters)
  200769. {
  200770. #if JUCE_IPHONE
  200771. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  200772. #else
  200773. const ScopedAutoReleasePool pool;
  200774. if (parameters.isEmpty())
  200775. {
  200776. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  200777. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  200778. }
  200779. bool ok = false;
  200780. FSRef ref;
  200781. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  200782. {
  200783. if (PlatformUtilities::isBundle (fileName))
  200784. {
  200785. NSMutableArray* urls = [NSMutableArray array];
  200786. StringArray docs;
  200787. docs.addTokens (parameters, true);
  200788. for (int i = 0; i < docs.size(); ++i)
  200789. [urls addObject: juceStringToNS (docs[i])];
  200790. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  200791. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  200792. options: 0
  200793. additionalEventParamDescriptor: nil
  200794. launchIdentifiers: nil];
  200795. }
  200796. else
  200797. {
  200798. ok = juce_launchExecutable ("\"" + fileName + "\" " + parameters);
  200799. }
  200800. }
  200801. return ok;
  200802. #endif
  200803. }
  200804. void File::revealToUser() const
  200805. {
  200806. #if ! JUCE_IPHONE
  200807. if (exists())
  200808. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  200809. else if (getParentDirectory().exists())
  200810. getParentDirectory().revealToUser();
  200811. #endif
  200812. }
  200813. #if ! JUCE_IPHONE
  200814. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  200815. {
  200816. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  200817. }
  200818. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  200819. {
  200820. char path [2048];
  200821. zerostruct (path);
  200822. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  200823. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  200824. return String::empty;
  200825. }
  200826. #endif
  200827. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  200828. {
  200829. const ScopedAutoReleasePool pool;
  200830. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  200831. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  200832. #else
  200833. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  200834. #endif
  200835. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  200836. return [fileDict fileHFSTypeCode];
  200837. }
  200838. bool PlatformUtilities::isBundle (const String& filename)
  200839. {
  200840. #if JUCE_IPHONE
  200841. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  200842. #else
  200843. const ScopedAutoReleasePool pool;
  200844. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  200845. #endif
  200846. }
  200847. #endif
  200848. /*** End of inlined file: juce_mac_Files.mm ***/
  200849. #if JUCE_IPHONE
  200850. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  200851. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200852. // compiled on its own).
  200853. #if JUCE_INCLUDED_FILE
  200854. static JUCEApplication* juce_intialisingApp;
  200855. END_JUCE_NAMESPACE
  200856. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  200857. {
  200858. }
  200859. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  200860. - (void) applicationWillResignActive: (UIApplication*) application;
  200861. @end
  200862. @implementation JuceAppStartupDelegate
  200863. - (void) applicationDidFinishLaunching: (UIApplication*) application
  200864. {
  200865. String dummy;
  200866. if (! juce_intialisingApp->initialiseApp (dummy))
  200867. exit (0);
  200868. }
  200869. - (void) applicationWillResignActive: (UIApplication*) application
  200870. {
  200871. JUCEApplication::shutdownAppAndClearUp();
  200872. }
  200873. @end
  200874. BEGIN_JUCE_NAMESPACE
  200875. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  200876. {
  200877. juce_intialisingApp = app;
  200878. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  200879. }
  200880. ScopedAutoReleasePool::ScopedAutoReleasePool()
  200881. {
  200882. pool = [[NSAutoreleasePool alloc] init];
  200883. }
  200884. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  200885. {
  200886. [((NSAutoreleasePool*) pool) release];
  200887. }
  200888. void PlatformUtilities::beep()
  200889. {
  200890. //xxx
  200891. //AudioServicesPlaySystemSound ();
  200892. }
  200893. void PlatformUtilities::addItemToDock (const File& file)
  200894. {
  200895. }
  200896. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  200897. END_JUCE_NAMESPACE
  200898. @interface JuceAlertBoxDelegate : NSObject
  200899. {
  200900. @public
  200901. bool clickedOk;
  200902. }
  200903. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  200904. @end
  200905. @implementation JuceAlertBoxDelegate
  200906. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  200907. {
  200908. clickedOk = (buttonIndex == 0);
  200909. alertView.hidden = true;
  200910. }
  200911. @end
  200912. BEGIN_JUCE_NAMESPACE
  200913. // (This function is used directly by other bits of code)
  200914. bool juce_iPhoneShowModalAlert (const String& title,
  200915. const String& bodyText,
  200916. NSString* okButtonText,
  200917. NSString* cancelButtonText)
  200918. {
  200919. const ScopedAutoReleasePool pool;
  200920. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  200921. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  200922. message: juceStringToNS (bodyText)
  200923. delegate: callback
  200924. cancelButtonTitle: okButtonText
  200925. otherButtonTitles: cancelButtonText, nil];
  200926. [alert retain];
  200927. [alert show];
  200928. while (! alert.hidden && alert.superview != nil)
  200929. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200930. const bool result = callback->clickedOk;
  200931. [alert release];
  200932. [callback release];
  200933. return result;
  200934. }
  200935. bool AlertWindow::showNativeDialogBox (const String& title,
  200936. const String& bodyText,
  200937. bool isOkCancel)
  200938. {
  200939. return juce_iPhoneShowModalAlert (title, bodyText,
  200940. @"OK",
  200941. isOkCancel ? @"Cancel" : nil);
  200942. }
  200943. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  200944. {
  200945. jassertfalse // no such thing on the iphone!
  200946. return false;
  200947. }
  200948. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  200949. {
  200950. jassertfalse // no such thing on the iphone!
  200951. return false;
  200952. }
  200953. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  200954. {
  200955. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  200956. }
  200957. bool Desktop::isScreenSaverEnabled() throw()
  200958. {
  200959. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  200960. }
  200961. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  200962. {
  200963. const ScopedAutoReleasePool pool;
  200964. monitorCoords.clear();
  200965. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  200966. : [[UIScreen mainScreen] bounds];
  200967. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  200968. (int) r.origin.y,
  200969. (int) r.size.width,
  200970. (int) r.size.height));
  200971. }
  200972. #endif
  200973. #endif
  200974. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  200975. #else
  200976. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  200977. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200978. // compiled on its own).
  200979. #if JUCE_INCLUDED_FILE
  200980. ScopedAutoReleasePool::ScopedAutoReleasePool()
  200981. {
  200982. pool = [[NSAutoreleasePool alloc] init];
  200983. }
  200984. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  200985. {
  200986. [((NSAutoreleasePool*) pool) release];
  200987. }
  200988. void PlatformUtilities::beep()
  200989. {
  200990. NSBeep();
  200991. }
  200992. void PlatformUtilities::addItemToDock (const File& file)
  200993. {
  200994. // check that it's not already there...
  200995. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  200996. .containsIgnoreCase (file.getFullPathName()))
  200997. {
  200998. juce_runSystemCommand ("defaults write com.apple.dock persistent-apps -array-add \"<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>"
  200999. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201000. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201001. }
  201002. }
  201003. int PlatformUtilities::getOSXMinorVersionNumber()
  201004. {
  201005. SInt32 versionMinor = 0;
  201006. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201007. (void) err;
  201008. jassert (err == noErr);
  201009. return (int) versionMinor;
  201010. }
  201011. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201012. bool AlertWindow::showNativeDialogBox (const String& title,
  201013. const String& bodyText,
  201014. bool isOkCancel)
  201015. {
  201016. const ScopedAutoReleasePool pool;
  201017. return NSRunAlertPanel (juceStringToNS (title),
  201018. juceStringToNS (bodyText),
  201019. @"Ok",
  201020. isOkCancel ? @"Cancel" : nil,
  201021. nil) == NSAlertDefaultReturn;
  201022. }
  201023. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201024. {
  201025. if (files.size() == 0)
  201026. return false;
  201027. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201028. if (draggingSource == 0)
  201029. {
  201030. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201031. return false;
  201032. }
  201033. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201034. if (sourceComp == 0)
  201035. {
  201036. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201037. return false;
  201038. }
  201039. const ScopedAutoReleasePool pool;
  201040. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201041. if (view == 0)
  201042. return false;
  201043. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201044. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201045. owner: nil];
  201046. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201047. for (int i = 0; i < files.size(); ++i)
  201048. [filesArray addObject: juceStringToNS (files[i])];
  201049. [pboard setPropertyList: filesArray
  201050. forType: NSFilenamesPboardType];
  201051. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201052. fromView: nil];
  201053. dragPosition.x -= 16;
  201054. dragPosition.y -= 16;
  201055. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201056. at: dragPosition
  201057. offset: NSMakeSize (0, 0)
  201058. event: [[view window] currentEvent]
  201059. pasteboard: pboard
  201060. source: view
  201061. slideBack: YES];
  201062. return true;
  201063. }
  201064. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201065. {
  201066. jassertfalse // not implemented!
  201067. return false;
  201068. }
  201069. bool Desktop::canUseSemiTransparentWindows() throw()
  201070. {
  201071. return true;
  201072. }
  201073. const Point<int> Desktop::getMousePosition()
  201074. {
  201075. const ScopedAutoReleasePool pool;
  201076. const NSPoint p ([NSEvent mouseLocation]);
  201077. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201078. }
  201079. void Desktop::setMousePosition (const Point<int>& newPosition)
  201080. {
  201081. // this rubbish needs to be done around the warp call, to avoid causing a
  201082. // bizarre glitch..
  201083. CGAssociateMouseAndMouseCursorPosition (false);
  201084. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201085. CGAssociateMouseAndMouseCursorPosition (true);
  201086. }
  201087. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201088. class ScreenSaverDefeater : public Timer,
  201089. public DeletedAtShutdown
  201090. {
  201091. public:
  201092. ScreenSaverDefeater() throw()
  201093. {
  201094. startTimer (10000);
  201095. timerCallback();
  201096. }
  201097. ~ScreenSaverDefeater() {}
  201098. void timerCallback()
  201099. {
  201100. if (Process::isForegroundProcess())
  201101. UpdateSystemActivity (UsrActivity);
  201102. }
  201103. };
  201104. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201105. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201106. {
  201107. if (isEnabled)
  201108. {
  201109. deleteAndZero (screenSaverDefeater);
  201110. }
  201111. else if (screenSaverDefeater == 0)
  201112. {
  201113. screenSaverDefeater = new ScreenSaverDefeater();
  201114. }
  201115. }
  201116. bool Desktop::isScreenSaverEnabled() throw()
  201117. {
  201118. return screenSaverDefeater == 0;
  201119. }
  201120. #else
  201121. static IOPMAssertionID screenSaverDisablerID = 0;
  201122. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201123. {
  201124. if (isEnabled)
  201125. {
  201126. if (screenSaverDisablerID != 0)
  201127. {
  201128. IOPMAssertionRelease (screenSaverDisablerID);
  201129. screenSaverDisablerID = 0;
  201130. }
  201131. }
  201132. else
  201133. {
  201134. if (screenSaverDisablerID == 0)
  201135. {
  201136. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201137. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201138. CFSTR ("Juce"), &screenSaverDisablerID);
  201139. #else
  201140. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201141. &screenSaverDisablerID);
  201142. #endif
  201143. }
  201144. }
  201145. }
  201146. bool Desktop::isScreenSaverEnabled() throw()
  201147. {
  201148. return screenSaverDisablerID == 0;
  201149. }
  201150. #endif
  201151. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201152. {
  201153. const ScopedAutoReleasePool pool;
  201154. monitorCoords.clear();
  201155. NSArray* screens = [NSScreen screens];
  201156. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201157. for (unsigned int i = 0; i < [screens count]; ++i)
  201158. {
  201159. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201160. NSRect r = clipToWorkArea ? [s visibleFrame]
  201161. : [s frame];
  201162. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201163. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201164. (int) r.size.width,
  201165. (int) r.size.height));
  201166. }
  201167. jassert (monitorCoords.size() > 0);
  201168. }
  201169. #endif
  201170. #endif
  201171. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201172. #endif
  201173. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201174. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201175. // compiled on its own).
  201176. #if JUCE_INCLUDED_FILE
  201177. void Logger::outputDebugString (const String& text) throw()
  201178. {
  201179. std::cerr << text << std::endl;
  201180. }
  201181. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201182. {
  201183. static char testResult = 0;
  201184. if (testResult == 0)
  201185. {
  201186. struct kinfo_proc info;
  201187. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201188. size_t sz = sizeof (info);
  201189. sysctl (m, 4, &info, &sz, 0, 0);
  201190. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201191. }
  201192. return testResult > 0;
  201193. }
  201194. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201195. {
  201196. return juce_isRunningUnderDebugger();
  201197. }
  201198. #endif
  201199. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201200. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201201. #if JUCE_IPHONE
  201202. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201203. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201204. // compiled on its own).
  201205. #if JUCE_INCLUDED_FILE
  201206. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201207. #define SUPPORT_10_4_FONTS 1
  201208. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201209. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201210. #define SUPPORT_ONLY_10_4_FONTS 1
  201211. #endif
  201212. END_JUCE_NAMESPACE
  201213. @interface NSFont (PrivateHack)
  201214. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201215. @end
  201216. BEGIN_JUCE_NAMESPACE
  201217. #endif
  201218. class MacTypeface : public Typeface
  201219. {
  201220. public:
  201221. MacTypeface (const Font& font)
  201222. : Typeface (font.getTypefaceName())
  201223. {
  201224. const ScopedAutoReleasePool pool;
  201225. renderingTransform = CGAffineTransformIdentity;
  201226. bool needsItalicTransform = false;
  201227. #if JUCE_IPHONE
  201228. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201229. if (font.isItalic() || font.isBold())
  201230. {
  201231. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201232. for (NSString* i in familyFonts)
  201233. {
  201234. const String fn (nsStringToJuce (i));
  201235. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  201236. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  201237. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  201238. || afterDash.containsIgnoreCase ("italic")
  201239. || fn.endsWithIgnoreCase ("oblique")
  201240. || fn.endsWithIgnoreCase ("italic");
  201241. if (probablyBold == font.isBold()
  201242. && probablyItalic == font.isItalic())
  201243. {
  201244. fontName = i;
  201245. needsItalicTransform = false;
  201246. break;
  201247. }
  201248. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201249. {
  201250. fontName = i;
  201251. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201252. }
  201253. }
  201254. if (needsItalicTransform)
  201255. renderingTransform.c = 0.15f;
  201256. }
  201257. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201258. const int ascender = abs (CGFontGetAscent (fontRef));
  201259. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201260. ascent = ascender / totalHeight;
  201261. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201262. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201263. #else
  201264. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201265. if (font.isItalic())
  201266. {
  201267. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201268. toHaveTrait: NSItalicFontMask];
  201269. if (newFont == nsFont)
  201270. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201271. nsFont = newFont;
  201272. }
  201273. if (font.isBold())
  201274. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201275. [nsFont retain];
  201276. ascent = fabsf ((float) [nsFont ascender]);
  201277. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201278. ascent /= totalSize;
  201279. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201280. if (needsItalicTransform)
  201281. {
  201282. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201283. renderingTransform.c = 0.15f;
  201284. }
  201285. #if SUPPORT_ONLY_10_4_FONTS
  201286. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201287. if (atsFont == 0)
  201288. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201289. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  201290. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201291. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201292. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201293. #else
  201294. #if SUPPORT_10_4_FONTS
  201295. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201296. {
  201297. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201298. if (atsFont == 0)
  201299. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201300. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  201301. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201302. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201303. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201304. }
  201305. else
  201306. #endif
  201307. {
  201308. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201309. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201310. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201311. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201312. }
  201313. #endif
  201314. #endif
  201315. }
  201316. ~MacTypeface()
  201317. {
  201318. #if ! JUCE_IPHONE
  201319. [nsFont release];
  201320. #endif
  201321. if (fontRef != 0)
  201322. CGFontRelease (fontRef);
  201323. }
  201324. float getAscent() const
  201325. {
  201326. return ascent;
  201327. }
  201328. float getDescent() const
  201329. {
  201330. return 1.0f - ascent;
  201331. }
  201332. float getStringWidth (const String& text)
  201333. {
  201334. if (fontRef == 0 || text.isEmpty())
  201335. return 0;
  201336. const int length = text.length();
  201337. HeapBlock <CGGlyph> glyphs;
  201338. createGlyphsForString (text, length, glyphs);
  201339. float x = 0;
  201340. #if SUPPORT_ONLY_10_4_FONTS
  201341. HeapBlock <NSSize> advances (length);
  201342. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201343. for (int i = 0; i < length; ++i)
  201344. x += advances[i].width;
  201345. #else
  201346. #if SUPPORT_10_4_FONTS
  201347. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201348. {
  201349. HeapBlock <NSSize> advances (length);
  201350. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201351. for (int i = 0; i < length; ++i)
  201352. x += advances[i].width;
  201353. }
  201354. else
  201355. #endif
  201356. {
  201357. HeapBlock <int> advances (length);
  201358. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201359. for (int i = 0; i < length; ++i)
  201360. x += advances[i];
  201361. }
  201362. #endif
  201363. return x * unitsToHeightScaleFactor;
  201364. }
  201365. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201366. {
  201367. xOffsets.add (0);
  201368. if (fontRef == 0 || text.isEmpty())
  201369. return;
  201370. const int length = text.length();
  201371. HeapBlock <CGGlyph> glyphs;
  201372. createGlyphsForString (text, length, glyphs);
  201373. #if SUPPORT_ONLY_10_4_FONTS
  201374. HeapBlock <NSSize> advances (length);
  201375. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201376. int x = 0;
  201377. for (int i = 0; i < length; ++i)
  201378. {
  201379. x += advances[i].width;
  201380. xOffsets.add (x * unitsToHeightScaleFactor);
  201381. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201382. }
  201383. #else
  201384. #if SUPPORT_10_4_FONTS
  201385. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201386. {
  201387. HeapBlock <NSSize> advances (length);
  201388. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201389. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201390. float x = 0;
  201391. for (int i = 0; i < length; ++i)
  201392. {
  201393. x += advances[i].width;
  201394. xOffsets.add (x * unitsToHeightScaleFactor);
  201395. resultGlyphs.add (nsGlyphs[i]);
  201396. }
  201397. }
  201398. else
  201399. #endif
  201400. {
  201401. HeapBlock <int> advances (length);
  201402. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201403. {
  201404. int x = 0;
  201405. for (int i = 0; i < length; ++i)
  201406. {
  201407. x += advances [i];
  201408. xOffsets.add (x * unitsToHeightScaleFactor);
  201409. resultGlyphs.add (glyphs[i]);
  201410. }
  201411. }
  201412. }
  201413. #endif
  201414. }
  201415. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201416. {
  201417. #if JUCE_IPHONE
  201418. return false;
  201419. #else
  201420. if (nsFont == 0)
  201421. return false;
  201422. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201423. jassert (path.isEmpty());
  201424. const ScopedAutoReleasePool pool;
  201425. NSBezierPath* bez = [NSBezierPath bezierPath];
  201426. [bez moveToPoint: NSMakePoint (0, 0)];
  201427. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201428. inFont: nsFont];
  201429. for (int i = 0; i < [bez elementCount]; ++i)
  201430. {
  201431. NSPoint p[3];
  201432. switch ([bez elementAtIndex: i associatedPoints: p])
  201433. {
  201434. case NSMoveToBezierPathElement:
  201435. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201436. break;
  201437. case NSLineToBezierPathElement:
  201438. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201439. break;
  201440. case NSCurveToBezierPathElement:
  201441. path.cubicTo ((float) p[0].x, (float) -p[0].y, (float) p[1].x, (float) -p[1].y, (float) p[2].x, (float) -p[2].y);
  201442. break;
  201443. case NSClosePathBezierPathElement:
  201444. path.closeSubPath();
  201445. break;
  201446. default:
  201447. jassertfalse
  201448. break;
  201449. }
  201450. }
  201451. path.applyTransform (pathTransform);
  201452. return true;
  201453. #endif
  201454. }
  201455. juce_UseDebuggingNewOperator
  201456. CGFontRef fontRef;
  201457. float fontHeightToCGSizeFactor;
  201458. CGAffineTransform renderingTransform;
  201459. private:
  201460. float ascent, unitsToHeightScaleFactor;
  201461. #if JUCE_IPHONE
  201462. #else
  201463. NSFont* nsFont;
  201464. AffineTransform pathTransform;
  201465. #endif
  201466. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201467. {
  201468. #if SUPPORT_10_4_FONTS
  201469. #if ! SUPPORT_ONLY_10_4_FONTS
  201470. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201471. #endif
  201472. {
  201473. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201474. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201475. for (int i = 0; i < length; ++i)
  201476. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201477. return;
  201478. }
  201479. #endif
  201480. #if ! SUPPORT_ONLY_10_4_FONTS
  201481. if (charToGlyphMapper == 0)
  201482. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201483. glyphs.malloc (length);
  201484. for (int i = 0; i < length; ++i)
  201485. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  201486. #endif
  201487. }
  201488. #if ! SUPPORT_ONLY_10_4_FONTS
  201489. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  201490. class CharToGlyphMapper
  201491. {
  201492. public:
  201493. CharToGlyphMapper (CGFontRef fontRef)
  201494. : segCount (0), endCode (0), startCode (0), idDelta (0),
  201495. idRangeOffset (0), glyphIndexes (0)
  201496. {
  201497. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  201498. if (cmapTable != 0)
  201499. {
  201500. const int numSubtables = getValue16 (cmapTable, 2);
  201501. for (int i = 0; i < numSubtables; ++i)
  201502. {
  201503. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  201504. {
  201505. const int offset = getValue32 (cmapTable, i * 8 + 8);
  201506. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  201507. {
  201508. const int length = getValue16 (cmapTable, offset + 2);
  201509. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  201510. segCount = segCountX2 / 2;
  201511. const int endCodeOffset = offset + 14;
  201512. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  201513. const int idDeltaOffset = startCodeOffset + segCountX2;
  201514. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  201515. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  201516. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  201517. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  201518. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  201519. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  201520. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  201521. }
  201522. break;
  201523. }
  201524. }
  201525. CFRelease (cmapTable);
  201526. }
  201527. }
  201528. ~CharToGlyphMapper()
  201529. {
  201530. if (endCode != 0)
  201531. {
  201532. CFRelease (endCode);
  201533. CFRelease (startCode);
  201534. CFRelease (idDelta);
  201535. CFRelease (idRangeOffset);
  201536. CFRelease (glyphIndexes);
  201537. }
  201538. }
  201539. int getGlyphForCharacter (const juce_wchar c) const
  201540. {
  201541. for (int i = 0; i < segCount; ++i)
  201542. {
  201543. if (getValue16 (endCode, i * 2) >= c)
  201544. {
  201545. const int start = getValue16 (startCode, i * 2);
  201546. if (start > c)
  201547. break;
  201548. const int delta = getValue16 (idDelta, i * 2);
  201549. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  201550. if (rangeOffset == 0)
  201551. return delta + c;
  201552. else
  201553. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  201554. }
  201555. }
  201556. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  201557. return jmax (-1, c - 29);
  201558. }
  201559. private:
  201560. int segCount;
  201561. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  201562. static uint16 getValue16 (CFDataRef data, const int index)
  201563. {
  201564. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  201565. }
  201566. static uint32 getValue32 (CFDataRef data, const int index)
  201567. {
  201568. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  201569. }
  201570. };
  201571. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  201572. #endif
  201573. MacTypeface (const MacTypeface&);
  201574. MacTypeface& operator= (const MacTypeface&);
  201575. };
  201576. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  201577. {
  201578. return new MacTypeface (font);
  201579. }
  201580. const StringArray Font::findAllTypefaceNames()
  201581. {
  201582. StringArray names;
  201583. const ScopedAutoReleasePool pool;
  201584. #if JUCE_IPHONE
  201585. NSArray* fonts = [UIFont familyNames];
  201586. #else
  201587. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  201588. #endif
  201589. for (unsigned int i = 0; i < [fonts count]; ++i)
  201590. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  201591. names.sort (true);
  201592. return names;
  201593. }
  201594. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  201595. {
  201596. #if JUCE_IPHONE
  201597. defaultSans = "Helvetica";
  201598. defaultSerif = "Times New Roman";
  201599. defaultFixed = "Courier New";
  201600. #else
  201601. defaultSans = "Lucida Grande";
  201602. defaultSerif = "Times New Roman";
  201603. defaultFixed = "Monaco";
  201604. #endif
  201605. }
  201606. #endif
  201607. /*** End of inlined file: juce_mac_Fonts.mm ***/
  201608. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  201609. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201610. // compiled on its own).
  201611. #if JUCE_INCLUDED_FILE
  201612. class CoreGraphicsImage : public Image
  201613. {
  201614. public:
  201615. CoreGraphicsImage (const PixelFormat format_,
  201616. const int imageWidth_,
  201617. const int imageHeight_,
  201618. const bool clearImage)
  201619. : Image (format_, imageWidth_, imageHeight_, clearImage)
  201620. {
  201621. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  201622. : CGColorSpaceCreateDeviceRGB();
  201623. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  201624. colourSpace, getCGImageFlags (*this));
  201625. CGColorSpaceRelease (colourSpace);
  201626. }
  201627. ~CoreGraphicsImage()
  201628. {
  201629. CGContextRelease (context);
  201630. }
  201631. LowLevelGraphicsContext* createLowLevelContext();
  201632. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  201633. {
  201634. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  201635. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  201636. {
  201637. return CGBitmapContextCreateImage (nativeImage->context);
  201638. }
  201639. else
  201640. {
  201641. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  201642. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  201643. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  201644. 8, srcData.pixelStride * 8, srcData.lineStride,
  201645. colourSpace, getCGImageFlags (juceImage), provider,
  201646. 0, true, kCGRenderingIntentDefault);
  201647. CGDataProviderRelease (provider);
  201648. return imageRef;
  201649. }
  201650. }
  201651. #if JUCE_MAC
  201652. static NSImage* createNSImage (const Image& image)
  201653. {
  201654. const ScopedAutoReleasePool pool;
  201655. NSImage* im = [[NSImage alloc] init];
  201656. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  201657. [im lockFocus];
  201658. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  201659. CGImageRef imageRef = createImage (image, false, colourSpace);
  201660. CGColorSpaceRelease (colourSpace);
  201661. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  201662. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  201663. CGImageRelease (imageRef);
  201664. [im unlockFocus];
  201665. return im;
  201666. }
  201667. #endif
  201668. CGContextRef context;
  201669. private:
  201670. static CGBitmapInfo getCGImageFlags (const Image& image)
  201671. {
  201672. #if JUCE_BIG_ENDIAN
  201673. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  201674. #else
  201675. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  201676. #endif
  201677. }
  201678. };
  201679. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  201680. {
  201681. #if USE_COREGRAPHICS_RENDERING
  201682. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  201683. #else
  201684. return new Image (format, imageWidth, imageHeight, clearImage);
  201685. #endif
  201686. }
  201687. class CoreGraphicsContext : public LowLevelGraphicsContext
  201688. {
  201689. public:
  201690. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  201691. : context (context_),
  201692. flipHeight (flipHeight_),
  201693. state (new SavedState()),
  201694. numGradientLookupEntries (0)
  201695. {
  201696. CGContextRetain (context);
  201697. CGContextSaveGState(context);
  201698. CGContextSetShouldSmoothFonts (context, true);
  201699. CGContextSetShouldAntialias (context, true);
  201700. CGContextSetBlendMode (context, kCGBlendModeNormal);
  201701. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  201702. greyColourSpace = CGColorSpaceCreateDeviceGray();
  201703. gradientCallbacks.version = 0;
  201704. gradientCallbacks.evaluate = gradientCallback;
  201705. gradientCallbacks.releaseInfo = 0;
  201706. setFont (Font());
  201707. }
  201708. ~CoreGraphicsContext()
  201709. {
  201710. CGContextRestoreGState (context);
  201711. CGContextRelease (context);
  201712. CGColorSpaceRelease (rgbColourSpace);
  201713. CGColorSpaceRelease (greyColourSpace);
  201714. }
  201715. bool isVectorDevice() const { return false; }
  201716. void setOrigin (int x, int y)
  201717. {
  201718. CGContextTranslateCTM (context, x, -y);
  201719. }
  201720. bool clipToRectangle (const Rectangle<int>& r)
  201721. {
  201722. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  201723. return ! isClipEmpty();
  201724. }
  201725. bool clipToRectangleList (const RectangleList& clipRegion)
  201726. {
  201727. if (clipRegion.isEmpty())
  201728. {
  201729. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  201730. return false;
  201731. }
  201732. else
  201733. {
  201734. const int numRects = clipRegion.getNumRectangles();
  201735. HeapBlock <CGRect> rects (numRects);
  201736. for (int i = 0; i < numRects; ++i)
  201737. {
  201738. const Rectangle<int>& r = clipRegion.getRectangle(i);
  201739. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  201740. }
  201741. CGContextClipToRects (context, rects, numRects);
  201742. return ! isClipEmpty();
  201743. }
  201744. }
  201745. void excludeClipRectangle (const Rectangle<int>& r)
  201746. {
  201747. RectangleList remaining (getClipBounds());
  201748. remaining.subtract (r);
  201749. clipToRectangleList (remaining);
  201750. }
  201751. void clipToPath (const Path& path, const AffineTransform& transform)
  201752. {
  201753. createPath (path, transform);
  201754. CGContextClip (context);
  201755. }
  201756. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  201757. {
  201758. if (! transform.isSingularity())
  201759. {
  201760. ScopedPointer<Image> imageToDelete;
  201761. const Image* singleChannelImage = &sourceImage;
  201762. if (sourceImage.getFormat() != Image::SingleChannel)
  201763. {
  201764. imageToDelete = sourceImage.createCopyOfAlphaChannel();
  201765. singleChannelImage = imageToDelete;
  201766. }
  201767. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  201768. flip();
  201769. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  201770. applyTransform (t);
  201771. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  201772. CGContextClipToMask (context, r, image);
  201773. applyTransform (t.inverted());
  201774. flip();
  201775. CGImageRelease (image);
  201776. }
  201777. }
  201778. bool clipRegionIntersects (const Rectangle<int>& r)
  201779. {
  201780. return getClipBounds().intersects (r);
  201781. }
  201782. const Rectangle<int> getClipBounds() const
  201783. {
  201784. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  201785. return Rectangle<int> (roundToInt (bounds.origin.x),
  201786. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  201787. roundToInt (bounds.size.width),
  201788. roundToInt (bounds.size.height));
  201789. }
  201790. bool isClipEmpty() const
  201791. {
  201792. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  201793. }
  201794. void saveState()
  201795. {
  201796. CGContextSaveGState (context);
  201797. stateStack.add (new SavedState (*state));
  201798. }
  201799. void restoreState()
  201800. {
  201801. CGContextRestoreGState (context);
  201802. SavedState* const top = stateStack.getLast();
  201803. if (top != 0)
  201804. {
  201805. state = top;
  201806. stateStack.removeLast (1, false);
  201807. }
  201808. else
  201809. {
  201810. jassertfalse // trying to pop with an empty stack!
  201811. }
  201812. }
  201813. void setFill (const FillType& fillType)
  201814. {
  201815. state->fillType = fillType;
  201816. if (fillType.isColour())
  201817. {
  201818. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  201819. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  201820. CGContextSetAlpha (context, 1.0f);
  201821. }
  201822. }
  201823. void setOpacity (float newOpacity)
  201824. {
  201825. state->fillType.setOpacity (newOpacity);
  201826. setFill (state->fillType);
  201827. }
  201828. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  201829. {
  201830. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  201831. ? kCGInterpolationLow
  201832. : kCGInterpolationHigh);
  201833. }
  201834. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  201835. {
  201836. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  201837. if (replaceExistingContents)
  201838. {
  201839. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201840. CGContextClearRect (context, cgRect);
  201841. #else
  201842. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201843. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  201844. CGContextClearRect (context, cgRect);
  201845. else
  201846. #endif
  201847. CGContextSetBlendMode (context, kCGBlendModeCopy);
  201848. #endif
  201849. fillRect (r, false);
  201850. CGContextSetBlendMode (context, kCGBlendModeNormal);
  201851. }
  201852. else
  201853. {
  201854. if (state->fillType.isColour())
  201855. {
  201856. CGContextFillRect (context, cgRect);
  201857. }
  201858. else if (state->fillType.isGradient())
  201859. {
  201860. CGContextSaveGState (context);
  201861. CGContextClipToRect (context, cgRect);
  201862. drawGradient();
  201863. CGContextRestoreGState (context);
  201864. }
  201865. else
  201866. {
  201867. CGContextSaveGState (context);
  201868. CGContextClipToRect (context, cgRect);
  201869. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  201870. CGContextRestoreGState (context);
  201871. }
  201872. }
  201873. }
  201874. void fillPath (const Path& path, const AffineTransform& transform)
  201875. {
  201876. CGContextSaveGState (context);
  201877. if (state->fillType.isColour())
  201878. {
  201879. flip();
  201880. applyTransform (transform);
  201881. createPath (path);
  201882. if (path.isUsingNonZeroWinding())
  201883. CGContextFillPath (context);
  201884. else
  201885. CGContextEOFillPath (context);
  201886. }
  201887. else
  201888. {
  201889. createPath (path, transform);
  201890. if (path.isUsingNonZeroWinding())
  201891. CGContextClip (context);
  201892. else
  201893. CGContextEOClip (context);
  201894. if (state->fillType.isGradient())
  201895. drawGradient();
  201896. else
  201897. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  201898. }
  201899. CGContextRestoreGState (context);
  201900. }
  201901. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  201902. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  201903. {
  201904. jassert (sourceImage.getBounds().contains (srcClip));
  201905. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  201906. CGImageRef image = fullImage;
  201907. if (srcClip != sourceImage.getBounds())
  201908. {
  201909. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  201910. srcClip.getWidth(), srcClip.getHeight()));
  201911. CGImageRelease (fullImage);
  201912. }
  201913. CGContextSaveGState (context);
  201914. CGContextSetAlpha (context, state->fillType.getOpacity());
  201915. flip();
  201916. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  201917. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  201918. if (fillEntireClipAsTiles)
  201919. {
  201920. #if JUCE_IPHONE
  201921. CGContextDrawTiledImage (context, imageRect, image);
  201922. #else
  201923. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  201924. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  201925. // if it's doing a transformation - it's quicker to just draw lots of images manually
  201926. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  201927. CGContextDrawTiledImage (context, imageRect, image);
  201928. else
  201929. #endif
  201930. {
  201931. // Fallback to manually doing a tiled fill on 10.4
  201932. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  201933. const int iw = srcClip.getWidth();
  201934. const int ih = srcClip.getHeight();
  201935. int x = 0, y = 0;
  201936. while (x > clip.origin.x) x -= iw;
  201937. while (y > clip.origin.y) y -= ih;
  201938. const int right = (int) (clip.origin.x + clip.size.width);
  201939. const int bottom = (int) (clip.origin.y + clip.size.height);
  201940. while (y < bottom)
  201941. {
  201942. for (int x2 = x; x2 < right; x2 += iw)
  201943. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  201944. y += ih;
  201945. }
  201946. }
  201947. #endif
  201948. }
  201949. else
  201950. {
  201951. CGContextDrawImage (context, imageRect, image);
  201952. }
  201953. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  201954. CGContextRestoreGState (context);
  201955. }
  201956. void drawLine (double x1, double y1, double x2, double y2)
  201957. {
  201958. CGContextSetLineCap (context, kCGLineCapSquare);
  201959. CGContextSetLineWidth (context, 1.0f);
  201960. CGContextSetRGBStrokeColor (context,
  201961. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  201962. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  201963. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  201964. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  201965. CGContextStrokeLineSegments (context, line, 1);
  201966. }
  201967. void drawVerticalLine (const int x, double top, double bottom)
  201968. {
  201969. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  201970. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  201971. #else
  201972. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  201973. // the x co-ord slightly to trick it..
  201974. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  201975. #endif
  201976. }
  201977. void drawHorizontalLine (const int y, double left, double right)
  201978. {
  201979. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  201980. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  201981. #else
  201982. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  201983. // the x co-ord slightly to trick it..
  201984. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  201985. #endif
  201986. }
  201987. void setFont (const Font& newFont)
  201988. {
  201989. if (state->font != newFont)
  201990. {
  201991. state->fontRef = 0;
  201992. state->font = newFont;
  201993. MacTypeface* mf = dynamic_cast <MacTypeface*> (state->font.getTypeface());
  201994. if (mf != 0)
  201995. {
  201996. state->fontRef = mf->fontRef;
  201997. CGContextSetFont (context, state->fontRef);
  201998. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  201999. state->fontTransform = mf->renderingTransform;
  202000. state->fontTransform.a *= state->font.getHorizontalScale();
  202001. CGContextSetTextMatrix (context, state->fontTransform);
  202002. }
  202003. }
  202004. }
  202005. const Font getFont()
  202006. {
  202007. return state->font;
  202008. }
  202009. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202010. {
  202011. if (state->fontRef != 0 && state->fillType.isColour())
  202012. {
  202013. if (transform.isOnlyTranslation())
  202014. {
  202015. CGGlyph g = glyphNumber;
  202016. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202017. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202018. }
  202019. else
  202020. {
  202021. CGContextSaveGState (context);
  202022. flip();
  202023. applyTransform (transform);
  202024. CGAffineTransform t = state->fontTransform;
  202025. t.d = -t.d;
  202026. CGContextSetTextMatrix (context, t);
  202027. CGGlyph g = glyphNumber;
  202028. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202029. CGContextSetTextMatrix (context, state->fontTransform);
  202030. CGContextRestoreGState (context);
  202031. }
  202032. }
  202033. else
  202034. {
  202035. Path p;
  202036. Font& f = state->font;
  202037. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202038. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202039. .followedBy (transform));
  202040. }
  202041. }
  202042. private:
  202043. CGContextRef context;
  202044. const CGFloat flipHeight;
  202045. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202046. CGFunctionCallbacks gradientCallbacks;
  202047. struct SavedState
  202048. {
  202049. SavedState()
  202050. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202051. {
  202052. }
  202053. SavedState (const SavedState& other)
  202054. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202055. fontTransform (other.fontTransform)
  202056. {
  202057. }
  202058. ~SavedState()
  202059. {
  202060. }
  202061. FillType fillType;
  202062. Font font;
  202063. CGFontRef fontRef;
  202064. CGAffineTransform fontTransform;
  202065. };
  202066. ScopedPointer <SavedState> state;
  202067. OwnedArray <SavedState> stateStack;
  202068. HeapBlock <PixelARGB> gradientLookupTable;
  202069. int numGradientLookupEntries;
  202070. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202071. {
  202072. const CoreGraphicsContext* const g = static_cast <const CoreGraphicsContext*> (info);
  202073. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202074. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202075. colour.unpremultiply();
  202076. outData[0] = colour.getRed() / 255.0f;
  202077. outData[1] = colour.getGreen() / 255.0f;
  202078. outData[2] = colour.getBlue() / 255.0f;
  202079. outData[3] = colour.getAlpha() / 255.0f;
  202080. }
  202081. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202082. {
  202083. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202084. --numGradientLookupEntries;
  202085. CGShadingRef result = 0;
  202086. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  202087. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202088. if (gradient.isRadial)
  202089. {
  202090. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202091. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202092. function, true, true);
  202093. }
  202094. else
  202095. {
  202096. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202097. CGPointMake (gradient.x2, gradient.y2),
  202098. function, true, true);
  202099. }
  202100. CGFunctionRelease (function);
  202101. return result;
  202102. }
  202103. void drawGradient()
  202104. {
  202105. flip();
  202106. applyTransform (state->fillType.transform);
  202107. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202108. // you draw a gradient with high quality interp enabled).
  202109. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202110. CGContextSetAlpha (context, state->fillType.getOpacity());
  202111. CGContextDrawShading (context, shading);
  202112. CGShadingRelease (shading);
  202113. }
  202114. void createPath (const Path& path) const
  202115. {
  202116. CGContextBeginPath (context);
  202117. Path::Iterator i (path);
  202118. while (i.next())
  202119. {
  202120. switch (i.elementType)
  202121. {
  202122. case Path::Iterator::startNewSubPath:
  202123. CGContextMoveToPoint (context, i.x1, i.y1);
  202124. break;
  202125. case Path::Iterator::lineTo:
  202126. CGContextAddLineToPoint (context, i.x1, i.y1);
  202127. break;
  202128. case Path::Iterator::quadraticTo:
  202129. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202130. break;
  202131. case Path::Iterator::cubicTo:
  202132. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202133. break;
  202134. case Path::Iterator::closePath:
  202135. CGContextClosePath (context); break;
  202136. default:
  202137. jassertfalse
  202138. break;
  202139. }
  202140. }
  202141. }
  202142. void createPath (const Path& path, const AffineTransform& transform) const
  202143. {
  202144. CGContextBeginPath (context);
  202145. Path::Iterator i (path);
  202146. while (i.next())
  202147. {
  202148. switch (i.elementType)
  202149. {
  202150. case Path::Iterator::startNewSubPath:
  202151. transform.transformPoint (i.x1, i.y1);
  202152. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202153. break;
  202154. case Path::Iterator::lineTo:
  202155. transform.transformPoint (i.x1, i.y1);
  202156. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202157. break;
  202158. case Path::Iterator::quadraticTo:
  202159. transform.transformPoint (i.x1, i.y1);
  202160. transform.transformPoint (i.x2, i.y2);
  202161. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202162. break;
  202163. case Path::Iterator::cubicTo:
  202164. transform.transformPoint (i.x1, i.y1);
  202165. transform.transformPoint (i.x2, i.y2);
  202166. transform.transformPoint (i.x3, i.y3);
  202167. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202168. break;
  202169. case Path::Iterator::closePath:
  202170. CGContextClosePath (context); break;
  202171. default:
  202172. jassertfalse
  202173. break;
  202174. }
  202175. }
  202176. }
  202177. void flip() const
  202178. {
  202179. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202180. }
  202181. void applyTransform (const AffineTransform& transform) const
  202182. {
  202183. CGAffineTransform t;
  202184. t.a = transform.mat00;
  202185. t.b = transform.mat10;
  202186. t.c = transform.mat01;
  202187. t.d = transform.mat11;
  202188. t.tx = transform.mat02;
  202189. t.ty = transform.mat12;
  202190. CGContextConcatCTM (context, t);
  202191. }
  202192. CoreGraphicsContext (const CoreGraphicsContext&);
  202193. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202194. };
  202195. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202196. {
  202197. return new CoreGraphicsContext (context, imageHeight);
  202198. }
  202199. #endif
  202200. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202201. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202202. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202203. // compiled on its own).
  202204. #if JUCE_INCLUDED_FILE
  202205. class UIViewComponentPeer;
  202206. END_JUCE_NAMESPACE
  202207. #define JuceUIView MakeObjCClassName(JuceUIView)
  202208. @interface JuceUIView : UIView <UITextFieldDelegate>
  202209. {
  202210. @public
  202211. UIViewComponentPeer* owner;
  202212. UITextField *hiddenTextField;
  202213. }
  202214. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202215. - (void) dealloc;
  202216. - (void) drawRect: (CGRect) r;
  202217. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202218. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202219. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202220. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202221. - (BOOL) becomeFirstResponder;
  202222. - (BOOL) resignFirstResponder;
  202223. - (BOOL) canBecomeFirstResponder;
  202224. - (void) asyncRepaint: (id) rect;
  202225. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string;
  202226. - (BOOL) textFieldShouldClear: (UITextField*) textField;
  202227. - (BOOL) textFieldShouldReturn: (UITextField*) textField;
  202228. @end
  202229. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202230. @interface JuceUIWindow : UIWindow
  202231. {
  202232. @private
  202233. UIViewComponentPeer* owner;
  202234. bool isZooming;
  202235. }
  202236. - (void) setOwner: (UIViewComponentPeer*) owner;
  202237. - (void) becomeKeyWindow;
  202238. @end
  202239. BEGIN_JUCE_NAMESPACE
  202240. class UIViewComponentPeer : public ComponentPeer,
  202241. public FocusChangeListener
  202242. {
  202243. public:
  202244. UIViewComponentPeer (Component* const component,
  202245. const int windowStyleFlags,
  202246. UIView* viewToAttachTo);
  202247. ~UIViewComponentPeer();
  202248. void* getNativeHandle() const;
  202249. void setVisible (bool shouldBeVisible);
  202250. void setTitle (const String& title);
  202251. void setPosition (int x, int y);
  202252. void setSize (int w, int h);
  202253. void setBounds (int x, int y, int w, int h, bool isNowFullScreen);
  202254. const Rectangle<int> getBounds() const;
  202255. const Rectangle<int> getBounds (const bool global) const;
  202256. const Point<int> getScreenPosition() const;
  202257. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202258. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202259. void setMinimised (bool shouldBeMinimised);
  202260. bool isMinimised() const;
  202261. void setFullScreen (bool shouldBeFullScreen);
  202262. bool isFullScreen() const;
  202263. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202264. const BorderSize getFrameSize() const;
  202265. bool setAlwaysOnTop (bool alwaysOnTop);
  202266. void toFront (bool makeActiveWindow);
  202267. void toBehind (ComponentPeer* other);
  202268. void setIcon (const Image& newIcon);
  202269. virtual void drawRect (CGRect r);
  202270. virtual bool canBecomeKeyWindow();
  202271. virtual bool windowShouldClose();
  202272. virtual void redirectMovedOrResized();
  202273. virtual CGRect constrainRect (CGRect r);
  202274. virtual void viewFocusGain();
  202275. virtual void viewFocusLoss();
  202276. bool isFocused() const;
  202277. void grabFocus();
  202278. void textInputRequired (const Point<int>& position);
  202279. virtual BOOL textFieldReplaceCharacters (const Range<int>& range, const String& text);
  202280. virtual BOOL textFieldShouldClear();
  202281. virtual BOOL textFieldShouldReturn();
  202282. void updateHiddenTextContent (TextInputTarget* target);
  202283. void globalFocusChanged (Component*);
  202284. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202285. void repaint (int x, int y, int w, int h);
  202286. void performAnyPendingRepaintsNow();
  202287. juce_UseDebuggingNewOperator
  202288. UIWindow* window;
  202289. JuceUIView* view;
  202290. bool isSharedWindow, fullScreen, insideDrawRect;
  202291. static ModifierKeys currentModifiers;
  202292. static int64 getMouseTime (UIEvent* e)
  202293. {
  202294. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202295. + (int64) ([e timestamp] * 1000.0);
  202296. }
  202297. Array <UITouch*> currentTouches;
  202298. };
  202299. END_JUCE_NAMESPACE
  202300. @implementation JuceUIView
  202301. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202302. withFrame: (CGRect) frame
  202303. {
  202304. [super initWithFrame: frame];
  202305. owner = owner_;
  202306. hiddenTextField = [[UITextField alloc] initWithFrame: CGRectMake (0, 0, 0, 0)];
  202307. [self addSubview: hiddenTextField];
  202308. hiddenTextField.delegate = self;
  202309. return self;
  202310. }
  202311. - (void) dealloc
  202312. {
  202313. [hiddenTextField removeFromSuperview];
  202314. [hiddenTextField release];
  202315. [super dealloc];
  202316. }
  202317. - (void) drawRect: (CGRect) r
  202318. {
  202319. if (owner != 0)
  202320. owner->drawRect (r);
  202321. }
  202322. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  202323. {
  202324. return false;
  202325. }
  202326. ModifierKeys UIViewComponentPeer::currentModifiers;
  202327. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202328. {
  202329. return UIViewComponentPeer::currentModifiers;
  202330. }
  202331. void ModifierKeys::updateCurrentModifiers() throw()
  202332. {
  202333. currentModifiers = UIViewComponentPeer::currentModifiers;
  202334. }
  202335. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202336. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202337. {
  202338. if (owner != 0)
  202339. owner->handleTouches (event, true, false, false);
  202340. }
  202341. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202342. {
  202343. if (owner != 0)
  202344. owner->handleTouches (event, false, false, false);
  202345. }
  202346. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202347. {
  202348. if (owner != 0)
  202349. owner->handleTouches (event, false, true, false);
  202350. }
  202351. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202352. {
  202353. if (owner != 0)
  202354. owner->handleTouches (event, false, true, true);
  202355. [self touchesEnded: touches withEvent: event];
  202356. }
  202357. - (BOOL) becomeFirstResponder
  202358. {
  202359. if (owner != 0)
  202360. owner->viewFocusGain();
  202361. return true;
  202362. }
  202363. - (BOOL) resignFirstResponder
  202364. {
  202365. if (owner != 0)
  202366. owner->viewFocusLoss();
  202367. return true;
  202368. }
  202369. - (BOOL) canBecomeFirstResponder
  202370. {
  202371. return owner != 0 && owner->canBecomeKeyWindow();
  202372. }
  202373. - (void) asyncRepaint: (id) rect
  202374. {
  202375. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202376. [self setNeedsDisplayInRect: *r];
  202377. }
  202378. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) text
  202379. {
  202380. return owner->textFieldReplaceCharacters (Range<int> (range.location, range.location + range.length),
  202381. nsStringToJuce (text));
  202382. }
  202383. - (BOOL) textFieldShouldClear: (UITextField*) textField
  202384. {
  202385. return owner->textFieldShouldClear();
  202386. }
  202387. - (BOOL) textFieldShouldReturn: (UITextField*) textField
  202388. {
  202389. return owner->textFieldShouldReturn();
  202390. }
  202391. @end
  202392. @implementation JuceUIWindow
  202393. - (void) setOwner: (UIViewComponentPeer*) owner_
  202394. {
  202395. owner = owner_;
  202396. isZooming = false;
  202397. }
  202398. - (void) becomeKeyWindow
  202399. {
  202400. [super becomeKeyWindow];
  202401. if (owner != 0)
  202402. owner->grabFocus();
  202403. }
  202404. @end
  202405. BEGIN_JUCE_NAMESPACE
  202406. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202407. const int windowStyleFlags,
  202408. UIView* viewToAttachTo)
  202409. : ComponentPeer (component, windowStyleFlags),
  202410. window (0),
  202411. view (0),
  202412. isSharedWindow (viewToAttachTo != 0),
  202413. fullScreen (false),
  202414. insideDrawRect (false)
  202415. {
  202416. CGRect r = CGRectMake (0, 0, (float) component->getWidth(), (float) component->getHeight());
  202417. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202418. if (isSharedWindow)
  202419. {
  202420. window = [viewToAttachTo window];
  202421. [viewToAttachTo addSubview: view];
  202422. setVisible (component->isVisible());
  202423. }
  202424. else
  202425. {
  202426. r.origin.x = (float) component->getX();
  202427. r.origin.y = (float) component->getY();
  202428. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202429. window = [[JuceUIWindow alloc] init];
  202430. window.frame = r;
  202431. window.opaque = component->isOpaque();
  202432. view.opaque = component->isOpaque();
  202433. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202434. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202435. [((JuceUIWindow*) window) setOwner: this];
  202436. if (component->isAlwaysOnTop())
  202437. window.windowLevel = UIWindowLevelAlert;
  202438. [window addSubview: view];
  202439. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202440. view.hidden = ! component->isVisible();
  202441. window.hidden = ! component->isVisible();
  202442. view.multipleTouchEnabled = YES;
  202443. }
  202444. setTitle (component->getName());
  202445. Desktop::getInstance().addFocusChangeListener (this);
  202446. }
  202447. UIViewComponentPeer::~UIViewComponentPeer()
  202448. {
  202449. Desktop::getInstance().removeFocusChangeListener (this);
  202450. view->owner = 0;
  202451. [view removeFromSuperview];
  202452. [view release];
  202453. if (! isSharedWindow)
  202454. {
  202455. [((JuceUIWindow*) window) setOwner: 0];
  202456. [window release];
  202457. }
  202458. }
  202459. void* UIViewComponentPeer::getNativeHandle() const
  202460. {
  202461. return view;
  202462. }
  202463. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202464. {
  202465. view.hidden = ! shouldBeVisible;
  202466. if (! isSharedWindow)
  202467. window.hidden = ! shouldBeVisible;
  202468. }
  202469. void UIViewComponentPeer::setTitle (const String& title)
  202470. {
  202471. // xxx is this possible?
  202472. }
  202473. void UIViewComponentPeer::setPosition (int x, int y)
  202474. {
  202475. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202476. }
  202477. void UIViewComponentPeer::setSize (int w, int h)
  202478. {
  202479. setBounds (component->getX(), component->getY(), w, h, false);
  202480. }
  202481. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202482. {
  202483. fullScreen = isNowFullScreen;
  202484. w = jmax (0, w);
  202485. h = jmax (0, h);
  202486. CGRect r;
  202487. r.origin.x = (float) x;
  202488. r.origin.y = (float) y;
  202489. r.size.width = (float) w;
  202490. r.size.height = (float) h;
  202491. if (isSharedWindow)
  202492. {
  202493. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202494. if ([view frame].size.width != r.size.width
  202495. || [view frame].size.height != r.size.height)
  202496. [view setNeedsDisplay];
  202497. view.frame = r;
  202498. }
  202499. else
  202500. {
  202501. window.frame = r;
  202502. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202503. }
  202504. }
  202505. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202506. {
  202507. CGRect r = [view frame];
  202508. if (global && [view window] != 0)
  202509. {
  202510. r = [view convertRect: r toView: nil];
  202511. CGRect wr = [[view window] frame];
  202512. r.origin.x += wr.origin.x;
  202513. r.origin.y += wr.origin.y;
  202514. }
  202515. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  202516. (int) r.size.width, (int) r.size.height);
  202517. }
  202518. const Rectangle<int> UIViewComponentPeer::getBounds() const
  202519. {
  202520. return getBounds (! isSharedWindow);
  202521. }
  202522. const Point<int> UIViewComponentPeer::getScreenPosition() const
  202523. {
  202524. return getBounds (true).getPosition();
  202525. }
  202526. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  202527. {
  202528. return relativePosition + getScreenPosition();
  202529. }
  202530. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  202531. {
  202532. return screenPosition - getScreenPosition();
  202533. }
  202534. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  202535. {
  202536. if (constrainer != 0)
  202537. {
  202538. CGRect current = [window frame];
  202539. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  202540. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  202541. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  202542. (int) r.size.width, (int) r.size.height);
  202543. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  202544. (int) current.size.width, (int) current.size.height);
  202545. constrainer->checkBounds (pos, original,
  202546. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  202547. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  202548. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  202549. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  202550. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  202551. r.origin.x = pos.getX();
  202552. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  202553. r.size.width = pos.getWidth();
  202554. r.size.height = pos.getHeight();
  202555. }
  202556. return r;
  202557. }
  202558. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  202559. {
  202560. // xxx
  202561. }
  202562. bool UIViewComponentPeer::isMinimised() const
  202563. {
  202564. return false;
  202565. }
  202566. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  202567. {
  202568. if (! isSharedWindow)
  202569. {
  202570. Rectangle<int> r (lastNonFullscreenBounds);
  202571. setMinimised (false);
  202572. if (fullScreen != shouldBeFullScreen)
  202573. {
  202574. if (shouldBeFullScreen)
  202575. r = Desktop::getInstance().getMainMonitorArea();
  202576. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  202577. if (r != getComponent()->getBounds() && ! r.isEmpty())
  202578. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  202579. }
  202580. }
  202581. }
  202582. bool UIViewComponentPeer::isFullScreen() const
  202583. {
  202584. return fullScreen;
  202585. }
  202586. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  202587. {
  202588. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  202589. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  202590. return false;
  202591. CGPoint p;
  202592. p.x = (float) position.getX();
  202593. p.y = (float) position.getY();
  202594. UIView* v = [view hitTest: p withEvent: nil];
  202595. if (trueIfInAChildWindow)
  202596. return v != nil;
  202597. return v == view;
  202598. }
  202599. const BorderSize UIViewComponentPeer::getFrameSize() const
  202600. {
  202601. BorderSize b;
  202602. if (! isSharedWindow)
  202603. {
  202604. CGRect v = [view convertRect: [view frame] toView: nil];
  202605. CGRect w = [window frame];
  202606. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  202607. b.setBottom ((int) v.origin.y);
  202608. b.setLeft ((int) v.origin.x);
  202609. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  202610. }
  202611. return b;
  202612. }
  202613. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  202614. {
  202615. if (! isSharedWindow)
  202616. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  202617. return true;
  202618. }
  202619. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  202620. {
  202621. if (isSharedWindow)
  202622. [[view superview] bringSubviewToFront: view];
  202623. if (window != 0 && component->isVisible())
  202624. [window makeKeyAndVisible];
  202625. }
  202626. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  202627. {
  202628. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  202629. if (isSharedWindow)
  202630. {
  202631. [[view superview] insertSubview: view belowSubview: o->view];
  202632. }
  202633. else
  202634. {
  202635. jassertfalse // don't know how to do this
  202636. }
  202637. }
  202638. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  202639. {
  202640. // to do..
  202641. }
  202642. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  202643. {
  202644. NSArray* touches = [[event touchesForView: view] allObjects];
  202645. for (unsigned int i = 0; i < [touches count]; ++i)
  202646. {
  202647. UITouch* touch = [touches objectAtIndex: i];
  202648. CGPoint p = [touch locationInView: view];
  202649. const Point<int> pos ((int) p.x, (int) p.y);
  202650. juce_lastMousePos = pos + getScreenPosition();
  202651. const int64 time = getMouseTime (event);
  202652. int touchIndex = currentTouches.indexOf (touch);
  202653. if (touchIndex < 0)
  202654. {
  202655. touchIndex = currentTouches.size();
  202656. currentTouches.add (touch);
  202657. }
  202658. if (isDown)
  202659. {
  202660. currentModifiers = currentModifiers.withoutMouseButtons();
  202661. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  202662. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  202663. }
  202664. else if (isUp)
  202665. {
  202666. currentModifiers = currentModifiers.withoutMouseButtons();
  202667. currentTouches.remove (touchIndex);
  202668. }
  202669. if (isCancel)
  202670. currentTouches.clear();
  202671. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  202672. }
  202673. }
  202674. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  202675. void UIViewComponentPeer::viewFocusGain()
  202676. {
  202677. if (currentlyFocusedPeer != this)
  202678. {
  202679. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  202680. currentlyFocusedPeer->handleFocusLoss();
  202681. currentlyFocusedPeer = this;
  202682. handleFocusGain();
  202683. }
  202684. }
  202685. void UIViewComponentPeer::viewFocusLoss()
  202686. {
  202687. if (currentlyFocusedPeer == this)
  202688. {
  202689. currentlyFocusedPeer = 0;
  202690. handleFocusLoss();
  202691. }
  202692. }
  202693. void juce_HandleProcessFocusChange()
  202694. {
  202695. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  202696. {
  202697. if (Process::isForegroundProcess())
  202698. {
  202699. currentlyFocusedPeer->handleFocusGain();
  202700. ComponentPeer::bringModalComponentToFront();
  202701. }
  202702. else
  202703. {
  202704. currentlyFocusedPeer->handleFocusLoss();
  202705. // turn kiosk mode off if we lose focus..
  202706. Desktop::getInstance().setKioskModeComponent (0);
  202707. }
  202708. }
  202709. }
  202710. bool UIViewComponentPeer::isFocused() const
  202711. {
  202712. return isSharedWindow ? this == currentlyFocusedPeer
  202713. : (window != 0 && [window isKeyWindow]);
  202714. }
  202715. void UIViewComponentPeer::grabFocus()
  202716. {
  202717. if (window != 0)
  202718. {
  202719. [window makeKeyWindow];
  202720. viewFocusGain();
  202721. }
  202722. }
  202723. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  202724. {
  202725. }
  202726. void UIViewComponentPeer::updateHiddenTextContent (TextInputTarget* target)
  202727. {
  202728. view->hiddenTextField.text = juceStringToNS (target->getTextInRange (Range<int> (0, target->getHighlightedRegion().getStart())));
  202729. }
  202730. BOOL UIViewComponentPeer::textFieldReplaceCharacters (const Range<int>& range, const String& text)
  202731. {
  202732. TextInputTarget* const target = findCurrentTextInputTarget();
  202733. if (target != 0)
  202734. {
  202735. const Range<int> currentSelection (target->getHighlightedRegion());
  202736. if (range.getLength() == 1 && text.isEmpty()) // (detect backspace)
  202737. if (currentSelection.isEmpty())
  202738. target->setHighlightedRegion (currentSelection.withStart (currentSelection.getStart() - 1));
  202739. target->insertTextAtCaret (text);
  202740. updateHiddenTextContent (target);
  202741. }
  202742. return NO;
  202743. }
  202744. BOOL UIViewComponentPeer::textFieldShouldClear()
  202745. {
  202746. TextInputTarget* const target = findCurrentTextInputTarget();
  202747. if (target != 0)
  202748. {
  202749. target->setHighlightedRegion (Range<int> (0, std::numeric_limits<int>::max()));
  202750. target->insertTextAtCaret (String::empty);
  202751. updateHiddenTextContent (target);
  202752. }
  202753. return YES;
  202754. }
  202755. BOOL UIViewComponentPeer::textFieldShouldReturn()
  202756. {
  202757. TextInputTarget* const target = findCurrentTextInputTarget();
  202758. if (target != 0)
  202759. {
  202760. target->insertTextAtCaret ("\n");
  202761. updateHiddenTextContent (target);
  202762. }
  202763. return YES;
  202764. }
  202765. void UIViewComponentPeer::globalFocusChanged (Component*)
  202766. {
  202767. TextInputTarget* const target = findCurrentTextInputTarget();
  202768. if (target != 0)
  202769. {
  202770. Component* comp = dynamic_cast<Component*> (target);
  202771. Point<int> pos (comp->relativePositionToOtherComponent (component, Point<int>()));
  202772. view->hiddenTextField.frame = CGRectMake (pos.getX(), pos.getY(), 0, 0);
  202773. updateHiddenTextContent (target);
  202774. [view->hiddenTextField becomeFirstResponder];
  202775. }
  202776. else
  202777. {
  202778. [view->hiddenTextField resignFirstResponder];
  202779. }
  202780. }
  202781. void UIViewComponentPeer::drawRect (CGRect r)
  202782. {
  202783. if (r.size.width < 1.0f || r.size.height < 1.0f)
  202784. return;
  202785. CGContextRef cg = UIGraphicsGetCurrentContext();
  202786. if (! component->isOpaque())
  202787. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  202788. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  202789. CoreGraphicsContext g (cg, view.bounds.size.height);
  202790. insideDrawRect = true;
  202791. handlePaint (g);
  202792. insideDrawRect = false;
  202793. }
  202794. bool UIViewComponentPeer::canBecomeKeyWindow()
  202795. {
  202796. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  202797. }
  202798. bool UIViewComponentPeer::windowShouldClose()
  202799. {
  202800. if (! isValidPeer (this))
  202801. return YES;
  202802. handleUserClosingWindow();
  202803. return NO;
  202804. }
  202805. void UIViewComponentPeer::redirectMovedOrResized()
  202806. {
  202807. handleMovedOrResized();
  202808. }
  202809. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  202810. {
  202811. }
  202812. class AsyncRepaintMessage : public CallbackMessage
  202813. {
  202814. public:
  202815. UIViewComponentPeer* const peer;
  202816. const Rectangle<int> rect;
  202817. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  202818. : peer (peer_), rect (rect_)
  202819. {
  202820. }
  202821. void messageCallback()
  202822. {
  202823. if (ComponentPeer::isValidPeer (peer))
  202824. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  202825. }
  202826. };
  202827. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  202828. {
  202829. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  202830. {
  202831. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  202832. }
  202833. else
  202834. {
  202835. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  202836. }
  202837. }
  202838. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  202839. {
  202840. }
  202841. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  202842. {
  202843. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  202844. }
  202845. Image* juce_createIconForFile (const File& file)
  202846. {
  202847. return 0;
  202848. }
  202849. void Desktop::createMouseInputSources()
  202850. {
  202851. for (int i = 0; i < 10; ++i)
  202852. mouseSources.add (new MouseInputSource (i, false));
  202853. }
  202854. bool Desktop::canUseSemiTransparentWindows() throw()
  202855. {
  202856. return true;
  202857. }
  202858. const Point<int> Desktop::getMousePosition()
  202859. {
  202860. return juce_lastMousePos;
  202861. }
  202862. void Desktop::setMousePosition (const Point<int>&)
  202863. {
  202864. }
  202865. const int KeyPress::spaceKey = ' ';
  202866. const int KeyPress::returnKey = 0x0d;
  202867. const int KeyPress::escapeKey = 0x1b;
  202868. const int KeyPress::backspaceKey = 0x7f;
  202869. const int KeyPress::leftKey = 0x1000;
  202870. const int KeyPress::rightKey = 0x1001;
  202871. const int KeyPress::upKey = 0x1002;
  202872. const int KeyPress::downKey = 0x1003;
  202873. const int KeyPress::pageUpKey = 0x1004;
  202874. const int KeyPress::pageDownKey = 0x1005;
  202875. const int KeyPress::endKey = 0x1006;
  202876. const int KeyPress::homeKey = 0x1007;
  202877. const int KeyPress::deleteKey = 0x1008;
  202878. const int KeyPress::insertKey = -1;
  202879. const int KeyPress::tabKey = 9;
  202880. const int KeyPress::F1Key = 0x2001;
  202881. const int KeyPress::F2Key = 0x2002;
  202882. const int KeyPress::F3Key = 0x2003;
  202883. const int KeyPress::F4Key = 0x2004;
  202884. const int KeyPress::F5Key = 0x2005;
  202885. const int KeyPress::F6Key = 0x2006;
  202886. const int KeyPress::F7Key = 0x2007;
  202887. const int KeyPress::F8Key = 0x2008;
  202888. const int KeyPress::F9Key = 0x2009;
  202889. const int KeyPress::F10Key = 0x200a;
  202890. const int KeyPress::F11Key = 0x200b;
  202891. const int KeyPress::F12Key = 0x200c;
  202892. const int KeyPress::F13Key = 0x200d;
  202893. const int KeyPress::F14Key = 0x200e;
  202894. const int KeyPress::F15Key = 0x200f;
  202895. const int KeyPress::F16Key = 0x2010;
  202896. const int KeyPress::numberPad0 = 0x30020;
  202897. const int KeyPress::numberPad1 = 0x30021;
  202898. const int KeyPress::numberPad2 = 0x30022;
  202899. const int KeyPress::numberPad3 = 0x30023;
  202900. const int KeyPress::numberPad4 = 0x30024;
  202901. const int KeyPress::numberPad5 = 0x30025;
  202902. const int KeyPress::numberPad6 = 0x30026;
  202903. const int KeyPress::numberPad7 = 0x30027;
  202904. const int KeyPress::numberPad8 = 0x30028;
  202905. const int KeyPress::numberPad9 = 0x30029;
  202906. const int KeyPress::numberPadAdd = 0x3002a;
  202907. const int KeyPress::numberPadSubtract = 0x3002b;
  202908. const int KeyPress::numberPadMultiply = 0x3002c;
  202909. const int KeyPress::numberPadDivide = 0x3002d;
  202910. const int KeyPress::numberPadSeparator = 0x3002e;
  202911. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  202912. const int KeyPress::numberPadEquals = 0x30030;
  202913. const int KeyPress::numberPadDelete = 0x30031;
  202914. const int KeyPress::playKey = 0x30000;
  202915. const int KeyPress::stopKey = 0x30001;
  202916. const int KeyPress::fastForwardKey = 0x30002;
  202917. const int KeyPress::rewindKey = 0x30003;
  202918. #endif
  202919. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202920. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  202921. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202922. // compiled on its own).
  202923. #if JUCE_INCLUDED_FILE
  202924. struct CallbackMessagePayload
  202925. {
  202926. MessageCallbackFunction* function;
  202927. void* parameter;
  202928. void* volatile result;
  202929. bool volatile hasBeenExecuted;
  202930. };
  202931. END_JUCE_NAMESPACE
  202932. using namespace JUCE_NAMESPACE;
  202933. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  202934. {
  202935. }
  202936. - (JuceAppDelegate*) init;
  202937. - (void) dealloc;
  202938. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  202939. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  202940. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  202941. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  202942. - (void) customEvent: (id) data;
  202943. - (void) performCallback: (id) info;
  202944. @end
  202945. @implementation JuceAppDelegate
  202946. - (JuceAppDelegate*) init
  202947. {
  202948. [super init];
  202949. [[UIApplication sharedApplication] setDelegate: self];
  202950. return self;
  202951. }
  202952. - (void) dealloc
  202953. {
  202954. [[UIApplication sharedApplication] setDelegate: nil];
  202955. [super dealloc];
  202956. }
  202957. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  202958. {
  202959. if (JUCEApplication::getInstance() != 0)
  202960. {
  202961. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  202962. return YES;
  202963. }
  202964. return NO;
  202965. }
  202966. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  202967. {
  202968. juce_HandleProcessFocusChange();
  202969. }
  202970. - (void) applicationDidResignActive: (NSNotification*) aNotification
  202971. {
  202972. juce_HandleProcessFocusChange();
  202973. }
  202974. - (void) applicationWillUnhide: (NSNotification*) aNotification
  202975. {
  202976. juce_HandleProcessFocusChange();
  202977. }
  202978. - (void) customEvent: (id) n
  202979. {
  202980. NSData* data = (NSData*) n;
  202981. void* message = 0;
  202982. [data getBytes: &message length: sizeof (message)];
  202983. [data release];
  202984. if (message != 0)
  202985. MessageManager::getInstance()->deliverMessage (message);
  202986. }
  202987. - (void) performCallback: (id) info
  202988. {
  202989. if ([info isKindOfClass: [NSData class]])
  202990. {
  202991. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  202992. if (pl != 0)
  202993. {
  202994. pl->result = (*pl->function) (pl->parameter);
  202995. pl->hasBeenExecuted = true;
  202996. }
  202997. }
  202998. else
  202999. {
  203000. jassertfalse // should never get here!
  203001. }
  203002. }
  203003. @end
  203004. BEGIN_JUCE_NAMESPACE
  203005. static JuceAppDelegate* juceAppDelegate = 0;
  203006. void MessageManager::runDispatchLoop()
  203007. {
  203008. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203009. runDispatchLoopUntil (-1);
  203010. }
  203011. void MessageManager::stopDispatchLoop()
  203012. {
  203013. exit (0); // iPhone apps get no mercy..
  203014. }
  203015. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203016. {
  203017. const ScopedAutoReleasePool pool;
  203018. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203019. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203020. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203021. while (! quitMessagePosted)
  203022. {
  203023. const ScopedAutoReleasePool pool;
  203024. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203025. beforeDate: endDate];
  203026. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203027. break;
  203028. }
  203029. return ! quitMessagePosted;
  203030. }
  203031. static CFRunLoopRef runLoop = 0;
  203032. static CFRunLoopSourceRef runLoopSource = 0;
  203033. static Array <void*, CriticalSection>* pendingMessages = 0;
  203034. static void runLoopSourceCallback (void*)
  203035. {
  203036. if (pendingMessages != 0)
  203037. {
  203038. int numDispatched = 0;
  203039. do
  203040. {
  203041. void* const nextMessage = pendingMessages->remove (0);
  203042. if (nextMessage == 0)
  203043. return;
  203044. const ScopedAutoReleasePool pool;
  203045. MessageManager::getInstance()->deliverMessage (nextMessage);
  203046. } while (++numDispatched <= 4);
  203047. CFRunLoopSourceSignal (runLoopSource);
  203048. CFRunLoopWakeUp (runLoop);
  203049. }
  203050. }
  203051. void MessageManager::doPlatformSpecificInitialisation()
  203052. {
  203053. pendingMessages = new Array <void*, CriticalSection>();
  203054. runLoop = CFRunLoopGetCurrent();
  203055. CFRunLoopSourceContext sourceContext;
  203056. zerostruct (sourceContext);
  203057. sourceContext.perform = runLoopSourceCallback;
  203058. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203059. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203060. if (juceAppDelegate == 0)
  203061. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203062. }
  203063. void MessageManager::doPlatformSpecificShutdown()
  203064. {
  203065. CFRunLoopSourceInvalidate (runLoopSource);
  203066. CFRelease (runLoopSource);
  203067. runLoopSource = 0;
  203068. if (pendingMessages != 0)
  203069. {
  203070. while (pendingMessages->size() > 0)
  203071. delete ((Message*) pendingMessages->remove(0));
  203072. deleteAndZero (pendingMessages);
  203073. }
  203074. if (juceAppDelegate != 0)
  203075. {
  203076. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203077. [juceAppDelegate release];
  203078. juceAppDelegate = 0;
  203079. }
  203080. }
  203081. bool juce_postMessageToSystemQueue (void* message)
  203082. {
  203083. if (pendingMessages != 0)
  203084. {
  203085. pendingMessages->add (message);
  203086. CFRunLoopSourceSignal (runLoopSource);
  203087. CFRunLoopWakeUp (runLoop);
  203088. }
  203089. return true;
  203090. }
  203091. void MessageManager::broadcastMessage (const String& value) throw()
  203092. {
  203093. }
  203094. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203095. void* data)
  203096. {
  203097. if (isThisTheMessageThread())
  203098. {
  203099. return (*callback) (data);
  203100. }
  203101. else
  203102. {
  203103. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203104. // deadlock because the message manager is blocked from running, so can never
  203105. // call your function..
  203106. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203107. const ScopedAutoReleasePool pool;
  203108. CallbackMessagePayload cmp;
  203109. cmp.function = callback;
  203110. cmp.parameter = data;
  203111. cmp.result = 0;
  203112. cmp.hasBeenExecuted = false;
  203113. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203114. withObject: [NSData dataWithBytesNoCopy: &cmp
  203115. length: sizeof (cmp)
  203116. freeWhenDone: NO]
  203117. waitUntilDone: YES];
  203118. return cmp.result;
  203119. }
  203120. }
  203121. #endif
  203122. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203123. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203124. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203125. // compiled on its own).
  203126. #if JUCE_INCLUDED_FILE
  203127. #if JUCE_MAC
  203128. END_JUCE_NAMESPACE
  203129. using namespace JUCE_NAMESPACE;
  203130. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203131. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203132. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203133. #else
  203134. @interface JuceFileChooserDelegate : NSObject
  203135. #endif
  203136. {
  203137. StringArray* filters;
  203138. }
  203139. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203140. - (void) dealloc;
  203141. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203142. @end
  203143. @implementation JuceFileChooserDelegate
  203144. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203145. {
  203146. [super init];
  203147. filters = filters_;
  203148. return self;
  203149. }
  203150. - (void) dealloc
  203151. {
  203152. delete filters;
  203153. [super dealloc];
  203154. }
  203155. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203156. {
  203157. const File f (nsStringToJuce (filename));
  203158. for (int i = filters->size(); --i >= 0;)
  203159. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203160. return true;
  203161. return f.isDirectory();
  203162. }
  203163. @end
  203164. BEGIN_JUCE_NAMESPACE
  203165. void FileChooser::showPlatformDialog (Array<File>& results,
  203166. const String& title,
  203167. const File& currentFileOrDirectory,
  203168. const String& filter,
  203169. bool selectsDirectory,
  203170. bool selectsFiles,
  203171. bool isSaveDialogue,
  203172. bool warnAboutOverwritingExistingFiles,
  203173. bool selectMultipleFiles,
  203174. FilePreviewComponent* extraInfoComponent)
  203175. {
  203176. const ScopedAutoReleasePool pool;
  203177. StringArray* filters = new StringArray();
  203178. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  203179. filters->trim();
  203180. filters->removeEmptyStrings();
  203181. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203182. [delegate autorelease];
  203183. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203184. : [NSOpenPanel openPanel];
  203185. [panel setTitle: juceStringToNS (title)];
  203186. if (! isSaveDialogue)
  203187. {
  203188. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203189. [openPanel setCanChooseDirectories: selectsDirectory];
  203190. [openPanel setCanChooseFiles: selectsFiles];
  203191. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203192. }
  203193. [panel setDelegate: delegate];
  203194. if (isSaveDialogue || selectsDirectory)
  203195. [panel setCanCreateDirectories: YES];
  203196. String directory, filename;
  203197. if (currentFileOrDirectory.isDirectory())
  203198. {
  203199. directory = currentFileOrDirectory.getFullPathName();
  203200. }
  203201. else
  203202. {
  203203. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203204. filename = currentFileOrDirectory.getFileName();
  203205. }
  203206. if ([panel runModalForDirectory: juceStringToNS (directory)
  203207. file: juceStringToNS (filename)]
  203208. == NSOKButton)
  203209. {
  203210. if (isSaveDialogue)
  203211. {
  203212. results.add (File (nsStringToJuce ([panel filename])));
  203213. }
  203214. else
  203215. {
  203216. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203217. NSArray* urls = [openPanel filenames];
  203218. for (unsigned int i = 0; i < [urls count]; ++i)
  203219. {
  203220. NSString* f = [urls objectAtIndex: i];
  203221. results.add (File (nsStringToJuce (f)));
  203222. }
  203223. }
  203224. }
  203225. [panel setDelegate: nil];
  203226. }
  203227. #else
  203228. void FileChooser::showPlatformDialog (Array<File>& results,
  203229. const String& title,
  203230. const File& currentFileOrDirectory,
  203231. const String& filter,
  203232. bool selectsDirectory,
  203233. bool selectsFiles,
  203234. bool isSaveDialogue,
  203235. bool warnAboutOverwritingExistingFiles,
  203236. bool selectMultipleFiles,
  203237. FilePreviewComponent* extraInfoComponent)
  203238. {
  203239. const ScopedAutoReleasePool pool;
  203240. jassertfalse //xxx to do
  203241. }
  203242. #endif
  203243. #endif
  203244. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203245. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203246. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203247. // compiled on its own).
  203248. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203249. #if JUCE_MAC
  203250. END_JUCE_NAMESPACE
  203251. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203252. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203253. {
  203254. CriticalSection* contextLock;
  203255. bool needsUpdate;
  203256. }
  203257. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203258. - (bool) makeActive;
  203259. - (void) makeInactive;
  203260. - (void) reshape;
  203261. @end
  203262. @implementation ThreadSafeNSOpenGLView
  203263. - (id) initWithFrame: (NSRect) frameRect
  203264. pixelFormat: (NSOpenGLPixelFormat*) format
  203265. {
  203266. contextLock = new CriticalSection();
  203267. self = [super initWithFrame: frameRect pixelFormat: format];
  203268. if (self != nil)
  203269. [[NSNotificationCenter defaultCenter] addObserver: self
  203270. selector: @selector (_surfaceNeedsUpdate:)
  203271. name: NSViewGlobalFrameDidChangeNotification
  203272. object: self];
  203273. return self;
  203274. }
  203275. - (void) dealloc
  203276. {
  203277. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203278. delete contextLock;
  203279. [super dealloc];
  203280. }
  203281. - (bool) makeActive
  203282. {
  203283. const ScopedLock sl (*contextLock);
  203284. if ([self openGLContext] == 0)
  203285. return false;
  203286. [[self openGLContext] makeCurrentContext];
  203287. if (needsUpdate)
  203288. {
  203289. [super update];
  203290. needsUpdate = false;
  203291. }
  203292. return true;
  203293. }
  203294. - (void) makeInactive
  203295. {
  203296. const ScopedLock sl (*contextLock);
  203297. [NSOpenGLContext clearCurrentContext];
  203298. }
  203299. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203300. {
  203301. const ScopedLock sl (*contextLock);
  203302. needsUpdate = true;
  203303. }
  203304. - (void) update
  203305. {
  203306. const ScopedLock sl (*contextLock);
  203307. needsUpdate = true;
  203308. }
  203309. - (void) reshape
  203310. {
  203311. const ScopedLock sl (*contextLock);
  203312. needsUpdate = true;
  203313. }
  203314. @end
  203315. BEGIN_JUCE_NAMESPACE
  203316. class WindowedGLContext : public OpenGLContext
  203317. {
  203318. public:
  203319. WindowedGLContext (Component* const component,
  203320. const OpenGLPixelFormat& pixelFormat_,
  203321. NSOpenGLContext* sharedContext)
  203322. : renderContext (0),
  203323. pixelFormat (pixelFormat_)
  203324. {
  203325. jassert (component != 0);
  203326. NSOpenGLPixelFormatAttribute attribs [64];
  203327. int n = 0;
  203328. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203329. attribs[n++] = NSOpenGLPFAAccelerated;
  203330. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203331. attribs[n++] = NSOpenGLPFAColorSize;
  203332. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203333. pixelFormat.greenBits,
  203334. pixelFormat.blueBits);
  203335. attribs[n++] = NSOpenGLPFAAlphaSize;
  203336. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203337. attribs[n++] = NSOpenGLPFADepthSize;
  203338. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203339. attribs[n++] = NSOpenGLPFAStencilSize;
  203340. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203341. attribs[n++] = NSOpenGLPFAAccumSize;
  203342. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203343. pixelFormat.accumulationBufferGreenBits,
  203344. pixelFormat.accumulationBufferBlueBits,
  203345. pixelFormat.accumulationBufferAlphaBits);
  203346. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203347. attribs[n++] = NSOpenGLPFASampleBuffers;
  203348. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203349. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203350. attribs[n++] = NSOpenGLPFANoRecovery;
  203351. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203352. NSOpenGLPixelFormat* format
  203353. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203354. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203355. pixelFormat: format];
  203356. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203357. shareContext: sharedContext] autorelease];
  203358. const GLint swapInterval = 1;
  203359. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203360. [view setOpenGLContext: renderContext];
  203361. [renderContext setView: view];
  203362. [format release];
  203363. viewHolder = new NSViewComponentInternal (view, component);
  203364. }
  203365. ~WindowedGLContext()
  203366. {
  203367. makeInactive();
  203368. [renderContext clearDrawable];
  203369. viewHolder = 0;
  203370. }
  203371. bool makeActive() const throw()
  203372. {
  203373. jassert (renderContext != 0);
  203374. [view makeActive];
  203375. return isActive();
  203376. }
  203377. bool makeInactive() const throw()
  203378. {
  203379. [view makeInactive];
  203380. return true;
  203381. }
  203382. bool isActive() const throw()
  203383. {
  203384. return [NSOpenGLContext currentContext] == renderContext;
  203385. }
  203386. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203387. void* getRawContext() const throw() { return renderContext; }
  203388. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203389. {
  203390. }
  203391. void swapBuffers()
  203392. {
  203393. [renderContext flushBuffer];
  203394. }
  203395. bool setSwapInterval (const int numFramesPerSwap)
  203396. {
  203397. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203398. forParameter: NSOpenGLCPSwapInterval];
  203399. return true;
  203400. }
  203401. int getSwapInterval() const
  203402. {
  203403. GLint numFrames = 0;
  203404. [renderContext getValues: &numFrames
  203405. forParameter: NSOpenGLCPSwapInterval];
  203406. return numFrames;
  203407. }
  203408. void repaint()
  203409. {
  203410. // we need to invalidate the juce view that holds this gl view, to make it
  203411. // cause a repaint callback
  203412. NSView* v = (NSView*) viewHolder->view;
  203413. NSRect r = [v frame];
  203414. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203415. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203416. // repaint message, thus never causing our paint() callback, and never repainting
  203417. // the comp. So invalidating just a little bit around the edge helps..
  203418. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203419. }
  203420. void* getNativeWindowHandle() const { return viewHolder->view; }
  203421. juce_UseDebuggingNewOperator
  203422. NSOpenGLContext* renderContext;
  203423. ThreadSafeNSOpenGLView* view;
  203424. private:
  203425. OpenGLPixelFormat pixelFormat;
  203426. ScopedPointer <NSViewComponentInternal> viewHolder;
  203427. WindowedGLContext (const WindowedGLContext&);
  203428. WindowedGLContext& operator= (const WindowedGLContext&);
  203429. };
  203430. OpenGLContext* OpenGLComponent::createContext()
  203431. {
  203432. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  203433. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  203434. return (c->renderContext != 0) ? c.release() : 0;
  203435. }
  203436. void* OpenGLComponent::getNativeWindowHandle() const
  203437. {
  203438. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  203439. : 0;
  203440. }
  203441. void juce_glViewport (const int w, const int h)
  203442. {
  203443. glViewport (0, 0, w, h);
  203444. }
  203445. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203446. OwnedArray <OpenGLPixelFormat>& results)
  203447. {
  203448. /* GLint attribs [64];
  203449. int n = 0;
  203450. attribs[n++] = AGL_RGBA;
  203451. attribs[n++] = AGL_DOUBLEBUFFER;
  203452. attribs[n++] = AGL_ACCELERATED;
  203453. attribs[n++] = AGL_NO_RECOVERY;
  203454. attribs[n++] = AGL_NONE;
  203455. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203456. while (p != 0)
  203457. {
  203458. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203459. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203460. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203461. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203462. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203463. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203464. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203465. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203466. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203467. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203468. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203469. results.add (pf);
  203470. p = aglNextPixelFormat (p);
  203471. }*/
  203472. //jassertfalse //xxx can't see how you do this in cocoa!
  203473. }
  203474. #else
  203475. END_JUCE_NAMESPACE
  203476. @interface JuceGLView : UIView
  203477. {
  203478. }
  203479. + (Class) layerClass;
  203480. @end
  203481. @implementation JuceGLView
  203482. + (Class) layerClass
  203483. {
  203484. return [CAEAGLLayer class];
  203485. }
  203486. @end
  203487. BEGIN_JUCE_NAMESPACE
  203488. class GLESContext : public OpenGLContext
  203489. {
  203490. public:
  203491. GLESContext (UIViewComponentPeer* peer,
  203492. Component* const component_,
  203493. const OpenGLPixelFormat& pixelFormat_,
  203494. const GLESContext* const sharedContext,
  203495. NSUInteger apiType)
  203496. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  203497. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  203498. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  203499. {
  203500. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  203501. view.opaque = YES;
  203502. view.hidden = NO;
  203503. view.backgroundColor = [UIColor blackColor];
  203504. view.userInteractionEnabled = NO;
  203505. glLayer = (CAEAGLLayer*) [view layer];
  203506. [peer->view addSubview: view];
  203507. if (sharedContext != 0)
  203508. context = [[EAGLContext alloc] initWithAPI: apiType
  203509. sharegroup: [sharedContext->context sharegroup]];
  203510. else
  203511. context = [[EAGLContext alloc] initWithAPI: apiType];
  203512. createGLBuffers();
  203513. }
  203514. ~GLESContext()
  203515. {
  203516. makeInactive();
  203517. [context release];
  203518. [view removeFromSuperview];
  203519. [view release];
  203520. freeGLBuffers();
  203521. }
  203522. bool makeActive() const throw()
  203523. {
  203524. jassert (context != 0);
  203525. [EAGLContext setCurrentContext: context];
  203526. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203527. return true;
  203528. }
  203529. void swapBuffers()
  203530. {
  203531. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203532. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  203533. }
  203534. bool makeInactive() const throw()
  203535. {
  203536. return [EAGLContext setCurrentContext: nil];
  203537. }
  203538. bool isActive() const throw()
  203539. {
  203540. return [EAGLContext currentContext] == context;
  203541. }
  203542. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203543. void* getRawContext() const throw() { return glLayer; }
  203544. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203545. {
  203546. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  203547. if (lastWidth != w || lastHeight != h)
  203548. {
  203549. lastWidth = w;
  203550. lastHeight = h;
  203551. freeGLBuffers();
  203552. createGLBuffers();
  203553. }
  203554. }
  203555. bool setSwapInterval (const int numFramesPerSwap)
  203556. {
  203557. numFrames = numFramesPerSwap;
  203558. return true;
  203559. }
  203560. int getSwapInterval() const
  203561. {
  203562. return numFrames;
  203563. }
  203564. void repaint()
  203565. {
  203566. }
  203567. void createGLBuffers()
  203568. {
  203569. makeActive();
  203570. glGenFramebuffersOES (1, &frameBufferHandle);
  203571. glGenRenderbuffersOES (1, &colorBufferHandle);
  203572. glGenRenderbuffersOES (1, &depthBufferHandle);
  203573. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203574. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  203575. GLint width, height;
  203576. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  203577. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  203578. if (useDepthBuffer)
  203579. {
  203580. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  203581. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  203582. }
  203583. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203584. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203585. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  203586. if (useDepthBuffer)
  203587. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  203588. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  203589. }
  203590. void freeGLBuffers()
  203591. {
  203592. if (frameBufferHandle != 0)
  203593. {
  203594. glDeleteFramebuffersOES (1, &frameBufferHandle);
  203595. frameBufferHandle = 0;
  203596. }
  203597. if (colorBufferHandle != 0)
  203598. {
  203599. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  203600. colorBufferHandle = 0;
  203601. }
  203602. if (depthBufferHandle != 0)
  203603. {
  203604. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  203605. depthBufferHandle = 0;
  203606. }
  203607. }
  203608. juce_UseDebuggingNewOperator
  203609. private:
  203610. Component::SafePointer<Component> component;
  203611. OpenGLPixelFormat pixelFormat;
  203612. JuceGLView* view;
  203613. CAEAGLLayer* glLayer;
  203614. EAGLContext* context;
  203615. bool useDepthBuffer;
  203616. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  203617. int numFrames;
  203618. int lastWidth, lastHeight;
  203619. GLESContext (const GLESContext&);
  203620. GLESContext& operator= (const GLESContext&);
  203621. };
  203622. OpenGLContext* OpenGLComponent::createContext()
  203623. {
  203624. ScopedAutoReleasePool pool;
  203625. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  203626. if (peer != 0)
  203627. return new GLESContext (peer, this, preferredPixelFormat,
  203628. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  203629. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  203630. return 0;
  203631. }
  203632. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203633. OwnedArray <OpenGLPixelFormat>& /*results*/)
  203634. {
  203635. }
  203636. void juce_glViewport (const int w, const int h)
  203637. {
  203638. glViewport (0, 0, w, h);
  203639. }
  203640. #endif
  203641. #endif
  203642. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  203643. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  203644. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203645. // compiled on its own).
  203646. #if JUCE_INCLUDED_FILE
  203647. #if JUCE_MAC
  203648. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  203649. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  203650. {
  203651. NSImage* im = CoreGraphicsImage::createNSImage (image);
  203652. NSCursor* c = [[NSCursor alloc] initWithImage: im
  203653. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  203654. [im release];
  203655. return c;
  203656. }
  203657. static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy)
  203658. {
  203659. MemoryInputStream stream (data, false);
  203660. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  203661. jassert (im != 0);
  203662. if (im == 0)
  203663. return 0;
  203664. return juce_createMouseCursorFromImage (*im,
  203665. (int) (hx * im->getWidth()),
  203666. (int) (hy * im->getHeight()));
  203667. }
  203668. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  203669. {
  203670. const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  203671. MemoryBlock mb;
  203672. if (f.getChildFile (filename).loadFileAsData (mb))
  203673. return juce_cursorFromData (mb, hx, hy);
  203674. return 0;
  203675. }
  203676. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  203677. {
  203678. const ScopedAutoReleasePool pool;
  203679. NSCursor* c = 0;
  203680. switch (type)
  203681. {
  203682. case MouseCursor::NormalCursor:
  203683. c = [NSCursor arrowCursor];
  203684. break;
  203685. case MouseCursor::NoCursor:
  203686. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  203687. case MouseCursor::DraggingHandCursor:
  203688. c = [NSCursor openHandCursor];
  203689. break;
  203690. case MouseCursor::CopyingCursor:
  203691. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  203692. case MouseCursor::WaitCursor:
  203693. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  203694. break;
  203695. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  203696. case MouseCursor::IBeamCursor:
  203697. c = [NSCursor IBeamCursor];
  203698. break;
  203699. case MouseCursor::PointingHandCursor:
  203700. c = [NSCursor pointingHandCursor];
  203701. break;
  203702. case MouseCursor::LeftRightResizeCursor:
  203703. c = [NSCursor resizeLeftRightCursor];
  203704. break;
  203705. case MouseCursor::LeftEdgeResizeCursor:
  203706. c = [NSCursor resizeLeftCursor];
  203707. break;
  203708. case MouseCursor::RightEdgeResizeCursor:
  203709. c = [NSCursor resizeRightCursor];
  203710. break;
  203711. case MouseCursor::UpDownResizeCursor:
  203712. case MouseCursor::TopEdgeResizeCursor:
  203713. case MouseCursor::BottomEdgeResizeCursor:
  203714. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  203715. case MouseCursor::TopLeftCornerResizeCursor:
  203716. case MouseCursor::BottomRightCornerResizeCursor:
  203717. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  203718. case MouseCursor::TopRightCornerResizeCursor:
  203719. case MouseCursor::BottomLeftCornerResizeCursor:
  203720. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  203721. case MouseCursor::UpDownLeftRightResizeCursor:
  203722. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  203723. case MouseCursor::CrosshairCursor:
  203724. c = [NSCursor crosshairCursor];
  203725. break;
  203726. }
  203727. [c retain];
  203728. return c;
  203729. }
  203730. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  203731. {
  203732. NSCursor* c = (NSCursor*) cursorHandle;
  203733. [c release];
  203734. }
  203735. void MouseCursor::showInAllWindows() const
  203736. {
  203737. showInWindow (0);
  203738. }
  203739. void MouseCursor::showInWindow (ComponentPeer*) const
  203740. {
  203741. NSCursor* const c = (NSCursor*) getHandle();
  203742. [c set];
  203743. }
  203744. #else
  203745. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; }
  203746. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; }
  203747. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {}
  203748. void MouseCursor::showInAllWindows() const {}
  203749. void MouseCursor::showInWindow (ComponentPeer*) const {}
  203750. #endif
  203751. #endif
  203752. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  203753. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  203754. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203755. // compiled on its own).
  203756. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  203757. #if JUCE_MAC
  203758. END_JUCE_NAMESPACE
  203759. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  203760. @interface DownloadClickDetector : NSObject
  203761. {
  203762. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  203763. }
  203764. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  203765. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  203766. request: (NSURLRequest*) request
  203767. frame: (WebFrame*) frame
  203768. decisionListener: (id<WebPolicyDecisionListener>) listener;
  203769. @end
  203770. @implementation DownloadClickDetector
  203771. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  203772. {
  203773. [super init];
  203774. ownerComponent = ownerComponent_;
  203775. return self;
  203776. }
  203777. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  203778. request: (NSURLRequest*) request
  203779. frame: (WebFrame*) frame
  203780. decisionListener: (id <WebPolicyDecisionListener>) listener
  203781. {
  203782. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  203783. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  203784. [listener use];
  203785. else
  203786. [listener ignore];
  203787. }
  203788. @end
  203789. BEGIN_JUCE_NAMESPACE
  203790. class WebBrowserComponentInternal : public NSViewComponent
  203791. {
  203792. public:
  203793. WebBrowserComponentInternal (WebBrowserComponent* owner)
  203794. {
  203795. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203796. frameName: @""
  203797. groupName: @""];
  203798. setView (webView);
  203799. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  203800. [webView setPolicyDelegate: clickListener];
  203801. }
  203802. ~WebBrowserComponentInternal()
  203803. {
  203804. [webView setPolicyDelegate: nil];
  203805. [clickListener release];
  203806. setView (0);
  203807. }
  203808. void goToURL (const String& url,
  203809. const StringArray* headers,
  203810. const MemoryBlock* postData)
  203811. {
  203812. NSMutableURLRequest* r
  203813. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  203814. cachePolicy: NSURLRequestUseProtocolCachePolicy
  203815. timeoutInterval: 30.0];
  203816. if (postData != 0 && postData->getSize() > 0)
  203817. {
  203818. [r setHTTPMethod: @"POST"];
  203819. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  203820. length: postData->getSize()]];
  203821. }
  203822. if (headers != 0)
  203823. {
  203824. for (int i = 0; i < headers->size(); ++i)
  203825. {
  203826. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  203827. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  203828. [r setValue: juceStringToNS (headerValue)
  203829. forHTTPHeaderField: juceStringToNS (headerName)];
  203830. }
  203831. }
  203832. stop();
  203833. [[webView mainFrame] loadRequest: r];
  203834. }
  203835. void goBack()
  203836. {
  203837. [webView goBack];
  203838. }
  203839. void goForward()
  203840. {
  203841. [webView goForward];
  203842. }
  203843. void stop()
  203844. {
  203845. [webView stopLoading: nil];
  203846. }
  203847. void refresh()
  203848. {
  203849. [webView reload: nil];
  203850. }
  203851. private:
  203852. WebView* webView;
  203853. DownloadClickDetector* clickListener;
  203854. };
  203855. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  203856. : browser (0),
  203857. blankPageShown (false),
  203858. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  203859. {
  203860. setOpaque (true);
  203861. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  203862. }
  203863. WebBrowserComponent::~WebBrowserComponent()
  203864. {
  203865. deleteAndZero (browser);
  203866. }
  203867. void WebBrowserComponent::goToURL (const String& url,
  203868. const StringArray* headers,
  203869. const MemoryBlock* postData)
  203870. {
  203871. lastURL = url;
  203872. lastHeaders.clear();
  203873. if (headers != 0)
  203874. lastHeaders = *headers;
  203875. lastPostData.setSize (0);
  203876. if (postData != 0)
  203877. lastPostData = *postData;
  203878. blankPageShown = false;
  203879. browser->goToURL (url, headers, postData);
  203880. }
  203881. void WebBrowserComponent::stop()
  203882. {
  203883. browser->stop();
  203884. }
  203885. void WebBrowserComponent::goBack()
  203886. {
  203887. lastURL = String::empty;
  203888. blankPageShown = false;
  203889. browser->goBack();
  203890. }
  203891. void WebBrowserComponent::goForward()
  203892. {
  203893. lastURL = String::empty;
  203894. browser->goForward();
  203895. }
  203896. void WebBrowserComponent::refresh()
  203897. {
  203898. browser->refresh();
  203899. }
  203900. void WebBrowserComponent::paint (Graphics& g)
  203901. {
  203902. }
  203903. void WebBrowserComponent::checkWindowAssociation()
  203904. {
  203905. if (isShowing())
  203906. {
  203907. if (blankPageShown)
  203908. goBack();
  203909. }
  203910. else
  203911. {
  203912. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  203913. {
  203914. // when the component becomes invisible, some stuff like flash
  203915. // carries on playing audio, so we need to force it onto a blank
  203916. // page to avoid this, (and send it back when it's made visible again).
  203917. blankPageShown = true;
  203918. browser->goToURL ("about:blank", 0, 0);
  203919. }
  203920. }
  203921. }
  203922. void WebBrowserComponent::reloadLastURL()
  203923. {
  203924. if (lastURL.isNotEmpty())
  203925. {
  203926. goToURL (lastURL, &lastHeaders, &lastPostData);
  203927. lastURL = String::empty;
  203928. }
  203929. }
  203930. void WebBrowserComponent::parentHierarchyChanged()
  203931. {
  203932. checkWindowAssociation();
  203933. }
  203934. void WebBrowserComponent::resized()
  203935. {
  203936. browser->setSize (getWidth(), getHeight());
  203937. }
  203938. void WebBrowserComponent::visibilityChanged()
  203939. {
  203940. checkWindowAssociation();
  203941. }
  203942. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  203943. {
  203944. return true;
  203945. }
  203946. #else
  203947. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  203948. {
  203949. }
  203950. WebBrowserComponent::~WebBrowserComponent()
  203951. {
  203952. }
  203953. void WebBrowserComponent::goToURL (const String& url,
  203954. const StringArray* headers,
  203955. const MemoryBlock* postData)
  203956. {
  203957. }
  203958. void WebBrowserComponent::stop()
  203959. {
  203960. }
  203961. void WebBrowserComponent::goBack()
  203962. {
  203963. }
  203964. void WebBrowserComponent::goForward()
  203965. {
  203966. }
  203967. void WebBrowserComponent::refresh()
  203968. {
  203969. }
  203970. void WebBrowserComponent::paint (Graphics& g)
  203971. {
  203972. }
  203973. void WebBrowserComponent::checkWindowAssociation()
  203974. {
  203975. }
  203976. void WebBrowserComponent::reloadLastURL()
  203977. {
  203978. }
  203979. void WebBrowserComponent::parentHierarchyChanged()
  203980. {
  203981. }
  203982. void WebBrowserComponent::resized()
  203983. {
  203984. }
  203985. void WebBrowserComponent::visibilityChanged()
  203986. {
  203987. }
  203988. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  203989. {
  203990. return true;
  203991. }
  203992. #endif
  203993. #endif
  203994. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  203995. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  203996. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203997. // compiled on its own).
  203998. #if JUCE_INCLUDED_FILE
  203999. class IPhoneAudioIODevice : public AudioIODevice
  204000. {
  204001. public:
  204002. IPhoneAudioIODevice (const String& deviceName)
  204003. : AudioIODevice (deviceName, "Audio"),
  204004. audioUnit (0),
  204005. isRunning (false),
  204006. callback (0),
  204007. actualBufferSize (0),
  204008. floatData (1, 2)
  204009. {
  204010. numInputChannels = 2;
  204011. numOutputChannels = 2;
  204012. preferredBufferSize = 0;
  204013. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204014. updateDeviceInfo();
  204015. }
  204016. ~IPhoneAudioIODevice()
  204017. {
  204018. close();
  204019. }
  204020. const StringArray getOutputChannelNames()
  204021. {
  204022. StringArray s;
  204023. s.add ("Left");
  204024. s.add ("Right");
  204025. return s;
  204026. }
  204027. const StringArray getInputChannelNames()
  204028. {
  204029. StringArray s;
  204030. if (audioInputIsAvailable)
  204031. {
  204032. s.add ("Left");
  204033. s.add ("Right");
  204034. }
  204035. return s;
  204036. }
  204037. int getNumSampleRates()
  204038. {
  204039. return 1;
  204040. }
  204041. double getSampleRate (int index)
  204042. {
  204043. return sampleRate;
  204044. }
  204045. int getNumBufferSizesAvailable()
  204046. {
  204047. return 1;
  204048. }
  204049. int getBufferSizeSamples (int index)
  204050. {
  204051. return getDefaultBufferSize();
  204052. }
  204053. int getDefaultBufferSize()
  204054. {
  204055. return 1024;
  204056. }
  204057. const String open (const BigInteger& inputChannels,
  204058. const BigInteger& outputChannels,
  204059. double sampleRate,
  204060. int bufferSize)
  204061. {
  204062. close();
  204063. lastError = String::empty;
  204064. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204065. // xxx set up channel mapping
  204066. activeOutputChans = outputChannels;
  204067. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204068. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204069. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204070. activeInputChans = inputChannels;
  204071. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204072. numInputChannels = activeInputChans.countNumberOfSetBits();
  204073. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204074. AudioSessionSetActive (true);
  204075. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204076. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204077. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204078. fixAudioRouteIfSetToReceiver();
  204079. updateDeviceInfo();
  204080. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204081. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204082. actualBufferSize = preferredBufferSize;
  204083. prepareFloatBuffers();
  204084. isRunning = true;
  204085. propertyChanged (0, 0, 0); // creates and starts the AU
  204086. lastError = audioUnit != 0 ? "" : "Couldn't open the device";
  204087. return lastError;
  204088. }
  204089. void close()
  204090. {
  204091. if (isRunning)
  204092. {
  204093. isRunning = false;
  204094. AudioSessionSetActive (false);
  204095. if (audioUnit != 0)
  204096. {
  204097. AudioComponentInstanceDispose (audioUnit);
  204098. audioUnit = 0;
  204099. }
  204100. }
  204101. }
  204102. bool isOpen()
  204103. {
  204104. return isRunning;
  204105. }
  204106. int getCurrentBufferSizeSamples()
  204107. {
  204108. return actualBufferSize;
  204109. }
  204110. double getCurrentSampleRate()
  204111. {
  204112. return sampleRate;
  204113. }
  204114. int getCurrentBitDepth()
  204115. {
  204116. return 16;
  204117. }
  204118. const BigInteger getActiveOutputChannels() const
  204119. {
  204120. return activeOutputChans;
  204121. }
  204122. const BigInteger getActiveInputChannels() const
  204123. {
  204124. return activeInputChans;
  204125. }
  204126. int getOutputLatencyInSamples()
  204127. {
  204128. return 0; //xxx
  204129. }
  204130. int getInputLatencyInSamples()
  204131. {
  204132. return 0; //xxx
  204133. }
  204134. void start (AudioIODeviceCallback* callback_)
  204135. {
  204136. if (isRunning && callback != callback_)
  204137. {
  204138. if (callback_ != 0)
  204139. callback_->audioDeviceAboutToStart (this);
  204140. const ScopedLock sl (callbackLock);
  204141. callback = callback_;
  204142. }
  204143. }
  204144. void stop()
  204145. {
  204146. if (isRunning)
  204147. {
  204148. AudioIODeviceCallback* lastCallback;
  204149. {
  204150. const ScopedLock sl (callbackLock);
  204151. lastCallback = callback;
  204152. callback = 0;
  204153. }
  204154. if (lastCallback != 0)
  204155. lastCallback->audioDeviceStopped();
  204156. }
  204157. }
  204158. bool isPlaying()
  204159. {
  204160. return isRunning && callback != 0;
  204161. }
  204162. const String getLastError()
  204163. {
  204164. return lastError;
  204165. }
  204166. private:
  204167. CriticalSection callbackLock;
  204168. Float64 sampleRate;
  204169. int numInputChannels, numOutputChannels;
  204170. int preferredBufferSize;
  204171. int actualBufferSize;
  204172. bool isRunning;
  204173. String lastError;
  204174. AudioStreamBasicDescription format;
  204175. AudioUnit audioUnit;
  204176. UInt32 audioInputIsAvailable;
  204177. AudioIODeviceCallback* callback;
  204178. BigInteger activeOutputChans, activeInputChans;
  204179. AudioSampleBuffer floatData;
  204180. float* inputChannels[3];
  204181. float* outputChannels[3];
  204182. bool monoInputChannelNumber, monoOutputChannelNumber;
  204183. void prepareFloatBuffers()
  204184. {
  204185. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204186. zerostruct (inputChannels);
  204187. zerostruct (outputChannels);
  204188. for (int i = 0; i < numInputChannels; ++i)
  204189. inputChannels[i] = floatData.getSampleData (i);
  204190. for (int i = 0; i < numOutputChannels; ++i)
  204191. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204192. }
  204193. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204194. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204195. {
  204196. OSStatus err = noErr;
  204197. if (audioInputIsAvailable)
  204198. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204199. const ScopedLock sl (callbackLock);
  204200. if (callback != 0)
  204201. {
  204202. if (audioInputIsAvailable && numInputChannels > 0)
  204203. {
  204204. short* shortData = (short*) ioData->mBuffers[0].mData;
  204205. if (numInputChannels >= 2)
  204206. {
  204207. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204208. {
  204209. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204210. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204211. }
  204212. }
  204213. else
  204214. {
  204215. if (monoInputChannelNumber > 0)
  204216. ++shortData;
  204217. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204218. {
  204219. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204220. ++shortData;
  204221. }
  204222. }
  204223. }
  204224. else
  204225. {
  204226. for (int i = numInputChannels; --i >= 0;)
  204227. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204228. }
  204229. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204230. outputChannels, numOutputChannels,
  204231. (int) inNumberFrames);
  204232. short* shortData = (short*) ioData->mBuffers[0].mData;
  204233. int n = 0;
  204234. if (numOutputChannels >= 2)
  204235. {
  204236. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204237. {
  204238. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204239. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204240. }
  204241. }
  204242. else if (numOutputChannels == 1)
  204243. {
  204244. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204245. {
  204246. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204247. shortData [n++] = s;
  204248. shortData [n++] = s;
  204249. }
  204250. }
  204251. else
  204252. {
  204253. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204254. }
  204255. }
  204256. else
  204257. {
  204258. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204259. }
  204260. return err;
  204261. }
  204262. void updateDeviceInfo()
  204263. {
  204264. UInt32 size = sizeof (sampleRate);
  204265. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204266. size = sizeof (audioInputIsAvailable);
  204267. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204268. }
  204269. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204270. {
  204271. if (! isRunning)
  204272. return;
  204273. if (inPropertyValue != 0)
  204274. {
  204275. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204276. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204277. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204278. SInt32 routeChangeReason;
  204279. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204280. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204281. fixAudioRouteIfSetToReceiver();
  204282. }
  204283. updateDeviceInfo();
  204284. createAudioUnit();
  204285. AudioSessionSetActive (true);
  204286. if (audioUnit != 0)
  204287. {
  204288. UInt32 formatSize = sizeof (format);
  204289. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204290. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204291. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204292. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204293. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204294. AudioOutputUnitStart (audioUnit);
  204295. }
  204296. }
  204297. void interruptionListener (UInt32 inInterruption)
  204298. {
  204299. if (inInterruption == kAudioSessionEndInterruption)
  204300. {
  204301. isRunning = true;
  204302. AudioSessionSetActive (true);
  204303. AudioOutputUnitStart (audioUnit);
  204304. }
  204305. }
  204306. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204307. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204308. {
  204309. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204310. }
  204311. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204312. {
  204313. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204314. }
  204315. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204316. {
  204317. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204318. }
  204319. void resetFormat (const int numChannels)
  204320. {
  204321. memset (&format, 0, sizeof (format));
  204322. format.mFormatID = kAudioFormatLinearPCM;
  204323. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204324. format.mBitsPerChannel = 8 * sizeof (short);
  204325. format.mChannelsPerFrame = 2;
  204326. format.mFramesPerPacket = 1;
  204327. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204328. }
  204329. bool createAudioUnit()
  204330. {
  204331. if (audioUnit != 0)
  204332. {
  204333. AudioComponentInstanceDispose (audioUnit);
  204334. audioUnit = 0;
  204335. }
  204336. resetFormat (2);
  204337. AudioComponentDescription desc;
  204338. desc.componentType = kAudioUnitType_Output;
  204339. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204340. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204341. desc.componentFlags = 0;
  204342. desc.componentFlagsMask = 0;
  204343. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204344. AudioComponentInstanceNew (comp, &audioUnit);
  204345. if (audioUnit == 0)
  204346. return false;
  204347. const UInt32 one = 1;
  204348. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204349. AudioChannelLayout layout;
  204350. layout.mChannelBitmap = 0;
  204351. layout.mNumberChannelDescriptions = 0;
  204352. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204353. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204354. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204355. AURenderCallbackStruct inputProc;
  204356. inputProc.inputProc = processStatic;
  204357. inputProc.inputProcRefCon = this;
  204358. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204359. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204360. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204361. AudioUnitInitialize (audioUnit);
  204362. return true;
  204363. }
  204364. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204365. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204366. static void fixAudioRouteIfSetToReceiver()
  204367. {
  204368. CFStringRef audioRoute = 0;
  204369. UInt32 propertySize = sizeof (audioRoute);
  204370. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204371. {
  204372. NSString* route = (NSString*) audioRoute;
  204373. //DBG ("audio route: " + nsStringToJuce (route));
  204374. if ([route hasPrefix: @"Receiver"])
  204375. {
  204376. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204377. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204378. }
  204379. CFRelease (audioRoute);
  204380. }
  204381. }
  204382. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204383. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204384. };
  204385. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204386. {
  204387. public:
  204388. IPhoneAudioIODeviceType()
  204389. : AudioIODeviceType ("iPhone Audio")
  204390. {
  204391. }
  204392. ~IPhoneAudioIODeviceType()
  204393. {
  204394. }
  204395. void scanForDevices()
  204396. {
  204397. }
  204398. const StringArray getDeviceNames (bool wantInputNames) const
  204399. {
  204400. StringArray s;
  204401. s.add ("iPhone Audio");
  204402. return s;
  204403. }
  204404. int getDefaultDeviceIndex (bool forInput) const
  204405. {
  204406. return 0;
  204407. }
  204408. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  204409. {
  204410. return device != 0 ? 0 : -1;
  204411. }
  204412. bool hasSeparateInputsAndOutputs() const { return false; }
  204413. AudioIODevice* createDevice (const String& outputDeviceName,
  204414. const String& inputDeviceName)
  204415. {
  204416. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204417. {
  204418. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204419. : inputDeviceName);
  204420. }
  204421. return 0;
  204422. }
  204423. juce_UseDebuggingNewOperator
  204424. private:
  204425. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204426. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204427. };
  204428. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204429. {
  204430. return new IPhoneAudioIODeviceType();
  204431. }
  204432. #endif
  204433. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204434. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204435. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204436. // compiled on its own).
  204437. #if JUCE_INCLUDED_FILE
  204438. #if JUCE_MAC
  204439. #undef log
  204440. #define log(a) Logger::writeToLog(a)
  204441. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204442. {
  204443. if (err == noErr)
  204444. return true;
  204445. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  204446. jassertfalse
  204447. return false;
  204448. }
  204449. #undef OK
  204450. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204451. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204452. {
  204453. String result;
  204454. CFStringRef str = 0;
  204455. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204456. if (str != 0)
  204457. {
  204458. result = PlatformUtilities::cfStringToJuceString (str);
  204459. CFRelease (str);
  204460. str = 0;
  204461. }
  204462. MIDIEntityRef entity = 0;
  204463. MIDIEndpointGetEntity (endpoint, &entity);
  204464. if (entity == 0)
  204465. return result; // probably virtual
  204466. if (result.isEmpty())
  204467. {
  204468. // endpoint name has zero length - try the entity
  204469. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204470. if (str != 0)
  204471. {
  204472. result += PlatformUtilities::cfStringToJuceString (str);
  204473. CFRelease (str);
  204474. str = 0;
  204475. }
  204476. }
  204477. // now consider the device's name
  204478. MIDIDeviceRef device = 0;
  204479. MIDIEntityGetDevice (entity, &device);
  204480. if (device == 0)
  204481. return result;
  204482. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204483. if (str != 0)
  204484. {
  204485. const String s (PlatformUtilities::cfStringToJuceString (str));
  204486. CFRelease (str);
  204487. // if an external device has only one entity, throw away
  204488. // the endpoint name and just use the device name
  204489. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204490. {
  204491. result = s;
  204492. }
  204493. else if (! result.startsWithIgnoreCase (s))
  204494. {
  204495. // prepend the device name to the entity name
  204496. result = (s + " " + result).trimEnd();
  204497. }
  204498. }
  204499. return result;
  204500. }
  204501. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204502. {
  204503. String result;
  204504. // Does the endpoint have connections?
  204505. CFDataRef connections = 0;
  204506. int numConnections = 0;
  204507. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204508. if (connections != 0)
  204509. {
  204510. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204511. if (numConnections > 0)
  204512. {
  204513. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204514. for (int i = 0; i < numConnections; ++i, ++pid)
  204515. {
  204516. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204517. MIDIObjectRef connObject;
  204518. MIDIObjectType connObjectType;
  204519. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204520. if (err == noErr)
  204521. {
  204522. String s;
  204523. if (connObjectType == kMIDIObjectType_ExternalSource
  204524. || connObjectType == kMIDIObjectType_ExternalDestination)
  204525. {
  204526. // Connected to an external device's endpoint (10.3 and later).
  204527. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204528. }
  204529. else
  204530. {
  204531. // Connected to an external device (10.2) (or something else, catch-all)
  204532. CFStringRef str = 0;
  204533. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204534. if (str != 0)
  204535. {
  204536. s = PlatformUtilities::cfStringToJuceString (str);
  204537. CFRelease (str);
  204538. }
  204539. }
  204540. if (s.isNotEmpty())
  204541. {
  204542. if (result.isNotEmpty())
  204543. result += ", ";
  204544. result += s;
  204545. }
  204546. }
  204547. }
  204548. }
  204549. CFRelease (connections);
  204550. }
  204551. if (result.isNotEmpty())
  204552. return result;
  204553. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204554. return getEndpointName (endpoint, false);
  204555. }
  204556. const StringArray MidiOutput::getDevices()
  204557. {
  204558. StringArray s;
  204559. const ItemCount num = MIDIGetNumberOfDestinations();
  204560. for (ItemCount i = 0; i < num; ++i)
  204561. {
  204562. MIDIEndpointRef dest = MIDIGetDestination (i);
  204563. if (dest != 0)
  204564. {
  204565. String name (getConnectedEndpointName (dest));
  204566. if (name.isEmpty())
  204567. name = "<error>";
  204568. s.add (name);
  204569. }
  204570. else
  204571. {
  204572. s.add ("<error>");
  204573. }
  204574. }
  204575. return s;
  204576. }
  204577. int MidiOutput::getDefaultDeviceIndex()
  204578. {
  204579. return 0;
  204580. }
  204581. static MIDIClientRef globalMidiClient;
  204582. static bool hasGlobalClientBeenCreated = false;
  204583. static bool makeSureClientExists()
  204584. {
  204585. if (! hasGlobalClientBeenCreated)
  204586. {
  204587. String name ("JUCE");
  204588. if (JUCEApplication::getInstance() != 0)
  204589. name = JUCEApplication::getInstance()->getApplicationName();
  204590. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  204591. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  204592. CFRelease (appName);
  204593. }
  204594. return hasGlobalClientBeenCreated;
  204595. }
  204596. class MidiPortAndEndpoint
  204597. {
  204598. public:
  204599. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  204600. : port (port_), endPoint (endPoint_)
  204601. {
  204602. }
  204603. ~MidiPortAndEndpoint()
  204604. {
  204605. if (port != 0)
  204606. MIDIPortDispose (port);
  204607. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  204608. MIDIEndpointDispose (endPoint);
  204609. }
  204610. MIDIPortRef port;
  204611. MIDIEndpointRef endPoint;
  204612. };
  204613. MidiOutput* MidiOutput::openDevice (int index)
  204614. {
  204615. MidiOutput* mo = 0;
  204616. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  204617. {
  204618. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  204619. CFStringRef pname;
  204620. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  204621. {
  204622. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  204623. if (makeSureClientExists())
  204624. {
  204625. MIDIPortRef port;
  204626. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  204627. {
  204628. mo = new MidiOutput();
  204629. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  204630. }
  204631. }
  204632. CFRelease (pname);
  204633. }
  204634. }
  204635. return mo;
  204636. }
  204637. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  204638. {
  204639. MidiOutput* mo = 0;
  204640. if (makeSureClientExists())
  204641. {
  204642. MIDIEndpointRef endPoint;
  204643. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  204644. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  204645. {
  204646. mo = new MidiOutput();
  204647. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  204648. }
  204649. CFRelease (name);
  204650. }
  204651. return mo;
  204652. }
  204653. MidiOutput::~MidiOutput()
  204654. {
  204655. delete (MidiPortAndEndpoint*) internal;
  204656. }
  204657. void MidiOutput::reset()
  204658. {
  204659. }
  204660. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  204661. {
  204662. return false;
  204663. }
  204664. void MidiOutput::setVolume (float leftVol, float rightVol)
  204665. {
  204666. }
  204667. void MidiOutput::sendMessageNow (const MidiMessage& message)
  204668. {
  204669. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  204670. if (message.isSysEx())
  204671. {
  204672. const int maxPacketSize = 256;
  204673. int pos = 0, bytesLeft = message.getRawDataSize();
  204674. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  204675. HeapBlock <MIDIPacketList> packets;
  204676. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  204677. packets->numPackets = numPackets;
  204678. MIDIPacket* p = packets->packet;
  204679. for (int i = 0; i < numPackets; ++i)
  204680. {
  204681. p->timeStamp = 0;
  204682. p->length = jmin (maxPacketSize, bytesLeft);
  204683. memcpy (p->data, message.getRawData() + pos, p->length);
  204684. pos += p->length;
  204685. bytesLeft -= p->length;
  204686. p = MIDIPacketNext (p);
  204687. }
  204688. if (mpe->port != 0)
  204689. MIDISend (mpe->port, mpe->endPoint, packets);
  204690. else
  204691. MIDIReceived (mpe->endPoint, packets);
  204692. }
  204693. else
  204694. {
  204695. MIDIPacketList packets;
  204696. packets.numPackets = 1;
  204697. packets.packet[0].timeStamp = 0;
  204698. packets.packet[0].length = message.getRawDataSize();
  204699. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  204700. if (mpe->port != 0)
  204701. MIDISend (mpe->port, mpe->endPoint, &packets);
  204702. else
  204703. MIDIReceived (mpe->endPoint, &packets);
  204704. }
  204705. }
  204706. const StringArray MidiInput::getDevices()
  204707. {
  204708. StringArray s;
  204709. const ItemCount num = MIDIGetNumberOfSources();
  204710. for (ItemCount i = 0; i < num; ++i)
  204711. {
  204712. MIDIEndpointRef source = MIDIGetSource (i);
  204713. if (source != 0)
  204714. {
  204715. String name (getConnectedEndpointName (source));
  204716. if (name.isEmpty())
  204717. name = "<error>";
  204718. s.add (name);
  204719. }
  204720. else
  204721. {
  204722. s.add ("<error>");
  204723. }
  204724. }
  204725. return s;
  204726. }
  204727. int MidiInput::getDefaultDeviceIndex()
  204728. {
  204729. return 0;
  204730. }
  204731. struct MidiPortAndCallback
  204732. {
  204733. MidiInput* input;
  204734. MidiPortAndEndpoint* portAndEndpoint;
  204735. MidiInputCallback* callback;
  204736. MemoryBlock pendingData;
  204737. int pendingBytes;
  204738. double pendingDataTime;
  204739. bool active;
  204740. void processSysex (const uint8*& d, int& size, const double time)
  204741. {
  204742. if (*d == 0xf0)
  204743. {
  204744. pendingBytes = 0;
  204745. pendingDataTime = time;
  204746. }
  204747. pendingData.ensureSize (pendingBytes + size, false);
  204748. uint8* totalMessage = (uint8*) pendingData.getData();
  204749. uint8* dest = totalMessage + pendingBytes;
  204750. while (size > 0)
  204751. {
  204752. if (pendingBytes > 0 && *d >= 0x80)
  204753. {
  204754. if (*d >= 0xfa || *d == 0xf8)
  204755. {
  204756. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  204757. ++d;
  204758. --size;
  204759. }
  204760. else
  204761. {
  204762. if (*d == 0xf7)
  204763. {
  204764. *dest++ = *d++;
  204765. pendingBytes++;
  204766. --size;
  204767. }
  204768. break;
  204769. }
  204770. }
  204771. else
  204772. {
  204773. *dest++ = *d++;
  204774. pendingBytes++;
  204775. --size;
  204776. }
  204777. }
  204778. if (totalMessage [pendingBytes - 1] == 0xf7)
  204779. {
  204780. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  204781. pendingBytes = 0;
  204782. }
  204783. else
  204784. {
  204785. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  204786. }
  204787. }
  204788. };
  204789. namespace CoreMidiCallbacks
  204790. {
  204791. static CriticalSection callbackLock;
  204792. static VoidArray activeCallbacks;
  204793. }
  204794. static void midiInputProc (const MIDIPacketList* pktlist,
  204795. void* readProcRefCon,
  204796. void* srcConnRefCon)
  204797. {
  204798. double time = Time::getMillisecondCounterHiRes() * 0.001;
  204799. const double originalTime = time;
  204800. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  204801. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  204802. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  204803. {
  204804. const MIDIPacket* packet = &pktlist->packet[0];
  204805. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  204806. {
  204807. const uint8* d = (const uint8*) (packet->data);
  204808. int size = packet->length;
  204809. while (size > 0)
  204810. {
  204811. time = originalTime;
  204812. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  204813. {
  204814. mpc->processSysex (d, size, time);
  204815. }
  204816. else
  204817. {
  204818. int used = 0;
  204819. const MidiMessage m (d, size, used, 0, time);
  204820. if (used <= 0)
  204821. {
  204822. jassertfalse // malformed midi message
  204823. break;
  204824. }
  204825. else
  204826. {
  204827. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  204828. }
  204829. size -= used;
  204830. d += used;
  204831. }
  204832. }
  204833. packet = MIDIPacketNext (packet);
  204834. }
  204835. }
  204836. }
  204837. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  204838. {
  204839. MidiInput* mi = 0;
  204840. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  204841. {
  204842. MIDIEndpointRef endPoint = MIDIGetSource (index);
  204843. if (endPoint != 0)
  204844. {
  204845. CFStringRef pname;
  204846. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  204847. {
  204848. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  204849. if (makeSureClientExists())
  204850. {
  204851. MIDIPortRef port;
  204852. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  204853. mpc->active = false;
  204854. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  204855. {
  204856. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  204857. {
  204858. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  204859. mpc->callback = callback;
  204860. mpc->pendingBytes = 0;
  204861. mpc->pendingData.ensureSize (128);
  204862. mi = new MidiInput (getDevices() [index]);
  204863. mpc->input = mi;
  204864. mi->internal = mpc;
  204865. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  204866. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  204867. }
  204868. else
  204869. {
  204870. OK (MIDIPortDispose (port));
  204871. }
  204872. }
  204873. }
  204874. }
  204875. CFRelease (pname);
  204876. }
  204877. }
  204878. return mi;
  204879. }
  204880. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  204881. {
  204882. MidiInput* mi = 0;
  204883. if (makeSureClientExists())
  204884. {
  204885. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  204886. mpc->active = false;
  204887. MIDIEndpointRef endPoint;
  204888. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  204889. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  204890. {
  204891. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  204892. mpc->callback = callback;
  204893. mpc->pendingBytes = 0;
  204894. mpc->pendingData.ensureSize (128);
  204895. mi = new MidiInput (deviceName);
  204896. mpc->input = mi;
  204897. mi->internal = mpc;
  204898. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  204899. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  204900. }
  204901. CFRelease (name);
  204902. }
  204903. return mi;
  204904. }
  204905. MidiInput::MidiInput (const String& name_)
  204906. : name (name_)
  204907. {
  204908. }
  204909. MidiInput::~MidiInput()
  204910. {
  204911. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  204912. mpc->active = false;
  204913. {
  204914. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  204915. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  204916. }
  204917. if (mpc->portAndEndpoint->port != 0)
  204918. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  204919. delete mpc->portAndEndpoint;
  204920. delete mpc;
  204921. }
  204922. void MidiInput::start()
  204923. {
  204924. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  204925. ((MidiPortAndCallback*) internal)->active = true;
  204926. }
  204927. void MidiInput::stop()
  204928. {
  204929. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  204930. ((MidiPortAndCallback*) internal)->active = false;
  204931. }
  204932. #undef log
  204933. #else
  204934. MidiOutput::~MidiOutput()
  204935. {
  204936. }
  204937. void MidiOutput::reset()
  204938. {
  204939. }
  204940. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  204941. {
  204942. return false;
  204943. }
  204944. void MidiOutput::setVolume (float leftVol, float rightVol)
  204945. {
  204946. }
  204947. void MidiOutput::sendMessageNow (const MidiMessage& message)
  204948. {
  204949. }
  204950. const StringArray MidiOutput::getDevices()
  204951. {
  204952. return StringArray();
  204953. }
  204954. MidiOutput* MidiOutput::openDevice (int index)
  204955. {
  204956. return 0;
  204957. }
  204958. const StringArray MidiInput::getDevices()
  204959. {
  204960. return StringArray();
  204961. }
  204962. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  204963. {
  204964. return 0;
  204965. }
  204966. #endif
  204967. #endif
  204968. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  204969. #else
  204970. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  204971. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204972. // compiled on its own).
  204973. #if JUCE_INCLUDED_FILE
  204974. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  204975. #define SUPPORT_10_4_FONTS 1
  204976. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  204977. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  204978. #define SUPPORT_ONLY_10_4_FONTS 1
  204979. #endif
  204980. END_JUCE_NAMESPACE
  204981. @interface NSFont (PrivateHack)
  204982. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  204983. @end
  204984. BEGIN_JUCE_NAMESPACE
  204985. #endif
  204986. class MacTypeface : public Typeface
  204987. {
  204988. public:
  204989. MacTypeface (const Font& font)
  204990. : Typeface (font.getTypefaceName())
  204991. {
  204992. const ScopedAutoReleasePool pool;
  204993. renderingTransform = CGAffineTransformIdentity;
  204994. bool needsItalicTransform = false;
  204995. #if JUCE_IPHONE
  204996. NSString* fontName = juceStringToNS (font.getTypefaceName());
  204997. if (font.isItalic() || font.isBold())
  204998. {
  204999. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205000. for (NSString* i in familyFonts)
  205001. {
  205002. const String fn (nsStringToJuce (i));
  205003. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  205004. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  205005. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  205006. || afterDash.containsIgnoreCase ("italic")
  205007. || fn.endsWithIgnoreCase ("oblique")
  205008. || fn.endsWithIgnoreCase ("italic");
  205009. if (probablyBold == font.isBold()
  205010. && probablyItalic == font.isItalic())
  205011. {
  205012. fontName = i;
  205013. needsItalicTransform = false;
  205014. break;
  205015. }
  205016. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205017. {
  205018. fontName = i;
  205019. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205020. }
  205021. }
  205022. if (needsItalicTransform)
  205023. renderingTransform.c = 0.15f;
  205024. }
  205025. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205026. const int ascender = abs (CGFontGetAscent (fontRef));
  205027. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205028. ascent = ascender / totalHeight;
  205029. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205030. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205031. #else
  205032. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205033. if (font.isItalic())
  205034. {
  205035. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205036. toHaveTrait: NSItalicFontMask];
  205037. if (newFont == nsFont)
  205038. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205039. nsFont = newFont;
  205040. }
  205041. if (font.isBold())
  205042. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205043. [nsFont retain];
  205044. ascent = fabsf ((float) [nsFont ascender]);
  205045. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205046. ascent /= totalSize;
  205047. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205048. if (needsItalicTransform)
  205049. {
  205050. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205051. renderingTransform.c = 0.15f;
  205052. }
  205053. #if SUPPORT_ONLY_10_4_FONTS
  205054. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205055. if (atsFont == 0)
  205056. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205057. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  205058. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205059. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205060. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205061. #else
  205062. #if SUPPORT_10_4_FONTS
  205063. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205064. {
  205065. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205066. if (atsFont == 0)
  205067. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205068. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  205069. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205070. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205071. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205072. }
  205073. else
  205074. #endif
  205075. {
  205076. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205077. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205078. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205079. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205080. }
  205081. #endif
  205082. #endif
  205083. }
  205084. ~MacTypeface()
  205085. {
  205086. #if ! JUCE_IPHONE
  205087. [nsFont release];
  205088. #endif
  205089. if (fontRef != 0)
  205090. CGFontRelease (fontRef);
  205091. }
  205092. float getAscent() const
  205093. {
  205094. return ascent;
  205095. }
  205096. float getDescent() const
  205097. {
  205098. return 1.0f - ascent;
  205099. }
  205100. float getStringWidth (const String& text)
  205101. {
  205102. if (fontRef == 0 || text.isEmpty())
  205103. return 0;
  205104. const int length = text.length();
  205105. HeapBlock <CGGlyph> glyphs;
  205106. createGlyphsForString (text, length, glyphs);
  205107. float x = 0;
  205108. #if SUPPORT_ONLY_10_4_FONTS
  205109. HeapBlock <NSSize> advances (length);
  205110. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205111. for (int i = 0; i < length; ++i)
  205112. x += advances[i].width;
  205113. #else
  205114. #if SUPPORT_10_4_FONTS
  205115. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205116. {
  205117. HeapBlock <NSSize> advances (length);
  205118. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205119. for (int i = 0; i < length; ++i)
  205120. x += advances[i].width;
  205121. }
  205122. else
  205123. #endif
  205124. {
  205125. HeapBlock <int> advances (length);
  205126. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205127. for (int i = 0; i < length; ++i)
  205128. x += advances[i];
  205129. }
  205130. #endif
  205131. return x * unitsToHeightScaleFactor;
  205132. }
  205133. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205134. {
  205135. xOffsets.add (0);
  205136. if (fontRef == 0 || text.isEmpty())
  205137. return;
  205138. const int length = text.length();
  205139. HeapBlock <CGGlyph> glyphs;
  205140. createGlyphsForString (text, length, glyphs);
  205141. #if SUPPORT_ONLY_10_4_FONTS
  205142. HeapBlock <NSSize> advances (length);
  205143. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205144. int x = 0;
  205145. for (int i = 0; i < length; ++i)
  205146. {
  205147. x += advances[i].width;
  205148. xOffsets.add (x * unitsToHeightScaleFactor);
  205149. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205150. }
  205151. #else
  205152. #if SUPPORT_10_4_FONTS
  205153. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205154. {
  205155. HeapBlock <NSSize> advances (length);
  205156. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205157. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205158. float x = 0;
  205159. for (int i = 0; i < length; ++i)
  205160. {
  205161. x += advances[i].width;
  205162. xOffsets.add (x * unitsToHeightScaleFactor);
  205163. resultGlyphs.add (nsGlyphs[i]);
  205164. }
  205165. }
  205166. else
  205167. #endif
  205168. {
  205169. HeapBlock <int> advances (length);
  205170. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205171. {
  205172. int x = 0;
  205173. for (int i = 0; i < length; ++i)
  205174. {
  205175. x += advances [i];
  205176. xOffsets.add (x * unitsToHeightScaleFactor);
  205177. resultGlyphs.add (glyphs[i]);
  205178. }
  205179. }
  205180. }
  205181. #endif
  205182. }
  205183. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205184. {
  205185. #if JUCE_IPHONE
  205186. return false;
  205187. #else
  205188. if (nsFont == 0)
  205189. return false;
  205190. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205191. jassert (path.isEmpty());
  205192. const ScopedAutoReleasePool pool;
  205193. NSBezierPath* bez = [NSBezierPath bezierPath];
  205194. [bez moveToPoint: NSMakePoint (0, 0)];
  205195. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205196. inFont: nsFont];
  205197. for (int i = 0; i < [bez elementCount]; ++i)
  205198. {
  205199. NSPoint p[3];
  205200. switch ([bez elementAtIndex: i associatedPoints: p])
  205201. {
  205202. case NSMoveToBezierPathElement:
  205203. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205204. break;
  205205. case NSLineToBezierPathElement:
  205206. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205207. break;
  205208. case NSCurveToBezierPathElement:
  205209. path.cubicTo ((float) p[0].x, (float) -p[0].y, (float) p[1].x, (float) -p[1].y, (float) p[2].x, (float) -p[2].y);
  205210. break;
  205211. case NSClosePathBezierPathElement:
  205212. path.closeSubPath();
  205213. break;
  205214. default:
  205215. jassertfalse
  205216. break;
  205217. }
  205218. }
  205219. path.applyTransform (pathTransform);
  205220. return true;
  205221. #endif
  205222. }
  205223. juce_UseDebuggingNewOperator
  205224. CGFontRef fontRef;
  205225. float fontHeightToCGSizeFactor;
  205226. CGAffineTransform renderingTransform;
  205227. private:
  205228. float ascent, unitsToHeightScaleFactor;
  205229. #if JUCE_IPHONE
  205230. #else
  205231. NSFont* nsFont;
  205232. AffineTransform pathTransform;
  205233. #endif
  205234. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205235. {
  205236. #if SUPPORT_10_4_FONTS
  205237. #if ! SUPPORT_ONLY_10_4_FONTS
  205238. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205239. #endif
  205240. {
  205241. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205242. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205243. for (int i = 0; i < length; ++i)
  205244. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205245. return;
  205246. }
  205247. #endif
  205248. #if ! SUPPORT_ONLY_10_4_FONTS
  205249. if (charToGlyphMapper == 0)
  205250. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205251. glyphs.malloc (length);
  205252. for (int i = 0; i < length; ++i)
  205253. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205254. #endif
  205255. }
  205256. #if ! SUPPORT_ONLY_10_4_FONTS
  205257. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205258. class CharToGlyphMapper
  205259. {
  205260. public:
  205261. CharToGlyphMapper (CGFontRef fontRef)
  205262. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205263. idRangeOffset (0), glyphIndexes (0)
  205264. {
  205265. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205266. if (cmapTable != 0)
  205267. {
  205268. const int numSubtables = getValue16 (cmapTable, 2);
  205269. for (int i = 0; i < numSubtables; ++i)
  205270. {
  205271. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205272. {
  205273. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205274. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205275. {
  205276. const int length = getValue16 (cmapTable, offset + 2);
  205277. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205278. segCount = segCountX2 / 2;
  205279. const int endCodeOffset = offset + 14;
  205280. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205281. const int idDeltaOffset = startCodeOffset + segCountX2;
  205282. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205283. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205284. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205285. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205286. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205287. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205288. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205289. }
  205290. break;
  205291. }
  205292. }
  205293. CFRelease (cmapTable);
  205294. }
  205295. }
  205296. ~CharToGlyphMapper()
  205297. {
  205298. if (endCode != 0)
  205299. {
  205300. CFRelease (endCode);
  205301. CFRelease (startCode);
  205302. CFRelease (idDelta);
  205303. CFRelease (idRangeOffset);
  205304. CFRelease (glyphIndexes);
  205305. }
  205306. }
  205307. int getGlyphForCharacter (const juce_wchar c) const
  205308. {
  205309. for (int i = 0; i < segCount; ++i)
  205310. {
  205311. if (getValue16 (endCode, i * 2) >= c)
  205312. {
  205313. const int start = getValue16 (startCode, i * 2);
  205314. if (start > c)
  205315. break;
  205316. const int delta = getValue16 (idDelta, i * 2);
  205317. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205318. if (rangeOffset == 0)
  205319. return delta + c;
  205320. else
  205321. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205322. }
  205323. }
  205324. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205325. return jmax (-1, c - 29);
  205326. }
  205327. private:
  205328. int segCount;
  205329. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205330. static uint16 getValue16 (CFDataRef data, const int index)
  205331. {
  205332. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205333. }
  205334. static uint32 getValue32 (CFDataRef data, const int index)
  205335. {
  205336. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205337. }
  205338. };
  205339. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205340. #endif
  205341. MacTypeface (const MacTypeface&);
  205342. MacTypeface& operator= (const MacTypeface&);
  205343. };
  205344. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205345. {
  205346. return new MacTypeface (font);
  205347. }
  205348. const StringArray Font::findAllTypefaceNames()
  205349. {
  205350. StringArray names;
  205351. const ScopedAutoReleasePool pool;
  205352. #if JUCE_IPHONE
  205353. NSArray* fonts = [UIFont familyNames];
  205354. #else
  205355. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205356. #endif
  205357. for (unsigned int i = 0; i < [fonts count]; ++i)
  205358. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205359. names.sort (true);
  205360. return names;
  205361. }
  205362. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  205363. {
  205364. #if JUCE_IPHONE
  205365. defaultSans = "Helvetica";
  205366. defaultSerif = "Times New Roman";
  205367. defaultFixed = "Courier New";
  205368. #else
  205369. defaultSans = "Lucida Grande";
  205370. defaultSerif = "Times New Roman";
  205371. defaultFixed = "Monaco";
  205372. #endif
  205373. }
  205374. #endif
  205375. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205376. // (must go before juce_mac_CoreGraphicsContext.mm)
  205377. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205378. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205379. // compiled on its own).
  205380. #if JUCE_INCLUDED_FILE
  205381. class CoreGraphicsImage : public Image
  205382. {
  205383. public:
  205384. CoreGraphicsImage (const PixelFormat format_,
  205385. const int imageWidth_,
  205386. const int imageHeight_,
  205387. const bool clearImage)
  205388. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205389. {
  205390. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205391. : CGColorSpaceCreateDeviceRGB();
  205392. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205393. colourSpace, getCGImageFlags (*this));
  205394. CGColorSpaceRelease (colourSpace);
  205395. }
  205396. ~CoreGraphicsImage()
  205397. {
  205398. CGContextRelease (context);
  205399. }
  205400. LowLevelGraphicsContext* createLowLevelContext();
  205401. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205402. {
  205403. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205404. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205405. {
  205406. return CGBitmapContextCreateImage (nativeImage->context);
  205407. }
  205408. else
  205409. {
  205410. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205411. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205412. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205413. 8, srcData.pixelStride * 8, srcData.lineStride,
  205414. colourSpace, getCGImageFlags (juceImage), provider,
  205415. 0, true, kCGRenderingIntentDefault);
  205416. CGDataProviderRelease (provider);
  205417. return imageRef;
  205418. }
  205419. }
  205420. #if JUCE_MAC
  205421. static NSImage* createNSImage (const Image& image)
  205422. {
  205423. const ScopedAutoReleasePool pool;
  205424. NSImage* im = [[NSImage alloc] init];
  205425. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205426. [im lockFocus];
  205427. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205428. CGImageRef imageRef = createImage (image, false, colourSpace);
  205429. CGColorSpaceRelease (colourSpace);
  205430. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205431. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205432. CGImageRelease (imageRef);
  205433. [im unlockFocus];
  205434. return im;
  205435. }
  205436. #endif
  205437. CGContextRef context;
  205438. private:
  205439. static CGBitmapInfo getCGImageFlags (const Image& image)
  205440. {
  205441. #if JUCE_BIG_ENDIAN
  205442. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205443. #else
  205444. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205445. #endif
  205446. }
  205447. };
  205448. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205449. {
  205450. #if USE_COREGRAPHICS_RENDERING
  205451. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205452. #else
  205453. return new Image (format, imageWidth, imageHeight, clearImage);
  205454. #endif
  205455. }
  205456. class CoreGraphicsContext : public LowLevelGraphicsContext
  205457. {
  205458. public:
  205459. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205460. : context (context_),
  205461. flipHeight (flipHeight_),
  205462. state (new SavedState()),
  205463. numGradientLookupEntries (0)
  205464. {
  205465. CGContextRetain (context);
  205466. CGContextSaveGState(context);
  205467. CGContextSetShouldSmoothFonts (context, true);
  205468. CGContextSetShouldAntialias (context, true);
  205469. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205470. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205471. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205472. gradientCallbacks.version = 0;
  205473. gradientCallbacks.evaluate = gradientCallback;
  205474. gradientCallbacks.releaseInfo = 0;
  205475. setFont (Font());
  205476. }
  205477. ~CoreGraphicsContext()
  205478. {
  205479. CGContextRestoreGState (context);
  205480. CGContextRelease (context);
  205481. CGColorSpaceRelease (rgbColourSpace);
  205482. CGColorSpaceRelease (greyColourSpace);
  205483. }
  205484. bool isVectorDevice() const { return false; }
  205485. void setOrigin (int x, int y)
  205486. {
  205487. CGContextTranslateCTM (context, x, -y);
  205488. }
  205489. bool clipToRectangle (const Rectangle<int>& r)
  205490. {
  205491. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205492. return ! isClipEmpty();
  205493. }
  205494. bool clipToRectangleList (const RectangleList& clipRegion)
  205495. {
  205496. if (clipRegion.isEmpty())
  205497. {
  205498. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205499. return false;
  205500. }
  205501. else
  205502. {
  205503. const int numRects = clipRegion.getNumRectangles();
  205504. HeapBlock <CGRect> rects (numRects);
  205505. for (int i = 0; i < numRects; ++i)
  205506. {
  205507. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205508. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205509. }
  205510. CGContextClipToRects (context, rects, numRects);
  205511. return ! isClipEmpty();
  205512. }
  205513. }
  205514. void excludeClipRectangle (const Rectangle<int>& r)
  205515. {
  205516. RectangleList remaining (getClipBounds());
  205517. remaining.subtract (r);
  205518. clipToRectangleList (remaining);
  205519. }
  205520. void clipToPath (const Path& path, const AffineTransform& transform)
  205521. {
  205522. createPath (path, transform);
  205523. CGContextClip (context);
  205524. }
  205525. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205526. {
  205527. if (! transform.isSingularity())
  205528. {
  205529. ScopedPointer<Image> imageToDelete;
  205530. const Image* singleChannelImage = &sourceImage;
  205531. if (sourceImage.getFormat() != Image::SingleChannel)
  205532. {
  205533. imageToDelete = sourceImage.createCopyOfAlphaChannel();
  205534. singleChannelImage = imageToDelete;
  205535. }
  205536. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205537. flip();
  205538. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205539. applyTransform (t);
  205540. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205541. CGContextClipToMask (context, r, image);
  205542. applyTransform (t.inverted());
  205543. flip();
  205544. CGImageRelease (image);
  205545. }
  205546. }
  205547. bool clipRegionIntersects (const Rectangle<int>& r)
  205548. {
  205549. return getClipBounds().intersects (r);
  205550. }
  205551. const Rectangle<int> getClipBounds() const
  205552. {
  205553. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205554. return Rectangle<int> (roundToInt (bounds.origin.x),
  205555. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205556. roundToInt (bounds.size.width),
  205557. roundToInt (bounds.size.height));
  205558. }
  205559. bool isClipEmpty() const
  205560. {
  205561. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205562. }
  205563. void saveState()
  205564. {
  205565. CGContextSaveGState (context);
  205566. stateStack.add (new SavedState (*state));
  205567. }
  205568. void restoreState()
  205569. {
  205570. CGContextRestoreGState (context);
  205571. SavedState* const top = stateStack.getLast();
  205572. if (top != 0)
  205573. {
  205574. state = top;
  205575. stateStack.removeLast (1, false);
  205576. }
  205577. else
  205578. {
  205579. jassertfalse // trying to pop with an empty stack!
  205580. }
  205581. }
  205582. void setFill (const FillType& fillType)
  205583. {
  205584. state->fillType = fillType;
  205585. if (fillType.isColour())
  205586. {
  205587. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  205588. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  205589. CGContextSetAlpha (context, 1.0f);
  205590. }
  205591. }
  205592. void setOpacity (float newOpacity)
  205593. {
  205594. state->fillType.setOpacity (newOpacity);
  205595. setFill (state->fillType);
  205596. }
  205597. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  205598. {
  205599. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  205600. ? kCGInterpolationLow
  205601. : kCGInterpolationHigh);
  205602. }
  205603. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  205604. {
  205605. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205606. if (replaceExistingContents)
  205607. {
  205608. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205609. CGContextClearRect (context, cgRect);
  205610. #else
  205611. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205612. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  205613. CGContextClearRect (context, cgRect);
  205614. else
  205615. #endif
  205616. CGContextSetBlendMode (context, kCGBlendModeCopy);
  205617. #endif
  205618. fillRect (r, false);
  205619. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205620. }
  205621. else
  205622. {
  205623. if (state->fillType.isColour())
  205624. {
  205625. CGContextFillRect (context, cgRect);
  205626. }
  205627. else if (state->fillType.isGradient())
  205628. {
  205629. CGContextSaveGState (context);
  205630. CGContextClipToRect (context, cgRect);
  205631. drawGradient();
  205632. CGContextRestoreGState (context);
  205633. }
  205634. else
  205635. {
  205636. CGContextSaveGState (context);
  205637. CGContextClipToRect (context, cgRect);
  205638. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  205639. CGContextRestoreGState (context);
  205640. }
  205641. }
  205642. }
  205643. void fillPath (const Path& path, const AffineTransform& transform)
  205644. {
  205645. CGContextSaveGState (context);
  205646. if (state->fillType.isColour())
  205647. {
  205648. flip();
  205649. applyTransform (transform);
  205650. createPath (path);
  205651. if (path.isUsingNonZeroWinding())
  205652. CGContextFillPath (context);
  205653. else
  205654. CGContextEOFillPath (context);
  205655. }
  205656. else
  205657. {
  205658. createPath (path, transform);
  205659. if (path.isUsingNonZeroWinding())
  205660. CGContextClip (context);
  205661. else
  205662. CGContextEOClip (context);
  205663. if (state->fillType.isGradient())
  205664. drawGradient();
  205665. else
  205666. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  205667. }
  205668. CGContextRestoreGState (context);
  205669. }
  205670. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  205671. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  205672. {
  205673. jassert (sourceImage.getBounds().contains (srcClip));
  205674. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  205675. CGImageRef image = fullImage;
  205676. if (srcClip != sourceImage.getBounds())
  205677. {
  205678. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  205679. srcClip.getWidth(), srcClip.getHeight()));
  205680. CGImageRelease (fullImage);
  205681. }
  205682. CGContextSaveGState (context);
  205683. CGContextSetAlpha (context, state->fillType.getOpacity());
  205684. flip();
  205685. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  205686. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  205687. if (fillEntireClipAsTiles)
  205688. {
  205689. #if JUCE_IPHONE
  205690. CGContextDrawTiledImage (context, imageRect, image);
  205691. #else
  205692. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  205693. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  205694. // if it's doing a transformation - it's quicker to just draw lots of images manually
  205695. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  205696. CGContextDrawTiledImage (context, imageRect, image);
  205697. else
  205698. #endif
  205699. {
  205700. // Fallback to manually doing a tiled fill on 10.4
  205701. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205702. const int iw = srcClip.getWidth();
  205703. const int ih = srcClip.getHeight();
  205704. int x = 0, y = 0;
  205705. while (x > clip.origin.x) x -= iw;
  205706. while (y > clip.origin.y) y -= ih;
  205707. const int right = (int) (clip.origin.x + clip.size.width);
  205708. const int bottom = (int) (clip.origin.y + clip.size.height);
  205709. while (y < bottom)
  205710. {
  205711. for (int x2 = x; x2 < right; x2 += iw)
  205712. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  205713. y += ih;
  205714. }
  205715. }
  205716. #endif
  205717. }
  205718. else
  205719. {
  205720. CGContextDrawImage (context, imageRect, image);
  205721. }
  205722. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  205723. CGContextRestoreGState (context);
  205724. }
  205725. void drawLine (double x1, double y1, double x2, double y2)
  205726. {
  205727. CGContextSetLineCap (context, kCGLineCapSquare);
  205728. CGContextSetLineWidth (context, 1.0f);
  205729. CGContextSetRGBStrokeColor (context,
  205730. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  205731. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  205732. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  205733. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  205734. CGContextStrokeLineSegments (context, line, 1);
  205735. }
  205736. void drawVerticalLine (const int x, double top, double bottom)
  205737. {
  205738. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  205739. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  205740. #else
  205741. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  205742. // the x co-ord slightly to trick it..
  205743. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  205744. #endif
  205745. }
  205746. void drawHorizontalLine (const int y, double left, double right)
  205747. {
  205748. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  205749. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  205750. #else
  205751. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  205752. // the x co-ord slightly to trick it..
  205753. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  205754. #endif
  205755. }
  205756. void setFont (const Font& newFont)
  205757. {
  205758. if (state->font != newFont)
  205759. {
  205760. state->fontRef = 0;
  205761. state->font = newFont;
  205762. MacTypeface* mf = dynamic_cast <MacTypeface*> (state->font.getTypeface());
  205763. if (mf != 0)
  205764. {
  205765. state->fontRef = mf->fontRef;
  205766. CGContextSetFont (context, state->fontRef);
  205767. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  205768. state->fontTransform = mf->renderingTransform;
  205769. state->fontTransform.a *= state->font.getHorizontalScale();
  205770. CGContextSetTextMatrix (context, state->fontTransform);
  205771. }
  205772. }
  205773. }
  205774. const Font getFont()
  205775. {
  205776. return state->font;
  205777. }
  205778. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  205779. {
  205780. if (state->fontRef != 0 && state->fillType.isColour())
  205781. {
  205782. if (transform.isOnlyTranslation())
  205783. {
  205784. CGGlyph g = glyphNumber;
  205785. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  205786. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  205787. }
  205788. else
  205789. {
  205790. CGContextSaveGState (context);
  205791. flip();
  205792. applyTransform (transform);
  205793. CGAffineTransform t = state->fontTransform;
  205794. t.d = -t.d;
  205795. CGContextSetTextMatrix (context, t);
  205796. CGGlyph g = glyphNumber;
  205797. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  205798. CGContextSetTextMatrix (context, state->fontTransform);
  205799. CGContextRestoreGState (context);
  205800. }
  205801. }
  205802. else
  205803. {
  205804. Path p;
  205805. Font& f = state->font;
  205806. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  205807. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  205808. .followedBy (transform));
  205809. }
  205810. }
  205811. private:
  205812. CGContextRef context;
  205813. const CGFloat flipHeight;
  205814. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  205815. CGFunctionCallbacks gradientCallbacks;
  205816. struct SavedState
  205817. {
  205818. SavedState()
  205819. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  205820. {
  205821. }
  205822. SavedState (const SavedState& other)
  205823. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  205824. fontTransform (other.fontTransform)
  205825. {
  205826. }
  205827. ~SavedState()
  205828. {
  205829. }
  205830. FillType fillType;
  205831. Font font;
  205832. CGFontRef fontRef;
  205833. CGAffineTransform fontTransform;
  205834. };
  205835. ScopedPointer <SavedState> state;
  205836. OwnedArray <SavedState> stateStack;
  205837. HeapBlock <PixelARGB> gradientLookupTable;
  205838. int numGradientLookupEntries;
  205839. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  205840. {
  205841. const CoreGraphicsContext* const g = static_cast <const CoreGraphicsContext*> (info);
  205842. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  205843. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  205844. colour.unpremultiply();
  205845. outData[0] = colour.getRed() / 255.0f;
  205846. outData[1] = colour.getGreen() / 255.0f;
  205847. outData[2] = colour.getBlue() / 255.0f;
  205848. outData[3] = colour.getAlpha() / 255.0f;
  205849. }
  205850. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  205851. {
  205852. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  205853. --numGradientLookupEntries;
  205854. CGShadingRef result = 0;
  205855. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  205856. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  205857. if (gradient.isRadial)
  205858. {
  205859. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  205860. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  205861. function, true, true);
  205862. }
  205863. else
  205864. {
  205865. result = CGShadingCreateAxial (rgbColourSpace, p1,
  205866. CGPointMake (gradient.x2, gradient.y2),
  205867. function, true, true);
  205868. }
  205869. CGFunctionRelease (function);
  205870. return result;
  205871. }
  205872. void drawGradient()
  205873. {
  205874. flip();
  205875. applyTransform (state->fillType.transform);
  205876. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  205877. // you draw a gradient with high quality interp enabled).
  205878. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  205879. CGContextSetAlpha (context, state->fillType.getOpacity());
  205880. CGContextDrawShading (context, shading);
  205881. CGShadingRelease (shading);
  205882. }
  205883. void createPath (const Path& path) const
  205884. {
  205885. CGContextBeginPath (context);
  205886. Path::Iterator i (path);
  205887. while (i.next())
  205888. {
  205889. switch (i.elementType)
  205890. {
  205891. case Path::Iterator::startNewSubPath:
  205892. CGContextMoveToPoint (context, i.x1, i.y1);
  205893. break;
  205894. case Path::Iterator::lineTo:
  205895. CGContextAddLineToPoint (context, i.x1, i.y1);
  205896. break;
  205897. case Path::Iterator::quadraticTo:
  205898. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  205899. break;
  205900. case Path::Iterator::cubicTo:
  205901. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  205902. break;
  205903. case Path::Iterator::closePath:
  205904. CGContextClosePath (context); break;
  205905. default:
  205906. jassertfalse
  205907. break;
  205908. }
  205909. }
  205910. }
  205911. void createPath (const Path& path, const AffineTransform& transform) const
  205912. {
  205913. CGContextBeginPath (context);
  205914. Path::Iterator i (path);
  205915. while (i.next())
  205916. {
  205917. switch (i.elementType)
  205918. {
  205919. case Path::Iterator::startNewSubPath:
  205920. transform.transformPoint (i.x1, i.y1);
  205921. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  205922. break;
  205923. case Path::Iterator::lineTo:
  205924. transform.transformPoint (i.x1, i.y1);
  205925. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  205926. break;
  205927. case Path::Iterator::quadraticTo:
  205928. transform.transformPoint (i.x1, i.y1);
  205929. transform.transformPoint (i.x2, i.y2);
  205930. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  205931. break;
  205932. case Path::Iterator::cubicTo:
  205933. transform.transformPoint (i.x1, i.y1);
  205934. transform.transformPoint (i.x2, i.y2);
  205935. transform.transformPoint (i.x3, i.y3);
  205936. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  205937. break;
  205938. case Path::Iterator::closePath:
  205939. CGContextClosePath (context); break;
  205940. default:
  205941. jassertfalse
  205942. break;
  205943. }
  205944. }
  205945. }
  205946. void flip() const
  205947. {
  205948. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  205949. }
  205950. void applyTransform (const AffineTransform& transform) const
  205951. {
  205952. CGAffineTransform t;
  205953. t.a = transform.mat00;
  205954. t.b = transform.mat10;
  205955. t.c = transform.mat01;
  205956. t.d = transform.mat11;
  205957. t.tx = transform.mat02;
  205958. t.ty = transform.mat12;
  205959. CGContextConcatCTM (context, t);
  205960. }
  205961. CoreGraphicsContext (const CoreGraphicsContext&);
  205962. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  205963. };
  205964. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  205965. {
  205966. return new CoreGraphicsContext (context, imageHeight);
  205967. }
  205968. #endif
  205969. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205970. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  205971. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205972. // compiled on its own).
  205973. #if JUCE_INCLUDED_FILE
  205974. class NSViewComponentPeer;
  205975. END_JUCE_NAMESPACE
  205976. #define JuceNSView MakeObjCClassName(JuceNSView)
  205977. @interface JuceNSView : NSView<NSTextInput>
  205978. {
  205979. @public
  205980. NSViewComponentPeer* owner;
  205981. NSNotificationCenter* notificationCenter;
  205982. String* stringBeingComposed;
  205983. bool textWasInserted;
  205984. }
  205985. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  205986. - (void) dealloc;
  205987. - (BOOL) isOpaque;
  205988. - (void) drawRect: (NSRect) r;
  205989. - (void) mouseDown: (NSEvent*) ev;
  205990. - (void) asyncMouseDown: (NSEvent*) ev;
  205991. - (void) mouseUp: (NSEvent*) ev;
  205992. - (void) asyncMouseUp: (NSEvent*) ev;
  205993. - (void) mouseDragged: (NSEvent*) ev;
  205994. - (void) mouseMoved: (NSEvent*) ev;
  205995. - (void) mouseEntered: (NSEvent*) ev;
  205996. - (void) mouseExited: (NSEvent*) ev;
  205997. - (void) rightMouseDown: (NSEvent*) ev;
  205998. - (void) rightMouseDragged: (NSEvent*) ev;
  205999. - (void) rightMouseUp: (NSEvent*) ev;
  206000. - (void) otherMouseDown: (NSEvent*) ev;
  206001. - (void) otherMouseDragged: (NSEvent*) ev;
  206002. - (void) otherMouseUp: (NSEvent*) ev;
  206003. - (void) scrollWheel: (NSEvent*) ev;
  206004. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206005. - (void) frameChanged: (NSNotification*) n;
  206006. - (void) viewDidMoveToWindow;
  206007. - (void) keyDown: (NSEvent*) ev;
  206008. - (void) keyUp: (NSEvent*) ev;
  206009. // NSTextInput Methods
  206010. - (void) insertText: (id) aString;
  206011. - (void) doCommandBySelector: (SEL) aSelector;
  206012. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206013. - (void) unmarkText;
  206014. - (BOOL) hasMarkedText;
  206015. - (long) conversationIdentifier;
  206016. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206017. - (NSRange) markedRange;
  206018. - (NSRange) selectedRange;
  206019. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206020. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206021. - (NSArray*) validAttributesForMarkedText;
  206022. - (void) flagsChanged: (NSEvent*) ev;
  206023. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206024. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206025. #endif
  206026. - (BOOL) becomeFirstResponder;
  206027. - (BOOL) resignFirstResponder;
  206028. - (BOOL) acceptsFirstResponder;
  206029. - (void) asyncRepaint: (id) rect;
  206030. - (NSArray*) getSupportedDragTypes;
  206031. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206032. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206033. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206034. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206035. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206036. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206037. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206038. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206039. @end
  206040. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206041. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206042. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206043. #else
  206044. @interface JuceNSWindow : NSWindow
  206045. #endif
  206046. {
  206047. @private
  206048. NSViewComponentPeer* owner;
  206049. bool isZooming;
  206050. }
  206051. - (void) setOwner: (NSViewComponentPeer*) owner;
  206052. - (BOOL) canBecomeKeyWindow;
  206053. - (void) becomeKeyWindow;
  206054. - (BOOL) windowShouldClose: (id) window;
  206055. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206056. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206057. - (void) zoom: (id) sender;
  206058. @end
  206059. BEGIN_JUCE_NAMESPACE
  206060. class NSViewComponentPeer : public ComponentPeer
  206061. {
  206062. public:
  206063. NSViewComponentPeer (Component* const component,
  206064. const int windowStyleFlags,
  206065. NSView* viewToAttachTo);
  206066. ~NSViewComponentPeer();
  206067. void* getNativeHandle() const;
  206068. void setVisible (bool shouldBeVisible);
  206069. void setTitle (const String& title);
  206070. void setPosition (int x, int y);
  206071. void setSize (int w, int h);
  206072. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206073. const Rectangle<int> getBounds (const bool global) const;
  206074. const Rectangle<int> getBounds() const;
  206075. const Point<int> getScreenPosition() const;
  206076. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206077. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206078. void setMinimised (bool shouldBeMinimised);
  206079. bool isMinimised() const;
  206080. void setFullScreen (bool shouldBeFullScreen);
  206081. bool isFullScreen() const;
  206082. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206083. const BorderSize getFrameSize() const;
  206084. bool setAlwaysOnTop (bool alwaysOnTop);
  206085. void toFront (bool makeActiveWindow);
  206086. void toBehind (ComponentPeer* other);
  206087. void setIcon (const Image& newIcon);
  206088. const StringArray getAvailableRenderingEngines() throw();
  206089. int getCurrentRenderingEngine() throw();
  206090. void setCurrentRenderingEngine (int index) throw();
  206091. virtual void redirectMouseDown (NSEvent* ev);
  206092. virtual void redirectMouseUp (NSEvent* ev);
  206093. virtual void redirectMouseDrag (NSEvent* ev);
  206094. virtual void redirectMouseMove (NSEvent* ev);
  206095. virtual void redirectMouseEnter (NSEvent* ev);
  206096. virtual void redirectMouseExit (NSEvent* ev);
  206097. virtual void redirectMouseWheel (NSEvent* ev);
  206098. void sendMouseEvent (NSEvent* ev);
  206099. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206100. virtual bool redirectKeyDown (NSEvent* ev);
  206101. virtual bool redirectKeyUp (NSEvent* ev);
  206102. virtual void redirectModKeyChange (NSEvent* ev);
  206103. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206104. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206105. #endif
  206106. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206107. virtual bool isOpaque();
  206108. virtual void drawRect (NSRect r);
  206109. virtual bool canBecomeKeyWindow();
  206110. virtual bool windowShouldClose();
  206111. virtual void redirectMovedOrResized();
  206112. virtual void viewMovedToWindow();
  206113. virtual NSRect constrainRect (NSRect r);
  206114. static void showArrowCursorIfNeeded();
  206115. static void updateModifiers (NSEvent* e);
  206116. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206117. static int getKeyCodeFromEvent (NSEvent* ev)
  206118. {
  206119. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206120. int keyCode = unmodified[0];
  206121. if (keyCode == 0x19) // (backwards-tab)
  206122. keyCode = '\t';
  206123. else if (keyCode == 0x03) // (enter)
  206124. keyCode = '\r';
  206125. return keyCode;
  206126. }
  206127. static int64 getMouseTime (NSEvent* e)
  206128. {
  206129. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206130. + (int64) ([e timestamp] * 1000.0);
  206131. }
  206132. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206133. {
  206134. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206135. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206136. }
  206137. static int getModifierForButtonNumber (const NSInteger num)
  206138. {
  206139. return num == 0 ? ModifierKeys::leftButtonModifier
  206140. : (num == 1 ? ModifierKeys::rightButtonModifier
  206141. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206142. }
  206143. virtual void viewFocusGain();
  206144. virtual void viewFocusLoss();
  206145. bool isFocused() const;
  206146. void grabFocus();
  206147. void textInputRequired (const Point<int>& position);
  206148. void repaint (int x, int y, int w, int h);
  206149. void performAnyPendingRepaintsNow();
  206150. juce_UseDebuggingNewOperator
  206151. NSWindow* window;
  206152. JuceNSView* view;
  206153. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206154. static ModifierKeys currentModifiers;
  206155. static ComponentPeer* currentlyFocusedPeer;
  206156. static Array<int> keysCurrentlyDown;
  206157. };
  206158. END_JUCE_NAMESPACE
  206159. @implementation JuceNSView
  206160. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206161. withFrame: (NSRect) frame
  206162. {
  206163. [super initWithFrame: frame];
  206164. owner = owner_;
  206165. stringBeingComposed = 0;
  206166. textWasInserted = false;
  206167. notificationCenter = [NSNotificationCenter defaultCenter];
  206168. [notificationCenter addObserver: self
  206169. selector: @selector (frameChanged:)
  206170. name: NSViewFrameDidChangeNotification
  206171. object: self];
  206172. if (! owner_->isSharedWindow)
  206173. {
  206174. [notificationCenter addObserver: self
  206175. selector: @selector (frameChanged:)
  206176. name: NSWindowDidMoveNotification
  206177. object: owner_->window];
  206178. }
  206179. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206180. return self;
  206181. }
  206182. - (void) dealloc
  206183. {
  206184. [notificationCenter removeObserver: self];
  206185. delete stringBeingComposed;
  206186. [super dealloc];
  206187. }
  206188. - (void) drawRect: (NSRect) r
  206189. {
  206190. if (owner != 0)
  206191. owner->drawRect (r);
  206192. }
  206193. - (BOOL) isOpaque
  206194. {
  206195. return owner == 0 || owner->isOpaque();
  206196. }
  206197. - (void) mouseDown: (NSEvent*) ev
  206198. {
  206199. // In some host situations, the host will stop modal loops from working
  206200. // correctly if they're called from a mouse event, so we'll trigger
  206201. // the event asynchronously..
  206202. if (JUCEApplication::getInstance() == 0)
  206203. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206204. withObject: ev
  206205. waitUntilDone: NO];
  206206. else
  206207. [self asyncMouseDown: ev];
  206208. }
  206209. - (void) asyncMouseDown: (NSEvent*) ev
  206210. {
  206211. if (owner != 0)
  206212. owner->redirectMouseDown (ev);
  206213. }
  206214. - (void) mouseUp: (NSEvent*) ev
  206215. {
  206216. // In some host situations, the host will stop modal loops from working
  206217. // correctly if they're called from a mouse event, so we'll trigger
  206218. // the event asynchronously..
  206219. if (JUCEApplication::getInstance() == 0)
  206220. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206221. withObject: ev
  206222. waitUntilDone: NO];
  206223. else
  206224. [self asyncMouseUp: ev];
  206225. }
  206226. - (void) asyncMouseUp: (NSEvent*) ev
  206227. {
  206228. if (owner != 0)
  206229. owner->redirectMouseUp (ev);
  206230. }
  206231. - (void) mouseDragged: (NSEvent*) ev
  206232. {
  206233. if (owner != 0)
  206234. owner->redirectMouseDrag (ev);
  206235. }
  206236. - (void) mouseMoved: (NSEvent*) ev
  206237. {
  206238. if (owner != 0)
  206239. owner->redirectMouseMove (ev);
  206240. }
  206241. - (void) mouseEntered: (NSEvent*) ev
  206242. {
  206243. if (owner != 0)
  206244. owner->redirectMouseEnter (ev);
  206245. }
  206246. - (void) mouseExited: (NSEvent*) ev
  206247. {
  206248. if (owner != 0)
  206249. owner->redirectMouseExit (ev);
  206250. }
  206251. - (void) rightMouseDown: (NSEvent*) ev
  206252. {
  206253. [self mouseDown: ev];
  206254. }
  206255. - (void) rightMouseDragged: (NSEvent*) ev
  206256. {
  206257. [self mouseDragged: ev];
  206258. }
  206259. - (void) rightMouseUp: (NSEvent*) ev
  206260. {
  206261. [self mouseUp: ev];
  206262. }
  206263. - (void) otherMouseDown: (NSEvent*) ev
  206264. {
  206265. [self mouseDown: ev];
  206266. }
  206267. - (void) otherMouseDragged: (NSEvent*) ev
  206268. {
  206269. [self mouseDragged: ev];
  206270. }
  206271. - (void) otherMouseUp: (NSEvent*) ev
  206272. {
  206273. [self mouseUp: ev];
  206274. }
  206275. - (void) scrollWheel: (NSEvent*) ev
  206276. {
  206277. if (owner != 0)
  206278. owner->redirectMouseWheel (ev);
  206279. }
  206280. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206281. {
  206282. return YES;
  206283. }
  206284. - (void) frameChanged: (NSNotification*) n
  206285. {
  206286. if (owner != 0)
  206287. owner->redirectMovedOrResized();
  206288. }
  206289. - (void) viewDidMoveToWindow
  206290. {
  206291. if (owner != 0)
  206292. owner->viewMovedToWindow();
  206293. }
  206294. - (void) asyncRepaint: (id) rect
  206295. {
  206296. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206297. [self setNeedsDisplayInRect: *r];
  206298. }
  206299. - (void) keyDown: (NSEvent*) ev
  206300. {
  206301. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206302. textWasInserted = false;
  206303. if (target != 0)
  206304. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206305. else
  206306. deleteAndZero (stringBeingComposed);
  206307. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206308. [super keyDown: ev];
  206309. }
  206310. - (void) keyUp: (NSEvent*) ev
  206311. {
  206312. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206313. [super keyUp: ev];
  206314. }
  206315. - (void) insertText: (id) aString
  206316. {
  206317. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206318. if ([aString length] > 0)
  206319. {
  206320. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206321. if (target != 0)
  206322. {
  206323. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206324. textWasInserted = true;
  206325. }
  206326. }
  206327. deleteAndZero (stringBeingComposed);
  206328. }
  206329. - (void) doCommandBySelector: (SEL) aSelector
  206330. {
  206331. }
  206332. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206333. {
  206334. if (stringBeingComposed == 0)
  206335. stringBeingComposed = new String();
  206336. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206337. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206338. if (target != 0)
  206339. {
  206340. const Range<int> currentHighlight (target->getHighlightedRegion());
  206341. target->insertTextAtCaret (*stringBeingComposed);
  206342. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206343. textWasInserted = true;
  206344. }
  206345. }
  206346. - (void) unmarkText
  206347. {
  206348. if (stringBeingComposed != 0)
  206349. {
  206350. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206351. if (target != 0)
  206352. {
  206353. target->insertTextAtCaret (*stringBeingComposed);
  206354. textWasInserted = true;
  206355. }
  206356. }
  206357. deleteAndZero (stringBeingComposed);
  206358. }
  206359. - (BOOL) hasMarkedText
  206360. {
  206361. return stringBeingComposed != 0;
  206362. }
  206363. - (long) conversationIdentifier
  206364. {
  206365. return (long) (pointer_sized_int) self;
  206366. }
  206367. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206368. {
  206369. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206370. if (target != 0)
  206371. {
  206372. const Range<int> r ((int) theRange.location,
  206373. (int) (theRange.location + theRange.length));
  206374. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206375. }
  206376. return nil;
  206377. }
  206378. - (NSRange) markedRange
  206379. {
  206380. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206381. : NSMakeRange (NSNotFound, 0);
  206382. }
  206383. - (NSRange) selectedRange
  206384. {
  206385. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206386. if (target != 0)
  206387. {
  206388. const Range<int> highlight (target->getHighlightedRegion());
  206389. if (! highlight.isEmpty())
  206390. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206391. }
  206392. return NSMakeRange (NSNotFound, 0);
  206393. }
  206394. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206395. {
  206396. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206397. if (comp == 0)
  206398. return NSMakeRect (0, 0, 0, 0);
  206399. const Rectangle<int> bounds (comp->getScreenBounds());
  206400. return NSMakeRect (bounds.getX(),
  206401. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206402. bounds.getWidth(),
  206403. bounds.getHeight());
  206404. }
  206405. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206406. {
  206407. return NSNotFound;
  206408. }
  206409. - (NSArray*) validAttributesForMarkedText
  206410. {
  206411. return [NSArray array];
  206412. }
  206413. - (void) flagsChanged: (NSEvent*) ev
  206414. {
  206415. if (owner != 0)
  206416. owner->redirectModKeyChange (ev);
  206417. }
  206418. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206419. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206420. {
  206421. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206422. return true;
  206423. return [super performKeyEquivalent: ev];
  206424. }
  206425. #endif
  206426. - (BOOL) becomeFirstResponder
  206427. {
  206428. if (owner != 0)
  206429. owner->viewFocusGain();
  206430. return true;
  206431. }
  206432. - (BOOL) resignFirstResponder
  206433. {
  206434. if (owner != 0)
  206435. owner->viewFocusLoss();
  206436. return true;
  206437. }
  206438. - (BOOL) acceptsFirstResponder
  206439. {
  206440. return owner != 0 && owner->canBecomeKeyWindow();
  206441. }
  206442. - (NSArray*) getSupportedDragTypes
  206443. {
  206444. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206445. }
  206446. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206447. {
  206448. return owner != 0 && owner->sendDragCallback (type, sender);
  206449. }
  206450. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206451. {
  206452. if ([self sendDragCallback: 0 sender: sender])
  206453. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206454. else
  206455. return NSDragOperationNone;
  206456. }
  206457. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206458. {
  206459. if ([self sendDragCallback: 0 sender: sender])
  206460. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206461. else
  206462. return NSDragOperationNone;
  206463. }
  206464. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206465. {
  206466. [self sendDragCallback: 1 sender: sender];
  206467. }
  206468. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206469. {
  206470. [self sendDragCallback: 1 sender: sender];
  206471. }
  206472. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206473. {
  206474. return YES;
  206475. }
  206476. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206477. {
  206478. return [self sendDragCallback: 2 sender: sender];
  206479. }
  206480. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206481. {
  206482. }
  206483. @end
  206484. @implementation JuceNSWindow
  206485. - (void) setOwner: (NSViewComponentPeer*) owner_
  206486. {
  206487. owner = owner_;
  206488. isZooming = false;
  206489. }
  206490. - (BOOL) canBecomeKeyWindow
  206491. {
  206492. return owner != 0 && owner->canBecomeKeyWindow();
  206493. }
  206494. - (void) becomeKeyWindow
  206495. {
  206496. [super becomeKeyWindow];
  206497. if (owner != 0)
  206498. owner->grabFocus();
  206499. }
  206500. - (BOOL) windowShouldClose: (id) window
  206501. {
  206502. return owner == 0 || owner->windowShouldClose();
  206503. }
  206504. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206505. {
  206506. if (owner != 0)
  206507. frameRect = owner->constrainRect (frameRect);
  206508. return frameRect;
  206509. }
  206510. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206511. {
  206512. if (isZooming)
  206513. return proposedFrameSize;
  206514. NSRect frameRect = [self frame];
  206515. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206516. frameRect.size = proposedFrameSize;
  206517. if (owner != 0)
  206518. frameRect = owner->constrainRect (frameRect);
  206519. return frameRect.size;
  206520. }
  206521. - (void) zoom: (id) sender
  206522. {
  206523. isZooming = true;
  206524. [super zoom: sender];
  206525. isZooming = false;
  206526. }
  206527. - (void) windowWillMove: (NSNotification*) notification
  206528. {
  206529. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206530. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206531. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206532. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206533. }
  206534. @end
  206535. BEGIN_JUCE_NAMESPACE
  206536. ModifierKeys NSViewComponentPeer::currentModifiers;
  206537. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206538. Array<int> NSViewComponentPeer::keysCurrentlyDown;
  206539. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  206540. {
  206541. if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
  206542. return true;
  206543. if (keyCode >= 'A' && keyCode <= 'Z'
  206544. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
  206545. return true;
  206546. if (keyCode >= 'a' && keyCode <= 'z'
  206547. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
  206548. return true;
  206549. return false;
  206550. }
  206551. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206552. {
  206553. int m = 0;
  206554. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206555. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206556. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  206557. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  206558. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  206559. }
  206560. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  206561. {
  206562. updateModifiers (ev);
  206563. int keyCode = getKeyCodeFromEvent (ev);
  206564. if (keyCode != 0)
  206565. {
  206566. if (isKeyDown)
  206567. keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
  206568. else
  206569. keysCurrentlyDown.removeValue (keyCode);
  206570. }
  206571. }
  206572. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  206573. {
  206574. return NSViewComponentPeer::currentModifiers;
  206575. }
  206576. void ModifierKeys::updateCurrentModifiers() throw()
  206577. {
  206578. currentModifiers = NSViewComponentPeer::currentModifiers;
  206579. }
  206580. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  206581. const int windowStyleFlags,
  206582. NSView* viewToAttachTo)
  206583. : ComponentPeer (component_, windowStyleFlags),
  206584. window (0),
  206585. view (0),
  206586. isSharedWindow (viewToAttachTo != 0),
  206587. fullScreen (false),
  206588. insideDrawRect (false),
  206589. #if USE_COREGRAPHICS_RENDERING
  206590. usingCoreGraphics (true),
  206591. #else
  206592. usingCoreGraphics (false),
  206593. #endif
  206594. recursiveToFrontCall (false)
  206595. {
  206596. NSRect r;
  206597. r.origin.x = 0;
  206598. r.origin.y = 0;
  206599. r.size.width = (float) component->getWidth();
  206600. r.size.height = (float) component->getHeight();
  206601. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  206602. [view setPostsFrameChangedNotifications: YES];
  206603. if (isSharedWindow)
  206604. {
  206605. window = [viewToAttachTo window];
  206606. [viewToAttachTo addSubview: view];
  206607. setVisible (component->isVisible());
  206608. }
  206609. else
  206610. {
  206611. r.origin.x = (float) component->getX();
  206612. r.origin.y = (float) component->getY();
  206613. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  206614. unsigned int style = 0;
  206615. if ((windowStyleFlags & windowHasTitleBar) == 0)
  206616. style = NSBorderlessWindowMask;
  206617. else
  206618. style = NSTitledWindowMask;
  206619. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  206620. style |= NSMiniaturizableWindowMask;
  206621. if ((windowStyleFlags & windowHasCloseButton) != 0)
  206622. style |= NSClosableWindowMask;
  206623. if ((windowStyleFlags & windowIsResizable) != 0)
  206624. style |= NSResizableWindowMask;
  206625. window = [[JuceNSWindow alloc] initWithContentRect: r
  206626. styleMask: style
  206627. backing: NSBackingStoreBuffered
  206628. defer: YES];
  206629. [((JuceNSWindow*) window) setOwner: this];
  206630. [window orderOut: nil];
  206631. [window setDelegate: (JuceNSWindow*) window];
  206632. [window setOpaque: component->isOpaque()];
  206633. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  206634. if (component->isAlwaysOnTop())
  206635. [window setLevel: NSFloatingWindowLevel];
  206636. [window setContentView: view];
  206637. [window setAutodisplay: YES];
  206638. [window setAcceptsMouseMovedEvents: YES];
  206639. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  206640. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  206641. [window setReleasedWhenClosed: YES];
  206642. [window retain];
  206643. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  206644. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  206645. }
  206646. setTitle (component->getName());
  206647. }
  206648. NSViewComponentPeer::~NSViewComponentPeer()
  206649. {
  206650. view->owner = 0;
  206651. [view removeFromSuperview];
  206652. [view release];
  206653. if (! isSharedWindow)
  206654. {
  206655. [((JuceNSWindow*) window) setOwner: 0];
  206656. [window close];
  206657. [window release];
  206658. }
  206659. }
  206660. void* NSViewComponentPeer::getNativeHandle() const
  206661. {
  206662. return view;
  206663. }
  206664. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  206665. {
  206666. if (isSharedWindow)
  206667. {
  206668. [view setHidden: ! shouldBeVisible];
  206669. }
  206670. else
  206671. {
  206672. if (shouldBeVisible)
  206673. {
  206674. [window orderFront: nil];
  206675. handleBroughtToFront();
  206676. }
  206677. else
  206678. {
  206679. [window orderOut: nil];
  206680. }
  206681. }
  206682. }
  206683. void NSViewComponentPeer::setTitle (const String& title)
  206684. {
  206685. const ScopedAutoReleasePool pool;
  206686. if (! isSharedWindow)
  206687. [window setTitle: juceStringToNS (title)];
  206688. }
  206689. void NSViewComponentPeer::setPosition (int x, int y)
  206690. {
  206691. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  206692. }
  206693. void NSViewComponentPeer::setSize (int w, int h)
  206694. {
  206695. setBounds (component->getX(), component->getY(), w, h, false);
  206696. }
  206697. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  206698. {
  206699. fullScreen = isNowFullScreen;
  206700. w = jmax (0, w);
  206701. h = jmax (0, h);
  206702. NSRect r;
  206703. r.origin.x = (float) x;
  206704. r.origin.y = (float) y;
  206705. r.size.width = (float) w;
  206706. r.size.height = (float) h;
  206707. if (isSharedWindow)
  206708. {
  206709. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  206710. if ([view frame].size.width != r.size.width
  206711. || [view frame].size.height != r.size.height)
  206712. [view setNeedsDisplay: true];
  206713. [view setFrame: r];
  206714. }
  206715. else
  206716. {
  206717. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  206718. [window setFrame: [window frameRectForContentRect: r]
  206719. display: true];
  206720. }
  206721. }
  206722. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  206723. {
  206724. NSRect r = [view frame];
  206725. if (global && [view window] != 0)
  206726. {
  206727. r = [view convertRect: r toView: nil];
  206728. NSRect wr = [[view window] frame];
  206729. r.origin.x += wr.origin.x;
  206730. r.origin.y += wr.origin.y;
  206731. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  206732. }
  206733. else
  206734. {
  206735. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  206736. }
  206737. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  206738. }
  206739. const Rectangle<int> NSViewComponentPeer::getBounds() const
  206740. {
  206741. return getBounds (! isSharedWindow);
  206742. }
  206743. const Point<int> NSViewComponentPeer::getScreenPosition() const
  206744. {
  206745. return getBounds (true).getPosition();
  206746. }
  206747. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  206748. {
  206749. return relativePosition + getScreenPosition();
  206750. }
  206751. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  206752. {
  206753. return screenPosition - getScreenPosition();
  206754. }
  206755. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  206756. {
  206757. if (constrainer != 0)
  206758. {
  206759. NSRect current = [window frame];
  206760. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  206761. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  206762. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  206763. (int) r.size.width, (int) r.size.height);
  206764. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  206765. (int) current.size.width, (int) current.size.height);
  206766. constrainer->checkBounds (pos, original,
  206767. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  206768. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  206769. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  206770. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  206771. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  206772. r.origin.x = pos.getX();
  206773. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  206774. r.size.width = pos.getWidth();
  206775. r.size.height = pos.getHeight();
  206776. }
  206777. return r;
  206778. }
  206779. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  206780. {
  206781. if (! isSharedWindow)
  206782. {
  206783. if (shouldBeMinimised)
  206784. [window miniaturize: nil];
  206785. else
  206786. [window deminiaturize: nil];
  206787. }
  206788. }
  206789. bool NSViewComponentPeer::isMinimised() const
  206790. {
  206791. return window != 0 && [window isMiniaturized];
  206792. }
  206793. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  206794. {
  206795. if (! isSharedWindow)
  206796. {
  206797. Rectangle<int> r (lastNonFullscreenBounds);
  206798. setMinimised (false);
  206799. if (fullScreen != shouldBeFullScreen)
  206800. {
  206801. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  206802. {
  206803. fullScreen = true;
  206804. [window performZoom: nil];
  206805. }
  206806. else
  206807. {
  206808. if (shouldBeFullScreen)
  206809. r = Desktop::getInstance().getMainMonitorArea();
  206810. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  206811. if (r != getComponent()->getBounds() && ! r.isEmpty())
  206812. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  206813. }
  206814. }
  206815. }
  206816. }
  206817. bool NSViewComponentPeer::isFullScreen() const
  206818. {
  206819. return fullScreen;
  206820. }
  206821. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  206822. {
  206823. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  206824. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  206825. return false;
  206826. NSPoint p;
  206827. p.x = (float) position.getX();
  206828. p.y = (float) position.getY();
  206829. NSView* v = [view hitTest: p];
  206830. if (trueIfInAChildWindow)
  206831. return v != nil;
  206832. return v == view;
  206833. }
  206834. const BorderSize NSViewComponentPeer::getFrameSize() const
  206835. {
  206836. BorderSize b;
  206837. if (! isSharedWindow)
  206838. {
  206839. NSRect v = [view convertRect: [view frame] toView: nil];
  206840. NSRect w = [window frame];
  206841. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  206842. b.setBottom ((int) v.origin.y);
  206843. b.setLeft ((int) v.origin.x);
  206844. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  206845. }
  206846. return b;
  206847. }
  206848. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  206849. {
  206850. if (! isSharedWindow)
  206851. {
  206852. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  206853. : NSNormalWindowLevel];
  206854. }
  206855. return true;
  206856. }
  206857. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  206858. {
  206859. if (isSharedWindow)
  206860. {
  206861. [[view superview] addSubview: view
  206862. positioned: NSWindowAbove
  206863. relativeTo: nil];
  206864. }
  206865. if (window != 0 && component->isVisible())
  206866. {
  206867. if (makeActiveWindow)
  206868. [window makeKeyAndOrderFront: nil];
  206869. else
  206870. [window orderFront: nil];
  206871. if (! recursiveToFrontCall)
  206872. {
  206873. recursiveToFrontCall = true;
  206874. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  206875. handleBroughtToFront();
  206876. recursiveToFrontCall = false;
  206877. }
  206878. }
  206879. }
  206880. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  206881. {
  206882. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  206883. if (isSharedWindow)
  206884. {
  206885. [[view superview] addSubview: view
  206886. positioned: NSWindowBelow
  206887. relativeTo: o->view];
  206888. }
  206889. else
  206890. {
  206891. [window orderWindow: NSWindowBelow
  206892. relativeTo: o->window != 0 ? [o->window windowNumber]
  206893. : nil ];
  206894. }
  206895. }
  206896. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  206897. {
  206898. // to do..
  206899. }
  206900. void NSViewComponentPeer::viewFocusGain()
  206901. {
  206902. if (currentlyFocusedPeer != this)
  206903. {
  206904. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  206905. currentlyFocusedPeer->handleFocusLoss();
  206906. currentlyFocusedPeer = this;
  206907. handleFocusGain();
  206908. }
  206909. }
  206910. void NSViewComponentPeer::viewFocusLoss()
  206911. {
  206912. if (currentlyFocusedPeer == this)
  206913. {
  206914. currentlyFocusedPeer = 0;
  206915. handleFocusLoss();
  206916. }
  206917. }
  206918. void juce_HandleProcessFocusChange()
  206919. {
  206920. NSViewComponentPeer::keysCurrentlyDown.clear();
  206921. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  206922. {
  206923. if (Process::isForegroundProcess())
  206924. {
  206925. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  206926. ComponentPeer::bringModalComponentToFront();
  206927. }
  206928. else
  206929. {
  206930. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  206931. // turn kiosk mode off if we lose focus..
  206932. Desktop::getInstance().setKioskModeComponent (0);
  206933. }
  206934. }
  206935. }
  206936. bool NSViewComponentPeer::isFocused() const
  206937. {
  206938. return isSharedWindow ? this == currentlyFocusedPeer
  206939. : (window != 0 && [window isKeyWindow]);
  206940. }
  206941. void NSViewComponentPeer::grabFocus()
  206942. {
  206943. if (window != 0)
  206944. {
  206945. [window makeKeyWindow];
  206946. [window makeFirstResponder: view];
  206947. viewFocusGain();
  206948. }
  206949. }
  206950. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  206951. {
  206952. }
  206953. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  206954. {
  206955. String unicode (nsStringToJuce ([ev characters]));
  206956. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206957. int keyCode = getKeyCodeFromEvent (ev);
  206958. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  206959. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  206960. if (unicode.isNotEmpty() || keyCode != 0)
  206961. {
  206962. if (isKeyDown)
  206963. {
  206964. bool used = false;
  206965. while (unicode.length() > 0)
  206966. {
  206967. juce_wchar textCharacter = unicode[0];
  206968. unicode = unicode.substring (1);
  206969. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  206970. textCharacter = 0;
  206971. used = handleKeyUpOrDown (true) || used;
  206972. used = handleKeyPress (keyCode, textCharacter) || used;
  206973. }
  206974. return used;
  206975. }
  206976. else
  206977. {
  206978. if (handleKeyUpOrDown (false))
  206979. return true;
  206980. }
  206981. }
  206982. return false;
  206983. }
  206984. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  206985. {
  206986. updateKeysDown (ev, true);
  206987. bool used = handleKeyEvent (ev, true);
  206988. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  206989. {
  206990. // for command keys, the key-up event is thrown away, so simulate one..
  206991. updateKeysDown (ev, false);
  206992. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  206993. }
  206994. // (If we're running modally, don't allow unused keystrokes to be passed
  206995. // along to other blocked views..)
  206996. if (Component::getCurrentlyModalComponent() != 0)
  206997. used = true;
  206998. return used;
  206999. }
  207000. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207001. {
  207002. updateKeysDown (ev, false);
  207003. return handleKeyEvent (ev, false)
  207004. || Component::getCurrentlyModalComponent() != 0;
  207005. }
  207006. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207007. {
  207008. keysCurrentlyDown.clear();
  207009. handleKeyUpOrDown (true);
  207010. updateModifiers (ev);
  207011. handleModifierKeysChange();
  207012. }
  207013. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207014. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207015. {
  207016. if ([ev type] == NSKeyDown)
  207017. return redirectKeyDown (ev);
  207018. else if ([ev type] == NSKeyUp)
  207019. return redirectKeyUp (ev);
  207020. return false;
  207021. }
  207022. #endif
  207023. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207024. {
  207025. updateModifiers (ev);
  207026. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207027. }
  207028. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207029. {
  207030. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207031. sendMouseEvent (ev);
  207032. }
  207033. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207034. {
  207035. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207036. sendMouseEvent (ev);
  207037. showArrowCursorIfNeeded();
  207038. }
  207039. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207040. {
  207041. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207042. sendMouseEvent (ev);
  207043. }
  207044. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207045. {
  207046. currentModifiers = currentModifiers.withoutMouseButtons();
  207047. sendMouseEvent (ev);
  207048. showArrowCursorIfNeeded();
  207049. }
  207050. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207051. {
  207052. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207053. currentModifiers = currentModifiers.withoutMouseButtons();
  207054. sendMouseEvent (ev);
  207055. }
  207056. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207057. {
  207058. currentModifiers = currentModifiers.withoutMouseButtons();
  207059. sendMouseEvent (ev);
  207060. }
  207061. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207062. {
  207063. updateModifiers (ev);
  207064. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207065. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207066. }
  207067. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207068. {
  207069. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207070. if (mouse.getComponentUnderMouse() == 0
  207071. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207072. {
  207073. [[NSCursor arrowCursor] set];
  207074. }
  207075. }
  207076. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207077. {
  207078. NSString* bestType
  207079. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207080. if (bestType == nil)
  207081. return false;
  207082. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207083. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207084. StringArray files;
  207085. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207086. if (list == nil)
  207087. return false;
  207088. if ([list isKindOfClass: [NSArray class]])
  207089. {
  207090. NSArray* items = (NSArray*) list;
  207091. for (unsigned int i = 0; i < [items count]; ++i)
  207092. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207093. }
  207094. if (files.size() == 0)
  207095. return false;
  207096. if (type == 0)
  207097. handleFileDragMove (files, pos);
  207098. else if (type == 1)
  207099. handleFileDragExit (files);
  207100. else if (type == 2)
  207101. handleFileDragDrop (files, pos);
  207102. return true;
  207103. }
  207104. bool NSViewComponentPeer::isOpaque()
  207105. {
  207106. return component == 0 || component->isOpaque();
  207107. }
  207108. void NSViewComponentPeer::drawRect (NSRect r)
  207109. {
  207110. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207111. return;
  207112. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207113. if (! component->isOpaque())
  207114. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207115. #if USE_COREGRAPHICS_RENDERING
  207116. if (usingCoreGraphics)
  207117. {
  207118. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207119. insideDrawRect = true;
  207120. handlePaint (context);
  207121. insideDrawRect = false;
  207122. }
  207123. else
  207124. #endif
  207125. {
  207126. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207127. (int) (r.size.width + 0.5f),
  207128. (int) (r.size.height + 0.5f),
  207129. ! getComponent()->isOpaque());
  207130. LowLevelGraphicsSoftwareRenderer context (temp);
  207131. context.setOrigin (-roundToInt (r.origin.x),
  207132. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207133. const NSRect* rects = 0;
  207134. NSInteger numRects = 0;
  207135. [view getRectsBeingDrawn: &rects count: &numRects];
  207136. RectangleList clip;
  207137. for (int i = 0; i < numRects; ++i)
  207138. {
  207139. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207140. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207141. roundToInt (rects[i].size.width),
  207142. roundToInt (rects[i].size.height)));
  207143. }
  207144. if (context.clipToRectangleList (clip))
  207145. {
  207146. insideDrawRect = true;
  207147. handlePaint (context);
  207148. insideDrawRect = false;
  207149. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207150. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207151. CGColorSpaceRelease (colourSpace);
  207152. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207153. CGImageRelease (image);
  207154. }
  207155. }
  207156. }
  207157. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207158. {
  207159. StringArray s;
  207160. s.add ("Software Renderer");
  207161. #if USE_COREGRAPHICS_RENDERING
  207162. s.add ("CoreGraphics Renderer");
  207163. #endif
  207164. return s;
  207165. }
  207166. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207167. {
  207168. return usingCoreGraphics ? 1 : 0;
  207169. }
  207170. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207171. {
  207172. #if USE_COREGRAPHICS_RENDERING
  207173. if (usingCoreGraphics != (index > 0))
  207174. {
  207175. usingCoreGraphics = index > 0;
  207176. [view setNeedsDisplay: true];
  207177. }
  207178. #endif
  207179. }
  207180. bool NSViewComponentPeer::canBecomeKeyWindow()
  207181. {
  207182. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207183. }
  207184. bool NSViewComponentPeer::windowShouldClose()
  207185. {
  207186. if (! isValidPeer (this))
  207187. return YES;
  207188. handleUserClosingWindow();
  207189. return NO;
  207190. }
  207191. void NSViewComponentPeer::redirectMovedOrResized()
  207192. {
  207193. handleMovedOrResized();
  207194. }
  207195. void NSViewComponentPeer::viewMovedToWindow()
  207196. {
  207197. if (isSharedWindow)
  207198. window = [view window];
  207199. }
  207200. void Desktop::createMouseInputSources()
  207201. {
  207202. mouseSources.add (new MouseInputSource (0, true));
  207203. }
  207204. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207205. {
  207206. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207207. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207208. // is apparently still available in 64-bit apps..
  207209. if (enableOrDisable)
  207210. {
  207211. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207212. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207213. }
  207214. else
  207215. {
  207216. SetSystemUIMode (kUIModeNormal, 0);
  207217. }
  207218. }
  207219. class AsyncRepaintMessage : public CallbackMessage
  207220. {
  207221. public:
  207222. NSViewComponentPeer* const peer;
  207223. const Rectangle<int> rect;
  207224. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207225. : peer (peer_), rect (rect_)
  207226. {
  207227. }
  207228. void messageCallback()
  207229. {
  207230. if (ComponentPeer::isValidPeer (peer))
  207231. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207232. }
  207233. };
  207234. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207235. {
  207236. if (insideDrawRect)
  207237. {
  207238. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207239. }
  207240. else
  207241. {
  207242. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207243. (float) w, (float) h)];
  207244. }
  207245. }
  207246. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207247. {
  207248. [view displayIfNeeded];
  207249. }
  207250. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207251. {
  207252. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207253. }
  207254. Image* juce_createIconForFile (const File& file)
  207255. {
  207256. const ScopedAutoReleasePool pool;
  207257. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207258. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207259. [NSGraphicsContext saveGraphicsState];
  207260. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207261. [image drawAtPoint: NSMakePoint (0, 0)
  207262. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207263. operation: NSCompositeSourceOver fraction: 1.0f];
  207264. [[NSGraphicsContext currentContext] flushGraphics];
  207265. [NSGraphicsContext restoreGraphicsState];
  207266. return result;
  207267. }
  207268. const int KeyPress::spaceKey = ' ';
  207269. const int KeyPress::returnKey = 0x0d;
  207270. const int KeyPress::escapeKey = 0x1b;
  207271. const int KeyPress::backspaceKey = 0x7f;
  207272. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207273. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207274. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207275. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207276. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207277. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207278. const int KeyPress::endKey = NSEndFunctionKey;
  207279. const int KeyPress::homeKey = NSHomeFunctionKey;
  207280. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207281. const int KeyPress::insertKey = -1;
  207282. const int KeyPress::tabKey = 9;
  207283. const int KeyPress::F1Key = NSF1FunctionKey;
  207284. const int KeyPress::F2Key = NSF2FunctionKey;
  207285. const int KeyPress::F3Key = NSF3FunctionKey;
  207286. const int KeyPress::F4Key = NSF4FunctionKey;
  207287. const int KeyPress::F5Key = NSF5FunctionKey;
  207288. const int KeyPress::F6Key = NSF6FunctionKey;
  207289. const int KeyPress::F7Key = NSF7FunctionKey;
  207290. const int KeyPress::F8Key = NSF8FunctionKey;
  207291. const int KeyPress::F9Key = NSF9FunctionKey;
  207292. const int KeyPress::F10Key = NSF10FunctionKey;
  207293. const int KeyPress::F11Key = NSF1FunctionKey;
  207294. const int KeyPress::F12Key = NSF12FunctionKey;
  207295. const int KeyPress::F13Key = NSF13FunctionKey;
  207296. const int KeyPress::F14Key = NSF14FunctionKey;
  207297. const int KeyPress::F15Key = NSF15FunctionKey;
  207298. const int KeyPress::F16Key = NSF16FunctionKey;
  207299. const int KeyPress::numberPad0 = 0x30020;
  207300. const int KeyPress::numberPad1 = 0x30021;
  207301. const int KeyPress::numberPad2 = 0x30022;
  207302. const int KeyPress::numberPad3 = 0x30023;
  207303. const int KeyPress::numberPad4 = 0x30024;
  207304. const int KeyPress::numberPad5 = 0x30025;
  207305. const int KeyPress::numberPad6 = 0x30026;
  207306. const int KeyPress::numberPad7 = 0x30027;
  207307. const int KeyPress::numberPad8 = 0x30028;
  207308. const int KeyPress::numberPad9 = 0x30029;
  207309. const int KeyPress::numberPadAdd = 0x3002a;
  207310. const int KeyPress::numberPadSubtract = 0x3002b;
  207311. const int KeyPress::numberPadMultiply = 0x3002c;
  207312. const int KeyPress::numberPadDivide = 0x3002d;
  207313. const int KeyPress::numberPadSeparator = 0x3002e;
  207314. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207315. const int KeyPress::numberPadEquals = 0x30030;
  207316. const int KeyPress::numberPadDelete = 0x30031;
  207317. const int KeyPress::playKey = 0x30000;
  207318. const int KeyPress::stopKey = 0x30001;
  207319. const int KeyPress::fastForwardKey = 0x30002;
  207320. const int KeyPress::rewindKey = 0x30003;
  207321. #endif
  207322. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207323. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207324. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207325. // compiled on its own).
  207326. #if JUCE_INCLUDED_FILE
  207327. #if JUCE_MAC
  207328. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207329. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  207330. {
  207331. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207332. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207333. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207334. [im release];
  207335. return c;
  207336. }
  207337. static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy)
  207338. {
  207339. MemoryInputStream stream (data, false);
  207340. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207341. jassert (im != 0);
  207342. if (im == 0)
  207343. return 0;
  207344. return juce_createMouseCursorFromImage (*im,
  207345. (int) (hx * im->getWidth()),
  207346. (int) (hy * im->getHeight()));
  207347. }
  207348. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207349. {
  207350. const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207351. MemoryBlock mb;
  207352. if (f.getChildFile (filename).loadFileAsData (mb))
  207353. return juce_cursorFromData (mb, hx, hy);
  207354. return 0;
  207355. }
  207356. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  207357. {
  207358. const ScopedAutoReleasePool pool;
  207359. NSCursor* c = 0;
  207360. switch (type)
  207361. {
  207362. case MouseCursor::NormalCursor:
  207363. c = [NSCursor arrowCursor];
  207364. break;
  207365. case MouseCursor::NoCursor:
  207366. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207367. case MouseCursor::DraggingHandCursor:
  207368. c = [NSCursor openHandCursor];
  207369. break;
  207370. case MouseCursor::CopyingCursor:
  207371. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207372. case MouseCursor::WaitCursor:
  207373. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207374. break;
  207375. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207376. case MouseCursor::IBeamCursor:
  207377. c = [NSCursor IBeamCursor];
  207378. break;
  207379. case MouseCursor::PointingHandCursor:
  207380. c = [NSCursor pointingHandCursor];
  207381. break;
  207382. case MouseCursor::LeftRightResizeCursor:
  207383. c = [NSCursor resizeLeftRightCursor];
  207384. break;
  207385. case MouseCursor::LeftEdgeResizeCursor:
  207386. c = [NSCursor resizeLeftCursor];
  207387. break;
  207388. case MouseCursor::RightEdgeResizeCursor:
  207389. c = [NSCursor resizeRightCursor];
  207390. break;
  207391. case MouseCursor::UpDownResizeCursor:
  207392. case MouseCursor::TopEdgeResizeCursor:
  207393. case MouseCursor::BottomEdgeResizeCursor:
  207394. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207395. case MouseCursor::TopLeftCornerResizeCursor:
  207396. case MouseCursor::BottomRightCornerResizeCursor:
  207397. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207398. case MouseCursor::TopRightCornerResizeCursor:
  207399. case MouseCursor::BottomLeftCornerResizeCursor:
  207400. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207401. case MouseCursor::UpDownLeftRightResizeCursor:
  207402. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207403. case MouseCursor::CrosshairCursor:
  207404. c = [NSCursor crosshairCursor];
  207405. break;
  207406. }
  207407. [c retain];
  207408. return c;
  207409. }
  207410. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  207411. {
  207412. NSCursor* c = (NSCursor*) cursorHandle;
  207413. [c release];
  207414. }
  207415. void MouseCursor::showInAllWindows() const
  207416. {
  207417. showInWindow (0);
  207418. }
  207419. void MouseCursor::showInWindow (ComponentPeer*) const
  207420. {
  207421. NSCursor* const c = (NSCursor*) getHandle();
  207422. [c set];
  207423. }
  207424. #else
  207425. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; }
  207426. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; }
  207427. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {}
  207428. void MouseCursor::showInAllWindows() const {}
  207429. void MouseCursor::showInWindow (ComponentPeer*) const {}
  207430. #endif
  207431. #endif
  207432. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207433. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207434. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207435. // compiled on its own).
  207436. #if JUCE_INCLUDED_FILE
  207437. class NSViewComponentInternal : public ComponentMovementWatcher
  207438. {
  207439. Component* const owner;
  207440. NSViewComponentPeer* currentPeer;
  207441. bool wasShowing;
  207442. public:
  207443. NSView* const view;
  207444. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207445. : ComponentMovementWatcher (owner_),
  207446. owner (owner_),
  207447. currentPeer (0),
  207448. wasShowing (false),
  207449. view (view_)
  207450. {
  207451. [view_ retain];
  207452. if (owner_->isShowing())
  207453. componentPeerChanged();
  207454. }
  207455. ~NSViewComponentInternal()
  207456. {
  207457. [view removeFromSuperview];
  207458. [view release];
  207459. }
  207460. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207461. {
  207462. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207463. // The ComponentMovementWatcher version of this method avoids calling
  207464. // us when the top-level comp is resized, but for an NSView we need to know this
  207465. // because with inverted co-ords, we need to update the position even if the
  207466. // top-left pos hasn't changed
  207467. if (comp.isOnDesktop() && wasResized)
  207468. componentMovedOrResized (wasMoved, wasResized);
  207469. }
  207470. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207471. {
  207472. Component* const topComp = owner->getTopLevelComponent();
  207473. if (topComp->getPeer() != 0)
  207474. {
  207475. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207476. NSRect r;
  207477. r.origin.x = (float) pos.getX();
  207478. r.origin.y = (float) pos.getY();
  207479. r.size.width = (float) owner->getWidth();
  207480. r.size.height = (float) owner->getHeight();
  207481. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207482. [view setFrame: r];
  207483. }
  207484. }
  207485. void componentPeerChanged()
  207486. {
  207487. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207488. if (currentPeer != peer)
  207489. {
  207490. [view removeFromSuperview];
  207491. currentPeer = peer;
  207492. if (peer != 0)
  207493. {
  207494. [peer->view addSubview: view];
  207495. componentMovedOrResized (false, false);
  207496. }
  207497. }
  207498. [view setHidden: ! owner->isShowing()];
  207499. }
  207500. void componentVisibilityChanged (Component&)
  207501. {
  207502. componentPeerChanged();
  207503. }
  207504. juce_UseDebuggingNewOperator
  207505. private:
  207506. NSViewComponentInternal (const NSViewComponentInternal&);
  207507. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207508. };
  207509. NSViewComponent::NSViewComponent()
  207510. {
  207511. }
  207512. NSViewComponent::~NSViewComponent()
  207513. {
  207514. }
  207515. void NSViewComponent::setView (void* view)
  207516. {
  207517. if (view != getView())
  207518. {
  207519. if (view != 0)
  207520. info = new NSViewComponentInternal ((NSView*) view, this);
  207521. else
  207522. info = 0;
  207523. }
  207524. }
  207525. void* NSViewComponent::getView() const
  207526. {
  207527. return info == 0 ? 0 : info->view;
  207528. }
  207529. void NSViewComponent::paint (Graphics& g)
  207530. {
  207531. }
  207532. #endif
  207533. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207534. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207535. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207536. // compiled on its own).
  207537. #if JUCE_INCLUDED_FILE
  207538. AppleRemoteDevice::AppleRemoteDevice()
  207539. : device (0),
  207540. queue (0),
  207541. remoteId (0)
  207542. {
  207543. }
  207544. AppleRemoteDevice::~AppleRemoteDevice()
  207545. {
  207546. stop();
  207547. }
  207548. static io_object_t getAppleRemoteDevice()
  207549. {
  207550. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207551. io_iterator_t iter = 0;
  207552. io_object_t iod = 0;
  207553. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207554. && iter != 0)
  207555. {
  207556. iod = IOIteratorNext (iter);
  207557. }
  207558. IOObjectRelease (iter);
  207559. return iod;
  207560. }
  207561. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207562. {
  207563. jassert (*device == 0);
  207564. io_name_t classname;
  207565. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207566. {
  207567. IOCFPlugInInterface** cfPlugInInterface = 0;
  207568. SInt32 score = 0;
  207569. if (IOCreatePlugInInterfaceForService (iod,
  207570. kIOHIDDeviceUserClientTypeID,
  207571. kIOCFPlugInInterfaceID,
  207572. &cfPlugInInterface,
  207573. &score) == kIOReturnSuccess)
  207574. {
  207575. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  207576. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  207577. device);
  207578. (void) hr;
  207579. (*cfPlugInInterface)->Release (cfPlugInInterface);
  207580. }
  207581. }
  207582. return *device != 0;
  207583. }
  207584. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  207585. {
  207586. if (queue != 0)
  207587. return true;
  207588. stop();
  207589. bool result = false;
  207590. io_object_t iod = getAppleRemoteDevice();
  207591. if (iod != 0)
  207592. {
  207593. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  207594. result = true;
  207595. else
  207596. stop();
  207597. IOObjectRelease (iod);
  207598. }
  207599. return result;
  207600. }
  207601. void AppleRemoteDevice::stop()
  207602. {
  207603. if (queue != 0)
  207604. {
  207605. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  207606. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  207607. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  207608. queue = 0;
  207609. }
  207610. if (device != 0)
  207611. {
  207612. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  207613. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  207614. device = 0;
  207615. }
  207616. }
  207617. bool AppleRemoteDevice::isActive() const
  207618. {
  207619. return queue != 0;
  207620. }
  207621. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  207622. {
  207623. if (result == kIOReturnSuccess)
  207624. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  207625. }
  207626. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  207627. {
  207628. Array <int> cookies;
  207629. CFArrayRef elements;
  207630. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  207631. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  207632. return false;
  207633. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  207634. {
  207635. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  207636. // get the cookie
  207637. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  207638. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  207639. continue;
  207640. long number;
  207641. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  207642. continue;
  207643. cookies.add ((int) number);
  207644. }
  207645. CFRelease (elements);
  207646. if ((*(IOHIDDeviceInterface**) device)
  207647. ->open ((IOHIDDeviceInterface**) device,
  207648. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  207649. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  207650. {
  207651. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  207652. if (queue != 0)
  207653. {
  207654. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  207655. for (int i = 0; i < cookies.size(); ++i)
  207656. {
  207657. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  207658. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  207659. }
  207660. CFRunLoopSourceRef eventSource;
  207661. if ((*(IOHIDQueueInterface**) queue)
  207662. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  207663. {
  207664. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  207665. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  207666. {
  207667. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  207668. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  207669. return true;
  207670. }
  207671. }
  207672. }
  207673. }
  207674. return false;
  207675. }
  207676. void AppleRemoteDevice::handleCallbackInternal()
  207677. {
  207678. int totalValues = 0;
  207679. AbsoluteTime nullTime = { 0, 0 };
  207680. char cookies [12];
  207681. int numCookies = 0;
  207682. while (numCookies < numElementsInArray (cookies))
  207683. {
  207684. IOHIDEventStruct e;
  207685. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  207686. break;
  207687. if ((int) e.elementCookie == 19)
  207688. {
  207689. remoteId = e.value;
  207690. buttonPressed (switched, false);
  207691. }
  207692. else
  207693. {
  207694. totalValues += e.value;
  207695. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  207696. }
  207697. }
  207698. cookies [numCookies++] = 0;
  207699. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  207700. static const char buttonPatterns[] =
  207701. {
  207702. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  207703. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  207704. 0x1f, 0x1d, 0x1c, 0x12, 0,
  207705. 0x1f, 0x1e, 0x1c, 0x12, 0,
  207706. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  207707. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  207708. 0x1f, 0x12, 0x04, 0x02, 0,
  207709. 0x1f, 0x12, 0x03, 0x02, 0,
  207710. 0x1f, 0x12, 0x1f, 0x12, 0,
  207711. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  207712. 19, 0
  207713. };
  207714. int buttonNum = (int) menuButton;
  207715. int i = 0;
  207716. while (i < numElementsInArray (buttonPatterns))
  207717. {
  207718. if (strcmp (cookies, buttonPatterns + i) == 0)
  207719. {
  207720. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  207721. break;
  207722. }
  207723. i += (int) strlen (buttonPatterns + i) + 1;
  207724. ++buttonNum;
  207725. }
  207726. }
  207727. #endif
  207728. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  207729. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  207730. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207731. // compiled on its own).
  207732. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  207733. #if JUCE_MAC
  207734. END_JUCE_NAMESPACE
  207735. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  207736. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  207737. {
  207738. CriticalSection* contextLock;
  207739. bool needsUpdate;
  207740. }
  207741. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  207742. - (bool) makeActive;
  207743. - (void) makeInactive;
  207744. - (void) reshape;
  207745. @end
  207746. @implementation ThreadSafeNSOpenGLView
  207747. - (id) initWithFrame: (NSRect) frameRect
  207748. pixelFormat: (NSOpenGLPixelFormat*) format
  207749. {
  207750. contextLock = new CriticalSection();
  207751. self = [super initWithFrame: frameRect pixelFormat: format];
  207752. if (self != nil)
  207753. [[NSNotificationCenter defaultCenter] addObserver: self
  207754. selector: @selector (_surfaceNeedsUpdate:)
  207755. name: NSViewGlobalFrameDidChangeNotification
  207756. object: self];
  207757. return self;
  207758. }
  207759. - (void) dealloc
  207760. {
  207761. [[NSNotificationCenter defaultCenter] removeObserver: self];
  207762. delete contextLock;
  207763. [super dealloc];
  207764. }
  207765. - (bool) makeActive
  207766. {
  207767. const ScopedLock sl (*contextLock);
  207768. if ([self openGLContext] == 0)
  207769. return false;
  207770. [[self openGLContext] makeCurrentContext];
  207771. if (needsUpdate)
  207772. {
  207773. [super update];
  207774. needsUpdate = false;
  207775. }
  207776. return true;
  207777. }
  207778. - (void) makeInactive
  207779. {
  207780. const ScopedLock sl (*contextLock);
  207781. [NSOpenGLContext clearCurrentContext];
  207782. }
  207783. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  207784. {
  207785. const ScopedLock sl (*contextLock);
  207786. needsUpdate = true;
  207787. }
  207788. - (void) update
  207789. {
  207790. const ScopedLock sl (*contextLock);
  207791. needsUpdate = true;
  207792. }
  207793. - (void) reshape
  207794. {
  207795. const ScopedLock sl (*contextLock);
  207796. needsUpdate = true;
  207797. }
  207798. @end
  207799. BEGIN_JUCE_NAMESPACE
  207800. class WindowedGLContext : public OpenGLContext
  207801. {
  207802. public:
  207803. WindowedGLContext (Component* const component,
  207804. const OpenGLPixelFormat& pixelFormat_,
  207805. NSOpenGLContext* sharedContext)
  207806. : renderContext (0),
  207807. pixelFormat (pixelFormat_)
  207808. {
  207809. jassert (component != 0);
  207810. NSOpenGLPixelFormatAttribute attribs [64];
  207811. int n = 0;
  207812. attribs[n++] = NSOpenGLPFADoubleBuffer;
  207813. attribs[n++] = NSOpenGLPFAAccelerated;
  207814. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  207815. attribs[n++] = NSOpenGLPFAColorSize;
  207816. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  207817. pixelFormat.greenBits,
  207818. pixelFormat.blueBits);
  207819. attribs[n++] = NSOpenGLPFAAlphaSize;
  207820. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  207821. attribs[n++] = NSOpenGLPFADepthSize;
  207822. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  207823. attribs[n++] = NSOpenGLPFAStencilSize;
  207824. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  207825. attribs[n++] = NSOpenGLPFAAccumSize;
  207826. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  207827. pixelFormat.accumulationBufferGreenBits,
  207828. pixelFormat.accumulationBufferBlueBits,
  207829. pixelFormat.accumulationBufferAlphaBits);
  207830. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  207831. attribs[n++] = NSOpenGLPFASampleBuffers;
  207832. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  207833. attribs[n++] = NSOpenGLPFAClosestPolicy;
  207834. attribs[n++] = NSOpenGLPFANoRecovery;
  207835. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  207836. NSOpenGLPixelFormat* format
  207837. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  207838. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  207839. pixelFormat: format];
  207840. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  207841. shareContext: sharedContext] autorelease];
  207842. const GLint swapInterval = 1;
  207843. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  207844. [view setOpenGLContext: renderContext];
  207845. [renderContext setView: view];
  207846. [format release];
  207847. viewHolder = new NSViewComponentInternal (view, component);
  207848. }
  207849. ~WindowedGLContext()
  207850. {
  207851. makeInactive();
  207852. [renderContext clearDrawable];
  207853. viewHolder = 0;
  207854. }
  207855. bool makeActive() const throw()
  207856. {
  207857. jassert (renderContext != 0);
  207858. [view makeActive];
  207859. return isActive();
  207860. }
  207861. bool makeInactive() const throw()
  207862. {
  207863. [view makeInactive];
  207864. return true;
  207865. }
  207866. bool isActive() const throw()
  207867. {
  207868. return [NSOpenGLContext currentContext] == renderContext;
  207869. }
  207870. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  207871. void* getRawContext() const throw() { return renderContext; }
  207872. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  207873. {
  207874. }
  207875. void swapBuffers()
  207876. {
  207877. [renderContext flushBuffer];
  207878. }
  207879. bool setSwapInterval (const int numFramesPerSwap)
  207880. {
  207881. [renderContext setValues: (const GLint*) &numFramesPerSwap
  207882. forParameter: NSOpenGLCPSwapInterval];
  207883. return true;
  207884. }
  207885. int getSwapInterval() const
  207886. {
  207887. GLint numFrames = 0;
  207888. [renderContext getValues: &numFrames
  207889. forParameter: NSOpenGLCPSwapInterval];
  207890. return numFrames;
  207891. }
  207892. void repaint()
  207893. {
  207894. // we need to invalidate the juce view that holds this gl view, to make it
  207895. // cause a repaint callback
  207896. NSView* v = (NSView*) viewHolder->view;
  207897. NSRect r = [v frame];
  207898. // bit of a bodge here.. if we only invalidate the area of the gl component,
  207899. // it's completely covered by the NSOpenGLView, so the OS throws away the
  207900. // repaint message, thus never causing our paint() callback, and never repainting
  207901. // the comp. So invalidating just a little bit around the edge helps..
  207902. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  207903. }
  207904. void* getNativeWindowHandle() const { return viewHolder->view; }
  207905. juce_UseDebuggingNewOperator
  207906. NSOpenGLContext* renderContext;
  207907. ThreadSafeNSOpenGLView* view;
  207908. private:
  207909. OpenGLPixelFormat pixelFormat;
  207910. ScopedPointer <NSViewComponentInternal> viewHolder;
  207911. WindowedGLContext (const WindowedGLContext&);
  207912. WindowedGLContext& operator= (const WindowedGLContext&);
  207913. };
  207914. OpenGLContext* OpenGLComponent::createContext()
  207915. {
  207916. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  207917. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  207918. return (c->renderContext != 0) ? c.release() : 0;
  207919. }
  207920. void* OpenGLComponent::getNativeWindowHandle() const
  207921. {
  207922. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  207923. : 0;
  207924. }
  207925. void juce_glViewport (const int w, const int h)
  207926. {
  207927. glViewport (0, 0, w, h);
  207928. }
  207929. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  207930. OwnedArray <OpenGLPixelFormat>& results)
  207931. {
  207932. /* GLint attribs [64];
  207933. int n = 0;
  207934. attribs[n++] = AGL_RGBA;
  207935. attribs[n++] = AGL_DOUBLEBUFFER;
  207936. attribs[n++] = AGL_ACCELERATED;
  207937. attribs[n++] = AGL_NO_RECOVERY;
  207938. attribs[n++] = AGL_NONE;
  207939. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  207940. while (p != 0)
  207941. {
  207942. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  207943. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  207944. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  207945. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  207946. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  207947. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  207948. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  207949. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  207950. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  207951. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  207952. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  207953. results.add (pf);
  207954. p = aglNextPixelFormat (p);
  207955. }*/
  207956. //jassertfalse //xxx can't see how you do this in cocoa!
  207957. }
  207958. #else
  207959. END_JUCE_NAMESPACE
  207960. @interface JuceGLView : UIView
  207961. {
  207962. }
  207963. + (Class) layerClass;
  207964. @end
  207965. @implementation JuceGLView
  207966. + (Class) layerClass
  207967. {
  207968. return [CAEAGLLayer class];
  207969. }
  207970. @end
  207971. BEGIN_JUCE_NAMESPACE
  207972. class GLESContext : public OpenGLContext
  207973. {
  207974. public:
  207975. GLESContext (UIViewComponentPeer* peer,
  207976. Component* const component_,
  207977. const OpenGLPixelFormat& pixelFormat_,
  207978. const GLESContext* const sharedContext,
  207979. NSUInteger apiType)
  207980. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  207981. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  207982. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  207983. {
  207984. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  207985. view.opaque = YES;
  207986. view.hidden = NO;
  207987. view.backgroundColor = [UIColor blackColor];
  207988. view.userInteractionEnabled = NO;
  207989. glLayer = (CAEAGLLayer*) [view layer];
  207990. [peer->view addSubview: view];
  207991. if (sharedContext != 0)
  207992. context = [[EAGLContext alloc] initWithAPI: apiType
  207993. sharegroup: [sharedContext->context sharegroup]];
  207994. else
  207995. context = [[EAGLContext alloc] initWithAPI: apiType];
  207996. createGLBuffers();
  207997. }
  207998. ~GLESContext()
  207999. {
  208000. makeInactive();
  208001. [context release];
  208002. [view removeFromSuperview];
  208003. [view release];
  208004. freeGLBuffers();
  208005. }
  208006. bool makeActive() const throw()
  208007. {
  208008. jassert (context != 0);
  208009. [EAGLContext setCurrentContext: context];
  208010. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208011. return true;
  208012. }
  208013. void swapBuffers()
  208014. {
  208015. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208016. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  208017. }
  208018. bool makeInactive() const throw()
  208019. {
  208020. return [EAGLContext setCurrentContext: nil];
  208021. }
  208022. bool isActive() const throw()
  208023. {
  208024. return [EAGLContext currentContext] == context;
  208025. }
  208026. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208027. void* getRawContext() const throw() { return glLayer; }
  208028. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208029. {
  208030. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  208031. if (lastWidth != w || lastHeight != h)
  208032. {
  208033. lastWidth = w;
  208034. lastHeight = h;
  208035. freeGLBuffers();
  208036. createGLBuffers();
  208037. }
  208038. }
  208039. bool setSwapInterval (const int numFramesPerSwap)
  208040. {
  208041. numFrames = numFramesPerSwap;
  208042. return true;
  208043. }
  208044. int getSwapInterval() const
  208045. {
  208046. return numFrames;
  208047. }
  208048. void repaint()
  208049. {
  208050. }
  208051. void createGLBuffers()
  208052. {
  208053. makeActive();
  208054. glGenFramebuffersOES (1, &frameBufferHandle);
  208055. glGenRenderbuffersOES (1, &colorBufferHandle);
  208056. glGenRenderbuffersOES (1, &depthBufferHandle);
  208057. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208058. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  208059. GLint width, height;
  208060. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  208061. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  208062. if (useDepthBuffer)
  208063. {
  208064. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  208065. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  208066. }
  208067. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208068. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208069. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  208070. if (useDepthBuffer)
  208071. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  208072. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  208073. }
  208074. void freeGLBuffers()
  208075. {
  208076. if (frameBufferHandle != 0)
  208077. {
  208078. glDeleteFramebuffersOES (1, &frameBufferHandle);
  208079. frameBufferHandle = 0;
  208080. }
  208081. if (colorBufferHandle != 0)
  208082. {
  208083. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  208084. colorBufferHandle = 0;
  208085. }
  208086. if (depthBufferHandle != 0)
  208087. {
  208088. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  208089. depthBufferHandle = 0;
  208090. }
  208091. }
  208092. juce_UseDebuggingNewOperator
  208093. private:
  208094. Component::SafePointer<Component> component;
  208095. OpenGLPixelFormat pixelFormat;
  208096. JuceGLView* view;
  208097. CAEAGLLayer* glLayer;
  208098. EAGLContext* context;
  208099. bool useDepthBuffer;
  208100. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  208101. int numFrames;
  208102. int lastWidth, lastHeight;
  208103. GLESContext (const GLESContext&);
  208104. GLESContext& operator= (const GLESContext&);
  208105. };
  208106. OpenGLContext* OpenGLComponent::createContext()
  208107. {
  208108. ScopedAutoReleasePool pool;
  208109. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  208110. if (peer != 0)
  208111. return new GLESContext (peer, this, preferredPixelFormat,
  208112. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  208113. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  208114. return 0;
  208115. }
  208116. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208117. OwnedArray <OpenGLPixelFormat>& /*results*/)
  208118. {
  208119. }
  208120. void juce_glViewport (const int w, const int h)
  208121. {
  208122. glViewport (0, 0, w, h);
  208123. }
  208124. #endif
  208125. #endif
  208126. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208127. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208128. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208129. // compiled on its own).
  208130. #if JUCE_INCLUDED_FILE
  208131. class JuceMainMenuHandler;
  208132. END_JUCE_NAMESPACE
  208133. using namespace JUCE_NAMESPACE;
  208134. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208135. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208136. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208137. #else
  208138. @interface JuceMenuCallback : NSObject
  208139. #endif
  208140. {
  208141. JuceMainMenuHandler* owner;
  208142. }
  208143. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208144. - (void) dealloc;
  208145. - (void) menuItemInvoked: (id) menu;
  208146. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208147. @end
  208148. BEGIN_JUCE_NAMESPACE
  208149. class JuceMainMenuHandler : private MenuBarModelListener,
  208150. private DeletedAtShutdown
  208151. {
  208152. public:
  208153. static JuceMainMenuHandler* instance;
  208154. JuceMainMenuHandler()
  208155. : currentModel (0),
  208156. lastUpdateTime (0)
  208157. {
  208158. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208159. }
  208160. ~JuceMainMenuHandler()
  208161. {
  208162. setMenu (0);
  208163. jassert (instance == this);
  208164. instance = 0;
  208165. [callback release];
  208166. }
  208167. void setMenu (MenuBarModel* const newMenuBarModel)
  208168. {
  208169. if (currentModel != newMenuBarModel)
  208170. {
  208171. if (currentModel != 0)
  208172. currentModel->removeListener (this);
  208173. currentModel = newMenuBarModel;
  208174. if (currentModel != 0)
  208175. currentModel->addListener (this);
  208176. menuBarItemsChanged (0);
  208177. }
  208178. }
  208179. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208180. const String& name, const int menuId, const int tag)
  208181. {
  208182. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208183. action: nil
  208184. keyEquivalent: @""];
  208185. [item setTag: tag];
  208186. NSMenu* sub = createMenu (child, name, menuId, tag);
  208187. [parent setSubmenu: sub forItem: item];
  208188. [sub setAutoenablesItems: false];
  208189. [sub release];
  208190. }
  208191. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208192. const String& name, const int menuId, const int tag)
  208193. {
  208194. [parentItem setTag: tag];
  208195. NSMenu* menu = [parentItem submenu];
  208196. [menu setTitle: juceStringToNS (name)];
  208197. while ([menu numberOfItems] > 0)
  208198. [menu removeItemAtIndex: 0];
  208199. PopupMenu::MenuItemIterator iter (menuToCopy);
  208200. while (iter.next())
  208201. addMenuItem (iter, menu, menuId, tag);
  208202. [menu setAutoenablesItems: false];
  208203. [menu update];
  208204. }
  208205. void menuBarItemsChanged (MenuBarModel*)
  208206. {
  208207. lastUpdateTime = Time::getMillisecondCounter();
  208208. StringArray menuNames;
  208209. if (currentModel != 0)
  208210. menuNames = currentModel->getMenuBarNames();
  208211. NSMenu* menuBar = [NSApp mainMenu];
  208212. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208213. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208214. int menuId = 1;
  208215. for (int i = 0; i < menuNames.size(); ++i)
  208216. {
  208217. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208218. if (i >= [menuBar numberOfItems] - 1)
  208219. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208220. else
  208221. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208222. }
  208223. }
  208224. static void flashMenuBar (NSMenu* menu)
  208225. {
  208226. if ([[menu title] isEqualToString: @"Apple"])
  208227. return;
  208228. [menu retain];
  208229. const unichar f35Key = NSF35FunctionKey;
  208230. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208231. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208232. action: nil
  208233. keyEquivalent: f35String];
  208234. [item setTarget: nil];
  208235. [menu insertItem: item atIndex: [menu numberOfItems]];
  208236. [item release];
  208237. if ([menu indexOfItem: item] >= 0)
  208238. {
  208239. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208240. location: NSZeroPoint
  208241. modifierFlags: NSCommandKeyMask
  208242. timestamp: 0
  208243. windowNumber: 0
  208244. context: [NSGraphicsContext currentContext]
  208245. characters: f35String
  208246. charactersIgnoringModifiers: f35String
  208247. isARepeat: NO
  208248. keyCode: 0];
  208249. [menu performKeyEquivalent: f35Event];
  208250. if ([menu indexOfItem: item] >= 0)
  208251. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208252. }
  208253. [menu release];
  208254. }
  208255. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208256. {
  208257. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208258. {
  208259. NSMenuItem* m = [menu itemAtIndex: i];
  208260. if ([m tag] == info.commandID)
  208261. return m;
  208262. if ([m submenu] != 0)
  208263. {
  208264. NSMenuItem* found = findMenuItem ([m submenu], info);
  208265. if (found != 0)
  208266. return found;
  208267. }
  208268. }
  208269. return 0;
  208270. }
  208271. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208272. {
  208273. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208274. if (item != 0)
  208275. flashMenuBar ([item menu]);
  208276. }
  208277. void updateMenus()
  208278. {
  208279. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208280. menuBarItemsChanged (0);
  208281. }
  208282. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208283. {
  208284. if (currentModel != 0)
  208285. {
  208286. if (commandManager != 0)
  208287. {
  208288. ApplicationCommandTarget::InvocationInfo info (commandId);
  208289. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208290. commandManager->invoke (info, true);
  208291. }
  208292. currentModel->menuItemSelected (commandId, topLevelIndex);
  208293. }
  208294. }
  208295. MenuBarModel* currentModel;
  208296. uint32 lastUpdateTime;
  208297. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208298. const int topLevelMenuId, const int topLevelIndex)
  208299. {
  208300. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf ("<end>", false, true));
  208301. if (text == 0)
  208302. text = @"";
  208303. if (iter.isSeparator)
  208304. {
  208305. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208306. }
  208307. else if (iter.isSectionHeader)
  208308. {
  208309. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208310. action: nil
  208311. keyEquivalent: @""];
  208312. [item setEnabled: false];
  208313. }
  208314. else if (iter.subMenu != 0)
  208315. {
  208316. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208317. action: nil
  208318. keyEquivalent: @""];
  208319. [item setTag: iter.itemId];
  208320. [item setEnabled: iter.isEnabled];
  208321. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208322. [sub setDelegate: nil];
  208323. [menuToAddTo setSubmenu: sub forItem: item];
  208324. [sub release];
  208325. }
  208326. else
  208327. {
  208328. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208329. action: @selector (menuItemInvoked:)
  208330. keyEquivalent: @""];
  208331. [item setTag: iter.itemId];
  208332. [item setEnabled: iter.isEnabled];
  208333. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208334. [item setTarget: (id) callback];
  208335. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208336. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208337. [item setRepresentedObject: info];
  208338. if (iter.commandManager != 0)
  208339. {
  208340. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208341. ->getKeyPressesAssignedToCommand (iter.itemId));
  208342. if (keyPresses.size() > 0)
  208343. {
  208344. const KeyPress& kp = keyPresses.getReference(0);
  208345. juce_wchar key = kp.getTextCharacter();
  208346. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208347. key = NSBackspaceCharacter;
  208348. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208349. key = NSDeleteCharacter;
  208350. else if (key == 0)
  208351. key = (juce_wchar) kp.getKeyCode();
  208352. unsigned int mods = 0;
  208353. if (kp.getModifiers().isShiftDown())
  208354. mods |= NSShiftKeyMask;
  208355. if (kp.getModifiers().isCtrlDown())
  208356. mods |= NSControlKeyMask;
  208357. if (kp.getModifiers().isAltDown())
  208358. mods |= NSAlternateKeyMask;
  208359. if (kp.getModifiers().isCommandDown())
  208360. mods |= NSCommandKeyMask;
  208361. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208362. [item setKeyEquivalentModifierMask: mods];
  208363. }
  208364. }
  208365. }
  208366. }
  208367. JuceMenuCallback* callback;
  208368. private:
  208369. NSMenu* createMenu (const PopupMenu menu,
  208370. const String& menuName,
  208371. const int topLevelMenuId,
  208372. const int topLevelIndex)
  208373. {
  208374. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208375. [m setAutoenablesItems: false];
  208376. [m setDelegate: callback];
  208377. PopupMenu::MenuItemIterator iter (menu);
  208378. while (iter.next())
  208379. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208380. [m update];
  208381. return m;
  208382. }
  208383. };
  208384. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208385. END_JUCE_NAMESPACE
  208386. @implementation JuceMenuCallback
  208387. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208388. {
  208389. [super init];
  208390. owner = owner_;
  208391. return self;
  208392. }
  208393. - (void) dealloc
  208394. {
  208395. [super dealloc];
  208396. }
  208397. - (void) menuItemInvoked: (id) menu
  208398. {
  208399. NSMenuItem* item = (NSMenuItem*) menu;
  208400. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208401. {
  208402. // If the menu is being triggered by a keypress, the OS will have picked it up before we had a chance to offer it to
  208403. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208404. // into the focused component and let it trigger the menu item indirectly.
  208405. NSEvent* e = [NSApp currentEvent];
  208406. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208407. {
  208408. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208409. {
  208410. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208411. if (peer != 0)
  208412. {
  208413. if ([e type] == NSKeyDown)
  208414. peer->redirectKeyDown (e);
  208415. else
  208416. peer->redirectKeyUp (e);
  208417. return;
  208418. }
  208419. }
  208420. }
  208421. NSArray* info = (NSArray*) [item representedObject];
  208422. owner->invoke ((int) [item tag],
  208423. (ApplicationCommandManager*) (pointer_sized_int)
  208424. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208425. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208426. }
  208427. }
  208428. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208429. {
  208430. if (JuceMainMenuHandler::instance != 0)
  208431. JuceMainMenuHandler::instance->updateMenus();
  208432. }
  208433. @end
  208434. BEGIN_JUCE_NAMESPACE
  208435. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208436. const PopupMenu* extraItems)
  208437. {
  208438. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208439. {
  208440. PopupMenu::MenuItemIterator iter (*extraItems);
  208441. while (iter.next())
  208442. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208443. [menu addItem: [NSMenuItem separatorItem]];
  208444. }
  208445. NSMenuItem* item;
  208446. // Services...
  208447. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208448. action: nil keyEquivalent: @""];
  208449. [menu addItem: item];
  208450. [item release];
  208451. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208452. [menu setSubmenu: servicesMenu forItem: item];
  208453. [NSApp setServicesMenu: servicesMenu];
  208454. [servicesMenu release];
  208455. [menu addItem: [NSMenuItem separatorItem]];
  208456. // Hide + Show stuff...
  208457. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208458. action: @selector (hide:) keyEquivalent: @"h"];
  208459. [item setTarget: NSApp];
  208460. [menu addItem: item];
  208461. [item release];
  208462. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208463. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208464. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208465. [item setTarget: NSApp];
  208466. [menu addItem: item];
  208467. [item release];
  208468. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208469. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208470. [item setTarget: NSApp];
  208471. [menu addItem: item];
  208472. [item release];
  208473. [menu addItem: [NSMenuItem separatorItem]];
  208474. // Quit item....
  208475. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208476. action: @selector (terminate:) keyEquivalent: @"q"];
  208477. [item setTarget: NSApp];
  208478. [menu addItem: item];
  208479. [item release];
  208480. return menu;
  208481. }
  208482. // Since our app has no NIB, this initialises a standard app menu...
  208483. static void rebuildMainMenu (const PopupMenu* extraItems)
  208484. {
  208485. // this can't be used in a plugin!
  208486. jassert (JUCEApplication::getInstance() != 0);
  208487. if (JUCEApplication::getInstance() != 0)
  208488. {
  208489. const ScopedAutoReleasePool pool;
  208490. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208491. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208492. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208493. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208494. [mainMenu setSubmenu: appMenu forItem: item];
  208495. [NSApp setMainMenu: mainMenu];
  208496. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208497. [appMenu release];
  208498. [mainMenu release];
  208499. }
  208500. }
  208501. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208502. const PopupMenu* extraAppleMenuItems)
  208503. {
  208504. if (getMacMainMenu() != newMenuBarModel)
  208505. {
  208506. const ScopedAutoReleasePool pool;
  208507. if (newMenuBarModel == 0)
  208508. {
  208509. delete JuceMainMenuHandler::instance;
  208510. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208511. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208512. extraAppleMenuItems = 0;
  208513. }
  208514. else
  208515. {
  208516. if (JuceMainMenuHandler::instance == 0)
  208517. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208518. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208519. }
  208520. }
  208521. rebuildMainMenu (extraAppleMenuItems);
  208522. if (newMenuBarModel != 0)
  208523. newMenuBarModel->menuItemsChanged();
  208524. }
  208525. MenuBarModel* MenuBarModel::getMacMainMenu()
  208526. {
  208527. return JuceMainMenuHandler::instance != 0
  208528. ? JuceMainMenuHandler::instance->currentModel : 0;
  208529. }
  208530. void initialiseMainMenu()
  208531. {
  208532. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208533. rebuildMainMenu (0);
  208534. }
  208535. #endif
  208536. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208537. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208538. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208539. // compiled on its own).
  208540. #if JUCE_INCLUDED_FILE
  208541. #if JUCE_MAC
  208542. END_JUCE_NAMESPACE
  208543. using namespace JUCE_NAMESPACE;
  208544. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208545. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208546. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208547. #else
  208548. @interface JuceFileChooserDelegate : NSObject
  208549. #endif
  208550. {
  208551. StringArray* filters;
  208552. }
  208553. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208554. - (void) dealloc;
  208555. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208556. @end
  208557. @implementation JuceFileChooserDelegate
  208558. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208559. {
  208560. [super init];
  208561. filters = filters_;
  208562. return self;
  208563. }
  208564. - (void) dealloc
  208565. {
  208566. delete filters;
  208567. [super dealloc];
  208568. }
  208569. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208570. {
  208571. const File f (nsStringToJuce (filename));
  208572. for (int i = filters->size(); --i >= 0;)
  208573. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208574. return true;
  208575. return f.isDirectory();
  208576. }
  208577. @end
  208578. BEGIN_JUCE_NAMESPACE
  208579. void FileChooser::showPlatformDialog (Array<File>& results,
  208580. const String& title,
  208581. const File& currentFileOrDirectory,
  208582. const String& filter,
  208583. bool selectsDirectory,
  208584. bool selectsFiles,
  208585. bool isSaveDialogue,
  208586. bool warnAboutOverwritingExistingFiles,
  208587. bool selectMultipleFiles,
  208588. FilePreviewComponent* extraInfoComponent)
  208589. {
  208590. const ScopedAutoReleasePool pool;
  208591. StringArray* filters = new StringArray();
  208592. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  208593. filters->trim();
  208594. filters->removeEmptyStrings();
  208595. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208596. [delegate autorelease];
  208597. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208598. : [NSOpenPanel openPanel];
  208599. [panel setTitle: juceStringToNS (title)];
  208600. if (! isSaveDialogue)
  208601. {
  208602. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208603. [openPanel setCanChooseDirectories: selectsDirectory];
  208604. [openPanel setCanChooseFiles: selectsFiles];
  208605. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208606. }
  208607. [panel setDelegate: delegate];
  208608. if (isSaveDialogue || selectsDirectory)
  208609. [panel setCanCreateDirectories: YES];
  208610. String directory, filename;
  208611. if (currentFileOrDirectory.isDirectory())
  208612. {
  208613. directory = currentFileOrDirectory.getFullPathName();
  208614. }
  208615. else
  208616. {
  208617. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208618. filename = currentFileOrDirectory.getFileName();
  208619. }
  208620. if ([panel runModalForDirectory: juceStringToNS (directory)
  208621. file: juceStringToNS (filename)]
  208622. == NSOKButton)
  208623. {
  208624. if (isSaveDialogue)
  208625. {
  208626. results.add (File (nsStringToJuce ([panel filename])));
  208627. }
  208628. else
  208629. {
  208630. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208631. NSArray* urls = [openPanel filenames];
  208632. for (unsigned int i = 0; i < [urls count]; ++i)
  208633. {
  208634. NSString* f = [urls objectAtIndex: i];
  208635. results.add (File (nsStringToJuce (f)));
  208636. }
  208637. }
  208638. }
  208639. [panel setDelegate: nil];
  208640. }
  208641. #else
  208642. void FileChooser::showPlatformDialog (Array<File>& results,
  208643. const String& title,
  208644. const File& currentFileOrDirectory,
  208645. const String& filter,
  208646. bool selectsDirectory,
  208647. bool selectsFiles,
  208648. bool isSaveDialogue,
  208649. bool warnAboutOverwritingExistingFiles,
  208650. bool selectMultipleFiles,
  208651. FilePreviewComponent* extraInfoComponent)
  208652. {
  208653. const ScopedAutoReleasePool pool;
  208654. jassertfalse //xxx to do
  208655. }
  208656. #endif
  208657. #endif
  208658. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  208659. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  208660. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208661. // compiled on its own).
  208662. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  208663. END_JUCE_NAMESPACE
  208664. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  208665. @interface NonInterceptingQTMovieView : QTMovieView
  208666. {
  208667. }
  208668. - (id) initWithFrame: (NSRect) frame;
  208669. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  208670. - (NSView*) hitTest: (NSPoint) p;
  208671. @end
  208672. @implementation NonInterceptingQTMovieView
  208673. - (id) initWithFrame: (NSRect) frame
  208674. {
  208675. self = [super initWithFrame: frame];
  208676. [self setNextResponder: [self superview]];
  208677. return self;
  208678. }
  208679. - (void) dealloc
  208680. {
  208681. [super dealloc];
  208682. }
  208683. - (NSView*) hitTest: (NSPoint) point
  208684. {
  208685. return [self isControllerVisible] ? [super hitTest: point] : nil;
  208686. }
  208687. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  208688. {
  208689. return YES;
  208690. }
  208691. @end
  208692. BEGIN_JUCE_NAMESPACE
  208693. #define theMovie (static_cast <QTMovie*> (movie))
  208694. QuickTimeMovieComponent::QuickTimeMovieComponent()
  208695. : movie (0)
  208696. {
  208697. setOpaque (true);
  208698. setVisible (true);
  208699. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  208700. setView (view);
  208701. [view release];
  208702. }
  208703. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  208704. {
  208705. closeMovie();
  208706. setView (0);
  208707. }
  208708. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  208709. {
  208710. return true;
  208711. }
  208712. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  208713. {
  208714. // unfortunately, QTMovie objects can only be created on the main thread..
  208715. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208716. QTMovie* movie = 0;
  208717. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  208718. if (fin != 0)
  208719. {
  208720. movieFile = fin->getFile();
  208721. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  208722. error: nil];
  208723. }
  208724. else
  208725. {
  208726. MemoryBlock temp;
  208727. movieStream->readIntoMemoryBlock (temp);
  208728. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  208729. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  208730. {
  208731. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  208732. length: temp.getSize()]
  208733. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  208734. MIMEType: @""]
  208735. error: nil];
  208736. if (movie != 0)
  208737. break;
  208738. }
  208739. }
  208740. return movie;
  208741. }
  208742. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  208743. const bool isControllerVisible_)
  208744. {
  208745. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  208746. }
  208747. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  208748. const bool controllerVisible_)
  208749. {
  208750. closeMovie();
  208751. if (getPeer() == 0)
  208752. {
  208753. // To open a movie, this component must be visible inside a functioning window, so that
  208754. // the QT control can be assigned to the window.
  208755. jassertfalse
  208756. return false;
  208757. }
  208758. movie = openMovieFromStream (movieStream, movieFile);
  208759. [theMovie retain];
  208760. QTMovieView* view = (QTMovieView*) getView();
  208761. [view setMovie: theMovie];
  208762. [view setControllerVisible: controllerVisible_];
  208763. setLooping (looping);
  208764. return movie != nil;
  208765. }
  208766. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  208767. const bool isControllerVisible_)
  208768. {
  208769. // unfortunately, QTMovie objects can only be created on the main thread..
  208770. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208771. closeMovie();
  208772. if (getPeer() == 0)
  208773. {
  208774. // To open a movie, this component must be visible inside a functioning window, so that
  208775. // the QT control can be assigned to the window.
  208776. jassertfalse
  208777. return false;
  208778. }
  208779. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  208780. NSError* err;
  208781. if ([QTMovie canInitWithURL: url])
  208782. movie = [QTMovie movieWithURL: url error: &err];
  208783. [theMovie retain];
  208784. QTMovieView* view = (QTMovieView*) getView();
  208785. [view setMovie: theMovie];
  208786. [view setControllerVisible: controllerVisible];
  208787. setLooping (looping);
  208788. return movie != nil;
  208789. }
  208790. void QuickTimeMovieComponent::closeMovie()
  208791. {
  208792. stop();
  208793. QTMovieView* view = (QTMovieView*) getView();
  208794. [view setMovie: nil];
  208795. [theMovie release];
  208796. movie = 0;
  208797. movieFile = File::nonexistent;
  208798. }
  208799. bool QuickTimeMovieComponent::isMovieOpen() const
  208800. {
  208801. return movie != nil;
  208802. }
  208803. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  208804. {
  208805. return movieFile;
  208806. }
  208807. void QuickTimeMovieComponent::play()
  208808. {
  208809. [theMovie play];
  208810. }
  208811. void QuickTimeMovieComponent::stop()
  208812. {
  208813. [theMovie stop];
  208814. }
  208815. bool QuickTimeMovieComponent::isPlaying() const
  208816. {
  208817. return movie != 0 && [theMovie rate] != 0;
  208818. }
  208819. void QuickTimeMovieComponent::setPosition (const double seconds)
  208820. {
  208821. if (movie != 0)
  208822. {
  208823. QTTime t;
  208824. t.timeValue = (uint64) (100000.0 * seconds);
  208825. t.timeScale = 100000;
  208826. t.flags = 0;
  208827. [theMovie setCurrentTime: t];
  208828. }
  208829. }
  208830. double QuickTimeMovieComponent::getPosition() const
  208831. {
  208832. if (movie == 0)
  208833. return 0.0;
  208834. QTTime t = [theMovie currentTime];
  208835. return t.timeValue / (double) t.timeScale;
  208836. }
  208837. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  208838. {
  208839. [theMovie setRate: newSpeed];
  208840. }
  208841. double QuickTimeMovieComponent::getMovieDuration() const
  208842. {
  208843. if (movie == 0)
  208844. return 0.0;
  208845. QTTime t = [theMovie duration];
  208846. return t.timeValue / (double) t.timeScale;
  208847. }
  208848. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  208849. {
  208850. looping = shouldLoop;
  208851. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  208852. forKey: QTMovieLoopsAttribute];
  208853. }
  208854. bool QuickTimeMovieComponent::isLooping() const
  208855. {
  208856. return looping;
  208857. }
  208858. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  208859. {
  208860. [theMovie setVolume: newVolume];
  208861. }
  208862. float QuickTimeMovieComponent::getMovieVolume() const
  208863. {
  208864. return movie != 0 ? [theMovie volume] : 0.0f;
  208865. }
  208866. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  208867. {
  208868. width = 0;
  208869. height = 0;
  208870. if (movie != 0)
  208871. {
  208872. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  208873. width = (int) s.width;
  208874. height = (int) s.height;
  208875. }
  208876. }
  208877. void QuickTimeMovieComponent::paint (Graphics& g)
  208878. {
  208879. if (movie == 0)
  208880. g.fillAll (Colours::black);
  208881. }
  208882. bool QuickTimeMovieComponent::isControllerVisible() const
  208883. {
  208884. return controllerVisible;
  208885. }
  208886. void QuickTimeMovieComponent::goToStart()
  208887. {
  208888. setPosition (0.0);
  208889. }
  208890. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  208891. const RectanglePlacement& placement)
  208892. {
  208893. int normalWidth, normalHeight;
  208894. getMovieNormalSize (normalWidth, normalHeight);
  208895. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  208896. {
  208897. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  208898. placement.applyTo (x, y, w, h,
  208899. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  208900. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  208901. if (w > 0 && h > 0)
  208902. {
  208903. setBounds (roundToInt (x), roundToInt (y),
  208904. roundToInt (w), roundToInt (h));
  208905. }
  208906. }
  208907. else
  208908. {
  208909. setBounds (spaceToFitWithin);
  208910. }
  208911. }
  208912. #if ! (JUCE_MAC && JUCE_64BIT)
  208913. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  208914. {
  208915. if (movieStream == 0)
  208916. return false;
  208917. File file;
  208918. QTMovie* movie = openMovieFromStream (movieStream, file);
  208919. if (movie != nil)
  208920. result = [movie quickTimeMovie];
  208921. return movie != nil;
  208922. }
  208923. #endif
  208924. #endif
  208925. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  208926. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  208927. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208928. // compiled on its own).
  208929. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  208930. const int kilobytesPerSecond1x = 176;
  208931. END_JUCE_NAMESPACE
  208932. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  208933. @interface OpenDiskDevice : NSObject
  208934. {
  208935. @public
  208936. DRDevice* device;
  208937. NSMutableArray* tracks;
  208938. bool underrunProtection;
  208939. }
  208940. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  208941. - (void) dealloc;
  208942. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  208943. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  208944. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  208945. @end
  208946. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  208947. @interface AudioTrackProducer : NSObject
  208948. {
  208949. JUCE_NAMESPACE::AudioSource* source;
  208950. int readPosition, lengthInFrames;
  208951. }
  208952. - (AudioTrackProducer*) init: (int) lengthInFrames;
  208953. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  208954. - (void) dealloc;
  208955. - (void) setupTrackProperties: (DRTrack*) track;
  208956. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  208957. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  208958. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  208959. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  208960. toMedia:(NSDictionary*)mediaInfo;
  208961. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  208962. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  208963. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  208964. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  208965. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  208966. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  208967. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  208968. ioFlags:(uint32_t*)flags;
  208969. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  208970. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  208971. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  208972. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  208973. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  208974. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  208975. ioFlags:(uint32_t*)flags;
  208976. @end
  208977. @implementation OpenDiskDevice
  208978. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  208979. {
  208980. [super init];
  208981. device = device_;
  208982. tracks = [[NSMutableArray alloc] init];
  208983. underrunProtection = true;
  208984. return self;
  208985. }
  208986. - (void) dealloc
  208987. {
  208988. [tracks release];
  208989. [super dealloc];
  208990. }
  208991. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  208992. {
  208993. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  208994. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  208995. [p setupTrackProperties: t];
  208996. [tracks addObject: t];
  208997. [t release];
  208998. [p release];
  208999. }
  209000. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209001. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209002. {
  209003. DRBurn* burn = [DRBurn burnForDevice: device];
  209004. if (! [device acquireExclusiveAccess])
  209005. {
  209006. *error = "Couldn't open or write to the CD device";
  209007. return;
  209008. }
  209009. [device acquireMediaReservation];
  209010. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209011. [d autorelease];
  209012. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209013. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209014. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209015. if (burnSpeed > 0)
  209016. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209017. if (! underrunProtection)
  209018. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209019. [burn setProperties: d];
  209020. [burn writeLayout: tracks];
  209021. for (;;)
  209022. {
  209023. JUCE_NAMESPACE::Thread::sleep (300);
  209024. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209025. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209026. {
  209027. [burn abort];
  209028. *error = "User cancelled the write operation";
  209029. break;
  209030. }
  209031. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209032. {
  209033. *error = "Write operation failed";
  209034. break;
  209035. }
  209036. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209037. {
  209038. break;
  209039. }
  209040. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209041. objectForKey: DRErrorStatusErrorStringKey];
  209042. if ([err length] > 0)
  209043. {
  209044. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209045. break;
  209046. }
  209047. }
  209048. [device releaseMediaReservation];
  209049. [device releaseExclusiveAccess];
  209050. }
  209051. @end
  209052. @implementation AudioTrackProducer
  209053. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209054. {
  209055. lengthInFrames = lengthInFrames_;
  209056. readPosition = 0;
  209057. return self;
  209058. }
  209059. - (void) setupTrackProperties: (DRTrack*) track
  209060. {
  209061. NSMutableDictionary* p = [[track properties] mutableCopy];
  209062. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209063. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209064. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209065. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209066. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209067. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209068. [track setProperties: p];
  209069. [p release];
  209070. }
  209071. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209072. {
  209073. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209074. if (s != nil)
  209075. s->source = source_;
  209076. return s;
  209077. }
  209078. - (void) dealloc
  209079. {
  209080. if (source != 0)
  209081. {
  209082. source->releaseResources();
  209083. delete source;
  209084. }
  209085. [super dealloc];
  209086. }
  209087. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209088. {
  209089. }
  209090. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209091. {
  209092. return true;
  209093. }
  209094. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209095. {
  209096. return lengthInFrames;
  209097. }
  209098. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209099. toMedia: (NSDictionary*) mediaInfo
  209100. {
  209101. if (source != 0)
  209102. source->prepareToPlay (44100 / 75, 44100);
  209103. readPosition = 0;
  209104. return true;
  209105. }
  209106. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209107. {
  209108. if (source != 0)
  209109. source->prepareToPlay (44100 / 75, 44100);
  209110. return true;
  209111. }
  209112. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209113. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209114. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209115. {
  209116. if (source != 0)
  209117. {
  209118. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209119. if (numSamples > 0)
  209120. {
  209121. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209122. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209123. info.buffer = &tempBuffer;
  209124. info.startSample = 0;
  209125. info.numSamples = numSamples;
  209126. source->getNextAudioBlock (info);
  209127. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209128. buffer, numSamples, 4);
  209129. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209130. buffer + 2, numSamples, 4);
  209131. readPosition += numSamples;
  209132. }
  209133. return numSamples * 4;
  209134. }
  209135. return 0;
  209136. }
  209137. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209138. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209139. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209140. ioFlags: (uint32_t*) flags
  209141. {
  209142. zeromem (buffer, bufferLength);
  209143. return bufferLength;
  209144. }
  209145. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209146. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209147. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209148. {
  209149. return true;
  209150. }
  209151. @end
  209152. BEGIN_JUCE_NAMESPACE
  209153. class AudioCDBurner::Pimpl : public Timer
  209154. {
  209155. public:
  209156. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209157. : device (0), owner (owner_)
  209158. {
  209159. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209160. if (dev != 0)
  209161. {
  209162. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209163. lastState = getDiskState();
  209164. startTimer (1000);
  209165. }
  209166. }
  209167. ~Pimpl()
  209168. {
  209169. stopTimer();
  209170. [device release];
  209171. }
  209172. void timerCallback()
  209173. {
  209174. const DiskState state = getDiskState();
  209175. if (state != lastState)
  209176. {
  209177. lastState = state;
  209178. owner.sendChangeMessage (&owner);
  209179. }
  209180. }
  209181. DiskState getDiskState() const
  209182. {
  209183. if ([device->device isValid])
  209184. {
  209185. NSDictionary* status = [device->device status];
  209186. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209187. if ([state isEqualTo: DRDeviceMediaStateNone])
  209188. {
  209189. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209190. return trayOpen;
  209191. return noDisc;
  209192. }
  209193. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209194. {
  209195. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209196. return writableDiskPresent;
  209197. else
  209198. return readOnlyDiskPresent;
  209199. }
  209200. }
  209201. return unknown;
  209202. }
  209203. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209204. const Array<int> getAvailableWriteSpeeds() const
  209205. {
  209206. Array<int> results;
  209207. if ([device->device isValid])
  209208. {
  209209. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209210. for (unsigned int i = 0; i < [speeds count]; ++i)
  209211. {
  209212. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209213. results.add (kbPerSec / kilobytesPerSecond1x);
  209214. }
  209215. }
  209216. return results;
  209217. }
  209218. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209219. {
  209220. if ([device->device isValid])
  209221. {
  209222. device->underrunProtection = shouldBeEnabled;
  209223. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209224. }
  209225. return false;
  209226. }
  209227. int getNumAvailableAudioBlocks() const
  209228. {
  209229. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209230. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209231. }
  209232. OpenDiskDevice* device;
  209233. private:
  209234. DiskState lastState;
  209235. AudioCDBurner& owner;
  209236. };
  209237. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209238. {
  209239. pimpl = new Pimpl (*this, deviceIndex);
  209240. }
  209241. AudioCDBurner::~AudioCDBurner()
  209242. {
  209243. }
  209244. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209245. {
  209246. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209247. if (b->pimpl->device == 0)
  209248. b = 0;
  209249. return b.release();
  209250. }
  209251. static NSArray* findDiskBurnerDevices()
  209252. {
  209253. NSMutableArray* results = [NSMutableArray array];
  209254. NSArray* devs = [DRDevice devices];
  209255. if (devs != 0)
  209256. {
  209257. int num = [devs count];
  209258. int i;
  209259. for (i = 0; i < num; ++i)
  209260. {
  209261. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209262. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209263. if (name != nil)
  209264. [results addObject: name];
  209265. }
  209266. }
  209267. return results;
  209268. }
  209269. const StringArray AudioCDBurner::findAvailableDevices()
  209270. {
  209271. NSArray* names = findDiskBurnerDevices();
  209272. StringArray s;
  209273. for (unsigned int i = 0; i < [names count]; ++i)
  209274. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209275. return s;
  209276. }
  209277. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209278. {
  209279. return pimpl->getDiskState();
  209280. }
  209281. bool AudioCDBurner::isDiskPresent() const
  209282. {
  209283. return getDiskState() == writableDiskPresent;
  209284. }
  209285. bool AudioCDBurner::openTray()
  209286. {
  209287. return pimpl->openTray();
  209288. }
  209289. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209290. {
  209291. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209292. DiskState oldState = getDiskState();
  209293. DiskState newState = oldState;
  209294. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209295. {
  209296. newState = getDiskState();
  209297. Thread::sleep (100);
  209298. }
  209299. return newState;
  209300. }
  209301. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209302. {
  209303. return pimpl->getAvailableWriteSpeeds();
  209304. }
  209305. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209306. {
  209307. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209308. }
  209309. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209310. {
  209311. return pimpl->getNumAvailableAudioBlocks();
  209312. }
  209313. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209314. {
  209315. if ([pimpl->device->device isValid])
  209316. {
  209317. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209318. return true;
  209319. }
  209320. return false;
  209321. }
  209322. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209323. bool ejectDiscAfterwards,
  209324. bool performFakeBurnForTesting,
  209325. int writeSpeed)
  209326. {
  209327. String error ("Couldn't open or write to the CD device");
  209328. if ([pimpl->device->device isValid])
  209329. {
  209330. error = String::empty;
  209331. [pimpl->device burn: listener
  209332. errorString: &error
  209333. ejectAfterwards: ejectDiscAfterwards
  209334. isFake: performFakeBurnForTesting
  209335. speed: writeSpeed];
  209336. }
  209337. return error;
  209338. }
  209339. #endif
  209340. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209341. void AudioCDReader::ejectDisk()
  209342. {
  209343. const ScopedAutoReleasePool p;
  209344. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209345. }
  209346. #endif
  209347. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209348. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209349. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209350. // compiled on its own).
  209351. #if JUCE_INCLUDED_FILE
  209352. class AppDelegateRedirector
  209353. {
  209354. public:
  209355. AppDelegateRedirector()
  209356. {
  209357. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209358. runLoop = CFRunLoopGetMain();
  209359. #else
  209360. runLoop = CFRunLoopGetCurrent();
  209361. #endif
  209362. CFRunLoopSourceContext sourceContext;
  209363. zerostruct (sourceContext);
  209364. sourceContext.info = this;
  209365. sourceContext.perform = runLoopSourceCallback;
  209366. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209367. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209368. }
  209369. virtual ~AppDelegateRedirector()
  209370. {
  209371. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209372. CFRunLoopSourceInvalidate (runLoopSource);
  209373. CFRelease (runLoopSource);
  209374. while (messages.size() > 0)
  209375. delete static_cast <Message*> (messages.remove(0));
  209376. }
  209377. virtual NSApplicationTerminateReply shouldTerminate()
  209378. {
  209379. if (JUCEApplication::getInstance() != 0)
  209380. {
  209381. JUCEApplication::getInstance()->systemRequestedQuit();
  209382. return NSTerminateCancel;
  209383. }
  209384. return NSTerminateNow;
  209385. }
  209386. virtual BOOL openFile (const NSString* filename)
  209387. {
  209388. if (JUCEApplication::getInstance() != 0)
  209389. {
  209390. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209391. return YES;
  209392. }
  209393. return NO;
  209394. }
  209395. virtual void openFiles (NSArray* filenames)
  209396. {
  209397. StringArray files;
  209398. for (unsigned int i = 0; i < [filenames count]; ++i)
  209399. {
  209400. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209401. if (filename.containsChar (' '))
  209402. filename = filename.quoted('"');
  209403. files.add (filename);
  209404. }
  209405. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209406. {
  209407. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (" "));
  209408. }
  209409. }
  209410. virtual void focusChanged()
  209411. {
  209412. juce_HandleProcessFocusChange();
  209413. }
  209414. struct CallbackMessagePayload
  209415. {
  209416. MessageCallbackFunction* function;
  209417. void* parameter;
  209418. void* volatile result;
  209419. bool volatile hasBeenExecuted;
  209420. };
  209421. virtual void performCallback (CallbackMessagePayload* pl)
  209422. {
  209423. pl->result = (*pl->function) (pl->parameter);
  209424. pl->hasBeenExecuted = true;
  209425. }
  209426. virtual void deleteSelf()
  209427. {
  209428. delete this;
  209429. }
  209430. void postMessage (void* m)
  209431. {
  209432. messages.add (m);
  209433. CFRunLoopSourceSignal (runLoopSource);
  209434. CFRunLoopWakeUp (runLoop);
  209435. }
  209436. private:
  209437. CFRunLoopRef runLoop;
  209438. CFRunLoopSourceRef runLoopSource;
  209439. Array <void*, CriticalSection> messages;
  209440. void runLoopCallback()
  209441. {
  209442. int numDispatched = 0;
  209443. do
  209444. {
  209445. void* const nextMessage = messages.remove (0);
  209446. if (nextMessage == 0)
  209447. return;
  209448. const ScopedAutoReleasePool pool;
  209449. MessageManager::getInstance()->deliverMessage (nextMessage);
  209450. } while (++numDispatched <= 4);
  209451. CFRunLoopSourceSignal (runLoopSource);
  209452. CFRunLoopWakeUp (runLoop);
  209453. }
  209454. static void runLoopSourceCallback (void* info)
  209455. {
  209456. static_cast <AppDelegateRedirector*> (info)->runLoopCallback();
  209457. }
  209458. };
  209459. END_JUCE_NAMESPACE
  209460. using namespace JUCE_NAMESPACE;
  209461. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209462. @interface JuceAppDelegate : NSObject
  209463. {
  209464. @private
  209465. id oldDelegate;
  209466. @public
  209467. AppDelegateRedirector* redirector;
  209468. }
  209469. - (JuceAppDelegate*) init;
  209470. - (void) dealloc;
  209471. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209472. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209473. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209474. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209475. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209476. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209477. - (void) performCallback: (id) info;
  209478. - (void) dummyMethod;
  209479. @end
  209480. @implementation JuceAppDelegate
  209481. - (JuceAppDelegate*) init
  209482. {
  209483. [super init];
  209484. redirector = new AppDelegateRedirector();
  209485. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209486. if (JUCEApplication::getInstance() != 0)
  209487. {
  209488. oldDelegate = [NSApp delegate];
  209489. [NSApp setDelegate: self];
  209490. }
  209491. else
  209492. {
  209493. oldDelegate = 0;
  209494. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209495. name: NSApplicationDidResignActiveNotification object: NSApp];
  209496. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209497. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209498. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209499. name: NSApplicationWillUnhideNotification object: NSApp];
  209500. }
  209501. return self;
  209502. }
  209503. - (void) dealloc
  209504. {
  209505. if (oldDelegate != 0)
  209506. [NSApp setDelegate: oldDelegate];
  209507. redirector->deleteSelf();
  209508. [super dealloc];
  209509. }
  209510. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209511. {
  209512. return redirector->shouldTerminate();
  209513. }
  209514. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209515. {
  209516. return redirector->openFile (filename);
  209517. }
  209518. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209519. {
  209520. return redirector->openFiles (filenames);
  209521. }
  209522. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209523. {
  209524. redirector->focusChanged();
  209525. }
  209526. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209527. {
  209528. redirector->focusChanged();
  209529. }
  209530. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209531. {
  209532. redirector->focusChanged();
  209533. }
  209534. - (void) performCallback: (id) info
  209535. {
  209536. if ([info isKindOfClass: [NSData class]])
  209537. {
  209538. AppDelegateRedirector::CallbackMessagePayload* pl
  209539. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  209540. if (pl != 0)
  209541. redirector->performCallback (pl);
  209542. }
  209543. else
  209544. {
  209545. jassertfalse // should never get here!
  209546. }
  209547. }
  209548. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209549. @end
  209550. BEGIN_JUCE_NAMESPACE
  209551. static JuceAppDelegate* juceAppDelegate = 0;
  209552. void MessageManager::runDispatchLoop()
  209553. {
  209554. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209555. {
  209556. const ScopedAutoReleasePool pool;
  209557. // must only be called by the message thread!
  209558. jassert (isThisTheMessageThread());
  209559. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209560. @try
  209561. {
  209562. [NSApp run];
  209563. }
  209564. @catch (NSException* e)
  209565. {
  209566. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209567. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209568. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209569. }
  209570. @finally
  209571. {
  209572. }
  209573. #else
  209574. [NSApp run];
  209575. #endif
  209576. }
  209577. }
  209578. void MessageManager::stopDispatchLoop()
  209579. {
  209580. quitMessagePosted = true;
  209581. [NSApp stop: nil];
  209582. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209583. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209584. }
  209585. static bool isEventBlockedByModalComps (NSEvent* e)
  209586. {
  209587. if (Component::getNumCurrentlyModalComponents() == 0)
  209588. return false;
  209589. NSWindow* const w = [e window];
  209590. if (w == 0 || [w worksWhenModal])
  209591. return false;
  209592. bool isKey = false, isInputAttempt = false;
  209593. switch ([e type])
  209594. {
  209595. case NSKeyDown:
  209596. case NSKeyUp:
  209597. isKey = isInputAttempt = true;
  209598. break;
  209599. case NSLeftMouseDown:
  209600. case NSRightMouseDown:
  209601. case NSOtherMouseDown:
  209602. isInputAttempt = true;
  209603. break;
  209604. case NSLeftMouseDragged:
  209605. case NSRightMouseDragged:
  209606. case NSLeftMouseUp:
  209607. case NSRightMouseUp:
  209608. case NSOtherMouseUp:
  209609. case NSOtherMouseDragged:
  209610. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  209611. return false;
  209612. break;
  209613. case NSMouseMoved:
  209614. case NSMouseEntered:
  209615. case NSMouseExited:
  209616. case NSCursorUpdate:
  209617. case NSScrollWheel:
  209618. case NSTabletPoint:
  209619. case NSTabletProximity:
  209620. break;
  209621. default:
  209622. return false;
  209623. }
  209624. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209625. {
  209626. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209627. NSView* const compView = (NSView*) peer->getNativeHandle();
  209628. if ([compView window] == w)
  209629. {
  209630. if (isKey)
  209631. {
  209632. if (compView == [w firstResponder])
  209633. return false;
  209634. }
  209635. else
  209636. {
  209637. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209638. [compView bounds]))
  209639. return false;
  209640. }
  209641. }
  209642. }
  209643. if (isInputAttempt)
  209644. {
  209645. if (! [NSApp isActive])
  209646. [NSApp activateIgnoringOtherApps: YES];
  209647. Component* const modal = Component::getCurrentlyModalComponent (0);
  209648. if (modal != 0)
  209649. modal->inputAttemptWhenModal();
  209650. }
  209651. return true;
  209652. }
  209653. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209654. {
  209655. const ScopedAutoReleasePool pool;
  209656. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209657. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209658. while (! quitMessagePosted)
  209659. {
  209660. const ScopedAutoReleasePool pool2;
  209661. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209662. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209663. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209664. inMode: NSDefaultRunLoopMode
  209665. dequeue: YES];
  209666. if (e != 0 && ! isEventBlockedByModalComps (e))
  209667. [NSApp sendEvent: e];
  209668. if (Time::getMillisecondCounter() >= endTime)
  209669. break;
  209670. }
  209671. return ! quitMessagePosted;
  209672. }
  209673. void MessageManager::doPlatformSpecificInitialisation()
  209674. {
  209675. if (juceAppDelegate == 0)
  209676. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209677. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209678. // correctly (needed prior to 10.5)
  209679. if (! [NSThread isMultiThreaded])
  209680. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209681. toTarget: juceAppDelegate
  209682. withObject: nil];
  209683. initialiseMainMenu();
  209684. }
  209685. void MessageManager::doPlatformSpecificShutdown()
  209686. {
  209687. if (juceAppDelegate != 0)
  209688. {
  209689. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209690. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209691. [juceAppDelegate release];
  209692. juceAppDelegate = 0;
  209693. }
  209694. }
  209695. bool juce_postMessageToSystemQueue (void* message)
  209696. {
  209697. juceAppDelegate->redirector->postMessage (message);
  209698. return true;
  209699. }
  209700. void MessageManager::broadcastMessage (const String& value) throw()
  209701. {
  209702. }
  209703. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209704. void* data)
  209705. {
  209706. if (isThisTheMessageThread())
  209707. {
  209708. return (*callback) (data);
  209709. }
  209710. else
  209711. {
  209712. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209713. // deadlock because the message manager is blocked from running, so can never
  209714. // call your function..
  209715. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209716. const ScopedAutoReleasePool pool;
  209717. AppDelegateRedirector::CallbackMessagePayload cmp;
  209718. cmp.function = callback;
  209719. cmp.parameter = data;
  209720. cmp.result = 0;
  209721. cmp.hasBeenExecuted = false;
  209722. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209723. withObject: [NSData dataWithBytesNoCopy: &cmp
  209724. length: sizeof (cmp)
  209725. freeWhenDone: NO]
  209726. waitUntilDone: YES];
  209727. return cmp.result;
  209728. }
  209729. }
  209730. #endif
  209731. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  209732. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209733. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209734. // compiled on its own).
  209735. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  209736. #if JUCE_MAC
  209737. END_JUCE_NAMESPACE
  209738. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  209739. @interface DownloadClickDetector : NSObject
  209740. {
  209741. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  209742. }
  209743. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  209744. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209745. request: (NSURLRequest*) request
  209746. frame: (WebFrame*) frame
  209747. decisionListener: (id<WebPolicyDecisionListener>) listener;
  209748. @end
  209749. @implementation DownloadClickDetector
  209750. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  209751. {
  209752. [super init];
  209753. ownerComponent = ownerComponent_;
  209754. return self;
  209755. }
  209756. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209757. request: (NSURLRequest*) request
  209758. frame: (WebFrame*) frame
  209759. decisionListener: (id <WebPolicyDecisionListener>) listener
  209760. {
  209761. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  209762. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  209763. [listener use];
  209764. else
  209765. [listener ignore];
  209766. }
  209767. @end
  209768. BEGIN_JUCE_NAMESPACE
  209769. class WebBrowserComponentInternal : public NSViewComponent
  209770. {
  209771. public:
  209772. WebBrowserComponentInternal (WebBrowserComponent* owner)
  209773. {
  209774. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  209775. frameName: @""
  209776. groupName: @""];
  209777. setView (webView);
  209778. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  209779. [webView setPolicyDelegate: clickListener];
  209780. }
  209781. ~WebBrowserComponentInternal()
  209782. {
  209783. [webView setPolicyDelegate: nil];
  209784. [clickListener release];
  209785. setView (0);
  209786. }
  209787. void goToURL (const String& url,
  209788. const StringArray* headers,
  209789. const MemoryBlock* postData)
  209790. {
  209791. NSMutableURLRequest* r
  209792. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  209793. cachePolicy: NSURLRequestUseProtocolCachePolicy
  209794. timeoutInterval: 30.0];
  209795. if (postData != 0 && postData->getSize() > 0)
  209796. {
  209797. [r setHTTPMethod: @"POST"];
  209798. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  209799. length: postData->getSize()]];
  209800. }
  209801. if (headers != 0)
  209802. {
  209803. for (int i = 0; i < headers->size(); ++i)
  209804. {
  209805. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  209806. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  209807. [r setValue: juceStringToNS (headerValue)
  209808. forHTTPHeaderField: juceStringToNS (headerName)];
  209809. }
  209810. }
  209811. stop();
  209812. [[webView mainFrame] loadRequest: r];
  209813. }
  209814. void goBack()
  209815. {
  209816. [webView goBack];
  209817. }
  209818. void goForward()
  209819. {
  209820. [webView goForward];
  209821. }
  209822. void stop()
  209823. {
  209824. [webView stopLoading: nil];
  209825. }
  209826. void refresh()
  209827. {
  209828. [webView reload: nil];
  209829. }
  209830. private:
  209831. WebView* webView;
  209832. DownloadClickDetector* clickListener;
  209833. };
  209834. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  209835. : browser (0),
  209836. blankPageShown (false),
  209837. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  209838. {
  209839. setOpaque (true);
  209840. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  209841. }
  209842. WebBrowserComponent::~WebBrowserComponent()
  209843. {
  209844. deleteAndZero (browser);
  209845. }
  209846. void WebBrowserComponent::goToURL (const String& url,
  209847. const StringArray* headers,
  209848. const MemoryBlock* postData)
  209849. {
  209850. lastURL = url;
  209851. lastHeaders.clear();
  209852. if (headers != 0)
  209853. lastHeaders = *headers;
  209854. lastPostData.setSize (0);
  209855. if (postData != 0)
  209856. lastPostData = *postData;
  209857. blankPageShown = false;
  209858. browser->goToURL (url, headers, postData);
  209859. }
  209860. void WebBrowserComponent::stop()
  209861. {
  209862. browser->stop();
  209863. }
  209864. void WebBrowserComponent::goBack()
  209865. {
  209866. lastURL = String::empty;
  209867. blankPageShown = false;
  209868. browser->goBack();
  209869. }
  209870. void WebBrowserComponent::goForward()
  209871. {
  209872. lastURL = String::empty;
  209873. browser->goForward();
  209874. }
  209875. void WebBrowserComponent::refresh()
  209876. {
  209877. browser->refresh();
  209878. }
  209879. void WebBrowserComponent::paint (Graphics& g)
  209880. {
  209881. }
  209882. void WebBrowserComponent::checkWindowAssociation()
  209883. {
  209884. if (isShowing())
  209885. {
  209886. if (blankPageShown)
  209887. goBack();
  209888. }
  209889. else
  209890. {
  209891. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  209892. {
  209893. // when the component becomes invisible, some stuff like flash
  209894. // carries on playing audio, so we need to force it onto a blank
  209895. // page to avoid this, (and send it back when it's made visible again).
  209896. blankPageShown = true;
  209897. browser->goToURL ("about:blank", 0, 0);
  209898. }
  209899. }
  209900. }
  209901. void WebBrowserComponent::reloadLastURL()
  209902. {
  209903. if (lastURL.isNotEmpty())
  209904. {
  209905. goToURL (lastURL, &lastHeaders, &lastPostData);
  209906. lastURL = String::empty;
  209907. }
  209908. }
  209909. void WebBrowserComponent::parentHierarchyChanged()
  209910. {
  209911. checkWindowAssociation();
  209912. }
  209913. void WebBrowserComponent::resized()
  209914. {
  209915. browser->setSize (getWidth(), getHeight());
  209916. }
  209917. void WebBrowserComponent::visibilityChanged()
  209918. {
  209919. checkWindowAssociation();
  209920. }
  209921. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  209922. {
  209923. return true;
  209924. }
  209925. #else
  209926. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  209927. {
  209928. }
  209929. WebBrowserComponent::~WebBrowserComponent()
  209930. {
  209931. }
  209932. void WebBrowserComponent::goToURL (const String& url,
  209933. const StringArray* headers,
  209934. const MemoryBlock* postData)
  209935. {
  209936. }
  209937. void WebBrowserComponent::stop()
  209938. {
  209939. }
  209940. void WebBrowserComponent::goBack()
  209941. {
  209942. }
  209943. void WebBrowserComponent::goForward()
  209944. {
  209945. }
  209946. void WebBrowserComponent::refresh()
  209947. {
  209948. }
  209949. void WebBrowserComponent::paint (Graphics& g)
  209950. {
  209951. }
  209952. void WebBrowserComponent::checkWindowAssociation()
  209953. {
  209954. }
  209955. void WebBrowserComponent::reloadLastURL()
  209956. {
  209957. }
  209958. void WebBrowserComponent::parentHierarchyChanged()
  209959. {
  209960. }
  209961. void WebBrowserComponent::resized()
  209962. {
  209963. }
  209964. void WebBrowserComponent::visibilityChanged()
  209965. {
  209966. }
  209967. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  209968. {
  209969. return true;
  209970. }
  209971. #endif
  209972. #endif
  209973. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209974. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  209975. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209976. // compiled on its own).
  209977. #if JUCE_INCLUDED_FILE
  209978. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  209979. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  209980. #endif
  209981. #undef log
  209982. #if JUCE_COREAUDIO_LOGGING_ENABLED
  209983. #define log(a) Logger::writeToLog (a)
  209984. #else
  209985. #define log(a)
  209986. #endif
  209987. #undef OK
  209988. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  209989. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  209990. {
  209991. if (err == noErr)
  209992. return true;
  209993. Logger::writeToLog ("CoreAudio error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  209994. jassertfalse
  209995. return false;
  209996. }
  209997. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  209998. #else
  209999. #define OK(a) (a == noErr)
  210000. #endif
  210001. class CoreAudioInternal : public Timer
  210002. {
  210003. public:
  210004. CoreAudioInternal (AudioDeviceID id)
  210005. : inputLatency (0),
  210006. outputLatency (0),
  210007. callback (0),
  210008. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210009. audioProcID (0),
  210010. #endif
  210011. inputDevice (0),
  210012. isSlaveDevice (false),
  210013. deviceID (id),
  210014. started (false),
  210015. sampleRate (0),
  210016. bufferSize (512),
  210017. numInputChans (0),
  210018. numOutputChans (0),
  210019. callbacksAllowed (true),
  210020. numInputChannelInfos (0),
  210021. numOutputChannelInfos (0)
  210022. {
  210023. jassert (deviceID != 0);
  210024. updateDetailsFromDevice();
  210025. AudioObjectPropertyAddress pa;
  210026. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210027. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210028. pa.mElement = kAudioObjectPropertyElementWildcard;
  210029. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210030. }
  210031. ~CoreAudioInternal()
  210032. {
  210033. AudioObjectPropertyAddress pa;
  210034. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210035. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210036. pa.mElement = kAudioObjectPropertyElementWildcard;
  210037. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210038. stop (false);
  210039. delete inputDevice;
  210040. }
  210041. void allocateTempBuffers()
  210042. {
  210043. const int tempBufSize = bufferSize + 4;
  210044. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210045. tempInputBuffers.calloc (numInputChans + 2);
  210046. tempOutputBuffers.calloc (numOutputChans + 2);
  210047. int i, count = 0;
  210048. for (i = 0; i < numInputChans; ++i)
  210049. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210050. for (i = 0; i < numOutputChans; ++i)
  210051. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210052. }
  210053. // returns the number of actual available channels
  210054. void fillInChannelInfo (const bool input)
  210055. {
  210056. int chanNum = 0;
  210057. UInt32 size;
  210058. AudioObjectPropertyAddress pa;
  210059. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210060. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210061. pa.mElement = kAudioObjectPropertyElementMaster;
  210062. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210063. {
  210064. HeapBlock <AudioBufferList> bufList;
  210065. bufList.calloc (size, 1);
  210066. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210067. {
  210068. const int numStreams = bufList->mNumberBuffers;
  210069. for (int i = 0; i < numStreams; ++i)
  210070. {
  210071. const AudioBuffer& b = bufList->mBuffers[i];
  210072. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210073. {
  210074. String name;
  210075. {
  210076. char channelName [256];
  210077. zerostruct (channelName);
  210078. UInt32 nameSize = sizeof (channelName);
  210079. UInt32 channelNum = chanNum + 1;
  210080. pa.mSelector = kAudioDevicePropertyChannelName;
  210081. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210082. name = String::fromUTF8 (channelName, nameSize);
  210083. }
  210084. if (input)
  210085. {
  210086. if (activeInputChans[chanNum])
  210087. {
  210088. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210089. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210090. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210091. ++numInputChannelInfos;
  210092. }
  210093. if (name.isEmpty())
  210094. name << "Input " << (chanNum + 1);
  210095. inChanNames.add (name);
  210096. }
  210097. else
  210098. {
  210099. if (activeOutputChans[chanNum])
  210100. {
  210101. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210102. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210103. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210104. ++numOutputChannelInfos;
  210105. }
  210106. if (name.isEmpty())
  210107. name << "Output " << (chanNum + 1);
  210108. outChanNames.add (name);
  210109. }
  210110. ++chanNum;
  210111. }
  210112. }
  210113. }
  210114. }
  210115. }
  210116. void updateDetailsFromDevice()
  210117. {
  210118. stopTimer();
  210119. if (deviceID == 0)
  210120. return;
  210121. const ScopedLock sl (callbackLock);
  210122. Float64 sr;
  210123. UInt32 size = sizeof (Float64);
  210124. AudioObjectPropertyAddress pa;
  210125. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210126. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210127. pa.mElement = kAudioObjectPropertyElementMaster;
  210128. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210129. sampleRate = sr;
  210130. UInt32 framesPerBuf;
  210131. size = sizeof (framesPerBuf);
  210132. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210133. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210134. {
  210135. bufferSize = framesPerBuf;
  210136. allocateTempBuffers();
  210137. }
  210138. bufferSizes.clear();
  210139. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210140. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210141. {
  210142. HeapBlock <AudioValueRange> ranges;
  210143. ranges.calloc (size, 1);
  210144. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210145. {
  210146. bufferSizes.add ((int) ranges[0].mMinimum);
  210147. for (int i = 32; i < 2048; i += 32)
  210148. {
  210149. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210150. {
  210151. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210152. {
  210153. bufferSizes.addIfNotAlreadyThere (i);
  210154. break;
  210155. }
  210156. }
  210157. }
  210158. if (bufferSize > 0)
  210159. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210160. }
  210161. }
  210162. if (bufferSizes.size() == 0 && bufferSize > 0)
  210163. bufferSizes.add (bufferSize);
  210164. sampleRates.clear();
  210165. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210166. String rates;
  210167. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210168. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210169. {
  210170. HeapBlock <AudioValueRange> ranges;
  210171. ranges.calloc (size, 1);
  210172. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210173. {
  210174. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210175. {
  210176. bool ok = false;
  210177. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210178. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210179. ok = true;
  210180. if (ok)
  210181. {
  210182. sampleRates.add (possibleRates[i]);
  210183. rates << possibleRates[i] << ' ';
  210184. }
  210185. }
  210186. }
  210187. }
  210188. if (sampleRates.size() == 0 && sampleRate > 0)
  210189. {
  210190. sampleRates.add (sampleRate);
  210191. rates << sampleRate;
  210192. }
  210193. log ("sr: " + rates);
  210194. inputLatency = 0;
  210195. outputLatency = 0;
  210196. UInt32 lat;
  210197. size = sizeof (lat);
  210198. pa.mSelector = kAudioDevicePropertyLatency;
  210199. pa.mScope = kAudioDevicePropertyScopeInput;
  210200. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210201. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210202. inputLatency = (int) lat;
  210203. pa.mScope = kAudioDevicePropertyScopeOutput;
  210204. size = sizeof (lat);
  210205. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210206. outputLatency = (int) lat;
  210207. log ("lat: " + String (inputLatency) + " " + String (outputLatency));
  210208. inChanNames.clear();
  210209. outChanNames.clear();
  210210. inputChannelInfo.calloc (numInputChans + 2);
  210211. numInputChannelInfos = 0;
  210212. outputChannelInfo.calloc (numOutputChans + 2);
  210213. numOutputChannelInfos = 0;
  210214. fillInChannelInfo (true);
  210215. fillInChannelInfo (false);
  210216. }
  210217. const StringArray getSources (bool input)
  210218. {
  210219. StringArray s;
  210220. HeapBlock <OSType> types;
  210221. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210222. for (int i = 0; i < num; ++i)
  210223. {
  210224. AudioValueTranslation avt;
  210225. char buffer[256];
  210226. avt.mInputData = &(types[i]);
  210227. avt.mInputDataSize = sizeof (UInt32);
  210228. avt.mOutputData = buffer;
  210229. avt.mOutputDataSize = 256;
  210230. UInt32 transSize = sizeof (avt);
  210231. AudioObjectPropertyAddress pa;
  210232. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210233. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210234. pa.mElement = kAudioObjectPropertyElementMaster;
  210235. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210236. {
  210237. DBG (buffer);
  210238. s.add (buffer);
  210239. }
  210240. }
  210241. return s;
  210242. }
  210243. int getCurrentSourceIndex (bool input) const
  210244. {
  210245. OSType currentSourceID = 0;
  210246. UInt32 size = sizeof (currentSourceID);
  210247. int result = -1;
  210248. AudioObjectPropertyAddress pa;
  210249. pa.mSelector = kAudioDevicePropertyDataSource;
  210250. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210251. pa.mElement = kAudioObjectPropertyElementMaster;
  210252. if (deviceID != 0)
  210253. {
  210254. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210255. {
  210256. HeapBlock <OSType> types;
  210257. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210258. for (int i = 0; i < num; ++i)
  210259. {
  210260. if (types[num] == currentSourceID)
  210261. {
  210262. result = i;
  210263. break;
  210264. }
  210265. }
  210266. }
  210267. }
  210268. return result;
  210269. }
  210270. void setCurrentSourceIndex (int index, bool input)
  210271. {
  210272. if (deviceID != 0)
  210273. {
  210274. HeapBlock <OSType> types;
  210275. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210276. if (((unsigned int) index) < (unsigned int) num)
  210277. {
  210278. AudioObjectPropertyAddress pa;
  210279. pa.mSelector = kAudioDevicePropertyDataSource;
  210280. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210281. pa.mElement = kAudioObjectPropertyElementMaster;
  210282. OSType typeId = types[index];
  210283. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210284. }
  210285. }
  210286. }
  210287. const String reopen (const BigInteger& inputChannels,
  210288. const BigInteger& outputChannels,
  210289. double newSampleRate,
  210290. int bufferSizeSamples)
  210291. {
  210292. String error;
  210293. log ("CoreAudio reopen");
  210294. callbacksAllowed = false;
  210295. stopTimer();
  210296. stop (false);
  210297. activeInputChans = inputChannels;
  210298. activeInputChans.setRange (inChanNames.size(),
  210299. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210300. false);
  210301. activeOutputChans = outputChannels;
  210302. activeOutputChans.setRange (outChanNames.size(),
  210303. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210304. false);
  210305. numInputChans = activeInputChans.countNumberOfSetBits();
  210306. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210307. // set sample rate
  210308. AudioObjectPropertyAddress pa;
  210309. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210310. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210311. pa.mElement = kAudioObjectPropertyElementMaster;
  210312. Float64 sr = newSampleRate;
  210313. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210314. {
  210315. error = "Couldn't change sample rate";
  210316. }
  210317. else
  210318. {
  210319. // change buffer size
  210320. UInt32 framesPerBuf = bufferSizeSamples;
  210321. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210322. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210323. {
  210324. error = "Couldn't change buffer size";
  210325. }
  210326. else
  210327. {
  210328. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210329. // correctly report their new settings until some random time in the future, so
  210330. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210331. // to make sure we're using the correct numbers..
  210332. updateDetailsFromDevice();
  210333. sampleRate = newSampleRate;
  210334. bufferSize = bufferSizeSamples;
  210335. if (sampleRates.size() == 0)
  210336. error = "Device has no available sample-rates";
  210337. else if (bufferSizes.size() == 0)
  210338. error = "Device has no available buffer-sizes";
  210339. else if (inputDevice != 0)
  210340. error = inputDevice->reopen (inputChannels,
  210341. outputChannels,
  210342. newSampleRate,
  210343. bufferSizeSamples);
  210344. }
  210345. }
  210346. callbacksAllowed = true;
  210347. return error;
  210348. }
  210349. bool start (AudioIODeviceCallback* cb)
  210350. {
  210351. if (! started)
  210352. {
  210353. callback = 0;
  210354. if (deviceID != 0)
  210355. {
  210356. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210357. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, this)))
  210358. #else
  210359. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, this, &audioProcID)))
  210360. #endif
  210361. {
  210362. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210363. {
  210364. started = true;
  210365. }
  210366. else
  210367. {
  210368. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210369. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210370. #else
  210371. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210372. audioProcID = 0;
  210373. #endif
  210374. }
  210375. }
  210376. }
  210377. }
  210378. if (started)
  210379. {
  210380. const ScopedLock sl (callbackLock);
  210381. callback = cb;
  210382. }
  210383. if (inputDevice != 0)
  210384. return started && inputDevice->start (cb);
  210385. else
  210386. return started;
  210387. }
  210388. void stop (bool leaveInterruptRunning)
  210389. {
  210390. {
  210391. const ScopedLock sl (callbackLock);
  210392. callback = 0;
  210393. }
  210394. if (started
  210395. && (deviceID != 0)
  210396. && ! leaveInterruptRunning)
  210397. {
  210398. OK (AudioDeviceStop (deviceID, audioIOProc));
  210399. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210400. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210401. #else
  210402. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210403. audioProcID = 0;
  210404. #endif
  210405. started = false;
  210406. { const ScopedLock sl (callbackLock); }
  210407. // wait until it's definately stopped calling back..
  210408. for (int i = 40; --i >= 0;)
  210409. {
  210410. Thread::sleep (50);
  210411. UInt32 running = 0;
  210412. UInt32 size = sizeof (running);
  210413. AudioObjectPropertyAddress pa;
  210414. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210415. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210416. pa.mElement = kAudioObjectPropertyElementMaster;
  210417. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210418. if (running == 0)
  210419. break;
  210420. }
  210421. const ScopedLock sl (callbackLock);
  210422. }
  210423. if (inputDevice != 0)
  210424. inputDevice->stop (leaveInterruptRunning);
  210425. }
  210426. double getSampleRate() const
  210427. {
  210428. return sampleRate;
  210429. }
  210430. int getBufferSize() const
  210431. {
  210432. return bufferSize;
  210433. }
  210434. void audioCallback (const AudioBufferList* inInputData,
  210435. AudioBufferList* outOutputData)
  210436. {
  210437. int i;
  210438. const ScopedLock sl (callbackLock);
  210439. if (callback != 0)
  210440. {
  210441. if (inputDevice == 0)
  210442. {
  210443. for (i = numInputChans; --i >= 0;)
  210444. {
  210445. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210446. float* dest = tempInputBuffers [i];
  210447. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210448. + info.dataOffsetSamples;
  210449. const int stride = info.dataStrideSamples;
  210450. if (stride != 0) // if this is zero, info is invalid
  210451. {
  210452. for (int j = bufferSize; --j >= 0;)
  210453. {
  210454. *dest++ = *src;
  210455. src += stride;
  210456. }
  210457. }
  210458. }
  210459. }
  210460. if (! isSlaveDevice)
  210461. {
  210462. if (inputDevice == 0)
  210463. {
  210464. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210465. numInputChans,
  210466. tempOutputBuffers,
  210467. numOutputChans,
  210468. bufferSize);
  210469. }
  210470. else
  210471. {
  210472. jassert (inputDevice->bufferSize == bufferSize);
  210473. // Sometimes the two linked devices seem to get their callbacks in
  210474. // parallel, so we need to lock both devices to stop the input data being
  210475. // changed while inside our callback..
  210476. const ScopedLock sl2 (inputDevice->callbackLock);
  210477. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210478. inputDevice->numInputChans,
  210479. tempOutputBuffers,
  210480. numOutputChans,
  210481. bufferSize);
  210482. }
  210483. for (i = numOutputChans; --i >= 0;)
  210484. {
  210485. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210486. const float* src = tempOutputBuffers [i];
  210487. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210488. + info.dataOffsetSamples;
  210489. const int stride = info.dataStrideSamples;
  210490. if (stride != 0) // if this is zero, info is invalid
  210491. {
  210492. for (int j = bufferSize; --j >= 0;)
  210493. {
  210494. *dest = *src++;
  210495. dest += stride;
  210496. }
  210497. }
  210498. }
  210499. }
  210500. }
  210501. else
  210502. {
  210503. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210504. {
  210505. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210506. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210507. + info.dataOffsetSamples;
  210508. const int stride = info.dataStrideSamples;
  210509. if (stride != 0) // if this is zero, info is invalid
  210510. {
  210511. for (int j = bufferSize; --j >= 0;)
  210512. {
  210513. *dest = 0.0f;
  210514. dest += stride;
  210515. }
  210516. }
  210517. }
  210518. }
  210519. }
  210520. // called by callbacks
  210521. void deviceDetailsChanged()
  210522. {
  210523. if (callbacksAllowed)
  210524. startTimer (100);
  210525. }
  210526. void timerCallback()
  210527. {
  210528. stopTimer();
  210529. log ("CoreAudio device changed callback");
  210530. const double oldSampleRate = sampleRate;
  210531. const int oldBufferSize = bufferSize;
  210532. updateDetailsFromDevice();
  210533. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210534. {
  210535. callbacksAllowed = false;
  210536. stop (false);
  210537. updateDetailsFromDevice();
  210538. callbacksAllowed = true;
  210539. }
  210540. }
  210541. CoreAudioInternal* getRelatedDevice() const
  210542. {
  210543. UInt32 size = 0;
  210544. ScopedPointer <CoreAudioInternal> result;
  210545. AudioObjectPropertyAddress pa;
  210546. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210547. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210548. pa.mElement = kAudioObjectPropertyElementMaster;
  210549. if (deviceID != 0
  210550. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210551. && size > 0)
  210552. {
  210553. HeapBlock <AudioDeviceID> devs;
  210554. devs.calloc (size, 1);
  210555. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210556. {
  210557. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210558. {
  210559. if (devs[i] != deviceID && devs[i] != 0)
  210560. {
  210561. result = new CoreAudioInternal (devs[i]);
  210562. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210563. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210564. if (thisIsInput != otherIsInput
  210565. || (inChanNames.size() + outChanNames.size() == 0)
  210566. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210567. break;
  210568. result = 0;
  210569. }
  210570. }
  210571. }
  210572. }
  210573. return result.release();
  210574. }
  210575. juce_UseDebuggingNewOperator
  210576. int inputLatency, outputLatency;
  210577. BigInteger activeInputChans, activeOutputChans;
  210578. StringArray inChanNames, outChanNames;
  210579. Array <double> sampleRates;
  210580. Array <int> bufferSizes;
  210581. AudioIODeviceCallback* callback;
  210582. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210583. AudioDeviceIOProcID audioProcID;
  210584. #endif
  210585. CoreAudioInternal* inputDevice;
  210586. bool isSlaveDevice;
  210587. private:
  210588. CriticalSection callbackLock;
  210589. AudioDeviceID deviceID;
  210590. bool started;
  210591. double sampleRate;
  210592. int bufferSize;
  210593. HeapBlock <float> audioBuffer;
  210594. int numInputChans, numOutputChans;
  210595. bool callbacksAllowed;
  210596. struct CallbackDetailsForChannel
  210597. {
  210598. int streamNum;
  210599. int dataOffsetSamples;
  210600. int dataStrideSamples;
  210601. };
  210602. int numInputChannelInfos, numOutputChannelInfos;
  210603. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210604. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210605. CoreAudioInternal (const CoreAudioInternal&);
  210606. CoreAudioInternal& operator= (const CoreAudioInternal&);
  210607. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210608. const AudioTimeStamp* inNow,
  210609. const AudioBufferList* inInputData,
  210610. const AudioTimeStamp* inInputTime,
  210611. AudioBufferList* outOutputData,
  210612. const AudioTimeStamp* inOutputTime,
  210613. void* device)
  210614. {
  210615. static_cast <CoreAudioInternal*> (device)->audioCallback (inInputData, outOutputData);
  210616. return noErr;
  210617. }
  210618. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210619. {
  210620. CoreAudioInternal* const intern = static_cast <CoreAudioInternal*> (inClientData);
  210621. switch (pa->mSelector)
  210622. {
  210623. case kAudioDevicePropertyBufferSize:
  210624. case kAudioDevicePropertyBufferFrameSize:
  210625. case kAudioDevicePropertyNominalSampleRate:
  210626. case kAudioDevicePropertyStreamFormat:
  210627. case kAudioDevicePropertyDeviceIsAlive:
  210628. intern->deviceDetailsChanged();
  210629. break;
  210630. case kAudioDevicePropertyBufferSizeRange:
  210631. case kAudioDevicePropertyVolumeScalar:
  210632. case kAudioDevicePropertyMute:
  210633. case kAudioDevicePropertyPlayThru:
  210634. case kAudioDevicePropertyDataSource:
  210635. case kAudioDevicePropertyDeviceIsRunning:
  210636. break;
  210637. }
  210638. return noErr;
  210639. }
  210640. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210641. {
  210642. AudioObjectPropertyAddress pa;
  210643. pa.mSelector = kAudioDevicePropertyDataSources;
  210644. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210645. pa.mElement = kAudioObjectPropertyElementMaster;
  210646. UInt32 size = 0;
  210647. if (deviceID != 0
  210648. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210649. {
  210650. types.calloc (size, 1);
  210651. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210652. return size / (int) sizeof (OSType);
  210653. }
  210654. return 0;
  210655. }
  210656. };
  210657. class CoreAudioIODevice : public AudioIODevice
  210658. {
  210659. public:
  210660. CoreAudioIODevice (const String& deviceName,
  210661. AudioDeviceID inputDeviceId,
  210662. const int inputIndex_,
  210663. AudioDeviceID outputDeviceId,
  210664. const int outputIndex_)
  210665. : AudioIODevice (deviceName, "CoreAudio"),
  210666. inputIndex (inputIndex_),
  210667. outputIndex (outputIndex_),
  210668. isOpen_ (false),
  210669. isStarted (false)
  210670. {
  210671. internal = 0;
  210672. CoreAudioInternal* device = 0;
  210673. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210674. {
  210675. jassert (inputDeviceId != 0);
  210676. device = new CoreAudioInternal (inputDeviceId);
  210677. }
  210678. else
  210679. {
  210680. device = new CoreAudioInternal (outputDeviceId);
  210681. if (inputDeviceId != 0)
  210682. {
  210683. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210684. device->inputDevice = secondDevice;
  210685. secondDevice->isSlaveDevice = true;
  210686. }
  210687. }
  210688. internal = device;
  210689. AudioObjectPropertyAddress pa;
  210690. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210691. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210692. pa.mElement = kAudioObjectPropertyElementWildcard;
  210693. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210694. }
  210695. ~CoreAudioIODevice()
  210696. {
  210697. AudioObjectPropertyAddress pa;
  210698. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210699. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210700. pa.mElement = kAudioObjectPropertyElementWildcard;
  210701. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210702. delete internal;
  210703. }
  210704. const StringArray getOutputChannelNames()
  210705. {
  210706. return internal->outChanNames;
  210707. }
  210708. const StringArray getInputChannelNames()
  210709. {
  210710. if (internal->inputDevice != 0)
  210711. return internal->inputDevice->inChanNames;
  210712. else
  210713. return internal->inChanNames;
  210714. }
  210715. int getNumSampleRates()
  210716. {
  210717. return internal->sampleRates.size();
  210718. }
  210719. double getSampleRate (int index)
  210720. {
  210721. return internal->sampleRates [index];
  210722. }
  210723. int getNumBufferSizesAvailable()
  210724. {
  210725. return internal->bufferSizes.size();
  210726. }
  210727. int getBufferSizeSamples (int index)
  210728. {
  210729. return internal->bufferSizes [index];
  210730. }
  210731. int getDefaultBufferSize()
  210732. {
  210733. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  210734. if (getBufferSizeSamples(i) >= 512)
  210735. return getBufferSizeSamples(i);
  210736. return 512;
  210737. }
  210738. const String open (const BigInteger& inputChannels,
  210739. const BigInteger& outputChannels,
  210740. double sampleRate,
  210741. int bufferSizeSamples)
  210742. {
  210743. isOpen_ = true;
  210744. if (bufferSizeSamples <= 0)
  210745. bufferSizeSamples = getDefaultBufferSize();
  210746. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  210747. isOpen_ = lastError.isEmpty();
  210748. return lastError;
  210749. }
  210750. void close()
  210751. {
  210752. isOpen_ = false;
  210753. internal->stop (false);
  210754. }
  210755. bool isOpen()
  210756. {
  210757. return isOpen_;
  210758. }
  210759. int getCurrentBufferSizeSamples()
  210760. {
  210761. return internal != 0 ? internal->getBufferSize() : 512;
  210762. }
  210763. double getCurrentSampleRate()
  210764. {
  210765. return internal != 0 ? internal->getSampleRate() : 0;
  210766. }
  210767. int getCurrentBitDepth()
  210768. {
  210769. return 32; // no way to find out, so just assume it's high..
  210770. }
  210771. const BigInteger getActiveOutputChannels() const
  210772. {
  210773. return internal != 0 ? internal->activeOutputChans : BigInteger();
  210774. }
  210775. const BigInteger getActiveInputChannels() const
  210776. {
  210777. BigInteger chans;
  210778. if (internal != 0)
  210779. {
  210780. chans = internal->activeInputChans;
  210781. if (internal->inputDevice != 0)
  210782. chans |= internal->inputDevice->activeInputChans;
  210783. }
  210784. return chans;
  210785. }
  210786. int getOutputLatencyInSamples()
  210787. {
  210788. if (internal == 0)
  210789. return 0;
  210790. // this seems like a good guess at getting the latency right - comparing
  210791. // this with a round-trip measurement, it gets it to within a few millisecs
  210792. // for the built-in mac soundcard
  210793. return internal->outputLatency + internal->getBufferSize() * 2;
  210794. }
  210795. int getInputLatencyInSamples()
  210796. {
  210797. if (internal == 0)
  210798. return 0;
  210799. return internal->inputLatency + internal->getBufferSize() * 2;
  210800. }
  210801. void start (AudioIODeviceCallback* callback)
  210802. {
  210803. if (internal != 0 && ! isStarted)
  210804. {
  210805. if (callback != 0)
  210806. callback->audioDeviceAboutToStart (this);
  210807. isStarted = true;
  210808. internal->start (callback);
  210809. }
  210810. }
  210811. void stop()
  210812. {
  210813. if (isStarted && internal != 0)
  210814. {
  210815. AudioIODeviceCallback* const lastCallback = internal->callback;
  210816. isStarted = false;
  210817. internal->stop (true);
  210818. if (lastCallback != 0)
  210819. lastCallback->audioDeviceStopped();
  210820. }
  210821. }
  210822. bool isPlaying()
  210823. {
  210824. if (internal->callback == 0)
  210825. isStarted = false;
  210826. return isStarted;
  210827. }
  210828. const String getLastError()
  210829. {
  210830. return lastError;
  210831. }
  210832. int inputIndex, outputIndex;
  210833. juce_UseDebuggingNewOperator
  210834. private:
  210835. CoreAudioInternal* internal;
  210836. bool isOpen_, isStarted;
  210837. String lastError;
  210838. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210839. {
  210840. CoreAudioInternal* const intern = static_cast <CoreAudioInternal*> (inClientData);
  210841. switch (pa->mSelector)
  210842. {
  210843. case kAudioHardwarePropertyDevices:
  210844. intern->deviceDetailsChanged();
  210845. break;
  210846. case kAudioHardwarePropertyDefaultOutputDevice:
  210847. case kAudioHardwarePropertyDefaultInputDevice:
  210848. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  210849. break;
  210850. }
  210851. return noErr;
  210852. }
  210853. CoreAudioIODevice (const CoreAudioIODevice&);
  210854. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  210855. };
  210856. class CoreAudioIODeviceType : public AudioIODeviceType
  210857. {
  210858. public:
  210859. CoreAudioIODeviceType()
  210860. : AudioIODeviceType ("CoreAudio"),
  210861. hasScanned (false)
  210862. {
  210863. }
  210864. ~CoreAudioIODeviceType()
  210865. {
  210866. }
  210867. void scanForDevices()
  210868. {
  210869. hasScanned = true;
  210870. inputDeviceNames.clear();
  210871. outputDeviceNames.clear();
  210872. inputIds.clear();
  210873. outputIds.clear();
  210874. UInt32 size;
  210875. AudioObjectPropertyAddress pa;
  210876. pa.mSelector = kAudioHardwarePropertyDevices;
  210877. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210878. pa.mElement = kAudioObjectPropertyElementMaster;
  210879. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  210880. {
  210881. HeapBlock <AudioDeviceID> devs;
  210882. devs.calloc (size, 1);
  210883. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  210884. {
  210885. static bool alreadyLogged = false;
  210886. const int num = size / (int) sizeof (AudioDeviceID);
  210887. for (int i = 0; i < num; ++i)
  210888. {
  210889. char name [1024];
  210890. size = sizeof (name);
  210891. pa.mSelector = kAudioDevicePropertyDeviceName;
  210892. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  210893. {
  210894. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  210895. if (! alreadyLogged)
  210896. log ("CoreAudio device: " + nameString);
  210897. const int numIns = getNumChannels (devs[i], true);
  210898. const int numOuts = getNumChannels (devs[i], false);
  210899. if (numIns > 0)
  210900. {
  210901. inputDeviceNames.add (nameString);
  210902. inputIds.add (devs[i]);
  210903. }
  210904. if (numOuts > 0)
  210905. {
  210906. outputDeviceNames.add (nameString);
  210907. outputIds.add (devs[i]);
  210908. }
  210909. }
  210910. }
  210911. alreadyLogged = true;
  210912. }
  210913. }
  210914. inputDeviceNames.appendNumbersToDuplicates (false, true);
  210915. outputDeviceNames.appendNumbersToDuplicates (false, true);
  210916. }
  210917. const StringArray getDeviceNames (bool wantInputNames) const
  210918. {
  210919. jassert (hasScanned); // need to call scanForDevices() before doing this
  210920. if (wantInputNames)
  210921. return inputDeviceNames;
  210922. else
  210923. return outputDeviceNames;
  210924. }
  210925. int getDefaultDeviceIndex (bool forInput) const
  210926. {
  210927. jassert (hasScanned); // need to call scanForDevices() before doing this
  210928. AudioDeviceID deviceID;
  210929. UInt32 size = sizeof (deviceID);
  210930. // if they're asking for any input channels at all, use the default input, so we
  210931. // get the built-in mic rather than the built-in output with no inputs..
  210932. AudioObjectPropertyAddress pa;
  210933. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  210934. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210935. pa.mElement = kAudioObjectPropertyElementMaster;
  210936. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  210937. {
  210938. if (forInput)
  210939. {
  210940. for (int i = inputIds.size(); --i >= 0;)
  210941. if (inputIds[i] == deviceID)
  210942. return i;
  210943. }
  210944. else
  210945. {
  210946. for (int i = outputIds.size(); --i >= 0;)
  210947. if (outputIds[i] == deviceID)
  210948. return i;
  210949. }
  210950. }
  210951. return 0;
  210952. }
  210953. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  210954. {
  210955. jassert (hasScanned); // need to call scanForDevices() before doing this
  210956. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  210957. if (d == 0)
  210958. return -1;
  210959. return asInput ? d->inputIndex
  210960. : d->outputIndex;
  210961. }
  210962. bool hasSeparateInputsAndOutputs() const { return true; }
  210963. AudioIODevice* createDevice (const String& outputDeviceName,
  210964. const String& inputDeviceName)
  210965. {
  210966. jassert (hasScanned); // need to call scanForDevices() before doing this
  210967. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  210968. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  210969. String deviceName (outputDeviceName);
  210970. if (deviceName.isEmpty())
  210971. deviceName = inputDeviceName;
  210972. if (index >= 0)
  210973. return new CoreAudioIODevice (deviceName,
  210974. inputIds [inputIndex],
  210975. inputIndex,
  210976. outputIds [outputIndex],
  210977. outputIndex);
  210978. return 0;
  210979. }
  210980. juce_UseDebuggingNewOperator
  210981. private:
  210982. StringArray inputDeviceNames, outputDeviceNames;
  210983. Array <AudioDeviceID> inputIds, outputIds;
  210984. bool hasScanned;
  210985. static int getNumChannels (AudioDeviceID deviceID, bool input)
  210986. {
  210987. int total = 0;
  210988. UInt32 size;
  210989. AudioObjectPropertyAddress pa;
  210990. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210991. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210992. pa.mElement = kAudioObjectPropertyElementMaster;
  210993. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210994. {
  210995. HeapBlock <AudioBufferList> bufList;
  210996. bufList.calloc (size, 1);
  210997. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210998. {
  210999. const int numStreams = bufList->mNumberBuffers;
  211000. for (int i = 0; i < numStreams; ++i)
  211001. {
  211002. const AudioBuffer& b = bufList->mBuffers[i];
  211003. total += b.mNumberChannels;
  211004. }
  211005. }
  211006. }
  211007. return total;
  211008. }
  211009. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211010. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211011. };
  211012. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211013. {
  211014. return new CoreAudioIODeviceType();
  211015. }
  211016. #undef log
  211017. #endif
  211018. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211019. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211020. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211021. // compiled on its own).
  211022. #if JUCE_INCLUDED_FILE
  211023. #if JUCE_MAC
  211024. #undef log
  211025. #define log(a) Logger::writeToLog(a)
  211026. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211027. {
  211028. if (err == noErr)
  211029. return true;
  211030. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  211031. jassertfalse
  211032. return false;
  211033. }
  211034. #undef OK
  211035. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211036. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211037. {
  211038. String result;
  211039. CFStringRef str = 0;
  211040. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211041. if (str != 0)
  211042. {
  211043. result = PlatformUtilities::cfStringToJuceString (str);
  211044. CFRelease (str);
  211045. str = 0;
  211046. }
  211047. MIDIEntityRef entity = 0;
  211048. MIDIEndpointGetEntity (endpoint, &entity);
  211049. if (entity == 0)
  211050. return result; // probably virtual
  211051. if (result.isEmpty())
  211052. {
  211053. // endpoint name has zero length - try the entity
  211054. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211055. if (str != 0)
  211056. {
  211057. result += PlatformUtilities::cfStringToJuceString (str);
  211058. CFRelease (str);
  211059. str = 0;
  211060. }
  211061. }
  211062. // now consider the device's name
  211063. MIDIDeviceRef device = 0;
  211064. MIDIEntityGetDevice (entity, &device);
  211065. if (device == 0)
  211066. return result;
  211067. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211068. if (str != 0)
  211069. {
  211070. const String s (PlatformUtilities::cfStringToJuceString (str));
  211071. CFRelease (str);
  211072. // if an external device has only one entity, throw away
  211073. // the endpoint name and just use the device name
  211074. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211075. {
  211076. result = s;
  211077. }
  211078. else if (! result.startsWithIgnoreCase (s))
  211079. {
  211080. // prepend the device name to the entity name
  211081. result = (s + " " + result).trimEnd();
  211082. }
  211083. }
  211084. return result;
  211085. }
  211086. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211087. {
  211088. String result;
  211089. // Does the endpoint have connections?
  211090. CFDataRef connections = 0;
  211091. int numConnections = 0;
  211092. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211093. if (connections != 0)
  211094. {
  211095. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211096. if (numConnections > 0)
  211097. {
  211098. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211099. for (int i = 0; i < numConnections; ++i, ++pid)
  211100. {
  211101. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211102. MIDIObjectRef connObject;
  211103. MIDIObjectType connObjectType;
  211104. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211105. if (err == noErr)
  211106. {
  211107. String s;
  211108. if (connObjectType == kMIDIObjectType_ExternalSource
  211109. || connObjectType == kMIDIObjectType_ExternalDestination)
  211110. {
  211111. // Connected to an external device's endpoint (10.3 and later).
  211112. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211113. }
  211114. else
  211115. {
  211116. // Connected to an external device (10.2) (or something else, catch-all)
  211117. CFStringRef str = 0;
  211118. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211119. if (str != 0)
  211120. {
  211121. s = PlatformUtilities::cfStringToJuceString (str);
  211122. CFRelease (str);
  211123. }
  211124. }
  211125. if (s.isNotEmpty())
  211126. {
  211127. if (result.isNotEmpty())
  211128. result += ", ";
  211129. result += s;
  211130. }
  211131. }
  211132. }
  211133. }
  211134. CFRelease (connections);
  211135. }
  211136. if (result.isNotEmpty())
  211137. return result;
  211138. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211139. return getEndpointName (endpoint, false);
  211140. }
  211141. const StringArray MidiOutput::getDevices()
  211142. {
  211143. StringArray s;
  211144. const ItemCount num = MIDIGetNumberOfDestinations();
  211145. for (ItemCount i = 0; i < num; ++i)
  211146. {
  211147. MIDIEndpointRef dest = MIDIGetDestination (i);
  211148. if (dest != 0)
  211149. {
  211150. String name (getConnectedEndpointName (dest));
  211151. if (name.isEmpty())
  211152. name = "<error>";
  211153. s.add (name);
  211154. }
  211155. else
  211156. {
  211157. s.add ("<error>");
  211158. }
  211159. }
  211160. return s;
  211161. }
  211162. int MidiOutput::getDefaultDeviceIndex()
  211163. {
  211164. return 0;
  211165. }
  211166. static MIDIClientRef globalMidiClient;
  211167. static bool hasGlobalClientBeenCreated = false;
  211168. static bool makeSureClientExists()
  211169. {
  211170. if (! hasGlobalClientBeenCreated)
  211171. {
  211172. String name ("JUCE");
  211173. if (JUCEApplication::getInstance() != 0)
  211174. name = JUCEApplication::getInstance()->getApplicationName();
  211175. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211176. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211177. CFRelease (appName);
  211178. }
  211179. return hasGlobalClientBeenCreated;
  211180. }
  211181. class MidiPortAndEndpoint
  211182. {
  211183. public:
  211184. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211185. : port (port_), endPoint (endPoint_)
  211186. {
  211187. }
  211188. ~MidiPortAndEndpoint()
  211189. {
  211190. if (port != 0)
  211191. MIDIPortDispose (port);
  211192. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211193. MIDIEndpointDispose (endPoint);
  211194. }
  211195. MIDIPortRef port;
  211196. MIDIEndpointRef endPoint;
  211197. };
  211198. MidiOutput* MidiOutput::openDevice (int index)
  211199. {
  211200. MidiOutput* mo = 0;
  211201. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211202. {
  211203. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211204. CFStringRef pname;
  211205. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211206. {
  211207. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  211208. if (makeSureClientExists())
  211209. {
  211210. MIDIPortRef port;
  211211. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211212. {
  211213. mo = new MidiOutput();
  211214. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  211215. }
  211216. }
  211217. CFRelease (pname);
  211218. }
  211219. }
  211220. return mo;
  211221. }
  211222. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211223. {
  211224. MidiOutput* mo = 0;
  211225. if (makeSureClientExists())
  211226. {
  211227. MIDIEndpointRef endPoint;
  211228. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211229. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211230. {
  211231. mo = new MidiOutput();
  211232. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  211233. }
  211234. CFRelease (name);
  211235. }
  211236. return mo;
  211237. }
  211238. MidiOutput::~MidiOutput()
  211239. {
  211240. delete (MidiPortAndEndpoint*) internal;
  211241. }
  211242. void MidiOutput::reset()
  211243. {
  211244. }
  211245. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211246. {
  211247. return false;
  211248. }
  211249. void MidiOutput::setVolume (float leftVol, float rightVol)
  211250. {
  211251. }
  211252. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211253. {
  211254. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211255. if (message.isSysEx())
  211256. {
  211257. const int maxPacketSize = 256;
  211258. int pos = 0, bytesLeft = message.getRawDataSize();
  211259. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211260. HeapBlock <MIDIPacketList> packets;
  211261. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211262. packets->numPackets = numPackets;
  211263. MIDIPacket* p = packets->packet;
  211264. for (int i = 0; i < numPackets; ++i)
  211265. {
  211266. p->timeStamp = 0;
  211267. p->length = jmin (maxPacketSize, bytesLeft);
  211268. memcpy (p->data, message.getRawData() + pos, p->length);
  211269. pos += p->length;
  211270. bytesLeft -= p->length;
  211271. p = MIDIPacketNext (p);
  211272. }
  211273. if (mpe->port != 0)
  211274. MIDISend (mpe->port, mpe->endPoint, packets);
  211275. else
  211276. MIDIReceived (mpe->endPoint, packets);
  211277. }
  211278. else
  211279. {
  211280. MIDIPacketList packets;
  211281. packets.numPackets = 1;
  211282. packets.packet[0].timeStamp = 0;
  211283. packets.packet[0].length = message.getRawDataSize();
  211284. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211285. if (mpe->port != 0)
  211286. MIDISend (mpe->port, mpe->endPoint, &packets);
  211287. else
  211288. MIDIReceived (mpe->endPoint, &packets);
  211289. }
  211290. }
  211291. const StringArray MidiInput::getDevices()
  211292. {
  211293. StringArray s;
  211294. const ItemCount num = MIDIGetNumberOfSources();
  211295. for (ItemCount i = 0; i < num; ++i)
  211296. {
  211297. MIDIEndpointRef source = MIDIGetSource (i);
  211298. if (source != 0)
  211299. {
  211300. String name (getConnectedEndpointName (source));
  211301. if (name.isEmpty())
  211302. name = "<error>";
  211303. s.add (name);
  211304. }
  211305. else
  211306. {
  211307. s.add ("<error>");
  211308. }
  211309. }
  211310. return s;
  211311. }
  211312. int MidiInput::getDefaultDeviceIndex()
  211313. {
  211314. return 0;
  211315. }
  211316. struct MidiPortAndCallback
  211317. {
  211318. MidiInput* input;
  211319. MidiPortAndEndpoint* portAndEndpoint;
  211320. MidiInputCallback* callback;
  211321. MemoryBlock pendingData;
  211322. int pendingBytes;
  211323. double pendingDataTime;
  211324. bool active;
  211325. void processSysex (const uint8*& d, int& size, const double time)
  211326. {
  211327. if (*d == 0xf0)
  211328. {
  211329. pendingBytes = 0;
  211330. pendingDataTime = time;
  211331. }
  211332. pendingData.ensureSize (pendingBytes + size, false);
  211333. uint8* totalMessage = (uint8*) pendingData.getData();
  211334. uint8* dest = totalMessage + pendingBytes;
  211335. while (size > 0)
  211336. {
  211337. if (pendingBytes > 0 && *d >= 0x80)
  211338. {
  211339. if (*d >= 0xfa || *d == 0xf8)
  211340. {
  211341. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211342. ++d;
  211343. --size;
  211344. }
  211345. else
  211346. {
  211347. if (*d == 0xf7)
  211348. {
  211349. *dest++ = *d++;
  211350. pendingBytes++;
  211351. --size;
  211352. }
  211353. break;
  211354. }
  211355. }
  211356. else
  211357. {
  211358. *dest++ = *d++;
  211359. pendingBytes++;
  211360. --size;
  211361. }
  211362. }
  211363. if (totalMessage [pendingBytes - 1] == 0xf7)
  211364. {
  211365. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211366. pendingBytes = 0;
  211367. }
  211368. else
  211369. {
  211370. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211371. }
  211372. }
  211373. };
  211374. namespace CoreMidiCallbacks
  211375. {
  211376. static CriticalSection callbackLock;
  211377. static VoidArray activeCallbacks;
  211378. }
  211379. static void midiInputProc (const MIDIPacketList* pktlist,
  211380. void* readProcRefCon,
  211381. void* srcConnRefCon)
  211382. {
  211383. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211384. const double originalTime = time;
  211385. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211386. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211387. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211388. {
  211389. const MIDIPacket* packet = &pktlist->packet[0];
  211390. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211391. {
  211392. const uint8* d = (const uint8*) (packet->data);
  211393. int size = packet->length;
  211394. while (size > 0)
  211395. {
  211396. time = originalTime;
  211397. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211398. {
  211399. mpc->processSysex (d, size, time);
  211400. }
  211401. else
  211402. {
  211403. int used = 0;
  211404. const MidiMessage m (d, size, used, 0, time);
  211405. if (used <= 0)
  211406. {
  211407. jassertfalse // malformed midi message
  211408. break;
  211409. }
  211410. else
  211411. {
  211412. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211413. }
  211414. size -= used;
  211415. d += used;
  211416. }
  211417. }
  211418. packet = MIDIPacketNext (packet);
  211419. }
  211420. }
  211421. }
  211422. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211423. {
  211424. MidiInput* mi = 0;
  211425. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211426. {
  211427. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211428. if (endPoint != 0)
  211429. {
  211430. CFStringRef pname;
  211431. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211432. {
  211433. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  211434. if (makeSureClientExists())
  211435. {
  211436. MIDIPortRef port;
  211437. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211438. mpc->active = false;
  211439. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211440. {
  211441. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211442. {
  211443. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211444. mpc->callback = callback;
  211445. mpc->pendingBytes = 0;
  211446. mpc->pendingData.ensureSize (128);
  211447. mi = new MidiInput (getDevices() [index]);
  211448. mpc->input = mi;
  211449. mi->internal = mpc;
  211450. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211451. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211452. }
  211453. else
  211454. {
  211455. OK (MIDIPortDispose (port));
  211456. }
  211457. }
  211458. }
  211459. }
  211460. CFRelease (pname);
  211461. }
  211462. }
  211463. return mi;
  211464. }
  211465. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211466. {
  211467. MidiInput* mi = 0;
  211468. if (makeSureClientExists())
  211469. {
  211470. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211471. mpc->active = false;
  211472. MIDIEndpointRef endPoint;
  211473. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211474. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211475. {
  211476. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211477. mpc->callback = callback;
  211478. mpc->pendingBytes = 0;
  211479. mpc->pendingData.ensureSize (128);
  211480. mi = new MidiInput (deviceName);
  211481. mpc->input = mi;
  211482. mi->internal = mpc;
  211483. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211484. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211485. }
  211486. CFRelease (name);
  211487. }
  211488. return mi;
  211489. }
  211490. MidiInput::MidiInput (const String& name_)
  211491. : name (name_)
  211492. {
  211493. }
  211494. MidiInput::~MidiInput()
  211495. {
  211496. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211497. mpc->active = false;
  211498. {
  211499. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211500. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211501. }
  211502. if (mpc->portAndEndpoint->port != 0)
  211503. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211504. delete mpc->portAndEndpoint;
  211505. delete mpc;
  211506. }
  211507. void MidiInput::start()
  211508. {
  211509. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211510. ((MidiPortAndCallback*) internal)->active = true;
  211511. }
  211512. void MidiInput::stop()
  211513. {
  211514. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211515. ((MidiPortAndCallback*) internal)->active = false;
  211516. }
  211517. #undef log
  211518. #else
  211519. MidiOutput::~MidiOutput()
  211520. {
  211521. }
  211522. void MidiOutput::reset()
  211523. {
  211524. }
  211525. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211526. {
  211527. return false;
  211528. }
  211529. void MidiOutput::setVolume (float leftVol, float rightVol)
  211530. {
  211531. }
  211532. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211533. {
  211534. }
  211535. const StringArray MidiOutput::getDevices()
  211536. {
  211537. return StringArray();
  211538. }
  211539. MidiOutput* MidiOutput::openDevice (int index)
  211540. {
  211541. return 0;
  211542. }
  211543. const StringArray MidiInput::getDevices()
  211544. {
  211545. return StringArray();
  211546. }
  211547. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211548. {
  211549. return 0;
  211550. }
  211551. #endif
  211552. #endif
  211553. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211554. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211555. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211556. // compiled on its own).
  211557. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  211558. #if ! JUCE_QUICKTIME
  211559. #error "On the Mac, cameras use Quicktime, so if you turn on JUCE_USE_CAMERA, you also need to enable JUCE_QUICKTIME"
  211560. #endif
  211561. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211562. class QTCameraDeviceInteral;
  211563. END_JUCE_NAMESPACE
  211564. @interface QTCaptureCallbackDelegate : NSObject
  211565. {
  211566. @public
  211567. CameraDevice* owner;
  211568. QTCameraDeviceInteral* internal;
  211569. int64 firstPresentationTime;
  211570. int64 averageTimeOffset;
  211571. }
  211572. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211573. - (void) dealloc;
  211574. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211575. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211576. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211577. fromConnection: (QTCaptureConnection*) connection;
  211578. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211579. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211580. fromConnection: (QTCaptureConnection*) connection;
  211581. @end
  211582. BEGIN_JUCE_NAMESPACE
  211583. class QTCameraDeviceInteral
  211584. {
  211585. public:
  211586. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211587. {
  211588. const ScopedAutoReleasePool pool;
  211589. session = [[QTCaptureSession alloc] init];
  211590. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211591. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211592. input = 0;
  211593. audioInput = 0;
  211594. audioDevice = 0;
  211595. fileOutput = 0;
  211596. imageOutput = 0;
  211597. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211598. internalDev: this];
  211599. NSError* err = 0;
  211600. [device retain];
  211601. [device open: &err];
  211602. if (err == 0)
  211603. {
  211604. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211605. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211606. [session addInput: input error: &err];
  211607. if (err == 0)
  211608. {
  211609. resetFile();
  211610. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211611. [imageOutput setDelegate: callbackDelegate];
  211612. if (err == 0)
  211613. {
  211614. [session startRunning];
  211615. return;
  211616. }
  211617. }
  211618. }
  211619. openingError = nsStringToJuce ([err description]);
  211620. DBG (openingError);
  211621. }
  211622. ~QTCameraDeviceInteral()
  211623. {
  211624. [session stopRunning];
  211625. [session removeOutput: imageOutput];
  211626. [session release];
  211627. [input release];
  211628. [device release];
  211629. [audioDevice release];
  211630. [audioInput release];
  211631. [fileOutput release];
  211632. [imageOutput release];
  211633. [callbackDelegate release];
  211634. }
  211635. void resetFile()
  211636. {
  211637. [fileOutput recordToOutputFileURL: nil];
  211638. [session removeOutput: fileOutput];
  211639. [fileOutput release];
  211640. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211641. [session removeInput: audioInput];
  211642. [audioInput release];
  211643. audioInput = 0;
  211644. [audioDevice release];
  211645. audioDevice = 0;
  211646. [fileOutput setDelegate: callbackDelegate];
  211647. }
  211648. void addDefaultAudioInput()
  211649. {
  211650. NSError* err = nil;
  211651. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211652. if ([audioDevice open: &err])
  211653. [audioDevice retain];
  211654. else
  211655. audioDevice = nil;
  211656. if (audioDevice != 0)
  211657. {
  211658. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211659. [session addInput: audioInput error: &err];
  211660. }
  211661. }
  211662. void addListener (CameraImageListener* listenerToAdd)
  211663. {
  211664. const ScopedLock sl (listenerLock);
  211665. if (listeners.size() == 0)
  211666. [session addOutput: imageOutput error: nil];
  211667. listeners.addIfNotAlreadyThere (listenerToAdd);
  211668. }
  211669. void removeListener (CameraImageListener* listenerToRemove)
  211670. {
  211671. const ScopedLock sl (listenerLock);
  211672. listeners.removeValue (listenerToRemove);
  211673. if (listeners.size() == 0)
  211674. [session removeOutput: imageOutput];
  211675. }
  211676. void callListeners (CIImage* frame, int w, int h)
  211677. {
  211678. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211679. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211680. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211681. CGContextFlush (image.context);
  211682. const ScopedLock sl (listenerLock);
  211683. for (int i = listeners.size(); --i >= 0;)
  211684. {
  211685. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211686. if (l != 0)
  211687. l->imageReceived (image);
  211688. }
  211689. }
  211690. QTCaptureDevice* device;
  211691. QTCaptureDeviceInput* input;
  211692. QTCaptureDevice* audioDevice;
  211693. QTCaptureDeviceInput* audioInput;
  211694. QTCaptureSession* session;
  211695. QTCaptureMovieFileOutput* fileOutput;
  211696. QTCaptureDecompressedVideoOutput* imageOutput;
  211697. QTCaptureCallbackDelegate* callbackDelegate;
  211698. String openingError;
  211699. VoidArray listeners;
  211700. CriticalSection listenerLock;
  211701. };
  211702. END_JUCE_NAMESPACE
  211703. @implementation QTCaptureCallbackDelegate
  211704. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211705. internalDev: (QTCameraDeviceInteral*) d
  211706. {
  211707. [super init];
  211708. owner = owner_;
  211709. internal = d;
  211710. firstPresentationTime = 0;
  211711. averageTimeOffset = 0;
  211712. return self;
  211713. }
  211714. - (void) dealloc
  211715. {
  211716. [super dealloc];
  211717. }
  211718. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211719. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211720. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211721. fromConnection: (QTCaptureConnection*) connection
  211722. {
  211723. if (internal->listeners.size() > 0)
  211724. {
  211725. const ScopedAutoReleasePool pool;
  211726. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211727. CVPixelBufferGetWidth (videoFrame),
  211728. CVPixelBufferGetHeight (videoFrame));
  211729. }
  211730. }
  211731. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211732. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211733. fromConnection: (QTCaptureConnection*) connection
  211734. {
  211735. const Time now (Time::getCurrentTime());
  211736. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  211737. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  211738. #else
  211739. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  211740. #endif
  211741. int64 presentationTime = (hosttime != nil)
  211742. ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
  211743. : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50);
  211744. const int64 timeDiff = now.toMilliseconds() - presentationTime;
  211745. if (firstPresentationTime == 0)
  211746. {
  211747. firstPresentationTime = presentationTime;
  211748. averageTimeOffset = timeDiff;
  211749. }
  211750. else
  211751. {
  211752. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  211753. }
  211754. }
  211755. @end
  211756. BEGIN_JUCE_NAMESPACE
  211757. class QTCaptureViewerComp : public NSViewComponent
  211758. {
  211759. public:
  211760. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  211761. {
  211762. const ScopedAutoReleasePool pool;
  211763. captureView = [[QTCaptureView alloc] init];
  211764. [captureView setCaptureSession: internal->session];
  211765. setSize (640, 480); // xxx need to somehow get the movie size - how?
  211766. setView (captureView);
  211767. }
  211768. ~QTCaptureViewerComp()
  211769. {
  211770. setView (0);
  211771. [captureView setCaptureSession: nil];
  211772. [captureView release];
  211773. }
  211774. QTCaptureView* captureView;
  211775. };
  211776. CameraDevice::CameraDevice (const String& name_, int index)
  211777. : name (name_)
  211778. {
  211779. isRecording = false;
  211780. internal = new QTCameraDeviceInteral (this, index);
  211781. }
  211782. CameraDevice::~CameraDevice()
  211783. {
  211784. stopRecording();
  211785. delete static_cast <QTCameraDeviceInteral*> (internal);
  211786. internal = 0;
  211787. }
  211788. Component* CameraDevice::createViewerComponent()
  211789. {
  211790. return new QTCaptureViewerComp (this, static_cast <QTCameraDeviceInteral*> (internal));
  211791. }
  211792. const String CameraDevice::getFileExtension()
  211793. {
  211794. return ".mov";
  211795. }
  211796. void CameraDevice::startRecordingToFile (const File& file, int quality)
  211797. {
  211798. stopRecording();
  211799. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  211800. d->callbackDelegate->firstPresentationTime = 0;
  211801. file.deleteFile();
  211802. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  211803. // out wrong, so we'll put some audio in there too..,
  211804. d->addDefaultAudioInput();
  211805. [d->session addOutput: d->fileOutput error: nil];
  211806. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  211807. for (;;)
  211808. {
  211809. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  211810. if (connection == 0)
  211811. break;
  211812. QTCompressionOptions* options = 0;
  211813. NSString* mediaType = [connection mediaType];
  211814. if ([mediaType isEqualToString: QTMediaTypeVideo])
  211815. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  211816. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  211817. : @"QTCompressionOptions240SizeH264Video"];
  211818. else if ([mediaType isEqualToString: QTMediaTypeSound])
  211819. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  211820. [d->fileOutput setCompressionOptions: options forConnection: connection];
  211821. }
  211822. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  211823. isRecording = true;
  211824. }
  211825. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  211826. {
  211827. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  211828. if (d->callbackDelegate->firstPresentationTime != 0)
  211829. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  211830. return Time();
  211831. }
  211832. void CameraDevice::stopRecording()
  211833. {
  211834. if (isRecording)
  211835. {
  211836. static_cast <QTCameraDeviceInteral*> (internal)->resetFile();
  211837. isRecording = false;
  211838. }
  211839. }
  211840. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  211841. {
  211842. if (listenerToAdd != 0)
  211843. static_cast <QTCameraDeviceInteral*> (internal)->addListener (listenerToAdd);
  211844. }
  211845. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  211846. {
  211847. if (listenerToRemove != 0)
  211848. static_cast <QTCameraDeviceInteral*> (internal)->removeListener (listenerToRemove);
  211849. }
  211850. const StringArray CameraDevice::getAvailableDevices()
  211851. {
  211852. const ScopedAutoReleasePool pool;
  211853. StringArray results;
  211854. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211855. for (int i = 0; i < (int) [devs count]; ++i)
  211856. {
  211857. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  211858. results.add (nsStringToJuce ([dev localizedDisplayName]));
  211859. }
  211860. return results;
  211861. }
  211862. CameraDevice* CameraDevice::openDevice (int index,
  211863. int minWidth, int minHeight,
  211864. int maxWidth, int maxHeight)
  211865. {
  211866. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  211867. if (static_cast <QTCameraDeviceInteral*> (d->internal)->openingError.isEmpty())
  211868. return d.release();
  211869. return 0;
  211870. }
  211871. #endif
  211872. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  211873. #endif
  211874. #endif
  211875. END_JUCE_NAMESPACE
  211876. #endif
  211877. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  211878. #endif
  211879. #endif